10 #include <ecl/calibration/eclTValidationAlgorithm.h>
11 #include <ecl/dbobjects/ECLCrystalCalib.h>
12 #include <ecl/dbobjects/ECLReferenceCrystalPerCrateCalib.h>
13 #include <ecl/digitization/EclConfiguration.h>
14 #include <ecl/utility/ECLChannelMapper.h>
15 #include <ecl/geometry/ECLGeometryPar.h>
17 #include <framework/database/DBObjPtr.h>
18 #include <framework/database/DBStore.h>
19 #include <framework/database/DBImportObjPtr.h>
20 #include <framework/datastore/StoreObjPtr.h>
21 #include <framework/datastore/DataStore.h>
22 #include <framework/dataobjects/EventMetaData.h>
30 #include <TGraphErrors.h>
31 #include <TGraphAsymmErrors.h>
32 #include <TMultiGraph.h>
44 eclTValidationAlgorithm::eclTValidationAlgorithm():
49 readPrevCrysPayload(false),
50 meanCleanRebinFactor(1),
51 meanCleanCutMinFactor(0),
52 clusterTimesFractionWindow_maxtime(8),
53 debugFilenameBase(
"eclTValidationAlgorithm")
55 setDescription(
"Fit gaussian function to the cluster times to validate results.");
70 readPrevCrysPayload(false),
71 meanCleanRebinFactor(1),
72 meanCleanCutMinFactor(0),
73 clusterTimesFractionWindow_maxtime(8),
74 debugFilenameBase(
"eclTValidationAlgorithm")
76 setDescription(
"Fit gaussian function to the cluster times to validate results.");
89 B2INFO(
"eclTValidationAlgorithm parameters:");
99 auto clusterTime = getObjectPtr<TH1F>(
"clusterTime");
100 auto clusterTime_cid = getObjectPtr<TH2F>(
"clusterTime_cid");
101 auto clusterTime_run = getObjectPtr<TH2F>(
"clusterTime_run");
102 auto clusterTimeClusterE = getObjectPtr<TH2F>(
"clusterTimeClusterE");
103 auto dt99_clusterE = getObjectPtr<TH2F>(
"dt99_clusterE");
104 auto eventT0 = getObjectPtr<TH1F>(
"eventT0");
105 auto clusterTimeE0E1diff = getObjectPtr<TH1F>(
"clusterTimeE0E1diff");
108 auto cutflow = getObjectPtr<TH1F>(
"cutflow");
110 vector <int> binProjectionLeft_Time_vs_E_runDep ;
111 vector <int> binProjectionRight_Time_vs_E_runDep ;
113 for (
int binCounter = 1; binCounter <= clusterTimeClusterE->GetNbinsX(); binCounter++) {
114 binProjectionLeft_Time_vs_E_runDep.push_back(binCounter);
115 binProjectionRight_Time_vs_E_runDep.push_back(binCounter);
129 vector<float> t_offsets(8736, 0.0);
130 vector<float> t_offsets_unc(8736, 0.0);
131 vector<long> numClusterPerCrys(8736, 0);
132 vector<bool> crysHasGoodFitandStats(8736,
false);
133 vector<bool> crysHasGoodFit(8736,
false);
134 int numCrysWithNonZeroEntries = 0 ;
135 int numCrysWithGoodFit = 0 ;
137 int minNumEntries = 40;
143 bool minRunNumBool =
false;
144 bool maxRunNumBool =
false;
150 int expNumber = expRun.first;
151 int runNumber = expRun.second;
152 if (!minRunNumBool) {
153 minExpNum = expNumber;
154 minRunNum = runNumber;
155 minRunNumBool =
true;
157 if (!maxRunNumBool) {
158 maxExpNum = expNumber;
159 maxRunNum = runNumber;
160 maxRunNumBool =
true;
162 if (((minRunNum > runNumber) && (minExpNum >= expNumber)) ||
163 (minExpNum > expNumber)) {
164 minExpNum = expNumber;
165 minRunNum = runNumber;
167 if (((maxRunNum < runNumber) && (maxExpNum <= expNumber)) ||
168 (maxExpNum < expNumber))
171 maxExpNum = expNumber;
172 maxRunNum = runNumber;
177 string runNumsString = string(
"_") + to_string(minExpNum) +
"_" + to_string(minRunNum) + string(
"-") +
178 to_string(maxExpNum) +
"_" + to_string(maxRunNum);
186 int eventNumberForCrates = 1;
198 evtPtr.
construct(eventNumberForCrates, minRunNum, minExpNum);
207 B2INFO(
"Uploading payload for exp " << minExpNum <<
", run " << minRunNum <<
", event " << eventNumberForCrates);
210 crystalMapper->initFromDB();
215 B2INFO(
"Dumping payload");
218 std::vector<float> currentValuesCrys = crystalTimeObject->
getCalibVector();
222 B2INFO(
"Values read from database. Write out for their values for comparison against those from tcol");
223 for (
int ic = 0; ic < 8736; ic += 500) {
224 B2INFO(
"ts: cellID " << ic + 1 <<
" " << currentValuesCrys[ic] <<
" +/- " << currentUncCrys[ic]);
230 vector<float> prevValuesCrys(8736);
236 B2INFO(
"Previous values read from database. Write out for their values for comparison against those from tcol");
237 for (
int ic = 0; ic < 8736; ic += 500) {
238 B2INFO(
"ts custom previous payload: cellID " << ic + 1 <<
" " << prevValuesCrys[ic]);
246 B2INFO(
"Debug output rootfile: " << debugFilename);
247 histfile =
new TFile(debugFilename.c_str(),
"recreate");
250 clusterTime ->Write();
251 clusterTime_cid ->Write();
252 clusterTime_run ->Write();
253 clusterTimeClusterE ->Write();
254 dt99_clusterE ->Write();
256 clusterTimeE0E1diff ->Write();
261 double hist_tmin = clusterTime->GetXaxis()->GetXmin();
262 double hist_tmax = clusterTime->GetXaxis()->GetXmax();
263 int hist_nTbins = clusterTime->GetNbinsX();
265 B2INFO(
"hist_tmin = " << hist_tmin);
266 B2INFO(
"hist_tmax = " << hist_tmax);
267 B2INFO(
"hist_nTbins = " << hist_nTbins);
269 double time_fit_min = hist_tmax;
270 double time_fit_max = hist_tmin;
274 auto peakClusterTime_cid =
new TH1F(
"peakClusterTime_cid",
";cell id;Peak cluster time [ns]", 8736, 1, 8736 + 1);
275 auto peakClusterTimes =
new TH1F(
"peakClusterTimes",
276 "-For crystals with at least one hit-;Peak cluster time [ns];Number of crystals",
277 hist_nTbins, hist_tmin, hist_tmax);
278 auto peakClusterTimesGoodFit =
new TH1F(
"peakClusterTimesGoodFit",
279 "-For crystals with a good fit to distribution of hits-;Peak cluster time [ns];Number of crystals",
280 hist_nTbins, hist_tmin, hist_tmax);
282 auto peakClusterTimesGoodFit__cid =
new TH1F(
"peakClusterTimesGoodFit__cid",
283 "-For crystals with a good fit to distribution of hits-;cell id (only crystals with good fit);Peak cluster time [ns]",
288 auto tsNew_MINUS_tsCustomPrev__cid =
new TH1F(
"TsNew_MINUS_TsCustomPrev__cid",
289 ";cell id; ts(new|merged) - ts(old = 'pre-calib'|merged) [ns]",
292 auto tsNew_MINUS_tsCustomPrev =
new TH1F(
"TsNew_MINUS_TsCustomPrev",
293 ";ts(new | merged) - ts(old = 'pre-calib' | merged) [ns];Number of crystals",
294 285, -69.5801, 69.5801);
300 B2INFO(
"timeWindow_maxTime = " << timeWindow_maxTime);
301 int binyLeft = clusterTime_cid->GetYaxis()->FindBin(-timeWindow_maxTime);
302 int binyRight = clusterTime_cid->GetYaxis()->FindBin(timeWindow_maxTime);
303 double windowLowTimeFromBin = clusterTime_cid->GetYaxis()->GetBinLowEdge(binyLeft);
304 double windowHighTimeFromBin = clusterTime_cid->GetYaxis()->GetBinLowEdge(binyRight + 1);
305 std::string s_lowTime = std::to_string(windowLowTimeFromBin);
306 std::string s_highTime = std::to_string(windowHighTimeFromBin);
307 TString fracWindowTitle =
"Fraction of cluster times in window [" + s_lowTime +
", " + s_highTime +
308 "] ns;cell id;Fraction of cluster times in window";
309 B2INFO(
"fracWindowTitle = " << fracWindowTitle);
310 TString fracWindowInGoodECLRingsTitle =
"Fraction of cluster times in window [" + s_lowTime +
", " + s_highTime +
311 "] ns and in good ECL theta rings;cell id;Fraction cluster times in window + good ECL rings";
312 B2INFO(
"fracWindowInGoodECLRingsTitle = " << fracWindowInGoodECLRingsTitle);
313 B2INFO(
"Good ECL rings skip gaps in the acceptance, and includes ECL theta IDs: 3-10, 15-39, 44-56, 61-66.");
315 TString fracWindowHistTitle =
"Fraction of cluster times in window [" + s_lowTime +
", " + s_highTime +
316 "] ns;Fraction of cluster times in window;Number of crystals";
318 auto clusterTimeNumberInWindow__cid =
new TH1F(
"clusterTimeNumberInWindow__cid", fracWindowTitle, 8736, 1, 8736 + 1);
319 auto clusterTimeNumberInWindowInGoodECLRings__cid =
new TH1F(
"clusterTimeNumberInWindowInGoodECLRings__cid", fracWindowTitle, 8736,
321 auto clusterTimeNumber__cid =
new TH1F(
"clusterTimeNumber_cid", fracWindowTitle, 8736, 1, 8736 + 1);
322 auto clusterTimeFractionInWindow =
new TH1F(
"clusterTimeFractionInWindow", fracWindowHistTitle, 110, 0.0, 1.1);
324 clusterTimeNumberInWindow__cid->Sumw2();
325 clusterTimeNumberInWindowInGoodECLRings__cid->Sumw2();
326 clusterTimeNumber__cid->Sumw2();
336 double clusterTime_mean = 0;
337 double clusterTime_mean_unc = 0;
339 B2INFO(
"Crystal cell id = " << crys_id);
348 TH1D* h_time = clusterTime_cid->ProjectionY((std::string(
"h_time_psi__") + std::to_string(crys_id)).c_str(),
350 TH1D* h_timeMask = (TH1D*)h_time->Clone();
351 TH1D* h_timeMasked = (TH1D*)h_time->Clone((std::string(
"h_time_psi_masked__") + std::to_string(crys_id)).c_str());
352 TH1D* h_timeRebin = (TH1D*)h_time->Clone();
359 h_timeMask->Scale(0.0);
361 time_fit_min = hist_tmax;
362 time_fit_max = hist_tmin;
365 double histRebin_max = h_timeRebin->GetMaximum();
367 bool maskedOutNonZeroBin =
false;
369 for (
int bin = 1; bin <= h_timeRebin->GetNbinsX(); bin++) {
372 if (nonRebinnedBinNumber < h_time->GetNbinsX()) {
374 h_timeMask->SetBinContent(nonRebinnedBinNumber, 1);
377 double x_lower = h_timeRebin->GetXaxis()->GetBinLowEdge(bin);
378 double x_upper = h_timeRebin->GetXaxis()->GetBinUpEdge(bin);
379 if (x_lower < time_fit_min) {
380 time_fit_min = x_lower;
382 if (x_upper > time_fit_max) {
383 time_fit_max = x_upper;
387 if (h_time->GetBinContent(nonRebinnedBinNumber) > 0) {
388 B2DEBUG(22,
"Setting bin " << nonRebinnedBinNumber <<
" from " << h_timeMasked->GetBinContent(nonRebinnedBinNumber) <<
" to 0");
389 maskedOutNonZeroBin =
true;
391 h_timeMasked->SetBinContent(nonRebinnedBinNumber, 0);
396 B2INFO(
"Bins with non-zero values have been masked out: " << maskedOutNonZeroBin);
397 h_timeMasked->ResetStats();
398 h_timeMask->ResetStats();
403 double default_meanMasked = h_timeMasked->GetMean();
405 B2INFO(
"default_meanMasked = " << default_meanMasked);
409 double default_mean = h_time->GetMean();
410 double default_mean_unc = h_time->GetMeanError();
411 double default_sigma = h_time->GetStdDev();
413 B2INFO(
"Fitting crystal between " << time_fit_min <<
" and " << time_fit_max);
416 TF1* gaus =
new TF1(
"func",
"gaus(0)", time_fit_min, time_fit_max);
417 gaus->SetParNames(
"numCrystalHitsNormalization",
"mean",
"sigma");
424 double hist_max = h_time->GetMaximum();
427 double stddev = h_time->GetStdDev();
432 gaus->SetParameter(0, hist_max / 2.);
433 gaus->SetParameter(1, mean);
434 gaus->SetParameter(2, sigma);
441 h_timeMasked->Fit(gaus,
"LQR");
443 double fit_mean = gaus->GetParameter(1);
444 double fit_mean_unc = gaus->GetParError(1);
445 double fit_sigma = gaus->GetParameter(2);
447 double meanDiff = fit_mean - default_mean;
448 double meanUncDiff = fit_mean_unc - default_mean_unc;
449 double sigmaDiff = fit_sigma - default_sigma;
451 bool good_fit =
false;
453 if ((fabs(meanDiff) > 10) ||
454 (fabs(meanUncDiff) > 10) ||
455 (fabs(sigmaDiff) > 10) ||
456 (fit_mean_unc > 3) ||
458 (fit_mean < time_fit_min) ||
459 (fit_mean > time_fit_max)) {
460 B2INFO(
"Crystal cell id = " << crys_id);
461 B2INFO(
"fit mean, default mean = " << fit_mean <<
", " << default_mean);
462 B2INFO(
"fit mean unc, default mean unc = " << fit_mean_unc <<
", " << default_mean_unc);
463 B2INFO(
"fit sigma, default sigma = " << fit_sigma <<
", " << default_sigma);
465 B2INFO(
"crystal fit mean - hist mean = " << meanDiff);
466 B2INFO(
"fit mean unc. - hist mean unc. = " << meanUncDiff);
467 B2INFO(
"fit sigma - hist sigma = " << sigmaDiff);
469 B2INFO(
"fit_mean = " << fit_mean);
470 B2INFO(
"time_fit_min = " << time_fit_min);
471 B2INFO(
"time_fit_max = " << time_fit_max);
473 if (fabs(meanDiff) > 10) B2INFO(
"fit mean diff too large");
474 if (fabs(meanUncDiff) > 10) B2INFO(
"fit mean unc diff too large");
475 if (fabs(sigmaDiff) > 10) B2INFO(
"fit mean sigma diff too large");
476 if (fit_mean_unc > 3) B2INFO(
"fit mean unc too large");
477 if (fit_sigma < 0.1) B2INFO(
"fit sigma too small");
481 numCrysWithGoodFit++;
482 crysHasGoodFit[crys_id - 1] = true ;
486 int numEntries = h_time->GetEntries();
489 if ((numEntries >= minNumEntries) && good_fit) {
490 clusterTime_mean = fit_mean;
491 clusterTime_mean_unc = fit_mean_unc;
492 crysHasGoodFitandStats[crys_id - 1] = true ;
494 clusterTime_mean = default_mean;
495 clusterTime_mean_unc = default_mean_unc;
498 if (numEntries < minNumEntries) B2INFO(
"Number of entries less than minimum");
499 if (numEntries == 0) B2INFO(
"Number of entries == 0");
502 t_offsets[crys_id - 1] = clusterTime_mean ;
503 t_offsets_unc[crys_id - 1] = clusterTime_mean_unc ;
504 numClusterPerCrys[crys_id - 1] = numEntries ;
506 histfile->WriteTObject(h_time, (std::string(
"h_time_psi") + std::to_string(crys_id)).c_str());
507 histfile->WriteTObject(h_timeMasked, (std::string(
"h_time_psi_masked") + std::to_string(crys_id)).c_str());
510 peakClusterTime_cid->SetBinContent(crys_id, t_offsets[crys_id - 1]);
511 peakClusterTime_cid->SetBinError(crys_id, t_offsets_unc[crys_id - 1]);
515 if (numEntries > 0) {
516 peakClusterTimes->Fill(t_offsets[crys_id - 1]);
517 numCrysWithNonZeroEntries++ ;
519 if ((numEntries >= minNumEntries) && good_fit) {
520 peakClusterTimesGoodFit->Fill(t_offsets[crys_id - 1]);
521 peakClusterTimesGoodFit__cid->SetBinContent(crys_id, t_offsets[crys_id - 1]);
522 peakClusterTimesGoodFit__cid->SetBinError(crys_id, t_offsets_unc[crys_id - 1]);
527 double numClusterTimesWithinWindowFraction = h_time->Integral(binyLeft, binyRight) ;
528 double clusterTimesWithinWindowFraction = numClusterTimesWithinWindowFraction;
529 if (numEntries > 0) {
530 clusterTimesWithinWindowFraction /= numEntries;
532 clusterTimesWithinWindowFraction = -0.1;
535 B2INFO(
"Crystal cell id = " << crys_id <<
", theta id = " <<
536 thetaID <<
", clusterTimesWithinWindowFraction = " <<
537 numClusterTimesWithinWindowFraction <<
" / " << numEntries <<
" = " <<
538 clusterTimesWithinWindowFraction);
540 clusterTimeFractionInWindow->Fill(clusterTimesWithinWindowFraction);
541 clusterTimeNumberInWindow__cid->SetBinContent(crys_id, numClusterTimesWithinWindowFraction);
542 clusterTimeNumber__cid->SetBinContent(crys_id, numEntries);
544 if ((thetaID >= 3 && thetaID <= 10) ||
545 (thetaID >= 15 && thetaID <= 39) ||
546 (thetaID >= 44 && thetaID <= 56) ||
547 (thetaID >= 61 && thetaID <= 66)) {
548 clusterTimeNumberInWindowInGoodECLRings__cid->SetBinContent(crys_id, numClusterTimesWithinWindowFraction);
556 auto g_clusterTimeFractionInWindow__cid =
new TGraphAsymmErrors(clusterTimeNumberInWindow__cid, clusterTimeNumber__cid,
"w");
557 auto g_clusterTimeFractionInWindowInGoodECLRings__cid =
new TGraphAsymmErrors(clusterTimeNumberInWindowInGoodECLRings__cid,
558 clusterTimeNumber__cid,
"w");
559 g_clusterTimeFractionInWindow__cid->SetTitle(fracWindowTitle);
560 g_clusterTimeFractionInWindowInGoodECLRings__cid->SetTitle(fracWindowInGoodECLRingsTitle);
563 peakClusterTime_cid->ResetStats();
564 peakClusterTimesGoodFit__cid->ResetStats();
566 histfile->WriteTObject(peakClusterTime_cid,
"peakClusterTime_cid");
567 histfile->WriteTObject(peakClusterTimes,
"peakClusterTimes");
568 histfile->WriteTObject(peakClusterTimesGoodFit__cid,
"peakClusterTimesGoodFit__cid");
569 histfile->WriteTObject(peakClusterTimesGoodFit,
"peakClusterTimesGoodFit");
570 histfile->WriteTObject(g_clusterTimeFractionInWindow__cid,
"g_clusterTimeFractionInWindow__cid");
571 histfile->WriteTObject(g_clusterTimeFractionInWindowInGoodECLRings__cid,
"g_clusterTimeFractionInWindowInGoodECLRings__cid");
572 histfile->WriteTObject(clusterTimeFractionInWindow,
"clusterTimeFractionInWindow");
579 vector <int> binProjectionLeft = binProjectionLeft_Time_vs_E_runDep;
580 vector <int> binProjectionRight = binProjectionRight_Time_vs_E_runDep;
582 auto h2 = clusterTimeClusterE;
585 double max_E = h2->GetXaxis()->GetXmax();
588 vector <double> E_binEdges(binProjectionLeft.size() + 1);
589 for (
long unsigned int x_bin = 0; x_bin < binProjectionLeft.size(); x_bin++) {
590 TH1D* h_E_t_slice = h2->ProjectionX(
"h_E_t_slice", 1, 1) ;
591 E_binEdges[x_bin] = h_E_t_slice->GetXaxis()->GetBinLowEdge(binProjectionLeft[x_bin]) ;
592 B2INFO(
"E_binEdges[" << x_bin <<
"] = " << E_binEdges[x_bin]);
593 if (x_bin == binProjectionLeft.size() - 1) {
594 E_binEdges[x_bin + 1] = max_E ;
595 B2INFO(
"E_binEdges[" << x_bin + 1 <<
"] = " << E_binEdges[x_bin + 1]);
600 auto clusterTimePeak_ClusterEnergy_varBin =
new TH1F(
"clusterTimePeak_ClusterEnergy_varBin",
601 ";ECL cluster energy [GeV];Cluster time fit position [ns]", E_binEdges.size() - 1, &(E_binEdges[0]));
602 auto clusterTimePeakWidth_ClusterEnergy_varBin =
new TH1F(
"clusterTimePeakWidth_ClusterEnergy_varBin",
603 ";ECL cluster energy [GeV];Cluster time fit width [ns]", E_binEdges.size() - 1, &(E_binEdges[0]));
605 int Ebin_counter = 1 ;
608 for (
long unsigned int x_bin = 0; x_bin < binProjectionLeft.size(); x_bin++) {
609 double clusterTime_mean = 0;
610 double clusterTime_mean_unc = 0;
611 double clusterTime_sigma = 0;
613 B2INFO(
"x_bin = " << x_bin);
617 TH1D* h_time = h2->ProjectionY((
"h_time_E_slice_" + std::to_string(x_bin)).c_str(), binProjectionLeft[x_bin],
618 binProjectionRight[x_bin]) ;
621 TH1D* h_E_t_slice = h2->ProjectionX(
"h_E_t_slice", 1, 1) ;
622 double lowE = h_E_t_slice->GetXaxis()->GetBinLowEdge(binProjectionLeft[x_bin]) ;
623 double highE = h_E_t_slice->GetXaxis()->GetBinUpEdge(binProjectionRight[x_bin]) ;
624 double meanE = (lowE + highE) / 2.0 ;
626 B2INFO(
"bin " << Ebin_counter <<
": low E = " << lowE <<
", high E = " << highE <<
" GeV");
628 TH1D* h_timeMask = (TH1D*)h_time->Clone();
629 TH1D* h_timeMasked = (TH1D*)h_time->Clone((std::string(
"h_time_E_slice_masked__") + std::to_string(meanE)).c_str());
630 TH1D* h_timeRebin = (TH1D*)h_time->Clone();
637 h_timeMask->Scale(0.0);
639 time_fit_min = hist_tmax;
640 time_fit_max = hist_tmin;
643 double histRebin_max = h_timeRebin->GetMaximum();
645 bool maskedOutNonZeroBin =
false;
647 for (
int bin = 1; bin <= h_timeRebin->GetNbinsX(); bin++) {
650 if (nonRebinnedBinNumber < h_time->GetNbinsX()) {
652 h_timeMask->SetBinContent(nonRebinnedBinNumber, 1);
655 double x_lower = h_timeRebin->GetXaxis()->GetBinLowEdge(bin);
656 double x_upper = h_timeRebin->GetXaxis()->GetBinUpEdge(bin);
657 if (x_lower < time_fit_min) {
658 time_fit_min = x_lower;
660 if (x_upper > time_fit_max) {
661 time_fit_max = x_upper;
665 if (h_time->GetBinContent(nonRebinnedBinNumber) > 0) {
666 B2DEBUG(22,
"Setting bin " << nonRebinnedBinNumber <<
" from " << h_timeMasked->GetBinContent(nonRebinnedBinNumber) <<
" to 0");
667 maskedOutNonZeroBin =
true;
669 h_timeMasked->SetBinContent(nonRebinnedBinNumber, 0);
674 B2INFO(
"Bins with non-zero values have been masked out: " << maskedOutNonZeroBin);
675 h_timeMasked->ResetStats();
676 h_timeMask->ResetStats();
682 double default_meanMasked = h_timeMasked->GetMean();
684 B2INFO(
"default_meanMasked = " << default_meanMasked);
688 double default_mean = h_time->GetMean();
689 double default_mean_unc = h_time->GetMeanError();
690 double default_sigma = h_time->GetStdDev();
692 B2INFO(
"Fitting crystal between " << time_fit_min <<
" and " << time_fit_max);
695 TF1* gaus =
new TF1(
"func",
"gaus(0)", time_fit_min, time_fit_max);
696 gaus->SetParNames(
"numCrystalHitsNormalization",
"mean",
"sigma");
703 double hist_max = h_time->GetMaximum();
706 double stddev = h_time->GetStdDev();
711 gaus->SetParameter(0, hist_max / 2.);
712 gaus->SetParameter(1, mean);
713 gaus->SetParameter(2, sigma);
720 h_timeMasked->Fit(gaus,
"LQR");
722 double fit_mean = gaus->GetParameter(1);
723 double fit_mean_unc = gaus->GetParError(1);
724 double fit_sigma = gaus->GetParameter(2);
726 double meanDiff = fit_mean - default_mean;
727 double meanUncDiff = fit_mean_unc - default_mean_unc;
728 double sigmaDiff = fit_sigma - default_sigma;
730 bool good_fit =
false;
732 if ((fabs(meanDiff) > 10) ||
733 (fabs(meanUncDiff) > 10) ||
734 (fabs(sigmaDiff) > 10) ||
735 (fit_mean_unc > 3) ||
737 (fit_mean < time_fit_min) ||
738 (fit_mean > time_fit_max)) {
739 B2INFO(
"x_bin = " << x_bin);
740 B2INFO(
"fit mean, default mean = " << fit_mean <<
", " << default_mean);
741 B2INFO(
"fit mean unc, default mean unc = " << fit_mean_unc <<
", " << default_mean_unc);
742 B2INFO(
"fit sigma, default sigma = " << fit_sigma <<
", " << default_sigma);
744 B2INFO(
"crystal fit mean - hist mean = " << meanDiff);
745 B2INFO(
"fit mean unc. - hist mean unc. = " << meanUncDiff);
746 B2INFO(
"fit sigma - hist sigma = " << sigmaDiff);
748 B2INFO(
"fit_mean = " << fit_mean);
749 B2INFO(
"time_fit_min = " << time_fit_min);
750 B2INFO(
"time_fit_max = " << time_fit_max);
752 if (fabs(meanDiff) > 10) B2INFO(
"fit mean diff too large");
753 if (fabs(meanUncDiff) > 10) B2INFO(
"fit mean unc diff too large");
754 if (fabs(sigmaDiff) > 10) B2INFO(
"fit mean sigma diff too large");
755 if (fit_mean_unc > 3) B2INFO(
"fit mean unc too large");
756 if (fit_sigma < 0.1) B2INFO(
"fit sigma too small");
763 int numEntries = h_time->GetEntries();
767 if ((numEntries >= minNumEntries) && good_fit) {
768 clusterTime_mean = fit_mean;
769 clusterTime_mean_unc = fit_mean_unc;
770 clusterTime_sigma = fit_sigma;
772 clusterTime_mean = default_mean;
773 clusterTime_mean_unc = default_mean_unc;
774 clusterTime_sigma = default_sigma;
777 if (numEntries < minNumEntries) B2INFO(
"Number of entries less than minimum");
778 if (numEntries == 0) B2INFO(
"Number of entries == 0");
780 histfile->WriteTObject(h_time, (std::string(
"h_time_E_slice") + std::to_string(meanE)).c_str());
781 histfile->WriteTObject(h_timeMasked, (std::string(
"h_time_E_slice_masked") + std::to_string(meanE)).c_str());
784 clusterTimePeak_ClusterEnergy_varBin->SetBinContent(Ebin_counter, clusterTime_mean);
785 clusterTimePeak_ClusterEnergy_varBin->SetBinError(Ebin_counter, clusterTime_mean_unc);
787 clusterTimePeakWidth_ClusterEnergy_varBin->SetBinContent(Ebin_counter, clusterTime_sigma);
788 clusterTimePeakWidth_ClusterEnergy_varBin->SetBinError(Ebin_counter, 0);
804 vector< pair<double, int> > fitClusterTime__crystalIDBase0__pairs;
807 for (
int cid = 0; cid < 8736; cid++) {
808 fitClusterTime__crystalIDBase0__pairs.push_back(make_pair(0.0, cid));
813 fitClusterTime__crystalIDBase0__pairs[crys_id - 1] = make_pair(fabs(t_offsets[crys_id - 1]), crys_id - 1) ;
817 sort(fitClusterTime__crystalIDBase0__pairs.begin(), fitClusterTime__crystalIDBase0__pairs.end());
821 B2INFO(
"-------- List of the (fitted) peak cluster times sorted by their absolute value ----------");
822 B2INFO(
"------------------------------------------------------------------------------------------");
823 B2INFO(
"------------------------------------------------------------------------------------------");
824 B2INFO(
"Quoted # of clusters is before the cutting off of the distribution tails, cellID=1..8736, crysID=0..8735");
826 bool hasHitThresholdBadTimes = false ;
827 for (
int iSortedTimes = 0; iSortedTimes < 8736; iSortedTimes++) {
828 int cid = fitClusterTime__crystalIDBase0__pairs[iSortedTimes].second ;
829 if (!hasHitThresholdBadTimes && fitClusterTime__crystalIDBase0__pairs[iSortedTimes].first > 2) {
830 B2INFO(
"======== |t_fit| > Xns threshold ======");
831 hasHitThresholdBadTimes =
true;
834 B2INFO(
"cid = " << cid <<
", peak clust t = " << t_offsets[cid] <<
" +- " << t_offsets_unc[cid] <<
" ns, # clust = " <<
835 numClusterPerCrys[cid] <<
", good fit = " << crysHasGoodFit[cid] <<
", good fit & stats = " << crysHasGoodFitandStats[cid]);
843 B2INFO(
"######## List of poor (fitted) peak cluster times sorted by their absolute value #########");
844 B2INFO(
"##########################################################################################");
845 B2INFO(
"##########################################################################################");
847 for (
int iSortedTimes = 0; iSortedTimes < 8736; iSortedTimes++) {
848 int cid = fitClusterTime__crystalIDBase0__pairs[iSortedTimes].second ;
849 if (fitClusterTime__crystalIDBase0__pairs[iSortedTimes].first > 2 && crysHasGoodFitandStats[cid]) {
850 B2INFO(
"WARNING: cid = " << cid <<
", peak clust t = " << t_offsets[cid] <<
" +- " << t_offsets_unc[cid] <<
" ns, # clust = " <<
851 numClusterPerCrys[cid] <<
", good fit = " << crysHasGoodFit[cid] <<
", good fit & stats = " << crysHasGoodFitandStats[cid]);
857 B2INFO(
"Number of crystals with non-zero number of hits = " << numCrysWithNonZeroEntries);
858 B2INFO(
"Number of crystals with good quality fits = " << numCrysWithGoodFit);
861 clusterTimePeak_ClusterEnergy_varBin->ResetStats();
862 clusterTimePeakWidth_ClusterEnergy_varBin->ResetStats();
864 histfile->WriteTObject(clusterTimePeak_ClusterEnergy_varBin,
"clusterTimePeak_ClusterEnergy_varBin");
865 histfile->WriteTObject(clusterTimePeakWidth_ClusterEnergy_varBin,
"clusterTimePeakWidth_ClusterEnergy_varBin");
871 B2INFO(
"Filling histograms for difference in crystal payload values and the pre-calibration values. These older values may be from a previous bucket or older reprocessing of the data.");
872 for (
int crys_id = 1; crys_id <= 8736; crys_id++) {
873 double tsDiffCustomOld_ns = -999;
875 tsDiffCustomOld_ns = (currentValuesCrys[crys_id - 1] - prevValuesCrys[crys_id - 1]) * TICKS_TO_NS;
876 B2INFO(
"Crystal " << crys_id <<
": ts new merged - 'before 1st iter' merged = (" <<
877 currentValuesCrys[crys_id - 1] <<
" - " << prevValuesCrys[crys_id - 1] <<
878 ") ticks * " << TICKS_TO_NS <<
" ns/tick = " << tsDiffCustomOld_ns <<
" ns");
881 tsNew_MINUS_tsCustomPrev__cid->SetBinContent(crys_id, tsDiffCustomOld_ns);
882 tsNew_MINUS_tsCustomPrev__cid->SetBinError(crys_id, 0);
883 tsNew_MINUS_tsCustomPrev__cid->ResetStats();
885 tsNew_MINUS_tsCustomPrev->Fill(tsDiffCustomOld_ns);
886 tsNew_MINUS_tsCustomPrev->ResetStats();
889 histfile->WriteTObject(tsNew_MINUS_tsCustomPrev__cid,
"tsNew_MINUS_tsCustomPrev__cid");
890 histfile->WriteTObject(tsNew_MINUS_tsCustomPrev,
"tsNew_MINUS_tsCustomPrev");
895 B2INFO(
"Finished validations algorithm");
Base class for calibration algorithms.
void updateDBObjPtrs(const unsigned int event, const int run, const int experiment)
Updates any DBObjPtrs by calling update(event) for DBStore.
void setDescription(const std::string &description)
Set algorithm description (in constructor)
EResult
The result of calibration.
@ c_OK
Finished successfuly =0 in Python.
@ c_Failure
Failed =3 in Python.
const std::vector< Calibration::ExpRun > & getRunList() const
Get the list of runs for which calibration is called.
Singleton class to cache database objects.
static DataStore & Instance()
Instance of singleton Store.
void setInitializeActive(bool active)
Setter for m_initializeActive.
const std::vector< float > & getCalibUncVector() const
Get vector of uncertainties on calibration constants.
const std::vector< float > & getCalibVector() const
Get vector of calibration constants.
This class provides access to ECL channel map that is either a) Loaded from the database (see ecl/dbo...
The Class for ECL Geometry Parameters.
static ECLGeometryPar * Instance()
Static method to get a reference to the ECLGeometryPar instance.
void Mapping(int cid)
Mapping theta, phi Id.
int GetThetaID()
Get Theta Id.
static constexpr double m_rf
accelerating RF, http://ptep.oxfordjournals.org/content/2013/3/03A006.full.pdf
eclTValidationAlgorithm()
..Constructor
int cellIDHi
Fit crystals with cellID0 in the inclusive range [cellIDLo,cellIDHi].
int cellIDLo
Fit crystals with cellID0 in the inclusive range [cellIDLo,cellIDHi].
double meanCleanRebinFactor
Rebinning factor for mean calculation.
double clusterTimesFractionWindow_maxtime
Maximum time for window to calculate cluster time fraction, in ns.
double meanCleanCutMinFactor
After rebinning, create a mask for bins that have values less than meanCleanCutMinFactor times the ma...
bool readPrevCrysPayload
Read the previous crystal payload values for comparison.
EResult calibrate() override
..Run algorithm on events
std::string debugFilenameBase
Name of file with debug output, eclTValidationAlgorithm.root by default.
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
Type-safe access to single objects in the data store.
bool construct(Args &&... params)
Construct an object of type T in this StoreObjPtr, using the provided constructor arguments.
static DBStore & Instance()
Instance of a singleton DBStore.
void updateEvent()
Updates all intra-run dependent objects.
void update()
Updates all objects that are outside their interval of validity.
Abstract base class for different kinds of events.