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");
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();
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: " 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_) {
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());
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");
503 : appendMode_(iConfig.getUntrackedParameter<
bool>(
"appendMode",
true)),
505 theGainCalibrationDbInputService_(iConfig, consumesCollector()),
506 record_(iConfig.getUntrackedParameter<
std::
string>(
"record",
"SiPixelGainCalibrationOfflineRcd")),
511 usemeanwhenempty_(iConfig.getUntrackedParameter<
bool>(
"useMeanWhenEmpty",
false)),
512 rootfilestring_(iConfig.getUntrackedParameter<
std::
string>(
"inputrootfile",
"inputfile.root")),
515 badchi2_(iConfig.getUntrackedParameter<double>(
"badChi2Prob", 0.01)),
521 ::putenv((
char *)
"CORAL_AUTH_USER=me");
522 ::putenv((
char *)
"CORAL_AUTH_PASSWORD=test");
526 "default gain, contains mean",
534 "default pedestal, contains mean",
542 "default fitresult, contains '0'",
550 "default chi2 probability, contains '1'",
574 TDirectory *
dir = therootfile->GetDirectory(
"DQMData");
575 TList *list =
dir->GetListOfKeys();
577 TString comparestring =
"Module";
579 std::vector<TString> keylist;
580 std::vector<TString> hist2list;
581 std::vector<TString> dirlist;
582 std::vector<TString> notdonelist;
583 std::vector<int> nsubdirs;
586 for (ikey = 0; ikey < list->GetEntries(); ikey++) {
587 TKey *thekey = (TKey *)list->At(ikey);
588 if (thekey ==
nullptr)
590 TString keyname = thekey->GetName();
591 TString keytype = thekey->GetClassName();
595 if (keytype ==
"TDirectoryFile") {
602 list =
dir->GetListOfKeys();
603 if (
dirname.Contains(comparestring)) {
607 notdonelist.push_back(
dirname);
608 nsubdirs.push_back(-1);
613 while (nempty != notdonelist.size()) {
614 for (
size_t idir = 0; idir < notdonelist.size(); ++idir) {
615 if (nsubdirs[idir] == 0)
618 dir = therootfile->GetDirectory(notdonelist[idir]);
620 list =
dir->GetListOfKeys();
622 int ndirectories = 0;
623 for (ikey = 0; ikey < list->GetEntries(); ikey++) {
624 TKey *thekey = (TKey *)list->At(ikey);
625 if (thekey ==
nullptr)
627 TString keyname = thekey->GetName();
628 TString keytype = thekey->GetClassName();
630 if (keytype ==
"TDirectoryFile") {
636 if (
dirname.Contains(comparestring)) {
640 notdonelist.push_back(
dirname);
641 nsubdirs.push_back(-1);
645 nsubdirs[idir] = ndirectories;
649 for (
size_t i = 0;
i < nsubdirs.size();
i++) {
650 if (nsubdirs[
i] != -1)
656 for (
size_t idir = 0; idir < dirlist.size(); ++idir) {
661 dir = therootfile->GetDirectory(dirlist[idir]);
662 list =
dir->GetListOfKeys();
663 for (ikey = 0; ikey < list->GetEntries(); ikey++) {
664 TKey *thekey = (TKey *)list->At(ikey);
665 if (thekey ==
nullptr)
667 TString keyname = thekey->GetName();
668 TString keytype = thekey->GetClassName();
670 if (keytype ==
"TH2F" && (keyname.Contains(
"Gain2d") || keyname.Contains(
"Pedestal2d") ||
671 keyname.Contains(
"GainChi2Prob2d") || keyname.Contains(
"GainFitResult2d"))) {
672 TString detidstring = keyname;
673 detidstring.Remove(0, detidstring.Sizeof() - 10);
675 detid = atoi(detidstring.Data());
677 if (keyname.Contains(
"GainChi2Prob2d")) {
678 TString tempstr = dirlist[idir];
682 replacestring +=
":";
683 tempstr.ReplaceAll(replacestring,
"");
686 }
else if (keyname.Contains(
"GainFitResult2d")) {
687 TString tempstr = dirlist[idir];
691 replacestring +=
":";
692 tempstr.ReplaceAll(replacestring,
"");
695 }
else if (keyname.Contains(
"Gain2d")) {
697 std::map<std::string, TString> tempmap;
698 TString tempstr = dirlist[idir];
702 replacestring +=
":";
703 tempstr.ReplaceAll(replacestring,
"");
708 if (keyname.Contains(
"Pedestal2d")) {
710 std::map<std::string, TString> tempmap;
712 TString tempstr = dirlist[idir];
717 replacestring +=
":";
718 tempstr.ReplaceAll(replacestring,
"");
727 TH2F *temphistoped =
dynamic_cast<TH2F *
>(therootfile->Get(
bookkeeper_[detid][
"ped_2d"]));
728 TH2F *temphistogain =
dynamic_cast<TH2F *
>(therootfile->Get(
bookkeeper_[detid][
"gain_2d"]));
729 TH2F *temphistofitresult =
dynamic_cast<TH2F *
>(therootfile->Get(
bookkeeper_[detid][
"gain_2d"]));
731 for (
int xbin = 1; xbin <= temphistoped->GetNbinsX(); ++xbin) {
732 for (
int ybin = 1; ybin <= temphistoped->GetNbinsY(); ++ybin) {
733 if (temphistofitresult->GetBinContent(xbin, ybin) <= 0)
735 float val = temphistoped->GetBinContent(xbin, ybin);
746 for (
int xbin = 1; xbin <= temphistogain->GetNbinsX(); ++xbin) {
747 for (
int ybin = 1; ybin <= temphistogain->GetNbinsY(); ++ybin) {
748 if (temphistofitresult->GetBinContent(xbin, ybin) <= 0)
750 float val = temphistogain->GetBinContent(xbin, ybin);
static const std::string kSharedResource
std::unique_ptr< TH2F > defaultGain_
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
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)
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)