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"),
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 //------------------------------------------------------------------------
234
235
236
237
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 const int firstHighStatsCrysID = 673 - 1; // cellID 673
244 const int lastHighStatsCrysID = 8160 - 1; // cellID 8160
245 for (int ic = 0; ic < m_numCrystals; ic++) {
246 /* Define a good bhabha calibration value. This is the
247 uncertainty on the calibration constant (e.g. fit mean),
248 not the gaussian width of the timing distribution for
249 that crystal (i.e. resolution).
250
251 Uncertainty stored as ticks so converted to ns for
252 more human readable cut.*/
253 if (bhabhaCalibUnc[ic] != 0
254 && fabs(bhabhaCalibUnc[ic])*TICKS_TO_NS < 2 and ic >= firstHighStatsCrysID and ic <= lastHighStatsCrysID) {
255 // The limits on the uncertainties are not fully optimized !!!!!!!!!!!!!!!!!!!!!!!!!!
256 // Tighten the uncertainty cut after introduction of bhabha gamma calibration. Perhaps checking if the
257 // value is negative as that flags poor fits / the overall hist mean was used. In these cases,
258 // the bhabha gamma calibration should be used (if it has good stats) but until that calibration is
259 // properly made (not all zeros) then the bhabha calibration should be used instead as the only
260 // other option is the cosmic calibration.
261 bhabhaCalibGoodQuality[ic] = true ;
262 }
263 /* Define a good radiative bhabha calibration value, which
264 should be looser than the bhabha requirements since
265 the radiative bhabha calibration is the backup choice.
266 If the radiative bhabha calibration is not good then
267 we resort to using the cosmic calibration so the
268 radiative bhabha requirements should be fairly loose.
269
270 Uncertainty stored as ticks so converted to ns for
271 more human readable cut.*/
272 if (bhabhaGammaCalibUnc[ic] != 0
273 && fabs(bhabhaGammaCalibUnc[ic])*TICKS_TO_NS <
274 3.5) { // The limits on the uncertainties are not fully optimized !!!!!!!!!!!!!!!!!!!!!!!!!!
275 bhabhaGammaCalibGoodQuality[ic] = true ;
276 }
277 }
278
279
280 /* Loop over all crystals and shift the cosmic crystal calibration by
281 the crate calibration because the cosmic calibration was made
282 assuming the crate calibration is 0.*/
283
284 vector<float> crateCalibShort(m_numCrates);
285 vector<float> cosmicCalibShifted = cosmicCalib;
286 vector<float> cosmicCalibShiftedUnc = cosmicCalibUnc; // Do not modify uncertainty?
287 for (int ic = 0; ic < m_numCrystals; ic++) {
288 cosmicCalibShifted[ic] -= crateCalib[ic];
289 int crate_id_from_crystal = crystalMapper->getCrateID(ic + 1);
290 crateCalibShort[crate_id_from_crystal - 1] = crateCalib[ic];
291 }
292
293 for (int icrate = 0; icrate < m_numCrates; icrate++) {
294 B2INFO("crate time calibration for crate " <<
295 icrate + 1 << " = " << crateCalibShort[icrate]);
296 }
297
298
299 /* Keep track of the mean value of the crystal calibration constants
300 for each crate. Exclude crystals with bad quality or that have
301 a value of 0 (except reference crystals). */
302 vector<float> meanGoodCrystalCalibPerCrate_bhabha(m_numCrates, 0);
303 vector<float> meanGoodCrystalCalibPerCrate_cosmic(m_numCrates, 0);
304
305 /* Start num entries at 1 because we will skip all 0s but include
306 the reference crystal (ts=0) by just increasing the counter.
307 We only need a counter for the bhabha events since we want to
308 get the same sample of crystals for both the bhabha and cosmic
309 calibrations.*/
310 vector<short> numGoodCrystalCalibPerCrate_bhabha(m_numCrates, 1);
311
312
313 /* Loop over all crystals and save the crystal calibration information
314 for each crate. */
315 for (int ic_base1 = 1; ic_base1 <= m_numCrystals; ic_base1++) {
316 int crate_id_from_crystal = crystalMapper->getCrateID(ic_base1);
317
318 if (!((bhabhaCalib[ic_base1 - 1] == 0) || (! bhabhaCalibGoodQuality[ic_base1 - 1]))) {
319 meanGoodCrystalCalibPerCrate_bhabha[crate_id_from_crystal - 1] += bhabhaCalib[ic_base1 - 1];
320 meanGoodCrystalCalibPerCrate_cosmic[crate_id_from_crystal - 1] += cosmicCalibShifted[ic_base1 - 1];
321 numGoodCrystalCalibPerCrate_bhabha[crate_id_from_crystal - 1]++ ;
322 }
323 }
324
325 /* Complete the calculation of the mean by dividing the sum by the number of entries */
326 for (int icrate = 0; icrate < m_numCrates; icrate++) {
327 meanGoodCrystalCalibPerCrate_bhabha[icrate] /= numGoodCrystalCalibPerCrate_bhabha[icrate] ;
328 meanGoodCrystalCalibPerCrate_cosmic[icrate] /= numGoodCrystalCalibPerCrate_bhabha[icrate] ;
329 B2INFO("Mean bhabha crystal calibration for crate " << icrate + 1 << " = " << meanGoodCrystalCalibPerCrate_bhabha[icrate]);
330 B2INFO("Mean cosmic crystal calibration for crate " << icrate + 1 << " = " << meanGoodCrystalCalibPerCrate_cosmic[icrate]);
331 B2INFO("Number of good crystal calibrations for crate" << icrate + 1 << " = " << numGoodCrystalCalibPerCrate_bhabha[icrate]);
332 }
333
334
336
337 /* Loop over all crystals and correct the cosmic calibration by the cosmic calibration
338 for each crate by the average difference to the bhabha calibration. */
339 for (int ic_base1 = 1; ic_base1 <= m_numCrystals; ic_base1++) {
340 int crate_id_from_crystal = crystalMapper->getCrateID(ic_base1);
341 cosmicCalibShifted[ic_base1 - 1] += meanGoodCrystalCalibPerCrate_bhabha[crate_id_from_crystal - 1] -
342 meanGoodCrystalCalibPerCrate_cosmic[crate_id_from_crystal - 1] ;
343 }
344
345
346 //------------------------------------------------------------------------
354
355
356 vector<float> newCalib(m_numCrystals);
357 vector<float> newCalibUnc(m_numCrystals);
358
359 vector<float> newBhabhaMinusCustomPrevCalib__cid(m_numCrystals);
360 vector<float> newBhabhaMinusCustomPrevBhabhaCalib__cid(m_numCrystals);
361 vector<float> newBhabhaMinusCustomPrevCalib;
362 vector<float> newBhabhaMinusCustomPrevBhabhaCalib;
363
364
365 // Loop over each crystal we want to check
366 for (int ic = 0; ic < m_numCrystals; ic++) {
367 B2DEBUG(29, "Merging crystal " << ic + 1);
368 int crate_id_from_crystal = crystalMapper->getCrateID(ic + 1);
369
370 // Determine if the current crystal is a reference crystal
371 bool isRefCrys = false ;
372 for (int icrate = 0; icrate < m_numCrates; icrate++) {
373 if (ic + 1 == refCrystalPerCrate[icrate]) {
374 isRefCrys = true;
375 B2INFO("Crystal " << ic + 1 << " is a reference crystal");
376 break;
377 }
378 B2DEBUG(29, "Checked reference crystal for crate " << icrate + 1);
379 }
380 B2DEBUG(29, "Checked ref crystal");
381
382 string whichCalibUsed = "bhabha";
383
384 // By default set the new calibration to the bhabha calibration
385 newCalib[ic] = bhabhaCalib[ic];
386 newCalibUnc[ic] = fabs(bhabhaCalibUnc[ic]);
387
388 double newMinusMerged ;
389 double newMinusBhabha ;
390
391
392 /* If the crystal is not a reference crystal and there is no bhabha
393 calib for that crystal then use a different calibration. If the
394 crystal is not a reference crystal and the crystal has a bad bhabha
395 crystal calibration uncertainty. */
396 if ((!isRefCrys) &&
397 ((bhabhaCalib[ic] == 0) || (! bhabhaCalibGoodQuality[ic]))) {
398
399 /* If there is a radiative bhabha calibration for this crystal then
400 use it otherwise use the cosmic calibration */
401 if (bhabhaGammaCalib[ic] != 0 || bhabhaGammaCalibGoodQuality[ic]) {
402 newCalib[ic] = bhabhaGammaCalib[ic] ;
403 newCalibUnc[ic] = fabs(bhabhaGammaCalibUnc[ic]);
404 whichCalibUsed = "bhabhaGamma";
405 } else {
406 newCalib[ic] = cosmicCalibShifted[ic] ;
407 newCalibUnc[ic] = cosmicCalibShiftedUnc[ic];
408 whichCalibUsed = "cosmic";
409 }
410 } else {
411 newMinusMerged = (newCalib[ic] - prevValuesCrys[ic]) * TICKS_TO_NS;
412 newMinusBhabha = (newCalib[ic] - prevBhabhaValuesCrys[ic]) * TICKS_TO_NS;
413
414 newBhabhaMinusCustomPrevCalib__cid[ic] = newMinusMerged;
415 newBhabhaMinusCustomPrevBhabhaCalib__cid[ic] = newMinusBhabha;
416 newBhabhaMinusCustomPrevCalib.push_back(newMinusMerged);
417 newBhabhaMinusCustomPrevBhabhaCalib.push_back(newMinusBhabha);
418 }
419
420 newMinusMerged = (newCalib[ic] - prevValuesCrys[ic]) * TICKS_TO_NS;
421 newMinusBhabha = (newCalib[ic] - prevBhabhaValuesCrys[ic]) * TICKS_TO_NS;
422
423
424 B2INFO("Crystal " << ic + 1 << ", crate " << crate_id_from_crystal <<
425 "::: bhabha = " << bhabhaCalib[ic] << "+-" << bhabhaCalibUnc[ic] <<
426 " ticks, rad bhabha = " << bhabhaGammaCalib[ic] << "+-" << bhabhaGammaCalibUnc[ic] <<
427 " ticks, cosmic UNshifted = " << cosmicCalib[ic] << "+-" << cosmicCalibUnc[ic] <<
428 " ticks, cosmic shifted = " << cosmicCalibShifted[ic] << "+-" << cosmicCalibShiftedUnc[ic] <<
429 " ticks. ||| New calib = " << newCalib[ic] << " ticks, selected " << whichCalibUsed);
430 B2INFO(" Crystal " << ic + 1 << ", pre calib ts = " << prevValuesCrys[ic] <<
431 ", pre calib bhabha ts = " << prevBhabhaValuesCrys[ic] <<
432 " ticks ||| new - pre calib ts = " << newMinusMerged <<
433 ", new - pre calib bhabha ts = " << newMinusBhabha << " ns");
434 } // end of setting new calibration for each crystal
435
436
437
438 //------------------------------------------------------------------------
439 //..Histograms of calibrations
440
441 // Just in case, we remember the current TDirectory so we can return to it
442 TDirectory* executeDir = gDirectory;
443
444 TString fname = debugFilename;
445 TFile hfile(fname, "recreate");
446
447 TString htitle = "ECLCrystalTimeOffsetBhabha;cellID;Bhabha ts values [ticks]";
448 TH1F* bhabhaPayload = new TH1F("bhabhaPayload", htitle, m_numCrystals, 1, 8737);
449
450 htitle = "ECLCrystalTimeOffsetBhabhaGamma;cellID;Radiative bhabha ts values [ticks]";
451 TH1F* bhabhaGammaPayload = new TH1F("bhabhaGammaPayload", htitle, m_numCrystals, 1, 8737);
452
453 htitle = "ECLCrystalTimeOffsetCosmic : unshifted;cellID;Unshifted cosmic ts values [ticks]";
454 TH1F* cosmicPayload = new TH1F("cosmicUnshiftedPayload", htitle, m_numCrystals, 1, 8737);
455
456 htitle = "ECLCrystalTimeOffsetCosmic : shifted;cellID;Shifted cosmic ts values [ticks]";
457 TH1F* cosmicShiftedPayload = new TH1F("cosmicShiftedPayload", htitle, m_numCrystals, 1, 8737);
458
459 htitle = "New ECLCrystalTimeOffset;cellID;New (merged) ts values [ticks]";
460 TH1F* newPayload = new TH1F("newPayload", htitle, m_numCrystals, 1, 8737);
461
462
463 htitle = "ECLCrystalTimeOffsetBhabha : 'pre-calib' values;cellID;Pre-calibration bhabha ts values [ticks]";
464 TH1F* tsCustomPrevBhabha_payload = new TH1F("tsCustomPrevBhabha_payload", htitle, m_numCrystals, 1, 8737);
465
466 htitle = "ECLCrystalTimeOffset : 'pre-calib' values;cellID;Pre-calibration merged ts values [ticks]";
467 TH1F* tsCustomPrev_payload = new TH1F("tsCustomPrev_payload", htitle, m_numCrystals, 1, 8737);
468
469
470
471 htitle = "-Only for crystals where the new bhabha ts value is used-;cellID;ts(new | bhabha) - ts(old = 'pre-calib' | merged) [ns]";
472 TH1F* newBhabhaMinusCustomPrev__cid = new TH1F("newBhabhaMinusCustomPrev__cid", htitle, m_numCrystals, 1, 8737);
473
474 htitle = "-Only for crystals where the new bhabha ts value is used-;cellID;ts(new | bhabha) - ts(old = 'pre-calib' | bhabha) [ns]";
475 TH1F* newBhabhaMinusCustomPrevBhabha__cid = new TH1F("newBhabhaMinusCustomPrevBhabha__cid", htitle, m_numCrystals, 1, 8737);
476
477 htitle = "-Only for crystals where the new bhabha ts value is used-;ts(new | bhabha) - ts(old = 'pre-calib' | merged) [ns];Number of crystals";
478 auto tsNewBhabha_MINUS_tsCustomPrev = new TH1F("TsNewBhabha_MINUS_TsCustomPrev", htitle, 285, -69.5801, 69.5801);
479
480 htitle = "-Only for crystals where the new bhabha ts value is used-;ts(new | bhabha) - ts(old = 'pre-calib' | bhabha) [ns];Number of crystals";
481 auto tsNewBhabha_MINUS_tsCustomPrevBhabha = new TH1F("TsNewBhabha_MINUS_TsCustomPrevBhabha", htitle, 285, -69.5801, 69.5801);
482
483
484 for (int cellID = 1; cellID <= m_numCrystals; cellID++) {
485 bhabhaPayload->SetBinContent(cellID, bhabhaCalib[cellID - 1]);
486 bhabhaPayload->SetBinError(cellID, fabs(bhabhaCalibUnc[cellID - 1]));
487
488 bhabhaGammaPayload->SetBinContent(cellID, bhabhaGammaCalib[cellID - 1]);
489 bhabhaGammaPayload->SetBinError(cellID, fabs(bhabhaGammaCalibUnc[cellID - 1]));
490
491 cosmicPayload->SetBinContent(cellID, cosmicCalib[cellID - 1]);
492 cosmicPayload->SetBinError(cellID, cosmicCalibUnc[cellID - 1]);
493
494 cosmicShiftedPayload->SetBinContent(cellID, cosmicCalibShifted[cellID - 1]);
495 cosmicShiftedPayload->SetBinError(cellID, cosmicCalibShiftedUnc[cellID - 1]);
496
497 newPayload->SetBinContent(cellID, newCalib[cellID - 1]);
498 newPayload->SetBinError(cellID, newCalibUnc[cellID - 1]);
499
500 // Comparisons of change in ts
502 newBhabhaMinusCustomPrev__cid->SetBinContent(cellID, newBhabhaMinusCustomPrevCalib__cid[cellID - 1]);
503 newBhabhaMinusCustomPrev__cid->SetBinError(cellID, 0);
504
505 newBhabhaMinusCustomPrevBhabha__cid->SetBinContent(cellID, newBhabhaMinusCustomPrevBhabhaCalib__cid[cellID - 1]);
506 newBhabhaMinusCustomPrevBhabha__cid->SetBinError(cellID, 0);
507
508
509 tsCustomPrev_payload->SetBinContent(cellID, prevValuesCrys[cellID - 1]);
510 tsCustomPrev_payload->SetBinError(cellID, prevValuesCrysUnc[cellID - 1]);
511
512 tsCustomPrevBhabha_payload->SetBinContent(cellID, prevBhabhaValuesCrys[cellID - 1]);
513 tsCustomPrevBhabha_payload->SetBinError(cellID, fabs(prevBhabhaValuesCrysUnc[cellID - 1]));
514 }
515 }
516
518 for (long unsigned int ib = 0; ib < newBhabhaMinusCustomPrevCalib.size(); ib++) {
519 tsNewBhabha_MINUS_tsCustomPrev->Fill(newBhabhaMinusCustomPrevCalib[ib]);
520 }
521
522 for (long unsigned int ib = 0; ib < newBhabhaMinusCustomPrevBhabhaCalib.size(); ib++) {
523 tsNewBhabha_MINUS_tsCustomPrevBhabha->Fill(newBhabhaMinusCustomPrevBhabhaCalib[ib]);
524 }
525 }
526
527
528 hfile.cd();
529 hfile.Write();
530 hfile.Close();
531 B2INFO("Debugging histograms written to " << fname);
532 // Go back to original TDirectory
533 executeDir->cd();
534
535
536 /* Re-save the new bhabha calibrations to a payload. The bhabha calibrations have NOT
537 been changed; however, the best way of controlling which payloads get get uploaded to
538 the GT as part of the prommp calibrations is to save a second copy in this calibration
539 directory since we don't want to save all the payloads from the previous directory.
540 See the "<calibration>.save_payloads = <True/False>" code in the airflow steering file.*/
541 ECLCrystalCalib* bhabhaCalibCopy = new ECLCrystalCalib();
542 bhabhaCalibCopy->setCalibVector(bhabhaCalib, bhabhaCalibUnc);
543 saveCalibration(bhabhaCalibCopy, "ECLCrystalTimeOffsetBhabha");
544
545 // Save the new merged calibrations to a payload
546 ECLCrystalCalib* newCrystalTimes = new ECLCrystalCalib();
547 newCrystalTimes->setCalibVector(newCalib, newCalibUnc);
548 saveCalibration(newCrystalTimes, "ECLCrystalTimeOffset");
549 return c_OK;
550}
void saveCalibration(TClonesArray *data, const std::string &name)
Store DBArray payload with given name with default IOV.
static 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.
CalibrationAlgorithm(const std::string &collectorModuleName)
Constructor - sets the prefix for collected objects (won't be accesses until execute(....
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