46 #include "TDirectory.h" 68 std::map<uint32_t, std::map<std::string, TString> >
bookkeeper_;
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();
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: " 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_) {
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());
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");
524 : appendMode_(iConfig.getUntrackedParameter<
bool>(
"appendMode",
true)),
526 theGainCalibrationDbInputService_(iConfig, consumesCollector()),
527 record_(iConfig.getUntrackedParameter<
std::
string>(
"record",
"SiPixelGainCalibrationOfflineRcd")),
532 usemeanwhenempty_(iConfig.getUntrackedParameter<
bool>(
"useMeanWhenEmpty",
false)),
533 rootfilestring_(iConfig.getUntrackedParameter<
std::
string>(
"inputrootfile",
"inputfile.root")),
536 badchi2_(iConfig.getUntrackedParameter<double>(
"badChi2Prob", 0.01)),
542 ::putenv((
char *)
"CORAL_AUTH_USER=me");
543 ::putenv((
char *)
"CORAL_AUTH_PASSWORD=test");
547 "default gain, contains mean",
555 "default pedestal, contains mean",
563 "default fitresult, contains '0'",
571 "default chi2 probability, contains '1'",
595 TDirectory *
dir = therootfile->GetDirectory(
"DQMData");
596 TList *list =
dir->GetListOfKeys();
598 TString comparestring =
"Module";
600 std::vector<TString> keylist;
601 std::vector<TString> hist2list;
602 std::vector<TString> dirlist;
603 std::vector<TString> notdonelist;
604 std::vector<int> nsubdirs;
607 for (ikey = 0; ikey < list->GetEntries(); ikey++) {
608 TKey *thekey = (TKey *)list->At(ikey);
609 if (thekey ==
nullptr)
611 TString keyname = thekey->GetName();
612 TString keytype = thekey->GetClassName();
616 if (keytype ==
"TDirectoryFile") {
623 list =
dir->GetListOfKeys();
624 if (
dirname.Contains(comparestring)) {
628 notdonelist.push_back(
dirname);
629 nsubdirs.push_back(-1);
634 while (nempty != notdonelist.size()) {
635 for (
size_t idir = 0; idir < notdonelist.size(); ++idir) {
636 if (nsubdirs[idir] == 0)
639 dir = therootfile->GetDirectory(notdonelist[idir]);
641 list =
dir->GetListOfKeys();
643 int ndirectories = 0;
644 for (ikey = 0; ikey < list->GetEntries(); ikey++) {
645 TKey *thekey = (TKey *)list->At(ikey);
646 if (thekey ==
nullptr)
648 TString keyname = thekey->GetName();
649 TString keytype = thekey->GetClassName();
651 if (keytype ==
"TDirectoryFile") {
657 if (
dirname.Contains(comparestring)) {
661 notdonelist.push_back(
dirname);
662 nsubdirs.push_back(-1);
666 nsubdirs[idir] = ndirectories;
670 for (
size_t i = 0;
i < nsubdirs.size();
i++) {
671 if (nsubdirs[
i] != -1)
677 for (
size_t idir = 0; idir < dirlist.size(); ++idir) {
682 dir = therootfile->GetDirectory(dirlist[idir]);
683 list =
dir->GetListOfKeys();
684 for (ikey = 0; ikey < list->GetEntries(); ikey++) {
685 TKey *thekey = (TKey *)list->At(ikey);
686 if (thekey ==
nullptr)
688 TString keyname = thekey->GetName();
689 TString keytype = thekey->GetClassName();
691 if (keytype ==
"TH2F" && (keyname.Contains(
"Gain2d") || keyname.Contains(
"Pedestal2d") ||
692 keyname.Contains(
"GainChi2Prob2d") || keyname.Contains(
"GainFitResult2d"))) {
693 TString detidstring = keyname;
694 detidstring.Remove(0, detidstring.Sizeof() - 10);
696 detid = atoi(detidstring.Data());
698 if (keyname.Contains(
"GainChi2Prob2d")) {
699 TString tempstr = dirlist[idir];
703 replacestring +=
":";
704 tempstr.ReplaceAll(replacestring,
"");
707 }
else if (keyname.Contains(
"GainFitResult2d")) {
708 TString tempstr = dirlist[idir];
712 replacestring +=
":";
713 tempstr.ReplaceAll(replacestring,
"");
716 }
else if (keyname.Contains(
"Gain2d")) {
718 std::map<std::string, TString> tempmap;
719 TString tempstr = dirlist[idir];
723 replacestring +=
":";
724 tempstr.ReplaceAll(replacestring,
"");
729 if (keyname.Contains(
"Pedestal2d")) {
731 std::map<std::string, TString> tempmap;
733 TString tempstr = dirlist[idir];
738 replacestring +=
":";
739 tempstr.ReplaceAll(replacestring,
"");
748 TH2F *temphistoped =
dynamic_cast<TH2F *
>(therootfile->Get(
bookkeeper_[detid][
"ped_2d"]));
749 TH2F *temphistogain =
dynamic_cast<TH2F *
>(therootfile->Get(
bookkeeper_[detid][
"gain_2d"]));
750 TH2F *temphistofitresult =
dynamic_cast<TH2F *
>(therootfile->Get(
bookkeeper_[detid][
"gain_2d"]));
752 for (
int xbin = 1; xbin <= temphistoped->GetNbinsX(); ++xbin) {
753 for (
int ybin = 1; ybin <= temphistoped->GetNbinsY(); ++ybin) {
754 if (temphistofitresult->GetBinContent(xbin, ybin) <= 0)
756 float val = temphistoped->GetBinContent(xbin, ybin);
767 for (
int xbin = 1; xbin <= temphistogain->GetNbinsX(); ++xbin) {
768 for (
int ybin = 1; ybin <= temphistogain->GetNbinsY(); ++ybin) {
769 if (temphistofitresult->GetBinContent(xbin, ybin) <= 0)
771 float val = temphistogain->GetBinContent(xbin, ybin);
static const std::string kSharedResource
std::unique_ptr< TH2F > defaultGain_
bool put(const uint32_t &detID, Range input, const int &nCols)
void setDeadPixel(std::vector< char > &vped)
void analyze(const edm::Event &, const edm::EventSetup &) final
const std::string rootfilestring_
void setData(float ped, float gain, std::vector< char > &vped, bool thisColumnIsDead=false, bool thisColumnIsNoisy=false)
virtual int ncolumns() const =0
cond::Time_t beginOfTime() const
const std::string record_
void setDataPedestal(float pedestal, std::vector< char > &vped, bool thisPixelIsDead=false, bool thisPixelIsNoisy=false)
unsigned int getNumberOfRowsToAverageOver() const
virtual int nrows() const =0
const DetContainer & dets() const override
Returm a vector of all GeomDet (including all GeomDetUnits)
unsigned int getNumberOfRowsToAverageOver() const
Log< level::Error, false > LogError
std::pair< ContainerIterator, ContainerIterator > Range
void setDataGain(float gain, const int &nRows, std::vector< char > &vped, bool thisColumnIsDead=false, bool thisColumnIsNoisy=false)
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
SiPixelGainCalibrationService theGainCalibrationDbInputService_
std::unique_ptr< TH2F > defaultPed_
std::map< uint32_t, std::map< double, double > > Meankeeper_
std::unique_ptr< TH1F > meanPedHist_
#define DEFINE_FWK_MODULE(type)
bool getData(T &iHolder) const
Log< level::Warning, true > LogPrint
void setDeadPixel(std::vector< char > &vped)
constexpr float gains[NGAINS]
Log< level::Info, false > LogInfo
void fillDatabase(const edm::EventSetup &iSetup, TFile *)
bool put(const uint32_t &detID, Range input, const int &nCols)
std::unique_ptr< TFile > getHistograms()
std::map< uint32_t, std::vector< std::map< int, int > > > noisyPixelsKeeper_
std::map< uint32_t, std::map< std::string, TString > > bookkeeper_
void setDeadColumn(const int &nRows, std::vector< char > &vped)
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_
void setData(float ped, float gain, std::vector< char > &vped, bool thisPixelIsDead=false, bool thisPixelIsNoisy=false)
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > pddToken_
SiPixelGainCalibrationReadDQMFile(const edm::ParameterSet &)
bool put(const uint32_t &detID, Range input, const int &nCols)
void setDeadColumn(const int &nRows, std::vector< char > &vped)