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>
35 void setupDatabase(
int exp,
int run,
int eventNr = 1)
42 std::cout <<
"about to construct EventMetaData, exp = " << exp <<
" run = " << run <<
" eventNr = " << eventNr << std::endl;
51 int main(
int argc,
char** argv)
53 if (argc < 4 || argc > 5) {
54 std::cout <<
"insufficient arguments for eclElectronicsPayloads" << std::endl;
57 std::string payloadName = argv[1];
58 if (payloadName !=
"ECLCrystalElectronics" and payloadName !=
"ECLCrystalElectronicsTime" and payloadName !=
"ECLRefAmplNom"
59 and payloadName !=
"ECLRefTimeNom") {
60 std::cout <<
"First argument must be ECLCrystalElectronics, ECLCrystalElectronicsTime, ECLRefAmplNom, or ECLRefTimeNom" <<
64 int experiment = std::stoi(argv[2]);
65 int run = std::stoi(argv[3]);
66 bool writeOutput =
true;
67 if (argc == 5) writeOutput = std::stoi(argv[4]);
68 std::cout <<
"eclElectronicsPayloads called with arguments " << payloadName <<
" " << experiment <<
" " << run <<
" " << writeOutput
74 auto states = conf.getUsableTagStates();
75 states.insert(
"OPEN");
76 conf.setUsableTagStates(states);
77 conf.prependGlobalTag(
"ECL_localrun_data");
78 conf.prependTestingPayloadLocation(
"localdb/database.txt");
86 std::cout <<
"calling setupDatabase " << std::endl;
87 setupDatabase(experiment, run);
100 std::cout <<
"Reading ECLRefAmpl, ECLRefAmplNom, ECLRefTime, ECLRefTimeNom, ECLCrystalElectronics, and ECLCrystalElectronicsTime" <<
102 std::cout <<
"Dumping " << payloadName << std::endl;
103 existingObject->Dump();
106 std::vector<float> currentValues = existingObject->getCalibVector();
107 std::vector<float> currentUnc = existingObject->getCalibUncVector();
109 std::vector<float> refAmpl = InputAmpl->getCalibVector();
110 std::vector<float> refAmplUnc = InputAmpl->getCalibUncVector();
112 std::vector<float> refAmplNom = InputAmplNom->getCalibVector();
114 std::vector<float> refTime = InputTime->getCalibVector();
115 std::vector<float> refTimeUnc = InputTime->getCalibUncVector();
117 std::vector<float> refTimeNom = InputTimeNom->getCalibVector();
119 std::vector<float> crysElec = CurrentElec->getCalibVector();
121 std::vector<float> crysTime = CurrentTime->getCalibVector();
125 std::cout << std::endl <<
"Reference amplitudes and times read from database " << std::endl;
126 for (
int ic = 0; ic < 9000; ic += 1000) {
127 std::cout <<
"cellID " << ic + 1 <<
" ref amplitude = " << refAmpl[ic] <<
" +/- " << refAmplUnc[ic] <<
" nom = " << refAmplNom[ic]
128 <<
" ref time = " << refTime[ic]
129 <<
" +/- " << refTimeUnc[ic] <<
" nom = " << refTimeNom[ic] << std::endl;
134 std::vector<float> newValues;
135 std::vector<float> newUnc;
137 if (payloadName ==
"ECLCrystalElectronics") {
138 newValues.push_back(refAmplNom[ic] / refAmpl[ic]);
139 newUnc.push_back(newValues[ic]*refAmplUnc[ic] / refAmpl[ic]);
140 }
else if (payloadName ==
"ECLCrystalElectronicsTime") {
141 newValues.push_back(refTime[ic] - refTimeNom[ic]);
142 newUnc.push_back(refTimeUnc[ic]);
143 }
else if (payloadName ==
"ECLRefAmplNom") {
144 newValues.push_back(crysElec[ic]*refAmpl[ic]);
145 newUnc.push_back(0.);
146 }
else if (payloadName ==
"ECLRefTimeNom") {
147 newValues.push_back(refTime[ic] - crysTime[ic]);
148 newUnc.push_back(0.);
155 std::cout << std::endl <<
"Comparison of existing and new values for " << payloadName << std::endl;
156 for (
int ic = 0; ic < 9000; ic += 1000) {
157 std::cout <<
"cellID " << ic + 1 <<
" existing = " << currentValues[ic] <<
" +/- " << currentUnc[ic] <<
" new = " << newValues[ic]
158 <<
" +/- " << newUnc[ic] << std::endl;
160 std::cout << std::endl;
162 TString payloadTitle = payloadName;
164 payloadTitle += experiment;
167 TString fname = payloadTitle;
169 TFile hfile(fname,
"recreate");
170 TString htitle = payloadTitle;
171 htitle +=
" existing calibration values;cellID";
174 htitle = payloadTitle;
175 htitle +=
" new calibration values;cellID";
178 htitle = payloadTitle;
180 TH1F* calibRatio =
new TH1F(
"calibRatio", htitle, 200, 0.9, 1.1);
182 htitle = payloadTitle;
183 htitle +=
" difference";
184 TH1F* calibDiff =
new TH1F(
"calibDiff", htitle, 200, -100, 100);
186 htitle = payloadTitle;
187 htitle +=
" reference";
190 htitle = payloadTitle;
191 htitle +=
" ratio vs cellID;cellID;new/old";
194 htitle = payloadTitle;
195 htitle +=
" diff vs cellID;cellID;new - old";
199 float oldValue = currentValues[cellID - 1];
200 float newValue = newValues[cellID - 1];
202 if (oldValue != 0.) {
203 ratio = newValue / oldValue;
204 }
else if (newValue != 0.) {
205 ratio = ratio * newValue / fabs(newValue);
208 existingCalib->SetBinContent(cellID, oldValue);
209 existingCalib->SetBinError(cellID, currentUnc[cellID - 1]);
210 newCalib->SetBinContent(cellID, newValue);
211 newCalib->SetBinError(cellID, newUnc[cellID - 1]);
212 calibRatio->Fill(ratio);
213 ratioVsCellID->SetBinContent(cellID, ratio);
214 ratioVsCellID->SetBinError(cellID, 0);
215 calibDiff->Fill(newValue - oldValue);
216 diffVsCellID->SetBinContent(cellID, newValue - oldValue);
217 diffVsCellID->SetBinError(cellID, 0);
218 if (payloadName ==
"ECLCrystalElectronics" or payloadName ==
"ECLRefAmplNom") {
219 refValues->SetBinContent(cellID, refAmpl[cellID - 1]);
220 refValues->SetBinError(cellID, refAmplUnc[cellID - 1]);
222 refValues->SetBinContent(cellID, refTime[cellID - 1]);
223 refValues->SetBinError(cellID, refTimeUnc[cellID - 1]);
227 if ((payloadName ==
"ECLCrystalElectronics" or payloadName ==
"ECLRefAmplNom") and (ratio<0.99 or ratio>1.01)) {
228 std::cout <<
"Ratio = " << ratio <<
" for cellID = " << cellID <<
" refAmpl = " << refAmpl[cellID - 1] <<
" refAmplNom = " <<
229 refAmplNom[cellID - 1] << std::endl;
230 }
else if (abs(newValue - oldValue) > 20.) {
231 std::cout <<
"Difference = " << newValue - oldValue <<
" for cellID = " << cellID <<
" refTime = " << refTime[cellID - 1] <<
232 " refTimeNom = " << refTimeNom[cellID - 1] << std::endl;
239 std::cout << std::endl <<
"Comparison of existing and new calibration values written to " << fname << std::endl;
244 std::cout <<
"Creating importer" << std::endl;
246 importer.construct();
247 importer->setCalibVector(newValues, newUnc);
249 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.
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.
int main(int argc, char **argv)
Run all tests.