8 #include <ecl/calibration/eclMergingCrystalEAlgorithm.h>
9 #include <ecl/dbobjects/ECLCrystalCalib.h>
13 #include "TDirectory.h"
18 using namespace Calibration;
22 m_existingGammaGamma(
"ECLCrystalEnergyGammaGamma"), m_existingMuMu(
"ECLCrystalEnergyMuMu"),
23 m_existing5x5(
"ECLCrystalEnergyee5x5"), m_existing(m_payloadName)
26 "Perform energy calibration of ecl crystals by combining previous values from the DB for different calibrations."
36 ExpRun chosenRun = runs.front();
37 B2INFO(
"merging using the ExpRun (" << chosenRun.second <<
"," << chosenRun.first <<
")");
43 bool allObjectsFound =
true;
46 allObjectsFound =
false;
47 B2ERROR(
"No valid DBObject found for 'ECLCrystalEnergyGammaGamma'");
50 allObjectsFound =
false;
51 B2ERROR(
"No valid DBObject found for 'ECLCrystalEnergyMuMu'");
54 allObjectsFound =
false;
55 B2ERROR(
"No valid DBObject found for 'ECLCrystalEnergyee5x5'");
58 allObjectsFound =
false;
59 B2ERROR(
"No valid DBObject found for 'ECLCrystalEnergy'");
62 if (allObjectsFound) {
63 B2INFO(
"Valid objects found for both 'ECLCrystalEnergy' and 'ECLCrystalEnergyGammaGamma'");
65 B2INFO(
"Exiting with failure");
74 vector<float> existingCalib =
m_existing->getCalibVector();
75 vector<float> existingCalibUnc =
m_existing->getCalibUncVector();
84 if (gammaGammaCalib[ic] > 0.) {
85 newCalib[ic] = gammaGammaCalib[ic];
86 newCalibUnc[ic] = gammaGammaCalibUnc[ic];
88 newCalib[ic] = existingCalib[ic];
89 newCalibUnc[ic] = existingCalibUnc[ic];
95 for (
int ic = 0; ic < 9000; ic += 1000) {
96 B2INFO(ic + 1 <<
" " << existingCalib[ic] <<
" " << existingCalibUnc[ic] <<
" "
97 << gammaGammaCalib[ic] <<
" " << gammaGammaCalibUnc[ic] <<
" "
98 << newCalib[ic] <<
" " << newCalibUnc[ic]);
105 TDirectory* executeDir = gDirectory;
109 TFile hfile(fname,
"recreate");
112 htitle +=
" existing values;cellID";
113 TH1F* existingPayload =
new TH1F(
"existingPayload", htitle,
m_numCrystals, 1, 8737);
116 htitle +=
" new values;cellID";
117 TH1F* newPayload =
new TH1F(
"newPayload", htitle,
m_numCrystals, 1, 8737);
120 htitle +=
" ratio new/old;cellID";
121 TH1F* payloadRatioVsCellID =
new TH1F(
"payloadRatioVsCellID", htitle,
m_numCrystals, 1, 8737);
124 htitle +=
" ratio new/old";
125 TH1F* payloadRatio =
new TH1F(
"payloadRatio", htitle, 200, 0.95, 1.05);
128 existingPayload->SetBinContent(cellID, existingCalib[cellID - 1]);
129 existingPayload->SetBinError(cellID, existingCalibUnc[cellID - 1]);
131 newPayload->SetBinContent(cellID, newCalib[cellID - 1]);
132 newPayload->SetBinError(cellID, newCalibUnc[cellID - 1]);
136 if (abs(existingCalib[cellID - 1]) > 1.0e-12) {
137 ratio = newCalib[cellID - 1] / existingCalib[cellID - 1];
138 float rUnc0 = existingCalibUnc[cellID - 1] / existingCalib[cellID - 1];
140 if (abs(newCalib[cellID - 1]) > 1.0e-12) {rUnc1 = newCalibUnc[cellID - 1] / newCalib[cellID - 1];}
141 ratioUnc = ratio * sqrt(rUnc0 * rUnc0 + rUnc1 * rUnc1);
144 payloadRatioVsCellID->SetBinContent(cellID, ratio);
145 payloadRatioVsCellID->SetBinError(cellID, ratioUnc);
147 payloadRatio->Fill(ratio);
152 B2INFO(
"Debugging histograms written to " << fname);
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)
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.
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.
DBObjPtr< ECLCrystalCalib > m_existing5x5
ECLCrystalEnergyee5x5 payloads that we want to read from the DB.
DBObjPtr< ECLCrystalCalib > m_existing
ECLCrystalEnergy payloads that we want to read from the DB.
const std::string m_payloadName
The output payload name.
DBObjPtr< ECLCrystalCalib > m_existingGammaGamma
ECLCrystalEnergyGammaGamma payloads that we want to read from the DB.
const int m_numCrystals
Number of Crystals expected.
virtual EResult calibrate() override
..Run algorithm
DBObjPtr< ECLCrystalCalib > m_existingMuMu
ECLCrystalEnergyMuMu payloads that we want to read from the DB.
Abstract base class for different kinds of events.
Struct containing exp number and run number.