10#include <ecl/dataobjects/ECLElementNumbers.h>
11#include <ecl/dbobjects/ECLCrystalCalib.h>
14#include <framework/database/Configuration.h>
15#include <framework/database/DBImportObjPtr.h>
16#include <framework/database/DBObjPtr.h>
17#include <framework/database/DBStore.h>
18#include <framework/dataobjects/EventMetaData.h>
19#include <framework/datastore/DataStore.h>
20#include <framework/datastore/StoreObjPtr.h>
33 void setupDatabase(
int exp,
int run,
int eventNr = 1)
52int main(
int argc,
char** argv)
56 if (argc < 3 || argc > 5) {
57 std::cout <<
"incorrect number of arguments for eclCrystalEnergy" << std::endl;
60 int experiment = std::stoi(argv[1]);
61 int run = std::stoi(argv[2]);
62 std::string gtName =
"ECL_energy_calibrations";
63 if (argc >= 4) {gtName = argv[3];}
64 bool writeOutput =
true;
65 if (argc == 5) {writeOutput = std::stoi(argv[4]);}
67 std::cout <<
"eclCrystalEnergy called with arguments exp = " << experiment <<
" run = " << run <<
" GT = " << gtName <<
68 " writeOutput = " << writeOutput << std::endl;
74 conf.prependGlobalTag(gtName);
75 conf.prependTestingPayloadLocation(
"localdb/database.txt");
82 setupDatabase(experiment, run);
86 std::vector<float> GammaGammaCalib;
87 std::vector<float> GammaGammaCalibUnc;
88 GammaGammaCalib = GammaGamma->getCalibVector();
89 GammaGammaCalibUnc = GammaGamma->getCalibUncVector();
91 std::vector<float> ExistingCalib;
92 std::vector<float> ExistingCalibUnc;
93 ExistingCalib = Existing->getCalibVector();
94 ExistingCalibUnc = Existing->getCalibUncVector();
99 std::vector<float> NewCalib;
100 std::vector<float> NewCalibUnc;
104 if (GammaGammaCalib[ic] > 0.) {
105 NewCalib[ic] = GammaGammaCalib[ic];
106 NewCalibUnc[ic] = GammaGammaCalibUnc[ic];
108 NewCalib[ic] = ExistingCalib[ic];
109 NewCalibUnc[ic] = ExistingCalibUnc[ic];
115 for (
int ic = 0; ic < 9000; ic += 1000) {
116 std::cout << ic + 1 <<
" " << ExistingCalib[ic] <<
" " << ExistingCalibUnc[ic] <<
" " << GammaGammaCalib[ic] <<
" " <<
117 GammaGammaCalibUnc[ic] <<
" " << NewCalib[ic] <<
" " << NewCalibUnc[ic] << std::endl;
122 TString payloadTitle =
"ECLCrystalEnergy";
124 payloadTitle += experiment;
127 TString fname = payloadTitle;
129 TFile hfile(fname,
"recreate");
131 TString htitle = payloadTitle;
132 htitle +=
" existing values;cellID";
135 htitle = payloadTitle;
136 htitle +=
" new values;cellID";
139 htitle = payloadTitle;
140 htitle +=
" ratio new/old;cellID";
143 htitle = payloadTitle;
144 htitle +=
" ratio new/old";
145 TH1F* payloadRatio =
new TH1F(
"payloadRatio", htitle, 200, 0.95, 1.05);
148 existingPayload->SetBinContent(cellID, ExistingCalib[cellID - 1]);
149 existingPayload->SetBinError(cellID, ExistingCalibUnc[cellID - 1]);
151 newPayload->SetBinContent(cellID, NewCalib[cellID - 1]);
152 newPayload->SetBinError(cellID, NewCalibUnc[cellID - 1]);
156 if (abs(ExistingCalib[cellID - 1]) > 1.0e-12) {
157 ratio = NewCalib[cellID - 1] / ExistingCalib[cellID - 1];
158 float rUnc0 = ExistingCalibUnc[cellID - 1] / ExistingCalib[cellID - 1];
160 if (abs(NewCalib[cellID - 1]) > 1.0e-12) {rUnc1 = NewCalibUnc[cellID - 1] / NewCalib[cellID - 1];}
161 ratioUnc = ratio *
sqrt(rUnc0 * rUnc0 + rUnc1 * rUnc1);
164 payloadRatioVsCellID->SetBinContent(cellID, ratio);
165 payloadRatioVsCellID->SetBinError(cellID, ratioUnc);
167 payloadRatio->Fill(ratio);
173 std::cout << std::endl <<
"Values written to " << fname << std::endl;
178 std::cout <<
"Creating importer" << std::endl;
180 importer.construct();
181 importer->setCalibVector(NewCalib, NewCalibUnc);
183 std::cout <<
"Successfully wrote payload ECLCrystalEnergy with iov " << experiment <<
"," << run <<
",-1,-1" << std::endl;
185 std::cout <<
"Payload not written to database" << std::endl;
static Configuration & getInstance()
Get a reference to the instance which will be used when the Database is initialized.
Class for importing a single object to the database.
Class for accessing objects in the database.
Singleton class to cache database objects.
static DataStore & Instance()
Instance of singleton Store.
void setInitializeActive(bool active)
Setter for m_initializeActive.
A class that describes the interval of experiments/runs for which an object in the database is valid.
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
Type-safe access to single objects in the data store.
bool construct(Args &&... params)
Construct an object of type T in this StoreObjPtr, using the provided constructor arguments.
static DBStore & Instance()
Instance of a singleton DBStore.
void updateEvent()
Updates all intra-run dependent objects.
void update()
Updates all objects that are outside their interval of validity.
double sqrt(double a)
sqrt for double
const int c_NCrystals
Number of crystals.
Abstract base class for different kinds of events.