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");
127 edm::LogPrint(
"SiPixelGainCalibrationReadDQMFile") <<
"now filling record " <<
record_ << std::endl;
128 if (
record_ !=
"SiPixelGainCalibrationForHLTRcd" &&
record_ !=
"SiPixelGainCalibrationOfflineRcd") {
130 <<
"you passed record " <<
record_ <<
", which I have no idea what to do with!" << std::endl;
147 float badpedval =
pedlow_ - 200;
149 edm::LogPrint(
"SiPixelGainCalibrationReadDQMFile") <<
"now filling db: values: pedlow, hi: " <<
pedlow_ <<
", " 158 for (
size_t icol = 0; icol <
nmaxcols; ++icol) {
159 for (
size_t irow = 0; irow <
nmaxrows; ++irow) {
160 defaultGain_->SetBinContent(icol + 1, irow + 1, meangain);
161 defaultPed_->SetBinContent(icol + 1, irow + 1, meanped);
173 uint32_t nchannels = 0;
174 uint32_t nmodules = 0;
176 <<
"now starting loop on detids, there are " <<
bookkeeper_.size() <<
" histograms to consider..." << std::endl;
180 edm::LogInfo(
"SiPixelCondObjOfflineBuilder") <<
" There are " << pDD->
dets().size() <<
" detectors" << std::endl;
182 for (TrackerGeometry::DetContainer::const_iterator
it = pDD->
dets().begin();
it != pDD->
dets().end();
it++) {
184 if (dynamic_cast<PixelGeomDetUnit const *>((*
it)) !=
nullptr)
185 detid = ((*it)->geographicalId()).
rawId();
192 useddefaultfortree = 0;
194 <<
"now creating database object for detid " << detid
202 TString tempgainstring;
205 TString tempchi2string =
bookkeeper_[detid][
"chi2prob_2d"];
206 tempchi2 =
dynamic_cast<TH2F *
>(therootfile->Get(tempchi2string));
207 if (tempchi2 ==
nullptr || badDetId) {
209 useddefaultfortree = 1;
211 TString tempfitresultstring =
bookkeeper_[detid][
"fitresult_2d"];
212 tempfitresult =
dynamic_cast<TH2F *
>(therootfile->Get(tempfitresultstring));
213 if (tempfitresult ==
nullptr) {
215 useddefaultfortree = 1;
217 TString tempgainstring =
bookkeeper_[detid][
"gain_2d"];
218 tempgain =
dynamic_cast<TH2F *
>(therootfile->Get(tempgainstring));
219 if (tempgain ==
nullptr) {
222 useddefaultfortree = 1;
224 TString temppedstring =
bookkeeper_[detid][
"ped_2d"];
225 tempped =
dynamic_cast<TH2F *
>(therootfile->Get(temppedstring));
226 if (tempped ==
nullptr) {
228 std::pair<TString, int> tempval(tempgainstring, 0);
229 badresults[detid] = tempval;
231 useddefaultfortree = 1;
237 std::pair<TString, int> tempval(tempgainstring, 0);
238 badresults[detid] = tempval;
240 useddefaultfortree = 1;
246 size_t nrows = topol.
nrows();
252 size_t nrowsrocsplit = theGainCalibrationDbInputHLT.getNumberOfRowsToAverageOver();
253 if (theGainCalibrationDbInputOffline.getNumberOfRowsToAverageOver() != nrowsrocsplit)
254 throw cms::Exception(
"GainCalibration Payload configuration error")
255 <<
"[SiPixelGainCalibrationAnalysis::fillDatabase] ERROR the SiPixelGainCalibrationOffline and " 256 "SiPixelGainCalibrationForHLT database payloads have different settings for the number of rows per roc: " 257 << theGainCalibrationDbInputHLT.getNumberOfRowsToAverageOver() <<
"(HLT), " 258 << theGainCalibrationDbInputOffline.getNumberOfRowsToAverageOver() <<
"(offline)";
259 std::vector<char> theSiPixelGainCalibrationPerPixel;
260 std::vector<char> theSiPixelGainCalibrationPerColumn;
261 std::vector<char> theSiPixelGainCalibrationGainPerColPedPerPixel;
267 double meanGainForThisModule = 0;
268 double meanPedForThisModule = 0;
269 for (
size_t icol = 1; icol <=
ncols; icol++) {
270 for (
size_t jrow = 1; jrow <= nrows; jrow++) {
271 if (tempfitresult->GetBinContent(icol, jrow) > 0) {
273 meanGainForThisModule += tempgain->GetBinContent(icol, jrow);
274 meanPedForThisModule += tempped->GetBinContent(icol, jrow);
279 meanPedForThisModule /= npix;
281 meanGainForThisModule /= npix;
283 if (meanGainForThisModule >
gainlow_ && meanGainForThisModule < gainhi_ && npix > 100)
284 meangain = meanGainForThisModule;
285 if (meanPedForThisModule >
pedlow_ && meanPedForThisModule < pedhi_ && npix > 100)
286 meanped = meanPedForThisModule;
292 float pedforthiscol[2];
293 float gainforthiscol[2];
296 for (
size_t icol = 1; icol <=
ncols; icol++) {
297 nusedrows[0] = nusedrows[1] = 0;
298 pedforthiscol[0] = pedforthiscol[1] = 0;
299 gainforthiscol[0] = gainforthiscol[1] = 0;
301 for (
size_t jrow = 1; jrow <= nrows; jrow++) {
302 size_t iglobalrow = 0;
303 if (jrow > nrowsrocsplit)
305 peds[jrow] = badpedval;
306 gains[jrow] = badgainval;
307 float ped = tempped->GetBinContent(icol, jrow);
308 float gain = tempgain->GetBinContent(icol, jrow);
309 float chi2 = tempchi2->GetBinContent(icol, jrow);
310 float fitresult = tempfitresult->GetBinContent(icol, jrow);
313 VCAL_endpoint->Fill((255 - ped) /
gain);
316 pedforthiscol[iglobalrow] += ped;
317 gainforthiscol[iglobalrow] +=
gain;
318 nusedrows[iglobalrow]++;
320 goodgains->Fill(
gain);
321 detidfortree = detid;
322 rowfortree = jrow - 1;
323 colfortree = icol - 1;
330 peds[jrow] = meanped;
331 gains[jrow] = meangain;
332 std::pair<TString, int> tempval(tempgainstring, 1);
333 badresults[detid] = tempval;
335 std::pair<TString, int> tempval(tempgainstring, 2);
336 badresults[detid] = tempval;
338 peds[jrow] = badpedval;
339 gains[jrow] = badgainval;
344 totgains->Fill(
gains[jrow]);
345 totpeds->Fill(peds[jrow]);
349 for (
size_t jrow = 1; jrow <= nrows; jrow++) {
351 size_t iglobalrow = 0;
352 if (jrow > nrowsrocsplit)
354 float ped = peds[jrow];
358 theGainCalibrationDbInput.setData(ped,
gain, theSiPixelGainCalibrationPerPixel);
359 theGainCalibrationDbInputOffline.setDataPedestal(ped, theSiPixelGainCalibrationGainPerColPedPerPixel);
361 theGainCalibrationDbInput.setDeadPixel(theSiPixelGainCalibrationPerPixel);
362 theGainCalibrationDbInputOffline.setDeadPixel(theSiPixelGainCalibrationGainPerColPedPerPixel);
365 if (jrow % nrowsrocsplit == 0) {
367 if (nusedrows[iglobalrow] > 0) {
368 pedforthiscol[iglobalrow] /= (
float)nusedrows[iglobalrow];
369 gainforthiscol[iglobalrow] /= (
float)nusedrows[iglobalrow];
371 if (gainforthiscol[iglobalrow] >
gainlow_ && gainforthiscol[iglobalrow] <
gainhi_ &&
372 pedforthiscol[iglobalrow] >
pedlow_ && pedforthiscol[iglobalrow] <
pedhi_) {
377 pedforthiscol[iglobalrow] = meanped;
378 gainforthiscol[iglobalrow] = meangain;
379 std::pair<TString, int> tempval(tempgainstring, 3);
380 badresults[detid] = tempval;
382 pedforthiscol[iglobalrow] = badpedval;
383 gainforthiscol[iglobalrow] = badgainval;
384 std::pair<TString, int> tempval(tempgainstring, 4);
385 badresults[detid] = tempval;
389 if (gainforthiscol[iglobalrow] >
gainlow_ && gainforthiscol[iglobalrow] <
gainhi_ &&
390 pedforthiscol[iglobalrow] >
pedlow_ && pedforthiscol[iglobalrow] <
pedhi_) {
391 theGainCalibrationDbInputOffline.setDataGain(
392 gainforthiscol[iglobalrow], nrowsrocsplit, theSiPixelGainCalibrationGainPerColPedPerPixel);
393 theGainCalibrationDbInputHLT.setData(
394 pedforthiscol[iglobalrow], gainforthiscol[iglobalrow], theSiPixelGainCalibrationPerColumn);
397 theGainCalibrationDbInputOffline.setDeadColumn(nrowsrocsplit,
398 theSiPixelGainCalibrationGainPerColPedPerPixel);
399 theGainCalibrationDbInputHLT.setDeadColumn(nrowsrocsplit, theSiPixelGainCalibrationPerColumn);
407 theSiPixelGainCalibrationPerPixel.end());
409 theSiPixelGainCalibrationPerColumn.end());
411 theSiPixelGainCalibrationGainPerColPedPerPixel.end());
415 if (!theGainCalibrationDbInput.put(detid,
range,
ncols))
417 <<
"warning: detid already exists for Offline (gain per col, ped per pixel) calibration database" 419 if (!theGainCalibrationDbInputOffline.put(detid, offlinerange,
ncols))
421 <<
"warning: detid already exists for Offline (gain per col, ped per pixel) calibration database" 423 if (!theGainCalibrationDbInputHLT.put(detid, hltrange,
ncols))
425 <<
"warning: detid already exists for HLT (pedestal and gain per column) calibration database" << std::endl;
433 size_t ncoldefault = 0;
435 for (
std::map<uint32_t, std::pair<TString, int> >::const_iterator ibad = badresults.begin(); ibad != badresults.end();
437 uint32_t detid = ibad->first;
438 if (badresults[detid].
second == 0) {
441 }
else if (badresults[detid].
second == 1) {
444 }
else if (badresults[detid].
second == 2) {
445 edm::LogPrint(
"SiPixelGainCalibrationReadDQMFile") << badresults[detid].first;
446 edm::LogPrint(
"SiPixelGainCalibrationReadDQMFile") <<
" has one or more dead pixels";
447 edm::LogPrint(
"SiPixelGainCalibrationReadDQMFile") << std::endl;
449 }
else if (badresults[detid].
second == 3) {
452 }
else if (badresults[detid].
second == 4) {
453 edm::LogPrint(
"SiPixelGainCalibrationReadDQMFile") << badresults[detid].first;
454 edm::LogPrint(
"SiPixelGainCalibrationReadDQMFile") <<
" has one or more dead columns";
456 edm::LogPrint(
"SiPixelGainCalibrationReadDQMFile") << std::endl;
460 << nempty <<
" modules were empty and now have pixels filled with default values." << std::endl;
462 << ndefault <<
" modules have pixels filled with default values." << std::endl;
463 edm::LogPrint(
"SiPixelGainCalibrationReadDQMFile") << ndead <<
" modules have pixels flagged as dead." << std::endl;
465 << ncoldefault <<
" modules have columns filled with default values." << std::endl;
467 << ncoldead <<
" modules have columns filled with dead values." << std::endl;
468 edm::LogPrint(
"SiPixelGainCalibrationReadDQMFile") <<
" ---> PIXEL Modules " << nmodules <<
"\n" 469 <<
" ---> PIXEL Channels " << nchannels << std::endl;
471 edm::LogPrint(
"SiPixelGainCalibrationReadDQMFile") <<
" --- writing to DB!" << std::endl;
477 if (
record_ ==
"SiPixelGainCalibrationForHLTRcd") {
479 <<
"now doing SiPixelGainCalibrationForHLTRcd payload..." << std::endl;
482 theGainCalibrationDbInputHLT, mydbservice->
beginOfTime(),
"SiPixelGainCalibrationForHLTRcd");
485 theGainCalibrationDbInputHLT, mydbservice->
currentTime(),
"SiPixelGainCalibrationForHLTRcd");
487 }
else if (
record_ ==
"SiPixelGainCalibrationOfflineRcd") {
489 <<
"now doing SiPixelGainCalibrationOfflineRcd payload..." << std::endl;
492 theGainCalibrationDbInputOffline, mydbservice->
beginOfTime(),
"SiPixelGainCalibrationOfflineRcd");
495 theGainCalibrationDbInputOffline, mydbservice->
currentTime(),
"SiPixelGainCalibrationOfflineRcd");
std::unique_ptr< TH2F > defaultGain_
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
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_
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_