File indexing completed on 2021-02-14 13:09:47
0001
0002
0003
0004
0005
0006
0007
0008 #include "DQM/DTMonitorModule/interface/DTTimeEvolutionHisto.h"
0009
0010 #include "DQMServices/Core/interface/DQMStore.h"
0011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0012
0013 using namespace std;
0014 using namespace edm;
0015
0016 DTTimeEvolutionHisto::DTTimeEvolutionHisto(DQMStore::IBooker& ibooker,
0017 const string& name,
0018 const string& title,
0019 int nbins,
0020 int lsPrescale,
0021 bool sliding,
0022 int mode)
0023 : DTTimeEvolutionHisto(ibooker, name, title, nbins, 1, lsPrescale, sliding, mode) {
0024 nBookedBins = histo->getNbinsX();
0025 }
0026
0027 DTTimeEvolutionHisto::DTTimeEvolutionHisto(DQMStore::IBooker& ibooker,
0028 const string& name,
0029 const string& title,
0030 int nbins,
0031 int firstLS,
0032 int lsPrescale,
0033 bool sliding,
0034 int mode)
0035 : valueLastTimeSlot(0), theFirstLS(firstLS), theLSPrescale(lsPrescale), doSlide(sliding), theMode(mode) {
0036
0037 nBookedBins = nbins;
0038 if (sliding)
0039 nBookedBins++;
0040 if (!sliding && theMode == 0)
0041 LogWarning("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
0042 << "[DTTimeEvolutionHisto]***Error: wrong configuration" << endl;
0043
0044 stringstream realTitle;
0045 realTitle << title << "/" << theLSPrescale << " LS";
0046
0047
0048
0049 histo = ibooker.book1D(name, realTitle.str(), nBookedBins, (float)theFirstLS, nBookedBins + 1.);
0050
0051
0052 if (sliding) {
0053 histo->setBinLabel(1, "avg. previous", 1);
0054 } else {
0055
0056
0057 for (int bin = 1; bin != nBookedBins + 1; ++bin) {
0058 stringstream label;
0059 if (theLSPrescale > 1) {
0060 label << "LS " << ((bin - 1) * theLSPrescale) + theFirstLS << "-" << bin * theLSPrescale + theFirstLS;
0061 } else {
0062 label << "LS " << ((bin - 1) * theLSPrescale) + theFirstLS;
0063 }
0064 if (bin % (2 * (int)theLSPrescale) == 0)
0065 histo->setBinLabel(bin, label.str(), 1);
0066 }
0067 }
0068 }
0069
0070
0071
0072
0073 DTTimeEvolutionHisto::DTTimeEvolutionHisto(MonitorElement* histoGot)
0074 : valueLastTimeSlot(0),
0075 theFirstLS(1),
0076 theLSPrescale(-1),
0077 doSlide(false),
0078 theMode(0) {
0079 LogVerbatim("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
0080 << "[DTTimeEvolutionHisto] Retrieve ME with name: "
0081 << " " << endl;
0082 histo = histoGot;
0083 }
0084
0085 DTTimeEvolutionHisto::~DTTimeEvolutionHisto() {}
0086
0087 void DTTimeEvolutionHisto::setTimeSlotValue(float value, int timeSlot) {
0088 if (!doSlide) {
0089 histo->Fill(timeSlot, value);
0090 } else {
0091 for (int bin = 1; bin != nBookedBins; ++bin) {
0092 float value = histo->getBinContent(bin);
0093
0094 if (bin == 1) {
0095 histo->setBinContent(bin, (value + histo->getBinContent(bin + 1)) / 2.);
0096 } else if (bin != nBookedBins) {
0097 histo->setBinContent(bin, histo->getBinContent(bin + 1));
0098 histo->setBinError(bin, histo->getBinError(bin + 1));
0099 histo->setBinLabel(bin, histo->getTH1F()->GetXaxis()->GetBinLabel(bin + 1), 1);
0100 }
0101 }
0102 histo->setBinContent(nBookedBins, value);
0103 }
0104 }
0105
0106 void DTTimeEvolutionHisto::accumulateValueTimeSlot(float value) { valueLastTimeSlot += value; }
0107
0108 void DTTimeEvolutionHisto::updateTimeSlot(int ls, int nEventsInLS) {
0109 if (doSlide) {
0110
0111 if (nEventsInLastTimeSlot.find(ls) != nEventsInLastTimeSlot.end()) {
0112 nEventsInLastTimeSlot[ls] += nEventsInLS;
0113 nLumiTrInLastTimeSlot[ls]++;
0114 } else {
0115 nEventsInLastTimeSlot[ls] = nEventsInLS;
0116 nLumiTrInLastTimeSlot[ls] = 1;
0117 }
0118
0119 if (!nEventsInLastTimeSlot.empty() &&
0120 nEventsInLastTimeSlot.size() % theLSPrescale == 0) {
0121 int firstLSinTimeSlot = nEventsInLastTimeSlot.begin()->first;
0122 int lastLSinTimeSlot = nEventsInLastTimeSlot.rbegin()->first;
0123
0124 map<int, int>::const_iterator nEventsIt = nEventsInLastTimeSlot.begin();
0125 map<int, int>::const_iterator nEventsEnd = nEventsInLastTimeSlot.end();
0126
0127 int nEvents = 0;
0128 for (; nEventsIt != nEventsEnd; ++nEventsIt)
0129 nEvents += nEventsIt->second;
0130
0131 LogVerbatim("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
0132 << "[DTTimeEvolutionHisto] Update time-slot, # entries: " << valueLastTimeSlot << " # events: " << nEvents
0133 << endl;
0134
0135
0136 float value = 0;
0137 if (theMode == 0) {
0138 if (nEvents != 0)
0139 value = valueLastTimeSlot / (float)nEvents;
0140 } else if (theMode == 1) {
0141 value = valueLastTimeSlot;
0142 } else if (theMode == 2) {
0143 value = nEvents;
0144 } else if (theMode == 3) {
0145 map<int, int>::const_iterator nLumiTrIt = nLumiTrInLastTimeSlot.begin();
0146 map<int, int>::const_iterator nLumiTrEnd = nLumiTrInLastTimeSlot.end();
0147
0148 float nLumiTr = 0.;
0149 for (; nLumiTrIt != nLumiTrEnd; ++nLumiTrIt)
0150 nLumiTr += nLumiTrIt->second;
0151
0152 value = valueLastTimeSlot / nLumiTr;
0153 }
0154 setTimeSlotValue(value, nBookedBins);
0155 LogVerbatim("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
0156 << " updated value: " << histo->getBinContent(nBookedBins) << endl;
0157
0158
0159 stringstream binLabel;
0160 binLabel << "LS " << firstLSinTimeSlot;
0161 if (nEventsInLastTimeSlot.size() > 1)
0162 binLabel << "-" << lastLSinTimeSlot;
0163
0164
0165 histo->setBinLabel(nBookedBins, binLabel.str(), 1);
0166
0167
0168 nEventsInLastTimeSlot.clear();
0169 nLumiTrInLastTimeSlot.clear();
0170 valueLastTimeSlot = 0;
0171 }
0172
0173 } else {
0174 int binN = (int)ls - (theFirstLS - 1) / (int)theLSPrescale;
0175
0176 float value = 0;
0177 if (theMode == 1) {
0178 value = valueLastTimeSlot;
0179 } else if (theMode == 2) {
0180 value = nEventsInLS;
0181 } else if (theMode == 3) {
0182 value = valueLastTimeSlot / theLSPrescale;
0183 }
0184 LogVerbatim("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
0185 << "[DTTimeEvolutionHisto] Update time-slot: " << binN << " with value: " << value << endl;
0186 setTimeSlotValue(value, binN);
0187 }
0188 }
0189
0190 void DTTimeEvolutionHisto::normalizeTo(const MonitorElement* histForNorm) {
0191 if (histo == nullptr) {
0192 LogWarning("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
0193 << "[DTTimeEvolutionHisto]***Error: pointer to ME is NULL" << endl;
0194 return;
0195 }
0196 int nBins = histo->getNbinsX();
0197 if (histForNorm->getNbinsX() != nBins) {
0198 LogWarning("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
0199 << "[DTTimeEvolutionHisto]***Error: normalizing histos with != # of bins" << endl;
0200 return;
0201 }
0202 for (int bin = 1; bin <= nBins; ++bin) {
0203 if (histForNorm->getBinContent(bin) != 0) {
0204 double normValue = histo->getBinContent(bin) / histForNorm->getBinContent(bin);
0205 LogVerbatim("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
0206 << "[DTTimeEvolutionHisto] Normalizing bin: " << bin << " to: " << histo->getBinContent(bin) << " / "
0207 << histForNorm->getBinContent(bin) << " = " << normValue << endl;
0208 histo->setBinContent(bin, normValue);
0209 } else {
0210 histo->setBinContent(bin, 0);
0211 }
0212 }
0213 }
0214
0215
0216
0217
0218