18 #include "CbmTofHit.h"
22 #include "FairLogger.h"
23 #include "FairRunAna.h"
24 #include "FairRuntimeDb.h"
27 #include <TClonesArray.h>
28 #include <TDirectory.h>
30 #include <TGeoManager.h>
38 , fTofClusterizer(NULL)
39 , fTofFindTracks(NULL)
40 , fTrackletTools(NULL)
43 , fTofDigiMatchColl(NULL)
60 FairRootManager* fManager = FairRootManager::Instance();
64 LOG(warning) <<
"No CbmDigiManager";
70 LOG(warn) <<
"CbmTofCalibrator: No digi input!";
76 LOG(warn) <<
"CbmTofCalibrator: no access to active calibration";
79 LOG(info) <<
"Current calibration file: " << CalParFileName;
83 LOG(warn) <<
"CbmTofCalibrator: no access to tof tracker ";
92 LOG(error) <<
"CbmTofCalibrator: no access to DigiMatch ";
97 if (!
InitParameters()) { LOG(error) <<
"CbmTofCalibrator: No parameters!"; }
100 LOG(error) <<
"CbmTofCalibrator: No histograms!";
106 LOG(info) <<
"TofCalibrator initialized successfully";
111 LOG(info) <<
"InitParameters: get par pointers from RTDB";
113 FairRun* ana = FairRun::Instance();
114 FairRuntimeDb* rtdb = ana->GetRuntimeDb();
117 if (NULL ==
fDigiPar)
return kFALSE;
128 LOG(info) <<
"Define Calibrator histos for " << iNbDet <<
" detectors ";
136 for (Int_t iDetIndx = 0; iDetIndx < iNbDet; iDetIndx++) {
146 if (NULL == fChannelInfo) {
147 LOG(warning) <<
"No DigiPar for Det " << Form(
"0x%08x", iUCellId);
152 Form(
"cal_SmT%01d_sm%03d_rpc%03d_Pos", iSmType, iSmId, iRpcId),
154 "Clu position of Rpc #%03d in Sm %03d of type %d; Strip []; ypos [cm]",
165 Double_t TSumMax = 2.;
168 Form(
"cal_SmT%01d_sm%03d_rpc%03d_TOff", iSmType, iSmId, iRpcId),
170 "Clu TimeZero of Rpc #%03d in Sm %03d of type %d; Strip []; TOff [ns]",
181 Double_t TotMax = 25.;
183 Form(
"cal_SmT%01d_sm%03d_rpc%03d_Tot", iSmType, iSmId, iRpcId),
185 "Clu Tot of Rpc #%03d in Sm %03d of type %d; StripSide []; TOT [a.u.]",
200 for (Int_t iSide = 0; iSide < 2; iSide++) {
202 new TH2D(Form(
"cal_SmT%01d_sm%03d_rpc%03d_Ch%03d_S%01d_Walk",
208 Form(
"Walk in SmT%01d_sm%03d_rpc%03d_Ch%03d_S%01d_Walk; Tot "
209 "[a.u.]; #DeltaT [ns]",
230 if (pTrk->
GetTt() < 0)
return;
237 for (Int_t iHit = 0; iHit < pTrk->
GetNofHits(); iHit++) {
244 std::map<UInt_t, UInt_t>::iterator it =
fDetIdIndexMap.find(iDetId);
247 Int_t iDetIndx = it->second;
252 if (NULL == fChannelInfo) {
253 LOG(error) <<
"Invalid Channel Pointer for ChId "
254 << Form(
" 0x%08x ", iChId) <<
", Ch " << iCh;
257 gGeoManager->FindNode(
258 fChannelInfo->
GetX(), fChannelInfo->
GetY(), fChannelInfo->
GetZ());
260 hitpos[0] = pHit->
GetX();
261 hitpos[1] = pHit->
GetY();
262 hitpos[2] = pHit->
GetZ();
263 Double_t hlocal_p[3];
265 gGeoManager->GetCurrentNode();
266 gGeoManager->MasterToLocal(hitpos, hlocal_p);
269 Double_t hlocal_f[3];
270 gGeoManager->MasterToLocal(hitpos, hlocal_f);
273 (Double_t) iCh, hlocal_p[1] - hlocal_f[1]);
282 LOG(error) <<
" Inconsistent DigiMatches for Hitind " << iMA
287 for (Int_t iLink = 0; iLink < digiMatch->
GetNofLinks();
291 Int_t iDigInd1 = (digiMatch->
GetLink(iLink + 1)).GetIndex();
295 Int_t iSide0 = tDigi0->
GetSide();
296 LOG(debug) <<
"Fill Walk for " << iDetIndx <<
", TSRCS " << iSmType << iSm
297 << iRpc << iCh0 << iSide0 <<
", " << tDigi0 <<
", " << pTrk;
298 if (iDetIndx > (Int_t)
fhCalWalk.size()) {
299 LOG(error) <<
"Invalid DetIndx " << iDetIndx;
302 if (iCh0 > (Int_t)
fhCalWalk[iDetIndx].size()) {
303 LOG(error) <<
"Invalid Ch0 " << iCh0;
306 if (iSide0 > (Int_t)
fhCalWalk[iDetIndx][iCh0].size()) {
307 LOG(error) <<
"Invalid Side0 " << iSide0;
314 + (1. - 2. * tDigi0->
GetSide()) * hlocal_p[1]
319 + 2. * (1. - 2. * tDigi0->
GetSide()) * (hlocal_p[1] - hlocal_f[1])
333 Int_t iSide1 = tDigi1->
GetSide();
334 LOG(debug) <<
"Fill Walk for " << iDetIndx <<
", TSRCS " << iSmType << iSm
335 << iRpc << iCh1 << iSide1 <<
", " << tDigi1 <<
", " << pTrk;
336 if (iCh1 > (Int_t)
fhCalWalk[iDetIndx].size()) {
337 LOG(error) <<
"Invalid Ch1 " << iCh1;
340 if (iSide1 > (Int_t)
fhCalWalk[iDetIndx][iCh1].size()) {
341 LOG(error) <<
"Invalid Side1 " << iSide1;
347 + (1. - 2. * tDigi1->
GetSide()) * hlocal_p[1]
352 + 2. * (1. - 2. * tDigi1->
GetSide()) * (hlocal_p[1] - hlocal_f[1])
360 LOG(info) <<
"CbmTofCalibrator:: update histos from "
363 <<
" with option " << iOpt;
366 if (NULL == fCalParFile) {
368 <<
"Could not open TofClusterizer calibration file, abort Update ";
374 const Double_t MINCTS = 100.;
388 TProfile* hpP =
fhCalPos[iDetIndx]->ProfileX();
389 TProfile* hpT =
fhCalTOff[iDetIndx]->ProfileX();
390 TH1* hCalT =
fhCalTOff[iDetIndx]->ProjectionX();
393 Double_t dAvOff = 0.;
394 for (Int_t iBin = 0; iBin <
fhCorTOff[iDetIndx]->GetNbinsX(); iBin++) {
395 Double_t dDt = hpT->GetBinContent(iBin + 1);
396 Double_t dCorT =
fhCorTOff[iDetIndx]->GetBinContent(iBin + 1);
397 Double_t dCts = hCalT->GetBinContent(iBin + 1);
398 if (iDetIndx == -1) {
400 "Update %s: bin %02d, Cts: %d, Old %f, dev %f, av %f, new %f",
407 dCorT - dDt + dAvOff);
409 Double_t dDp = hpP->GetBinContent(iBin + 1);
410 Double_t dCorP =
fhCorPos[iDetIndx]->GetBinContent(iBin + 1);
412 fhCorTOff[iDetIndx]->SetBinContent(iBin + 1, dCorT + dDt + dAvOff);
413 fhCorPos[iDetIndx]->SetBinContent(iBin + 1, dCorP + dDp);
418 const Double_t MinCounts = 10.;
420 for (Int_t iCh = 0; iCh < iNbCh; iCh++) {
421 for (Int_t iSide = 0; iSide < 2; iSide++) {
424 fhCalWalk[iDetIndx][iCh][iSide]->ProfileX();
425 TH1* hCW =
fhCalWalk[iDetIndx][iCh][iSide]
429 for (Int_t iBin = 0; iBin <
fhCorTOff[iDetIndx]->GetNbinsX();
431 Double_t dCts = hCW->GetBinContent(iBin + 1);
432 Double_t dWOff =
fhCorWalk[iDetIndx][iCh][iSide]->GetBinContent(
434 if (dCts > MinCounts) { dCorT = hpW->GetBinContent(iBin + 1); }
435 fhCorWalk[iDetIndx][iCh][iSide]->SetBinContent(
436 iBin + 1, dWOff + dCorT);
440 Double_t dCtsAll = 0.;
441 for (Int_t iBin = 0; iBin <
fhCorTOff[iDetIndx]->GetNbinsX();
443 Double_t dCts = hCW->GetBinContent(iBin + 1);
444 Double_t dWOff =
fhCorWalk[iDetIndx][iCh][iSide]->GetBinContent(
446 if (dCts > MinCounts) {
448 dMean += dCts * dWOff;
451 if (dCtsAll > 0.) dMean /= dCtsAll;
453 for (Int_t iBin = 0; iBin <
fhCorTOff[iDetIndx]->GetNbinsX();
455 Double_t dWOff =
fhCorWalk[iDetIndx][iCh][iSide]->GetBinContent(
457 fhCorWalk[iDetIndx][iCh][iSide]->SetBinContent(
458 iBin + 1, dWOff - dMean);
466 TFile* fCalParFileNew =
467 new TFile(Form(
"New_%s", fCalParFile->GetName()),
"RECREATE");
469 fCalParFileNew->Close();
475 LOG(info) <<
"Read Cor histos from file " << fHist->GetName();
495 fhCorPos[iDetIndx] = (TH1*) gDirectory->FindObjectAny(
496 Form(
"cl_CorSmT%01d_sm%03d_rpc%03d_Pos_pfx", iSmType, iSm, iRpc));
498 LOG(error) <<
"hCorPos not found";
501 fhCorTOff[iDetIndx] = (TH1*) gDirectory->FindObjectAny(
502 Form(
"cl_CorSmT%01d_sm%03d_rpc%03d_TOff_pfx", iSmType, iSm, iRpc));
503 fhCorTot[iDetIndx] = (TH1*) gDirectory->FindObjectAny(
504 Form(
"cl_CorSmT%01d_sm%03d_rpc%03d_Tot_Mean", iSmType, iSm, iRpc));
505 fhCorTotOff[iDetIndx] = (TH1*) gDirectory->FindObjectAny(
506 Form(
"cl_CorSmT%01d_sm%03d_rpc%03d_Tot_Off", iSmType, iSm, iRpc));
510 for (Int_t iCh = 0; iCh < iNbCh; iCh++) {
512 for (Int_t iSide = 0; iSide < 2; iSide++) {
514 fhCorWalk[iDetIndx][iCh][iSide] = (TH1*) gDirectory->FindObjectAny(
515 Form(
"Cor_SmT%01d_sm%03d_rpc%03d_Ch%03d_S%d_Walk_px",
527 LOG(info) <<
"Write Cor histos to file " << fHist->GetName();
528 TDirectory* oldir = gDirectory;
536 Int_t iNbCh = (Int_t)
fhCorWalk[iDetIndx].size();
537 for (Int_t iCh = 0; iCh < iNbCh; iCh++) {
538 for (Int_t iSide = 0; iSide < 2; iSide++) {
539 fhCorWalk[iDetIndx][iCh][iSide]->Write();