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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by pam-fi, Fri Aug 4 13:33:32 2006 UTC revision 1.4 by mocchiut, Tue Jan 16 15:26:30 2007 UTC
# Line 15  Line 15 
15  //  All selected trees in all the files are chained and made friends.  //  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.  //  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){  void example3(TString dir,TString list="", TString treelist="+ALL", Int_t nmax=500000000){
23    
24          //   Create a timer object to benchmark this loop      //   Create a timer object to benchmark this loop
25          TStopwatch timer;      TStopwatch timer;
26          timer.Start();      timer.Start();
27          TString wd=gSystem->WorkingDirectory();      TString wd=gSystem->WorkingDirectory();
28          //      //
29          PamLevel2*  event  = new PamLevel2();       // << create pamela event      PamLevel2*  event  = new PamLevel2();       // << create pamela event
30                    
31          // =========================================================      // =========================================================
32          // << First a TList of root files is created      // << First a TList of root files is created
33          // << (either from a specific list or from the whole input directory)      // << (either from a specific list or from the whole input directory)
34          TList *l  = event->GetListOfLevel2Files(dir,list);      TList *l  = event->GetListOfLevel2Files(dir,list);
35          // << Hence a TChain is created from the list.      // << Hence a TChain is created from the list.
36          // << All the trees required by the user are made friend.      // << All the trees required by the user are made friend.
37          TChain *T = event->LoadPamTrees(l,treelist);      TChain *T = event->GetPamTree(l,treelist);
38          // << In the following the TChain can be used similarly to a TTree.      // << 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);      TChain *RUNT = event->GetRunTree(dir,list); // << get the run information and store it in RUNT
42          // TTree* LoadPamTrees(TFile *f,TString treelist);  
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();      Int_t nevent = T->GetEntries();    
50                                    
51          Int_t ntrk=0;      Int_t ntrk=0;
52          if(nevent < nmax)nmax=nevent;      if(nevent < nmax)nmax=nevent;
53          cout << endl<<" Start loop over events   "<<endl;      cout << endl<<" Start loop over events   "<<endl;
54      for (Int_t i=0; i<nmax;i++){      for (Int_t i=0; i<nmax;i++){
55          //          //
56                  T->GetEntry(i);          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->GetNTracks() > 1)cout << " Ev "<<i << " multiple tracks: "<< event->GetNTracks() << endl;          if(event->GetTrkLevel2()->GetNTracks() > 1)cout << " Ev "<<i << " multiple tracks: "<< event->GetTrkLevel2()->GetNTracks() << endl;
62                                    
63                  if(event->TrkLevel2::ntrk() >0){          if(event->GetTrkLevel2()->ntrk() >0){
64                          ntrk++;              ntrk++;
65                  };          };
66                                    
67                  for(Int_t it=0; it<event->GetNTracks(); it++){          for(Int_t it=0; it<event->GetTrkLevel2()->GetNTracks(); it++){
68                                                    
69                          PamTrack *track = event->GetTrack(it);              PamTrack *track = event->GetTrack(it);
70                          PamTrack *image = 0;              PamTrack *image = 0;
71                                                    
72                          if(track->HasImage())image = event->GetTrackImage(it);              if(track->GetTrkTrack()->HasImage())image = event->GetTrackImage(it);
73                                                    
74                          delete track;          };
                         if(image)delete image;  
                   
                 };  
75    
76      };                                       // end loop over the events      };                                       // end loop over the events
77      cout << endl << endl << " Done "<< endl<<endl;      cout << endl << endl << " Done "<< endl<<endl;
78          cout << ntrk <<" tracks over "<<nmax<<" events ("<< 100*ntrk/nmax<<"%)"<<endl;      cout << ntrk <<" tracks over "<<nmax<<" events ("<< 100*ntrk/nmax<<"%)"<<endl;
79    
80  //  Stop timer and print results  //  Stop timer and print results
81          timer.Stop();      timer.Stop();
82          Double_t rtime = timer.RealTime();      Double_t rtime = timer.RealTime();
83          Double_t ctime = timer.CpuTime();      Double_t ctime = timer.CpuTime();
84          printf("RealTime=%f seconds, CpuTime=%f seconds\n",rtime,ctime);      printf("RealTime=%f seconds, CpuTime=%f seconds\n",rtime,ctime);
85    
86          delete T;      gSystem->ChangeDirectory(wd);
         delete event;  
         gSystem->ChangeDirectory(wd);  
87                    
88  };  };

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.4

  ViewVC Help
Powered by ViewVC 1.1.23