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  * $Date: 2011/06/10 13:23:26 $
6  * $Revision: 1.6 $
7  * \author G. Cerminara - INFN Torino
8  */
9 
11 
15 
16 using namespace std;
17 using namespace edm;
18 
19 
21  const string& title,
22  int nbins,
23  int lsPrescale,
24  bool sliding,
25  int mode) : valueLastTimeSlot(0),
26  theFirstLS(1),
27  theLSPrescale(lsPrescale),
28  doSlide(sliding),
29  theMode(mode) {
30 
31  DTTimeEvolutionHisto(dbe, name, title, nbins, theFirstLS, lsPrescale, sliding, mode);
32  histo = dbe->get(dbe->pwd() + "/" + name);
33  nBookedBins = histo->getNbinsX();
34 }
35 
36 
37 // DTTimeEvolutionHisto::DTTimeEvolutionHisto(DQMStore *dbe, const string& name,
38 // const string& title,
39 // int nbins,
40 // int lsPrescale,
41 // bool sliding,
42 // int mode) : valueLastTimeSlot(0),
43 // theLSPrescale(lsPrescale),
44 // doSlide(sliding),
45 // theMode(mode) {
46 // // set the number of bins to be booked
47 // nBookedBins = nbins;
48 // if(sliding) nBookedBins++;
49 // if(!sliding && theMode == 0)
50 // LogWarning("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
51 // << "[DTTimeEvolutionHisto]***Error: wrong configuration" << endl;
52 
53 
54 // stringstream realTitle; realTitle << title << "/" << theLSPrescale << " LS";
55 
56 // // book the ME
57 // histo = dbe->book1D(name, realTitle.str(), nBookedBins, 1., nBookedBins+1.);
58 
59 // // set the axis label
60 // if(sliding) {
61 // histo->setBinLabel(1,"avg. previous",1);
62 // } else {
63 // // loop over bins and
64 // for(int bin =1; bin != nBookedBins+1; ++bin) {
65 // stringstream label;
66 // if(theLSPrescale > 1) {
67 // label << "LS " << ((bin-1)*theLSPrescale)+1 << "-" << bin*theLSPrescale;
68 // } else {
69 // label << "LS " << ((bin-1)*theLSPrescale)+1;
70 // }
71 // histo->setBinLabel(bin, label.str(),1);
72 
73 // }
74 
75 // }
76 
77 // }
78 
79 
80 
81 
83  const string& title,
84  int nbins,
85  int firstLS,
86  int lsPrescale,
87  bool sliding,
88  int mode) : valueLastTimeSlot(0),
89  theFirstLS(firstLS),
90  theLSPrescale(lsPrescale),
91  doSlide(sliding),
92  theMode(mode) {
93  // set the number of bins to be booked
94  nBookedBins = nbins;
95  if(sliding) nBookedBins++;
96  if(!sliding && theMode == 0)
97  LogWarning("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
98  << "[DTTimeEvolutionHisto]***Error: wrong configuration" << endl;
99 
100 
101  stringstream realTitle; realTitle << title << "/" << theLSPrescale << " LS";
102 
103  // book the ME
104  histo = dbe->book1D(name, realTitle.str(), nBookedBins, (float)theFirstLS, nBookedBins+1.);
105 
106  // set the axis label
107  if(sliding) {
108  histo->setBinLabel(1,"avg. previous",1);
109  } else {
110  // loop over bins and
111  for(int bin =1; bin != nBookedBins+1; ++bin) {
112  stringstream label;
113  if(theLSPrescale > 1) {
114  label << "LS " << ((bin-1)*theLSPrescale)+theFirstLS << "-" << bin*theLSPrescale+theFirstLS;
115  } else {
116  label << "LS " << ((bin-1)*theLSPrescale)+theFirstLS;
117  }
118  histo->setBinLabel(bin, label.str(),1);
119 
120  }
121 
122  }
123 
124 }
125 
126 
127 
128 DTTimeEvolutionHisto::DTTimeEvolutionHisto(DQMStore *dbe, const string& name) : valueLastTimeSlot(0),
129  theFirstLS(1),
130  theLSPrescale(-1),
131  doSlide(false),
132  theMode(0) { // FIXME: set other memebers to sensible values
133  LogVerbatim("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
134  << "[DTTimeEvolutionHisto] Retrieve ME with name: " << name << endl;
135  histo = dbe->get(name);
136 }
137 
138 
140 
141 
142 
144  // LogVerbatim("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
145  // << "[DTTimeEvolutionHisto] ME name: " << histo->getName() << endl;
146  if(!doSlide) {
147  // LogVerbatim("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
148  // << " fill bin: " << timeSlot << " with value: " << value << endl;
149  histo->Fill(timeSlot,value);
150  } else {
151  for(int bin = 1; bin != nBookedBins; ++bin) {
152  float value = histo->getBinContent(bin);
153  // LogVerbatim("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
154  // << " bin: " << bin << " has value: " << value << endl;
155  if(bin == 1) { // average of previous time slots (fixme)
156  histo->setBinContent(bin, (value + histo->getBinContent(bin+1))/2.);
157  } else if(bin != nBookedBins) {
160  histo->setBinLabel(bin, histo->getTH1F()->GetXaxis()->GetBinLabel(bin+1),1);
161  }
162  }
164  }
165 }
166 
167 
170 }
171 
172 
173 
174 void DTTimeEvolutionHisto::updateTimeSlot(int ls, int nEventsInLS) {
175 
176  if(doSlide) { // sliding bins
177  // count LS in this time-slot
178  if (nEventsInLastTimeSlot.find(ls) != nEventsInLastTimeSlot.end()) {
179  nEventsInLastTimeSlot[ls] += nEventsInLS;
181  } else {
182  nEventsInLastTimeSlot[ls] = nEventsInLS;
184  }
185 
186 
187  if(nEventsInLastTimeSlot.size() > 0 && nEventsInLastTimeSlot.size()%theLSPrescale==0) { // update the value of the slot and reset the counters
188  int firstLSinTimeSlot = nEventsInLastTimeSlot.begin()->first;
189  int lastLSinTimeSlot = nEventsInLastTimeSlot.rbegin()->first;
190 
191  map<int,int>::const_iterator nEventsIt = nEventsInLastTimeSlot.begin();
192  map<int,int>::const_iterator nEventsEnd = nEventsInLastTimeSlot.end();
193 
194  int nEvents = 0;
195  for (;nEventsIt!=nEventsEnd;++nEventsIt)
196  nEvents+=nEventsIt->second;
197 
198  LogVerbatim("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
199  << "[DTTimeEvolutionHisto] Update time-slot, # entries: " << valueLastTimeSlot
200  << " # events: " << nEvents << endl;
201  // set the bin content
202 
203  float value = 0;
204  if(theMode == 0) {
205  if(nEvents != 0) value = valueLastTimeSlot/(float)nEvents;
206  } else if(theMode == 1) {
207  value = valueLastTimeSlot;
208  } else if(theMode == 2) {
209  value = nEvents;
210  } else if(theMode == 3) {
211  map<int,int>::const_iterator nLumiTrIt = nLumiTrInLastTimeSlot.begin();
212  map<int,int>::const_iterator nLumiTrEnd = nLumiTrInLastTimeSlot.end();
213 
214  float nLumiTr = 0.;
215  for (;nLumiTrIt!=nLumiTrEnd;++nLumiTrIt)
216  nLumiTr+=nLumiTrIt->second;
217 
218  value = valueLastTimeSlot/nLumiTr;
219  }
221  LogVerbatim("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
222  << " updated value: " << histo->getBinContent(nBookedBins) << endl;
223 
224  // set the bin label
225  stringstream binLabel;
226  binLabel << "LS " << firstLSinTimeSlot;
227  if(nEventsInLastTimeSlot.size() > 1)
228  binLabel << "-" << lastLSinTimeSlot;
229 
230  histo->setBinLabel(nBookedBins,binLabel.str(),1);
231 
232  // reset the counters for the time slot
233  nEventsInLastTimeSlot.clear();
234  nLumiTrInLastTimeSlot.clear();
235  valueLastTimeSlot = 0;
236  }
237 
238 
239  } else {
240  int binN = (int)ls-(theFirstLS-1)/(int)theLSPrescale;
241  // set the bin content
242  float value = 0;
243  if(theMode == 1) {
244  value = valueLastTimeSlot;
245  } else if(theMode == 2) {
246  value = nEventsInLS;
247  } else if(theMode == 3) {
249  }
250  LogVerbatim("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
251  << "[DTTimeEvolutionHisto] Update time-slot: "<< binN << " with value: " << value << endl;
252  setTimeSlotValue(value,binN);
253  }
254 }
255 
256 
257 
258 
260  if(histo == 0) {
261  LogWarning("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
262  << "[DTTimeEvolutionHisto]***Error: pointer to ME is NULL" << endl;
263  return;
264  }
265  int nBins = histo->getNbinsX();
266  if(histForNorm->getNbinsX() != nBins) {
267  LogWarning("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
268  << "[DTTimeEvolutionHisto]***Error: normalizing histos with != # of bins" << endl;
269  return;
270  }
271  for(int bin = 1; bin <= nBins; ++bin) { // loop over bins
272  if(histForNorm->getBinContent(bin) != 0) {
273  double normValue = histo->getBinContent(bin)/histForNorm->getBinContent(bin);
274  LogVerbatim("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
275  << "[DTTimeEvolutionHisto] Normalizing bin: " << bin << " to: " << histo->getBinContent(bin) << " / " << histForNorm->getBinContent(bin)
276  << " = " << normValue << endl;
277  histo->setBinContent(bin, normValue);
278  } else {
279  histo->setBinContent(bin, 0);
280  }
281  }
282 }
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:717
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:1468
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
UInt_t nEvents
Definition: hcalCalib.cc:43
const std::string & pwd(void) const
Definition: DQMStore.cc:401