185 for (int32_t iSmType = 0; iSmType < iNbSmTypes; iSmType++) {
188 fvCPTOff[iSmType].resize(iNbSm * iNbRpc);
191 fvCPWalk[iSmType].resize(iNbSm * iNbRpc);
192 fvCPTOffY[iSmType].resize(iNbSm * iNbRpc);
195 for (int32_t iSm = 0; iSm < iNbSm; iSm++) {
196 for (int32_t iRpc = 0; iRpc < iNbRpc; iRpc++) {
211 fvCPTOff[iSmType][iSm * iNbRpc + iRpc].resize(iNbChan);
212 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc].resize(iNbChan);
213 fvCPTotOff[iSmType][iSm * iNbRpc + iRpc].resize(iNbChan);
214 fvCPWalk[iSmType][iSm * iNbRpc + iRpc].resize(iNbChan);
216 for (int32_t iCh = 0; iCh < iNbChan; iCh++) {
217 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh].resize(nbSide);
218 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh].resize(nbSide);
219 fvCPTotOff[iSmType][iSm * iNbRpc + iRpc][iCh].resize(nbSide);
220 fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh].resize(nbSide);
221 for (int32_t iSide = 0; iSide < nbSide; iSide++) {
222 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][iSide] = 0.;
223 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][iSide] = 1.;
224 fvCPTotOff[iSmType][iSm * iNbRpc + iRpc][iCh][iSide] = 0.;
227 fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][iSide][iWx] = 0.;
234 LOG(info) <<
"CbmTaskTofClusterizerParWrite::InitCalibParameter: defaults set";
242 TFile* oldFile = gFile;
243 TDirectory* oldDir = gDirectory;
245 LOG(info) <<
"CbmTaskTofClusterizerParWrite::InitCalibParameter: read histos from "
252 if (NULL == calParFile) {
258 if (NULL == calParFile)
259 LOG(fatal) <<
"CbmTaskTofClusterizerParWrite::InitCalibParameter: "
264 LOG(fatal) <<
"Calibration parameter file not existing!";
267 for (int32_t iSmType = 0; iSmType < iNbSmTypes; iSmType++) {
270 TProfile*
hSvel = (TProfile*) gDirectory->FindObjectAny(Form(
"cl_SmT%01d_Svel", iSmType));
271 for (int32_t iSm = 0; iSm < iNbSm; iSm++)
272 for (int32_t iRpc = 0; iRpc < iNbRpc; iRpc++) {
274 std::vector<std::vector<double>>& vCPTotGain =
fvCPTotGain[iSmType][iSm * iNbRpc + iRpc];
275 std::vector<std::vector<double>>& vCPTOff =
fvCPTOff[iSmType][iSm * iNbRpc + iRpc];
276 std::vector<std::vector<double>>& vCPTotOff =
fvCPTotOff[iSmType][iSm * iNbRpc + iRpc];
277 std::vector<std::vector<std::vector<double>>>& vCPWalk =
fvCPWalk[iSmType][iSm * iNbRpc + iRpc];
279 std::vector<double>& vCPTOffY =
fvCPTOffY[iSmType][iSm * iNbRpc + iRpc];
281 double& vCPTOffYRange =
fvCPTOffYRange[iSmType][iSm * iNbRpc + iRpc];
285 double Vscal =
hSvel->GetBinContent(iSm * iNbRpc + iRpc + 1);
286 if (Vscal == 0.) Vscal = 1.;
289 LOG(info) <<
"Modify " << iSmType << iSm << iRpc <<
" Svel by " << Vscal <<
" to "
293 (TH2D*) gDirectory->FindObjectAny(Form(
"cl_CorSmT%01d_sm%03d_rpc%03d_Pos_pfx", iSmType, iSm, iRpc));
294 TH2D* htempTOff_pfx =
295 (TH2D*) gDirectory->FindObjectAny(Form(
"cl_CorSmT%01d_sm%03d_rpc%03d_TOff_pfx", iSmType, iSm, iRpc));
296 TH1D* htempTot_Mean =
297 (TH1D*) gDirectory->FindObjectAny(Form(
"cl_CorSmT%01d_sm%03d_rpc%03d_Tot_Mean", iSmType, iSm, iRpc));
299 (TH1D*) gDirectory->FindObjectAny(Form(
"cl_CorSmT%01d_sm%03d_rpc%03d_Tot_Off", iSmType, iSm, iRpc));
300 if (NULL != htempPos_pfx && NULL != htempTOff_pfx && NULL != htempTot_Mean && NULL != htempTot_Off) {
303 for (int32_t iCh = 0; iCh < iNbCh; iCh++) {
304 for (int32_t iSide = 0; iSide < 2; iSide++) {
305 double TotMean = htempTot_Mean->GetBinContent(iCh * 2 + 1 + iSide);
306 if (0.001 < TotMean) {
307 vCPTotGain[iCh][iSide] *=
fdTTotMean / TotMean;
309 vCPTotOff[iCh][iSide] = htempTot_Off->GetBinContent(iCh * 2 + 1 + iSide);
311 double YMean = ((TProfile*) htempPos_pfx)->GetBinContent(iCh + 1);
312 double TMean = ((TProfile*) htempTOff_pfx)->GetBinContent(iCh + 1);
313 if (std::isnan(YMean) || std::isnan(TMean)) {
314 LOG(warn) <<
"Invalid calibration for TSRC " << iSmType << iSm << iRpc << iCh <<
", use default!";
318 if (5 == iSmType || 8 == iSmType) dTYOff = 0.;
319 vCPTOff[iCh][0] += -dTYOff + TMean;
320 vCPTOff[iCh][1] += +dTYOff + TMean;
322 if (5 == iSmType || 8 == iSmType) {
323 vCPTOff[iCh][1] = vCPTOff[iCh][0];
324 vCPTotGain[iCh][1] = vCPTotGain[iCh][0];
325 vCPTotOff[iCh][1] = vCPTotOff[iCh][0];
328 if (iSmType == 0 && iSm == 2 && iRpc == 0)
330 LOG(info) <<
"InitCalibParameter:"
331 <<
" TSRC " << iSmType << iSm << iRpc << iCh
332 << Form(
": YMean %6.3f, TYOff %6.3f, TMean %6.3f", YMean, dTYOff, TMean) <<
" -> "
333 << Form(
" TOff %f, %f, TotG %f, %f ", vCPTOff[iCh][0], vCPTOff[iCh][1], vCPTotGain[iCh][0],
336 TH1D* htempWalk0 = (TH1D*) gDirectory->FindObjectAny(
337 Form(
"Cor_SmT%01d_sm%03d_rpc%03d_Ch%03d_S0_Walk_px", iSmType, iSm, iRpc, iCh));
338 TH1D* htempWalk1 = (TH1D*) gDirectory->FindObjectAny(
339 Form(
"Cor_SmT%01d_sm%03d_rpc%03d_Ch%03d_S1_Walk_px", iSmType, iSm, iRpc, iCh));
340 if (NULL == htempWalk0 && NULL == htempWalk1) {
342 htempWalk0 =
new TH1D(Form(
"Cor_SmT%01d_sm%03d_rpc%03d_Ch%03d_S0_Walk_px", iSmType, iSm, iRpc, iCh),
343 Form(
"Walk in SmT%01d_sm%03d_rpc%03d_Ch%03d_S%01d_Walk; Tot [a.u.]; #DeltaT [ns]",
344 iSmType, iSm, iRpc, iCh, iSide),
347 htempWalk1 =
new TH1D(Form(
"Cor_SmT%01d_sm%03d_rpc%03d_Ch%03d_S0_Walk_px", iSmType, iSm, iRpc, iCh),
348 Form(
"Walk in SmT%01d_sm%03d_rpc%03d_Ch%03d_S%01d_Walk; Tot [a.u.]; #DeltaT [ns]",
349 iSmType, iSm, iRpc, iCh, iSide),
352 if (NULL != htempWalk0 && NULL != htempWalk1) {
353 LOG(debug) <<
"Initialize Walk correction for "
354 << Form(
" SmT%01d_sm%03d_rpc%03d_Ch%03d", iSmType, iSm, iRpc, iCh);
356 LOG(error) <<
"CbmTaskTofClusterizerParWrite::InitCalibParameter: "
357 "Inconsistent Walk histograms";
359 vCPWalk[iCh][0][iBin] = htempWalk0->GetBinContent(iBin + 1);
360 vCPWalk[iCh][1][iBin] = htempWalk1->GetBinContent(iBin + 1);
361 if (iSmType == 0 && iSm == 0 && iRpc == 2 && iCh == 15)
362 LOG(info) << Form(
"Read new SmT%01d_sm%03d_rpc%03d_Ch%03d bin %d cen %f walk %f %f", iSmType, iSm,
363 iRpc, iCh, iBin, htempWalk0->GetBinCenter(iBin + 1), vCPWalk[iCh][0][iBin],
364 vCPWalk[iCh][1][iBin]);
365 if (5 == iSmType || 8 == iSmType) {
366 if (vCPWalk[iCh][1][iBin] != vCPWalk[iCh][0][iBin]) {
367 LOG(fatal) <<
"Inconsisten walk values for TSRC " << iSmType << iSm << iRpc << iCh <<
", Bin "
368 << iBin <<
": " << vCPWalk[iCh][0][iBin] <<
", " << vCPWalk[iCh][1][iBin];
370 vCPWalk[iCh][1][iBin] = vCPWalk[iCh][0][iBin];
371 htempWalk1->SetBinContent(iBin + 1, vCPWalk[iCh][1][iBin]);
376 LOG(info) <<
"No Walk histograms for TSRC " << iSmType << iSm << iRpc << iCh;
380 LOG(info) <<
"Check for TCorY in " << gDirectory->GetName();
382 (TH1*) gDirectory->FindObjectAny(Form(
"calXY_SmT%d_sm%03d_rpc%03d_TOff_z_all_TcorY", iSmType, iSm, iRpc));
383 if (NULL != hTCorY) {
384 vCPTOffYBinWidth = hTCorY->GetBinWidth(0);
385 vCPTOffYRange = hTCorY->GetXaxis()->GetXmax();
386 LOG(info) <<
"Initialize TCorY: TSR " << iSmType << iSm << iRpc <<
", Bwid " << vCPTOffYBinWidth
387 <<
", Range " << vCPTOffYRange;
388 vCPTOffY.resize(hTCorY->GetNbinsX());
389 for (
int iB = 0; iB < hTCorY->GetNbinsX(); iB++) {
390 vCPTOffY[iB] = hTCorY->GetBinContent(iB + 1);
395 LOG(warning) <<
" Calibration histos " << Form(
"cl_SmT%01d_sm%03d_rpc%03d_XXX", iSmType, iSm, iRpc)
405 LOG(info) <<
"CbmTaskTofClusterizerParWrite::InitCalibParameter: initialization done";
417 gGeoManager->CdTop();
422 std::map<uint32_t, uint32_t> detIdIndexMap;
425 detIdIndexMap[iUniqueId] = ind;
431 setup.
rpcs.resize(iNbSmTypes);
433 for (int32_t iSmType = 0; iSmType < iNbSmTypes; iSmType++) {
437 setup.
NbSm.push_back(iNbSm);
438 setup.
NbRpc.push_back(iNbRpc);
440 setup.
rpcs[iSmType].resize(iNbSm * iNbRpc);
442 for (int32_t iSm = 0; iSm < iNbSm; iSm++) {
443 for (int32_t iRpc = 0; iRpc < iNbRpc; iRpc++) {
451 if (channelInfo ==
nullptr) {
456 gGeoManager->FindNode(channelInfo->
GetX(), channelInfo->
GetY(), channelInfo->
GetZ());
457 const double* tra_ptr = gGeoManager->MakePhysicalNode()->GetMatrix()->GetTranslation();
458 const double* rot_ptr = gGeoManager->GetCurrentMatrix()->GetRotationMatrix();
460 memcpy(par.
cell.
rotation.data(), rot_ptr, 9 *
sizeof(
double));
468 const int32_t iDetIndx = detIdIndexMap[iDetId];
483 for (int32_t iCh = 0; iCh < iNbChan; iCh++) {
489 setup.
rpcs[iSmType][iSm * iNbRpc + iRpc] = par;
497 calib.
rpcs.resize(iNbSmTypes);
499 for (int32_t iSmType = 0; iSmType < iNbSmTypes; iSmType++) {
502 calib.
NbSm.push_back(iNbSm);
503 calib.
NbRpc.push_back(iNbRpc);
504 calib.
rpcs[iSmType].resize(iNbSm * iNbRpc);
506 for (int32_t iSm = 0; iSm < iNbSm; iSm++) {
507 for (int32_t iRpc = 0; iRpc < iNbRpc; iRpc++) {
519 for (int32_t iCh = 0; iCh < iNbChan; iCh++) {
527 calib.
rpcs[iSmType][iSm * iNbRpc + iRpc] = par;
535 std::ofstream fout(
"TofHitfinderPar.yaml");
539 std::ofstream fcalout(
"TofCalibratePar.yaml");
540 fcalout << dump(calib);