/[PAMELA software]/PamelaLevel2/src/PamLevel2.cpp
ViewVC logotype

Diff of /PamelaLevel2/src/PamLevel2.cpp

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

revision 1.9 by pam-fi, Tue Dec 5 12:13:39 2006 UTC revision 1.43 by pam-fi, Fri Aug 17 16:57:12 2007 UTC
# Line 7  Line 7 
7   * Default constructor   * Default constructor
8   */   */
9  PamTrack::PamTrack(){  PamTrack::PamTrack(){
10      trk_track  = this->TrkTrack::GetTrkTrack();      trk_track  = 0;
11      calo_track = this->CaloTrkVar::GetCaloTrkVar();      calo_track = 0;
12      tof_track  = this->ToFTrkVar::GetToFTrkVar();      tof_track  = 0;
13        candeleteobj = 0;
14  };  };
15  //--------------------------------------  //--------------------------------------
16  //  //
# Line 19  PamTrack::PamTrack(){ Line 20  PamTrack::PamTrack(){
20   * Constructor   * Constructor
21   */   */
22  PamTrack::PamTrack(TrkTrack* t, CaloTrkVar* c, ToFTrkVar* o){  PamTrack::PamTrack(TrkTrack* t, CaloTrkVar* c, ToFTrkVar* o){
23      trk_track  = this->TrkTrack::GetTrkTrack();  
24      calo_track = this->CaloTrkVar::GetCaloTrkVar();      trk_track  = 0;
25      tof_track  = this->ToFTrkVar::GetToFTrkVar();      calo_track = 0;
26      if(t) *trk_track  = *t;      tof_track  = 0;
27      if(c) *calo_track = *c;  //     if(t)trk_track  = new TrkTrack(*t);
28      if(o) *tof_track  = *o;      //     if(c)calo_track = new CaloTrkVar(*c);
29    //     if(o)tof_track  = new ToFTrkVar(*o);
30        if(t)trk_track  = t;
31        if(c)calo_track = c;
32        if(o)tof_track  = o;
33        candeleteobj = 0;
34    
35  };  };
36    PamTrack::PamTrack(const PamTrack& track){
37    
38        TrkTrack   *t = track.trk_track;
39        CaloTrkVar *c = track.calo_track;
40        ToFTrkVar  *o = track.tof_track;
41    
42        trk_track  = 0;
43        calo_track = 0;
44        tof_track  = 0;
45        if(t)trk_track  = new TrkTrack(*t);
46        if(c)calo_track = new CaloTrkVar(*c);
47        if(o)tof_track  = new ToFTrkVar(*o);
48        candeleteobj = 1;
49        
50    }
51    void PamTrack::Clear(){
52    
53    //    cout << "PamTrack::Clear() "<<candeleteobj<<endl;
54        if(candeleteobj){
55            if(trk_track)  trk_track->TrkTrack::Clear();
56            if(calo_track) calo_track->CaloTrkVar::Clear();//???
57            if(tof_track)  tof_track->ToFTrkVar::Clear();//???
58        }else{
59            trk_track  = 0;
60            calo_track = 0;
61            tof_track  = 0;
62        }
63    }
64    void PamTrack::Delete(){
65    //    cout << "PamTrack::Delete() "<<candeleteobj<<endl;
66        if(candeleteobj){
67            if(trk_track)  {
68                trk_track->TrkTrack::Clear();
69                delete trk_track;
70            }
71            if(calo_track){
72                calo_track->CaloTrkVar::Clear();//???
73                delete calo_track;
74            }
75            if(tof_track){
76                tof_track->ToFTrkVar::Clear();//???
77                delete tof_track;
78            }
79        }else{
80            Clear();
81        }
82    }
83  //--------------------------------------  //--------------------------------------
84  //  //
85  //  //
86  //--------------------------------------  //--------------------------------------
87  /**  /**
88   * Constructor   * Default Constructor
89   */   */
90  PamLevel2::PamLevel2(){  PamLevel2::PamLevel2(){
91      Initialize();
92    };
93    
94    /**
95     * Constructor with given dir, list and detectors
96     */
97    PamLevel2::PamLevel2(TString ddir,TString list,TString detlist){
98      Initialize();
99      GetPamTree(GetListOfLevel2Files(ddir,list),detlist);
100      GetRunTree(GetListOfLevel2Files(ddir,list));
101    };
102    
103    /**
104     * Constructor with given dir and list
105     */
106    PamLevel2::PamLevel2(TString ddir,TString list){
107      Initialize();
108      GetPamTree(GetListOfLevel2Files(ddir,list),"");
109      GetRunTree(GetListOfLevel2Files(ddir,list));
110    };
111    
112    
113    void PamLevel2::Initialize(){
114                    
115      trk2_obj  = TrkLevel2::GetTrkLevel2();      h0_obj    = 0;
116      trk1_obj  = TrkLevel1::GetTrkLevel1();      trk0_obj  = 0;
117      trkh_obj  = TrkHough::GetTrkHough();      calo0_obj  = 0;
118      calo1_obj = CaloLevel1::GetCaloLevel1();  
119      calo2_obj = CaloLevel2::GetCaloLevel2();      trk2_obj  = 0;
120      tof_obj   = ToFLevel2::GetToFLevel2();      trk1_obj  = 0;
121      trig_obj  = TrigLevel2::GetTrigLevel2();      trkh_obj  = 0;
122      s4_obj    = S4Level2::GetS4Level2();      calo1_obj = 0;
123      nd_obj    = NDLevel2::GetNDLevel2();      calo2_obj = 0;
124      ac_obj    = AcLevel2::GetAcLevel2();      tof_obj   = 0;
125      orb_obj   = OrbitalInfo::GetOrbitalInfo();      trig_obj  = 0;
126        s4_obj    = 0;
127      run_obj   = new GL_RUN();      nd_obj    = 0;
128            ac_obj    = 0;
129  //     trk1_clone  = 0;      orb_obj   = 0;
130  //     trk2_clone  = 0;  
131  //     trkh_clone  = 0;      run_obj   = 0;//new GL_RUN();
132  //     calo1_clone = 0;      soft_obj   = 0;// Emiliano
133  //     calo2_clone = 0;      irun = -1LL;
134  //     tof_clone   = 0;      runfirstentry = 0LL;
135  //     trig_clone  = 0;      runlastentry = 0LL;
136  //     s4_clone    = 0;  
137  //     nd_clone    = 0;      l0_file = NULL;
138  //     ac_clone    = 0;      l0_tree = NULL;
139  //     orb_clone   = 0;      iroot   = -1;
140        dbc     = 0;
141  //     T_clone  = 0;  
142  //     C_clone  = 0;      prevshift = 0;
143  //     O_clone  = 0;      
144  //     R_clone  = 0;      run_tree = NULL;
145  //     S_clone  = 0;      run_tree_clone = NULL;
146  //     N_clone  = 0;      sel_tree = NULL;
147  //     A_clone  = 0;      sel_tree_clone = NULL;
148  //     B_clone  = 0;      
149        irunentry = -1LL;
150        pam_tree = NULL;
151        for(Int_t i=0; i<NCLONES; i++ )pam_tree_clone[i]=NULL;
152    
153        host = "mysql://localhost/pamelaprod";
154        user = "anonymous";
155        psw = "";
156        const char *pamdbhost=gSystem->Getenv("PAM_DBHOST");
157        const char *pamdbuser=gSystem->Getenv("PAM_DBUSER");
158        const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW");
159        if ( !pamdbhost ) pamdbhost = "";
160        if ( !pamdbuser ) pamdbuser = "";
161        if ( !pamdbpsw ) pamdbpsw = "";
162        if ( strcmp(pamdbhost,"") ) host = pamdbhost;
163        if ( strcmp(pamdbuser,"") ) user = pamdbuser;
164        if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw;
165    
166      for(Int_t i=0; i<8; i++ )tree_clone[i]=NULL;      
167    
168      sorted_tracks = new TRefArray();  //    sorted_tracks = 0;//new TRefArray();
169            
170        CAL0 = false;
171      CAL1 = true;      CAL1 = true;
172      CAL2 = true;      CAL2 = true;
173      TRK2 = true;      TRK2 = true;
174      TRK1 = false;      TRK1 = false;
175      TRKh = false;      TRKh = false;
176      TRG = true;      TRKh = false;
177      TOF = true;      TRG  = true;
178      S4  = true;      TOF  = true;
179      ND  = true;      TOF0 = false;
180      AC  = true;      S4   = true;
181      ORB = true;      ND   = true;
182            AC   = true;
183        ORB  = true;
184        
185        RUN  = true;
186    
187        SELLI = -1;
188    
189        ISGP = false;
190    
191        tsorted=0;
192        timage=0;
193        
194        howtosort = "+CAL+TOF";
195        //howtosort = "+TOF";
196        sortthr = 100.;
197    
198  };  };
199  /**  /**
200   * Destructor   * Delete the event (act as Dtor)
201   */   */
202  PamLevel2::~PamLevel2(){                  void PamLevel2::Delete(){
203      delete run_obj;          
204      Clear();      if(run_obj)delete run_obj;
205        if(soft_obj)delete soft_obj; //Emiliano
206    
207    //    cout << "void PamLevel2::Clear()"<<endl;
208        if(h0_obj)   delete h0_obj;
209        if(trk0_obj) delete trk0_obj;      
210        if(calo0_obj) delete calo0_obj;    
211        if(trk1_obj) delete trk1_obj;      
212        if(trk2_obj) delete trk2_obj;
213        if(trkh_obj) delete trkh_obj;
214        if(calo1_obj)delete calo1_obj;
215        if(calo2_obj)delete calo2_obj;
216        if(tof_obj)  delete tof_obj;
217        if(trig_obj) delete trig_obj;
218        if(s4_obj)   delete s4_obj;
219        if(nd_obj)   delete nd_obj;
220        if(ac_obj)   delete ac_obj;
221        if(orb_obj)  delete orb_obj;
222        
223        if(tsorted){
224            tsorted->Delete();
225            delete tsorted;
226        }
227        if(timage){
228            timage->Delete();
229            delete timage;
230        }
231    
232        if(dbc){
233            dbc->Close();
234            delete dbc;
235        }
236        
237        if(l0_file)l0_file->Close();
238        //    if(pam_tree)pam_tree->Delete();;
239    
240      if ( pam_tree ){
241        //
242        // we have first to find which chains we have to delete, then delete the main chain and only after delete the friend chains. Any other order causes a segfault...
243        //
244        TList *temp = pam_tree->GetListOfFriends();
245        TList *contents  = new TList; // create chain friend list
246        contents->SetOwner();
247        TIter next(temp);
248        TChain *questo = 0;
249        while ( (questo = (TChain*) next()) ){
250          TString name =  questo->GetName();
251          contents->Add((TChain*)gROOT->FindObject(name.Data()));// add object to the list
252        };
253        //
254        // deleting the main chain
255        //
256        pam_tree->Delete();
257        //
258        // deleting the friends...
259        //
260        TIter next2(contents);
261        TChain *questa = 0;
262        while ( questa = (TChain*)next2() ){
263          TString name =  questa->GetName();
264          questa->Delete();      
265          questa=NULL;
266        };
267        //
268      };
269      pam_tree = NULL;
270    
271        if(run_tree)run_tree->Delete();;
272        if(sel_tree)sel_tree->Delete();;
273        for(Int_t i=0; i<NCLONES; i++ )if(pam_tree_clone[i])pam_tree_clone[i]->Delete();;
274        if(run_tree_clone)run_tree_clone->Delete();;
275        if(sel_tree_clone)sel_tree_clone->Delete();;
276        
277    
278  };  };
279    
280  /**  /**
281   * Clear the event   * Clear the event (NB! does not deallocate objects)
282   */   */
283  void PamLevel2::Clear(){  void PamLevel2::Clear(){
284                    
285      TrkLevel1::Clear();  //    cout << "void PamLevel2::Clear()"<<endl;
286            
287      TrkLevel2::Clear();  //
288      CaloLevel2::Clear();  // This method is called once for every entry but RunInfo and SoftInfo do not change until the next run so we cannot clear them here unless we don't
289      ToFLevel2::Clear();  // want to load them for each event even if they are the same...
290      TrigLevel2::Clear();  //
291      S4Level2::Clear();  //    if(run_obj)delete run_obj;
292      NDLevel2::Clear();  //    if(run_obj) run_obj->Clear();  // Emiliano: Do not deallocate run_obj here, it will give segmentation fault! call clear instead
293      AcLevel2::Clear();  //    if(soft_obj) soft_obj->Clear();
294      OrbitalInfo::Clear();  
295        if(h0_obj)   h0_obj->Clear();      
296  //     if(trk1_clone)trk1_clone->Clear();  //    if(trk0_obj) trk0_obj->Clear();  
297  //     if(trk2_clone)trk2_clone->Clear();      if(trk1_obj) trk1_obj->Clear();    
298  //     if(trkh_clone)trkh_clone->Clear();      if(trk2_obj) trk2_obj->Clear();
299  //     if(calo1_clone)calo1_clone->Clear();      if(trkh_obj) trkh_obj->Clear();
300  //     if(calo2_clone)calo2_clone->Clear();      if(calo0_obj) calo0_obj->Clear();  
301  //     if(tof_clone)tof_clone->Clear();      if(calo1_obj)calo1_obj->Clear();
302  //     if(trig_clone)trig_clone->Clear();      if(calo2_obj)calo2_obj->Clear();
303  //     if(s4_clone)s4_clone->Clear();      if(tof_obj)  tof_obj->Clear();
304  //     if(nd_clone)nd_clone->Clear();      if(trig_obj) trig_obj->Clear();
305  //     if(ac_clone)ac_clone->Clear();      if(s4_obj)   s4_obj->Clear();
306  //     if(orb_clone)orb_clone->Clear();      if(nd_obj)   nd_obj->Clear();
307            if(ac_obj)   ac_obj->Clear();
308      sorted_tracks->Delete(); // clean the reference array      if(orb_obj)  orb_obj->Clear();
309            
310    //    if(sorted_tracks)sorted_tracks->Clear();
311    //    sorted_tracks.Clear();
312    
313        if(tsorted){
314            tsorted->Delete();
315        }
316        if(timage){
317            timage->Delete();
318        }
319    };
320    
321    void PamLevel2::Reset(){
322      //
323      // First of all clear everything
324      //
325      Clear();
326      //
327      // close and reset chains and pointers
328      //    
329      if ( pam_tree ){
330        //
331        // we have first to find which chains we have to delete, then delete the main chain and only after delete the friend chains. Any other order causes a segfault...
332        //
333        TList *temp = pam_tree->GetListOfFriends();
334        TList *contents  = new TList; // create chain friend list
335        contents->SetOwner();
336        TIter next(temp);
337        TChain *questo = 0;
338        while ( (questo = (TChain*) next()) ){
339          TString name =  questo->GetName();
340          contents->Add((TChain*)gROOT->FindObject(name.Data()));// add object to the list
341        };
342        //
343        // deleting the main chain
344        //
345        pam_tree->Delete();
346        //
347        // deleting the friends...
348        //
349        TIter next2(contents);
350        TChain *questa = 0;
351        while ( questa = (TChain*)next2() ){
352          TString name =  questa->GetName();
353          questa->Delete();      
354          questa=NULL;
355        };
356        //
357      };
358      pam_tree = NULL;
359      //
360      if(run_tree)run_tree->Delete();;
361      run_tree = NULL;
362      if(sel_tree)sel_tree->Delete();;
363      sel_tree = NULL;
364      //
365      // Close file
366      //
367      if(l0_file)l0_file->Close("R");
368      l0_file = NULL;
369      //
370      h0_obj    = 0;
371      trk0_obj  = 0;
372      calo0_obj  = 0;
373      //
374      trk2_obj  = 0;
375      trk1_obj  = 0;
376      trkh_obj  = 0;
377      calo1_obj = 0;
378      calo2_obj = 0;
379      tof_obj   = 0;
380      trig_obj  = 0;
381      s4_obj    = 0;
382      nd_obj    = 0;
383      ac_obj    = 0;
384      orb_obj   = 0;
385      //
386      // Reset run pointers
387      //
388      run_obj   = 0;//new GL_RUN();
389      soft_obj   = 0;// Emiliano
390      irun = -1;
391      runfirstentry = 0ULL;
392      runlastentry = 0ULL;    
393      //
394  };  };
395    
396    Bool_t PamLevel2::IsGood(){
397      Bool_t goodev=true;
398      //  if(trk2_obj && trk2_obj->UnpackError() != 0 ) goodev = false;
399      if(calo2_obj && calo2_obj->good != 1) goodev = false;
400      if(tof_obj && tof_obj->unpackError != 0) goodev = false;  
401      if(trig_obj && trig_obj->unpackError != 0) goodev = false;
402      if(s4_obj && s4_obj->unpackError != 0) goodev = false;  
403      if(nd_obj && nd_obj->unpackError != 0) goodev = false;  
404      if(ac_obj && ac_obj->unpackError != 255) goodev = false;  
405        //  if(orb_obj)  
406      return goodev;
407    };
408    
409  //--------------------------------------  //--------------------------------------
410  //  //
# Line 136  void PamLevel2::Clear(){ Line 413  void PamLevel2::Clear(){
413  void *PamLevel2::GetPointerTo(const char* c ){  void *PamLevel2::GetPointerTo(const char* c ){
414    
415      TString objname = c;      TString objname = c;
416      if(!objname.CompareTo("TrkLevel1"))return &trk1_obj;  
417      if(!objname.CompareTo("TrkLevel2"))return &trk2_obj;      if(!objname.CompareTo("TrkLevel1"))  {
418      if(!objname.CompareTo("TrkHough"))return &trkh_obj;          if(!trk1_obj){
419      if(!objname.CompareTo("CaloLevel1"))return &calo1_obj;              trk1_obj  = new TrkLevel1();
420      if(!objname.CompareTo("CaloLevel2"))return &calo2_obj;              trk1_obj->Set();
421      if(!objname.CompareTo("ToFLevel2"))return &tof_obj;          }
422      if(!objname.CompareTo("TrigLevel2"))return &trig_obj;          return &trk1_obj;
423      if(!objname.CompareTo("S4Level2"))return &s4_obj;      };
424      if(!objname.CompareTo("NDLevel2"))return &nd_obj;      if(!objname.CompareTo("TrkLevel2"))  {
425      if(!objname.CompareTo("AcLevel2"))return &ac_obj;          if(!trk2_obj){  
426      if(!objname.CompareTo("OrbitalInfo"))return &orb_obj;              trk2_obj  = new TrkLevel2();
427                trk2_obj->Set();
428            }
429            return &trk2_obj;
430        };
431        if(!objname.CompareTo("TrkHough"))   {
432            if(!trkh_obj)  trkh_obj  = new TrkHough();
433            return &trkh_obj;
434        };
435        if(!objname.CompareTo("CaloLevel1")) {
436            if(!calo1_obj) calo1_obj = new CaloLevel1();
437            return &calo1_obj;
438        };
439        if(!objname.CompareTo("CaloLevel2")) {
440            if(!calo2_obj){
441                calo2_obj = new CaloLevel2();
442                calo2_obj->Set();
443            };
444            return &calo2_obj;
445        };
446        if(!objname.CompareTo("ToFLevel2"))  {
447            if(!tof_obj){
448                tof_obj   = new ToFLevel2();
449                tof_obj->Set();
450            }
451            return &tof_obj;
452        };
453        if(!objname.CompareTo("TrigLevel2")) {
454            if(!trig_obj)  trig_obj  = new TrigLevel2();
455            return &trig_obj;
456        };
457        if(!objname.CompareTo("S4Level2"))   {
458            if(!s4_obj)    s4_obj    = new S4Level2();
459            return &s4_obj;
460        };
461        if(!objname.CompareTo("NDLevel2"))   {
462            if(!nd_obj)    nd_obj    = new NDLevel2();
463            return &nd_obj;
464        };
465        if(!objname.CompareTo("AcLevel2"))   {
466            if(!ac_obj)    ac_obj    = new AcLevel2();
467            return &ac_obj;
468        };
469        if(!objname.CompareTo("OrbitalInfo")){
470            if(!orb_obj)   orb_obj   = new OrbitalInfo();
471            return &orb_obj;
472        };
473        
474      if(!objname.CompareTo("RunInfo"))return &run_obj;      if(!objname.CompareTo("RunInfo"))return &run_obj;
475    
476        if(!objname.CompareTo("SoftInfo"))return &soft_obj; // Emiliano
477    
478      return NULL;      return NULL;
479  };  };
480  //--------------------------------------  //--------------------------------------
# Line 159  void *PamLevel2::GetPointerTo(const char Line 486  void *PamLevel2::GetPointerTo(const char
486   * (If seqno = -1 retrieves the self-trigger calorimeter track)   * (If seqno = -1 retrieves the self-trigger calorimeter track)
487   */   */
488   CaloTrkVar *PamLevel2::GetCaloStoredTrack(int seqno){   CaloTrkVar *PamLevel2::GetCaloStoredTrack(int seqno){
489                
490       if( CaloLevel2::ntrk()==0 ){       if( !calo2_obj )return 0;
491    
492         if( calo2_obj->CaloLevel2::ntrk()==0 ){
493           cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no Calorimeter tracks are stored"<<endl;           cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no Calorimeter tracks are stored"<<endl;
494           return NULL;           return NULL;
495       };       };
# Line 169  void *PamLevel2::GetPointerTo(const char Line 498  void *PamLevel2::GetPointerTo(const char
498       Int_t it_calo=0;       Int_t it_calo=0;
499            
500       do{       do{
501           c = CaloLevel2::GetCaloTrkVar(it_calo);           c = calo2_obj->CaloLevel2::GetCaloTrkVar(it_calo);
502           it_calo++;           it_calo++;
503       } while( c && seqno != c->trkseqno && it_calo < CaloLevel2::ntrk());             } while( c && seqno != c->trkseqno && it_calo < calo2_obj->CaloLevel2::ntrk());    
504            
505       if(!c || seqno != c->trkseqno){       if(!c || seqno != c->trkseqno){
506           c = 0;           c = 0;
# Line 190  void *PamLevel2::GetPointerTo(const char Line 519  void *PamLevel2::GetPointerTo(const char
519   */   */
520   ToFTrkVar *PamLevel2::GetToFStoredTrack(int seqno){   ToFTrkVar *PamLevel2::GetToFStoredTrack(int seqno){
521                    
522       if( ToFLevel2::ntrk()==0 ){       if( !tof_obj )return 0;
523    
524         if( tof_obj->ToFLevel2::ntrk()==0 ){
525           cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no ToF tracks are stored"<<endl;           cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no ToF tracks are stored"<<endl;
526           return NULL;           return NULL;
527       };       };
# Line 199  void *PamLevel2::GetPointerTo(const char Line 530  void *PamLevel2::GetPointerTo(const char
530       Int_t it_tof=0;       Int_t it_tof=0;
531            
532       do{       do{
533           c = ToFLevel2::GetToFTrkVar(it_tof);           c = tof_obj->ToFLevel2::GetToFTrkVar(it_tof);
534           it_tof++;           it_tof++;
535       } while( c && seqno != c->trkseqno && it_tof < ToFLevel2::ntrk());       } while( c && seqno != c->trkseqno && it_tof < tof_obj->ToFLevel2::ntrk());        
536            
537       if(!c || seqno != c->trkseqno){       if(!c || seqno != c->trkseqno){
538           c = 0;           c = 0;
# Line 219  void *PamLevel2::GetPointerTo(const char Line 550  void *PamLevel2::GetPointerTo(const char
550   * Give the pamela track associated to a tracker track, retrieving related calorimeter and tof track information.   * Give the pamela track associated to a tracker track, retrieving related calorimeter and tof track information.
551   */   */
552   PamTrack* PamLevel2::GetPamTrackAlong(TrkTrack* t){   PamTrack* PamLevel2::GetPamTrackAlong(TrkTrack* t){
553                
554         cout <<"PamLevel2::GetPamTrackAlong(TrkTrack* t) **obsolete** "<<endl;
555         cout <<"(if you use it, remember to delete the PamTrack object)"<<endl;
556    
557       CaloTrkVar *c = 0;       CaloTrkVar *c = 0;
558       ToFTrkVar  *o = 0;       ToFTrkVar  *o = 0;
559            
# Line 244  void *PamLevel2::GetPointerTo(const char Line 578  void *PamLevel2::GetPointerTo(const char
578    
579  PamTrack* PamLevel2::GetStoredTrack(Int_t itrk){  PamTrack* PamLevel2::GetStoredTrack(Int_t itrk){
580            
581        cout <<"PamLevel2::GetStoredTrack(Int_t itrk) **to-be-updated** "<<endl;
582        cout <<"for the moment, better use separately the methods: TrkLevel2::GetStoredTrack(seqno) CaloLevel2::GetCaloTrkVar(Int_t notrack) ToFLevel2::GetToFTrkVar(Int_t notrack)"<<endl;
583        cout <<"(if you use it, remember to delete the PamTrack object)"<<endl;
584      PamTrack *track = 0;      PamTrack *track = 0;
585            
586      if( itrk >=0 && itrk < TrkLevel2::ntrk() ){      if( itrk >=0 && itrk < trk2_obj->TrkLevel2::ntrk() ){
587                    
588          TrkTrack *t = TrkLevel2::GetStoredTrack(itrk);          TrkTrack *t = trk2_obj->TrkLevel2::GetStoredTrack(itrk);
589          track = GetPamTrackAlong(t);          track = GetPamTrackAlong(t);
590                    
591            
592    
593      }else{      }else{
594          cout << "PamLevel2::GetStoredTrack(int) : tracker track SeqNo "<< itrk <<" does not exist (GetNTracks() = "<<TrkLevel2::GetNTracks()<<")"<<endl;          cout << "PamLevel2::GetStoredTrack(int) : tracker track SeqNo "<< itrk <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl;
595      };      };
596            
597      return track;      return track;
# Line 260  PamTrack* PamLevel2::GetStoredTrack(Int_ Line 599  PamTrack* PamLevel2::GetStoredTrack(Int_
599  }  }
600  //--------------------------------------  //--------------------------------------
601  //  //
602    
603    /**
604     * Sort physical (tracker) tracks and stores them in the TRefArray (of TrkTrack objects) which pointer is  PamLevel2::sorted_tracks. Left here as backward compatibility method.
605     **/
606    void PamLevel2::SortTracks(TString how){
607      printf(" WARNING! obsolete, use SortTracks() and SetSortingMethod(TString) instead! \n Setting sorting method to %s \n",how.Data());
608      howtosort = how;  
609      SortTracks();
610    };
611    
612  //  //
613  //--------------------------------------  //--------------------------------------
614  /**  /**
# Line 273  PamTrack* PamLevel2::GetStoredTrack(Int_ Line 622  PamTrack* PamLevel2::GetStoredTrack(Int_
622   *   *
623   * The total number of physical tracks is always given by GetNTracks() and the it-th physical track can be retrieved by means of the methods GetTrack(int it) and GetTrack(int it, TString how).   * The total number of physical tracks is always given by GetNTracks() and the it-th physical track can be retrieved by means of the methods GetTrack(int it) and GetTrack(int it, TString how).
624   */   */
625  void PamLevel2::SortTracks(TString how){  void PamLevel2::SortTracks(){
626      TString how = howtosort;
627    
628  //    cout << "call SortTracs() "<<endl;    //    cout <<" PamLevel2::SortTracks(TString how) "<<endl;
629      if( !trk2_obj ){
630        cout << "void PamLevel2::SortTracks():  TrkLevel2 not loaded !!!";
631        return;
632      };
633      //    cout << "call SortTracs() "<<endl;
634    //Save current Object count    //Save current Object count
635      Int_t ObjectNumber = TProcessID::GetObjectCount();    Int_t ObjectNumber = TProcessID::GetObjectCount();
636    
637      //    cout << "ObjectNumber  "<<ObjectNumber <<endl;
638    
639      //     if(!sorted_tracks)sorted_tracks = new TRefArray();
640      //     sorted_tracks->Clear();
641      //    sorted_tracks.Clear();
642    
643      if(!tsorted)tsorted = new TClonesArray("PamTrack",trk2_obj->GetNTracks());
644      tsorted->Delete();
645      TClonesArray &ttsorted = *tsorted;
646      if(!timage)timage = new TClonesArray("PamTrack",trk2_obj->GetNTracks());
647      timage->Delete();
648      TClonesArray &ttimage = *timage;
649    
 //    cout << "ObjectNumber  "<<ObjectNumber <<endl;  
       
     sorted_tracks->Delete(); //temporaneo???  
           
     // loop over the tracks sorted by the tracker  
     Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);  
     Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);  
     Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase);  
       
     if( !CAL2 &&  use_CAL) use_CAL = false;  
     if( !TOF &&  use_TOF) use_TOF = false;  
       
     if( !TRK2 ){  
 //      cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl;  
         return;  
     };  
650    
     //   cout << "use_CAL "<<use_CAL<<" use_TOF "<<use_TOF<<" use_TRK "<<use_TRK <<endl;  
       
     for(Int_t i=0; i < TrkLevel2::GetNTracks(); i++){  
           
         TrkTrack *ts = 0;  
           
         // get tracker tracks  
         TrkTrack   *tp = TrkLevel2::GetTrack(i);                    //tracker  
         CaloTrkVar *cp = 0;  
         ToFTrkVar  *op = 0;  
651    
652  //      cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;    //--------------------------------------------------
653          // if track has an image, check image selection    // retrieve sorting method
654          if(tp->HasImage()){    //--------------------------------------------------
655      Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);
656      Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);
657      Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase);
658        
659      if( !CAL2 &&  use_CAL) use_CAL = false;
660      if( !TOF &&  use_TOF) use_TOF = false;
661        
662      if( !TRK2 ){
663        //  cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl;
664        return;
665      };
666    
667      //   cout << "use_CAL "<<use_CAL<<" use_TOF "<<use_TOF<<" use_TRK "<<use_TRK <<endl;
668      
669    
670      //--------------------------------------------------
671      // loop over "physical" tracks sorted by the tracker
672      //--------------------------------------------------
673      for(Int_t i=0; i < trk2_obj->TrkLevel2::GetNTracks(); i++){
674            
675        TrkTrack   *ts = 0;
676        CaloTrkVar *cs = 0;
677        ToFTrkVar  *os = 0;
678            
679        // get tracker tracks
680        TrkTrack   *tp = trk2_obj->TrkLevel2::GetTrack(i); //tracker
681        CaloTrkVar *cp = GetCaloStoredTrack(tp->GetSeqNo());
682        ToFTrkVar  *op = GetToFStoredTrack(tp->GetSeqNo());
683    
684        TrkTrack   *ti = 0; //tracker (image)
685        CaloTrkVar *ci = 0;
686        ToFTrkVar  *oi = 0;
687        //  cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;
688        // if track has an image, check image selection
689        if(tp->HasImage()){
690                            
691              TrkTrack   *ti = TrkLevel2::GetTrackImage(i);              //tracker (image)        ti = trk2_obj->TrkLevel2::GetTrackImage(i);              //tracker (image)
692              CaloTrkVar *ci = 0;        ci = GetCaloStoredTrack(ti->GetSeqNo());
693              ToFTrkVar  *oi = 0;        oi = GetToFStoredTrack(ti->GetSeqNo());
694                            
695  //          cout << "its image "<<i << " "<<hex<< ti <<dec<< endl;        //            cout << "its image "<<i << " "<<hex<< ti <<dec<< endl;
696    
697              //assign starting scores        //assign starting scores
698              Int_t tp_score = 0;  //main track sorted by the tracker        Int_t tp_score = 0;  //main track sorted by the tracker
699              Int_t ti_score = 0;  //image track        Int_t ti_score = 0;  //image track
700                            
701              // ------------------------        // -----------------------------------------------------------------------------------------
702              // calorimeter check        // calorimeter check
703              // ------------------------        // -----------------------------------------------------------------------------------------
704              // check the Y spatial residual on the first calorimeter plane        // check the Y spatial residual on the first calorimeter plane
705              // (cut on calorimeter variables from Emiliano)        // (cut on calorimeter variables from Emiliano)
706              if(        if( use_CAL && !calo2_obj ){
707                  use_CAL            &&          cout << "void PamLevel2::SortTracks(): howtosort= "<<how<<" but CaloLevel2 not loaded !!!";
708                  npcfit[1] > 15     &&   //no. of fit planes on Y view          return;
709                  varcfit[1] < 1000. &&  //fit variance on Y view        };
710                  true){        if(
711             use_CAL            &&
712    //       calo2_obj->npcfit[1] > 5     &&   //no. of fit planes on Y view
713    //       calo2_obj->varcfit[1] < 1000. &&  //fit variance on Y view
714             cp && ci &&
715             true){
716    
                 cp = GetCaloStoredTrack(tp->GetSeqNo());  
                 ci = GetCaloStoredTrack(ti->GetSeqNo());  
717                                    
718                  Float_t resy_p = cp->tbar[0][1] - cbar[0][1]; if(resy_p < 0)resy_p= - resy_p;  //      Float_t resy_p = cp->tbar[0][1] - calo2_obj->cbar[0][1]; if(resy_p < 0)resy_p= - resy_p;
719                  Float_t resy_i = ci->tbar[0][1] - cbar[0][1]; if(resy_i < 0)resy_i= - resy_i;  //      Float_t resy_i = ci->tbar[0][1] - calo2_obj->cbar[0][1]; if(resy_i < 0)resy_i= - resy_i;
720                    
721    //      if(resy_p <= resy_i) tp_score++;
722    //      else                 ti_score++;
723            
724    
725              if( cp->npresh > ci->npresh) tp_score++;
726              if( cp->npresh < ci->npresh) ti_score++;
727              else ;//niente
728    
729            //      cout << "CALO "<<tp_score<<ti_score<<endl;
730    
731          };
732          // -----------------------------------------------------------------------------------------
733          // TOF check
734          // -----------------------------------------------------------------------------------------
735          // check the number of hit pmts along the track
736          // on S12 S21 and S32, where paddles are parallel to Y axis
737          if( use_TOF && !tof_obj ){
738            cout << "void PamLevel2::SortTracks(): howtosort= "<<how<<" but ToFLevel2 not loaded !!!";
739            return;
740          };
741          if( use_TOF && op && oi ){
742                                    
743                  if(resy_p <= resy_i) tp_score++;          //
744                  else                 ti_score++;          Float_t sen = 0.;
745            for (Int_t ih=0; ih < op->npmtadc; ih++){
746              Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
747              if ( pl == 2 || pl == 3 || pl == 4 || pl == 5 ) sen += (op->dedx).At(ih);
748            };
749            for (Int_t ih=0; ih < oi->npmtadc; ih++){
750              Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
751              if ( pl == 2 || pl == 3 || pl == 4 || pl == 5 ) sen += (oi->dedx).At(ih);
752            };
753            //
754            if (  sen >= sortthr ){
755              //printf(" IS A NUCLEUS! en = %f \n",sen);
756              //
757              // is a nucleus use a different algorithm
758              //
759              Int_t nz = 6; Float_t zin[6];                                          // << define TOF z-coordinates
760              for(Int_t ip=0; ip<nz; ip++)
761                zin[ip] = tof_obj->ToFLevel2::GetZTOF(tof_obj->ToFLevel2::GetToFPlaneID(ip));     // << read ToF plane z-coordinates
762              Trajectory *tr = new Trajectory(nz,zin);
763              //
764              Int_t nphit_p =0;
765              Int_t nphit_i =0;
766              Float_t enhit_p = 0.;
767              Float_t enhit_i = 0.;
768              //
769              for (Int_t ih=0; ih < op->npmtadc; ih++){
770                Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
771                if(pl == 1 || pl == 2 || pl == 5){
772                  nphit_p++;
773                  enhit_p += (op->dedx).At(ih);
774                };
775              };
776              //
777              tp->DoTrack2(tr);
778              //
779              if ( fabs(tr->y[0]-oi->ytofpos[0]) < 2. ){
780                for (Int_t ih=0; ih < op->npmtadc; ih++){
781                  Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
782                  if(pl == 0){
783                    nphit_p++;
784                    enhit_p += (op->dedx).At(ih);
785                  };
786                };
787              };
788              if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){
789                for (Int_t ih=0; ih < op->npmtadc; ih++){
790                  Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
791                  if(pl == 3){
792                    nphit_p++;
793                    enhit_p += (op->dedx).At(ih);
794                  };
795                };
796              };
797              if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){
798                for (Int_t ih=0; ih < op->npmtadc; ih++){
799                  Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
800                  if(pl == 4){
801                    nphit_p++;
802                    enhit_p += (op->dedx).At(ih);
803                  };
804                };
805              };
806    
807  //              cout << "CALO "<<tp_score<<ti_score<<endl;            for (Int_t ih=0; ih < oi->npmtadc; ih++){
808                Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
809                if(pl == 1 || pl == 2 || pl == 5){
810                  nphit_i++;        
811                  enhit_i += (op->dedx).At(ih);
812                };
813              };
814              //
815              ti->DoTrack2(tr);
816              //
817              if ( fabs(tr->y[0]-oi->ytofpos[0]) < 2. ){
818                for (Int_t ih=0; ih < oi->npmtadc; ih++){
819                  Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
820                  if(pl == 0){
821                    nphit_i++;
822                    enhit_i += (op->dedx).At(ih);
823                  };
824                };
825              };
826              if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){
827                for (Int_t ih=0; ih < oi->npmtadc; ih++){
828                  Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
829                  if(pl == 3){
830                    nphit_i++;
831                    enhit_i += (op->dedx).At(ih);
832                  };
833                };
834              };
835              if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){
836                for (Int_t ih=0; ih < oi->npmtadc; ih++){
837                  Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
838                  if(pl == 4){
839                    nphit_i++;
840                    enhit_i += (op->dedx).At(ih);
841                  };
842                };
843              };            
844    
845                    
846              if(
847                 use_TOF            &&
848                 (nphit_p+nphit_i) !=0 &&  
849                 true){
850                        
851                //      printf(" seqno %i nphit_p %i nphit_i %i enhit_p %f enhit_i %f \n",trk2_obj->TrkLevel2::GetSeqNo(i),nphit_p,nphit_i,enhit_p,enhit_i);
852                //      printf(" score p %i score i %i \n",tp_score,ti_score);
853                //            if( enhit_p > enhit_i ) tp_score++;
854                //            if( nphit_p >= nphit_i && enhit_p > enhit_i ) tp_score++;
855                if ( nphit_p > nphit_i ) tp_score++;
856                if ( nphit_p < nphit_i ) ti_score++;
857                if ( nphit_p == nphit_i ){
858                  if ( enhit_p > enhit_i ) tp_score++;
859                  else ti_score++;
860              };              };
861              // ------------------------              //      printf(" dopo score p %i score i %i \n",tp_score,ti_score);
862              // TOF check            };
863              // ------------------------                delete tr;
864              // check the number of hit pmts along the track            //
865              // on S12 S21 and S32, where paddles are parallel to Y axis          } else {
866              if( use_TOF ){            //
867              // NOT a NUCLEUS
868              //
869              //printf(" NOT a NUCLEUS! en = %f \n",sen);
870    
871              Int_t nphit_p =0;
872              Int_t nphit_i =0;
873                                    
                 Int_t nphit_p =0;  
                 Int_t nphit_i =0;  
874                                    
875                  op = GetToFStoredTrack(tp->GetSeqNo());            /*                            cout << "track: npmtadc "<< op->npmtadc << endl;
876                  oi = GetToFStoredTrack(ti->GetSeqNo());              cout << "track: npmttdc "<< op->npmttdc << endl;
877                cout << "image: npmtadc "<< oi->npmtadc << endl;
878                cout << "image: npmttdc "<< oi->npmttdc << endl;*/
879                                    
880  /*                              cout << "track: npmtadc "<< op->npmtadc << endl;  //        for (Int_t ih=0; ih < op->npmtadc; ih++){
881                                  cout << "track: npmttdc "<< op->npmttdc << endl;  //          Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
882                                  cout << "image: npmtadc "<< oi->npmtadc << endl;  //          if(pl == 1 || pl == 2 || pl == 5)nphit_p++;
883                                  cout << "image: npmttdc "<< oi->npmttdc << endl;*/  //        };
884                                    
885                  for (Int_t ih=0; ih < op->npmtadc; ih++){  //        for (Int_t ih=0; ih < oi->npmtadc; ih++){
886                      Int_t pl = GetPlaneIndex( (op->pmtadc).At(ih) );  //          Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
887                      if(pl == 1 || pl == 2 || pl == 5)nphit_p++;  //          if(pl == 1 || pl == 2 || pl == 5)nphit_i++;
888                  };  //        };
889              // --- modified to count tdc signals (more efficient?)
890              // --- and to implement check on tdcflag
891              for (Int_t ih=0; ih < op->npmttdc; ih++){
892                Int_t pl = tof_obj->GetPlaneIndex( (op->pmttdc).At(ih) );
893    //          if( (op->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_p++;
894                if( (op->tdcflag).At(ih)==0 )nphit_p++;
895              };
896                                    
897                  for (Int_t ih=0; ih < oi->npmtadc; ih++){            for (Int_t ih=0; ih < oi->npmttdc; ih++){
898                      Int_t pl = GetPlaneIndex( (oi->pmtadc).At(ih) );              Int_t pl = tof_obj->GetPlaneIndex( (oi->pmttdc).At(ih) );
899                      if(pl == 1 || pl == 2 || pl == 5)nphit_i++;  //          if( (oi->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_i++;  
900                  };              if( (oi->tdcflag).At(ih)==0 )nphit_i++;    
901              };
902                                    
903                  if(            if(
904                      use_TOF            &&               (nphit_p+nphit_i) !=0 &&  
905                      (nphit_p+nphit_i) !=0 &&                   true){
                     true){  
906                                            
907                      if( nphit_p >= nphit_i) tp_score++;              if     ( nphit_p > nphit_i) tp_score++;
908                      else ti_score++;              else if( nphit_p < nphit_i) ti_score++;
909                  };              else ;//niente
910  //              cout << "TOF "<<tp_score<<ti_score<<endl;            };
911              };          };
912              if(tp_score == ti_score) use_TRK = true;          //      cout << "TOF "<<tp_score<<ti_score<<endl;
913              // ------------------------        };
914              // tracker check  
915              // ------------------------  
916              // chi**2 difference is not always large enough to distinguish among  //      if(tp_score == ti_score) use_TRK = true;
917              // the real track and its image.  
918              // Tracker check will be applied always when calorimeter and tof information is ambiguous.  
919              if(use_TRK){        // -----------------------------------------------------------------------------------------
920                  if(      tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ;        // tracker check
921                  else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ;        // -----------------------------------------------------------------------------------------
922  //              cout << "TRK "<<tp_score<<ti_score<<endl;        // chi**2 difference is not always large enough to distinguish among
923              };        // the real track and its image.
924          // Tracker check will be applied always when calorimeter and tof information is ambiguous.
925          // *** MODIFIED ON AUGUST 2007 ***
926          if(use_TRK){
927    //      if(      tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ;
928    //      else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ;
929    
930              // CHECK 1 : number of points along X  
931              if ( tp->GetNX() >= ti->GetNX() )tp_score++ ;
932              if ( tp->GetNX() <= ti->GetNX() )ti_score++ ;
933              // CHECK 2 : number of points along Y  
934              if ( tp->GetNY() >= ti->GetNY() )tp_score++ ;
935              if ( tp->GetNY() <= ti->GetNY() )ti_score++ ;
936              // CHECK 3 : chi**2 along X  
937    //        if(      tp->GetChi2X() > 0 && (tp->GetChi2X() < ti->GetChi2X() || ti->GetChi2X() <=0) ) tp_score++ ;
938    //        if(      ti->GetChi2X() > 0 && (ti->GetChi2X() < tp->GetChi2X() || tp->GetChi2X() <=0) ) ti_score++ ;
939              // CHECK 4 : chi**2 along Y  
940    //        if(      tp->GetChi2Y() > 0 && (tp->GetChi2Y() < ti->GetChi2Y() || ti->GetChi2Y() <=0) ) tp_score++ ;
941    //        if(      ti->GetChi2Y() > 0 && (ti->GetChi2Y() < tp->GetChi2Y() || tp->GetChi2Y() <=0) ) ti_score++ ;
942              // CHECK 5 : total chi**2  
943    //        if(      tp->chi2 > 0 && (tp->chi2 < ti->chi2 || ti->chi2 <=0) ) tp_score++ ;
944    //        if(      ti->chi2 > 0 && (ti->chi2 < tp->chi2 || tp->chi2 <=0) ) ti_score++ ;
945    
946            //      cout << "TRK "<<tp_score<<ti_score<<endl;
947          };
948                            
949              // ------------------------  
950              // the winner is....  
951              // ------------------------            // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
952              if      (tp_score > ti_score) ts = tp;//the track sorted by the tracker!!        // the winner is....
953              else if (tp_score < ti_score) ts = ti;//its image!!        // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
954              else {        if      (tp_score > ti_score) {
955                  ts = tp;          
956  //                              cout << "Warning - track image ambiguity not solved" << endl;  
957  //                              cout << ts->GetNtot() << " "<< ts->chi2 << " " << npcfit[1] << " "<< nphit_p << endl;        }else if (tp_score < ti_score) {
958              };  
959    
960            ts = ti;//its image!!
961            cs = ci;
962            os = oi;
963    
964            ti = tp;//its image!!
965            ci = cp;
966            oi = op;
967    
968            tp = ts;//its image!!
969            cp = cs;
970            op = os;
971    
972                    
973          }else {
974    
975    //      cout << "Warning - track image ambiguity not solved" << endl;
976    
977          };
978                            
979          }else{      }else{
980              ts = tp;        //            ts = tp;
981          };        //            cs = cp;
982                  //            os = op;
983  //      cout <<" SortTracks() "<<i<<" -- "<<ts<<endl;      };
984          sorted_tracks->Add(ts);//save the track in the sorted array          
985  //      cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl;      //  cout <<" SortTracks() "<<i<<" -- "<<ts<<endl;
986                //  sorted_tracks->Add(ts);//save the track in the sorted array
987      };      //  sorted_tracks.Add(ts);//save the track in the sorted array
988      //Restore Object count      //  sorted_tracks.Add(tp);//save the track in the sorted array
989      //To save space in the table keeping track of all referenced objects      //  cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl;
990      //we assume that our events do not address each other. We reset the      //  cout<<"o "<<tp<<endl;
991      //object count to what it was at the beginning of the event.      //  cout<<"o "<<cp<<endl;
992      TProcessID::SetObjectCount(ObjectNumber);      //  cout<<"o "<<op<<endl;
993        new(ttsorted[i]) PamTrack(tp,cp,op);
994        new(ttimage[i])  PamTrack(ti,ci,oi);
995      };
996    
997      if( tsorted->GetEntries() != trk2_obj->GetNTracks() ){
998        cout << "void PamLevel2::SortTracks(): tsorted->GetEntries() "<<tsorted->GetEntries()<<" != trk2_obj->GetNTracks() = "<<trk2_obj->GetNTracks() <<endl;
999        tsorted->Delete(); tsorted=0;
1000        timage->Delete(); timage=0;
1001      }
1002    
1003      //Restore Object count
1004      //To save space in the table keeping track of all referenced objects
1005      //We reset the object count to what it was at the beginning of the event.
1006      TProcessID::SetObjectCount(ObjectNumber);
1007            
1008  };  };
1009  //--------------------------------------  //--------------------------------------
# Line 430  void PamLevel2::SortTracks(TString how){ Line 1014  void PamLevel2::SortTracks(TString how){
1014   * This method overrides TrkLevel2::GetTracks(), where sorting is done by decreasing number of fit points and increasing chi^2.   * This method overrides TrkLevel2::GetTracks(), where sorting is done by decreasing number of fit points and increasing chi^2.
1015   * PamLevel2::GetTracks() keeps the same track order given by TrkLevel2::GetTracks(), but checks image selection by using calorimeter and ToF tracking information.   * PamLevel2::GetTracks() keeps the same track order given by TrkLevel2::GetTracks(), but checks image selection by using calorimeter and ToF tracking information.
1016   */   */
1017  TRefArray *PamLevel2::GetTracks(){  // TRefArray *PamLevel2::GetTracks(){
1018    
1019    // //  *-*-*-*-*-*-*-*-*-*-*-*-*
1020    //     SortTracks("+CAL+TOF");
1021    // //  *-*-*-*-*-*-*-*-*-*-*-*-*
1022    
1023    // //   return  sorted_tracks;
1024    //     return &sorted_tracks;
1025        
1026    //  };
1027    TClonesArray *PamLevel2::GetTracks(){
1028    
1029  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
1030      SortTracks("+CAL+TOF");      SortTracks();
1031  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
1032    
1033      return sorted_tracks;      return tsorted;
1034        
1035   };   };
1036  //--------------------------------------  //--------------------------------------
1037   //   //
# Line 448  TRefArray *PamLevel2::GetTracks(){ Line 1043  TRefArray *PamLevel2::GetTracks(){
1043   * @param it Track number, ranging from 0 to GetNTracks().   * @param it Track number, ranging from 0 to GetNTracks().
1044   */   */
1045  PamTrack *PamLevel2::GetTrack(int it){  PamTrack *PamLevel2::GetTrack(int it){
1046    
1047    //    if(!trk2_obj) return 0;
1048                    
1049    // //  *-*-*-*+-*-*-*-*-*-*-*-*-*
1050    //     SortTracks("+CAL+TOF");
1051    // //  *-*-*-*-*-*-*-*-*-*-*-*-*
1052    // //    if(!sorted_tracks)return 0;
1053    //     if(sorted_tracks.IsEmpty())return 0;
1054    
1055    //     PamTrack *track = 0;
1056        
1057    //     if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks() && it<sorted_tracks.GetEntriesFast() ){    
1058    //      TrkTrack   *t = (TrkTrack*)sorted_tracks.At(it);
1059    //      track = GetPamTrackAlong(t);
1060    //     }else{
1061    //      cout << "PamLevel2::GetTrack(int) : tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl;
1062    //     };
1063        
1064    //     return track;
1065    
1066    //    cout << "PamLevel2::GetTrack(int it) "<<endl;
1067  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
1068      SortTracks("+CAL+TOF");      SortTracks();
1069  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
1070            if(!tsorted)return 0;
1071        if(!tsorted->GetEntries())return 0;
1072    
1073      PamTrack *track = 0;      PamTrack *track = 0;
1074            
1075      if( it >=0 && it < TrkLevel2::GetNTracks() && it<sorted_tracks->GetEntriesFast() ){      if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks()){
1076          TrkTrack   *t = (TrkTrack*)sorted_tracks->At(it);  //      TrkTrack   *t = (TrkTrack*)sorted_tracks.At(it);
1077          track = GetPamTrackAlong(t);  //      track = GetPamTrackAlong(t);
1078            TClonesArray &t = *(tsorted);
1079            track = (PamTrack*)t[it];
1080            
1081      }else{      }else{
1082          cout << "PamLevel2::GetTrack(int) : tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<TrkLevel2::GetNTracks()<<")"<<endl;          cout << "PamLevel2::GetTrack(int) : tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl;
1083      };      };
1084            
1085      return track;      return track;
# Line 476  PamTrack *PamLevel2::GetTrack(int it){ Line 1096  PamTrack *PamLevel2::GetTrack(int it){
1096   */   */
1097  PamTrack *PamLevel2::GetTrackImage(int it){  PamTrack *PamLevel2::GetTrackImage(int it){
1098    
1099    //     if(!trk2_obj) return 0;
1100    
1101    // //  *-*-*-*-*-*-*-*-*-*-*-*-*
1102    //     SortTracks("+CAL+TOF");
1103    // //  *-*-*-*-*-*-*-*-*-*-*-*-*
1104    // //    if(!sorted_tracks)return 0;
1105    //     if(sorted_tracks.IsEmpty())return 0;
1106        
1107    //     PamTrack *image = 0;
1108        
1109    //     if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks() ){
1110    //      TrkTrack *temp = (TrkTrack*)sorted_tracks.At(it);
1111    //      if( temp->HasImage() ){
1112    //          TrkTrack   *t = trk2_obj->TrkLevel2::GetStoredTrack(temp->GetImageSeqNo());
1113    //          image = GetPamTrackAlong(t);
1114    //      }else{
1115    //          cout <<"PamLevel2::GetTrackImage(int) : Track SeqNo "<<it<<" does not have image"<<endl;
1116    //      };
1117    //     }else{
1118    //      cout << "PamLevel2::GetTrackImage(int) : Tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl;
1119    //     };
1120        
1121    //     return image;
1122    
1123    
1124  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
1125      SortTracks("+CAL+TOF");      SortTracks();
1126  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
1127        if(!timage)return 0;
1128        if(!timage->GetEntries())return 0;
1129            
1130      PamTrack *image = 0;      PamTrack *image = 0;
1131            
1132      if( it >=0 && it < TrkLevel2::GetNTracks() ){      if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks() ){
1133          TrkTrack *temp = (TrkTrack*)sorted_tracks->At(it);          TClonesArray &t = *(tsorted);
1134          if( temp->HasImage() ){          PamTrack *temp = (PamTrack*)t[it];
1135              TrkTrack   *t = TrkLevel2::GetStoredTrack(temp->GetImageSeqNo());          if( temp->GetTrkTrack()->HasImage() ){
1136              image = GetPamTrackAlong(t);              TClonesArray &t = *(timage);
1137                image = (PamTrack*)t[it];
1138          }else{          }else{
1139              cout <<"PamLevel2::GetTrackImage(int) : Track SeqNo "<<it<<" does not have image"<<endl;  //          cout <<"PamLevel2::GetTrackImage(int) : Track SeqNo "<<it<<" does not have image"<<endl;
1140          };          };
1141      }else{      }else{
1142          cout << "PamLevel2::GetTrackImage(int) : Tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<TrkLevel2::GetNTracks()<<")"<<endl;          cout << "PamLevel2::GetTrackImage(int) : Tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl;
1143      };      };
1144            
1145      return image;      return image;
# Line 507  PamTrack *PamLevel2::GetTrackImage(int i Line 1155  PamTrack *PamLevel2::GetTrackImage(int i
1155   * @param detlist String to select trees to be included   * @param detlist String to select trees to be included
1156   * @return Pointer to a TTree   * @return Pointer to a TTree
1157   */   */
1158  TTree *PamLevel2::GetPamTree(TFile *f, TString detlist="+ALL"){  TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ){
1159    
1160    //     if( !detlist.IsNull() ) SetWhichTrees(detlist);
1161    //     else                    GetWhichTrees(f);
1162      if ( pam_tree ){
1163        printf("WARNING: TTree *PamLevel2::GetPamTree(TFile *fl, TString detlist) -- pam_tree already exists!\n ");
1164        return pam_tree;
1165      };
1166      //
1167    
1168  //      cout << "WARNING!!! -- obsolete method -- \n";      cout << "TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ) -- obsolte "<<endl;
 //      cout << "better use TChain *PamLevel2::GetPamTree(TList*, TString) \n";  
1169    
1170      SetWhichTrees(detlist);      SetWhichTrees(detlist);
     TTree *Trout =0;  
1171    
1172        TTree *Trout =0;
1173    
1174      TString fname = f->GetName();      TString fname = f->GetName();
1175      if(!CheckLevel2File(fname))return NULL;      if(!CheckLevel2File(fname))return NULL;
1176    
1177        //    UInt_t *found=0;    
1178    
1179        cout<< "GetPamTree(TFile*,TString): detector list --> ";
1180        if(TRK1)cout<<"TRK1 ";
1181        if(TRK2)cout<<"TRK2 ";
1182        if(TRKh)cout<<"TRKH ";
1183        if(CAL1)cout<<"CAL1 ";
1184        if(CAL2)cout<<"CAL2 ";
1185        if(TOF)cout<<"TOF ";
1186        if(TRG)cout<<"TRG ";
1187        if(AC)cout<<"AC ";
1188        if(ND)cout<<"ND ";
1189        if(S4)cout<<"S4 ";
1190        if(ORB)cout<<"ORB ";
1191        cout << endl;
1192        if(SELLI)cout<<">>> Found selection-list <<<"<<endl;
1193    
1194        f->cd();
1195    
1196  // Tracker  // Tracker
1197      TTree *T = (TTree*)f->Get("Tracker");      TTree *T = (TTree*)f->Get("Tracker");
1198      if(T && (TRK2||TRK1||TRKh)) {      if(T && (TRK2||TRK1||TRKh)) {
1199          if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));          if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
1200    //      else    T->SetBranchStatus("TrkLevel2",0,found);
1201          if(TRK2)cout << "Tracker      : set branch address TrkLevel2"<<endl;          if(TRK2)cout << "Tracker      : set branch address TrkLevel2"<<endl;
1202          if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));          if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
1203    //      else    T->SetBranchStatus("TrkLevel1",0,found);
1204          if(TRK1)cout << "Tracker      : set branch address TrkLevel1"<<endl;          if(TRK1)cout << "Tracker      : set branch address TrkLevel1"<<endl;
1205          if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));          if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
1206    //      else    T->SetBranchStatus("TrkHough",0,found);
1207          if(TRKh)cout << "Tracker      : set branch address TrkHough"<<endl;          if(TRKh)cout << "Tracker      : set branch address TrkHough"<<endl;
1208          if(!Trout)Trout=T;          if(!Trout)Trout=T;
1209          else Trout->AddFriend(T);          else Trout->AddFriend(T);
# Line 538  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1214  TTree *PamLevel2::GetPamTree(TFile *f, T
1214      TTree *C = (TTree*)f->Get("Calorimeter");      TTree *C = (TTree*)f->Get("Calorimeter");
1215      if(C && (CAL2||CAL1)) {      if(C && (CAL2||CAL1)) {
1216          if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));          if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
1217    //      else    C->SetBranchStatus("CaloLevel2",0,found);
1218          if(CAL2)cout << "Calorimeter  : set branch address CaloLevel2"<<endl;          if(CAL2)cout << "Calorimeter  : set branch address CaloLevel2"<<endl;
1219          if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));          if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
1220    //      else    C->SetBranchStatus("CaloLevel1",0,found);
1221          if(CAL1)cout << "Calorimeter  : set branch address CaloLevel1"<<endl;          if(CAL1)cout << "Calorimeter  : set branch address CaloLevel1"<<endl;
1222          if(!Trout)Trout=C;          if(!Trout)Trout=C;
1223          else Trout->AddFriend(C);          else Trout->AddFriend(C);
1224      }else{      }else{
1225          cout << "Calorimeter  : missing tree"<<endl;          cout << "Calorimeter  : missing tree"<<endl;
1226      };      };
1227    
1228      // ToF          // ToF    
1229      TTree *O = (TTree*)f->Get("ToF");      TTree *O = (TTree*)f->Get("ToF");
1230      if(O && TOF) {      if(O && TOF) {
# Line 561  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1240  TTree *PamLevel2::GetPamTree(TFile *f, T
1240      if(R && TRG) {      if(R && TRG) {
1241          R->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));          R->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));
1242          cout << "Trigger      : set branch address TrigLevel2"<<endl;          cout << "Trigger      : set branch address TrigLevel2"<<endl;
1243          if(!Trout)Trout=O;          if(!Trout)Trout=R;
1244          else Trout->AddFriend(R);          else Trout->AddFriend(R);
1245      }else{      }else{
1246          cout << "Trigger      : missing tree"<<endl;          cout << "Trigger      : missing tree"<<endl;
# Line 571  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1250  TTree *PamLevel2::GetPamTree(TFile *f, T
1250      if(S && S4) {      if(S && S4) {
1251          S->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));          S->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));
1252          cout << "S4           : set branch address S4Level2"<<endl;          cout << "S4           : set branch address S4Level2"<<endl;
1253          if(!Trout)Trout=O;          if(!Trout)Trout=S;
1254          else Trout->AddFriend(S);          else Trout->AddFriend(S);
1255      }else{      }else{
1256          cout << "S4           : missing tree"<<endl;          cout << "S4           : missing tree"<<endl;
# Line 581  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1260  TTree *PamLevel2::GetPamTree(TFile *f, T
1260      if(N && ND) {      if(N && ND) {
1261          N->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));          N->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));
1262          cout << "NeutronD     : set branch address NDLevel2"<<endl;          cout << "NeutronD     : set branch address NDLevel2"<<endl;
1263          if(!Trout)Trout=O;          if(!Trout)Trout=N;
1264          else Trout->AddFriend(N);          else Trout->AddFriend(N);
1265      }else{      }else{
1266          cout << "NeutronD     : missing tree"<<endl;          cout << "NeutronD     : missing tree"<<endl;
# Line 591  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1270  TTree *PamLevel2::GetPamTree(TFile *f, T
1270      if(A && AC) {      if(A && AC) {
1271          A->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));          A->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));
1272          cout << "Anticounter  : set branch address AcLevel2"<<endl;          cout << "Anticounter  : set branch address AcLevel2"<<endl;
1273          if(!Trout)Trout=O;          if(!Trout)Trout=A;
1274          else Trout->AddFriend(A);          else Trout->AddFriend(A);
1275      }else{      }else{
1276          cout << "Anticounter  : missing tree"<<endl;          cout << "Anticounter  : missing tree"<<endl;
1277      };      };
1278      // Orbital Info      // Orbital Info
1279          TTree *B = (TTree*)f->Get("OrbitalInfo");      TTree *B = (TTree*)f->Get("OrbitalInfo");
1280          if(B && ORB) {      if(B && ORB) {
1281                  B->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));          B->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
1282                  cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;
1283                  if(!Trout)Trout=O;          if(!Trout)Trout=B;
1284                  else Trout->AddFriend(B);          else Trout->AddFriend(B);
1285          }else{      }else{
1286                  cout << "OrbitalInfo  : missing tree"<<endl;          cout << "OrbitalInfo  : missing tree"<<endl;
1287          };      };
1288    
1289        TTree *L = (TTree*)f->Get("SelectionList");
1290        if(L && SELLI==1) {
1291    //      L->SetBranchAddress("RunEntry",&irun);
1292    //      cout << "SelectionList: set branch address RunEntry"<<endl;
1293    //      L->SetBranchAddress("EventEntry",&irunentry);
1294    //      cout << "SelectionList: set branch address EventEntry"<<endl;
1295    //      if(!Trout)Trout=O;
1296    //      else Trout->AddFriend("SelectionList");
1297            cout << " TTree *PamLevel2::GetPamTree(TFile, TString) >>> SelectionList not implemente!!!!"<<endl;
1298            sel_tree = 0;
1299        }else{
1300            cout << "SelectionList  : missing tree"<<endl;
1301        };
1302            
1303          cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;      cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;
1304                    
1305          return Trout;      pam_tree = (TChain*)Trout;
1306        
1307        return Trout;
1308            
1309  }  }
1310  //--------------------------------------  //--------------------------------------
# Line 627  TList*  PamLevel2::GetListOfLevel2Files( Line 1322  TList*  PamLevel2::GetListOfLevel2Files(
1322                    
1323      TString wdir = gSystem->WorkingDirectory();      TString wdir = gSystem->WorkingDirectory();
1324            
1325      if(ddir=="")ddir = wdir;      //    if(ddir=="")ddir = wdir;
1326  //      TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);  //      TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);
1327      cout << "Level2 data directory : "<<  ddir << endl;      if ( ddir != ""){
1328              cout << "Level2 data directory : "<<  ddir << endl;
1329        } else {
1330          cout << "Level2 data directory not given as input: trying to evaluate from list or taking working directory " << endl;
1331        };
1332      TList *contents  = new TList; // create output list      TList *contents  = new TList; // create output list
1333      contents->SetOwner();      contents->SetOwner();
1334            
1335      char *fullpath;  //    char *fullpath;
1336    //    const char *fullpath;
1337            
1338      // if no input file list is given:        // if no input file list is given:  
1339      if ( flisttxt != "" ){      if ( flisttxt != "" ){
1340                    
1341          if( !gSystem->IsFileInIncludePath(flisttxt,&fullpath) )return 0;  //      if( !gSystem->IsFileInIncludePath(flisttxt,&fullpath) ){        
1342            //      if( !(fullpath = gSystem->FindFile("./",flisttxt)) ){
1343  //              flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));  //          cout <<"File "<<flisttxt<<" not found"<<endl;
1344          flisttxt = fullpath;  //          return 0;
1345            //      }      
1346          if( !gSystem->ChangeDirectory(ddir) )return 0;  //      flisttxt = fullpath;
1347          if ( !flisttxt.EndsWith(".root") ){
1348    
1349            flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
1350    
1351            if( !gSystem->ChangeDirectory(ddir) ){
1352                cout << "Cannot change directory : "<<ddir<<endl;
1353                return 0;
1354            }
1355                    
1356          cout <<"Input file list : " << flisttxt <<endl;          cout <<"Input file list : " << flisttxt <<endl;
1357          ifstream in;          ifstream in;
1358          in.open(flisttxt, ios::in); //open input file list          in.open(flisttxt, ios::in); //open input file list
1359            if(!in.good()){
1360                cout <<" ERROR opening the file "<<endl;
1361                gSystem->ChangeDirectory(wdir); // back to the working directory
1362                return 0;
1363            }      
1364          int line=0;          int line=0;
1365          while (1) {          while (1) {
1366              TString file;              TString file;
# Line 656  TList*  PamLevel2::GetListOfLevel2Files( Line 1368  TList*  PamLevel2::GetListOfLevel2Files(
1368              if (!in.good()) break;              if (!in.good()) break;
1369              line++;              line++;
1370  //          cout <<"(1) " << file << endl;  //          cout <<"(1) " << file << endl;
             if(file.Contains("#"))file = file(0,file.First("#"));  
 //          cout <<"(2) " << file << endl;  
1371              if(file.IsNull()){              if(file.IsNull()){
1372                  cout << "-- list interrupted at line "<<line <<endl;                  cout << "-- list interrupted at line "<<line <<endl;
1373                  break;                  break;
1374              }              }
1375              if( gSystem->IsFileInIncludePath(file,&fullpath) ){              if(file.Contains("#"))file = file(0,file.First("#"));
1376    //          cout <<"(2) " << file << endl;
1377    //          if( gSystem->IsFileInIncludePath(file,&fullpath) ){
1378    //          if( (fullpath = gSystem->FindFile(ddir,file)) ){
1379                if( file.EndsWith(".root") ){
1380                  TString filedir;
1381                  if (ddir != ""){
1382                    filedir = ddir; // take the input dir
1383                  } else {
1384                    gSystem->ChangeDirectory(wdir); // back to the working directory
1385                    filedir = gSystem->DirName(file); // this will take the path if exist in the list otherwise it will return automatically the working dir
1386                  };
1387                    char *fullpath = gSystem->ConcatFileName(gSystem->DirName(filedir),gSystem->BaseName(file));
1388                  contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list                  contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list
1389                    delete fullpath;
1390              }else{              }
1391                  if(file.Data()!="")cout << "File: "<<file<<" ---> missing "<< endl;  //          }else{
1392              };  //              if(file.Data()!="")cout << "File: "<<file<<" ---> missing "<< endl;
1393    //          };
1394          };          };
1395          in.close();          in.close();
1396                  } else {
1397              if(flisttxt.Contains("#"))flisttxt = flisttxt(0,flisttxt.First("#"));
1398              char *fullpath = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
1399              contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list
1400              delete fullpath;
1401          };        
1402      }else{      }else{
1403                    
1404          cout << "No input file list given."<<endl;          cout << "No input file list given."<<endl;
1405          cout << "Check for existing root files."<<endl;          cout << "Check for existing root files."<<endl;
1406  //              cout << "Warking directory: "<< gSystem->WorkingDirectory()<< endl;  //              cout << "Warking directory: "<< gSystem->WorkingDirectory()<< endl;
1407                    if ( ddir == "" ){
1408              ddir = wdir;
1409              cout << "Level2 data directory : "<<  ddir << endl;
1410            };
1411    
1412          TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);          TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);
1413          TList *temp = datadir->GetListOfFiles();          TList *temp = datadir->GetListOfFiles();
1414  //              temp->Print();  //              temp->Print();
# Line 690  TList*  PamLevel2::GetListOfLevel2Files( Line 1421  TList*  PamLevel2::GetListOfLevel2Files(
1421          while ( (questo = (TSystemFile*) next()) ) {          while ( (questo = (TSystemFile*) next()) ) {
1422              TString name =  questo-> GetName();              TString name =  questo-> GetName();
1423              if( name.EndsWith(".root") ){              if( name.EndsWith(".root") ){
1424                  char *fullpath;  //              const char *fullpath = gSystem->FindFile(ddir,name);
1425                  gSystem->IsFileInIncludePath(name,&fullpath);  //              char *fullpath;
1426    //              gSystem->IsFileInIncludePath(name,&fullpath);
1427                    char *fullpath = gSystem->ConcatFileName(gSystem->DirName(ddir),gSystem->BaseName(name));
1428                  contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));                  contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));
1429                    delete fullpath;
1430              };              };
1431          }          }
1432          delete temp;          delete temp;
# Line 702  TList*  PamLevel2::GetListOfLevel2Files( Line 1436  TList*  PamLevel2::GetListOfLevel2Files(
1436      gSystem->ChangeDirectory(wdir); // back to the working directory      gSystem->ChangeDirectory(wdir); // back to the working directory
1437  //      cout << endl << "Selected files:" << endl;  //      cout << endl << "Selected files:" << endl;
1438  //      contents->Print();  //      contents->Print();
1439      cout << contents->GetEntries()<<" files selected\n";      cout << contents->GetEntries()<<" files \n";
1440  //      cout << endl;  //      cout << endl;
1441  //      cout << "Working directory: "<< gSystem->WorkingDirectory()<< endl;  //      cout << "Working directory: "<< gSystem->WorkingDirectory()<< endl;
1442      return contents;      return contents;
# Line 717  TList*  PamLevel2::GetListOfLevel2Files( Line 1451  TList*  PamLevel2::GetListOfLevel2Files(
1451   * @param detlist String to select trees to be included   * @param detlist String to select trees to be included
1452   * @return Pointer to a TChain   * @return Pointer to a TChain
1453   */   */
1454  TChain *PamLevel2::GetPamTree(TList *fl, TString detlist="+ALL"){  TChain *PamLevel2::GetPamTree(TList *fl, TString detlist ){
1455      //
1456  //      TChain *Tout=0;    //
1457  //    if(Tout)Tout->Delete();    //
1458  //    Tout = NULL;    if ( pam_tree ){
1459        printf("WARNING: TChain *PamLevel2::GetPamTree(TList *fl, TString detlist) -- pam_tree already exists!\n ");
1460        return pam_tree;
1461      };
1462      //
1463            
1464      TChain *Tout =0;      TChain *Trout =0;
1465    
1466    //    if( !detlist.IsNull() )SetWhichTrees(detlist);
1467      SetWhichTrees(detlist);      SetWhichTrees(detlist);
1468            
1469      TChain *T = 0;            cout<< "GetPamTree(TList*,TString): input detector list --> ";
1470      TChain *C = 0;      if(TRK1)cout<<"TRK1 ";
1471      TChain *O = 0;      if(TRK2)cout<<"TRK2 ";
1472      TChain *R = 0;      if(TRKh)cout<<"TRKH ";
1473      TChain *S = 0;      if(CAL1)cout<<"CAL1 ";
1474      TChain *N = 0;      if(CAL2)cout<<"CAL2 ";
1475      TChain *A = 0;      if(TOF)cout<<"TOF ";
1476      TChain *B = 0;      if(TRG)cout<<"TRG ";
1477        if(AC)cout<<"AC ";
1478        if(ND)cout<<"ND ";
1479        if(S4)cout<<"S4 ";
1480        if(ORB)cout<<"ORB ";
1481        cout << endl;
1482    
1483         TChain *T = 0;    
1484         TChain *C = 0;
1485         TChain *O = 0;
1486         TChain *R = 0;
1487         TChain *S = 0;
1488         TChain *N = 0;
1489         TChain *A = 0;
1490         TChain *B = 0;
1491    
1492         TChain *L = 0;
1493            
1494      if(TRK2||TRK1||TRKh) T = new TChain("Tracker");          if(TRK2||TRK1||TRKh) T = new TChain("Tracker");    
1495      if(CAL2||CAL1) C = new TChain("Calorimeter");      if(CAL2||CAL1)       C = new TChain("Calorimeter");
1496      if(TOF) O = new TChain("ToF");      if(TOF)              O = new TChain("ToF");
1497      if(TRG) R = new TChain("Trigger");      if(TRG)              R = new TChain("Trigger");
1498      if(S4)  S = new TChain("S4");      if(S4)               S = new TChain("S4");
1499      if(ND)  N = new TChain("NeutronD");      if(ND)               N = new TChain("NeutronD");
1500      if(AC)  A = new TChain("Anticounter");      if(AC)               A = new TChain("Anticounter");
1501      if(ORB) B = new TChain("OrbitalInfo");      if(ORB)              B = new TChain("OrbitalInfo");
1502         L = new TChain("SelectionList");
1503            
1504      // loop over files and create chains              // loop over files and create chains        
1505      TIter next(fl);      TIter next(fl);
1506      TSystemFile *questo = 0;      TSystemFile *questo = 0;
1507      while ( (questo = (TSystemFile*) next()) ) {      while ( (questo = (TSystemFile*) next()) ) {
1508          TString name =  questo->GetName();          TString name =  questo->GetName();
1509  //              cout << "File: "<< name << endl;          cout << "File: "<< name << endl;
1510          if( CheckLevel2File(name) ){          if( CheckLevel2File(name) ){
1511              if(TRK2||TRK1||TRKh) T->Add(name);              if(TRK2||TRK1||TRKh) T->Add(name);
1512              if(CAL1||CAL2) C->Add(name);              if(CAL1||CAL2)       C->Add(name);
1513              if(TOF) O->Add(name);              if(TOF)              O->Add(name);
1514              if(TRG) R->Add(name);              if(TRG)              R->Add(name);
1515              if(S4)  S->Add(name);              if(S4)               S->Add(name);
1516              if(ND)  N->Add(name);              if(ND)               N->Add(name);
1517              if(AC)  A->Add(name);              if(AC)               A->Add(name);
1518              if(ORB) B->Add(name);              if(ORB)              B->Add(name);
1519                if(SELLI==1)         L->Add(name);
1520          };          };
1521      }      };
1522            
1523      cout << "done chain \n";      cout << "done chain \n";
1524            cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
1525    
1526    //    UInt_t *found=0;
1527    // Tracker
1528        if(T && (TRK2||TRK1||TRKh)) {
1529            if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
1530    //      else    T->SetBranchStatus("TrkLevel2",0,found);
1531            if(TRK2)cout << "Tracker      : set branch address TrkLevel2"<<endl;
1532            if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
1533    //      else    T->SetBranchStatus("TrkLevel1",0,found);
1534            if(TRK1)cout << "Tracker      : set branch address TrkLevel1"<<endl;
1535            if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
1536    //      else    T->SetBranchStatus("TrkHough",0,found);
1537            if(TRKh)cout << "Tracker      : set branch address TrkHough"<<endl;
1538            if(!Trout)Trout=T;
1539            else Trout->AddFriend("Tracker");
1540        }else{
1541            cout << "Tracker      : missing tree"<<endl;
1542        };
1543      // Calorimeter      // Calorimeter
1544      if(CAL2||CAL1) {                  if(C && (CAL2||CAL1)) {
1545          if(!Tout)Tout=C;          if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
1546          else Tout->AddFriend("Calorimeter");  //      else    C->SetBranchStatus("CaloLevel2",0,found);
1547            if(CAL2)cout << "Calorimeter  : set branch address CaloLevel2"<<endl;
1548            if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
1549    //      else    C->SetBranchStatus("CaloLevel1",0,found);
1550            if(CAL1)cout << "Calorimeter  : set branch address CaloLevel1"<<endl;
1551            if(!Trout)Trout=C;
1552            else Trout->AddFriend("Calorimeter");
1553        }else{
1554            cout << "Calorimeter  : missing tree"<<endl;
1555      };      };
1556      // ToF          // ToF    
1557      if(TOF) {      if(O && TOF) {
1558          if(!Tout)Tout=O;          O->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2"));
1559          else Tout->AddFriend("ToF");          cout << "ToF          : set branch address ToFLevel2"<<endl;
1560            if(!Trout)Trout=O;
1561            else Trout->AddFriend("ToF");
1562        }else{
1563            cout << "ToF         : missing tree"<<endl;
1564      };      };
     // Tracker  
     if(TRK2||TRK1||TRKh){  
         if(!Tout)Tout=T;  
         else Tout->AddFriend("Tracker");  
     }  
1565      // Trigger      // Trigger
1566      if(TRG) {      if(R && TRG) {
1567          if(!Tout)Tout=R;          R->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));
1568          else Tout->AddFriend("Trigger");          cout << "Trigger      : set branch address TrigLevel2"<<endl;
1569            if(!Trout)Trout=O;
1570            else Trout->AddFriend("Trigger");
1571        }else{
1572            cout << "Trigger      : missing tree"<<endl;
1573      };      };
1574      // S4      // S4
1575      if(S4) {      if(S && S4) {
1576          if(!Tout)Tout=S;          S->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));
1577          else Tout->AddFriend("S4");          cout << "S4           : set branch address S4Level2"<<endl;
1578            if(!Trout)Trout=O;
1579            else Trout->AddFriend("S4");
1580        }else{
1581            cout << "S4           : missing tree"<<endl;
1582      };      };
1583      // Neutron Detector      // Neutron Detector
1584      if(ND) {      if(N && ND) {
1585          if(!Tout)Tout=N;          N->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));
1586          else Tout->AddFriend("NeutronD");          cout << "NeutronD     : set branch address NDLevel2"<<endl;
1587            if(!Trout)Trout=O;
1588            else Trout->AddFriend("NeutronD");
1589        }else{
1590            cout << "NeutronD     : missing tree"<<endl;
1591      };      };
1592      // Anticounters      // Anticounters
1593      if(AC) {      if(A && AC) {
1594          if(!Tout)Tout=A;          A->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));
1595          else Tout->AddFriend("Anticounter");          cout << "Anticounter  : set branch address AcLevel2"<<endl;
1596      };          if(!Trout)Trout=O;
1597      // OrbitalInfo          else Trout->AddFriend("Anticounter");
1598      if(ORB) {      }else{
1599          if(!Tout)Tout=B;          cout << "Anticounter  : missing tree"<<endl;
1600          else Tout->AddFriend("OrbitalInfo");      };
1601        // Orbital Info
1602        if(B && ORB) {
1603            B->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
1604            cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;
1605            if(!Trout)Trout=O;
1606            else Trout->AddFriend("OrbitalInfo");
1607        }else{
1608            cout << "OrbitalInfo  : missing tree"<<endl;
1609        };
1610        cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
1611    
1612        // Selection List
1613        if(L && SELLI==1) {
1614            cout<<">>> Found selection-list <<<"<<endl;
1615            L->SetBranchAddress("RunEntry",&irun);
1616            cout << "SelectionList: set branch address RunEntry"<<endl;
1617            L->SetBranchAddress("EventEntry",&irunentry);
1618            cout << "SelectionList: set branch address EventEntry"<<endl;
1619            sel_tree = L;
1620    //      if(!Trout)Trout=O;
1621    //      else Trout->AddFriend("SelectionList");
1622            cout << "----------------------------------------------------" <<endl;
1623        }else{
1624    //      cout << "SelectionList  : missing tree"<<endl;
1625            if(L)L->Delete();
1626      };      };
1627            
1628  //    cout<<endl<<" Number of entries: "<<Tout->GetEntries()<<endl<<endl;  //    cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;
1629        
1630  //    if( Tout->GetEntries() )PamLevel2::SetBranchAddress();      pam_tree = Trout;
1631      if( Tout->GetEntries() )PamLevel2::SetBranchAddress( Tout );  
1632            return Trout;
     return Tout;  
1633  }  }
1634    
1635    
# Line 892  void PamLevel2::SetBranchAddress(TTree * Line 1710  void PamLevel2::SetBranchAddress(TTree *
1710          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
1711          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;
1712      };      };
1713        // SelectionList
1714        if(SELLI==1) {
1715            t->SetBranchAddress("RunEntry", &irun);
1716            cout << "SelectionList: set branch address RunEntry"<<endl;
1717            t->SetBranchAddress("EventEntry", &irunentry);
1718            cout << "SelectionList: set branch address EventEntry"<<endl;
1719        };
1720            
1721  }  }
1722  /**  /**
# Line 913  void PamLevel2::SetBranchAddress(TChain Line 1738  void PamLevel2::SetBranchAddress(TChain
1738    
1739      // Tracker      // Tracker
1740       if(TRK2) {       if(TRK2) {
1741          t->SetBranchAddress("TrkLevel2", this->GetPointerTo("TrkLevel2"));          t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
1742          cout << "Tracker      : set branch address TrkLevel2"<<endl;          cout << "Tracker      : set branch address TrkLevel2"<<endl;
1743      };      };
1744      if(TRK1) {      if(TRK1) {
# Line 965  void PamLevel2::SetBranchAddress(TChain Line 1790  void PamLevel2::SetBranchAddress(TChain
1790          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
1791          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;
1792      };      };
1793        // SelectionList
1794        if(SELLI==1) {
1795            t->SetBranchAddress("RunEntry", &irun);
1796            cout << "SelectionList: set branch address RunEntry"<<endl;
1797            t->SetBranchAddress("EventEntry", &irunentry);
1798            cout << "SelectionList: set branch address EventEntry"<<endl;
1799        };
1800            
1801  }  }
1802    
 // void* PamLevel2::GetPointerToTrk()  {return &trk2_obj;};  
 // void* PamLevel2::GetPointerToTrk(int s){  
 //     switch (s) {  
 //     case 1:  return &trk1_obj;  
 //     case 2:  return &trk2_obj;  
 //     case 3:  return &trkh_obj;  
 //     default: return 0;  
 //     };  
 // };  
 // void* PamLevel2::GetPointerToCalo() {return &calo2_obj; };  
 // void*       GetPointerToCalo(int s){  
 //     switch (s) {  
 //     case 1:  return &calo1_obj;  
 //     case 2:  return &calo2_obj;  
 //     default: return 0;  
 //     };  
 // };  
 // void*       GetPointerToToF()  {return &tof_obj;  };  
 // void*       GetPointerTo("TrigLevel2") {return &trig_obj; };  
 // void*       GetPointerTo("S4Level2")   {return &s4_obj;   };  
 // void*       GetPointerTo("NDLevel2")   {return &nd_obj;   };  
 // void*       GetPointerTo("AcLevel2")   {return &ac_obj;   };  
 // void*       GetPointerTo("OrbitalInfo")  {return &orb_obj;  };  
 // void*       GetPointerTo("RunInfo")  {return &run_obj;  };  
1803    
1804  //--------------------------------------  //--------------------------------------
1805  //  //
# Line 1003  void PamLevel2::SetBranchAddress(TChain Line 1811  void PamLevel2::SetBranchAddress(TChain
1811   * @return Pointer to a TChain   * @return Pointer to a TChain
1812   */   */
1813  TChain *PamLevel2::GetRunTree(TList *fl){  TChain *PamLevel2::GetRunTree(TList *fl){
1814              //
1815      TChain *R = new TChain("Run");    //
1816      //
1817      if ( run_tree ){
1818        printf("WARNING: TChain *PamLevel2::GetRunTree(TList *fl) -- run_tree already exists!\n ");
1819        return run_tree;
1820      };    
1821      //
1822      TChain *R = new TChain("Run");
1823            
1824      // loop over files and create chains              // loop over files and create chains        
1825      TIter next(fl);      TIter next(fl);
# Line 1016  TChain *PamLevel2::GetRunTree(TList *fl) Line 1831  TChain *PamLevel2::GetRunTree(TList *fl)
1831              R->Add(name);              R->Add(name);
1832          };          };
1833      }      }
1834    
1835        if(R->GetNtrees()){
1836            
1837      R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));          R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
1838      cout << "Run         : set branch address RunInfo"<<endl;          cout << "Run         : set branch address RunInfo"<<endl;
1839                R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
1840            cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano
1841        }else{
1842            delete R;
1843            R=0;
1844        }
1845    
1846        run_tree = R;
1847    
1848      return R;      return R;
1849            
1850  }  }
# Line 1033  TChain *PamLevel2::GetRunTree(TList *fl) Line 1858  TChain *PamLevel2::GetRunTree(TList *fl)
1858   * @return Pointer to a TTree   * @return Pointer to a TTree
1859   */   */
1860  TTree *PamLevel2::GetRunTree(TFile *f){  TTree *PamLevel2::GetRunTree(TFile *f){
1861      if ( run_tree ){
1862        printf("WARNING: TTree *PamLevel2::GetRunTree(TFile *f) -- run_tree already exists!\n ");
1863        return run_tree;
1864      };
1865            
1866    
1867        cout << "TTree *PamLevel2::GetRunTree(TFile *f) -- obsolte "<<endl;
1868    
1869      TTree *R = (TTree*)f->Get("Run");      TTree *T = (TTree*)f->Get("Run");
1870            
1871      R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));      if(T){
1872      cout << "Run         : set branch address RunInfo"<<endl;          T->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
1873                cout << "Run         : set branch address RunInfo"<<endl;
1874      return R;          T->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
1875            cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano
1876        }
1877    
1878        run_tree = (TChain*)T;
1879    
1880        return T;
1881            
1882  }  }
1883    /**
1884     * Update the runinfo informations (to be used to have Run infos event by event basis)
1885     * @param run Pointer to the chain/tree which contains run infos
1886     * @return true if a new run has been read, false if it is still the same run
1887     */
1888    Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev){
1889      //
1890      // check if we have already called once GetEntry, if not call it
1891      //
1892        cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev) --- NON FUNZIONA BENISSIMO.... "<<endl;
1893        if(!run){
1894              cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing RunInfo tree "<<endl;
1895              return(false);        
1896        }
1897        if ( run->GetEntries() <= 0 ) return(false);
1898      //
1899      
1900      //  Int_t oldrun = irun;
1901      Long64_t oldrun = irun;
1902    
1903      // --------------------------------------
1904      // if it is a full file (not preselected)
1905      // --------------------------------------
1906      if(SELLI==0){
1907    
1908          //
1909          // the absolute time is necessary to relate the event with the run
1910          //
1911          if( !GetOrbitalInfo() && !ISGP){
1912              cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;
1913              return(false);
1914          }
1915    
1916          ULong64_t abstime = 0;
1917          if( GetOrbitalInfo() )abstime=GetOrbitalInfo()->absTime;
1918    
1919    
1920          //
1921          // the first time the routine is called, set run search from the beginning
1922          //
1923          if ( irun < 0LL ){
1924              irun = 0LL;
1925              run->GetEntry(irun);
1926              runfirstentry = 0LL;
1927              runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
1928              if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;
1929              
1930              if( ISGP && run->GetEntries()!=1 ){
1931                  cout << "** WARNING ** simulated files are assumed to have 1 single run, not "<< run->GetEntries() << endl;
1932                  cout << "** WARNING ** run will not be updated"<<endl;
1933              }
1934    
1935          };      
1936          //
1937          if(ISGP)abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO
1938          //
1939          if ( irun == run->GetEntries()-1LL &&
1940               !(abstime >= GetRunInfo()->RUNHEADER_TIME &&
1941                 abstime <= GetRunInfo()->RUNTRAILER_TIME)
1942                ){
1943             irun = -1LL;
1944             runfirstentry = 0LL;
1945             runlastentry = -1LL;
1946           };
1947          // modificato il controllo sull'aggiornamento del run, per evitare problemi
1948          // dovuti agli eventi annidati (NB! NEVENTS conta anche questi!!)
1949          //
1950          bool fromfirst = true;
1951          //
1952          while ( !(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME) && irun < run->GetEntries()-1LL ){
1953    //      while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){
1954              irun++;
1955              run->GetEntry(irun);
1956              runfirstentry = runlastentry;
1957              if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runfirstentry += 1LL;
1958              runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
1959    //        cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
1960    //        cout << "runfirstentry "<<runfirstentry<<endl;
1961              //      printf(" iev %llu %u %llu \n",iev,this->GetRunInfo()->NEVENTS,(ULong64_t)(runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS)));
1962              //      printf(" abstime %u trailertime %u \n",abstime,GetRunInfo()->RUNTRAILER_TIME);
1963              //      printf(" IDRUN %u \n",GetRunInfo()->ID);
1964              //
1965    //        prevshift = 0;
1966              //
1967              if ( irun == (Long64_t)(run->GetEntries()-1LL) && fromfirst && !(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME)){
1968                  printf(" resetting irun  (it should NOT happen!!!)\n");
1969                  fromfirst = false;
1970                  irun = 0;
1971                  run->GetEntry(irun);
1972                  runfirstentry = 0ULL;
1973                  runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
1974                  if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;
1975              };
1976              //
1977          };
1978          //
1979          if (
1980               !(abstime >= GetRunInfo()->RUNHEADER_TIME &&
1981                 abstime <= GetRunInfo()->RUNTRAILER_TIME)
1982              ) {
1983              printf(" Something very wrong here: cannot find RUN containing absolute time %u \n",abstime);
1984              return false;
1985          }
1986          //
1987          if ( irun == oldrun || irun >= run->GetEntries() ) return(false);
1988          //
1989          //  printf(" iev %llu irun %i nevents %u 1st %llu last %llu \n",iev,irun,this->GetRunInfo()->NEVENTS,(ULong64_t)runfirstentry,(ULong64_t)runlastentry);
1990          //
1991          prevshift = 0;
1992          cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
1993    //      cout << "runfirstentry "<<runfirstentry<<endl;
1994          return(true);    
1995      };
1996      // ----------------------------------------------------
1997      // if it is a preselected file (there is SelectionList)
1998      // NBNB - the event tree MUST be read first
1999      // ----------------------------------------------------
2000      if(SELLI==1){      
2001          sel_tree->GetEntry(iev);
2002    //      cout << irun << " "<< irunentry << endl;
2003          if(irun != oldrun){
2004              run->GetEntry(irun);
2005              cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2006              prevshift = 0;
2007              return true;
2008          }
2009          return false;
2010      }
2011    
2012      return false;
2013      //
2014    };
2015    
2016    Bool_t PamLevel2::UpdateRunInfo(Long64_t iev){
2017    
2018        if(!run_tree){
2019            cout << " Bool_t PamLevel2::UpdateRunInfo(ULong64_t iev) -- ERROR -- run tree not loaded"<<endl;
2020            return false;
2021        }
2022        if ( run_tree->GetEntries() <= 0 ) {
2023            cout << " Bool_t PamLevel2::UpdateRunInfo(ULong64_t iev) -- ERROR -- run tree is empty"<<endl;
2024            return(false);
2025        }
2026      
2027        Int_t oldrun = irun; // store current run index
2028    
2029        // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2030        // if it is a full file (not preselected)
2031        // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2032        if(SELLI==0){
2033    
2034            ULong64_t abstime = 0;
2035            ULong64_t obt     = 0;
2036            if( GetOrbitalInfo() ){
2037                abstime = GetOrbitalInfo()->absTime;
2038                obt     = GetOrbitalInfo()->OBT;
2039            }
2040            // ---------------------------------------------------------------
2041            // the absolute time is necessary to relate the event with the run
2042            // ---------------------------------------------------------------
2043            if( !GetOrbitalInfo() && !ISGP ){
2044                cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;
2045                return(false);
2046            }
2047          
2048            // -----------------------------------------------------------------------
2049            // the first time the routine is called, set run search from the beginning
2050            // -----------------------------------------------------------------------
2051            if ( irun < 0 ){
2052                irun = 0LL;
2053                irunentry = 0;
2054                prevshift = 0;
2055                run_tree->GetEntry(irun);
2056    
2057                if( ISGP && run_tree->GetEntries()!=1 ){
2058                    cout << "** WARNING ** simulated files are assumed to have 1 single run, not "<< run_tree->GetEntries() << endl;
2059                    cout << "** WARNING ** run will not be updated"<<endl;
2060                }
2061            };      
2062    
2063            // -----------------------------------------------------------------------
2064            // if it is simulation, assigh abstime by end (temporaneo!!!)
2065            // -----------------------------------------------------------------------
2066            if(ISGP){
2067                abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO
2068                obt     = GetRunInfo()->RUNHEADER_OBT; // BARBATRUCCO
2069            }
2070            //
2071            bool fromfirst = true; // first loop over runs
2072    
2073    //      Bool_t hasfrag = false;
2074    //      if( GetRunInfo()->ID_RUN_FRAG!=0 && GetRunInfo()->ID_RUN_FRAG != GetRunInfo()->ID)hasfrag=true;
2075    //      ULong64_t fragid = GetRunInfo()->ID_RUN_FRAG;
2076    
2077            // ------------------------------------------------------
2078            // loop over runs to find the one that contains the event
2079            // ------------------------------------------------------
2080            while (
2081                (
2082                    (
2083                        !(abstime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s)
2084                          abstime <= GetRunInfo()->RUNTRAILER_TIME) &&
2085                        !(obt >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms)
2086                          obt <= GetRunInfo()->RUNTRAILER_OBT)
2087                        )
2088                    || GetRunInfo()->NEVENTS==0
2089                    || !(irunentry < GetRunInfo()->NEVENTS-1-prevshift)
2090                    )
2091                    && irun < run_tree->GetEntries() ){
2092    
2093                irun++;
2094                // ------------------------------------
2095                // if the end of run tree is reached...
2096                // ------------------------------------
2097                if( irun == run_tree->GetEntries() ){
2098                    if(!fromfirst){
2099                        // -----------------------------------------------------
2100                        // if it happened already once and the run was not found
2101                        // ---> exit with error
2102                        // -----------------------------------------------------
2103                        cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- ERROR -- event entry #"<<iev<<" does not belong to any run (should not happen)" <<endl;
2104                        return false;
2105                    }
2106                    // -----------------------------------------
2107                    // ...otherwise repeat search from beginning
2108                    // -----------------------------------------
2109                    cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- reached end of run tree. searchin again from beginning " <<endl;
2110                    fromfirst = false;
2111                    irun = 0LL;
2112                    runfirstentry = 0LL;
2113                }
2114                // -------------------------------------------------------------------
2115                // save the index of the first entry of the run, relative to pam_tree,
2116                // and read a new run
2117                // -------------------------------------------------------------------
2118                if(irun>0)runfirstentry += (GetRunInfo()->NEVENTS)-prevshift;
2119                irunentry = 0;
2120                prevshift = 0;
2121                run_tree->GetEntry(irun);      
2122                if(GetRunInfo()->RUNHEADER_OBT>GetRunInfo()->RUNTRAILER_OBT ){
2123                    cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- irun "<<irun<<"  has RUNHEADER_OBT>=RUNTRAILER_OBT " <<endl;
2124                    cout << "                                                            (NB!! in this case some events are assigned to a wrong run)"<<endl;
2125                }
2126    //          if(hasfrag &&  fragid != GetRunInfo()->ID){
2127    //              cout << "... where is the next fragment ??"<<endl;
2128    //          }
2129            };
2130    
2131    
2132            // --------------------------------------
2133            // if there was no need to update the run
2134            // ---> exit with FALSE
2135            // --------------------------------------
2136            if ( irun == oldrun ) return(false);
2137    
2138            // --------------------------------------
2139            // ... otherwise
2140            // ---> exit with TRUE
2141            // --------------------------------------
2142            cout << endl << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2143            // ----------------------------------------------------
2144            // then check if the run has a fragment
2145            // in this case we have to switch to the next fragment
2146            // when the end of the first fragment is reached
2147            // ----------------------------------------------------
2148            if(
2149                GetRunInfo()->ID_RUN_FRAG != 0 &&
2150    //          GetRunInfo()->ID_RUN_FRAG != GetRunInfo()->ID &&
2151                true ){
2152                cout << "* fragment *"<<endl;              
2153            }
2154            
2155            return(true);    
2156        };
2157        // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2158        // if it is a preselected file (there is SelectionList)
2159        // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2160        if(SELLI==1){      
2161            sel_tree->GetEntry(iev);
2162            if(irun != oldrun){
2163                run_tree->GetEntry(irun);
2164                cout << endl << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2165                prevshift = 0;
2166                return true;
2167            }
2168            return false;
2169        }
2170    
2171        return false;
2172        //
2173    };
2174    /**
2175     * Update the runinfo informations (to be used to have Run infos event by event basis)
2176     * @param run Pointer to the chain/tree which contains run infos
2177     * @return true if a new run has been read, false if it is still the same run
2178     */
2179    Bool_t PamLevel2::UpdateRunInfo(TTree *run, Long64_t iev){
2180      return(UpdateRunInfo((TChain*)run,iev));
2181    };
2182    
2183  //--------------------------------------  //--------------------------------------
2184  //  //
2185  //  //
# Line 1053  TTree *PamLevel2::GetRunTree(TFile *f){ Line 2190  TTree *PamLevel2::GetRunTree(TFile *f){
2190  */  */
2191  void PamLevel2::SetWhichTrees(TString detlist){  void PamLevel2::SetWhichTrees(TString detlist){
2192                    
2193      if(detlist.Contains("+ALL", TString::kIgnoreCase)){      if(detlist.IsNull() || detlist.Contains("+ALL", TString::kIgnoreCase)){
2194            CAL0 = false;
2195          CAL1 = true;          CAL1 = true;
2196          CAL2 = true;          CAL2 = true;
2197          TRK2 = true;          TRK2 = true;
2198          TRK1 = false;          TRK1 = false;
2199          TRKh = false;          TRKh = false;
2200            TRK0 = false;
2201          TRG = true;          TRG = true;
2202          TOF = true;          TOF = true;
2203            TOF0 = false;
2204          S4  = true;          S4  = true;
2205          ND  = true;          ND  = true;
2206          AC  = true;          AC  = true;
2207          ORB = true;          ORB = true;
2208      }else if( detlist.Contains("-ALL", TString::kIgnoreCase) ){      }else if( detlist.Contains("-ALL", TString::kIgnoreCase) ){
2209            CAL0 = false;
2210          CAL1 = false;          CAL1 = false;
2211          CAL2 = false;          CAL2 = false;
2212          TRK2 = false;          TRK2 = false;
2213          TRK1 = false;          TRK1 = false;
2214          TRKh = false;          TRKh = false;
2215            TRK0 = false;
2216          TRG = false;          TRG = false;
2217          TOF = false;          TOF = false;
2218            TOF0 = false;
2219          S4  = false;          S4  = false;
2220          ND  = false;          ND  = false;
2221          AC  = false;          AC  = false;
# Line 1084  void PamLevel2::SetWhichTrees(TString de Line 2227  void PamLevel2::SetWhichTrees(TString de
2227          if ( detlist.Contains("-CAL1", TString::kIgnoreCase) )CAL1=false;          if ( detlist.Contains("-CAL1", TString::kIgnoreCase) )CAL1=false;
2228          if ( detlist.Contains("+CAL1", TString::kIgnoreCase) )CAL1=true;          if ( detlist.Contains("+CAL1", TString::kIgnoreCase) )CAL1=true;
2229      };      };
2230    
2231        if( detlist.Contains("CAL0", TString::kIgnoreCase) ){
2232            if ( detlist.Contains("-CAL0", TString::kIgnoreCase) )CAL0=false;
2233            if ( detlist.Contains("+CAL0", TString::kIgnoreCase) )CAL0=true;
2234        };
2235                    
2236      if( detlist.Contains("CAL2", TString::kIgnoreCase)){      if( detlist.Contains("CAL2", TString::kIgnoreCase)){
2237          if ( detlist.Contains("-CAL2", TString::kIgnoreCase) )CAL2=false;          if ( detlist.Contains("-CAL2", TString::kIgnoreCase) )CAL2=false;
# Line 1096  void PamLevel2::SetWhichTrees(TString de Line 2244  void PamLevel2::SetWhichTrees(TString de
2244          CAL1=false;          CAL1=false;
2245      }      }
2246  //  -------------------------------------------------------------------------  //  -------------------------------------------------------------------------
2247        if( detlist.Contains("TRK0", TString::kIgnoreCase) ){
2248            if ( detlist.Contains("-TRK0", TString::kIgnoreCase) )TRK0=false;
2249            if ( detlist.Contains("+TRK0", TString::kIgnoreCase) )TRK0=true;
2250        };
2251    
2252      if( detlist.Contains("TRK1", TString::kIgnoreCase) ){      if( detlist.Contains("TRK1", TString::kIgnoreCase) ){
2253          if ( detlist.Contains("-TRK1", TString::kIgnoreCase) )TRK1=false;          if ( detlist.Contains("-TRK1", TString::kIgnoreCase) )TRK1=false;
2254          if ( detlist.Contains("+TRK1", TString::kIgnoreCase) )TRK1=true;          if ( detlist.Contains("+TRK1", TString::kIgnoreCase) )TRK1=true;
# Line 1118  void PamLevel2::SetWhichTrees(TString de Line 2271  void PamLevel2::SetWhichTrees(TString de
2271          TRKh=false;          TRKh=false;
2272      }      }
2273  //  -------------------------------------------------------------------------  //  -------------------------------------------------------------------------
   
   
       
 //     if( detlist.Contains("-TRK", TString::kIgnoreCase) )TRK2 = false;  
 //     else if( detlist.Contains("+TRK", TString::kIgnoreCase) )TRK2 = true;  
       
 //     if( detlist.Contains("-TRK1", TString::kIgnoreCase) )TRK1 = false;  
 //     else if( detlist.Contains("+TRK1", TString::kIgnoreCase) )TRK1 = true;  
   
 //     if( detlist.Contains("-TRKh", TString::kIgnoreCase) )TRKh = false;  
 //     else if( detlist.Contains("+TRKh", TString::kIgnoreCase) )TRKh = true;  
2274            
2275      if( detlist.Contains("-TRG", TString::kIgnoreCase) )TRG = false;      if( detlist.Contains("-TRG", TString::kIgnoreCase) )TRG = false;
2276      else if( detlist.Contains("+TRG", TString::kIgnoreCase) )TRG = true;      else if( detlist.Contains("+TRG", TString::kIgnoreCase) )TRG = true;
2277            
2278      if( detlist.Contains("-TOF", TString::kIgnoreCase) )TOF = false;      if( detlist.Contains("-TOF", TString::kIgnoreCase) )TOF = false;
2279      else if( detlist.Contains("+TOF", TString::kIgnoreCase) )TOF = true;      else if( detlist.Contains("+TOF", TString::kIgnoreCase) )TOF = true;
2280    
2281        if( detlist.Contains("-TOF0", TString::kIgnoreCase) )TOF0 = false;
2282        else if( detlist.Contains("+TOF0", TString::kIgnoreCase) )TOF0 = true;
2283            
2284      if( detlist.Contains("-S4",  TString::kIgnoreCase) )S4  = false;      if( detlist.Contains("-S4",  TString::kIgnoreCase) )S4  = false;
2285      else if( detlist.Contains("+S4",  TString::kIgnoreCase) )S4  = true;      else if( detlist.Contains("+S4",  TString::kIgnoreCase) )S4  = true;
# Line 1147  void PamLevel2::SetWhichTrees(TString de Line 2292  void PamLevel2::SetWhichTrees(TString de
2292            
2293      if( detlist.Contains("-ORB", TString::kIgnoreCase) )ORB = false;      if( detlist.Contains("-ORB", TString::kIgnoreCase) )ORB = false;
2294      else if( detlist.Contains("+ORB", TString::kIgnoreCase) )ORB = true;      else if( detlist.Contains("+ORB", TString::kIgnoreCase) )ORB = true;
2295    
2296    //     cout<< "Set detector list --> ";
2297    //     if(TRK1)cout<<"TRK1 ";
2298    //     if(TRK2)cout<<"TRK2 ";
2299    //     if(TRKh)cout<<"TRKH ";
2300    //     if(CAL1)cout<<"CAL1 ";
2301    //     if(CAL2)cout<<"CAL2 ";
2302    //     if(TOF)cout<<"TOF ";
2303    //     if(TRG)cout<<"TRG ";
2304    //     if(AC)cout<<"AC ";
2305    //     if(ND)cout<<"ND ";
2306    //     if(S4)cout<<"S4 ";
2307    //     if(ORB)cout<<"ORB ";
2308    //     cout << endl;
2309            
2310  };  };
2311    
2312    
2313    /**
2314     * Set tree/branch detector flags from the content of a tree
2315     */
2316    void  PamLevel2::GetWhichTrees(TFile* f){
2317        
2318    
2319    
2320        cout << "void  PamLevel2::GetWhichTrees(TFile* f) --- WARNING!! --- ...potrebbe non funzionare "<<endl;
2321        // -----------
2322        // reset flags
2323        // -----------
2324        CAL1   = false;    
2325        CAL2   = false;    
2326        TRK2   = false;    
2327        TRK1   = false;    
2328        TRKh   = false;    
2329        TRG    = false;    
2330        TOF    = false;    
2331        S4     = false;    
2332        ND     = false;    
2333        AC     = false;    
2334        ORB    = false;    
2335        
2336        RUN    = false;
2337            
2338        cout << "Checking file: "<<f->GetName()<<endl;
2339        if( !f || f->IsZombie() ){
2340            cout << "File: "<< f->GetName() <<" Non valid root file"<< endl;
2341            return;
2342        }
2343    
2344        TList *lk = f->GetListOfKeys();
2345        TIter next(lk);
2346        TKey *key =0;
2347    
2348        Int_t nev = 0;
2349    
2350        while( (key = (TKey*)next()) ){
2351            
2352            if( !strcmp(key->GetName(),"Run"        ) )RUN = true;
2353    
2354            //=========================================================    
2355            if( !strcmp(key->GetName(),"Trigger"    ) ){
2356                TRG = true;
2357                Int_t nevt = ((TTree*)f->Get("Trigger"))->GetEntries();
2358                if( nev && nevt!=nev){
2359                    cout << "File: "<< f->GetName() <<" Trigger tree has "<<nevt<<" events instead of "<<nev<< endl;
2360                    TRG = false;
2361                }else nev=nevt;
2362            }
2363            //=========================================================    
2364            if( !strcmp(key->GetName(),"ToF"        ) ){
2365                TOF = true;
2366                Int_t nevt = ((TTree*)f->Get("ToF"))->GetEntries();
2367                if( nev && nevt!=nev){
2368                    cout << "File: "<< f->GetName() <<"     ToF tree has "<<nevt<<" events instead of "<<nev<< endl;
2369                    TOF = false;
2370                }else nev=nevt;
2371            }
2372            //=========================================================  
2373            if( !strcmp(key->GetName(),"S4"         ) ){
2374                S4 = true;
2375                Int_t nevt = ((TTree*)f->Get("S4"))->GetEntries();
2376                if( nev && nevt!=nev){
2377                    cout << "File: "<< f->GetName() <<"      S4 tree has "<<nevt<<" events instead of "<<nev<< endl;
2378                    S4 = false;
2379                }else nev=nevt;
2380            }
2381            //=========================================================  
2382    
2383            if( !strcmp(key->GetName(),"NeutronD"   ) ){
2384                ND = true;
2385                Int_t nevt = ((TTree*)f->Get("NeutronD"))->GetEntries();
2386                if( nev && nevt!=nev){
2387                    cout << "File: "<< f->GetName() <<"NeutronD tree has "<<nevt<<" events instead of "<<nev<< endl;
2388                    ND =false;
2389                }else nev=nevt;
2390            }      
2391            //=========================================================  
2392            if( !strcmp(key->GetName(),"Anticounter") ){
2393                AC = true;
2394                Int_t nevt = ((TTree*)f->Get("Anticounter"))->GetEntries();
2395                if( nev && nevt!=nev){
2396                    cout << "File: "<< f->GetName() <<" Anticounter tree has "<<nevt<<" events instead of "<<nev<< endl;
2397                    AC =false;
2398                }else nev=nevt;
2399            }
2400            //=========================================================  
2401            if( !strcmp(key->GetName(),"OrbitalInfo") ){
2402                ORB = true;
2403                Int_t nevt = ((TTree*)f->Get("OrbitalInfo"))->GetEntries();
2404                if( nev && nevt!=nev){
2405                    cout << "File: "<< f->GetName() <<" OrbitalInfo tree has "<<nevt<<" events instead of "<<nev<< endl;
2406                    ORB = false;
2407                }else nev=nevt;
2408            }
2409            //=========================================================  
2410            if( !strcmp(key->GetName(),"Tracker"    ) ){
2411                TTree *T = (TTree*)f->Get("Tracker");
2412                for(Int_t i=0; i<T->GetListOfBranches()->GetEntries(); i++){
2413                    TString name = T->GetListOfBranches()->At(i)->GetName();
2414                    if( !name.CompareTo("TrkLevel1") )TRK1=true;
2415                    if( !name.CompareTo("TrkLevel2") )TRK2=true;
2416                    if( !name.CompareTo("TrkHough") )TRKh=true;
2417                };      
2418                Int_t nevt = T->GetEntries();
2419                if( nev && nevt!=nev){
2420                    cout << "File: "<< f->GetName() <<" Tracker tree has "<<nevt<<" events instead of "<<nev<< endl;
2421                    TRK1 = false;
2422                    TRK2 = false;
2423                    TRKh = false;
2424                }else nev=nevt;
2425                T->Delete();
2426            };
2427            //=========================================================  
2428            if( !strcmp(key->GetName(),"Calorimeter"    ) ){
2429                TTree *T = (TTree*)f->Get("Calorimeter");
2430                for(Int_t i=0; i<T->GetListOfBranches()->GetEntries(); i++){
2431                    TString name = T->GetListOfBranches()->At(i)->GetName();
2432                    if( !name.CompareTo("CaloLevel1") )CAL1=true;
2433                    if( !name.CompareTo("CaloLevel2") )CAL2=true;
2434                };    
2435                Int_t nevt = T->GetEntries();
2436                if( nev && nevt!=nev){
2437                    cout << "File: "<< f->GetName() <<"  Calorimeter tree has "<<nevt<<" events instead of "<<nev<< endl;
2438                    CAL1 = false;
2439                    CAL2 = false;
2440                }else nev=nevt;
2441                T->Delete();
2442            };      
2443    
2444        };
2445        
2446        delete lk;
2447    
2448    //     cout<< "Get detector list from input file --> ";
2449    //     if(TRK1)cout<<"TRK1 ";
2450    //     if(TRK2)cout<<"TRK2 ";
2451    //     if(TRKh)cout<<"TRKH ";
2452    //     if(CAL1)cout<<"CAL1 ";
2453    //     if(CAL2)cout<<"CAL2 ";
2454    //     if(TOF)cout<<"TOF ";
2455    //     if(TRG)cout<<"TRG ";
2456    //     if(AC)cout<<"AC ";
2457    //     if(ND)cout<<"ND ";
2458    //     if(S4)cout<<"S4 ";
2459    //     if(ORB)cout<<"ORB ";
2460    //     cout << endl;
2461          
2462        return ;
2463            
2464    };
2465    
2466    
2467  //--------------------------------------  //--------------------------------------
2468  //  //
2469  //  //
# Line 1174  Bool_t  PamLevel2::CheckLevel2File(TStri Line 2489  Bool_t  PamLevel2::CheckLevel2File(TStri
2489            
2490      Bool_t RUN__ok    = false;      Bool_t RUN__ok    = false;
2491            
2492            Bool_t SELLI__ok  = false;
2493    
2494      cout << "Checking file: "<<name<<endl;      cout << "Checking file: "<<name<<endl;
2495      TFile *f = new TFile(name.Data());      TFile *f = new TFile(name.Data());
# Line 1192  Bool_t  PamLevel2::CheckLevel2File(TStri Line 2507  Bool_t  PamLevel2::CheckLevel2File(TStri
2507      while( (key = (TKey*)next()) ){      while( (key = (TKey*)next()) ){
2508                    
2509  //      cout << key->GetName() << endl;  //      cout << key->GetName() << endl;
2510  //      cout << " Get tree: " << f->Get(key->GetName())<<endl;  //      cout << key->GetName() << ""<<key->GetClassName()<<endl;
2511    //              cout << " Get tree: " << f->Get(key->GetName())<<endl;
2512  //      nev_previous = nev;  //      nev_previous = nev;
2513  //      cout << " n.entries  "<< nev <<endl;  //      cout << " n.entries  "<< nev <<endl;
2514  //      if( key->GetClassName()=="TTree" && nev_previous && nev != nev_previous ){  //      if( key->GetClassName()=="TTree" && nev_previous && nev != nev_previous ){
# Line 1201  Bool_t  PamLevel2::CheckLevel2File(TStri Line 2517  Bool_t  PamLevel2::CheckLevel2File(TStri
2517  //          return false;  //          return false;
2518  //      };  //      };
2519    
2520    
2521          if( !strcmp(key->GetName(),"Run"        ) )RUN__ok = true;                if( !strcmp(key->GetName(),"Run"        ) )RUN__ok = true;      
2522    
2523          //=========================================================              //=========================================================    
2524            if( !strcmp(key->GetName(),"SelectionList"    ) ){
2525                SELLI__ok = true;
2526                if(SELLI==1){
2527                    Int_t nevt = ((TTree*)f->Get("SelectionList"))->GetEntries();
2528                    if( nev && nevt!=nev){
2529                        cout << "File: "<< f->GetName() <<" discarded ---- SelectionList tree has "<<nevt<<" events instead of "<<nev<< endl;
2530                        return false;
2531                    }
2532                    nev=nevt;
2533                }
2534            }
2535    
2536            //=========================================================    
2537          if( !strcmp(key->GetName(),"Trigger"    ) ){          if( !strcmp(key->GetName(),"Trigger"    ) ){
2538              TRG__ok = true;              TRG__ok = true;
2539              if(TRG){              if(TRG){
# Line 1315  Bool_t  PamLevel2::CheckLevel2File(TStri Line 2645  Bool_t  PamLevel2::CheckLevel2File(TStri
2645          };                };      
2646    
2647      };      };
2648    
2649        if( SELLI==-1 )SELLI = (Int_t)SELLI__ok;
2650        if( SELLI==0 && SELLI__ok ){
2651            cout << "File: "<< f->GetName() <<" discarded ---- found SelectionList (it is not a full-event file)" << endl;
2652            return false;  
2653        }
2654        if( SELLI==1 && !SELLI__ok ){
2655            cout << "File: "<< f->GetName() <<" discarded ---- SelectionList missing" << endl;
2656            return false;
2657        }
2658            
2659    //    cout << "SELLI "<<SELLI<<endl;
2660    
2661    //     cout<< "CheckLevel2File(TString): detector list --> ";
2662    //     if(TRK1__ok)cout<<"TRK1 ";
2663    //     if(TRK2__ok)cout<<"TRK2 ";
2664    //     if(TRKh__ok)cout<<"TRKH ";
2665    //     if(CAL1__ok)cout<<"CAL1 ";
2666    //     if(CAL2__ok)cout<<"CAL2 ";
2667    //     if(TOF__ok)cout<<"TOF ";
2668    //     if(TRG__ok)cout<<"TRG ";
2669    //     if(AC__ok)cout<<"AC ";
2670    //     if(ND__ok)cout<<"ND ";
2671    //     if(S4__ok)cout<<"S4 ";
2672    //     if(ORB__ok)cout<<"ORB ";
2673    //     cout << endl;
2674    
2675    
2676        if(TRK2 && TRK1__ok)TRK1=1;
2677    // ----------------------------------------------------------------------------
2678    // NOTA
2679    // se c'e` il level1, lo devo necessarimente leggere.
2680    // infatti (non ho capito perche`) i cluster vengono letti e allocati in memoria
2681    // comunque, ma non vengono disallocati da PamLevel2::Clear()
2682    // ----------------------------------------------------------------------------
2683    
2684    
2685      if(!RUN__ok) {      if(!RUN__ok) {
# Line 1360  Bool_t  PamLevel2::CheckLevel2File(TStri Line 2724  Bool_t  PamLevel2::CheckLevel2File(TStri
2724          return false;          return false;
2725      };      };
2726    
2727          if(ND && !ND__ok){      if(ND && !ND__ok){
2728              cout << "File: "<< f->GetName() <<" discarded ---- Missing ND tree"<< endl;          cout << "File: "<< f->GetName() <<" discarded ---- Missing ND tree"<< endl;
2729              return false;          return false;
2730          };      };
2731          if(TRG && !TRG__ok){      if(TRG && !TRG__ok){
2732              cout << "File: "<< f->GetName() <<" discarded ---- Missing Trigger tree"<< endl;          cout << "File: "<< f->GetName() <<" discarded ---- Missing Trigger tree"<< endl;
2733              return false;          return false;
2734          };      };
2735        
   
   
   
2736    
2737      lk->Delete();  //    lk->Delete();
2738    //    delete lk;
2739      f->Close();      f->Close();
2740    
2741    //     cout<< "CheckLevel2File(TString): detector list --> ";
2742    //     if(TRK1)cout<<"TRK1 ";
2743    //     if(TRK2)cout<<"TRK2 ";
2744    //     if(TRKh)cout<<"TRKH ";
2745    //     if(CAL1)cout<<"CAL1 ";
2746    //     if(CAL2)cout<<"CAL2 ";
2747    //     if(TOF)cout<<"TOF ";
2748    //     if(TRG)cout<<"TRG ";
2749    //     if(AC)cout<<"AC ";
2750    //     if(ND)cout<<"ND ";
2751    //     if(S4)cout<<"S4 ";
2752    //     if(ORB)cout<<"ORB ";
2753    //     cout << endl;
2754                
2755      return true;      return true;
2756                    
# Line 1384  Bool_t  PamLevel2::CheckLevel2File(TStri Line 2760  Bool_t  PamLevel2::CheckLevel2File(TStri
2760  /**  /**
2761   * Create clone-trees   * Create clone-trees
2762   */   */
2763  void PamLevel2::CreateCloneTrees( TChain *fChain ){  void PamLevel2::CreateCloneTrees0( TChain *fChain, TFile *ofile ){
2764    
2765      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2766      cout << "Create clones of PAMELA trees "<<endl;      cout << "Create clones of PAMELA trees "<<endl;
2767            
2768      Int_t i=0;      Int_t i=0;
2769      tree_clone[i] = fChain->GetTree()->CloneTree(0);      pam_tree_clone[i] = fChain->GetTree()->CloneTree(0);
2770      TString name =  tree_clone[i]->GetName();      TString name =  pam_tree_clone[i]->GetName();
2771      name.Append("_clone");      name.Append("_clone");
2772  //    tree_clone[i]->SetName(name.Data());  //    pam_tree_clone[i]->SetName(name.Data());
2773      cout << tree_clone[i]->GetName() <<endl;      cout << pam_tree_clone[i]->GetName() <<endl;
2774      i++;      i++;
2775    
2776      TList *li = fChain->GetListOfFriends();      TList *li = fChain->GetListOfFriends();
2777      TIter next(li);      TIter next(li);
2778      TFriendElement* T_friend=0;      TFriendElement* T_friend=0;
2779        ofile->cd();
2780      while( (T_friend = (TFriendElement*)next()) ){      while( (T_friend = (TFriendElement*)next()) ){
2781  //      cout<<T_friend->IsA()->GetName()<<" "<<T_friend->GetName()<<hex << T_friend->GetTree() << dec<<endl;  //      cout<<T_friend->IsA()->GetName()<<" "<<T_friend->GetName()<<hex << T_friend->GetTree() << dec<<endl;
2782  //      cout<<T_friend->GetTree()->GetName()<< endl;  //      cout<<T_friend->GetTree()->GetName()<< endl;
2783          tree_clone[i] = T_friend->GetTree()->CloneTree(0);                pam_tree_clone[i] = T_friend->GetTree()->CloneTree(0);
2784          name =  tree_clone[i]->GetName();          pam_tree_clone[i]->SetAutoSave(1000000);
2785            name =  pam_tree_clone[i]->GetName();
2786          name.Append("_clone");          name.Append("_clone");
2787  //      tree_clone[i]->SetName(name.Data());  //      pam_tree_clone[i]->SetName(name.Data());
2788          cout << tree_clone[i]->GetName() << endl;          cout << pam_tree_clone[i]->GetName() << endl;
2789          i++;          i++;
2790      }      }
2791        
2792        delete li;
2793    
2794      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2795    
2796  }  }
2797    
2798  // /**  /**
2799  //  * Create clone-trees   * Create clone-trees
2800  //  */   */
2801  // void PamLevel2::CreateCloneTrees(){  void PamLevel2::CreateCloneTrees(TFile *ofile){
2802    
2803    
2804    //  if the pointer is null, create a default file
2805    
2806        if(!ofile){
2807            cout << "void PamLevel2::CreateCloneTrees(TFile*) -- WARNING -- Creating file: clone-tree.root "<<endl;
2808            ofile = new TFile("clone-tree.root","recreate");
2809        }
2810    
2811  //     cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      ofile->cd();
2812  //     cout << "Create new PAMELA trees "<<endl;  
2813        cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2814        cout << "Create new PAMELA trees "<<endl;
2815                    
 //     if(TRK1||TRK2||TRKh){  
 //      T_clone = new TTree("Tracker_clone","PAMELA tracker level2 data ");      
 //      if(TRK1) {  
 //          trk1_clone = new TrkLevel1();  
 //          T_clone->Branch("TrkLevel1","TrkLevel1", GetPointerTo("TrkLevel1"));  
 //          T_clone->BranchRef();  
 //          cout << "Tracker      : branch TrkLevel1"<<endl;  
 //      };  
 //      if(TRK2) {  
 //          trk2_clone = new TrkLevel2();  
 //          T_clone->Branch("TrkLevel2", "TrkLevel2",GetPointerTo("TrkLevel2"));  
 //          cout << "Tracker      : branch TrkLevel2"<<endl;          
 //      };  
 //      if(TRKh) {  
 //          trkh_clone = new TrkHough();  
 //          T_clone->Branch("TrkHough","TrkHough", GetPointerTo("TrkHough"));  
 //          cout << "Tracker      : branch TrkHough"<<endl;  
 //      };  
 //      cout << hex << T_clone << dec << endl;  
 //     }  
2816    
2817  //     // Calorimeter      run_tree_clone = new TTree("Run","PAMELA Level2 data from the GL_RUN table ");
2818  //     if(CAL1||CAL2){      run_tree_clone->Branch("RunInfo","GL_RUN",GetPointerTo("RunInfo"));
2819  //      C_clone = new TTree("Calorimeter_clone","PAMELA calorimeter level2 data ");          cout << "Run          : branch RunInfo"<<endl;
2820  //      if(CAL1) {      run_tree_clone->Branch("SoftInfo","SoftInfo",GetPointerTo("SoftInfo"));
2821  //          calo1_clone = new CaloLevel1();      cout << "Run          : branch SoftInfo"<<endl;
2822  //          C_clone->Branch("CaloLevel1", "CaloLevel1", GetPointerTo("CaloLevel1"));      // ------------------
2823  //          cout << "Calorimeter  : branch CaloLevel1"<<endl;      // replicate run tree
2824  //      };      // ------------------
2825  //      if(CAL2) {      cout << "----------------------------------------------------"<<endl;
2826  //          calo2_clone = new CaloLevel2();      cout << "irun\t | RUN\t NEVENTS\t absolute time"<<endl;
2827  //          C_clone->Branch("CaloLevel2","CaloLevel2", GetPointerTo("CaloLevel2"));      for (Int_t i=0; i<run_tree->GetEntries(); i++){
2828  //          cout << "Calorimeter  : branch CaloLevel2"<<endl;          run_tree->GetEntry(i);
2829  //      };          cout << i<< "\t | "<<GetRunInfo()->ID<<"\t "<<GetRunInfo()->NEVENTS<< "\t "<<GetRunInfo()->RUNHEADER_TIME<<" <---> "<<GetRunInfo()->RUNTRAILER_TIME<<endl;
2830  //     }              run_tree_clone->Fill();
2831        }
2832        cout << "----------------------------------------------------"<<endl;
2833    
 //     // ToF      
 //     if(TOF) {  
 //      O_clone = new TTree("ToF_clone","PAMELA ToF level2 data ");      
 //      tof_clone = new ToFLevel2();  
 //      O_clone->Branch("ToFLevel2","ToFLevel2", GetPointerTo("ToFLevel2"));  
 //      cout << "ToF          : branch ToFLevel2"<<endl;  
 //     };  
 //     // Trigger  
 //     if(TRG) {  
 //      R_clone = new TTree("Trigger_clone","PAMELA trigger level2 data ");      
 //      trig_clone = new TrigLevel2();  
 //      R_clone->Branch("TrigLevel2","TrigLevel2", GetPointerTo("TrigLevel2"));  
 //      cout << "Trigger      : branch TrigLevel2"<<endl;  
 //     };  
 //     // S4  
 //     if(S4) {  
 //      S_clone = new TTree("S4_clone","PAMELA S4 level2 data ");        
 //      s4_clone = new S4Level2();  
 //      S_clone->Branch("S4Level2","S4Level2", GetPointerTo("S4Level2"));  
 //      cout << "S4           : branch S4Level2"<<endl;  
 //     };  
 //     // Neutron Detector  
 //     if(ND) {  
 //      N_clone = new TTree("NeutronD_clone","PAMELA neutron detector level2 data ");    
 //      nd_clone = new NDLevel2();  
 //      N_clone->Branch("NDLevel2","NDLevel2", GetPointerTo("NDLevel2"));  
 //      cout << "NeutronD     : branch NDLevel2"<<endl;  
 //     };  
 //     // Anticounters  
 //     if(AC) {  
 //      A_clone = new TTree("Anticounter_clone","PAMELA anticounter detector level2 data ");      
 //      ac_clone = new AcLevel2();  
 //      A_clone->Branch("AcLevel2","AcLevel2", GetPointerTo("AcLevel2"));  
 //      cout << "Anticounter  : branch AcLevel2"<<endl;  
 //     };  
 //     // OrbitalInfo  
 //     if(ORB) {  
 //      B_clone = new TTree("OrbitalInfo_clone","PAMELA oribital info  ");        
 //      orb_clone = new OrbitalInfo();  
 //      B_clone->Branch("OrbitalInfo","OrbitalInfo", GetPointerTo("OrbitalInfo"));  
 //      cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;  
 //     };  
 //     cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;  
2834    
2835  // }      sel_tree_clone = new TTree("SelectionList","List of selected events ");
2836        sel_tree_clone->Branch("RunEntry",&irun,"runentry/L");
2837        sel_tree_clone->Branch("EventEntry",&irunentry,"eventry/L");
2838        
2839    
2840  // /**      Int_t i=0;
2841  //  * Create clone-trees      if(TRK1||TRK2||TRKh){
2842  //  */          pam_tree_clone[i] = new TTree("Tracker","PAMELA tracker level2 data ");
2843  // void PamLevel2::CreateCloneTrees(){          if(TRK1) {
2844                pam_tree_clone[i]->Branch("TrkLevel1","TrkLevel1", GetPointerTo("TrkLevel1"));
2845                pam_tree_clone[i]->BranchRef();
2846                cout << "Tracker      : branch TrkLevel1"<<endl;
2847    //          cout << "CreateCloneTrees " << GetTrkLevel1()<<endl;
2848            };
2849            if(TRK2) {
2850                pam_tree_clone[i]->Branch("TrkLevel2", "TrkLevel2",GetPointerTo("TrkLevel2"));
2851                cout << "Tracker      : branch TrkLevel2"<<endl;        
2852            };
2853            if(TRKh) {
2854                pam_tree_clone[i]->Branch("TrkHough","TrkHough", GetPointerTo("TrkHough"));
2855                cout << "Tracker      : branch TrkHough"<<endl;
2856            };
2857            i++;
2858        }
2859    
2860  //     cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      // Calorimeter
2861  //     cout << "Create new PAMELA trees "<<endl;      if(CAL1||CAL2){
2862                    pam_tree_clone[i] = new TTree("Calorimeter","PAMELA calorimeter level2 data ");
2863  //     if(TRK1||TRK2||TRKh){          if(CAL1) {
2864  //      T_clone = new TTree("Tracker_clone","PAMELA tracker level2 data ");                  pam_tree_clone[i]->Branch("CaloLevel1", "CaloLevel1", GetPointerTo("CaloLevel1"));
2865  //      if(TRK1) {              cout << "Calorimeter  : branch CaloLevel1"<<endl;
2866  //          trk1_clone = new TrkLevel1();          };
2867  //          T_clone->Branch("TrkLevel1","TrkLevel1", &trk1_clone);          if(CAL2) {
2868  //          T_clone->BranchRef();              pam_tree_clone[i]->Branch("CaloLevel2","CaloLevel2", GetPointerTo("CaloLevel2"));
2869  //          cout << "Tracker      : branch TrkLevel1"<<endl;              cout << "Calorimeter  : branch CaloLevel2"<<endl;
2870  //      };          };
2871  //      if(TRK2) {          i++;
2872  //          trk2_clone = new TrkLevel2();      }    
 //          T_clone->Branch("TrkLevel2", "TrkLevel2",&trk2_clone);  
 //          cout << "Tracker      : branch TrkLevel2"<<endl;          
 //      };  
 //      if(TRKh) {  
 //          trkh_clone = new TrkHough();  
 //          T_clone->Branch("TrkHough","TrkHough", &trkh_clone);  
 //          cout << "Tracker      : branch TrkHough"<<endl;  
 //      };  
 //      cout << hex << T_clone << dec << endl;  
 //     }  
2873    
2874  //     // Calorimeter      // ToF    
2875  //     if(CAL1||CAL2){      if(TOF) {
2876  //      C_clone = new TTree("Calorimeter_clone","PAMELA calorimeter level2 data ");              pam_tree_clone[i] = new TTree("ToF","PAMELA ToF level2 data ");
2877  //      if(CAL1) {          pam_tree_clone[i]->Branch("ToFLevel2","ToFLevel2", GetPointerTo("ToFLevel2"));
2878  //          calo1_clone = new CaloLevel1();          cout << "ToF          : branch ToFLevel2"<<endl;
2879  //          C_clone->Branch("CaloLevel1", "CaloLevel1", &calo1_clone);          i++;
2880  //          cout << "Calorimeter  : branch CaloLevel1"<<endl;      };
2881  //      };      // Trigger
2882  //      if(CAL2) {      if(TRG) {
2883  //          calo2_clone = new CaloLevel2();          pam_tree_clone[i] = new TTree("Trigger","PAMELA trigger level2 data ");
2884  //          C_clone->Branch("CaloLevel2","CaloLevel2", &calo2_clone);          pam_tree_clone[i]->Branch("TrigLevel2","TrigLevel2", GetPointerTo("TrigLevel2"));
2885  //          cout << "Calorimeter  : branch CaloLevel2"<<endl;          cout << "Trigger      : branch TrigLevel2"<<endl;
2886  //      };          i++;
2887  //     }          };
2888        // S4
2889        if(S4) {
2890            pam_tree_clone[i] = new TTree("S4","PAMELA S4 level2 data ");  
2891            pam_tree_clone[i]->Branch("S4Level2","S4Level2", GetPointerTo("S4Level2"));
2892            cout << "S4           : branch S4Level2"<<endl;
2893            i++;
2894        };
2895        // Neutron Detector
2896        if(ND) {
2897            pam_tree_clone[i] = new TTree("NeutronD","PAMELA neutron detector level2 data ");      
2898            pam_tree_clone[i]->Branch("NDLevel2","NDLevel2", GetPointerTo("NDLevel2"));
2899            cout << "NeutronD     : branch NDLevel2"<<endl;
2900            i++;
2901        };
2902        // Anticounters
2903        if(AC) {
2904            pam_tree_clone[i] = new TTree("Anticounter","PAMELA anticounter detector level2 data ");        
2905            pam_tree_clone[i]->Branch("AcLevel2","AcLevel2", GetPointerTo("AcLevel2"));
2906            cout << "Anticounter  : branch AcLevel2"<<endl;
2907            i++;
2908        };
2909        // OrbitalInfo
2910        if(ORB) {
2911            pam_tree_clone[i] = new TTree("OrbitalInfo","PAMELA oribital info  ");  
2912            pam_tree_clone[i]->Branch("OrbitalInfo","OrbitalInfo", GetPointerTo("OrbitalInfo"));
2913            cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;
2914            i++;
2915        };
2916        cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2917    
2918  //     // ToF      }
 //     if(TOF) {  
 //      O_clone = new TTree("ToF_clone","PAMELA ToF level2 data ");      
 //      tof_clone = new ToFLevel2();  
 //      O_clone->Branch("ToFLevel2","ToFLevel2", &tof_clone);  
 //      cout << "ToF          : branch ToFLevel2"<<endl;  
 //     };  
 //     // Trigger  
 //     if(TRG) {  
 //      R_clone = new TTree("Trigger_clone","PAMELA trigger level2 data ");      
 //      trig_clone = new TrigLevel2();  
 //      R_clone->Branch("TrigLevel2","TrigLevel2", &trig_clone);  
 //      cout << "Trigger      : branch TrigLevel2"<<endl;  
 //     };  
 //     // S4  
 //     if(S4) {  
 //      S_clone = new TTree("S4_clone","PAMELA S4 level2 data ");        
 //      s4_clone = new S4Level2();  
 //      S_clone->Branch("S4Level2","S4Level2", &s4_clone);  
 //      cout << "S4           : branch S4Level2"<<endl;  
 //     };  
 //     // Neutron Detector  
 //     if(ND) {  
 //      N_clone = new TTree("NeutronD_clone","PAMELA neutron detector level2 data ");    
 //      nd_clone = new NDLevel2();  
 //      N_clone->Branch("NDLevel2","NDLevel2", &nd_clone);  
 //      cout << "NeutronD     : branch NDLevel2"<<endl;  
 //     };  
 //     // Anticounters  
 //     if(AC) {  
 //      A_clone = new TTree("Anticounter_clone","PAMELA anticounter detector level2 data ");      
 //      ac_clone = new AcLevel2();  
 //      A_clone->Branch("AcLevel2","AcLevel2", &ac_clone);  
 //      cout << "Anticounter  : branch AcLevel2"<<endl;  
 //     };  
 //     // OrbitalInfo  
 //     if(ORB) {  
 //      B_clone = new TTree("OrbitalInfo_clone","PAMELA oribital info  ");        
 //      orb_clone = new OrbitalInfo();  
 //      B_clone->Branch("OrbitalInfo","OrbitalInfo", &orb_clone);  
 //      cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;  
 //     };  
 //     cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;  
2919    
 // }  
2920    
2921  /**  /**
2922   * Fill tree (created with CreateCloneTrees)   * Fill tree (created with CreateCloneTrees)
# Line 1601  void PamLevel2::CreateCloneTrees( TChain Line 2924  void PamLevel2::CreateCloneTrees( TChain
2924   */   */
2925  //void PamLevel2::FillNewPamTree(TTree *T){  //void PamLevel2::FillNewPamTree(TTree *T){
2926  void PamLevel2::FillCloneTrees(){  void PamLevel2::FillCloneTrees(){
2927                
2928  // //  --------------------------------------  //    cout << "PamLevel2::FillCloneTrees()" << irunentry << endl;
 // //  copy the event  
 // //  --------------------------------------  
 //     if(trk1_clone)  *trk1_clone = *trk1_obj;  
 //     if(trk2_clone){  
 //      trk2_clone->Clear();  
 //      trk2_obj->Copy(*trk2_clone);  
 // //   *trk2_clone = *trk2_obj;  
 //     }  
 //     if(trkh_clone)  *trkh_clone = *trkh_obj;  
 //     if(calo1_clone){  
 // //   *calo1_clone = *calo1_obj;  
 //      calo1_clone->Clear();  
 //      calo1_obj->Copy(*calo1_clone);  
 //     }  
 //     if(calo2_clone){  
 // //   *calo2_clone = *calo2_obj;  
 //      calo2_clone->Clear();  
 //      calo2_obj->Copy(*calo2_clone);  
 //     }  
 //     if(tof_clone)   *tof_clone  = *tof_obj;  
 //     if(trig_clone)  *trig_clone = *trig_obj;  
 //     if(s4_clone)    *s4_clone   = *s4_obj;  
 //     if(nd_clone)    *nd_clone   = *nd_obj;  
 //     if(ac_clone)    *ac_clone   = *ac_obj;  
 //     if(orb_clone)   *orb_clone  = *orb_obj;  
   
 //     if(T_clone)T_clone->Fill();  
 //     if(C_clone)C_clone->Fill();  
 //     if(O_clone)O_clone->Fill();  
 //     if(R_clone)R_clone->Fill();  
 //     if(S_clone)S_clone->Fill();  
 //     if(N_clone)N_clone->Fill();  
 //     if(A_clone)A_clone->Fill();  
 //     if(O_clone)O_clone->Fill();  
2929    
2930      for(Int_t i=0; i<8; i++){      for(Int_t i=0; i<NCLONES; i++){
2931          if(tree_clone[i])tree_clone[i]->Fill();          if(pam_tree_clone[i])pam_tree_clone[i]->Fill();
2932      }      }
2933        if(sel_tree_clone)sel_tree_clone->Fill();    
2934    
2935  }  }
2936    
2937    
2938  TTree* PamLevel2::GetCloneTree(TString name){  TTree* PamLevel2::GetCloneTree(TString name){
2939    
2940      for(Int_t i=0; i<8; i++){        for(Int_t i=0; i<NCLONES; i++){    
2941          if(tree_clone[i]){          if(pam_tree_clone[i]){
2942              TString na = tree_clone[i]->GetName();              TString na = pam_tree_clone[i]->GetName();
2943              if(!name.CompareTo(na))return tree_clone[i];              if(!name.CompareTo(na))return pam_tree_clone[i];
2944          };          };
2945      }      }
2946        if(run_tree_clone){
2947            TString na = run_tree_clone->GetName();
2948            if(!name.CompareTo(na))return run_tree_clone;
2949        }
2950        if(sel_tree_clone){
2951            TString na = sel_tree_clone->GetName();
2952            if(!name.CompareTo(na))return sel_tree_clone;
2953        }
2954      return NULL;      return NULL;
2955    
2956  }  }
2957  void PamLevel2::WriteCloneTrees(){  void PamLevel2::WriteCloneTrees(){
2958      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2959      cout << "Write clones of PAMELA trees "<<endl;      cout << "Write clones of PAMELA trees "<<endl;
2960      for(Int_t i=0; i<8; i++){        cout << run_tree_clone->GetName()<<endl;    
2961          if(tree_clone[i]){      run_tree_clone->Write();
2962              cout << tree_clone[i]->GetName()<<endl;      cout << sel_tree_clone->GetName()<<endl;    
2963              tree_clone[i]->Write();      sel_tree_clone->Write();
2964        for(Int_t i=0; i<NCLONES; i++){    
2965            if(pam_tree_clone[i]){
2966                cout << pam_tree_clone[i]->GetName()<<endl;
2967                pam_tree_clone[i]->Write();
2968          };          };
2969      }      }
2970      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
# Line 1669  void PamLevel2::WriteCloneTrees(){ Line 2972  void PamLevel2::WriteCloneTrees(){
2972  }  }
2973    
2974  /**  /**
2975   * Create a new (empty) Pamela trees   * Method to get level2-trees entry, the corresponding run entry and (if required) the level0 entry.
2976   */   */
2977  // TTree* PamLevel2::GetNewPamTree(){  //Int_t PamLevel2::GetEntry(Int_t iee){
2978    Int_t PamLevel2::GetEntry(Long64_t iee){
2979        
2980    //     cout << "-------------------------------------"<<endl;
2981    //     cout << "Int_t PamLevel2::GetEntry("<<iee<<")"<<endl;
2982    
2983  //     if(tree_clone)return tree_clone;      if(!pam_tree){
2984            cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- level2 trees not loaded"<<endl;
2985            return 0;
2986        }
2987    
2988  //     TTree *Tout = 0;  
2989            //
2990  //     cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      // This is a sort of bug: if you don't have the run tree you don't want to exit here you want to have loaded the event anyway...
2991  //     cout << "Create new PAMELA trees "<<endl;      //
2992        //    if(!run_tree ){
2993        //  cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- run tree not loeaded"<<endl;
2994        //  return 0;
2995        //    }
2996    
2997        Long64_t ii=0;
2998        //-------------------------------
2999        ii = iee;
3000        if( !pam_tree->GetEntry(ii) ){      
3001            cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- error reading pam tree"<<endl;
3002            return 0;
3003        }
3004        //
3005        // ... that's way I put it here. Notice that nothing change in the code (is backward compatible) since in any case you return with 0.
3006        // in theory one would like to return 1 if run is not loaded but now I don't have the will to add that 2 lines of code and it is not
3007        // a problem if you don't check the return code of getentry.
3008        //
3009        if(!run_tree ){
3010            if ( TRK0 || CAL0 || TOF0 || RUN ) { //forse cosi` va bene per tornare 1?
3011                cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- run tree not loaded"<<endl;
3012                return 0;
3013            }  else {
3014                return 1; //cosi` se non c'e` run esce qua...
3015            }
3016        }
3017    
3018        //-------------------------------
3019        ii = iee;
3020    //    Bool_t UPDATED = UpdateRunInfo(run_tree,ii);
3021    //    Bool_t UPDATED = UpdateRunInfo(ii);
3022        UpdateRunInfo(ii);
3023        if(SELLI==0)irunentry = iee-runfirstentry;
3024    //    if(UPDATED && run_tree_clone)run_tree_clone->Fill();
3025      
3026    //    cout << "PamLevel2::GetEntry("<<iee<<") "<<irun<<" "<<runfirstentry<<" "<<irunentry<<endl;
3027    
3028    //     cout << "irunentry     "<<irunentry << endl;
3029    //     cout << "runfirstentry "<<runfirstentry << endl;
3030    //     cout << "nevents       "<<GetRunInfo()->NEVENTS<< endl;
3031    
3032    //     if( TRK0 || CAL0 || TOF0 ){
3033    //      if( !GetYodaEntry( ) ){
3034    //          cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- error reading level0 tree"<<endl;
3035    //          return 0;
3036    //      }
3037    //     }
3038    
3039    
3040        return 1;
3041    
3042    }
3043    
3044    TrkLevel0    *PamLevel2::GetTrkLevel0(){
3045        if( !TRK0 )return NULL;
3046        if( !GetYodaEntry( ) ){
3047            cout << " Int_t PamLevel2::GetTrkLevel0() -- ERROR -- error reading level0 tree"<<endl;
3048            return 0;
3049        }
3050        return trk0_obj;
3051    };
3052    CaloLevel0    *PamLevel2::GetCaloLevel0(){
3053        if( !CAL0 )return NULL;
3054        if( !GetYodaEntry( ) ){
3055            cout << " Int_t PamLevel2::GetCaloLevel0() -- ERROR -- error reading level0 tree"<<endl;
3056            return 0;
3057        }
3058        return calo0_obj;
3059    };
3060    
3061    
3062    /**
3063     * Method to retrieve the level0 tree (YODA tree) that contains the current event.
3064     * Given the run ID (...), if needed it query the DB and load the proper file.
3065     * @return Pointer to the tree
3066     */
3067    
3068    
3069    TTree* PamLevel2::GetYodaTree( ){
3070        
3071    //    cout << "TTree* PamLevel2::GetYodaTree( )"<<endl;
3072        //===================================
3073        // check if iroot has changed
3074        //===================================
3075        if( irun<0 ){
3076            cout << "PamLevel2::GetYodaTree() -- ERROR -- irun = "<<irun<<endl;
3077    //      cout << "In order to use this method you have to first load the RunInfo tree "<<endl;
3078            return NULL;
3079        }    
3080        Int_t irootnew = run_obj->ID_ROOT_L0;
3081    //      cout << "iroot    "<<iroot<<endl;
3082    //      cout << "irootnew "<<irootnew<<endl;
3083    
3084        //===================================
3085        // load the level0 file
3086        // (if not already loaded)
3087        //===================================
3088        if( iroot != irootnew || !l0_tree){
3089            iroot = irootnew;
3090            //===================================
3091            // open the DB connection
3092            // (if not already opened)
3093            //===================================
3094            if(!dbc || (dbc && !dbc->IsConnected())){
3095                cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
3096                cout<<"Connecting to DB"<<endl;
3097                cout<<"HOST "<<host<<endl;
3098                cout<<"USER "<<user<<endl;
3099                cout<<"PSW  "<<psw<<endl;
3100                dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
3101                if( !dbc )return NULL;
3102                if( !dbc->IsConnected() )return NULL;    
3103    //          cout<<"...done"<<endl;
3104                cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
3105            }else{
3106    //          cout<<"DB already connected"<<endl;
3107            }
3108            GL_ROOT glroot = GL_ROOT();
3109            if( glroot.Query_GL_ROOT(iroot,dbc) ){
3110                cout << "TTree* PamLevel2::GetYodaTree( ) -- ERROR -- level0 file iroot = "<<iroot<< " does not exists"<<endl;
3111                return NULL;
3112            };
3113            TString filename = glroot.PATH + glroot.NAME;
3114            if(l0_file){
3115                l0_file->Close();
3116                l0_file->Delete();
3117            }
3118            cout << "Opening LEVEL0 file: "<< filename << endl;
3119            FileStat_t t;
3120            if( gSystem->GetPathInfo(filename.Data(),t) ){
3121                cout << " PamLevel2::GetYodaTree() -- ERROR opening file "<<endl;
3122                return NULL;
3123            }
3124            l0_file = new TFile(filename);
3125            if( !l0_file )return NULL;
3126            l0_tree = (TTree*)l0_file->Get("Physics");
3127            if(!h0_obj)h0_obj = new EventHeader();
3128            l0_tree->SetBranchAddress("Header" ,&h0_obj);
3129            prevshift = 0;
3130            //---------------------------------------------------
3131            // TRACKER:
3132            if(TRK0){
3133                if(!trk0_obj){
3134                    trk0_obj = new TrkLevel0();
3135                    trk0_obj->Set();
3136                };
3137                l0_tree->SetBranchAddress("Tracker" ,trk0_obj->GetPointerToTrackerEvent());
3138            }
3139            //--------------------------------------------------
3140            // CALORIMETER:
3141            if(CAL0){
3142                if(!calo0_obj){
3143                    calo0_obj = new CaloLevel0();
3144                    calo0_obj->Set();
3145                };
3146                l0_tree->SetBranchAddress("Calorimeter" ,calo0_obj->GetPointerToCalorimeterEvent());
3147                //      cout << "PamLevel2::GetYodaTree() --- level0 calorimeter not implemented "<<endl;
3148            }
3149            //---------------------------------------------------
3150            // TOF:
3151            if(TOF0){
3152                cout << "PamLevel2::GetYodaTree() --- level0 TOF not implemented "<<endl;
3153            }
3154    
3155        };
3156    
3157        if(!dbc || (dbc && !dbc->IsConnected())){
3158            cout << " TTree* PamLevel2::GetYodaTree( ) -- no DB connected... hai fatto qualche cazzata "<<endl;
3159        }
3160    
3161        if ( TRK0 ){
3162            TrkParams::Load(6);
3163            if( !TrkParams::IsLoaded(6) ){
3164                cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- VK-mask not loaded"<<endl;
3165            };
3166            TrkParams::SetCalib(run_obj,dbc);
3167            TrkParams::LoadCalib( );
3168            if( !TrkParams::CalibIsLoaded() ){
3169                cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- Calibration not loaded"<<endl;
3170            };
3171        }
3172    
3173    //    cout << l0_tree << endl;
3174            
3175        return l0_tree;
3176    
3177    }
3178    
3179    /**
3180     * Method to retrieve the level0 tree (YODA tree) that contains the current event.
3181     */
3182    Int_t PamLevel2::GetYodaEntry(){
3183    
3184    //    cout << "Int_t PamLevel2::GetYodaEntry()"<<endl;
3185        if(!GetYodaTree())return 0;
3186            
3187  //     if(TRK1||TRK2||TRKh){      // patch
3188  //      TTree *T = new TTree("Tracker_clone","PAMELA tracker level2 data ");          if( irunentry < 0){
3189  //      if(TRK1) {  //      cout << "Int_t PamLevel2::GetYodaEntry() -- ATTENZIONE -- irunentry negativo?!?! "<<(Int_t)irunentry<<endl;
3190  //          trk1_clone = new TrkLevel1();          irunentry=0LL;
3191  //          T->Branch("TrkLevel1","TrkLevel1", &trk1_clone);      }
3192  //          T->BranchRef();      //  ---------------------------------
3193  //          cout << "Tracker      : branch TrkLevel1"<<endl;      //  if file is NOT a preselected file
3194  //      };      //  ---------------------------------
3195  //      if(TRK2) {      Long64_t quellagiusta = irunentry + (Long64_t)(run_obj->EV_FROM);
3196  //          trk2_clone = new TrkLevel2();  //     cout << " irunentry "<<irunentry<<endl;
3197  //          T->Branch("TrkLevel2", "TrkLevel2",&trk2_clone);  //     cout << " EV_FROM "<<run_obj->EV_FROM<<endl;
3198  //          cout << "Tracker      : branch TrkLevel2"<<endl;          //     cout << " quellagiusta = irunentry + EV_FROM "<< quellagiusta << endl;
3199  //      };  
3200  //      if(TRKh) {  //     cout << " irun "<< irun << " irunentry "<< irunentry<<" run_obj->EV_FROM "<<run_obj->EV_FROM <<" quella giusta "<<quellagiusta << endl;
3201  //          trkh_clone = new TrkHough();  //     cout << " iroot "<<iroot<<" run_obj->ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<endl;
3202  //          T->Branch("TrkHough","TrkHough", &trkh_clone);  //     cout << " time "<< abstime << endl;
3203  //          cout << "Tracker      : branch TrkHough"<<endl;  //     cout << " trk_calib_used "<<run_obj->TRK_CALIB_USED<< endl;
3204  //      };      
3205  //      if(!Tout)Tout=T;      ULong64_t obt     = 0;
3206  //      else Tout->AddFriend("Tracker_clone");      ULong64_t pktn    = 0;
3207  //     }      if( GetOrbitalInfo() ){
3208            obt     = GetOrbitalInfo()->OBT;
3209            pktn    = GetOrbitalInfo()->pkt_num;
3210        }
3211    
3212  //     // Calorimeter      if( !GetOrbitalInfo() && !ISGP){
3213  //     if(CAL1||CAL2){          cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing OrbitalInfo "<<endl;
3214  //      TTree *C = new TTree("Calorimeter_clone","PAMELA calorimeter level2 data ");              return 0;
3215  //      if(CAL1) {      }
3216  //          calo1_clone = new CaloLevel1();      if( obt==0 && pktn==0 && !ISGP ){
3217  //          C->Branch("CaloLevel1", "CaloLevel1", &calo1_clone);          cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- level2 event corrupted ?? "<<endl;
3218  //          cout << "Calorimeter  : branch CaloLevel1"<<endl;          return 0;
3219  //      };      }
 //      if(CAL2) {  
 //          calo2_clone = new CaloLevel2();  
 //          C->Branch("CaloLevel2","CaloLevel2", &calo2_clone);  
 //          cout << "Calorimeter  : branch CaloLevel2"<<endl;  
 //      };  
 //      if(!Tout)Tout=C;  
 //      else Tout->AddFriend("Calorimeter_clone");  
 //     }      
   
 //     // ToF      
 //     if(TOF) {  
 //      TTree *O = new TTree("ToF_clone","PAMELA ToF level2 data ");      
 //      tof_clone = new ToFLevel2();  
 //      O->Branch("ToFLevel2","ToFLevel2", &tof_clone);  
 //      cout << "ToF          : branch ToFLevel2"<<endl;  
 //      if(!Tout)Tout=O;  
 //      else Tout->AddFriend("ToF_clone");  
 //     };  
 //     // Trigger  
 //     if(TRG) {  
 //      TTree *R = new TTree("Trigger_clone","PAMELA trigger level2 data ");      
 //      trig_clone = new TrigLevel2();  
 //      R->Branch("TrigLevel2","TrigLevel2", &trig_clone);  
 //      cout << "Trigger      : branch TrigLevel2"<<endl;  
 //      if(!Tout)Tout=R;  
 //      else Tout->AddFriend("Trigger_clone");  
 //     };  
 //     // S4  
 //     if(S4) {  
 //      TTree *S = new TTree("S4_clone","PAMELA S4 level2 data ");        
 //      s4_clone = new S4Level2();  
 //      S->Branch("S4Level2","S4Level2", &s4_clone);  
 //      cout << "S4           : branch S4Level2"<<endl;  
 //      if(!Tout)Tout=S;  
 //      else Tout->AddFriend("S4_clone");  
 //     };  
 //     // Neutron Detector  
 //     if(ND) {  
 //      TTree *N = new TTree("NeutronD_clone","PAMELA neutron detector level2 data ");    
 //      nd_clone = new NDLevel2();  
 //      N->Branch("NDLevel2","NDLevel2", &nd_clone);  
 //      cout << "NeutronD     : branch NDLevel2"<<endl;  
 //      if(!Tout)Tout=N;  
 //      else Tout->AddFriend("NeutronD_clone");  
 //     };  
 //     // Anticounters  
 //     if(AC) {  
 //      TTree *A = new TTree("Anticounter_clone","PAMELA anticounter detector level2 data ");    
 //      ac_clone = new AcLevel2();  
 //      A->Branch("AcLevel2","AcLevel2", &ac_clone);  
 //      cout << "Anticounter  : branch AcLevel2"<<endl;  
 //      if(!Tout)Tout=A;  
 //      else Tout->AddFriend("Anticounter_clone");  
 //     };  
 //     // OrbitalInfo  
 //     if(ORB) {  
 //      TTree *B = new TTree("OrbitalInfo_clone","PAMELA oribital info  ");      
 //      orb_clone = new OrbitalInfo();  
 //      B->Branch("OrbitalInfo","OrbitalInfo", &orb_clone);  
 //      cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;  
 //      if(!Tout)Tout=B;  
 //      else Tout->AddFriend("OrbitalInfo_clone");  
 //     };  
 //     cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;  
3220    
3221  //     tree_clone = Tout;      // ---------------------------------------------------------------------
3222  //     tree_clone->SetDirectory(0);      // ATTENTION!!!
3223        // If data are not pre-processed with cleaner, the level0 tree may contain
3224        // spurious nested physics packets.
3225        // The GL_RUN variables EV_FROM, EV_TO and NEVENTS counts also these entries
3226        // while level2 tree DOES NOT!!
3227        // This means that "quellagiusta" in these cases is not correct.
3228        // In order to retrieve the correct level0 event, I implemented a check
3229        // of the OBT and pkt-number. In case of mismatch, the level0 entry number
3230        // is shift forward until when the packets match.
3231        // ---------------------------------------------------------------------
3232        Int_t answer = 0;
3233        Int_t shift =0;
3234        //    printf(" siamo qui %i %i \n",shift,prevshift);
3235        Int_t maxshift = 10;
3236        do{
3237            if(shift>0){    
3238                cout << " PKTNUM  L2 --- "<< pktn << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl;
3239                cout << "         RUN: ID "<< GetRunInfo()->ID << " ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<" ID_RUN_FRAG "<<GetRunInfo()->ID_RUN_FRAG << " EV_FROM "<<GetRunInfo()->EV_FROM  <<endl;
3240                cout << "         L2 <--> L0 mismatch ( irun "<<irun<<" irunentry "<<irunentry<<" shift "<<shift<<" prevshift "<<prevshift<<" )"<<endl;
3241            }
3242            answer = l0_tree->GetEntry(quellagiusta+(Long64_t)shift+(Long64_t)prevshift);
3243            shift++;
3244            if( !GetEventHeader() ){
3245                cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing EventHeader "<<endl;
3246                return 0;
3247            }
3248    
3249  //     return Tout;          if(ISGP){
3250  // }              obt = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()); //BARBATRUCCO
3251  // /**              pktn = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter()); //BARBATRUCCO
3252  //  * Fill a tree (created with GetNewPamTree)          }
 //  *  
 //  */  
 // //void PamLevel2::FillNewPamTree(TTree *T){  
 // void PamLevel2::FillNewPamTree(){  
           
3253    
3254  //     if(trk1_clone)  *trk1_clone = *trk1_obj;  //      cout << "PKTNUM "<<shift<<" ==  L2 --- "<< pktn << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl;
3255  //     if(trk2_clone){  //      cout << " L2 --- "<< obt << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime()<<endl;
3256  //      trk2_clone->Clear();  //      if( (quellagiusta+shift) == l0_tree->GetEntries()+1 )cout << ">>> end of level0 tree <<<"<<endl;
3257  //      trk2_obj->Copy(*trk2_clone);  //      cout << " obt "<< obt << endl;
3258  // //   *trk2_clone = *trk2_obj;  //      cout << " GetEventHeader()->GetPscuHeader()->GetOrbitalTime() "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime() << endl;
3259  //     }  //      cout << " pktn "<< pktn << endl;
3260  //     if(trkh_clone)  *trkh_clone = *trkh_obj;  //      cout << " GetEventHeader()->GetPscuHeader()->GetCounter() "<< GetEventHeader()->GetPscuHeader()->GetCounter() << endl;
3261  //     if(calo1_clone){  //      printf(" IDRUN %u \n",GetRunInfo()->ID);
3262  // //   *calo1_clone = *calo1_obj;  //
3263  //      calo1_clone->Clear();          if ( prevshift != 0 && (quellagiusta+(Long64_t)shift) == GetYodaTree()->GetEntries() ){
3264  //      calo1_obj->Copy(*calo1_clone);            prevshift = 0;
3265  //     }            shift = -1;
3266  //     if(calo2_clone){          };
 // //   *calo2_clone = *calo2_obj;  
 //      calo2_clone->Clear();  
 //      calo2_obj->Copy(*calo2_clone);  
 //     }  
 //     if(tof_clone)   *tof_clone  = *tof_obj;  
 //     if(trig_clone)  *trig_clone = *trig_obj;  
 //     if(s4_clone)    *s4_clone   = *s4_obj;  
 //     if(nd_clone)    *nd_clone   = *nd_obj;  
 //     if(ac_clone)    *ac_clone   = *ac_obj;  
 //     if(orb_clone)   *orb_clone  = *orb_obj;  
   
 //     TTree *T = tree_clone;  
   
 //     T->Fill(); //fill main tree  
 // //    cout<<T->IsA()->GetName()<<" "<<T->GetName()<<endl;  
 //     TList *li = T->GetListOfFriends();  
 //     TIter next(li);  
 //     TFriendElement* T_friend=0;  
 //     while( (T_friend = (TFriendElement*)next()) ){  
 // //   cout<<T_friend->IsA()->GetName()<<" "<<T_friend->GetName()<<hex << T_friend->GetTree() << dec<<endl;  
 //      T_friend->GetTree()->Fill();//fill friends  
 //     }  
3267    
3268  // }      }while( ( obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) ||
3269                  pktn != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter())       )
3270                && (quellagiusta+(Long64_t)shift) < GetYodaTree()->GetEntries() && shift < maxshift);
3271    
3272        if ( (quellagiusta+(Long64_t)shift+(Long64_t)prevshift) > GetYodaTree()->GetEntries() || shift == maxshift ) {
3273            cout << " Big trouble here, no such event in Level0 data! " <<endl;
3274            return 0;
3275        }
3276    //    cout << "LA ENTRY GIUSTA E`: "<<quellagiusta<<" (spero...)"<<endl;
3277    //    return GetYodaTree()->GetEntry(quellagiusta);
3278        if ( shift > 1 ) prevshift += (shift-1);
3279        
3280        return answer;
3281        
3282    }
3283    /**
3284     * \Brief Set DB connection
3285     */
3286    Bool_t PamLevel2::SetDBConnection(){
3287    
3288        cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
3289        cout<<"Connecting to DB"<<endl;
3290        cout<<"HOST "<<host<<endl;
3291        cout<<"USER "<<user<<endl;
3292        cout<<"PSW  "<<psw<<endl;
3293        dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
3294        if( !dbc )return false;
3295        if( !dbc->IsConnected() )return false;    
3296        cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
3297        return true;
3298    
3299    }

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.43

  ViewVC Help
Powered by ViewVC 1.1.23