CMS 3D CMS Logo

DTTimeEvolutionHisto.cc
Go to the documentation of this file.
1 
2 /*
3  * See header file for a description of this class.
4  *
5  * \author G. Cerminara - INFN Torino
6  */
7 
9 
13 
14 using namespace std;
15 using namespace edm;
16 
17 
19  const string& title,
20  int nbins,
21  int lsPrescale,
22  bool sliding,
23  int mode) :
24  DTTimeEvolutionHisto(ibooker, name, title, nbins, 1, lsPrescale, sliding, mode) {
25 
26  nBookedBins = histo->getNbinsX();
27 }
28 
29 
31  const string& title,
32  int nbins,
33  int firstLS,
34  int lsPrescale,
35  bool sliding,
36  int mode) : valueLastTimeSlot(0),
37  theFirstLS(firstLS),
38  theLSPrescale(lsPrescale),
39  doSlide(sliding),
40  theMode(mode) {
41  // set the number of bins to be booked
42  nBookedBins = nbins;
43  if(sliding) nBookedBins++;
44  if(!sliding && theMode == 0)
45  LogWarning("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
46  << "[DTTimeEvolutionHisto]***Error: wrong configuration" << endl;
47 
48  stringstream realTitle; realTitle << title << "/" << theLSPrescale << " LS";
49 
50  // book the ME
51 
52  histo = ibooker.book1D(name, realTitle.str(), nBookedBins, (float)theFirstLS, nBookedBins+1.);
53 
54  // set the axis label
55  if(sliding) {
56  histo->setBinLabel(1,"avg. previous",1);
57  } else {
58  // loop over bins and
59 
60  for(int bin =1; bin != nBookedBins+1; ++bin) {
61  stringstream label;
62  if(theLSPrescale > 1) {
63  label << "LS " << ((bin-1)*theLSPrescale)+theFirstLS << "-" << bin*theLSPrescale+theFirstLS;
64  } else {
65  label << "LS " << ((bin-1)*theLSPrescale)+theFirstLS;
66  }
67  if (bin%(2*(int)theLSPrescale)==0) histo->setBinLabel(bin, label.str(),1); //JF to allow easy reading of x-axis
68  }
69  }
70 }
71 
72 //FR changed previous constructor with 2 arguments:
73 //no igetter here!! so I get the histo from the client and just instanciate here a DTTimeEvolutionHisto
74 
75 DTTimeEvolutionHisto::DTTimeEvolutionHisto(MonitorElement* histoGot) : valueLastTimeSlot(0), theFirstLS(1),
76  theLSPrescale(-1),
77  doSlide(false),
78  theMode(0) { // FIXME: set other memebers to sensible values
79  LogVerbatim("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
80  << "[DTTimeEvolutionHisto] Retrieve ME with name: " << " "<< endl;
81  histo = histoGot;
82 }
83 
84 
86 
87 
88 
89 void DTTimeEvolutionHisto::setTimeSlotValue(float value, int timeSlot) {
90 
91  if(!doSlide) {
92 
93  histo->Fill(timeSlot,value);
94  } else {
95  for(int bin = 1; bin != nBookedBins; ++bin) {
96  float value = histo->getBinContent(bin);
97 
98  if(bin == 1) { // average of previous time slots (fixme)
99  histo->setBinContent(bin, (value + histo->getBinContent(bin+1))/2.);
100  } else if(bin != nBookedBins) {
103  histo->setBinLabel(bin, histo->getTH1F()->GetXaxis()->GetBinLabel(bin+1),1);
104  }
105  }
107  }
108 }
109 
110 
113 }
114 
115 
116 
117 void DTTimeEvolutionHisto::updateTimeSlot(int ls, int nEventsInLS) {
118 
119  if(doSlide) { // sliding bins
120  // count LS in this time-slot
121  if (nEventsInLastTimeSlot.find(ls) != nEventsInLastTimeSlot.end()) {
122  nEventsInLastTimeSlot[ls] += nEventsInLS;
124  } else {
125  nEventsInLastTimeSlot[ls] = nEventsInLS;
127  }
128 
129 
130  if(!nEventsInLastTimeSlot.empty() && nEventsInLastTimeSlot.size()%theLSPrescale==0) { // update the value of the slot and reset the counters
131  int firstLSinTimeSlot = nEventsInLastTimeSlot.begin()->first;
132  int lastLSinTimeSlot = nEventsInLastTimeSlot.rbegin()->first;
133 
134  map<int,int>::const_iterator nEventsIt = nEventsInLastTimeSlot.begin();
135  map<int,int>::const_iterator nEventsEnd = nEventsInLastTimeSlot.end();
136 
137  int nEvents = 0;
138  for (;nEventsIt!=nEventsEnd;++nEventsIt)
139  nEvents+=nEventsIt->second;
140 
141  LogVerbatim("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
142  << "[DTTimeEvolutionHisto] Update time-slot, # entries: " << valueLastTimeSlot
143  << " # events: " << nEvents << endl;
144  // set the bin content
145 
146  float value = 0;
147  if(theMode == 0) {
148  if(nEvents != 0) value = valueLastTimeSlot/(float)nEvents;
149  } else if(theMode == 1) {
150  value = valueLastTimeSlot;
151  } else if(theMode == 2) {
152  value = nEvents;
153  } else if(theMode == 3) {
154  map<int,int>::const_iterator nLumiTrIt = nLumiTrInLastTimeSlot.begin();
155  map<int,int>::const_iterator nLumiTrEnd = nLumiTrInLastTimeSlot.end();
156 
157  float nLumiTr = 0.;
158  for (;nLumiTrIt!=nLumiTrEnd;++nLumiTrIt)
159  nLumiTr+=nLumiTrIt->second;
160 
161  value = valueLastTimeSlot/nLumiTr;
162  }
164  LogVerbatim("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
165  << " updated value: " << histo->getBinContent(nBookedBins) << endl;
166 
167  // set the bin label
168  stringstream binLabel;
169  binLabel << "LS " << firstLSinTimeSlot;
170  if(nEventsInLastTimeSlot.size() > 1)
171  binLabel << "-" << lastLSinTimeSlot;
172 
173  //if(lastLSinTimeSlot%(3*(int)theLSPrescale)==0)
174  histo->setBinLabel(nBookedBins,binLabel.str(),1);
175 
176  // reset the counters for the time slot
177  nEventsInLastTimeSlot.clear();
178  nLumiTrInLastTimeSlot.clear();
179  valueLastTimeSlot = 0;
180  }
181 
182 
183  } else {
184  int binN = (int)ls-(theFirstLS-1)/(int)theLSPrescale;
185  // set the bin content
186  float value = 0;
187  if(theMode == 1) {
188  value = valueLastTimeSlot;
189  } else if(theMode == 2) {
190  value = nEventsInLS;
191  } else if(theMode == 3) {
193  }
194  LogVerbatim("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
195  << "[DTTimeEvolutionHisto] Update time-slot: "<< binN << " with value: " << value << endl;
196  setTimeSlotValue(value,binN);
197  }
198 }
199 
200 
201 
202 
204  if(histo == nullptr) {
205  LogWarning("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
206  << "[DTTimeEvolutionHisto]***Error: pointer to ME is NULL" << endl;
207  return;
208  }
209  int nBins = histo->getNbinsX();
210  if(histForNorm->getNbinsX() != nBins) {
211  LogWarning("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
212  << "[DTTimeEvolutionHisto]***Error: normalizing histos with != # of bins" << endl;
213  return;
214  }
215  for(int bin = 1; bin <= nBins; ++bin) { // loop over bins
216  if(histForNorm->getBinContent(bin) != 0) {
217  double normValue = histo->getBinContent(bin)/histForNorm->getBinContent(bin);
218  LogVerbatim("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
219  << "[DTTimeEvolutionHisto] Normalizing bin: " << bin << " to: " << histo->getBinContent(bin) << " / " << histForNorm->getBinContent(bin)
220  << " = " << normValue << endl;
221  histo->setBinContent(bin, normValue);
222  } else {
223  histo->setBinContent(bin, 0);
224  }
225  }
226 }
227 
228 // Local Variables:
229 // show-trailing-whitespace: t
230 // truncate-lines: t
231 // End:
void setBinContent(int binx, double content)
set content of bin (1-D)
void accumulateValueTimeSlot(float value)
std::map< int, int > nLumiTrInLastTimeSlot
TH1F * getTH1F() const
DTTimeEvolutionHisto(DQMStore::IBooker &ibooker, const std::string &name, const std::string &title, int nbins, int lsPrescale, bool sliding, int mode=0)
void setBinLabel(int bin, const std::string &label, int axis=1)
set bin label for x, y or z axis (axis=1, 2, 3 respectively)
void Fill(long long x)
void setTimeSlotValue(float value, int timeSlot)
std::map< int, int > nEventsInLastTimeSlot
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:106
virtual ~DTTimeEvolutionHisto()
Destructor.
void setBinError(int binx, double error)
set uncertainty on content of bin (1-D)
Definition: value.py:1
bin
set the eta bin as selection string.
def ls(path, rec=False)
Definition: eostools.py:349
double getBinError(int binx) const
get uncertainty on content of bin (1-D) - See TH1::GetBinError for details
void normalizeTo(const MonitorElement *histForNorm)
void updateTimeSlot(int ls, int nEventsInLS)
double getBinContent(int binx) const
get content of bin (1-D)
HLT enums.
int getNbinsX() const
get # of bins in X-axis
UInt_t nEvents
Definition: hcalCalib.cc:42