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

Diff of /PamelaLevel2/src/PamLevel2.cpp

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

revision 1.16 by pam-fi, Tue Jan 16 13:19:58 2007 UTC revision 1.43 by pam-fi, Fri Aug 17 16:57:12 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                    
115  //     trk2_obj  = TrkLevel2::GetTrkLevel2();      h0_obj    = 0;
116  //     trk1_obj  = TrkLevel1::GetTrkLevel1();      trk0_obj  = 0;
117  //     trkh_obj  = TrkHough::GetTrkHough();      calo0_obj  = 0;
118  //     calo1_obj = CaloLevel1::GetCaloLevel1();  
 //     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();  
119      trk2_obj  = 0;      trk2_obj  = 0;
120      trk1_obj  = 0;      trk1_obj  = 0;
121      trkh_obj  = 0;      trkh_obj  = 0;
# Line 114  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 = -1LL;
134        runfirstentry = 0LL;
135        runlastentry = 0LL;
136    
137        l0_file = NULL;
138        l0_tree = NULL;
139        iroot   = -1;
140        dbc     = 0;
141    
142        prevshift = 0;
143        
144        run_tree = NULL;
145        run_tree_clone = NULL;
146        sel_tree = NULL;
147        sel_tree_clone = NULL;
148        
149        irunentry = -1LL;
150        pam_tree = NULL;
151        for(Int_t i=0; i<NCLONES; i++ )pam_tree_clone[i]=NULL;
152    
153        host = "mysql://localhost/pamelaprod";
154        user = "anonymous";
155        psw = "";
156        const char *pamdbhost=gSystem->Getenv("PAM_DBHOST");
157        const char *pamdbuser=gSystem->Getenv("PAM_DBUSER");
158        const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW");
159        if ( !pamdbhost ) pamdbhost = "";
160        if ( !pamdbuser ) pamdbuser = "";
161        if ( !pamdbpsw ) pamdbpsw = "";
162        if ( strcmp(pamdbhost,"") ) host = pamdbhost;
163        if ( strcmp(pamdbuser,"") ) user = pamdbuser;
164        if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw;
165    
166      for(Int_t i=0; i<8; i++ )tree_clone[i]=NULL;      
167    
168  //    sorted_tracks = 0;//new TRefArray();  //    sorted_tracks = 0;//new TRefArray();
169            
170        CAL0 = false;
171      CAL1 = true;      CAL1 = true;
172      CAL2 = true;      CAL2 = true;
173      TRK2 = true;      TRK2 = true;
174      TRK1 = false;      TRK1 = false;
175      TRKh = false;      TRKh = false;
176      TRG = true;      TRKh = false;
177      TOF = true;      TRG  = true;
178      S4  = true;      TOF  = true;
179      ND  = true;      TOF0 = false;
180      AC  = true;      S4   = true;
181      ORB = true;      ND   = true;
182        AC   = true;
183        ORB  = true;
184            
185      RUN = true;      RUN  = true;
186    
187        SELLI = -1;
188    
189        ISGP = false;
190    
191      tsorted=0;      tsorted=0;
192      timage=0;      timage=0;
193        
194        howtosort = "+CAL+TOF";
195        //howtosort = "+TOF";
196        sortthr = 100.;
197    
198  };  };
199  /**  /**
# Line 147  void PamLevel2::Delete(){ Line 205  void PamLevel2::Delete(){
205      if(soft_obj)delete soft_obj; //Emiliano      if(soft_obj)delete soft_obj; //Emiliano
206    
207  //    cout << "void PamLevel2::Clear()"<<endl;  //    cout << "void PamLevel2::Clear()"<<endl;
208        if(h0_obj)   delete h0_obj;
209        if(trk0_obj) delete trk0_obj;      
210        if(calo0_obj) delete calo0_obj;    
211      if(trk1_obj) delete trk1_obj;            if(trk1_obj) delete trk1_obj;      
212      if(trk2_obj) delete trk2_obj;      if(trk2_obj) delete trk2_obj;
213      if(trkh_obj) delete trkh_obj;      if(trkh_obj) delete trkh_obj;
# Line 167  void PamLevel2::Delete(){ Line 228  void PamLevel2::Delete(){
228          timage->Delete();          timage->Delete();
229          delete timage;          delete timage;
230      }      }
231    
232        if(dbc){
233            dbc->Close();
234            delete dbc;
235        }
236        
237        if(l0_file)l0_file->Close();
238        //    if(pam_tree)pam_tree->Delete();;
239    
240      if ( pam_tree ){
241        //
242        // we have first to find which chains we have to delete, then delete the main chain and only after delete the friend chains. Any other order causes a segfault...
243        //
244        TList *temp = pam_tree->GetListOfFriends();
245        TList *contents  = new TList; // create chain friend list
246        contents->SetOwner();
247        TIter next(temp);
248        TChain *questo = 0;
249        while ( (questo = (TChain*) next()) ){
250          TString name =  questo->GetName();
251          contents->Add((TChain*)gROOT->FindObject(name.Data()));// add object to the list
252        };
253        //
254        // deleting the main chain
255        //
256        pam_tree->Delete();
257        //
258        // deleting the friends...
259        //
260        TIter next2(contents);
261        TChain *questa = 0;
262        while ( questa = (TChain*)next2() ){
263          TString name =  questa->GetName();
264          questa->Delete();      
265          questa=NULL;
266        };
267        //
268      };
269      pam_tree = NULL;
270    
271        if(run_tree)run_tree->Delete();;
272        if(sel_tree)sel_tree->Delete();;
273        for(Int_t i=0; i<NCLONES; i++ )if(pam_tree_clone[i])pam_tree_clone[i]->Delete();;
274        if(run_tree_clone)run_tree_clone->Delete();;
275        if(sel_tree_clone)sel_tree_clone->Delete();;
276        
277    
278  };  };
279    
280  /**  /**
# Line 177  void PamLevel2::Clear(){ Line 285  void PamLevel2::Clear(){
285  //    cout << "void PamLevel2::Clear()"<<endl;  //    cout << "void PamLevel2::Clear()"<<endl;
286    
287  //  //
288    // This method is called once for every entry but RunInfo and SoftInfo do not change until the next run so we cannot clear them here unless we don't
289    // want to load them for each event even if they are the same...
290    //
291  //    if(run_obj)delete run_obj;  //    if(run_obj)delete run_obj;
292      if(run_obj) run_obj->Clear();  // Emiliano: Do not deallocate run_obj here, it will give segmentation fault! call clear instead  //    if(run_obj) run_obj->Clear();  // Emiliano: Do not deallocate run_obj here, it will give segmentation fault! call clear instead
293      if(soft_obj) soft_obj->Clear();  //    if(soft_obj) soft_obj->Clear();
294    
295        if(h0_obj)   h0_obj->Clear();      
296    //    if(trk0_obj) trk0_obj->Clear();  
297      if(trk1_obj) trk1_obj->Clear();          if(trk1_obj) trk1_obj->Clear();    
298      if(trk2_obj) trk2_obj->Clear();      if(trk2_obj) trk2_obj->Clear();
299      if(trkh_obj) trkh_obj->Clear();      if(trkh_obj) trkh_obj->Clear();
300        if(calo0_obj) calo0_obj->Clear();  
301      if(calo1_obj)calo1_obj->Clear();      if(calo1_obj)calo1_obj->Clear();
302      if(calo2_obj)calo2_obj->Clear();      if(calo2_obj)calo2_obj->Clear();
303      if(tof_obj)  tof_obj->Clear();      if(tof_obj)  tof_obj->Clear();
# Line 202  void PamLevel2::Clear(){ Line 316  void PamLevel2::Clear(){
316      if(timage){      if(timage){
317          timage->Delete();          timage->Delete();
318      }      }
       
319  };  };
320    
321    void PamLevel2::Reset(){
322      //
323      // First of all clear everything
324      //
325      Clear();
326      //
327      // close and reset chains and pointers
328      //    
329      if ( pam_tree ){
330        //
331        // we have first to find which chains we have to delete, then delete the main chain and only after delete the friend chains. Any other order causes a segfault...
332        //
333        TList *temp = pam_tree->GetListOfFriends();
334        TList *contents  = new TList; // create chain friend list
335        contents->SetOwner();
336        TIter next(temp);
337        TChain *questo = 0;
338        while ( (questo = (TChain*) next()) ){
339          TString name =  questo->GetName();
340          contents->Add((TChain*)gROOT->FindObject(name.Data()));// add object to the list
341        };
342        //
343        // deleting the main chain
344        //
345        pam_tree->Delete();
346        //
347        // deleting the friends...
348        //
349        TIter next2(contents);
350        TChain *questa = 0;
351        while ( questa = (TChain*)next2() ){
352          TString name =  questa->GetName();
353          questa->Delete();      
354          questa=NULL;
355        };
356        //
357      };
358      pam_tree = NULL;
359      //
360      if(run_tree)run_tree->Delete();;
361      run_tree = NULL;
362      if(sel_tree)sel_tree->Delete();;
363      sel_tree = NULL;
364      //
365      // Close file
366      //
367      if(l0_file)l0_file->Close("R");
368      l0_file = NULL;
369      //
370      h0_obj    = 0;
371      trk0_obj  = 0;
372      calo0_obj  = 0;
373      //
374      trk2_obj  = 0;
375      trk1_obj  = 0;
376      trkh_obj  = 0;
377      calo1_obj = 0;
378      calo2_obj = 0;
379      tof_obj   = 0;
380      trig_obj  = 0;
381      s4_obj    = 0;
382      nd_obj    = 0;
383      ac_obj    = 0;
384      orb_obj   = 0;
385      //
386      // Reset run pointers
387      //
388      run_obj   = 0;//new GL_RUN();
389      soft_obj   = 0;// Emiliano
390      irun = -1;
391      runfirstentry = 0ULL;
392      runlastentry = 0ULL;    
393      //
394    };
395    
396    Bool_t PamLevel2::IsGood(){
397      Bool_t goodev=true;
398      //  if(trk2_obj && trk2_obj->UnpackError() != 0 ) goodev = false;
399      if(calo2_obj && calo2_obj->good != 1) goodev = false;
400      if(tof_obj && tof_obj->unpackError != 0) goodev = false;  
401      if(trig_obj && trig_obj->unpackError != 0) goodev = false;
402      if(s4_obj && s4_obj->unpackError != 0) goodev = false;  
403      if(nd_obj && nd_obj->unpackError != 0) goodev = false;  
404      if(ac_obj && ac_obj->unpackError != 255) goodev = false;  
405        //  if(orb_obj)  
406      return goodev;
407    };
408    
409  //--------------------------------------  //--------------------------------------
410  //  //
# Line 399  PamTrack* PamLevel2::GetStoredTrack(Int_ Line 599  PamTrack* PamLevel2::GetStoredTrack(Int_
599  }  }
600  //--------------------------------------  //--------------------------------------
601  //  //
602    
603    /**
604     * Sort physical (tracker) tracks and stores them in the TRefArray (of TrkTrack objects) which pointer is  PamLevel2::sorted_tracks. Left here as backward compatibility method.
605     **/
606    void PamLevel2::SortTracks(TString how){
607      printf(" WARNING! obsolete, use SortTracks() and SetSortingMethod(TString) instead! \n Setting sorting method to %s \n",how.Data());
608      howtosort = how;  
609      SortTracks();
610    };
611    
612  //  //
613  //--------------------------------------  //--------------------------------------
614  /**  /**
# Line 412  PamTrack* PamLevel2::GetStoredTrack(Int_ Line 622  PamTrack* PamLevel2::GetStoredTrack(Int_
622   *   *
623   * The total number of physical tracks is always given by GetNTracks() and the it-th physical track can be retrieved by means of the methods GetTrack(int it) and GetTrack(int it, TString how).   * The total number of physical tracks is always given by GetNTracks() and the it-th physical track can be retrieved by means of the methods GetTrack(int it) and GetTrack(int it, TString how).
624   */   */
625  void PamLevel2::SortTracks(TString how){  void PamLevel2::SortTracks(){
626      TString how = howtosort;
627    
628  //    cout <<" PamLevel2::SortTracks(TString how) "<<endl;    //    cout <<" PamLevel2::SortTracks(TString how) "<<endl;
629      if( !trk2_obj ){    if( !trk2_obj ){
630          cout << "void PamLevel2::SortTracks(TString how):  TrkLevel2 not loaded !!!";      cout << "void PamLevel2::SortTracks():  TrkLevel2 not loaded !!!";
631          return;      return;
632      };    };
633  //    cout << "call SortTracs() "<<endl;    //    cout << "call SortTracs() "<<endl;
634    //Save current Object count    //Save current Object count
635      Int_t ObjectNumber = TProcessID::GetObjectCount();    Int_t ObjectNumber = TProcessID::GetObjectCount();
636    
637  //    cout << "ObjectNumber  "<<ObjectNumber <<endl;    //    cout << "ObjectNumber  "<<ObjectNumber <<endl;
638    
639  //     if(!sorted_tracks)sorted_tracks = new TRefArray();    //     if(!sorted_tracks)sorted_tracks = new TRefArray();
640  //     sorted_tracks->Clear();    //     sorted_tracks->Clear();
641  //    sorted_tracks.Clear();    //    sorted_tracks.Clear();
642    
643      if(!tsorted)tsorted = new TClonesArray("PamTrack",trk2_obj->GetNTracks());
644      tsorted->Delete();
645      TClonesArray &ttsorted = *tsorted;
646      if(!timage)timage = new TClonesArray("PamTrack",trk2_obj->GetNTracks());
647      timage->Delete();
648      TClonesArray &ttimage = *timage;
649    
     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;  
650    
651    
652      // loop over the tracks sorted by the tracker    //--------------------------------------------------
653      Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);    // retrieve sorting method
654      Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);    //--------------------------------------------------
655      Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase);    Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);
656          Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);
657      if( !CAL2 &&  use_CAL) use_CAL = false;    Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase);
658      if( !TOF &&  use_TOF) use_TOF = false;      
659          if( !CAL2 &&  use_CAL) use_CAL = false;
660      if( !TRK2 ){    if( !TOF &&  use_TOF) use_TOF = false;
661  //      cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl;      
662          return;    if( !TRK2 ){
663      };      //  cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl;
664        return;
665      //   cout << "use_CAL "<<use_CAL<<" use_TOF "<<use_TOF<<" use_TRK "<<use_TRK <<endl;    };
666        
667      for(Int_t i=0; i < trk2_obj->TrkLevel2::GetNTracks(); i++){    //   cout << "use_CAL "<<use_CAL<<" use_TOF "<<use_TOF<<" use_TRK "<<use_TRK <<endl;
668              
669          TrkTrack   *ts = 0;  
670          CaloTrkVar *cs = 0;    //--------------------------------------------------
671          ToFTrkVar  *os = 0;    // loop over "physical" tracks sorted by the tracker
672              //--------------------------------------------------
673          // get tracker tracks    for(Int_t i=0; i < trk2_obj->TrkLevel2::GetNTracks(); i++){
674          TrkTrack   *tp = trk2_obj->TrkLevel2::GetTrack(i);                    //tracker          
675          CaloTrkVar *cp = GetCaloStoredTrack(tp->GetSeqNo());      TrkTrack   *ts = 0;
676          ToFTrkVar  *op = GetToFStoredTrack(tp->GetSeqNo());      CaloTrkVar *cs = 0;
677        ToFTrkVar  *os = 0;
678          TrkTrack   *ti = 0;              //tracker (image)          
679          CaloTrkVar *ci = 0;      // get tracker tracks
680          ToFTrkVar  *oi = 0;      TrkTrack   *tp = trk2_obj->TrkLevel2::GetTrack(i); //tracker
681  //      cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;      CaloTrkVar *cp = GetCaloStoredTrack(tp->GetSeqNo());
682          // if track has an image, check image selection      ToFTrkVar  *op = GetToFStoredTrack(tp->GetSeqNo());
683          if(tp->HasImage()){  
684        TrkTrack   *ti = 0; //tracker (image)
685        CaloTrkVar *ci = 0;
686        ToFTrkVar  *oi = 0;
687        //  cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;
688        // if track has an image, check image selection
689        if(tp->HasImage()){
690                            
691              ti = trk2_obj->TrkLevel2::GetTrackImage(i);              //tracker (image)        ti = trk2_obj->TrkLevel2::GetTrackImage(i);              //tracker (image)
692              ci = GetCaloStoredTrack(ti->GetSeqNo());        ci = GetCaloStoredTrack(ti->GetSeqNo());
693              oi = GetToFStoredTrack(ti->GetSeqNo());        oi = GetToFStoredTrack(ti->GetSeqNo());
694                            
695  //          cout << "its image "<<i << " "<<hex<< ti <<dec<< endl;        //            cout << "its image "<<i << " "<<hex<< ti <<dec<< endl;
696    
697              //assign starting scores        //assign starting scores
698              Int_t tp_score = 0;  //main track sorted by the tracker        Int_t tp_score = 0;  //main track sorted by the tracker
699              Int_t ti_score = 0;  //image track        Int_t ti_score = 0;  //image track
700                            
701              // ------------------------        // -----------------------------------------------------------------------------------------
702              // calorimeter check        // calorimeter check
703              // ------------------------        // -----------------------------------------------------------------------------------------
704              // check the Y spatial residual on the first calorimeter plane        // check the Y spatial residual on the first calorimeter plane
705              // (cut on calorimeter variables from Emiliano)        // (cut on calorimeter variables from Emiliano)
706              if( use_CAL && !calo2_obj ){        if( use_CAL && !calo2_obj ){
707                  cout << "void PamLevel2::SortTracks(TString how): how= "<<how<<" but CaloLevel2 not loaded !!!";          cout << "void PamLevel2::SortTracks(): howtosort= "<<how<<" but CaloLevel2 not loaded !!!";
708                  return;          return;
709              };        };
710              if(        if(
711                  use_CAL            &&           use_CAL            &&
712                  calo2_obj->npcfit[1] > 15     &&   //no. of fit planes on Y view  //       calo2_obj->npcfit[1] > 5     &&   //no. of fit planes on Y view
713                  calo2_obj->varcfit[1] < 1000. &&  //fit variance on Y view  //       calo2_obj->varcfit[1] < 1000. &&  //fit variance on Y view
714                  true){           cp && ci &&
715             true){
716    
717                                    
718                  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;
719                  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;
720                                    
721                  if(resy_p <= resy_i) tp_score++;  //      if(resy_p <= resy_i) tp_score++;
722                  else                 ti_score++;  //      else                 ti_score++;
723            
724    
725  //              cout << "CALO "<<tp_score<<ti_score<<endl;            if( cp->npresh > ci->npresh) tp_score++;
726              if( cp->npresh < ci->npresh) ti_score++;
727              else ;//niente
728    
729            //      cout << "CALO "<<tp_score<<ti_score<<endl;
730    
731          };
732          // -----------------------------------------------------------------------------------------
733          // TOF check
734          // -----------------------------------------------------------------------------------------
735          // check the number of hit pmts along the track
736          // on S12 S21 and S32, where paddles are parallel to Y axis
737          if( use_TOF && !tof_obj ){
738            cout << "void PamLevel2::SortTracks(): howtosort= "<<how<<" but ToFLevel2 not loaded !!!";
739            return;
740          };
741          if( use_TOF && op && oi ){
742                    
743            //
744            Float_t sen = 0.;
745            for (Int_t ih=0; ih < op->npmtadc; ih++){
746              Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
747              if ( pl == 2 || pl == 3 || pl == 4 || pl == 5 ) sen += (op->dedx).At(ih);
748            };
749            for (Int_t ih=0; ih < oi->npmtadc; ih++){
750              Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
751              if ( pl == 2 || pl == 3 || pl == 4 || pl == 5 ) sen += (oi->dedx).At(ih);
752            };
753            //
754            if (  sen >= sortthr ){
755              //printf(" IS A NUCLEUS! en = %f \n",sen);
756              //
757              // is a nucleus use a different algorithm
758              //
759              Int_t nz = 6; Float_t zin[6];                                          // << define TOF z-coordinates
760              for(Int_t ip=0; ip<nz; ip++)
761                zin[ip] = tof_obj->ToFLevel2::GetZTOF(tof_obj->ToFLevel2::GetToFPlaneID(ip));     // << read ToF plane z-coordinates
762              Trajectory *tr = new Trajectory(nz,zin);
763              //
764              Int_t nphit_p =0;
765              Int_t nphit_i =0;
766              Float_t enhit_p = 0.;
767              Float_t enhit_i = 0.;
768              //
769              for (Int_t ih=0; ih < op->npmtadc; ih++){
770                Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
771                if(pl == 1 || pl == 2 || pl == 5){
772                  nphit_p++;
773                  enhit_p += (op->dedx).At(ih);
774                };
775              };
776              //
777              tp->DoTrack2(tr);
778              //
779              if ( fabs(tr->y[0]-oi->ytofpos[0]) < 2. ){
780                for (Int_t ih=0; ih < op->npmtadc; ih++){
781                  Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
782                  if(pl == 0){
783                    nphit_p++;
784                    enhit_p += (op->dedx).At(ih);
785                  };
786                };
787              };
788              if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){
789                for (Int_t ih=0; ih < op->npmtadc; ih++){
790                  Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
791                  if(pl == 3){
792                    nphit_p++;
793                    enhit_p += (op->dedx).At(ih);
794                  };
795                };
796              };
797              if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){
798                for (Int_t ih=0; ih < op->npmtadc; ih++){
799                  Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
800                  if(pl == 4){
801                    nphit_p++;
802                    enhit_p += (op->dedx).At(ih);
803                  };
804                };
805              };
806    
807              for (Int_t ih=0; ih < oi->npmtadc; ih++){
808                Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
809                if(pl == 1 || pl == 2 || pl == 5){
810                  nphit_i++;        
811                  enhit_i += (op->dedx).At(ih);
812                };
813              };
814              //
815              ti->DoTrack2(tr);
816              //
817              if ( fabs(tr->y[0]-oi->ytofpos[0]) < 2. ){
818                for (Int_t ih=0; ih < oi->npmtadc; ih++){
819                  Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
820                  if(pl == 0){
821                    nphit_i++;
822                    enhit_i += (op->dedx).At(ih);
823                  };
824              };              };
825              // ------------------------            };
826              // TOF check            if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){
827              // ------------------------                  for (Int_t ih=0; ih < oi->npmtadc; ih++){
828              // check the number of hit pmts along the track                Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
829              // on S12 S21 and S32, where paddles are parallel to Y axis                if(pl == 3){
830              if( use_TOF && !tof_obj ){                  nphit_i++;
831                  cout << "void PamLevel2::SortTracks(TString how): how= "<<how<<" but ToFLevel2 not loaded !!!";                  enhit_i += (op->dedx).At(ih);
832                  return;                };
833              };              };
834              if( use_TOF ){            };
835              if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){
836                for (Int_t ih=0; ih < oi->npmtadc; ih++){
837                  Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
838                  if(pl == 4){
839                    nphit_i++;
840                    enhit_i += (op->dedx).At(ih);
841                  };
842                };
843              };            
844    
845                    
846              if(
847                 use_TOF            &&
848                 (nphit_p+nphit_i) !=0 &&  
849                 true){
850                        
851                //      printf(" seqno %i nphit_p %i nphit_i %i enhit_p %f enhit_i %f \n",trk2_obj->TrkLevel2::GetSeqNo(i),nphit_p,nphit_i,enhit_p,enhit_i);
852                //      printf(" score p %i score i %i \n",tp_score,ti_score);
853                //            if( enhit_p > enhit_i ) tp_score++;
854                //            if( nphit_p >= nphit_i && enhit_p > enhit_i ) tp_score++;
855                if ( nphit_p > nphit_i ) tp_score++;
856                if ( nphit_p < nphit_i ) ti_score++;
857                if ( nphit_p == nphit_i ){
858                  if ( enhit_p > enhit_i ) tp_score++;
859                  else ti_score++;
860                };
861                //      printf(" dopo score p %i score i %i \n",tp_score,ti_score);
862              };
863              delete tr;
864              //
865            } else {
866              //
867              // NOT a NUCLEUS
868              //
869              //printf(" NOT a NUCLEUS! en = %f \n",sen);
870    
871              Int_t nphit_p =0;
872              Int_t nphit_i =0;
873                                    
                 Int_t nphit_p =0;  
                 Int_t nphit_i =0;  
874                                    
875              /*                            cout << "track: npmtadc "<< op->npmtadc << endl;
876                cout << "track: npmttdc "<< op->npmttdc << endl;
877                cout << "image: npmtadc "<< oi->npmtadc << endl;
878                cout << "image: npmttdc "<< oi->npmttdc << endl;*/
879                                    
880  /*                              cout << "track: npmtadc "<< op->npmtadc << endl;  //        for (Int_t ih=0; ih < op->npmtadc; ih++){
881                                  cout << "track: npmttdc "<< op->npmttdc << endl;  //          Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
882                                  cout << "image: npmtadc "<< oi->npmtadc << endl;  //          if(pl == 1 || pl == 2 || pl == 5)nphit_p++;
883                                  cout << "image: npmttdc "<< oi->npmttdc << endl;*/  //        };
884                                    
885                  for (Int_t ih=0; ih < op->npmtadc; ih++){  //        for (Int_t ih=0; ih < oi->npmtadc; ih++){
886                      Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );  //          Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
887                      if(pl == 1 || pl == 2 || pl == 5)nphit_p++;  //          if(pl == 1 || pl == 2 || pl == 5)nphit_i++;
888                  };  //        };
889              // --- modified to count tdc signals (more efficient?)
890              // --- and to implement check on tdcflag
891              for (Int_t ih=0; ih < op->npmttdc; ih++){
892                Int_t pl = tof_obj->GetPlaneIndex( (op->pmttdc).At(ih) );
893    //          if( (op->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_p++;
894                if( (op->tdcflag).At(ih)==0 )nphit_p++;
895              };
896                                    
897                  for (Int_t ih=0; ih < oi->npmtadc; ih++){            for (Int_t ih=0; ih < oi->npmttdc; ih++){
898                      Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );              Int_t pl = tof_obj->GetPlaneIndex( (oi->pmttdc).At(ih) );
899                      if(pl == 1 || pl == 2 || pl == 5)nphit_i++;  //          if( (oi->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_i++;  
900                  };              if( (oi->tdcflag).At(ih)==0 )nphit_i++;    
901              };
902                                    
903                  if(            if(
904                      use_TOF            &&               (nphit_p+nphit_i) !=0 &&  
905                      (nphit_p+nphit_i) !=0 &&                   true){
                     true){  
906                                            
907                      if( nphit_p >= nphit_i) tp_score++;              if     ( nphit_p > nphit_i) tp_score++;
908                      else ti_score++;              else if( nphit_p < nphit_i) ti_score++;
909                  };              else ;//niente
910  //              cout << "TOF "<<tp_score<<ti_score<<endl;            };
911              };          };
912              if(tp_score == ti_score) use_TRK = true;          //      cout << "TOF "<<tp_score<<ti_score<<endl;
913              // ------------------------        };
914              // tracker check  
915              // ------------------------  
916              // chi**2 difference is not always large enough to distinguish among  //      if(tp_score == ti_score) use_TRK = true;
917              // the real track and its image.  
918              // Tracker check will be applied always when calorimeter and tof information is ambiguous.  
919              if(use_TRK){        // -----------------------------------------------------------------------------------------
920                  if(      tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ;        // tracker check
921                  else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ;        // -----------------------------------------------------------------------------------------
922  //              cout << "TRK "<<tp_score<<ti_score<<endl;        // chi**2 difference is not always large enough to distinguish among
923              };        // the real track and its image.
924          // Tracker check will be applied always when calorimeter and tof information is ambiguous.
925          // *** MODIFIED ON AUGUST 2007 ***
926          if(use_TRK){
927    //      if(      tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ;
928    //      else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ;
929    
930              // CHECK 1 : number of points along X  
931              if ( tp->GetNX() >= ti->GetNX() )tp_score++ ;
932              if ( tp->GetNX() <= ti->GetNX() )ti_score++ ;
933              // CHECK 2 : number of points along Y  
934              if ( tp->GetNY() >= ti->GetNY() )tp_score++ ;
935              if ( tp->GetNY() <= ti->GetNY() )ti_score++ ;
936              // CHECK 3 : chi**2 along X  
937    //        if(      tp->GetChi2X() > 0 && (tp->GetChi2X() < ti->GetChi2X() || ti->GetChi2X() <=0) ) tp_score++ ;
938    //        if(      ti->GetChi2X() > 0 && (ti->GetChi2X() < tp->GetChi2X() || tp->GetChi2X() <=0) ) ti_score++ ;
939              // CHECK 4 : chi**2 along Y  
940    //        if(      tp->GetChi2Y() > 0 && (tp->GetChi2Y() < ti->GetChi2Y() || ti->GetChi2Y() <=0) ) tp_score++ ;
941    //        if(      ti->GetChi2Y() > 0 && (ti->GetChi2Y() < tp->GetChi2Y() || tp->GetChi2Y() <=0) ) ti_score++ ;
942              // CHECK 5 : total chi**2  
943    //        if(      tp->chi2 > 0 && (tp->chi2 < ti->chi2 || ti->chi2 <=0) ) tp_score++ ;
944    //        if(      ti->chi2 > 0 && (ti->chi2 < tp->chi2 || tp->chi2 <=0) ) ti_score++ ;
945    
946            //      cout << "TRK "<<tp_score<<ti_score<<endl;
947          };
948                            
949              // ------------------------  
950              // the winner is....  
951              // ------------------------            // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
952              if      (tp_score > ti_score) {        // the winner is....
953  //              ts = tp;//the track sorted by the tracker!!        // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
954  //              cs = cp;        if      (tp_score > ti_score) {
955  //              os = op;          
956              }else if (tp_score < ti_score) {  
957                  ts = ti;//its image!!        }else if (tp_score < ti_score) {
958                  cs = ci;  
959                  os = oi;  
960            ts = ti;//its image!!
961                  ti = tp;//its image!!          cs = ci;
962                  ci = cp;          os = oi;
963                  oi = op;  
964            ti = tp;//its image!!
965                  tp = ts;//its image!!          ci = cp;
966                  cp = cs;          oi = op;
967                  op = os;  
968            tp = ts;//its image!!
969            cp = cs;
970            op = os;
971    
972                                    
973              }else {        }else {
974  //              ts = tp;  
975  //              cs = cp;  //      cout << "Warning - track image ambiguity not solved" << endl;
976  //              os = op;  
977  //                              cout << "Warning - track image ambiguity not solved" << endl;        };
 //                              cout << ts->GetNtot() << " "<< ts->chi2 << " " << npcfit[1] << " "<< nphit_p << endl;  
             };  
978                            
979          }else{      }else{
980  //          ts = tp;        //            ts = tp;
981  //          cs = cp;        //            cs = cp;
982  //          os = op;        //            os = op;
983          };      };
984                    
985  //      cout <<" SortTracks() "<<i<<" -- "<<ts<<endl;      //  cout <<" SortTracks() "<<i<<" -- "<<ts<<endl;
986  //      sorted_tracks->Add(ts);//save the track in the sorted array      //  sorted_tracks->Add(ts);//save the track in the sorted array
987  //      sorted_tracks.Add(ts);//save the track in the sorted array      //  sorted_tracks.Add(ts);//save the track in the sorted array
988  //      sorted_tracks.Add(tp);//save the track in the sorted array      //  sorted_tracks.Add(tp);//save the track in the sorted array
989  //      cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl;      //  cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl;
990  //      cout<<"o "<<tp<<endl;      //  cout<<"o "<<tp<<endl;
991  //      cout<<"o "<<cp<<endl;      //  cout<<"o "<<cp<<endl;
992  //      cout<<"o "<<op<<endl;      //  cout<<"o "<<op<<endl;
993          new(ttsorted[i]) PamTrack(tp,cp,op);      new(ttsorted[i]) PamTrack(tp,cp,op);
994          new(ttimage[i])  PamTrack(ti,ci,oi);      new(ttimage[i])  PamTrack(ti,ci,oi);
995      };    };
996    
997      if( tsorted->GetEntries() != trk2_obj->GetNTracks() ){    if( tsorted->GetEntries() != trk2_obj->GetNTracks() ){
998          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;
999          tsorted->Delete(); tsorted=0;      tsorted->Delete(); tsorted=0;
1000          timage->Delete(); timage=0;          timage->Delete(); timage=0;
1001      }    }
1002    
1003      //Restore Object count    //Restore Object count
1004      //To save space in the table keeping track of all referenced objects    //To save space in the table keeping track of all referenced objects
1005      //We reset the object count to what it was at the beginning of the event.    //We reset the object count to what it was at the beginning of the event.
1006      TProcessID::SetObjectCount(ObjectNumber);    TProcessID::SetObjectCount(ObjectNumber);
1007            
1008  };  };
1009  //--------------------------------------  //--------------------------------------
# Line 638  void PamLevel2::SortTracks(TString how){ Line 1027  void PamLevel2::SortTracks(TString how){
1027  TClonesArray *PamLevel2::GetTracks(){  TClonesArray *PamLevel2::GetTracks(){
1028    
1029  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
1030      SortTracks("+CAL+TOF");      SortTracks();
1031  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
1032    
1033      return tsorted;      return tsorted;
# Line 657  PamTrack *PamLevel2::GetTrack(int it){ Line 1046  PamTrack *PamLevel2::GetTrack(int it){
1046    
1047  //    if(!trk2_obj) return 0;  //    if(!trk2_obj) return 0;
1048                    
1049  // //  *-*-*-*-*-*-*-*-*-*-*-*-*  // //  *-*-*-*+-*-*-*-*-*-*-*-*-*
1050  //     SortTracks("+CAL+TOF");  //     SortTracks("+CAL+TOF");
1051  // //  *-*-*-*-*-*-*-*-*-*-*-*-*  // //  *-*-*-*-*-*-*-*-*-*-*-*-*
1052  // //    if(!sorted_tracks)return 0;  // //    if(!sorted_tracks)return 0;
# Line 676  PamTrack *PamLevel2::GetTrack(int it){ Line 1065  PamTrack *PamLevel2::GetTrack(int it){
1065    
1066  //    cout << "PamLevel2::GetTrack(int it) "<<endl;  //    cout << "PamLevel2::GetTrack(int it) "<<endl;
1067  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
1068      SortTracks("+CAL+TOF");      SortTracks();
1069  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
1070      if(!tsorted)return 0;      if(!tsorted)return 0;
1071      if(!tsorted->GetEntries())return 0;      if(!tsorted->GetEntries())return 0;
# Line 733  PamTrack *PamLevel2::GetTrackImage(int i Line 1122  PamTrack *PamLevel2::GetTrackImage(int i
1122    
1123    
1124  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
1125      SortTracks("+CAL+TOF");      SortTracks();
1126  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
1127      if(!timage)return 0;      if(!timage)return 0;
1128      if(!timage->GetEntries())return 0;      if(!timage->GetEntries())return 0;
# Line 770  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1159  TTree *PamLevel2::GetPamTree(TFile *f, T
1159    
1160  //     if( !detlist.IsNull() ) SetWhichTrees(detlist);  //     if( !detlist.IsNull() ) SetWhichTrees(detlist);
1161  //     else                    GetWhichTrees(f);  //     else                    GetWhichTrees(f);
1162      if ( pam_tree ){
1163        printf("WARNING: TTree *PamLevel2::GetPamTree(TFile *fl, TString detlist) -- pam_tree already exists!\n ");
1164        return pam_tree;
1165      };
1166      //
1167    
1168        cout << "TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ) -- obsolte "<<endl;
1169    
1170      SetWhichTrees(detlist);      SetWhichTrees(detlist);
1171    
1172      TTree *Trout =0;      TTree *Trout =0;
# Line 777  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1174  TTree *PamLevel2::GetPamTree(TFile *f, T
1174      TString fname = f->GetName();      TString fname = f->GetName();
1175      if(!CheckLevel2File(fname))return NULL;      if(!CheckLevel2File(fname))return NULL;
1176    
1177      UInt_t *found=0;      //    UInt_t *found=0;    
1178    
1179      cout<< "GetPamTree(TFile*,TString): detector list --> ";      cout<< "GetPamTree(TFile*,TString): detector list --> ";
1180      if(TRK1)cout<<"TRK1 ";      if(TRK1)cout<<"TRK1 ";
# Line 792  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1189  TTree *PamLevel2::GetPamTree(TFile *f, T
1189      if(S4)cout<<"S4 ";      if(S4)cout<<"S4 ";
1190      if(ORB)cout<<"ORB ";      if(ORB)cout<<"ORB ";
1191      cout << endl;      cout << endl;
1192        if(SELLI)cout<<">>> Found selection-list <<<"<<endl;
1193    
1194      f->cd();      f->cd();
1195    
# Line 799  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1197  TTree *PamLevel2::GetPamTree(TFile *f, T
1197      TTree *T = (TTree*)f->Get("Tracker");      TTree *T = (TTree*)f->Get("Tracker");
1198      if(T && (TRK2||TRK1||TRKh)) {      if(T && (TRK2||TRK1||TRKh)) {
1199          if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));          if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
1200          else    T->SetBranchStatus("TrkLevel2",0,found);  //      else    T->SetBranchStatus("TrkLevel2",0,found);
1201          if(TRK2)cout << "Tracker      : set branch address TrkLevel2"<<endl;          if(TRK2)cout << "Tracker      : set branch address TrkLevel2"<<endl;
1202          if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));          if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
1203          else    T->SetBranchStatus("TrkLevel1",0,found);  //      else    T->SetBranchStatus("TrkLevel1",0,found);
1204          if(TRK1)cout << "Tracker      : set branch address TrkLevel1"<<endl;          if(TRK1)cout << "Tracker      : set branch address TrkLevel1"<<endl;
1205          if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));          if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
1206          else    T->SetBranchStatus("TrkHough",0,found);  //      else    T->SetBranchStatus("TrkHough",0,found);
1207          if(TRKh)cout << "Tracker      : set branch address TrkHough"<<endl;          if(TRKh)cout << "Tracker      : set branch address TrkHough"<<endl;
1208          if(!Trout)Trout=T;          if(!Trout)Trout=T;
1209          else Trout->AddFriend(T);          else Trout->AddFriend(T);
# Line 816  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1214  TTree *PamLevel2::GetPamTree(TFile *f, T
1214      TTree *C = (TTree*)f->Get("Calorimeter");      TTree *C = (TTree*)f->Get("Calorimeter");
1215      if(C && (CAL2||CAL1)) {      if(C && (CAL2||CAL1)) {
1216          if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));          if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
1217          else    C->SetBranchStatus("CaloLevel2",0,found);  //      else    C->SetBranchStatus("CaloLevel2",0,found);
1218          if(CAL2)cout << "Calorimeter  : set branch address CaloLevel2"<<endl;          if(CAL2)cout << "Calorimeter  : set branch address CaloLevel2"<<endl;
1219          if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));          if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
1220          else    C->SetBranchStatus("CaloLevel1",0,found);  //      else    C->SetBranchStatus("CaloLevel1",0,found);
1221          if(CAL1)cout << "Calorimeter  : set branch address CaloLevel1"<<endl;          if(CAL1)cout << "Calorimeter  : set branch address CaloLevel1"<<endl;
1222          if(!Trout)Trout=C;          if(!Trout)Trout=C;
1223          else Trout->AddFriend(C);          else Trout->AddFriend(C);
# Line 842  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1240  TTree *PamLevel2::GetPamTree(TFile *f, T
1240      if(R && TRG) {      if(R && TRG) {
1241          R->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));          R->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));
1242          cout << "Trigger      : set branch address TrigLevel2"<<endl;          cout << "Trigger      : set branch address TrigLevel2"<<endl;
1243          if(!Trout)Trout=O;          if(!Trout)Trout=R;
1244          else Trout->AddFriend(R);          else Trout->AddFriend(R);
1245      }else{      }else{
1246          cout << "Trigger      : missing tree"<<endl;          cout << "Trigger      : missing tree"<<endl;
# Line 852  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1250  TTree *PamLevel2::GetPamTree(TFile *f, T
1250      if(S && S4) {      if(S && S4) {
1251          S->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));          S->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));
1252          cout << "S4           : set branch address S4Level2"<<endl;          cout << "S4           : set branch address S4Level2"<<endl;
1253          if(!Trout)Trout=O;          if(!Trout)Trout=S;
1254          else Trout->AddFriend(S);          else Trout->AddFriend(S);
1255      }else{      }else{
1256          cout << "S4           : missing tree"<<endl;          cout << "S4           : missing tree"<<endl;
# Line 862  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1260  TTree *PamLevel2::GetPamTree(TFile *f, T
1260      if(N && ND) {      if(N && ND) {
1261          N->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));          N->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));
1262          cout << "NeutronD     : set branch address NDLevel2"<<endl;          cout << "NeutronD     : set branch address NDLevel2"<<endl;
1263          if(!Trout)Trout=O;          if(!Trout)Trout=N;
1264          else Trout->AddFriend(N);          else Trout->AddFriend(N);
1265      }else{      }else{
1266          cout << "NeutronD     : missing tree"<<endl;          cout << "NeutronD     : missing tree"<<endl;
# Line 872  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1270  TTree *PamLevel2::GetPamTree(TFile *f, T
1270      if(A && AC) {      if(A && AC) {
1271          A->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));          A->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));
1272          cout << "Anticounter  : set branch address AcLevel2"<<endl;          cout << "Anticounter  : set branch address AcLevel2"<<endl;
1273          if(!Trout)Trout=O;          if(!Trout)Trout=A;
1274          else Trout->AddFriend(A);          else Trout->AddFriend(A);
1275      }else{      }else{
1276          cout << "Anticounter  : missing tree"<<endl;          cout << "Anticounter  : missing tree"<<endl;
# Line 882  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1280  TTree *PamLevel2::GetPamTree(TFile *f, T
1280      if(B && ORB) {      if(B && ORB) {
1281          B->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));          B->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
1282          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;
1283          if(!Trout)Trout=O;          if(!Trout)Trout=B;
1284          else Trout->AddFriend(B);          else Trout->AddFriend(B);
1285      }else{      }else{
1286          cout << "OrbitalInfo  : missing tree"<<endl;          cout << "OrbitalInfo  : missing tree"<<endl;
1287      };      };
1288    
1289        TTree *L = (TTree*)f->Get("SelectionList");
1290        if(L && SELLI==1) {
1291    //      L->SetBranchAddress("RunEntry",&irun);
1292    //      cout << "SelectionList: set branch address RunEntry"<<endl;
1293    //      L->SetBranchAddress("EventEntry",&irunentry);
1294    //      cout << "SelectionList: set branch address EventEntry"<<endl;
1295    //      if(!Trout)Trout=O;
1296    //      else Trout->AddFriend("SelectionList");
1297            cout << " TTree *PamLevel2::GetPamTree(TFile, TString) >>> SelectionList not implemente!!!!"<<endl;
1298            sel_tree = 0;
1299        }else{
1300            cout << "SelectionList  : missing tree"<<endl;
1301        };
1302            
1303      cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;      cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;
1304    
1305        pam_tree = (TChain*)Trout;
1306            
1307      return Trout;      return Trout;
1308            
# Line 908  TList*  PamLevel2::GetListOfLevel2Files( Line 1322  TList*  PamLevel2::GetListOfLevel2Files(
1322                    
1323      TString wdir = gSystem->WorkingDirectory();      TString wdir = gSystem->WorkingDirectory();
1324            
1325      if(ddir=="")ddir = wdir;      //    if(ddir=="")ddir = wdir;
1326  //      TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);  //      TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);
1327      cout << "Level2 data directory : "<<  ddir << endl;      if ( ddir != ""){
1328              cout << "Level2 data directory : "<<  ddir << endl;
1329        } else {
1330          cout << "Level2 data directory not given as input: trying to evaluate from list or taking working directory " << endl;
1331        };
1332      TList *contents  = new TList; // create output list      TList *contents  = new TList; // create output list
1333      contents->SetOwner();      contents->SetOwner();
1334            
1335  //    char *fullpath;  //    char *fullpath;
1336      const char *fullpath;  //    const char *fullpath;
1337            
1338      // if no input file list is given:        // if no input file list is given:  
1339      if ( flisttxt != "" ){      if ( flisttxt != "" ){
1340                    
1341  //      if( !gSystem->IsFileInIncludePath(flisttxt,&fullpath) ){          //      if( !gSystem->IsFileInIncludePath(flisttxt,&fullpath) ){        
1342          if( !(fullpath = gSystem->FindFile("./",flisttxt)) ){  //      if( !(fullpath = gSystem->FindFile("./",flisttxt)) ){
1343              cout <<"File "<<flisttxt<<" not found"<<endl;  //          cout <<"File "<<flisttxt<<" not found"<<endl;
1344              return 0;  //          return 0;
1345          }        //      }      
1346  //              flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));  //      flisttxt = fullpath;
1347          flisttxt = fullpath;        if ( !flisttxt.EndsWith(".root") ){
1348    
1349            flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
1350    
1351          if( !gSystem->ChangeDirectory(ddir) ){          if( !gSystem->ChangeDirectory(ddir) ){
1352              cout << "Cannot change directory : "<<ddir<<endl;              cout << "Cannot change directory : "<<ddir<<endl;
# Line 937  TList*  PamLevel2::GetListOfLevel2Files( Line 1356  TList*  PamLevel2::GetListOfLevel2Files(
1356          cout <<"Input file list : " << flisttxt <<endl;          cout <<"Input file list : " << flisttxt <<endl;
1357          ifstream in;          ifstream in;
1358          in.open(flisttxt, ios::in); //open input file list          in.open(flisttxt, ios::in); //open input file list
1359            if(!in.good()){
1360                cout <<" ERROR opening the file "<<endl;
1361                gSystem->ChangeDirectory(wdir); // back to the working directory
1362                return 0;
1363            }      
1364          int line=0;          int line=0;
1365          while (1) {          while (1) {
1366              TString file;              TString file;
# Line 951  TList*  PamLevel2::GetListOfLevel2Files( Line 1375  TList*  PamLevel2::GetListOfLevel2Files(
1375              if(file.Contains("#"))file = file(0,file.First("#"));              if(file.Contains("#"))file = file(0,file.First("#"));
1376  //          cout <<"(2) " << file << endl;  //          cout <<"(2) " << file << endl;
1377  //          if( gSystem->IsFileInIncludePath(file,&fullpath) ){  //          if( gSystem->IsFileInIncludePath(file,&fullpath) ){
1378              if( (fullpath = gSystem->FindFile(ddir,file)) ){  //          if( (fullpath = gSystem->FindFile(ddir,file)) ){
1379                if( file.EndsWith(".root") ){
1380                  TString filedir;
1381                  if (ddir != ""){
1382                    filedir = ddir; // take the input dir
1383                  } else {
1384                    gSystem->ChangeDirectory(wdir); // back to the working directory
1385                    filedir = gSystem->DirName(file); // this will take the path if exist in the list otherwise it will return automatically the working dir
1386                  };
1387                    char *fullpath = gSystem->ConcatFileName(gSystem->DirName(filedir),gSystem->BaseName(file));
1388                  contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list                  contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list
1389                    delete fullpath;
1390              }else{              }
1391    //          }else{
1392  //              if(file.Data()!="")cout << "File: "<<file<<" ---> missing "<< endl;  //              if(file.Data()!="")cout << "File: "<<file<<" ---> missing "<< endl;
1393              };  //          };
1394          };          };
1395          in.close();          in.close();
1396                  } else {
1397              if(flisttxt.Contains("#"))flisttxt = flisttxt(0,flisttxt.First("#"));
1398              char *fullpath = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
1399              contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list
1400              delete fullpath;
1401          };        
1402      }else{      }else{
1403                    
1404          cout << "No input file list given."<<endl;          cout << "No input file list given."<<endl;
1405          cout << "Check for existing root files."<<endl;          cout << "Check for existing root files."<<endl;
1406  //              cout << "Warking directory: "<< gSystem->WorkingDirectory()<< endl;  //              cout << "Warking directory: "<< gSystem->WorkingDirectory()<< endl;
1407                    if ( ddir == "" ){
1408              ddir = wdir;
1409              cout << "Level2 data directory : "<<  ddir << endl;
1410            };
1411    
1412          TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);          TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);
1413          TList *temp = datadir->GetListOfFiles();          TList *temp = datadir->GetListOfFiles();
1414  //              temp->Print();  //              temp->Print();
# Line 979  TList*  PamLevel2::GetListOfLevel2Files( Line 1421  TList*  PamLevel2::GetListOfLevel2Files(
1421          while ( (questo = (TSystemFile*) next()) ) {          while ( (questo = (TSystemFile*) next()) ) {
1422              TString name =  questo-> GetName();              TString name =  questo-> GetName();
1423              if( name.EndsWith(".root") ){              if( name.EndsWith(".root") ){
1424                  const char *fullpath = gSystem->FindFile(ddir,name);  //              const char *fullpath = gSystem->FindFile(ddir,name);
1425  //              char *fullpath;  //              char *fullpath;
1426  //              gSystem->IsFileInIncludePath(name,&fullpath);  //              gSystem->IsFileInIncludePath(name,&fullpath);
1427                    char *fullpath = gSystem->ConcatFileName(gSystem->DirName(ddir),gSystem->BaseName(name));
1428                  contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));                  contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));
1429                    delete fullpath;
1430              };              };
1431          }          }
1432          delete temp;          delete temp;
# Line 992  TList*  PamLevel2::GetListOfLevel2Files( Line 1436  TList*  PamLevel2::GetListOfLevel2Files(
1436      gSystem->ChangeDirectory(wdir); // back to the working directory      gSystem->ChangeDirectory(wdir); // back to the working directory
1437  //      cout << endl << "Selected files:" << endl;  //      cout << endl << "Selected files:" << endl;
1438  //      contents->Print();  //      contents->Print();
1439      cout << contents->GetEntries()<<" files selected\n";      cout << contents->GetEntries()<<" files \n";
1440  //      cout << endl;  //      cout << endl;
1441  //      cout << "Working directory: "<< gSystem->WorkingDirectory()<< endl;  //      cout << "Working directory: "<< gSystem->WorkingDirectory()<< endl;
1442      return contents;      return contents;
# Line 1008  TList*  PamLevel2::GetListOfLevel2Files( Line 1452  TList*  PamLevel2::GetListOfLevel2Files(
1452   * @return Pointer to a TChain   * @return Pointer to a TChain
1453   */   */
1454  TChain *PamLevel2::GetPamTree(TList *fl, TString detlist ){  TChain *PamLevel2::GetPamTree(TList *fl, TString detlist ){
1455      //
1456      //
1457      //
1458      if ( pam_tree ){
1459        printf("WARNING: TChain *PamLevel2::GetPamTree(TList *fl, TString detlist) -- pam_tree already exists!\n ");
1460        return pam_tree;
1461      };
1462      //
1463            
1464      TChain *Trout =0;      TChain *Trout =0;
1465    
# Line 1028  TChain *PamLevel2::GetPamTree(TList *fl, Line 1480  TChain *PamLevel2::GetPamTree(TList *fl,
1480      if(ORB)cout<<"ORB ";      if(ORB)cout<<"ORB ";
1481      cout << endl;      cout << endl;
1482    
1483      TChain *T = 0;             TChain *T = 0;    
1484      TChain *C = 0;       TChain *C = 0;
1485      TChain *O = 0;       TChain *O = 0;
1486      TChain *R = 0;       TChain *R = 0;
1487      TChain *S = 0;       TChain *S = 0;
1488      TChain *N = 0;       TChain *N = 0;
1489      TChain *A = 0;       TChain *A = 0;
1490      TChain *B = 0;       TChain *B = 0;
1491    
1492         TChain *L = 0;
1493            
1494      if(TRK2||TRK1||TRKh) T = new TChain("Tracker");          if(TRK2||TRK1||TRKh) T = new TChain("Tracker");    
1495      if(CAL2||CAL1)       C = new TChain("Calorimeter");      if(CAL2||CAL1)       C = new TChain("Calorimeter");
# Line 1045  TChain *PamLevel2::GetPamTree(TList *fl, Line 1499  TChain *PamLevel2::GetPamTree(TList *fl,
1499      if(ND)               N = new TChain("NeutronD");      if(ND)               N = new TChain("NeutronD");
1500      if(AC)               A = new TChain("Anticounter");      if(AC)               A = new TChain("Anticounter");
1501      if(ORB)              B = new TChain("OrbitalInfo");      if(ORB)              B = new TChain("OrbitalInfo");
1502         L = new TChain("SelectionList");
1503            
1504      // loop over files and create chains              // loop over files and create chains        
1505      TIter next(fl);      TIter next(fl);
# Line 1061  TChain *PamLevel2::GetPamTree(TList *fl, Line 1516  TChain *PamLevel2::GetPamTree(TList *fl,
1516              if(ND)               N->Add(name);              if(ND)               N->Add(name);
1517              if(AC)               A->Add(name);              if(AC)               A->Add(name);
1518              if(ORB)              B->Add(name);              if(ORB)              B->Add(name);
1519                if(SELLI==1)         L->Add(name);
1520          };          };
1521      }      };
1522            
1523      cout << "done chain \n";      cout << "done chain \n";
1524        cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
1525    
1526      UInt_t *found=0;  //    UInt_t *found=0;
1527  // Tracker  // Tracker
1528      if(T && (TRK2||TRK1||TRKh)) {      if(T && (TRK2||TRK1||TRKh)) {
1529          if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));          if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
1530          else    T->SetBranchStatus("TrkLevel2",0,found);  //      else    T->SetBranchStatus("TrkLevel2",0,found);
1531          if(TRK2)cout << "Tracker      : set branch address TrkLevel2"<<endl;          if(TRK2)cout << "Tracker      : set branch address TrkLevel2"<<endl;
1532          if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));          if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
1533          else    T->SetBranchStatus("TrkLevel1",0,found);  //      else    T->SetBranchStatus("TrkLevel1",0,found);
1534          if(TRK1)cout << "Tracker      : set branch address TrkLevel1"<<endl;          if(TRK1)cout << "Tracker      : set branch address TrkLevel1"<<endl;
1535          if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));          if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
1536          else    T->SetBranchStatus("TrkHough",0,found);  //      else    T->SetBranchStatus("TrkHough",0,found);
1537          if(TRKh)cout << "Tracker      : set branch address TrkHough"<<endl;          if(TRKh)cout << "Tracker      : set branch address TrkHough"<<endl;
1538          if(!Trout)Trout=T;          if(!Trout)Trout=T;
1539          else Trout->AddFriend("Tracker");          else Trout->AddFriend("Tracker");
1540      }else{      }else{
1541          cout << "Tracker      : missing tree"<<endl;          cout << "Tracker      : missing tree"<<endl;
1542      };      };
1543      // Calorimeter      // Calorimeter
1544      if(C && (CAL2||CAL1)) {      if(C && (CAL2||CAL1)) {
1545          if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));          if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
1546          else    C->SetBranchStatus("CaloLevel2",0,found);  //      else    C->SetBranchStatus("CaloLevel2",0,found);
1547          if(CAL2)cout << "Calorimeter  : set branch address CaloLevel2"<<endl;          if(CAL2)cout << "Calorimeter  : set branch address CaloLevel2"<<endl;
1548          if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));          if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
1549          else    C->SetBranchStatus("CaloLevel1",0,found);  //      else    C->SetBranchStatus("CaloLevel1",0,found);
1550          if(CAL1)cout << "Calorimeter  : set branch address CaloLevel1"<<endl;          if(CAL1)cout << "Calorimeter  : set branch address CaloLevel1"<<endl;
1551          if(!Trout)Trout=C;          if(!Trout)Trout=C;
1552          else Trout->AddFriend("Calorimeter");          else Trout->AddFriend("Calorimeter");
# Line 1150  TChain *PamLevel2::GetPamTree(TList *fl, Line 1607  TChain *PamLevel2::GetPamTree(TList *fl,
1607      }else{      }else{
1608          cout << "OrbitalInfo  : missing tree"<<endl;          cout << "OrbitalInfo  : missing tree"<<endl;
1609      };      };
1610        cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
1611    
1612        // Selection List
1613        if(L && SELLI==1) {
1614            cout<<">>> Found selection-list <<<"<<endl;
1615            L->SetBranchAddress("RunEntry",&irun);
1616            cout << "SelectionList: set branch address RunEntry"<<endl;
1617            L->SetBranchAddress("EventEntry",&irunentry);
1618            cout << "SelectionList: set branch address EventEntry"<<endl;
1619            sel_tree = L;
1620    //      if(!Trout)Trout=O;
1621    //      else Trout->AddFriend("SelectionList");
1622            cout << "----------------------------------------------------" <<endl;
1623        }else{
1624    //      cout << "SelectionList  : missing tree"<<endl;
1625            if(L)L->Delete();
1626        };
1627            
1628  //    cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;  //    cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;
1629    
1630            pam_tree = Trout;
1631  //     // Tracker  
 //     if(TRK2||TRK1||TRKh){  
 //      if(!Tout)Tout=T;  
 //      else Tout->AddFriend("Tracker");  
 //     }  
 //     // Calorimeter  
 //     if(CAL2||CAL1) {          
 //      if(!Tout)Tout=C;  
 //      else Tout->AddFriend("Calorimeter");  
 //     };  
 //     // ToF      
 //     if(TOF) {  
 //      if(!Tout)Tout=O;  
 //      else Tout->AddFriend("ToF");  
 //     };  
 //     // Trigger  
 //     if(TRG) {  
 //      if(!Tout)Tout=R;  
 //      else Tout->AddFriend("Trigger");  
 //     };  
 //     // S4  
 //     if(S4) {  
 //      if(!Tout)Tout=S;  
 //      else Tout->AddFriend("S4");  
 //     };  
 //     // Neutron Detector  
 //     if(ND) {  
 //      if(!Tout)Tout=N;  
 //      else Tout->AddFriend("NeutronD");  
 //     };  
 //     // Anticounters  
 //     if(AC) {  
 //      if(!Tout)Tout=A;  
 //      else Tout->AddFriend("Anticounter");  
 //     };  
 //     // OrbitalInfo  
 //     if(ORB) {  
 //      if(!Tout)Tout=B;  
 //      else Tout->AddFriend("OrbitalInfo");  
 //     };  
       
 //    cout<<endl<<" Number of entries: "<<Tout->GetEntries()<<endl<<endl;  
       
 //    if( Tout->GetEntries() )PamLevel2::SetBranchAddress( Tout );  
       
1632      return Trout;      return Trout;
1633  }  }
1634    
# Line 1280  void PamLevel2::SetBranchAddress(TTree * Line 1710  void PamLevel2::SetBranchAddress(TTree *
1710          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
1711          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;
1712      };      };
1713        // SelectionList
1714        if(SELLI==1) {
1715            t->SetBranchAddress("RunEntry", &irun);
1716            cout << "SelectionList: set branch address RunEntry"<<endl;
1717            t->SetBranchAddress("EventEntry", &irunentry);
1718            cout << "SelectionList: set branch address EventEntry"<<endl;
1719        };
1720            
1721  }  }
1722  /**  /**
# Line 1353  void PamLevel2::SetBranchAddress(TChain Line 1790  void PamLevel2::SetBranchAddress(TChain
1790          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
1791          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;
1792      };      };
1793        // SelectionList
1794        if(SELLI==1) {
1795            t->SetBranchAddress("RunEntry", &irun);
1796            cout << "SelectionList: set branch address RunEntry"<<endl;
1797            t->SetBranchAddress("EventEntry", &irunentry);
1798            cout << "SelectionList: set branch address EventEntry"<<endl;
1799        };
1800            
1801  }  }
1802    
# Line 1367  void PamLevel2::SetBranchAddress(TChain Line 1811  void PamLevel2::SetBranchAddress(TChain
1811   * @return Pointer to a TChain   * @return Pointer to a TChain
1812   */   */
1813  TChain *PamLevel2::GetRunTree(TList *fl){  TChain *PamLevel2::GetRunTree(TList *fl){
1814              //
1815      TChain *R = new TChain("Run");    //
1816      //
1817      if ( run_tree ){
1818        printf("WARNING: TChain *PamLevel2::GetRunTree(TList *fl) -- run_tree already exists!\n ");
1819        return run_tree;
1820      };    
1821      //
1822      TChain *R = new TChain("Run");
1823            
1824      // loop over files and create chains              // loop over files and create chains        
1825      TIter next(fl);      TIter next(fl);
# Line 1380  TChain *PamLevel2::GetRunTree(TList *fl) Line 1831  TChain *PamLevel2::GetRunTree(TList *fl)
1831              R->Add(name);              R->Add(name);
1832          };          };
1833      }      }
1834    
1835        if(R->GetNtrees()){
1836            
1837      R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));          R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
1838      cout << "Run         : set branch address RunInfo"<<endl;          cout << "Run         : set branch address RunInfo"<<endl;
1839      R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano          R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
1840      cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano          cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano
1841            }else{
1842            delete R;
1843            R=0;
1844        }
1845    
1846        run_tree = R;
1847    
1848      return R;      return R;
1849            
1850  }  }
# Line 1399  TChain *PamLevel2::GetRunTree(TList *fl) Line 1858  TChain *PamLevel2::GetRunTree(TList *fl)
1858   * @return Pointer to a TTree   * @return Pointer to a TTree
1859   */   */
1860  TTree *PamLevel2::GetRunTree(TFile *f){  TTree *PamLevel2::GetRunTree(TFile *f){
1861      if ( run_tree ){
1862        printf("WARNING: TTree *PamLevel2::GetRunTree(TFile *f) -- run_tree already exists!\n ");
1863        return run_tree;
1864      };
1865            
1866    
1867        cout << "TTree *PamLevel2::GetRunTree(TFile *f) -- obsolte "<<endl;
1868    
1869      TTree *R = (TTree*)f->Get("Run");      TTree *T = (TTree*)f->Get("Run");
       
     R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));  
     cout << "Run         : set branch address RunInfo"<<endl;  
     R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano  
     cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano  
1870            
1871      return R;      if(T){
1872            T->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
1873            cout << "Run         : set branch address RunInfo"<<endl;
1874            T->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
1875            cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano
1876        }
1877    
1878        run_tree = (TChain*)T;
1879    
1880        return T;
1881            
1882  }  }
1883    /**
1884     * Update the runinfo informations (to be used to have Run infos event by event basis)
1885     * @param run Pointer to the chain/tree which contains run infos
1886     * @return true if a new run has been read, false if it is still the same run
1887     */
1888    Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev){
1889      //
1890      // check if we have already called once GetEntry, if not call it
1891      //
1892        cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev) --- NON FUNZIONA BENISSIMO.... "<<endl;
1893        if(!run){
1894              cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing RunInfo tree "<<endl;
1895              return(false);        
1896        }
1897        if ( run->GetEntries() <= 0 ) return(false);
1898      //
1899      
1900      //  Int_t oldrun = irun;
1901      Long64_t oldrun = irun;
1902    
1903      // --------------------------------------
1904      // if it is a full file (not preselected)
1905      // --------------------------------------
1906      if(SELLI==0){
1907    
1908          //
1909          // the absolute time is necessary to relate the event with the run
1910          //
1911          if( !GetOrbitalInfo() && !ISGP){
1912              cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;
1913              return(false);
1914          }
1915    
1916          ULong64_t abstime = 0;
1917          if( GetOrbitalInfo() )abstime=GetOrbitalInfo()->absTime;
1918    
1919    
1920          //
1921          // the first time the routine is called, set run search from the beginning
1922          //
1923          if ( irun < 0LL ){
1924              irun = 0LL;
1925              run->GetEntry(irun);
1926              runfirstentry = 0LL;
1927              runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
1928              if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;
1929              
1930              if( ISGP && run->GetEntries()!=1 ){
1931                  cout << "** WARNING ** simulated files are assumed to have 1 single run, not "<< run->GetEntries() << endl;
1932                  cout << "** WARNING ** run will not be updated"<<endl;
1933              }
1934    
1935          };      
1936          //
1937          if(ISGP)abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO
1938          //
1939          if ( irun == run->GetEntries()-1LL &&
1940               !(abstime >= GetRunInfo()->RUNHEADER_TIME &&
1941                 abstime <= GetRunInfo()->RUNTRAILER_TIME)
1942                ){
1943             irun = -1LL;
1944             runfirstentry = 0LL;
1945             runlastentry = -1LL;
1946           };
1947          // modificato il controllo sull'aggiornamento del run, per evitare problemi
1948          // dovuti agli eventi annidati (NB! NEVENTS conta anche questi!!)
1949          //
1950          bool fromfirst = true;
1951          //
1952          while ( !(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME) && irun < run->GetEntries()-1LL ){
1953    //      while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){
1954              irun++;
1955              run->GetEntry(irun);
1956              runfirstentry = runlastentry;
1957              if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runfirstentry += 1LL;
1958              runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
1959    //        cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
1960    //        cout << "runfirstentry "<<runfirstentry<<endl;
1961              //      printf(" iev %llu %u %llu \n",iev,this->GetRunInfo()->NEVENTS,(ULong64_t)(runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS)));
1962              //      printf(" abstime %u trailertime %u \n",abstime,GetRunInfo()->RUNTRAILER_TIME);
1963              //      printf(" IDRUN %u \n",GetRunInfo()->ID);
1964              //
1965    //        prevshift = 0;
1966              //
1967              if ( irun == (Long64_t)(run->GetEntries()-1LL) && fromfirst && !(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME)){
1968                  printf(" resetting irun  (it should NOT happen!!!)\n");
1969                  fromfirst = false;
1970                  irun = 0;
1971                  run->GetEntry(irun);
1972                  runfirstentry = 0ULL;
1973                  runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
1974                  if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;
1975              };
1976              //
1977          };
1978          //
1979          if (
1980               !(abstime >= GetRunInfo()->RUNHEADER_TIME &&
1981                 abstime <= GetRunInfo()->RUNTRAILER_TIME)
1982              ) {
1983              printf(" Something very wrong here: cannot find RUN containing absolute time %u \n",abstime);
1984              return false;
1985          }
1986          //
1987          if ( irun == oldrun || irun >= run->GetEntries() ) return(false);
1988          //
1989          //  printf(" iev %llu irun %i nevents %u 1st %llu last %llu \n",iev,irun,this->GetRunInfo()->NEVENTS,(ULong64_t)runfirstentry,(ULong64_t)runlastentry);
1990          //
1991          prevshift = 0;
1992          cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
1993    //      cout << "runfirstentry "<<runfirstentry<<endl;
1994          return(true);    
1995      };
1996      // ----------------------------------------------------
1997      // if it is a preselected file (there is SelectionList)
1998      // NBNB - the event tree MUST be read first
1999      // ----------------------------------------------------
2000      if(SELLI==1){      
2001          sel_tree->GetEntry(iev);
2002    //      cout << irun << " "<< irunentry << endl;
2003          if(irun != oldrun){
2004              run->GetEntry(irun);
2005              cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2006              prevshift = 0;
2007              return true;
2008          }
2009          return false;
2010      }
2011    
2012      return false;
2013      //
2014    };
2015    
2016    Bool_t PamLevel2::UpdateRunInfo(Long64_t iev){
2017    
2018        if(!run_tree){
2019            cout << " Bool_t PamLevel2::UpdateRunInfo(ULong64_t iev) -- ERROR -- run tree not loaded"<<endl;
2020            return false;
2021        }
2022        if ( run_tree->GetEntries() <= 0 ) {
2023            cout << " Bool_t PamLevel2::UpdateRunInfo(ULong64_t iev) -- ERROR -- run tree is empty"<<endl;
2024            return(false);
2025        }
2026      
2027        Int_t oldrun = irun; // store current run index
2028    
2029        // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2030        // if it is a full file (not preselected)
2031        // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2032        if(SELLI==0){
2033    
2034            ULong64_t abstime = 0;
2035            ULong64_t obt     = 0;
2036            if( GetOrbitalInfo() ){
2037                abstime = GetOrbitalInfo()->absTime;
2038                obt     = GetOrbitalInfo()->OBT;
2039            }
2040            // ---------------------------------------------------------------
2041            // the absolute time is necessary to relate the event with the run
2042            // ---------------------------------------------------------------
2043            if( !GetOrbitalInfo() && !ISGP ){
2044                cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;
2045                return(false);
2046            }
2047          
2048            // -----------------------------------------------------------------------
2049            // the first time the routine is called, set run search from the beginning
2050            // -----------------------------------------------------------------------
2051            if ( irun < 0 ){
2052                irun = 0LL;
2053                irunentry = 0;
2054                prevshift = 0;
2055                run_tree->GetEntry(irun);
2056    
2057                if( ISGP && run_tree->GetEntries()!=1 ){
2058                    cout << "** WARNING ** simulated files are assumed to have 1 single run, not "<< run_tree->GetEntries() << endl;
2059                    cout << "** WARNING ** run will not be updated"<<endl;
2060                }
2061            };      
2062    
2063            // -----------------------------------------------------------------------
2064            // if it is simulation, assigh abstime by end (temporaneo!!!)
2065            // -----------------------------------------------------------------------
2066            if(ISGP){
2067                abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO
2068                obt     = GetRunInfo()->RUNHEADER_OBT; // BARBATRUCCO
2069            }
2070            //
2071            bool fromfirst = true; // first loop over runs
2072    
2073    //      Bool_t hasfrag = false;
2074    //      if( GetRunInfo()->ID_RUN_FRAG!=0 && GetRunInfo()->ID_RUN_FRAG != GetRunInfo()->ID)hasfrag=true;
2075    //      ULong64_t fragid = GetRunInfo()->ID_RUN_FRAG;
2076    
2077            // ------------------------------------------------------
2078            // loop over runs to find the one that contains the event
2079            // ------------------------------------------------------
2080            while (
2081                (
2082                    (
2083                        !(abstime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s)
2084                          abstime <= GetRunInfo()->RUNTRAILER_TIME) &&
2085                        !(obt >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms)
2086                          obt <= GetRunInfo()->RUNTRAILER_OBT)
2087                        )
2088                    || GetRunInfo()->NEVENTS==0
2089                    || !(irunentry < GetRunInfo()->NEVENTS-1-prevshift)
2090                    )
2091                    && irun < run_tree->GetEntries() ){
2092    
2093                irun++;
2094                // ------------------------------------
2095                // if the end of run tree is reached...
2096                // ------------------------------------
2097                if( irun == run_tree->GetEntries() ){
2098                    if(!fromfirst){
2099                        // -----------------------------------------------------
2100                        // if it happened already once and the run was not found
2101                        // ---> exit with error
2102                        // -----------------------------------------------------
2103                        cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- ERROR -- event entry #"<<iev<<" does not belong to any run (should not happen)" <<endl;
2104                        return false;
2105                    }
2106                    // -----------------------------------------
2107                    // ...otherwise repeat search from beginning
2108                    // -----------------------------------------
2109                    cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- reached end of run tree. searchin again from beginning " <<endl;
2110                    fromfirst = false;
2111                    irun = 0LL;
2112                    runfirstentry = 0LL;
2113                }
2114                // -------------------------------------------------------------------
2115                // save the index of the first entry of the run, relative to pam_tree,
2116                // and read a new run
2117                // -------------------------------------------------------------------
2118                if(irun>0)runfirstentry += (GetRunInfo()->NEVENTS)-prevshift;
2119                irunentry = 0;
2120                prevshift = 0;
2121                run_tree->GetEntry(irun);      
2122                if(GetRunInfo()->RUNHEADER_OBT>GetRunInfo()->RUNTRAILER_OBT ){
2123                    cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- irun "<<irun<<"  has RUNHEADER_OBT>=RUNTRAILER_OBT " <<endl;
2124                    cout << "                                                            (NB!! in this case some events are assigned to a wrong run)"<<endl;
2125                }
2126    //          if(hasfrag &&  fragid != GetRunInfo()->ID){
2127    //              cout << "... where is the next fragment ??"<<endl;
2128    //          }
2129            };
2130    
2131    
2132            // --------------------------------------
2133            // if there was no need to update the run
2134            // ---> exit with FALSE
2135            // --------------------------------------
2136            if ( irun == oldrun ) return(false);
2137    
2138            // --------------------------------------
2139            // ... otherwise
2140            // ---> exit with TRUE
2141            // --------------------------------------
2142            cout << endl << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2143            // ----------------------------------------------------
2144            // then check if the run has a fragment
2145            // in this case we have to switch to the next fragment
2146            // when the end of the first fragment is reached
2147            // ----------------------------------------------------
2148            if(
2149                GetRunInfo()->ID_RUN_FRAG != 0 &&
2150    //          GetRunInfo()->ID_RUN_FRAG != GetRunInfo()->ID &&
2151                true ){
2152                cout << "* fragment *"<<endl;              
2153            }
2154            
2155            return(true);    
2156        };
2157        // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2158        // if it is a preselected file (there is SelectionList)
2159        // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2160        if(SELLI==1){      
2161            sel_tree->GetEntry(iev);
2162            if(irun != oldrun){
2163                run_tree->GetEntry(irun);
2164                cout << endl << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2165                prevshift = 0;
2166                return true;
2167            }
2168            return false;
2169        }
2170    
2171        return false;
2172        //
2173    };
2174    /**
2175     * Update the runinfo informations (to be used to have Run infos event by event basis)
2176     * @param run Pointer to the chain/tree which contains run infos
2177     * @return true if a new run has been read, false if it is still the same run
2178     */
2179    Bool_t PamLevel2::UpdateRunInfo(TTree *run, Long64_t iev){
2180      return(UpdateRunInfo((TChain*)run,iev));
2181    };
2182    
2183  //--------------------------------------  //--------------------------------------
2184  //  //
2185  //  //
# Line 1422  TTree *PamLevel2::GetRunTree(TFile *f){ Line 2191  TTree *PamLevel2::GetRunTree(TFile *f){
2191  void PamLevel2::SetWhichTrees(TString detlist){  void PamLevel2::SetWhichTrees(TString detlist){
2192                    
2193      if(detlist.IsNull() || detlist.Contains("+ALL", TString::kIgnoreCase)){      if(detlist.IsNull() || detlist.Contains("+ALL", TString::kIgnoreCase)){
2194            CAL0 = false;
2195          CAL1 = true;          CAL1 = true;
2196          CAL2 = true;          CAL2 = true;
2197          TRK2 = true;          TRK2 = true;
2198          TRK1 = false;          TRK1 = false;
2199          TRKh = false;          TRKh = false;
2200            TRK0 = false;
2201          TRG = true;          TRG = true;
2202          TOF = true;          TOF = true;
2203            TOF0 = false;
2204          S4  = true;          S4  = true;
2205          ND  = true;          ND  = true;
2206          AC  = true;          AC  = true;
2207          ORB = true;          ORB = true;
2208      }else if( detlist.Contains("-ALL", TString::kIgnoreCase) ){      }else if( detlist.Contains("-ALL", TString::kIgnoreCase) ){
2209            CAL0 = false;
2210          CAL1 = false;          CAL1 = false;
2211          CAL2 = false;          CAL2 = false;
2212          TRK2 = false;          TRK2 = false;
2213          TRK1 = false;          TRK1 = false;
2214          TRKh = false;          TRKh = false;
2215            TRK0 = false;
2216          TRG = false;          TRG = false;
2217          TOF = false;          TOF = false;
2218            TOF0 = false;
2219          S4  = false;          S4  = false;
2220          ND  = false;          ND  = false;
2221          AC  = false;          AC  = false;
# Line 1452  void PamLevel2::SetWhichTrees(TString de Line 2227  void PamLevel2::SetWhichTrees(TString de
2227          if ( detlist.Contains("-CAL1", TString::kIgnoreCase) )CAL1=false;          if ( detlist.Contains("-CAL1", TString::kIgnoreCase) )CAL1=false;
2228          if ( detlist.Contains("+CAL1", TString::kIgnoreCase) )CAL1=true;          if ( detlist.Contains("+CAL1", TString::kIgnoreCase) )CAL1=true;
2229      };      };
2230    
2231        if( detlist.Contains("CAL0", TString::kIgnoreCase) ){
2232            if ( detlist.Contains("-CAL0", TString::kIgnoreCase) )CAL0=false;
2233            if ( detlist.Contains("+CAL0", TString::kIgnoreCase) )CAL0=true;
2234        };
2235                    
2236      if( detlist.Contains("CAL2", TString::kIgnoreCase)){      if( detlist.Contains("CAL2", TString::kIgnoreCase)){
2237          if ( detlist.Contains("-CAL2", TString::kIgnoreCase) )CAL2=false;          if ( detlist.Contains("-CAL2", TString::kIgnoreCase) )CAL2=false;
# Line 1464  void PamLevel2::SetWhichTrees(TString de Line 2244  void PamLevel2::SetWhichTrees(TString de
2244          CAL1=false;          CAL1=false;
2245      }      }
2246  //  -------------------------------------------------------------------------  //  -------------------------------------------------------------------------
2247        if( detlist.Contains("TRK0", TString::kIgnoreCase) ){
2248            if ( detlist.Contains("-TRK0", TString::kIgnoreCase) )TRK0=false;
2249            if ( detlist.Contains("+TRK0", TString::kIgnoreCase) )TRK0=true;
2250        };
2251    
2252      if( detlist.Contains("TRK1", TString::kIgnoreCase) ){      if( detlist.Contains("TRK1", TString::kIgnoreCase) ){
2253          if ( detlist.Contains("-TRK1", TString::kIgnoreCase) )TRK1=false;          if ( detlist.Contains("-TRK1", TString::kIgnoreCase) )TRK1=false;
2254          if ( detlist.Contains("+TRK1", TString::kIgnoreCase) )TRK1=true;          if ( detlist.Contains("+TRK1", TString::kIgnoreCase) )TRK1=true;
# Line 1492  void PamLevel2::SetWhichTrees(TString de Line 2277  void PamLevel2::SetWhichTrees(TString de
2277            
2278      if( detlist.Contains("-TOF", TString::kIgnoreCase) )TOF = false;      if( detlist.Contains("-TOF", TString::kIgnoreCase) )TOF = false;
2279      else if( detlist.Contains("+TOF", TString::kIgnoreCase) )TOF = true;      else if( detlist.Contains("+TOF", TString::kIgnoreCase) )TOF = true;
2280    
2281        if( detlist.Contains("-TOF0", TString::kIgnoreCase) )TOF0 = false;
2282        else if( detlist.Contains("+TOF0", TString::kIgnoreCase) )TOF0 = true;
2283            
2284      if( detlist.Contains("-S4",  TString::kIgnoreCase) )S4  = false;      if( detlist.Contains("-S4",  TString::kIgnoreCase) )S4  = false;
2285      else if( detlist.Contains("+S4",  TString::kIgnoreCase) )S4  = true;      else if( detlist.Contains("+S4",  TString::kIgnoreCase) )S4  = true;
# Line 1526  void PamLevel2::SetWhichTrees(TString de Line 2314  void PamLevel2::SetWhichTrees(TString de
2314   * Set tree/branch detector flags from the content of a tree   * Set tree/branch detector flags from the content of a tree
2315   */   */
2316  void  PamLevel2::GetWhichTrees(TFile* f){  void  PamLevel2::GetWhichTrees(TFile* f){
2317                
2318    
2319    
2320        cout << "void  PamLevel2::GetWhichTrees(TFile* f) --- WARNING!! --- ...potrebbe non funzionare "<<endl;
2321      // -----------      // -----------
2322      // reset flags      // reset flags
2323      // -----------      // -----------
# Line 1698  Bool_t  PamLevel2::CheckLevel2File(TStri Line 2489  Bool_t  PamLevel2::CheckLevel2File(TStri
2489            
2490      Bool_t RUN__ok    = false;      Bool_t RUN__ok    = false;
2491            
2492            Bool_t SELLI__ok  = false;
2493    
2494      cout << "Checking file: "<<name<<endl;      cout << "Checking file: "<<name<<endl;
2495      TFile *f = new TFile(name.Data());      TFile *f = new TFile(name.Data());
# Line 1715  Bool_t  PamLevel2::CheckLevel2File(TStri Line 2506  Bool_t  PamLevel2::CheckLevel2File(TStri
2506    
2507      while( (key = (TKey*)next()) ){      while( (key = (TKey*)next()) ){
2508                    
2509    //      cout << key->GetName() << endl;
2510  //      cout << key->GetName() << ""<<key->GetClassName()<<endl;  //      cout << key->GetName() << ""<<key->GetClassName()<<endl;
2511  //              cout << " Get tree: " << f->Get(key->GetName())<<endl;  //              cout << " Get tree: " << f->Get(key->GetName())<<endl;
2512  //      nev_previous = nev;  //      nev_previous = nev;
# Line 1725  Bool_t  PamLevel2::CheckLevel2File(TStri Line 2517  Bool_t  PamLevel2::CheckLevel2File(TStri
2517  //          return false;  //          return false;
2518  //      };  //      };
2519    
2520    
2521          if( !strcmp(key->GetName(),"Run"        ) )RUN__ok = true;                if( !strcmp(key->GetName(),"Run"        ) )RUN__ok = true;      
2522    
2523          //=========================================================              //=========================================================    
2524            if( !strcmp(key->GetName(),"SelectionList"    ) ){
2525                SELLI__ok = true;
2526                if(SELLI==1){
2527                    Int_t nevt = ((TTree*)f->Get("SelectionList"))->GetEntries();
2528                    if( nev && nevt!=nev){
2529                        cout << "File: "<< f->GetName() <<" discarded ---- SelectionList tree has "<<nevt<<" events instead of "<<nev<< endl;
2530                        return false;
2531                    }
2532                    nev=nevt;
2533                }
2534            }
2535    
2536            //=========================================================    
2537          if( !strcmp(key->GetName(),"Trigger"    ) ){          if( !strcmp(key->GetName(),"Trigger"    ) ){
2538              TRG__ok = true;              TRG__ok = true;
2539              if(TRG){              if(TRG){
# Line 1839  Bool_t  PamLevel2::CheckLevel2File(TStri Line 2645  Bool_t  PamLevel2::CheckLevel2File(TStri
2645          };                };      
2646    
2647      };      };
2648    
2649        if( SELLI==-1 )SELLI = (Int_t)SELLI__ok;
2650        if( SELLI==0 && SELLI__ok ){
2651            cout << "File: "<< f->GetName() <<" discarded ---- found SelectionList (it is not a full-event file)" << endl;
2652            return false;  
2653        }
2654        if( SELLI==1 && !SELLI__ok ){
2655            cout << "File: "<< f->GetName() <<" discarded ---- SelectionList missing" << endl;
2656            return false;
2657        }
2658            
2659    //    cout << "SELLI "<<SELLI<<endl;
2660    
2661  //     cout<< "CheckLevel2File(TString): detector list --> ";  //     cout<< "CheckLevel2File(TString): detector list --> ";
2662  //     if(TRK1__ok)cout<<"TRK1 ";  //     if(TRK1__ok)cout<<"TRK1 ";
2663  //     if(TRK2__ok)cout<<"TRK2 ";  //     if(TRK2__ok)cout<<"TRK2 ";
# Line 1948  void PamLevel2::CreateCloneTrees0( TChai Line 2766  void PamLevel2::CreateCloneTrees0( TChai
2766      cout << "Create clones of PAMELA trees "<<endl;      cout << "Create clones of PAMELA trees "<<endl;
2767            
2768      Int_t i=0;      Int_t i=0;
2769      tree_clone[i] = fChain->GetTree()->CloneTree(0);      pam_tree_clone[i] = fChain->GetTree()->CloneTree(0);
2770      TString name =  tree_clone[i]->GetName();      TString name =  pam_tree_clone[i]->GetName();
2771      name.Append("_clone");      name.Append("_clone");
2772  //    tree_clone[i]->SetName(name.Data());  //    pam_tree_clone[i]->SetName(name.Data());
2773      cout << tree_clone[i]->GetName() <<endl;      cout << pam_tree_clone[i]->GetName() <<endl;
2774      i++;      i++;
2775    
2776      TList *li = fChain->GetListOfFriends();      TList *li = fChain->GetListOfFriends();
# Line 1962  void PamLevel2::CreateCloneTrees0( TChai Line 2780  void PamLevel2::CreateCloneTrees0( TChai
2780      while( (T_friend = (TFriendElement*)next()) ){      while( (T_friend = (TFriendElement*)next()) ){
2781  //      cout<<T_friend->IsA()->GetName()<<" "<<T_friend->GetName()<<hex << T_friend->GetTree() << dec<<endl;  //      cout<<T_friend->IsA()->GetName()<<" "<<T_friend->GetName()<<hex << T_friend->GetTree() << dec<<endl;
2782  //      cout<<T_friend->GetTree()->GetName()<< endl;  //      cout<<T_friend->GetTree()->GetName()<< endl;
2783          tree_clone[i] = T_friend->GetTree()->CloneTree(0);          pam_tree_clone[i] = T_friend->GetTree()->CloneTree(0);
2784          tree_clone[i]->SetAutoSave(1000000);          pam_tree_clone[i]->SetAutoSave(1000000);
2785          name =  tree_clone[i]->GetName();          name =  pam_tree_clone[i]->GetName();
2786          name.Append("_clone");          name.Append("_clone");
2787  //      tree_clone[i]->SetName(name.Data());  //      pam_tree_clone[i]->SetName(name.Data());
2788          cout << tree_clone[i]->GetName() << endl;          cout << pam_tree_clone[i]->GetName() << endl;
2789          i++;          i++;
2790      }      }
2791            
# Line 1982  void PamLevel2::CreateCloneTrees0( TChai Line 2800  void PamLevel2::CreateCloneTrees0( TChai
2800   */   */
2801  void PamLevel2::CreateCloneTrees(TFile *ofile){  void PamLevel2::CreateCloneTrees(TFile *ofile){
2802    
2803    
2804    //  if the pointer is null, create a default file
2805    
2806        if(!ofile){
2807            cout << "void PamLevel2::CreateCloneTrees(TFile*) -- WARNING -- Creating file: clone-tree.root "<<endl;
2808            ofile = new TFile("clone-tree.root","recreate");
2809        }
2810    
2811      ofile->cd();      ofile->cd();
2812    
2813      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2814      cout << "Create new PAMELA trees "<<endl;      cout << "Create new PAMELA trees "<<endl;
2815                    
     Int_t i=0;  
2816    
2817        run_tree_clone = new TTree("Run","PAMELA Level2 data from the GL_RUN table ");
2818        run_tree_clone->Branch("RunInfo","GL_RUN",GetPointerTo("RunInfo"));
2819        cout << "Run          : branch RunInfo"<<endl;
2820        run_tree_clone->Branch("SoftInfo","SoftInfo",GetPointerTo("SoftInfo"));
2821        cout << "Run          : branch SoftInfo"<<endl;
2822        // ------------------
2823        // replicate run tree
2824        // ------------------
2825        cout << "----------------------------------------------------"<<endl;
2826        cout << "irun\t | RUN\t NEVENTS\t absolute time"<<endl;
2827        for (Int_t i=0; i<run_tree->GetEntries(); i++){
2828            run_tree->GetEntry(i);
2829            cout << i<< "\t | "<<GetRunInfo()->ID<<"\t "<<GetRunInfo()->NEVENTS<< "\t "<<GetRunInfo()->RUNHEADER_TIME<<" <---> "<<GetRunInfo()->RUNTRAILER_TIME<<endl;
2830            run_tree_clone->Fill();
2831        }
2832        cout << "----------------------------------------------------"<<endl;
2833    
2834    
2835        sel_tree_clone = new TTree("SelectionList","List of selected events ");
2836        sel_tree_clone->Branch("RunEntry",&irun,"runentry/L");
2837        sel_tree_clone->Branch("EventEntry",&irunentry,"eventry/L");
2838        
2839    
2840        Int_t i=0;
2841      if(TRK1||TRK2||TRKh){      if(TRK1||TRK2||TRKh){
2842          tree_clone[i] = new TTree("Tracker","PAMELA tracker level2 data ");              pam_tree_clone[i] = new TTree("Tracker","PAMELA tracker level2 data ");
2843          if(TRK1) {          if(TRK1) {
2844              tree_clone[i]->Branch("TrkLevel1","TrkLevel1", GetPointerTo("TrkLevel1"));              pam_tree_clone[i]->Branch("TrkLevel1","TrkLevel1", GetPointerTo("TrkLevel1"));
2845              tree_clone[i]->BranchRef();              pam_tree_clone[i]->BranchRef();
2846              cout << "Tracker      : branch TrkLevel1"<<endl;              cout << "Tracker      : branch TrkLevel1"<<endl;
2847    //          cout << "CreateCloneTrees " << GetTrkLevel1()<<endl;
2848          };          };
2849          if(TRK2) {          if(TRK2) {
2850              tree_clone[i]->Branch("TrkLevel2", "TrkLevel2",GetPointerTo("TrkLevel2"));              pam_tree_clone[i]->Branch("TrkLevel2", "TrkLevel2",GetPointerTo("TrkLevel2"));
2851              cout << "Tracker      : branch TrkLevel2"<<endl;                      cout << "Tracker      : branch TrkLevel2"<<endl;        
2852          };          };
2853          if(TRKh) {          if(TRKh) {
2854              tree_clone[i]->Branch("TrkHough","TrkHough", GetPointerTo("TrkHough"));              pam_tree_clone[i]->Branch("TrkHough","TrkHough", GetPointerTo("TrkHough"));
2855              cout << "Tracker      : branch TrkHough"<<endl;              cout << "Tracker      : branch TrkHough"<<endl;
2856          };          };
2857          i++;          i++;
# Line 2009  void PamLevel2::CreateCloneTrees(TFile * Line 2859  void PamLevel2::CreateCloneTrees(TFile *
2859    
2860      // Calorimeter      // Calorimeter
2861      if(CAL1||CAL2){      if(CAL1||CAL2){
2862          tree_clone[i] = new TTree("Calorimeter","PAMELA calorimeter level2 data ");              pam_tree_clone[i] = new TTree("Calorimeter","PAMELA calorimeter level2 data ");
2863          if(CAL1) {          if(CAL1) {
2864              tree_clone[i]->Branch("CaloLevel1", "CaloLevel1", GetPointerTo("CaloLevel1"));              pam_tree_clone[i]->Branch("CaloLevel1", "CaloLevel1", GetPointerTo("CaloLevel1"));
2865              cout << "Calorimeter  : branch CaloLevel1"<<endl;              cout << "Calorimeter  : branch CaloLevel1"<<endl;
2866          };          };
2867          if(CAL2) {          if(CAL2) {
2868              tree_clone[i]->Branch("CaloLevel2","CaloLevel2", GetPointerTo("CaloLevel2"));              pam_tree_clone[i]->Branch("CaloLevel2","CaloLevel2", GetPointerTo("CaloLevel2"));
2869              cout << "Calorimeter  : branch CaloLevel2"<<endl;              cout << "Calorimeter  : branch CaloLevel2"<<endl;
2870          };          };
2871          i++;          i++;
# Line 2023  void PamLevel2::CreateCloneTrees(TFile * Line 2873  void PamLevel2::CreateCloneTrees(TFile *
2873    
2874      // ToF          // ToF    
2875      if(TOF) {      if(TOF) {
2876          tree_clone[i] = new TTree("ToF","PAMELA ToF level2 data ");              pam_tree_clone[i] = new TTree("ToF","PAMELA ToF level2 data ");
2877          tree_clone[i]->Branch("ToFLevel2","ToFLevel2", GetPointerTo("ToFLevel2"));          pam_tree_clone[i]->Branch("ToFLevel2","ToFLevel2", GetPointerTo("ToFLevel2"));
2878          cout << "ToF          : branch ToFLevel2"<<endl;          cout << "ToF          : branch ToFLevel2"<<endl;
2879          i++;          i++;
2880      };      };
2881      // Trigger      // Trigger
2882      if(TRG) {      if(TRG) {
2883          tree_clone[i] = new TTree("Trigger","PAMELA trigger level2 data ");              pam_tree_clone[i] = new TTree("Trigger","PAMELA trigger level2 data ");
2884          tree_clone[i]->Branch("TrigLevel2","TrigLevel2", GetPointerTo("TrigLevel2"));          pam_tree_clone[i]->Branch("TrigLevel2","TrigLevel2", GetPointerTo("TrigLevel2"));
2885          cout << "Trigger      : branch TrigLevel2"<<endl;          cout << "Trigger      : branch TrigLevel2"<<endl;
2886          i++;          i++;
2887      };      };
2888      // S4      // S4
2889      if(S4) {      if(S4) {
2890          tree_clone[i] = new TTree("S4","PAMELA S4 level2 data ");                pam_tree_clone[i] = new TTree("S4","PAMELA S4 level2 data ");  
2891          tree_clone[i]->Branch("S4Level2","S4Level2", GetPointerTo("S4Level2"));          pam_tree_clone[i]->Branch("S4Level2","S4Level2", GetPointerTo("S4Level2"));
2892          cout << "S4           : branch S4Level2"<<endl;          cout << "S4           : branch S4Level2"<<endl;
2893          i++;          i++;
2894      };      };
2895      // Neutron Detector      // Neutron Detector
2896      if(ND) {      if(ND) {
2897          tree_clone[i] = new TTree("NeutronD","PAMELA neutron detector level2 data ");            pam_tree_clone[i] = new TTree("NeutronD","PAMELA neutron detector level2 data ");      
2898          tree_clone[i]->Branch("NDLevel2","NDLevel2", GetPointerTo("NDLevel2"));          pam_tree_clone[i]->Branch("NDLevel2","NDLevel2", GetPointerTo("NDLevel2"));
2899          cout << "NeutronD     : branch NDLevel2"<<endl;          cout << "NeutronD     : branch NDLevel2"<<endl;
2900          i++;          i++;
2901      };      };
2902      // Anticounters      // Anticounters
2903      if(AC) {      if(AC) {
2904          tree_clone[i] = new TTree("Anticounter","PAMELA anticounter detector level2 data ");              pam_tree_clone[i] = new TTree("Anticounter","PAMELA anticounter detector level2 data ");        
2905          tree_clone[i]->Branch("AcLevel2","AcLevel2", GetPointerTo("AcLevel2"));          pam_tree_clone[i]->Branch("AcLevel2","AcLevel2", GetPointerTo("AcLevel2"));
2906          cout << "Anticounter  : branch AcLevel2"<<endl;          cout << "Anticounter  : branch AcLevel2"<<endl;
2907          i++;          i++;
2908      };      };
2909      // OrbitalInfo      // OrbitalInfo
2910      if(ORB) {      if(ORB) {
2911          tree_clone[i] = new TTree("OrbitalInfo","PAMELA oribital info  ");                pam_tree_clone[i] = new TTree("OrbitalInfo","PAMELA oribital info  ");  
2912          tree_clone[i]->Branch("OrbitalInfo","OrbitalInfo", GetPointerTo("OrbitalInfo"));          pam_tree_clone[i]->Branch("OrbitalInfo","OrbitalInfo", GetPointerTo("OrbitalInfo"));
2913          cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;          cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;
2914          i++;          i++;
2915      };      };
# Line 2074  void PamLevel2::CreateCloneTrees(TFile * Line 2924  void PamLevel2::CreateCloneTrees(TFile *
2924   */   */
2925  //void PamLevel2::FillNewPamTree(TTree *T){  //void PamLevel2::FillNewPamTree(TTree *T){
2926  void PamLevel2::FillCloneTrees(){  void PamLevel2::FillCloneTrees(){
2927                
2928      for(Int_t i=0; i<8; i++){  //    cout << "PamLevel2::FillCloneTrees()" << irunentry << endl;
2929          if(tree_clone[i])tree_clone[i]->Fill();  
2930        for(Int_t i=0; i<NCLONES; i++){
2931            if(pam_tree_clone[i])pam_tree_clone[i]->Fill();
2932      }      }
2933        if(sel_tree_clone)sel_tree_clone->Fill();    
2934    
2935  }  }
2936    
2937    
2938  TTree* PamLevel2::GetCloneTree(TString name){  TTree* PamLevel2::GetCloneTree(TString name){
2939    
2940      for(Int_t i=0; i<8; i++){        for(Int_t i=0; i<NCLONES; i++){    
2941          if(tree_clone[i]){          if(pam_tree_clone[i]){
2942              TString na = tree_clone[i]->GetName();              TString na = pam_tree_clone[i]->GetName();
2943              if(!name.CompareTo(na))return tree_clone[i];              if(!name.CompareTo(na))return pam_tree_clone[i];
2944          };          };
2945      }      }
2946        if(run_tree_clone){
2947            TString na = run_tree_clone->GetName();
2948            if(!name.CompareTo(na))return run_tree_clone;
2949        }
2950        if(sel_tree_clone){
2951            TString na = sel_tree_clone->GetName();
2952            if(!name.CompareTo(na))return sel_tree_clone;
2953        }
2954      return NULL;      return NULL;
2955    
2956  }  }
2957  void PamLevel2::WriteCloneTrees(){  void PamLevel2::WriteCloneTrees(){
2958      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2959      cout << "Write clones of PAMELA trees "<<endl;      cout << "Write clones of PAMELA trees "<<endl;
2960      for(Int_t i=0; i<8; i++){        cout << run_tree_clone->GetName()<<endl;    
2961          if(tree_clone[i]){      run_tree_clone->Write();
2962              cout << tree_clone[i]->GetName()<<endl;      cout << sel_tree_clone->GetName()<<endl;    
2963              tree_clone[i]->Write();      sel_tree_clone->Write();
2964        for(Int_t i=0; i<NCLONES; i++){    
2965            if(pam_tree_clone[i]){
2966                cout << pam_tree_clone[i]->GetName()<<endl;
2967                pam_tree_clone[i]->Write();
2968          };          };
2969      }      }
2970      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
# Line 2106  void PamLevel2::WriteCloneTrees(){ Line 2972  void PamLevel2::WriteCloneTrees(){
2972  }  }
2973    
2974  /**  /**
2975   * Create a new (empty) Pamela trees   * Method to get level2-trees entry, the corresponding run entry and (if required) the level0 entry.
2976   */   */
2977  // TTree* PamLevel2::GetNewPamTree(){  //Int_t PamLevel2::GetEntry(Int_t iee){
2978    Int_t PamLevel2::GetEntry(Long64_t iee){
2979        
2980    //     cout << "-------------------------------------"<<endl;
2981    //     cout << "Int_t PamLevel2::GetEntry("<<iee<<")"<<endl;
2982    
2983  //     if(tree_clone)return tree_clone;      if(!pam_tree){
2984            cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- level2 trees not loaded"<<endl;
2985            return 0;
2986        }
2987    
2988  //     TTree *Tout = 0;  
2989            //
2990  //     cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      // This is a sort of bug: if you don't have the run tree you don't want to exit here you want to have loaded the event anyway...
2991  //     cout << "Create new PAMELA trees "<<endl;      //
2992        //    if(!run_tree ){
2993        //  cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- run tree not loeaded"<<endl;
2994        //  return 0;
2995        //    }
2996    
2997        Long64_t ii=0;
2998        //-------------------------------
2999        ii = iee;
3000        if( !pam_tree->GetEntry(ii) ){      
3001            cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- error reading pam tree"<<endl;
3002            return 0;
3003        }
3004        //
3005        // ... that's way I put it here. Notice that nothing change in the code (is backward compatible) since in any case you return with 0.
3006        // in theory one would like to return 1 if run is not loaded but now I don't have the will to add that 2 lines of code and it is not
3007        // a problem if you don't check the return code of getentry.
3008        //
3009        if(!run_tree ){
3010            if ( TRK0 || CAL0 || TOF0 || RUN ) { //forse cosi` va bene per tornare 1?
3011                cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- run tree not loaded"<<endl;
3012                return 0;
3013            }  else {
3014                return 1; //cosi` se non c'e` run esce qua...
3015            }
3016        }
3017    
3018        //-------------------------------
3019        ii = iee;
3020    //    Bool_t UPDATED = UpdateRunInfo(run_tree,ii);
3021    //    Bool_t UPDATED = UpdateRunInfo(ii);
3022        UpdateRunInfo(ii);
3023        if(SELLI==0)irunentry = iee-runfirstentry;
3024    //    if(UPDATED && run_tree_clone)run_tree_clone->Fill();
3025      
3026    //    cout << "PamLevel2::GetEntry("<<iee<<") "<<irun<<" "<<runfirstentry<<" "<<irunentry<<endl;
3027    
3028    //     cout << "irunentry     "<<irunentry << endl;
3029    //     cout << "runfirstentry "<<runfirstentry << endl;
3030    //     cout << "nevents       "<<GetRunInfo()->NEVENTS<< endl;
3031    
3032    //     if( TRK0 || CAL0 || TOF0 ){
3033    //      if( !GetYodaEntry( ) ){
3034    //          cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- error reading level0 tree"<<endl;
3035    //          return 0;
3036    //      }
3037    //     }
3038    
3039    
3040        return 1;
3041    
3042    }
3043    
3044    TrkLevel0    *PamLevel2::GetTrkLevel0(){
3045        if( !TRK0 )return NULL;
3046        if( !GetYodaEntry( ) ){
3047            cout << " Int_t PamLevel2::GetTrkLevel0() -- ERROR -- error reading level0 tree"<<endl;
3048            return 0;
3049        }
3050        return trk0_obj;
3051    };
3052    CaloLevel0    *PamLevel2::GetCaloLevel0(){
3053        if( !CAL0 )return NULL;
3054        if( !GetYodaEntry( ) ){
3055            cout << " Int_t PamLevel2::GetCaloLevel0() -- ERROR -- error reading level0 tree"<<endl;
3056            return 0;
3057        }
3058        return calo0_obj;
3059    };
3060    
3061    
3062    /**
3063     * Method to retrieve the level0 tree (YODA tree) that contains the current event.
3064     * Given the run ID (...), if needed it query the DB and load the proper file.
3065     * @return Pointer to the tree
3066     */
3067    
3068    
3069    TTree* PamLevel2::GetYodaTree( ){
3070        
3071    //    cout << "TTree* PamLevel2::GetYodaTree( )"<<endl;
3072        //===================================
3073        // check if iroot has changed
3074        //===================================
3075        if( irun<0 ){
3076            cout << "PamLevel2::GetYodaTree() -- ERROR -- irun = "<<irun<<endl;
3077    //      cout << "In order to use this method you have to first load the RunInfo tree "<<endl;
3078            return NULL;
3079        }    
3080        Int_t irootnew = run_obj->ID_ROOT_L0;
3081    //      cout << "iroot    "<<iroot<<endl;
3082    //      cout << "irootnew "<<irootnew<<endl;
3083    
3084        //===================================
3085        // load the level0 file
3086        // (if not already loaded)
3087        //===================================
3088        if( iroot != irootnew || !l0_tree){
3089            iroot = irootnew;
3090            //===================================
3091            // open the DB connection
3092            // (if not already opened)
3093            //===================================
3094            if(!dbc || (dbc && !dbc->IsConnected())){
3095                cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
3096                cout<<"Connecting to DB"<<endl;
3097                cout<<"HOST "<<host<<endl;
3098                cout<<"USER "<<user<<endl;
3099                cout<<"PSW  "<<psw<<endl;
3100                dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
3101                if( !dbc )return NULL;
3102                if( !dbc->IsConnected() )return NULL;    
3103    //          cout<<"...done"<<endl;
3104                cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
3105            }else{
3106    //          cout<<"DB already connected"<<endl;
3107            }
3108            GL_ROOT glroot = GL_ROOT();
3109            if( glroot.Query_GL_ROOT(iroot,dbc) ){
3110                cout << "TTree* PamLevel2::GetYodaTree( ) -- ERROR -- level0 file iroot = "<<iroot<< " does not exists"<<endl;
3111                return NULL;
3112            };
3113            TString filename = glroot.PATH + glroot.NAME;
3114            if(l0_file){
3115                l0_file->Close();
3116                l0_file->Delete();
3117            }
3118            cout << "Opening LEVEL0 file: "<< filename << endl;
3119            FileStat_t t;
3120            if( gSystem->GetPathInfo(filename.Data(),t) ){
3121                cout << " PamLevel2::GetYodaTree() -- ERROR opening file "<<endl;
3122                return NULL;
3123            }
3124            l0_file = new TFile(filename);
3125            if( !l0_file )return NULL;
3126            l0_tree = (TTree*)l0_file->Get("Physics");
3127            if(!h0_obj)h0_obj = new EventHeader();
3128            l0_tree->SetBranchAddress("Header" ,&h0_obj);
3129            prevshift = 0;
3130            //---------------------------------------------------
3131            // TRACKER:
3132            if(TRK0){
3133                if(!trk0_obj){
3134                    trk0_obj = new TrkLevel0();
3135                    trk0_obj->Set();
3136                };
3137                l0_tree->SetBranchAddress("Tracker" ,trk0_obj->GetPointerToTrackerEvent());
3138            }
3139            //--------------------------------------------------
3140            // CALORIMETER:
3141            if(CAL0){
3142                if(!calo0_obj){
3143                    calo0_obj = new CaloLevel0();
3144                    calo0_obj->Set();
3145                };
3146                l0_tree->SetBranchAddress("Calorimeter" ,calo0_obj->GetPointerToCalorimeterEvent());
3147                //      cout << "PamLevel2::GetYodaTree() --- level0 calorimeter not implemented "<<endl;
3148            }
3149            //---------------------------------------------------
3150            // TOF:
3151            if(TOF0){
3152                cout << "PamLevel2::GetYodaTree() --- level0 TOF not implemented "<<endl;
3153            }
3154    
3155        };
3156    
3157        if(!dbc || (dbc && !dbc->IsConnected())){
3158            cout << " TTree* PamLevel2::GetYodaTree( ) -- no DB connected... hai fatto qualche cazzata "<<endl;
3159        }
3160    
3161        if ( TRK0 ){
3162            TrkParams::Load(6);
3163            if( !TrkParams::IsLoaded(6) ){
3164                cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- VK-mask not loaded"<<endl;
3165            };
3166            TrkParams::SetCalib(run_obj,dbc);
3167            TrkParams::LoadCalib( );
3168            if( !TrkParams::CalibIsLoaded() ){
3169                cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- Calibration not loaded"<<endl;
3170            };
3171        }
3172    
3173    //    cout << l0_tree << endl;
3174            
3175        return l0_tree;
3176    
3177    }
3178    
3179    /**
3180     * Method to retrieve the level0 tree (YODA tree) that contains the current event.
3181     */
3182    Int_t PamLevel2::GetYodaEntry(){
3183    
3184    //    cout << "Int_t PamLevel2::GetYodaEntry()"<<endl;
3185        if(!GetYodaTree())return 0;
3186            
3187  //     if(TRK1||TRK2||TRKh){      // patch
3188  //      TTree *T = new TTree("Tracker_clone","PAMELA tracker level2 data ");          if( irunentry < 0){
3189  //      if(TRK1) {  //      cout << "Int_t PamLevel2::GetYodaEntry() -- ATTENZIONE -- irunentry negativo?!?! "<<(Int_t)irunentry<<endl;
3190  //          trk1_clone = new TrkLevel1();          irunentry=0LL;
3191  //          T->Branch("TrkLevel1","TrkLevel1", &trk1_clone);      }
3192  //          T->BranchRef();      //  ---------------------------------
3193  //          cout << "Tracker      : branch TrkLevel1"<<endl;      //  if file is NOT a preselected file
3194  //      };      //  ---------------------------------
3195  //      if(TRK2) {      Long64_t quellagiusta = irunentry + (Long64_t)(run_obj->EV_FROM);
3196  //          trk2_clone = new TrkLevel2();  //     cout << " irunentry "<<irunentry<<endl;
3197  //          T->Branch("TrkLevel2", "TrkLevel2",&trk2_clone);  //     cout << " EV_FROM "<<run_obj->EV_FROM<<endl;
3198  //          cout << "Tracker      : branch TrkLevel2"<<endl;          //     cout << " quellagiusta = irunentry + EV_FROM "<< quellagiusta << endl;
3199  //      };  
3200  //      if(TRKh) {  //     cout << " irun "<< irun << " irunentry "<< irunentry<<" run_obj->EV_FROM "<<run_obj->EV_FROM <<" quella giusta "<<quellagiusta << endl;
3201  //          trkh_clone = new TrkHough();  //     cout << " iroot "<<iroot<<" run_obj->ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<endl;
3202  //          T->Branch("TrkHough","TrkHough", &trkh_clone);  //     cout << " time "<< abstime << endl;
3203  //          cout << "Tracker      : branch TrkHough"<<endl;  //     cout << " trk_calib_used "<<run_obj->TRK_CALIB_USED<< endl;
3204  //      };      
3205  //      if(!Tout)Tout=T;      ULong64_t obt     = 0;
3206  //      else Tout->AddFriend("Tracker_clone");      ULong64_t pktn    = 0;
3207  //     }      if( GetOrbitalInfo() ){
3208            obt     = GetOrbitalInfo()->OBT;
3209            pktn    = GetOrbitalInfo()->pkt_num;
3210        }
3211    
3212  //     // Calorimeter      if( !GetOrbitalInfo() && !ISGP){
3213  //     if(CAL1||CAL2){          cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing OrbitalInfo "<<endl;
3214  //      TTree *C = new TTree("Calorimeter_clone","PAMELA calorimeter level2 data ");              return 0;
3215  //      if(CAL1) {      }
3216  //          calo1_clone = new CaloLevel1();      if( obt==0 && pktn==0 && !ISGP ){
3217  //          C->Branch("CaloLevel1", "CaloLevel1", &calo1_clone);          cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- level2 event corrupted ?? "<<endl;
3218  //          cout << "Calorimeter  : branch CaloLevel1"<<endl;          return 0;
3219  //      };      }
3220  //      if(CAL2) {  
3221  //          calo2_clone = new CaloLevel2();      // ---------------------------------------------------------------------
3222  //          C->Branch("CaloLevel2","CaloLevel2", &calo2_clone);      // ATTENTION!!!
3223  //          cout << "Calorimeter  : branch CaloLevel2"<<endl;      // If data are not pre-processed with cleaner, the level0 tree may contain
3224  //      };      // spurious nested physics packets.
3225  //      if(!Tout)Tout=C;      // The GL_RUN variables EV_FROM, EV_TO and NEVENTS counts also these entries
3226  //      else Tout->AddFriend("Calorimeter_clone");      // while level2 tree DOES NOT!!
3227  //     }          // This means that "quellagiusta" in these cases is not correct.
3228        // In order to retrieve the correct level0 event, I implemented a check
3229  //     // ToF          // of the OBT and pkt-number. In case of mismatch, the level0 entry number
3230  //     if(TOF) {      // is shift forward until when the packets match.
3231  //      TTree *O = new TTree("ToF_clone","PAMELA ToF level2 data ");          // ---------------------------------------------------------------------
3232  //      tof_clone = new ToFLevel2();      Int_t answer = 0;
3233  //      O->Branch("ToFLevel2","ToFLevel2", &tof_clone);      Int_t shift =0;
3234  //      cout << "ToF          : branch ToFLevel2"<<endl;      //    printf(" siamo qui %i %i \n",shift,prevshift);
3235  //      if(!Tout)Tout=O;      Int_t maxshift = 10;
3236  //      else Tout->AddFriend("ToF_clone");      do{
3237  //     };          if(shift>0){    
3238  //     // Trigger              cout << " PKTNUM  L2 --- "<< pktn << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl;
3239  //     if(TRG) {              cout << "         RUN: ID "<< GetRunInfo()->ID << " ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<" ID_RUN_FRAG "<<GetRunInfo()->ID_RUN_FRAG << " EV_FROM "<<GetRunInfo()->EV_FROM  <<endl;
3240  //      TTree *R = new TTree("Trigger_clone","PAMELA trigger level2 data ");                  cout << "         L2 <--> L0 mismatch ( irun "<<irun<<" irunentry "<<irunentry<<" shift "<<shift<<" prevshift "<<prevshift<<" )"<<endl;
3241  //      trig_clone = new TrigLevel2();          }
3242  //      R->Branch("TrigLevel2","TrigLevel2", &trig_clone);          answer = l0_tree->GetEntry(quellagiusta+(Long64_t)shift+(Long64_t)prevshift);
3243  //      cout << "Trigger      : branch TrigLevel2"<<endl;          shift++;
3244  //      if(!Tout)Tout=R;          if( !GetEventHeader() ){
3245  //      else Tout->AddFriend("Trigger_clone");              cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing EventHeader "<<endl;
3246  //     };              return 0;
3247  //     // S4          }
 //     if(S4) {  
 //      TTree *S = new TTree("S4_clone","PAMELA S4 level2 data ");        
 //      s4_clone = new S4Level2();  
 //      S->Branch("S4Level2","S4Level2", &s4_clone);  
 //      cout << "S4           : branch S4Level2"<<endl;  
 //      if(!Tout)Tout=S;  
 //      else Tout->AddFriend("S4_clone");  
 //     };  
 //     // Neutron Detector  
 //     if(ND) {  
 //      TTree *N = new TTree("NeutronD_clone","PAMELA neutron detector level2 data ");    
 //      nd_clone = new NDLevel2();  
 //      N->Branch("NDLevel2","NDLevel2", &nd_clone);  
 //      cout << "NeutronD     : branch NDLevel2"<<endl;  
 //      if(!Tout)Tout=N;  
 //      else Tout->AddFriend("NeutronD_clone");  
 //     };  
 //     // Anticounters  
 //     if(AC) {  
 //      TTree *A = new TTree("Anticounter_clone","PAMELA anticounter detector level2 data ");    
 //      ac_clone = new AcLevel2();  
 //      A->Branch("AcLevel2","AcLevel2", &ac_clone);  
 //      cout << "Anticounter  : branch AcLevel2"<<endl;  
 //      if(!Tout)Tout=A;  
 //      else Tout->AddFriend("Anticounter_clone");  
 //     };  
 //     // OrbitalInfo  
 //     if(ORB) {  
 //      TTree *B = new TTree("OrbitalInfo_clone","PAMELA oribital info  ");      
 //      orb_clone = new OrbitalInfo();  
 //      B->Branch("OrbitalInfo","OrbitalInfo", &orb_clone);  
 //      cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;  
 //      if(!Tout)Tout=B;  
 //      else Tout->AddFriend("OrbitalInfo_clone");  
 //     };  
 //     cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;  
3248    
3249  //     tree_clone = Tout;          if(ISGP){
3250  //     tree_clone->SetDirectory(0);              obt = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()); //BARBATRUCCO
3251                pktn = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter()); //BARBATRUCCO
3252            }
3253    
3254  //     return Tout;  //      cout << "PKTNUM "<<shift<<" ==  L2 --- "<< pktn << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl;
3255  // }  //      cout << " L2 --- "<< obt << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime()<<endl;
3256  // /**  //      if( (quellagiusta+shift) == l0_tree->GetEntries()+1 )cout << ">>> end of level0 tree <<<"<<endl;
3257  //  * Fill a tree (created with GetNewPamTree)  //      cout << " obt "<< obt << endl;
3258  //  *  //      cout << " GetEventHeader()->GetPscuHeader()->GetOrbitalTime() "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime() << endl;
3259  //  */  //      cout << " pktn "<< pktn << endl;
3260  // //void PamLevel2::FillNewPamTree(TTree *T){  //      cout << " GetEventHeader()->GetPscuHeader()->GetCounter() "<< GetEventHeader()->GetPscuHeader()->GetCounter() << endl;
3261  // void PamLevel2::FillNewPamTree(){  //      printf(" IDRUN %u \n",GetRunInfo()->ID);
3262            //
3263            if ( prevshift != 0 && (quellagiusta+(Long64_t)shift) == GetYodaTree()->GetEntries() ){
3264              prevshift = 0;
3265              shift = -1;
3266            };
3267    
3268  //     if(trk1_clone)  *trk1_clone = *trk1_obj;      }while( ( obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) ||
3269  //     if(trk2_clone){                pktn != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter())       )
3270  //      trk2_clone->Clear();              && (quellagiusta+(Long64_t)shift) < GetYodaTree()->GetEntries() && shift < maxshift);
3271  //      trk2_obj->Copy(*trk2_clone);  
3272  // //   *trk2_clone = *trk2_obj;      if ( (quellagiusta+(Long64_t)shift+(Long64_t)prevshift) > GetYodaTree()->GetEntries() || shift == maxshift ) {
3273  //     }          cout << " Big trouble here, no such event in Level0 data! " <<endl;
3274  //     if(trkh_clone)  *trkh_clone = *trkh_obj;          return 0;
3275  //     if(calo1_clone){      }
3276  // //   *calo1_clone = *calo1_obj;  //    cout << "LA ENTRY GIUSTA E`: "<<quellagiusta<<" (spero...)"<<endl;
3277  //      calo1_clone->Clear();  //    return GetYodaTree()->GetEntry(quellagiusta);
3278  //      calo1_obj->Copy(*calo1_clone);      if ( shift > 1 ) prevshift += (shift-1);
3279  //     }      
3280  //     if(calo2_clone){      return answer;
3281  // //   *calo2_clone = *calo2_obj;      
3282  //      calo2_clone->Clear();  }
3283  //      calo2_obj->Copy(*calo2_clone);  /**
3284  //     }   * \Brief Set DB connection
3285  //     if(tof_clone)   *tof_clone  = *tof_obj;   */
3286  //     if(trig_clone)  *trig_clone = *trig_obj;  Bool_t PamLevel2::SetDBConnection(){
3287  //     if(s4_clone)    *s4_clone   = *s4_obj;  
3288  //     if(nd_clone)    *nd_clone   = *nd_obj;      cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
3289  //     if(ac_clone)    *ac_clone   = *ac_obj;      cout<<"Connecting to DB"<<endl;
3290  //     if(orb_clone)   *orb_clone  = *orb_obj;      cout<<"HOST "<<host<<endl;
3291        cout<<"USER "<<user<<endl;
3292  //     TTree *T = tree_clone;      cout<<"PSW  "<<psw<<endl;
3293        dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
3294  //     T->Fill(); //fill main tree      if( !dbc )return false;
3295  // //    cout<<T->IsA()->GetName()<<" "<<T->GetName()<<endl;      if( !dbc->IsConnected() )return false;    
3296  //     TList *li = T->GetListOfFriends();      cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
3297  //     TIter next(li);      return true;
 //     TFriendElement* T_friend=0;  
 //     while( (T_friend = (TFriendElement*)next()) ){  
 // //   cout<<T_friend->IsA()->GetName()<<" "<<T_friend->GetName()<<hex << T_friend->GetTree() << dec<<endl;  
 //      T_friend->GetTree()->Fill();//fill friends  
 //     }  
3298    
3299  // }  }

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

  ViewVC Help
Powered by ViewVC 1.1.23