/[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.4 by pam-fi, Mon Jan 15 11:51:39 2007 UTC revision 1.5 by pam-fi, Fri Feb 16 18:38:13 2007 UTC
# Line 30  TString   OUTFILE; Line 30  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 41  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 50  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->GetTrkLevel2()->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 86  bool Process(int iev){ Line 85  bool Process(int iev){
85            
86      if( !Select(event) )return false;      if( !Select(event) )return false;
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 98  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 169  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();  //    gObjectTable->Print();
177      tree->SetCacheSize(0);      tree->SetCacheSize(0);
# Line 200  Int_t Loop(TString ddir,TString list, UL Line 201  Int_t Loop(TString ddir,TString list, UL
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++;
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;
214              };              };
215          }else{          }else{
216              cout << "Chain entry "<<iev<<" -- ERROR --"<<endl;              cout << "Chain entry "<<iev<<" -- ERROR --"<<endl;
217          };          };
218          if( !(iev%5000) && DEBUG)gObjectTable->Print();          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;

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

  ViewVC Help
Powered by ViewVC 1.1.23