-
Notifications
You must be signed in to change notification settings - Fork 1
Basic Use Macros
This is just a quick example of how you can use EvioTool in a ROOT macro.
In this case, since you know what it is you want to read from the EVIO file, you setup the required data structure in your code and only read those parts from EVIO file that you want.
Here is an example that reads HPS data for the ECAL FADC mode1 pulses and makes a cumulative 2-D histogram. To run this, make sure that the libEvioTool.so (or .dylib on a Mac) is in your LD_LIBRARY_PATH so ROOT can find it.
The code below also here: macros/FADC_plot.C
R__LOAD_LIBRARY(libHPSEvioReader); // ROOT6 way to load a library.
void FADC_plot(){
EvioTool *p = new EvioTool();
// Open an EVIO data file. Modify the filename and path to where you have your data.
p->Open("hps_005772.evio");
int i=0;
TStopwatch st;
p->SetAutoAdd(false); // Do not add in all the data found in the file. (not needed, it is the default :-)
auto head = p->AddLeaf<unsigned int>("Header",49152,0,"Header bank"); // Add a Leaf for the Header data of type unsigned_int.
Bank *ECAL = p->AddBank("Ecal",{37,39},0,"Ecal banks"); // Add the ECAL Bank, with can have tag 37 or 39
// Then, in the ECAL bank, add the FADC data Leaf for mode 1 data.
Leaf<FADCdata> *FADC = ECAL->AddLeaf<FADCdata>("FADC",57601,0,"FADC mode 1 data");
TH2F *fa=new TH2F("fa","FADC pulse accumulation",51,0,50,201,0,400); // Book 2-D histogram.
cout << "Start Stopwatch\n";
st.Start();
while(p->Next()==0 ){ // Run through the events.
if( (++i % 10000) == 0 ){
st.Stop();
double time=st.RealTime();
cout << i << " at " << time << " ";
cout << (double)i/time/1000. << " kHz " << 1.e6*time/i << " micro s/event"<< endl;
st.Continue();
}
// Retrieve the data for the FADCs and fill the 2D histogram.
for(int ii=0;ii<FADC->Size(); ++ii){ // For each bit of FADC data found
for(int j=0;j<FADC->At(ii).GetSampleSize();++j){ // Run through the size of the Leaf
fa->Fill(j,FADC->At(ii).GetSample(j)); // Fill histogram with each pulse sample.
}
}
};
st.Stop();
cout << "Processing for " << st.RealTime() << endl;
cout << (double)i/st.RealTime()/1000. << " kHz " << 1.e6*st.RealTime()/i << " micro seconds/event."<< endl;
fa->Draw("colz");
}
Assuming that you stored the file in macros/FADC_plot.C, you run this code from the ROOT prompt with:
root [0] .x macros/FADC_plot.C
The speed is much slower than just going through the file (at 1.9kHz), since the double loop and the histogramming takes a lot of time. The plot you get will have about 1.8E+08 entries.