10#include <ecl/calibration/eclMergingCrystalEAlgorithm.h>
13#include <ecl/dbobjects/ECLCrystalCalib.h>
16#include <TDirectory.h>
24using namespace Calibration;
28 m_existingGammaGamma(
"ECLCrystalEnergyGammaGamma"), m_existingMuMu(
"ECLCrystalEnergyMuMu"),
29 m_existing5x5(
"ECLCrystalEnergyee5x5"), m_existing(m_payloadName)
32 "Perform energy calibration of ecl crystals by combining previous values from the DB for different calibrations."
42 ExpRun chosenRun = runs.front();
43 B2INFO(
"merging using the ExpRun (" << chosenRun.second <<
"," << chosenRun.first <<
")");
49 bool allObjectsFound =
true;
52 allObjectsFound =
false;
53 B2ERROR(
"No valid DBObject found for 'ECLCrystalEnergyGammaGamma'");
56 allObjectsFound =
false;
57 B2ERROR(
"No valid DBObject found for 'ECLCrystalEnergyMuMu'");
60 allObjectsFound =
false;
61 B2ERROR(
"No valid DBObject found for 'ECLCrystalEnergyee5x5'");
64 allObjectsFound =
false;
65 B2ERROR(
"No valid DBObject found for 'ECLCrystalEnergy'");
68 if (allObjectsFound) {
69 B2INFO(
"Valid objects found for both 'ECLCrystalEnergy' and 'ECLCrystalEnergyGammaGamma'");
71 B2INFO(
"Exiting with failure");
80 vector<float> existingCalib =
m_existing->getCalibVector();
81 vector<float> existingCalibUnc =
m_existing->getCalibUncVector();
90 if (gammaGammaCalib[ic] > 0.) {
91 newCalib[ic] = gammaGammaCalib[ic];
92 newCalibUnc[ic] = gammaGammaCalibUnc[ic];
94 newCalib[ic] = existingCalib[ic];
95 newCalibUnc[ic] = existingCalibUnc[ic];
101 for (
int ic = 0; ic < 9000; ic += 1000) {
102 B2INFO(ic + 1 <<
" " << existingCalib[ic] <<
" " << existingCalibUnc[ic] <<
" "
103 << gammaGammaCalib[ic] <<
" " << gammaGammaCalibUnc[ic] <<
" "
104 << newCalib[ic] <<
" " << newCalibUnc[ic]);
111 TDirectory* executeDir = gDirectory;
115 TFile hfile(fname,
"recreate");
118 htitle +=
" existing values;cellID";
119 TH1F* existingPayload =
new TH1F(
"existingPayload", htitle,
m_numCrystals, 1, 8737);
122 htitle +=
" new values;cellID";
123 TH1F* newPayload =
new TH1F(
"newPayload", htitle,
m_numCrystals, 1, 8737);
126 htitle +=
" ratio new/old;cellID";
127 TH1F* payloadRatioVsCellID =
new TH1F(
"payloadRatioVsCellID", htitle,
m_numCrystals, 1, 8737);
130 htitle +=
" ratio new/old";
131 TH1F* payloadRatio =
new TH1F(
"payloadRatio", htitle, 200, 0.95, 1.05);
134 existingPayload->SetBinContent(cellID, existingCalib[cellID - 1]);
135 existingPayload->SetBinError(cellID, existingCalibUnc[cellID - 1]);
137 newPayload->SetBinContent(cellID, newCalib[cellID - 1]);
138 newPayload->SetBinError(cellID, newCalibUnc[cellID - 1]);
142 if (abs(existingCalib[cellID - 1]) > 1.0e-12) {
143 ratio = newCalib[cellID - 1] / existingCalib[cellID - 1];
144 float rUnc0 = existingCalibUnc[cellID - 1] / existingCalib[cellID - 1];
146 if (abs(newCalib[cellID - 1]) > 1.0e-12) {rUnc1 = newCalibUnc[cellID - 1] / newCalib[cellID - 1];}
147 ratioUnc = ratio *
sqrt(rUnc0 * rUnc0 + rUnc1 * rUnc1);
150 payloadRatioVsCellID->SetBinContent(cellID, ratio);
151 payloadRatioVsCellID->SetBinError(cellID, ratioUnc);
153 payloadRatio->Fill(ratio);
158 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)
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.
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.
eclMergingCrystalEAlgorithm()
..Constructor
virtual EResult calibrate() override
..Run algorithm
DBObjPtr< ECLCrystalCalib > m_existingMuMu
ECLCrystalEnergyMuMu payloads that we want to read from the DB.
double sqrt(double a)
sqrt for double
Abstract base class for different kinds of events.
Struct containing exp number and run number.