/[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.39 by pam-fi, Mon May 14 11:57:36 2007 UTC revision 1.42 by pam-fi, Tue Aug 7 15:37:12 2007 UTC
# Line 304  void PamLevel2::Clear(){ Line 304  void PamLevel2::Clear(){
304    
305      if(h0_obj)   h0_obj->Clear();            if(h0_obj)   h0_obj->Clear();      
306  //    if(trk0_obj) trk0_obj->Clear();    //    if(trk0_obj) trk0_obj->Clear();  
     if(calo0_obj) calo0_obj->Clear();    
307      if(trk1_obj) trk1_obj->Clear();          if(trk1_obj) trk1_obj->Clear();    
308      if(trk2_obj) trk2_obj->Clear();      if(trk2_obj) trk2_obj->Clear();
309      if(trkh_obj) trkh_obj->Clear();      if(trkh_obj) trkh_obj->Clear();
310        if(calo0_obj) calo0_obj->Clear();  
311      if(calo1_obj)calo1_obj->Clear();      if(calo1_obj)calo1_obj->Clear();
312      if(calo2_obj)calo2_obj->Clear();      if(calo2_obj)calo2_obj->Clear();
313      if(tof_obj)  tof_obj->Clear();      if(tof_obj)  tof_obj->Clear();
# Line 658  void PamLevel2::SortTracks(){ Line 658  void PamLevel2::SortTracks(){
658    TClonesArray &ttimage = *timage;    TClonesArray &ttimage = *timage;
659    
660    
661    // loop over the tracks sorted by the tracker  
662      //--------------------------------------------------
663      // retrieve sorting method
664      //--------------------------------------------------
665    Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);    Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);
666    Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);    Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);
667    Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase);    Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase);
# Line 672  void PamLevel2::SortTracks(){ Line 675  void PamLevel2::SortTracks(){
675    };    };
676    
677    //   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;
678          
679    
680      //--------------------------------------------------
681      // loop over "physical" tracks sorted by the tracker
682      //--------------------------------------------------
683    for(Int_t i=0; i < trk2_obj->TrkLevel2::GetNTracks(); i++){    for(Int_t i=0; i < trk2_obj->TrkLevel2::GetNTracks(); i++){
684                    
685      TrkTrack   *ts = 0;      TrkTrack   *ts = 0;
# Line 680  void PamLevel2::SortTracks(){ Line 687  void PamLevel2::SortTracks(){
687      ToFTrkVar  *os = 0;      ToFTrkVar  *os = 0;
688                    
689      // get tracker tracks      // get tracker tracks
690      TrkTrack   *tp = trk2_obj->TrkLevel2::GetTrack(i);                    //tracker      TrkTrack   *tp = trk2_obj->TrkLevel2::GetTrack(i); //tracker
691      CaloTrkVar *cp = GetCaloStoredTrack(tp->GetSeqNo());      CaloTrkVar *cp = GetCaloStoredTrack(tp->GetSeqNo());
692      ToFTrkVar  *op = GetToFStoredTrack(tp->GetSeqNo());      ToFTrkVar  *op = GetToFStoredTrack(tp->GetSeqNo());
693    
694      TrkTrack   *ti = 0;              //tracker (image)      TrkTrack   *ti = 0; //tracker (image)
695      CaloTrkVar *ci = 0;      CaloTrkVar *ci = 0;
696      ToFTrkVar  *oi = 0;      ToFTrkVar  *oi = 0;
697      //  cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;      //  cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;
# Line 701  void PamLevel2::SortTracks(){ Line 708  void PamLevel2::SortTracks(){
708        Int_t tp_score = 0;  //main track sorted by the tracker        Int_t tp_score = 0;  //main track sorted by the tracker
709        Int_t ti_score = 0;  //image track        Int_t ti_score = 0;  //image track
710                            
711        // ------------------------        // -----------------------------------------------------------------------------------------
712        // calorimeter check        // calorimeter check
713        // ------------------------        // -----------------------------------------------------------------------------------------
714        // check the Y spatial residual on the first calorimeter plane        // check the Y spatial residual on the first calorimeter plane
715        // (cut on calorimeter variables from Emiliano)        // (cut on calorimeter variables from Emiliano)
716        if( use_CAL && !calo2_obj ){        if( use_CAL && !calo2_obj ){
# Line 712  void PamLevel2::SortTracks(){ Line 719  void PamLevel2::SortTracks(){
719        };        };
720        if(        if(
721           use_CAL            &&           use_CAL            &&
722           calo2_obj->npcfit[1] > 5     &&   //no. of fit planes on Y view  //       calo2_obj->npcfit[1] > 5     &&   //no. of fit planes on Y view
723           calo2_obj->varcfit[1] < 1000. &&  //fit variance on Y view  //       calo2_obj->varcfit[1] < 1000. &&  //fit variance on Y view
724           cp && ci &&           cp && ci &&
725           true){           true){
726    
727                                    
728          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;
729          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;
730                                    
731          if(resy_p <= resy_i) tp_score++;  //      if(resy_p <= resy_i) tp_score++;
732          else                 ti_score++;  //      else                 ti_score++;
733                    
734    
735              if( cp->npresh > ci->npresh) tp_score++;
736              if( cp->npresh < ci->npresh) ti_score++;
737              else ;//niente
738    
739          //      cout << "CALO "<<tp_score<<ti_score<<endl;          //      cout << "CALO "<<tp_score<<ti_score<<endl;
740    
741        };        };
742        // ------------------------        // -----------------------------------------------------------------------------------------
743        // TOF check        // TOF check
744        // ------------------------                  // -----------------------------------------------------------------------------------------
745        // check the number of hit pmts along the track        // check the number of hit pmts along the track
746        // on S12 S21 and S32, where paddles are parallel to Y axis        // on S12 S21 and S32, where paddles are parallel to Y axis
747        if( use_TOF && !tof_obj ){        if( use_TOF && !tof_obj ){
# Line 875  void PamLevel2::SortTracks(){ Line 887  void PamLevel2::SortTracks(){
887              cout << "image: npmtadc "<< oi->npmtadc << endl;              cout << "image: npmtadc "<< oi->npmtadc << endl;
888              cout << "image: npmttdc "<< oi->npmttdc << endl;*/              cout << "image: npmttdc "<< oi->npmttdc << endl;*/
889                                    
890            for (Int_t ih=0; ih < op->npmtadc; ih++){  //        for (Int_t ih=0; ih < op->npmtadc; ih++){
891              Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );  //          Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
892              if(pl == 1 || pl == 2 || pl == 5)nphit_p++;  //          if(pl == 1 || pl == 2 || pl == 5)nphit_p++;
893    //        };
894                    
895    //        for (Int_t ih=0; ih < oi->npmtadc; ih++){
896    //          Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
897    //          if(pl == 1 || pl == 2 || pl == 5)nphit_i++;
898    //        };
899              // --- modified to count tdc signals (more efficient?)
900              // --- and to implement check on tdcflag
901              for (Int_t ih=0; ih < op->npmttdc; ih++){
902                Int_t pl = tof_obj->GetPlaneIndex( (op->pmttdc).At(ih) );
903    //          if( (op->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_p++;
904                if( (op->tdcflag).At(ih)==0 )nphit_p++;
905            };            };
906                                    
907            for (Int_t ih=0; ih < oi->npmtadc; ih++){            for (Int_t ih=0; ih < oi->npmttdc; ih++){
908              Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );              Int_t pl = tof_obj->GetPlaneIndex( (oi->pmttdc).At(ih) );
909              if(pl == 1 || pl == 2 || pl == 5)nphit_i++;  //          if( (oi->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_i++;  
910                if( (oi->tdcflag).At(ih)==0 )nphit_i++;    
911            };            };
912                                    
913            if(            if(
              use_TOF            &&  
914               (nphit_p+nphit_i) !=0 &&                 (nphit_p+nphit_i) !=0 &&  
915               true){               true){
916                                            
917              if( nphit_p >= nphit_i) tp_score++;              if     ( nphit_p > nphit_i) tp_score++;
918              else ti_score++;              else if( nphit_p < nphit_i) ti_score++;
919                else ;//niente
920            };            };
921          };          };
922          //      cout << "TOF "<<tp_score<<ti_score<<endl;          //      cout << "TOF "<<tp_score<<ti_score<<endl;
923        };        };
924        if(tp_score == ti_score) use_TRK = true;  
925        // ------------------------  
926    //      if(tp_score == ti_score) use_TRK = true;
927    
928    
929          // -----------------------------------------------------------------------------------------
930        // tracker check        // tracker check
931        // ------------------------        // -----------------------------------------------------------------------------------------
932        // chi**2 difference is not always large enough to distinguish among        // chi**2 difference is not always large enough to distinguish among
933        // the real track and its image.        // the real track and its image.
934        // 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.
935          // *** MODIFIED ON AUGUST 2007 ***
936        if(use_TRK){        if(use_TRK){
937          if(      tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ;  //      if(      tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ;
938          else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ;  //      else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ;
939    
940              // CHECK 1 : number of points along X  
941              if ( tp->GetNX() >= ti->GetNX() )tp_score++ ;
942              if ( tp->GetNX() <= ti->GetNX() )ti_score++ ;
943              // CHECK 2 : number of points along Y  
944              if ( tp->GetNY() >= ti->GetNY() )tp_score++ ;
945              if ( tp->GetNY() <= ti->GetNY() )ti_score++ ;
946              // CHECK 3 : chi**2 along X  
947    //        if(      tp->GetChi2X() > 0 && (tp->GetChi2X() < ti->GetChi2X() || ti->GetChi2X() <=0) ) tp_score++ ;
948    //        if(      ti->GetChi2X() > 0 && (ti->GetChi2X() < tp->GetChi2X() || tp->GetChi2X() <=0) ) ti_score++ ;
949              // CHECK 4 : chi**2 along Y  
950    //        if(      tp->GetChi2Y() > 0 && (tp->GetChi2Y() < ti->GetChi2Y() || ti->GetChi2Y() <=0) ) tp_score++ ;
951    //        if(      ti->GetChi2Y() > 0 && (ti->GetChi2Y() < tp->GetChi2Y() || tp->GetChi2Y() <=0) ) ti_score++ ;
952              // CHECK 5 : total chi**2  
953    //        if(      tp->chi2 > 0 && (tp->chi2 < ti->chi2 || ti->chi2 <=0) ) tp_score++ ;
954    //        if(      ti->chi2 > 0 && (ti->chi2 < tp->chi2 || tp->chi2 <=0) ) ti_score++ ;
955    
956          //      cout << "TRK "<<tp_score<<ti_score<<endl;          //      cout << "TRK "<<tp_score<<ti_score<<endl;
957        };        };
958                            
959        // ------------------------  
960    
961          // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
962        // the winner is....        // the winner is....
963        // ------------------------                  // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
964        if      (tp_score > ti_score) {        if      (tp_score > ti_score) {
965          //              ts = tp;//the track sorted by the tracker!!          
         //              cs = cp;  
         //              os = op;  
         //      cout << "It's primary!" << endl;  
966    
967        }else if (tp_score < ti_score) {        }else if (tp_score < ti_score) {
968    
         //      cout << "It's image!" << endl;  
969    
970          ts = ti;//its image!!          ts = ti;//its image!!
971          cs = ci;          cs = ci;
# Line 936  void PamLevel2::SortTracks(){ Line 981  void PamLevel2::SortTracks(){
981    
982                                    
983        }else {        }else {
984          //              ts = tp;  
         //              cs = cp;  
         //              os = op;  
985  //      cout << "Warning - track image ambiguity not solved" << endl;  //      cout << "Warning - track image ambiguity not solved" << endl;
986          //                              cout << ts->GetNtot() << " "<< ts->chi2 << " " << npcfit[1] << " "<< nphit_p << endl;  
987        };        };
988                            
989      }else{      }else{
# Line 2964  Int_t PamLevel2::GetEntry(Long64_t iee){ Line 3007  Int_t PamLevel2::GetEntry(Long64_t iee){
3007  //     cout << "irunentry     "<<irunentry << endl;  //     cout << "irunentry     "<<irunentry << endl;
3008  //     cout << "runfirstentry "<<runfirstentry << endl;  //     cout << "runfirstentry "<<runfirstentry << endl;
3009  //     cout << "nevents       "<<GetRunInfo()->NEVENTS<< endl;  //     cout << "nevents       "<<GetRunInfo()->NEVENTS<< endl;
3010      if( TRK0 || CAL0 || TOF0 ){  
3011          if( !GetYodaEntry( ) ){  //     if( TRK0 || CAL0 || TOF0 ){
3012              cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- error reading level0 tree"<<endl;  //      if( !GetYodaEntry( ) ){
3013              return 0;  //          cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- error reading level0 tree"<<endl;
3014          }  //          return 0;
3015      }  //      }
3016    //     }
3017    
3018    
3019      return 1;      return 1;
3020    
3021  }  }
3022    
3023    TrkLevel0    *PamLevel2::GetTrkLevel0(){
3024        if( !TRK0 )return NULL;
3025        if( !GetYodaEntry( ) ){
3026            cout << " Int_t PamLevel2::GetTrkLevel0() -- ERROR -- error reading level0 tree"<<endl;
3027            return 0;
3028        }
3029        return trk0_obj;
3030    };
3031    CaloLevel0    *PamLevel2::GetCaloLevel0(){
3032        if( !CAL0 )return NULL;
3033        if( !GetYodaEntry( ) ){
3034            cout << " Int_t PamLevel2::GetCaloLevel0() -- ERROR -- error reading level0 tree"<<endl;
3035            return 0;
3036        }
3037        return calo0_obj;
3038    };
3039    
3040    
3041  /**  /**
3042   * 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.
3043   * 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 3051  TTree* PamLevel2::GetYodaTree( ){ Line 3115  TTree* PamLevel2::GetYodaTree( ){
3115              };              };
3116              l0_tree->SetBranchAddress("Tracker" ,trk0_obj->GetPointerToTrackerEvent());              l0_tree->SetBranchAddress("Tracker" ,trk0_obj->GetPointerToTrackerEvent());
3117          }          }
3118          //---------------------------------------------------          //--------------------------------------------------
3119          // CALORIMETER:          // CALORIMETER:
3120          if(CAL0){          if(CAL0){
3121              if(!calo0_obj){              if(!calo0_obj){
# Line 3180  Int_t PamLevel2::GetYodaEntry(){ Line 3244  Int_t PamLevel2::GetYodaEntry(){
3244      return answer;      return answer;
3245            
3246  }  }
3247    /**
3248     * \Brief Set DB connection
3249     */
3250    Bool_t PamLevel2::SetDBConnection(){
3251    
3252        cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
3253        cout<<"Connecting to DB"<<endl;
3254        cout<<"HOST "<<host<<endl;
3255        cout<<"USER "<<user<<endl;
3256        cout<<"PSW  "<<psw<<endl;
3257        dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
3258        if( !dbc )return false;
3259        if( !dbc->IsConnected() )return false;    
3260        cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
3261        return true;
3262    
3263    }

Legend:
Removed from v.1.39  
changed lines
  Added in v.1.42

  ViewVC Help
Powered by ViewVC 1.1.23