/[PAMELA software]/PamelaLevel2/doc/examples/example3.C
ViewVC logotype

Contents of /PamelaLevel2/doc/examples/example3.C

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations) (download)
Mon Jan 15 11:51:39 2007 UTC (17 years, 10 months ago) by pam-fi
Branch: MAIN
Changes since 1.2: +44 -42 lines
File MIME type: text/plain
v3r00 **NEW**

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 // 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
45 Int_t nevent = T->GetEntries();
46
47 Int_t ntrk=0;
48 if(nevent < nmax)nmax=nevent;
49 cout << endl<<" Start loop over events "<<endl;
50 for (Int_t i=0; i<nmax;i++){
51 //
52 event->Clear();
53 T->GetEntry(i);
54
55 if(event->GetTrkLevel2()->GetNTracks() > 1)cout << " Ev "<<i << " multiple tracks: "<< event->GetTrkLevel2()->GetNTracks() << endl;
56
57 if(event->GetTrkLevel2()->ntrk() >0){
58 ntrk++;
59 };
60
61 for(Int_t it=0; it<event->GetTrkLevel2()->GetNTracks(); it++){
62
63 PamTrack *track = event->GetTrack(it);
64 PamTrack *image = 0;
65
66 if(track->GetTrkTrack()->HasImage())image = event->GetTrackImage(it);
67
68 };
69
70 }; // end loop over the events
71 cout << endl << endl << " Done "<< endl<<endl;
72 cout << ntrk <<" tracks over "<<nmax<<" events ("<< 100*ntrk/nmax<<"%)"<<endl;
73
74 // Stop timer and print results
75 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
80 gSystem->ChangeDirectory(wd);
81
82 };

  ViewVC Help
Powered by ViewVC 1.1.23