Simple Macro to count the Number of Candidates
TH1* nCand( KanEventSource& input, const char* listName, UInt_t nEvt = 0) {
// This is a simple macro to fill a 1D the # of candidate on a given list
// The input is a KanEventSource.
// The return value is the filled histogram
//
// To Build a KanEventSource you need to do:
// root[0] KanEventSource* input = KanEventSource::mini("in");
// root[1] input->Add("/A/Collection/Name")
//
// To invoke this macro you could do (for example)
// root[2] .L ../KanExample/nCand.C
// root[3] TH1F* hist = nCand(*input,"ChargedTracks");
// root[4] hist->Draw();
//
// Note that this macro is the equivalent of doing:
// root[5] input->getComponent(3)->Draw("Cnd_<list>__n");
//
// Setup the input data
TString theName("Cnd_");
theName += listName;
BtaCandHandleList cands(KanCompMap::cnd,theName.Data());
input.setBranchToRead(cands);
// Build the output histogram
TH1F* hist = new TH1F("nCand","A plot of number of candidates on a list",31,-0.5,30.5);
// Setup the Event Loop
UInt_t n = (UInt_t)input.GetEntries();
if ( nEvt > 0 ) {
n = n > nEvt ? nEvt : n;
}
cout << "Will run on " << n << " events." << endl;
// Event Loop
for ( UInt_t i(0); i < n; ++i ) {
// Load the event
input.LoadTree(i);
// Read the data
if ( !cands(input) ) {
cerr << "Failed to read branch object for event " << i << endl;
break;
}
// Fill the output histogram
hist->Fill((Float_t)(cands.size()));
}
// Return the histogram
return hist;
}
ROOT page - Class index - Class Hierarchy - Top of the page
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.
|