Skip to content

Instantly share code, notes, and snippets.

@jdbrice
jdbrice / starlight_reader_example.C
Created July 28, 2021 18:06
Example reader code for STARLight text format
ifstream infile( starlight.c_str() );
int iEvent =0;
while (infile) {
string sEvent, sVertex, sTrack1, sTrack2;
if (!getline( infile, sEvent )) break;
if (!getline( infile, sVertex )) break;
if (!getline( infile, sTrack1 )) break;
if (!getline( infile, sTrack2 )) break;
@jdbrice
jdbrice / Agufld.C
Created April 19, 2021 13:53
Export the STAR Magnetic field
static const Int_t nrp = 200; // number of R nodes in the map
static const Int_t nzp = 800; // number of Z nodes in the map
static const Float_t zm = 800.0; // map max length
static const Float_t rm = 400.0; // map max radius
static const Int_t nphi = 36;
//________________________________________________________________________________
void Agufld(const Char_t *field = "FieldOn") {
// if ( gClassTable->GetID("TGiant3") >= 0) { // root4star
// gROOT->LoadMacro("bfc.C");
// bfc(-1,"MagF,nodefault",0);
@jdbrice
jdbrice / plot_from_tree.C
Last active March 9, 2021 19:51
Plot tracking from ttree on Pythia events
TLatex tl;
TString label = "";
TString klabel = "";
TH1* sliceFit(TH2 * h2, TString _klabel){
TF1 * fgyRes = new TF1( "fgyRes", "gaus" );
fgyRes->SetRange( -0.5, 0.5 );
h2->RebinX(4);
h2->FitSlicesY( fgyRes );
@jdbrice
jdbrice / rootSTGM.C
Created February 12, 2021 01:03
Rough STAR sTGC geometry using ROOT TGeo
// Globals
TGeoManager *geom;
TGeoElementTable *table;
// Materials
TGeoMedium *mediumAir;
TGeoMedium *mediumG10;
TGeoMedium *mediumNPC02;
@jdbrice
jdbrice / pair_pt.C
Last active January 24, 2021 02:15
Rho photonuclear STARLight MC
#include "TFile.h"
#include "TH1F.h"
#include "TH1D.h"
#include "TH2F.h"
#include "TH3F.h"
#include "TCanvas.h"
#include "TMath.h"
#include "TVector3.h"
#include "TLegend.h"
@jdbrice
jdbrice / md-cal.sh
Last active October 8, 2024 11:49
Generate markdown table calendar. Use wiki links to individual days
# Author: Daniel Brandenburg
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@jdbrice
jdbrice / marp-example.md
Created July 13, 2020 20:48
Marp style block for custom css in preview AND export
theme _class backgroundColor marp footer tags
gaia
lead
true
Daniel Brandenburg | 07142020
<style> /* this works for export */
@jdbrice
jdbrice / gitcommitstr.C
Created July 26, 2019 14:42
TAG your ROOT files with your codes git commit so you always know what version of the code produced output
#include <cstdio>
#include <iostream>
#include <memory>
#include <stdexcept>
#include <string>
#include <array>
// credit : https://stackoverflow.com/users/58008/waqas
// from : https://stackoverflow.com/questions/478898/how-do-i-execute-a-command-and-get-output-of-command-within-c-using-posix
@jdbrice
jdbrice / moment.C
Created July 25, 2019 15:05
Calculate the moments of a histogram
//usr/bin/env root -l -b -q "$0( $1, \"$2\" )"; exit $?
/* Calculate the nth moment of a distribution
*
* int n : order of the moment to calculate
* TString filehist :
*/
double moment( int n = 1, TString filehist = "", float x1=0, float x2=-1 ){
cout << "Calculating moment " << n << " on " << filehist << endl;
@jdbrice
jdbrice / linspace.py
Last active January 31, 2019 21:29
Makes numpy linspace ranges from the shell, even chain together with commas
#!/usr/bin/env python
import numpy
import sys
if len(sys.argv) < 4:
print( "Usage: linspace start stop step [, endpoint, ndecimals]" )
exit()
if not sys.stdin.isatty():