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
00021
00022 DTTimeEvolutionHisto::DTTimeEvolutionHisto(DQMStore *dbe, const string& name,
00023 const string& title,
00024 int nbins,
00025 int lsPrescale,
00026 bool sliding,
00027 int mode) : valueLastTimeSlot(0),
00028 nEventsInLastTimeSlot(0),
00029 theLSPrescale(lsPrescale),
00030 doSlide(sliding),
00031 nLSinTimeSlot(0),
00032 firstLSinTimeSlot(0),
00033 theMode(mode) {
00034
00035 nBookedBins = nbins;
00036 if(sliding) nBookedBins++;
00037 if(!sliding && theMode == 0)
00038 LogWarning("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
00039 << "[DTTimeEvolutionHisto]***Error: wrong configuration" << endl;
00040
00041
00042 stringstream realTitle; realTitle << title << "/" << theLSPrescale << " LS";
00043
00044
00045 histo = dbe->book1D(name, realTitle.str(), nBookedBins, 0, nBookedBins);
00046
00047
00048 if(sliding) {
00049 histo->setBinLabel(1,"avg. previous",1);
00050 } else {
00051
00052 for(int bin =1; bin != nBookedBins; ++bin) {
00053 stringstream label; label << "LS " << ((bin-1)*theLSPrescale)+1 << "-" << bin*theLSPrescale;
00054 histo->setBinLabel(bin, label.str(),1);
00055
00056 }
00057
00058 }
00059
00060 }
00061
00062
00063
00064
00065 DTTimeEvolutionHisto::DTTimeEvolutionHisto(DQMStore *dbe, const string& name) : valueLastTimeSlot(0),
00066 nEventsInLastTimeSlot(0),
00067 theLSPrescale(-1),
00068 doSlide(false),
00069 nLSinTimeSlot(0),
00070 firstLSinTimeSlot(0),
00071 theMode(0) {
00072 LogVerbatim("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
00073 << "[DTTimeEvolutionHisto] Retrieve ME with name: " << name << endl;
00074 histo = dbe->get(name);
00075 }
00076
00077
00078 DTTimeEvolutionHisto::~DTTimeEvolutionHisto(){}
00079
00080
00081
00082 void DTTimeEvolutionHisto::setTimeSlotValue(float value, int timeSlot) {
00083
00084
00085 if(!doSlide) {
00086
00087
00088 histo->Fill(timeSlot,value);
00089 } else {
00090 for(int bin = 1; bin != nBookedBins; ++bin) {
00091 float value = histo->getBinContent(bin);
00092
00093
00094 if(bin == 1) {
00095 histo->setBinContent(bin, (value + histo->getBinContent(bin+1))/2.);
00096 } else if(bin != nBookedBins) {
00097 histo->setBinContent(bin, histo->getBinContent(bin+1));
00098 histo->setBinLabel(bin, histo->getTH1F()->GetXaxis()->GetBinLabel(bin+1),1);
00099 }
00100 }
00101 histo->setBinContent(nBookedBins, value);
00102 }
00103 }
00104
00105
00106 void DTTimeEvolutionHisto::accumulateValueTimeSlot(float value) {
00107 valueLastTimeSlot += value;
00108 }
00109
00110
00111
00112 void DTTimeEvolutionHisto::updateTimeSlot(int ls, int nEventsInLS) {
00113
00114 if(doSlide) {
00115
00116 nLSinTimeSlot++;
00117 nEventsInLastTimeSlot += nEventsInLS;
00118
00119 if(nLSinTimeSlot == 1) firstLSinTimeSlot = ls;
00120
00121 if(nLSinTimeSlot%theLSPrescale ==0) {
00122 LogVerbatim("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
00123 << "[DTTimeEvolutionHisto] Update time-slot, # entries: " << valueLastTimeSlot
00124 << " # events: " << nEventsInLastTimeSlot << endl;
00125
00126 float value = 0;
00127 if(theMode == 0) {
00128 if(nEventsInLastTimeSlot != 0) value = valueLastTimeSlot/(float)nEventsInLastTimeSlot;
00129 } else if(theMode == 1) {
00130 value = valueLastTimeSlot;
00131 } else if(theMode == 2) {
00132 value = nEventsInLastTimeSlot;
00133 }
00134 setTimeSlotValue(value, nBookedBins);
00135 LogVerbatim("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
00136 << " updated value: " << histo->getBinContent(nBookedBins) << endl;
00137
00138
00139 stringstream binLabel; binLabel << "LS " << firstLSinTimeSlot;
00140 if(nLSinTimeSlot > 1) binLabel << "-" << ls;
00141 histo->setBinLabel(nBookedBins,binLabel.str(),1);
00142
00143
00144 nLSinTimeSlot = 0;
00145 nEventsInLastTimeSlot = 0;
00146 valueLastTimeSlot = 0;
00147 }
00148
00149
00150 } else {
00151 int binN = (int)ls/(int)theLSPrescale;
00152
00153 float value = 0;
00154 if(theMode == 1) {
00155 value = valueLastTimeSlot;
00156 } else if(theMode == 2) {
00157 value = nEventsInLS;
00158 }
00159 LogVerbatim("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
00160 << "[DTTimeEvolutionHisto] Update time-slot: "<< binN << " with value: " << value << endl;
00161 setTimeSlotValue(value,binN);
00162 }
00163 }
00164
00165
00166
00167
00168 void DTTimeEvolutionHisto::normalizeTo(const MonitorElement *histForNorm) {
00169 if(histo == 0) {
00170 LogWarning("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
00171 << "[DTTimeEvolutionHisto]***Error: pointer to ME is NULL" << endl;
00172 return;
00173 }
00174 int nBins = histo->getNbinsX();
00175 if(histForNorm->getNbinsX() != nBins) {
00176 LogWarning("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
00177 << "[DTTimeEvolutionHisto]***Error: normalizing histos with != # of bins" << endl;
00178 return;
00179 }
00180 for(int bin = 1; bin <= nBins; ++bin) {
00181 if(histForNorm->getBinContent(bin) != 0) {
00182 double normValue = histo->getBinContent(bin)/histForNorm->getBinContent(bin);
00183 LogVerbatim("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
00184 << "[DTTimeEvolutionHisto] Normalizing bin: " << bin << " to: " << histo->getBinContent(bin) << " / " << histForNorm->getBinContent(bin)
00185 << " = " << normValue << endl;
00186 histo->setBinContent(bin, normValue);
00187 } else {
00188 histo->setBinContent(bin, 0);
00189 }
00190 }
00191 }