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>
21#include <framework/logging/LogSystem.h>
53 void setupDatabase(
int exp,
int run,
int eventNr = 1)
60 std::cout <<
"about to construct EventMetaData, exp = " << exp <<
" run = " << run <<
" eventNr = " << eventNr << std::endl;
69int main(
int argc,
char** argv)
71 if (argc < 5 || argc > 6) {
72 std::cout <<
"incorrected number of arguments for eclElectronicsPayloads" << std::endl;
75 std::string payloadName = argv[1];
76 if (payloadName !=
"ECLCrystalElectronics" and payloadName !=
"ECLCrystalElectronicsTime" and payloadName !=
"ECLRefAmplNom"
77 and payloadName !=
"ECLRefTimeNom") {
78 std::cout <<
"First argument must be ECLCrystalElectronics, ECLCrystalElectronicsTime, ECLRefAmplNom, or ECLRefTimeNom" <<
82 int experiment = std::stoi(argv[2]);
83 int run = std::stoi(argv[3]);
84 std::string globalTag = argv[4];
85 bool writeOutput =
true;
86 if (argc == 6) writeOutput = std::stoi(argv[5]);
87 std::cout <<
"eclElectronicsPayloads called with arguments " << payloadName <<
" " << experiment <<
" " << run <<
" " << globalTag
88 <<
" " << writeOutput << std::endl;
93 auto states = conf.getUsableTagStates();
94 states.insert(
"OPEN");
95 conf.setUsableTagStates(states);
96 conf.prependGlobalTag(globalTag);
97 conf.prependTestingPayloadLocation(
"localdb/database.txt");
105 std::cout <<
"calling setupDatabase " << std::endl;
106 setupDatabase(experiment, run);
119 std::cout <<
"Reading ECLRefAmpl, ECLRefAmplNom, ECLRefTime, ECLRefTimeNom, ECLCrystalElectronics, and ECLCrystalElectronicsTime" <<
121 std::cout <<
"Dumping " << payloadName << std::endl;
122 existingObject->Dump();
125 std::vector<float> currentValues = existingObject->getCalibVector();
126 std::vector<float> currentUnc = existingObject->getCalibUncVector();
128 std::vector<float> refAmpl = InputAmpl->getCalibVector();
129 std::vector<float> refAmplUnc = InputAmpl->getCalibUncVector();
131 std::vector<float> refAmplNom = InputAmplNom->getCalibVector();
133 std::vector<float> refTime = InputTime->getCalibVector();
134 std::vector<float> refTimeUnc = InputTime->getCalibUncVector();
136 std::vector<float> refTimeNom = InputTimeNom->getCalibVector();
138 std::vector<float> crysElec = CurrentElec->getCalibVector();
140 std::vector<float> crysTime = CurrentTime->getCalibVector();
144 std::cout << std::endl <<
"Reference amplitudes and times read from database " << std::endl;
145 for (
int ic = 0; ic < 9000; ic += 1000) {
146 std::cout <<
"cellID " << ic + 1 <<
" ref amplitude = " << refAmpl[ic] <<
" +/- " << refAmplUnc[ic] <<
" nom = " << refAmplNom[ic]
147 <<
" ref time = " << refTime[ic]
148 <<
" +/- " << refTimeUnc[ic] <<
" nom = " << refTimeNom[ic] << std::endl;
153 std::vector<float> newValues;
154 std::vector<float> newUnc;
156 if (payloadName ==
"ECLCrystalElectronics") {
157 newValues.push_back(refAmplNom[ic] / refAmpl[ic]);
158 newUnc.push_back(newValues[ic]*refAmplUnc[ic] / refAmpl[ic]);
159 }
else if (payloadName ==
"ECLCrystalElectronicsTime") {
160 newValues.push_back(refTime[ic] - refTimeNom[ic]);
161 newUnc.push_back(refTimeUnc[ic]);
162 }
else if (payloadName ==
"ECLRefAmplNom") {
163 newValues.push_back(crysElec[ic]*refAmpl[ic]);
164 newUnc.push_back(0.);
165 }
else if (payloadName ==
"ECLRefTimeNom") {
166 newValues.push_back(refTime[ic] - crysTime[ic]);
167 newUnc.push_back(0.);
174 std::cout << std::endl <<
"Comparison of existing and new values for " << payloadName << std::endl;
175 for (
int ic = 0; ic < 9000; ic += 1000) {
176 std::cout <<
"cellID " << ic + 1 <<
" existing = " << currentValues[ic] <<
" +/- " << currentUnc[ic] <<
" new = " << newValues[ic]
177 <<
" +/- " << newUnc[ic] << std::endl;
179 std::cout << std::endl;
181 TString payloadTitle = payloadName;
183 payloadTitle += experiment;
186 TString fname = payloadTitle;
188 TFile hfile(fname,
"recreate");
189 TString htitle = payloadTitle;
190 htitle +=
" existing calibration values;cellID";
193 htitle = payloadTitle;
194 htitle +=
" new calibration values;cellID";
197 htitle = payloadTitle;
199 TH1F* calibRatio =
new TH1F(
"calibRatio", htitle, 200, 0.9, 1.1);
201 htitle = payloadTitle;
202 htitle +=
" difference";
203 TH1F* calibDiff =
new TH1F(
"calibDiff", htitle, 200, -100, 100);
205 htitle = payloadTitle;
206 htitle +=
" reference";
209 htitle = payloadTitle;
210 htitle +=
" ratio vs cellID;cellID;new/old";
213 htitle = payloadTitle;
214 htitle +=
" diff vs cellID;cellID;new - old";
218 float oldValue = currentValues[cellID - 1];
219 float newValue = newValues[cellID - 1];
221 if (oldValue != 0.) {
222 ratio = newValue / oldValue;
223 }
else if (newValue != 0.) {
224 ratio = ratio * newValue / fabs(newValue);
227 existingCalib->SetBinContent(cellID, oldValue);
228 existingCalib->SetBinError(cellID, currentUnc[cellID - 1]);
229 newCalib->SetBinContent(cellID, newValue);
230 newCalib->SetBinError(cellID, newUnc[cellID - 1]);
231 calibRatio->Fill(ratio);
232 ratioVsCellID->SetBinContent(cellID, ratio);
233 ratioVsCellID->SetBinError(cellID, 0);
234 calibDiff->Fill(newValue - oldValue);
235 diffVsCellID->SetBinContent(cellID, newValue - oldValue);
236 diffVsCellID->SetBinError(cellID, 0);
237 if (payloadName ==
"ECLCrystalElectronics" or payloadName ==
"ECLRefAmplNom") {
238 refValues->SetBinContent(cellID, refAmpl[cellID - 1]);
239 refValues->SetBinError(cellID, refAmplUnc[cellID - 1]);
241 refValues->SetBinContent(cellID, refTime[cellID - 1]);
242 refValues->SetBinError(cellID, refTimeUnc[cellID - 1]);
246 if ((payloadName ==
"ECLCrystalElectronics" or payloadName ==
"ECLRefAmplNom") and (ratio<0.99 or ratio>1.01)) {
247 std::cout <<
"Ratio = " << ratio <<
" for cellID = " << cellID <<
" refAmpl = " << refAmpl[cellID - 1] <<
" refAmplNom = " <<
248 refAmplNom[cellID - 1] << std::endl;
249 }
else if (abs(newValue - oldValue) > 20.) {
250 std::cout <<
"Difference = " << newValue - oldValue <<
" for cellID = " << cellID <<
" refTime = " << refTime[cellID - 1] <<
251 " refTimeNom = " << refTimeNom[cellID - 1] << std::endl;
258 std::cout << std::endl <<
"Comparison of existing and new calibration values written to " << fname << std::endl;
263 std::cout <<
"Creating importer" << std::endl;
265 importer.construct();
266 importer->setCalibVector(newValues, newUnc);
268 std::cout <<
"Successfully wrote payload " << payloadName <<
" with iov " << experiment <<
"," << run <<
",-1,-1" << 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.
void setDebugLevel(int debugLevel)
Configure the debug messaging level.
@ c_Debug
Debug: for code development.
void setLogLevel(ELogLevel logLevel)
Configure the log level.
LogConfig * getLogConfig()
Returns global log system configuration.
static LogSystem & Instance()
Static method to get a reference to the LogSystem instance.
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.
const int c_NCrystals
Number of crystals.
Abstract base class for different kinds of events.