9 #include <framework/database/DBImportObjPtr.h>
10 #include <framework/database/DBObjPtr.h>
11 #include <framework/database/DBStore.h>
12 #include <framework/datastore/StoreObjPtr.h>
13 #include <framework/datastore/DataStore.h>
14 #include <framework/dataobjects/EventMetaData.h>
15 #include <framework/database/Configuration.h>
16 #include <ecl/dbobjects/ECLCrystalCalib.h>
25 void setupDatabase(
int exp,
int run,
int eventNr = 1)
44 int main(
int argc,
char** argv)
48 if (argc < 3 || argc > 5) {
49 std::cout <<
"incorrect number of arguments for eclCrystalEnergy" << std::endl;
52 int experiment = std::stoi(argv[1]);
53 int run = std::stoi(argv[2]);
54 std::string gtName =
"ECL_energy_calibrations";
55 if (argc >= 4) {gtName = argv[3];}
56 bool writeOutput =
true;
57 if (argc == 5) {writeOutput = std::stoi(argv[4]);}
59 std::cout <<
"eclCrystalEnergy called with arguments exp = " << experiment <<
" run = " << run <<
" GT = " << gtName <<
60 " writeOutput = " << writeOutput << std::endl;
66 conf.prependGlobalTag(gtName);
67 conf.prependTestingPayloadLocation(
"localdb/database.txt");
74 setupDatabase(experiment, run);
78 std::vector<float> GammaGammaCalib;
79 std::vector<float> GammaGammaCalibUnc;
80 GammaGammaCalib = GammaGamma->getCalibVector();
81 GammaGammaCalibUnc = GammaGamma->getCalibUncVector();
83 std::vector<float> ExistingCalib;
84 std::vector<float> ExistingCalibUnc;
85 ExistingCalib = Existing->getCalibVector();
86 ExistingCalibUnc = Existing->getCalibUncVector();
91 std::vector<float> NewCalib;
92 std::vector<float> NewCalibUnc;
93 NewCalib.resize(8736);
94 NewCalibUnc.resize(8736);
95 for (
int ic = 0; ic < 8736; ic++) {
96 if (GammaGammaCalib[ic] > 0.) {
97 NewCalib[ic] = GammaGammaCalib[ic];
98 NewCalibUnc[ic] = GammaGammaCalibUnc[ic];
100 NewCalib[ic] = ExistingCalib[ic];
101 NewCalibUnc[ic] = ExistingCalibUnc[ic];
107 for (
int ic = 0; ic < 9000; ic += 1000) {
108 std::cout << ic + 1 <<
" " << ExistingCalib[ic] <<
" " << ExistingCalibUnc[ic] <<
" " << GammaGammaCalib[ic] <<
" " <<
109 GammaGammaCalibUnc[ic] <<
" " << NewCalib[ic] <<
" " << NewCalibUnc[ic] << std::endl;
114 TString payloadTitle =
"ECLCrystalEnergy";
116 payloadTitle += experiment;
119 TString fname = payloadTitle;
121 TFile hfile(fname,
"recreate");
123 TString htitle = payloadTitle;
124 htitle +=
" existing values;cellID";
125 TH1F* existingPayload =
new TH1F(
"existingPayload", htitle, 8736, 1, 8737);
127 htitle = payloadTitle;
128 htitle +=
" new values;cellID";
129 TH1F* newPayload =
new TH1F(
"newPayload", htitle, 8736, 1, 8737);
131 htitle = payloadTitle;
132 htitle +=
" ratio new/old;cellID";
133 TH1F* payloadRatioVsCellID =
new TH1F(
"payloadRatioVsCellID", htitle, 8736, 1, 8737);
135 htitle = payloadTitle;
136 htitle +=
" ratio new/old";
137 TH1F* payloadRatio =
new TH1F(
"payloadRatio", htitle, 200, 0.95, 1.05);
139 for (
int cellID = 1; cellID <= 8736; cellID++) {
140 existingPayload->SetBinContent(cellID, ExistingCalib[cellID - 1]);
141 existingPayload->SetBinError(cellID, ExistingCalibUnc[cellID - 1]);
143 newPayload->SetBinContent(cellID, NewCalib[cellID - 1]);
144 newPayload->SetBinError(cellID, NewCalibUnc[cellID - 1]);
148 if (abs(ExistingCalib[cellID - 1]) > 1.0e-12) {
149 ratio = NewCalib[cellID - 1] / ExistingCalib[cellID - 1];
150 float rUnc0 = ExistingCalibUnc[cellID - 1] / ExistingCalib[cellID - 1];
152 if (abs(NewCalib[cellID - 1]) > 1.0e-12) {rUnc1 = NewCalibUnc[cellID - 1] / NewCalib[cellID - 1];}
153 ratioUnc = ratio * sqrt(rUnc0 * rUnc0 + rUnc1 * rUnc1);
156 payloadRatioVsCellID->SetBinContent(cellID, ratio);
157 payloadRatioVsCellID->SetBinError(cellID, ratioUnc);
159 payloadRatio->Fill(ratio);
165 std::cout << std::endl <<
"Values written to " << fname << std::endl;
170 std::cout <<
"Creating importer" << std::endl;
172 importer.construct();
173 importer->setCalibVector(NewCalib, NewCalibUnc);
175 std::cout <<
"Successfully wrote payload ECLCrystalEnergy with iov " << experiment <<
"," << run <<
",-1,-1" << std::endl;
177 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.
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.
Abstract base class for different kinds of events.
int main(int argc, char **argv)
Run all tests.