98 for (Int_t iT = 0; iT < iNbSmTypes; iT++) {
101 for (Int_t iRpc = 0; iRpc < iNbRpc; iRpc++)
112 for (Int_t iSmType = 0; iSmType < iNbSmTypes; iSmType++) {
115 fvCPTOff[iSmType].resize(iNbSm * iNbRpc);
117 fvCPWalk[iSmType].resize(iNbSm * iNbRpc);
119 for (Int_t iSm = 0; iSm < iNbSm; iSm++) {
120 for (Int_t iRpc = 0; iRpc < iNbRpc; iRpc++) {
127 for (Int_t iTrg = 0; iTrg <
iNTrg; iTrg++)
128 fvCPDelTof[iSmType][iSm * iNbRpc + iRpc][iBx][iTrg] = 0.;
132 fvCPTOff[iSmType][iSm * iNbRpc + iRpc].resize(iNbChan);
133 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc].resize(iNbChan);
134 fvCPWalk[iSmType][iSm * iNbRpc + iRpc].resize(iNbChan);
136 for (Int_t iCh = 0; iCh < iNbChan; iCh++) {
137 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh].resize(nbSide);
138 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh].resize(nbSide);
139 fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh].resize(nbSide);
140 for (Int_t iSide = 0; iSide < nbSide; iSide++) {
141 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][iSide] = 0.;
142 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][iSide] = 1.;
145 fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][iSide][iWx] = 0.;
153 LOG(info) <<
"CbmTofSimpClusterizer::InitCalibParameter: defaults set";
157 TFile* oldFile = gFile;
158 TDirectory* oldDir = gDirectory;
162 LOG(info) <<
"CbmTofSimpClusterizer::InitCalibParameter: read histos from "
163 <<
"file " << fCalParFileName ;
166 if(fCalParFileName.IsNull())
return kTRUE;
168 fCalParFile =
new TFile(fCalParFileName,
"");
169 if(NULL == fCalParFile) {
170 LOG(error) <<
"CbmTofSimpClusterizer::InitCalibParameter: "
171 <<
"file " << fCalParFileName <<
" does not exist!" ;
180 for( Int_t iSmType = 0; iSmType < iNbSmTypes; iSmType++ )
184 for( Int_t iSm = 0; iSm < iNbSm; iSm++ )
185 for( Int_t iRpc = 0; iRpc < iNbRpc; iRpc++ )
187 TH2F *htempPos_pfx =(TH2F*) gDirectory->FindObjectAny( Form(
"cl_CorSmT%01d_sm%03d_rpc%03d_Pos_pfx",iSmType,iSm,iRpc));
188 TH2F *htempTOff_pfx=(TH2F*) gDirectory->FindObjectAny( Form(
"cl_CorSmT%01d_sm%03d_rpc%03d_TOff_pfx",iSmType,iSm,iRpc));
189 TH2F *htempTot_pfx =(TH2F*) gDirectory->FindObjectAny( Form(
"cl_CorSmT%01d_sm%03d_rpc%03d_Tot_pfx",iSmType,iSm,iRpc));
190 if(NULL != htempPos_pfx && NULL != htempTOff_pfx && NULL != htempTot_pfx)
193 Int_t iNbinTot = htempTot_pfx->GetNbinsX();
194 for( Int_t iCh = 0; iCh < iNbCh; iCh++ )
196 Double_t YMean=((TProfile *)htempPos_pfx)->GetBinContent(iCh+1);
197 Double_t TMean=((TProfile *)htempTOff_pfx)->GetBinContent(iCh+1);
199 fvCPTOff[iSmType][iSm*iNbRpc+iRpc][iCh][0] += -dTYOff + TMean ;
200 fvCPTOff[iSmType][iSm*iNbRpc+iRpc][iCh][1] += +dTYOff + TMean ;
202 Double_t TotMean=((TProfile *)htempTot_pfx)->GetBinContent(iCh+1);
207 LOG(debug1)<<
"CbmTofSimpClusterizer::InitCalibParameter:"
208 <<
" SmT "<< iSmType<<
" Sm "<<iSm<<
" Rpc "<<iRpc<<
" Ch "<<iCh
209 <<
": YMean "<<YMean<<
", TMean "<< TMean
210 <<
" -> " <<
fvCPTOff[iSmType][iSm*iNbRpc+iRpc][iCh][0]
211 <<
", " <<
fvCPTOff[iSmType][iSm*iNbRpc+iRpc][iCh][1]
212 <<
", " <<
fvCPTotGain[iSmType][iSm*iNbRpc+iRpc][iCh][0]
213 <<
", NbinTot "<< iNbinTot
216 TH1D *htempWalk0=(TH1D*)gDirectory->FindObjectAny(
217 Form(
"Cor_SmT%01d_sm%03d_rpc%03d_Ch%03d_S0_Walk_px", iSmType, iSm, iRpc, iCh ));
218 TH1D *htempWalk1=(TH1D*)gDirectory->FindObjectAny(
219 Form(
"Cor_SmT%01d_sm%03d_rpc%03d_Ch%03d_S1_Walk_px", iSmType, iSm, iRpc, iCh ));
220 if(NULL != htempWalk0 && NULL != htempWalk1 ) {
221 LOG(info)<<
"Initialize Walk correction for "
222 <<Form(
" SmT%01d_sm%03d_rpc%03d_Ch%03d",iSmType, iSm, iRpc, iCh)
225 LOG(error)<<
"CbmTofSimpClusterizer::InitCalibParameter: Inconsistent Walk histograms"
229 fvCPWalk[iSmType][iSm*iNbRpc+iRpc][iCh][0][iBin]=htempWalk0->GetBinContent(iBin+1);
230 fvCPWalk[iSmType][iSm*iNbRpc+iRpc][iCh][1][iBin]=htempWalk1->GetBinContent(iBin+1);
231 LOG(debug1)<<Form(
" SmT%01d_sm%03d_rpc%03d_Ch%03d bin %d walk %f ",iSmType, iSm, iRpc, iCh, iBin,
232 fvCPWalk[iSmType][iSm*iNbRpc+iRpc][iCh][0][iBin])
240 LOG(error)<<
" Histos " << Form(
"cl_SmT%01d_sm%03d_rpc%03d_XXX", iSmType, iSm, iRpc) <<
" not found. "
243 for(Int_t iTrg=0; iTrg<
iNTrg; iTrg++){
244 TH1D *htmpDelTof =(TH1D*) gDirectory->FindObjectAny( Form(
"cl_CorSmT%01d_sm%03d_rpc%03d_Trg%02d_DelTof",iSmType,iSm,iRpc,iTrg));
245 if (NULL==htmpDelTof) {
246 LOG(info)<<
" Histos " << Form(
"cl_CorSmT%01d_sm%03d_rpc%03d_Trg%02d_DelTof", iSmType, iSm, iRpc, iTrg) <<
" not found. "
250 LOG(info)<<
" Load DelTof from histos "<< Form(
"cl_CorSmT%01d_sm%03d_rpc%03d_Trg%02d_DelTof",iSmType,iSm,iRpc,iTrg)<<
"."
253 fvCPDelTof[iSmType][iSm*iNbRpc+iRpc][iBx][iTrg] += htmpDelTof->GetBinContent(iBx+1);
257 TDirectory * curdir = gDirectory;
258 gDirectory->cd( oldDir->GetPath() );
259 TH1D *h1DelTof=(TH1D *)htmpDelTof->Clone(Form(
"cl_CorSmT%01d_sm%03d_rpc%03d_Trg%02d_DelTof",iSmType,iSm,iRpc,iTrg));
261 LOG(info)<<
" copy histo "
262 <<h1DelTof->GetName()
267 gDirectory->cd( curdir->GetPath() );
278 LOG(info) <<
"CbmTofSimpClusterizer::InitCalibParameter: initialization done";
391 clock_gettime(CLOCK_REALTIME, &ts);
392 long beginTime = ts.tv_sec * 1000000000 + ts.tv_nsec;
396 Double_t dEventTime = 0.;
398 LOG(debug) << GetName() <<
": Input " << iInputNr <<
", event " << iEventNr <<
", event time " << dEventTime <<
" ns";
405 Double_t dMaxPairTimeDist = 3.2;
406 Double_t dMaxClustTimeDist = 0.2;
408 Int_t iNbTofDigi =
fTofDigis->GetEntriesFast();
410 LOG(debug) << GetName() <<
": Input " << iInputNr <<
", event " << iEventNr <<
", event time " << dEventTime <<
" ns"
411 <<
", TOF digis: " << iNbTofDigi;
481 for (Int_t iDigInd = 0; iDigInd < iNbTofDigi; ++iDigInd) {
482 CbmTofDigiExp* pDigi =
static_cast<CbmTofDigiExp*
>(
fTofDigis->At(iDigInd));
483 LOG(debug) << GetName() <<
": digi " << iDigInd <<
" pointer " << pDigi;
486 if (0 == pDigi->GetSide()) {
487 LOG(debug) <<
"top side";
488 LOG(debug) <<
"Type" << pDigi->GetType();
489 LOG(debug) <<
"RPC" << pDigi->GetRpc();
490 LOG(debug) <<
"Channel" << pDigi->GetChannel();
491 LOG(debug) <<
"Time" << pDigi->GetTime();
492 LOG(debug) <<
"SM " << pDigi->GetSm();
494 Int_t type = pDigi->GetType();
495 Int_t superModule = pDigi->GetSm();
496 Int_t rpc = pDigi->GetRpc();
498 Int_t channel = pDigi->GetChannel();
499 Double_t time = pDigi->GetTime();
501 Int_t index2 = superModule * nofRpc;
502 Int_t index3 = channel;
503 LOG(debug) <<
"Index 1 " << index1;
504 LOG(debug) <<
"Index 2 " << index2;
505 LOG(debug) <<
"Index 2 " << index3;
509 LOG(debug) <<
"Size 3 " <<
fStorDigiExp[index1][index2].size();
513 [pDigi->GetChannel()]
514 .topDigis[pDigi->GetTime()] = {pDigi, iDigInd};
515 LOG(debug) <<
"done";
518 LOG(debug) <<
"bottom side";
520 [pDigi->GetChannel()]
521 .bottomDigis[pDigi->GetTime()] = {pDigi, iDigInd};
584 LOG(debug) << GetName() <<
": TOF digis sorted";
586 Double_t hitpos_local[3];
591 for (Int_t iSmType = 0; iSmType < iNbSmTypes; ++iSmType) {
592 vector<vector<ChannelDigis>>& digisOfType =
fStorDigiExp[iSmType];
596 for (Int_t iSm = 0; iSm < iNbSm; ++iSm) {
597 for (Int_t iRpc = 0; iRpc < iNbRpc; ++iRpc) {
598 vector<ChannelDigis>& digisOfRpc = digisOfType[iSm *
fDigiBdfPar->
GetNbRpc(iSmType) + iRpc];
602 for (Int_t iCh = 0; iCh < iNbCh; ++iCh) {
604 map<Double_t, ChannelDigis::DigiDesc>& topDigis = digisOfChannel.
topDigis;
605 map<Double_t, ChannelDigis::DigiDesc>& bottomDigis = digisOfChannel.
bottomDigis;
607 if (bottomDigis.empty()) {
612 map<Double_t, ChannelDigis::DigiPair>& digiPairs = digisOfChannel.
digiPairs;
614 for (map<Double_t, ChannelDigis::DigiDesc>::iterator topDigiIter = topDigis.begin();
615 topDigiIter != topDigis.end(); ++topDigiIter) {
616 Double_t topTime = topDigiIter->first;
617 map<Double_t, ChannelDigis::DigiDesc>::iterator bottomDigiIter = bottomDigis.lower_bound(topTime);
619 if (bottomDigiIter == bottomDigis.end())
621 else if (bottomDigiIter->first > topTime) {
622 Double_t deltaT = bottomDigiIter->first - topTime;
624 if (deltaT > dMaxPairTimeDist && bottomDigiIter != bottomDigis.begin())
627 map<Double_t, ChannelDigis::DigiDesc>::iterator bottomDigiIter2 = bottomDigiIter;
630 Double_t deltaT2 = topTime - bottomDigiIter2->first;
632 if (deltaT2 < deltaT) bottomDigiIter = bottomDigiIter2;
636 if (TMath::Abs(bottomDigiIter->first - topTime) > dMaxPairTimeDist)
continue;
638 Double_t
y =
fvCPSigPropSpeed[iSmType][iRpc] * (bottomDigiIter->first - topTime) / 2;
648 Double_t digiPairTime = (topTime + bottomDigiIter->first) / 2;
649 digiPairs[digiPairTime] = {
y, topDigiIter->second, bottomDigiIter->second};
657 gGeoManager->GetCurrentMatrix();
659 gGeoManager->GetCurrentMatrix();
661 for (Int_t iCh = 0; iCh < iNbCh; ++iCh)
663 map<Double_t, ChannelDigis::DigiPair>& digiPairs = digisOfRpc[iCh].digiPairs;
665 for (map<Double_t, ChannelDigis::DigiPair>::iterator chIter = digiPairs.begin(); chIter != digiPairs.end();
667 Double_t chTime = chIter->first;
668 Double_t chY = chIter->second.y;
669 Double_t dTotS = chIter->second.topDigi.pDigi->GetTot() + chIter->second.bottomDigi.pDigi->GetTot();
670 Double_t dWeightedTime = chTime * dTotS;
671 Double_t dWeightedPosY = chY * dTotS;
673 Double_t dWeightedTimeErrorS =
674 chIter->second.topDigi.pDigi->GetTot() * chIter->second.topDigi.pDigi->GetTot()
675 + chIter->second.bottomDigi.pDigi->GetTot() * chIter->second.bottomDigi.pDigi->GetTot();
676 Double_t dWeightsSum = dTotS;
678 digiMatch->
AddLink(
CbmLink(0., chIter->second.topDigi.digiInd, iEventNr, iInputNr));
679 digiMatch->
AddLink(
CbmLink(0., chIter->second.bottomDigi.digiInd, iEventNr, iInputNr));
680 set<pair<Int_t, Int_t>> sPtsRef;
681 AddPts(sPtsRef, chIter->second.topDigi.pDigi);
682 AddPts(sPtsRef, chIter->second.bottomDigi.pDigi);
684 for (Int_t iNeighCh = iCh + 1; iNeighCh < iNbCh ; ++iNeighCh) {
685 map<Double_t, ChannelDigis::DigiPair>& neighDigiPairs = digisOfRpc[iNeighCh].digiPairs;
687 if (neighDigiPairs.empty())
break;
689 map<Double_t, ChannelDigis::DigiPair>::iterator neighIter = neighDigiPairs.lower_bound(chTime);
691 if (neighIter == neighDigiPairs.end())
693 else if (neighIter->first > chTime && neighIter != neighDigiPairs.begin()) {
694 Double_t deltaTHigh = neighIter->first - chTime;
695 map<Double_t, ChannelDigis::DigiPair>::iterator neighIter_1 = neighIter;
697 Double_t deltaTLow = chTime - neighIter_1->first;
699 if (deltaTLow < deltaTHigh) neighIter = neighIter_1;
702 if (TMath::Abs(neighIter->first - chTime) > dMaxClustTimeDist
703 || TMath::Abs(neighIter->second.y - chY) > dMaxSpaceDist)
706 Double_t dTotNeighS =
707 neighIter->second.topDigi.pDigi->GetTot() + neighIter->second.bottomDigi.pDigi->GetTot();
708 dWeightedTimeErrorS +=
709 neighIter->second.topDigi.pDigi->GetTot() * neighIter->second.topDigi.pDigi->GetTot()
710 + neighIter->second.bottomDigi.pDigi->GetTot() * neighIter->second.bottomDigi.pDigi->GetTot();
711 dWeightedTime += neighIter->first * dTotNeighS;
712 dWeightedPosY += neighIter->second.y * dTotNeighS;
714 dWeightsSum += dTotNeighS;
716 digiMatch->
AddLink(
CbmLink(0., neighIter->second.topDigi.digiInd, iEventNr, iInputNr));
717 digiMatch->
AddLink(
CbmLink(0., neighIter->second.bottomDigi.digiInd, iEventNr, iInputNr));
718 AddPts(sPtsRef, neighIter->second.topDigi.pDigi);
719 AddPts(sPtsRef, neighIter->second.bottomDigi.pDigi);
720 neighDigiPairs.erase(neighIter);
723 Double_t clusterTime = dWeightedTime / dWeightsSum;
725 Double_t clusterTimeError = TMath::Sqrt(dWeightedTimeErrorS) * timeRes / dWeightsSum;
726 Double_t clusterY = dWeightedPosY / dWeightsSum;
727 Double_t clusterX = dWeightedPosX / dWeightsSum;
728 hitpos_local[0] = clusterX;
729 hitpos_local[1] = clusterY;
734 gGeoManager->LocalToMaster(hitpos_local, hitpos);
735 TVector3 hitPos(hitpos[0], hitpos[1], hitpos[2]);
747 new ((*fTofHits)[fiNbHits])
CbmTofHit(iDetId, hitPos,
753 new ((*fTofDigiMatchs)[fiNbHits])
CbmMatch(*digiMatch);
765 clock_gettime(CLOCK_REALTIME, &ts);
766 long endTime = ts.tv_sec * 1000000000 + ts.tv_nsec;