--- PamelaLevel2/src/PamLevel2.cpp 2007/05/14 11:57:36 1.39 +++ PamelaLevel2/src/PamLevel2.cpp 2007/09/12 09:51:57 1.48 @@ -11,6 +11,8 @@ calo_track = 0; tof_track = 0; candeleteobj = 0; + pscore = 0; + iscore = 0; }; //-------------------------------------- // @@ -60,6 +62,9 @@ calo_track = 0; tof_track = 0; } + pscore = 0; + iscore = 0; + } void PamTrack::Delete(){ // cout << "PamTrack::Delete() "<Clear(); // if(trk0_obj) trk0_obj->Clear(); - if(calo0_obj) calo0_obj->Clear(); if(trk1_obj) trk1_obj->Clear(); if(trk2_obj) trk2_obj->Clear(); if(trkh_obj) trkh_obj->Clear(); + if(calo0_obj) calo0_obj->Clear(); if(calo1_obj)calo1_obj->Clear(); if(calo2_obj)calo2_obj->Clear(); if(tof_obj) tof_obj->Clear(); @@ -401,6 +399,9 @@ runfirstentry = 0ULL; runlastentry = 0ULL; // + totdltime[0] = 0LL; + totdltime[1] = 0LL; + // }; Bool_t PamLevel2::IsGood(){ @@ -635,7 +636,7 @@ void PamLevel2::SortTracks(){ TString how = howtosort; - // cout <<" PamLevel2::SortTracks(TString how) "<TrkLevel2::GetNTracks(); i++){ TrkTrack *ts = 0; @@ -680,15 +701,21 @@ ToFTrkVar *os = 0; // get tracker tracks - TrkTrack *tp = trk2_obj->TrkLevel2::GetTrack(i); //tracker + TrkTrack *tp = trk2_obj->TrkLevel2::GetTrack(i); //tracker CaloTrkVar *cp = GetCaloStoredTrack(tp->GetSeqNo()); ToFTrkVar *op = GetToFStoredTrack(tp->GetSeqNo()); - TrkTrack *ti = 0; //tracker (image) + TrkTrack *ti = 0; //tracker (image) CaloTrkVar *ci = 0; ToFTrkVar *oi = 0; // cout << "trk track n. "<HasImage()){ ti = trk2_obj->TrkLevel2::GetTrackImage(i); //tracker (image) @@ -698,46 +725,72 @@ // cout << "its image "<npcfit[1] > 5 && //no. of fit planes on Y view - calo2_obj->varcfit[1] < 1000. && //fit variance on Y view +// calo2_obj->npcfit[1] > 5 && //no. of fit planes on Y view +// calo2_obj->varcfit[1] < 1000. && //fit variance on Y view cp && ci && true){ - Float_t resy_p = cp->tbar[0][1] - calo2_obj->cbar[0][1]; if(resy_p < 0)resy_p= - resy_p; - Float_t resy_i = ci->tbar[0][1] - calo2_obj->cbar[0][1]; if(resy_i < 0)resy_i= - resy_i; +// Float_t resy_p = cp->tbar[0][1] - calo2_obj->cbar[0][1]; if(resy_p < 0)resy_p= - resy_p; +// Float_t resy_i = ci->tbar[0][1] - calo2_obj->cbar[0][1]; if(resy_i < 0)resy_i= - resy_i; - if(resy_p <= resy_i) tp_score++; - else ti_score++; +// if(resy_p <= resy_i) tp_score++; +// else ti_score++; + + if( cp->npresh > ci->npresh){ + tp_score++; + totp_score++; + }; + if( cp->npresh < ci->npresh){ + ti_score++; + toti_score++; + }; + // cout << "CALO "<npmtadc; ih++){ @@ -749,7 +802,7 @@ if ( pl == 2 || pl == 3 || pl == 4 || pl == 5 ) sen += (oi->dedx).At(ih); }; // - if ( sen >= sortthr ){ + if ( sen >= sortthr && false){ // temporary disabled NUCLEI special algorithm since the new one should work for every particle (to be checked!) //printf(" IS A NUCLEUS! en = %f \n",sen); // // is a nucleus use a different algorithm @@ -842,7 +895,7 @@ if( - use_TOF && + (use_TOF || use_S1 || use_S2 || use_S3) && (nphit_p+nphit_i) !=0 && true){ @@ -875,56 +928,112 @@ cout << "image: npmtadc "<< oi->npmtadc << endl; cout << "image: npmttdc "<< oi->npmttdc << endl;*/ - for (Int_t ih=0; ih < op->npmtadc; ih++){ - Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) ); - if(pl == 1 || pl == 2 || pl == 5)nphit_p++; +// for (Int_t ih=0; ih < op->npmtadc; ih++){ +// Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) ); +// if(pl == 1 || pl == 2 || pl == 5)nphit_p++; +// }; + +// for (Int_t ih=0; ih < oi->npmtadc; ih++){ +// Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) ); +// if(pl == 1 || pl == 2 || pl == 5)nphit_i++; +// }; + // --- modified to count tdc signals (more efficient?) + // --- and to implement check on tdcflag + for (Int_t ih=0; ih < op->npmttdc; ih++){ + Int_t pl = tof_obj->GetPlaneIndex( (op->pmttdc).At(ih) ); +// if( (op->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_p++; + if ( (use_S1 && ( pl == 0 || pl == 1 )) || (use_S2 && ( pl == 2 || pl == 3 )) || (use_S3 && ( pl == 4 || pl == 5 )) ){ + if( (op->tdcflag).At(ih)==0 )nphit_p++; + }; }; - for (Int_t ih=0; ih < oi->npmtadc; ih++){ - Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) ); - if(pl == 1 || pl == 2 || pl == 5)nphit_i++; + for (Int_t ih=0; ih < oi->npmttdc; ih++){ + Int_t pl = tof_obj->GetPlaneIndex( (oi->pmttdc).At(ih) ); +// if( (oi->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_i++; + if ( (use_S1 && ( pl == 0 || pl == 1 )) || (use_S2 && ( pl == 2 || pl == 3 )) || (use_S3 && ( pl == 4 || pl == 5 )) ){ + if( (oi->tdcflag).At(ih)==0 )nphit_i++; + }; }; if( - use_TOF && (nphit_p+nphit_i) !=0 && true){ - if( nphit_p >= nphit_i) tp_score++; - else ti_score++; + if ( nphit_p != nphit_i ){ + totp_score += nphit_p; + toti_score += nphit_i; + tp_score+=nphit_p; + ti_score+=nphit_i; + }; + // if ( nphit_p > nphit_i) tp_score+=nphit_p; + // else if( nphit_p < nphit_i) ti_score+=nphit_i; + // else ;//niente }; }; // cout << "TOF "<chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ; - else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ; +// if( tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ; +// else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ; + + // CHECK 1 : number of points along X + if ( tp->GetNX() >= ti->GetNX() ){ + tp_score++ ; + totp_score++ ; + }; + if ( tp->GetNX() <= ti->GetNX() ){ + ti_score++ ; + toti_score++ ; + }; + // CHECK 2 : number of points along Y + if ( tp->GetNY() >= ti->GetNY() ){ + tp_score++ ; + totp_score++ ; + }; + if ( tp->GetNY() <= ti->GetNY() ){ + ti_score++ ; + toti_score++ ; + }; + // CHECK 3 : chi**2 along X +// if( tp->GetChi2X() > 0 && (tp->GetChi2X() < ti->GetChi2X() || ti->GetChi2X() <=0) ) tp_score++ ; +// if( ti->GetChi2X() > 0 && (ti->GetChi2X() < tp->GetChi2X() || tp->GetChi2X() <=0) ) ti_score++ ; + // CHECK 4 : chi**2 along Y +// if( tp->GetChi2Y() > 0 && (tp->GetChi2Y() < ti->GetChi2Y() || ti->GetChi2Y() <=0) ) tp_score++ ; +// if( ti->GetChi2Y() > 0 && (ti->GetChi2Y() < tp->GetChi2Y() || tp->GetChi2Y() <=0) ) ti_score++ ; + // CHECK 5 : total chi**2 +// if( tp->chi2 > 0 && (tp->chi2 < ti->chi2 || ti->chi2 <=0) ) tp_score++ ; +// if( ti->chi2 > 0 && (ti->chi2 < tp->chi2 || tp->chi2 <=0) ) ti_score++ ; + // cout << "TRK "< ti_score) { - // ts = tp;//the track sorted by the tracker!! - // cs = cp; - // os = op; - // cout << "It's primary!" << endl; + }else if (tp_score < ti_score) { - // cout << "It's image!" << endl; ts = ti;//its image!! cs = ci; os = oi; + Int_t totis = toti_score; ti = tp;//its image!! ci = cp; @@ -934,16 +1043,20 @@ cp = cs; op = os; + toti_score = totp_score; + totp_score = totis; + }else { - // ts = tp; - // cs = cp; - // os = op; + // cout << "Warning - track image ambiguity not solved" << endl; - // cout << ts->GetNtot() << " "<< ts->chi2 << " " << npcfit[1] << " "<< nphit_p << endl; + }; }else{ + totp_score = 1; + toti_score = 0; + // ts = tp; // cs = cp; // os = op; @@ -957,8 +1070,14 @@ // cout<<"o "<SetPScore(totp_score); + ((PamTrack*)(ttsorted[i]))->SetIScore(toti_score); + ((PamTrack*)(ttimage[i]))->SetPScore(totp_score); + ((PamTrack*)(ttimage[i]))->SetIScore(toti_score); }; if( tsorted->GetEntries() != trk2_obj->GetNTracks() ){ @@ -1875,11 +1994,15 @@ // // the absolute time is necessary to relate the event with the run // - if( !GetOrbitalInfo() ){ + if( !GetOrbitalInfo() && !ISGP){ cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing OrbitalInfo "<absTime; + + // // the first time the routine is called, set run search from the beginning // @@ -1889,11 +2012,19 @@ runfirstentry = 0LL; runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS); if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL; + + if( ISGP && run->GetEntries()!=1 ){ + cout << "** WARNING ** simulated files are assumed to have 1 single run, not "<< run->GetEntries() << endl; + cout << "** WARNING ** run will not be updated"<GetEntries()-1LL && - !(GetOrbitalInfo()->absTime >= GetRunInfo()->RUNHEADER_TIME && - GetOrbitalInfo()->absTime <= GetRunInfo()->RUNTRAILER_TIME) + if(ISGP)abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO + // + if ( irun == run->GetEntries()-1LL && + !(abstime >= GetRunInfo()->RUNHEADER_TIME && + abstime <= GetRunInfo()->RUNTRAILER_TIME) ){ irun = -1LL; runfirstentry = 0LL; @@ -1904,7 +2035,7 @@ // bool fromfirst = true; // - 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 ){ // while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){ irun++; run->GetEntry(irun); @@ -1914,12 +2045,12 @@ // cout << " ))))) UPDATE RUN INFO ((((( @iev "<ID<<" irun "<GetRunInfo()->NEVENTS,(ULong64_t)(runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS))); - // printf(" abstime %u trailertime %u \n",GetOrbitalInfo()->absTime,GetRunInfo()->RUNTRAILER_TIME); + // printf(" abstime %u trailertime %u \n",abstime,GetRunInfo()->RUNTRAILER_TIME); // printf(" IDRUN %u \n",GetRunInfo()->ID); // // prevshift = 0; // - 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)){ printf(" resetting irun (it should NOT happen!!!)\n"); fromfirst = false; irun = 0; @@ -1932,10 +2063,10 @@ }; // if ( - !(GetOrbitalInfo()->absTime >= GetRunInfo()->RUNHEADER_TIME && - GetOrbitalInfo()->absTime <= GetRunInfo()->RUNTRAILER_TIME) + !(abstime >= GetRunInfo()->RUNHEADER_TIME && + abstime <= GetRunInfo()->RUNTRAILER_TIME) ) { - 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); return false; } // @@ -1987,9 +2118,29 @@ if(SELLI==0){ // --------------------------------------------------------------- + // increment dead and live-time counters + // --------------------------------------------------------------- + if( GetTrigLevel2() ){ + totdltime[0]+=GetTrigLevel2()->dltime[0]; + totdltime[1]+=GetTrigLevel2()->dltime[1]; + } + totdltime[2]++; + +// cout << setw(10)<absTime; + obt = GetOrbitalInfo()->OBT; + } + // --------------------------------------------------------------- // the absolute time is necessary to relate the event with the run // --------------------------------------------------------------- - if( !GetOrbitalInfo() ){ + if( !GetOrbitalInfo() && !ISGP ){ cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- ERROR -- missing OrbitalInfo "<GetEntry(irun); + + if( ISGP && run_tree->GetEntries()!=1 ){ + cout << "** WARNING ** simulated files are assumed to have 1 single run, not "<< run_tree->GetEntries() << endl; + cout << "** WARNING ** run will not be updated"<RUNHEADER_TIME; // BARBATRUCCO + obt = GetRunInfo()->RUNHEADER_OBT; // BARBATRUCCO + } // bool fromfirst = true; // first loop over runs @@ -2016,16 +2180,53 @@ while ( ( ( - !(GetOrbitalInfo()->absTime >= GetRunInfo()->RUNHEADER_TIME && // check on absolute time (s) - GetOrbitalInfo()->absTime <= GetRunInfo()->RUNTRAILER_TIME) && - !(GetOrbitalInfo()->OBT >= GetRunInfo()->RUNHEADER_OBT && // additional check on OBT (ms) - GetOrbitalInfo()->OBT <= GetRunInfo()->RUNTRAILER_OBT) + !(abstime >= GetRunInfo()->RUNHEADER_TIME && // check on absolute time (s) + abstime <= GetRunInfo()->RUNTRAILER_TIME) && + !(obt >= GetRunInfo()->RUNHEADER_OBT && // additional check on OBT (ms) + obt <= GetRunInfo()->RUNTRAILER_OBT) ) || GetRunInfo()->NEVENTS==0 || !(irunentry < GetRunInfo()->NEVENTS-1-prevshift) ) && irun < run_tree->GetEntries() ){ + + + + // ----------------------------------------- + // store dead and live-time of previous run + // ----------------------------------------- + if(fromfirst){ + if(oldrun==irun){ + /// decrement counters + if( GetTrigLevel2()){ + totdltime[0]-=GetTrigLevel2()->dltime[0];//live-time + totdltime[1]-=GetTrigLevel2()->dltime[1];//dead-time + } + totdltime[2]--; //event counter + cout << endl; + cout << "n.events : "<GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries()) + run_tree_clone->GetBranch("DeadLiveTime")->Fill(); + /// reset counters + if( GetTrigLevel2() ){ + totdltime[0]=GetTrigLevel2()->dltime[0];//live-time + totdltime[1]=0; //dead-time + } + totdltime[2]=1; //event counter + } + + irun++; // ------------------------------------ // if the end of run tree is reached... @@ -2053,7 +2254,7 @@ // ------------------------------------------------------------------- if(irun>0)runfirstentry += (GetRunInfo()->NEVENTS)-prevshift; irunentry = 0; - prevshift = 0; + prevshift = 0; run_tree->GetEntry(irun); if(GetRunInfo()->RUNHEADER_OBT>GetRunInfo()->RUNTRAILER_OBT ){ cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- irun "<=RUNTRAILER_OBT " <1){ +// ULong64_t temp[3]; +// temp[0]=totdltime[0]; +// temp[1]=totdltime[1]; +// temp[2]=totdltime[2]; +// for(int i=oldrun+1; iGetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries()) +// run_tree_clone->GetBranch("DeadLiveTime")->Fill(); +// } +// totdltime[0]=temp[0]; +// totdltime[1]=temp[1]; +// totdltime[2]=temp[2]; +// } +// /// decrement counters +// if( GetTrigLevel2() ){ +// totdltime[0]-=GetTrigLevel2()->dltime[0];//live-time +// totdltime[1]-=GetTrigLevel2()->dltime[1];//dead-time +// } +// totdltime[2]--; //event counter +// /// add an entry +// if(irun>0 ){ +// cout << endl; +// cout << "n.events : "<GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries()) +// run_tree_clone->GetBranch("DeadLiveTime")->Fill(); +// } +// /// reset counters +// if( GetTrigLevel2() ){ +// totdltime[0]=GetTrigLevel2()->dltime[0];//live-time +// totdltime[1]=0; //dead-time +// } +// totdltime[2]=1; //event counter + + + // -------------------------------------- // ---> exit with TRUE // -------------------------------------- cout << endl << " ))))) UPDATE RUN INFO ((((( @iev "<ID<<" irun "<Branch("DeadLiveTime",totdltime,"dltime[3]/l"); + cout << "Run : branch DeadLiveTime"<Branch("RunEntry",&irun,"runentry/L"); @@ -2893,7 +3154,9 @@ void PamLevel2::WriteCloneTrees(){ cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <GetName()<GetName()<GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries()) + run_tree_clone->GetBranch("DeadLiveTime")->Fill(); run_tree_clone->Write(); cout << sel_tree_clone->GetName()<Write(); @@ -2964,16 +3227,37 @@ // cout << "irunentry "<NEVENTS<< endl; - if( TRK0 || CAL0 || TOF0 ){ - if( !GetYodaEntry( ) ){ - cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- error reading level0 tree"<SetBranchAddress("Tracker" ,trk0_obj->GetPointerToTrackerEvent()); } - //--------------------------------------------------- + //-------------------------------------------------- // CALORIMETER: if(CAL0){ if(!calo0_obj){ @@ -3114,14 +3398,21 @@ // cout << " irun "<< irun << " irunentry "<< irunentry<<" run_obj->EV_FROM "<EV_FROM <<" quella giusta "<ID_ROOT_L0 "<ID_ROOT_L0<absTime << endl; +// cout << " time "<< abstime << endl; // cout << " trk_calib_used "<TRK_CALIB_USED<< endl; - if( !GetOrbitalInfo() ){ + ULong64_t obt = 0; + ULong64_t pktn = 0; + if( GetOrbitalInfo() ){ + obt = GetOrbitalInfo()->OBT; + pktn = GetOrbitalInfo()->pkt_num; + } + + if( !GetOrbitalInfo() && !ISGP){ cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing OrbitalInfo "<OBT==0 && GetOrbitalInfo()->pkt_num==0 ){ + if( obt==0 && pktn==0 && !ISGP ){ cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- level2 event corrupted ?? "<0){ - cout << " PKTNUM L2 --- "<< GetOrbitalInfo()->pkt_num << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<GetPscuHeader()->GetCounter()<ID << " ID_ROOT_L0 "<ID_ROOT_L0<<" ID_RUN_FRAG "<ID_RUN_FRAG << " EV_FROM "<EV_FROM < L0 mismatch ( irun "<pkt_num << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<OBT << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime()<GetPscuHeader()->GetOrbitalTime()); //BARBATRUCCO + pktn = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter()); //BARBATRUCCO + } + +// cout << "PKTNUM "<GetPscuHeader()->GetCounter()<GetPscuHeader()->GetOrbitalTime()<GetEntries()+1 )cout << ">>> end of level0 tree <<<"<OBT "<< GetOrbitalInfo()->OBT << endl; +// cout << " obt "<< obt << endl; // cout << " GetEventHeader()->GetPscuHeader()->GetOrbitalTime() "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime() << endl; -// cout << " GetOrbitalInfo()->pkt_num "<< GetOrbitalInfo()->pkt_num << endl; +// cout << " pktn "<< pktn << endl; // cout << " GetEventHeader()->GetPscuHeader()->GetCounter() "<< GetEventHeader()->GetPscuHeader()->GetCounter() << endl; // printf(" IDRUN %u \n",GetRunInfo()->ID); // @@ -3167,7 +3464,9 @@ shift = -1; }; - }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()) || + pktn != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter()) ) + && (quellagiusta+(Long64_t)shift) < GetYodaTree()->GetEntries() && shift < maxshift); if ( (quellagiusta+(Long64_t)shift+(Long64_t)prevshift) > GetYodaTree()->GetEntries() || shift == maxshift ) { cout << " Big trouble here, no such event in Level0 data! " <IsConnected() )return false; + cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<GetListOfFiles() ); + Int_t nf = 0; + TChainElement* element = 0; + while ((element = (TChainElement*) next())) { + c->Add(element->GetTitle()); + nf++; + } + + GetPamTree()->AddFriend(cname.Data()); + + cout << "external chain created and added to pamela friends :"<