File indexing completed on 2023-03-17 10:48:44
0001
0002
0003
0004
0005 #include <iomanip>
0006 #include <fstream>
0007 #include <iostream>
0008 #include <cmath>
0009 #include <memory>
0010
0011 #include "FWCore/Framework/interface/ESHandle.h"
0012 #include "FWCore/Framework/interface/EventSetup.h"
0013 #include "CondFormats/SiPixelTransient/interface/SiPixelGenError.h"
0014
0015 #include "FWCore/Framework/interface/Frameworkfwd.h"
0016 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0017 #include "FWCore/Framework/interface/ESWatcher.h"
0018
0019 #include "FWCore/Framework/interface/Event.h"
0020 #include "FWCore/Framework/interface/MakerMacros.h"
0021
0022 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0023 #include "FWCore/Framework/interface/ConsumesCollector.h"
0024 #include "FWCore/Utilities/interface/ESGetToken.h"
0025
0026 #include "CondFormats/SiPixelObjects/interface/SiPixelGenErrorDBObject.h"
0027 #include "CondFormats/DataRecord/interface/SiPixelGenErrorDBObjectRcd.h"
0028 #include "CalibTracker/Records/interface/SiPixelGenErrorDBObjectESProducerRcd.h"
0029 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0030
0031 class SiPixelGenErrorDBObjectReader : public edm::one::EDAnalyzer<> {
0032 public:
0033 explicit SiPixelGenErrorDBObjectReader(const edm::ParameterSet&);
0034 ~SiPixelGenErrorDBObjectReader() override;
0035
0036 private:
0037 void beginJob() override;
0038 void analyze(const edm::Event&, const edm::EventSetup&) override;
0039 void endJob() override;
0040
0041 std::string theGenErrorCalibrationLocation;
0042 bool theDetailedGenErrorDBErrorOutput;
0043 bool theFullGenErrorDBOutput;
0044
0045 edm::ESGetToken<SiPixelGenErrorDBObject, SiPixelGenErrorDBObjectRcd> genErrToken_;
0046 };
0047
0048 SiPixelGenErrorDBObjectReader::SiPixelGenErrorDBObjectReader(const edm::ParameterSet& iConfig)
0049 : theGenErrorCalibrationLocation(iConfig.getParameter<std::string>("siPixelGenErrorCalibrationLocation")),
0050 theDetailedGenErrorDBErrorOutput(iConfig.getParameter<bool>("wantDetailedGenErrorDBErrorOutput")),
0051 theFullGenErrorDBOutput(iConfig.getParameter<bool>("wantFullGenErrorDBOutput")),
0052 genErrToken_(esConsumes()) {}
0053
0054 SiPixelGenErrorDBObjectReader::~SiPixelGenErrorDBObjectReader() = default;
0055
0056 void SiPixelGenErrorDBObjectReader::beginJob() {}
0057
0058 void SiPixelGenErrorDBObjectReader::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0059 edm::LogPrint("SiPixelGenErrorDBObjectReader") << "\nLoading ... " << std::endl;
0060
0061 SiPixelGenErrorDBObject dbobject = *&iSetup.getData(genErrToken_);
0062 const SiPixelGenErrorDBObject* db = &iSetup.getData(genErrToken_);
0063
0064
0065 edm::LogPrint("SiPixelGenErrorDBObjectReader")
0066 << " DBObject version " << dbobject.version() << " index " << dbobject.index() << " max " << dbobject.maxIndex()
0067 << " fail " << dbobject.fail() << " numOfTeml " << dbobject.numOfTempl() << std::endl;
0068
0069 if (theFullGenErrorDBOutput) {
0070 edm::LogPrint("SiPixelGenErrorDBObjectReader") << "Map info" << std::endl;
0071 std::vector<short> tempMapId;
0072 std::map<unsigned int, short> templMap = dbobject.getGenErrorIDs();
0073 for (std::map<unsigned int, short>::const_iterator it = templMap.begin(); it != templMap.end(); ++it) {
0074 if (tempMapId.empty())
0075 tempMapId.push_back(it->second);
0076 for (unsigned int i = 0; i < tempMapId.size(); ++i) {
0077 if (tempMapId[i] == it->second)
0078 continue;
0079 else if (i == tempMapId.size() - 1) {
0080 tempMapId.push_back(it->second);
0081 break;
0082 }
0083 }
0084
0085 edm::LogPrint("SiPixelGenErrorDBObjectReader") << "DetId: " << it->first << " GenErrorID: " << it->second << "\n";
0086 }
0087
0088 edm::LogPrint("SiPixelGenErrorDBObjectReader") << "\nMap stores GenError Id(s): ";
0089 for (unsigned int vindex = 0; vindex < tempMapId.size(); ++vindex)
0090 edm::LogPrint("SiPixelGenErrorDBObjectReader") << tempMapId[vindex] << " ";
0091 edm::LogPrint("SiPixelGenErrorDBObjectReader") << std::endl;
0092 }
0093
0094
0095 if (theGenErrorCalibrationLocation.empty()) {
0096 edm::LogPrint("SiPixelGenErrorDBObjectReader")
0097 << " no file for camparison defined, comparison will be skipped " << std::endl;
0098
0099 } else {
0100
0101 bool error = false;
0102 int numOfTempl = dbobject.numOfTempl();
0103 int index = 0;
0104 float tempnum = 0, diff = 0;
0105 float tol = 1.0E-23;
0106 bool givenErrorMsg = false;
0107
0108 edm::LogPrint("SiPixelGenErrorDBObjectReader")
0109 << "\nChecking GenError DB object version " << dbobject.version() << " containing " << numOfTempl
0110 << " calibration(s) at " << dbobject.sVector()[index + 22] << "T\n";
0111
0112 for (int i = 0; i < numOfTempl; ++i) {
0113
0114 index += 20;
0115
0116
0117
0118 edm::LogPrint("SiPixelGenErrorDBObjectReader")
0119 << "Calibration " << i + 1 << " of " << numOfTempl << ", with GenError ID " << dbobject.sVector()[index]
0120 << "\tand Version " << dbobject.sVector()[index + 1] << "\t-------- " << std::endl;
0121
0122
0123 std::ostringstream tout;
0124 tout << theGenErrorCalibrationLocation.c_str() << "generror_summary_zp" << std::setw(4) << std::setfill('0')
0125 << std::right << dbobject.sVector()[index] << ".out" << std::ends;
0126
0127 std::string temp = tout.str();
0128 std::ifstream in_file(temp.c_str(), std::ios::in);
0129
0130 edm::LogPrint("SiPixelGenErrorDBObjectReader")
0131 << " open file " << tout.str() << " " << in_file.is_open() << std::endl;
0132
0133 if (in_file.is_open()) {
0134
0135
0136 in_file >> tempnum;
0137
0138
0139 while (!in_file.eof()) {
0140
0141 diff = std::abs(tempnum - dbobject.sVector()[index]);
0142
0143
0144 if (diff > tol) {
0145
0146 if (!givenErrorMsg)
0147 edm::LogPrint("SiPixelGenErrorDBObjectReader") << "does NOT match\n";
0148
0149 error = true;
0150 givenErrorMsg = true;
0151
0152 if (theDetailedGenErrorDBErrorOutput) {
0153 edm::LogPrint("SiPixelGenErrorDBObjectReader")
0154 << "from file = " << tempnum << "\t from dbobject = " << dbobject.sVector()[index]
0155 << "\tdiff = " << diff << "\t db index = " << index << std::endl;
0156 }
0157 }
0158
0159 in_file >> tempnum;
0160 ++index;
0161 }
0162
0163 if (!givenErrorMsg)
0164 edm::LogPrint("SiPixelGenErrorDBObjectReader") << "MATCHES\n";
0165 } else {
0166 edm::LogPrint("SiPixelGenErrorDBObjectReader")
0167 << " ERROR: cannot open file, comparison will be stopped" << std::endl;
0168 break;
0169 }
0170 in_file.close();
0171 givenErrorMsg = false;
0172
0173 }
0174
0175 if (error && !theDetailedGenErrorDBErrorOutput)
0176 edm::LogPrint("SiPixelGenErrorDBObjectReader")
0177 << "\nThe were differences found between the files and the database.\n"
0178 << "If you would like more detailed information please set\n"
0179 << "wantDetailedOutput = True in the cfg file. If you would like a\n"
0180 << "full output of the contents of the database file please set\n"
0181 << "wantFullOutput = True. Make sure that you pipe the output to a\n"
0182 << "log file. This could take a few minutes.\n\n";
0183
0184 }
0185
0186
0187 std::vector<SiPixelGenErrorStore> thePixelGenError;
0188 bool status = SiPixelGenError::pushfile(*db, thePixelGenError);
0189 edm::LogPrint("SiPixelGenErrorDBObjectReader")
0190 << " status = " << status << " size = " << thePixelGenError.size() << std::endl;
0191
0192 SiPixelGenError genError(thePixelGenError);
0193
0194 edm::LogPrint("SiPixelGenErrorDBObjectReader")
0195 << " some values " << genError.lorxwidth() << " " << genError.lorywidth() << " " << std::endl;
0196
0197
0198 if (theFullGenErrorDBOutput)
0199 edm::LogPrint("SiPixelGenErrorDBObjectReader") << dbobject << std::endl;
0200 }
0201
0202 void SiPixelGenErrorDBObjectReader::endJob() {}
0203
0204
0205
0206 std::ostream& operator<<(std::ostream& s, const SiPixelGenErrorDBObject& dbobject) {
0207
0208 int index = 0;
0209
0210 int txsize[4] = {7, 13, 0, 0};
0211 int tysize[4] = {21, 21, 0, 0};
0212
0213 int entries[4] = {0};
0214
0215 int i, j, k, l, m, n, entry_it;
0216
0217 int sizeSetter = 1, generrorVersion = 0;
0218
0219 edm::LogPrint("SiPixelGenErrorDBObjectReader") << "\n\nDBobject version: " << dbobject.version() << std::endl;
0220
0221 for (m = 0; m < dbobject.numOfTempl(); ++m) {
0222
0223 generrorVersion = (int)dbobject.sVector_[index + 21];
0224
0225 edm::LogPrint("SiPixelGenErrorDBObjectReader") << " GenError version " << generrorVersion << " " << m << std::endl;
0226
0227 if (generrorVersion <= 10) {
0228 edm::LogPrint("SiPixelGenErrorDBObjectReader")
0229 << "*****WARNING***** This code will not format this GenError version properly *****WARNING*****\n";
0230 sizeSetter = 0;
0231 } else if (generrorVersion <= 16)
0232 sizeSetter = 1;
0233 else
0234 edm::LogPrint("SiPixelGenErrorDBObjectReader")
0235 << "*****WARNING***** This code has not been tested at formatting this version *****WARNING*****\n";
0236
0237 edm::LogPrint("SiPixelGenErrorDBObjectReader")
0238 << "\n\n*********************************************************************************************"
0239 << std::endl;
0240 edm::LogPrint("SiPixelGenErrorDBObjectReader")
0241 << "*************** Reading GenError ID " << dbobject.sVector_[index + 20] << "\t(" << m + 1
0242 << "/" << dbobject.numOfTempl_ << ") ***************" << std::endl;
0243 edm::LogPrint("SiPixelGenErrorDBObjectReader")
0244 << "*********************************************************************************************\n\n"
0245 << std::endl;
0246
0247
0248 edm::LogPrint("SiPixelGenErrorDBObjectReader") << " Header Title" << std::endl;
0249 SiPixelGenErrorDBObject::char2float temp;
0250 for (n = 0; n < 20; ++n) {
0251 temp.f = dbobject.sVector_[index];
0252 s << temp.c[0] << temp.c[1] << temp.c[2] << temp.c[3];
0253 ++index;
0254 }
0255
0256 entries[0] = (int)dbobject.sVector_[index + 3];
0257 entries[1] = (int)(dbobject.sVector_[index + 4] * dbobject.sVector_[index + 5]);
0258
0259
0260 edm::LogPrint("SiPixelGenErrorDBObjectReader") << " Header " << std::endl;
0261 s << dbobject.sVector_[index] << "\t" << dbobject.sVector_[index + 1] << "\t" << dbobject.sVector_[index + 2]
0262 << "\t" << dbobject.sVector_[index + 3] << "\t" << dbobject.sVector_[index + 4] << "\t"
0263 << dbobject.sVector_[index + 5] << "\t" << dbobject.sVector_[index + 6] << "\t" << dbobject.sVector_[index + 7]
0264 << "\t" << dbobject.sVector_[index + 8] << "\t" << dbobject.sVector_[index + 9] << "\t"
0265 << dbobject.sVector_[index + 10] << "\t" << dbobject.sVector_[index + 11] << "\t" << dbobject.sVector_[index + 12]
0266 << "\t" << dbobject.sVector_[index + 13] << "\t" << dbobject.sVector_[index + 14] << "\t"
0267 << dbobject.sVector_[index + 15] << "\t" << dbobject.sVector_[index + 16] << std::endl;
0268 index += 17;
0269
0270
0271 edm::LogPrint("SiPixelGenErrorDBObjectReader") << " ByBxFyFx" << std::endl;
0272 for (entry_it = 0; entry_it < 4; ++entry_it) {
0273
0274 for (i = 0; i < entries[entry_it]; ++i) {
0275 s << dbobject.sVector_[index] << "\t" << dbobject.sVector_[index + 1] << "\t" << dbobject.sVector_[index + 2]
0276 << "\t" << dbobject.sVector_[index + 3] << "\n"
0277 << dbobject.sVector_[index + 4] << "\t" << dbobject.sVector_[index + 5] << "\t"
0278 << dbobject.sVector_[index + 6] << "\t" << dbobject.sVector_[index + 7] << "\t"
0279 << dbobject.sVector_[index + 8] << "\t" << dbobject.sVector_[index + 9] << "\t"
0280 << dbobject.sVector_[index + 10] << "\t" << dbobject.sVector_[index + 11] << "\n"
0281 << dbobject.sVector_[index + 12] << "\t" << dbobject.sVector_[index + 13] << "\t"
0282 << dbobject.sVector_[index + 14] << "\t" << dbobject.sVector_[index + 15] << "\t"
0283 << dbobject.sVector_[index + 16] << "\t" << dbobject.sVector_[index + 17] << "\t"
0284 << dbobject.sVector_[index + 18] << std::endl;
0285 index += 19;
0286
0287 edm::LogPrint("SiPixelGenErrorDBObjectReader") << " YPar" << std::endl;
0288 for (j = 0; j < 2; ++j) {
0289 for (k = 0; k < 5; ++k) {
0290 s << dbobject.sVector_[index] << "\t";
0291 ++index;
0292 }
0293 s << std::endl;
0294 }
0295
0296 edm::LogPrint("SiPixelGenErrorDBObjectReader") << " YTemp" << std::endl;
0297 for (j = 0; j < 9; ++j) {
0298 for (k = 0; k < tysize[sizeSetter]; ++k) {
0299 s << dbobject.sVector_[index] << "\t";
0300 ++index;
0301 }
0302 s << std::endl;
0303 }
0304
0305 edm::LogPrint("SiPixelGenErrorDBObjectReader") << " XPar" << std::endl;
0306 for (j = 0; j < 2; ++j) {
0307 for (k = 0; k < 5; ++k) {
0308 s << dbobject.sVector_[index] << "\t";
0309 ++index;
0310 }
0311 s << std::endl;
0312 }
0313
0314 edm::LogPrint("SiPixelGenErrorDBObjectReader") << " Xtemp" << std::endl;
0315 for (j = 0; j < 9; ++j) {
0316 for (k = 0; k < txsize[sizeSetter]; ++k) {
0317 s << dbobject.sVector_[index] << "\t";
0318 ++index;
0319 }
0320 s << std::endl;
0321 }
0322
0323 edm::LogPrint("SiPixelGenErrorDBObjectReader") << " Y average reco params " << std::endl;
0324 for (j = 0; j < 4; ++j) {
0325 for (k = 0; k < 4; ++k) {
0326 s << dbobject.sVector_[index] << "\t";
0327 ++index;
0328 }
0329 s << std::endl;
0330 }
0331
0332 edm::LogPrint("SiPixelGenErrorDBObjectReader") << " Yflar " << std::endl;
0333 for (j = 0; j < 4; ++j) {
0334 for (k = 0; k < 6; ++k) {
0335 s << dbobject.sVector_[index] << "\t";
0336 ++index;
0337 }
0338 s << std::endl;
0339 }
0340
0341 edm::LogPrint("SiPixelGenErrorDBObjectReader") << " X average reco params" << std::endl;
0342 for (j = 0; j < 4; ++j) {
0343 for (k = 0; k < 4; ++k) {
0344 s << dbobject.sVector_[index] << "\t";
0345 ++index;
0346 }
0347 s << std::endl;
0348 }
0349
0350 edm::LogPrint("SiPixelGenErrorDBObjectReader") << " Xflar" << std::endl;
0351 for (j = 0; j < 4; ++j) {
0352 for (k = 0; k < 6; ++k) {
0353 s << dbobject.sVector_[index] << "\t";
0354 ++index;
0355 }
0356 s << std::endl;
0357 }
0358
0359 edm::LogPrint("SiPixelGenErrorDBObjectReader") << " XY chi2" << std::endl;
0360 for (j = 0; j < 4; ++j) {
0361 for (k = 0; k < 2; ++k) {
0362 for (l = 0; l < 2; ++l) {
0363 s << dbobject.sVector_[index] << "\t";
0364 ++index;
0365 }
0366 }
0367 s << std::endl;
0368 }
0369
0370 edm::LogPrint("SiPixelGenErrorDBObjectReader") << " Y chi2" << std::endl;
0371 for (j = 0; j < 4; ++j) {
0372 for (k = 0; k < 4; ++k) {
0373 s << dbobject.sVector_[index] << "\t";
0374 ++index;
0375 }
0376 s << std::endl;
0377 }
0378
0379 edm::LogPrint("SiPixelGenErrorDBObjectReader") << " X chi2" << std::endl;
0380 for (j = 0; j < 4; ++j) {
0381 for (k = 0; k < 4; ++k) {
0382 s << dbobject.sVector_[index] << "\t";
0383 ++index;
0384 }
0385 s << std::endl;
0386 }
0387
0388 edm::LogPrint("SiPixelGenErrorDBObjectReader") << " Y reco params for generic" << std::endl;
0389 for (j = 0; j < 4; ++j) {
0390 for (k = 0; k < 4; ++k) {
0391 s << dbobject.sVector_[index] << "\t";
0392 ++index;
0393 }
0394 s << std::endl;
0395 }
0396
0397 edm::LogPrint("SiPixelGenErrorDBObjectReader") << " X reco params for generic" << std::endl;
0398 for (j = 0; j < 4; ++j) {
0399 for (k = 0; k < 4; ++k) {
0400 s << dbobject.sVector_[index] << "\t";
0401 ++index;
0402 }
0403 s << std::endl;
0404 }
0405
0406 edm::LogPrint("SiPixelGenErrorDBObjectReader") << " Spare " << std::endl;
0407 for (j = 0; j < 20; ++j) {
0408 s << dbobject.sVector_[index] << "\t";
0409 ++index;
0410 if (j == 9 || j == 19)
0411 s << std::endl;
0412 }
0413 }
0414 }
0415 }
0416 return s;
0417 }
0418
0419 DEFINE_FWK_MODULE(SiPixelGenErrorDBObjectReader);