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 |
void example3(TString dir,TString list="", TString treelist="+ALL", Int_t nmax=500000000){ |
19 |
|
20 |
// Create a timer object to benchmark this loop |
21 |
TStopwatch timer; |
22 |
timer.Start(); |
23 |
TString wd=gSystem->WorkingDirectory(); |
24 |
// |
25 |
PamLevel2* event = new PamLevel2(); // << create pamela event |
26 |
|
27 |
// ========================================================= |
28 |
// << First a TList of root files is created |
29 |
// << (either from a specific list or from the whole input directory) |
30 |
TList *l = event->GetListOfLevel2Files(dir,list); |
31 |
// << Hence a TChain is created from the list. |
32 |
// << All the trees required by the user are made friend. |
33 |
TChain *T = event->GetPamTree(l,treelist); |
34 |
// << In the following the TChain can be used similarly to a TTree. |
35 |
// |
36 |
// NB! It is still possible to read a single file and get a TTree, by means of the methods: |
37 |
// TTree* LoadPamTrees(TFile *f); |
38 |
// TTree* LoadPamTrees(TFile *f,TString treelist); |
39 |
// ========================================================= |
40 |
|
41 |
Int_t nevent = T->GetEntries(); |
42 |
|
43 |
Int_t ntrk=0; |
44 |
if(nevent < nmax)nmax=nevent; |
45 |
cout << endl<<" Start loop over events "<<endl; |
46 |
for (Int_t i=0; i<nmax;i++){ |
47 |
// |
48 |
T->GetEntry(i); |
49 |
|
50 |
if(event->GetNTracks() > 1)cout << " Ev "<<i << " multiple tracks: "<< event->GetNTracks() << endl; |
51 |
|
52 |
if(event->TrkLevel2::ntrk() >0){ |
53 |
ntrk++; |
54 |
}; |
55 |
|
56 |
for(Int_t it=0; it<event->GetNTracks(); it++){ |
57 |
|
58 |
PamTrack *track = event->GetTrack(it); |
59 |
PamTrack *image = 0; |
60 |
|
61 |
if(track->HasImage())image = event->GetTrackImage(it); |
62 |
|
63 |
delete track; |
64 |
if(image)delete image; |
65 |
|
66 |
}; |
67 |
|
68 |
}; // end loop over the events |
69 |
cout << endl << endl << " Done "<< endl<<endl; |
70 |
cout << ntrk <<" tracks over "<<nmax<<" events ("<< 100*ntrk/nmax<<"%)"<<endl; |
71 |
|
72 |
// Stop timer and print results |
73 |
timer.Stop(); |
74 |
Double_t rtime = timer.RealTime(); |
75 |
Double_t ctime = timer.CpuTime(); |
76 |
printf("RealTime=%f seconds, CpuTime=%f seconds\n",rtime,ctime); |
77 |
|
78 |
gSystem->ChangeDirectory(wd); |
79 |
|
80 |
}; |