/[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.2 by pam-fi, Mon Oct 9 12:37:52 2006 UTC revision 1.3 by pam-fi, Mon Jan 15 11:51:39 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->GetPamTree(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:      // NB! It is still possible to read a single file and get a TTree, by means of the methods:
41          // TTree* LoadPamTrees(TFile *f);      // TTree* LoadPamTrees(TFile *f);
42          // TTree* LoadPamTrees(TFile *f,TString treelist);      // TTree* LoadPamTrees(TFile *f,TString treelist);
43          // =========================================================      // =========================================================
44                    
45          Int_t nevent = T->GetEntries();      Int_t nevent = T->GetEntries();    
46                                    
47          Int_t ntrk=0;      Int_t ntrk=0;
48          if(nevent < nmax)nmax=nevent;      if(nevent < nmax)nmax=nevent;
49          cout << endl<<" Start loop over events   "<<endl;      cout << endl<<" Start loop over events   "<<endl;
50      for (Int_t i=0; i<nmax;i++){      for (Int_t i=0; i<nmax;i++){
51          //          //
52                  T->GetEntry(i);          event->Clear();
53            T->GetEntry(i);
54                                    
55                  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;
56                                    
57                  if(event->TrkLevel2::ntrk() >0){          if(event->GetTrkLevel2()->ntrk() >0){
58                          ntrk++;              ntrk++;
59                  };          };
60                                    
61                  for(Int_t it=0; it<event->GetNTracks(); it++){          for(Int_t it=0; it<event->GetTrkLevel2()->GetNTracks(); it++){
62                                                    
63                          PamTrack *track = event->GetTrack(it);              PamTrack *track = event->GetTrack(it);
64                          PamTrack *image = 0;              PamTrack *image = 0;
65                                                    
66                          if(track->HasImage())image = event->GetTrackImage(it);              if(track->GetTrkTrack()->HasImage())image = event->GetTrackImage(it);
67                                                    
68                          delete track;          };
                         if(image)delete image;  
                   
                 };  
69    
70      };                                       // end loop over the events      };                                       // end loop over the events
71      cout << endl << endl << " Done "<< endl<<endl;      cout << endl << endl << " Done "<< endl<<endl;
72          cout << ntrk <<" tracks over "<<nmax<<" events ("<< 100*ntrk/nmax<<"%)"<<endl;      cout << ntrk <<" tracks over "<<nmax<<" events ("<< 100*ntrk/nmax<<"%)"<<endl;
73    
74  //  Stop timer and print results  //  Stop timer and print results
75          timer.Stop();      timer.Stop();
76          Double_t rtime = timer.RealTime();      Double_t rtime = timer.RealTime();
77          Double_t ctime = timer.CpuTime();      Double_t ctime = timer.CpuTime();
78          printf("RealTime=%f seconds, CpuTime=%f seconds\n",rtime,ctime);      printf("RealTime=%f seconds, CpuTime=%f seconds\n",rtime,ctime);
79    
80          gSystem->ChangeDirectory(wd);      gSystem->ChangeDirectory(wd);
81                    
82  };  };

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

  ViewVC Help
Powered by ViewVC 1.1.23