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 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
334
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 //..For each crate, get the average Bhabha calibration using only crystals
345 // with good Bhabha calibrations and cellID [673, 8160], the region with
346 // consistently high statistics.
347 const int firstHiStatCellID = 673;
348 const int lastHiStatCellID = 8160;
349 int nGoodBhabhaPerCrate[m_numCrates] = {};
350 double averageBhabhaCalibPerCrate[m_numCrates] = {};
351
352 //..Find the good crystals and sum
353 for (int cellID = firstHiStatCellID; cellID <= lastHiStatCellID; cellID++) {
354 int crysID = cellID - 1;
355 int crateID = crystalMapper->getCrateID(cellID);
356 if (bhabhaCalibGoodQuality[crysID]) {
357 nGoodBhabhaPerCrate[crateID - 1]++;
358 averageBhabhaCalibPerCrate[crateID - 1] += bhabhaCalib[crysID];
359 }
360 }
361
362 //..Crate average
363 for (int crateID = 1; crateID <= m_numCrates; crateID++) {
364 if (nGoodBhabhaPerCrate[crateID - 1] != 0) {
365 averageBhabhaCalibPerCrate[crateID - 1] /= nGoodBhabhaPerCrate[crateID - 1];
366 }
367 B2INFO("crateID " << crateID << " nGood " << nGoodBhabhaPerCrate[crateID - 1] << " average Bhabha calib " <<
368 averageBhabhaCalibPerCrate[crateID - 1]);
369 }
370
371
372 //------------------------------------------------------------------------
380
381
382 vector<float> newCalib(m_numCrystals);
383 vector<float> newCalibUnc(m_numCrystals);
384
385 vector<float> newBhabhaMinusCustomPrevCalib__cid(m_numCrystals);
386 vector<float> newBhabhaMinusCustomPrevBhabhaCalib__cid(m_numCrystals);
387 vector<float> newBhabhaMinusCustomPrevCalib;
388 vector<float> newBhabhaMinusCustomPrevBhabhaCalib;
389
390
391 // Loop over each crystal we want to check
392 for (int ic = 0; ic < m_numCrystals; ic++) {
393 B2DEBUG(29, "Merging crystal " << ic + 1);
394 int crate_id_from_crystal = crystalMapper->getCrateID(ic + 1);
395
396 // Determine if the current crystal is a reference crystal
397 bool isRefCrys = false ;
398 for (int icrate = 0; icrate < m_numCrates; icrate++) {
399 if (ic + 1 == refCrystalPerCrate[icrate]) {
400 isRefCrys = true;
401 B2INFO("Crystal " << ic + 1 << " is a reference crystal");
402 break;
403 }
404 B2DEBUG(29, "Checked reference crystal for crate " << icrate + 1);
405 }
406 B2DEBUG(29, "Checked ref crystal");
407
408 string whichCalibUsed = "bhabha";
409
410 // By default set the new calibration to the bhabha calibration
411 newCalib[ic] = bhabhaCalib[ic];
412 newCalibUnc[ic] = fabs(bhabhaCalibUnc[ic]);
413
414 double newMinusMerged ;
415 double newMinusBhabha ;
416
417
418 /* If the crystal is not a reference crystal and there is no bhabha
419 calib for that crystal then use a different calibration. If the
420 crystal is not a reference crystal and the crystal has a bad bhabha
421 crystal calibration uncertainty. */
422 if ((!isRefCrys) &&
423 ((bhabhaCalib[ic] == 0) || (! bhabhaCalibGoodQuality[ic]))) {
424
425 /* If there is a radiative bhabha calibration for this crystal then
426 use it otherwise use the cosmic calibration */
427 if (bhabhaGammaCalib[ic] != 0 || bhabhaGammaCalibGoodQuality[ic]) {
428 newCalib[ic] = bhabhaGammaCalib[ic] + averageBhabhaCalibPerCrate[crate_id_from_crystal - 1];
429 newCalibUnc[ic] = fabs(bhabhaGammaCalibUnc[ic]);
430 whichCalibUsed = "bhabhaGamma";
431 } else {
432 newCalib[ic] = cosmicCalibShifted[ic] ;
433 newCalibUnc[ic] = cosmicCalibShiftedUnc[ic];
434 whichCalibUsed = "cosmic";
435 }
436 } else {
437 newMinusMerged = (newCalib[ic] - prevValuesCrys[ic]) * TICKS_TO_NS;
438 newMinusBhabha = (newCalib[ic] - prevBhabhaValuesCrys[ic]) * TICKS_TO_NS;
439
440 newBhabhaMinusCustomPrevCalib__cid[ic] = newMinusMerged;
441 newBhabhaMinusCustomPrevBhabhaCalib__cid[ic] = newMinusBhabha;
442 newBhabhaMinusCustomPrevCalib.push_back(newMinusMerged);
443 newBhabhaMinusCustomPrevBhabhaCalib.push_back(newMinusBhabha);
444 }
445
446 newMinusMerged = (newCalib[ic] - prevValuesCrys[ic]) * TICKS_TO_NS;
447 newMinusBhabha = (newCalib[ic] - prevBhabhaValuesCrys[ic]) * TICKS_TO_NS;
448
449
450 B2INFO("Crystal " << ic + 1 << ", crate " << crate_id_from_crystal <<
451 "::: bhabha = " << bhabhaCalib[ic] << "+-" << bhabhaCalibUnc[ic] <<
452 " ticks, rad bhabha = " << bhabhaGammaCalib[ic] << "+-" << bhabhaGammaCalibUnc[ic] <<
453 " ticks, cosmic UNshifted = " << cosmicCalib[ic] << "+-" << cosmicCalibUnc[ic] <<
454 " ticks, cosmic shifted = " << cosmicCalibShifted[ic] << "+-" << cosmicCalibShiftedUnc[ic] <<
455 " ticks. ||| New calib = " << newCalib[ic] << " ticks, selected " << whichCalibUsed);
456 B2INFO(" Crystal " << ic + 1 << ", pre calib ts = " << prevValuesCrys[ic] <<
457 ", pre calib bhabha ts = " << prevBhabhaValuesCrys[ic] <<
458 " ticks ||| new - pre calib ts = " << newMinusMerged <<
459 ", new - pre calib bhabha ts = " << newMinusBhabha << " ns");
460 } // end of setting new calibration for each crystal
461
462
463
464 //------------------------------------------------------------------------
465 //..Histograms of calibrations
466
467 // Just in case, we remember the current TDirectory so we can return to it
468 TDirectory* executeDir = gDirectory;
469
470 TString fname = debugFilename;
471 TFile hfile(fname, "recreate");
472
473 TString htitle = "ECLCrystalTimeOffsetBhabha;cellID;Bhabha ts values [ticks]";
474 TH1F* bhabhaPayload = new TH1F("bhabhaPayload", htitle, m_numCrystals, 1, 8737);
475
476 htitle = "ECLCrystalTimeOffsetBhabhaGamma;cellID;Radiative bhabha ts values [ticks]";
477 TH1F* bhabhaGammaPayload = new TH1F("bhabhaGammaPayload", htitle, m_numCrystals, 1, 8737);
478
479 htitle = "ECLCrystalTimeOffsetCosmic : unshifted;cellID;Unshifted cosmic ts values [ticks]";
480 TH1F* cosmicPayload = new TH1F("cosmicUnshiftedPayload", htitle, m_numCrystals, 1, 8737);
481
482 htitle = "ECLCrystalTimeOffsetCosmic : shifted;cellID;Shifted cosmic ts values [ticks]";
483 TH1F* cosmicShiftedPayload = new TH1F("cosmicShiftedPayload", htitle, m_numCrystals, 1, 8737);
484
485 htitle = "New ECLCrystalTimeOffset;cellID;New (merged) ts values [ticks]";
486 TH1F* newPayload = new TH1F("newPayload", htitle, m_numCrystals, 1, 8737);
487
488
489 htitle = "ECLCrystalTimeOffsetBhabha : 'pre-calib' values;cellID;Pre-calibration bhabha ts values [ticks]";
490 TH1F* tsCustomPrevBhabha_payload = new TH1F("tsCustomPrevBhabha_payload", htitle, m_numCrystals, 1, 8737);
491
492 htitle = "ECLCrystalTimeOffset : 'pre-calib' values;cellID;Pre-calibration merged ts values [ticks]";
493 TH1F* tsCustomPrev_payload = new TH1F("tsCustomPrev_payload", htitle, m_numCrystals, 1, 8737);
494
495
496
497 htitle = "-Only for crystals where the new bhabha ts value is used-;cellID;ts(new | bhabha) - ts(old = 'pre-calib' | merged) [ns]";
498 TH1F* newBhabhaMinusCustomPrev__cid = new TH1F("newBhabhaMinusCustomPrev__cid", htitle, m_numCrystals, 1, 8737);
499
500 htitle = "-Only for crystals where the new bhabha ts value is used-;cellID;ts(new | bhabha) - ts(old = 'pre-calib' | bhabha) [ns]";
501 TH1F* newBhabhaMinusCustomPrevBhabha__cid = new TH1F("newBhabhaMinusCustomPrevBhabha__cid", htitle, m_numCrystals, 1, 8737);
502
503 htitle = "-Only for crystals where the new bhabha ts value is used-;ts(new | bhabha) - ts(old = 'pre-calib' | merged) [ns];Number of crystals";
504 auto tsNewBhabha_MINUS_tsCustomPrev = new TH1F("TsNewBhabha_MINUS_TsCustomPrev", htitle, 285, -69.5801, 69.5801);
505
506 htitle = "-Only for crystals where the new bhabha ts value is used-;ts(new | bhabha) - ts(old = 'pre-calib' | bhabha) [ns];Number of crystals";
507 auto tsNewBhabha_MINUS_tsCustomPrevBhabha = new TH1F("TsNewBhabha_MINUS_TsCustomPrevBhabha", htitle, 285, -69.5801, 69.5801);
508
509
510 for (int cellID = 1; cellID <= m_numCrystals; cellID++) {
511 bhabhaPayload->SetBinContent(cellID, bhabhaCalib[cellID - 1]);
512 bhabhaPayload->SetBinError(cellID, fabs(bhabhaCalibUnc[cellID - 1]));
513
514 bhabhaGammaPayload->SetBinContent(cellID, bhabhaGammaCalib[cellID - 1]);
515 bhabhaGammaPayload->SetBinError(cellID, fabs(bhabhaGammaCalibUnc[cellID - 1]));
516
517 cosmicPayload->SetBinContent(cellID, cosmicCalib[cellID - 1]);
518 cosmicPayload->SetBinError(cellID, cosmicCalibUnc[cellID - 1]);
519
520 cosmicShiftedPayload->SetBinContent(cellID, cosmicCalibShifted[cellID - 1]);
521 cosmicShiftedPayload->SetBinError(cellID, cosmicCalibShiftedUnc[cellID - 1]);
522
523 newPayload->SetBinContent(cellID, newCalib[cellID - 1]);
524 newPayload->SetBinError(cellID, newCalibUnc[cellID - 1]);
525
526 // Comparisons of change in ts
528 newBhabhaMinusCustomPrev__cid->SetBinContent(cellID, newBhabhaMinusCustomPrevCalib__cid[cellID - 1]);
529 newBhabhaMinusCustomPrev__cid->SetBinError(cellID, 0);
530
531 newBhabhaMinusCustomPrevBhabha__cid->SetBinContent(cellID, newBhabhaMinusCustomPrevBhabhaCalib__cid[cellID - 1]);
532 newBhabhaMinusCustomPrevBhabha__cid->SetBinError(cellID, 0);
533
534
535 tsCustomPrev_payload->SetBinContent(cellID, prevValuesCrys[cellID - 1]);
536 tsCustomPrev_payload->SetBinError(cellID, prevValuesCrysUnc[cellID - 1]);
537
538 tsCustomPrevBhabha_payload->SetBinContent(cellID, prevBhabhaValuesCrys[cellID - 1]);
539 tsCustomPrevBhabha_payload->SetBinError(cellID, fabs(prevBhabhaValuesCrysUnc[cellID - 1]));
540 }
541 }
542
544 for (long unsigned int ib = 0; ib < newBhabhaMinusCustomPrevCalib.size(); ib++) {
545 tsNewBhabha_MINUS_tsCustomPrev->Fill(newBhabhaMinusCustomPrevCalib[ib]);
546 }
547
548 for (long unsigned int ib = 0; ib < newBhabhaMinusCustomPrevBhabhaCalib.size(); ib++) {
549 tsNewBhabha_MINUS_tsCustomPrevBhabha->Fill(newBhabhaMinusCustomPrevBhabhaCalib[ib]);
550 }
551 }
552
553
554 hfile.cd();
555 hfile.Write();
556 hfile.Close();
557 B2INFO("Debugging histograms written to " << fname);
558 // Go back to original TDirectory
559 executeDir->cd();
560
561
562 /* Re-save the new bhabha calibrations to a payload. The bhabha calibrations have NOT
563 been changed; however, the best way of controling which payloads get get uploaded to
564 the GT as part of the prommp calibrations is to save a second copy in this calibration
565 directory since we don't want to save all the payloads from the previous directory.
566 See the "<calibration>.save_payloads = <True/False>" code in the airflow steering file.*/
567 ECLCrystalCalib* bhabhaCalibCopy = new ECLCrystalCalib();
568 bhabhaCalibCopy->setCalibVector(bhabhaCalib, bhabhaCalibUnc);
569 saveCalibration(bhabhaCalibCopy, "ECLCrystalTimeOffsetBhabha");
570
571 // Save the new merged calibrations to a payload
572 ECLCrystalCalib* newCrystalTimes = new ECLCrystalCalib();
573 newCrystalTimes->setCalibVector(newCalib, newCalibUnc);
574 saveCalibration(newCrystalTimes, "ECLCrystalTimeOffset");
575 return c_OK;
576}
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