/[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.35 by mocchiut, Wed Mar 21 13:52:15 2007 UTC revision 1.46 by mocchiut, Wed Sep 12 09:25:22 2007 UTC
# Line 11  PamTrack::PamTrack(){ Line 11  PamTrack::PamTrack(){
11      calo_track = 0;      calo_track = 0;
12      tof_track  = 0;      tof_track  = 0;
13      candeleteobj = 0;      candeleteobj = 0;
14        pscore = 0;
15        iscore = 0;
16  };  };
17  //--------------------------------------  //--------------------------------------
18  //  //
# Line 60  void PamTrack::Clear(){ Line 62  void PamTrack::Clear(){
62          calo_track = 0;          calo_track = 0;
63          tof_track  = 0;          tof_track  = 0;
64      }      }
65        pscore = 0;
66        iscore = 0;
67    
68  }  }
69  void PamTrack::Delete(){  void PamTrack::Delete(){
70  //    cout << "PamTrack::Delete() "<<candeleteobj<<endl;  //    cout << "PamTrack::Delete() "<<candeleteobj<<endl;
# Line 112  PamLevel2::PamLevel2(TString ddir,TStrin Line 117  PamLevel2::PamLevel2(TString ddir,TStrin
117    
118  void PamLevel2::Initialize(){  void PamLevel2::Initialize(){
119                    
 //     trk2_obj  = TrkLevel2::GetTrkLevel2();  
 //     trk1_obj  = TrkLevel1::GetTrkLevel1();  
 //     trkh_obj  = TrkHough::GetTrkHough();  
 //     calo1_obj = CaloLevel1::GetCaloLevel1();  
 //     calo2_obj = CaloLevel2::GetCaloLevel2();  
 //     tof_obj   = ToFLevel2::GetToFLevel2();  
 //     trig_obj  = TrigLevel2::GetTrigLevel2();  
 //     s4_obj    = S4Level2::GetS4Level2();  
 //     nd_obj    = NDLevel2::GetNDLevel2();  
 //     ac_obj    = AcLevel2::GetAcLevel2();  
 //     orb_obj   = OrbitalInfo::GetOrbitalInfo();  
       
120      h0_obj    = 0;      h0_obj    = 0;
121      trk0_obj  = 0;      trk0_obj  = 0;
122      calo0_obj  = 0;      calo0_obj  = 0;
# Line 162  void PamLevel2::Initialize(){ Line 155  void PamLevel2::Initialize(){
155      pam_tree = NULL;      pam_tree = NULL;
156      for(Int_t i=0; i<NCLONES; i++ )pam_tree_clone[i]=NULL;      for(Int_t i=0; i<NCLONES; i++ )pam_tree_clone[i]=NULL;
157    
158        totdltime[0] = 0LL;
159        totdltime[1] = 0LL;
160    
161      host = "mysql://localhost/pamelaprod";      host = "mysql://localhost/pamelaprod";
162      user = "anonymous";      user = "anonymous";
163      psw = "";      psw = "";
# Line 198  void PamLevel2::Initialize(){ Line 194  void PamLevel2::Initialize(){
194    
195      SELLI = -1;      SELLI = -1;
196    
197        ISGP = false;
198    
199      tsorted=0;      tsorted=0;
200      timage=0;      timage=0;
201        
202        howtosort = "+CAL+TOF";
203        //howtosort = "+TOF";
204        sortthr = 100.;
205    
206  };  };
207  /**  /**
# Line 300  void PamLevel2::Clear(){ Line 302  void PamLevel2::Clear(){
302    
303      if(h0_obj)   h0_obj->Clear();            if(h0_obj)   h0_obj->Clear();      
304  //    if(trk0_obj) trk0_obj->Clear();    //    if(trk0_obj) trk0_obj->Clear();  
     if(calo0_obj) calo0_obj->Clear();    
305      if(trk1_obj) trk1_obj->Clear();          if(trk1_obj) trk1_obj->Clear();    
306      if(trk2_obj) trk2_obj->Clear();      if(trk2_obj) trk2_obj->Clear();
307      if(trkh_obj) trkh_obj->Clear();      if(trkh_obj) trkh_obj->Clear();
308        if(calo0_obj) calo0_obj->Clear();  
309      if(calo1_obj)calo1_obj->Clear();      if(calo1_obj)calo1_obj->Clear();
310      if(calo2_obj)calo2_obj->Clear();      if(calo2_obj)calo2_obj->Clear();
311      if(tof_obj)  tof_obj->Clear();      if(tof_obj)  tof_obj->Clear();
# Line 397  void PamLevel2::Reset(){ Line 399  void PamLevel2::Reset(){
399    runfirstentry = 0ULL;    runfirstentry = 0ULL;
400    runlastentry = 0ULL;        runlastentry = 0ULL;    
401    //    //
402      totdltime[0] = 0LL;
403      totdltime[1] = 0LL;
404      //
405  };  };
406    
407    Bool_t PamLevel2::IsGood(){
408      Bool_t goodev=true;
409      //  if(trk2_obj && trk2_obj->UnpackError() != 0 ) goodev = false;
410      if(calo2_obj && calo2_obj->good != 1) goodev = false;
411      if(tof_obj && tof_obj->unpackError != 0) goodev = false;  
412      if(trig_obj && trig_obj->unpackError != 0) goodev = false;
413      if(s4_obj && s4_obj->unpackError != 0) goodev = false;  
414      if(nd_obj && nd_obj->unpackError != 0) goodev = false;  
415      if(ac_obj && ac_obj->unpackError != 255) goodev = false;  
416        //  if(orb_obj)  
417      return goodev;
418    };
419    
420  //--------------------------------------  //--------------------------------------
421  //  //
# Line 593  PamTrack* PamLevel2::GetStoredTrack(Int_ Line 610  PamTrack* PamLevel2::GetStoredTrack(Int_
610  }  }
611  //--------------------------------------  //--------------------------------------
612  //  //
613    
614    /**
615     * Sort physical (tracker) tracks and stores them in the TRefArray (of TrkTrack objects) which pointer is  PamLevel2::sorted_tracks. Left here as backward compatibility method.
616     **/
617    void PamLevel2::SortTracks(TString how){
618      printf(" WARNING! obsolete, use SortTracks() and SetSortingMethod(TString) instead! \n Setting sorting method to %s \n",how.Data());
619      howtosort = how;  
620      SortTracks();
621    };
622    
623  //  //
624  //--------------------------------------  //--------------------------------------
625  /**  /**
# Line 606  PamTrack* PamLevel2::GetStoredTrack(Int_ Line 633  PamTrack* PamLevel2::GetStoredTrack(Int_
633   *   *
634   * The total number of physical tracks is always given by GetNTracks() and the it-th physical track can be retrieved by means of the methods GetTrack(int it) and GetTrack(int it, TString how).   * The total number of physical tracks is always given by GetNTracks() and the it-th physical track can be retrieved by means of the methods GetTrack(int it) and GetTrack(int it, TString how).
635   */   */
636  void PamLevel2::SortTracks(TString how){  void PamLevel2::SortTracks(){
637      TString how = howtosort;
638    
639  //    cout <<" PamLevel2::SortTracks(TString how) "<<endl;    //  cout <<" PamLevel2::SortTracks(TString how) "<<endl;
640      if( !trk2_obj ){    if( !trk2_obj ){
641          cout << "void PamLevel2::SortTracks(TString how):  TrkLevel2 not loaded !!!";      cout << "void PamLevel2::SortTracks():  TrkLevel2 not loaded !!!";
642          return;      return;
643      };    };
644  //    cout << "call SortTracs() "<<endl;    //    cout << "call SortTracs() "<<endl;
645    //Save current Object count    //Save current Object count
646      Int_t ObjectNumber = TProcessID::GetObjectCount();    Int_t ObjectNumber = TProcessID::GetObjectCount();
647    
648  //    cout << "ObjectNumber  "<<ObjectNumber <<endl;    //    cout << "ObjectNumber  "<<ObjectNumber <<endl;
649    
650  //     if(!sorted_tracks)sorted_tracks = new TRefArray();    //     if(!sorted_tracks)sorted_tracks = new TRefArray();
651  //     sorted_tracks->Clear();    //     sorted_tracks->Clear();
652  //    sorted_tracks.Clear();    //    sorted_tracks.Clear();
653    
654      if(!tsorted)tsorted = new TClonesArray("PamTrack",trk2_obj->GetNTracks());
655      tsorted->Delete();
656      TClonesArray &ttsorted = *tsorted;
657      if(!timage)timage = new TClonesArray("PamTrack",trk2_obj->GetNTracks());
658      timage->Delete();
659      TClonesArray &ttimage = *timage;
660    
     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;  
661    
662    
663      // loop over the tracks sorted by the tracker    //--------------------------------------------------
664      Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);    // retrieve sorting method
665      Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);    //--------------------------------------------------
666      Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase);    Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);
667          Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);
668      if( !CAL2 &&  use_CAL) use_CAL = false;    Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase);
669      if( !TOF &&  use_TOF) use_TOF = false;    Bool_t use_S1 = how.Contains("S1", TString::kIgnoreCase);
670          Bool_t use_S2 = how.Contains("S2", TString::kIgnoreCase);
671      if( !TRK2 ){    Bool_t use_S3 = how.Contains("S3", TString::kIgnoreCase);
672  //      cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl;    
673          return;    if ( use_TOF ){
674      };      use_S1 = true;
675        use_S2 = true;
676        use_S3 = true;
677      };
678      if( !CAL2 &&  use_CAL) use_CAL = false;
679      if( !TOF ){
680        use_TOF = false;
681        use_S1  = false;
682        use_S2  = false;
683        use_S3  = false;
684      }
685    
686      //   cout << "use_CAL "<<use_CAL<<" use_TOF "<<use_TOF<<" use_TRK "<<use_TRK <<endl;    if( !TRK2 ){
687            //  cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl;
688      for(Int_t i=0; i < trk2_obj->TrkLevel2::GetNTracks(); i++){      return;
689              };
690          TrkTrack   *ts = 0;  
691          CaloTrkVar *cs = 0;    //   cout << "use_CAL "<<use_CAL<<" use_TOF "<<use_TOF<<" use_TRK "<<use_TRK <<endl;
692          ToFTrkVar  *os = 0;    
693            
694          // get tracker tracks    //--------------------------------------------------
695          TrkTrack   *tp = trk2_obj->TrkLevel2::GetTrack(i);                    //tracker    // loop over "physical" tracks sorted by the tracker
696          CaloTrkVar *cp = GetCaloStoredTrack(tp->GetSeqNo());    //--------------------------------------------------
697          ToFTrkVar  *op = GetToFStoredTrack(tp->GetSeqNo());    for(Int_t i=0; i < trk2_obj->TrkLevel2::GetNTracks(); i++){
698            
699          TrkTrack   *ti = 0;              //tracker (image)      TrkTrack   *ts = 0;
700          CaloTrkVar *ci = 0;      CaloTrkVar *cs = 0;
701          ToFTrkVar  *oi = 0;      ToFTrkVar  *os = 0;
702  //      cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;          
703          // if track has an image, check image selection      // get tracker tracks
704          if(tp->HasImage()){      TrkTrack   *tp = trk2_obj->TrkLevel2::GetTrack(i); //tracker
705        CaloTrkVar *cp = GetCaloStoredTrack(tp->GetSeqNo());
706        ToFTrkVar  *op = GetToFStoredTrack(tp->GetSeqNo());
707    
708        TrkTrack   *ti = 0; //tracker (image)
709        CaloTrkVar *ci = 0;
710        ToFTrkVar  *oi = 0;
711        //  cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;
712        // if track has an image, check image selection
713    
714        Int_t tp_score = 0;  //main track sorted by the tracker
715        Int_t ti_score = 0;  //image track
716        Int_t totp_score = 0;  //main track sorted by the tracker
717        Int_t toti_score = 0;  //image track
718    
719        if(tp->HasImage()){
720                            
721              ti = trk2_obj->TrkLevel2::GetTrackImage(i);              //tracker (image)        ti = trk2_obj->TrkLevel2::GetTrackImage(i);              //tracker (image)
722              ci = GetCaloStoredTrack(ti->GetSeqNo());        ci = GetCaloStoredTrack(ti->GetSeqNo());
723              oi = GetToFStoredTrack(ti->GetSeqNo());        oi = GetToFStoredTrack(ti->GetSeqNo());
724                            
725  //          cout << "its image "<<i << " "<<hex<< ti <<dec<< endl;        //            cout << "its image "<<i << " "<<hex<< ti <<dec<< endl;
726    
727              //assign starting scores        //assign starting scores
728              Int_t tp_score = 0;  //main track sorted by the tracker        tp_score = 0;  //main track sorted by the tracker
729              Int_t ti_score = 0;  //image track        ti_score = 0;  //image track
730                            
731              // ------------------------        // -----------------------------------------------------------------------------------------
732              // calorimeter check        // calorimeter check
733              // ------------------------        // -----------------------------------------------------------------------------------------
734              // check the Y spatial residual on the first calorimeter plane        // check the Y spatial residual on the first calorimeter plane
735              // (cut on calorimeter variables from Emiliano)        // (cut on calorimeter variables from Emiliano)
736              if( use_CAL && !calo2_obj ){        if( use_CAL && !calo2_obj ){
737                  cout << "void PamLevel2::SortTracks(TString how): how= "<<how<<" but CaloLevel2 not loaded !!!";          cout << "void PamLevel2::SortTracks(): howtosort= "<<how<<" but CaloLevel2 not loaded !!!";
738                  return;          return;
739              };        };
740              if(        if( use_CAL && !cp &&  ci ){
741                  use_CAL            &&          ti_score++;
742                  calo2_obj->npcfit[1] > 15     &&   //no. of fit planes on Y view          toti_score++;
743                  calo2_obj->varcfit[1] < 1000. &&  //fit variance on Y view        };
744                  cp && ci &&        if( use_CAL &&  cp && !ci ){
745                  true){          tp_score++;
746            totp_score++;
747          };
748          if(
749             use_CAL            &&
750    //       calo2_obj->npcfit[1] > 5     &&   //no. of fit planes on Y view
751    //       calo2_obj->varcfit[1] < 1000. &&  //fit variance on Y view
752             cp && ci &&
753             true){
754    
755                                    
756                  Float_t resy_p = cp->tbar[0][1] - calo2_obj->cbar[0][1]; if(resy_p < 0)resy_p= - resy_p;  //      Float_t resy_p = cp->tbar[0][1] - calo2_obj->cbar[0][1]; if(resy_p < 0)resy_p= - resy_p;
757                  Float_t resy_i = ci->tbar[0][1] - calo2_obj->cbar[0][1]; if(resy_i < 0)resy_i= - resy_i;  //      Float_t resy_i = ci->tbar[0][1] - calo2_obj->cbar[0][1]; if(resy_i < 0)resy_i= - resy_i;
758                                    
759                  if(resy_p <= resy_i) tp_score++;  //      if(resy_p <= resy_i) tp_score++;
760                  else                 ti_score++;  //      else                 ti_score++;
761            
762    
763            if( cp->npresh > ci->npresh){
764              tp_score++;
765              totp_score++;
766            };
767            if( cp->npresh < ci->npresh){
768              ti_score++;
769              toti_score++;
770            };
771    
772            //      cout << "CALO "<<tp_score<<ti_score<<endl;
773    
774  //              cout << "CALO "<<tp_score<<ti_score<<endl;        };
775          // -----------------------------------------------------------------------------------------
776          // TOF check
777          // -----------------------------------------------------------------------------------------
778          // check the number of hit pmts along the track
779          // on S12 S21 and S32, where paddles are parallel to Y axis
780          if( (use_TOF || use_S1 || use_S2 || use_S3 ) && !tof_obj ){
781            cout << "void PamLevel2::SortTracks(): howtosort= "<<how<<" but ToFLevel2 not loaded !!!";
782            return;
783          };
784          //
785          if( (use_TOF || use_S1 || use_S2 || use_S3 ) && !op && oi ){
786            ti_score++;
787            toti_score++;
788          };
789          if( (use_TOF || use_S1 || use_S2 || use_S3 ) && op && !oi ){
790            tp_score++;
791            totp_score++;
792          };
793          if( (use_TOF || use_S1 || use_S2 || use_S3 ) && op && oi ){
794            //
795            Float_t sen = 0.;
796            for (Int_t ih=0; ih < op->npmtadc; ih++){
797              Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
798              if ( pl == 2 || pl == 3 || pl == 4 || pl == 5 ) sen += (op->dedx).At(ih);
799            };
800            for (Int_t ih=0; ih < oi->npmtadc; ih++){
801              Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
802              if ( pl == 2 || pl == 3 || pl == 4 || pl == 5 ) sen += (oi->dedx).At(ih);
803            };
804            //
805            if (  sen >= sortthr && false){ // temporary disabled NUCLEI special algorithm since the new one should work for every particle (to be checked!)
806              //printf(" IS A NUCLEUS! en = %f \n",sen);
807              //
808              // is a nucleus use a different algorithm
809              //
810              Int_t nz = 6; Float_t zin[6];                                          // << define TOF z-coordinates
811              for(Int_t ip=0; ip<nz; ip++)
812                zin[ip] = tof_obj->ToFLevel2::GetZTOF(tof_obj->ToFLevel2::GetToFPlaneID(ip));     // << read ToF plane z-coordinates
813              Trajectory *tr = new Trajectory(nz,zin);
814              //
815              Int_t nphit_p =0;
816              Int_t nphit_i =0;
817              Float_t enhit_p = 0.;
818              Float_t enhit_i = 0.;
819              //
820              for (Int_t ih=0; ih < op->npmtadc; ih++){
821                Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
822                if(pl == 1 || pl == 2 || pl == 5){
823                  nphit_p++;
824                  enhit_p += (op->dedx).At(ih);
825                };
826              };
827              //
828              tp->DoTrack2(tr);
829              //
830              if ( fabs(tr->y[0]-oi->ytofpos[0]) < 2. ){
831                for (Int_t ih=0; ih < op->npmtadc; ih++){
832                  Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
833                  if(pl == 0){
834                    nphit_p++;
835                    enhit_p += (op->dedx).At(ih);
836                  };
837                };
838              };
839              if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){
840                for (Int_t ih=0; ih < op->npmtadc; ih++){
841                  Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
842                  if(pl == 3){
843                    nphit_p++;
844                    enhit_p += (op->dedx).At(ih);
845                  };
846                };
847              };
848              if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){
849                for (Int_t ih=0; ih < op->npmtadc; ih++){
850                  Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
851                  if(pl == 4){
852                    nphit_p++;
853                    enhit_p += (op->dedx).At(ih);
854                  };
855                };
856              };
857    
858              for (Int_t ih=0; ih < oi->npmtadc; ih++){
859                Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
860                if(pl == 1 || pl == 2 || pl == 5){
861                  nphit_i++;        
862                  enhit_i += (op->dedx).At(ih);
863                };
864              };
865              //
866              ti->DoTrack2(tr);
867              //
868              if ( fabs(tr->y[0]-oi->ytofpos[0]) < 2. ){
869                for (Int_t ih=0; ih < oi->npmtadc; ih++){
870                  Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
871                  if(pl == 0){
872                    nphit_i++;
873                    enhit_i += (op->dedx).At(ih);
874                  };
875              };              };
876              // ------------------------            };
877              // TOF check            if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){
878              // ------------------------                  for (Int_t ih=0; ih < oi->npmtadc; ih++){
879              // check the number of hit pmts along the track                Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
880              // on S12 S21 and S32, where paddles are parallel to Y axis                if(pl == 3){
881              if( use_TOF && !tof_obj ){                  nphit_i++;
882                  cout << "void PamLevel2::SortTracks(TString how): how= "<<how<<" but ToFLevel2 not loaded !!!";                  enhit_i += (op->dedx).At(ih);
883                  return;                };
884                };
885              };
886              if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){
887                for (Int_t ih=0; ih < oi->npmtadc; ih++){
888                  Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
889                  if(pl == 4){
890                    nphit_i++;
891                    enhit_i += (op->dedx).At(ih);
892                  };
893              };              };
894              if( use_TOF && op && oi ){            };            
895    
896                                    
897                  Int_t nphit_p =0;            if(
898                  Int_t nphit_i =0;               (use_TOF || use_S1 || use_S2 || use_S3)            &&
899                 (nphit_p+nphit_i) !=0 &&  
900                 true){
901                        
902                //      printf(" seqno %i nphit_p %i nphit_i %i enhit_p %f enhit_i %f \n",trk2_obj->TrkLevel2::GetSeqNo(i),nphit_p,nphit_i,enhit_p,enhit_i);
903                //      printf(" score p %i score i %i \n",tp_score,ti_score);
904                //            if( enhit_p > enhit_i ) tp_score++;
905                //            if( nphit_p >= nphit_i && enhit_p > enhit_i ) tp_score++;
906                if ( nphit_p > nphit_i ) tp_score++;
907                if ( nphit_p < nphit_i ) ti_score++;
908                if ( nphit_p == nphit_i ){
909                  if ( enhit_p > enhit_i ) tp_score++;
910                  else ti_score++;
911                };
912                //      printf(" dopo score p %i score i %i \n",tp_score,ti_score);
913              };
914              delete tr;
915              //
916            } else {
917              //
918              // NOT a NUCLEUS
919              //
920              //printf(" NOT a NUCLEUS! en = %f \n",sen);
921    
922              Int_t nphit_p =0;
923              Int_t nphit_i =0;
924                                    
925                                    
926  /*                              cout << "track: npmtadc "<< op->npmtadc << endl;            /*                            cout << "track: npmtadc "<< op->npmtadc << endl;
927                                  cout << "track: npmttdc "<< op->npmttdc << endl;              cout << "track: npmttdc "<< op->npmttdc << endl;
928                                  cout << "image: npmtadc "<< oi->npmtadc << endl;              cout << "image: npmtadc "<< oi->npmtadc << endl;
929                                  cout << "image: npmttdc "<< oi->npmttdc << endl;*/              cout << "image: npmttdc "<< oi->npmttdc << endl;*/
930                                    
931                  for (Int_t ih=0; ih < op->npmtadc; ih++){  //        for (Int_t ih=0; ih < op->npmtadc; ih++){
932                      Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );  //          Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
933                      if(pl == 1 || pl == 2 || pl == 5)nphit_p++;  //          if(pl == 1 || pl == 2 || pl == 5)nphit_p++;
934                  };  //        };
935                                    
936                  for (Int_t ih=0; ih < oi->npmtadc; ih++){  //        for (Int_t ih=0; ih < oi->npmtadc; ih++){
937                      Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );  //          Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
938                      if(pl == 1 || pl == 2 || pl == 5)nphit_i++;  //          if(pl == 1 || pl == 2 || pl == 5)nphit_i++;
939                  };  //        };
940              // --- modified to count tdc signals (more efficient?)
941              // --- and to implement check on tdcflag
942              for (Int_t ih=0; ih < op->npmttdc; ih++){
943                Int_t pl = tof_obj->GetPlaneIndex( (op->pmttdc).At(ih) );
944    //          if( (op->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_p++;
945                if ( (use_S1 && ( pl == 0 || pl == 1 )) || (use_S2 && ( pl == 2 || pl == 3 )) || (use_S3 && ( pl == 4 || pl == 5 )) ){
946                  if( (op->tdcflag).At(ih)==0 )nphit_p++;
947                };
948              };
949                                    
950                  if(            for (Int_t ih=0; ih < oi->npmttdc; ih++){
951                      use_TOF            &&              Int_t pl = tof_obj->GetPlaneIndex( (oi->pmttdc).At(ih) );
952                      (nphit_p+nphit_i) !=0 &&      //          if( (oi->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_i++;  
953                      true){              if ( (use_S1 && ( pl == 0 || pl == 1 )) || (use_S2 && ( pl == 2 || pl == 3 )) || (use_S3 && ( pl == 4 || pl == 5 )) ){
954                                      if( (oi->tdcflag).At(ih)==0 )nphit_i++;  
                     if( nphit_p >= nphit_i) tp_score++;  
                     else ti_score++;  
                 };  
 //              cout << "TOF "<<tp_score<<ti_score<<endl;  
955              };              };
956              if(tp_score == ti_score) use_TRK = true;            };
957              // ------------------------                  
958              // tracker check            if(
959              // ------------------------               (nphit_p+nphit_i) !=0 &&  
960              // chi**2 difference is not always large enough to distinguish among               true){
961              // the real track and its image.                      
962              // Tracker check will be applied always when calorimeter and tof information is ambiguous.              if ( nphit_p != nphit_i ){
963              if(use_TRK){                totp_score += nphit_p;
964                  if(      tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ;                toti_score += nphit_i;
                 else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ;  
 //              cout << "TRK "<<tp_score<<ti_score<<endl;  
965              };              };
966                if     ( nphit_p > nphit_i) tp_score++;
967                else if( nphit_p < nphit_i) ti_score++;
968                else ;//niente
969              };
970            };
971            //      cout << "TOF "<<tp_score<<ti_score<<endl;
972          };
973    
974    
975    //      if(tp_score == ti_score) use_TRK = true;
976    
977    
978          // -----------------------------------------------------------------------------------------
979          // tracker check
980          // -----------------------------------------------------------------------------------------
981          // chi**2 difference is not always large enough to distinguish among
982          // the real track and its image.
983          // Tracker check will be applied always when calorimeter and tof information is ambiguous.
984          // *** MODIFIED ON AUGUST 2007 ***
985          if(use_TRK){
986    //      if(      tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ;
987    //      else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ;
988    
989              // CHECK 1 : number of points along X  
990            if ( tp->GetNX() >= ti->GetNX() ){
991              tp_score++ ;
992              totp_score++ ;
993            };
994            if ( tp->GetNX() <= ti->GetNX() ){
995              ti_score++ ;
996              toti_score++ ;
997            };
998              // CHECK 2 : number of points along Y  
999            if ( tp->GetNY() >= ti->GetNY() ){
1000              tp_score++ ;
1001              totp_score++ ;
1002            };
1003            if ( tp->GetNY() <= ti->GetNY() ){
1004              ti_score++ ;
1005              toti_score++ ;
1006            };
1007              // CHECK 3 : chi**2 along X  
1008    //        if(      tp->GetChi2X() > 0 && (tp->GetChi2X() < ti->GetChi2X() || ti->GetChi2X() <=0) ) tp_score++ ;
1009    //        if(      ti->GetChi2X() > 0 && (ti->GetChi2X() < tp->GetChi2X() || tp->GetChi2X() <=0) ) ti_score++ ;
1010              // CHECK 4 : chi**2 along Y  
1011    //        if(      tp->GetChi2Y() > 0 && (tp->GetChi2Y() < ti->GetChi2Y() || ti->GetChi2Y() <=0) ) tp_score++ ;
1012    //        if(      ti->GetChi2Y() > 0 && (ti->GetChi2Y() < tp->GetChi2Y() || tp->GetChi2Y() <=0) ) ti_score++ ;
1013              // CHECK 5 : total chi**2  
1014    //        if(      tp->chi2 > 0 && (tp->chi2 < ti->chi2 || ti->chi2 <=0) ) tp_score++ ;
1015    //        if(      ti->chi2 > 0 && (ti->chi2 < tp->chi2 || tp->chi2 <=0) ) ti_score++ ;
1016    
1017            //      cout << "TRK "<<tp_score<<ti_score<<endl;
1018          };
1019                            
1020              // ------------------------  
1021              // the winner is....  
1022              // ------------------------            // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1023              if      (tp_score > ti_score) {        // the winner is....
1024  //              ts = tp;//the track sorted by the tracker!!        // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1025  //              cs = cp;        if      (tp_score > ti_score) {
1026  //              os = op;          
1027              }else if (tp_score < ti_score) {  
1028                  ts = ti;//its image!!        }else if (tp_score < ti_score) {
1029                  cs = ci;  
1030                  os = oi;  
1031            ts = ti;//its image!!
1032                  ti = tp;//its image!!          cs = ci;
1033                  ci = cp;          os = oi;
1034                  oi = op;  
1035            ti = tp;//its image!!
1036                  tp = ts;//its image!!          ci = cp;
1037                  cp = cs;          oi = op;
1038                  op = os;  
1039            tp = ts;//its image!!
1040            cp = cs;
1041            op = os;
1042    
1043                                    
1044              }else {        }else {
1045  //              ts = tp;  
1046  //              cs = cp;  //      cout << "Warning - track image ambiguity not solved" << endl;
1047  //              os = op;  
1048  //                              cout << "Warning - track image ambiguity not solved" << endl;        };
 //                              cout << ts->GetNtot() << " "<< ts->chi2 << " " << npcfit[1] << " "<< nphit_p << endl;  
             };  
1049                            
1050          }else{      }else{
1051  //          ts = tp;        totp_score = 1;
1052  //          cs = cp;        toti_score = 0;
1053  //          os = op;        
1054          };        //            ts = tp;
1055                  //            cs = cp;
1056  //      cout <<" SortTracks() "<<i<<" -- "<<ts<<endl;        //            os = op;
1057  //      sorted_tracks->Add(ts);//save the track in the sorted array      };
1058  //      sorted_tracks.Add(ts);//save the track in the sorted array          
1059  //      sorted_tracks.Add(tp);//save the track in the sorted array      //  cout <<" SortTracks() "<<i<<" -- "<<ts<<endl;
1060  //      cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl;      //  sorted_tracks->Add(ts);//save the track in the sorted array
1061  //      cout<<"o "<<tp<<endl;      //  sorted_tracks.Add(ts);//save the track in the sorted array
1062  //      cout<<"o "<<cp<<endl;      //  sorted_tracks.Add(tp);//save the track in the sorted array
1063  //      cout<<"o "<<op<<endl;      //  cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl;
1064          new(ttsorted[i]) PamTrack(tp,cp,op);      //  cout<<"o "<<tp<<endl;
1065          new(ttimage[i])  PamTrack(ti,ci,oi);      //  cout<<"o "<<cp<<endl;
1066      };      //  cout<<"o "<<op<<endl;
1067    
1068      if( tsorted->GetEntries() != trk2_obj->GetNTracks() ){      new(ttsorted[i]) PamTrack(tp,cp,op);
1069          cout << "void PamLevel2::SortTracks(TString how): tsorted->GetEntries() "<<tsorted->GetEntries()<<" != trk2_obj->GetNTracks() = "<<trk2_obj->GetNTracks() <<endl;      new(ttimage[i])  PamTrack(ti,ci,oi);
1070          tsorted->Delete(); tsorted=0;  
1071          timage->Delete(); timage=0;          ((PamTrack*)(ttsorted[i]))->SetPScore(totp_score);
1072      }      ((PamTrack*)(ttimage[i]))->SetIScore(toti_score);
1073      };
1074      //Restore Object count  
1075      //To save space in the table keeping track of all referenced objects    if( tsorted->GetEntries() != trk2_obj->GetNTracks() ){
1076      //We reset the object count to what it was at the beginning of the event.      cout << "void PamLevel2::SortTracks(): tsorted->GetEntries() "<<tsorted->GetEntries()<<" != trk2_obj->GetNTracks() = "<<trk2_obj->GetNTracks() <<endl;
1077      TProcessID::SetObjectCount(ObjectNumber);      tsorted->Delete(); tsorted=0;
1078        timage->Delete(); timage=0;
1079      }
1080    
1081      //Restore Object count
1082      //To save space in the table keeping track of all referenced objects
1083      //We reset the object count to what it was at the beginning of the event.
1084      TProcessID::SetObjectCount(ObjectNumber);
1085            
1086  };  };
1087  //--------------------------------------  //--------------------------------------
# Line 833  void PamLevel2::SortTracks(TString how){ Line 1105  void PamLevel2::SortTracks(TString how){
1105  TClonesArray *PamLevel2::GetTracks(){  TClonesArray *PamLevel2::GetTracks(){
1106    
1107  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
1108      SortTracks("+CAL+TOF");      SortTracks();
1109  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
1110    
1111      return tsorted;      return tsorted;
# Line 852  PamTrack *PamLevel2::GetTrack(int it){ Line 1124  PamTrack *PamLevel2::GetTrack(int it){
1124    
1125  //    if(!trk2_obj) return 0;  //    if(!trk2_obj) return 0;
1126                    
1127  // //  *-*-*-*-*-*-*-*-*-*-*-*-*  // //  *-*-*-*+-*-*-*-*-*-*-*-*-*
1128  //     SortTracks("+CAL+TOF");  //     SortTracks("+CAL+TOF");
1129  // //  *-*-*-*-*-*-*-*-*-*-*-*-*  // //  *-*-*-*-*-*-*-*-*-*-*-*-*
1130  // //    if(!sorted_tracks)return 0;  // //    if(!sorted_tracks)return 0;
# Line 871  PamTrack *PamLevel2::GetTrack(int it){ Line 1143  PamTrack *PamLevel2::GetTrack(int it){
1143    
1144  //    cout << "PamLevel2::GetTrack(int it) "<<endl;  //    cout << "PamLevel2::GetTrack(int it) "<<endl;
1145  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
1146      SortTracks("+CAL+TOF");      SortTracks();
1147  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
1148      if(!tsorted)return 0;      if(!tsorted)return 0;
1149      if(!tsorted->GetEntries())return 0;      if(!tsorted->GetEntries())return 0;
# Line 928  PamTrack *PamLevel2::GetTrackImage(int i Line 1200  PamTrack *PamLevel2::GetTrackImage(int i
1200    
1201    
1202  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
1203      SortTracks("+CAL+TOF");      SortTracks();
1204  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
1205      if(!timage)return 0;      if(!timage)return 0;
1206      if(!timage->GetEntries())return 0;      if(!timage->GetEntries())return 0;
# Line 1327  TChain *PamLevel2::GetPamTree(TList *fl, Line 1599  TChain *PamLevel2::GetPamTree(TList *fl,
1599      };      };
1600            
1601      cout << "done chain \n";      cout << "done chain \n";
1602        cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
1603    
1604  //    UInt_t *found=0;  //    UInt_t *found=0;
1605  // Tracker  // Tracker
# Line 1412  TChain *PamLevel2::GetPamTree(TList *fl, Line 1685  TChain *PamLevel2::GetPamTree(TList *fl,
1685      }else{      }else{
1686          cout << "OrbitalInfo  : missing tree"<<endl;          cout << "OrbitalInfo  : missing tree"<<endl;
1687      };      };
1688        cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
1689    
1690      // Selection List      // Selection List
1691      if(L && SELLI==1) {      if(L && SELLI==1) {
# Line 1423  TChain *PamLevel2::GetPamTree(TList *fl, Line 1697  TChain *PamLevel2::GetPamTree(TList *fl,
1697          sel_tree = L;          sel_tree = L;
1698  //      if(!Trout)Trout=O;  //      if(!Trout)Trout=O;
1699  //      else Trout->AddFriend("SelectionList");  //      else Trout->AddFriend("SelectionList");
1700            cout << "----------------------------------------------------" <<endl;
1701      }else{      }else{
1702  //      cout << "SelectionList  : missing tree"<<endl;  //      cout << "SelectionList  : missing tree"<<endl;
1703          if(L)L->Delete();          if(L)L->Delete();
# Line 1692  Bool_t PamLevel2::UpdateRunInfo(TChain * Line 1967  Bool_t PamLevel2::UpdateRunInfo(TChain *
1967    //    //
1968    // check if we have already called once GetEntry, if not call it    // check if we have already called once GetEntry, if not call it
1969    //    //
1970        cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev) --- NON FUNZIONA BENISSIMO.... "<<endl;
1971      if(!run){      if(!run){
1972            cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing RunInfo tree "<<endl;            cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing RunInfo tree "<<endl;
1973            return(false);                    return(false);        
# Line 1707  Bool_t PamLevel2::UpdateRunInfo(TChain * Line 1983  Bool_t PamLevel2::UpdateRunInfo(TChain *
1983    // --------------------------------------    // --------------------------------------
1984    if(SELLI==0){    if(SELLI==0){
1985    
1986        if( !GetOrbitalInfo() ){        //
1987          // the absolute time is necessary to relate the event with the run
1988          //
1989          if( !GetOrbitalInfo() && !ISGP){
1990            cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;            cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;
1991            return(false);            return(false);
1992        }        }
1993    
1994          ULong64_t abstime = 0;
1995          if( GetOrbitalInfo() )abstime=GetOrbitalInfo()->absTime;
1996    
1997    
1998          //
1999          // the first time the routine is called, set run search from the beginning
2000          //
2001        if ( irun < 0LL ){        if ( irun < 0LL ){
2002            irun = 0LL;            irun = 0LL;
2003            run->GetEntry(irun);            run->GetEntry(irun);
2004            runfirstentry = 0LL;            runfirstentry = 0LL;
2005            runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);            runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
2006            if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;            if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;
2007  //        cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;            
2008  //        cout << "runfirstentry "<<runfirstentry<<endl;            if( ISGP && run->GetEntries()!=1 ){
2009  //        return(true);                cout << "** WARNING ** simulated files are assumed to have 1 single run, not "<< run->GetEntries() << endl;
2010                  cout << "** WARNING ** run will not be updated"<<endl;
2011              }
2012    
2013        };              };      
2014        //        //
2015         if ( irun == run->GetEntries()-1LL &&        if(ISGP)abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO
2016             !(GetOrbitalInfo()->absTime >= GetRunInfo()->RUNHEADER_TIME &&        //
2017               GetOrbitalInfo()->absTime <= GetRunInfo()->RUNTRAILER_TIME)        if ( irun == run->GetEntries()-1LL &&
2018               !(abstime >= GetRunInfo()->RUNHEADER_TIME &&
2019                 abstime <= GetRunInfo()->RUNTRAILER_TIME)
2020              ){              ){
2021           irun = -1LL;           irun = -1LL;
2022           runfirstentry = 0LL;           runfirstentry = 0LL;
# Line 1736  Bool_t PamLevel2::UpdateRunInfo(TChain * Line 2027  Bool_t PamLevel2::UpdateRunInfo(TChain *
2027        //        //
2028        bool fromfirst = true;        bool fromfirst = true;
2029        //        //
2030        while ( !(GetOrbitalInfo()->absTime >= GetRunInfo()->RUNHEADER_TIME && GetOrbitalInfo()->absTime <= GetRunInfo()->RUNTRAILER_TIME) && irun < run->GetEntries()-1LL ){        while ( !(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME) && irun < run->GetEntries()-1LL ){
2031  //      while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){  //      while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){
2032            irun++;            irun++;
2033            run->GetEntry(irun);            run->GetEntry(irun);
# Line 1746  Bool_t PamLevel2::UpdateRunInfo(TChain * Line 2037  Bool_t PamLevel2::UpdateRunInfo(TChain *
2037  //        cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;  //        cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2038  //        cout << "runfirstentry "<<runfirstentry<<endl;  //        cout << "runfirstentry "<<runfirstentry<<endl;
2039            //      printf(" iev %llu %u %llu \n",iev,this->GetRunInfo()->NEVENTS,(ULong64_t)(runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS)));            //      printf(" iev %llu %u %llu \n",iev,this->GetRunInfo()->NEVENTS,(ULong64_t)(runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS)));
2040            //      printf(" abstime %u trailertime %u \n",GetOrbitalInfo()->absTime,GetRunInfo()->RUNTRAILER_TIME);            //      printf(" abstime %u trailertime %u \n",abstime,GetRunInfo()->RUNTRAILER_TIME);
2041            //      printf(" IDRUN %u \n",GetRunInfo()->ID);            //      printf(" IDRUN %u \n",GetRunInfo()->ID);
2042            //            //
2043  //        prevshift = 0;  //        prevshift = 0;
2044            //            //
2045            if ( irun == (Long64_t)(run->GetEntries()-1LL) && fromfirst && !(GetOrbitalInfo()->absTime >= GetRunInfo()->RUNHEADER_TIME && GetOrbitalInfo()->absTime <= GetRunInfo()->RUNTRAILER_TIME)){            if ( irun == (Long64_t)(run->GetEntries()-1LL) && fromfirst && !(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME)){
2046                printf(" resetting irun  (it should NOT happen!!!)\n");                printf(" resetting irun  (it should NOT happen!!!)\n");
2047                fromfirst = false;                fromfirst = false;
2048                irun = 0;                irun = 0;
# Line 1764  Bool_t PamLevel2::UpdateRunInfo(TChain * Line 2055  Bool_t PamLevel2::UpdateRunInfo(TChain *
2055        };        };
2056        //        //
2057        if (        if (
2058             !(GetOrbitalInfo()->absTime >= GetRunInfo()->RUNHEADER_TIME &&             !(abstime >= GetRunInfo()->RUNHEADER_TIME &&
2059               GetOrbitalInfo()->absTime <= GetRunInfo()->RUNTRAILER_TIME)               abstime <= GetRunInfo()->RUNTRAILER_TIME)
2060            ) {            ) {
2061            printf(" Something very wrong here: cannot find RUN containing absolute time %u \n",GetOrbitalInfo()->absTime);          printf(" Something very wrong here: cannot find RUN containing absolute time %llu \n",abstime);
2062            return false;            return false;
2063        }        }
2064        //        //
# Line 1800  Bool_t PamLevel2::UpdateRunInfo(TChain * Line 2091  Bool_t PamLevel2::UpdateRunInfo(TChain *
2091    //    //
2092  };  };
2093    
2094  // Bool_t PamLevel2::UpdateRunInfo(ULong64_t iev){  Bool_t PamLevel2::UpdateRunInfo(Long64_t iev){
2095  //   //  
2096  //   // check if we have already called once GetEntry, if not call it      if(!run_tree){
2097  //   //          cout << " Bool_t PamLevel2::UpdateRunInfo(ULong64_t iev) -- ERROR -- run tree not loaded"<<endl;
2098  //     if(!run_tree){          return false;
2099  //      cout << " Bool_t PamLevel2::UpdateRunInfo(ULong64_t iev) -- ERROR -- run tree not loaded"<<endl;      }
2100  //      return false;      if ( run_tree->GetEntries() <= 0 ) {
2101  //     }          cout << " Bool_t PamLevel2::UpdateRunInfo(ULong64_t iev) -- ERROR -- run tree is empty"<<endl;
2102  //     if ( run_tree->GetEntries() <= 0 ) {          return(false);
2103  //      cout << " Bool_t PamLevel2::UpdateRunInfo(ULong64_t iev) -- ERROR -- run tree is empty"<<endl;      }
 //      return(false);  
 //     }  
 //   //  
2104        
2105  //   Int_t oldrun = irun;      Int_t oldrun = irun; // store current run index
2106  //   // --------------------------------------  
2107  //   // if it is a full file (not preselected)      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2108  //   // --------------------------------------      // if it is a full file (not preselected)
2109  //   if(SELLI==0){      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2110        if(SELLI==0){
2111  //       if( !GetOrbitalInfo() ){  
2112  //        cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;          // ---------------------------------------------------------------
2113  //        return(false);          // increment dead and live-time counters
2114  //       }          // ---------------------------------------------------------------
2115            if( GetTrigLevel2() ){
2116  //       if ( irun < 0 ){              totdltime[0]+=GetTrigLevel2()->dltime[0];
2117  //        irun = 0;              totdltime[1]+=GetTrigLevel2()->dltime[1];
2118  //        run_tree->GetEntry(irun);          }
2119  //        runfirstentry = iev;          totdltime[2]++;
2120  //        if( iev != 0){  
2121  //            cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- WARNING -- "<<endl;  //      cout << setw(10)<<totdltime[0]<<setw(10)<<totdltime[1]<<setw(10)<<totdltime[2]<<endl;
2122  //        }  
2123  //       };                // ---------------------------------------------------------------
2124            // retrieve OBT and absolute time of the event
2125  //       bool fromfirst = true;          // ---------------------------------------------------------------
2126            ULong64_t abstime = 0;
2127  //       while ( !(GetOrbitalInfo()->absTime >= GetRunInfo()->RUNHEADER_TIME && GetOrbitalInfo()->absTime <= GetRunInfo()->RUNTRAILER_TIME) && irun < run->GetEntries() ){          ULong64_t obt     = 0;
2128  //        irun++;          if( GetOrbitalInfo() ){
2129  //        if( irun == run->GetEntries() ){              abstime = GetOrbitalInfo()->absTime;
2130  //            if(!fromfirst){              obt     = GetOrbitalInfo()->OBT;
2131  //                cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- event entry #"<<iev<<" does not belong to any run (should not happen)" <<endl;          }
2132  //                return false;          // ---------------------------------------------------------------
2133  //            }          // the absolute time is necessary to relate the event with the run
2134  //            cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- reached end of run tree. searchin again from beginning (should not happen)" <<endl;          // ---------------------------------------------------------------
2135  //            fromfirst = false;          if( !GetOrbitalInfo() && !ISGP ){
2136  //            irun =0;              cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;
2137  //        }              return(false);
2138  //        run_tree->GetEntry(irun);          }
2139  //        runfirstentry = iev;        
2140  //       };          // -----------------------------------------------------------------------
2141  //       //          // the first time the routine is called, set run search from the beginning
2142  //       if ( irun == oldrun ) return(false);          // -----------------------------------------------------------------------
2143  //       //          if ( irun < 0 ){
2144  //       cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;              irun = 0LL;
2145  //       cout << "runfirstentry "<<runfirstentry<<endl;              irunentry = 0;
2146  //       prevshift = 0;              prevshift = 0;
2147  //       return(true);                  run_tree->GetEntry(irun);
2148  //   };  
2149  //   // ----------------------------------------------------              if( ISGP && run_tree->GetEntries()!=1 ){
2150  //   // if it is a preselected file (there is SelectionList)                  cout << "** WARNING ** simulated files are assumed to have 1 single run, not "<< run_tree->GetEntries() << endl;
2151  //   // NBNB - the event tree MUST be read first                  cout << "** WARNING ** run will not be updated"<<endl;
2152  //   // ----------------------------------------------------              }
2153  //   if(SELLI==1){                };      
2154  //       sel_tree->GetEntry(iev);  
2155  //       if(irun != oldrun){          // -----------------------------------------------------------------------
2156  //        run->GetEntry(irun);          // if it is simulation, assigh abstime by hand (temporaneo!!!)
2157  //        cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;          // -----------------------------------------------------------------------
2158  //        prevshift = 0;          if(ISGP){
2159  //        return true;              abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO
2160  //       }              obt     = GetRunInfo()->RUNHEADER_OBT; // BARBATRUCCO
2161  //       return false;          }
2162  //   }          //
2163            bool fromfirst = true; // first loop over runs
2164  //   return false;  
2165  //   //  //      Bool_t hasfrag = false;
2166  // };  //      if( GetRunInfo()->ID_RUN_FRAG!=0 && GetRunInfo()->ID_RUN_FRAG != GetRunInfo()->ID)hasfrag=true;
2167    //      ULong64_t fragid = GetRunInfo()->ID_RUN_FRAG;
2168    
2169            // ------------------------------------------------------
2170            // loop over runs to find the one that contains the event
2171            // ------------------------------------------------------
2172            while (
2173                (
2174                    (
2175                        !(abstime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s)
2176                          abstime <= GetRunInfo()->RUNTRAILER_TIME) &&
2177                        !(obt >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms)
2178                          obt <= GetRunInfo()->RUNTRAILER_OBT)
2179                        )
2180                    || GetRunInfo()->NEVENTS==0
2181                    || !(irunentry < GetRunInfo()->NEVENTS-1-prevshift)
2182                    )
2183                    && irun < run_tree->GetEntries() ){
2184    
2185    
2186    
2187    
2188                // -----------------------------------------
2189                // store dead and live-time of previous run
2190                // -----------------------------------------
2191                if(fromfirst){
2192                    if(oldrun==irun){
2193                        /// decrement counters
2194                        if( GetTrigLevel2()){
2195                            totdltime[0]-=GetTrigLevel2()->dltime[0];//live-time
2196                            totdltime[1]-=GetTrigLevel2()->dltime[1];//dead-time
2197                        }
2198                        totdltime[2]--;                              //event counter
2199                        cout << endl;
2200                        cout << "n.events     : "<<totdltime[2]<<endl;
2201                        cout << "RUN LIVE-TIME: "<<totdltime[0]*0.16<<" ms"<<endl;
2202                        cout << "RUN DEAD-TIME: "<<totdltime[1]*0.01<<" ms"<<endl;      
2203                    }else{
2204                        totdltime[0]=0;//live-time
2205                        totdltime[1]=0;//dead-time
2206                        totdltime[2]=0;                             //event counter
2207                        cout << " *** JUMP RUN *** irun "<<irun<<endl;
2208                    }
2209                    /// add an entry
2210                    if(run_tree_clone)
2211                        if(run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())
2212                            run_tree_clone->GetBranch("DeadLiveTime")->Fill();
2213                    /// reset counters
2214                    if( GetTrigLevel2() ){
2215                        totdltime[0]=GetTrigLevel2()->dltime[0];//live-time
2216                        totdltime[1]=0;                         //dead-time
2217                    }
2218                    totdltime[2]=1;                             //event counter
2219                }
2220    
2221    
2222                irun++;
2223                // ------------------------------------
2224                // if the end of run tree is reached...
2225                // ------------------------------------
2226                if( irun == run_tree->GetEntries() ){
2227                    if(!fromfirst){
2228                        // -----------------------------------------------------
2229                        // if it happened already once and the run was not found
2230                        // ---> exit with error
2231                        // -----------------------------------------------------
2232                        cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- ERROR -- event entry #"<<iev<<" does not belong to any run (should not happen)" <<endl;
2233                        return false;
2234                    }
2235                    // -----------------------------------------
2236                    // ...otherwise repeat search from beginning
2237                    // -----------------------------------------
2238                    cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- reached end of run tree. searchin again from beginning " <<endl;
2239                    fromfirst = false;
2240                    irun = 0LL;
2241                    runfirstentry = 0LL;
2242                }
2243                // -------------------------------------------------------------------
2244                // save the index of the first entry of the run, relative to pam_tree,
2245                // and read a new run
2246                // -------------------------------------------------------------------
2247                if(irun>0)runfirstentry += (GetRunInfo()->NEVENTS)-prevshift;
2248                irunentry = 0;
2249                prevshift = 0;          
2250                run_tree->GetEntry(irun);      
2251                if(GetRunInfo()->RUNHEADER_OBT>GetRunInfo()->RUNTRAILER_OBT ){
2252                    cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- irun "<<irun<<"  has RUNHEADER_OBT>=RUNTRAILER_OBT " <<endl;
2253                    cout << "                                                            (NB!! in this case some events are assigned to a wrong run)"<<endl;
2254                }
2255    //          if(hasfrag &&  fragid != GetRunInfo()->ID){
2256    //              cout << "... where is the next fragment ??"<<endl;
2257    //          }
2258            };
2259    
2260    
2261            // --------------------------------------
2262            // if there was no need to update the run
2263            // ---> exit with FALSE
2264            // --------------------------------------
2265            if ( irun == oldrun ) return(false);
2266    
2267            // --------------------------------------
2268            // ... otherwise
2269            // --------------------------------------
2270    
2271    
2272    
2273    //      // -----------------------------------------
2274    //      // store dead and live-time of previous run
2275    //      // -----------------------------------------
2276    //      // --------------------------------------------------------------
2277    //      // if the run is empty, fill the dead-live time branch with zeros
2278    //      // --------------------------------------------------------------
2279    //      /// if some runs have been jumped, fill with zeros
2280    //      if(irun-oldrun>1){
2281    //          ULong64_t  temp[3];
2282    //          temp[0]=totdltime[0];
2283    //          temp[1]=totdltime[1];
2284    //          temp[2]=totdltime[2];
2285    //          for(int i=oldrun+1; i<irun; irun++){
2286    //              totdltime[0]=0;
2287    //              totdltime[1]=0;
2288    //              totdltime[2]=0;
2289    //              cout << " ** JUMPED RUN **"<<endl;
2290    //              if(run_tree_clone)
2291    //                  if(run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())
2292    //                      run_tree_clone->GetBranch("DeadLiveTime")->Fill();
2293    //          }
2294    //          totdltime[0]=temp[0];
2295    //          totdltime[1]=temp[1];
2296    //          totdltime[2]=temp[2];
2297    //      }
2298    //      /// decrement counters
2299    //      if( GetTrigLevel2() ){
2300    //          totdltime[0]-=GetTrigLevel2()->dltime[0];//live-time
2301    //          totdltime[1]-=GetTrigLevel2()->dltime[1];//dead-time
2302    //      }
2303    //      totdltime[2]--;                              //event counter
2304    //      /// add an entry
2305    //      if(irun>0 ){
2306    //          cout << endl;
2307    //          cout << "n.events     : "<<totdltime[2]<<endl;
2308    //          cout << "RUN LIVE-TIME: "<<totdltime[0]*0.16<<" ms"<<endl;
2309    //          cout << "RUN DEAD-TIME: "<<totdltime[1]*0.01<<" ms"<<endl;      
2310    //          if(run_tree_clone)
2311    //              if(run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())
2312    //                  run_tree_clone->GetBranch("DeadLiveTime")->Fill();
2313    //      }
2314    //      /// reset counters
2315    //      if( GetTrigLevel2() ){
2316    //          totdltime[0]=GetTrigLevel2()->dltime[0];//live-time
2317    //          totdltime[1]=0;                         //dead-time
2318    //      }
2319    //      totdltime[2]=1;                             //event counter
2320            
2321    
2322            // --------------------------------------
2323            // ---> exit with TRUE
2324            // --------------------------------------
2325            cout << endl << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2326            // ----------------------------------------------------
2327            // then check if the run has a fragment
2328            // in this case we have to switch to the next fragment
2329            // when the end of the first fragment is reached
2330            // ----------------------------------------------------
2331            if(
2332                GetRunInfo()->ID_RUN_FRAG != 0 &&
2333    //          GetRunInfo()->ID_RUN_FRAG != GetRunInfo()->ID &&
2334                true ){
2335                cout << "* fragment *"<<endl;              
2336            }
2337    
2338            return(true);    
2339        };
2340        // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2341        // if it is a preselected file (there is SelectionList)
2342        // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2343        if(SELLI==1){      
2344            sel_tree->GetEntry(iev);
2345            if(irun != oldrun){
2346                run_tree->GetEntry(irun);
2347                cout << endl << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2348                prevshift = 0;
2349                return true;
2350            }
2351            return false;
2352        }
2353    
2354        return false;
2355        //
2356    };
2357  /**  /**
2358   * Update the runinfo informations (to be used to have Run infos event by event basis)   * Update the runinfo informations (to be used to have Run infos event by event basis)
2359   * @param run Pointer to the chain/tree which contains run infos   * @param run Pointer to the chain/tree which contains run infos
# Line 2505  void PamLevel2::CreateCloneTrees0( TChai Line 2983  void PamLevel2::CreateCloneTrees0( TChai
2983   */   */
2984  void PamLevel2::CreateCloneTrees(TFile *ofile){  void PamLevel2::CreateCloneTrees(TFile *ofile){
2985    
2986    
2987    //  if the pointer is null, create a default file
2988    
2989        if(!ofile){
2990            cout << "void PamLevel2::CreateCloneTrees(TFile*) -- WARNING -- Creating file: clone-tree.root "<<endl;
2991            ofile = new TFile("clone-tree.root","recreate");
2992        }
2993    
2994      ofile->cd();      ofile->cd();
2995    
2996      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
# Line 2516  void PamLevel2::CreateCloneTrees(TFile * Line 3002  void PamLevel2::CreateCloneTrees(TFile *
3002      cout << "Run          : branch RunInfo"<<endl;      cout << "Run          : branch RunInfo"<<endl;
3003      run_tree_clone->Branch("SoftInfo","SoftInfo",GetPointerTo("SoftInfo"));      run_tree_clone->Branch("SoftInfo","SoftInfo",GetPointerTo("SoftInfo"));
3004      cout << "Run          : branch SoftInfo"<<endl;      cout << "Run          : branch SoftInfo"<<endl;
3005                    // ------------------
3006        // replicate run tree
3007        // ------------------
3008        cout << "----------------------------------------------------"<<endl;
3009        cout << "irun\t | RUN\t NEVENTS\t absolute time"<<endl;
3010        for (Int_t i=0; i<run_tree->GetEntries(); i++){
3011            run_tree->GetEntry(i);
3012            cout << i<< "\t | "<<GetRunInfo()->ID<<"\t "<<GetRunInfo()->NEVENTS<< "\t "<<GetRunInfo()->RUNHEADER_TIME<<" <---> "<<GetRunInfo()->RUNTRAILER_TIME<<endl;
3013            run_tree_clone->Fill();
3014        }
3015        cout << "----------------------------------------------------"<<endl;
3016    
3017        // ------------------------------------
3018        // add branch with dead and live times
3019        // ------------------------------------
3020        run_tree_clone->Branch("DeadLiveTime",totdltime,"dltime[3]/l");
3021        cout << "Run          : branch DeadLiveTime"<<endl;
3022    
3023    
3024      sel_tree_clone = new TTree("SelectionList","List of selected events ");      sel_tree_clone = new TTree("SelectionList","List of selected events ");
# Line 2531  void PamLevel2::CreateCloneTrees(TFile * Line 3033  void PamLevel2::CreateCloneTrees(TFile *
3033              pam_tree_clone[i]->Branch("TrkLevel1","TrkLevel1", GetPointerTo("TrkLevel1"));              pam_tree_clone[i]->Branch("TrkLevel1","TrkLevel1", GetPointerTo("TrkLevel1"));
3034              pam_tree_clone[i]->BranchRef();              pam_tree_clone[i]->BranchRef();
3035              cout << "Tracker      : branch TrkLevel1"<<endl;              cout << "Tracker      : branch TrkLevel1"<<endl;
3036              cout << "CreateCloneTrees " << GetTrkLevel1()<<endl;  //          cout << "CreateCloneTrees " << GetTrkLevel1()<<endl;
3037          };          };
3038          if(TRK2) {          if(TRK2) {
3039              pam_tree_clone[i]->Branch("TrkLevel2", "TrkLevel2",GetPointerTo("TrkLevel2"));              pam_tree_clone[i]->Branch("TrkLevel2", "TrkLevel2",GetPointerTo("TrkLevel2"));
# Line 2644  TTree* PamLevel2::GetCloneTree(TString n Line 3146  TTree* PamLevel2::GetCloneTree(TString n
3146  void PamLevel2::WriteCloneTrees(){  void PamLevel2::WriteCloneTrees(){
3147      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
3148      cout << "Write clones of PAMELA trees "<<endl;      cout << "Write clones of PAMELA trees "<<endl;
3149      cout << run_tree_clone->GetName()<<endl;          cout << run_tree_clone->GetName()<<endl;  
3150        if(run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())
3151            run_tree_clone->GetBranch("DeadLiveTime")->Fill();
3152      run_tree_clone->Write();      run_tree_clone->Write();
3153      cout << sel_tree_clone->GetName()<<endl;          cout << sel_tree_clone->GetName()<<endl;    
3154      sel_tree_clone->Write();      sel_tree_clone->Write();
# Line 2664  void PamLevel2::WriteCloneTrees(){ Line 3168  void PamLevel2::WriteCloneTrees(){
3168  //Int_t PamLevel2::GetEntry(Int_t iee){  //Int_t PamLevel2::GetEntry(Int_t iee){
3169  Int_t PamLevel2::GetEntry(Long64_t iee){  Int_t PamLevel2::GetEntry(Long64_t iee){
3170            
3171    //     cout << "-------------------------------------"<<endl;
3172    //     cout << "Int_t PamLevel2::GetEntry("<<iee<<")"<<endl;
3173    
3174      if(!pam_tree){      if(!pam_tree){
3175          cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- level2 trees not loaded"<<endl;          cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- level2 trees not loaded"<<endl;
3176          return 0;          return 0;
# Line 2692  Int_t PamLevel2::GetEntry(Long64_t iee){ Line 3199  Int_t PamLevel2::GetEntry(Long64_t iee){
3199      //      //
3200      if(!run_tree ){      if(!run_tree ){
3201          if ( TRK0 || CAL0 || TOF0 || RUN ) { //forse cosi` va bene per tornare 1?          if ( TRK0 || CAL0 || TOF0 || RUN ) { //forse cosi` va bene per tornare 1?
3202                  cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- run tree not loaded"<<endl;              cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- run tree not loaded"<<endl;
3203                  return 0;              return 0;
3204          }  else {          }  else {
3205                  return 1; //cosi` se non c'e` run esce qua...              return 1; //cosi` se non c'e` run esce qua...
3206          }          }
3207      }      }
3208    
3209      //-------------------------------      //-------------------------------
3210      ii = iee;      ii = iee;
3211  //    Bool_t UPDATED = UpdateRunInfo(run_tree,ii);  //    Bool_t UPDATED = UpdateRunInfo(run_tree,ii);
3212      Bool_t UPDATED = UpdateRunInfo(ii);  //    Bool_t UPDATED = UpdateRunInfo(ii);
3213        UpdateRunInfo(ii);
3214      if(SELLI==0)irunentry = iee-runfirstentry;      if(SELLI==0)irunentry = iee-runfirstentry;
3215      if(UPDATED && run_tree_clone)run_tree_clone->Fill();  //    if(UPDATED && run_tree_clone)run_tree_clone->Fill();
3216      
3217  //    cout << "PamLevel2::GetEntry("<<iee<<") "<<irun<<" "<<runfirstentry<<" "<<irunentry<<endl;  //    cout << "PamLevel2::GetEntry("<<iee<<") "<<irun<<" "<<runfirstentry<<" "<<irunentry<<endl;
3218    
3219      if( TRK0 || CAL0 || TOF0 )GetYodaEntry( );  //     cout << "irunentry     "<<irunentry << endl;
3220    //     cout << "runfirstentry "<<runfirstentry << endl;
3221    //     cout << "nevents       "<<GetRunInfo()->NEVENTS<< endl;
3222    
3223    //     if( TRK0 || CAL0 || TOF0 ){
3224    //      if( !GetYodaEntry( ) ){
3225    //          cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- error reading level0 tree"<<endl;
3226    //          return 0;
3227    //      }
3228    //     }
3229    
3230    
3231      return 1;      return 1;
3232    
3233  }  }
3234    
3235    TrkLevel0    *PamLevel2::GetTrkLevel0(){
3236        if( !TRK0 )return NULL;
3237        if( !GetYodaEntry( ) ){
3238            cout << " Int_t PamLevel2::GetTrkLevel0() -- ERROR -- error reading level0 tree"<<endl;
3239            return 0;
3240        }
3241        return trk0_obj;
3242    };
3243    CaloLevel0    *PamLevel2::GetCaloLevel0(){
3244        if( !CAL0 )return NULL;
3245        if( !GetYodaEntry( ) ){
3246            cout << " Int_t PamLevel2::GetCaloLevel0() -- ERROR -- error reading level0 tree"<<endl;
3247            return 0;
3248        }
3249        return calo0_obj;
3250    };
3251    
3252    
3253  /**  /**
3254   * Method to retrieve the level0 tree (YODA tree) that contains the current event.   * Method to retrieve the level0 tree (YODA tree) that contains the current event.
3255   * Given the run ID (...), if needed it query the DB and load the proper file.   * Given the run ID (...), if needed it query the DB and load the proper file.
# Line 2733  TTree* PamLevel2::GetYodaTree( ){ Line 3269  TTree* PamLevel2::GetYodaTree( ){
3269          return NULL;          return NULL;
3270      }          }    
3271      Int_t irootnew = run_obj->ID_ROOT_L0;      Int_t irootnew = run_obj->ID_ROOT_L0;
3272  //     cout << "iroot    "<<iroot<<endl;  //      cout << "iroot    "<<iroot<<endl;
3273  //     cout << "irootnew "<<irootnew<<endl;  //      cout << "irootnew "<<irootnew<<endl;
3274    
3275      //===================================      //===================================
3276      // load the level0 file      // load the level0 file
# Line 2791  TTree* PamLevel2::GetYodaTree( ){ Line 3327  TTree* PamLevel2::GetYodaTree( ){
3327              };              };
3328              l0_tree->SetBranchAddress("Tracker" ,trk0_obj->GetPointerToTrackerEvent());              l0_tree->SetBranchAddress("Tracker" ,trk0_obj->GetPointerToTrackerEvent());
3329          }          }
3330          //---------------------------------------------------          //--------------------------------------------------
3331          // CALORIMETER:          // CALORIMETER:
3332          if(CAL0){          if(CAL0){
3333              if(!calo0_obj){              if(!calo0_obj){
# Line 2841  Int_t PamLevel2::GetYodaEntry(){ Line 3377  Int_t PamLevel2::GetYodaEntry(){
3377            
3378      // patch      // patch
3379      if( irunentry < 0){      if( irunentry < 0){
3380          cout << "Int_t PamLevel2::GetYodaEntry() -- ATTENZIONE -- irunentry negativo?!?! "<<(Int_t)irunentry<<endl;  //      cout << "Int_t PamLevel2::GetYodaEntry() -- ATTENZIONE -- irunentry negativo?!?! "<<(Int_t)irunentry<<endl;
3381          irunentry=0LL;          irunentry=0LL;
3382      }      }
3383      //  ---------------------------------      //  ---------------------------------
3384      //  if file is NOT a preselected file      //  if file is NOT a preselected file
3385      //  ---------------------------------      //  ---------------------------------
3386      Long64_t quellagiusta = irunentry + (Long64_t)(run_obj->EV_FROM);      Long64_t quellagiusta = irunentry + (Long64_t)(run_obj->EV_FROM);
3387        //     cout << " irunentry "<<irunentry<<endl;
3388    //     cout << " EV_FROM "<<run_obj->EV_FROM<<endl;
3389    //     cout << " quellagiusta = irunentry + EV_FROM "<< quellagiusta << endl;
3390    
3391  //     cout << " irun "<< irun << " irunentry "<< irunentry<<" run_obj->EV_FROM "<<run_obj->EV_FROM <<" quella giusta "<<quellagiusta << endl;  //     cout << " irun "<< irun << " irunentry "<< irunentry<<" run_obj->EV_FROM "<<run_obj->EV_FROM <<" quella giusta "<<quellagiusta << endl;
3392  //     cout << " iroot "<<iroot<<" run_obj->ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<endl;  //     cout << " iroot "<<iroot<<" run_obj->ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<endl;
3393  //     cout << " time "<< GetOrbitalInfo()->absTime << endl;  //     cout << " time "<< abstime << endl;
3394  //     cout << " trk_calib_used "<<run_obj->TRK_CALIB_USED<< endl;  //     cout << " trk_calib_used "<<run_obj->TRK_CALIB_USED<< endl;
3395            
3396      if( !GetOrbitalInfo() ){      ULong64_t obt     = 0;
3397        ULong64_t pktn    = 0;
3398        if( GetOrbitalInfo() ){
3399            obt     = GetOrbitalInfo()->OBT;
3400            pktn    = GetOrbitalInfo()->pkt_num;
3401        }
3402    
3403        if( !GetOrbitalInfo() && !ISGP){
3404          cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing OrbitalInfo "<<endl;          cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing OrbitalInfo "<<endl;
3405          return 0;          return 0;
3406      }      }
3407      if( GetOrbitalInfo()->OBT==0 && GetOrbitalInfo()->pkt_num==0 ){      if( obt==0 && pktn==0 && !ISGP ){
3408          cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- level2 event corrupted ?? "<<endl;          cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- level2 event corrupted ?? "<<endl;
3409          return 0;          return 0;
3410      }      }
# Line 2878  Int_t PamLevel2::GetYodaEntry(){ Line 3423  Int_t PamLevel2::GetYodaEntry(){
3423      Int_t answer = 0;      Int_t answer = 0;
3424      Int_t shift =0;      Int_t shift =0;
3425      //    printf(" siamo qui %i %i \n",shift,prevshift);      //    printf(" siamo qui %i %i \n",shift,prevshift);
3426        Int_t maxshift = 10;
3427      do{      do{
3428          if(shift>0){              if(shift>0){    
3429              cout << " level0 <--> level2 mismatch ( irun "<<irun<<" irunentry "<<irunentry<<" shift "<<shift<<" prevshift "<<prevshift<<" )"<<endl;              cout << " PKTNUM  L2 --- "<< pktn << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl;
3430                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;
3431                cout << "         L2 <--> L0 mismatch ( irun "<<irun<<" irunentry "<<irunentry<<" shift "<<shift<<" prevshift "<<prevshift<<" )"<<endl;
3432          }          }
3433          answer = l0_tree->GetEntry(quellagiusta+(Long64_t)shift+(Long64_t)prevshift);          answer = l0_tree->GetEntry(quellagiusta+(Long64_t)shift+(Long64_t)prevshift);
3434          shift++;          shift++;
# Line 2888  Int_t PamLevel2::GetYodaEntry(){ Line 3436  Int_t PamLevel2::GetYodaEntry(){
3436              cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing EventHeader "<<endl;              cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing EventHeader "<<endl;
3437              return 0;              return 0;
3438          }          }
3439  //      cout << "PKTNUM "<<shift<<" ==  L2 --- "<< GetOrbitalInfo()->pkt_num << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl;  
3440  //      cout << " L2 --- "<< GetOrbitalInfo()->OBT << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime()<<endl;          if(ISGP){
3441                obt = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()); //BARBATRUCCO
3442                pktn = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter()); //BARBATRUCCO
3443            }
3444    
3445    //      cout << "PKTNUM "<<shift<<" ==  L2 --- "<< pktn << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl;
3446    //      cout << " L2 --- "<< obt << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime()<<endl;
3447  //      if( (quellagiusta+shift) == l0_tree->GetEntries()+1 )cout << ">>> end of level0 tree <<<"<<endl;  //      if( (quellagiusta+shift) == l0_tree->GetEntries()+1 )cout << ">>> end of level0 tree <<<"<<endl;
3448  //      cout << " GetOrbitalInfo()->OBT "<< GetOrbitalInfo()->OBT << endl;  //      cout << " obt "<< obt << endl;
3449  //      cout << " GetEventHeader()->GetPscuHeader()->GetOrbitalTime() "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime() << endl;  //      cout << " GetEventHeader()->GetPscuHeader()->GetOrbitalTime() "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime() << endl;
3450  //      cout << " GetOrbitalInfo()->pkt_num "<< GetOrbitalInfo()->pkt_num << endl;  //      cout << " pktn "<< pktn << endl;
3451  //      cout << " GetEventHeader()->GetPscuHeader()->GetCounter() "<< GetEventHeader()->GetPscuHeader()->GetCounter() << endl;  //      cout << " GetEventHeader()->GetPscuHeader()->GetCounter() "<< GetEventHeader()->GetPscuHeader()->GetCounter() << endl;
3452  //      printf(" IDRUN %u \n",GetRunInfo()->ID);  //      printf(" IDRUN %u \n",GetRunInfo()->ID);
3453  //  //
# Line 2902  Int_t PamLevel2::GetYodaEntry(){ Line 3456  Int_t PamLevel2::GetYodaEntry(){
3456            shift = -1;            shift = -1;
3457          };          };
3458    
3459      }while( ( GetOrbitalInfo()->OBT != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) || GetOrbitalInfo()->pkt_num != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter())) && (quellagiusta+(Long64_t)shift) < GetYodaTree()->GetEntries() );      }while( ( obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) ||
3460                  pktn != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter())       )
3461      if ( (quellagiusta+(Long64_t)shift) == GetYodaTree()->GetEntries() ) cout << " Big trouble here, no such event in Level0 data! " <<endl;              && (quellagiusta+(Long64_t)shift) < GetYodaTree()->GetEntries() && shift < maxshift);
3462    
3463        if ( (quellagiusta+(Long64_t)shift+(Long64_t)prevshift) > GetYodaTree()->GetEntries() || shift == maxshift ) {
3464            cout << " Big trouble here, no such event in Level0 data! " <<endl;
3465            return 0;
3466        }
3467  //    cout << "LA ENTRY GIUSTA E`: "<<quellagiusta<<" (spero...)"<<endl;  //    cout << "LA ENTRY GIUSTA E`: "<<quellagiusta<<" (spero...)"<<endl;
3468  //    return GetYodaTree()->GetEntry(quellagiusta);  //    return GetYodaTree()->GetEntry(quellagiusta);
3469      if ( shift > 1 ) prevshift += (shift-1);      if ( shift > 1 ) prevshift += (shift-1);
# Line 2913  Int_t PamLevel2::GetYodaEntry(){ Line 3471  Int_t PamLevel2::GetYodaEntry(){
3471      return answer;      return answer;
3472            
3473  }  }
3474    /**
3475     * \Brief Set DB connection
3476     */
3477    Bool_t PamLevel2::SetDBConnection(){
3478    
3479        cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
3480        cout<<"Connecting to DB"<<endl;
3481        cout<<"HOST "<<host<<endl;
3482        cout<<"USER "<<user<<endl;
3483        cout<<"PSW  "<<psw<<endl;
3484        dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
3485        if( !dbc )return false;
3486        if( !dbc->IsConnected() )return false;    
3487        cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
3488        return true;
3489    
3490    }
3491    
3492    /**
3493     * \Brief Add a friend to the pamela chain.
3494     * @param cname name of the chain to be added
3495     */
3496    
3497    TChain* PamLevel2::AddFriend(TString cname){
3498    
3499        if(!GetPamTree()){
3500            cout << " TChain* PamLevel2::AddFriend(TString cname) --- a pamela tree must be created first"<<endl;
3501            return NULL;
3502        }
3503    
3504    
3505        TChain *c = new TChain( cname.Data() );
3506    
3507        TIter next( GetPamTree()->GetListOfFiles() );
3508        Int_t nf = 0;
3509        TChainElement* element = 0;    
3510        while ((element = (TChainElement*) next())) {      
3511            c->Add(element->GetTitle());
3512            nf++;
3513        }
3514    
3515        GetPamTree()->AddFriend(cname.Data());
3516    
3517        cout << "external chain created and added to pamela friends :"<<cname<<endl;
3518        cout << "n.files "<<nf<<endl;
3519        
3520    
3521        return c;    
3522    
3523    }

Legend:
Removed from v.1.35  
changed lines
  Added in v.1.46

  ViewVC Help
Powered by ViewVC 1.1.23