/[PAMELA software]/PamelaLevel2/doc/examples/Loop.cpp
ViewVC logotype

Diff of /PamelaLevel2/doc/examples/Loop.cpp

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

revision 1.2 by pam-fi, Mon Dec 11 18:29:01 2006 UTC revision 1.5 by pam-fi, Fri Feb 16 18:38:13 2007 UTC
# Line 10  Line 10 
10  #include <TString.h>  #include <TString.h>
11  #include <TBenchmark.h>  #include <TBenchmark.h>
12  #include <TFriendElement.h>  #include <TFriendElement.h>
13    #include <TObjectTable.h>
14    
15  #include <stdlib.h>  #include <stdlib.h>
16  #include <iostream>  #include <iostream>
# Line 20  using namespace std; Line 21  using namespace std;
21  //===================================  //===================================
22  // global variables  // global variables
23  //===================================  //===================================
24    Bool_t    DEBUG;
25    TString   DIR;
26    TString   LIST;
27    TString   OPTIONS;
28    ULong64_t MAXEV;
29    TString   OUTFILE;
30    
31  PamLevel2 *event = NULL;  PamLevel2 *event = NULL;
32  TChain    *tree  = NULL;  TChain    *tree  = NULL;
33    TChain    *runt  = NULL;
34  TFile     *outfh = NULL;  TFile     *outfh = NULL;
35  TFile     *outft = NULL;  TFile     *outft = NULL;
36  TTree     *otree = NULL;  TTree     *otree = NULL;
37    GL_RUN    *run   = NULL;
38    
39  bool fillTree   = false;  bool fillTree   = false;
40  bool fillHistos = false;  bool fillHistos = false;
# Line 33  bool fillHistos = false; Line 43  bool fillHistos = false;
43  // Functions to be provided externally  // Functions to be provided externally
44  //====================================  //====================================
45  bool Select(PamLevel2*);  bool Select(PamLevel2*);
46  void CreateHistos(TFile *);  void CreateHistos(PamLevel2*, TFile *);
47  void FillHistos(PamLevel2*);  void FillHistos(PamLevel2*);
48  void SaveHistos(TFile *);  void SaveHistos(TFile *);
49    
# Line 42  void SaveHistos(TFile *); Line 52  void SaveHistos(TFile *);
52  //==========================================  //==========================================
53  bool Begin(){  bool Begin(){
54                    
55      //------------------------  //     //------------------------
56      //  load magnetic field  //     //  load magnetic field
57      //------------------------  //     //------------------------
58      TString fieldpath = gSystem->Getenv("PAM_CALIB");  //     TString fieldpath = gSystem->Getenv("PAM_CALIB");
59      if(fieldpath.IsNull()){  //     if(fieldpath.IsNull()){
60          cout << " **ERROR** : No PAMELA environment variables defined "<<endl;  //      cout << " **ERROR** : No PAMELA environment variables defined "<<endl;
61          return 0;  //      return 0;
62      }  //     }
63      fieldpath.Append("/trk-param/field_param-0/");  //     fieldpath.Append("/trk-param/field_param-0/");
64      event->LoadField(fieldpath.Data());  //     event->GetTrkLevel2()->LoadField(fieldpath.Data());
65    // === non c'e` piu` bisogno
66    
67      //------------------------------      //------------------------------
68      //  create output histos/trees      //  create output histos/trees
69      //------------------------------      //------------------------------
70      if(fillHistos) CreateHistos(outfh);      if(fillHistos) CreateHistos(event,outfh);
71      if(fillTree){      if(fillTree)event->CreateCloneTrees(outft);
72  //      outft->cd();  
 //      event->CreateCloneTrees(tree,outft);  
         event->CreateCloneTrees(outft);  
     }  
73  //    gDirectory->ls();  //    gDirectory->ls();
74    
75      cout << "\nBegin() - done\n\n";      cout << "\nBegin() - done\n\n";
# Line 77  bool Process(int iev){ Line 84  bool Process(int iev){
84    
85            
86      if( !Select(event) )return false;      if( !Select(event) )return false;
 //    cout <<event->TrkLevel2::ntrk()<<endl;  
87    
   
     if(fillTree)event->FillCloneTrees();  
88      if(fillHistos)FillHistos(event);      if(fillHistos)FillHistos(event);
89        if(fillTree)event->FillCloneTrees();
90    
91      return true;      return true;
92    
# Line 92  bool Process(int iev){ Line 97  bool Process(int iev){
97    
98  bool Finish(){  bool Finish(){
99            
100        if(fillHistos){
101            SaveHistos(outfh);
102            outfh->Close();
103        }
104      if(fillTree){      if(fillTree){
105          outft->cd();          outft->cd();
106          event->WriteCloneTrees();          event->WriteCloneTrees();
107          outft->Close();          outft->Close();
108      }      }
     if(fillHistos){  
         SaveHistos(outfh);  
         outfh->Close();  
     }  
109            
110      cout << "Finish() - done\n";      cout << "Finish() - done\n";
111            
# Line 111  bool Finish(){ Line 116  bool Finish(){
116  //000000000000000000000000000000000000000000  //000000000000000000000000000000000000000000
117  //==========================================  //==========================================
118  Int_t Loop(TString ddir,TString list, ULong64_t nmax, TString options, TString outfile){  Int_t Loop(TString ddir,TString list, ULong64_t nmax, TString options, TString outfile){
119    
120    //    gObjectTable->Print();
121                    
122      if(options.Contains("fillTree"))fillTree=true;      if(options.Contains("fillTree"))fillTree=true;
123      if(options.Contains("fillHisto"))fillHistos=true;      if(options.Contains("fillHisto"))fillHistos=true;
# Line 153  Int_t Loop(TString ddir,TString list, UL Line 160  Int_t Loop(TString ddir,TString list, UL
160  //  read input file/list  //  read input file/list
161  //  --------------------  //  --------------------
162      event = new PamLevel2();      event = new PamLevel2();
163        if(DEBUG)gObjectTable->Print();
164      if(list.Contains(".root")){      if(list.Contains(".root")){
165          stringstream command;          stringstream command;
166          command.str("");          command.str("");
# Line 160  Int_t Loop(TString ddir,TString list, UL Line 168  Int_t Loop(TString ddir,TString list, UL
168          cout << command.str().c_str() << endl;          cout << command.str().c_str() << endl;
169          gSystem->Exec(command.str().c_str());          gSystem->Exec(command.str().c_str());
170          tree  = event->GetPamTree(ddir,"list-temp.txt",options);          tree  = event->GetPamTree(ddir,"list-temp.txt",options);
171            runt  = event->GetRunTree(ddir,"list-temp.txt");
172      }else{            }else{      
173          tree  = event->GetPamTree(ddir,list,options);          tree  = event->GetPamTree(ddir,list,options);
174            runt  = event->GetRunTree(ddir,list);
175      };      };
176    //    gObjectTable->Print();
177      tree->SetCacheSize(0);      tree->SetCacheSize(0);
178    
179  //  ---------------  //  ---------------
# Line 179  Int_t Loop(TString ddir,TString list, UL Line 190  Int_t Loop(TString ddir,TString list, UL
190            
191      cout << endl<<" Start loop over events:  "<< nmax<<endl;      cout << endl<<" Start loop over events:  "<< nmax<<endl;
192      Int_t ntrk = 0;      Int_t ntrk = 0;
193        Int_t ncls = 0;
194      Int_t sel  = 0;      Int_t sel  = 0;
195      Int_t get  = 0;      Int_t get  = 0;
196      TBenchmark *benchmark = new TBenchmark();      TBenchmark *benchmark = new TBenchmark();
197      benchmark->Start("event-loop");      benchmark->Start("event-loop");
198            
199      TString current_file = "";      TString current_file = "";
200        if(DEBUG)gObjectTable->Print();
201      for(ULong64_t iev=0; iev<nmax; iev++){      for(ULong64_t iev=0; iev<nmax; iev++){
202                    
203          event->Clear();          event->Clear();
204          if( tree->GetEntry(iev) ){  //      if( tree->GetEntry(iev) ){
205            if( event->GetEntry(iev) ){ //<<< new feature
206              get++;              get++;
207              if( Process(iev) ){              if( Process(iev) ){
208                    cout << "%%%% "<<iev << endl;
209                  sel++;                  sel++;
                 if(event->TrkLevel2::ntrk() >0)ntrk++;    
210              }              }
211              if(current_file.CompareTo(tree->GetFile()->GetName())){              if(current_file.CompareTo(tree->GetFile()->GetName())){
212                  current_file=tree->GetFile()->GetName();                  current_file=tree->GetFile()->GetName();
213                  cout << iev<< " -> "<< current_file << endl;                  cout <<endl<< iev<< " -> "<< current_file << endl;
 //          cout << tree->GetFile()->GetName() << endl;  
214              };              };
 //          if( fillTree && !(sel%10000) )  
 //          if(event->TrkLevel2::ntrk() >0)ntrk++;        
215          }else{          }else{
216              cout << "Chain entry "<<iev<<" -- ERROR --"<<endl;              cout << "Chain entry "<<iev<<" -- ERROR --"<<endl;
217          };          };
218  //      if(!(iev%100))cout << iev << endl;          if( !(iev%5000) && DEBUG)gObjectTable->Print();
219                    
220            if( !(iev%1000) )cout <<"|";
221    
222      };      };
223        cout <<endl;
224      benchmark->Show("event-loop");      benchmark->Show("event-loop");
225      cout << sel <<" selected events over "<<get;      cout << sel <<" selected events over "<<get;
226      if(get)cout<<" ("<< 100*sel/get<<"%)"<<endl;      if(get)cout<<" ("<< 100*sel/get<<"%)"<<endl;
227      cout << "Fitted tracks: "<<ntrk<<endl;      if(DEBUG)gObjectTable->Print();
228        event->Clear();
229  //  --------------  //  --------------
230  //  close and exit  //  close and exit
231  //  --------------  //  --------------
# Line 225  Int_t Loop(TString ddir,TString list, UL Line 239  Int_t Loop(TString ddir,TString list, UL
239    
240  #if !defined(__CINT__)  #if !defined(__CINT__)
241    
242  // input parameters  // // input parameters
243  Bool_t    DEBUG;  // Bool_t    DEBUG;
244  TString   DIR;  // TString   DIR;
245  TString   LIST;  // TString   LIST;
246  TString   OPTIONS;  // TString   OPTIONS;
247  ULong64_t MAXEV;  // ULong64_t MAXEV;
248  TString   OUTFILE;  // TString   OUTFILE;
249    
250  void usage(){  void usage(){
251    

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

  ViewVC Help
Powered by ViewVC 1.1.23