00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "DQM/DTMonitorModule/interface/DTTimeEvolutionHisto.h"
00011
00012 #include "DQMServices/Core/interface/DQMStore.h"
00013 #include "DQMServices/Core/interface/MonitorElement.h"
00014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00015
00016 using namespace std;
00017 using namespace edm;
00018
00019
00020 DTTimeEvolutionHisto::DTTimeEvolutionHisto(DQMStore *dbe, const string& name,
00021 const string& title,
00022 int nbins,
00023 int lsPrescale,
00024 bool sliding,
00025 int mode) : valueLastTimeSlot(0),
00026 nEventsInLastTimeSlot(0),
00027 theFirstLS(1),
00028 theLSPrescale(lsPrescale),
00029 doSlide(sliding),
00030 nLSinTimeSlot(0),
00031 firstLSinTimeSlot(0),
00032 theMode(mode) {
00033
00034 DTTimeEvolutionHisto(dbe, name, title, nbins, theFirstLS, lsPrescale, sliding, mode);
00035 histo = dbe->get(dbe->pwd() + "/" + name);
00036 nBookedBins = histo->getNbinsX();
00037 }
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088 DTTimeEvolutionHisto::DTTimeEvolutionHisto(DQMStore *dbe, const string& name,
00089 const string& title,
00090 int nbins,
00091 int firstLS,
00092 int lsPrescale,
00093 bool sliding,
00094 int mode) : valueLastTimeSlot(0),
00095 nEventsInLastTimeSlot(0),
00096 theFirstLS(firstLS),
00097 theLSPrescale(lsPrescale),
00098 doSlide(sliding),
00099 nLSinTimeSlot(0),
00100 firstLSinTimeSlot(0),
00101 theMode(mode) {
00102
00103 nBookedBins = nbins;
00104 if(sliding) nBookedBins++;
00105 if(!sliding && theMode == 0)
00106 LogWarning("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
00107 << "[DTTimeEvolutionHisto]***Error: wrong configuration" << endl;
00108
00109
00110 stringstream realTitle; realTitle << title << "/" << theLSPrescale << " LS";
00111
00112
00113 histo = dbe->book1D(name, realTitle.str(), nBookedBins, (float)theFirstLS, nBookedBins+1.);
00114
00115
00116 if(sliding) {
00117 histo->setBinLabel(1,"avg. previous",1);
00118 } else {
00119
00120 for(int bin =1; bin != nBookedBins+1; ++bin) {
00121 stringstream label;
00122 if(theLSPrescale > 1) {
00123 label << "LS " << ((bin-1)*theLSPrescale)+theFirstLS << "-" << bin*theLSPrescale+theFirstLS;
00124 } else {
00125 label << "LS " << ((bin-1)*theLSPrescale)+theFirstLS;
00126 }
00127 histo->setBinLabel(bin, label.str(),1);
00128
00129 }
00130
00131 }
00132
00133 }
00134
00135
00136
00137 DTTimeEvolutionHisto::DTTimeEvolutionHisto(DQMStore *dbe, const string& name) : valueLastTimeSlot(0),
00138 nEventsInLastTimeSlot(0),
00139 theFirstLS(1),
00140 theLSPrescale(-1),
00141 doSlide(false),
00142 nLSinTimeSlot(0),
00143 firstLSinTimeSlot(0),
00144 theMode(0) {
00145 LogVerbatim("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
00146 << "[DTTimeEvolutionHisto] Retrieve ME with name: " << name << endl;
00147 histo = dbe->get(name);
00148 }
00149
00150
00151 DTTimeEvolutionHisto::~DTTimeEvolutionHisto(){}
00152
00153
00154
00155 void DTTimeEvolutionHisto::setTimeSlotValue(float value, int timeSlot) {
00156
00157
00158 if(!doSlide) {
00159
00160
00161 histo->Fill(timeSlot,value);
00162 } else {
00163 for(int bin = 1; bin != nBookedBins; ++bin) {
00164 float value = histo->getBinContent(bin);
00165
00166
00167 if(bin == 1) {
00168 histo->setBinContent(bin, (value + histo->getBinContent(bin+1))/2.);
00169 } else if(bin != nBookedBins) {
00170 histo->setBinContent(bin, histo->getBinContent(bin+1));
00171 histo->setBinError(bin, histo->getBinError(bin+1));
00172 histo->setBinLabel(bin, histo->getTH1F()->GetXaxis()->GetBinLabel(bin+1),1);
00173 }
00174 }
00175 histo->setBinContent(nBookedBins, value);
00176 }
00177 }
00178
00179
00180 void DTTimeEvolutionHisto::accumulateValueTimeSlot(float value) {
00181 valueLastTimeSlot += value;
00182 }
00183
00184
00185
00186 void DTTimeEvolutionHisto::updateTimeSlot(int ls, int nEventsInLS) {
00187
00188 if(doSlide) {
00189
00190 nLSinTimeSlot++;
00191 nEventsInLastTimeSlot += nEventsInLS;
00192
00193 if(nLSinTimeSlot == 1) firstLSinTimeSlot = ls;
00194
00195 if(nLSinTimeSlot%theLSPrescale ==0) {
00196 LogVerbatim("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
00197 << "[DTTimeEvolutionHisto] Update time-slot, # entries: " << valueLastTimeSlot
00198 << " # events: " << nEventsInLastTimeSlot << endl;
00199
00200 float value = 0;
00201 if(theMode == 0) {
00202 if(nEventsInLastTimeSlot != 0) value = valueLastTimeSlot/(float)nEventsInLastTimeSlot;
00203 } else if(theMode == 1) {
00204 value = valueLastTimeSlot;
00205 } else if(theMode == 2) {
00206 value = nEventsInLastTimeSlot;
00207 } else if(theMode == 3) {
00208 value = valueLastTimeSlot/theLSPrescale;
00209 }
00210 setTimeSlotValue(value, nBookedBins);
00211 LogVerbatim("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
00212 << " updated value: " << histo->getBinContent(nBookedBins) << endl;
00213
00214
00215 stringstream binLabel; binLabel << "LS " << firstLSinTimeSlot;
00216 if(nLSinTimeSlot > 1) binLabel << "-" << ls;
00217 histo->setBinLabel(nBookedBins,binLabel.str(),1);
00218
00219
00220 nLSinTimeSlot = 0;
00221 nEventsInLastTimeSlot = 0;
00222 valueLastTimeSlot = 0;
00223 }
00224
00225
00226 } else {
00227 int binN = (int)ls-(theFirstLS-1)/(int)theLSPrescale;
00228
00229 float value = 0;
00230 if(theMode == 1) {
00231 value = valueLastTimeSlot;
00232 } else if(theMode == 2) {
00233 value = nEventsInLS;
00234 } else if(theMode == 3) {
00235 value = valueLastTimeSlot/theLSPrescale;
00236 }
00237 LogVerbatim("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
00238 << "[DTTimeEvolutionHisto] Update time-slot: "<< binN << " with value: " << value << endl;
00239 setTimeSlotValue(value,binN);
00240 }
00241 }
00242
00243
00244
00245
00246 void DTTimeEvolutionHisto::normalizeTo(const MonitorElement *histForNorm) {
00247 if(histo == 0) {
00248 LogWarning("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
00249 << "[DTTimeEvolutionHisto]***Error: pointer to ME is NULL" << endl;
00250 return;
00251 }
00252 int nBins = histo->getNbinsX();
00253 if(histForNorm->getNbinsX() != nBins) {
00254 LogWarning("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
00255 << "[DTTimeEvolutionHisto]***Error: normalizing histos with != # of bins" << endl;
00256 return;
00257 }
00258 for(int bin = 1; bin <= nBins; ++bin) {
00259 if(histForNorm->getBinContent(bin) != 0) {
00260 double normValue = histo->getBinContent(bin)/histForNorm->getBinContent(bin);
00261 LogVerbatim("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
00262 << "[DTTimeEvolutionHisto] Normalizing bin: " << bin << " to: " << histo->getBinContent(bin) << " / " << histForNorm->getBinContent(bin)
00263 << " = " << normValue << endl;
00264 histo->setBinContent(bin, normValue);
00265 } else {
00266 histo->setBinContent(bin, 0);
00267 }
00268 }
00269 }