/[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.16 by pam-fi, Tue Jan 16 13:19:58 2007 UTC revision 1.48 by mocchiut, Wed Sep 12 09:51:57 2007 UTC
# Line 11  PamTrack::PamTrack(){ Line 11  PamTrack::PamTrack(){
11      calo_track = 0;      calo_track = 0;
12      tof_track  = 0;      tof_track  = 0;
13      candeleteobj = 0;      candeleteobj = 0;
14        pscore = 0;
15        iscore = 0;
16  };  };
17  //--------------------------------------  //--------------------------------------
18  //  //
# Line 60  void PamTrack::Clear(){ Line 62  void PamTrack::Clear(){
62          calo_track = 0;          calo_track = 0;
63          tof_track  = 0;          tof_track  = 0;
64      }      }
65        pscore = 0;
66        iscore = 0;
67    
68  }  }
69  void PamTrack::Delete(){  void PamTrack::Delete(){
70  //    cout << "PamTrack::Delete() "<<candeleteobj<<endl;  //    cout << "PamTrack::Delete() "<<candeleteobj<<endl;
# Line 85  void PamTrack::Delete(){ Line 90  void PamTrack::Delete(){
90  //  //
91  //--------------------------------------  //--------------------------------------
92  /**  /**
93   * Constructor   * Default Constructor
94   */   */
95  PamLevel2::PamLevel2(){  PamLevel2::PamLevel2(){
96      Initialize();
97    };
98    
99    /**
100     * Constructor with given dir, list and detectors
101     */
102    PamLevel2::PamLevel2(TString ddir,TString list,TString detlist){
103      Initialize();
104      GetPamTree(GetListOfLevel2Files(ddir,list),detlist);
105      GetRunTree(GetListOfLevel2Files(ddir,list));
106    };
107    
108    /**
109     * Constructor with given dir and list
110     */
111    PamLevel2::PamLevel2(TString ddir,TString list){
112      Initialize();
113      GetPamTree(GetListOfLevel2Files(ddir,list),"");
114      GetRunTree(GetListOfLevel2Files(ddir,list));
115    };
116    
117    
118    void PamLevel2::Initialize(){
119                    
120  //     trk2_obj  = TrkLevel2::GetTrkLevel2();      h0_obj    = 0;
121  //     trk1_obj  = TrkLevel1::GetTrkLevel1();      trk0_obj  = 0;
122  //     trkh_obj  = TrkHough::GetTrkHough();      calo0_obj  = 0;
123  //     calo1_obj = CaloLevel1::GetCaloLevel1();  
 //     calo2_obj = CaloLevel2::GetCaloLevel2();  
 //     tof_obj   = ToFLevel2::GetToFLevel2();  
 //     trig_obj  = TrigLevel2::GetTrigLevel2();  
 //     s4_obj    = S4Level2::GetS4Level2();  
 //     nd_obj    = NDLevel2::GetNDLevel2();  
 //     ac_obj    = AcLevel2::GetAcLevel2();  
 //     orb_obj   = OrbitalInfo::GetOrbitalInfo();  
124      trk2_obj  = 0;      trk2_obj  = 0;
125      trk1_obj  = 0;      trk1_obj  = 0;
126      trkh_obj  = 0;      trkh_obj  = 0;
# Line 114  PamLevel2::PamLevel2(){ Line 135  PamLevel2::PamLevel2(){
135    
136      run_obj   = 0;//new GL_RUN();      run_obj   = 0;//new GL_RUN();
137      soft_obj   = 0;// Emiliano      soft_obj   = 0;// Emiliano
138            irun = -1LL;
139        runfirstentry = 0LL;
140        runlastentry = 0LL;
141    
142        l0_file = NULL;
143        l0_tree = NULL;
144        iroot   = -1;
145        dbc     = 0;
146    
147        prevshift = 0;
148        
149        run_tree = NULL;
150        run_tree_clone = NULL;
151        sel_tree = NULL;
152        sel_tree_clone = NULL;
153        
154        irunentry = -1LL;
155        pam_tree = NULL;
156        for(Int_t i=0; i<NCLONES; i++ )pam_tree_clone[i]=NULL;
157    
158        totdltime[0] = 0LL;
159        totdltime[1] = 0LL;
160    
161        host = "mysql://localhost/pamelaprod";
162        user = "anonymous";
163        psw = "";
164        const char *pamdbhost=gSystem->Getenv("PAM_DBHOST");
165        const char *pamdbuser=gSystem->Getenv("PAM_DBUSER");
166        const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW");
167        if ( !pamdbhost ) pamdbhost = "";
168        if ( !pamdbuser ) pamdbuser = "";
169        if ( !pamdbpsw ) pamdbpsw = "";
170        if ( strcmp(pamdbhost,"") ) host = pamdbhost;
171        if ( strcmp(pamdbuser,"") ) user = pamdbuser;
172        if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw;
173    
174      for(Int_t i=0; i<8; i++ )tree_clone[i]=NULL;      
175    
176  //    sorted_tracks = 0;//new TRefArray();  //    sorted_tracks = 0;//new TRefArray();
177            
178        CAL0 = false;
179      CAL1 = true;      CAL1 = true;
180      CAL2 = true;      CAL2 = true;
181      TRK2 = true;      TRK2 = true;
182      TRK1 = false;      TRK1 = false;
183      TRKh = false;      TRKh = false;
184      TRG = true;      TRKh = false;
185      TOF = true;      TRG  = true;
186      S4  = true;      TOF  = true;
187      ND  = true;      TOF0 = false;
188      AC  = true;      S4   = true;
189      ORB = true;      ND   = true;
190        AC   = true;
191        ORB  = true;
192            
193      RUN = true;      RUN  = true;
194    
195        SELLI = -1;
196    
197        ISGP = false;
198    
199      tsorted=0;      tsorted=0;
200      timage=0;      timage=0;
201        
202        howtosort = "+CAL+TOF";
203        //howtosort = "+TOF";
204        sortthr = 100.;
205    
206  };  };
207  /**  /**
# Line 147  void PamLevel2::Delete(){ Line 213  void PamLevel2::Delete(){
213      if(soft_obj)delete soft_obj; //Emiliano      if(soft_obj)delete soft_obj; //Emiliano
214    
215  //    cout << "void PamLevel2::Clear()"<<endl;  //    cout << "void PamLevel2::Clear()"<<endl;
216        if(h0_obj)   delete h0_obj;
217        if(trk0_obj) delete trk0_obj;      
218        if(calo0_obj) delete calo0_obj;    
219      if(trk1_obj) delete trk1_obj;            if(trk1_obj) delete trk1_obj;      
220      if(trk2_obj) delete trk2_obj;      if(trk2_obj) delete trk2_obj;
221      if(trkh_obj) delete trkh_obj;      if(trkh_obj) delete trkh_obj;
# Line 167  void PamLevel2::Delete(){ Line 236  void PamLevel2::Delete(){
236          timage->Delete();          timage->Delete();
237          delete timage;          delete timage;
238      }      }
239    
240        if(dbc){
241            dbc->Close();
242            delete dbc;
243        }
244        
245        if(l0_file)l0_file->Close();
246        //    if(pam_tree)pam_tree->Delete();;
247    
248      if ( pam_tree ){
249        //
250        // 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...
251        //
252        TList *temp = pam_tree->GetListOfFriends();
253        TList *contents  = new TList; // create chain friend list
254        contents->SetOwner();
255        TIter next(temp);
256        TChain *questo = 0;
257        while ( (questo = (TChain*) next()) ){
258          TString name =  questo->GetName();
259          contents->Add((TChain*)gROOT->FindObject(name.Data()));// add object to the list
260        };
261        //
262        // deleting the main chain
263        //
264        pam_tree->Delete();
265        //
266        // deleting the friends...
267        //
268        TIter next2(contents);
269        TChain *questa = 0;
270        while ( questa = (TChain*)next2() ){
271          TString name =  questa->GetName();
272          questa->Delete();      
273          questa=NULL;
274        };
275        //
276      };
277      pam_tree = NULL;
278    
279        if(run_tree)run_tree->Delete();;
280        if(sel_tree)sel_tree->Delete();;
281        for(Int_t i=0; i<NCLONES; i++ )if(pam_tree_clone[i])pam_tree_clone[i]->Delete();;
282        if(run_tree_clone)run_tree_clone->Delete();;
283        if(sel_tree_clone)sel_tree_clone->Delete();;
284        
285    
286  };  };
287    
288  /**  /**
# Line 177  void PamLevel2::Clear(){ Line 293  void PamLevel2::Clear(){
293  //    cout << "void PamLevel2::Clear()"<<endl;  //    cout << "void PamLevel2::Clear()"<<endl;
294    
295  //  //
296    // 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
297    // want to load them for each event even if they are the same...
298    //
299  //    if(run_obj)delete run_obj;  //    if(run_obj)delete run_obj;
300      if(run_obj) run_obj->Clear();  // Emiliano: Do not deallocate run_obj here, it will give segmentation fault! call clear instead  //    if(run_obj) run_obj->Clear();  // Emiliano: Do not deallocate run_obj here, it will give segmentation fault! call clear instead
301      if(soft_obj) soft_obj->Clear();  //    if(soft_obj) soft_obj->Clear();
302    
303        if(h0_obj)   h0_obj->Clear();      
304    //    if(trk0_obj) trk0_obj->Clear();  
305      if(trk1_obj) trk1_obj->Clear();          if(trk1_obj) trk1_obj->Clear();    
306      if(trk2_obj) trk2_obj->Clear();      if(trk2_obj) trk2_obj->Clear();
307      if(trkh_obj) trkh_obj->Clear();      if(trkh_obj) trkh_obj->Clear();
308        if(calo0_obj) calo0_obj->Clear();  
309      if(calo1_obj)calo1_obj->Clear();      if(calo1_obj)calo1_obj->Clear();
310      if(calo2_obj)calo2_obj->Clear();      if(calo2_obj)calo2_obj->Clear();
311      if(tof_obj)  tof_obj->Clear();      if(tof_obj)  tof_obj->Clear();
# Line 202  void PamLevel2::Clear(){ Line 324  void PamLevel2::Clear(){
324      if(timage){      if(timage){
325          timage->Delete();          timage->Delete();
326      }      }
       
327  };  };
328    
329    void PamLevel2::Reset(){
330      //
331      // First of all clear everything
332      //
333      Clear();
334      //
335      // close and reset chains and pointers
336      //    
337      if ( pam_tree ){
338        //
339        // 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...
340        //
341        TList *temp = pam_tree->GetListOfFriends();
342        TList *contents  = new TList; // create chain friend list
343        contents->SetOwner();
344        TIter next(temp);
345        TChain *questo = 0;
346        while ( (questo = (TChain*) next()) ){
347          TString name =  questo->GetName();
348          contents->Add((TChain*)gROOT->FindObject(name.Data()));// add object to the list
349        };
350        //
351        // deleting the main chain
352        //
353        pam_tree->Delete();
354        //
355        // deleting the friends...
356        //
357        TIter next2(contents);
358        TChain *questa = 0;
359        while ( questa = (TChain*)next2() ){
360          TString name =  questa->GetName();
361          questa->Delete();      
362          questa=NULL;
363        };
364        //
365      };
366      pam_tree = NULL;
367      //
368      if(run_tree)run_tree->Delete();;
369      run_tree = NULL;
370      if(sel_tree)sel_tree->Delete();;
371      sel_tree = NULL;
372      //
373      // Close file
374      //
375      if(l0_file)l0_file->Close("R");
376      l0_file = NULL;
377      //
378      h0_obj    = 0;
379      trk0_obj  = 0;
380      calo0_obj  = 0;
381      //
382      trk2_obj  = 0;
383      trk1_obj  = 0;
384      trkh_obj  = 0;
385      calo1_obj = 0;
386      calo2_obj = 0;
387      tof_obj   = 0;
388      trig_obj  = 0;
389      s4_obj    = 0;
390      nd_obj    = 0;
391      ac_obj    = 0;
392      orb_obj   = 0;
393      //
394      // Reset run pointers
395      //
396      run_obj   = 0;//new GL_RUN();
397      soft_obj   = 0;// Emiliano
398      irun = -1;
399      runfirstentry = 0ULL;
400      runlastentry = 0ULL;    
401      //
402      totdltime[0] = 0LL;
403      totdltime[1] = 0LL;
404      //
405    };
406    
407    Bool_t PamLevel2::IsGood(){
408      Bool_t goodev=true;
409      //  if(trk2_obj && trk2_obj->UnpackError() != 0 ) goodev = false;
410      if(calo2_obj && calo2_obj->good != 1) goodev = false;
411      if(tof_obj && tof_obj->unpackError != 0) goodev = false;  
412      if(trig_obj && trig_obj->unpackError != 0) goodev = false;
413      if(s4_obj && s4_obj->unpackError != 0) goodev = false;  
414      if(nd_obj && nd_obj->unpackError != 0) goodev = false;  
415      if(ac_obj && ac_obj->unpackError != 255) goodev = false;  
416        //  if(orb_obj)  
417      return goodev;
418    };
419    
420  //--------------------------------------  //--------------------------------------
421  //  //
# Line 399  PamTrack* PamLevel2::GetStoredTrack(Int_ Line 610  PamTrack* PamLevel2::GetStoredTrack(Int_
610  }  }
611  //--------------------------------------  //--------------------------------------
612  //  //
613    
614    /**
615     * Sort physical (tracker) tracks and stores them in the TRefArray (of TrkTrack objects) which pointer is  PamLevel2::sorted_tracks. Left here as backward compatibility method.
616     **/
617    void PamLevel2::SortTracks(TString how){
618      printf(" WARNING! obsolete, use SortTracks() and SetSortingMethod(TString) instead! \n Setting sorting method to %s \n",how.Data());
619      howtosort = how;  
620      SortTracks();
621    };
622    
623  //  //
624  //--------------------------------------  //--------------------------------------
625  /**  /**
# Line 412  PamTrack* PamLevel2::GetStoredTrack(Int_ Line 633  PamTrack* PamLevel2::GetStoredTrack(Int_
633   *   *
634   * The total number of physical tracks is always given by GetNTracks() and the it-th physical track can be retrieved by means of the methods GetTrack(int it) and GetTrack(int it, TString how).   * The total number of physical tracks is always given by GetNTracks() and the it-th physical track can be retrieved by means of the methods GetTrack(int it) and GetTrack(int it, TString how).
635   */   */
636  void PamLevel2::SortTracks(TString how){  void PamLevel2::SortTracks(){
637      TString how = howtosort;
638    
639  //    cout <<" PamLevel2::SortTracks(TString how) "<<endl;    //  cout <<" PamLevel2::SortTracks(TString how) "<<endl;
640      if( !trk2_obj ){    if( !trk2_obj ){
641          cout << "void PamLevel2::SortTracks(TString how):  TrkLevel2 not loaded !!!";      cout << "void PamLevel2::SortTracks():  TrkLevel2 not loaded !!!";
642          return;      return;
643      };    };
644  //    cout << "call SortTracs() "<<endl;    //    cout << "call SortTracs() "<<endl;
645    //Save current Object count    //Save current Object count
646      Int_t ObjectNumber = TProcessID::GetObjectCount();    Int_t ObjectNumber = TProcessID::GetObjectCount();
   
 //    cout << "ObjectNumber  "<<ObjectNumber <<endl;  
647    
648  //     if(!sorted_tracks)sorted_tracks = new TRefArray();    //    cout << "ObjectNumber  "<<ObjectNumber <<endl;
 //     sorted_tracks->Clear();  
 //    sorted_tracks.Clear();  
649    
650      if(!tsorted)tsorted = new TClonesArray("PamTrack",trk2_obj->GetNTracks());    //     if(!sorted_tracks)sorted_tracks = new TRefArray();
651      tsorted->Delete();    //     sorted_tracks->Clear();
652      TClonesArray &ttsorted = *tsorted;    //    sorted_tracks.Clear();
653      if(!timage)timage = new TClonesArray("PamTrack",trk2_obj->GetNTracks());  
654      timage->Delete();    if(!tsorted)tsorted = new TClonesArray("PamTrack",trk2_obj->GetNTracks());
655      TClonesArray &ttimage = *timage;    tsorted->Delete();
656      TClonesArray &ttsorted = *tsorted;
657      if(!timage)timage = new TClonesArray("PamTrack",trk2_obj->GetNTracks());
658      timage->Delete();
659      TClonesArray &ttimage = *timage;
660    
661    
662    
663      //--------------------------------------------------
664      // retrieve sorting method
665      //--------------------------------------------------
666      Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);
667      Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);
668      Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase);
669      Bool_t use_S1 = how.Contains("S1", TString::kIgnoreCase);
670      Bool_t use_S2 = how.Contains("S2", TString::kIgnoreCase);
671      Bool_t use_S3 = how.Contains("S3", TString::kIgnoreCase);
672      
673      if ( use_TOF ){
674        use_S1 = true;
675        use_S2 = true;
676        use_S3 = true;
677      };
678      if( !CAL2 &&  use_CAL) use_CAL = false;
679      if( !TOF ){
680        use_TOF = false;
681        use_S1  = false;
682        use_S2  = false;
683        use_S3  = false;
684      }
685    
686      if( !TRK2 ){
687        //  cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl;
688        return;
689      };
690    
691      //   cout << "use_CAL "<<use_CAL<<" use_TOF "<<use_TOF<<" use_TRK "<<use_TRK <<endl;
692      
693    
694      //--------------------------------------------------
695      // loop over "physical" tracks sorted by the tracker
696      //--------------------------------------------------
697      for(Int_t i=0; i < trk2_obj->TrkLevel2::GetNTracks(); i++){
698            
699        TrkTrack   *ts = 0;
700        CaloTrkVar *cs = 0;
701        ToFTrkVar  *os = 0;
702            
703        // get tracker tracks
704        TrkTrack   *tp = trk2_obj->TrkLevel2::GetTrack(i); //tracker
705        CaloTrkVar *cp = GetCaloStoredTrack(tp->GetSeqNo());
706        ToFTrkVar  *op = GetToFStoredTrack(tp->GetSeqNo());
707    
708        TrkTrack   *ti = 0; //tracker (image)
709        CaloTrkVar *ci = 0;
710        ToFTrkVar  *oi = 0;
711        //  cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;
712        // if track has an image, check image selection
713    
714        Int_t tp_score = 0;  //main track sorted by the tracker
715        Int_t ti_score = 0;  //image track
716        Int_t totp_score = 0;  //main track sorted by the tracker
717        Int_t toti_score = 0;  //image track
718    
719        if(tp->HasImage()){
     // loop over the tracks sorted by the tracker  
     Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);  
     Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);  
     Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase);  
       
     if( !CAL2 &&  use_CAL) use_CAL = false;  
     if( !TOF &&  use_TOF) use_TOF = false;  
       
     if( !TRK2 ){  
 //      cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl;  
         return;  
     };  
   
     //   cout << "use_CAL "<<use_CAL<<" use_TOF "<<use_TOF<<" use_TRK "<<use_TRK <<endl;  
       
     for(Int_t i=0; i < trk2_obj->TrkLevel2::GetNTracks(); i++){  
           
         TrkTrack   *ts = 0;  
         CaloTrkVar *cs = 0;  
         ToFTrkVar  *os = 0;  
           
         // get tracker tracks  
         TrkTrack   *tp = trk2_obj->TrkLevel2::GetTrack(i);                    //tracker  
         CaloTrkVar *cp = GetCaloStoredTrack(tp->GetSeqNo());  
         ToFTrkVar  *op = GetToFStoredTrack(tp->GetSeqNo());  
   
         TrkTrack   *ti = 0;              //tracker (image)  
         CaloTrkVar *ci = 0;  
         ToFTrkVar  *oi = 0;  
 //      cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;  
         // if track has an image, check image selection  
         if(tp->HasImage()){  
720                            
721              ti = trk2_obj->TrkLevel2::GetTrackImage(i);              //tracker (image)        ti = trk2_obj->TrkLevel2::GetTrackImage(i);              //tracker (image)
722              ci = GetCaloStoredTrack(ti->GetSeqNo());        ci = GetCaloStoredTrack(ti->GetSeqNo());
723              oi = GetToFStoredTrack(ti->GetSeqNo());        oi = GetToFStoredTrack(ti->GetSeqNo());
724                            
725  //          cout << "its image "<<i << " "<<hex<< ti <<dec<< endl;        //            cout << "its image "<<i << " "<<hex<< ti <<dec<< endl;
726    
727              //assign starting scores        //assign starting scores
728              Int_t tp_score = 0;  //main track sorted by the tracker        tp_score = 0;  //main track sorted by the tracker
729              Int_t ti_score = 0;  //image track        ti_score = 0;  //image track
730                            
731              // ------------------------        // -----------------------------------------------------------------------------------------
732              // calorimeter check        // calorimeter check
733              // ------------------------        // -----------------------------------------------------------------------------------------
734              // check the Y spatial residual on the first calorimeter plane        // check the Y spatial residual on the first calorimeter plane
735              // (cut on calorimeter variables from Emiliano)        // (cut on calorimeter variables from Emiliano)
736              if( use_CAL && !calo2_obj ){        if( use_CAL && !calo2_obj ){
737                  cout << "void PamLevel2::SortTracks(TString how): how= "<<how<<" but CaloLevel2 not loaded !!!";          cout << "void PamLevel2::SortTracks(): howtosort= "<<how<<" but CaloLevel2 not loaded !!!";
738                  return;          return;
739              };        };
740              if(        if( use_CAL && !cp &&  ci ){
741                  use_CAL            &&          ti_score++;
742                  calo2_obj->npcfit[1] > 15     &&   //no. of fit planes on Y view          toti_score++;
743                  calo2_obj->varcfit[1] < 1000. &&  //fit variance on Y view        };
744                  true){        if( use_CAL &&  cp && !ci ){
745            tp_score++;
746            totp_score++;
747          };
748          if(
749             use_CAL            &&
750    //       calo2_obj->npcfit[1] > 5     &&   //no. of fit planes on Y view
751    //       calo2_obj->varcfit[1] < 1000. &&  //fit variance on Y view
752             cp && ci &&
753             true){
754    
755                                    
756                  Float_t resy_p = cp->tbar[0][1] - calo2_obj->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;
757                  Float_t resy_i = ci->tbar[0][1] - calo2_obj->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;
758                                    
759                  if(resy_p <= resy_i) tp_score++;  //      if(resy_p <= resy_i) tp_score++;
760                  else                 ti_score++;  //      else                 ti_score++;
761            
762    
763            if( cp->npresh > ci->npresh){
764              tp_score++;
765              totp_score++;
766            };
767            if( cp->npresh < ci->npresh){
768              ti_score++;
769              toti_score++;
770            };
771    
772  //              cout << "CALO "<<tp_score<<ti_score<<endl;          //      cout << "CALO "<<tp_score<<ti_score<<endl;
773    
774          };
775          // -----------------------------------------------------------------------------------------
776          // TOF check
777          // -----------------------------------------------------------------------------------------
778          // check the number of hit pmts along the track
779          // on S12 S21 and S32, where paddles are parallel to Y axis
780          if( (use_TOF || use_S1 || use_S2 || use_S3 ) && !tof_obj ){
781            cout << "void PamLevel2::SortTracks(): howtosort= "<<how<<" but ToFLevel2 not loaded !!!";
782            return;
783          };
784          //
785          if( (use_TOF || use_S1 || use_S2 || use_S3 ) && !op && oi ){
786            ti_score++;
787            toti_score++;
788          };
789          if( (use_TOF || use_S1 || use_S2 || use_S3 ) && op && !oi ){
790            tp_score++;
791            totp_score++;
792          };
793          if( (use_TOF || use_S1 || use_S2 || use_S3 ) && op && oi ){
794            //
795            Float_t sen = 0.;
796            for (Int_t ih=0; ih < op->npmtadc; ih++){
797              Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
798              if ( pl == 2 || pl == 3 || pl == 4 || pl == 5 ) sen += (op->dedx).At(ih);
799            };
800            for (Int_t ih=0; ih < oi->npmtadc; ih++){
801              Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
802              if ( pl == 2 || pl == 3 || pl == 4 || pl == 5 ) sen += (oi->dedx).At(ih);
803            };
804            //
805            if (  sen >= sortthr && false){ // temporary disabled NUCLEI special algorithm since the new one should work for every particle (to be checked!)
806              //printf(" IS A NUCLEUS! en = %f \n",sen);
807              //
808              // is a nucleus use a different algorithm
809              //
810              Int_t nz = 6; Float_t zin[6];                                          // << define TOF z-coordinates
811              for(Int_t ip=0; ip<nz; ip++)
812                zin[ip] = tof_obj->ToFLevel2::GetZTOF(tof_obj->ToFLevel2::GetToFPlaneID(ip));     // << read ToF plane z-coordinates
813              Trajectory *tr = new Trajectory(nz,zin);
814              //
815              Int_t nphit_p =0;
816              Int_t nphit_i =0;
817              Float_t enhit_p = 0.;
818              Float_t enhit_i = 0.;
819              //
820              for (Int_t ih=0; ih < op->npmtadc; ih++){
821                Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
822                if(pl == 1 || pl == 2 || pl == 5){
823                  nphit_p++;
824                  enhit_p += (op->dedx).At(ih);
825                };
826              };
827              //
828              tp->DoTrack2(tr);
829              //
830              if ( fabs(tr->y[0]-oi->ytofpos[0]) < 2. ){
831                for (Int_t ih=0; ih < op->npmtadc; ih++){
832                  Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
833                  if(pl == 0){
834                    nphit_p++;
835                    enhit_p += (op->dedx).At(ih);
836                  };
837                };
838              };
839              if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){
840                for (Int_t ih=0; ih < op->npmtadc; ih++){
841                  Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
842                  if(pl == 3){
843                    nphit_p++;
844                    enhit_p += (op->dedx).At(ih);
845                  };
846                };
847              };
848              if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){
849                for (Int_t ih=0; ih < op->npmtadc; ih++){
850                  Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
851                  if(pl == 4){
852                    nphit_p++;
853                    enhit_p += (op->dedx).At(ih);
854                  };
855                };
856              };
857    
858              for (Int_t ih=0; ih < oi->npmtadc; ih++){
859                Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
860                if(pl == 1 || pl == 2 || pl == 5){
861                  nphit_i++;        
862                  enhit_i += (op->dedx).At(ih);
863                };
864              };
865              //
866              ti->DoTrack2(tr);
867              //
868              if ( fabs(tr->y[0]-oi->ytofpos[0]) < 2. ){
869                for (Int_t ih=0; ih < oi->npmtadc; ih++){
870                  Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
871                  if(pl == 0){
872                    nphit_i++;
873                    enhit_i += (op->dedx).At(ih);
874                  };
875                };
876              };
877              if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){
878                for (Int_t ih=0; ih < oi->npmtadc; ih++){
879                  Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
880                  if(pl == 3){
881                    nphit_i++;
882                    enhit_i += (op->dedx).At(ih);
883                  };
884              };              };
885              // ------------------------            };
886              // TOF check            if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){
887              // ------------------------                  for (Int_t ih=0; ih < oi->npmtadc; ih++){
888              // check the number of hit pmts along the track                Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
889              // on S12 S21 and S32, where paddles are parallel to Y axis                if(pl == 4){
890              if( use_TOF && !tof_obj ){                  nphit_i++;
891                  cout << "void PamLevel2::SortTracks(TString how): how= "<<how<<" but ToFLevel2 not loaded !!!";                  enhit_i += (op->dedx).At(ih);
892                  return;                };
893              };              };
894              if( use_TOF ){            };            
895    
896                                    
897                  Int_t nphit_p =0;            if(
898                  Int_t nphit_i =0;               (use_TOF || use_S1 || use_S2 || use_S3)            &&
899                 (nphit_p+nphit_i) !=0 &&  
900                 true){
901                        
902                //      printf(" seqno %i nphit_p %i nphit_i %i enhit_p %f enhit_i %f \n",trk2_obj->TrkLevel2::GetSeqNo(i),nphit_p,nphit_i,enhit_p,enhit_i);
903                //      printf(" score p %i score i %i \n",tp_score,ti_score);
904                //            if( enhit_p > enhit_i ) tp_score++;
905                //            if( nphit_p >= nphit_i && enhit_p > enhit_i ) tp_score++;
906                if ( nphit_p > nphit_i ) tp_score++;
907                if ( nphit_p < nphit_i ) ti_score++;
908                if ( nphit_p == nphit_i ){
909                  if ( enhit_p > enhit_i ) tp_score++;
910                  else ti_score++;
911                };
912                //      printf(" dopo score p %i score i %i \n",tp_score,ti_score);
913              };
914              delete tr;
915              //
916            } else {
917              //
918              // NOT a NUCLEUS
919              //
920              //printf(" NOT a NUCLEUS! en = %f \n",sen);
921    
922              Int_t nphit_p =0;
923              Int_t nphit_i =0;
924                                    
925                                    
926  /*                              cout << "track: npmtadc "<< op->npmtadc << endl;            /*                            cout << "track: npmtadc "<< op->npmtadc << endl;
927                                  cout << "track: npmttdc "<< op->npmttdc << endl;              cout << "track: npmttdc "<< op->npmttdc << endl;
928                                  cout << "image: npmtadc "<< oi->npmtadc << endl;              cout << "image: npmtadc "<< oi->npmtadc << endl;
929                                  cout << "image: npmttdc "<< oi->npmttdc << endl;*/              cout << "image: npmttdc "<< oi->npmttdc << endl;*/
930                                    
931                  for (Int_t ih=0; ih < op->npmtadc; ih++){  //        for (Int_t ih=0; ih < op->npmtadc; ih++){
932                      Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );  //          Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
933                      if(pl == 1 || pl == 2 || pl == 5)nphit_p++;  //          if(pl == 1 || pl == 2 || pl == 5)nphit_p++;
934                  };  //        };
935                                    
936                  for (Int_t ih=0; ih < oi->npmtadc; ih++){  //        for (Int_t ih=0; ih < oi->npmtadc; ih++){
937                      Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );  //          Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
938                      if(pl == 1 || pl == 2 || pl == 5)nphit_i++;  //          if(pl == 1 || pl == 2 || pl == 5)nphit_i++;
939                  };  //        };
940              // --- modified to count tdc signals (more efficient?)
941              // --- and to implement check on tdcflag
942              for (Int_t ih=0; ih < op->npmttdc; ih++){
943                Int_t pl = tof_obj->GetPlaneIndex( (op->pmttdc).At(ih) );
944    //          if( (op->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_p++;
945                if ( (use_S1 && ( pl == 0 || pl == 1 )) || (use_S2 && ( pl == 2 || pl == 3 )) || (use_S3 && ( pl == 4 || pl == 5 )) ){
946                  if( (op->tdcflag).At(ih)==0 )nphit_p++;
947                };
948              };
949                                    
950                  if(            for (Int_t ih=0; ih < oi->npmttdc; ih++){
951                      use_TOF            &&              Int_t pl = tof_obj->GetPlaneIndex( (oi->pmttdc).At(ih) );
952                      (nphit_p+nphit_i) !=0 &&      //          if( (oi->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_i++;  
953                      true){              if ( (use_S1 && ( pl == 0 || pl == 1 )) || (use_S2 && ( pl == 2 || pl == 3 )) || (use_S3 && ( pl == 4 || pl == 5 )) ){
954                                      if( (oi->tdcflag).At(ih)==0 )nphit_i++;  
                     if( nphit_p >= nphit_i) tp_score++;  
                     else ti_score++;  
                 };  
 //              cout << "TOF "<<tp_score<<ti_score<<endl;  
955              };              };
956              if(tp_score == ti_score) use_TRK = true;            };
957              // ------------------------                  
958              // tracker check            if(
959              // ------------------------               (nphit_p+nphit_i) !=0 &&  
960              // chi**2 difference is not always large enough to distinguish among               true){
961              // the real track and its image.                      
962              // Tracker check will be applied always when calorimeter and tof information is ambiguous.              if ( nphit_p != nphit_i ){
963              if(use_TRK){                totp_score += nphit_p;
964                  if(      tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ;                toti_score += nphit_i;
965                  else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ;                tp_score+=nphit_p;
966  //              cout << "TRK "<<tp_score<<ti_score<<endl;                ti_score+=nphit_i;
967              };              };
968                //      if     ( nphit_p > nphit_i) tp_score+=nphit_p;
969                //      else if( nphit_p < nphit_i) ti_score+=nphit_i;
970                //      else ;//niente
971              };
972            };
973            //      cout << "TOF "<<tp_score<<ti_score<<endl;
974          };
975    
976    
977    //      if(tp_score == ti_score) use_TRK = true;
978    
979    
980          // -----------------------------------------------------------------------------------------
981          // tracker check
982          // -----------------------------------------------------------------------------------------
983          // chi**2 difference is not always large enough to distinguish among
984          // the real track and its image.
985          // Tracker check will be applied always when calorimeter and tof information is ambiguous.
986          // *** MODIFIED ON AUGUST 2007 ***
987          if(use_TRK){
988    //      if(      tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ;
989    //      else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ;
990    
991              // CHECK 1 : number of points along X  
992            if ( tp->GetNX() >= ti->GetNX() ){
993              tp_score++ ;
994              totp_score++ ;
995            };
996            if ( tp->GetNX() <= ti->GetNX() ){
997              ti_score++ ;
998              toti_score++ ;
999            };
1000              // CHECK 2 : number of points along Y  
1001            if ( tp->GetNY() >= ti->GetNY() ){
1002              tp_score++ ;
1003              totp_score++ ;
1004            };
1005            if ( tp->GetNY() <= ti->GetNY() ){
1006              ti_score++ ;
1007              toti_score++ ;
1008            };
1009              // CHECK 3 : chi**2 along X  
1010    //        if(      tp->GetChi2X() > 0 && (tp->GetChi2X() < ti->GetChi2X() || ti->GetChi2X() <=0) ) tp_score++ ;
1011    //        if(      ti->GetChi2X() > 0 && (ti->GetChi2X() < tp->GetChi2X() || tp->GetChi2X() <=0) ) ti_score++ ;
1012              // CHECK 4 : chi**2 along Y  
1013    //        if(      tp->GetChi2Y() > 0 && (tp->GetChi2Y() < ti->GetChi2Y() || ti->GetChi2Y() <=0) ) tp_score++ ;
1014    //        if(      ti->GetChi2Y() > 0 && (ti->GetChi2Y() < tp->GetChi2Y() || tp->GetChi2Y() <=0) ) ti_score++ ;
1015              // CHECK 5 : total chi**2  
1016    //        if(      tp->chi2 > 0 && (tp->chi2 < ti->chi2 || ti->chi2 <=0) ) tp_score++ ;
1017    //        if(      ti->chi2 > 0 && (ti->chi2 < tp->chi2 || tp->chi2 <=0) ) ti_score++ ;
1018    
1019            //      cout << "TRK "<<tp_score<<ti_score<<endl;
1020          };
1021                            
1022              // ------------------------  
1023              // the winner is....  
1024              // ------------------------            // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1025              if      (tp_score > ti_score) {        // the winner is....
1026  //              ts = tp;//the track sorted by the tracker!!        // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1027  //              cs = cp;        if      (tp_score > ti_score) {
1028  //              os = op;          
1029              }else if (tp_score < ti_score) {  
1030                  ts = ti;//its image!!        }else if (tp_score < ti_score) {
1031                  cs = ci;  
1032                  os = oi;  
1033            ts = ti;//its image!!
1034                  ti = tp;//its image!!          cs = ci;
1035                  ci = cp;          os = oi;
1036                  oi = op;          Int_t totis = toti_score;
1037    
1038                  tp = ts;//its image!!          ti = tp;//its image!!
1039                  cp = cs;          ci = cp;
1040                  op = os;          oi = op;
1041    
1042            tp = ts;//its image!!
1043            cp = cs;
1044            op = os;
1045    
1046            toti_score = totp_score;
1047            totp_score = totis;
1048    
1049                                    
1050              }else {        }else {
1051  //              ts = tp;  
1052  //              cs = cp;  //      cout << "Warning - track image ambiguity not solved" << endl;
1053  //              os = op;  
1054  //                              cout << "Warning - track image ambiguity not solved" << endl;        };
 //                              cout << ts->GetNtot() << " "<< ts->chi2 << " " << npcfit[1] << " "<< nphit_p << endl;  
             };  
1055                            
1056          }else{      }else{
1057  //          ts = tp;        totp_score = 1;
1058  //          cs = cp;        toti_score = 0;
1059  //          os = op;        
1060          };        //            ts = tp;
1061                  //            cs = cp;
1062  //      cout <<" SortTracks() "<<i<<" -- "<<ts<<endl;        //            os = op;
1063  //      sorted_tracks->Add(ts);//save the track in the sorted array      };
1064  //      sorted_tracks.Add(ts);//save the track in the sorted array          
1065  //      sorted_tracks.Add(tp);//save the track in the sorted array      //  cout <<" SortTracks() "<<i<<" -- "<<ts<<endl;
1066  //      cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl;      //  sorted_tracks->Add(ts);//save the track in the sorted array
1067  //      cout<<"o "<<tp<<endl;      //  sorted_tracks.Add(ts);//save the track in the sorted array
1068  //      cout<<"o "<<cp<<endl;      //  sorted_tracks.Add(tp);//save the track in the sorted array
1069  //      cout<<"o "<<op<<endl;      //  cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl;
1070          new(ttsorted[i]) PamTrack(tp,cp,op);      //  cout<<"o "<<tp<<endl;
1071          new(ttimage[i])  PamTrack(ti,ci,oi);      //  cout<<"o "<<cp<<endl;
1072      };      //  cout<<"o "<<op<<endl;
1073    
1074      if( tsorted->GetEntries() != trk2_obj->GetNTracks() ){      new(ttsorted[i]) PamTrack(tp,cp,op);
1075          cout << "void PamLevel2::SortTracks(TString how): tsorted->GetEntries() "<<tsorted->GetEntries()<<" != trk2_obj->GetNTracks() = "<<trk2_obj->GetNTracks() <<endl;      new(ttimage[i])  PamTrack(ti,ci,oi);
1076          tsorted->Delete(); tsorted=0;  
1077          timage->Delete(); timage=0;          ((PamTrack*)(ttsorted[i]))->SetPScore(totp_score);
1078      }      ((PamTrack*)(ttsorted[i]))->SetIScore(toti_score);
1079        ((PamTrack*)(ttimage[i]))->SetPScore(totp_score);
1080      //Restore Object count      ((PamTrack*)(ttimage[i]))->SetIScore(toti_score);
1081      //To save space in the table keeping track of all referenced objects    };
1082      //We reset the object count to what it was at the beginning of the event.  
1083      TProcessID::SetObjectCount(ObjectNumber);    if( tsorted->GetEntries() != trk2_obj->GetNTracks() ){
1084        cout << "void PamLevel2::SortTracks(): tsorted->GetEntries() "<<tsorted->GetEntries()<<" != trk2_obj->GetNTracks() = "<<trk2_obj->GetNTracks() <<endl;
1085        tsorted->Delete(); tsorted=0;
1086        timage->Delete(); timage=0;
1087      }
1088    
1089      //Restore Object count
1090      //To save space in the table keeping track of all referenced objects
1091      //We reset the object count to what it was at the beginning of the event.
1092      TProcessID::SetObjectCount(ObjectNumber);
1093            
1094  };  };
1095  //--------------------------------------  //--------------------------------------
# Line 638  void PamLevel2::SortTracks(TString how){ Line 1113  void PamLevel2::SortTracks(TString how){
1113  TClonesArray *PamLevel2::GetTracks(){  TClonesArray *PamLevel2::GetTracks(){
1114    
1115  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
1116      SortTracks("+CAL+TOF");      SortTracks();
1117  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
1118    
1119      return tsorted;      return tsorted;
# Line 657  PamTrack *PamLevel2::GetTrack(int it){ Line 1132  PamTrack *PamLevel2::GetTrack(int it){
1132    
1133  //    if(!trk2_obj) return 0;  //    if(!trk2_obj) return 0;
1134                    
1135  // //  *-*-*-*-*-*-*-*-*-*-*-*-*  // //  *-*-*-*+-*-*-*-*-*-*-*-*-*
1136  //     SortTracks("+CAL+TOF");  //     SortTracks("+CAL+TOF");
1137  // //  *-*-*-*-*-*-*-*-*-*-*-*-*  // //  *-*-*-*-*-*-*-*-*-*-*-*-*
1138  // //    if(!sorted_tracks)return 0;  // //    if(!sorted_tracks)return 0;
# Line 676  PamTrack *PamLevel2::GetTrack(int it){ Line 1151  PamTrack *PamLevel2::GetTrack(int it){
1151    
1152  //    cout << "PamLevel2::GetTrack(int it) "<<endl;  //    cout << "PamLevel2::GetTrack(int it) "<<endl;
1153  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
1154      SortTracks("+CAL+TOF");      SortTracks();
1155  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
1156      if(!tsorted)return 0;      if(!tsorted)return 0;
1157      if(!tsorted->GetEntries())return 0;      if(!tsorted->GetEntries())return 0;
# Line 733  PamTrack *PamLevel2::GetTrackImage(int i Line 1208  PamTrack *PamLevel2::GetTrackImage(int i
1208    
1209    
1210  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
1211      SortTracks("+CAL+TOF");      SortTracks();
1212  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
1213      if(!timage)return 0;      if(!timage)return 0;
1214      if(!timage->GetEntries())return 0;      if(!timage->GetEntries())return 0;
# Line 770  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1245  TTree *PamLevel2::GetPamTree(TFile *f, T
1245    
1246  //     if( !detlist.IsNull() ) SetWhichTrees(detlist);  //     if( !detlist.IsNull() ) SetWhichTrees(detlist);
1247  //     else                    GetWhichTrees(f);  //     else                    GetWhichTrees(f);
1248      if ( pam_tree ){
1249        printf("WARNING: TTree *PamLevel2::GetPamTree(TFile *fl, TString detlist) -- pam_tree already exists!\n ");
1250        return pam_tree;
1251      };
1252      //
1253    
1254        cout << "TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ) -- obsolte "<<endl;
1255    
1256      SetWhichTrees(detlist);      SetWhichTrees(detlist);
1257    
1258      TTree *Trout =0;      TTree *Trout =0;
# Line 777  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1260  TTree *PamLevel2::GetPamTree(TFile *f, T
1260      TString fname = f->GetName();      TString fname = f->GetName();
1261      if(!CheckLevel2File(fname))return NULL;      if(!CheckLevel2File(fname))return NULL;
1262    
1263      UInt_t *found=0;      //    UInt_t *found=0;    
1264    
1265      cout<< "GetPamTree(TFile*,TString): detector list --> ";      cout<< "GetPamTree(TFile*,TString): detector list --> ";
1266      if(TRK1)cout<<"TRK1 ";      if(TRK1)cout<<"TRK1 ";
# Line 792  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1275  TTree *PamLevel2::GetPamTree(TFile *f, T
1275      if(S4)cout<<"S4 ";      if(S4)cout<<"S4 ";
1276      if(ORB)cout<<"ORB ";      if(ORB)cout<<"ORB ";
1277      cout << endl;      cout << endl;
1278        if(SELLI)cout<<">>> Found selection-list <<<"<<endl;
1279    
1280      f->cd();      f->cd();
1281    
# Line 799  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1283  TTree *PamLevel2::GetPamTree(TFile *f, T
1283      TTree *T = (TTree*)f->Get("Tracker");      TTree *T = (TTree*)f->Get("Tracker");
1284      if(T && (TRK2||TRK1||TRKh)) {      if(T && (TRK2||TRK1||TRKh)) {
1285          if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));          if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
1286          else    T->SetBranchStatus("TrkLevel2",0,found);  //      else    T->SetBranchStatus("TrkLevel2",0,found);
1287          if(TRK2)cout << "Tracker      : set branch address TrkLevel2"<<endl;          if(TRK2)cout << "Tracker      : set branch address TrkLevel2"<<endl;
1288          if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));          if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
1289          else    T->SetBranchStatus("TrkLevel1",0,found);  //      else    T->SetBranchStatus("TrkLevel1",0,found);
1290          if(TRK1)cout << "Tracker      : set branch address TrkLevel1"<<endl;          if(TRK1)cout << "Tracker      : set branch address TrkLevel1"<<endl;
1291          if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));          if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
1292          else    T->SetBranchStatus("TrkHough",0,found);  //      else    T->SetBranchStatus("TrkHough",0,found);
1293          if(TRKh)cout << "Tracker      : set branch address TrkHough"<<endl;          if(TRKh)cout << "Tracker      : set branch address TrkHough"<<endl;
1294          if(!Trout)Trout=T;          if(!Trout)Trout=T;
1295          else Trout->AddFriend(T);          else Trout->AddFriend(T);
# Line 816  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1300  TTree *PamLevel2::GetPamTree(TFile *f, T
1300      TTree *C = (TTree*)f->Get("Calorimeter");      TTree *C = (TTree*)f->Get("Calorimeter");
1301      if(C && (CAL2||CAL1)) {      if(C && (CAL2||CAL1)) {
1302          if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));          if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
1303          else    C->SetBranchStatus("CaloLevel2",0,found);  //      else    C->SetBranchStatus("CaloLevel2",0,found);
1304          if(CAL2)cout << "Calorimeter  : set branch address CaloLevel2"<<endl;          if(CAL2)cout << "Calorimeter  : set branch address CaloLevel2"<<endl;
1305          if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));          if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
1306          else    C->SetBranchStatus("CaloLevel1",0,found);  //      else    C->SetBranchStatus("CaloLevel1",0,found);
1307          if(CAL1)cout << "Calorimeter  : set branch address CaloLevel1"<<endl;          if(CAL1)cout << "Calorimeter  : set branch address CaloLevel1"<<endl;
1308          if(!Trout)Trout=C;          if(!Trout)Trout=C;
1309          else Trout->AddFriend(C);          else Trout->AddFriend(C);
# Line 842  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1326  TTree *PamLevel2::GetPamTree(TFile *f, T
1326      if(R && TRG) {      if(R && TRG) {
1327          R->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));          R->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));
1328          cout << "Trigger      : set branch address TrigLevel2"<<endl;          cout << "Trigger      : set branch address TrigLevel2"<<endl;
1329          if(!Trout)Trout=O;          if(!Trout)Trout=R;
1330          else Trout->AddFriend(R);          else Trout->AddFriend(R);
1331      }else{      }else{
1332          cout << "Trigger      : missing tree"<<endl;          cout << "Trigger      : missing tree"<<endl;
# Line 852  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1336  TTree *PamLevel2::GetPamTree(TFile *f, T
1336      if(S && S4) {      if(S && S4) {
1337          S->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));          S->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));
1338          cout << "S4           : set branch address S4Level2"<<endl;          cout << "S4           : set branch address S4Level2"<<endl;
1339          if(!Trout)Trout=O;          if(!Trout)Trout=S;
1340          else Trout->AddFriend(S);          else Trout->AddFriend(S);
1341      }else{      }else{
1342          cout << "S4           : missing tree"<<endl;          cout << "S4           : missing tree"<<endl;
# Line 862  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1346  TTree *PamLevel2::GetPamTree(TFile *f, T
1346      if(N && ND) {      if(N && ND) {
1347          N->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));          N->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));
1348          cout << "NeutronD     : set branch address NDLevel2"<<endl;          cout << "NeutronD     : set branch address NDLevel2"<<endl;
1349          if(!Trout)Trout=O;          if(!Trout)Trout=N;
1350          else Trout->AddFriend(N);          else Trout->AddFriend(N);
1351      }else{      }else{
1352          cout << "NeutronD     : missing tree"<<endl;          cout << "NeutronD     : missing tree"<<endl;
# Line 872  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1356  TTree *PamLevel2::GetPamTree(TFile *f, T
1356      if(A && AC) {      if(A && AC) {
1357          A->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));          A->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));
1358          cout << "Anticounter  : set branch address AcLevel2"<<endl;          cout << "Anticounter  : set branch address AcLevel2"<<endl;
1359          if(!Trout)Trout=O;          if(!Trout)Trout=A;
1360          else Trout->AddFriend(A);          else Trout->AddFriend(A);
1361      }else{      }else{
1362          cout << "Anticounter  : missing tree"<<endl;          cout << "Anticounter  : missing tree"<<endl;
# Line 882  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1366  TTree *PamLevel2::GetPamTree(TFile *f, T
1366      if(B && ORB) {      if(B && ORB) {
1367          B->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));          B->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
1368          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;
1369          if(!Trout)Trout=O;          if(!Trout)Trout=B;
1370          else Trout->AddFriend(B);          else Trout->AddFriend(B);
1371      }else{      }else{
1372          cout << "OrbitalInfo  : missing tree"<<endl;          cout << "OrbitalInfo  : missing tree"<<endl;
1373      };      };
1374    
1375        TTree *L = (TTree*)f->Get("SelectionList");
1376        if(L && SELLI==1) {
1377    //      L->SetBranchAddress("RunEntry",&irun);
1378    //      cout << "SelectionList: set branch address RunEntry"<<endl;
1379    //      L->SetBranchAddress("EventEntry",&irunentry);
1380    //      cout << "SelectionList: set branch address EventEntry"<<endl;
1381    //      if(!Trout)Trout=O;
1382    //      else Trout->AddFriend("SelectionList");
1383            cout << " TTree *PamLevel2::GetPamTree(TFile, TString) >>> SelectionList not implemente!!!!"<<endl;
1384            sel_tree = 0;
1385        }else{
1386            cout << "SelectionList  : missing tree"<<endl;
1387        };
1388            
1389      cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;      cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;
1390    
1391        pam_tree = (TChain*)Trout;
1392            
1393      return Trout;      return Trout;
1394            
# Line 908  TList*  PamLevel2::GetListOfLevel2Files( Line 1408  TList*  PamLevel2::GetListOfLevel2Files(
1408                    
1409      TString wdir = gSystem->WorkingDirectory();      TString wdir = gSystem->WorkingDirectory();
1410            
1411      if(ddir=="")ddir = wdir;      //    if(ddir=="")ddir = wdir;
1412  //      TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);  //      TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);
1413      cout << "Level2 data directory : "<<  ddir << endl;      if ( ddir != ""){
1414              cout << "Level2 data directory : "<<  ddir << endl;
1415        } else {
1416          cout << "Level2 data directory not given as input: trying to evaluate from list or taking working directory " << endl;
1417        };
1418      TList *contents  = new TList; // create output list      TList *contents  = new TList; // create output list
1419      contents->SetOwner();      contents->SetOwner();
1420            
1421  //    char *fullpath;  //    char *fullpath;
1422      const char *fullpath;  //    const char *fullpath;
1423            
1424      // if no input file list is given:        // if no input file list is given:  
1425      if ( flisttxt != "" ){      if ( flisttxt != "" ){
1426                    
1427  //      if( !gSystem->IsFileInIncludePath(flisttxt,&fullpath) ){          //      if( !gSystem->IsFileInIncludePath(flisttxt,&fullpath) ){        
1428          if( !(fullpath = gSystem->FindFile("./",flisttxt)) ){  //      if( !(fullpath = gSystem->FindFile("./",flisttxt)) ){
1429              cout <<"File "<<flisttxt<<" not found"<<endl;  //          cout <<"File "<<flisttxt<<" not found"<<endl;
1430              return 0;  //          return 0;
1431          }        //      }      
1432  //              flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));  //      flisttxt = fullpath;
1433          flisttxt = fullpath;        if ( !flisttxt.EndsWith(".root") ){
1434    
1435            flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
1436    
1437          if( !gSystem->ChangeDirectory(ddir) ){          if( !gSystem->ChangeDirectory(ddir) ){
1438              cout << "Cannot change directory : "<<ddir<<endl;              cout << "Cannot change directory : "<<ddir<<endl;
# Line 937  TList*  PamLevel2::GetListOfLevel2Files( Line 1442  TList*  PamLevel2::GetListOfLevel2Files(
1442          cout <<"Input file list : " << flisttxt <<endl;          cout <<"Input file list : " << flisttxt <<endl;
1443          ifstream in;          ifstream in;
1444          in.open(flisttxt, ios::in); //open input file list          in.open(flisttxt, ios::in); //open input file list
1445            if(!in.good()){
1446                cout <<" ERROR opening the file "<<endl;
1447                gSystem->ChangeDirectory(wdir); // back to the working directory
1448                return 0;
1449            }      
1450          int line=0;          int line=0;
1451          while (1) {          while (1) {
1452              TString file;              TString file;
# Line 951  TList*  PamLevel2::GetListOfLevel2Files( Line 1461  TList*  PamLevel2::GetListOfLevel2Files(
1461              if(file.Contains("#"))file = file(0,file.First("#"));              if(file.Contains("#"))file = file(0,file.First("#"));
1462  //          cout <<"(2) " << file << endl;  //          cout <<"(2) " << file << endl;
1463  //          if( gSystem->IsFileInIncludePath(file,&fullpath) ){  //          if( gSystem->IsFileInIncludePath(file,&fullpath) ){
1464              if( (fullpath = gSystem->FindFile(ddir,file)) ){  //          if( (fullpath = gSystem->FindFile(ddir,file)) ){
1465                if( file.EndsWith(".root") ){
1466                  TString filedir;
1467                  if (ddir != ""){
1468                    filedir = ddir; // take the input dir
1469                  } else {
1470                    gSystem->ChangeDirectory(wdir); // back to the working directory
1471                    filedir = gSystem->DirName(file); // this will take the path if exist in the list otherwise it will return automatically the working dir
1472                  };
1473                    char *fullpath = gSystem->ConcatFileName(gSystem->DirName(filedir),gSystem->BaseName(file));
1474                  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
1475                    delete fullpath;
1476              }else{              }
1477    //          }else{
1478  //              if(file.Data()!="")cout << "File: "<<file<<" ---> missing "<< endl;  //              if(file.Data()!="")cout << "File: "<<file<<" ---> missing "<< endl;
1479              };  //          };
1480          };          };
1481          in.close();          in.close();
1482                  } else {
1483              if(flisttxt.Contains("#"))flisttxt = flisttxt(0,flisttxt.First("#"));
1484              char *fullpath = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
1485              contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list
1486              delete fullpath;
1487          };        
1488      }else{      }else{
1489                    
1490          cout << "No input file list given."<<endl;          cout << "No input file list given."<<endl;
1491          cout << "Check for existing root files."<<endl;          cout << "Check for existing root files."<<endl;
1492  //              cout << "Warking directory: "<< gSystem->WorkingDirectory()<< endl;  //              cout << "Warking directory: "<< gSystem->WorkingDirectory()<< endl;
1493                    if ( ddir == "" ){
1494              ddir = wdir;
1495              cout << "Level2 data directory : "<<  ddir << endl;
1496            };
1497    
1498          TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);          TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);
1499          TList *temp = datadir->GetListOfFiles();          TList *temp = datadir->GetListOfFiles();
1500  //              temp->Print();  //              temp->Print();
# Line 979  TList*  PamLevel2::GetListOfLevel2Files( Line 1507  TList*  PamLevel2::GetListOfLevel2Files(
1507          while ( (questo = (TSystemFile*) next()) ) {          while ( (questo = (TSystemFile*) next()) ) {
1508              TString name =  questo-> GetName();              TString name =  questo-> GetName();
1509              if( name.EndsWith(".root") ){              if( name.EndsWith(".root") ){
1510                  const char *fullpath = gSystem->FindFile(ddir,name);  //              const char *fullpath = gSystem->FindFile(ddir,name);
1511  //              char *fullpath;  //              char *fullpath;
1512  //              gSystem->IsFileInIncludePath(name,&fullpath);  //              gSystem->IsFileInIncludePath(name,&fullpath);
1513                    char *fullpath = gSystem->ConcatFileName(gSystem->DirName(ddir),gSystem->BaseName(name));
1514                  contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));                  contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));
1515                    delete fullpath;
1516              };              };
1517          }          }
1518          delete temp;          delete temp;
# Line 992  TList*  PamLevel2::GetListOfLevel2Files( Line 1522  TList*  PamLevel2::GetListOfLevel2Files(
1522      gSystem->ChangeDirectory(wdir); // back to the working directory      gSystem->ChangeDirectory(wdir); // back to the working directory
1523  //      cout << endl << "Selected files:" << endl;  //      cout << endl << "Selected files:" << endl;
1524  //      contents->Print();  //      contents->Print();
1525      cout << contents->GetEntries()<<" files selected\n";      cout << contents->GetEntries()<<" files \n";
1526  //      cout << endl;  //      cout << endl;
1527  //      cout << "Working directory: "<< gSystem->WorkingDirectory()<< endl;  //      cout << "Working directory: "<< gSystem->WorkingDirectory()<< endl;
1528      return contents;      return contents;
# Line 1008  TList*  PamLevel2::GetListOfLevel2Files( Line 1538  TList*  PamLevel2::GetListOfLevel2Files(
1538   * @return Pointer to a TChain   * @return Pointer to a TChain
1539   */   */
1540  TChain *PamLevel2::GetPamTree(TList *fl, TString detlist ){  TChain *PamLevel2::GetPamTree(TList *fl, TString detlist ){
1541      //
1542      //
1543      //
1544      if ( pam_tree ){
1545        printf("WARNING: TChain *PamLevel2::GetPamTree(TList *fl, TString detlist) -- pam_tree already exists!\n ");
1546        return pam_tree;
1547      };
1548      //
1549            
1550      TChain *Trout =0;      TChain *Trout =0;
1551    
# Line 1028  TChain *PamLevel2::GetPamTree(TList *fl, Line 1566  TChain *PamLevel2::GetPamTree(TList *fl,
1566      if(ORB)cout<<"ORB ";      if(ORB)cout<<"ORB ";
1567      cout << endl;      cout << endl;
1568    
1569      TChain *T = 0;             TChain *T = 0;    
1570      TChain *C = 0;       TChain *C = 0;
1571      TChain *O = 0;       TChain *O = 0;
1572      TChain *R = 0;       TChain *R = 0;
1573      TChain *S = 0;       TChain *S = 0;
1574      TChain *N = 0;       TChain *N = 0;
1575      TChain *A = 0;       TChain *A = 0;
1576      TChain *B = 0;       TChain *B = 0;
1577    
1578         TChain *L = 0;
1579            
1580      if(TRK2||TRK1||TRKh) T = new TChain("Tracker");          if(TRK2||TRK1||TRKh) T = new TChain("Tracker");    
1581      if(CAL2||CAL1)       C = new TChain("Calorimeter");      if(CAL2||CAL1)       C = new TChain("Calorimeter");
# Line 1045  TChain *PamLevel2::GetPamTree(TList *fl, Line 1585  TChain *PamLevel2::GetPamTree(TList *fl,
1585      if(ND)               N = new TChain("NeutronD");      if(ND)               N = new TChain("NeutronD");
1586      if(AC)               A = new TChain("Anticounter");      if(AC)               A = new TChain("Anticounter");
1587      if(ORB)              B = new TChain("OrbitalInfo");      if(ORB)              B = new TChain("OrbitalInfo");
1588         L = new TChain("SelectionList");
1589            
1590      // loop over files and create chains              // loop over files and create chains        
1591      TIter next(fl);      TIter next(fl);
# Line 1061  TChain *PamLevel2::GetPamTree(TList *fl, Line 1602  TChain *PamLevel2::GetPamTree(TList *fl,
1602              if(ND)               N->Add(name);              if(ND)               N->Add(name);
1603              if(AC)               A->Add(name);              if(AC)               A->Add(name);
1604              if(ORB)              B->Add(name);              if(ORB)              B->Add(name);
1605                if(SELLI==1)         L->Add(name);
1606          };          };
1607      }      };
1608            
1609      cout << "done chain \n";      cout << "done chain \n";
1610        cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
1611    
1612      UInt_t *found=0;  //    UInt_t *found=0;
1613  // Tracker  // Tracker
1614      if(T && (TRK2||TRK1||TRKh)) {      if(T && (TRK2||TRK1||TRKh)) {
1615          if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));          if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
1616          else    T->SetBranchStatus("TrkLevel2",0,found);  //      else    T->SetBranchStatus("TrkLevel2",0,found);
1617          if(TRK2)cout << "Tracker      : set branch address TrkLevel2"<<endl;          if(TRK2)cout << "Tracker      : set branch address TrkLevel2"<<endl;
1618          if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));          if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
1619          else    T->SetBranchStatus("TrkLevel1",0,found);  //      else    T->SetBranchStatus("TrkLevel1",0,found);
1620          if(TRK1)cout << "Tracker      : set branch address TrkLevel1"<<endl;          if(TRK1)cout << "Tracker      : set branch address TrkLevel1"<<endl;
1621          if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));          if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
1622          else    T->SetBranchStatus("TrkHough",0,found);  //      else    T->SetBranchStatus("TrkHough",0,found);
1623          if(TRKh)cout << "Tracker      : set branch address TrkHough"<<endl;          if(TRKh)cout << "Tracker      : set branch address TrkHough"<<endl;
1624          if(!Trout)Trout=T;          if(!Trout)Trout=T;
1625          else Trout->AddFriend("Tracker");          else Trout->AddFriend("Tracker");
1626      }else{      }else{
1627          cout << "Tracker      : missing tree"<<endl;          cout << "Tracker      : missing tree"<<endl;
1628      };      };
1629      // Calorimeter      // Calorimeter
1630      if(C && (CAL2||CAL1)) {      if(C && (CAL2||CAL1)) {
1631          if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));          if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
1632          else    C->SetBranchStatus("CaloLevel2",0,found);  //      else    C->SetBranchStatus("CaloLevel2",0,found);
1633          if(CAL2)cout << "Calorimeter  : set branch address CaloLevel2"<<endl;          if(CAL2)cout << "Calorimeter  : set branch address CaloLevel2"<<endl;
1634          if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));          if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
1635          else    C->SetBranchStatus("CaloLevel1",0,found);  //      else    C->SetBranchStatus("CaloLevel1",0,found);
1636          if(CAL1)cout << "Calorimeter  : set branch address CaloLevel1"<<endl;          if(CAL1)cout << "Calorimeter  : set branch address CaloLevel1"<<endl;
1637          if(!Trout)Trout=C;          if(!Trout)Trout=C;
1638          else Trout->AddFriend("Calorimeter");          else Trout->AddFriend("Calorimeter");
# Line 1150  TChain *PamLevel2::GetPamTree(TList *fl, Line 1693  TChain *PamLevel2::GetPamTree(TList *fl,
1693      }else{      }else{
1694          cout << "OrbitalInfo  : missing tree"<<endl;          cout << "OrbitalInfo  : missing tree"<<endl;
1695      };      };
1696        cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
1697    
1698        // Selection List
1699        if(L && SELLI==1) {
1700            cout<<">>> Found selection-list <<<"<<endl;
1701            L->SetBranchAddress("RunEntry",&irun);
1702            cout << "SelectionList: set branch address RunEntry"<<endl;
1703            L->SetBranchAddress("EventEntry",&irunentry);
1704            cout << "SelectionList: set branch address EventEntry"<<endl;
1705            sel_tree = L;
1706    //      if(!Trout)Trout=O;
1707    //      else Trout->AddFriend("SelectionList");
1708            cout << "----------------------------------------------------" <<endl;
1709        }else{
1710    //      cout << "SelectionList  : missing tree"<<endl;
1711            if(L)L->Delete();
1712        };
1713            
1714  //    cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;  //    cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;
1715    
1716            pam_tree = Trout;
1717  //     // 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 );  
       
1718      return Trout;      return Trout;
1719  }  }
1720    
# Line 1280  void PamLevel2::SetBranchAddress(TTree * Line 1796  void PamLevel2::SetBranchAddress(TTree *
1796          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
1797          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;
1798      };      };
1799        // SelectionList
1800        if(SELLI==1) {
1801            t->SetBranchAddress("RunEntry", &irun);
1802            cout << "SelectionList: set branch address RunEntry"<<endl;
1803            t->SetBranchAddress("EventEntry", &irunentry);
1804            cout << "SelectionList: set branch address EventEntry"<<endl;
1805        };
1806            
1807  }  }
1808  /**  /**
# Line 1353  void PamLevel2::SetBranchAddress(TChain Line 1876  void PamLevel2::SetBranchAddress(TChain
1876          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
1877          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;
1878      };      };
1879        // SelectionList
1880        if(SELLI==1) {
1881            t->SetBranchAddress("RunEntry", &irun);
1882            cout << "SelectionList: set branch address RunEntry"<<endl;
1883            t->SetBranchAddress("EventEntry", &irunentry);
1884            cout << "SelectionList: set branch address EventEntry"<<endl;
1885        };
1886            
1887  }  }
1888    
# Line 1367  void PamLevel2::SetBranchAddress(TChain Line 1897  void PamLevel2::SetBranchAddress(TChain
1897   * @return Pointer to a TChain   * @return Pointer to a TChain
1898   */   */
1899  TChain *PamLevel2::GetRunTree(TList *fl){  TChain *PamLevel2::GetRunTree(TList *fl){
1900              //
1901      TChain *R = new TChain("Run");    //
1902      //
1903      if ( run_tree ){
1904        printf("WARNING: TChain *PamLevel2::GetRunTree(TList *fl) -- run_tree already exists!\n ");
1905        return run_tree;
1906      };    
1907      //
1908      TChain *R = new TChain("Run");
1909            
1910      // loop over files and create chains              // loop over files and create chains        
1911      TIter next(fl);      TIter next(fl);
# Line 1380  TChain *PamLevel2::GetRunTree(TList *fl) Line 1917  TChain *PamLevel2::GetRunTree(TList *fl)
1917              R->Add(name);              R->Add(name);
1918          };          };
1919      }      }
1920    
1921        if(R->GetNtrees()){
1922            
1923      R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));          R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
1924      cout << "Run         : set branch address RunInfo"<<endl;          cout << "Run         : set branch address RunInfo"<<endl;
1925      R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano          R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
1926      cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano          cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano
1927            }else{
1928            delete R;
1929            R=0;
1930        }
1931    
1932        run_tree = R;
1933    
1934      return R;      return R;
1935            
1936  }  }
# Line 1399  TChain *PamLevel2::GetRunTree(TList *fl) Line 1944  TChain *PamLevel2::GetRunTree(TList *fl)
1944   * @return Pointer to a TTree   * @return Pointer to a TTree
1945   */   */
1946  TTree *PamLevel2::GetRunTree(TFile *f){  TTree *PamLevel2::GetRunTree(TFile *f){
1947      if ( run_tree ){
1948        printf("WARNING: TTree *PamLevel2::GetRunTree(TFile *f) -- run_tree already exists!\n ");
1949        return run_tree;
1950      };
1951            
1952    
1953        cout << "TTree *PamLevel2::GetRunTree(TFile *f) -- obsolte "<<endl;
1954    
1955      TTree *R = (TTree*)f->Get("Run");      TTree *T = (TTree*)f->Get("Run");
       
     R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));  
     cout << "Run         : set branch address RunInfo"<<endl;  
     R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano  
     cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano  
1956            
1957      return R;      if(T){
1958            T->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
1959            cout << "Run         : set branch address RunInfo"<<endl;
1960            T->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
1961            cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano
1962        }
1963    
1964        run_tree = (TChain*)T;
1965    
1966        return T;
1967            
1968  }  }
1969    /**
1970     * Update the runinfo informations (to be used to have Run infos event by event basis)
1971     * @param run Pointer to the chain/tree which contains run infos
1972     * @return true if a new run has been read, false if it is still the same run
1973     */
1974    Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev){
1975      //
1976      // check if we have already called once GetEntry, if not call it
1977      //
1978        cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev) --- NON FUNZIONA BENISSIMO.... "<<endl;
1979        if(!run){
1980              cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing RunInfo tree "<<endl;
1981              return(false);        
1982        }
1983        if ( run->GetEntries() <= 0 ) return(false);
1984      //
1985      
1986      //  Int_t oldrun = irun;
1987      Long64_t oldrun = irun;
1988    
1989      // --------------------------------------
1990      // if it is a full file (not preselected)
1991      // --------------------------------------
1992      if(SELLI==0){
1993    
1994          //
1995          // the absolute time is necessary to relate the event with the run
1996          //
1997          if( !GetOrbitalInfo() && !ISGP){
1998              cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;
1999              return(false);
2000          }
2001    
2002          ULong64_t abstime = 0;
2003          if( GetOrbitalInfo() )abstime=GetOrbitalInfo()->absTime;
2004    
2005    
2006          //
2007          // the first time the routine is called, set run search from the beginning
2008          //
2009          if ( irun < 0LL ){
2010              irun = 0LL;
2011              run->GetEntry(irun);
2012              runfirstentry = 0LL;
2013              runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
2014              if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;
2015              
2016              if( ISGP && run->GetEntries()!=1 ){
2017                  cout << "** WARNING ** simulated files are assumed to have 1 single run, not "<< run->GetEntries() << endl;
2018                  cout << "** WARNING ** run will not be updated"<<endl;
2019              }
2020    
2021          };      
2022          //
2023          if(ISGP)abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO
2024          //
2025          if ( irun == run->GetEntries()-1LL &&
2026               !(abstime >= GetRunInfo()->RUNHEADER_TIME &&
2027                 abstime <= GetRunInfo()->RUNTRAILER_TIME)
2028                ){
2029             irun = -1LL;
2030             runfirstentry = 0LL;
2031             runlastentry = -1LL;
2032           };
2033          // modificato il controllo sull'aggiornamento del run, per evitare problemi
2034          // dovuti agli eventi annidati (NB! NEVENTS conta anche questi!!)
2035          //
2036          bool fromfirst = true;
2037          //
2038          while ( !(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME) && irun < run->GetEntries()-1LL ){
2039    //      while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){
2040              irun++;
2041              run->GetEntry(irun);
2042              runfirstentry = runlastentry;
2043              if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runfirstentry += 1LL;
2044              runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
2045    //        cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2046    //        cout << "runfirstentry "<<runfirstentry<<endl;
2047              //      printf(" iev %llu %u %llu \n",iev,this->GetRunInfo()->NEVENTS,(ULong64_t)(runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS)));
2048              //      printf(" abstime %u trailertime %u \n",abstime,GetRunInfo()->RUNTRAILER_TIME);
2049              //      printf(" IDRUN %u \n",GetRunInfo()->ID);
2050              //
2051    //        prevshift = 0;
2052              //
2053              if ( irun == (Long64_t)(run->GetEntries()-1LL) && fromfirst && !(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME)){
2054                  printf(" resetting irun  (it should NOT happen!!!)\n");
2055                  fromfirst = false;
2056                  irun = 0;
2057                  run->GetEntry(irun);
2058                  runfirstentry = 0ULL;
2059                  runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
2060                  if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;
2061              };
2062              //
2063          };
2064          //
2065          if (
2066               !(abstime >= GetRunInfo()->RUNHEADER_TIME &&
2067                 abstime <= GetRunInfo()->RUNTRAILER_TIME)
2068              ) {
2069            printf(" Something very wrong here: cannot find RUN containing absolute time %llu \n",abstime);
2070              return false;
2071          }
2072          //
2073          if ( irun == oldrun || irun >= run->GetEntries() ) return(false);
2074          //
2075          //  printf(" iev %llu irun %i nevents %u 1st %llu last %llu \n",iev,irun,this->GetRunInfo()->NEVENTS,(ULong64_t)runfirstentry,(ULong64_t)runlastentry);
2076          //
2077          prevshift = 0;
2078          cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2079    //      cout << "runfirstentry "<<runfirstentry<<endl;
2080          return(true);    
2081      };
2082      // ----------------------------------------------------
2083      // if it is a preselected file (there is SelectionList)
2084      // NBNB - the event tree MUST be read first
2085      // ----------------------------------------------------
2086      if(SELLI==1){      
2087          sel_tree->GetEntry(iev);
2088    //      cout << irun << " "<< irunentry << endl;
2089          if(irun != oldrun){
2090              run->GetEntry(irun);
2091              cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2092              prevshift = 0;
2093              return true;
2094          }
2095          return false;
2096      }
2097    
2098      return false;
2099      //
2100    };
2101    
2102    Bool_t PamLevel2::UpdateRunInfo(Long64_t iev){
2103    
2104        if(!run_tree){
2105            cout << " Bool_t PamLevel2::UpdateRunInfo(ULong64_t iev) -- ERROR -- run tree not loaded"<<endl;
2106            return false;
2107        }
2108        if ( run_tree->GetEntries() <= 0 ) {
2109            cout << " Bool_t PamLevel2::UpdateRunInfo(ULong64_t iev) -- ERROR -- run tree is empty"<<endl;
2110            return(false);
2111        }
2112      
2113        Int_t oldrun = irun; // store current run index
2114    
2115        // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2116        // if it is a full file (not preselected)
2117        // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2118        if(SELLI==0){
2119    
2120            // ---------------------------------------------------------------
2121            // increment dead and live-time counters
2122            // ---------------------------------------------------------------
2123            if( GetTrigLevel2() ){
2124                totdltime[0]+=GetTrigLevel2()->dltime[0];
2125                totdltime[1]+=GetTrigLevel2()->dltime[1];
2126            }
2127            totdltime[2]++;
2128    
2129    //      cout << setw(10)<<totdltime[0]<<setw(10)<<totdltime[1]<<setw(10)<<totdltime[2]<<endl;
2130    
2131            // ---------------------------------------------------------------
2132            // retrieve OBT and absolute time of the event
2133            // ---------------------------------------------------------------
2134            ULong64_t abstime = 0;
2135            ULong64_t obt     = 0;
2136            if( GetOrbitalInfo() ){
2137                abstime = GetOrbitalInfo()->absTime;
2138                obt     = GetOrbitalInfo()->OBT;
2139            }
2140            // ---------------------------------------------------------------
2141            // the absolute time is necessary to relate the event with the run
2142            // ---------------------------------------------------------------
2143            if( !GetOrbitalInfo() && !ISGP ){
2144                cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;
2145                return(false);
2146            }
2147          
2148            // -----------------------------------------------------------------------
2149            // the first time the routine is called, set run search from the beginning
2150            // -----------------------------------------------------------------------
2151            if ( irun < 0 ){
2152                irun = 0LL;
2153                irunentry = 0;
2154                prevshift = 0;
2155                run_tree->GetEntry(irun);
2156    
2157                if( ISGP && run_tree->GetEntries()!=1 ){
2158                    cout << "** WARNING ** simulated files are assumed to have 1 single run, not "<< run_tree->GetEntries() << endl;
2159                    cout << "** WARNING ** run will not be updated"<<endl;
2160                }
2161            };      
2162    
2163            // -----------------------------------------------------------------------
2164            // if it is simulation, assigh abstime by hand (temporaneo!!!)
2165            // -----------------------------------------------------------------------
2166            if(ISGP){
2167                abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO
2168                obt     = GetRunInfo()->RUNHEADER_OBT; // BARBATRUCCO
2169            }
2170            //
2171            bool fromfirst = true; // first loop over runs
2172    
2173    //      Bool_t hasfrag = false;
2174    //      if( GetRunInfo()->ID_RUN_FRAG!=0 && GetRunInfo()->ID_RUN_FRAG != GetRunInfo()->ID)hasfrag=true;
2175    //      ULong64_t fragid = GetRunInfo()->ID_RUN_FRAG;
2176    
2177            // ------------------------------------------------------
2178            // loop over runs to find the one that contains the event
2179            // ------------------------------------------------------
2180            while (
2181                (
2182                    (
2183                        !(abstime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s)
2184                          abstime <= GetRunInfo()->RUNTRAILER_TIME) &&
2185                        !(obt >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms)
2186                          obt <= GetRunInfo()->RUNTRAILER_OBT)
2187                        )
2188                    || GetRunInfo()->NEVENTS==0
2189                    || !(irunentry < GetRunInfo()->NEVENTS-1-prevshift)
2190                    )
2191                    && irun < run_tree->GetEntries() ){
2192    
2193    
2194    
2195    
2196                // -----------------------------------------
2197                // store dead and live-time of previous run
2198                // -----------------------------------------
2199                if(fromfirst){
2200                    if(oldrun==irun){
2201                        /// decrement counters
2202                        if( GetTrigLevel2()){
2203                            totdltime[0]-=GetTrigLevel2()->dltime[0];//live-time
2204                            totdltime[1]-=GetTrigLevel2()->dltime[1];//dead-time
2205                        }
2206                        totdltime[2]--;                              //event counter
2207                        cout << endl;
2208                        cout << "n.events     : "<<totdltime[2]<<endl;
2209                        cout << "RUN LIVE-TIME: "<<totdltime[0]*0.16<<" ms"<<endl;
2210                        cout << "RUN DEAD-TIME: "<<totdltime[1]*0.01<<" ms"<<endl;      
2211                    }else{
2212                        totdltime[0]=0;//live-time
2213                        totdltime[1]=0;//dead-time
2214                        totdltime[2]=0;                             //event counter
2215                        cout << " *** JUMP RUN *** irun "<<irun<<endl;
2216                    }
2217                    /// add an entry
2218                    if(run_tree_clone)
2219                        if(run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())
2220                            run_tree_clone->GetBranch("DeadLiveTime")->Fill();
2221                    /// reset counters
2222                    if( GetTrigLevel2() ){
2223                        totdltime[0]=GetTrigLevel2()->dltime[0];//live-time
2224                        totdltime[1]=0;                         //dead-time
2225                    }
2226                    totdltime[2]=1;                             //event counter
2227                }
2228    
2229    
2230                irun++;
2231                // ------------------------------------
2232                // if the end of run tree is reached...
2233                // ------------------------------------
2234                if( irun == run_tree->GetEntries() ){
2235                    if(!fromfirst){
2236                        // -----------------------------------------------------
2237                        // if it happened already once and the run was not found
2238                        // ---> exit with error
2239                        // -----------------------------------------------------
2240                        cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- ERROR -- event entry #"<<iev<<" does not belong to any run (should not happen)" <<endl;
2241                        return false;
2242                    }
2243                    // -----------------------------------------
2244                    // ...otherwise repeat search from beginning
2245                    // -----------------------------------------
2246                    cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- reached end of run tree. searchin again from beginning " <<endl;
2247                    fromfirst = false;
2248                    irun = 0LL;
2249                    runfirstentry = 0LL;
2250                }
2251                // -------------------------------------------------------------------
2252                // save the index of the first entry of the run, relative to pam_tree,
2253                // and read a new run
2254                // -------------------------------------------------------------------
2255                if(irun>0)runfirstentry += (GetRunInfo()->NEVENTS)-prevshift;
2256                irunentry = 0;
2257                prevshift = 0;          
2258                run_tree->GetEntry(irun);      
2259                if(GetRunInfo()->RUNHEADER_OBT>GetRunInfo()->RUNTRAILER_OBT ){
2260                    cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- irun "<<irun<<"  has RUNHEADER_OBT>=RUNTRAILER_OBT " <<endl;
2261                    cout << "                                                            (NB!! in this case some events are assigned to a wrong run)"<<endl;
2262                }
2263    //          if(hasfrag &&  fragid != GetRunInfo()->ID){
2264    //              cout << "... where is the next fragment ??"<<endl;
2265    //          }
2266            };
2267    
2268    
2269            // --------------------------------------
2270            // if there was no need to update the run
2271            // ---> exit with FALSE
2272            // --------------------------------------
2273            if ( irun == oldrun ) return(false);
2274    
2275            // --------------------------------------
2276            // ... otherwise
2277            // --------------------------------------
2278    
2279    
2280    
2281    //      // -----------------------------------------
2282    //      // store dead and live-time of previous run
2283    //      // -----------------------------------------
2284    //      // --------------------------------------------------------------
2285    //      // if the run is empty, fill the dead-live time branch with zeros
2286    //      // --------------------------------------------------------------
2287    //      /// if some runs have been jumped, fill with zeros
2288    //      if(irun-oldrun>1){
2289    //          ULong64_t  temp[3];
2290    //          temp[0]=totdltime[0];
2291    //          temp[1]=totdltime[1];
2292    //          temp[2]=totdltime[2];
2293    //          for(int i=oldrun+1; i<irun; irun++){
2294    //              totdltime[0]=0;
2295    //              totdltime[1]=0;
2296    //              totdltime[2]=0;
2297    //              cout << " ** JUMPED RUN **"<<endl;
2298    //              if(run_tree_clone)
2299    //                  if(run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())
2300    //                      run_tree_clone->GetBranch("DeadLiveTime")->Fill();
2301    //          }
2302    //          totdltime[0]=temp[0];
2303    //          totdltime[1]=temp[1];
2304    //          totdltime[2]=temp[2];
2305    //      }
2306    //      /// decrement counters
2307    //      if( GetTrigLevel2() ){
2308    //          totdltime[0]-=GetTrigLevel2()->dltime[0];//live-time
2309    //          totdltime[1]-=GetTrigLevel2()->dltime[1];//dead-time
2310    //      }
2311    //      totdltime[2]--;                              //event counter
2312    //      /// add an entry
2313    //      if(irun>0 ){
2314    //          cout << endl;
2315    //          cout << "n.events     : "<<totdltime[2]<<endl;
2316    //          cout << "RUN LIVE-TIME: "<<totdltime[0]*0.16<<" ms"<<endl;
2317    //          cout << "RUN DEAD-TIME: "<<totdltime[1]*0.01<<" ms"<<endl;      
2318    //          if(run_tree_clone)
2319    //              if(run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())
2320    //                  run_tree_clone->GetBranch("DeadLiveTime")->Fill();
2321    //      }
2322    //      /// reset counters
2323    //      if( GetTrigLevel2() ){
2324    //          totdltime[0]=GetTrigLevel2()->dltime[0];//live-time
2325    //          totdltime[1]=0;                         //dead-time
2326    //      }
2327    //      totdltime[2]=1;                             //event counter
2328            
2329    
2330            // --------------------------------------
2331            // ---> exit with TRUE
2332            // --------------------------------------
2333            cout << endl << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2334            // ----------------------------------------------------
2335            // then check if the run has a fragment
2336            // in this case we have to switch to the next fragment
2337            // when the end of the first fragment is reached
2338            // ----------------------------------------------------
2339            if(
2340                GetRunInfo()->ID_RUN_FRAG != 0 &&
2341    //          GetRunInfo()->ID_RUN_FRAG != GetRunInfo()->ID &&
2342                true ){
2343                cout << "* fragment *"<<endl;              
2344            }
2345    
2346            return(true);    
2347        };
2348        // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2349        // if it is a preselected file (there is SelectionList)
2350        // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2351        if(SELLI==1){      
2352            sel_tree->GetEntry(iev);
2353            if(irun != oldrun){
2354                run_tree->GetEntry(irun);
2355                cout << endl << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2356                prevshift = 0;
2357                return true;
2358            }
2359            return false;
2360        }
2361    
2362        return false;
2363        //
2364    };
2365    /**
2366     * Update the runinfo informations (to be used to have Run infos event by event basis)
2367     * @param run Pointer to the chain/tree which contains run infos
2368     * @return true if a new run has been read, false if it is still the same run
2369     */
2370    Bool_t PamLevel2::UpdateRunInfo(TTree *run, Long64_t iev){
2371      return(UpdateRunInfo((TChain*)run,iev));
2372    };
2373    
2374  //--------------------------------------  //--------------------------------------
2375  //  //
2376  //  //
# Line 1422  TTree *PamLevel2::GetRunTree(TFile *f){ Line 2382  TTree *PamLevel2::GetRunTree(TFile *f){
2382  void PamLevel2::SetWhichTrees(TString detlist){  void PamLevel2::SetWhichTrees(TString detlist){
2383                    
2384      if(detlist.IsNull() || detlist.Contains("+ALL", TString::kIgnoreCase)){      if(detlist.IsNull() || detlist.Contains("+ALL", TString::kIgnoreCase)){
2385            CAL0 = false;
2386          CAL1 = true;          CAL1 = true;
2387          CAL2 = true;          CAL2 = true;
2388          TRK2 = true;          TRK2 = true;
2389          TRK1 = false;          TRK1 = false;
2390          TRKh = false;          TRKh = false;
2391            TRK0 = false;
2392          TRG = true;          TRG = true;
2393          TOF = true;          TOF = true;
2394            TOF0 = false;
2395          S4  = true;          S4  = true;
2396          ND  = true;          ND  = true;
2397          AC  = true;          AC  = true;
2398          ORB = true;          ORB = true;
2399      }else if( detlist.Contains("-ALL", TString::kIgnoreCase) ){      }else if( detlist.Contains("-ALL", TString::kIgnoreCase) ){
2400            CAL0 = false;
2401          CAL1 = false;          CAL1 = false;
2402          CAL2 = false;          CAL2 = false;
2403          TRK2 = false;          TRK2 = false;
2404          TRK1 = false;          TRK1 = false;
2405          TRKh = false;          TRKh = false;
2406            TRK0 = false;
2407          TRG = false;          TRG = false;
2408          TOF = false;          TOF = false;
2409            TOF0 = false;
2410          S4  = false;          S4  = false;
2411          ND  = false;          ND  = false;
2412          AC  = false;          AC  = false;
# Line 1452  void PamLevel2::SetWhichTrees(TString de Line 2418  void PamLevel2::SetWhichTrees(TString de
2418          if ( detlist.Contains("-CAL1", TString::kIgnoreCase) )CAL1=false;          if ( detlist.Contains("-CAL1", TString::kIgnoreCase) )CAL1=false;
2419          if ( detlist.Contains("+CAL1", TString::kIgnoreCase) )CAL1=true;          if ( detlist.Contains("+CAL1", TString::kIgnoreCase) )CAL1=true;
2420      };      };
2421    
2422        if( detlist.Contains("CAL0", TString::kIgnoreCase) ){
2423            if ( detlist.Contains("-CAL0", TString::kIgnoreCase) )CAL0=false;
2424            if ( detlist.Contains("+CAL0", TString::kIgnoreCase) )CAL0=true;
2425        };
2426                    
2427      if( detlist.Contains("CAL2", TString::kIgnoreCase)){      if( detlist.Contains("CAL2", TString::kIgnoreCase)){
2428          if ( detlist.Contains("-CAL2", TString::kIgnoreCase) )CAL2=false;          if ( detlist.Contains("-CAL2", TString::kIgnoreCase) )CAL2=false;
# Line 1464  void PamLevel2::SetWhichTrees(TString de Line 2435  void PamLevel2::SetWhichTrees(TString de
2435          CAL1=false;          CAL1=false;
2436      }      }
2437  //  -------------------------------------------------------------------------  //  -------------------------------------------------------------------------
2438        if( detlist.Contains("TRK0", TString::kIgnoreCase) ){
2439            if ( detlist.Contains("-TRK0", TString::kIgnoreCase) )TRK0=false;
2440            if ( detlist.Contains("+TRK0", TString::kIgnoreCase) )TRK0=true;
2441        };
2442    
2443      if( detlist.Contains("TRK1", TString::kIgnoreCase) ){      if( detlist.Contains("TRK1", TString::kIgnoreCase) ){
2444          if ( detlist.Contains("-TRK1", TString::kIgnoreCase) )TRK1=false;          if ( detlist.Contains("-TRK1", TString::kIgnoreCase) )TRK1=false;
2445          if ( detlist.Contains("+TRK1", TString::kIgnoreCase) )TRK1=true;          if ( detlist.Contains("+TRK1", TString::kIgnoreCase) )TRK1=true;
# Line 1492  void PamLevel2::SetWhichTrees(TString de Line 2468  void PamLevel2::SetWhichTrees(TString de
2468            
2469      if( detlist.Contains("-TOF", TString::kIgnoreCase) )TOF = false;      if( detlist.Contains("-TOF", TString::kIgnoreCase) )TOF = false;
2470      else if( detlist.Contains("+TOF", TString::kIgnoreCase) )TOF = true;      else if( detlist.Contains("+TOF", TString::kIgnoreCase) )TOF = true;
2471    
2472        if( detlist.Contains("-TOF0", TString::kIgnoreCase) )TOF0 = false;
2473        else if( detlist.Contains("+TOF0", TString::kIgnoreCase) )TOF0 = true;
2474            
2475      if( detlist.Contains("-S4",  TString::kIgnoreCase) )S4  = false;      if( detlist.Contains("-S4",  TString::kIgnoreCase) )S4  = false;
2476      else if( detlist.Contains("+S4",  TString::kIgnoreCase) )S4  = true;      else if( detlist.Contains("+S4",  TString::kIgnoreCase) )S4  = true;
# Line 1526  void PamLevel2::SetWhichTrees(TString de Line 2505  void PamLevel2::SetWhichTrees(TString de
2505   * Set tree/branch detector flags from the content of a tree   * Set tree/branch detector flags from the content of a tree
2506   */   */
2507  void  PamLevel2::GetWhichTrees(TFile* f){  void  PamLevel2::GetWhichTrees(TFile* f){
2508                
2509    
2510    
2511        cout << "void  PamLevel2::GetWhichTrees(TFile* f) --- WARNING!! --- ...potrebbe non funzionare "<<endl;
2512      // -----------      // -----------
2513      // reset flags      // reset flags
2514      // -----------      // -----------
# Line 1698  Bool_t  PamLevel2::CheckLevel2File(TStri Line 2680  Bool_t  PamLevel2::CheckLevel2File(TStri
2680            
2681      Bool_t RUN__ok    = false;      Bool_t RUN__ok    = false;
2682            
2683            Bool_t SELLI__ok  = false;
2684    
2685      cout << "Checking file: "<<name<<endl;      cout << "Checking file: "<<name<<endl;
2686      TFile *f = new TFile(name.Data());      TFile *f = new TFile(name.Data());
# Line 1715  Bool_t  PamLevel2::CheckLevel2File(TStri Line 2697  Bool_t  PamLevel2::CheckLevel2File(TStri
2697    
2698      while( (key = (TKey*)next()) ){      while( (key = (TKey*)next()) ){
2699                    
2700    //      cout << key->GetName() << endl;
2701  //      cout << key->GetName() << ""<<key->GetClassName()<<endl;  //      cout << key->GetName() << ""<<key->GetClassName()<<endl;
2702  //              cout << " Get tree: " << f->Get(key->GetName())<<endl;  //              cout << " Get tree: " << f->Get(key->GetName())<<endl;
2703  //      nev_previous = nev;  //      nev_previous = nev;
# Line 1725  Bool_t  PamLevel2::CheckLevel2File(TStri Line 2708  Bool_t  PamLevel2::CheckLevel2File(TStri
2708  //          return false;  //          return false;
2709  //      };  //      };
2710    
2711    
2712          if( !strcmp(key->GetName(),"Run"        ) )RUN__ok = true;                if( !strcmp(key->GetName(),"Run"        ) )RUN__ok = true;      
2713    
2714          //=========================================================              //=========================================================    
2715            if( !strcmp(key->GetName(),"SelectionList"    ) ){
2716                SELLI__ok = true;
2717                if(SELLI==1){
2718                    Int_t nevt = ((TTree*)f->Get("SelectionList"))->GetEntries();
2719                    if( nev && nevt!=nev){
2720                        cout << "File: "<< f->GetName() <<" discarded ---- SelectionList tree has "<<nevt<<" events instead of "<<nev<< endl;
2721                        return false;
2722                    }
2723                    nev=nevt;
2724                }
2725            }
2726    
2727            //=========================================================    
2728          if( !strcmp(key->GetName(),"Trigger"    ) ){          if( !strcmp(key->GetName(),"Trigger"    ) ){
2729              TRG__ok = true;              TRG__ok = true;
2730              if(TRG){              if(TRG){
# Line 1839  Bool_t  PamLevel2::CheckLevel2File(TStri Line 2836  Bool_t  PamLevel2::CheckLevel2File(TStri
2836          };                };      
2837    
2838      };      };
2839    
2840        if( SELLI==-1 )SELLI = (Int_t)SELLI__ok;
2841        if( SELLI==0 && SELLI__ok ){
2842            cout << "File: "<< f->GetName() <<" discarded ---- found SelectionList (it is not a full-event file)" << endl;
2843            return false;  
2844        }
2845        if( SELLI==1 && !SELLI__ok ){
2846            cout << "File: "<< f->GetName() <<" discarded ---- SelectionList missing" << endl;
2847            return false;
2848        }
2849            
2850    //    cout << "SELLI "<<SELLI<<endl;
2851    
2852  //     cout<< "CheckLevel2File(TString): detector list --> ";  //     cout<< "CheckLevel2File(TString): detector list --> ";
2853  //     if(TRK1__ok)cout<<"TRK1 ";  //     if(TRK1__ok)cout<<"TRK1 ";
2854  //     if(TRK2__ok)cout<<"TRK2 ";  //     if(TRK2__ok)cout<<"TRK2 ";
# Line 1948  void PamLevel2::CreateCloneTrees0( TChai Line 2957  void PamLevel2::CreateCloneTrees0( TChai
2957      cout << "Create clones of PAMELA trees "<<endl;      cout << "Create clones of PAMELA trees "<<endl;
2958            
2959      Int_t i=0;      Int_t i=0;
2960      tree_clone[i] = fChain->GetTree()->CloneTree(0);      pam_tree_clone[i] = fChain->GetTree()->CloneTree(0);
2961      TString name =  tree_clone[i]->GetName();      TString name =  pam_tree_clone[i]->GetName();
2962      name.Append("_clone");      name.Append("_clone");
2963  //    tree_clone[i]->SetName(name.Data());  //    pam_tree_clone[i]->SetName(name.Data());
2964      cout << tree_clone[i]->GetName() <<endl;      cout << pam_tree_clone[i]->GetName() <<endl;
2965      i++;      i++;
2966    
2967      TList *li = fChain->GetListOfFriends();      TList *li = fChain->GetListOfFriends();
# Line 1962  void PamLevel2::CreateCloneTrees0( TChai Line 2971  void PamLevel2::CreateCloneTrees0( TChai
2971      while( (T_friend = (TFriendElement*)next()) ){      while( (T_friend = (TFriendElement*)next()) ){
2972  //      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;
2973  //      cout<<T_friend->GetTree()->GetName()<< endl;  //      cout<<T_friend->GetTree()->GetName()<< endl;
2974          tree_clone[i] = T_friend->GetTree()->CloneTree(0);          pam_tree_clone[i] = T_friend->GetTree()->CloneTree(0);
2975          tree_clone[i]->SetAutoSave(1000000);          pam_tree_clone[i]->SetAutoSave(1000000);
2976          name =  tree_clone[i]->GetName();          name =  pam_tree_clone[i]->GetName();
2977          name.Append("_clone");          name.Append("_clone");
2978  //      tree_clone[i]->SetName(name.Data());  //      pam_tree_clone[i]->SetName(name.Data());
2979          cout << tree_clone[i]->GetName() << endl;          cout << pam_tree_clone[i]->GetName() << endl;
2980          i++;          i++;
2981      }      }
2982            
# Line 1982  void PamLevel2::CreateCloneTrees0( TChai Line 2991  void PamLevel2::CreateCloneTrees0( TChai
2991   */   */
2992  void PamLevel2::CreateCloneTrees(TFile *ofile){  void PamLevel2::CreateCloneTrees(TFile *ofile){
2993    
2994    
2995    //  if the pointer is null, create a default file
2996    
2997        if(!ofile){
2998            cout << "void PamLevel2::CreateCloneTrees(TFile*) -- WARNING -- Creating file: clone-tree.root "<<endl;
2999            ofile = new TFile("clone-tree.root","recreate");
3000        }
3001    
3002      ofile->cd();      ofile->cd();
3003    
3004      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
3005      cout << "Create new PAMELA trees "<<endl;      cout << "Create new PAMELA trees "<<endl;
3006                    
     Int_t i=0;  
3007    
3008        run_tree_clone = new TTree("Run","PAMELA Level2 data from the GL_RUN table ");
3009        run_tree_clone->Branch("RunInfo","GL_RUN",GetPointerTo("RunInfo"));
3010        cout << "Run          : branch RunInfo"<<endl;
3011        run_tree_clone->Branch("SoftInfo","SoftInfo",GetPointerTo("SoftInfo"));
3012        cout << "Run          : branch SoftInfo"<<endl;
3013        // ------------------
3014        // replicate run tree
3015        // ------------------
3016        cout << "----------------------------------------------------"<<endl;
3017        cout << "irun\t | RUN\t NEVENTS\t absolute time"<<endl;
3018        for (Int_t i=0; i<run_tree->GetEntries(); i++){
3019            run_tree->GetEntry(i);
3020            cout << i<< "\t | "<<GetRunInfo()->ID<<"\t "<<GetRunInfo()->NEVENTS<< "\t "<<GetRunInfo()->RUNHEADER_TIME<<" <---> "<<GetRunInfo()->RUNTRAILER_TIME<<endl;
3021            run_tree_clone->Fill();
3022        }
3023        cout << "----------------------------------------------------"<<endl;
3024    
3025        // ------------------------------------
3026        // add branch with dead and live times
3027        // ------------------------------------
3028        run_tree_clone->Branch("DeadLiveTime",totdltime,"dltime[3]/l");
3029        cout << "Run          : branch DeadLiveTime"<<endl;
3030    
3031    
3032        sel_tree_clone = new TTree("SelectionList","List of selected events ");
3033        sel_tree_clone->Branch("RunEntry",&irun,"runentry/L");
3034        sel_tree_clone->Branch("EventEntry",&irunentry,"eventry/L");
3035        
3036    
3037        Int_t i=0;
3038      if(TRK1||TRK2||TRKh){      if(TRK1||TRK2||TRKh){
3039          tree_clone[i] = new TTree("Tracker","PAMELA tracker level2 data ");              pam_tree_clone[i] = new TTree("Tracker","PAMELA tracker level2 data ");
3040          if(TRK1) {          if(TRK1) {
3041              tree_clone[i]->Branch("TrkLevel1","TrkLevel1", GetPointerTo("TrkLevel1"));              pam_tree_clone[i]->Branch("TrkLevel1","TrkLevel1", GetPointerTo("TrkLevel1"));
3042              tree_clone[i]->BranchRef();              pam_tree_clone[i]->BranchRef();
3043              cout << "Tracker      : branch TrkLevel1"<<endl;              cout << "Tracker      : branch TrkLevel1"<<endl;
3044    //          cout << "CreateCloneTrees " << GetTrkLevel1()<<endl;
3045          };          };
3046          if(TRK2) {          if(TRK2) {
3047              tree_clone[i]->Branch("TrkLevel2", "TrkLevel2",GetPointerTo("TrkLevel2"));              pam_tree_clone[i]->Branch("TrkLevel2", "TrkLevel2",GetPointerTo("TrkLevel2"));
3048              cout << "Tracker      : branch TrkLevel2"<<endl;                      cout << "Tracker      : branch TrkLevel2"<<endl;        
3049          };          };
3050          if(TRKh) {          if(TRKh) {
3051              tree_clone[i]->Branch("TrkHough","TrkHough", GetPointerTo("TrkHough"));              pam_tree_clone[i]->Branch("TrkHough","TrkHough", GetPointerTo("TrkHough"));
3052              cout << "Tracker      : branch TrkHough"<<endl;              cout << "Tracker      : branch TrkHough"<<endl;
3053          };          };
3054          i++;          i++;
# Line 2009  void PamLevel2::CreateCloneTrees(TFile * Line 3056  void PamLevel2::CreateCloneTrees(TFile *
3056    
3057      // Calorimeter      // Calorimeter
3058      if(CAL1||CAL2){      if(CAL1||CAL2){
3059          tree_clone[i] = new TTree("Calorimeter","PAMELA calorimeter level2 data ");              pam_tree_clone[i] = new TTree("Calorimeter","PAMELA calorimeter level2 data ");
3060          if(CAL1) {          if(CAL1) {
3061              tree_clone[i]->Branch("CaloLevel1", "CaloLevel1", GetPointerTo("CaloLevel1"));              pam_tree_clone[i]->Branch("CaloLevel1", "CaloLevel1", GetPointerTo("CaloLevel1"));
3062              cout << "Calorimeter  : branch CaloLevel1"<<endl;              cout << "Calorimeter  : branch CaloLevel1"<<endl;
3063          };          };
3064          if(CAL2) {          if(CAL2) {
3065              tree_clone[i]->Branch("CaloLevel2","CaloLevel2", GetPointerTo("CaloLevel2"));              pam_tree_clone[i]->Branch("CaloLevel2","CaloLevel2", GetPointerTo("CaloLevel2"));
3066              cout << "Calorimeter  : branch CaloLevel2"<<endl;              cout << "Calorimeter  : branch CaloLevel2"<<endl;
3067          };          };
3068          i++;          i++;
# Line 2023  void PamLevel2::CreateCloneTrees(TFile * Line 3070  void PamLevel2::CreateCloneTrees(TFile *
3070    
3071      // ToF          // ToF    
3072      if(TOF) {      if(TOF) {
3073          tree_clone[i] = new TTree("ToF","PAMELA ToF level2 data ");              pam_tree_clone[i] = new TTree("ToF","PAMELA ToF level2 data ");
3074          tree_clone[i]->Branch("ToFLevel2","ToFLevel2", GetPointerTo("ToFLevel2"));          pam_tree_clone[i]->Branch("ToFLevel2","ToFLevel2", GetPointerTo("ToFLevel2"));
3075          cout << "ToF          : branch ToFLevel2"<<endl;          cout << "ToF          : branch ToFLevel2"<<endl;
3076          i++;          i++;
3077      };      };
3078      // Trigger      // Trigger
3079      if(TRG) {      if(TRG) {
3080          tree_clone[i] = new TTree("Trigger","PAMELA trigger level2 data ");              pam_tree_clone[i] = new TTree("Trigger","PAMELA trigger level2 data ");
3081          tree_clone[i]->Branch("TrigLevel2","TrigLevel2", GetPointerTo("TrigLevel2"));          pam_tree_clone[i]->Branch("TrigLevel2","TrigLevel2", GetPointerTo("TrigLevel2"));
3082          cout << "Trigger      : branch TrigLevel2"<<endl;          cout << "Trigger      : branch TrigLevel2"<<endl;
3083          i++;          i++;
3084      };      };
3085      // S4      // S4
3086      if(S4) {      if(S4) {
3087          tree_clone[i] = new TTree("S4","PAMELA S4 level2 data ");                pam_tree_clone[i] = new TTree("S4","PAMELA S4 level2 data ");  
3088          tree_clone[i]->Branch("S4Level2","S4Level2", GetPointerTo("S4Level2"));          pam_tree_clone[i]->Branch("S4Level2","S4Level2", GetPointerTo("S4Level2"));
3089          cout << "S4           : branch S4Level2"<<endl;          cout << "S4           : branch S4Level2"<<endl;
3090          i++;          i++;
3091      };      };
3092      // Neutron Detector      // Neutron Detector
3093      if(ND) {      if(ND) {
3094          tree_clone[i] = new TTree("NeutronD","PAMELA neutron detector level2 data ");            pam_tree_clone[i] = new TTree("NeutronD","PAMELA neutron detector level2 data ");      
3095          tree_clone[i]->Branch("NDLevel2","NDLevel2", GetPointerTo("NDLevel2"));          pam_tree_clone[i]->Branch("NDLevel2","NDLevel2", GetPointerTo("NDLevel2"));
3096          cout << "NeutronD     : branch NDLevel2"<<endl;          cout << "NeutronD     : branch NDLevel2"<<endl;
3097          i++;          i++;
3098      };      };
3099      // Anticounters      // Anticounters
3100      if(AC) {      if(AC) {
3101          tree_clone[i] = new TTree("Anticounter","PAMELA anticounter detector level2 data ");              pam_tree_clone[i] = new TTree("Anticounter","PAMELA anticounter detector level2 data ");        
3102          tree_clone[i]->Branch("AcLevel2","AcLevel2", GetPointerTo("AcLevel2"));          pam_tree_clone[i]->Branch("AcLevel2","AcLevel2", GetPointerTo("AcLevel2"));
3103          cout << "Anticounter  : branch AcLevel2"<<endl;          cout << "Anticounter  : branch AcLevel2"<<endl;
3104          i++;          i++;
3105      };      };
3106      // OrbitalInfo      // OrbitalInfo
3107      if(ORB) {      if(ORB) {
3108          tree_clone[i] = new TTree("OrbitalInfo","PAMELA oribital info  ");                pam_tree_clone[i] = new TTree("OrbitalInfo","PAMELA oribital info  ");  
3109          tree_clone[i]->Branch("OrbitalInfo","OrbitalInfo", GetPointerTo("OrbitalInfo"));          pam_tree_clone[i]->Branch("OrbitalInfo","OrbitalInfo", GetPointerTo("OrbitalInfo"));
3110          cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;          cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;
3111          i++;          i++;
3112      };      };
# Line 2074  void PamLevel2::CreateCloneTrees(TFile * Line 3121  void PamLevel2::CreateCloneTrees(TFile *
3121   */   */
3122  //void PamLevel2::FillNewPamTree(TTree *T){  //void PamLevel2::FillNewPamTree(TTree *T){
3123  void PamLevel2::FillCloneTrees(){  void PamLevel2::FillCloneTrees(){
3124                
3125      for(Int_t i=0; i<8; i++){  //    cout << "PamLevel2::FillCloneTrees()" << irunentry << endl;
3126          if(tree_clone[i])tree_clone[i]->Fill();  
3127        for(Int_t i=0; i<NCLONES; i++){
3128            if(pam_tree_clone[i])pam_tree_clone[i]->Fill();
3129      }      }
3130        if(sel_tree_clone)sel_tree_clone->Fill();    
3131    
3132  }  }
3133    
3134    
3135  TTree* PamLevel2::GetCloneTree(TString name){  TTree* PamLevel2::GetCloneTree(TString name){
3136    
3137      for(Int_t i=0; i<8; i++){        for(Int_t i=0; i<NCLONES; i++){    
3138          if(tree_clone[i]){          if(pam_tree_clone[i]){
3139              TString na = tree_clone[i]->GetName();              TString na = pam_tree_clone[i]->GetName();
3140              if(!name.CompareTo(na))return tree_clone[i];              if(!name.CompareTo(na))return pam_tree_clone[i];
3141          };          };
3142      }      }
3143        if(run_tree_clone){
3144            TString na = run_tree_clone->GetName();
3145            if(!name.CompareTo(na))return run_tree_clone;
3146        }
3147        if(sel_tree_clone){
3148            TString na = sel_tree_clone->GetName();
3149            if(!name.CompareTo(na))return sel_tree_clone;
3150        }
3151      return NULL;      return NULL;
3152    
3153  }  }
3154  void PamLevel2::WriteCloneTrees(){  void PamLevel2::WriteCloneTrees(){
3155      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
3156      cout << "Write clones of PAMELA trees "<<endl;      cout << "Write clones of PAMELA trees "<<endl;
3157      for(Int_t i=0; i<8; i++){        cout << run_tree_clone->GetName()<<endl;  
3158          if(tree_clone[i]){      if(run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())
3159              cout << tree_clone[i]->GetName()<<endl;          run_tree_clone->GetBranch("DeadLiveTime")->Fill();
3160              tree_clone[i]->Write();      run_tree_clone->Write();
3161        cout << sel_tree_clone->GetName()<<endl;    
3162        sel_tree_clone->Write();
3163        for(Int_t i=0; i<NCLONES; i++){    
3164            if(pam_tree_clone[i]){
3165                cout << pam_tree_clone[i]->GetName()<<endl;
3166                pam_tree_clone[i]->Write();
3167          };          };
3168      }      }
3169      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
# Line 2106  void PamLevel2::WriteCloneTrees(){ Line 3171  void PamLevel2::WriteCloneTrees(){
3171  }  }
3172    
3173  /**  /**
3174   * Create a new (empty) Pamela trees   * Method to get level2-trees entry, the corresponding run entry and (if required) the level0 entry.
3175   */   */
3176  // TTree* PamLevel2::GetNewPamTree(){  //Int_t PamLevel2::GetEntry(Int_t iee){
3177    Int_t PamLevel2::GetEntry(Long64_t iee){
3178        
3179    //     cout << "-------------------------------------"<<endl;
3180    //     cout << "Int_t PamLevel2::GetEntry("<<iee<<")"<<endl;
3181    
3182        if(!pam_tree){
3183            cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- level2 trees not loaded"<<endl;
3184            return 0;
3185        }
3186    
 //     if(tree_clone)return tree_clone;  
3187    
3188  //     TTree *Tout = 0;      //
3189        // 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...
3190        //
3191        //    if(!run_tree ){
3192        //  cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- run tree not loeaded"<<endl;
3193        //  return 0;
3194        //    }
3195    
3196        Long64_t ii=0;
3197        //-------------------------------
3198        ii = iee;
3199        if( !pam_tree->GetEntry(ii) ){      
3200            cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- error reading pam tree"<<endl;
3201            return 0;
3202        }
3203        //
3204        // ... 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.
3205        // 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
3206        // a problem if you don't check the return code of getentry.
3207        //
3208        if(!run_tree ){
3209            if ( TRK0 || CAL0 || TOF0 || RUN ) { //forse cosi` va bene per tornare 1?
3210                cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- run tree not loaded"<<endl;
3211                return 0;
3212            }  else {
3213                return 1; //cosi` se non c'e` run esce qua...
3214            }
3215        }
3216    
3217        //-------------------------------
3218        ii = iee;
3219    //    Bool_t UPDATED = UpdateRunInfo(run_tree,ii);
3220    //    Bool_t UPDATED = UpdateRunInfo(ii);
3221        UpdateRunInfo(ii);
3222        if(SELLI==0)irunentry = iee-runfirstentry;
3223    //    if(UPDATED && run_tree_clone)run_tree_clone->Fill();
3224      
3225    //    cout << "PamLevel2::GetEntry("<<iee<<") "<<irun<<" "<<runfirstentry<<" "<<irunentry<<endl;
3226    
3227    //     cout << "irunentry     "<<irunentry << endl;
3228    //     cout << "runfirstentry "<<runfirstentry << endl;
3229    //     cout << "nevents       "<<GetRunInfo()->NEVENTS<< endl;
3230    
3231    //     if( TRK0 || CAL0 || TOF0 ){
3232    //      if( !GetYodaEntry( ) ){
3233    //          cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- error reading level0 tree"<<endl;
3234    //          return 0;
3235    //      }
3236    //     }
3237    
3238    
3239        return 1;
3240    
3241    }
3242    
3243    TrkLevel0    *PamLevel2::GetTrkLevel0(){
3244        if( !TRK0 )return NULL;
3245        if( !GetYodaEntry( ) ){
3246            cout << " Int_t PamLevel2::GetTrkLevel0() -- ERROR -- error reading level0 tree"<<endl;
3247            return 0;
3248        }
3249        return trk0_obj;
3250    };
3251    CaloLevel0    *PamLevel2::GetCaloLevel0(){
3252        if( !CAL0 )return NULL;
3253        if( !GetYodaEntry( ) ){
3254            cout << " Int_t PamLevel2::GetCaloLevel0() -- ERROR -- error reading level0 tree"<<endl;
3255            return 0;
3256        }
3257        return calo0_obj;
3258    };
3259    
3260    
3261    /**
3262     * Method to retrieve the level0 tree (YODA tree) that contains the current event.
3263     * Given the run ID (...), if needed it query the DB and load the proper file.
3264     * @return Pointer to the tree
3265     */
3266    
3267    
3268    TTree* PamLevel2::GetYodaTree( ){
3269        
3270    //    cout << "TTree* PamLevel2::GetYodaTree( )"<<endl;
3271        //===================================
3272        // check if iroot has changed
3273        //===================================
3274        if( irun<0 ){
3275            cout << "PamLevel2::GetYodaTree() -- ERROR -- irun = "<<irun<<endl;
3276    //      cout << "In order to use this method you have to first load the RunInfo tree "<<endl;
3277            return NULL;
3278        }    
3279        Int_t irootnew = run_obj->ID_ROOT_L0;
3280    //      cout << "iroot    "<<iroot<<endl;
3281    //      cout << "irootnew "<<irootnew<<endl;
3282    
3283        //===================================
3284        // load the level0 file
3285        // (if not already loaded)
3286        //===================================
3287        if( iroot != irootnew || !l0_tree){
3288            iroot = irootnew;
3289            //===================================
3290            // open the DB connection
3291            // (if not already opened)
3292            //===================================
3293            if(!dbc || (dbc && !dbc->IsConnected())){
3294                cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
3295                cout<<"Connecting to DB"<<endl;
3296                cout<<"HOST "<<host<<endl;
3297                cout<<"USER "<<user<<endl;
3298                cout<<"PSW  "<<psw<<endl;
3299                dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
3300                if( !dbc )return NULL;
3301                if( !dbc->IsConnected() )return NULL;    
3302    //          cout<<"...done"<<endl;
3303                cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
3304            }else{
3305    //          cout<<"DB already connected"<<endl;
3306            }
3307            GL_ROOT glroot = GL_ROOT();
3308            if( glroot.Query_GL_ROOT(iroot,dbc) ){
3309                cout << "TTree* PamLevel2::GetYodaTree( ) -- ERROR -- level0 file iroot = "<<iroot<< " does not exists"<<endl;
3310                return NULL;
3311            };
3312            TString filename = glroot.PATH + glroot.NAME;
3313            if(l0_file){
3314                l0_file->Close();
3315                l0_file->Delete();
3316            }
3317            cout << "Opening LEVEL0 file: "<< filename << endl;
3318            FileStat_t t;
3319            if( gSystem->GetPathInfo(filename.Data(),t) ){
3320                cout << " PamLevel2::GetYodaTree() -- ERROR opening file "<<endl;
3321                return NULL;
3322            }
3323            l0_file = new TFile(filename);
3324            if( !l0_file )return NULL;
3325            l0_tree = (TTree*)l0_file->Get("Physics");
3326            if(!h0_obj)h0_obj = new EventHeader();
3327            l0_tree->SetBranchAddress("Header" ,&h0_obj);
3328            prevshift = 0;
3329            //---------------------------------------------------
3330            // TRACKER:
3331            if(TRK0){
3332                if(!trk0_obj){
3333                    trk0_obj = new TrkLevel0();
3334                    trk0_obj->Set();
3335                };
3336                l0_tree->SetBranchAddress("Tracker" ,trk0_obj->GetPointerToTrackerEvent());
3337            }
3338            //--------------------------------------------------
3339            // CALORIMETER:
3340            if(CAL0){
3341                if(!calo0_obj){
3342                    calo0_obj = new CaloLevel0();
3343                    calo0_obj->Set();
3344                };
3345                l0_tree->SetBranchAddress("Calorimeter" ,calo0_obj->GetPointerToCalorimeterEvent());
3346                //      cout << "PamLevel2::GetYodaTree() --- level0 calorimeter not implemented "<<endl;
3347            }
3348            //---------------------------------------------------
3349            // TOF:
3350            if(TOF0){
3351                cout << "PamLevel2::GetYodaTree() --- level0 TOF not implemented "<<endl;
3352            }
3353    
3354        };
3355    
3356        if(!dbc || (dbc && !dbc->IsConnected())){
3357            cout << " TTree* PamLevel2::GetYodaTree( ) -- no DB connected... hai fatto qualche cazzata "<<endl;
3358        }
3359    
3360        if ( TRK0 ){
3361            TrkParams::Load(6);
3362            if( !TrkParams::IsLoaded(6) ){
3363                cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- VK-mask not loaded"<<endl;
3364            };
3365            TrkParams::SetCalib(run_obj,dbc);
3366            TrkParams::LoadCalib( );
3367            if( !TrkParams::CalibIsLoaded() ){
3368                cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- Calibration not loaded"<<endl;
3369            };
3370        }
3371    
3372    //    cout << l0_tree << endl;
3373            
3374  //     cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      return l0_tree;
3375  //     cout << "Create new PAMELA trees "<<endl;  
3376    }
3377    
3378    /**
3379     * Method to retrieve the level0 tree (YODA tree) that contains the current event.
3380     */
3381    Int_t PamLevel2::GetYodaEntry(){
3382    
3383    //    cout << "Int_t PamLevel2::GetYodaEntry()"<<endl;
3384        if(!GetYodaTree())return 0;
3385        
3386        // patch
3387        if( irunentry < 0){
3388    //      cout << "Int_t PamLevel2::GetYodaEntry() -- ATTENZIONE -- irunentry negativo?!?! "<<(Int_t)irunentry<<endl;
3389            irunentry=0LL;
3390        }
3391        //  ---------------------------------
3392        //  if file is NOT a preselected file
3393        //  ---------------------------------
3394        Long64_t quellagiusta = irunentry + (Long64_t)(run_obj->EV_FROM);
3395    //     cout << " irunentry "<<irunentry<<endl;
3396    //     cout << " EV_FROM "<<run_obj->EV_FROM<<endl;
3397    //     cout << " quellagiusta = irunentry + EV_FROM "<< quellagiusta << endl;
3398    
3399    //     cout << " irun "<< irun << " irunentry "<< irunentry<<" run_obj->EV_FROM "<<run_obj->EV_FROM <<" quella giusta "<<quellagiusta << endl;
3400    //     cout << " iroot "<<iroot<<" run_obj->ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<endl;
3401    //     cout << " time "<< abstime << endl;
3402    //     cout << " trk_calib_used "<<run_obj->TRK_CALIB_USED<< endl;
3403        
3404        ULong64_t obt     = 0;
3405        ULong64_t pktn    = 0;
3406        if( GetOrbitalInfo() ){
3407            obt     = GetOrbitalInfo()->OBT;
3408            pktn    = GetOrbitalInfo()->pkt_num;
3409        }
3410    
3411        if( !GetOrbitalInfo() && !ISGP){
3412            cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing OrbitalInfo "<<endl;
3413            return 0;
3414        }
3415        if( obt==0 && pktn==0 && !ISGP ){
3416            cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- level2 event corrupted ?? "<<endl;
3417            return 0;
3418        }
3419    
3420        // ---------------------------------------------------------------------
3421        // ATTENTION!!!
3422        // If data are not pre-processed with cleaner, the level0 tree may contain
3423        // spurious nested physics packets.
3424        // The GL_RUN variables EV_FROM, EV_TO and NEVENTS counts also these entries
3425        // while level2 tree DOES NOT!!
3426        // This means that "quellagiusta" in these cases is not correct.
3427        // In order to retrieve the correct level0 event, I implemented a check
3428        // of the OBT and pkt-number. In case of mismatch, the level0 entry number
3429        // is shift forward until when the packets match.
3430        // ---------------------------------------------------------------------
3431        Int_t answer = 0;
3432        Int_t shift =0;
3433        //    printf(" siamo qui %i %i \n",shift,prevshift);
3434        Int_t maxshift = 10;
3435        do{
3436            if(shift>0){    
3437                cout << " PKTNUM  L2 --- "<< pktn << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl;
3438                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;
3439                cout << "         L2 <--> L0 mismatch ( irun "<<irun<<" irunentry "<<irunentry<<" shift "<<shift<<" prevshift "<<prevshift<<" )"<<endl;
3440            }
3441            answer = l0_tree->GetEntry(quellagiusta+(Long64_t)shift+(Long64_t)prevshift);
3442            shift++;
3443            if( !GetEventHeader() ){
3444                cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing EventHeader "<<endl;
3445                return 0;
3446            }
3447    
3448            if(ISGP){
3449                obt = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()); //BARBATRUCCO
3450                pktn = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter()); //BARBATRUCCO
3451            }
3452    
3453    //      cout << "PKTNUM "<<shift<<" ==  L2 --- "<< pktn << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl;
3454    //      cout << " L2 --- "<< obt << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime()<<endl;
3455    //      if( (quellagiusta+shift) == l0_tree->GetEntries()+1 )cout << ">>> end of level0 tree <<<"<<endl;
3456    //      cout << " obt "<< obt << endl;
3457    //      cout << " GetEventHeader()->GetPscuHeader()->GetOrbitalTime() "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime() << endl;
3458    //      cout << " pktn "<< pktn << endl;
3459    //      cout << " GetEventHeader()->GetPscuHeader()->GetCounter() "<< GetEventHeader()->GetPscuHeader()->GetCounter() << endl;
3460    //      printf(" IDRUN %u \n",GetRunInfo()->ID);
3461    //
3462            if ( prevshift != 0 && (quellagiusta+(Long64_t)shift) == GetYodaTree()->GetEntries() ){
3463              prevshift = 0;
3464              shift = -1;
3465            };
3466    
3467        }while( ( obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) ||
3468                  pktn != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter())       )
3469                && (quellagiusta+(Long64_t)shift) < GetYodaTree()->GetEntries() && shift < maxshift);
3470    
3471        if ( (quellagiusta+(Long64_t)shift+(Long64_t)prevshift) > GetYodaTree()->GetEntries() || shift == maxshift ) {
3472            cout << " Big trouble here, no such event in Level0 data! " <<endl;
3473            return 0;
3474        }
3475    //    cout << "LA ENTRY GIUSTA E`: "<<quellagiusta<<" (spero...)"<<endl;
3476    //    return GetYodaTree()->GetEntry(quellagiusta);
3477        if ( shift > 1 ) prevshift += (shift-1);
3478            
3479        return answer;
3480            
3481  //     if(TRK1||TRK2||TRKh){  }
3482  //      TTree *T = new TTree("Tracker_clone","PAMELA tracker level2 data ");      /**
3483  //      if(TRK1) {   * \Brief Set DB connection
3484  //          trk1_clone = new TrkLevel1();   */
3485  //          T->Branch("TrkLevel1","TrkLevel1", &trk1_clone);  Bool_t PamLevel2::SetDBConnection(){
 //          T->BranchRef();  
 //          cout << "Tracker      : branch TrkLevel1"<<endl;  
 //      };  
 //      if(TRK2) {  
 //          trk2_clone = new TrkLevel2();  
 //          T->Branch("TrkLevel2", "TrkLevel2",&trk2_clone);  
 //          cout << "Tracker      : branch TrkLevel2"<<endl;          
 //      };  
 //      if(TRKh) {  
 //          trkh_clone = new TrkHough();  
 //          T->Branch("TrkHough","TrkHough", &trkh_clone);  
 //          cout << "Tracker      : branch TrkHough"<<endl;  
 //      };  
 //      if(!Tout)Tout=T;  
 //      else Tout->AddFriend("Tracker_clone");  
 //     }  
3486    
3487  //     // Calorimeter      cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
3488  //     if(CAL1||CAL2){      cout<<"Connecting to DB"<<endl;
3489  //      TTree *C = new TTree("Calorimeter_clone","PAMELA calorimeter level2 data ");          cout<<"HOST "<<host<<endl;
3490  //      if(CAL1) {      cout<<"USER "<<user<<endl;
3491  //          calo1_clone = new CaloLevel1();      cout<<"PSW  "<<psw<<endl;
3492  //          C->Branch("CaloLevel1", "CaloLevel1", &calo1_clone);      dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
3493  //          cout << "Calorimeter  : branch CaloLevel1"<<endl;      if( !dbc )return false;
3494  //      };      if( !dbc->IsConnected() )return false;    
3495  //      if(CAL2) {      cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
3496  //          calo2_clone = new CaloLevel2();      return true;
 //          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;  
3497    
3498  //     tree_clone = Tout;  }
 //     tree_clone->SetDirectory(0);  
3499    
3500  //     return Tout;  /**
3501  // }   * \Brief Add a friend to the pamela chain.
3502  // /**   * @param cname name of the chain to be added
3503  //  * Fill a tree (created with GetNewPamTree)   */
 //  *  
 //  */  
 // //void PamLevel2::FillNewPamTree(TTree *T){  
 // void PamLevel2::FillNewPamTree(){  
           
3504    
3505  //     if(trk1_clone)  *trk1_clone = *trk1_obj;  TChain* PamLevel2::AddFriend(TString cname){
 //     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  
 //     }  
3506    
3507  // }      if(!GetPamTree()){
3508            cout << " TChain* PamLevel2::AddFriend(TString cname) --- a pamela tree must be created first"<<endl;
3509            return NULL;
3510        }
3511    
3512    
3513        TChain *c = new TChain( cname.Data() );
3514    
3515        TIter next( GetPamTree()->GetListOfFiles() );
3516        Int_t nf = 0;
3517        TChainElement* element = 0;    
3518        while ((element = (TChainElement*) next())) {      
3519            c->Add(element->GetTitle());
3520            nf++;
3521        }
3522    
3523        GetPamTree()->AddFriend(cname.Data());
3524    
3525        cout << "external chain created and added to pamela friends :"<<cname<<endl;
3526        cout << "n.files "<<nf<<endl;
3527        
3528    
3529        return c;    
3530    
3531    }

Legend:
Removed from v.1.16  
changed lines
  Added in v.1.48

  ViewVC Help
Powered by ViewVC 1.1.23