/[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.12 by pam-fi, Wed Dec 13 09:57:29 2006 UTC revision 1.36 by pam-fi, Thu Mar 22 10:12:35 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();  //     trk2_obj  = TrkLevel2::GetTrkLevel2();
116      trk1_obj  = TrkLevel1::GetTrkLevel1();  //     trk1_obj  = TrkLevel1::GetTrkLevel1();
117      trkh_obj  = TrkHough::GetTrkHough();  //     trkh_obj  = TrkHough::GetTrkHough();
118      calo1_obj = CaloLevel1::GetCaloLevel1();  //     calo1_obj = CaloLevel1::GetCaloLevel1();
119      calo2_obj = CaloLevel2::GetCaloLevel2();  //     calo2_obj = CaloLevel2::GetCaloLevel2();
120      tof_obj   = ToFLevel2::GetToFLevel2();  //     tof_obj   = ToFLevel2::GetToFLevel2();
121      trig_obj  = TrigLevel2::GetTrigLevel2();  //     trig_obj  = TrigLevel2::GetTrigLevel2();
122      s4_obj    = S4Level2::GetS4Level2();  //     s4_obj    = S4Level2::GetS4Level2();
123      nd_obj    = NDLevel2::GetNDLevel2();  //     nd_obj    = NDLevel2::GetNDLevel2();
124      ac_obj    = AcLevel2::GetAcLevel2();  //     ac_obj    = AcLevel2::GetAcLevel2();
125      orb_obj   = OrbitalInfo::GetOrbitalInfo();  //     orb_obj   = OrbitalInfo::GetOrbitalInfo();
126        
127      run_obj   = new GL_RUN();      h0_obj    = 0;
128            trk0_obj  = 0;
129  //     trk1_clone  = 0;      calo0_obj  = 0;
130  //     trk2_clone  = 0;  
131  //     trkh_clone  = 0;      trk2_obj  = 0;
132  //     calo1_clone = 0;      trk1_obj  = 0;
133  //     calo2_clone = 0;      trkh_obj  = 0;
134  //     tof_clone   = 0;      calo1_obj = 0;
135  //     trig_clone  = 0;      calo2_obj = 0;
136  //     s4_clone    = 0;      tof_obj   = 0;
137  //     nd_clone    = 0;      trig_obj  = 0;
138  //     ac_clone    = 0;      s4_obj    = 0;
139  //     orb_clone   = 0;      nd_obj    = 0;
140        ac_obj    = 0;
141  //     T_clone  = 0;      orb_obj   = 0;
142  //     C_clone  = 0;  
143  //     O_clone  = 0;      run_obj   = 0;//new GL_RUN();
144  //     R_clone  = 0;      soft_obj   = 0;// Emiliano
145  //     S_clone  = 0;      irun = -1LL;
146  //     N_clone  = 0;      runfirstentry = 0LL;
147  //     A_clone  = 0;      runlastentry = 0LL;
148  //     B_clone  = 0;  
149        l0_file = NULL;
150        l0_tree = NULL;
151        iroot   = -1;
152        dbc     = 0;
153    
154        prevshift = 0;
155        
156        run_tree = NULL;
157        run_tree_clone = NULL;
158        sel_tree = NULL;
159        sel_tree_clone = NULL;
160        
161        irunentry = -1LL;
162        pam_tree = NULL;
163        for(Int_t i=0; i<NCLONES; i++ )pam_tree_clone[i]=NULL;
164    
165        host = "mysql://localhost/pamelaprod";
166        user = "anonymous";
167        psw = "";
168        const char *pamdbhost=gSystem->Getenv("PAM_DBHOST");
169        const char *pamdbuser=gSystem->Getenv("PAM_DBUSER");
170        const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW");
171        if ( !pamdbhost ) pamdbhost = "";
172        if ( !pamdbuser ) pamdbuser = "";
173        if ( !pamdbpsw ) pamdbpsw = "";
174        if ( strcmp(pamdbhost,"") ) host = pamdbhost;
175        if ( strcmp(pamdbuser,"") ) user = pamdbuser;
176        if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw;
177    
178      for(Int_t i=0; i<8; i++ )tree_clone[i]=NULL;      
179    
180      sorted_tracks = new TRefArray();  //    sorted_tracks = 0;//new TRefArray();
181            
182        CAL0 = false;
183      CAL1 = true;      CAL1 = true;
184      CAL2 = true;      CAL2 = true;
185      TRK2 = true;      TRK2 = true;
186      TRK1 = false;      TRK1 = false;
187      TRKh = false;      TRKh = false;
188      TRG = true;      TRKh = false;
189      TOF = true;      TRG  = true;
190      S4  = true;      TOF  = true;
191      ND  = true;      TOF0 = false;
192      AC  = true;      S4   = true;
193      ORB = true;      ND   = true;
194        AC   = true;
195        ORB  = true;
196            
197      RUN = true;      RUN  = true;
198    
199        SELLI = -1;
200    
201        tsorted=0;
202        timage=0;
203    
204  };  };
205  /**  /**
206   * Destructor   * Delete the event (act as Dtor)
207   */   */
208  PamLevel2::~PamLevel2(){                  void PamLevel2::Delete(){
209      delete run_obj;          
210      Clear();      if(run_obj)delete run_obj;
211        if(soft_obj)delete soft_obj; //Emiliano
212    
213    //    cout << "void PamLevel2::Clear()"<<endl;
214        if(h0_obj)   delete h0_obj;
215        if(trk0_obj) delete trk0_obj;      
216        if(calo0_obj) delete calo0_obj;    
217        if(trk1_obj) delete trk1_obj;      
218        if(trk2_obj) delete trk2_obj;
219        if(trkh_obj) delete trkh_obj;
220        if(calo1_obj)delete calo1_obj;
221        if(calo2_obj)delete calo2_obj;
222        if(tof_obj)  delete tof_obj;
223        if(trig_obj) delete trig_obj;
224        if(s4_obj)   delete s4_obj;
225        if(nd_obj)   delete nd_obj;
226        if(ac_obj)   delete ac_obj;
227        if(orb_obj)  delete orb_obj;
228        
229        if(tsorted){
230            tsorted->Delete();
231            delete tsorted;
232        }
233        if(timage){
234            timage->Delete();
235            delete timage;
236        }
237    
238        if(dbc){
239            dbc->Close();
240            delete dbc;
241        }
242        
243        if(l0_file)l0_file->Close();
244        //    if(pam_tree)pam_tree->Delete();;
245    
246      if ( pam_tree ){
247        //
248        // 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...
249        //
250        TList *temp = pam_tree->GetListOfFriends();
251        TList *contents  = new TList; // create chain friend list
252        contents->SetOwner();
253        TIter next(temp);
254        TChain *questo = 0;
255        while ( (questo = (TChain*) next()) ){
256          TString name =  questo->GetName();
257          contents->Add((TChain*)gROOT->FindObject(name.Data()));// add object to the list
258        };
259        //
260        // deleting the main chain
261        //
262        pam_tree->Delete();
263        //
264        // deleting the friends...
265        //
266        TIter next2(contents);
267        TChain *questa = 0;
268        while ( questa = (TChain*)next2() ){
269          TString name =  questa->GetName();
270          questa->Delete();      
271          questa=NULL;
272        };
273        //
274      };
275      pam_tree = NULL;
276    
277        if(run_tree)run_tree->Delete();;
278        if(sel_tree)sel_tree->Delete();;
279        for(Int_t i=0; i<NCLONES; i++ )if(pam_tree_clone[i])pam_tree_clone[i]->Delete();;
280        if(run_tree_clone)run_tree_clone->Delete();;
281        if(sel_tree_clone)sel_tree_clone->Delete();;
282        
283    
284  };  };
285    
286  /**  /**
287   * Clear the event   * Clear the event (NB! does not deallocate objects)
288   */   */
289  void PamLevel2::Clear(){  void PamLevel2::Clear(){
290                    
291      TrkLevel1::Clear();  //    cout << "void PamLevel2::Clear()"<<endl;
292            
293      TrkLevel2::Clear();  //
294      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
295      ToFLevel2::Clear();  // want to load them for each event even if they are the same...
296      TrigLevel2::Clear();  //
297      S4Level2::Clear();  //    if(run_obj)delete run_obj;
298      NDLevel2::Clear();  //    if(run_obj) run_obj->Clear();  // Emiliano: Do not deallocate run_obj here, it will give segmentation fault! call clear instead
299      AcLevel2::Clear();  //    if(soft_obj) soft_obj->Clear();
300      OrbitalInfo::Clear();  
301        if(h0_obj)   h0_obj->Clear();      
302  //     if(trk1_clone)trk1_clone->Clear();  //    if(trk0_obj) trk0_obj->Clear();  
303  //     if(trk2_clone)trk2_clone->Clear();      if(calo0_obj) calo0_obj->Clear();  
304  //     if(trkh_clone)trkh_clone->Clear();      if(trk1_obj) trk1_obj->Clear();    
305  //     if(calo1_clone)calo1_clone->Clear();      if(trk2_obj) trk2_obj->Clear();
306  //     if(calo2_clone)calo2_clone->Clear();      if(trkh_obj) trkh_obj->Clear();
307  //     if(tof_clone)tof_clone->Clear();      if(calo1_obj)calo1_obj->Clear();
308  //     if(trig_clone)trig_clone->Clear();      if(calo2_obj)calo2_obj->Clear();
309  //     if(s4_clone)s4_clone->Clear();      if(tof_obj)  tof_obj->Clear();
310  //     if(nd_clone)nd_clone->Clear();      if(trig_obj) trig_obj->Clear();
311  //     if(ac_clone)ac_clone->Clear();      if(s4_obj)   s4_obj->Clear();
312  //     if(orb_clone)orb_clone->Clear();      if(nd_obj)   nd_obj->Clear();
313            if(ac_obj)   ac_obj->Clear();
314      sorted_tracks->Delete(); // clean the reference array      if(orb_obj)  orb_obj->Clear();
315            
316    //    if(sorted_tracks)sorted_tracks->Clear();
317    //    sorted_tracks.Clear();
318    
319        if(tsorted){
320            tsorted->Delete();
321        }
322        if(timage){
323            timage->Delete();
324        }
325    };
326    
327    void PamLevel2::Reset(){
328      //
329      // First of all clear everything
330      //
331      Clear();
332      //
333      // close and reset chains and pointers
334      //    
335      if ( pam_tree ){
336        //
337        // 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...
338        //
339        TList *temp = pam_tree->GetListOfFriends();
340        TList *contents  = new TList; // create chain friend list
341        contents->SetOwner();
342        TIter next(temp);
343        TChain *questo = 0;
344        while ( (questo = (TChain*) next()) ){
345          TString name =  questo->GetName();
346          contents->Add((TChain*)gROOT->FindObject(name.Data()));// add object to the list
347        };
348        //
349        // deleting the main chain
350        //
351        pam_tree->Delete();
352        //
353        // deleting the friends...
354        //
355        TIter next2(contents);
356        TChain *questa = 0;
357        while ( questa = (TChain*)next2() ){
358          TString name =  questa->GetName();
359          questa->Delete();      
360          questa=NULL;
361        };
362        //
363      };
364      pam_tree = NULL;
365      //
366      if(run_tree)run_tree->Delete();;
367      run_tree = NULL;
368      if(sel_tree)sel_tree->Delete();;
369      sel_tree = NULL;
370      //
371      // Close file
372      //
373      if(l0_file)l0_file->Close("R");
374      l0_file = NULL;
375      //
376      h0_obj    = 0;
377      trk0_obj  = 0;
378      calo0_obj  = 0;
379      //
380      trk2_obj  = 0;
381      trk1_obj  = 0;
382      trkh_obj  = 0;
383      calo1_obj = 0;
384      calo2_obj = 0;
385      tof_obj   = 0;
386      trig_obj  = 0;
387      s4_obj    = 0;
388      nd_obj    = 0;
389      ac_obj    = 0;
390      orb_obj   = 0;
391      //
392      // Reset run pointers
393      //
394      run_obj   = 0;//new GL_RUN();
395      soft_obj   = 0;// Emiliano
396      irun = -1;
397      runfirstentry = 0ULL;
398      runlastentry = 0ULL;    
399      //
400  };  };
401    
402    
# Line 137  void PamLevel2::Clear(){ Line 407  void PamLevel2::Clear(){
407  void *PamLevel2::GetPointerTo(const char* c ){  void *PamLevel2::GetPointerTo(const char* c ){
408    
409      TString objname = c;      TString objname = c;
410      if(!objname.CompareTo("TrkLevel1"))return &trk1_obj;  
411      if(!objname.CompareTo("TrkLevel2"))return &trk2_obj;      if(!objname.CompareTo("TrkLevel1"))  {
412      if(!objname.CompareTo("TrkHough"))return &trkh_obj;          if(!trk1_obj){
413      if(!objname.CompareTo("CaloLevel1"))return &calo1_obj;              trk1_obj  = new TrkLevel1();
414      if(!objname.CompareTo("CaloLevel2"))return &calo2_obj;              trk1_obj->Set();
415      if(!objname.CompareTo("ToFLevel2"))return &tof_obj;          }
416      if(!objname.CompareTo("TrigLevel2"))return &trig_obj;          return &trk1_obj;
417      if(!objname.CompareTo("S4Level2"))return &s4_obj;      };
418      if(!objname.CompareTo("NDLevel2"))return &nd_obj;      if(!objname.CompareTo("TrkLevel2"))  {
419      if(!objname.CompareTo("AcLevel2"))return &ac_obj;          if(!trk2_obj){  
420      if(!objname.CompareTo("OrbitalInfo"))return &orb_obj;              trk2_obj  = new TrkLevel2();
421                trk2_obj->Set();
422            }
423            return &trk2_obj;
424        };
425        if(!objname.CompareTo("TrkHough"))   {
426            if(!trkh_obj)  trkh_obj  = new TrkHough();
427            return &trkh_obj;
428        };
429        if(!objname.CompareTo("CaloLevel1")) {
430            if(!calo1_obj) calo1_obj = new CaloLevel1();
431            return &calo1_obj;
432        };
433        if(!objname.CompareTo("CaloLevel2")) {
434            if(!calo2_obj){
435                calo2_obj = new CaloLevel2();
436                calo2_obj->Set();
437            };
438            return &calo2_obj;
439        };
440        if(!objname.CompareTo("ToFLevel2"))  {
441            if(!tof_obj){
442                tof_obj   = new ToFLevel2();
443                tof_obj->Set();
444            }
445            return &tof_obj;
446        };
447        if(!objname.CompareTo("TrigLevel2")) {
448            if(!trig_obj)  trig_obj  = new TrigLevel2();
449            return &trig_obj;
450        };
451        if(!objname.CompareTo("S4Level2"))   {
452            if(!s4_obj)    s4_obj    = new S4Level2();
453            return &s4_obj;
454        };
455        if(!objname.CompareTo("NDLevel2"))   {
456            if(!nd_obj)    nd_obj    = new NDLevel2();
457            return &nd_obj;
458        };
459        if(!objname.CompareTo("AcLevel2"))   {
460            if(!ac_obj)    ac_obj    = new AcLevel2();
461            return &ac_obj;
462        };
463        if(!objname.CompareTo("OrbitalInfo")){
464            if(!orb_obj)   orb_obj   = new OrbitalInfo();
465            return &orb_obj;
466        };
467        
468      if(!objname.CompareTo("RunInfo"))return &run_obj;      if(!objname.CompareTo("RunInfo"))return &run_obj;
469    
470        if(!objname.CompareTo("SoftInfo"))return &soft_obj; // Emiliano
471    
472      return NULL;      return NULL;
473  };  };
474  //--------------------------------------  //--------------------------------------
# Line 160  void *PamLevel2::GetPointerTo(const char Line 480  void *PamLevel2::GetPointerTo(const char
480   * (If seqno = -1 retrieves the self-trigger calorimeter track)   * (If seqno = -1 retrieves the self-trigger calorimeter track)
481   */   */
482   CaloTrkVar *PamLevel2::GetCaloStoredTrack(int seqno){   CaloTrkVar *PamLevel2::GetCaloStoredTrack(int seqno){
483                
484       if( CaloLevel2::ntrk()==0 ){       if( !calo2_obj )return 0;
485    
486         if( calo2_obj->CaloLevel2::ntrk()==0 ){
487           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;
488           return NULL;           return NULL;
489       };       };
# Line 170  void *PamLevel2::GetPointerTo(const char Line 492  void *PamLevel2::GetPointerTo(const char
492       Int_t it_calo=0;       Int_t it_calo=0;
493            
494       do{       do{
495           c = CaloLevel2::GetCaloTrkVar(it_calo);           c = calo2_obj->CaloLevel2::GetCaloTrkVar(it_calo);
496           it_calo++;           it_calo++;
497       } while( c && seqno != c->trkseqno && it_calo < CaloLevel2::ntrk());             } while( c && seqno != c->trkseqno && it_calo < calo2_obj->CaloLevel2::ntrk());    
498            
499       if(!c || seqno != c->trkseqno){       if(!c || seqno != c->trkseqno){
500           c = 0;           c = 0;
# Line 191  void *PamLevel2::GetPointerTo(const char Line 513  void *PamLevel2::GetPointerTo(const char
513   */   */
514   ToFTrkVar *PamLevel2::GetToFStoredTrack(int seqno){   ToFTrkVar *PamLevel2::GetToFStoredTrack(int seqno){
515                    
516       if( ToFLevel2::ntrk()==0 ){       if( !tof_obj )return 0;
517    
518         if( tof_obj->ToFLevel2::ntrk()==0 ){
519           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;
520           return NULL;           return NULL;
521       };       };
# Line 200  void *PamLevel2::GetPointerTo(const char Line 524  void *PamLevel2::GetPointerTo(const char
524       Int_t it_tof=0;       Int_t it_tof=0;
525            
526       do{       do{
527           c = ToFLevel2::GetToFTrkVar(it_tof);           c = tof_obj->ToFLevel2::GetToFTrkVar(it_tof);
528           it_tof++;           it_tof++;
529       } while( c && seqno != c->trkseqno && it_tof < ToFLevel2::ntrk());       } while( c && seqno != c->trkseqno && it_tof < tof_obj->ToFLevel2::ntrk());        
530            
531       if(!c || seqno != c->trkseqno){       if(!c || seqno != c->trkseqno){
532           c = 0;           c = 0;
# Line 220  void *PamLevel2::GetPointerTo(const char Line 544  void *PamLevel2::GetPointerTo(const char
544   * 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.
545   */   */
546   PamTrack* PamLevel2::GetPamTrackAlong(TrkTrack* t){   PamTrack* PamLevel2::GetPamTrackAlong(TrkTrack* t){
547                
548         cout <<"PamLevel2::GetPamTrackAlong(TrkTrack* t) **obsolete** "<<endl;
549         cout <<"(if you use it, remember to delete the PamTrack object)"<<endl;
550    
551       CaloTrkVar *c = 0;       CaloTrkVar *c = 0;
552       ToFTrkVar  *o = 0;       ToFTrkVar  *o = 0;
553            
# Line 245  void *PamLevel2::GetPointerTo(const char Line 572  void *PamLevel2::GetPointerTo(const char
572    
573  PamTrack* PamLevel2::GetStoredTrack(Int_t itrk){  PamTrack* PamLevel2::GetStoredTrack(Int_t itrk){
574            
575        cout <<"PamLevel2::GetStoredTrack(Int_t itrk) **to-be-updated** "<<endl;
576        cout <<"for the moment, better use separately the methods: TrkLevel2::GetStoredTrack(seqno) CaloLevel2::GetCaloTrkVar(Int_t notrack) ToFLevel2::GetToFTrkVar(Int_t notrack)"<<endl;
577        cout <<"(if you use it, remember to delete the PamTrack object)"<<endl;
578      PamTrack *track = 0;      PamTrack *track = 0;
579            
580      if( itrk >=0 && itrk < TrkLevel2::ntrk() ){      if( itrk >=0 && itrk < trk2_obj->TrkLevel2::ntrk() ){
581                    
582          TrkTrack *t = TrkLevel2::GetStoredTrack(itrk);          TrkTrack *t = trk2_obj->TrkLevel2::GetStoredTrack(itrk);
583          track = GetPamTrackAlong(t);          track = GetPamTrackAlong(t);
584                    
585            
586    
587      }else{      }else{
588          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;
589      };      };
590            
591      return track;      return track;
# Line 276  PamTrack* PamLevel2::GetStoredTrack(Int_ Line 608  PamTrack* PamLevel2::GetStoredTrack(Int_
608   */   */
609  void PamLevel2::SortTracks(TString how){  void PamLevel2::SortTracks(TString how){
610    
611    //    cout <<" PamLevel2::SortTracks(TString how) "<<endl;
612        if( !trk2_obj ){
613            cout << "void PamLevel2::SortTracks(TString how):  TrkLevel2 not loaded !!!";
614            return;
615        };
616  //    cout << "call SortTracs() "<<endl;  //    cout << "call SortTracs() "<<endl;
617    //Save current Object count    //Save current Object count
618      Int_t ObjectNumber = TProcessID::GetObjectCount();      Int_t ObjectNumber = TProcessID::GetObjectCount();
619    
620  //    cout << "ObjectNumber  "<<ObjectNumber <<endl;  //    cout << "ObjectNumber  "<<ObjectNumber <<endl;
621        
622      sorted_tracks->Delete(); //temporaneo???  //     if(!sorted_tracks)sorted_tracks = new TRefArray();
623            //     sorted_tracks->Clear();
624    //    sorted_tracks.Clear();
625    
626        if(!tsorted)tsorted = new TClonesArray("PamTrack",trk2_obj->GetNTracks());
627        tsorted->Delete();
628        TClonesArray &ttsorted = *tsorted;
629        if(!timage)timage = new TClonesArray("PamTrack",trk2_obj->GetNTracks());
630        timage->Delete();
631        TClonesArray &ttimage = *timage;
632    
633    
634      // loop over the tracks sorted by the tracker      // loop over the tracks sorted by the tracker
635      Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);      Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);
636      Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);      Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);
# Line 299  void PamLevel2::SortTracks(TString how){ Line 646  void PamLevel2::SortTracks(TString how){
646    
647      //   cout << "use_CAL "<<use_CAL<<" use_TOF "<<use_TOF<<" use_TRK "<<use_TRK <<endl;      //   cout << "use_CAL "<<use_CAL<<" use_TOF "<<use_TOF<<" use_TRK "<<use_TRK <<endl;
648            
649      for(Int_t i=0; i < TrkLevel2::GetNTracks(); i++){      for(Int_t i=0; i < trk2_obj->TrkLevel2::GetNTracks(); i++){
650                    
651          TrkTrack *ts = 0;          TrkTrack   *ts = 0;
652            CaloTrkVar *cs = 0;
653            ToFTrkVar  *os = 0;
654                    
655          // get tracker tracks          // get tracker tracks
656          TrkTrack   *tp = TrkLevel2::GetTrack(i);                    //tracker          TrkTrack   *tp = trk2_obj->TrkLevel2::GetTrack(i);                    //tracker
657          CaloTrkVar *cp = 0;          CaloTrkVar *cp = GetCaloStoredTrack(tp->GetSeqNo());
658          ToFTrkVar  *op = 0;          ToFTrkVar  *op = GetToFStoredTrack(tp->GetSeqNo());
659    
660            TrkTrack   *ti = 0;              //tracker (image)
661            CaloTrkVar *ci = 0;
662            ToFTrkVar  *oi = 0;
663  //      cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;  //      cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;
664          // if track has an image, check image selection          // if track has an image, check image selection
665          if(tp->HasImage()){          if(tp->HasImage()){
666                            
667              TrkTrack   *ti = TrkLevel2::GetTrackImage(i);              //tracker (image)              ti = trk2_obj->TrkLevel2::GetTrackImage(i);              //tracker (image)
668              CaloTrkVar *ci = 0;              ci = GetCaloStoredTrack(ti->GetSeqNo());
669              ToFTrkVar  *oi = 0;              oi = GetToFStoredTrack(ti->GetSeqNo());
670                            
671  //          cout << "its image "<<i << " "<<hex<< ti <<dec<< endl;  //          cout << "its image "<<i << " "<<hex<< ti <<dec<< endl;
672    
# Line 327  void PamLevel2::SortTracks(TString how){ Line 679  void PamLevel2::SortTracks(TString how){
679              // ------------------------              // ------------------------
680              // check the Y spatial residual on the first calorimeter plane              // check the Y spatial residual on the first calorimeter plane
681              // (cut on calorimeter variables from Emiliano)              // (cut on calorimeter variables from Emiliano)
682                if( use_CAL && !calo2_obj ){
683                    cout << "void PamLevel2::SortTracks(TString how): how= "<<how<<" but CaloLevel2 not loaded !!!";
684                    return;
685                };
686              if(              if(
687                  use_CAL            &&                  use_CAL            &&
688                  npcfit[1] > 15     &&   //no. of fit planes on Y view                  calo2_obj->npcfit[1] > 15     &&   //no. of fit planes on Y view
689                  varcfit[1] < 1000. &&  //fit variance on Y view                  calo2_obj->varcfit[1] < 1000. &&  //fit variance on Y view
690                    cp && ci &&
691                  true){                  true){
692    
                 cp = GetCaloStoredTrack(tp->GetSeqNo());  
                 ci = GetCaloStoredTrack(ti->GetSeqNo());  
693                                    
694                  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;
695                  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;
696                                    
697                  if(resy_p <= resy_i) tp_score++;                  if(resy_p <= resy_i) tp_score++;
698                  else                 ti_score++;                  else                 ti_score++;
# Line 350  void PamLevel2::SortTracks(TString how){ Line 705  void PamLevel2::SortTracks(TString how){
705              // ------------------------                  // ------------------------    
706              // check the number of hit pmts along the track              // check the number of hit pmts along the track
707              // on S12 S21 and S32, where paddles are parallel to Y axis              // on S12 S21 and S32, where paddles are parallel to Y axis
708              if( use_TOF ){              if( use_TOF && !tof_obj ){
709                    cout << "void PamLevel2::SortTracks(TString how): how= "<<how<<" but ToFLevel2 not loaded !!!";
710                    return;
711                };
712                if( use_TOF && op && oi ){
713                                    
714                  Int_t nphit_p =0;                  Int_t nphit_p =0;
715                  Int_t nphit_i =0;                  Int_t nphit_i =0;
716                                    
                 op = GetToFStoredTrack(tp->GetSeqNo());  
                 oi = GetToFStoredTrack(ti->GetSeqNo());  
717                                    
718  /*                              cout << "track: npmtadc "<< op->npmtadc << endl;  /*                              cout << "track: npmtadc "<< op->npmtadc << endl;
719                                  cout << "track: npmttdc "<< op->npmttdc << endl;                                  cout << "track: npmttdc "<< op->npmttdc << endl;
# Line 364  void PamLevel2::SortTracks(TString how){ Line 721  void PamLevel2::SortTracks(TString how){
721                                  cout << "image: npmttdc "<< oi->npmttdc << endl;*/                                  cout << "image: npmttdc "<< oi->npmttdc << endl;*/
722                                    
723                  for (Int_t ih=0; ih < op->npmtadc; ih++){                  for (Int_t ih=0; ih < op->npmtadc; ih++){
724                      Int_t pl = GetPlaneIndex( (op->pmtadc).At(ih) );                      Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
725                      if(pl == 1 || pl == 2 || pl == 5)nphit_p++;                      if(pl == 1 || pl == 2 || pl == 5)nphit_p++;
726                  };                  };
727                                    
728                  for (Int_t ih=0; ih < oi->npmtadc; ih++){                  for (Int_t ih=0; ih < oi->npmtadc; ih++){
729                      Int_t pl = GetPlaneIndex( (oi->pmtadc).At(ih) );                      Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
730                      if(pl == 1 || pl == 2 || pl == 5)nphit_i++;                      if(pl == 1 || pl == 2 || pl == 5)nphit_i++;
731                  };                  };
732                                    
# Line 399  void PamLevel2::SortTracks(TString how){ Line 756  void PamLevel2::SortTracks(TString how){
756              // ------------------------              // ------------------------
757              // the winner is....              // the winner is....
758              // ------------------------                  // ------------------------    
759              if      (tp_score > ti_score) ts = tp;//the track sorted by the tracker!!              if      (tp_score > ti_score) {
760              else if (tp_score < ti_score) ts = ti;//its image!!  //              ts = tp;//the track sorted by the tracker!!
761              else {  //              cs = cp;
762                  ts = tp;  //              os = op;
763                }else if (tp_score < ti_score) {
764                    ts = ti;//its image!!
765                    cs = ci;
766                    os = oi;
767    
768                    ti = tp;//its image!!
769                    ci = cp;
770                    oi = op;
771    
772                    tp = ts;//its image!!
773                    cp = cs;
774                    op = os;
775    
776                    
777                }else {
778    //              ts = tp;
779    //              cs = cp;
780    //              os = op;
781  //                              cout << "Warning - track image ambiguity not solved" << endl;  //                              cout << "Warning - track image ambiguity not solved" << endl;
782  //                              cout << ts->GetNtot() << " "<< ts->chi2 << " " << npcfit[1] << " "<< nphit_p << endl;  //                              cout << ts->GetNtot() << " "<< ts->chi2 << " " << npcfit[1] << " "<< nphit_p << endl;
783              };              };
784                            
785          }else{          }else{
786              ts = tp;  //          ts = tp;
787    //          cs = cp;
788    //          os = op;
789          };          };
790                    
791  //      cout <<" SortTracks() "<<i<<" -- "<<ts<<endl;  //      cout <<" SortTracks() "<<i<<" -- "<<ts<<endl;
792          sorted_tracks->Add(ts);//save the track in the sorted array  //      sorted_tracks->Add(ts);//save the track in the sorted array
793    //      sorted_tracks.Add(ts);//save the track in the sorted array
794    //      sorted_tracks.Add(tp);//save the track in the sorted array
795  //      cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl;  //      cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl;
796            //      cout<<"o "<<tp<<endl;
797    //      cout<<"o "<<cp<<endl;
798    //      cout<<"o "<<op<<endl;
799            new(ttsorted[i]) PamTrack(tp,cp,op);
800            new(ttimage[i])  PamTrack(ti,ci,oi);
801      };      };
802    
803        if( tsorted->GetEntries() != trk2_obj->GetNTracks() ){
804            cout << "void PamLevel2::SortTracks(TString how): tsorted->GetEntries() "<<tsorted->GetEntries()<<" != trk2_obj->GetNTracks() = "<<trk2_obj->GetNTracks() <<endl;
805            tsorted->Delete(); tsorted=0;
806            timage->Delete(); timage=0;    
807        }
808    
809      //Restore Object count      //Restore Object count
810      //To save space in the table keeping track of all referenced objects      //To save space in the table keeping track of all referenced objects
811      //we assume that our events do not address each other. We reset the      //We reset the object count to what it was at the beginning of the event.
     //object count to what it was at the beginning of the event.  
812      TProcessID::SetObjectCount(ObjectNumber);      TProcessID::SetObjectCount(ObjectNumber);
813            
814  };  };
# Line 431  void PamLevel2::SortTracks(TString how){ Line 820  void PamLevel2::SortTracks(TString how){
820   * 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.
821   * 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.
822   */   */
823  TRefArray *PamLevel2::GetTracks(){  // TRefArray *PamLevel2::GetTracks(){
824    
825    // //  *-*-*-*-*-*-*-*-*-*-*-*-*
826    //     SortTracks("+CAL+TOF");
827    // //  *-*-*-*-*-*-*-*-*-*-*-*-*
828    
829    // //   return  sorted_tracks;
830    //     return &sorted_tracks;
831        
832    //  };
833    TClonesArray *PamLevel2::GetTracks(){
834    
835  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
836      SortTracks("+CAL+TOF");      SortTracks("+CAL+TOF");
837  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
838    
839      return sorted_tracks;      return tsorted;
840        
841   };   };
842  //--------------------------------------  //--------------------------------------
843   //   //
# Line 449  TRefArray *PamLevel2::GetTracks(){ Line 849  TRefArray *PamLevel2::GetTracks(){
849   * @param it Track number, ranging from 0 to GetNTracks().   * @param it Track number, ranging from 0 to GetNTracks().
850   */   */
851  PamTrack *PamLevel2::GetTrack(int it){  PamTrack *PamLevel2::GetTrack(int it){
852    
853    //    if(!trk2_obj) return 0;
854                    
855    // //  *-*-*-*-*-*-*-*-*-*-*-*-*
856    //     SortTracks("+CAL+TOF");
857    // //  *-*-*-*-*-*-*-*-*-*-*-*-*
858    // //    if(!sorted_tracks)return 0;
859    //     if(sorted_tracks.IsEmpty())return 0;
860    
861    //     PamTrack *track = 0;
862        
863    //     if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks() && it<sorted_tracks.GetEntriesFast() ){    
864    //      TrkTrack   *t = (TrkTrack*)sorted_tracks.At(it);
865    //      track = GetPamTrackAlong(t);
866    //     }else{
867    //      cout << "PamLevel2::GetTrack(int) : tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl;
868    //     };
869        
870    //     return track;
871    
872    //    cout << "PamLevel2::GetTrack(int it) "<<endl;
873  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
874      SortTracks("+CAL+TOF");      SortTracks("+CAL+TOF");
875  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
876            if(!tsorted)return 0;
877        if(!tsorted->GetEntries())return 0;
878    
879      PamTrack *track = 0;      PamTrack *track = 0;
880            
881      if( it >=0 && it < TrkLevel2::GetNTracks() && it<sorted_tracks->GetEntriesFast() ){      if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks()){
882          TrkTrack   *t = (TrkTrack*)sorted_tracks->At(it);  //      TrkTrack   *t = (TrkTrack*)sorted_tracks.At(it);
883          track = GetPamTrackAlong(t);  //      track = GetPamTrackAlong(t);
884            TClonesArray &t = *(tsorted);
885            track = (PamTrack*)t[it];
886            
887      }else{      }else{
888          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;
889      };      };
890            
891      return track;      return track;
# Line 477  PamTrack *PamLevel2::GetTrack(int it){ Line 902  PamTrack *PamLevel2::GetTrack(int it){
902   */   */
903  PamTrack *PamLevel2::GetTrackImage(int it){  PamTrack *PamLevel2::GetTrackImage(int it){
904    
905    //     if(!trk2_obj) return 0;
906    
907    // //  *-*-*-*-*-*-*-*-*-*-*-*-*
908    //     SortTracks("+CAL+TOF");
909    // //  *-*-*-*-*-*-*-*-*-*-*-*-*
910    // //    if(!sorted_tracks)return 0;
911    //     if(sorted_tracks.IsEmpty())return 0;
912        
913    //     PamTrack *image = 0;
914        
915    //     if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks() ){
916    //      TrkTrack *temp = (TrkTrack*)sorted_tracks.At(it);
917    //      if( temp->HasImage() ){
918    //          TrkTrack   *t = trk2_obj->TrkLevel2::GetStoredTrack(temp->GetImageSeqNo());
919    //          image = GetPamTrackAlong(t);
920    //      }else{
921    //          cout <<"PamLevel2::GetTrackImage(int) : Track SeqNo "<<it<<" does not have image"<<endl;
922    //      };
923    //     }else{
924    //      cout << "PamLevel2::GetTrackImage(int) : Tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl;
925    //     };
926        
927    //     return image;
928    
929    
930  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
931      SortTracks("+CAL+TOF");      SortTracks("+CAL+TOF");
932  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
933        if(!timage)return 0;
934        if(!timage->GetEntries())return 0;
935            
936      PamTrack *image = 0;      PamTrack *image = 0;
937            
938      if( it >=0 && it < TrkLevel2::GetNTracks() ){      if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks() ){
939          TrkTrack *temp = (TrkTrack*)sorted_tracks->At(it);          TClonesArray &t = *(tsorted);
940          if( temp->HasImage() ){          PamTrack *temp = (PamTrack*)t[it];
941              TrkTrack   *t = TrkLevel2::GetStoredTrack(temp->GetImageSeqNo());          if( temp->GetTrkTrack()->HasImage() ){
942              image = GetPamTrackAlong(t);              TClonesArray &t = *(timage);
943                image = (PamTrack*)t[it];
944          }else{          }else{
945              cout <<"PamLevel2::GetTrackImage(int) : Track SeqNo "<<it<<" does not have image"<<endl;  //          cout <<"PamLevel2::GetTrackImage(int) : Track SeqNo "<<it<<" does not have image"<<endl;
946          };          };
947      }else{      }else{
948          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;
949      };      };
950            
951      return image;      return image;
# Line 512  TTree *PamLevel2::GetPamTree(TFile *f, T Line 965  TTree *PamLevel2::GetPamTree(TFile *f, T
965    
966  //     if( !detlist.IsNull() ) SetWhichTrees(detlist);  //     if( !detlist.IsNull() ) SetWhichTrees(detlist);
967  //     else                    GetWhichTrees(f);  //     else                    GetWhichTrees(f);
968      if ( pam_tree ){
969        printf("WARNING: TTree *PamLevel2::GetPamTree(TFile *fl, TString detlist) -- pam_tree already exists!\n ");
970        return pam_tree;
971      };
972      //
973    
974        cout << "TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ) -- obsolte "<<endl;
975    
976      SetWhichTrees(detlist);      SetWhichTrees(detlist);
977    
978      TTree *Trout =0;      TTree *Trout =0;
# Line 519  TTree *PamLevel2::GetPamTree(TFile *f, T Line 980  TTree *PamLevel2::GetPamTree(TFile *f, T
980      TString fname = f->GetName();      TString fname = f->GetName();
981      if(!CheckLevel2File(fname))return NULL;      if(!CheckLevel2File(fname))return NULL;
982    
983      UInt_t *found=0;      //    UInt_t *found=0;    
984    
985      cout<< "GetPamTree(TFile*,TString): detector list --> ";      cout<< "GetPamTree(TFile*,TString): detector list --> ";
986      if(TRK1)cout<<"TRK1 ";      if(TRK1)cout<<"TRK1 ";
# Line 534  TTree *PamLevel2::GetPamTree(TFile *f, T Line 995  TTree *PamLevel2::GetPamTree(TFile *f, T
995      if(S4)cout<<"S4 ";      if(S4)cout<<"S4 ";
996      if(ORB)cout<<"ORB ";      if(ORB)cout<<"ORB ";
997      cout << endl;      cout << endl;
998        if(SELLI)cout<<">>> Found selection-list <<<"<<endl;
999    
1000      f->cd();      f->cd();
1001    
# Line 541  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1003  TTree *PamLevel2::GetPamTree(TFile *f, T
1003      TTree *T = (TTree*)f->Get("Tracker");      TTree *T = (TTree*)f->Get("Tracker");
1004      if(T && (TRK2||TRK1||TRKh)) {      if(T && (TRK2||TRK1||TRKh)) {
1005          if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));          if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
1006          else    T->SetBranchStatus("TrkLevel2",0,found);  //      else    T->SetBranchStatus("TrkLevel2",0,found);
1007          if(TRK2)cout << "Tracker      : set branch address TrkLevel2"<<endl;          if(TRK2)cout << "Tracker      : set branch address TrkLevel2"<<endl;
1008          if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));          if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
1009          else    T->SetBranchStatus("TrkLevel1",0,found);  //      else    T->SetBranchStatus("TrkLevel1",0,found);
1010          if(TRK1)cout << "Tracker      : set branch address TrkLevel1"<<endl;          if(TRK1)cout << "Tracker      : set branch address TrkLevel1"<<endl;
1011          if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));          if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
1012          else    T->SetBranchStatus("TrkHough",0,found);  //      else    T->SetBranchStatus("TrkHough",0,found);
1013          if(TRKh)cout << "Tracker      : set branch address TrkHough"<<endl;          if(TRKh)cout << "Tracker      : set branch address TrkHough"<<endl;
1014          if(!Trout)Trout=T;          if(!Trout)Trout=T;
1015          else Trout->AddFriend(T);          else Trout->AddFriend(T);
# Line 558  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1020  TTree *PamLevel2::GetPamTree(TFile *f, T
1020      TTree *C = (TTree*)f->Get("Calorimeter");      TTree *C = (TTree*)f->Get("Calorimeter");
1021      if(C && (CAL2||CAL1)) {      if(C && (CAL2||CAL1)) {
1022          if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));          if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
1023          else    C->SetBranchStatus("CaloLevel2",0,found);  //      else    C->SetBranchStatus("CaloLevel2",0,found);
1024          if(CAL2)cout << "Calorimeter  : set branch address CaloLevel2"<<endl;          if(CAL2)cout << "Calorimeter  : set branch address CaloLevel2"<<endl;
1025          if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));          if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
1026          else    C->SetBranchStatus("CaloLevel1",0,found);  //      else    C->SetBranchStatus("CaloLevel1",0,found);
1027          if(CAL1)cout << "Calorimeter  : set branch address CaloLevel1"<<endl;          if(CAL1)cout << "Calorimeter  : set branch address CaloLevel1"<<endl;
1028          if(!Trout)Trout=C;          if(!Trout)Trout=C;
1029          else Trout->AddFriend(C);          else Trout->AddFriend(C);
# Line 584  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1046  TTree *PamLevel2::GetPamTree(TFile *f, T
1046      if(R && TRG) {      if(R && TRG) {
1047          R->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));          R->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));
1048          cout << "Trigger      : set branch address TrigLevel2"<<endl;          cout << "Trigger      : set branch address TrigLevel2"<<endl;
1049          if(!Trout)Trout=O;          if(!Trout)Trout=R;
1050          else Trout->AddFriend(R);          else Trout->AddFriend(R);
1051      }else{      }else{
1052          cout << "Trigger      : missing tree"<<endl;          cout << "Trigger      : missing tree"<<endl;
# Line 594  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1056  TTree *PamLevel2::GetPamTree(TFile *f, T
1056      if(S && S4) {      if(S && S4) {
1057          S->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));          S->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));
1058          cout << "S4           : set branch address S4Level2"<<endl;          cout << "S4           : set branch address S4Level2"<<endl;
1059          if(!Trout)Trout=O;          if(!Trout)Trout=S;
1060          else Trout->AddFriend(S);          else Trout->AddFriend(S);
1061      }else{      }else{
1062          cout << "S4           : missing tree"<<endl;          cout << "S4           : missing tree"<<endl;
# Line 604  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1066  TTree *PamLevel2::GetPamTree(TFile *f, T
1066      if(N && ND) {      if(N && ND) {
1067          N->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));          N->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));
1068          cout << "NeutronD     : set branch address NDLevel2"<<endl;          cout << "NeutronD     : set branch address NDLevel2"<<endl;
1069          if(!Trout)Trout=O;          if(!Trout)Trout=N;
1070          else Trout->AddFriend(N);          else Trout->AddFriend(N);
1071      }else{      }else{
1072          cout << "NeutronD     : missing tree"<<endl;          cout << "NeutronD     : missing tree"<<endl;
# Line 614  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1076  TTree *PamLevel2::GetPamTree(TFile *f, T
1076      if(A && AC) {      if(A && AC) {
1077          A->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));          A->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));
1078          cout << "Anticounter  : set branch address AcLevel2"<<endl;          cout << "Anticounter  : set branch address AcLevel2"<<endl;
1079          if(!Trout)Trout=O;          if(!Trout)Trout=A;
1080          else Trout->AddFriend(A);          else Trout->AddFriend(A);
1081      }else{      }else{
1082          cout << "Anticounter  : missing tree"<<endl;          cout << "Anticounter  : missing tree"<<endl;
# Line 624  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1086  TTree *PamLevel2::GetPamTree(TFile *f, T
1086      if(B && ORB) {      if(B && ORB) {
1087          B->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));          B->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
1088          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;
1089          if(!Trout)Trout=O;          if(!Trout)Trout=B;
1090          else Trout->AddFriend(B);          else Trout->AddFriend(B);
1091      }else{      }else{
1092          cout << "OrbitalInfo  : missing tree"<<endl;          cout << "OrbitalInfo  : missing tree"<<endl;
1093      };      };
1094    
1095        TTree *L = (TTree*)f->Get("SelectionList");
1096        if(L && SELLI==1) {
1097    //      L->SetBranchAddress("RunEntry",&irun);
1098    //      cout << "SelectionList: set branch address RunEntry"<<endl;
1099    //      L->SetBranchAddress("EventEntry",&irunentry);
1100    //      cout << "SelectionList: set branch address EventEntry"<<endl;
1101    //      if(!Trout)Trout=O;
1102    //      else Trout->AddFriend("SelectionList");
1103            cout << " TTree *PamLevel2::GetPamTree(TFile, TString) >>> SelectionList not implemente!!!!"<<endl;
1104            sel_tree = 0;
1105        }else{
1106            cout << "SelectionList  : missing tree"<<endl;
1107        };
1108            
1109      cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;      cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;
1110    
1111        pam_tree = (TChain*)Trout;
1112            
1113      return Trout;      return Trout;
1114            
# Line 650  TList*  PamLevel2::GetListOfLevel2Files( Line 1128  TList*  PamLevel2::GetListOfLevel2Files(
1128                    
1129      TString wdir = gSystem->WorkingDirectory();      TString wdir = gSystem->WorkingDirectory();
1130            
1131      if(ddir=="")ddir = wdir;      //    if(ddir=="")ddir = wdir;
1132  //      TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);  //      TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);
1133      cout << "Level2 data directory : "<<  ddir << endl;      if ( ddir != ""){
1134              cout << "Level2 data directory : "<<  ddir << endl;
1135        } else {
1136          cout << "Level2 data directory not given as input: trying to evaluate from list or taking working directory " << endl;
1137        };
1138      TList *contents  = new TList; // create output list      TList *contents  = new TList; // create output list
1139      contents->SetOwner();      contents->SetOwner();
1140            
1141      char *fullpath;  //    char *fullpath;
1142    //    const char *fullpath;
1143            
1144      // if no input file list is given:        // if no input file list is given:  
1145      if ( flisttxt != "" ){      if ( flisttxt != "" ){
1146                    
1147          if( !gSystem->IsFileInIncludePath(flisttxt,&fullpath) ){  //      if( !gSystem->IsFileInIncludePath(flisttxt,&fullpath) ){        
1148              cout <<"File "<<flisttxt<<" not found"<<endl;  //      if( !(fullpath = gSystem->FindFile("./",flisttxt)) ){
1149              return 0;  //          cout <<"File "<<flisttxt<<" not found"<<endl;
1150          }        //          return 0;
1151  //              flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));  //      }      
1152          flisttxt = fullpath;  //      flisttxt = fullpath;
1153                  if ( !flisttxt.EndsWith(".root") ){
1154    
1155            flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
1156    
1157          if( !gSystem->ChangeDirectory(ddir) ){          if( !gSystem->ChangeDirectory(ddir) ){
1158              cout << "Cannot change directory : "<<ddir<<endl;              cout << "Cannot change directory : "<<ddir<<endl;
1159              return 0;              return 0;
# Line 677  TList*  PamLevel2::GetListOfLevel2Files( Line 1162  TList*  PamLevel2::GetListOfLevel2Files(
1162          cout <<"Input file list : " << flisttxt <<endl;          cout <<"Input file list : " << flisttxt <<endl;
1163          ifstream in;          ifstream in;
1164          in.open(flisttxt, ios::in); //open input file list          in.open(flisttxt, ios::in); //open input file list
1165            if(!in.good()){
1166                cout <<" ERROR opening the file "<<endl;
1167                gSystem->ChangeDirectory(wdir); // back to the working directory
1168                return 0;
1169            }      
1170          int line=0;          int line=0;
1171          while (1) {          while (1) {
1172              TString file;              TString file;
# Line 690  TList*  PamLevel2::GetListOfLevel2Files( Line 1180  TList*  PamLevel2::GetListOfLevel2Files(
1180              }              }
1181              if(file.Contains("#"))file = file(0,file.First("#"));              if(file.Contains("#"))file = file(0,file.First("#"));
1182  //          cout <<"(2) " << file << endl;  //          cout <<"(2) " << file << endl;
1183              if( gSystem->IsFileInIncludePath(file,&fullpath) ){  //          if( gSystem->IsFileInIncludePath(file,&fullpath) ){
1184    //          if( (fullpath = gSystem->FindFile(ddir,file)) ){
1185                if( file.EndsWith(".root") ){
1186                  TString filedir;
1187                  if (ddir != ""){
1188                    filedir = ddir; // take the input dir
1189                  } else {
1190                    gSystem->ChangeDirectory(wdir); // back to the working directory
1191                    filedir = gSystem->DirName(file); // this will take the path if exist in the list otherwise it will return automatically the working dir
1192                  };
1193                    char *fullpath = gSystem->ConcatFileName(gSystem->DirName(filedir),gSystem->BaseName(file));
1194                  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
1195                    delete fullpath;
1196              }else{              }
1197    //          }else{
1198  //              if(file.Data()!="")cout << "File: "<<file<<" ---> missing "<< endl;  //              if(file.Data()!="")cout << "File: "<<file<<" ---> missing "<< endl;
1199              };  //          };
1200          };          };
1201          in.close();          in.close();
1202                  } else {
1203              if(flisttxt.Contains("#"))flisttxt = flisttxt(0,flisttxt.First("#"));
1204              char *fullpath = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
1205              contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list
1206              delete fullpath;
1207          };        
1208      }else{      }else{
1209                    
1210          cout << "No input file list given."<<endl;          cout << "No input file list given."<<endl;
1211          cout << "Check for existing root files."<<endl;          cout << "Check for existing root files."<<endl;
1212  //              cout << "Warking directory: "<< gSystem->WorkingDirectory()<< endl;  //              cout << "Warking directory: "<< gSystem->WorkingDirectory()<< endl;
1213                    if ( ddir == "" ){
1214              ddir = wdir;
1215              cout << "Level2 data directory : "<<  ddir << endl;
1216            };
1217    
1218          TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);          TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);
1219          TList *temp = datadir->GetListOfFiles();          TList *temp = datadir->GetListOfFiles();
1220  //              temp->Print();  //              temp->Print();
# Line 718  TList*  PamLevel2::GetListOfLevel2Files( Line 1227  TList*  PamLevel2::GetListOfLevel2Files(
1227          while ( (questo = (TSystemFile*) next()) ) {          while ( (questo = (TSystemFile*) next()) ) {
1228              TString name =  questo-> GetName();              TString name =  questo-> GetName();
1229              if( name.EndsWith(".root") ){              if( name.EndsWith(".root") ){
1230                  char *fullpath;  //              const char *fullpath = gSystem->FindFile(ddir,name);
1231                  gSystem->IsFileInIncludePath(name,&fullpath);  //              char *fullpath;
1232    //              gSystem->IsFileInIncludePath(name,&fullpath);
1233                    char *fullpath = gSystem->ConcatFileName(gSystem->DirName(ddir),gSystem->BaseName(name));
1234                  contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));                  contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));
1235                    delete fullpath;
1236              };              };
1237          }          }
1238          delete temp;          delete temp;
# Line 730  TList*  PamLevel2::GetListOfLevel2Files( Line 1242  TList*  PamLevel2::GetListOfLevel2Files(
1242      gSystem->ChangeDirectory(wdir); // back to the working directory      gSystem->ChangeDirectory(wdir); // back to the working directory
1243  //      cout << endl << "Selected files:" << endl;  //      cout << endl << "Selected files:" << endl;
1244  //      contents->Print();  //      contents->Print();
1245      cout << contents->GetEntries()<<" files selected\n";      cout << contents->GetEntries()<<" files \n";
1246  //      cout << endl;  //      cout << endl;
1247  //      cout << "Working directory: "<< gSystem->WorkingDirectory()<< endl;  //      cout << "Working directory: "<< gSystem->WorkingDirectory()<< endl;
1248      return contents;      return contents;
# Line 746  TList*  PamLevel2::GetListOfLevel2Files( Line 1258  TList*  PamLevel2::GetListOfLevel2Files(
1258   * @return Pointer to a TChain   * @return Pointer to a TChain
1259   */   */
1260  TChain *PamLevel2::GetPamTree(TList *fl, TString detlist ){  TChain *PamLevel2::GetPamTree(TList *fl, TString detlist ){
1261      //
1262      //
1263      //
1264      if ( pam_tree ){
1265        printf("WARNING: TChain *PamLevel2::GetPamTree(TList *fl, TString detlist) -- pam_tree already exists!\n ");
1266        return pam_tree;
1267      };
1268      //
1269            
1270      TChain *Trout =0;      TChain *Trout =0;
1271    
1272  //    if( !detlist.IsNull() )SetWhichTrees(detlist);  //    if( !detlist.IsNull() )SetWhichTrees(detlist);
1273      SetWhichTrees(detlist);      SetWhichTrees(detlist);
1274            
1275      cout<< "GetPamTree(TList*,TString): detector list --> ";      cout<< "GetPamTree(TList*,TString): input detector list --> ";
1276      if(TRK1)cout<<"TRK1 ";      if(TRK1)cout<<"TRK1 ";
1277      if(TRK2)cout<<"TRK2 ";      if(TRK2)cout<<"TRK2 ";
1278      if(TRKh)cout<<"TRKH ";      if(TRKh)cout<<"TRKH ";
# Line 766  TChain *PamLevel2::GetPamTree(TList *fl, Line 1286  TChain *PamLevel2::GetPamTree(TList *fl,
1286      if(ORB)cout<<"ORB ";      if(ORB)cout<<"ORB ";
1287      cout << endl;      cout << endl;
1288    
1289         TChain *T = 0;    
1290         TChain *C = 0;
1291         TChain *O = 0;
1292         TChain *R = 0;
1293         TChain *S = 0;
1294         TChain *N = 0;
1295         TChain *A = 0;
1296         TChain *B = 0;
1297    
1298             TChain *L = 0;
     TChain *T = 0;        
     TChain *C = 0;  
     TChain *O = 0;  
     TChain *R = 0;  
     TChain *S = 0;  
     TChain *N = 0;  
     TChain *A = 0;  
     TChain *B = 0;  
1299            
1300      if(TRK2||TRK1||TRKh) T = new TChain("Tracker");          if(TRK2||TRK1||TRKh) T = new TChain("Tracker");    
1301      if(CAL2||CAL1)       C = new TChain("Calorimeter");      if(CAL2||CAL1)       C = new TChain("Calorimeter");
# Line 785  TChain *PamLevel2::GetPamTree(TList *fl, Line 1305  TChain *PamLevel2::GetPamTree(TList *fl,
1305      if(ND)               N = new TChain("NeutronD");      if(ND)               N = new TChain("NeutronD");
1306      if(AC)               A = new TChain("Anticounter");      if(AC)               A = new TChain("Anticounter");
1307      if(ORB)              B = new TChain("OrbitalInfo");      if(ORB)              B = new TChain("OrbitalInfo");
1308         L = new TChain("SelectionList");
1309            
1310      // loop over files and create chains              // loop over files and create chains        
1311      TIter next(fl);      TIter next(fl);
1312      TSystemFile *questo = 0;      TSystemFile *questo = 0;
1313      while ( (questo = (TSystemFile*) next()) ) {      while ( (questo = (TSystemFile*) next()) ) {
1314          TString name =  questo->GetName();          TString name =  questo->GetName();
1315  //      cout << "File: "<< name << endl;          cout << "File: "<< name << endl;
1316          if( CheckLevel2File(name) ){          if( CheckLevel2File(name) ){
1317              if(TRK2||TRK1||TRKh) T->Add(name);              if(TRK2||TRK1||TRKh) T->Add(name);
1318              if(CAL1||CAL2)       C->Add(name);              if(CAL1||CAL2)       C->Add(name);
# Line 801  TChain *PamLevel2::GetPamTree(TList *fl, Line 1322  TChain *PamLevel2::GetPamTree(TList *fl,
1322              if(ND)               N->Add(name);              if(ND)               N->Add(name);
1323              if(AC)               A->Add(name);              if(AC)               A->Add(name);
1324              if(ORB)              B->Add(name);              if(ORB)              B->Add(name);
1325                if(SELLI==1)         L->Add(name);
1326          };          };
1327      }      };
1328            
1329      cout << "done chain \n";      cout << "done chain \n";
1330        cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
1331    
1332      UInt_t *found=0;  //    UInt_t *found=0;
1333  // Tracker  // Tracker
1334      if(T && (TRK2||TRK1||TRKh)) {      if(T && (TRK2||TRK1||TRKh)) {
1335          if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));          if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
1336          else    T->SetBranchStatus("TrkLevel2",0,found);  //      else    T->SetBranchStatus("TrkLevel2",0,found);
1337          if(TRK2)cout << "Tracker      : set branch address TrkLevel2"<<endl;          if(TRK2)cout << "Tracker      : set branch address TrkLevel2"<<endl;
1338          if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));          if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
1339          else    T->SetBranchStatus("TrkLevel1",0,found);  //      else    T->SetBranchStatus("TrkLevel1",0,found);
1340          if(TRK1)cout << "Tracker      : set branch address TrkLevel1"<<endl;          if(TRK1)cout << "Tracker      : set branch address TrkLevel1"<<endl;
1341          if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));          if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
1342          else    T->SetBranchStatus("TrkHough",0,found);  //      else    T->SetBranchStatus("TrkHough",0,found);
1343          if(TRKh)cout << "Tracker      : set branch address TrkHough"<<endl;          if(TRKh)cout << "Tracker      : set branch address TrkHough"<<endl;
1344          if(!Trout)Trout=T;          if(!Trout)Trout=T;
1345          else Trout->AddFriend("Tracker");          else Trout->AddFriend("Tracker");
1346      }else{      }else{
1347          cout << "Tracker      : missing tree"<<endl;          cout << "Tracker      : missing tree"<<endl;
1348      };      };
1349      // Calorimeter      // Calorimeter
1350      if(C && (CAL2||CAL1)) {      if(C && (CAL2||CAL1)) {
1351          if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));          if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
1352          else    C->SetBranchStatus("CaloLevel2",0,found);  //      else    C->SetBranchStatus("CaloLevel2",0,found);
1353          if(CAL2)cout << "Calorimeter  : set branch address CaloLevel2"<<endl;          if(CAL2)cout << "Calorimeter  : set branch address CaloLevel2"<<endl;
1354          if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));          if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
1355          else    C->SetBranchStatus("CaloLevel1",0,found);  //      else    C->SetBranchStatus("CaloLevel1",0,found);
1356          if(CAL1)cout << "Calorimeter  : set branch address CaloLevel1"<<endl;          if(CAL1)cout << "Calorimeter  : set branch address CaloLevel1"<<endl;
1357          if(!Trout)Trout=C;          if(!Trout)Trout=C;
1358          else Trout->AddFriend("Calorimeter");          else Trout->AddFriend("Calorimeter");
# Line 890  TChain *PamLevel2::GetPamTree(TList *fl, Line 1413  TChain *PamLevel2::GetPamTree(TList *fl,
1413      }else{      }else{
1414          cout << "OrbitalInfo  : missing tree"<<endl;          cout << "OrbitalInfo  : missing tree"<<endl;
1415      };      };
1416        cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
1417    
1418        // Selection List
1419        if(L && SELLI==1) {
1420            cout<<">>> Found selection-list <<<"<<endl;
1421            L->SetBranchAddress("RunEntry",&irun);
1422            cout << "SelectionList: set branch address RunEntry"<<endl;
1423            L->SetBranchAddress("EventEntry",&irunentry);
1424            cout << "SelectionList: set branch address EventEntry"<<endl;
1425            sel_tree = L;
1426    //      if(!Trout)Trout=O;
1427    //      else Trout->AddFriend("SelectionList");
1428            cout << "----------------------------------------------------" <<endl;
1429        }else{
1430    //      cout << "SelectionList  : missing tree"<<endl;
1431            if(L)L->Delete();
1432        };
1433            
1434  //    cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;  //    cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;
1435    
1436            pam_tree = Trout;
1437  //     // Tracker  
 //     if(TRK2||TRK1||TRKh){  
 //      if(!Tout)Tout=T;  
 //      else Tout->AddFriend("Tracker");  
 //     }  
 //     // Calorimeter  
 //     if(CAL2||CAL1) {          
 //      if(!Tout)Tout=C;  
 //      else Tout->AddFriend("Calorimeter");  
 //     };  
 //     // ToF      
 //     if(TOF) {  
 //      if(!Tout)Tout=O;  
 //      else Tout->AddFriend("ToF");  
 //     };  
 //     // Trigger  
 //     if(TRG) {  
 //      if(!Tout)Tout=R;  
 //      else Tout->AddFriend("Trigger");  
 //     };  
 //     // S4  
 //     if(S4) {  
 //      if(!Tout)Tout=S;  
 //      else Tout->AddFriend("S4");  
 //     };  
 //     // Neutron Detector  
 //     if(ND) {  
 //      if(!Tout)Tout=N;  
 //      else Tout->AddFriend("NeutronD");  
 //     };  
 //     // Anticounters  
 //     if(AC) {  
 //      if(!Tout)Tout=A;  
 //      else Tout->AddFriend("Anticounter");  
 //     };  
 //     // OrbitalInfo  
 //     if(ORB) {  
 //      if(!Tout)Tout=B;  
 //      else Tout->AddFriend("OrbitalInfo");  
 //     };  
       
 //    cout<<endl<<" Number of entries: "<<Tout->GetEntries()<<endl<<endl;  
       
 //    if( Tout->GetEntries() )PamLevel2::SetBranchAddress( Tout );  
       
1438      return Trout;      return Trout;
1439  }  }
1440    
# Line 1020  void PamLevel2::SetBranchAddress(TTree * Line 1516  void PamLevel2::SetBranchAddress(TTree *
1516          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
1517          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;
1518      };      };
1519        // SelectionList
1520        if(SELLI==1) {
1521            t->SetBranchAddress("RunEntry", &irun);
1522            cout << "SelectionList: set branch address RunEntry"<<endl;
1523            t->SetBranchAddress("EventEntry", &irunentry);
1524            cout << "SelectionList: set branch address EventEntry"<<endl;
1525        };
1526            
1527  }  }
1528  /**  /**
# Line 1093  void PamLevel2::SetBranchAddress(TChain Line 1596  void PamLevel2::SetBranchAddress(TChain
1596          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
1597          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;
1598      };      };
1599        // SelectionList
1600        if(SELLI==1) {
1601            t->SetBranchAddress("RunEntry", &irun);
1602            cout << "SelectionList: set branch address RunEntry"<<endl;
1603            t->SetBranchAddress("EventEntry", &irunentry);
1604            cout << "SelectionList: set branch address EventEntry"<<endl;
1605        };
1606            
1607  }  }
1608    
# Line 1107  void PamLevel2::SetBranchAddress(TChain Line 1617  void PamLevel2::SetBranchAddress(TChain
1617   * @return Pointer to a TChain   * @return Pointer to a TChain
1618   */   */
1619  TChain *PamLevel2::GetRunTree(TList *fl){  TChain *PamLevel2::GetRunTree(TList *fl){
1620              //
1621      TChain *R = new TChain("Run");    //
1622      //
1623      if ( run_tree ){
1624        printf("WARNING: TChain *PamLevel2::GetRunTree(TList *fl) -- run_tree already exists!\n ");
1625        return run_tree;
1626      };    
1627      //
1628      TChain *R = new TChain("Run");
1629            
1630      // loop over files and create chains              // loop over files and create chains        
1631      TIter next(fl);      TIter next(fl);
# Line 1120  TChain *PamLevel2::GetRunTree(TList *fl) Line 1637  TChain *PamLevel2::GetRunTree(TList *fl)
1637              R->Add(name);              R->Add(name);
1638          };          };
1639      }      }
1640    
1641        if(R->GetNtrees()){
1642            
1643      R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));          R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
1644      cout << "Run         : set branch address RunInfo"<<endl;          cout << "Run         : set branch address RunInfo"<<endl;
1645                R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
1646            cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano
1647        }else{
1648            delete R;
1649            R=0;
1650        }
1651    
1652        run_tree = R;
1653    
1654      return R;      return R;
1655            
1656  }  }
# Line 1137  TChain *PamLevel2::GetRunTree(TList *fl) Line 1664  TChain *PamLevel2::GetRunTree(TList *fl)
1664   * @return Pointer to a TTree   * @return Pointer to a TTree
1665   */   */
1666  TTree *PamLevel2::GetRunTree(TFile *f){  TTree *PamLevel2::GetRunTree(TFile *f){
1667      if ( run_tree ){
1668        printf("WARNING: TTree *PamLevel2::GetRunTree(TFile *f) -- run_tree already exists!\n ");
1669        return run_tree;
1670      };
1671            
1672    
1673        cout << "TTree *PamLevel2::GetRunTree(TFile *f) -- obsolte "<<endl;
1674    
1675      TTree *R = (TTree*)f->Get("Run");      TTree *T = (TTree*)f->Get("Run");
       
     R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));  
     cout << "Run         : set branch address RunInfo"<<endl;  
1676            
1677      return R;      if(T){
1678            T->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
1679            cout << "Run         : set branch address RunInfo"<<endl;
1680            T->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
1681            cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano
1682        }
1683    
1684        run_tree = (TChain*)T;
1685    
1686        return T;
1687            
1688  }  }
1689    /**
1690     * Update the runinfo informations (to be used to have Run infos event by event basis)
1691     * @param run Pointer to the chain/tree which contains run infos
1692     * @return true if a new run has been read, false if it is still the same run
1693     */
1694    Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev){
1695      //
1696      // check if we have already called once GetEntry, if not call it
1697      //
1698        cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev) --- NON FUNZIONA BENISSIMO.... "<<endl;
1699        if(!run){
1700              cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing RunInfo tree "<<endl;
1701              return(false);        
1702        }
1703        if ( run->GetEntries() <= 0 ) return(false);
1704      //
1705      
1706      //  Int_t oldrun = irun;
1707      Long64_t oldrun = irun;
1708    
1709      // --------------------------------------
1710      // if it is a full file (not preselected)
1711      // --------------------------------------
1712      if(SELLI==0){
1713    
1714          //
1715          // the absolute time is necessary to relate the event with the run
1716          //
1717          if( !GetOrbitalInfo() ){
1718              cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;
1719              return(false);
1720          }
1721    
1722          //
1723          // the first time the routine is called, set run search from the beginning
1724          //
1725          if ( irun < 0LL ){
1726              irun = 0LL;
1727              run->GetEntry(irun);
1728              runfirstentry = 0LL;
1729              runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
1730              if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;
1731          };      
1732          //
1733           if ( irun == run->GetEntries()-1LL &&
1734               !(GetOrbitalInfo()->absTime >= GetRunInfo()->RUNHEADER_TIME &&
1735                 GetOrbitalInfo()->absTime <= GetRunInfo()->RUNTRAILER_TIME)
1736                ){
1737             irun = -1LL;
1738             runfirstentry = 0LL;
1739             runlastentry = -1LL;
1740           };
1741          // modificato il controllo sull'aggiornamento del run, per evitare problemi
1742          // dovuti agli eventi annidati (NB! NEVENTS conta anche questi!!)
1743          //
1744          bool fromfirst = true;
1745          //
1746          while ( !(GetOrbitalInfo()->absTime >= GetRunInfo()->RUNHEADER_TIME && GetOrbitalInfo()->absTime <= GetRunInfo()->RUNTRAILER_TIME) && irun < run->GetEntries()-1LL ){
1747    //      while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){
1748              irun++;
1749              run->GetEntry(irun);
1750              runfirstentry = runlastentry;
1751              if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runfirstentry += 1LL;
1752              runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
1753    //        cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
1754    //        cout << "runfirstentry "<<runfirstentry<<endl;
1755              //      printf(" iev %llu %u %llu \n",iev,this->GetRunInfo()->NEVENTS,(ULong64_t)(runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS)));
1756              //      printf(" abstime %u trailertime %u \n",GetOrbitalInfo()->absTime,GetRunInfo()->RUNTRAILER_TIME);
1757              //      printf(" IDRUN %u \n",GetRunInfo()->ID);
1758              //
1759    //        prevshift = 0;
1760              //
1761              if ( irun == (Long64_t)(run->GetEntries()-1LL) && fromfirst && !(GetOrbitalInfo()->absTime >= GetRunInfo()->RUNHEADER_TIME && GetOrbitalInfo()->absTime <= GetRunInfo()->RUNTRAILER_TIME)){
1762                  printf(" resetting irun  (it should NOT happen!!!)\n");
1763                  fromfirst = false;
1764                  irun = 0;
1765                  run->GetEntry(irun);
1766                  runfirstentry = 0ULL;
1767                  runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
1768                  if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;
1769              };
1770              //
1771          };
1772          //
1773          if (
1774               !(GetOrbitalInfo()->absTime >= GetRunInfo()->RUNHEADER_TIME &&
1775                 GetOrbitalInfo()->absTime <= GetRunInfo()->RUNTRAILER_TIME)
1776              ) {
1777              printf(" Something very wrong here: cannot find RUN containing absolute time %u \n",GetOrbitalInfo()->absTime);
1778              return false;
1779          }
1780          //
1781          if ( irun == oldrun || irun >= run->GetEntries() ) return(false);
1782          //
1783          //  printf(" iev %llu irun %i nevents %u 1st %llu last %llu \n",iev,irun,this->GetRunInfo()->NEVENTS,(ULong64_t)runfirstentry,(ULong64_t)runlastentry);
1784          //
1785          prevshift = 0;
1786          cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
1787    //      cout << "runfirstentry "<<runfirstentry<<endl;
1788          return(true);    
1789      };
1790      // ----------------------------------------------------
1791      // if it is a preselected file (there is SelectionList)
1792      // NBNB - the event tree MUST be read first
1793      // ----------------------------------------------------
1794      if(SELLI==1){      
1795          sel_tree->GetEntry(iev);
1796    //      cout << irun << " "<< irunentry << endl;
1797          if(irun != oldrun){
1798              run->GetEntry(irun);
1799              cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
1800              prevshift = 0;
1801              return true;
1802          }
1803          return false;
1804      }
1805    
1806      return false;
1807      //
1808    };
1809    
1810    Bool_t PamLevel2::UpdateRunInfo(Long64_t iev){
1811    
1812        if(!run_tree){
1813            cout << " Bool_t PamLevel2::UpdateRunInfo(ULong64_t iev) -- ERROR -- run tree not loaded"<<endl;
1814            return false;
1815        }
1816        if ( run_tree->GetEntries() <= 0 ) {
1817            cout << " Bool_t PamLevel2::UpdateRunInfo(ULong64_t iev) -- ERROR -- run tree is empty"<<endl;
1818            return(false);
1819        }
1820      
1821        Int_t oldrun = irun; // store current run index
1822    
1823        // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
1824        // if it is a full file (not preselected)
1825        // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
1826        if(SELLI==0){
1827    
1828            // ---------------------------------------------------------------
1829            // the absolute time is necessary to relate the event with the run
1830            // ---------------------------------------------------------------
1831            if( !GetOrbitalInfo() ){
1832                cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;
1833                return(false);
1834            }
1835          
1836            // -----------------------------------------------------------------------
1837            // the first time the routine is called, set run search from the beginning
1838            // -----------------------------------------------------------------------
1839            if ( irun < 0 ){
1840                irun = 0LL;
1841                run_tree->GetEntry(irun);
1842            };      
1843            //
1844            bool fromfirst = true; // first loop over runs
1845            // ------------------------------------------------------
1846            // loop over runs to find the one that contains the event
1847            // ------------------------------------------------------
1848            while ( !(GetOrbitalInfo()->absTime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s)
1849                      GetOrbitalInfo()->absTime <= GetRunInfo()->RUNTRAILER_TIME) &&
1850                    !(GetOrbitalInfo()->OBT >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms)
1851                      GetOrbitalInfo()->OBT <= GetRunInfo()->RUNTRAILER_OBT) &&
1852                    irun < run_tree->GetEntries() ){
1853                irun++;
1854                // ------------------------------------
1855                // if the end of run tree is reached...
1856                // ------------------------------------
1857                if( irun == run_tree->GetEntries() ){
1858                    if(!fromfirst){
1859                        // -----------------------------------------------------
1860                        // if it happened already once and the run was not found
1861                        // ---> exit with error
1862                        // -----------------------------------------------------
1863                        cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- ERROR -- event entry #"<<iev<<" does not belong to any run (should not happen)" <<endl;
1864                        return false;
1865                    }
1866                    // -----------------------------------------
1867                    // ...otherwise repeat search from beginning
1868                    // -----------------------------------------
1869                    cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- reached end of run tree. searchin again from beginning " <<endl;
1870                    fromfirst = false;
1871                    irun = 0LL;
1872                    runfirstentry = 0LL;
1873                }
1874                // -------------------------------------------------------------------
1875                // save the index of the first entry of the run, relative to pam_tree,
1876                // and read a new run
1877                // -------------------------------------------------------------------
1878                if(irun>0)runfirstentry += (GetRunInfo()->NEVENTS);
1879                run_tree->GetEntry(irun);      
1880                if(GetRunInfo()->RUNHEADER_OBT>=GetRunInfo()->RUNTRAILER_OBT ){
1881                    cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- irun "<<irun<<"  has RUNHEADER_OBT>=RUNTRAILER_OBT " <<endl;
1882                    cout << "                                                            (NB!! in this case some events are assigned to a wrong run)"<<endl;
1883                }
1884            };
1885            // --------------------------------------
1886            // if there was no need to update the run
1887            // ---> exit with FALSE
1888            // --------------------------------------
1889            if ( irun == oldrun ) return(false);
1890    
1891            // --------------------------------------
1892            // ... otherwise
1893            // ---> exit with TRUE
1894            // --------------------------------------
1895            cout << endl << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
1896            prevshift = 0;
1897            return(true);    
1898        };
1899        // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
1900        // if it is a preselected file (there is SelectionList)
1901        // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
1902        if(SELLI==1){      
1903            sel_tree->GetEntry(iev);
1904            if(irun != oldrun){
1905                run_tree->GetEntry(irun);
1906                cout << endl << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
1907                prevshift = 0;
1908                return true;
1909            }
1910            return false;
1911        }
1912    
1913        return false;
1914        //
1915    };
1916    /**
1917     * Update the runinfo informations (to be used to have Run infos event by event basis)
1918     * @param run Pointer to the chain/tree which contains run infos
1919     * @return true if a new run has been read, false if it is still the same run
1920     */
1921    Bool_t PamLevel2::UpdateRunInfo(TTree *run, Long64_t iev){
1922      return(UpdateRunInfo((TChain*)run,iev));
1923    };
1924    
1925  //--------------------------------------  //--------------------------------------
1926  //  //
1927  //  //
# Line 1158  TTree *PamLevel2::GetRunTree(TFile *f){ Line 1933  TTree *PamLevel2::GetRunTree(TFile *f){
1933  void PamLevel2::SetWhichTrees(TString detlist){  void PamLevel2::SetWhichTrees(TString detlist){
1934                    
1935      if(detlist.IsNull() || detlist.Contains("+ALL", TString::kIgnoreCase)){      if(detlist.IsNull() || detlist.Contains("+ALL", TString::kIgnoreCase)){
1936            CAL0 = false;
1937          CAL1 = true;          CAL1 = true;
1938          CAL2 = true;          CAL2 = true;
1939          TRK2 = true;          TRK2 = true;
1940          TRK1 = false;          TRK1 = false;
1941          TRKh = false;          TRKh = false;
1942            TRK0 = false;
1943          TRG = true;          TRG = true;
1944          TOF = true;          TOF = true;
1945            TOF0 = false;
1946          S4  = true;          S4  = true;
1947          ND  = true;          ND  = true;
1948          AC  = true;          AC  = true;
1949          ORB = true;          ORB = true;
1950      }else if( detlist.Contains("-ALL", TString::kIgnoreCase) ){      }else if( detlist.Contains("-ALL", TString::kIgnoreCase) ){
1951            CAL0 = false;
1952          CAL1 = false;          CAL1 = false;
1953          CAL2 = false;          CAL2 = false;
1954          TRK2 = false;          TRK2 = false;
1955          TRK1 = false;          TRK1 = false;
1956          TRKh = false;          TRKh = false;
1957            TRK0 = false;
1958          TRG = false;          TRG = false;
1959          TOF = false;          TOF = false;
1960            TOF0 = false;
1961          S4  = false;          S4  = false;
1962          ND  = false;          ND  = false;
1963          AC  = false;          AC  = false;
# Line 1188  void PamLevel2::SetWhichTrees(TString de Line 1969  void PamLevel2::SetWhichTrees(TString de
1969          if ( detlist.Contains("-CAL1", TString::kIgnoreCase) )CAL1=false;          if ( detlist.Contains("-CAL1", TString::kIgnoreCase) )CAL1=false;
1970          if ( detlist.Contains("+CAL1", TString::kIgnoreCase) )CAL1=true;          if ( detlist.Contains("+CAL1", TString::kIgnoreCase) )CAL1=true;
1971      };      };
1972    
1973        if( detlist.Contains("CAL0", TString::kIgnoreCase) ){
1974            if ( detlist.Contains("-CAL0", TString::kIgnoreCase) )CAL0=false;
1975            if ( detlist.Contains("+CAL0", TString::kIgnoreCase) )CAL0=true;
1976        };
1977                    
1978      if( detlist.Contains("CAL2", TString::kIgnoreCase)){      if( detlist.Contains("CAL2", TString::kIgnoreCase)){
1979          if ( detlist.Contains("-CAL2", TString::kIgnoreCase) )CAL2=false;          if ( detlist.Contains("-CAL2", TString::kIgnoreCase) )CAL2=false;
# Line 1200  void PamLevel2::SetWhichTrees(TString de Line 1986  void PamLevel2::SetWhichTrees(TString de
1986          CAL1=false;          CAL1=false;
1987      }      }
1988  //  -------------------------------------------------------------------------  //  -------------------------------------------------------------------------
1989        if( detlist.Contains("TRK0", TString::kIgnoreCase) ){
1990            if ( detlist.Contains("-TRK0", TString::kIgnoreCase) )TRK0=false;
1991            if ( detlist.Contains("+TRK0", TString::kIgnoreCase) )TRK0=true;
1992        };
1993    
1994      if( detlist.Contains("TRK1", TString::kIgnoreCase) ){      if( detlist.Contains("TRK1", TString::kIgnoreCase) ){
1995          if ( detlist.Contains("-TRK1", TString::kIgnoreCase) )TRK1=false;          if ( detlist.Contains("-TRK1", TString::kIgnoreCase) )TRK1=false;
1996          if ( detlist.Contains("+TRK1", TString::kIgnoreCase) )TRK1=true;          if ( detlist.Contains("+TRK1", TString::kIgnoreCase) )TRK1=true;
# Line 1228  void PamLevel2::SetWhichTrees(TString de Line 2019  void PamLevel2::SetWhichTrees(TString de
2019            
2020      if( detlist.Contains("-TOF", TString::kIgnoreCase) )TOF = false;      if( detlist.Contains("-TOF", TString::kIgnoreCase) )TOF = false;
2021      else if( detlist.Contains("+TOF", TString::kIgnoreCase) )TOF = true;      else if( detlist.Contains("+TOF", TString::kIgnoreCase) )TOF = true;
2022    
2023        if( detlist.Contains("-TOF0", TString::kIgnoreCase) )TOF0 = false;
2024        else if( detlist.Contains("+TOF0", TString::kIgnoreCase) )TOF0 = true;
2025            
2026      if( detlist.Contains("-S4",  TString::kIgnoreCase) )S4  = false;      if( detlist.Contains("-S4",  TString::kIgnoreCase) )S4  = false;
2027      else if( detlist.Contains("+S4",  TString::kIgnoreCase) )S4  = true;      else if( detlist.Contains("+S4",  TString::kIgnoreCase) )S4  = true;
# Line 1262  void PamLevel2::SetWhichTrees(TString de Line 2056  void PamLevel2::SetWhichTrees(TString de
2056   * Set tree/branch detector flags from the content of a tree   * Set tree/branch detector flags from the content of a tree
2057   */   */
2058  void  PamLevel2::GetWhichTrees(TFile* f){  void  PamLevel2::GetWhichTrees(TFile* f){
2059                
2060    
2061    
2062        cout << "void  PamLevel2::GetWhichTrees(TFile* f) --- WARNING!! --- ...potrebbe non funzionare "<<endl;
2063      // -----------      // -----------
2064      // reset flags      // reset flags
2065      // -----------      // -----------
# Line 1389  void  PamLevel2::GetWhichTrees(TFile* f) Line 2185  void  PamLevel2::GetWhichTrees(TFile* f)
2185    
2186      };      };
2187            
2188      lk->Delete();      delete lk;
2189    
2190  //     cout<< "Get detector list from input file --> ";  //     cout<< "Get detector list from input file --> ";
2191  //     if(TRK1)cout<<"TRK1 ";  //     if(TRK1)cout<<"TRK1 ";
# Line 1435  Bool_t  PamLevel2::CheckLevel2File(TStri Line 2231  Bool_t  PamLevel2::CheckLevel2File(TStri
2231            
2232      Bool_t RUN__ok    = false;      Bool_t RUN__ok    = false;
2233            
2234            Bool_t SELLI__ok  = false;
2235    
2236      cout << "Checking file: "<<name<<endl;      cout << "Checking file: "<<name<<endl;
2237      TFile *f = new TFile(name.Data());      TFile *f = new TFile(name.Data());
# Line 1452  Bool_t  PamLevel2::CheckLevel2File(TStri Line 2248  Bool_t  PamLevel2::CheckLevel2File(TStri
2248    
2249      while( (key = (TKey*)next()) ){      while( (key = (TKey*)next()) ){
2250                    
2251    //      cout << key->GetName() << endl;
2252  //      cout << key->GetName() << ""<<key->GetClassName()<<endl;  //      cout << key->GetName() << ""<<key->GetClassName()<<endl;
2253  //              cout << " Get tree: " << f->Get(key->GetName())<<endl;  //              cout << " Get tree: " << f->Get(key->GetName())<<endl;
2254  //      nev_previous = nev;  //      nev_previous = nev;
# Line 1462  Bool_t  PamLevel2::CheckLevel2File(TStri Line 2259  Bool_t  PamLevel2::CheckLevel2File(TStri
2259  //          return false;  //          return false;
2260  //      };  //      };
2261    
2262    
2263          if( !strcmp(key->GetName(),"Run"        ) )RUN__ok = true;                if( !strcmp(key->GetName(),"Run"        ) )RUN__ok = true;      
2264    
2265          //=========================================================              //=========================================================    
2266            if( !strcmp(key->GetName(),"SelectionList"    ) ){
2267                SELLI__ok = true;
2268                if(SELLI==1){
2269                    Int_t nevt = ((TTree*)f->Get("SelectionList"))->GetEntries();
2270                    if( nev && nevt!=nev){
2271                        cout << "File: "<< f->GetName() <<" discarded ---- SelectionList tree has "<<nevt<<" events instead of "<<nev<< endl;
2272                        return false;
2273                    }
2274                    nev=nevt;
2275                }
2276            }
2277    
2278            //=========================================================    
2279          if( !strcmp(key->GetName(),"Trigger"    ) ){          if( !strcmp(key->GetName(),"Trigger"    ) ){
2280              TRG__ok = true;              TRG__ok = true;
2281              if(TRG){              if(TRG){
# Line 1576  Bool_t  PamLevel2::CheckLevel2File(TStri Line 2387  Bool_t  PamLevel2::CheckLevel2File(TStri
2387          };                };      
2388    
2389      };      };
2390    
2391        if( SELLI==-1 )SELLI = (Int_t)SELLI__ok;
2392        if( SELLI==0 && SELLI__ok ){
2393            cout << "File: "<< f->GetName() <<" discarded ---- found SelectionList (it is not a full-event file)" << endl;
2394            return false;  
2395        }
2396        if( SELLI==1 && !SELLI__ok ){
2397            cout << "File: "<< f->GetName() <<" discarded ---- SelectionList missing" << endl;
2398            return false;
2399        }
2400            
2401    //    cout << "SELLI "<<SELLI<<endl;
2402    
2403  //     cout<< "CheckLevel2File(TString): detector list --> ";  //     cout<< "CheckLevel2File(TString): detector list --> ";
2404  //     if(TRK1__ok)cout<<"TRK1 ";  //     if(TRK1__ok)cout<<"TRK1 ";
2405  //     if(TRK2__ok)cout<<"TRK2 ";  //     if(TRK2__ok)cout<<"TRK2 ";
# Line 1592  Bool_t  PamLevel2::CheckLevel2File(TStri Line 2415  Bool_t  PamLevel2::CheckLevel2File(TStri
2415  //     cout << endl;  //     cout << endl;
2416    
2417    
2418        if(TRK2 && TRK1__ok)TRK1=1;
2419    // ----------------------------------------------------------------------------
2420    // NOTA
2421    // se c'e` il level1, lo devo necessarimente leggere.
2422    // infatti (non ho capito perche`) i cluster vengono letti e allocati in memoria
2423    // comunque, ma non vengono disallocati da PamLevel2::Clear()
2424    // ----------------------------------------------------------------------------
2425    
2426    
2427      if(!RUN__ok) {      if(!RUN__ok) {
2428          cout << "File: "<< f->GetName() <<" *WARNING* ---- Missing RunInfo tree"<< endl;          cout << "File: "<< f->GetName() <<" *WARNING* ---- Missing RunInfo tree"<< endl;
2429  //      return false;  //      return false;
# Line 1644  Bool_t  PamLevel2::CheckLevel2File(TStri Line 2476  Bool_t  PamLevel2::CheckLevel2File(TStri
2476      };      };
2477            
2478    
2479      lk->Delete();  //    lk->Delete();
2480    //    delete lk;
2481      f->Close();      f->Close();
2482    
2483  //     cout<< "CheckLevel2File(TString): detector list --> ";  //     cout<< "CheckLevel2File(TString): detector list --> ";
# Line 1675  void PamLevel2::CreateCloneTrees0( TChai Line 2508  void PamLevel2::CreateCloneTrees0( TChai
2508      cout << "Create clones of PAMELA trees "<<endl;      cout << "Create clones of PAMELA trees "<<endl;
2509            
2510      Int_t i=0;      Int_t i=0;
2511      tree_clone[i] = fChain->GetTree()->CloneTree(0);      pam_tree_clone[i] = fChain->GetTree()->CloneTree(0);
2512      TString name =  tree_clone[i]->GetName();      TString name =  pam_tree_clone[i]->GetName();
2513      name.Append("_clone");      name.Append("_clone");
2514  //    tree_clone[i]->SetName(name.Data());  //    pam_tree_clone[i]->SetName(name.Data());
2515      cout << tree_clone[i]->GetName() <<endl;      cout << pam_tree_clone[i]->GetName() <<endl;
2516      i++;      i++;
2517    
2518      TList *li = fChain->GetListOfFriends();      TList *li = fChain->GetListOfFriends();
# Line 1689  void PamLevel2::CreateCloneTrees0( TChai Line 2522  void PamLevel2::CreateCloneTrees0( TChai
2522      while( (T_friend = (TFriendElement*)next()) ){      while( (T_friend = (TFriendElement*)next()) ){
2523  //      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;
2524  //      cout<<T_friend->GetTree()->GetName()<< endl;  //      cout<<T_friend->GetTree()->GetName()<< endl;
2525          tree_clone[i] = T_friend->GetTree()->CloneTree(0);          pam_tree_clone[i] = T_friend->GetTree()->CloneTree(0);
2526          tree_clone[i]->SetAutoSave(1000000);          pam_tree_clone[i]->SetAutoSave(1000000);
2527          name =  tree_clone[i]->GetName();          name =  pam_tree_clone[i]->GetName();
2528          name.Append("_clone");          name.Append("_clone");
2529  //      tree_clone[i]->SetName(name.Data());  //      pam_tree_clone[i]->SetName(name.Data());
2530          cout << tree_clone[i]->GetName() << endl;          cout << pam_tree_clone[i]->GetName() << endl;
2531          i++;          i++;
2532      }      }
2533        
2534        delete li;
2535    
2536      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2537    
# Line 1712  void PamLevel2::CreateCloneTrees(TFile * Line 2547  void PamLevel2::CreateCloneTrees(TFile *
2547      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2548      cout << "Create new PAMELA trees "<<endl;      cout << "Create new PAMELA trees "<<endl;
2549                    
     Int_t i=0;  
2550    
2551        run_tree_clone = new TTree("Run","PAMELA Level2 data from the GL_RUN table ");
2552        run_tree_clone->Branch("RunInfo","GL_RUN",GetPointerTo("RunInfo"));
2553        cout << "Run          : branch RunInfo"<<endl;
2554        run_tree_clone->Branch("SoftInfo","SoftInfo",GetPointerTo("SoftInfo"));
2555        cout << "Run          : branch SoftInfo"<<endl;
2556        // ------------------
2557        // replicate run tree
2558        // ------------------
2559        cout << "----------------------------------------------------"<<endl;
2560        cout << "irun\t | RUN\t NEVENTS\t absolute time"<<endl;
2561        for (Int_t i=0; i<run_tree->GetEntries(); i++){
2562            run_tree->GetEntry(i);
2563            cout << i<< "\t | "<<GetRunInfo()->ID<<"\t "<<GetRunInfo()->NEVENTS<< "\t "<<GetRunInfo()->RUNHEADER_TIME<<" <---> "<<GetRunInfo()->RUNTRAILER_TIME<<endl;
2564            run_tree_clone->Fill();
2565        }
2566        cout << "----------------------------------------------------"<<endl;
2567    
2568    
2569        sel_tree_clone = new TTree("SelectionList","List of selected events ");
2570        sel_tree_clone->Branch("RunEntry",&irun,"runentry/L");
2571        sel_tree_clone->Branch("EventEntry",&irunentry,"eventry/L");
2572        
2573    
2574        Int_t i=0;
2575      if(TRK1||TRK2||TRKh){      if(TRK1||TRK2||TRKh){
2576          tree_clone[i] = new TTree("Tracker","PAMELA tracker level2 data ");              pam_tree_clone[i] = new TTree("Tracker","PAMELA tracker level2 data ");
2577          if(TRK1) {          if(TRK1) {
2578              tree_clone[i]->Branch("TrkLevel1","TrkLevel1", GetPointerTo("TrkLevel1"));              pam_tree_clone[i]->Branch("TrkLevel1","TrkLevel1", GetPointerTo("TrkLevel1"));
2579              tree_clone[i]->BranchRef();              pam_tree_clone[i]->BranchRef();
2580              cout << "Tracker      : branch TrkLevel1"<<endl;              cout << "Tracker      : branch TrkLevel1"<<endl;
2581    //          cout << "CreateCloneTrees " << GetTrkLevel1()<<endl;
2582          };          };
2583          if(TRK2) {          if(TRK2) {
2584              tree_clone[i]->Branch("TrkLevel2", "TrkLevel2",GetPointerTo("TrkLevel2"));              pam_tree_clone[i]->Branch("TrkLevel2", "TrkLevel2",GetPointerTo("TrkLevel2"));
2585              cout << "Tracker      : branch TrkLevel2"<<endl;                      cout << "Tracker      : branch TrkLevel2"<<endl;        
2586          };          };
2587          if(TRKh) {          if(TRKh) {
2588              tree_clone[i]->Branch("TrkHough","TrkHough", GetPointerTo("TrkHough"));              pam_tree_clone[i]->Branch("TrkHough","TrkHough", GetPointerTo("TrkHough"));
2589              cout << "Tracker      : branch TrkHough"<<endl;              cout << "Tracker      : branch TrkHough"<<endl;
2590          };          };
2591          i++;          i++;
# Line 1734  void PamLevel2::CreateCloneTrees(TFile * Line 2593  void PamLevel2::CreateCloneTrees(TFile *
2593    
2594      // Calorimeter      // Calorimeter
2595      if(CAL1||CAL2){      if(CAL1||CAL2){
2596          tree_clone[i] = new TTree("Calorimeter","PAMELA calorimeter level2 data ");              pam_tree_clone[i] = new TTree("Calorimeter","PAMELA calorimeter level2 data ");
2597          if(CAL1) {          if(CAL1) {
2598              tree_clone[i]->Branch("CaloLevel1", "CaloLevel1", GetPointerTo("CaloLevel1"));              pam_tree_clone[i]->Branch("CaloLevel1", "CaloLevel1", GetPointerTo("CaloLevel1"));
2599              cout << "Calorimeter  : branch CaloLevel1"<<endl;              cout << "Calorimeter  : branch CaloLevel1"<<endl;
2600          };          };
2601          if(CAL2) {          if(CAL2) {
2602              tree_clone[i]->Branch("CaloLevel2","CaloLevel2", GetPointerTo("CaloLevel2"));              pam_tree_clone[i]->Branch("CaloLevel2","CaloLevel2", GetPointerTo("CaloLevel2"));
2603              cout << "Calorimeter  : branch CaloLevel2"<<endl;              cout << "Calorimeter  : branch CaloLevel2"<<endl;
2604          };          };
2605          i++;          i++;
# Line 1748  void PamLevel2::CreateCloneTrees(TFile * Line 2607  void PamLevel2::CreateCloneTrees(TFile *
2607    
2608      // ToF          // ToF    
2609      if(TOF) {      if(TOF) {
2610          tree_clone[i] = new TTree("ToF","PAMELA ToF level2 data ");              pam_tree_clone[i] = new TTree("ToF","PAMELA ToF level2 data ");
2611          tree_clone[i]->Branch("ToFLevel2","ToFLevel2", GetPointerTo("ToFLevel2"));          pam_tree_clone[i]->Branch("ToFLevel2","ToFLevel2", GetPointerTo("ToFLevel2"));
2612          cout << "ToF          : branch ToFLevel2"<<endl;          cout << "ToF          : branch ToFLevel2"<<endl;
2613          i++;          i++;
2614      };      };
2615      // Trigger      // Trigger
2616      if(TRG) {      if(TRG) {
2617          tree_clone[i] = new TTree("Trigger","PAMELA trigger level2 data ");              pam_tree_clone[i] = new TTree("Trigger","PAMELA trigger level2 data ");
2618          tree_clone[i]->Branch("TrigLevel2","TrigLevel2", GetPointerTo("TrigLevel2"));          pam_tree_clone[i]->Branch("TrigLevel2","TrigLevel2", GetPointerTo("TrigLevel2"));
2619          cout << "Trigger      : branch TrigLevel2"<<endl;          cout << "Trigger      : branch TrigLevel2"<<endl;
2620          i++;          i++;
2621      };      };
2622      // S4      // S4
2623      if(S4) {      if(S4) {
2624          tree_clone[i] = new TTree("S4","PAMELA S4 level2 data ");                pam_tree_clone[i] = new TTree("S4","PAMELA S4 level2 data ");  
2625          tree_clone[i]->Branch("S4Level2","S4Level2", GetPointerTo("S4Level2"));          pam_tree_clone[i]->Branch("S4Level2","S4Level2", GetPointerTo("S4Level2"));
2626          cout << "S4           : branch S4Level2"<<endl;          cout << "S4           : branch S4Level2"<<endl;
2627          i++;          i++;
2628      };      };
2629      // Neutron Detector      // Neutron Detector
2630      if(ND) {      if(ND) {
2631          tree_clone[i] = new TTree("NeutronD","PAMELA neutron detector level2 data ");            pam_tree_clone[i] = new TTree("NeutronD","PAMELA neutron detector level2 data ");      
2632          tree_clone[i]->Branch("NDLevel2","NDLevel2", GetPointerTo("NDLevel2"));          pam_tree_clone[i]->Branch("NDLevel2","NDLevel2", GetPointerTo("NDLevel2"));
2633          cout << "NeutronD     : branch NDLevel2"<<endl;          cout << "NeutronD     : branch NDLevel2"<<endl;
2634          i++;          i++;
2635      };      };
2636      // Anticounters      // Anticounters
2637      if(AC) {      if(AC) {
2638          tree_clone[i] = new TTree("Anticounter","PAMELA anticounter detector level2 data ");              pam_tree_clone[i] = new TTree("Anticounter","PAMELA anticounter detector level2 data ");        
2639          tree_clone[i]->Branch("AcLevel2","AcLevel2", GetPointerTo("AcLevel2"));          pam_tree_clone[i]->Branch("AcLevel2","AcLevel2", GetPointerTo("AcLevel2"));
2640          cout << "Anticounter  : branch AcLevel2"<<endl;          cout << "Anticounter  : branch AcLevel2"<<endl;
2641          i++;          i++;
2642      };      };
2643      // OrbitalInfo      // OrbitalInfo
2644      if(ORB) {      if(ORB) {
2645          tree_clone[i] = new TTree("OrbitalInfo","PAMELA oribital info  ");                pam_tree_clone[i] = new TTree("OrbitalInfo","PAMELA oribital info  ");  
2646          tree_clone[i]->Branch("OrbitalInfo","OrbitalInfo", GetPointerTo("OrbitalInfo"));          pam_tree_clone[i]->Branch("OrbitalInfo","OrbitalInfo", GetPointerTo("OrbitalInfo"));
2647          cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;          cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;
2648          i++;          i++;
2649      };      };
# Line 1792  void PamLevel2::CreateCloneTrees(TFile * Line 2651  void PamLevel2::CreateCloneTrees(TFile *
2651    
2652  }  }
2653    
 // /**  
 //  * Create clone-trees  
 //  */  
 // void PamLevel2::CreateCloneTrees(){  
   
 //     cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;  
 //     cout << "Create new PAMELA trees "<<endl;  
           
 //     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", &trk1_clone);  
 //          T_clone->BranchRef();  
 //          cout << "Tracker      : branch TrkLevel1"<<endl;  
 //      };  
 //      if(TRK2) {  
 //          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;  
 //     }  
   
 //     // Calorimeter  
 //     if(CAL1||CAL2){  
 //      C_clone = new TTree("Calorimeter_clone","PAMELA calorimeter level2 data ");      
 //      if(CAL1) {  
 //          calo1_clone = new CaloLevel1();  
 //          C_clone->Branch("CaloLevel1", "CaloLevel1", &calo1_clone);  
 //          cout << "Calorimeter  : branch CaloLevel1"<<endl;  
 //      };  
 //      if(CAL2) {  
 //          calo2_clone = new CaloLevel2();  
 //          C_clone->Branch("CaloLevel2","CaloLevel2", &calo2_clone);  
 //          cout << "Calorimeter  : branch CaloLevel2"<<endl;  
 //      };  
 //     }      
   
 //     // 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;  
   
 // }  
2654    
2655  /**  /**
2656   * Fill tree (created with CreateCloneTrees)   * Fill tree (created with CreateCloneTrees)
# Line 1888  void PamLevel2::CreateCloneTrees(TFile * Line 2658  void PamLevel2::CreateCloneTrees(TFile *
2658   */   */
2659  //void PamLevel2::FillNewPamTree(TTree *T){  //void PamLevel2::FillNewPamTree(TTree *T){
2660  void PamLevel2::FillCloneTrees(){  void PamLevel2::FillCloneTrees(){
2661                
2662  // //  --------------------------------------  //    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();  
2663    
2664      for(Int_t i=0; i<8; i++){      for(Int_t i=0; i<NCLONES; i++){
2665          if(tree_clone[i])tree_clone[i]->Fill();          if(pam_tree_clone[i])pam_tree_clone[i]->Fill();
2666      }      }
2667        if(sel_tree_clone)sel_tree_clone->Fill();    
2668    
2669  }  }
2670    
2671    
2672  TTree* PamLevel2::GetCloneTree(TString name){  TTree* PamLevel2::GetCloneTree(TString name){
2673    
2674      for(Int_t i=0; i<8; i++){        for(Int_t i=0; i<NCLONES; i++){    
2675          if(tree_clone[i]){          if(pam_tree_clone[i]){
2676              TString na = tree_clone[i]->GetName();              TString na = pam_tree_clone[i]->GetName();
2677              if(!name.CompareTo(na))return tree_clone[i];              if(!name.CompareTo(na))return pam_tree_clone[i];
2678          };          };
2679      }      }
2680        if(run_tree_clone){
2681            TString na = run_tree_clone->GetName();
2682            if(!name.CompareTo(na))return run_tree_clone;
2683        }
2684        if(sel_tree_clone){
2685            TString na = sel_tree_clone->GetName();
2686            if(!name.CompareTo(na))return sel_tree_clone;
2687        }
2688      return NULL;      return NULL;
2689    
2690  }  }
2691  void PamLevel2::WriteCloneTrees(){  void PamLevel2::WriteCloneTrees(){
2692      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2693      cout << "Write clones of PAMELA trees "<<endl;      cout << "Write clones of PAMELA trees "<<endl;
2694      for(Int_t i=0; i<8; i++){        cout << run_tree_clone->GetName()<<endl;    
2695          if(tree_clone[i]){      run_tree_clone->Write();
2696              cout << tree_clone[i]->GetName()<<endl;      cout << sel_tree_clone->GetName()<<endl;    
2697              tree_clone[i]->Write();      sel_tree_clone->Write();
2698        for(Int_t i=0; i<NCLONES; i++){    
2699            if(pam_tree_clone[i]){
2700                cout << pam_tree_clone[i]->GetName()<<endl;
2701                pam_tree_clone[i]->Write();
2702          };          };
2703      }      }
2704      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
# Line 1956  void PamLevel2::WriteCloneTrees(){ Line 2706  void PamLevel2::WriteCloneTrees(){
2706  }  }
2707    
2708  /**  /**
2709   * Create a new (empty) Pamela trees   * Method to get level2-trees entry, the corresponding run entry and (if required) the level0 entry.
2710   */   */
2711  // TTree* PamLevel2::GetNewPamTree(){  //Int_t PamLevel2::GetEntry(Int_t iee){
2712    Int_t PamLevel2::GetEntry(Long64_t iee){
2713        
2714        if(!pam_tree){
2715            cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- level2 trees not loaded"<<endl;
2716            return 0;
2717        }
2718    
 //     if(tree_clone)return tree_clone;  
2719    
2720  //     TTree *Tout = 0;      //
2721            // 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...
2722  //     cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      //
2723  //     cout << "Create new PAMELA trees "<<endl;      //    if(!run_tree ){
2724        //  cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- run tree not loeaded"<<endl;
2725        //  return 0;
2726        //    }
2727    
2728        Long64_t ii=0;
2729        //-------------------------------
2730        ii = iee;
2731        if( !pam_tree->GetEntry(ii) ){      
2732            cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- error reading pam tree"<<endl;
2733            return 0;
2734        }
2735        //
2736        // ... 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.
2737        // 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
2738        // a problem if you don't check the return code of getentry.
2739        //
2740        if(!run_tree ){
2741            if ( TRK0 || CAL0 || TOF0 || RUN ) { //forse cosi` va bene per tornare 1?
2742                cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- run tree not loaded"<<endl;
2743                return 0;
2744            }  else {
2745                return 1; //cosi` se non c'e` run esce qua...
2746            }
2747        }
2748    
2749        //-------------------------------
2750        ii = iee;
2751    //    Bool_t UPDATED = UpdateRunInfo(run_tree,ii);
2752    //    Bool_t UPDATED = UpdateRunInfo(ii);
2753        UpdateRunInfo(ii);
2754        if(SELLI==0)irunentry = iee-runfirstentry;
2755    //    if(UPDATED && run_tree_clone)run_tree_clone->Fill();
2756      
2757    //    cout << "PamLevel2::GetEntry("<<iee<<") "<<irun<<" "<<runfirstentry<<" "<<irunentry<<endl;
2758    
2759    //    cout << " irunentry "<<irunentry << endl;
2760    
2761        if( TRK0 || CAL0 || TOF0 ){
2762            if( !GetYodaEntry( ) ){
2763                cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- error reading level0 tree"<<endl;
2764                return 0;
2765            }
2766        }
2767        return 1;
2768    
2769    }
2770    
2771    /**
2772     * Method to retrieve the level0 tree (YODA tree) that contains the current event.
2773     * Given the run ID (...), if needed it query the DB and load the proper file.
2774     * @return Pointer to the tree
2775     */
2776    
2777    
2778    TTree* PamLevel2::GetYodaTree( ){
2779        
2780    //    cout << "TTree* PamLevel2::GetYodaTree( )"<<endl;
2781        //===================================
2782        // check if iroot has changed
2783        //===================================
2784        if( irun<0 ){
2785            cout << "PamLevel2::GetYodaTree() -- ERROR -- irun = "<<irun<<endl;
2786    //      cout << "In order to use this method you have to first load the RunInfo tree "<<endl;
2787            return NULL;
2788        }    
2789        Int_t irootnew = run_obj->ID_ROOT_L0;
2790    //     cout << "iroot    "<<iroot<<endl;
2791    //     cout << "irootnew "<<irootnew<<endl;
2792    
2793        //===================================
2794        // load the level0 file
2795        // (if not already loaded)
2796        //===================================
2797        if( iroot != irootnew || !l0_tree){
2798            iroot = irootnew;
2799            //===================================
2800            // open the DB connection
2801            // (if not already opened)
2802            //===================================
2803            if(!dbc || (dbc && !dbc->IsConnected())){
2804                cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
2805                cout<<"Connecting to DB"<<endl;
2806                cout<<"HOST "<<host<<endl;
2807                cout<<"USER "<<user<<endl;
2808                cout<<"PSW  "<<psw<<endl;
2809                dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
2810                if( !dbc )return NULL;
2811                if( !dbc->IsConnected() )return NULL;    
2812    //          cout<<"...done"<<endl;
2813                cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
2814            }else{
2815    //          cout<<"DB already connected"<<endl;
2816            }
2817            GL_ROOT glroot = GL_ROOT();
2818            if( glroot.Query_GL_ROOT(iroot,dbc) ){
2819                cout << "TTree* PamLevel2::GetYodaTree( ) -- ERROR -- level0 file iroot = "<<iroot<< " does not exists"<<endl;
2820                return NULL;
2821            };
2822            TString filename = glroot.PATH + glroot.NAME;
2823            if(l0_file){
2824                l0_file->Close();
2825                l0_file->Delete();
2826            }
2827            cout << "Opening LEVEL0 file: "<< filename << endl;
2828            FileStat_t t;
2829            if( gSystem->GetPathInfo(filename.Data(),t) ){
2830                cout << " PamLevel2::GetYodaTree() -- ERROR opening file "<<endl;
2831                return NULL;
2832            }
2833            l0_file = new TFile(filename);
2834            if( !l0_file )return NULL;
2835            l0_tree = (TTree*)l0_file->Get("Physics");
2836            if(!h0_obj)h0_obj = new EventHeader();
2837            l0_tree->SetBranchAddress("Header" ,&h0_obj);
2838            prevshift = 0;
2839            //---------------------------------------------------
2840            // TRACKER:
2841            if(TRK0){
2842                if(!trk0_obj){
2843                    trk0_obj = new TrkLevel0();
2844                    trk0_obj->Set();
2845                };
2846                l0_tree->SetBranchAddress("Tracker" ,trk0_obj->GetPointerToTrackerEvent());
2847            }
2848            //---------------------------------------------------
2849            // CALORIMETER:
2850            if(CAL0){
2851                if(!calo0_obj){
2852                    calo0_obj = new CaloLevel0();
2853                    calo0_obj->Set();
2854                };
2855                l0_tree->SetBranchAddress("Calorimeter" ,calo0_obj->GetPointerToCalorimeterEvent());
2856                //      cout << "PamLevel2::GetYodaTree() --- level0 calorimeter not implemented "<<endl;
2857            }
2858            //---------------------------------------------------
2859            // TOF:
2860            if(TOF0){
2861                cout << "PamLevel2::GetYodaTree() --- level0 TOF not implemented "<<endl;
2862            }
2863    
2864        };
2865    
2866        if(!dbc || (dbc && !dbc->IsConnected())){
2867            cout << " TTree* PamLevel2::GetYodaTree( ) -- no DB connected... hai fatto qualche cazzata "<<endl;
2868        }
2869    
2870        if ( TRK0 ){
2871            TrkParams::Load(6);
2872            if( !TrkParams::IsLoaded(6) ){
2873                cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- VK-mask not loaded"<<endl;
2874            };
2875            TrkParams::SetCalib(run_obj,dbc);
2876            TrkParams::LoadCalib( );
2877            if( !TrkParams::CalibIsLoaded() ){
2878                cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- Calibration not loaded"<<endl;
2879            };
2880        }
2881    
2882    //    cout << l0_tree << endl;
2883            
2884        return l0_tree;
2885    
2886    }
2887    
2888    /**
2889     * Method to retrieve the level0 tree (YODA tree) that contains the current event.
2890     */
2891    Int_t PamLevel2::GetYodaEntry(){
2892    
2893    //    cout << "Int_t PamLevel2::GetYodaEntry()"<<endl;
2894        if(!GetYodaTree())return 0;
2895            
2896  //     if(TRK1||TRK2||TRKh){      // patch
2897  //      TTree *T = new TTree("Tracker_clone","PAMELA tracker level2 data ");          if( irunentry < 0){
2898  //      if(TRK1) {  //      cout << "Int_t PamLevel2::GetYodaEntry() -- ATTENZIONE -- irunentry negativo?!?! "<<(Int_t)irunentry<<endl;
2899  //          trk1_clone = new TrkLevel1();          irunentry=0LL;
2900  //          T->Branch("TrkLevel1","TrkLevel1", &trk1_clone);      }
2901  //          T->BranchRef();      //  ---------------------------------
2902  //          cout << "Tracker      : branch TrkLevel1"<<endl;      //  if file is NOT a preselected file
2903  //      };      //  ---------------------------------
2904  //      if(TRK2) {      Long64_t quellagiusta = irunentry + (Long64_t)(run_obj->EV_FROM);
2905  //          trk2_clone = new TrkLevel2();  //     cout << " irunentry "<<irunentry<<endl;
2906  //          T->Branch("TrkLevel2", "TrkLevel2",&trk2_clone);  //     cout << " EV_FROM "<<run_obj->EV_FROM<<endl;
2907  //          cout << "Tracker      : branch TrkLevel2"<<endl;          //     cout << " quellagiusta = irunentry + EV_FROM "<< quellagiusta << endl;
2908  //      };  
2909  //      if(TRKh) {  //     cout << " irun "<< irun << " irunentry "<< irunentry<<" run_obj->EV_FROM "<<run_obj->EV_FROM <<" quella giusta "<<quellagiusta << endl;
2910  //          trkh_clone = new TrkHough();  //     cout << " iroot "<<iroot<<" run_obj->ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<endl;
2911  //          T->Branch("TrkHough","TrkHough", &trkh_clone);  //     cout << " time "<< GetOrbitalInfo()->absTime << endl;
2912  //          cout << "Tracker      : branch TrkHough"<<endl;  //     cout << " trk_calib_used "<<run_obj->TRK_CALIB_USED<< endl;
2913  //      };      
2914  //      if(!Tout)Tout=T;      if( !GetOrbitalInfo() ){
2915  //      else Tout->AddFriend("Tracker_clone");          cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing OrbitalInfo "<<endl;
2916  //     }          return 0;
2917        }
2918  //     // Calorimeter      if( GetOrbitalInfo()->OBT==0 && GetOrbitalInfo()->pkt_num==0 ){
2919  //     if(CAL1||CAL2){          cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- level2 event corrupted ?? "<<endl;
2920  //      TTree *C = new TTree("Calorimeter_clone","PAMELA calorimeter level2 data ");              return 0;
2921  //      if(CAL1) {      }
 //          calo1_clone = new CaloLevel1();  
 //          C->Branch("CaloLevel1", "CaloLevel1", &calo1_clone);  
 //          cout << "Calorimeter  : branch CaloLevel1"<<endl;  
 //      };  
 //      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;  
2922    
2923  //     tree_clone = Tout;      // ---------------------------------------------------------------------
2924  //     tree_clone->SetDirectory(0);      // ATTENTION!!!
2925        // If data are not pre-processed with cleaner, the level0 tree may contain
2926        // spurious nested physics packets.
2927        // The GL_RUN variables EV_FROM, EV_TO and NEVENTS counts also these entries
2928        // while level2 tree DOES NOT!!
2929        // This means that "quellagiusta" in these cases is not correct.
2930        // In order to retrieve the correct level0 event, I implemented a check
2931        // of the OBT and pkt-number. In case of mismatch, the level0 entry number
2932        // is shift forward until when the packets match.
2933        // ---------------------------------------------------------------------
2934        Int_t answer = 0;
2935        Int_t shift =0;
2936        //    printf(" siamo qui %i %i \n",shift,prevshift);
2937        Int_t maxshift = 100;
2938        do{
2939            if(shift>0){    
2940                cout << " PKTNUM  L2 --- "<< GetOrbitalInfo()->pkt_num << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl;
2941                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;
2942                cout << "         L2 <--> L0 mismatch ( irun "<<irun<<" irunentry "<<irunentry<<" shift "<<shift<<" prevshift "<<prevshift<<" )"<<endl;
2943            }
2944            answer = l0_tree->GetEntry(quellagiusta+(Long64_t)shift+(Long64_t)prevshift);
2945            shift++;
2946            if( !GetEventHeader() ){
2947                cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing EventHeader "<<endl;
2948                return 0;
2949            }
2950    //      cout << "PKTNUM "<<shift<<" ==  L2 --- "<< GetOrbitalInfo()->pkt_num << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl;
2951    //      cout << " L2 --- "<< GetOrbitalInfo()->OBT << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime()<<endl;
2952    //      if( (quellagiusta+shift) == l0_tree->GetEntries()+1 )cout << ">>> end of level0 tree <<<"<<endl;
2953    //      cout << " GetOrbitalInfo()->OBT "<< GetOrbitalInfo()->OBT << endl;
2954    //      cout << " GetEventHeader()->GetPscuHeader()->GetOrbitalTime() "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime() << endl;
2955    //      cout << " GetOrbitalInfo()->pkt_num "<< GetOrbitalInfo()->pkt_num << endl;
2956    //      cout << " GetEventHeader()->GetPscuHeader()->GetCounter() "<< GetEventHeader()->GetPscuHeader()->GetCounter() << endl;
2957    //      printf(" IDRUN %u \n",GetRunInfo()->ID);
2958    //
2959            if ( prevshift != 0 && (quellagiusta+(Long64_t)shift) == GetYodaTree()->GetEntries() ){
2960              prevshift = 0;
2961              shift = -1;
2962            };
2963    
2964  //     return Tout;      }while( ( GetOrbitalInfo()->OBT != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) || GetOrbitalInfo()->pkt_num != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter())) && (quellagiusta+(Long64_t)shift) < GetYodaTree()->GetEntries() && shift < maxshift);
2965  // }  
2966  // /**      if ( (quellagiusta+(Long64_t)shift) == GetYodaTree()->GetEntries() || shift == maxshift ) {
2967  //  * Fill a tree (created with GetNewPamTree)          cout << " Big trouble here, no such event in Level0 data! " <<endl;
2968  //  *          return 0;
2969  //  */      }
2970  // //void PamLevel2::FillNewPamTree(TTree *T){  //    cout << "LA ENTRY GIUSTA E`: "<<quellagiusta<<" (spero...)"<<endl;
2971  // void PamLevel2::FillNewPamTree(){  //    return GetYodaTree()->GetEntry(quellagiusta);
2972                if ( shift > 1 ) prevshift += (shift-1);
2973        
2974        return answer;
2975        
2976    }
2977    
 //     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;  
   
 //     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  
 //     }  
2978    
 // }  

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.36

  ViewVC Help
Powered by ViewVC 1.1.23