99 edm::LogPrint(
"SiPixelGainCalibrationReadDQMFile") <<
"now starting db fill!!!" << std::endl;
101 std::map<uint32_t, std::pair<TString, int> > badresults;
107 TH1F *VCAL_endpoint =
108 fs->make<TH1F>(
"VCAL_endpoint",
"value where response = 255 ( x = (255 - ped)/gain )", 256, 0, 256);
109 TH1F *goodgains =
fs->make<TH1F>(
"goodgains",
"gain values", 100, 0, 10);
110 TH1F *goodpeds =
fs->make<TH1F>(
"goodpeds",
"pedestal values", 356, -100, 256);
111 TH1F *totgains =
fs->make<TH1F>(
"totgains",
"gain values", 200, 0, 10);
112 TH1F *totpeds =
fs->make<TH1F>(
"totpeds",
"pedestal values", 356, -100, 256);
113 TTree *
tree =
new TTree(
"tree",
"tree");
114 int detidfortree, rowfortree, colfortree, useddefaultfortree;
115 float pedfortree, gainfortree, chi2fortree;
116 tree->Branch(
"detid", &detidfortree,
"detid/I");
117 tree->Branch(
"row", &rowfortree,
"row/I");
118 tree->Branch(
"col", &colfortree,
"col/I");
119 tree->Branch(
"defaultval", &useddefaultfortree,
"defaultval/I");
120 tree->Branch(
"ped", &pedfortree,
"ped/F");
121 tree->Branch(
"gain", &gainfortree,
"gain/F");
122 tree->Branch(
"chi2", &chi2fortree,
"chi2/F");
128 edm::LogPrint(
"SiPixelGainCalibrationReadDQMFile") <<
"now filling record " <<
record_ << std::endl;
129 if (
record_ !=
"SiPixelGainCalibrationForHLTRcd" &&
record_ !=
"SiPixelGainCalibrationOfflineRcd") {
131 <<
"you passed record " <<
record_ <<
", which I have no idea what to do with!" << std::endl;
148 float badpedval =
pedlow_ - 200;
150 edm::LogPrint(
"SiPixelGainCalibrationReadDQMFile") <<
"now filling db: values: pedlow, hi: " <<
pedlow_ <<
", " 159 for (
size_t icol = 0; icol <
nmaxcols; ++icol) {
160 for (
size_t irow = 0; irow <
nmaxrows; ++irow) {
161 defaultGain_->SetBinContent(icol + 1, irow + 1, meangain);
162 defaultPed_->SetBinContent(icol + 1, irow + 1, meanped);
174 uint32_t nchannels = 0;
175 uint32_t nmodules = 0;
177 <<
"now starting loop on detids, there are " <<
bookkeeper_.size() <<
" histograms to consider..." << std::endl;
181 edm::LogInfo(
"SiPixelCondObjOfflineBuilder") <<
" There are " << pDD->
dets().size() <<
" detectors" << std::endl;
184 for (TrackerGeometry::DetContainer::const_iterator it = pDD->
dets().begin(); it != pDD->
dets().end(); it++) {
186 if (dynamic_cast<PixelGeomDetUnit const *>((*it)) !=
nullptr)
187 detid = ((*it)->geographicalId()).rawId();
197 useddefaultfortree = 0;
199 <<
"now creating database object for detid " << detid
207 TString tempgainstring;
210 TString tempchi2string =
bookkeeper_[detid][
"chi2prob_2d"];
211 tempchi2 =
dynamic_cast<TH2F *
>(therootfile->Get(tempchi2string));
212 if (tempchi2 ==
nullptr || badDetId) {
214 useddefaultfortree = 1;
216 TString tempfitresultstring =
bookkeeper_[detid][
"fitresult_2d"];
217 tempfitresult =
dynamic_cast<TH2F *
>(therootfile->Get(tempfitresultstring));
218 if (tempfitresult ==
nullptr) {
220 useddefaultfortree = 1;
222 TString tempgainstring =
bookkeeper_[detid][
"gain_2d"];
223 tempgain =
dynamic_cast<TH2F *
>(therootfile->Get(tempgainstring));
224 if (tempgain ==
nullptr) {
227 useddefaultfortree = 1;
229 TString temppedstring =
bookkeeper_[detid][
"ped_2d"];
230 tempped =
dynamic_cast<TH2F *
>(therootfile->Get(temppedstring));
231 if (tempped ==
nullptr) {
233 std::pair<TString, int> tempval(tempgainstring, 0);
234 badresults[detid] = tempval;
236 useddefaultfortree = 1;
242 std::pair<TString, int> tempval(tempgainstring, 0);
243 badresults[detid] = tempval;
245 useddefaultfortree = 1;
251 size_t nrows = topol.
nrows();
257 size_t nrowsrocsplit = theGainCalibrationDbInputHLT.getNumberOfRowsToAverageOver();
258 if (theGainCalibrationDbInputOffline.getNumberOfRowsToAverageOver() != nrowsrocsplit)
259 throw cms::Exception(
"GainCalibration Payload configuration error")
260 <<
"[SiPixelGainCalibrationAnalysis::fillDatabase] ERROR the SiPixelGainCalibrationOffline and " 261 "SiPixelGainCalibrationForHLT database payloads have different settings for the number of rows per roc: " 262 << theGainCalibrationDbInputHLT.getNumberOfRowsToAverageOver() <<
"(HLT), " 263 << theGainCalibrationDbInputOffline.getNumberOfRowsToAverageOver() <<
"(offline)";
264 std::vector<char> theSiPixelGainCalibrationPerPixel;
265 std::vector<char> theSiPixelGainCalibrationPerColumn;
266 std::vector<char> theSiPixelGainCalibrationGainPerColPedPerPixel;
272 double meanGainForThisModule = 0;
273 double meanPedForThisModule = 0;
274 for (
size_t icol = 1; icol <=
ncols; icol++) {
275 for (
size_t jrow = 1; jrow <= nrows; jrow++) {
276 if (tempfitresult->GetBinContent(icol, jrow) > 0) {
278 meanGainForThisModule += tempgain->GetBinContent(icol, jrow);
279 meanPedForThisModule += tempped->GetBinContent(icol, jrow);
284 meanPedForThisModule /= npix;
286 meanGainForThisModule /= npix;
288 if (meanGainForThisModule >
gainlow_ && meanGainForThisModule < gainhi_ && npix > 100)
289 meangain = meanGainForThisModule;
290 if (meanPedForThisModule >
pedlow_ && meanPedForThisModule < pedhi_ && npix > 100)
291 meanped = meanPedForThisModule;
297 float pedforthiscol[2];
298 float gainforthiscol[2];
300 size_t nemptypixels = 0;
302 for (
size_t icol = 1; icol <=
ncols; icol++) {
303 nusedrows[0] = nusedrows[1] = 0;
304 pedforthiscol[0] = pedforthiscol[1] = 0;
305 gainforthiscol[0] = gainforthiscol[1] = 0;
307 for (
size_t jrow = 1; jrow <= nrows; jrow++) {
308 size_t iglobalrow = 0;
309 if (jrow > nrowsrocsplit)
311 peds[jrow] = badpedval;
312 gains[jrow] = badgainval;
313 float ped = tempped->GetBinContent(icol, jrow);
314 float gain = tempgain->GetBinContent(icol, jrow);
315 float chi2 = tempchi2->GetBinContent(icol, jrow);
316 float fitresult = tempfitresult->GetBinContent(icol, jrow);
322 VCAL_endpoint->Fill((255 - ped) /
gain);
325 pedforthiscol[iglobalrow] += ped;
326 gainforthiscol[iglobalrow] +=
gain;
327 nusedrows[iglobalrow]++;
329 goodgains->Fill(
gain);
330 detidfortree = detid;
331 rowfortree = jrow - 1;
332 colfortree = icol - 1;
347 peds[jrow] = meanped;
348 gains[jrow] = meangain;
349 std::pair<TString, int> tempval(tempgainstring, 1);
350 badresults[detid] = tempval;
354 std::pair<TString, int> tempval(tempgainstring, 2);
355 badresults[detid] = tempval;
357 peds[jrow] = badpedval;
358 gains[jrow] = badgainval;
363 totgains->Fill(
gains[jrow]);
364 totpeds->Fill(peds[jrow]);
368 for (
size_t jrow = 1; jrow <= nrows; jrow++) {
370 size_t iglobalrow = 0;
371 if (jrow > nrowsrocsplit)
373 float ped = peds[jrow];
377 theGainCalibrationDbInput.setData(ped,
gain, theSiPixelGainCalibrationPerPixel);
378 theGainCalibrationDbInputOffline.setDataPedestal(ped, theSiPixelGainCalibrationGainPerColPedPerPixel);
380 theGainCalibrationDbInput.setDeadPixel(theSiPixelGainCalibrationPerPixel);
381 theGainCalibrationDbInputOffline.setDeadPixel(theSiPixelGainCalibrationGainPerColPedPerPixel);
384 if (jrow % nrowsrocsplit == 0) {
386 if (nusedrows[iglobalrow] > 0) {
387 pedforthiscol[iglobalrow] /= (
float)nusedrows[iglobalrow];
388 gainforthiscol[iglobalrow] /= (
float)nusedrows[iglobalrow];
390 if (gainforthiscol[iglobalrow] >
gainlow_ && gainforthiscol[iglobalrow] <
gainhi_ &&
391 pedforthiscol[iglobalrow] >
pedlow_ && pedforthiscol[iglobalrow] <
pedhi_) {
396 pedforthiscol[iglobalrow] = meanped;
397 gainforthiscol[iglobalrow] = meangain;
398 std::pair<TString, int> tempval(tempgainstring, 3);
399 badresults[detid] = tempval;
403 pedforthiscol[iglobalrow] = badpedval;
404 gainforthiscol[iglobalrow] = badgainval;
405 std::pair<TString, int> tempval(tempgainstring, 4);
406 badresults[detid] = tempval;
410 if (gainforthiscol[iglobalrow] >
gainlow_ && gainforthiscol[iglobalrow] <
gainhi_ &&
411 pedforthiscol[iglobalrow] >
pedlow_ && pedforthiscol[iglobalrow] <
pedhi_) {
412 theGainCalibrationDbInputOffline.setDataGain(
413 gainforthiscol[iglobalrow], nrowsrocsplit, theSiPixelGainCalibrationGainPerColPedPerPixel);
414 theGainCalibrationDbInputHLT.setData(
415 pedforthiscol[iglobalrow], gainforthiscol[iglobalrow], theSiPixelGainCalibrationPerColumn);
418 theGainCalibrationDbInputOffline.setDeadColumn(nrowsrocsplit,
419 theSiPixelGainCalibrationGainPerColPedPerPixel);
420 theGainCalibrationDbInputHLT.setDeadColumn(nrowsrocsplit, theSiPixelGainCalibrationPerColumn);
428 theSiPixelGainCalibrationPerPixel.end());
430 theSiPixelGainCalibrationPerColumn.end());
432 theSiPixelGainCalibrationGainPerColPedPerPixel.end());
436 if (!theGainCalibrationDbInput.put(detid,
range,
ncols))
438 <<
"warning: detid already exists for Offline (gain per col, ped per pixel) calibration database" 440 if (!theGainCalibrationDbInputOffline.put(detid, offlinerange,
ncols))
442 <<
"warning: detid already exists for Offline (gain per col, ped per pixel) calibration database" 444 if (!theGainCalibrationDbInputHLT.put(detid, hltrange,
ncols))
446 <<
"warning: detid already exists for HLT (pedestal and gain per column) calibration database" << std::endl;
454 size_t ncoldefault = 0;
456 for (
std::map<uint32_t, std::pair<TString, int> >::const_iterator ibad = badresults.begin(); ibad != badresults.end();
458 uint32_t detid = ibad->first;
459 if (badresults[detid].
second == 0) {
462 }
else if (badresults[detid].
second == 1) {
465 }
else if (badresults[detid].
second == 2) {
466 edm::LogPrint(
"SiPixelGainCalibrationReadDQMFile") << badresults[detid].first;
467 edm::LogPrint(
"SiPixelGainCalibrationReadDQMFile") <<
" has one or more dead pixels";
468 edm::LogPrint(
"SiPixelGainCalibrationReadDQMFile") << std::endl;
470 }
else if (badresults[detid].
second == 3) {
473 }
else if (badresults[detid].
second == 4) {
474 edm::LogPrint(
"SiPixelGainCalibrationReadDQMFile") << badresults[detid].first;
475 edm::LogPrint(
"SiPixelGainCalibrationReadDQMFile") <<
" has one or more dead columns";
477 edm::LogPrint(
"SiPixelGainCalibrationReadDQMFile") << std::endl;
481 << nempty <<
" modules were empty and now have pixels filled with default values." << std::endl;
483 << ndefault <<
" modules have pixels filled with default values." << std::endl;
484 edm::LogPrint(
"SiPixelGainCalibrationReadDQMFile") << ndead <<
" modules have pixels flagged as dead." << std::endl;
486 << ncoldefault <<
" modules have columns filled with default values." << std::endl;
488 << ncoldead <<
" modules have columns filled with dead values." << std::endl;
489 edm::LogPrint(
"SiPixelGainCalibrationReadDQMFile") <<
" ---> PIXEL Modules " << nmodules <<
"\n" 490 <<
" ---> PIXEL Channels " << nchannels << std::endl;
492 edm::LogPrint(
"SiPixelGainCalibrationReadDQMFile") <<
" --- writing to DB!" << std::endl;
498 if (
record_ ==
"SiPixelGainCalibrationForHLTRcd") {
500 <<
"now doing SiPixelGainCalibrationForHLTRcd payload..." << std::endl;
503 theGainCalibrationDbInputHLT, mydbservice->
beginOfTime(),
"SiPixelGainCalibrationForHLTRcd");
506 theGainCalibrationDbInputHLT, mydbservice->
currentTime(),
"SiPixelGainCalibrationForHLTRcd");
508 }
else if (
record_ ==
"SiPixelGainCalibrationOfflineRcd") {
510 <<
"now doing SiPixelGainCalibrationOfflineRcd payload..." << std::endl;
513 theGainCalibrationDbInputOffline, mydbservice->
beginOfTime(),
"SiPixelGainCalibrationOfflineRcd");
516 theGainCalibrationDbInputOffline, mydbservice->
currentTime(),
"SiPixelGainCalibrationOfflineRcd");
std::unique_ptr< TH2F > defaultGain_
virtual int ncolumns() const =0
cond::Time_t beginOfTime() const
const std::string record_
virtual int nrows() const =0
const DetContainer & dets() const override
Returm a vector of all GeomDet (including all GeomDetUnits)
Log< level::Error, false > LogError
std::pair< ContainerIterator, ContainerIterator > Range
std::pair< ContainerIterator, ContainerIterator > Range
void createOneIOV(const T &payload, cond::Time_t firstSinceTime, const std::string &recordName)
U second(std::pair< T, U > const &p)
void appendOneIOV(const T &payload, cond::Time_t sinceTime, const std::string &recordName)
std::unique_ptr< TH1F > meanGainHist_
bool isNewTagRequest(const std::string &recordName)
cond::Time_t currentTime() const
std::unique_ptr< TH2F > defaultPed_
std::unique_ptr< TH1F > meanPedHist_
bool getData(T &iHolder) const
Log< level::Warning, true > LogPrint
constexpr float gains[NGAINS]
Log< level::Info, false > LogInfo
std::map< uint32_t, std::map< std::string, TString > > bookkeeper_
std::unique_ptr< TH2F > defaultChi2_
std::pair< ContainerIterator, ContainerIterator > Range
std::unique_ptr< TH2F > defaultFitResult_
virtual const PixelTopology & specificTopology() const
Returns a reference to the pixel proxy topology.
const bool usemeanwhenempty_
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > pddToken_