Belle II Software development
eclMergingCrystalTimingAlgorithm.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9/* Own header. */
10#include <ecl/calibration/eclMergingCrystalTimingAlgorithm.h>
11
12/* ECL headers. */
13#include <ecl/dbobjects/ECLCrystalCalib.h>
14#include <ecl/dbobjects/ECLReferenceCrystalPerCrateCalib.h>
15#include <ecl/digitization/EclConfiguration.h>
16#include <ecl/mapper/ECLChannelMapper.h>
17
18/* ROOT headers. */
19#include <TDirectory.h>
20#include <TFile.h>
21#include <TH1F.h>
22#include <TString.h>
23
24using namespace std;
25using namespace Belle2;
26using namespace ECL;
27using namespace Calibration;
28
31 CalibrationAlgorithm("DummyCollector"),
32 readPrevCrysPayload(false),
33 m_ECLCrystalTimeOffsetBhabha("ECLCrystalTimeOffsetBhabha"),
34 m_ECLCrystalTimeOffsetBhabhaGamma("ECLCrystalTimeOffsetBhabhaGamma"),
35 m_ECLCrystalTimeOffsetCosmic("ECLCrystalTimeOffsetCosmic"),
36 m_ECLReferenceCrystalPerCrateCalib("ECLReferenceCrystalPerCrateCalib"),
37 m_ECLCrateTimeOffset("ECLCrateTimeOffset")
38{
40 "Perform time calibration of ecl crystals by combining previous values from the DB for different calibrations."
41 );
42}
43
45{
47 B2INFO("readPrevCrysPayload = " << readPrevCrysPayload);
48
49 //------------------------------------------------------------------------
50 // Get the input run list to use to update the DBObjectPtrs
51 auto runs = getRunList();
52 /* Take the first run. For the crystal cosmic calibrations, because of the crate
53 calibrations, there is not a known correct run to use within the range. */
54 ExpRun chosenRun = runs.front();
55 B2INFO("merging using the ExpRun (" << chosenRun.second << "," << chosenRun.first << ")");
56 // After here your DBObjPtrs are correct
57 updateDBObjPtrs(1, chosenRun.second, chosenRun.first);
58
59
60 //------------------------------------------------------------------------
61 /* With the database set up, load the ecl channel mapper to access the
62 crystal to crate mapping information */
63 unique_ptr<ECLChannelMapper> crystalMapper(new ECL::ECLChannelMapper());
64 crystalMapper->initFromDB();
65
66 //------------------------------------------------------------------------
67 // Test the DBObjects we want to exist and fail if not all of them do.
68 bool allObjectsFound = true;
69
71 // Check that the payloads we want to merge are sufficiently loaded
73 allObjectsFound = false;
74 B2ERROR("No valid DBObject found for 'ECLCrystalTimeOffsetBhabha'");
75 }
77 allObjectsFound = false;
78 B2ERROR("No valid DBObject found for 'ECLCrystalTimeOffsetBhabhaGamma'");
79 }
81 allObjectsFound = false;
82 B2ERROR("No valid DBObject found for 'ECLCrystalTimeOffsetCosmic'");
83 }
84
85 // Check that the reference crystal payload is loaded
87 allObjectsFound = false;
88 B2ERROR("No valid DBObject found for 'ECLReferenceCrystalPerCrateCalib'");
89 }
90
91 // Check that the crate payload is loaded (used for transforming cosmic payload)
93 allObjectsFound = false;
94 B2ERROR("No valid DBObject found for 'ECLCrateTimeOffset'");
95 }
96
97
98 if (allObjectsFound) {
99 B2INFO("Valid objects found for 'ECLCrystalTimeOffsetBhabha', 'ECLCrystalTimeOffsetBhabhaGamma' and 'ECLCrystalTimeOffsetCosmic')");
100 B2INFO("Valid object found for 'ECLReferenceCrystalPerCrateCalib'");
101 B2INFO("Valid object found for 'ECLCrateTimeOffset'");
102 } else {
103 B2INFO("Exiting with failure");
104 return c_Failure;
105 }
106
107
108 /* 1/(4fRF) = 0.4913 ns/clock tick, where fRF is the accelerator RF frequency.
109 Same for all crystals. */
110 const double TICKS_TO_NS = 1.0 / (4.0 * EclConfiguration::getRF()) * 1e3;
111
112
113
114 // Set the rootfile name
115 bool minRunNumBool = false;
116 bool maxRunNumBool = false;
117 int minRunNum = -1;
118 int maxRunNum = -1;
119 int minExpNum = -1;
120 int maxExpNum = -1;
121 for (auto expRun : getRunList()) {
122 int expNumber = expRun.first;
123 int runNumber = expRun.second;
124 if (!minRunNumBool) {
125 minExpNum = expNumber;
126 minRunNum = runNumber;
127 minRunNumBool = true;
128 }
129 if (!maxRunNumBool) {
130 maxExpNum = expNumber;
131 maxRunNum = runNumber;
132 maxRunNumBool = true;
133 }
134 if (((minRunNum > runNumber) && (minExpNum >= expNumber)) ||
135 (minExpNum > expNumber)) {
136 minExpNum = expNumber;
137 minRunNum = runNumber;
138 }
139 if (((maxRunNum < runNumber) && (maxExpNum <= expNumber)) ||
140 (maxExpNum < expNumber))
141
142 {
143 maxExpNum = expNumber;
144 maxRunNum = runNumber;
145 }
146 }
147
148 string debugFilenameBase = "ECLCrystalTimeOffsetMerged";
149 B2INFO("debugFilenameBase = " << debugFilenameBase);
150 string runNumsString = string("_") + to_string(minExpNum) + "_" + to_string(minRunNum) + string("-") +
151 to_string(maxExpNum) + "_" + to_string(maxRunNum);
152 string debugFilename = debugFilenameBase + runNumsString + string(".root");
153
154
155
156
157 //------------------------------------------------------------------------
159 vector<float> bhabhaCalib = m_ECLCrystalTimeOffsetBhabha->getCalibVector();
160 vector<float> bhabhaCalibUnc = m_ECLCrystalTimeOffsetBhabha->getCalibUncVector(); // Negative uncertainties are flags of bad fits
161
162 vector<float> bhabhaGammaCalib = m_ECLCrystalTimeOffsetBhabhaGamma->getCalibVector();
163 vector<float> bhabhaGammaCalibUnc = m_ECLCrystalTimeOffsetBhabhaGamma->getCalibUncVector(); // Negative uncertainties can be flags
164
165 vector<float> cosmicCalib = m_ECLCrystalTimeOffsetCosmic->getCalibVector();
166 vector<float> cosmicCalibUnc = m_ECLCrystalTimeOffsetCosmic->getCalibUncVector();
167
168 B2INFO("Loaded 'ECLCrystalTimeOffset*' calibrations");
169
170 // Get the list of reference crystals as special case crystals
171 vector<short> refCrystalPerCrate = m_ECLReferenceCrystalPerCrateCalib->getReferenceCrystals();
172
173 B2INFO("Loaded 'ECLReferenceCrystalPerCrateCalib' calibration");
174
175 vector<float> crateCalib = m_ECLCrateTimeOffset->getCalibVector();
176
177 B2INFO("Loaded 'ECLCrateTimeOffset' calibration");
178
179
180 // Get the previous crystal payloads
181 DBObjPtr<Belle2::ECLCrystalCalib> customPrevCrystalTimeObject("ECLCrystalTimeOffsetPreviousValues");
182 vector<float> prevValuesCrys(ECLElementNumbers::c_NCrystals);
183 vector<float> prevValuesCrysUnc(ECLElementNumbers::c_NCrystals);
184
185 DBObjPtr<Belle2::ECLCrystalCalib> customPrevBhabhaCrystalTimeObject("ECLCrystalTimeOffsetBhabhaPreviousValues");
186 vector<float> prevBhabhaValuesCrys(ECLElementNumbers::c_NCrystals);
187 vector<float> prevBhabhaValuesCrysUnc(ECLElementNumbers::c_NCrystals);
188
190 //..Get vectors of values from the payloads
191 prevValuesCrys = customPrevCrystalTimeObject->getCalibVector();
192 prevValuesCrysUnc = customPrevCrystalTimeObject->getCalibUncVector();
193
194 prevBhabhaValuesCrys = customPrevBhabhaCrystalTimeObject->getCalibVector();
195 prevBhabhaValuesCrysUnc = customPrevBhabhaCrystalTimeObject->getCalibUncVector();
196
197 //..Print out a few values for quality control
198 B2INFO("Previous values read from database. Write out for their values for comparison");
199 for (int ic = 0; ic < ECLElementNumbers::c_NCrystals; ic += 500) {
200 B2INFO("ts custom previous payload: cellID " << ic + 1 << " " << prevValuesCrys[ic]);
201 }
202 B2INFO("Previous bhabha values read from database. Write out for their values for comparison");
203 for (int ic = 0; ic < ECLElementNumbers::c_NCrystals; ic += 500) {
204 B2INFO("ts custom previous bhabha payload: cellID " << ic + 1 << " " << prevBhabhaValuesCrys[ic]);
205 }
206 }
207
208
209
210 //------------------------------------------------------------------------
238 //------------------------------------------------------------------------
239 /* Determine the bhabha and radiative bhabha calibration quality*/
240
241 vector<bool> bhabhaCalibGoodQuality(m_numCrystals, false);
242 vector<bool> bhabhaGammaCalibGoodQuality(m_numCrystals, false);
243 for (int ic = 0; ic < m_numCrystals; ic++) {
244 /* Define a good bhabha calibration value. This is the
245 uncertainty on the calibration constant (e.g. fit mean),
246 not the gaussian width of the timing distribution for
247 that crystal (i.e. resolution).
248
249 Uncertainty stored as ticks so converted to ns for
250 more human readable cut.*/
251 if (bhabhaCalibUnc[ic] != 0
252 && fabs(bhabhaCalibUnc[ic])*TICKS_TO_NS < 2) {
253 // The limits on the uncertainties are not fully optimized !!!!!!!!!!!!!!!!!!!!!!!!!!
254 // Tighten the uncertainty cut after introduction of bhabha gamma calibration. Perhaps checking if the
255 // value is negative as that flags poor fits / the overall hist mean was used. In these cases,
256 // the bhabha gamma calibration should be used (if it has good stats) but until that calibration is
257 // properly made (not all zeros) then the bhabha calibration should be used instead as the only
258 // other option is the cosmic calibration.
259 bhabhaCalibGoodQuality[ic] = true ;
260 }
261 /* Define a good radiative bhabha calibration value, which
262 should be looser than the bhabha requirements since
263 the radiative bhabha calibration is the backup choice.
264 If the radiative bhabha calibration is not good then
265 we resort to using the cosmic calibration so the
266 radiative bhabha requirements should be fairly loose.
267
268 Uncertainty stored as ticks so converted to ns for
269 more human readable cut.*/
270 if (bhabhaGammaCalibUnc[ic] != 0
271 && fabs(bhabhaGammaCalibUnc[ic])*TICKS_TO_NS <
272 3.5) { // The limits on the uncertainties are not fully optimized !!!!!!!!!!!!!!!!!!!!!!!!!!
273 bhabhaGammaCalibGoodQuality[ic] = true ;
274 }
275 }
276
277
278 /* Loop over all crystals and shift the cosmic crystal calibration by
279 the crate calibration because the cosmic calibration was made
280 assuming the crate calibration is 0.*/
281
282 vector<float> crateCalibShort(m_numCrates);
283 vector<float> cosmicCalibShifted = cosmicCalib;
284 vector<float> cosmicCalibShiftedUnc = cosmicCalibUnc; // Do not modify uncertainty?
285 for (int ic = 0; ic < m_numCrystals; ic++) {
286 cosmicCalibShifted[ic] -= crateCalib[ic];
287 int crate_id_from_crystal = crystalMapper->getCrateID(ic + 1);
288 crateCalibShort[crate_id_from_crystal - 1] = crateCalib[ic];
289 }
290
291 for (int icrate = 0; icrate < m_numCrates; icrate++) {
292 B2INFO("crate time calibration for crate " <<
293 icrate + 1 << " = " << crateCalibShort[icrate]);
294 }
295
296
297 /* Keep track of the mean value of the crystal calibration constants
298 for each crate. Exclude crystals with bad quality or that have
299 a value of 0 (except reference crystals). */
300 vector<float> meanGoodCrystalCalibPerCrate_bhabha(m_numCrates, 0);
301 vector<float> meanGoodCrystalCalibPerCrate_cosmic(m_numCrates, 0);
302
303 /* Start num entries at 1 because we will skip all 0s but include
304 the reference crystal (ts=0) by just increasing the counter.
305 We only need a counter for the bhabha events since we want to
306 get the same sample of crystals for both the bhabha and cosmic
307 calibrations.*/
308 vector<short> numGoodCrystalCalibPerCrate_bhabha(m_numCrates, 1);
309
310
311 /* Loop over all crystals and save the crystal calibration information
312 for each crate. */
313 for (int ic_base1 = 1; ic_base1 <= m_numCrystals; ic_base1++) {
314 int crate_id_from_crystal = crystalMapper->getCrateID(ic_base1);
315
316 if (!((bhabhaCalib[ic_base1 - 1] == 0) || (! bhabhaCalibGoodQuality[ic_base1 - 1]))) {
317 meanGoodCrystalCalibPerCrate_bhabha[crate_id_from_crystal - 1] += bhabhaCalib[ic_base1 - 1];
318 meanGoodCrystalCalibPerCrate_cosmic[crate_id_from_crystal - 1] += cosmicCalibShifted[ic_base1 - 1];
319 numGoodCrystalCalibPerCrate_bhabha[crate_id_from_crystal - 1]++ ;
320 }
321 }
322
323 /* Complete the calculation of the mean by dividing the sum by the number of entries */
324 for (int icrate = 0; icrate < m_numCrates; icrate++) {
325 meanGoodCrystalCalibPerCrate_bhabha[icrate] /= numGoodCrystalCalibPerCrate_bhabha[icrate] ;
326 meanGoodCrystalCalibPerCrate_cosmic[icrate] /= numGoodCrystalCalibPerCrate_bhabha[icrate] ;
327 B2INFO("Mean bhabha crystal calibration for crate " << icrate + 1 << " = " << meanGoodCrystalCalibPerCrate_bhabha[icrate]);
328 B2INFO("Mean cosmic crystal calibration for crate " << icrate + 1 << " = " << meanGoodCrystalCalibPerCrate_cosmic[icrate]);
329 B2INFO("Number of good crystal calibrations for crate" << icrate + 1 << " = " << numGoodCrystalCalibPerCrate_bhabha[icrate]);
330 }
331
332
335 /* Loop over all crystals and correct the cosmic calibration by the cosmic calibration
336 for each crate by the average difference to the bhabha calibration. */
337 for (int ic_base1 = 1; ic_base1 <= m_numCrystals; ic_base1++) {
338 int crate_id_from_crystal = crystalMapper->getCrateID(ic_base1);
339 cosmicCalibShifted[ic_base1 - 1] += meanGoodCrystalCalibPerCrate_bhabha[crate_id_from_crystal - 1] -
340 meanGoodCrystalCalibPerCrate_cosmic[crate_id_from_crystal - 1] ;
341 }
342
343
344 //------------------------------------------------------------------------
354 vector<float> newCalib(m_numCrystals);
355 vector<float> newCalibUnc(m_numCrystals);
356
357 vector<float> newBhabhaMinusCustomPrevCalib__cid(m_numCrystals);
358 vector<float> newBhabhaMinusCustomPrevBhabhaCalib__cid(m_numCrystals);
359 vector<float> newBhabhaMinusCustomPrevCalib;
360 vector<float> newBhabhaMinusCustomPrevBhabhaCalib;
361
362
363 // Loop over each crystal we want to check
364 for (int ic = 0; ic < m_numCrystals; ic++) {
365 B2DEBUG(29, "Merging crystal " << ic + 1);
366 int crate_id_from_crystal = crystalMapper->getCrateID(ic + 1);
367
368 // Determine if the current crystal is a reference crystal
369 bool isRefCrys = false ;
370 for (int icrate = 0; icrate < m_numCrates; icrate++) {
371 if (ic + 1 == refCrystalPerCrate[icrate]) {
372 isRefCrys = true;
373 B2INFO("Crystal " << ic + 1 << " is a reference crystal");
374 break;
375 }
376 B2DEBUG(29, "Checked reference crystal for crate " << icrate + 1);
377 }
378 B2DEBUG(29, "Checked ref crystal");
379
380 string whichCalibUsed = "bhabha";
381
382 // By default set the new calibration to the bhabha calibration
383 newCalib[ic] = bhabhaCalib[ic];
384 newCalibUnc[ic] = fabs(bhabhaCalibUnc[ic]);
385
386 double newMinusMerged ;
387 double newMinusBhabha ;
388
389
390 /* If the crystal is not a reference crystal and there is no bhabha
391 calib for that crystal then use a different calibration. If the
392 crystal is not a reference crystal and the crystal has a bad bhabha
393 crystal calibration uncertainty. */
394 if ((!isRefCrys) &&
395 ((bhabhaCalib[ic] == 0) || (! bhabhaCalibGoodQuality[ic]))) {
396
397 /* If there is a radiative bhabha calibration for this crystal then
398 use it otherwise use the cosmic calibration */
399 if (bhabhaGammaCalib[ic] != 0 || bhabhaGammaCalibGoodQuality[ic]) {
400 newCalib[ic] = bhabhaGammaCalib[ic] ;
401 newCalibUnc[ic] = fabs(bhabhaGammaCalibUnc[ic]);
402 whichCalibUsed = "bhabhaGamma";
403 } else {
404 newCalib[ic] = cosmicCalibShifted[ic] ;
405 newCalibUnc[ic] = cosmicCalibShiftedUnc[ic];
406 whichCalibUsed = "cosmic";
407 }
408 } else {
409 newMinusMerged = (newCalib[ic] - prevValuesCrys[ic]) * TICKS_TO_NS;
410 newMinusBhabha = (newCalib[ic] - prevBhabhaValuesCrys[ic]) * TICKS_TO_NS;
411
412 newBhabhaMinusCustomPrevCalib__cid[ic] = newMinusMerged;
413 newBhabhaMinusCustomPrevBhabhaCalib__cid[ic] = newMinusBhabha;
414 newBhabhaMinusCustomPrevCalib.push_back(newMinusMerged);
415 newBhabhaMinusCustomPrevBhabhaCalib.push_back(newMinusBhabha);
416 }
417
418 newMinusMerged = (newCalib[ic] - prevValuesCrys[ic]) * TICKS_TO_NS;
419 newMinusBhabha = (newCalib[ic] - prevBhabhaValuesCrys[ic]) * TICKS_TO_NS;
420
421
422 B2INFO("Crystal " << ic + 1 << ", crate " << crate_id_from_crystal <<
423 "::: bhabha = " << bhabhaCalib[ic] << "+-" << bhabhaCalibUnc[ic] <<
424 " ticks, rad bhabha = " << bhabhaGammaCalib[ic] << "+-" << bhabhaGammaCalibUnc[ic] <<
425 " ticks, cosmic UNshifted = " << cosmicCalib[ic] << "+-" << cosmicCalibUnc[ic] <<
426 " ticks, cosmic shifted = " << cosmicCalibShifted[ic] << "+-" << cosmicCalibShiftedUnc[ic] <<
427 " ticks. ||| New calib = " << newCalib[ic] << " ticks, selected " << whichCalibUsed);
428 B2INFO(" Crystal " << ic + 1 << ", pre calib ts = " << prevValuesCrys[ic] <<
429 ", pre calib bhabha ts = " << prevBhabhaValuesCrys[ic] <<
430 " ticks ||| new - pre calib ts = " << newMinusMerged <<
431 ", new - pre calib bhabha ts = " << newMinusBhabha << " ns");
432 } // end of setting new calibration for each crystal
433
434
435
436 //------------------------------------------------------------------------
437 //..Histograms of calibrations
438
439 // Just in case, we remember the current TDirectory so we can return to it
440 TDirectory* executeDir = gDirectory;
441
442 TString fname = debugFilename;
443 TFile hfile(fname, "recreate");
444
445 TString htitle = "ECLCrystalTimeOffsetBhabha;cellID;Bhabha ts values [ticks]";
446 TH1F* bhabhaPayload = new TH1F("bhabhaPayload", htitle, m_numCrystals, 1, 8737);
447
448 htitle = "ECLCrystalTimeOffsetBhabhaGamma;cellID;Radiative bhabha ts values [ticks]";
449 TH1F* bhabhaGammaPayload = new TH1F("bhabhaGammaPayload", htitle, m_numCrystals, 1, 8737);
450
451 htitle = "ECLCrystalTimeOffsetCosmic : unshifted;cellID;Unshifted cosmic ts values [ticks]";
452 TH1F* cosmicPayload = new TH1F("cosmicUnshiftedPayload", htitle, m_numCrystals, 1, 8737);
453
454 htitle = "ECLCrystalTimeOffsetCosmic : shifted;cellID;Shifted cosmic ts values [ticks]";
455 TH1F* cosmicShiftedPayload = new TH1F("cosmicShiftedPayload", htitle, m_numCrystals, 1, 8737);
456
457 htitle = "New ECLCrystalTimeOffset;cellID;New (merged) ts values [ticks]";
458 TH1F* newPayload = new TH1F("newPayload", htitle, m_numCrystals, 1, 8737);
459
460
461 htitle = "ECLCrystalTimeOffsetBhabha : 'pre-calib' values;cellID;Pre-calibration bhabha ts values [ticks]";
462 TH1F* tsCustomPrevBhabha_payload = new TH1F("tsCustomPrevBhabha_payload", htitle, m_numCrystals, 1, 8737);
463
464 htitle = "ECLCrystalTimeOffset : 'pre-calib' values;cellID;Pre-calibration merged ts values [ticks]";
465 TH1F* tsCustomPrev_payload = new TH1F("tsCustomPrev_payload", htitle, m_numCrystals, 1, 8737);
466
467
468
469 htitle = "-Only for crystals where the new bhabha ts value is used-;cellID;ts(new | bhabha) - ts(old = 'pre-calib' | merged) [ns]";
470 TH1F* newBhabhaMinusCustomPrev__cid = new TH1F("newBhabhaMinusCustomPrev__cid", htitle, m_numCrystals, 1, 8737);
471
472 htitle = "-Only for crystals where the new bhabha ts value is used-;cellID;ts(new | bhabha) - ts(old = 'pre-calib' | bhabha) [ns]";
473 TH1F* newBhabhaMinusCustomPrevBhabha__cid = new TH1F("newBhabhaMinusCustomPrevBhabha__cid", htitle, m_numCrystals, 1, 8737);
474
475 htitle = "-Only for crystals where the new bhabha ts value is used-;ts(new | bhabha) - ts(old = 'pre-calib' | merged) [ns];Number of crystals";
476 auto tsNewBhabha_MINUS_tsCustomPrev = new TH1F("TsNewBhabha_MINUS_TsCustomPrev", htitle, 285, -69.5801, 69.5801);
477
478 htitle = "-Only for crystals where the new bhabha ts value is used-;ts(new | bhabha) - ts(old = 'pre-calib' | bhabha) [ns];Number of crystals";
479 auto tsNewBhabha_MINUS_tsCustomPrevBhabha = new TH1F("TsNewBhabha_MINUS_TsCustomPrevBhabha", htitle, 285, -69.5801, 69.5801);
480
481
482 for (int cellID = 1; cellID <= m_numCrystals; cellID++) {
483 bhabhaPayload->SetBinContent(cellID, bhabhaCalib[cellID - 1]);
484 bhabhaPayload->SetBinError(cellID, fabs(bhabhaCalibUnc[cellID - 1]));
485
486 bhabhaGammaPayload->SetBinContent(cellID, bhabhaGammaCalib[cellID - 1]);
487 bhabhaGammaPayload->SetBinError(cellID, fabs(bhabhaGammaCalibUnc[cellID - 1]));
488
489 cosmicPayload->SetBinContent(cellID, cosmicCalib[cellID - 1]);
490 cosmicPayload->SetBinError(cellID, cosmicCalibUnc[cellID - 1]);
491
492 cosmicShiftedPayload->SetBinContent(cellID, cosmicCalibShifted[cellID - 1]);
493 cosmicShiftedPayload->SetBinError(cellID, cosmicCalibShiftedUnc[cellID - 1]);
494
495 newPayload->SetBinContent(cellID, newCalib[cellID - 1]);
496 newPayload->SetBinError(cellID, newCalibUnc[cellID - 1]);
497
498 // Comparisons of change in ts
500 newBhabhaMinusCustomPrev__cid->SetBinContent(cellID, newBhabhaMinusCustomPrevCalib__cid[cellID - 1]);
501 newBhabhaMinusCustomPrev__cid->SetBinError(cellID, 0);
502
503 newBhabhaMinusCustomPrevBhabha__cid->SetBinContent(cellID, newBhabhaMinusCustomPrevBhabhaCalib__cid[cellID - 1]);
504 newBhabhaMinusCustomPrevBhabha__cid->SetBinError(cellID, 0);
505
506
507 tsCustomPrev_payload->SetBinContent(cellID, prevValuesCrys[cellID - 1]);
508 tsCustomPrev_payload->SetBinError(cellID, prevValuesCrysUnc[cellID - 1]);
509
510 tsCustomPrevBhabha_payload->SetBinContent(cellID, prevBhabhaValuesCrys[cellID - 1]);
511 tsCustomPrevBhabha_payload->SetBinError(cellID, fabs(prevBhabhaValuesCrysUnc[cellID - 1]));
512 }
513 }
514
516 for (long unsigned int ib = 0; ib < newBhabhaMinusCustomPrevCalib.size(); ib++) {
517 tsNewBhabha_MINUS_tsCustomPrev->Fill(newBhabhaMinusCustomPrevCalib[ib]);
518 }
519
520 for (long unsigned int ib = 0; ib < newBhabhaMinusCustomPrevBhabhaCalib.size(); ib++) {
521 tsNewBhabha_MINUS_tsCustomPrevBhabha->Fill(newBhabhaMinusCustomPrevBhabhaCalib[ib]);
522 }
523 }
524
525
526 hfile.cd();
527 hfile.Write();
528 hfile.Close();
529 B2INFO("Debugging histograms written to " << fname);
530 // Go back to original TDirectory
531 executeDir->cd();
532
533
534 /* Re-save the new bhabha calibrations to a payload. The bhabha calibrations have NOT
535 been changed; however, the best way of controlling which payloads get get uploaded to
536 the GT as part of the prommp calibrations is to save a second copy in this calibration
537 directory since we don't want to save all the payloads from the previous directory.
538 See the "<calibration>.save_payloads = <True/False>" code in the airflow steering file.*/
539 ECLCrystalCalib* bhabhaCalibCopy = new ECLCrystalCalib();
540 bhabhaCalibCopy->setCalibVector(bhabhaCalib, bhabhaCalibUnc);
541 saveCalibration(bhabhaCalibCopy, "ECLCrystalTimeOffsetBhabha");
542
543 // Save the new merged calibrations to a payload
544 ECLCrystalCalib* newCrystalTimes = new ECLCrystalCalib();
545 newCrystalTimes->setCalibVector(newCalib, newCalibUnc);
546 saveCalibration(newCrystalTimes, "ECLCrystalTimeOffset");
547 return c_OK;
548}
Base class for calibration algorithms.
void saveCalibration(TClonesArray *data, const std::string &name)
Store DBArray payload with given name with default IOV.
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)
const std::vector< Calibration::ExpRun > & getRunList() const
Get the list of runs for which calibration is called.
EResult
The result of calibration.
@ c_OK
Finished successfully =0 in Python.
@ c_Failure
Failed =3 in Python.
Class for accessing objects in the database.
Definition: DBObjPtr.h:21
General DB object to store one calibration number per ECL crystal.
void setCalibVector(const std::vector< float > &CalibConst, const std::vector< float > &CalibConstUnc)
Set vector of constants with uncertainties.
This class provides access to ECL channel map that is either a) Loaded from the database (see ecl/dbo...
static double getRF()
See m_rf.
DBObjPtr< ECLCrystalCalib > m_ECLCrystalTimeOffsetBhabha
ECLCrystalTimeOffsetBhabha payload that we want to read from the DB.
DBObjPtr< ECLReferenceCrystalPerCrateCalib > m_ECLReferenceCrystalPerCrateCalib
ECLReferenceCrystalPerCrateCalib payload that we want to read from the DB.
static constexpr int m_numCrates
Number of Crates expected.
DBObjPtr< ECLCrystalCalib > m_ECLCrateTimeOffset
ECLCrateTimeOffset payload that we want to read from the DB.
static constexpr int m_numCrystals
Number of Crystals expected.
bool readPrevCrysPayload
< Read the previous crystal payload values for comparison
DBObjPtr< ECLCrystalCalib > m_ECLCrystalTimeOffsetCosmic
ECLCrystalTimeOffsetCosmic payload that we want to read from the DB.
DBObjPtr< ECLCrystalCalib > m_ECLCrystalTimeOffsetBhabhaGamma
ECLCrystalTimeOffsetBhabhaGamma payload that we want to read from the DB.
const int c_NCrystals
Number of crystals.
Abstract base class for different kinds of events.
STL namespace.
Struct containing exp number and run number.
Definition: Splitter.h:51