190 TDirectory* oldir = gDirectory;
195 LOG(info) <<
"Define Calibrator histos for " << iNbDet <<
" detectors "
196 <<
"in directory " << gDirectory->GetName() <<
", old " << oldir->GetName();
198 fhCalR0 =
new TH1D(
"hCalR0",
"Tracklet distance to nominal vertex; R_0 [cm]", 100, 0., 0.5);
199 fhCalDX0 =
new TH1D(
"hCalDX0",
"Tracklet distance to nominal vertex; #DeltaX_0 [cm]", 100, -1.5, 1.5);
200 fhCalDY0 =
new TH1D(
"hCalDY0",
"Tracklet distance to nominal vertex; #DeltaY_0 [cm]", 100, -1.5, 1.5);
202 fhCalCounterDt =
new TH1D(
"hCalCounterDt",
"CalibCounterDt ; #Deltat [ns]", 100, -0.2, 0.2);
203 fhCalCounterDy =
new TH1D(
"hCalCounterDy",
"CalibCounterDy ; #Deltay [cm]", 100, -0.8, 0.8);
204 fhCalChannelDt =
new TH1D(
"hCalChannelDt",
"CalibChannelDt ; #Deltat [ns]", 100, -0.25, 0.25);
205 fhCalChannelDy =
new TH1D(
"hCalChannelDy",
"CalibChannelDy ; #Deltat [ns]", 100, -1.8, 1.8);
227 for (Int_t iDetIndx = 0; iDetIndx < iNbDet; iDetIndx++) {
236 if (NULL == fChannelInfo) {
237 LOG(warning) <<
"No DigiPar for Det " << Form(
"0x%08x", iUCellId);
240 Double_t YMAX = TMath::Max(2., fChannelInfo->
GetSizey()) * 0.75;
242 Double_t TotMax = 20.;
244 Form(
"cal_SmT%01d_sm%03d_rpc%03d_Tot", iSmType, iSmId, iRpcId),
245 Form(
"Clu Tot of Rpc #%03d in Sm %03d of type %d; Strip []; Tot [a.u.]", iRpcId, iSmId, iSmType),
249 new TH3F(Form(
"calXY_SmT%01d_sm%03d_rpc%03d_Tot", iSmType, iSmId, iRpcId),
250 Form(
"Clu Tot of Rpc #%03d in Sm %03d of type %d; Strip []; y [cm]; Tot [a.u.]", iRpcId, iSmId, iSmType),
252 YMAX, 100, 0., TotMax);
255 new TH2F(Form(
"cal_SmT%01d_sm%03d_rpc%03d_Position", iSmType, iSmId, iRpcId),
256 Form(
"Clu position of Rpc #%03d in Sm %03d of type %d; Strip []; ypos [cm]", iRpcId, iSmId, iSmType),
261 new TH2F(Form(
"cal_SmT%01d_sm%03d_rpc%03d_Pos", iSmType, iSmId, iRpcId),
262 Form(
"Clu pos deviation of Rpc #%03d in Sm %03d of type %d; "
263 "Strip []; ypos [cm]",
264 iRpcId, iSmId, iSmType),
267 Double_t TSumMax = 2.;
270 Form(
"cal_SmT%01d_sm%03d_rpc%03d_TOff", iSmType, iSmId, iRpcId),
271 Form(
"Clu T0 deviation of Rpc #%03d in Sm %03d of type %d; Strip []; TOff [ns]", iRpcId, iSmId, iSmType),
275 Form(
"calXY_SmT%01d_sm%03d_rpc%03d_TOff", iSmType, iSmId, iRpcId),
276 Form(
"XY T0 deviation of Rpc #%03d in Sm %03d of type %d; Strip []; y[cm]; TOff [ns]", iRpcId, iSmId, iSmType),
278 -TSumMax * 0.5, TSumMax * 0.5);
281 fhCalTofOff[iDetIndx] =
new TH2F(Form(
"cal_SmT%01d_sm%03d_rpc%03d_TofOff", iSmType, iSmId, iRpcId),
282 Form(
"Clu T0 deviation of Rpc #%03d in Sm %03d of type %d; "
283 "Strip []; TofOff [ns]",
284 iRpcId, iSmId, iSmType),
289 new TH2F(Form(
"cal_SmT%01d_sm%03d_rpc%03d_DelPos", iSmType, iSmId, iRpcId),
290 Form(
"Clu position difference of Rpc #%03d in Sm %03d of type "
291 "%d; Strip []; #Deltaypos(clu) [cm]",
292 iRpcId, iSmId, iSmType),
296 new TH2F(Form(
"cal_SmT%01d_sm%03d_rpc%03d_DelTOff", iSmType, iSmId, iRpcId),
297 Form(
"Clu TimeZero Difference of Rpc #%03d in Sm %03d of type %d; Strip "
298 "[]; #DeltaTOff(clu) [ns]",
299 iRpcId, iSmId, iSmType),
303 new TH2D(Form(
"cal_SmT%01d_sm%03d_rpc%03d_Trms", iSmType, iSmId, iRpcId),
304 Form(
"Clu Time RMS of Rpc #%03d in Sm %03d of type %d; Strip []; Trms [ns]", iRpcId, iSmId, iSmType),
308 new TH2D(Form(
"cal_SmT%01d_sm%03d_rpc%03d_Size", iSmType, iSmId, iRpcId),
309 Form(
"Clu size of Rpc #%03d in Sm %03d of type %d; Strip []; size [strips]", iRpcId, iSmId, iSmType),
314 new TH2D(Form(
"cal_SmT%01d_sm%03d_rpc%03d_WalkAv", iSmType, iSmId, iRpcId),
315 Form(
"Walk in SmT%01d_sm%03d_rpc%03d_WalkAv; Tot [a.u.]; #DeltaT [ns]", iSmType, iSmId, iRpcId),
328 for (Int_t iSide = 0; iSide < 2; iSide++) {
330 new TH2D(Form(
"cal_SmT%01d_sm%03d_rpc%03d_Ch%03d_S%01d_Walk", iSmType, iSmId, iRpcId, iCh, iSide),
331 Form(
"Walk in SmT%01d_sm%03d_rpc%03d_Ch%03d_S%01d_Walk; Tot [a.u.]; #DeltaT [ns]", iSmType, iSmId,
335 new TH2D(Form(
"cal_SmT%01d_sm%03d_rpc%03d_Ch%03d_S%01d_DtWalk", iSmType, iSmId, iRpcId, iCh, iSide),
336 Form(
"SmT%01d_sm%03d_rpc%03d_Ch%03d_S%01d_DtWalk; Tot [a.u.]; #DeltaT [ns]", iSmType, iSmId, iRpcId,
341 new TH3D(Form(
"calTotY_SmT%01d_sm%03d_rpc%03d_Ch%03d_S%01d_Walk", iSmType, iSmId, iRpcId, iCh, iSide),
342 Form(
"YWalk in SmT%01d_sm%03d_rpc%03d_Ch%03d_S%01d_Walk; Tot [a.u.]; y [cm]; #DeltaT [ns]", iSmType,
343 iSmId, iRpcId, iCh, iSide),
347 new TH3D(Form(
"calTotY_SmT%01d_sm%03d_rpc%03d_Ch%03d_S%01d_TOff", iSmType, iSmId, iRpcId, iCh, iSide),
348 Form(
"YTot in SmT%01d_sm%03d_rpc%03d_Ch%03d_S%01d_TOff; Tot [a.u.]; y [cm]; #DeltaT [ns]", iSmType,
349 iSmId, iRpcId, iCh, iSide),
986 LOG(info) <<
"CbmTofCalibrator:: update histos from "
987 <<
"file " << CalFileName <<
" with option " << iOpt;
988 int iOpt0 = iOpt % 10;
989 int iOpt1 = (iOpt - iOpt0) / 10;
992 TFile* oldFile = gFile;
993 TDirectory* oldDir = gDirectory;
995 TFile* fCalParFile =
new TFile(CalFileName,
"update");
996 if (NULL == fCalParFile) {
997 LOG(warn) <<
"Could not open TofClusterizer calibration file " << CalFileName;
999 int iCalMode = CalFileName.Index(
"tofClust") - 3;
1000 CalFileName(iCalMode) =
'3';
1001 LOG(info) <<
"Modified CalFileName = " << CalFileName;
1002 fCalParFile =
new TFile(CalFileName,
"update");
1003 if (NULL == fCalParFile) LOG(fatal) <<
"Could not open TofClusterizer calibration file " << CalFileName;
1006 assert(fCalParFile);
1009 const Double_t MINCTS = 100.;
1012 Double_t dBeamTOff = 0.;
1017 if (
fhCalTOff[iDetIndx]->GetEntries() > MINCTS) {
1018 TH1* hBy = (TH1*)
fhCalTOff[iDetIndx]->ProjectionY();
1020 Double_t dFMean = hBy->GetBinCenter(hBy->GetMaximumBin());
1021 Double_t dFLim = 0.5;
1022 Double_t dBinSize = hBy->GetBinWidth(1);
1023 dFLim = TMath::Max(dFLim, 5. * dBinSize);
1024 TFitResultPtr fRes = hBy->Fit(
"gaus",
"SQM",
"", dFMean - dFLim, dFMean + dFLim);
1025 dBeamTOff = fRes->Parameter(1);
1026 LOG(info) <<
"Found beam counter with average TOff = " << dBeamTOff;
1029 LOG(info) <<
"Beam counter has too few entries: " <<
fhCalTOff[iDetIndx]->GetEntries();
1034 if (dBeamTOff == 0.) LOG(warn) <<
"No beam counter found";
1043 LOG(warn) <<
"hCorTOff for TSR " << iSmType << iSm << iRpc <<
" not available";
1053 LOG(info) <<
"Equalize velocities with const threshold counterwise for " <<
fhCorTOff[iDetIndx]->GetName()
1054 <<
", MeanTOff " <<
fhCorTOff[iDetIndx]->GetMean();
1055 TString hname2 = Form(
"cal_SmT%d_sm%03d_rpc%03d_TOff", iSmType, iSm, iRpc);
1060 LOG(warn) <<
"Calibration data not available from " << hname2;
1064 double dResIni[1] = {0.};
1066 Int_t NStrips = h2->GetNbinsX();
1067 TH1* h2Wy = h2W->ProjectionY(Form(
"%s_py", h2W->GetName()), 1, NStrips);
1068 TH1* h2y = h2->ProjectionY(Form(
"%s_py", h2->GetName()), 1, NStrips);
1076 dEdge = h2Wy->GetBinCenter(h2Wy->GetMaximumBin());
1084 if (dEdge < h2y->GetBinCenter(1) || dEdge > h2y->GetBinCenter(h2y->GetNbinsX())) {
1086 LOG(info) << h2Wy->GetName() <<
": Coarse TOff shift by " << dRes[0];
1092 if (TMath::Abs(dRes[0]) < 0.5) {
1094 double dTfind = dRes[0];
1097 if (std::isnan(dRes[0])) dRes[0] = dTfind;
1103 for (Int_t i = 0; i < NStrips; i++) {
1104 fhCorTOff[iDetIndx]->SetBinContent(i + 1,
fhCorTOff[iDetIndx]->GetBinContent(i + 1) + dRes[0]);
1111 LOG(info) <<
"Equalize velocities with chi2 deviations for " <<
fhCorTOff[iDetIndx]->GetName();
1112 TString hname2 = Form(
"cal_SmT%d_sm%03d_rpc%03d_TOff", iSmType, iSm, iRpc);
1114 double dTRefSum = 0.;
1115 double dRefNormSum = 0.;
1120 if (h2W->GetEntries() < MINCTS)
continue;
1123 Int_t NStrips = h2->GetNbinsX();
1125 double dResIni[1] = {0.};
1128 TH1* h2Wy = h2W->ProjectionY(Form(
"%s_py", h2W->GetName()), 1, NStrips);
1129 h2yAv = h2->ProjectionY(Form(
"%s_py", h2->GetName()), 1, NStrips);
1134 dEdge = h2Wy->GetBinCenter(h2Wy->GetMaximumBin());
1135 dNorm = h2Wy->GetBinContent(h2Wy->GetMaximumBin());
1141 if ((dMean - dEdge) > 10.) {
1142 LOG(warn) << h2Wy->GetName() <<
": wrong edge detected " << dEdge <<
", Mean " << dMean;
1152 if (dEdge < h2yAv->GetBinCenter(1) || dEdge > h2yAv->GetBinCenter(h2yAv->GetNbinsX())) {
1161 double dTfind = dRes[0];
1164 if (std::isnan(dRes[0])) dRes[0] = dTfind;
1165 LOG(info) << h2yAv->GetName() <<
": fitted AvEdge up to " <<
dTmax <<
", Res " << dRes[0]
1166 <<
", FindE " << dTfind;
1174 LOG(warn) <<
"Channel ooCR: " <<
fhCorTOff[iDetIndx]->GetName() <<
", " << dRes[0] <<
", "
1182 const double dResAv = dRes[0];
1183 const int nValues =
MaxShift * 2 + 1;
1184 const double dRangeFac = 1.;
1185 double chi2Shift[NStrips][nValues];
1186 double chi2Minimum[NStrips];
1187 double chi2MinShift[NStrips];
1188 double chi2LowMinNeighbor[NStrips];
1189 double chi2LowMinNeighborShift[NStrips];
1190 for (Int_t i = 0; i < NStrips; i++) {
1191 double dTminShift = 0.;
1194 TH1* h2y = h2->ProjectionY(Form(
"%s_py%d", h2->GetName(), i), i + 1, i + 1);
1195 if (h2y->GetEntries() < MINCTS)
continue;
1196 LOG(info) << h2y->GetName() <<
": inspect with iOpt1 = " << iOpt1;
1198 if (iOpt1 == 11 || iOpt1 == 15) {
1200 TH1* h2Wyi = h2W->ProjectionY(Form(
"%s_py%d", h2W->GetName(), i), i + 1, i + 1);
1202 dEdgei = h2Wy->GetBinCenter(h2Wy->GetMaximumBin());
1203 dNorm = h2Wy->GetBinContent(h2Wy->GetMaximumBin());
1211 if (dEdgei < dRangeFac * h2y->GetBinCenter(1)
1212 || dEdgei > dRangeFac * h2y->GetBinCenter(h2y->GetNbinsX())) {
1213 dMeani = h2Wyi->GetMean();
1214 LOG(info) << h2Wyi->GetName() <<
" ooR: " << dRes[0] <<
", E " << dEdgei <<
", Av " << dResAv
1215 <<
", Meani " << dMeani <<
", MeanY " << dMean;
1216 if ((dMeani - dEdgei) > 10.) {
1217 LOG(warn) << h2Wyi->GetName() <<
": invalid edge detected " << dEdgei <<
", Mean " << dMeani;
1218 dRes[0] = dMeani - dMean;
1226 LOG(info) << h2y->GetName() <<
" CheckValidEdge: " << dRes[0] <<
", " <<
dValidEdge;
1230 double dTfind = dRes[0];
1233 if (std::isnan(dRes[0])) dRes[0] = dTfind;
1234 LOG(info) << h2y->GetName() <<
": fit edge up to " <<
dTmax <<
", Res " << dRes[0]
1235 <<
", FindE " << dTfind;
1238 chi2Minimum[i] = 1.E6;
1239 chi2LowMinNeighbor[i] = 1.E6;
1242 chi2Shift[i][idx] =
CalcChi2(h2yAv, h2y, j);
1243 if (chi2Shift[i][idx] < chi2Minimum[i]) {
1244 chi2LowMinNeighbor[i] = chi2Minimum[i];
1245 chi2LowMinNeighborShift[i] = chi2MinShift[i];
1246 chi2Minimum[i] = chi2Shift[i][idx];
1247 chi2MinShift[i] = j * h2y->GetBinWidth(1);
1250 if (chi2Shift[i][idx] < chi2LowMinNeighbor[i]) {
1251 chi2LowMinNeighbor[i] = chi2Shift[i][idx];
1252 chi2LowMinNeighborShift[i] = j * h2y->GetBinWidth(1);
1257 double chi2sum = chi2Minimum[i] + chi2LowMinNeighbor[i];
1258 dTminShift = (chi2MinShift[i] * (chi2sum - chi2Minimum[i])
1259 + chi2LowMinNeighborShift[i] * (chi2sum - chi2LowMinNeighbor[i]))
1262 LOG(info) << h2y->GetName() <<
": Chi2 shift " << dTminShift <<
", Res " << dRes[0]
1263 <<
", ResAv " << dResAv;
1269 LOG(info) << h2y->GetName() <<
": stick to coarse offset " << dEdgei <<
", Res " << dRes[0];
1274 dEdgei = h2y->GetBinCenter(h2y->GetMaximumBin());
1275 dNorm = h2y->GetBinContent(h2y->GetMaximumBin());
1283 LOG(info) <<
"Update StartCounterCalib " << i <<
": " << dRes[0] <<
", " << dBeamTOff <<
", "
1284 << dTminShift <<
", " << dEdgei <<
", N " << dNorm;
1291 if (TMath::Abs(dRes[0] + dTminShift) > -
fhCalChannelDt->GetBinCenter(1)) {
1292 LOG(warn) <<
"Channel ooHR: " << h2Wy->GetName() << i <<
", " << dRes[0] <<
", " << dTminShift;
1294 double dVal =
fhCorTOff[iDetIndx]->GetBinContent(i + 1);
1295 if (std::isnan(dVal))
fhCorTOff[iDetIndx]->SetBinContent(i + 1, 0.);
1297 LOG(info) << h2Wy->GetName() << i <<
" CorTOff: " << dRes[0] <<
", " << dResAv <<
", " << dTminShift
1298 <<
", " <<
fhCorTOff[iDetIndx]->GetBinContent(i + 1) <<
" -> "
1299 <<
fhCorTOff[iDetIndx]->GetBinContent(i + 1) + dRes[0] + dTminShift;
1301 fhCorTOff[iDetIndx]->SetBinContent(i + 1,
1302 (
fhCorTOff[iDetIndx]->GetBinContent(i + 1) + dRes[0] + dTminShift));
1304 dTRefSum +=
fhCorTOff[iDetIndx]->GetBinContent(i + 1) * dNorm;
1305 dRefNormSum += dNorm;
1310 double dTRefAv = dTRefSum / dRefNormSum;
1311 LOG(info) <<
"Shift average ref time to 0: " << dTRefAv;
1312 for (Int_t i = 0; i < NStrips; i++) {
1313 fhCorTOff[iDetIndx]->SetBinContent(i + 1, (
fhCorTOff[iDetIndx]->GetBinContent(i + 1) - dTRefAv));
1320 LOG(info) <<
"TofCalibrator: skip TOff, calibrate hit positions, check YBox, Opt = " << iOpt;
1323 LOG(info) <<
"TofCalibrator: determine counter time offsets with cosmics, Opt = " << iOpt;
1327 LOG(warn) <<
"Calibration data not available for detx " << iDetIndx;
1330 Int_t NStrips = h2->GetNbinsX();
1331 TH1* h2Wy = h2W->ProjectionY(Form(
"%s_py", h2W->GetName()), 1, NStrips);
1332 TH1* h2y = h2->ProjectionY(Form(
"%s_py", h2->GetName()), 1, NStrips);
1334 Double_t dCtsWy = h2Wy->GetEntries();
1336 if (dCtsWy > MINCTS) {
1337 double dFMean = h2Wy->GetBinCenter(h2Wy->GetMaximumBin());
1339 double dBinSize = h2Wy->GetBinWidth(1);
1340 dFLim = TMath::Max(dFLim, 5. * dBinSize);
1341 TFitResultPtr fRes = h2Wy->Fit(
"gaus",
"SQM",
"", dFMean - dFLim, dFMean + dFLim);
1342 if (gMinuit->fCstatu.Contains(
"OK") || gMinuit->fCstatu.Contains(
"CONVERGED")) {
1343 dDt = fRes->Parameter(1);
1344 if (TMath::Abs(dDt) < 0.9 * h2y->GetXaxis()->GetXmax()) {
1345 dFMean = h2y->GetBinCenter(h2y->GetMaximumBin());
1347 dBinSize = h2y->GetBinWidth(1);
1348 dFLim = TMath::Max(dFLim, 5. * dBinSize);
1349 fRes = h2y->Fit(
"gaus",
"SQM",
"", dFMean - dFLim, dFMean + dFLim);
1350 if (gMinuit->fCstatu.Contains(
"OK") || gMinuit->fCstatu.Contains(
"CONVERGED")) {
1351 dDt = fRes->Parameter(1);
1356 LOG(info) <<
"Update cor hist " <<
fhCorTOff[iDetIndx]->GetName() <<
" by " << dDt <<
", " << dBeamTOff;
1357 for (
int iCh = 0; iCh <
fhCorTOff[iDetIndx]->GetNbinsX(); iCh++) {
1359 fhCorTOff[iDetIndx]->SetBinContent(iCh + 1,
fhCorTOff[iDetIndx]->GetBinContent(iCh + 1) + dDt);
1365 LOG(info) <<
"TofCalibrator: determine channel time offsets with cosmics, Opt = " << iOpt;
1369 LOG(warn) <<
"Calibration data not available for detx " << iDetIndx;
1372 Int_t NStrips = h2->GetNbinsX();
1373 for (
int i = 0; i < NStrips; i++) {
1374 TH1* h2Wy = h2W->ProjectionY(Form(
"%s_py_%02d", h2W->GetName(), i), i + 1, i + 1);
1375 TH1* h2y = h2->ProjectionY(Form(
"%s_py_%02d", h2->GetName(), i), i + 1, i + 1);
1377 Double_t dCtsWy = h2Wy->GetEntries();
1379 if (dCtsWy > MINCTS) {
1380 double dFMean = h2Wy->GetBinCenter(h2Wy->GetMaximumBin());
1382 double dBinSize = h2Wy->GetBinWidth(1);
1383 dFLim = TMath::Max(dFLim, 5. * dBinSize);
1384 TFitResultPtr fRes = h2Wy->Fit(
"gaus",
"SQM",
"", dFMean - dFLim, dFMean + dFLim);
1385 Int_t iFitStatus = fRes;
1387 if (iFitStatus != -1)
1388 if (gMinuit->fCstatu.Contains(
"OK") || gMinuit->fCstatu.Contains(
"CONVERGED")) {
1389 dDt = fRes->Parameter(1);
1391 if (h2y->GetEntries() > MINCTS)
1392 if (TMath::Abs(dDt) < 0.9 * h2y->GetXaxis()->GetXmax()) {
1393 dFMean = h2y->GetBinCenter(h2y->GetMaximumBin());
1395 dBinSize = h2y->GetBinWidth(1);
1396 dFLim = TMath::Max(dFLim, 5. * dBinSize);
1397 fRes = h2y->Fit(
"gaus",
"SQM",
"", dFMean - dFLim, dFMean + dFLim);
1398 if (gMinuit->fCstatu.Contains(
"OK") || gMinuit->fCstatu.Contains(
"CONVERGED")) {
1399 dDt = fRes->Parameter(1);
1403 fhCorTOff[iDetIndx]->SetBinContent(i + 1,
fhCorTOff[iDetIndx]->GetBinContent(i + 1) + dDt);
1407 LOG(warn) <<
"Too few counts in " << h2Wy->GetName() <<
": " << dCtsWy;
1413 LOG(info) <<
"TofCalibrator: determine channel walks with cosmics, Opt = " << iOpt <<
" for TSR "
1414 << iSmType << iSm << iRpc;
1416 const Double_t MinCounts = 10.;
1418 for (Int_t iCh = 0; iCh < iNbCh; iCh++) {
1419 TH1* hCY =
fhCalPos[iDetIndx]->ProjectionY(Form(
"%s_py_%d",
fhCalPos[iDetIndx]->GetName(), iCh),
1421 if (hCY->GetEntries() > 1)
1424 TProfile* hpW0 =
fhCalWalk[iDetIndx][iCh][0]->ProfileX();
1425 TH1* hCW0 =
fhCalWalk[iDetIndx][iCh][0]->ProjectionX();
1426 TProfile* hpW1 =
fhCalWalk[iDetIndx][iCh][1]->ProfileX();
1427 TH1* hCW1 =
fhCalWalk[iDetIndx][iCh][1]->ProjectionX();
1428 if (hCW0->GetEntries() == 0 || hCW1->GetEntries() == 0) {
1433 for (Int_t iBin = 0; iBin <
fhCorWalk[iDetIndx][iCh][0]->GetNbinsX(); iBin++) {
1434 Double_t dCts0 = hCW0->GetBinContent(iBin + 1);
1435 Double_t dCts1 = hCW1->GetBinContent(iBin + 1);
1436 Double_t dWOff0 =
fhCorWalk[iDetIndx][iCh][0]->GetBinContent(iBin + 1);
1437 Double_t dWOff1 =
fhCorWalk[iDetIndx][iCh][1]->GetBinContent(iBin + 1);
1438 if (iBin > 0 && dCts0 == 0 && dCts1 == 0) {
1439 fhCorWalk[iDetIndx][iCh][0]->SetBinContent(iBin + 1,
1440 fhCorWalk[iDetIndx][iCh][0]->GetBinContent(iBin));
1441 fhCorWalk[iDetIndx][iCh][1]->SetBinContent(iBin + 1,
1442 fhCorWalk[iDetIndx][iCh][1]->GetBinContent(iBin));
1445 if (dCts0 > MinCounts && dCts1 > MinCounts) {
1446 dCorT = 0.5 * (hpW0->GetBinContent(iBin + 1) + hpW1->GetBinContent(iBin + 1));
1449 fhCorWalk[iDetIndx][iCh][0]->SetBinContent(iBin + 1, dWOff0 + dCorT);
1450 fhCorWalk[iDetIndx][iCh][1]->SetBinContent(iBin + 1, dWOff1 + dCorT);
1456 LOG(info) <<
"TofCalibrator: unknown option " << iOpt;
1466 dYShift = hCalPos_py->GetMean();
1469 if (NULL == fChannelInfo) LOG(fatal) << Form(
"invalid ChannelInfo for 0x%08x", iChId);
1472 TF1* ff = hCalPos_py->GetFunction(
"YBox");
1474 LOG(info) <<
"FRes YBox " << hCalPos_py->GetEntries() <<
" entries in TSR " << iSmType << iSm << iRpc
1475 <<
", chi2 " << ff->GetChisquare() / ff->GetNDF()
1476 << Form(
", striplen (%5.2f): %7.2f +/- %5.2f, pos "
1477 "res %5.2f +/- %5.2f at y_cen = %5.2f +/- %5.2f",
1479 2. * ff->GetParError(1), ff->GetParameter(2), ff->GetParError(2), ff->GetParameter(3),
1480 ff->GetParError(3));
1483 if (
hSvel[iSmType] != NULL) {
1485 double dSscal =
hSvel[iSmType]->GetBinContent(iSm * iNbRpc + iRpc + 1);
1487 LOG(info) <<
"Modify SigVel modifier for TSR " << iSmType << iSm << iRpc <<
": " << dSscal <<
", "
1488 << dRatio <<
" -> " << dSscal * dRatio;
1489 dSscal = dSscal * dRatio;
1490 if (dSscal < 0.8) dSscal = 0.8;
1491 if (dSscal > 1.2) dSscal = 1.2;
1492 hSvel[iSmType]->SetBinContent(iSm * iNbRpc + iRpc + 1,
1498 double dThr = hCalPos_py->GetBinContent(hCalPos_py->GetMaximumBin()) / 10;
1499 if (dThr < 3.) dThr = 3.;
1501 if (TMath::Abs(dRes[0] - fChannelInfo->
GetSizey()) / fChannelInfo->
GetSizey() < 0.1) {
1505 if (iOpt1 != 16 && iOpt1 != 12) {
1506 for (Int_t iBin = 0; iBin <
fhCorPos[iDetIndx]->GetNbinsX(); iBin++) {
1507 Double_t dCorP =
fhCorPos[iDetIndx]->GetBinContent(iBin + 1);
1508 Double_t dCtsP = hCalP->GetBinContent(iBin + 1);
1509 if (dCtsP > MINCTS) {
1511 Form(
"%s_py_%d",
fhCalPosition[iDetIndx]->GetName(), iBin), iBin + 1, iBin + 1);
1512 dYShift = hPos_py->GetMean();
1513 dThr = hPos_py->GetBinContent(hPos_py->GetMaximumBin()) / 10;
1514 if (dThr < 3.) dThr = 3.;
1517 LOG(info) << Form(
"EdgeY for %s, TSR %d%d%d: DY %5.2f, Len %5.2f, Size %5.2f ", hPos_py->GetName(),
1518 iSmType, iSm, iRpc, dRes[1], dRes[0],
1521 if (TMath::Abs(dRes[0] - fChannelInfo->
GetSizey()) / fChannelInfo->
GetSizey() < 0.1) {
1525 dYShift = hPos_py->GetMean();
1529 fhCorPos[iDetIndx]->SetBinContent(iBin + 1, dCorP + dYShift);
1535 for (Int_t iBin = 0; iBin <
fhCorPos[iDetIndx]->GetNbinsX(); iBin++) {
1536 Double_t dCorP =
fhCorPos[iDetIndx]->GetBinContent(iBin + 1);
1537 fhCorPos[iDetIndx]->SetBinContent(iBin + 1, dCorP + dYShift);
1545 LOG(info) <<
"Update time offsets for TSR " << iSmType << iSm << iRpc <<
" with opt1 " << iOpt1;
1546 TProfile* hpP =
fhCalPos[iDetIndx]->ProfileX();
1547 TProfile* hpT =
fhCalTOff[iDetIndx]->ProfileX();
1548 TH1* hCalP =
fhCalPos[iDetIndx]->ProjectionX();
1549 TH1* hCalT =
fhCalTOff[iDetIndx]->ProjectionX();
1553 TH1* hCalTpy =
fhCalTOff[iDetIndx]->ProjectionY();
1554 Double_t dCtsTpy = hCalTpy->GetEntries();
1556 if (dCtsTpy > MINCTS) {
1557 double dFMean = hCalTpy->GetBinCenter(hCalTpy->GetMaximumBin());
1559 double dBinSize = hCalTpy->GetBinWidth(1);
1560 dFLim = TMath::Max(dFLim, 5. * dBinSize);
1561 TFitResultPtr fRes = hCalTpy->Fit(
"gaus",
"SQM",
"", dFMean - dFLim, dFMean + dFLim);
1562 if (gMinuit->fCstatu.Contains(
"OK") || gMinuit->fCstatu.Contains(
"CONVERGED")) {
1563 dDt = fRes->Parameter(1);
1564 LOG(info) <<
"Update cor hist " <<
fhCorTOff[iDetIndx]->GetName() <<
" by " << dDt <<
", " << dBeamTOff;
1572 for (
int iCh = 0; iCh <
fhCorTOff[iDetIndx]->GetNbinsX(); iCh++) {
1574 fhCorTOff[iDetIndx]->SetBinContent(iCh + 1,
fhCorTOff[iDetIndx]->GetBinContent(iCh + 1) + dDt);
1580 double dTOffMeanShift = 0.;
1582 for (Int_t iBin = 0; iBin <
fhCorTOff[iDetIndx]->GetNbinsX(); iBin++) {
1583 Double_t dDt = hpT->GetBinContent(iBin + 1);
1584 Double_t dCorT =
fhCorTOff[iDetIndx]->GetBinContent(iBin + 1);
1585 Double_t dCtsT = hCalT->GetBinContent(iBin + 1);
1586 Double_t dCtsP = hCalP->GetBinContent(iBin + 1);
1587 Double_t dDp = hpP->GetBinContent(iBin + 1);
1588 Double_t dCorP =
fhCorPos[iDetIndx]->GetBinContent(iBin + 1);
1589 LOG(debug) <<
"Cts check for " <<
fhCalTOff[iDetIndx]->GetName() <<
", bin " << iBin <<
": " << dCtsT
1590 <<
", " << dCtsP <<
", " << MINCTS;
1591 if (dCtsT > MINCTS && dCtsP > MINCTS) {
1594 (TH1*)
fhCalPos[iDetIndx]->ProjectionY(Form(
"PosPy_%d_%d", iDetIndx, iBin), iBin + 1, iBin + 1);
1595 if (hpPy->Integral() > MINCTS) {
1596 Double_t dFMean = hpPy->GetBinCenter(hpPy->GetMaximumBin());
1597 Double_t dFLim = 0.5;
1598 Double_t dBinSize = hpPy->GetBinWidth(1);
1599 dFLim = TMath::Max(dFLim, 5. * dBinSize);
1600 TFitResultPtr fRes = hpPy->Fit(
"gaus",
"SQM",
"", dFMean - dFLim, dFMean + dFLim);
1601 if (gMinuit->fCstatu.Contains(
"OK") || gMinuit->fCstatu.Contains(
"CONVERGED")) {
1602 dDp = fRes->Parameter(1);
1607 (TH1*)
fhCalTOff[iDetIndx]->ProjectionY(Form(
"TOffPy_%d_%d", iDetIndx, iBin), iBin + 1, iBin + 1);
1608 if (hpTy->Integral() > MINCTS) {
1609 Double_t dFMean = hpTy->GetBinCenter(hpTy->GetMaximumBin());
1610 Double_t dFLim = 0.5;
1611 Double_t dBinSize = hpTy->GetBinWidth(1);
1612 dFLim = TMath::Max(dFLim, 5. * dBinSize);
1613 TFitResultPtr fRes = hpTy->Fit(
"gaus",
"SQM",
"", dFMean - dFLim, dFMean + dFLim);
1614 if (gMinuit->fCstatu.Contains(
"OK") || gMinuit->fCstatu.Contains(
"CONVERGED")) {
1615 dDt = fRes->Parameter(1);
1621 fhCorTOff[iDetIndx]->SetBinContent(iBin + 1, dCorT + dDt - dBeamTOff);
1622 dTOffMeanShift += dDt - dBeamTOff;
1625 fhCorTOff[iDetIndx]->SetBinContent(iBin + 1, dCorT + dDt + dBeamTOff);
1626 dTOffMeanShift += dDt + dBeamTOff;
1630 fhCorPos[iDetIndx]->SetBinContent(iBin + 1, dCorP + dDp);
1632 if (iDetIndx > -1) {
1633 LOG(debug) << Form(
"Update %s: bin %02d, Cts: %d, Old %6.3f, dev %6.3f, beam %6.3f, new %6.3f",
1634 fhCorTOff[iDetIndx]->GetName(), iBin, (Int_t) dCtsT, dCorT, dDt, dBeamTOff,
1635 dCorT + dDt + dBeamTOff);
1639 if (dNCh > 0) dTOffMeanShift /= dNCh;
1641 for (Int_t iBin = 0; iBin <
fhCorTOff[iDetIndx]->GetNbinsX(); iBin++) {
1642 fhCorTOff[iDetIndx]->SetBinContent(iBin + 1,
1643 fhCorTOff[iDetIndx]->GetBinContent(iBin + 1) - dTOffMeanShift);
1650 LOG(debug) <<
"Update Cluster Offsets for TSR " << iSmType << iSm << iRpc;
1651 if (iSmType == 5)
continue;
1654 TH1* hCalP =
fhCalDelPos[iDetIndx]->ProjectionX();
1658 for (Int_t iBin = 0; iBin <
fhCorTOff[iDetIndx]->GetNbinsX(); iBin++) {
1659 Double_t dDt = hpT->GetBinContent(iBin + 1);
1660 Double_t dCorT =
fhCorTOff[iDetIndx]->GetBinContent(iBin + 1);
1661 Double_t dCtsT = hCalT->GetBinContent(iBin + 1);
1662 Double_t dCtsP = hCalP->GetBinContent(iBin + 1);
1665 LOG(debug) <<
"Cts check for " <<
fhCalDelTOff[iDetIndx]->GetName() <<
", bin " << iBin <<
": " << dCtsT
1666 <<
", " << dCtsP <<
", " << MINCTS;
1667 if (dCtsT > MINCTS) {
1669 TH1* hpTy = (TH1*)
fhCalDelTOff[iDetIndx]->ProjectionY(Form(
"DelTOffPy_%d_%d", iDetIndx, iBin),
1670 iBin + 1, iBin + 1);
1671 double dFMean = hpTy->GetBinCenter(hpTy->GetMaximumBin());
1673 double dBinSize = hpTy->GetBinWidth(1);
1674 dFLim = TMath::Max(dFLim, 5. * dBinSize);
1675 TFitResultPtr fRes = hpTy->Fit(
"gaus",
"SQM",
"", dFMean - dFLim, dFMean + dFLim);
1676 if (gMinuit->fCstatu.Contains(
"OK") || gMinuit->fCstatu.Contains(
"CONVERGED")) {
1677 dDt = fRes->Parameter(1);
1679 fhCorTOff[iDetIndx]->SetBinContent(iBin + 1, dCorT + dDt);
1682 if (iDetIndx > -1) {
1683 LOG(debug) << Form(
"Update %s: bin %02d, Cts: %d, Old %6.3f, dev %6.3f, new %6.3f",
1684 fhCorTOff[iDetIndx]->GetName(), iBin, (Int_t) dCtsT, dCorT, dDt, dCorT + dDt);
1689 LOG(debug) <<
"Update Cluster Position for TSR " << iSmType << iSm << iRpc;
1690 if (iSmType == 5)
continue;
1691 TProfile* hpP =
fhCalDelPos[iDetIndx]->ProfileX();
1693 TH1* hCalP =
fhCalDelPos[iDetIndx]->ProjectionX();
1697 for (Int_t iBin = 0; iBin <
fhCorTOff[iDetIndx]->GetNbinsX(); iBin++) {
1698 Double_t dDt = hpT->GetBinContent(iBin + 1);
1699 Double_t dCorT =
fhCorTOff[iDetIndx]->GetBinContent(iBin + 1);
1700 Double_t dCtsT = hCalT->GetBinContent(iBin + 1);
1701 Double_t dCtsP = hCalP->GetBinContent(iBin + 1);
1702 Double_t dDp = hpP->GetBinContent(iBin + 1);
1703 Double_t dCorP =
fhCorPos[iDetIndx]->GetBinContent(iBin + 1);
1704 LOG(debug) <<
"Cts check for " <<
fhCalDelTOff[iDetIndx]->GetName() <<
", bin " << iBin <<
": " << dCtsT
1705 <<
", " << dCtsP <<
", " << MINCTS;
1706 if (dCtsT > MINCTS && dCtsP > MINCTS) {
1708 TH1* hpTy = (TH1*)
fhCalDelTOff[iDetIndx]->ProjectionY(Form(
"DelTOffPy_%d_%d", iDetIndx, iBin),
1709 iBin + 1, iBin + 1);
1710 double dFMean = hpTy->GetBinCenter(hpTy->GetMaximumBin());
1712 double dBinSize = hpTy->GetBinWidth(1);
1713 dFLim = TMath::Max(dFLim, 5. * dBinSize);
1714 TFitResultPtr fRes = hpTy->Fit(
"gaus",
"SQM",
"", dFMean - dFLim, dFMean + dFLim);
1715 if (gMinuit->fCstatu.Contains(
"OK") || gMinuit->fCstatu.Contains(
"CONVERGED")) {
1716 dDt = fRes->Parameter(1);
1718 fhCorTOff[iDetIndx]->SetBinContent(iBin + 1, dCorT + dDt);
1721 TH1* hpPy = (TH1*)
fhCalDelPos[iDetIndx]->ProjectionY(Form(
"DelPosPy_%d_%d", iDetIndx, iBin),
1722 iBin + 1, iBin + 1);
1723 dFMean = hpPy->GetBinCenter(hpTy->GetMaximumBin());
1725 dBinSize = hpPy->GetBinWidth(1);
1726 dFLim = TMath::Max(dFLim, 5. * dBinSize);
1727 fRes = hpPy->Fit(
"gaus",
"SQM",
"", dFMean - dFLim, dFMean + dFLim);
1728 if (gMinuit->fCstatu.Contains(
"OK") || gMinuit->fCstatu.Contains(
"CONVERGED")) {
1729 dDp = fRes->Parameter(1);
1731 fhCorPos[iDetIndx]->SetBinContent(iBin + 1, dCorP + dDp);
1734 if (iDetIndx > -1) {
1735 LOG(debug) << Form(
"Update %s: bin %02d, Cts: %d, Old %6.3f, dev %6.3f, new %6.3f",
1736 fhCorTOff[iDetIndx]->GetName(), iBin, (Int_t) dCtsT, dCorT, dDt, dCorT + dDt);
1742 LOG(debug) <<
"Update Walks for TSR " << iSmType << iSm << iRpc;
1744 const Double_t MinCounts = 10.;
1746 for (Int_t iCh = 0; iCh < iNbCh; iCh++) {
1747 TH1* hCY =
fhCalPos[iDetIndx]->ProjectionY(Form(
"%s_py_%d",
fhCalPos[iDetIndx]->GetName(), iCh),
1751 TProfile* hpW0 =
fhCalWalk[iDetIndx][iCh][0]->ProfileX();
1752 TH1* hCW0 =
fhCalWalk[iDetIndx][iCh][0]->ProjectionX();
1753 TProfile* hpW1 =
fhCalWalk[iDetIndx][iCh][1]->ProfileX();
1754 TH1* hCW1 =
fhCalWalk[iDetIndx][iCh][1]->ProjectionX();
1761 if (hCW0->GetEntries() == 0 || hCW1->GetEntries() == 0) {
1766 for (Int_t iBin = 0; iBin <
fhCorWalk[iDetIndx][iCh][0]->GetNbinsX(); iBin++) {
1767 Double_t dCts0 = hCW0->GetBinContent(iBin + 1);
1768 Double_t dCts1 = hCW1->GetBinContent(iBin + 1);
1769 Double_t dWOff0 =
fhCorWalk[iDetIndx][iCh][0]->GetBinContent(iBin + 1);
1770 Double_t dWOff1 =
fhCorWalk[iDetIndx][iCh][1]->GetBinContent(iBin + 1);
1771 if (iBin > 0 && dCts0 == 0 && dCts1 == 0) {
1772 fhCorWalk[iDetIndx][iCh][0]->SetBinContent(iBin + 1,
1773 fhCorWalk[iDetIndx][iCh][0]->GetBinContent(iBin));
1774 fhCorWalk[iDetIndx][iCh][1]->SetBinContent(iBin + 1,
1775 fhCorWalk[iDetIndx][iCh][1]->GetBinContent(iBin));
1778 if (dCts0 > MinCounts && dCts1 > MinCounts) {
1779 dCorT = 0.5 * (hpW0->GetBinContent(iBin + 1) + hpW1->GetBinContent(iBin + 1));
1782 fhCorWalk[iDetIndx][iCh][0]->SetBinContent(iBin + 1, dWOff0 + dCorT);
1783 fhCorWalk[iDetIndx][iCh][1]->SetBinContent(iBin + 1, dWOff1 + dCorT);
1784 if (iSmType == 0 && iSm == 0 && iRpc == 2)
1785 LOG(info) <<
"UpdWalk " <<
fhCorWalk[iDetIndx][iCh][0]->GetName() <<
" bin " << iBin <<
" Tot "
1786 << hCW0->GetBinCenter(iBin + 1) <<
", " << hCW1->GetBinCenter(iBin + 1) <<
": curVal "
1787 << dWOff0 <<
", " << dWOff1 <<
", Cts " << dCts0 <<
", " << dCts1 <<
", dCorT " << dCorT
1788 <<
", newVal " << dWOff0 + dCorT <<
", " << dWOff1 + dCorT;
1822 default:; LOG(info) <<
"Calibrator option " << iOpt <<
" not implemented ";
1834 for (Int_t iBin = 0; iBin <
fhCorPos[iDetIndx]->GetNbinsX(); iBin++) {
1835 Double_t dCorP =
fhCorPos[iDetIndx]->GetBinContent(iBin + 1);
1837 Double_t dCtsP = hCalP->GetBinContent(iBin + 1);
1838 if (dCtsP > MINCTS) {
1840 Form(
"%s_py_%d",
fhCalPosition[iDetIndx]->GetName(), iBin), iBin + 1, iBin + 1);
1841 double dYShift = hPos_py->GetMean();
1844 if (NULL == fChannelInfo) LOG(fatal) << Form(
"invalid ChannelInfo for 0x%08x", iChId);
1846 double dThr = dCtsP / 100;
1847 if (dThr < 3.) dThr = 3.;
1854 if (TMath::Abs(dRes[0] - fChannelInfo->
GetSizey()) / fChannelInfo->
GetSizey() < 0.1) {
1858 dYShift = hPos_py->GetMean();
1862 fhCorPos[iDetIndx]->SetBinContent(iBin + 1, dCorP + dYShift);
1869 TProfile* hpT =
fhCalTOff[iDetIndx]->ProfileX();
1870 TH1* hCalT =
fhCalTOff[iDetIndx]->ProjectionX();
1871 for (Int_t iBin = 0; iBin <
fhCorTOff[iDetIndx]->GetNbinsX(); iBin++) {
1873 Double_t dCorT =
fhCorTOff[iDetIndx]->GetBinContent(iBin + 1);
1874 Double_t dCtsT = hCalT->GetBinContent(iBin + 1);
1875 if (dCtsT > MINCTS) {
1876 double dTmean = hpT->GetBinContent(iBin + 1);
1877 TH1* hTy = (TH1*)
fhCalTofOff[iDetIndx]->ProjectionY(
1878 Form(
"%s_py%d",
fhCalTofOff[iDetIndx]->GetName(), iBin), iBin + 1, iBin + 1);
1879 Double_t dNPeak = hTy->GetBinContent(hTy->GetMaximumBin());
1880 if (dNPeak > MINCTS * 0.1) {
1881 Double_t dFMean = hTy->GetBinCenter(hTy->GetMaximumBin());
1882 Double_t dFLim = 2.0;
1883 Double_t dBinSize = hTy->GetBinWidth(1);
1884 dFLim = TMath::Max(dFLim, 10. * dBinSize);
1885 TFitResultPtr fRes = hTy->Fit(
"gaus",
"SQM",
"", dFMean - dFLim, dFMean + dFLim);
1887 if (gMinuit->fCstatu.Contains(
"OK") || gMinuit->fCstatu.Contains(
"CONVERGED")) {
1896 dTmean = fRes->Parameter(1);
1903 fhCorTOff[iDetIndx]->SetBinContent(iBin + 1, dCorT + dTmean);
1909 for (Int_t iBin = 0; iBin <
fhCorTot[iDetIndx]->GetNbinsX(); iBin++) {
1911 TH1* hbin =
fhCalTot[iDetIndx]->ProjectionY(Form(
"bin%d", ib), ib, ib);
1912 double dTotMean = hbin->GetMean();
1914 Double_t dCtsTot = hbin->GetEntries();
1915 if (dCtsTot > MINCTS) {
1916 double dFMean = hbin->GetBinCenter(hbin->GetMaximumBin());
1917 double dFLim = dFMean * 0.5;
1920 TFitResultPtr fRes = hbin->Fit(
"gaus",
"SQM",
"", dFMean - dFLim, dFMean + dFLim);
1921 if (gMinuit->fCstatu.Contains(
"OK") || gMinuit->fCstatu.Contains(
"CONVERGED")) {
1922 dTotMean = fRes->Parameter(1);
1925 LOG(warn) <<
"FitFail " << hbin->GetName();
1931 int iSide = iBin - iCh * 2;
1934 TString shcmd = Form(
"echo %d >> %s ", iChId,
cBadChannelFile.Data());
1935 gSystem->Exec(shcmd.Data());
1937 if (dTotMean > 0.) {
1938 double dCorTot =
fhCorTot[iDetIndx]->GetBinContent(ib);
1943 fhCorTot[iDetIndx]->SetBinContent(ib, dCorTot * dTotMean / dCalTotMean);
1948 default: LOG(fatal) <<
"No valid calibration mode " << iOpt0;
1955 TString fFile = fCalParFile->GetName();
1956 if (!fFile.Contains(
"/")) {
1957 TFile* fCalParFileNew =
new TFile(Form(
"New_%s", fCalParFile->GetName()),
"RECREATE");
1959 fCalParFileNew->Close();
1964 fCalParFile->Close();
1969 gDirectory->cd(oldDir->GetPath());