| 1 |
// |
| 2 |
// Example to loop over events, reading more than one file. |
| 3 |
// |
| 4 |
// Input parameters are: |
| 5 |
// - dir: name of the directory where Level2 files are stored |
| 6 |
// - list: name of a text file with the list of file names to be processed. |
| 7 |
// If list="" all ROOT files inside the directory are processed (ROOT files that does not |
| 8 |
// match Pamela Level2 structure are automatically discarded) |
| 9 |
// - treelist: string containing the list of trees to be loaded (es: "-ORB-ND" or "-ALL+TRK+CAL+TOF"). |
| 10 |
// Possible options are: |
| 11 |
// +ALL +TRK +CAL +TRG +TOF +ND +AC +S4 +ORB |
| 12 |
// -ALL -TRK -CAL -TRG -TOF -ND -AC -S4 -ORB |
| 13 |
// - nmax: maximum number of events to be processed |
| 14 |
// |
| 15 |
// All selected trees in all the files are chained and made friends. |
| 16 |
// The whole "blob" can be accessed as if it was a single tree. |
| 17 |
// |
| 18 |
// --- Modified on January 2007 --- |
| 19 |
// |
| 20 |
// see the comment at the beginning of example1.C |
| 21 |
// |
| 22 |
void example3(TString dir,TString list="", TString treelist="+ALL", Int_t nmax=500000000){ |
| 23 |
|
| 24 |
// Create a timer object to benchmark this loop |
| 25 |
TStopwatch timer; |
| 26 |
timer.Start(); |
| 27 |
TString wd=gSystem->WorkingDirectory(); |
| 28 |
// |
| 29 |
PamLevel2* event = new PamLevel2(); // << create pamela event |
| 30 |
|
| 31 |
// ========================================================= |
| 32 |
// << First a TList of root files is created |
| 33 |
// << (either from a specific list or from the whole input directory) |
| 34 |
TList *l = event->GetListOfLevel2Files(dir,list); |
| 35 |
// << Hence a TChain is created from the list. |
| 36 |
// << All the trees required by the user are made friend. |
| 37 |
TChain *T = event->GetPamTree(l,treelist); |
| 38 |
// << In the following the TChain can be used similarly to a TTree. |
| 39 |
|
| 40 |
// |
| 41 |
TChain *RUNT = event->GetRunTree(dir,list); // << get the run information and store it in RUNT |
| 42 |
|
| 43 |
// |
| 44 |
// NB! It is still possible to read a single file and get a TTree, by means of the methods: |
| 45 |
// TTree* LoadPamTrees(TFile *f); |
| 46 |
// TTree* LoadPamTrees(TFile *f,TString treelist); |
| 47 |
// ========================================================= |
| 48 |
|
| 49 |
Int_t nevent = T->GetEntries(); |
| 50 |
|
| 51 |
Int_t ntrk=0; |
| 52 |
if(nevent < nmax)nmax=nevent; |
| 53 |
cout << endl<<" Start loop over events "<<endl; |
| 54 |
for (Int_t i=0; i<nmax;i++){ |
| 55 |
// |
| 56 |
event->Clear(); |
| 57 |
T->GetEntry(i); |
| 58 |
|
| 59 |
if ( event->UpdateRunInfo(RUNT,i) ) printf(" New RUN at entry = %llu RUN ID is %u NEVENTS is %u \n",i,event->GetRunInfo()->ID,event->GetRunInfo()->NEVENTS); |
| 60 |
|
| 61 |
if(event->GetTrkLevel2()->GetNTracks() > 1)cout << " Ev "<<i << " multiple tracks: "<< event->GetTrkLevel2()->GetNTracks() << endl; |
| 62 |
|
| 63 |
if(event->GetTrkLevel2()->ntrk() >0){ |
| 64 |
ntrk++; |
| 65 |
}; |
| 66 |
|
| 67 |
for(Int_t it=0; it<event->GetTrkLevel2()->GetNTracks(); it++){ |
| 68 |
|
| 69 |
PamTrack *track = event->GetTrack(it); |
| 70 |
PamTrack *image = 0; |
| 71 |
|
| 72 |
if(track->GetTrkTrack()->HasImage())image = event->GetTrackImage(it); |
| 73 |
|
| 74 |
}; |
| 75 |
|
| 76 |
}; // end loop over the events |
| 77 |
cout << endl << endl << " Done "<< endl<<endl; |
| 78 |
cout << ntrk <<" tracks over "<<nmax<<" events ("<< 100*ntrk/nmax<<"%)"<<endl; |
| 79 |
|
| 80 |
// Stop timer and print results |
| 81 |
timer.Stop(); |
| 82 |
Double_t rtime = timer.RealTime(); |
| 83 |
Double_t ctime = timer.CpuTime(); |
| 84 |
printf("RealTime=%f seconds, CpuTime=%f seconds\n",rtime,ctime); |
| 85 |
|
| 86 |
gSystem->ChangeDirectory(wd); |
| 87 |
|
| 88 |
}; |