/[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.1 by pam-fi, Wed Dec 6 11:07:35 2006 UTC revision 1.2 by pam-fi, Mon Dec 11 18:29:01 2006 UTC
# Line 33  bool fillHistos = false; Line 33  bool fillHistos = false;
33  // Functions to be provided externally  // Functions to be provided externally
34  //====================================  //====================================
35  bool Select(PamLevel2*);  bool Select(PamLevel2*);
36  void CreateHistos();  void CreateHistos(TFile *);
37  void FillHistos(PamLevel2*);  void FillHistos(PamLevel2*);
38  void SaveHistos(TFile *);  void SaveHistos(TFile *);
39    
# Line 57  bool Begin(){ Line 57  bool Begin(){
57      //------------------------------      //------------------------------
58      //  create output histos/trees      //  create output histos/trees
59      //------------------------------      //------------------------------
60      if(fillHistos) CreateHistos();      if(fillHistos) CreateHistos(outfh);
61      if(fillTree)   event->CreateCloneTrees(tree);      if(fillTree){
62    //      outft->cd();
63    //      event->CreateCloneTrees(tree,outft);
64            event->CreateCloneTrees(outft);
65        }
66    //    gDirectory->ls();
67    
68      cout << "\nBegin() - done\n\n";      cout << "\nBegin() - done\n\n";
69      return 1;      return 1;
# Line 70  bool Begin(){ Line 75  bool Begin(){
75    
76  bool Process(int iev){  bool Process(int iev){
77    
     //------------------------------  
     //  create output histos/trees  
     //------------------------------  
   
     event->Clear();  
     tree->GetEntry(iev);  
78            
79      if( !Select(event) )return false;      if( !Select(event) )return false;
80  //    cout <<event->TrkLevel2::ntrk()<<endl;  //    cout <<event->TrkLevel2::ntrk()<<endl;
81    
82    
83  //    if(fillTree)event->FillCloneTrees();      if(fillTree)event->FillCloneTrees();
84  //    if(fillHistos)FillHistos(event);      if(fillHistos)FillHistos(event);
85    
86      return true;      return true;
87    
# Line 160  Int_t Loop(TString ddir,TString list, UL Line 159  Int_t Loop(TString ddir,TString list, UL
159          command << " echo "<<list<<" > list-temp.txt";          command << " echo "<<list<<" > list-temp.txt";
160          cout << command.str().c_str() << endl;          cout << command.str().c_str() << endl;
161          gSystem->Exec(command.str().c_str());          gSystem->Exec(command.str().c_str());
162          tree  = event->GetPamTree(event->GetListOfLevel2Files(ddir,"list-temp.txt"),options);          tree  = event->GetPamTree(ddir,"list-temp.txt",options);
163      }else{            }else{      
164          tree  = event->GetPamTree(event->GetListOfLevel2Files(ddir,list),options);          tree  = event->GetPamTree(ddir,list,options);
165      };      };
166      tree->SetCacheSize(0);      tree->SetCacheSize(0);
167    
# Line 174  Int_t Loop(TString ddir,TString list, UL Line 173  Int_t Loop(TString ddir,TString list, UL
173  //  -----------------  //  -----------------
174  //  loop over events  //  loop over events
175  //  -----------------  //  -----------------
176      ULong64_t nevents = tree->GetEntriesFast();      ULong64_t nevents = tree->GetEntries();    
177      if(!nmax)nmax = numeric_limits<ULong64_t>::max();        if(!nmax)nmax = numeric_limits<ULong64_t>::max();  
178      if(nevents < nmax)nmax=nevents;      if(nevents < nmax)nmax=nevents;
179            
180      cout << endl<<" Start loop over events:  "<< nmax<<endl;      cout << endl<<" Start loop over events:  "<< nmax<<endl;
181      Int_t ntrk=0;      Int_t ntrk = 0;
182      Int_t sel=0;      Int_t sel  = 0;
183        Int_t get  = 0;
184      TBenchmark *benchmark = new TBenchmark();      TBenchmark *benchmark = new TBenchmark();
185      benchmark->Start("event-loop");      benchmark->Start("event-loop");
186            
187      TString current_file = "";      TString current_file = "";
188      for(ULong64_t iev=60000; iev<nmax; iev++){      for(ULong64_t iev=0; iev<nmax; iev++){
189                    
190  //      tree->GetEntry(iev);          event->Clear();
191          if( Process(iev) )sel++;          if( tree->GetEntry(iev) ){
192                get++;
193          if(current_file.CompareTo(tree->GetFile()->GetName())){              if( Process(iev) ){
194              current_file=tree->GetFile()->GetName();                  sel++;
195              cout << iev<< " -> "<< current_file << endl;                  if(event->TrkLevel2::ntrk() >0)ntrk++;  
196                }
197                if(current_file.CompareTo(tree->GetFile()->GetName())){
198                    current_file=tree->GetFile()->GetName();
199                    cout << iev<< " -> "<< current_file << endl;
200  //          cout << tree->GetFile()->GetName() << endl;  //          cout << tree->GetFile()->GetName() << endl;
201                };
202    //          if( fillTree && !(sel%10000) )
203    //          if(event->TrkLevel2::ntrk() >0)ntrk++;      
204            }else{
205                cout << "Chain entry "<<iev<<" -- ERROR --"<<endl;
206          };          };
207    //      if(!(iev%100))cout << iev << endl;
         if(event->TrkLevel2::ntrk() >0)ntrk++;    
         if(!(iev%100))cout << iev << endl;  
208                    
209      };      };
210      benchmark->Show("event-loop");      benchmark->Show("event-loop");
211      cout << ntrk <<" tracks over "<<nmax<<" events ";      cout << sel <<" selected events over "<<get;
212      if(nmax)cout<<"("<< 100*ntrk/nmax<<"%)"<<endl;      if(get)cout<<" ("<< 100*sel/get<<"%)"<<endl;
213      cout << "Selected events: "<<sel<<endl;      cout << "Fitted tracks: "<<ntrk<<endl;
214        
215  //  --------------  //  --------------
216  //  close and exit  //  close and exit
217  //  --------------  //  --------------
# Line 216  Int_t Loop(TString ddir,TString list, UL Line 223  Int_t Loop(TString ddir,TString list, UL
223    
224  /////////////////////////////////////////////////////////////////  /////////////////////////////////////////////////////////////////
225    
226  #if !defined(__CINT__)  #if !defined(__CINT__)
227    
228  // input parameters  // input parameters
229  Bool_t    DEBUG;  Bool_t    DEBUG;
230  TString   DIR;  TString   DIR;
231  TString   LIST;  TString   LIST;
232    TString   OPTIONS;
233  ULong64_t MAXEV;  ULong64_t MAXEV;
234  TString   OUTFILE;  TString   OUTFILE;
235    
236  void usage(){  void usage(){
237    
238        cout << "------------------------------------------------------------"<<endl;
239        cout << "Loop over events (on one or more Level2-files), applying some selection cuts (defined in My-Selection.cpp), \n";
240        cout << "creating output histograms (defined in My-Histos.cpp) and/or trees with selected events. \n \n ";
241      cout << "USAGE:"<<endl;      cout << "USAGE:"<<endl;
242      cout << "-processDir  [DIR]   -  Level2/Level1 data directory \n";      cout << "-processDir  DIR     -  Level2 data directory \n";
243      cout << "-processList [LIST]  -  list (txt) of names of files to be analysed \n";      cout << "-processList LIST    -  list  of files (.txt) or single file (.root) to be analysed \n";
244      cout << "-outputFile  [PATH]  -  name of the output file \n";      cout << "-outputFile  PATH    -  name of the output file \n";
245      cout << "-NumEvents   [XXX]   -  number of events to be analysed \n";      cout << "-NumEvents   XXX     -  number of events to be analysed \n";
246      cout << "--debug, -g          -  debug mode \n";      cout << "--debug, -g          -  debug mode \n";
247      cout << "--help, -h           -  print this help \n";      cout << "--help, -h           -  print this help \n";
248        cout << "-options [ options ] -  options: \n";
249        cout << "                        fillHistos --> create an output file with histograms  \n";
250        cout << "                        fillTree   --> create an output file with trees storing the selected events \n ";
251        cout << "                        +(-)ALL    --> inlcude(exclude) all trees and branches \n "   ;
252        cout << "                        +(-)TRK1 +(-)TRK2 +(-)CAL1 +(-)CAL2 +(-)TOF +(-)TRG +(-)ND +(-)S4 +(-)ORB --> inlcude(exclude) trees and branches  \n"  ;
253        cout << "------------------------------------------------------------"<<endl;
254  }  }
255  //  //
256  int HandleInputPar(int argc, char **argv){  int HandleInputPar(int argc, char **argv){
# Line 246  int HandleInputPar(int argc, char **argv Line 264  int HandleInputPar(int argc, char **argv
264  // -----------------------  // -----------------------
265  // Read input parameters  // Read input parameters
266  // -----------------------    // -----------------------  
267  /*              DEBUG   = false;          DEBUG   = false;
268                  DIR     = gSystem->WorkingDirectory();          DIR     = gSystem->WorkingDirectory();
269                  LIST    = "";          LIST    = "";
270                  OUTFILE = "TrkLevel1Report_output.root";          OUTFILE = "";
271                  MAXEV = numeric_limits<ULong64_t>::max();          OPTIONS = "+ALL fillTree";
272  */          MAXEV   = 0;    
273                                    
274    
275          for (int i = 1; i < argc; i++){                  for (int i = 1; i < argc; i++){        
# Line 284  int HandleInputPar(int argc, char **argv Line 302  int HandleInputPar(int argc, char **argv
302                  continue;                        continue;      
303              }              }
304              // -----------------------------------------------------//              // -----------------------------------------------------//
305                else if (!strcmp(argv[i], "-options")){
306                    if (++i >= argc) throw -1;
307                    OPTIONS = argv[i];
308                    if( OPTIONS.Contains("[") ){
309                        do{
310                            if (++i >= argc) throw -1;
311                            OPTIONS.Append(argv[i]);
312                        }while(!OPTIONS.Contains("]"));
313                    }else cout << "wrong option format --> ignoring " << endl;
314                }
315                // -----------------------------------------------------//
316              else if (!strcmp(argv[i], "--debug") || !strcmp(argv[i], "-g")){              else if (!strcmp(argv[i], "--debug") || !strcmp(argv[i], "-g")){
317                  DEBUG = true;                  DEBUG = true;
318                  continue;                        continue;      
# Line 312  int main(int argc, char **argv) Line 341  int main(int argc, char **argv)
341                    
342      if( HandleInputPar(argc,argv) )return(1);      if( HandleInputPar(argc,argv) )return(1);
343                    
344      Loop(DIR,LIST,MAXEV,"-ALL+TRK1+TRK2+CAL1+CAL2+TOF+AC fillHisto fillTree",OUTFILE);  //    Loop(DIR,LIST,MAXEV,"-ALL+TRK1+TRK2+CAL1+CAL2+TOF+AC",OUTFILE);
345        cout << "OPTIONS "<<OPTIONS<<endl;
346        Loop(DIR,LIST,MAXEV,OPTIONS,OUTFILE);
347            
348      cout << "Back to main - end"<<endl;      cout << "Back to main - end"<<endl;
349            

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

  ViewVC Help
Powered by ViewVC 1.1.23