/[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.28 by mocchiut, Sat Mar 17 07:44:24 2007 UTC revision 1.45 by pam-fi, Wed Sep 12 08:14:00 2007 UTC
# Line 85  void PamTrack::Delete(){ Line 85  void PamTrack::Delete(){
85  //  //
86  //--------------------------------------  //--------------------------------------
87  /**  /**
88   * Constructor   * Default Constructor
89   */   */
90  PamLevel2::PamLevel2(){  PamLevel2::PamLevel2(){
91      Initialize();
92    };
93    
94    /**
95     * Constructor with given dir, list and detectors
96     */
97    PamLevel2::PamLevel2(TString ddir,TString list,TString detlist){
98      Initialize();
99      GetPamTree(GetListOfLevel2Files(ddir,list),detlist);
100      GetRunTree(GetListOfLevel2Files(ddir,list));
101    };
102    
103    /**
104     * Constructor with given dir and list
105     */
106    PamLevel2::PamLevel2(TString ddir,TString list){
107      Initialize();
108      GetPamTree(GetListOfLevel2Files(ddir,list),"");
109      GetRunTree(GetListOfLevel2Files(ddir,list));
110    };
111    
112    
113    void PamLevel2::Initialize(){
114                    
 //     trk2_obj  = TrkLevel2::GetTrkLevel2();  
 //     trk1_obj  = TrkLevel1::GetTrkLevel1();  
 //     trkh_obj  = TrkHough::GetTrkHough();  
 //     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();  
       
115      h0_obj    = 0;      h0_obj    = 0;
116      trk0_obj  = 0;      trk0_obj  = 0;
117        calo0_obj  = 0;
118    
119      trk2_obj  = 0;      trk2_obj  = 0;
120      trk1_obj  = 0;      trk1_obj  = 0;
# Line 118  PamLevel2::PamLevel2(){ Line 130  PamLevel2::PamLevel2(){
130    
131      run_obj   = 0;//new GL_RUN();      run_obj   = 0;//new GL_RUN();
132      soft_obj   = 0;// Emiliano      soft_obj   = 0;// Emiliano
133      irun = -1;      irun = -1LL;
134      runfirstentry = 0ULL;      runfirstentry = 0LL;
135      runlastentry = 0ULL;      runlastentry = 0LL;
136    
137      l0_file = NULL;      l0_file = NULL;
138      l0_tree = NULL;      l0_tree = NULL;
139      iroot   = -1;      iroot   = -1;
140      dbc     = 0;      dbc     = 0;
141    
142        prevshift = 0;
143            
     irun = -1;  
144      run_tree = NULL;      run_tree = NULL;
145      run_tree_clone = NULL;      run_tree_clone = NULL;
146      sel_tree = NULL;      sel_tree = NULL;
147      sel_tree_clone = NULL;      sel_tree_clone = NULL;
148            
149      irunentry = -1;      irunentry = -1LL;
150      pam_tree = NULL;      pam_tree = NULL;
151      for(Int_t i=0; i<NCLONES; i++ )pam_tree_clone[i]=NULL;      for(Int_t i=0; i<NCLONES; i++ )pam_tree_clone[i]=NULL;
152    
153        totdltime[0] = 0LL;
154        totdltime[1] = 0LL;
155    
156      host = "mysql://localhost/pamelaprod";      host = "mysql://localhost/pamelaprod";
157      user = "anonymous";      user = "anonymous";
158      psw = "";      psw = "";
# Line 173  PamLevel2::PamLevel2(){ Line 189  PamLevel2::PamLevel2(){
189    
190      SELLI = -1;      SELLI = -1;
191    
192        ISGP = false;
193    
194      tsorted=0;      tsorted=0;
195      timage=0;      timage=0;
196        
197        howtosort = "+CAL+TOF";
198        //howtosort = "+TOF";
199        sortthr = 100.;
200    
201  };  };
202  /**  /**
# Line 188  void PamLevel2::Delete(){ Line 210  void PamLevel2::Delete(){
210  //    cout << "void PamLevel2::Clear()"<<endl;  //    cout << "void PamLevel2::Clear()"<<endl;
211      if(h0_obj)   delete h0_obj;      if(h0_obj)   delete h0_obj;
212      if(trk0_obj) delete trk0_obj;            if(trk0_obj) delete trk0_obj;      
213        if(calo0_obj) delete calo0_obj;    
214      if(trk1_obj) delete trk1_obj;            if(trk1_obj) delete trk1_obj;      
215      if(trk2_obj) delete trk2_obj;      if(trk2_obj) delete trk2_obj;
216      if(trkh_obj) delete trkh_obj;      if(trkh_obj) delete trkh_obj;
# Line 215  void PamLevel2::Delete(){ Line 238  void PamLevel2::Delete(){
238      }      }
239            
240      if(l0_file)l0_file->Close();      if(l0_file)l0_file->Close();
241      if(pam_tree)pam_tree->Delete();;      //    if(pam_tree)pam_tree->Delete();;
242    
243      if ( pam_tree ){
244        //
245        // 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...
246        //
247        TList *temp = pam_tree->GetListOfFriends();
248        TList *contents  = new TList; // create chain friend list
249        contents->SetOwner();
250        TIter next(temp);
251        TChain *questo = 0;
252        while ( (questo = (TChain*) next()) ){
253          TString name =  questo->GetName();
254          contents->Add((TChain*)gROOT->FindObject(name.Data()));// add object to the list
255        };
256        //
257        // deleting the main chain
258        //
259        pam_tree->Delete();
260        //
261        // deleting the friends...
262        //
263        TIter next2(contents);
264        TChain *questa = 0;
265        while ( questa = (TChain*)next2() ){
266          TString name =  questa->GetName();
267          questa->Delete();      
268          questa=NULL;
269        };
270        //
271      };
272      pam_tree = NULL;
273    
274      if(run_tree)run_tree->Delete();;      if(run_tree)run_tree->Delete();;
275      if(sel_tree)sel_tree->Delete();;      if(sel_tree)sel_tree->Delete();;
276      for(Int_t i=0; i<NCLONES; i++ )if(pam_tree_clone[i])pam_tree_clone[i]->Delete();;      for(Int_t i=0; i<NCLONES; i++ )if(pam_tree_clone[i])pam_tree_clone[i]->Delete();;
# Line 241  void PamLevel2::Clear(){ Line 296  void PamLevel2::Clear(){
296  //    if(soft_obj) soft_obj->Clear();  //    if(soft_obj) soft_obj->Clear();
297    
298      if(h0_obj)   h0_obj->Clear();            if(h0_obj)   h0_obj->Clear();      
299      if(trk0_obj) trk0_obj->Clear();      //    if(trk0_obj) trk0_obj->Clear();  
300      if(trk1_obj) trk1_obj->Clear();          if(trk1_obj) trk1_obj->Clear();    
301      if(trk2_obj) trk2_obj->Clear();      if(trk2_obj) trk2_obj->Clear();
302      if(trkh_obj) trkh_obj->Clear();      if(trkh_obj) trkh_obj->Clear();
303        if(calo0_obj) calo0_obj->Clear();  
304      if(calo1_obj)calo1_obj->Clear();      if(calo1_obj)calo1_obj->Clear();
305      if(calo2_obj)calo2_obj->Clear();      if(calo2_obj)calo2_obj->Clear();
306      if(tof_obj)  tof_obj->Clear();      if(tof_obj)  tof_obj->Clear();
# Line 263  void PamLevel2::Clear(){ Line 319  void PamLevel2::Clear(){
319      if(timage){      if(timage){
320          timage->Delete();          timage->Delete();
321      }      }
       
322  };  };
323    
324    void PamLevel2::Reset(){
325      //
326      // First of all clear everything
327      //
328      Clear();
329      //
330      // close and reset chains and pointers
331      //    
332      if ( pam_tree ){
333        //
334        // 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...
335        //
336        TList *temp = pam_tree->GetListOfFriends();
337        TList *contents  = new TList; // create chain friend list
338        contents->SetOwner();
339        TIter next(temp);
340        TChain *questo = 0;
341        while ( (questo = (TChain*) next()) ){
342          TString name =  questo->GetName();
343          contents->Add((TChain*)gROOT->FindObject(name.Data()));// add object to the list
344        };
345        //
346        // deleting the main chain
347        //
348        pam_tree->Delete();
349        //
350        // deleting the friends...
351        //
352        TIter next2(contents);
353        TChain *questa = 0;
354        while ( questa = (TChain*)next2() ){
355          TString name =  questa->GetName();
356          questa->Delete();      
357          questa=NULL;
358        };
359        //
360      };
361      pam_tree = NULL;
362      //
363      if(run_tree)run_tree->Delete();;
364      run_tree = NULL;
365      if(sel_tree)sel_tree->Delete();;
366      sel_tree = NULL;
367      //
368      // Close file
369      //
370      if(l0_file)l0_file->Close("R");
371      l0_file = NULL;
372      //
373      h0_obj    = 0;
374      trk0_obj  = 0;
375      calo0_obj  = 0;
376      //
377      trk2_obj  = 0;
378      trk1_obj  = 0;
379      trkh_obj  = 0;
380      calo1_obj = 0;
381      calo2_obj = 0;
382      tof_obj   = 0;
383      trig_obj  = 0;
384      s4_obj    = 0;
385      nd_obj    = 0;
386      ac_obj    = 0;
387      orb_obj   = 0;
388      //
389      // Reset run pointers
390      //
391      run_obj   = 0;//new GL_RUN();
392      soft_obj   = 0;// Emiliano
393      irun = -1;
394      runfirstentry = 0ULL;
395      runlastentry = 0ULL;    
396      //
397      totdltime[0] = 0LL;
398      totdltime[1] = 0LL;
399      //
400    };
401    
402    Bool_t PamLevel2::IsGood(){
403      Bool_t goodev=true;
404      //  if(trk2_obj && trk2_obj->UnpackError() != 0 ) goodev = false;
405      if(calo2_obj && calo2_obj->good != 1) goodev = false;
406      if(tof_obj && tof_obj->unpackError != 0) goodev = false;  
407      if(trig_obj && trig_obj->unpackError != 0) goodev = false;
408      if(s4_obj && s4_obj->unpackError != 0) goodev = false;  
409      if(nd_obj && nd_obj->unpackError != 0) goodev = false;  
410      if(ac_obj && ac_obj->unpackError != 255) goodev = false;  
411        //  if(orb_obj)  
412      return goodev;
413    };
414    
415  //--------------------------------------  //--------------------------------------
416  //  //
# Line 460  PamTrack* PamLevel2::GetStoredTrack(Int_ Line 605  PamTrack* PamLevel2::GetStoredTrack(Int_
605  }  }
606  //--------------------------------------  //--------------------------------------
607  //  //
608    
609    /**
610     * 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.
611     **/
612    void PamLevel2::SortTracks(TString how){
613      printf(" WARNING! obsolete, use SortTracks() and SetSortingMethod(TString) instead! \n Setting sorting method to %s \n",how.Data());
614      howtosort = how;  
615      SortTracks();
616    };
617    
618  //  //
619  //--------------------------------------  //--------------------------------------
620  /**  /**
# Line 473  PamTrack* PamLevel2::GetStoredTrack(Int_ Line 628  PamTrack* PamLevel2::GetStoredTrack(Int_
628   *   *
629   * 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).
630   */   */
631  void PamLevel2::SortTracks(TString how){  void PamLevel2::SortTracks(){
632      TString how = howtosort;
633    
634  //    cout <<" PamLevel2::SortTracks(TString how) "<<endl;    //    cout <<" PamLevel2::SortTracks(TString how) "<<endl;
635      if( !trk2_obj ){    if( !trk2_obj ){
636          cout << "void PamLevel2::SortTracks(TString how):  TrkLevel2 not loaded !!!";      cout << "void PamLevel2::SortTracks():  TrkLevel2 not loaded !!!";
637          return;      return;
638      };    };
639  //    cout << "call SortTracs() "<<endl;    //    cout << "call SortTracs() "<<endl;
640    //Save current Object count    //Save current Object count
641      Int_t ObjectNumber = TProcessID::GetObjectCount();    Int_t ObjectNumber = TProcessID::GetObjectCount();
642    
643      //    cout << "ObjectNumber  "<<ObjectNumber <<endl;
644    
645  //    cout << "ObjectNumber  "<<ObjectNumber <<endl;    //     if(!sorted_tracks)sorted_tracks = new TRefArray();
646      //     sorted_tracks->Clear();
647      //    sorted_tracks.Clear();
648    
649  //     if(!sorted_tracks)sorted_tracks = new TRefArray();    if(!tsorted)tsorted = new TClonesArray("PamTrack",trk2_obj->GetNTracks());
650  //     sorted_tracks->Clear();    tsorted->Delete();
651  //    sorted_tracks.Clear();    TClonesArray &ttsorted = *tsorted;
652      if(!timage)timage = new TClonesArray("PamTrack",trk2_obj->GetNTracks());
653      timage->Delete();
654      TClonesArray &ttimage = *timage;
655    
     if(!tsorted)tsorted = new TClonesArray("PamTrack",trk2_obj->GetNTracks());  
     tsorted->Delete();  
     TClonesArray &ttsorted = *tsorted;  
     if(!timage)timage = new TClonesArray("PamTrack",trk2_obj->GetNTracks());  
     timage->Delete();  
     TClonesArray &ttimage = *timage;  
656    
657    
658      // loop over the tracks sorted by the tracker    //--------------------------------------------------
659      Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);    // retrieve sorting method
660      Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);    //--------------------------------------------------
661      Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase);    Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);
662      Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);
663      Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase);
664            
665      if( !CAL2 &&  use_CAL) use_CAL = false;    if( !CAL2 &&  use_CAL) use_CAL = false;
666      if( !TOF &&  use_TOF) use_TOF = false;    if( !TOF &&  use_TOF) use_TOF = false;
667            
668      if( !TRK2 ){    if( !TRK2 ){
669  //      cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl;      //  cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl;
670          return;      return;
671      };    };
672    
673      //   cout << "use_CAL "<<use_CAL<<" use_TOF "<<use_TOF<<" use_TRK "<<use_TRK <<endl;    //   cout << "use_CAL "<<use_CAL<<" use_TOF "<<use_TOF<<" use_TRK "<<use_TRK <<endl;
674          
675      for(Int_t i=0; i < trk2_obj->TrkLevel2::GetNTracks(); i++){  
676              //--------------------------------------------------
677          TrkTrack   *ts = 0;    // loop over "physical" tracks sorted by the tracker
678          CaloTrkVar *cs = 0;    //--------------------------------------------------
679          ToFTrkVar  *os = 0;    for(Int_t i=0; i < trk2_obj->TrkLevel2::GetNTracks(); i++){
680                    
681          // get tracker tracks      TrkTrack   *ts = 0;
682          TrkTrack   *tp = trk2_obj->TrkLevel2::GetTrack(i);                    //tracker      CaloTrkVar *cs = 0;
683          CaloTrkVar *cp = GetCaloStoredTrack(tp->GetSeqNo());      ToFTrkVar  *os = 0;
684          ToFTrkVar  *op = GetToFStoredTrack(tp->GetSeqNo());          
685        // get tracker tracks
686          TrkTrack   *ti = 0;              //tracker (image)      TrkTrack   *tp = trk2_obj->TrkLevel2::GetTrack(i); //tracker
687          CaloTrkVar *ci = 0;      CaloTrkVar *cp = GetCaloStoredTrack(tp->GetSeqNo());
688          ToFTrkVar  *oi = 0;      ToFTrkVar  *op = GetToFStoredTrack(tp->GetSeqNo());
689  //      cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;  
690          // if track has an image, check image selection      TrkTrack   *ti = 0; //tracker (image)
691          if(tp->HasImage()){      CaloTrkVar *ci = 0;
692        ToFTrkVar  *oi = 0;
693        //  cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;
694        // if track has an image, check image selection
695        if(tp->HasImage()){
696                            
697              ti = trk2_obj->TrkLevel2::GetTrackImage(i);              //tracker (image)        ti = trk2_obj->TrkLevel2::GetTrackImage(i);              //tracker (image)
698              ci = GetCaloStoredTrack(ti->GetSeqNo());        ci = GetCaloStoredTrack(ti->GetSeqNo());
699              oi = GetToFStoredTrack(ti->GetSeqNo());        oi = GetToFStoredTrack(ti->GetSeqNo());
700                            
701  //          cout << "its image "<<i << " "<<hex<< ti <<dec<< endl;        //            cout << "its image "<<i << " "<<hex<< ti <<dec<< endl;
702    
703              //assign starting scores        //assign starting scores
704              Int_t tp_score = 0;  //main track sorted by the tracker        Int_t tp_score = 0;  //main track sorted by the tracker
705              Int_t ti_score = 0;  //image track        Int_t ti_score = 0;  //image track
706                            
707              // ------------------------        // -----------------------------------------------------------------------------------------
708              // calorimeter check        // calorimeter check
709              // ------------------------        // -----------------------------------------------------------------------------------------
710              // check the Y spatial residual on the first calorimeter plane        // check the Y spatial residual on the first calorimeter plane
711              // (cut on calorimeter variables from Emiliano)        // (cut on calorimeter variables from Emiliano)
712              if( use_CAL && !calo2_obj ){        if( use_CAL && !calo2_obj ){
713                  cout << "void PamLevel2::SortTracks(TString how): how= "<<how<<" but CaloLevel2 not loaded !!!";          cout << "void PamLevel2::SortTracks(): howtosort= "<<how<<" but CaloLevel2 not loaded !!!";
714                  return;          return;
715              };        };
716              if(        if( use_CAL && !cp &&  ci )ti_score++;
717                  use_CAL            &&        if( use_CAL &&  cp && !ci )tp_score++;
718                  calo2_obj->npcfit[1] > 15     &&   //no. of fit planes on Y view        if(
719                  calo2_obj->varcfit[1] < 1000. &&  //fit variance on Y view           use_CAL            &&
720                  cp && ci &&  //       calo2_obj->npcfit[1] > 5     &&   //no. of fit planes on Y view
721                  true){  //       calo2_obj->varcfit[1] < 1000. &&  //fit variance on Y view
722             cp && ci &&
723             true){
724    
725                                    
726                  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;
727                  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;
728                                    
729                  if(resy_p <= resy_i) tp_score++;  //      if(resy_p <= resy_i) tp_score++;
730                  else                 ti_score++;  //      else                 ti_score++;
731            
732    
733  //              cout << "CALO "<<tp_score<<ti_score<<endl;            if( cp->npresh > ci->npresh) tp_score++;
734              if( cp->npresh < ci->npresh) ti_score++;
735              else ;//niente
736    
737            //      cout << "CALO "<<tp_score<<ti_score<<endl;
738    
739          };
740          // -----------------------------------------------------------------------------------------
741          // TOF check
742          // -----------------------------------------------------------------------------------------
743          // check the number of hit pmts along the track
744          // on S12 S21 and S32, where paddles are parallel to Y axis
745          if( use_TOF && !tof_obj ){
746            cout << "void PamLevel2::SortTracks(): howtosort= "<<how<<" but ToFLevel2 not loaded !!!";
747            return;
748          };
749          if( use_TOF && !op &&  oi )ti_score++;
750          if( use_TOF &&  op && !oi )tp_score++;
751          if( use_TOF && op && oi ){
752                    
753            //
754            Float_t sen = 0.;
755            for (Int_t ih=0; ih < op->npmtadc; ih++){
756              Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
757              if ( pl == 2 || pl == 3 || pl == 4 || pl == 5 ) sen += (op->dedx).At(ih);
758            };
759            for (Int_t ih=0; ih < oi->npmtadc; ih++){
760              Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
761              if ( pl == 2 || pl == 3 || pl == 4 || pl == 5 ) sen += (oi->dedx).At(ih);
762            };
763            //
764            if (  sen >= sortthr ){
765              //printf(" IS A NUCLEUS! en = %f \n",sen);
766              //
767              // is a nucleus use a different algorithm
768              //
769              Int_t nz = 6; Float_t zin[6];                                          // << define TOF z-coordinates
770              for(Int_t ip=0; ip<nz; ip++)
771                zin[ip] = tof_obj->ToFLevel2::GetZTOF(tof_obj->ToFLevel2::GetToFPlaneID(ip));     // << read ToF plane z-coordinates
772              Trajectory *tr = new Trajectory(nz,zin);
773              //
774              Int_t nphit_p =0;
775              Int_t nphit_i =0;
776              Float_t enhit_p = 0.;
777              Float_t enhit_i = 0.;
778              //
779              for (Int_t ih=0; ih < op->npmtadc; ih++){
780                Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
781                if(pl == 1 || pl == 2 || pl == 5){
782                  nphit_p++;
783                  enhit_p += (op->dedx).At(ih);
784              };              };
785              // ------------------------            };
786              // TOF check            //
787              // ------------------------                tp->DoTrack2(tr);
788              // check the number of hit pmts along the track            //
789              // on S12 S21 and S32, where paddles are parallel to Y axis            if ( fabs(tr->y[0]-oi->ytofpos[0]) < 2. ){
790              if( use_TOF && !tof_obj ){              for (Int_t ih=0; ih < op->npmtadc; ih++){
791                  cout << "void PamLevel2::SortTracks(TString how): how= "<<how<<" but ToFLevel2 not loaded !!!";                Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
792                  return;                if(pl == 0){
793                    nphit_p++;
794                    enhit_p += (op->dedx).At(ih);
795                  };
796                };
797              };
798              if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){
799                for (Int_t ih=0; ih < op->npmtadc; ih++){
800                  Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
801                  if(pl == 3){
802                    nphit_p++;
803                    enhit_p += (op->dedx).At(ih);
804                  };
805                };
806              };
807              if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){
808                for (Int_t ih=0; ih < op->npmtadc; ih++){
809                  Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
810                  if(pl == 4){
811                    nphit_p++;
812                    enhit_p += (op->dedx).At(ih);
813                  };
814                };
815              };
816    
817              for (Int_t ih=0; ih < oi->npmtadc; ih++){
818                Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
819                if(pl == 1 || pl == 2 || pl == 5){
820                  nphit_i++;        
821                  enhit_i += (op->dedx).At(ih);
822              };              };
823              if( use_TOF && op && oi ){            };
824              //
825              ti->DoTrack2(tr);
826              //
827              if ( fabs(tr->y[0]-oi->ytofpos[0]) < 2. ){
828                for (Int_t ih=0; ih < oi->npmtadc; ih++){
829                  Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
830                  if(pl == 0){
831                    nphit_i++;
832                    enhit_i += (op->dedx).At(ih);
833                  };
834                };
835              };
836              if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){
837                for (Int_t ih=0; ih < oi->npmtadc; ih++){
838                  Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
839                  if(pl == 3){
840                    nphit_i++;
841                    enhit_i += (op->dedx).At(ih);
842                  };
843                };
844              };
845              if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){
846                for (Int_t ih=0; ih < oi->npmtadc; ih++){
847                  Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
848                  if(pl == 4){
849                    nphit_i++;
850                    enhit_i += (op->dedx).At(ih);
851                  };
852                };
853              };            
854    
855                                    
856                  Int_t nphit_p =0;            if(
857                  Int_t nphit_i =0;               use_TOF            &&
858                 (nphit_p+nphit_i) !=0 &&  
859                 true){
860                        
861                //      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);
862                //      printf(" score p %i score i %i \n",tp_score,ti_score);
863                //            if( enhit_p > enhit_i ) tp_score++;
864                //            if( nphit_p >= nphit_i && enhit_p > enhit_i ) tp_score++;
865                if ( nphit_p > nphit_i ) tp_score++;
866                if ( nphit_p < nphit_i ) ti_score++;
867                if ( nphit_p == nphit_i ){
868                  if ( enhit_p > enhit_i ) tp_score++;
869                  else ti_score++;
870                };
871                //      printf(" dopo score p %i score i %i \n",tp_score,ti_score);
872              };
873              delete tr;
874              //
875            } else {
876              //
877              // NOT a NUCLEUS
878              //
879              //printf(" NOT a NUCLEUS! en = %f \n",sen);
880    
881              Int_t nphit_p =0;
882              Int_t nphit_i =0;
883                                    
884                                    
885  /*                              cout << "track: npmtadc "<< op->npmtadc << endl;            /*                            cout << "track: npmtadc "<< op->npmtadc << endl;
886                                  cout << "track: npmttdc "<< op->npmttdc << endl;              cout << "track: npmttdc "<< op->npmttdc << endl;
887                                  cout << "image: npmtadc "<< oi->npmtadc << endl;              cout << "image: npmtadc "<< oi->npmtadc << endl;
888                                  cout << "image: npmttdc "<< oi->npmttdc << endl;*/              cout << "image: npmttdc "<< oi->npmttdc << endl;*/
889                                    
890                  for (Int_t ih=0; ih < op->npmtadc; ih++){  //        for (Int_t ih=0; ih < op->npmtadc; ih++){
891                      Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );  //          Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
892                      if(pl == 1 || pl == 2 || pl == 5)nphit_p++;  //          if(pl == 1 || pl == 2 || pl == 5)nphit_p++;
893                  };  //        };
894                                    
895                  for (Int_t ih=0; ih < oi->npmtadc; ih++){  //        for (Int_t ih=0; ih < oi->npmtadc; ih++){
896                      Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );  //          Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
897                      if(pl == 1 || pl == 2 || pl == 5)nphit_i++;  //          if(pl == 1 || pl == 2 || pl == 5)nphit_i++;
898                  };  //        };
899              // --- modified to count tdc signals (more efficient?)
900              // --- and to implement check on tdcflag
901              for (Int_t ih=0; ih < op->npmttdc; ih++){
902                //      Int_t pl = tof_obj->GetPlaneIndex( (op->pmttdc).At(ih) );
903    //          if( (op->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_p++;
904                if( (op->tdcflag).At(ih)==0 )nphit_p++;
905              };
906                                    
907                  if(            for (Int_t ih=0; ih < oi->npmttdc; ih++){
908                      use_TOF            &&              //      Int_t pl = tof_obj->GetPlaneIndex( (oi->pmttdc).At(ih) );
909                      (nphit_p+nphit_i) !=0 &&      //          if( (oi->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_i++;  
910                      true){              if( (oi->tdcflag).At(ih)==0 )nphit_i++;    
911              };
912                    
913              if(
914                 (nphit_p+nphit_i) !=0 &&  
915                 true){
916                                            
917                      if( nphit_p >= nphit_i) tp_score++;              if     ( nphit_p > nphit_i) tp_score++;
918                      else ti_score++;              else if( nphit_p < nphit_i) ti_score++;
919                  };              else ;//niente
920  //              cout << "TOF "<<tp_score<<ti_score<<endl;            };
921              };          };
922              if(tp_score == ti_score) use_TRK = true;          //      cout << "TOF "<<tp_score<<ti_score<<endl;
923              // ------------------------        };
924              // tracker check  
925              // ------------------------  
926              // chi**2 difference is not always large enough to distinguish among  //      if(tp_score == ti_score) use_TRK = true;
927              // the real track and its image.  
928              // Tracker check will be applied always when calorimeter and tof information is ambiguous.  
929              if(use_TRK){        // -----------------------------------------------------------------------------------------
930                  if(      tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ;        // tracker check
931                  else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ;        // -----------------------------------------------------------------------------------------
932  //              cout << "TRK "<<tp_score<<ti_score<<endl;        // chi**2 difference is not always large enough to distinguish among
933              };        // the real track and its image.
934          // Tracker check will be applied always when calorimeter and tof information is ambiguous.
935          // *** MODIFIED ON AUGUST 2007 ***
936          if(use_TRK){
937    //      if(      tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ;
938    //      else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ;
939    
940              // CHECK 1 : number of points along X  
941              if ( tp->GetNX() >= ti->GetNX() )tp_score++ ;
942              if ( tp->GetNX() <= ti->GetNX() )ti_score++ ;
943              // CHECK 2 : number of points along Y  
944              if ( tp->GetNY() >= ti->GetNY() )tp_score++ ;
945              if ( tp->GetNY() <= ti->GetNY() )ti_score++ ;
946              // CHECK 3 : chi**2 along X  
947    //        if(      tp->GetChi2X() > 0 && (tp->GetChi2X() < ti->GetChi2X() || ti->GetChi2X() <=0) ) tp_score++ ;
948    //        if(      ti->GetChi2X() > 0 && (ti->GetChi2X() < tp->GetChi2X() || tp->GetChi2X() <=0) ) ti_score++ ;
949              // CHECK 4 : chi**2 along Y  
950    //        if(      tp->GetChi2Y() > 0 && (tp->GetChi2Y() < ti->GetChi2Y() || ti->GetChi2Y() <=0) ) tp_score++ ;
951    //        if(      ti->GetChi2Y() > 0 && (ti->GetChi2Y() < tp->GetChi2Y() || tp->GetChi2Y() <=0) ) ti_score++ ;
952              // CHECK 5 : total chi**2  
953    //        if(      tp->chi2 > 0 && (tp->chi2 < ti->chi2 || ti->chi2 <=0) ) tp_score++ ;
954    //        if(      ti->chi2 > 0 && (ti->chi2 < tp->chi2 || tp->chi2 <=0) ) ti_score++ ;
955    
956            //      cout << "TRK "<<tp_score<<ti_score<<endl;
957          };
958                            
959              // ------------------------  
960              // the winner is....  
961              // ------------------------            // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
962              if      (tp_score > ti_score) {        // the winner is....
963  //              ts = tp;//the track sorted by the tracker!!        // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
964  //              cs = cp;        if      (tp_score > ti_score) {
965  //              os = op;          
966              }else if (tp_score < ti_score) {  
967                  ts = ti;//its image!!        }else if (tp_score < ti_score) {
968                  cs = ci;  
969                  os = oi;  
970            ts = ti;//its image!!
971                  ti = tp;//its image!!          cs = ci;
972                  ci = cp;          os = oi;
973                  oi = op;  
974            ti = tp;//its image!!
975                  tp = ts;//its image!!          ci = cp;
976                  cp = cs;          oi = op;
977                  op = os;  
978            tp = ts;//its image!!
979            cp = cs;
980            op = os;
981    
982                                    
983              }else {        }else {
984  //              ts = tp;  
985  //              cs = cp;  //      cout << "Warning - track image ambiguity not solved" << endl;
986  //              os = op;  
987  //                              cout << "Warning - track image ambiguity not solved" << endl;        };
 //                              cout << ts->GetNtot() << " "<< ts->chi2 << " " << npcfit[1] << " "<< nphit_p << endl;  
             };  
988                            
989          }else{      }else{
990  //          ts = tp;        //            ts = tp;
991  //          cs = cp;        //            cs = cp;
992  //          os = op;        //            os = op;
993          };      };
994                    
995  //      cout <<" SortTracks() "<<i<<" -- "<<ts<<endl;      //  cout <<" SortTracks() "<<i<<" -- "<<ts<<endl;
996  //      sorted_tracks->Add(ts);//save the track in the sorted array      //  sorted_tracks->Add(ts);//save the track in the sorted array
997  //      sorted_tracks.Add(ts);//save the track in the sorted array      //  sorted_tracks.Add(ts);//save the track in the sorted array
998  //      sorted_tracks.Add(tp);//save the track in the sorted array      //  sorted_tracks.Add(tp);//save the track in the sorted array
999  //      cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl;      //  cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl;
1000  //      cout<<"o "<<tp<<endl;      //  cout<<"o "<<tp<<endl;
1001  //      cout<<"o "<<cp<<endl;      //  cout<<"o "<<cp<<endl;
1002  //      cout<<"o "<<op<<endl;      //  cout<<"o "<<op<<endl;
1003          new(ttsorted[i]) PamTrack(tp,cp,op);      new(ttsorted[i]) PamTrack(tp,cp,op);
1004          new(ttimage[i])  PamTrack(ti,ci,oi);      new(ttimage[i])  PamTrack(ti,ci,oi);
1005      };    };
1006    
1007      if( tsorted->GetEntries() != trk2_obj->GetNTracks() ){    if( tsorted->GetEntries() != trk2_obj->GetNTracks() ){
1008          cout << "void PamLevel2::SortTracks(TString how): tsorted->GetEntries() "<<tsorted->GetEntries()<<" != trk2_obj->GetNTracks() = "<<trk2_obj->GetNTracks() <<endl;      cout << "void PamLevel2::SortTracks(): tsorted->GetEntries() "<<tsorted->GetEntries()<<" != trk2_obj->GetNTracks() = "<<trk2_obj->GetNTracks() <<endl;
1009          tsorted->Delete(); tsorted=0;      tsorted->Delete(); tsorted=0;
1010          timage->Delete(); timage=0;          timage->Delete(); timage=0;
1011      }    }
1012    
1013      //Restore Object count    //Restore Object count
1014      //To save space in the table keeping track of all referenced objects    //To save space in the table keeping track of all referenced objects
1015      //We reset the object count to what it was at the beginning of the event.    //We reset the object count to what it was at the beginning of the event.
1016      TProcessID::SetObjectCount(ObjectNumber);    TProcessID::SetObjectCount(ObjectNumber);
1017            
1018  };  };
1019  //--------------------------------------  //--------------------------------------
# Line 700  void PamLevel2::SortTracks(TString how){ Line 1037  void PamLevel2::SortTracks(TString how){
1037  TClonesArray *PamLevel2::GetTracks(){  TClonesArray *PamLevel2::GetTracks(){
1038    
1039  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
1040      SortTracks("+CAL+TOF");      SortTracks();
1041  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
1042    
1043      return tsorted;      return tsorted;
# Line 719  PamTrack *PamLevel2::GetTrack(int it){ Line 1056  PamTrack *PamLevel2::GetTrack(int it){
1056    
1057  //    if(!trk2_obj) return 0;  //    if(!trk2_obj) return 0;
1058                    
1059  // //  *-*-*-*-*-*-*-*-*-*-*-*-*  // //  *-*-*-*+-*-*-*-*-*-*-*-*-*
1060  //     SortTracks("+CAL+TOF");  //     SortTracks("+CAL+TOF");
1061  // //  *-*-*-*-*-*-*-*-*-*-*-*-*  // //  *-*-*-*-*-*-*-*-*-*-*-*-*
1062  // //    if(!sorted_tracks)return 0;  // //    if(!sorted_tracks)return 0;
# Line 738  PamTrack *PamLevel2::GetTrack(int it){ Line 1075  PamTrack *PamLevel2::GetTrack(int it){
1075    
1076  //    cout << "PamLevel2::GetTrack(int it) "<<endl;  //    cout << "PamLevel2::GetTrack(int it) "<<endl;
1077  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
1078      SortTracks("+CAL+TOF");      SortTracks();
1079  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
1080      if(!tsorted)return 0;      if(!tsorted)return 0;
1081      if(!tsorted->GetEntries())return 0;      if(!tsorted->GetEntries())return 0;
# Line 795  PamTrack *PamLevel2::GetTrackImage(int i Line 1132  PamTrack *PamLevel2::GetTrackImage(int i
1132    
1133    
1134  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
1135      SortTracks("+CAL+TOF");      SortTracks();
1136  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
1137      if(!timage)return 0;      if(!timage)return 0;
1138      if(!timage->GetEntries())return 0;      if(!timage->GetEntries())return 0;
# Line 832  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1169  TTree *PamLevel2::GetPamTree(TFile *f, T
1169    
1170  //     if( !detlist.IsNull() ) SetWhichTrees(detlist);  //     if( !detlist.IsNull() ) SetWhichTrees(detlist);
1171  //     else                    GetWhichTrees(f);  //     else                    GetWhichTrees(f);
1172          if ( pam_tree ){
1173        printf("WARNING: TTree *PamLevel2::GetPamTree(TFile *fl, TString detlist) -- pam_tree already exists!\n ");
1174        return pam_tree;
1175      };
1176      //
1177    
1178      cout << "TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ) -- obsolte "<<endl;      cout << "TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ) -- obsolte "<<endl;
1179    
1180      SetWhichTrees(detlist);      SetWhichTrees(detlist);
# Line 908  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1250  TTree *PamLevel2::GetPamTree(TFile *f, T
1250      if(R && TRG) {      if(R && TRG) {
1251          R->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));          R->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));
1252          cout << "Trigger      : set branch address TrigLevel2"<<endl;          cout << "Trigger      : set branch address TrigLevel2"<<endl;
1253          if(!Trout)Trout=O;          if(!Trout)Trout=R;
1254          else Trout->AddFriend(R);          else Trout->AddFriend(R);
1255      }else{      }else{
1256          cout << "Trigger      : missing tree"<<endl;          cout << "Trigger      : missing tree"<<endl;
# Line 918  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1260  TTree *PamLevel2::GetPamTree(TFile *f, T
1260      if(S && S4) {      if(S && S4) {
1261          S->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));          S->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));
1262          cout << "S4           : set branch address S4Level2"<<endl;          cout << "S4           : set branch address S4Level2"<<endl;
1263          if(!Trout)Trout=O;          if(!Trout)Trout=S;
1264          else Trout->AddFriend(S);          else Trout->AddFriend(S);
1265      }else{      }else{
1266          cout << "S4           : missing tree"<<endl;          cout << "S4           : missing tree"<<endl;
# Line 928  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1270  TTree *PamLevel2::GetPamTree(TFile *f, T
1270      if(N && ND) {      if(N && ND) {
1271          N->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));          N->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));
1272          cout << "NeutronD     : set branch address NDLevel2"<<endl;          cout << "NeutronD     : set branch address NDLevel2"<<endl;
1273          if(!Trout)Trout=O;          if(!Trout)Trout=N;
1274          else Trout->AddFriend(N);          else Trout->AddFriend(N);
1275      }else{      }else{
1276          cout << "NeutronD     : missing tree"<<endl;          cout << "NeutronD     : missing tree"<<endl;
# Line 938  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1280  TTree *PamLevel2::GetPamTree(TFile *f, T
1280      if(A && AC) {      if(A && AC) {
1281          A->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));          A->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));
1282          cout << "Anticounter  : set branch address AcLevel2"<<endl;          cout << "Anticounter  : set branch address AcLevel2"<<endl;
1283          if(!Trout)Trout=O;          if(!Trout)Trout=A;
1284          else Trout->AddFriend(A);          else Trout->AddFriend(A);
1285      }else{      }else{
1286          cout << "Anticounter  : missing tree"<<endl;          cout << "Anticounter  : missing tree"<<endl;
# Line 948  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1290  TTree *PamLevel2::GetPamTree(TFile *f, T
1290      if(B && ORB) {      if(B && ORB) {
1291          B->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));          B->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
1292          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;
1293          if(!Trout)Trout=O;          if(!Trout)Trout=B;
1294          else Trout->AddFriend(B);          else Trout->AddFriend(B);
1295      }else{      }else{
1296          cout << "OrbitalInfo  : missing tree"<<endl;          cout << "OrbitalInfo  : missing tree"<<endl;
# Line 990  TList*  PamLevel2::GetListOfLevel2Files( Line 1332  TList*  PamLevel2::GetListOfLevel2Files(
1332                    
1333      TString wdir = gSystem->WorkingDirectory();      TString wdir = gSystem->WorkingDirectory();
1334            
1335      if(ddir=="")ddir = wdir;      //    if(ddir=="")ddir = wdir;
1336  //      TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);  //      TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);
1337      cout << "Level2 data directory : "<<  ddir << endl;      if ( ddir != ""){
1338              cout << "Level2 data directory : "<<  ddir << endl;
1339        } else {
1340          cout << "Level2 data directory not given as input: trying to evaluate from list or taking working directory " << endl;
1341        };
1342      TList *contents  = new TList; // create output list      TList *contents  = new TList; // create output list
1343      contents->SetOwner();      contents->SetOwner();
1344            
# Line 1042  TList*  PamLevel2::GetListOfLevel2Files( Line 1387  TList*  PamLevel2::GetListOfLevel2Files(
1387  //          if( gSystem->IsFileInIncludePath(file,&fullpath) ){  //          if( gSystem->IsFileInIncludePath(file,&fullpath) ){
1388  //          if( (fullpath = gSystem->FindFile(ddir,file)) ){  //          if( (fullpath = gSystem->FindFile(ddir,file)) ){
1389              if( file.EndsWith(".root") ){              if( file.EndsWith(".root") ){
1390                  char *fullpath = gSystem->ConcatFileName(gSystem->DirName(ddir),gSystem->BaseName(file));                TString filedir;
1391                  if (ddir != ""){
1392                    filedir = ddir; // take the input dir
1393                  } else {
1394                    gSystem->ChangeDirectory(wdir); // back to the working directory
1395                    filedir = gSystem->DirName(file); // this will take the path if exist in the list otherwise it will return automatically the working dir
1396                  };
1397                    char *fullpath = gSystem->ConcatFileName(gSystem->DirName(filedir),gSystem->BaseName(file));
1398                  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
1399                  delete fullpath;                  delete fullpath;
1400              }              }
# Line 1052  TList*  PamLevel2::GetListOfLevel2Files( Line 1404  TList*  PamLevel2::GetListOfLevel2Files(
1404          };          };
1405          in.close();          in.close();
1406        } else {        } else {
1407              if(flisttxt.Contains("#"))flisttxt = flisttxt(0,flisttxt.First("#"));
1408            char *fullpath = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));            char *fullpath = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
1409            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
1410            delete fullpath;            delete fullpath;
# Line 1061  TList*  PamLevel2::GetListOfLevel2Files( Line 1414  TList*  PamLevel2::GetListOfLevel2Files(
1414          cout << "No input file list given."<<endl;          cout << "No input file list given."<<endl;
1415          cout << "Check for existing root files."<<endl;          cout << "Check for existing root files."<<endl;
1416  //              cout << "Warking directory: "<< gSystem->WorkingDirectory()<< endl;  //              cout << "Warking directory: "<< gSystem->WorkingDirectory()<< endl;
1417                    if ( ddir == "" ){
1418              ddir = wdir;
1419              cout << "Level2 data directory : "<<  ddir << endl;
1420            };
1421    
1422          TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);          TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);
1423          TList *temp = datadir->GetListOfFiles();          TList *temp = datadir->GetListOfFiles();
1424  //              temp->Print();  //              temp->Print();
# Line 1105  TList*  PamLevel2::GetListOfLevel2Files( Line 1462  TList*  PamLevel2::GetListOfLevel2Files(
1462   * @return Pointer to a TChain   * @return Pointer to a TChain
1463   */   */
1464  TChain *PamLevel2::GetPamTree(TList *fl, TString detlist ){  TChain *PamLevel2::GetPamTree(TList *fl, TString detlist ){
1465      //
1466      //
1467      //
1468      if ( pam_tree ){
1469        printf("WARNING: TChain *PamLevel2::GetPamTree(TList *fl, TString detlist) -- pam_tree already exists!\n ");
1470        return pam_tree;
1471      };
1472      //
1473            
1474      TChain *Trout =0;      TChain *Trout =0;
1475    
# Line 1125  TChain *PamLevel2::GetPamTree(TList *fl, Line 1490  TChain *PamLevel2::GetPamTree(TList *fl,
1490      if(ORB)cout<<"ORB ";      if(ORB)cout<<"ORB ";
1491      cout << endl;      cout << endl;
1492    
1493      TChain *T = 0;             TChain *T = 0;    
1494      TChain *C = 0;       TChain *C = 0;
1495      TChain *O = 0;       TChain *O = 0;
1496      TChain *R = 0;       TChain *R = 0;
1497      TChain *S = 0;       TChain *S = 0;
1498      TChain *N = 0;       TChain *N = 0;
1499      TChain *A = 0;       TChain *A = 0;
1500      TChain *B = 0;       TChain *B = 0;
1501    
1502      TChain *L = 0;       TChain *L = 0;
1503            
1504      if(TRK2||TRK1||TRKh) T = new TChain("Tracker");          if(TRK2||TRK1||TRKh) T = new TChain("Tracker");    
1505      if(CAL2||CAL1)       C = new TChain("Calorimeter");      if(CAL2||CAL1)       C = new TChain("Calorimeter");
# Line 1144  TChain *PamLevel2::GetPamTree(TList *fl, Line 1509  TChain *PamLevel2::GetPamTree(TList *fl,
1509      if(ND)               N = new TChain("NeutronD");      if(ND)               N = new TChain("NeutronD");
1510      if(AC)               A = new TChain("Anticounter");      if(AC)               A = new TChain("Anticounter");
1511      if(ORB)              B = new TChain("OrbitalInfo");      if(ORB)              B = new TChain("OrbitalInfo");
   
1512       L = new TChain("SelectionList");       L = new TChain("SelectionList");
1513            
1514      // loop over files and create chains              // loop over files and create chains        
# Line 1164  TChain *PamLevel2::GetPamTree(TList *fl, Line 1528  TChain *PamLevel2::GetPamTree(TList *fl,
1528              if(ORB)              B->Add(name);              if(ORB)              B->Add(name);
1529              if(SELLI==1)         L->Add(name);              if(SELLI==1)         L->Add(name);
1530          };          };
1531      }      };
1532            
1533      cout << "done chain \n";      cout << "done chain \n";
1534        cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
1535    
1536  //    UInt_t *found=0;  //    UInt_t *found=0;
1537  // Tracker  // Tracker
# Line 1181  TChain *PamLevel2::GetPamTree(TList *fl, Line 1546  TChain *PamLevel2::GetPamTree(TList *fl,
1546  //      else    T->SetBranchStatus("TrkHough",0,found);  //      else    T->SetBranchStatus("TrkHough",0,found);
1547          if(TRKh)cout << "Tracker      : set branch address TrkHough"<<endl;          if(TRKh)cout << "Tracker      : set branch address TrkHough"<<endl;
1548          if(!Trout)Trout=T;          if(!Trout)Trout=T;
1549          else Trout->AddFriend("Tracker");          else Trout->AddFriend("Tracker");
1550      }else{      }else{
1551          cout << "Tracker      : missing tree"<<endl;          cout << "Tracker      : missing tree"<<endl;
1552      };      };
# Line 1252  TChain *PamLevel2::GetPamTree(TList *fl, Line 1617  TChain *PamLevel2::GetPamTree(TList *fl,
1617      }else{      }else{
1618          cout << "OrbitalInfo  : missing tree"<<endl;          cout << "OrbitalInfo  : missing tree"<<endl;
1619      };      };
1620        cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
1621    
1622      // Selection List      // Selection List
1623      if(L && SELLI==1) {      if(L && SELLI==1) {
# Line 1263  TChain *PamLevel2::GetPamTree(TList *fl, Line 1629  TChain *PamLevel2::GetPamTree(TList *fl,
1629          sel_tree = L;          sel_tree = L;
1630  //      if(!Trout)Trout=O;  //      if(!Trout)Trout=O;
1631  //      else Trout->AddFriend("SelectionList");  //      else Trout->AddFriend("SelectionList");
1632            cout << "----------------------------------------------------" <<endl;
1633      }else{      }else{
1634  //      cout << "SelectionList  : missing tree"<<endl;  //      cout << "SelectionList  : missing tree"<<endl;
1635          if(L)L->Delete();          if(L)L->Delete();
# Line 1454  void PamLevel2::SetBranchAddress(TChain Line 1821  void PamLevel2::SetBranchAddress(TChain
1821   * @return Pointer to a TChain   * @return Pointer to a TChain
1822   */   */
1823  TChain *PamLevel2::GetRunTree(TList *fl){  TChain *PamLevel2::GetRunTree(TList *fl){
1824              //
1825      TChain *R = new TChain("Run");    //
1826      //
1827      if ( run_tree ){
1828        printf("WARNING: TChain *PamLevel2::GetRunTree(TList *fl) -- run_tree already exists!\n ");
1829        return run_tree;
1830      };    
1831      //
1832      TChain *R = new TChain("Run");
1833            
1834      // loop over files and create chains              // loop over files and create chains        
1835      TIter next(fl);      TIter next(fl);
# Line 1494  TChain *PamLevel2::GetRunTree(TList *fl) Line 1868  TChain *PamLevel2::GetRunTree(TList *fl)
1868   * @return Pointer to a TTree   * @return Pointer to a TTree
1869   */   */
1870  TTree *PamLevel2::GetRunTree(TFile *f){  TTree *PamLevel2::GetRunTree(TFile *f){
1871      if ( run_tree ){
1872        printf("WARNING: TTree *PamLevel2::GetRunTree(TFile *f) -- run_tree already exists!\n ");
1873        return run_tree;
1874      };
1875            
1876    
1877      cout << "TTree *PamLevel2::GetRunTree(TFile *f) -- obsolte "<<endl;      cout << "TTree *PamLevel2::GetRunTree(TFile *f) -- obsolte "<<endl;
1878    
1879      TTree *R = (TTree*)f->Get("Run");      TTree *T = (TTree*)f->Get("Run");
1880            
1881      if(R){      if(T){
1882          R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));          T->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
1883          cout << "Run         : set branch address RunInfo"<<endl;          cout << "Run         : set branch address RunInfo"<<endl;
1884          R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano          T->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
1885          cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano          cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano
1886      }      }
1887    
1888      run_tree = (TChain*)R;      run_tree = (TChain*)T;
1889    
1890      return R;      return T;
1891            
1892  }  }
1893  /**  /**
# Line 1516  TTree *PamLevel2::GetRunTree(TFile *f){ Line 1895  TTree *PamLevel2::GetRunTree(TFile *f){
1895   * @param run Pointer to the chain/tree which contains run infos   * @param run Pointer to the chain/tree which contains run infos
1896   * @return true if a new run has been read, false if it is still the same run   * @return true if a new run has been read, false if it is still the same run
1897   */   */
1898  Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev){  Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev){
1899    //    //
1900    // check if we have already called once GetEntry, if not call it    // check if we have already called once GetEntry, if not call it
1901    //    //
1902    if ( run->GetEntries() <= 0 ) return(false);      cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev) --- NON FUNZIONA BENISSIMO.... "<<endl;
1903        if(!run){
1904              cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing RunInfo tree "<<endl;
1905              return(false);        
1906        }
1907        if ( run->GetEntries() <= 0 ) return(false);
1908    //    //
1909        
1910    Int_t oldrun = irun;    //  Int_t oldrun = irun;
1911      Long64_t oldrun = irun;
1912    
1913    // --------------------------------------    // --------------------------------------
1914    // if it is a full file (not preselected)    // if it is a full file (not preselected)
1915    // --------------------------------------    // --------------------------------------
1916    if(SELLI==0){    if(SELLI==0){
       if ( irun < 0 ){  
           irun = 0;  
           run->GetEntry(irun);  
           runfirstentry = 0ULL;  
           runlastentry += (ULong64_t)(this->GetRunInfo()->NEVENTS) - 1ULL;  
           return(true);  
       };        
1917    
1918        if( !GetOrbitalInfo() ){        //
1919          // the absolute time is necessary to relate the event with the run
1920          //
1921          if( !GetOrbitalInfo() && !ISGP){
1922            cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;            cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;
1923            return(false);            return(false);
1924        }        }
1925    
1926          ULong64_t abstime = 0;
1927          if( GetOrbitalInfo() )abstime=GetOrbitalInfo()->absTime;
1928    
1929    
1930          //
1931          // the first time the routine is called, set run search from the beginning
1932          //
1933          if ( irun < 0LL ){
1934              irun = 0LL;
1935              run->GetEntry(irun);
1936              runfirstentry = 0LL;
1937              runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
1938              if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;
1939              
1940              if( ISGP && run->GetEntries()!=1 ){
1941                  cout << "** WARNING ** simulated files are assumed to have 1 single run, not "<< run->GetEntries() << endl;
1942                  cout << "** WARNING ** run will not be updated"<<endl;
1943              }
1944    
1945          };      
1946          //
1947          if(ISGP)abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO
1948          //
1949          if ( irun == run->GetEntries()-1LL &&
1950               !(abstime >= GetRunInfo()->RUNHEADER_TIME &&
1951                 abstime <= GetRunInfo()->RUNTRAILER_TIME)
1952                ){
1953             irun = -1LL;
1954             runfirstentry = 0LL;
1955             runlastentry = -1LL;
1956           };
1957        // modificato il controllo sull'aggiornamento del run, per evitare problemi        // modificato il controllo sull'aggiornamento del run, per evitare problemi
1958        // dovuti agli eventi annidati (NB! NEVENTS conta anche questi!!)        // dovuti agli eventi annidati (NB! NEVENTS conta anche questi!!)
1959        while ( GetOrbitalInfo()->absTime > GetRunInfo()->RUNTRAILER_TIME && irun < run->GetEntries() ){        //
1960          bool fromfirst = true;
1961          //
1962          while ( !(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME) && irun < run->GetEntries()-1LL ){
1963  //      while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){  //      while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){
           //    printf(" iev %llu %u %llu \n",iev,this->GetRunInfo()->NEVENTS,(ULong64_t)(runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS)));  
1964            irun++;            irun++;
1965            run->GetEntry(irun);            run->GetEntry(irun);
1966            runfirstentry = runlastentry+1ULL;            runfirstentry = runlastentry;
1967            runlastentry += (ULong64_t)(this->GetRunInfo()->NEVENTS);            if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runfirstentry += 1LL;
1968              runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
1969    //        cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
1970    //        cout << "runfirstentry "<<runfirstentry<<endl;
1971              //      printf(" iev %llu %u %llu \n",iev,this->GetRunInfo()->NEVENTS,(ULong64_t)(runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS)));
1972              //      printf(" abstime %u trailertime %u \n",abstime,GetRunInfo()->RUNTRAILER_TIME);
1973              //      printf(" IDRUN %u \n",GetRunInfo()->ID);
1974              //
1975    //        prevshift = 0;
1976              //
1977              if ( irun == (Long64_t)(run->GetEntries()-1LL) && fromfirst && !(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME)){
1978                  printf(" resetting irun  (it should NOT happen!!!)\n");
1979                  fromfirst = false;
1980                  irun = 0;
1981                  run->GetEntry(irun);
1982                  runfirstentry = 0ULL;
1983                  runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
1984                  if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;
1985              };
1986              //
1987        };        };
         
1988        //        //
1989        if        if (
1990   ( irun == oldrun || irun >= run->GetEntries() ) return(false);             !(abstime >= GetRunInfo()->RUNHEADER_TIME &&
1991                 abstime <= GetRunInfo()->RUNTRAILER_TIME)
1992              ) {
1993            printf(" Something very wrong here: cannot find RUN containing absolute time %llu \n",abstime);
1994              return false;
1995          }
1996          //
1997          if ( irun == oldrun || irun >= run->GetEntries() ) return(false);
1998        //        //
1999        //  printf(" iev %llu irun %i nevents %u 1st %llu last %llu \n",iev,irun,this->GetRunInfo()->NEVENTS,(ULong64_t)runfirstentry,(ULong64_t)runlastentry);        //  printf(" iev %llu irun %i nevents %u 1st %llu last %llu \n",iev,irun,this->GetRunInfo()->NEVENTS,(ULong64_t)runfirstentry,(ULong64_t)runlastentry);
2000        //        //
2001          prevshift = 0;
2002          cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2003    //      cout << "runfirstentry "<<runfirstentry<<endl;
2004        return(true);            return(true);    
2005    };    };
2006    // ----------------------------------------------------    // ----------------------------------------------------
# Line 1565  Bool_t PamLevel2::UpdateRunInfo(TChain * Line 2009  Bool_t PamLevel2::UpdateRunInfo(TChain *
2009    // ----------------------------------------------------    // ----------------------------------------------------
2010    if(SELLI==1){          if(SELLI==1){      
2011        sel_tree->GetEntry(iev);        sel_tree->GetEntry(iev);
2012    //      cout << irun << " "<< irunentry << endl;
2013        if(irun != oldrun){        if(irun != oldrun){
2014            run->GetEntry(irun);            run->GetEntry(irun);
2015              cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2016              prevshift = 0;
2017            return true;            return true;
2018        }        }
2019        return false;        return false;
# Line 1575  Bool_t PamLevel2::UpdateRunInfo(TChain * Line 2022  Bool_t PamLevel2::UpdateRunInfo(TChain *
2022    return false;    return false;
2023    //    //
2024  };  };
2025    
2026    Bool_t PamLevel2::UpdateRunInfo(Long64_t iev){
2027    
2028        if(!run_tree){
2029            cout << " Bool_t PamLevel2::UpdateRunInfo(ULong64_t iev) -- ERROR -- run tree not loaded"<<endl;
2030            return false;
2031        }
2032        if ( run_tree->GetEntries() <= 0 ) {
2033            cout << " Bool_t PamLevel2::UpdateRunInfo(ULong64_t iev) -- ERROR -- run tree is empty"<<endl;
2034            return(false);
2035        }
2036      
2037        Int_t oldrun = irun; // store current run index
2038    
2039        // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2040        // if it is a full file (not preselected)
2041        // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2042        if(SELLI==0){
2043    
2044            // ---------------------------------------------------------------
2045            // increment dead and live-time counters
2046            // ---------------------------------------------------------------
2047            if( GetTrigLevel2() ){
2048                totdltime[0]+=GetTrigLevel2()->dltime[0];
2049                totdltime[1]+=GetTrigLevel2()->dltime[1];
2050            }
2051            totdltime[2]++;
2052    
2053    //      cout << setw(10)<<totdltime[0]<<setw(10)<<totdltime[1]<<setw(10)<<totdltime[2]<<endl;
2054    
2055            // ---------------------------------------------------------------
2056            // retrieve OBT and absolute time of the event
2057            // ---------------------------------------------------------------
2058            ULong64_t abstime = 0;
2059            ULong64_t obt     = 0;
2060            if( GetOrbitalInfo() ){
2061                abstime = GetOrbitalInfo()->absTime;
2062                obt     = GetOrbitalInfo()->OBT;
2063            }
2064            // ---------------------------------------------------------------
2065            // the absolute time is necessary to relate the event with the run
2066            // ---------------------------------------------------------------
2067            if( !GetOrbitalInfo() && !ISGP ){
2068                cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;
2069                return(false);
2070            }
2071          
2072            // -----------------------------------------------------------------------
2073            // the first time the routine is called, set run search from the beginning
2074            // -----------------------------------------------------------------------
2075            if ( irun < 0 ){
2076                irun = 0LL;
2077                irunentry = 0;
2078                prevshift = 0;
2079                run_tree->GetEntry(irun);
2080    
2081                if( ISGP && run_tree->GetEntries()!=1 ){
2082                    cout << "** WARNING ** simulated files are assumed to have 1 single run, not "<< run_tree->GetEntries() << endl;
2083                    cout << "** WARNING ** run will not be updated"<<endl;
2084                }
2085            };      
2086    
2087            // -----------------------------------------------------------------------
2088            // if it is simulation, assigh abstime by hand (temporaneo!!!)
2089            // -----------------------------------------------------------------------
2090            if(ISGP){
2091                abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO
2092                obt     = GetRunInfo()->RUNHEADER_OBT; // BARBATRUCCO
2093            }
2094            //
2095            bool fromfirst = true; // first loop over runs
2096    
2097    //      Bool_t hasfrag = false;
2098    //      if( GetRunInfo()->ID_RUN_FRAG!=0 && GetRunInfo()->ID_RUN_FRAG != GetRunInfo()->ID)hasfrag=true;
2099    //      ULong64_t fragid = GetRunInfo()->ID_RUN_FRAG;
2100    
2101            // ------------------------------------------------------
2102            // loop over runs to find the one that contains the event
2103            // ------------------------------------------------------
2104            while (
2105                (
2106                    (
2107                        !(abstime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s)
2108                          abstime <= GetRunInfo()->RUNTRAILER_TIME) &&
2109                        !(obt >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms)
2110                          obt <= GetRunInfo()->RUNTRAILER_OBT)
2111                        )
2112                    || GetRunInfo()->NEVENTS==0
2113                    || !(irunentry < GetRunInfo()->NEVENTS-1-prevshift)
2114                    )
2115                    && irun < run_tree->GetEntries() ){
2116    
2117    
2118    
2119    
2120                // -----------------------------------------
2121                // store dead and live-time of previous run
2122                // -----------------------------------------
2123                if(fromfirst){
2124                    if(oldrun==irun){
2125                        /// decrement counters
2126                        if( GetTrigLevel2()){
2127                            totdltime[0]-=GetTrigLevel2()->dltime[0];//live-time
2128                            totdltime[1]-=GetTrigLevel2()->dltime[1];//dead-time
2129                        }
2130                        totdltime[2]--;                              //event counter
2131                        cout << endl;
2132                        cout << "n.events     : "<<totdltime[2]<<endl;
2133                        cout << "RUN LIVE-TIME: "<<totdltime[0]*0.16<<" ms"<<endl;
2134                        cout << "RUN DEAD-TIME: "<<totdltime[1]*0.01<<" ms"<<endl;      
2135                    }else{
2136                        totdltime[0]=0;//live-time
2137                        totdltime[1]=0;//dead-time
2138                        totdltime[2]=0;                             //event counter
2139                        cout << " *** JUMP RUN *** irun "<<irun<<endl;
2140                    }
2141                    /// add an entry
2142                    if(run_tree_clone)
2143                        if(run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())
2144                            run_tree_clone->GetBranch("DeadLiveTime")->Fill();
2145                    /// reset counters
2146                    if( GetTrigLevel2() ){
2147                        totdltime[0]=GetTrigLevel2()->dltime[0];//live-time
2148                        totdltime[1]=0;                         //dead-time
2149                    }
2150                    totdltime[2]=1;                             //event counter
2151                }
2152    
2153    
2154                irun++;
2155                // ------------------------------------
2156                // if the end of run tree is reached...
2157                // ------------------------------------
2158                if( irun == run_tree->GetEntries() ){
2159                    if(!fromfirst){
2160                        // -----------------------------------------------------
2161                        // if it happened already once and the run was not found
2162                        // ---> exit with error
2163                        // -----------------------------------------------------
2164                        cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- ERROR -- event entry #"<<iev<<" does not belong to any run (should not happen)" <<endl;
2165                        return false;
2166                    }
2167                    // -----------------------------------------
2168                    // ...otherwise repeat search from beginning
2169                    // -----------------------------------------
2170                    cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- reached end of run tree. searchin again from beginning " <<endl;
2171                    fromfirst = false;
2172                    irun = 0LL;
2173                    runfirstentry = 0LL;
2174                }
2175                // -------------------------------------------------------------------
2176                // save the index of the first entry of the run, relative to pam_tree,
2177                // and read a new run
2178                // -------------------------------------------------------------------
2179                if(irun>0)runfirstentry += (GetRunInfo()->NEVENTS)-prevshift;
2180                irunentry = 0;
2181                prevshift = 0;          
2182                run_tree->GetEntry(irun);      
2183                if(GetRunInfo()->RUNHEADER_OBT>GetRunInfo()->RUNTRAILER_OBT ){
2184                    cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- irun "<<irun<<"  has RUNHEADER_OBT>=RUNTRAILER_OBT " <<endl;
2185                    cout << "                                                            (NB!! in this case some events are assigned to a wrong run)"<<endl;
2186                }
2187    //          if(hasfrag &&  fragid != GetRunInfo()->ID){
2188    //              cout << "... where is the next fragment ??"<<endl;
2189    //          }
2190            };
2191    
2192    
2193            // --------------------------------------
2194            // if there was no need to update the run
2195            // ---> exit with FALSE
2196            // --------------------------------------
2197            if ( irun == oldrun ) return(false);
2198    
2199            // --------------------------------------
2200            // ... otherwise
2201            // --------------------------------------
2202    
2203    
2204    
2205    //      // -----------------------------------------
2206    //      // store dead and live-time of previous run
2207    //      // -----------------------------------------
2208    //      // --------------------------------------------------------------
2209    //      // if the run is empty, fill the dead-live time branch with zeros
2210    //      // --------------------------------------------------------------
2211    //      /// if some runs have been jumped, fill with zeros
2212    //      if(irun-oldrun>1){
2213    //          ULong64_t  temp[3];
2214    //          temp[0]=totdltime[0];
2215    //          temp[1]=totdltime[1];
2216    //          temp[2]=totdltime[2];
2217    //          for(int i=oldrun+1; i<irun; irun++){
2218    //              totdltime[0]=0;
2219    //              totdltime[1]=0;
2220    //              totdltime[2]=0;
2221    //              cout << " ** JUMPED RUN **"<<endl;
2222    //              if(run_tree_clone)
2223    //                  if(run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())
2224    //                      run_tree_clone->GetBranch("DeadLiveTime")->Fill();
2225    //          }
2226    //          totdltime[0]=temp[0];
2227    //          totdltime[1]=temp[1];
2228    //          totdltime[2]=temp[2];
2229    //      }
2230    //      /// decrement counters
2231    //      if( GetTrigLevel2() ){
2232    //          totdltime[0]-=GetTrigLevel2()->dltime[0];//live-time
2233    //          totdltime[1]-=GetTrigLevel2()->dltime[1];//dead-time
2234    //      }
2235    //      totdltime[2]--;                              //event counter
2236    //      /// add an entry
2237    //      if(irun>0 ){
2238    //          cout << endl;
2239    //          cout << "n.events     : "<<totdltime[2]<<endl;
2240    //          cout << "RUN LIVE-TIME: "<<totdltime[0]*0.16<<" ms"<<endl;
2241    //          cout << "RUN DEAD-TIME: "<<totdltime[1]*0.01<<" ms"<<endl;      
2242    //          if(run_tree_clone)
2243    //              if(run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())
2244    //                  run_tree_clone->GetBranch("DeadLiveTime")->Fill();
2245    //      }
2246    //      /// reset counters
2247    //      if( GetTrigLevel2() ){
2248    //          totdltime[0]=GetTrigLevel2()->dltime[0];//live-time
2249    //          totdltime[1]=0;                         //dead-time
2250    //      }
2251    //      totdltime[2]=1;                             //event counter
2252            
2253    
2254            // --------------------------------------
2255            // ---> exit with TRUE
2256            // --------------------------------------
2257            cout << endl << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2258            // ----------------------------------------------------
2259            // then check if the run has a fragment
2260            // in this case we have to switch to the next fragment
2261            // when the end of the first fragment is reached
2262            // ----------------------------------------------------
2263            if(
2264                GetRunInfo()->ID_RUN_FRAG != 0 &&
2265    //          GetRunInfo()->ID_RUN_FRAG != GetRunInfo()->ID &&
2266                true ){
2267                cout << "* fragment *"<<endl;              
2268            }
2269    
2270            return(true);    
2271        };
2272        // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2273        // if it is a preselected file (there is SelectionList)
2274        // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2275        if(SELLI==1){      
2276            sel_tree->GetEntry(iev);
2277            if(irun != oldrun){
2278                run_tree->GetEntry(irun);
2279                cout << endl << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2280                prevshift = 0;
2281                return true;
2282            }
2283            return false;
2284        }
2285    
2286        return false;
2287        //
2288    };
2289  /**  /**
2290   * Update the runinfo informations (to be used to have Run infos event by event basis)   * Update the runinfo informations (to be used to have Run infos event by event basis)
2291   * @param run Pointer to the chain/tree which contains run infos   * @param run Pointer to the chain/tree which contains run infos
2292   * @return true if a new run has been read, false if it is still the same run   * @return true if a new run has been read, false if it is still the same run
2293   */   */
2294  Bool_t PamLevel2::UpdateRunInfo(TTree *run, ULong64_t iev){  Bool_t PamLevel2::UpdateRunInfo(TTree *run, Long64_t iev){
2295    return(UpdateRunInfo((TChain*)run,iev));    return(UpdateRunInfo((TChain*)run,iev));
2296  };  };
2297    
# Line 2204  void PamLevel2::CreateCloneTrees0( TChai Line 2915  void PamLevel2::CreateCloneTrees0( TChai
2915   */   */
2916  void PamLevel2::CreateCloneTrees(TFile *ofile){  void PamLevel2::CreateCloneTrees(TFile *ofile){
2917    
2918    
2919    //  if the pointer is null, create a default file
2920    
2921        if(!ofile){
2922            cout << "void PamLevel2::CreateCloneTrees(TFile*) -- WARNING -- Creating file: clone-tree.root "<<endl;
2923            ofile = new TFile("clone-tree.root","recreate");
2924        }
2925    
2926      ofile->cd();      ofile->cd();
2927    
2928      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
# Line 2215  void PamLevel2::CreateCloneTrees(TFile * Line 2934  void PamLevel2::CreateCloneTrees(TFile *
2934      cout << "Run          : branch RunInfo"<<endl;      cout << "Run          : branch RunInfo"<<endl;
2935      run_tree_clone->Branch("SoftInfo","SoftInfo",GetPointerTo("SoftInfo"));      run_tree_clone->Branch("SoftInfo","SoftInfo",GetPointerTo("SoftInfo"));
2936      cout << "Run          : branch SoftInfo"<<endl;      cout << "Run          : branch SoftInfo"<<endl;
2937                    // ------------------
2938        // replicate run tree
2939        // ------------------
2940        cout << "----------------------------------------------------"<<endl;
2941        cout << "irun\t | RUN\t NEVENTS\t absolute time"<<endl;
2942        for (Int_t i=0; i<run_tree->GetEntries(); i++){
2943            run_tree->GetEntry(i);
2944            cout << i<< "\t | "<<GetRunInfo()->ID<<"\t "<<GetRunInfo()->NEVENTS<< "\t "<<GetRunInfo()->RUNHEADER_TIME<<" <---> "<<GetRunInfo()->RUNTRAILER_TIME<<endl;
2945            run_tree_clone->Fill();
2946        }
2947        cout << "----------------------------------------------------"<<endl;
2948    
2949        // ------------------------------------
2950        // add branch with dead and live times
2951        // ------------------------------------
2952        run_tree_clone->Branch("DeadLiveTime",totdltime,"dltime[3]/l");
2953        cout << "Run          : branch DeadLiveTime"<<endl;
2954    
2955    
2956      sel_tree_clone = new TTree("SelectionList","List of selected events ");      sel_tree_clone = new TTree("SelectionList","List of selected events ");
2957      sel_tree_clone->Branch("RunEntry",&irun,"runentry/I");      sel_tree_clone->Branch("RunEntry",&irun,"runentry/L");
2958      sel_tree_clone->Branch("EventEntry",&irunentry,"eventry/I");      sel_tree_clone->Branch("EventEntry",&irunentry,"eventry/L");
2959            
2960    
2961      Int_t i=0;      Int_t i=0;
# Line 2230  void PamLevel2::CreateCloneTrees(TFile * Line 2965  void PamLevel2::CreateCloneTrees(TFile *
2965              pam_tree_clone[i]->Branch("TrkLevel1","TrkLevel1", GetPointerTo("TrkLevel1"));              pam_tree_clone[i]->Branch("TrkLevel1","TrkLevel1", GetPointerTo("TrkLevel1"));
2966              pam_tree_clone[i]->BranchRef();              pam_tree_clone[i]->BranchRef();
2967              cout << "Tracker      : branch TrkLevel1"<<endl;              cout << "Tracker      : branch TrkLevel1"<<endl;
2968              cout << "CreateCloneTrees " << GetTrkLevel1()<<endl;  //          cout << "CreateCloneTrees " << GetTrkLevel1()<<endl;
2969          };          };
2970          if(TRK2) {          if(TRK2) {
2971              pam_tree_clone[i]->Branch("TrkLevel2", "TrkLevel2",GetPointerTo("TrkLevel2"));              pam_tree_clone[i]->Branch("TrkLevel2", "TrkLevel2",GetPointerTo("TrkLevel2"));
# Line 2343  TTree* PamLevel2::GetCloneTree(TString n Line 3078  TTree* PamLevel2::GetCloneTree(TString n
3078  void PamLevel2::WriteCloneTrees(){  void PamLevel2::WriteCloneTrees(){
3079      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
3080      cout << "Write clones of PAMELA trees "<<endl;      cout << "Write clones of PAMELA trees "<<endl;
3081      cout << run_tree_clone->GetName()<<endl;          cout << run_tree_clone->GetName()<<endl;  
3082        if(run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())
3083            run_tree_clone->GetBranch("DeadLiveTime")->Fill();
3084      run_tree_clone->Write();      run_tree_clone->Write();
3085      cout << sel_tree_clone->GetName()<<endl;          cout << sel_tree_clone->GetName()<<endl;    
3086      sel_tree_clone->Write();      sel_tree_clone->Write();
# Line 2360  void PamLevel2::WriteCloneTrees(){ Line 3097  void PamLevel2::WriteCloneTrees(){
3097  /**  /**
3098   * Method to get level2-trees entry, the corresponding run entry and (if required) the level0 entry.   * Method to get level2-trees entry, the corresponding run entry and (if required) the level0 entry.
3099   */   */
3100  Int_t PamLevel2::GetEntry(Int_t iee){  //Int_t PamLevel2::GetEntry(Int_t iee){
3101    Int_t PamLevel2::GetEntry(Long64_t iee){
3102            
3103    //     cout << "-------------------------------------"<<endl;
3104    //     cout << "Int_t PamLevel2::GetEntry("<<iee<<")"<<endl;
3105    
3106      if(!pam_tree){      if(!pam_tree){
3107          cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- level2 trees not loaded"<<endl;          cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- level2 trees not loaded"<<endl;
3108          return 0;          return 0;
# Line 2376  Int_t PamLevel2::GetEntry(Int_t iee){ Line 3117  Int_t PamLevel2::GetEntry(Int_t iee){
3117      //  return 0;      //  return 0;
3118      //    }      //    }
3119    
3120      Int_t ii=0;      Long64_t ii=0;
3121      //-------------------------------      //-------------------------------
3122      ii = iee;      ii = iee;
3123      if( !pam_tree->GetEntry(ii) ) return 0;      if( !pam_tree->GetEntry(ii) ){      
3124            cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- error reading pam tree"<<endl;
3125            return 0;
3126        }
3127      //      //
3128      // ... 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.      // ... 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.
3129      // 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      // 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
3130      // a problem if you don't check the return code of getentry.      // a problem if you don't check the return code of getentry.
3131      //      //
3132      if(!run_tree ){      if(!run_tree ){
3133          cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- run tree not loaded"<<endl;          if ( TRK0 || CAL0 || TOF0 || RUN ) { //forse cosi` va bene per tornare 1?
3134          return 0;              cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- run tree not loaded"<<endl;
3135                return 0;
3136            }  else {
3137                return 1; //cosi` se non c'e` run esce qua...
3138            }
3139      }      }
3140    
3141      //-------------------------------      //-------------------------------
3142      ii = iee;      ii = iee;
3143      Bool_t UPDATED = UpdateRunInfo(run_tree,ii);  //    Bool_t UPDATED = UpdateRunInfo(run_tree,ii);
3144    //    Bool_t UPDATED = UpdateRunInfo(ii);
3145        UpdateRunInfo(ii);
3146      if(SELLI==0)irunentry = iee-runfirstentry;      if(SELLI==0)irunentry = iee-runfirstentry;
3147      if(UPDATED && run_tree_clone)run_tree_clone->Fill();  //    if(UPDATED && run_tree_clone)run_tree_clone->Fill();
3148      
3149  //    cout << "PamLevel2::GetEntry("<<iee<<") "<<irun<<" "<<runfirstentry<<" "<<irunentry<<endl;  //    cout << "PamLevel2::GetEntry("<<iee<<") "<<irun<<" "<<runfirstentry<<" "<<irunentry<<endl;
3150    
3151      if( TRK0 || CAL0 || TOF0 )GetYodaEntry( );  //     cout << "irunentry     "<<irunentry << endl;
3152    //     cout << "runfirstentry "<<runfirstentry << endl;
3153    //     cout << "nevents       "<<GetRunInfo()->NEVENTS<< endl;
3154    
3155    //     if( TRK0 || CAL0 || TOF0 ){
3156    //      if( !GetYodaEntry( ) ){
3157    //          cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- error reading level0 tree"<<endl;
3158    //          return 0;
3159    //      }
3160    //     }
3161    
3162    
3163      return 1;      return 1;
3164    
3165  }  }
3166    
3167    TrkLevel0    *PamLevel2::GetTrkLevel0(){
3168        if( !TRK0 )return NULL;
3169        if( !GetYodaEntry( ) ){
3170            cout << " Int_t PamLevel2::GetTrkLevel0() -- ERROR -- error reading level0 tree"<<endl;
3171            return 0;
3172        }
3173        return trk0_obj;
3174    };
3175    CaloLevel0    *PamLevel2::GetCaloLevel0(){
3176        if( !CAL0 )return NULL;
3177        if( !GetYodaEntry( ) ){
3178            cout << " Int_t PamLevel2::GetCaloLevel0() -- ERROR -- error reading level0 tree"<<endl;
3179            return 0;
3180        }
3181        return calo0_obj;
3182    };
3183    
3184    
3185  /**  /**
3186   * Method to retrieve the level0 tree (YODA tree) that contains the current event.   * Method to retrieve the level0 tree (YODA tree) that contains the current event.
3187   * Given the run ID (...), if needed it query the DB and load the proper file.   * Given the run ID (...), if needed it query the DB and load the proper file.
# Line 2419  TTree* PamLevel2::GetYodaTree( ){ Line 3196  TTree* PamLevel2::GetYodaTree( ){
3196      // check if iroot has changed      // check if iroot has changed
3197      //===================================      //===================================
3198      if( irun<0 ){      if( irun<0 ){
3199          cout << "PamLevel2::GetYodaTree() -- ERROR "<<endl;          cout << "PamLevel2::GetYodaTree() -- ERROR -- irun = "<<irun<<endl;
3200          cout << "In order to use this method you have to load the RunInfo tree "<<endl;  //      cout << "In order to use this method you have to first load the RunInfo tree "<<endl;
         cout << "with the method TChain* PamLevel2::GetRunTree(TString, TString)"<<endl;  
 //      cout << " - read the event with PamLevel2::GetEntry(Int_t)"<<endl;  
3201          return NULL;          return NULL;
3202      }          }    
3203      Int_t irootnew = run_obj->ID_ROOT_L0;      Int_t irootnew = run_obj->ID_ROOT_L0;
3204  //     cout << "iroot    "<<iroot<<endl;  //      cout << "iroot    "<<iroot<<endl;
3205  //     cout << "irootnew "<<irootnew<<endl;  //      cout << "irootnew "<<irootnew<<endl;
3206    
3207      //===================================      //===================================
3208      // load the level0 file      // load the level0 file
# Line 2474  TTree* PamLevel2::GetYodaTree( ){ Line 3249  TTree* PamLevel2::GetYodaTree( ){
3249          l0_tree = (TTree*)l0_file->Get("Physics");          l0_tree = (TTree*)l0_file->Get("Physics");
3250          if(!h0_obj)h0_obj = new EventHeader();          if(!h0_obj)h0_obj = new EventHeader();
3251          l0_tree->SetBranchAddress("Header" ,&h0_obj);          l0_tree->SetBranchAddress("Header" ,&h0_obj);
3252            prevshift = 0;
3253          //---------------------------------------------------          //---------------------------------------------------
3254          // TRACKER:          // TRACKER:
3255          if(TRK0){          if(TRK0){
# Line 2483  TTree* PamLevel2::GetYodaTree( ){ Line 3259  TTree* PamLevel2::GetYodaTree( ){
3259              };              };
3260              l0_tree->SetBranchAddress("Tracker" ,trk0_obj->GetPointerToTrackerEvent());              l0_tree->SetBranchAddress("Tracker" ,trk0_obj->GetPointerToTrackerEvent());
3261          }          }
3262          //---------------------------------------------------          //--------------------------------------------------
3263          // CALORIMETER:          // CALORIMETER:
3264          if(CAL0){          if(CAL0){
3265              cout << "PamLevel2::GetYodaTree() --- level0 calorimeter not implemented "<<endl;              if(!calo0_obj){
3266                    calo0_obj = new CaloLevel0();
3267                    calo0_obj->Set();
3268                };
3269                l0_tree->SetBranchAddress("Calorimeter" ,calo0_obj->GetPointerToCalorimeterEvent());
3270                //      cout << "PamLevel2::GetYodaTree() --- level0 calorimeter not implemented "<<endl;
3271          }          }
3272          //---------------------------------------------------          //---------------------------------------------------
3273          // TOF:          // TOF:
# Line 2500  TTree* PamLevel2::GetYodaTree( ){ Line 3281  TTree* PamLevel2::GetYodaTree( ){
3281          cout << " TTree* PamLevel2::GetYodaTree( ) -- no DB connected... hai fatto qualche cazzata "<<endl;          cout << " TTree* PamLevel2::GetYodaTree( ) -- no DB connected... hai fatto qualche cazzata "<<endl;
3282      }      }
3283    
3284      TrkParams::SetCalib(run_obj,dbc);      if ( TRK0 ){
3285            TrkParams::Load(6);
3286            if( !TrkParams::IsLoaded(6) ){
3287                cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- VK-mask not loaded"<<endl;
3288            };
3289            TrkParams::SetCalib(run_obj,dbc);
3290            TrkParams::LoadCalib( );
3291            if( !TrkParams::CalibIsLoaded() ){
3292                cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- Calibration not loaded"<<endl;
3293            };
3294        }
3295    
3296  //    cout << l0_tree << endl;  //    cout << l0_tree << endl;
3297            
# Line 2518  Int_t PamLevel2::GetYodaEntry(){ Line 3308  Int_t PamLevel2::GetYodaEntry(){
3308      if(!GetYodaTree())return 0;      if(!GetYodaTree())return 0;
3309            
3310      // patch      // patch
3311      if( (Int_t)irunentry < 0){      if( irunentry < 0){
3312          cout << "Int_t PamLevel2::GetYodaEntry() -- ATTENZIONE -- irunentry negativo?!?! "<<(Int_t)irunentry<<endl;  //      cout << "Int_t PamLevel2::GetYodaEntry() -- ATTENZIONE -- irunentry negativo?!?! "<<(Int_t)irunentry<<endl;
3313          irunentry=0;          irunentry=0LL;
3314      }      }
3315      //  ---------------------------------      //  ---------------------------------
3316      //  if file is NOT a preselected file      //  if file is NOT a preselected file
3317      //  ---------------------------------      //  ---------------------------------
3318      UInt_t quellagiusta = irunentry + run_obj->EV_FROM;      Long64_t quellagiusta = irunentry + (Long64_t)(run_obj->EV_FROM);
3319        //     cout << " irunentry "<<irunentry<<endl;
3320    //     cout << " EV_FROM "<<run_obj->EV_FROM<<endl;
3321    //     cout << " quellagiusta = irunentry + EV_FROM "<< quellagiusta << endl;
3322    
3323  //     cout << " irun "<< irun << " irunentry "<< irunentry<<" run_obj->EV_FROM "<<run_obj->EV_FROM <<" quella giusta "<<quellagiusta << endl;  //     cout << " irun "<< irun << " irunentry "<< irunentry<<" run_obj->EV_FROM "<<run_obj->EV_FROM <<" quella giusta "<<quellagiusta << endl;
3324  //     cout << " iroot "<<iroot<<" run_obj->ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<endl;  //     cout << " iroot "<<iroot<<" run_obj->ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<endl;
3325  //     cout << " time "<< GetOrbitalInfo()->absTime << endl;  //     cout << " time "<< abstime << endl;
3326  //     cout << " trk_calib_used "<<run_obj->TRK_CALIB_USED<< endl;  //     cout << " trk_calib_used "<<run_obj->TRK_CALIB_USED<< endl;
3327            
3328      if( !GetOrbitalInfo() ){      ULong64_t obt     = 0;
3329        ULong64_t pktn    = 0;
3330        if( GetOrbitalInfo() ){
3331            obt     = GetOrbitalInfo()->OBT;
3332            pktn    = GetOrbitalInfo()->pkt_num;
3333        }
3334    
3335        if( !GetOrbitalInfo() && !ISGP){
3336          cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing OrbitalInfo "<<endl;          cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing OrbitalInfo "<<endl;
3337          return 0;          return 0;
3338      }      }
3339        if( obt==0 && pktn==0 && !ISGP ){
3340            cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- level2 event corrupted ?? "<<endl;
3341            return 0;
3342        }
3343    
3344      // ---------------------------------------------------------------------      // ---------------------------------------------------------------------
3345      // ATTENTION!!!      // ATTENTION!!!
# Line 2551  Int_t PamLevel2::GetYodaEntry(){ Line 3354  Int_t PamLevel2::GetYodaEntry(){
3354      // ---------------------------------------------------------------------      // ---------------------------------------------------------------------
3355      Int_t answer = 0;      Int_t answer = 0;
3356      Int_t shift =0;      Int_t shift =0;
3357        //    printf(" siamo qui %i %i \n",shift,prevshift);
3358        Int_t maxshift = 10;
3359      do{      do{
3360          if(shift>0){          if(shift>0){    
3361              cout << " level0 <--> level2 mismatch ( irun "<<irun<<" irunentry "<<irunentry<<" shift "<<shift<<" )"<<endl;              cout << " PKTNUM  L2 --- "<< pktn << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl;
3362                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;
3363                cout << "         L2 <--> L0 mismatch ( irun "<<irun<<" irunentry "<<irunentry<<" shift "<<shift<<" prevshift "<<prevshift<<" )"<<endl;
3364          }          }
3365          answer = l0_tree->GetEntry(quellagiusta+shift);          answer = l0_tree->GetEntry(quellagiusta+(Long64_t)shift+(Long64_t)prevshift);
3366          shift++;          shift++;
3367          if( !GetEventHeader() ){          if( !GetEventHeader() ){
3368              cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing EventHeader "<<endl;              cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing EventHeader "<<endl;
3369              return 0;              return 0;
3370          }          }
3371    
3372            if(ISGP){
3373                obt = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()); //BARBATRUCCO
3374                pktn = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter()); //BARBATRUCCO
3375            }
3376    
3377    //      cout << "PKTNUM "<<shift<<" ==  L2 --- "<< pktn << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl;
3378    //      cout << " L2 --- "<< obt << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime()<<endl;
3379  //      if( (quellagiusta+shift) == l0_tree->GetEntries()+1 )cout << ">>> end of level0 tree <<<"<<endl;  //      if( (quellagiusta+shift) == l0_tree->GetEntries()+1 )cout << ">>> end of level0 tree <<<"<<endl;
3380  //      cout << " GetOrbitalInfo()->OBT "<< GetOrbitalInfo()->OBT << endl;  //      cout << " obt "<< obt << endl;
3381  //      cout << " GetEventHeader()->GetPscuHeader()->GetOrbitalTime() "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime() << endl;  //      cout << " GetEventHeader()->GetPscuHeader()->GetOrbitalTime() "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime() << endl;
3382  //      cout << " GetOrbitalInfo()->pkt_num "<< GetOrbitalInfo()->pkt_num << endl;  //      cout << " pktn "<< pktn << endl;
3383  //      cout << " GetEventHeader()->GetPscuHeader()->GetCounter() "<< GetEventHeader()->GetPscuHeader()->GetCounter() << endl;  //      cout << " GetEventHeader()->GetPscuHeader()->GetCounter() "<< GetEventHeader()->GetPscuHeader()->GetCounter() << endl;
3384    //      printf(" IDRUN %u \n",GetRunInfo()->ID);
3385    //
3386            if ( prevshift != 0 && (quellagiusta+(Long64_t)shift) == GetYodaTree()->GetEntries() ){
3387              prevshift = 0;
3388              shift = -1;
3389            };
3390    
3391      }while( ( GetOrbitalInfo()->OBT != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) || GetOrbitalInfo()->pkt_num != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter())) && (quellagiusta+shift) < GetYodaTree()->GetEntries() );      }while( ( obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) ||
3392                  pktn != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter())       )
3393                && (quellagiusta+(Long64_t)shift) < GetYodaTree()->GetEntries() && shift < maxshift);
3394    
3395        if ( (quellagiusta+(Long64_t)shift+(Long64_t)prevshift) > GetYodaTree()->GetEntries() || shift == maxshift ) {
3396            cout << " Big trouble here, no such event in Level0 data! " <<endl;
3397            return 0;
3398        }
3399  //    cout << "LA ENTRY GIUSTA E`: "<<quellagiusta<<" (spero...)"<<endl;  //    cout << "LA ENTRY GIUSTA E`: "<<quellagiusta<<" (spero...)"<<endl;
3400  //    return GetYodaTree()->GetEntry(quellagiusta);  //    return GetYodaTree()->GetEntry(quellagiusta);
3401        if ( shift > 1 ) prevshift += (shift-1);
3402            
3403      return answer;      return answer;
3404            
3405  }  }
3406    /**
3407     * \Brief Set DB connection
3408     */
3409    Bool_t PamLevel2::SetDBConnection(){
3410    
3411        cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
3412        cout<<"Connecting to DB"<<endl;
3413        cout<<"HOST "<<host<<endl;
3414        cout<<"USER "<<user<<endl;
3415        cout<<"PSW  "<<psw<<endl;
3416        dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
3417        if( !dbc )return false;
3418        if( !dbc->IsConnected() )return false;    
3419        cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
3420        return true;
3421    
3422    }
3423    
3424    /**
3425     * \Brief Add a friend to the pamela chain.
3426     * @param cname name of the chain to be added
3427     */
3428    
3429    TChain* PamLevel2::AddFriend(TString cname){
3430    
3431        if(!GetPamTree()){
3432            cout << " TChain* PamLevel2::AddFriend(TString cname) --- a pamela tree must be created first"<<endl;
3433            return NULL;
3434        }
3435    
3436    
3437        TChain *c = new TChain( cname.Data() );
3438    
3439        TIter next( GetPamTree()->GetListOfFiles() );
3440        Int_t nf = 0;
3441        TChainElement* element = 0;    
3442        while ((element = (TChainElement*) next())) {      
3443            c->Add(element->GetTitle());
3444            nf++;
3445        }
3446    
3447        GetPamTree()->AddFriend(cname.Data());
3448    
3449        cout << "external chain created and added to pamela friends :"<<cname<<endl;
3450        cout << "n.files "<<nf<<endl;
3451        
3452    
3453        return c;    
3454    
3455    }

Legend:
Removed from v.1.28  
changed lines
  Added in v.1.45

  ViewVC Help
Powered by ViewVC 1.1.23