[Halld-offline] ANALYSIS Library: Histograms and Custom ROOT Branches
Paul Mattione
pmatt at jlab.org
Mon Mar 9 15:12:09 EDT 2015
I've recently committed two changes to the ANALYSIS library:
1) You can now add custom branches to the output ROOT TTree for your DReaction analysis plugin. This can be done by checking out and running the perl script:
https://halldsvn.jlab.org/repos/trunk/scripts/analysis/MakeEventWriterROOT.pl
Run it with no arguments for instructions.
2) As you all know, creating histograms in a multithreaded environment is tricky since you first need to check whether another thread has already created the histogram (unless you're in the DEventProcessor::init() method). For example:
TH1I* dMassHist = NULL;
if(gDirectory->Get("InvariantMass") == NULL) //check to see if already created by another thread
dMassHist = new TH1I("InvariantMass", "My Title", 600, 0.6, 1.8);
else //already created by another thread
dMassHist = static_cast<TH1I*>(gDirectory->Get("InvariantMass"));
Now, in your custom analysis actions, you can instead simply execute a one-liner:
TH1I* dMassHist = GetOrCreate_Histogram<TH1I>("InvariantMass", "My Title", 600, 0.6, 1.8);
And it will do all of the checking/creation for you. This works for all histogram types: just call the function with the same arguments you would normally call your histogram constructor with. Just remember to specify the type (e.g. <TH1I>).
- Paul
More information about the Halld-offline
mailing list