Created
January 8, 2014 21:16
-
-
Save mastbaum/8324821 to your computer and use it in GitHub Desktop.
Looping over a TTree
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Find the number of events simulated and the efficiency for a set of ntuples | |
// Usage: root -b -q "evcount.cxx([filename], rate=0)" # "filename" can have wildcards | |
// If provided, rate is events/detector-year | |
void evcount(TString filenames, float rate=0) { | |
TChain tc("output"); | |
tc.Add(filenames); | |
int entries = tc.GetEntries(); | |
cout << "Total entries: " << entries << endl; | |
// ROOT branch pointers | |
int evIndex; | |
tc.SetBranchAddress("evIndex", &evIndex); | |
bool scintFit; | |
tc.SetBranchAddress("scintFit", &scintFit); | |
// Counters | |
int mc_events = 0; | |
int triggered = 0; | |
int reconstructed = 0; | |
for (int i=0; i<entries; i++) { | |
if (i % 10000 == 0) { | |
cout << "."; | |
cout.flush(); | |
} | |
tc.GetEntry(i); | |
if (evIndex == -1 || evIndex == 0) { | |
mc_events++; | |
} | |
if (evIndex == 0) { | |
triggered++; | |
if (scintFit) { | |
reconstructed++; | |
} | |
} | |
} | |
cout << endl << "Simulated: " << mc_events; | |
if (rate > 0) { | |
cout << " (" << 1.0 * mc_events / rate << " years)"; | |
} | |
cout << endl; | |
cout << "Triggered: " << triggered << " (" << 1.0 * triggered / mc_events << ")" << endl; | |
cout << "Recon'ed: " << reconstructed << " (" << 1.0 * reconstructed / triggered << ")" << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment