CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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) : valueLastTimeSlot(0),
24  theFirstLS(1),
25  theLSPrescale(lsPrescale),
26  doSlide(sliding),
27  theMode(mode) {
28 
29  DTTimeEvolutionHisto(dbe, name, title, nbins, theFirstLS, lsPrescale, sliding, mode);
30  histo = dbe->get(dbe->pwd() + "/" + name);
31  nBookedBins = histo->getNbinsX();
32 }
33 
34 
35 // DTTimeEvolutionHisto::DTTimeEvolutionHisto(DQMStore *dbe, const string& name,
36 // const string& title,
37 // int nbins,
38 // int lsPrescale,
39 // bool sliding,
40 // int mode) : valueLastTimeSlot(0),
41 // theLSPrescale(lsPrescale),
42 // doSlide(sliding),
43 // theMode(mode) {
44 // // set the number of bins to be booked
45 // nBookedBins = nbins;
46 // if(sliding) nBookedBins++;
47 // if(!sliding && theMode == 0)
48 // LogWarning("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
49 // << "[DTTimeEvolutionHisto]***Error: wrong configuration" << endl;
50 
51 
52 // stringstream realTitle; realTitle << title << "/" << theLSPrescale << " LS";
53 
54 // // book the ME
55 // histo = dbe->book1D(name, realTitle.str(), nBookedBins, 1., nBookedBins+1.);
56 
57 // // set the axis label
58 // if(sliding) {
59 // histo->setBinLabel(1,"avg. previous",1);
60 // } else {
61 // // loop over bins and
62 // for(int bin =1; bin != nBookedBins+1; ++bin) {
63 // stringstream label;
64 // if(theLSPrescale > 1) {
65 // label << "LS " << ((bin-1)*theLSPrescale)+1 << "-" << bin*theLSPrescale;
66 // } else {
67 // label << "LS " << ((bin-1)*theLSPrescale)+1;
68 // }
69 // histo->setBinLabel(bin, label.str(),1);
70 
71 // }
72 
73 // }
74 
75 // }
76 
77 
78 
79 
81  const string& title,
82  int nbins,
83  int firstLS,
84  int lsPrescale,
85  bool sliding,
86  int mode) : valueLastTimeSlot(0),
87  theFirstLS(firstLS),
88  theLSPrescale(lsPrescale),
89  doSlide(sliding),
90  theMode(mode) {
91  // set the number of bins to be booked
92  nBookedBins = nbins;
93  if(sliding) nBookedBins++;
94  if(!sliding && theMode == 0)
95  LogWarning("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
96  << "[DTTimeEvolutionHisto]***Error: wrong configuration" << endl;
97 
98 
99  stringstream realTitle; realTitle << title << "/" << theLSPrescale << " LS";
100 
101  // book the ME
102  histo = dbe->book1D(name, realTitle.str(), nBookedBins, (float)theFirstLS, nBookedBins+1.);
103 
104  // set the axis label
105  if(sliding) {
106  histo->setBinLabel(1,"avg. previous",1);
107  } else {
108  // loop over bins and
109  for(int bin =1; bin != nBookedBins+1; ++bin) {
110  stringstream label;
111  if(theLSPrescale > 1) {
112  label << "LS " << ((bin-1)*theLSPrescale)+theFirstLS << "-" << bin*theLSPrescale+theFirstLS;
113  } else {
114  label << "LS " << ((bin-1)*theLSPrescale)+theFirstLS;
115  }
116  histo->setBinLabel(bin, label.str(),1);
117 
118  }
119 
120  }
121 
122 }
123 
124 
125 
126 DTTimeEvolutionHisto::DTTimeEvolutionHisto(DQMStore *dbe, const string& name) : valueLastTimeSlot(0),
127  theFirstLS(1),
128  theLSPrescale(-1),
129  doSlide(false),
130  theMode(0) { // FIXME: set other memebers to sensible values
131  LogVerbatim("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
132  << "[DTTimeEvolutionHisto] Retrieve ME with name: " << name << endl;
133  histo = dbe->get(name);
134 }
135 
136 
138 
139 
140 
142  // LogVerbatim("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
143  // << "[DTTimeEvolutionHisto] ME name: " << histo->getName() << endl;
144  if(!doSlide) {
145  // LogVerbatim("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
146  // << " fill bin: " << timeSlot << " with value: " << value << endl;
147  histo->Fill(timeSlot,value);
148  } else {
149  for(int bin = 1; bin != nBookedBins; ++bin) {
150  float value = histo->getBinContent(bin);
151  // LogVerbatim("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
152  // << " bin: " << bin << " has value: " << value << endl;
153  if(bin == 1) { // average of previous time slots (fixme)
154  histo->setBinContent(bin, (value + histo->getBinContent(bin+1))/2.);
155  } else if(bin != nBookedBins) {
158  histo->setBinLabel(bin, histo->getTH1F()->GetXaxis()->GetBinLabel(bin+1),1);
159  }
160  }
162  }
163 }
164 
165 
168 }
169 
170 
171 
172 void DTTimeEvolutionHisto::updateTimeSlot(int ls, int nEventsInLS) {
173 
174  if(doSlide) { // sliding bins
175  // count LS in this time-slot
176  if (nEventsInLastTimeSlot.find(ls) != nEventsInLastTimeSlot.end()) {
177  nEventsInLastTimeSlot[ls] += nEventsInLS;
179  } else {
180  nEventsInLastTimeSlot[ls] = nEventsInLS;
182  }
183 
184 
185  if(nEventsInLastTimeSlot.size() > 0 && nEventsInLastTimeSlot.size()%theLSPrescale==0) { // update the value of the slot and reset the counters
186  int firstLSinTimeSlot = nEventsInLastTimeSlot.begin()->first;
187  int lastLSinTimeSlot = nEventsInLastTimeSlot.rbegin()->first;
188 
189  map<int,int>::const_iterator nEventsIt = nEventsInLastTimeSlot.begin();
190  map<int,int>::const_iterator nEventsEnd = nEventsInLastTimeSlot.end();
191 
192  int nEvents = 0;
193  for (;nEventsIt!=nEventsEnd;++nEventsIt)
194  nEvents+=nEventsIt->second;
195 
196  LogVerbatim("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
197  << "[DTTimeEvolutionHisto] Update time-slot, # entries: " << valueLastTimeSlot
198  << " # events: " << nEvents << endl;
199  // set the bin content
200 
201  float value = 0;
202  if(theMode == 0) {
203  if(nEvents != 0) value = valueLastTimeSlot/(float)nEvents;
204  } else if(theMode == 1) {
205  value = valueLastTimeSlot;
206  } else if(theMode == 2) {
207  value = nEvents;
208  } else if(theMode == 3) {
209  map<int,int>::const_iterator nLumiTrIt = nLumiTrInLastTimeSlot.begin();
210  map<int,int>::const_iterator nLumiTrEnd = nLumiTrInLastTimeSlot.end();
211 
212  float nLumiTr = 0.;
213  for (;nLumiTrIt!=nLumiTrEnd;++nLumiTrIt)
214  nLumiTr+=nLumiTrIt->second;
215 
216  value = valueLastTimeSlot/nLumiTr;
217  }
219  LogVerbatim("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
220  << " updated value: " << histo->getBinContent(nBookedBins) << endl;
221 
222  // set the bin label
223  stringstream binLabel;
224  binLabel << "LS " << firstLSinTimeSlot;
225  if(nEventsInLastTimeSlot.size() > 1)
226  binLabel << "-" << lastLSinTimeSlot;
227 
228  histo->setBinLabel(nBookedBins,binLabel.str(),1);
229 
230  // reset the counters for the time slot
231  nEventsInLastTimeSlot.clear();
232  nLumiTrInLastTimeSlot.clear();
233  valueLastTimeSlot = 0;
234  }
235 
236 
237  } else {
238  int binN = (int)ls-(theFirstLS-1)/(int)theLSPrescale;
239  // set the bin content
240  float value = 0;
241  if(theMode == 1) {
242  value = valueLastTimeSlot;
243  } else if(theMode == 2) {
244  value = nEventsInLS;
245  } else if(theMode == 3) {
247  }
248  LogVerbatim("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
249  << "[DTTimeEvolutionHisto] Update time-slot: "<< binN << " with value: " << value << endl;
250  setTimeSlotValue(value,binN);
251  }
252 }
253 
254 
255 
256 
258  if(histo == 0) {
259  LogWarning("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
260  << "[DTTimeEvolutionHisto]***Error: pointer to ME is NULL" << endl;
261  return;
262  }
263  int nBins = histo->getNbinsX();
264  if(histForNorm->getNbinsX() != nBins) {
265  LogWarning("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
266  << "[DTTimeEvolutionHisto]***Error: normalizing histos with != # of bins" << endl;
267  return;
268  }
269  for(int bin = 1; bin <= nBins; ++bin) { // loop over bins
270  if(histForNorm->getBinContent(bin) != 0) {
271  double normValue = histo->getBinContent(bin)/histForNorm->getBinContent(bin);
272  LogVerbatim("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
273  << "[DTTimeEvolutionHisto] Normalizing bin: " << bin << " to: " << histo->getBinContent(bin) << " / " << histForNorm->getBinContent(bin)
274  << " = " << normValue << endl;
275  histo->setBinContent(bin, normValue);
276  } else {
277  histo->setBinContent(bin, 0);
278  }
279  }
280 }
281 
282 // Local Variables:
283 // show-trailing-whitespace: t
284 // truncate-lines: t
285 // End:
void setBinContent(int binx, double content)
set content of bin (1-D)
void accumulateValueTimeSlot(float value)
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:872
std::map< int, int > nLumiTrInLastTimeSlot
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)
DTTimeEvolutionHisto(DQMStore *dbe, const std::string &name, const std::string &title, int nbins, int lsPrescale, bool sliding, int mode=0)
void Fill(long long x)
void setTimeSlotValue(float value, int timeSlot)
std::map< int, int > nEventsInLastTimeSlot
virtual ~DTTimeEvolutionHisto()
Destructor.
void setBinError(int binx, double error)
set uncertainty on content of bin (1-D)
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. &quot;my/long/dir/my_histo&quot;)
Definition: DQMStore.cc:1623
double getBinError(int binx) const
get uncertainty on content of bin (1-D) - See TH1::GetBinError for details
TH1F * getTH1F(void) const
void normalizeTo(const MonitorElement *histForNorm)
void updateTimeSlot(int ls, int nEventsInLS)
double getBinContent(int binx) const
get content of bin (1-D)
int getNbinsX(void) const
get # of bins in X-axis
volatile std::atomic< bool > shutdown_flag false
UInt_t nEvents
Definition: hcalCalib.cc:42
const std::string & pwd(void) const
Definition: DQMStore.cc:556