/[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.37 by mocchiut, Wed Mar 28 15:29:14 2007 UTC revision 1.47 by mocchiut, Wed Sep 12 09:39:32 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            
# Line 304  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 401  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 623  void PamLevel2::SortTracks(TString how){ Line 636  void PamLevel2::SortTracks(TString how){
636  void PamLevel2::SortTracks(){  void PamLevel2::SortTracks(){
637    TString how = howtosort;    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():  TrkLevel2 not loaded !!!";      cout << "void PamLevel2::SortTracks():  TrkLevel2 not loaded !!!";
642      return;      return;
# Line 646  void PamLevel2::SortTracks(){ Line 659  void PamLevel2::SortTracks(){
659    TClonesArray &ttimage = *timage;    TClonesArray &ttimage = *timage;
660    
661    
662    // loop over the tracks sorted by the tracker  
663      //--------------------------------------------------
664      // retrieve sorting method
665      //--------------------------------------------------
666    Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);    Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);
667    Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);    Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);
668    Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase);    Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase);
669          Bool_t use_S1 = how.Contains("S1", TString::kIgnoreCase);
670      Bool_t use_S2 = how.Contains("S2", TString::kIgnoreCase);
671      Bool_t use_S3 = how.Contains("S3", TString::kIgnoreCase);
672      
673      if ( use_TOF ){
674        use_S1 = true;
675        use_S2 = true;
676        use_S3 = true;
677      };
678    if( !CAL2 &&  use_CAL) use_CAL = false;    if( !CAL2 &&  use_CAL) use_CAL = false;
679    if( !TOF &&  use_TOF) use_TOF = false;    if( !TOF ){
680            use_TOF = false;
681        use_S1  = false;
682        use_S2  = false;
683        use_S3  = false;
684      }
685    
686    if( !TRK2 ){    if( !TRK2 ){
687      //  cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl;      //  cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl;
688      return;      return;
689    };    };
690    
691    //   cout << "use_CAL "<<use_CAL<<" use_TOF "<<use_TOF<<" use_TRK "<<use_TRK <<endl;    //   cout << "use_CAL "<<use_CAL<<" use_TOF "<<use_TOF<<" use_TRK "<<use_TRK <<endl;
692          
693    
694      //--------------------------------------------------
695      // loop over "physical" tracks sorted by the tracker
696      //--------------------------------------------------
697    for(Int_t i=0; i < trk2_obj->TrkLevel2::GetNTracks(); i++){    for(Int_t i=0; i < trk2_obj->TrkLevel2::GetNTracks(); i++){
698                    
699      TrkTrack   *ts = 0;      TrkTrack   *ts = 0;
# Line 668  void PamLevel2::SortTracks(){ Line 701  void PamLevel2::SortTracks(){
701      ToFTrkVar  *os = 0;      ToFTrkVar  *os = 0;
702                    
703      // get tracker tracks      // get tracker tracks
704      TrkTrack   *tp = trk2_obj->TrkLevel2::GetTrack(i);                    //tracker      TrkTrack   *tp = trk2_obj->TrkLevel2::GetTrack(i); //tracker
705      CaloTrkVar *cp = GetCaloStoredTrack(tp->GetSeqNo());      CaloTrkVar *cp = GetCaloStoredTrack(tp->GetSeqNo());
706      ToFTrkVar  *op = GetToFStoredTrack(tp->GetSeqNo());      ToFTrkVar  *op = GetToFStoredTrack(tp->GetSeqNo());
707    
708      TrkTrack   *ti = 0;              //tracker (image)      TrkTrack   *ti = 0; //tracker (image)
709      CaloTrkVar *ci = 0;      CaloTrkVar *ci = 0;
710      ToFTrkVar  *oi = 0;      ToFTrkVar  *oi = 0;
711      //  cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;      //  cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;
712      // if track has an image, check image selection      // 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()){      if(tp->HasImage()){
720                            
721        ti = trk2_obj->TrkLevel2::GetTrackImage(i);              //tracker (image)        ti = trk2_obj->TrkLevel2::GetTrackImage(i);              //tracker (image)
# Line 686  void PamLevel2::SortTracks(){ Line 725  void PamLevel2::SortTracks(){
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(): howtosort= "<<how<<" but CaloLevel2 not loaded !!!";          cout << "void PamLevel2::SortTracks(): howtosort= "<<how<<" but CaloLevel2 not loaded !!!";
738          return;          return;
739        };        };
740          if( use_CAL && !cp &&  ci ){
741            ti_score++;
742            toti_score++;
743          };
744          if( use_CAL &&  cp && !ci ){
745            tp_score++;
746            totp_score++;
747          };
748        if(        if(
749           use_CAL            &&           use_CAL            &&
750           calo2_obj->npcfit[1] > 5     &&   //no. of fit planes on Y view  //       calo2_obj->npcfit[1] > 5     &&   //no. of fit planes on Y view
751           calo2_obj->varcfit[1] < 1000. &&  //fit variance on Y view  //       calo2_obj->varcfit[1] < 1000. &&  //fit variance on Y view
752           cp && ci &&           cp && ci &&
753           true){           true){
754    
755                                    
756          Float_t resy_p = cp->tbar[0][1] - calo2_obj->cbar[0][1]; if(resy_p < 0)resy_p= - resy_p;  //      Float_t resy_p = cp->tbar[0][1] - calo2_obj->cbar[0][1]; if(resy_p < 0)resy_p= - resy_p;
757          Float_t resy_i = ci->tbar[0][1] - calo2_obj->cbar[0][1]; if(resy_i < 0)resy_i= - resy_i;  //      Float_t resy_i = ci->tbar[0][1] - calo2_obj->cbar[0][1]; if(resy_i < 0)resy_i= - resy_i;
758                                    
759          if(resy_p <= resy_i) tp_score++;  //      if(resy_p <= resy_i) tp_score++;
760          else                 ti_score++;  //      else                 ti_score++;
761                    
762    
763            if( cp->npresh > ci->npresh){
764              tp_score++;
765              totp_score++;
766            };
767            if( cp->npresh < ci->npresh){
768              ti_score++;
769              toti_score++;
770            };
771    
772          //      cout << "CALO "<<tp_score<<ti_score<<endl;          //      cout << "CALO "<<tp_score<<ti_score<<endl;
773    
774        };        };
775        // ------------------------        // -----------------------------------------------------------------------------------------
776        // TOF check        // TOF check
777        // ------------------------                  // -----------------------------------------------------------------------------------------
778        // check the number of hit pmts along the track        // check the number of hit pmts along the track
779        // on S12 S21 and S32, where paddles are parallel to Y axis        // on S12 S21 and S32, where paddles are parallel to Y axis
780        if( use_TOF && !tof_obj ){        if( (use_TOF || use_S1 || use_S2 || use_S3 ) && !tof_obj ){
781          cout << "void PamLevel2::SortTracks(): howtosort= "<<how<<" but ToFLevel2 not loaded !!!";          cout << "void PamLevel2::SortTracks(): howtosort= "<<how<<" but ToFLevel2 not loaded !!!";
782          return;          return;
783        };        };
784        if( use_TOF && op && oi ){        //
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.;          Float_t sen = 0.;
796          for (Int_t ih=0; ih < op->npmtadc; ih++){          for (Int_t ih=0; ih < op->npmtadc; ih++){
# Line 737  void PamLevel2::SortTracks(){ Line 802  void PamLevel2::SortTracks(){
802            if ( pl == 2 || pl == 3 || pl == 4 || pl == 5 ) sen += (oi->dedx).At(ih);            if ( pl == 2 || pl == 3 || pl == 4 || pl == 5 ) sen += (oi->dedx).At(ih);
803          };          };
804          //          //
805          if (  sen >= sortthr ){          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);            //printf(" IS A NUCLEUS! en = %f \n",sen);
807            //            //
808            // is a nucleus use a different algorithm            // is a nucleus use a different algorithm
# Line 830  void PamLevel2::SortTracks(){ Line 895  void PamLevel2::SortTracks(){
895    
896                                    
897            if(            if(
898               use_TOF            &&               (use_TOF || use_S1 || use_S2 || use_S3)            &&
899               (nphit_p+nphit_i) !=0 &&                 (nphit_p+nphit_i) !=0 &&  
900               true){               true){
901                                            
# Line 863  void PamLevel2::SortTracks(){ Line 928  void PamLevel2::SortTracks(){
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++){
937    //          Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
938    //          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            for (Int_t ih=0; ih < oi->npmtadc; ih++){            for (Int_t ih=0; ih < oi->npmttdc; ih++){
951              Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );              Int_t pl = tof_obj->GetPlaneIndex( (oi->pmttdc).At(ih) );
952              if(pl == 1 || pl == 2 || pl == 5)nphit_i++;  //          if( (oi->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_i++;  
953                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++;  
955                };
956            };            };
957                                    
958            if(            if(
              use_TOF            &&  
959               (nphit_p+nphit_i) !=0 &&                 (nphit_p+nphit_i) !=0 &&  
960               true){               true){
961                                            
962              if( nphit_p >= nphit_i) tp_score++;              if ( nphit_p != nphit_i ){
963              else ti_score++;                totp_score += nphit_p;
964                  toti_score += nphit_i;
965                  tp_score+=nphit_p;
966                  ti_score+=nphit_i;
967                };
968                //      if     ( nphit_p > nphit_i) tp_score+=nphit_p;
969                //      else if( nphit_p < nphit_i) ti_score+=nphit_i;
970                //      else ;//niente
971            };            };
972          };          };
973          //      cout << "TOF "<<tp_score<<ti_score<<endl;          //      cout << "TOF "<<tp_score<<ti_score<<endl;
974        };        };
975        if(tp_score == ti_score) use_TRK = true;  
976        // ------------------------  
977    //      if(tp_score == ti_score) use_TRK = true;
978    
979    
980          // -----------------------------------------------------------------------------------------
981        // tracker check        // tracker check
982        // ------------------------        // -----------------------------------------------------------------------------------------
983        // chi**2 difference is not always large enough to distinguish among        // chi**2 difference is not always large enough to distinguish among
984        // the real track and its image.        // the real track and its image.
985        // Tracker check will be applied always when calorimeter and tof information is ambiguous.        // Tracker check will be applied always when calorimeter and tof information is ambiguous.
986          // *** MODIFIED ON AUGUST 2007 ***
987        if(use_TRK){        if(use_TRK){
988          if(      tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ;  //      if(      tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ;
989          else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ;  //      else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ;
990    
991              // CHECK 1 : number of points along X  
992            if ( tp->GetNX() >= ti->GetNX() ){
993              tp_score++ ;
994              totp_score++ ;
995            };
996            if ( tp->GetNX() <= ti->GetNX() ){
997              ti_score++ ;
998              toti_score++ ;
999            };
1000              // CHECK 2 : number of points along Y  
1001            if ( tp->GetNY() >= ti->GetNY() ){
1002              tp_score++ ;
1003              totp_score++ ;
1004            };
1005            if ( tp->GetNY() <= ti->GetNY() ){
1006              ti_score++ ;
1007              toti_score++ ;
1008            };
1009              // CHECK 3 : chi**2 along X  
1010    //        if(      tp->GetChi2X() > 0 && (tp->GetChi2X() < ti->GetChi2X() || ti->GetChi2X() <=0) ) tp_score++ ;
1011    //        if(      ti->GetChi2X() > 0 && (ti->GetChi2X() < tp->GetChi2X() || tp->GetChi2X() <=0) ) ti_score++ ;
1012              // CHECK 4 : chi**2 along Y  
1013    //        if(      tp->GetChi2Y() > 0 && (tp->GetChi2Y() < ti->GetChi2Y() || ti->GetChi2Y() <=0) ) tp_score++ ;
1014    //        if(      ti->GetChi2Y() > 0 && (ti->GetChi2Y() < tp->GetChi2Y() || tp->GetChi2Y() <=0) ) ti_score++ ;
1015              // CHECK 5 : total chi**2  
1016    //        if(      tp->chi2 > 0 && (tp->chi2 < ti->chi2 || ti->chi2 <=0) ) tp_score++ ;
1017    //        if(      ti->chi2 > 0 && (ti->chi2 < tp->chi2 || tp->chi2 <=0) ) ti_score++ ;
1018    
1019          //      cout << "TRK "<<tp_score<<ti_score<<endl;          //      cout << "TRK "<<tp_score<<ti_score<<endl;
1020        };        };
1021                            
1022        // ------------------------  
1023    
1024          // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1025        // the winner is....        // the winner is....
1026        // ------------------------                  // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1027        if      (tp_score > ti_score) {        if      (tp_score > ti_score) {
1028          //              ts = tp;//the track sorted by the tracker!!          
         //              cs = cp;  
         //              os = op;  
         //      cout << "It's primary!" << endl;  
1029    
1030        }else if (tp_score < ti_score) {        }else if (tp_score < ti_score) {
1031    
         //      cout << "It's image!" << endl;  
1032    
1033          ts = ti;//its image!!          ts = ti;//its image!!
1034          cs = ci;          cs = ci;
# Line 924  void PamLevel2::SortTracks(){ Line 1044  void PamLevel2::SortTracks(){
1044    
1045                                    
1046        }else {        }else {
1047          //              ts = tp;  
1048          //              cs = cp;  //      cout << "Warning - track image ambiguity not solved" << endl;
1049          //              os = op;  
         cout << "Warning - track image ambiguity not solved" << endl;  
         //                              cout << ts->GetNtot() << " "<< ts->chi2 << " " << npcfit[1] << " "<< nphit_p << endl;  
1050        };        };
1051                            
1052      }else{      }else{
1053          totp_score = 1;
1054          toti_score = 0;
1055          
1056        //            ts = tp;        //            ts = tp;
1057        //            cs = cp;        //            cs = cp;
1058        //            os = op;        //            os = op;
# Line 945  void PamLevel2::SortTracks(){ Line 1066  void PamLevel2::SortTracks(){
1066      //  cout<<"o "<<tp<<endl;      //  cout<<"o "<<tp<<endl;
1067      //  cout<<"o "<<cp<<endl;      //  cout<<"o "<<cp<<endl;
1068      //  cout<<"o "<<op<<endl;      //  cout<<"o "<<op<<endl;
1069    
1070      new(ttsorted[i]) PamTrack(tp,cp,op);      new(ttsorted[i]) PamTrack(tp,cp,op);
1071      new(ttimage[i])  PamTrack(ti,ci,oi);      new(ttimage[i])  PamTrack(ti,ci,oi);
1072    
1073        ((PamTrack*)(ttsorted[i]))->SetPScore(totp_score);
1074        ((PamTrack*)(ttimage[i]))->SetIScore(toti_score);
1075    };    };
1076    
1077    if( tsorted->GetEntries() != trk2_obj->GetNTracks() ){    if( tsorted->GetEntries() != trk2_obj->GetNTracks() ){
# Line 1863  Bool_t PamLevel2::UpdateRunInfo(TChain * Line 1988  Bool_t PamLevel2::UpdateRunInfo(TChain *
1988        //        //
1989        // the absolute time is necessary to relate the event with the run        // the absolute time is necessary to relate the event with the run
1990        //        //
1991        if( !GetOrbitalInfo() ){        if( !GetOrbitalInfo() && !ISGP){
1992            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;
1993            return(false);            return(false);
1994        }        }
1995    
1996          ULong64_t abstime = 0;
1997          if( GetOrbitalInfo() )abstime=GetOrbitalInfo()->absTime;
1998    
1999    
2000        //        //
2001        // the first time the routine is called, set run search from the beginning        // the first time the routine is called, set run search from the beginning
2002        //        //
# Line 1877  Bool_t PamLevel2::UpdateRunInfo(TChain * Line 2006  Bool_t PamLevel2::UpdateRunInfo(TChain *
2006            runfirstentry = 0LL;            runfirstentry = 0LL;
2007            runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);            runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
2008            if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;            if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;
2009              
2010              if( ISGP && run->GetEntries()!=1 ){
2011                  cout << "** WARNING ** simulated files are assumed to have 1 single run, not "<< run->GetEntries() << endl;
2012                  cout << "** WARNING ** run will not be updated"<<endl;
2013              }
2014    
2015        };              };      
2016        //        //
2017         if ( irun == run->GetEntries()-1LL &&        if(ISGP)abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO
2018             !(GetOrbitalInfo()->absTime >= GetRunInfo()->RUNHEADER_TIME &&        //
2019               GetOrbitalInfo()->absTime <= GetRunInfo()->RUNTRAILER_TIME)        if ( irun == run->GetEntries()-1LL &&
2020               !(abstime >= GetRunInfo()->RUNHEADER_TIME &&
2021                 abstime <= GetRunInfo()->RUNTRAILER_TIME)
2022              ){              ){
2023           irun = -1LL;           irun = -1LL;
2024           runfirstentry = 0LL;           runfirstentry = 0LL;
# Line 1892  Bool_t PamLevel2::UpdateRunInfo(TChain * Line 2029  Bool_t PamLevel2::UpdateRunInfo(TChain *
2029        //        //
2030        bool fromfirst = true;        bool fromfirst = true;
2031        //        //
2032        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 ){
2033  //      while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){  //      while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){
2034            irun++;            irun++;
2035            run->GetEntry(irun);            run->GetEntry(irun);
# Line 1902  Bool_t PamLevel2::UpdateRunInfo(TChain * Line 2039  Bool_t PamLevel2::UpdateRunInfo(TChain *
2039  //        cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;  //        cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2040  //        cout << "runfirstentry "<<runfirstentry<<endl;  //        cout << "runfirstentry "<<runfirstentry<<endl;
2041            //      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)));
2042            //      printf(" abstime %u trailertime %u \n",GetOrbitalInfo()->absTime,GetRunInfo()->RUNTRAILER_TIME);            //      printf(" abstime %u trailertime %u \n",abstime,GetRunInfo()->RUNTRAILER_TIME);
2043            //      printf(" IDRUN %u \n",GetRunInfo()->ID);            //      printf(" IDRUN %u \n",GetRunInfo()->ID);
2044            //            //
2045  //        prevshift = 0;  //        prevshift = 0;
2046            //            //
2047            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)){
2048                printf(" resetting irun  (it should NOT happen!!!)\n");                printf(" resetting irun  (it should NOT happen!!!)\n");
2049                fromfirst = false;                fromfirst = false;
2050                irun = 0;                irun = 0;
# Line 1920  Bool_t PamLevel2::UpdateRunInfo(TChain * Line 2057  Bool_t PamLevel2::UpdateRunInfo(TChain *
2057        };        };
2058        //        //
2059        if (        if (
2060             !(GetOrbitalInfo()->absTime >= GetRunInfo()->RUNHEADER_TIME &&             !(abstime >= GetRunInfo()->RUNHEADER_TIME &&
2061               GetOrbitalInfo()->absTime <= GetRunInfo()->RUNTRAILER_TIME)               abstime <= GetRunInfo()->RUNTRAILER_TIME)
2062            ) {            ) {
2063            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);
2064            return false;            return false;
2065        }        }
2066        //        //
# Line 1975  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2112  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2112      if(SELLI==0){      if(SELLI==0){
2113    
2114          // ---------------------------------------------------------------          // ---------------------------------------------------------------
2115            // increment dead and live-time counters
2116            // ---------------------------------------------------------------
2117            if( GetTrigLevel2() ){
2118                totdltime[0]+=GetTrigLevel2()->dltime[0];
2119                totdltime[1]+=GetTrigLevel2()->dltime[1];
2120            }
2121            totdltime[2]++;
2122    
2123    //      cout << setw(10)<<totdltime[0]<<setw(10)<<totdltime[1]<<setw(10)<<totdltime[2]<<endl;
2124    
2125            // ---------------------------------------------------------------
2126            // retrieve OBT and absolute time of the event
2127            // ---------------------------------------------------------------
2128            ULong64_t abstime = 0;
2129            ULong64_t obt     = 0;
2130            if( GetOrbitalInfo() ){
2131                abstime = GetOrbitalInfo()->absTime;
2132                obt     = GetOrbitalInfo()->OBT;
2133            }
2134            // ---------------------------------------------------------------
2135          // the absolute time is necessary to relate the event with the run          // the absolute time is necessary to relate the event with the run
2136          // ---------------------------------------------------------------          // ---------------------------------------------------------------
2137          if( !GetOrbitalInfo() ){          if( !GetOrbitalInfo() && !ISGP ){
2138              cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;              cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;
2139              return(false);              return(false);
2140          }          }
# Line 1987  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2144  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2144          // -----------------------------------------------------------------------          // -----------------------------------------------------------------------
2145          if ( irun < 0 ){          if ( irun < 0 ){
2146              irun = 0LL;              irun = 0LL;
2147                irunentry = 0;
2148                prevshift = 0;
2149              run_tree->GetEntry(irun);              run_tree->GetEntry(irun);
2150    
2151                if( ISGP && run_tree->GetEntries()!=1 ){
2152                    cout << "** WARNING ** simulated files are assumed to have 1 single run, not "<< run_tree->GetEntries() << endl;
2153                    cout << "** WARNING ** run will not be updated"<<endl;
2154                }
2155          };                };      
2156    
2157            // -----------------------------------------------------------------------
2158            // if it is simulation, assigh abstime by hand (temporaneo!!!)
2159            // -----------------------------------------------------------------------
2160            if(ISGP){
2161                abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO
2162                obt     = GetRunInfo()->RUNHEADER_OBT; // BARBATRUCCO
2163            }
2164          //          //
2165          bool fromfirst = true; // first loop over runs          bool fromfirst = true; // first loop over runs
2166    
2167    //      Bool_t hasfrag = false;
2168    //      if( GetRunInfo()->ID_RUN_FRAG!=0 && GetRunInfo()->ID_RUN_FRAG != GetRunInfo()->ID)hasfrag=true;
2169    //      ULong64_t fragid = GetRunInfo()->ID_RUN_FRAG;
2170    
2171          // ------------------------------------------------------          // ------------------------------------------------------
2172          // loop over runs to find the one that contains the event          // loop over runs to find the one that contains the event
2173          // ------------------------------------------------------          // ------------------------------------------------------
2174          while ( !(GetOrbitalInfo()->absTime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s)          while (
2175                    GetOrbitalInfo()->absTime <= GetRunInfo()->RUNTRAILER_TIME) &&              (
2176                  !(GetOrbitalInfo()->OBT >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms)                  (
2177                    GetOrbitalInfo()->OBT <= GetRunInfo()->RUNTRAILER_OBT) &&                      !(abstime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s)
2178                  irun < run_tree->GetEntries() ){                        abstime <= GetRunInfo()->RUNTRAILER_TIME) &&
2179                        !(obt >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms)
2180                          obt <= GetRunInfo()->RUNTRAILER_OBT)
2181                        )
2182                    || GetRunInfo()->NEVENTS==0
2183                    || !(irunentry < GetRunInfo()->NEVENTS-1-prevshift)
2184                    )
2185                    && irun < run_tree->GetEntries() ){
2186    
2187    
2188    
2189    
2190                // -----------------------------------------
2191                // store dead and live-time of previous run
2192                // -----------------------------------------
2193                if(fromfirst){
2194                    if(oldrun==irun){
2195                        /// decrement counters
2196                        if( GetTrigLevel2()){
2197                            totdltime[0]-=GetTrigLevel2()->dltime[0];//live-time
2198                            totdltime[1]-=GetTrigLevel2()->dltime[1];//dead-time
2199                        }
2200                        totdltime[2]--;                              //event counter
2201                        cout << endl;
2202                        cout << "n.events     : "<<totdltime[2]<<endl;
2203                        cout << "RUN LIVE-TIME: "<<totdltime[0]*0.16<<" ms"<<endl;
2204                        cout << "RUN DEAD-TIME: "<<totdltime[1]*0.01<<" ms"<<endl;      
2205                    }else{
2206                        totdltime[0]=0;//live-time
2207                        totdltime[1]=0;//dead-time
2208                        totdltime[2]=0;                             //event counter
2209                        cout << " *** JUMP RUN *** irun "<<irun<<endl;
2210                    }
2211                    /// add an entry
2212                    if(run_tree_clone)
2213                        if(run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())
2214                            run_tree_clone->GetBranch("DeadLiveTime")->Fill();
2215                    /// reset counters
2216                    if( GetTrigLevel2() ){
2217                        totdltime[0]=GetTrigLevel2()->dltime[0];//live-time
2218                        totdltime[1]=0;                         //dead-time
2219                    }
2220                    totdltime[2]=1;                             //event counter
2221                }
2222    
2223    
2224              irun++;              irun++;
2225              // ------------------------------------              // ------------------------------------
2226              // if the end of run tree is reached...              // if the end of run tree is reached...
# Line 2024  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2246  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2246              // save the index of the first entry of the run, relative to pam_tree,              // save the index of the first entry of the run, relative to pam_tree,
2247              // and read a new run              // and read a new run
2248              // -------------------------------------------------------------------              // -------------------------------------------------------------------
2249              if(irun>0)runfirstentry += (GetRunInfo()->NEVENTS);              if(irun>0)runfirstentry += (GetRunInfo()->NEVENTS)-prevshift;
2250                irunentry = 0;
2251                prevshift = 0;          
2252              run_tree->GetEntry(irun);                    run_tree->GetEntry(irun);      
2253              if(GetRunInfo()->RUNHEADER_OBT>=GetRunInfo()->RUNTRAILER_OBT ){              if(GetRunInfo()->RUNHEADER_OBT>GetRunInfo()->RUNTRAILER_OBT ){
2254                  cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- irun "<<irun<<"  has RUNHEADER_OBT>=RUNTRAILER_OBT " <<endl;                  cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- irun "<<irun<<"  has RUNHEADER_OBT>=RUNTRAILER_OBT " <<endl;
2255                  cout << "                                                            (NB!! in this case some events are assigned to a wrong run)"<<endl;                  cout << "                                                            (NB!! in this case some events are assigned to a wrong run)"<<endl;
2256              }              }
2257    //          if(hasfrag &&  fragid != GetRunInfo()->ID){
2258    //              cout << "... where is the next fragment ??"<<endl;
2259    //          }
2260          };          };
2261    
2262    
2263          // --------------------------------------          // --------------------------------------
2264          // if there was no need to update the run          // if there was no need to update the run
2265          // ---> exit with FALSE          // ---> exit with FALSE
# Line 2039  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2268  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2268    
2269          // --------------------------------------          // --------------------------------------
2270          // ... otherwise          // ... otherwise
2271            // --------------------------------------
2272    
2273    
2274    
2275    //      // -----------------------------------------
2276    //      // store dead and live-time of previous run
2277    //      // -----------------------------------------
2278    //      // --------------------------------------------------------------
2279    //      // if the run is empty, fill the dead-live time branch with zeros
2280    //      // --------------------------------------------------------------
2281    //      /// if some runs have been jumped, fill with zeros
2282    //      if(irun-oldrun>1){
2283    //          ULong64_t  temp[3];
2284    //          temp[0]=totdltime[0];
2285    //          temp[1]=totdltime[1];
2286    //          temp[2]=totdltime[2];
2287    //          for(int i=oldrun+1; i<irun; irun++){
2288    //              totdltime[0]=0;
2289    //              totdltime[1]=0;
2290    //              totdltime[2]=0;
2291    //              cout << " ** JUMPED RUN **"<<endl;
2292    //              if(run_tree_clone)
2293    //                  if(run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())
2294    //                      run_tree_clone->GetBranch("DeadLiveTime")->Fill();
2295    //          }
2296    //          totdltime[0]=temp[0];
2297    //          totdltime[1]=temp[1];
2298    //          totdltime[2]=temp[2];
2299    //      }
2300    //      /// decrement counters
2301    //      if( GetTrigLevel2() ){
2302    //          totdltime[0]-=GetTrigLevel2()->dltime[0];//live-time
2303    //          totdltime[1]-=GetTrigLevel2()->dltime[1];//dead-time
2304    //      }
2305    //      totdltime[2]--;                              //event counter
2306    //      /// add an entry
2307    //      if(irun>0 ){
2308    //          cout << endl;
2309    //          cout << "n.events     : "<<totdltime[2]<<endl;
2310    //          cout << "RUN LIVE-TIME: "<<totdltime[0]*0.16<<" ms"<<endl;
2311    //          cout << "RUN DEAD-TIME: "<<totdltime[1]*0.01<<" ms"<<endl;      
2312    //          if(run_tree_clone)
2313    //              if(run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())
2314    //                  run_tree_clone->GetBranch("DeadLiveTime")->Fill();
2315    //      }
2316    //      /// reset counters
2317    //      if( GetTrigLevel2() ){
2318    //          totdltime[0]=GetTrigLevel2()->dltime[0];//live-time
2319    //          totdltime[1]=0;                         //dead-time
2320    //      }
2321    //      totdltime[2]=1;                             //event counter
2322            
2323    
2324            // --------------------------------------
2325          // ---> exit with TRUE          // ---> exit with TRUE
2326          // --------------------------------------          // --------------------------------------
2327          cout << endl << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;          cout << endl << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2328          prevshift = 0;          // ----------------------------------------------------
2329            // then check if the run has a fragment
2330            // in this case we have to switch to the next fragment
2331            // when the end of the first fragment is reached
2332            // ----------------------------------------------------
2333            if(
2334                GetRunInfo()->ID_RUN_FRAG != 0 &&
2335    //          GetRunInfo()->ID_RUN_FRAG != GetRunInfo()->ID &&
2336                true ){
2337                cout << "* fragment *"<<endl;              
2338            }
2339    
2340          return(true);              return(true);    
2341      };      };
2342      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# Line 2691  void PamLevel2::CreateCloneTrees0( TChai Line 2985  void PamLevel2::CreateCloneTrees0( TChai
2985   */   */
2986  void PamLevel2::CreateCloneTrees(TFile *ofile){  void PamLevel2::CreateCloneTrees(TFile *ofile){
2987    
2988    
2989    //  if the pointer is null, create a default file
2990    
2991        if(!ofile){
2992            cout << "void PamLevel2::CreateCloneTrees(TFile*) -- WARNING -- Creating file: clone-tree.root "<<endl;
2993            ofile = new TFile("clone-tree.root","recreate");
2994        }
2995    
2996      ofile->cd();      ofile->cd();
2997    
2998      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
# Line 2714  void PamLevel2::CreateCloneTrees(TFile * Line 3016  void PamLevel2::CreateCloneTrees(TFile *
3016      }      }
3017      cout << "----------------------------------------------------"<<endl;      cout << "----------------------------------------------------"<<endl;
3018    
3019        // ------------------------------------
3020        // add branch with dead and live times
3021        // ------------------------------------
3022        run_tree_clone->Branch("DeadLiveTime",totdltime,"dltime[3]/l");
3023        cout << "Run          : branch DeadLiveTime"<<endl;
3024    
3025    
3026      sel_tree_clone = new TTree("SelectionList","List of selected events ");      sel_tree_clone = new TTree("SelectionList","List of selected events ");
3027      sel_tree_clone->Branch("RunEntry",&irun,"runentry/L");      sel_tree_clone->Branch("RunEntry",&irun,"runentry/L");
# Line 2840  TTree* PamLevel2::GetCloneTree(TString n Line 3148  TTree* PamLevel2::GetCloneTree(TString n
3148  void PamLevel2::WriteCloneTrees(){  void PamLevel2::WriteCloneTrees(){
3149      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
3150      cout << "Write clones of PAMELA trees "<<endl;      cout << "Write clones of PAMELA trees "<<endl;
3151      cout << run_tree_clone->GetName()<<endl;          cout << run_tree_clone->GetName()<<endl;  
3152        if(run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())
3153            run_tree_clone->GetBranch("DeadLiveTime")->Fill();
3154      run_tree_clone->Write();      run_tree_clone->Write();
3155      cout << sel_tree_clone->GetName()<<endl;          cout << sel_tree_clone->GetName()<<endl;    
3156      sel_tree_clone->Write();      sel_tree_clone->Write();
# Line 2860  void PamLevel2::WriteCloneTrees(){ Line 3170  void PamLevel2::WriteCloneTrees(){
3170  //Int_t PamLevel2::GetEntry(Int_t iee){  //Int_t PamLevel2::GetEntry(Int_t iee){
3171  Int_t PamLevel2::GetEntry(Long64_t iee){  Int_t PamLevel2::GetEntry(Long64_t iee){
3172            
3173    //     cout << "-------------------------------------"<<endl;
3174    //     cout << "Int_t PamLevel2::GetEntry("<<iee<<")"<<endl;
3175    
3176      if(!pam_tree){      if(!pam_tree){
3177          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;
3178          return 0;          return 0;
# Line 2905  Int_t PamLevel2::GetEntry(Long64_t iee){ Line 3218  Int_t PamLevel2::GetEntry(Long64_t iee){
3218        
3219  //    cout << "PamLevel2::GetEntry("<<iee<<") "<<irun<<" "<<runfirstentry<<" "<<irunentry<<endl;  //    cout << "PamLevel2::GetEntry("<<iee<<") "<<irun<<" "<<runfirstentry<<" "<<irunentry<<endl;
3220    
3221  //    cout << " irunentry "<<irunentry << endl;  //     cout << "irunentry     "<<irunentry << endl;
3222    //     cout << "runfirstentry "<<runfirstentry << endl;
3223    //     cout << "nevents       "<<GetRunInfo()->NEVENTS<< endl;
3224    
3225    //     if( TRK0 || CAL0 || TOF0 ){
3226    //      if( !GetYodaEntry( ) ){
3227    //          cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- error reading level0 tree"<<endl;
3228    //          return 0;
3229    //      }
3230    //     }
3231    
3232    
     if( TRK0 || CAL0 || TOF0 ){  
         if( !GetYodaEntry( ) ){  
             cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- error reading level0 tree"<<endl;  
             return 0;  
         }  
     }  
3233      return 1;      return 1;
3234    
3235  }  }
3236    
3237    TrkLevel0    *PamLevel2::GetTrkLevel0(){
3238        if( !TRK0 )return NULL;
3239        if( !GetYodaEntry( ) ){
3240            cout << " Int_t PamLevel2::GetTrkLevel0() -- ERROR -- error reading level0 tree"<<endl;
3241            return 0;
3242        }
3243        return trk0_obj;
3244    };
3245    CaloLevel0    *PamLevel2::GetCaloLevel0(){
3246        if( !CAL0 )return NULL;
3247        if( !GetYodaEntry( ) ){
3248            cout << " Int_t PamLevel2::GetCaloLevel0() -- ERROR -- error reading level0 tree"<<endl;
3249            return 0;
3250        }
3251        return calo0_obj;
3252    };
3253    
3254    
3255  /**  /**
3256   * 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.
3257   * 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 2936  TTree* PamLevel2::GetYodaTree( ){ Line 3271  TTree* PamLevel2::GetYodaTree( ){
3271          return NULL;          return NULL;
3272      }          }    
3273      Int_t irootnew = run_obj->ID_ROOT_L0;      Int_t irootnew = run_obj->ID_ROOT_L0;
3274  //     cout << "iroot    "<<iroot<<endl;  //      cout << "iroot    "<<iroot<<endl;
3275  //     cout << "irootnew "<<irootnew<<endl;  //      cout << "irootnew "<<irootnew<<endl;
3276    
3277      //===================================      //===================================
3278      // load the level0 file      // load the level0 file
# Line 2994  TTree* PamLevel2::GetYodaTree( ){ Line 3329  TTree* PamLevel2::GetYodaTree( ){
3329              };              };
3330              l0_tree->SetBranchAddress("Tracker" ,trk0_obj->GetPointerToTrackerEvent());              l0_tree->SetBranchAddress("Tracker" ,trk0_obj->GetPointerToTrackerEvent());
3331          }          }
3332          //---------------------------------------------------          //--------------------------------------------------
3333          // CALORIMETER:          // CALORIMETER:
3334          if(CAL0){          if(CAL0){
3335              if(!calo0_obj){              if(!calo0_obj){
# Line 3057  Int_t PamLevel2::GetYodaEntry(){ Line 3392  Int_t PamLevel2::GetYodaEntry(){
3392    
3393  //     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;
3394  //     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;
3395  //     cout << " time "<< GetOrbitalInfo()->absTime << endl;  //     cout << " time "<< abstime << endl;
3396  //     cout << " trk_calib_used "<<run_obj->TRK_CALIB_USED<< endl;  //     cout << " trk_calib_used "<<run_obj->TRK_CALIB_USED<< endl;
3397            
3398      if( !GetOrbitalInfo() ){      ULong64_t obt     = 0;
3399        ULong64_t pktn    = 0;
3400        if( GetOrbitalInfo() ){
3401            obt     = GetOrbitalInfo()->OBT;
3402            pktn    = GetOrbitalInfo()->pkt_num;
3403        }
3404    
3405        if( !GetOrbitalInfo() && !ISGP){
3406          cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing OrbitalInfo "<<endl;          cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing OrbitalInfo "<<endl;
3407          return 0;          return 0;
3408      }      }
3409      if( GetOrbitalInfo()->OBT==0 && GetOrbitalInfo()->pkt_num==0 ){      if( obt==0 && pktn==0 && !ISGP ){
3410          cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- level2 event corrupted ?? "<<endl;          cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- level2 event corrupted ?? "<<endl;
3411          return 0;          return 0;
3412      }      }
# Line 3083  Int_t PamLevel2::GetYodaEntry(){ Line 3425  Int_t PamLevel2::GetYodaEntry(){
3425      Int_t answer = 0;      Int_t answer = 0;
3426      Int_t shift =0;      Int_t shift =0;
3427      //    printf(" siamo qui %i %i \n",shift,prevshift);      //    printf(" siamo qui %i %i \n",shift,prevshift);
3428      Int_t maxshift = 100;      Int_t maxshift = 10;
3429      do{      do{
3430          if(shift>0){              if(shift>0){    
3431              cout << " PKTNUM  L2 --- "<< GetOrbitalInfo()->pkt_num << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl;              cout << " PKTNUM  L2 --- "<< pktn << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl;
3432              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;              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;
3433              cout << "         L2 <--> L0 mismatch ( irun "<<irun<<" irunentry "<<irunentry<<" shift "<<shift<<" prevshift "<<prevshift<<" )"<<endl;              cout << "         L2 <--> L0 mismatch ( irun "<<irun<<" irunentry "<<irunentry<<" shift "<<shift<<" prevshift "<<prevshift<<" )"<<endl;
3434          }          }
# Line 3096  Int_t PamLevel2::GetYodaEntry(){ Line 3438  Int_t PamLevel2::GetYodaEntry(){
3438              cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing EventHeader "<<endl;              cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing EventHeader "<<endl;
3439              return 0;              return 0;
3440          }          }
3441  //      cout << "PKTNUM "<<shift<<" ==  L2 --- "<< GetOrbitalInfo()->pkt_num << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl;  
3442  //      cout << " L2 --- "<< GetOrbitalInfo()->OBT << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime()<<endl;          if(ISGP){
3443                obt = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()); //BARBATRUCCO
3444                pktn = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter()); //BARBATRUCCO
3445            }
3446    
3447    //      cout << "PKTNUM "<<shift<<" ==  L2 --- "<< pktn << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl;
3448    //      cout << " L2 --- "<< obt << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime()<<endl;
3449  //      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;
3450  //      cout << " GetOrbitalInfo()->OBT "<< GetOrbitalInfo()->OBT << endl;  //      cout << " obt "<< obt << endl;
3451  //      cout << " GetEventHeader()->GetPscuHeader()->GetOrbitalTime() "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime() << endl;  //      cout << " GetEventHeader()->GetPscuHeader()->GetOrbitalTime() "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime() << endl;
3452  //      cout << " GetOrbitalInfo()->pkt_num "<< GetOrbitalInfo()->pkt_num << endl;  //      cout << " pktn "<< pktn << endl;
3453  //      cout << " GetEventHeader()->GetPscuHeader()->GetCounter() "<< GetEventHeader()->GetPscuHeader()->GetCounter() << endl;  //      cout << " GetEventHeader()->GetPscuHeader()->GetCounter() "<< GetEventHeader()->GetPscuHeader()->GetCounter() << endl;
3454  //      printf(" IDRUN %u \n",GetRunInfo()->ID);  //      printf(" IDRUN %u \n",GetRunInfo()->ID);
3455  //  //
# Line 3110  Int_t PamLevel2::GetYodaEntry(){ Line 3458  Int_t PamLevel2::GetYodaEntry(){
3458            shift = -1;            shift = -1;
3459          };          };
3460    
3461      }while( ( GetOrbitalInfo()->OBT != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) || GetOrbitalInfo()->pkt_num != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter())) && (quellagiusta+(Long64_t)shift) < GetYodaTree()->GetEntries() && shift < maxshift);      }while( ( obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) ||
3462                  pktn != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter())       )
3463                && (quellagiusta+(Long64_t)shift) < GetYodaTree()->GetEntries() && shift < maxshift);
3464    
3465      if ( (quellagiusta+(Long64_t)shift) == GetYodaTree()->GetEntries() || shift == maxshift ) {      if ( (quellagiusta+(Long64_t)shift+(Long64_t)prevshift) > GetYodaTree()->GetEntries() || shift == maxshift ) {
3466          cout << " Big trouble here, no such event in Level0 data! " <<endl;          cout << " Big trouble here, no such event in Level0 data! " <<endl;
3467          return 0;          return 0;
3468      }      }
# Line 3123  Int_t PamLevel2::GetYodaEntry(){ Line 3473  Int_t PamLevel2::GetYodaEntry(){
3473      return answer;      return answer;
3474            
3475  }  }
3476    /**
3477     * \Brief Set DB connection
3478     */
3479    Bool_t PamLevel2::SetDBConnection(){
3480    
3481        cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
3482        cout<<"Connecting to DB"<<endl;
3483        cout<<"HOST "<<host<<endl;
3484        cout<<"USER "<<user<<endl;
3485        cout<<"PSW  "<<psw<<endl;
3486        dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
3487        if( !dbc )return false;
3488        if( !dbc->IsConnected() )return false;    
3489        cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
3490        return true;
3491    
3492    }
3493    
3494    /**
3495     * \Brief Add a friend to the pamela chain.
3496     * @param cname name of the chain to be added
3497     */
3498    
3499    TChain* PamLevel2::AddFriend(TString cname){
3500    
3501        if(!GetPamTree()){
3502            cout << " TChain* PamLevel2::AddFriend(TString cname) --- a pamela tree must be created first"<<endl;
3503            return NULL;
3504        }
3505    
3506    
3507        TChain *c = new TChain( cname.Data() );
3508    
3509        TIter next( GetPamTree()->GetListOfFiles() );
3510        Int_t nf = 0;
3511        TChainElement* element = 0;    
3512        while ((element = (TChainElement*) next())) {      
3513            c->Add(element->GetTitle());
3514            nf++;
3515        }
3516    
3517        GetPamTree()->AddFriend(cname.Data());
3518    
3519        cout << "external chain created and added to pamela friends :"<<cname<<endl;
3520        cout << "n.files "<<nf<<endl;
3521        
3522    
3523        return c;    
3524    
3525    }

Legend:
Removed from v.1.37  
changed lines
  Added in v.1.47

  ViewVC Help
Powered by ViewVC 1.1.23