1 |
pam-fi |
1.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 |
pam-fi |
1.3 |
// --- Modified on January 2007 --- |
19 |
|
|
// |
20 |
|
|
// see the comment at the beginning of example1.C |
21 |
|
|
// |
22 |
pam-fi |
1.1 |
void example3(TString dir,TString list="", TString treelist="+ALL", Int_t nmax=500000000){ |
23 |
|
|
|
24 |
pam-fi |
1.3 |
// 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 |
pam-fi |
1.1 |
|
31 |
pam-fi |
1.3 |
// ========================================================= |
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 |
|
|
// NB! It is still possible to read a single file and get a TTree, by means of the methods: |
41 |
|
|
// TTree* LoadPamTrees(TFile *f); |
42 |
|
|
// TTree* LoadPamTrees(TFile *f,TString treelist); |
43 |
|
|
// ========================================================= |
44 |
pam-fi |
1.1 |
|
45 |
pam-fi |
1.3 |
Int_t nevent = T->GetEntries(); |
46 |
pam-fi |
1.1 |
|
47 |
pam-fi |
1.3 |
Int_t ntrk=0; |
48 |
|
|
if(nevent < nmax)nmax=nevent; |
49 |
|
|
cout << endl<<" Start loop over events "<<endl; |
50 |
pam-fi |
1.1 |
for (Int_t i=0; i<nmax;i++){ |
51 |
|
|
// |
52 |
pam-fi |
1.3 |
event->Clear(); |
53 |
|
|
T->GetEntry(i); |
54 |
pam-fi |
1.1 |
|
55 |
pam-fi |
1.3 |
if(event->GetTrkLevel2()->GetNTracks() > 1)cout << " Ev "<<i << " multiple tracks: "<< event->GetTrkLevel2()->GetNTracks() << endl; |
56 |
pam-fi |
1.1 |
|
57 |
pam-fi |
1.3 |
if(event->GetTrkLevel2()->ntrk() >0){ |
58 |
|
|
ntrk++; |
59 |
|
|
}; |
60 |
pam-fi |
1.1 |
|
61 |
pam-fi |
1.3 |
for(Int_t it=0; it<event->GetTrkLevel2()->GetNTracks(); it++){ |
62 |
pam-fi |
1.1 |
|
63 |
pam-fi |
1.3 |
PamTrack *track = event->GetTrack(it); |
64 |
|
|
PamTrack *image = 0; |
65 |
pam-fi |
1.1 |
|
66 |
pam-fi |
1.3 |
if(track->GetTrkTrack()->HasImage())image = event->GetTrackImage(it); |
67 |
pam-fi |
1.1 |
|
68 |
pam-fi |
1.3 |
}; |
69 |
pam-fi |
1.1 |
|
70 |
|
|
}; // end loop over the events |
71 |
|
|
cout << endl << endl << " Done "<< endl<<endl; |
72 |
pam-fi |
1.3 |
cout << ntrk <<" tracks over "<<nmax<<" events ("<< 100*ntrk/nmax<<"%)"<<endl; |
73 |
pam-fi |
1.1 |
|
74 |
|
|
// Stop timer and print results |
75 |
pam-fi |
1.3 |
timer.Stop(); |
76 |
|
|
Double_t rtime = timer.RealTime(); |
77 |
|
|
Double_t ctime = timer.CpuTime(); |
78 |
|
|
printf("RealTime=%f seconds, CpuTime=%f seconds\n",rtime,ctime); |
79 |
pam-fi |
1.1 |
|
80 |
pam-fi |
1.3 |
gSystem->ChangeDirectory(wd); |
81 |
pam-fi |
1.1 |
|
82 |
|
|
}; |