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: 2010/01/19 10:05:31 $
6  * $Revision: 1.4 $
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  nEventsInLastTimeSlot(0),
27  theFirstLS(1),
28  theLSPrescale(lsPrescale),
29  doSlide(sliding),
30  nLSinTimeSlot(0),
31  firstLSinTimeSlot(0),
32  theMode(mode) {
33 
34  DTTimeEvolutionHisto(dbe, name, title, nbins, theFirstLS, lsPrescale, sliding, mode);
35  histo = dbe->get(dbe->pwd() + "/" + name);
36  nBookedBins = histo->getNbinsX();
37 }
38 
39 
40 // DTTimeEvolutionHisto::DTTimeEvolutionHisto(DQMStore *dbe, const string& name,
41 // const string& title,
42 // int nbins,
43 // int lsPrescale,
44 // bool sliding,
45 // int mode) : valueLastTimeSlot(0),
46 // nEventsInLastTimeSlot(0),
47 // theLSPrescale(lsPrescale),
48 // doSlide(sliding),
49 // nLSinTimeSlot(0),
50 // firstLSinTimeSlot(0),
51 // theMode(mode) {
52 // // set the number of bins to be booked
53 // nBookedBins = nbins;
54 // if(sliding) nBookedBins++;
55 // if(!sliding && theMode == 0)
56 // LogWarning("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
57 // << "[DTTimeEvolutionHisto]***Error: wrong configuration" << endl;
58 
59 
60 // stringstream realTitle; realTitle << title << "/" << theLSPrescale << " LS";
61 
62 // // book the ME
63 // histo = dbe->book1D(name, realTitle.str(), nBookedBins, 1., nBookedBins+1.);
64 
65 // // set the axis label
66 // if(sliding) {
67 // histo->setBinLabel(1,"avg. previous",1);
68 // } else {
69 // // loop over bins and
70 // for(int bin =1; bin != nBookedBins+1; ++bin) {
71 // stringstream label;
72 // if(theLSPrescale > 1) {
73 // label << "LS " << ((bin-1)*theLSPrescale)+1 << "-" << bin*theLSPrescale;
74 // } else {
75 // label << "LS " << ((bin-1)*theLSPrescale)+1;
76 // }
77 // histo->setBinLabel(bin, label.str(),1);
78 
79 // }
80 
81 // }
82 
83 // }
84 
85 
86 
87 
89  const string& title,
90  int nbins,
91  int firstLS,
92  int lsPrescale,
93  bool sliding,
94  int mode) : valueLastTimeSlot(0),
95  nEventsInLastTimeSlot(0),
96  theFirstLS(firstLS),
97  theLSPrescale(lsPrescale),
98  doSlide(sliding),
99  nLSinTimeSlot(0),
100  firstLSinTimeSlot(0),
101  theMode(mode) {
102  // set the number of bins to be booked
103  nBookedBins = nbins;
104  if(sliding) nBookedBins++;
105  if(!sliding && theMode == 0)
106  LogWarning("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
107  << "[DTTimeEvolutionHisto]***Error: wrong configuration" << endl;
108 
109 
110  stringstream realTitle; realTitle << title << "/" << theLSPrescale << " LS";
111 
112  // book the ME
113  histo = dbe->book1D(name, realTitle.str(), nBookedBins, (float)theFirstLS, nBookedBins+1.);
114 
115  // set the axis label
116  if(sliding) {
117  histo->setBinLabel(1,"avg. previous",1);
118  } else {
119  // loop over bins and
120  for(int bin =1; bin != nBookedBins+1; ++bin) {
121  stringstream label;
122  if(theLSPrescale > 1) {
123  label << "LS " << ((bin-1)*theLSPrescale)+theFirstLS << "-" << bin*theLSPrescale+theFirstLS;
124  } else {
125  label << "LS " << ((bin-1)*theLSPrescale)+theFirstLS;
126  }
127  histo->setBinLabel(bin, label.str(),1);
128 
129  }
130 
131  }
132 
133 }
134 
135 
136 
137 DTTimeEvolutionHisto::DTTimeEvolutionHisto(DQMStore *dbe, const string& name) : valueLastTimeSlot(0),
138  nEventsInLastTimeSlot(0),
139  theFirstLS(1),
140  theLSPrescale(-1),
141  doSlide(false),
142  nLSinTimeSlot(0),
143  firstLSinTimeSlot(0),
144  theMode(0) { // FIXME: set other memebers to sensible values
145  LogVerbatim("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
146  << "[DTTimeEvolutionHisto] Retrieve ME with name: " << name << endl;
147  histo = dbe->get(name);
148 }
149 
150 
152 
153 
154 
156  // LogVerbatim("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
157  // << "[DTTimeEvolutionHisto] ME name: " << histo->getName() << endl;
158  if(!doSlide) {
159  // LogVerbatim("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
160  // << " fill bin: " << timeSlot << " with value: " << value << endl;
161  histo->Fill(timeSlot,value);
162  } else {
163  for(int bin = 1; bin != nBookedBins; ++bin) {
164  float value = histo->getBinContent(bin);
165  // LogVerbatim("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
166  // << " bin: " << bin << " has value: " << value << endl;
167  if(bin == 1) { // average of previous time slots (fixme)
168  histo->setBinContent(bin, (value + histo->getBinContent(bin+1))/2.);
169  } else if(bin != nBookedBins) {
172  histo->setBinLabel(bin, histo->getTH1F()->GetXaxis()->GetBinLabel(bin+1),1);
173  }
174  }
176  }
177 }
178 
179 
182 }
183 
184 
185 
186 void DTTimeEvolutionHisto::updateTimeSlot(int ls, int nEventsInLS) {
187 
188  if(doSlide) { // sliding bins
189  // count LS in this time-slot
190  nLSinTimeSlot++;
191  nEventsInLastTimeSlot += nEventsInLS;
192 
194 
195  if(nLSinTimeSlot%theLSPrescale ==0) { // update the value of the slot and reset the counters
196  LogVerbatim("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
197  << "[DTTimeEvolutionHisto] Update time-slot, # entries: " << valueLastTimeSlot
198  << " # events: " << nEventsInLastTimeSlot << endl;
199  // set the bin content
200  float value = 0;
201  if(theMode == 0) {
203  } else if(theMode == 1) {
204  value = valueLastTimeSlot;
205  } else if(theMode == 2) {
206  value = nEventsInLastTimeSlot;
207  } else if(theMode == 3) {
209  }
211  LogVerbatim("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
212  << " updated value: " << histo->getBinContent(nBookedBins) << endl;
213 
214  // set the bin label
215  stringstream binLabel; binLabel << "LS " << firstLSinTimeSlot;
216  if(nLSinTimeSlot > 1) binLabel << "-" << ls;
217  histo->setBinLabel(nBookedBins,binLabel.str(),1);
218 
219  // reset the counters for the time slot
220  nLSinTimeSlot = 0;
222  valueLastTimeSlot = 0;
223  }
224 
225 
226  } else {
227  int binN = (int)ls-(theFirstLS-1)/(int)theLSPrescale;
228  // set the bin content
229  float value = 0;
230  if(theMode == 1) {
231  value = valueLastTimeSlot;
232  } else if(theMode == 2) {
233  value = nEventsInLS;
234  } else if(theMode == 3) {
236  }
237  LogVerbatim("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
238  << "[DTTimeEvolutionHisto] Update time-slot: "<< binN << " with value: " << value << endl;
239  setTimeSlotValue(value,binN);
240  }
241 }
242 
243 
244 
245 
247  if(histo == 0) {
248  LogWarning("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
249  << "[DTTimeEvolutionHisto]***Error: pointer to ME is NULL" << endl;
250  return;
251  }
252  int nBins = histo->getNbinsX();
253  if(histForNorm->getNbinsX() != nBins) {
254  LogWarning("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
255  << "[DTTimeEvolutionHisto]***Error: normalizing histos with != # of bins" << endl;
256  return;
257  }
258  for(int bin = 1; bin <= nBins; ++bin) { // loop over bins
259  if(histForNorm->getBinContent(bin) != 0) {
260  double normValue = histo->getBinContent(bin)/histForNorm->getBinContent(bin);
261  LogVerbatim("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
262  << "[DTTimeEvolutionHisto] Normalizing bin: " << bin << " to: " << histo->getBinContent(bin) << " / " << histForNorm->getBinContent(bin)
263  << " = " << normValue << endl;
264  histo->setBinContent(bin, normValue);
265  } else {
266  histo->setBinContent(bin, 0);
267  }
268  }
269 }
void setBinContent(int binx, double content)
set content of bin (1-D)
const std::string & label
Definition: MVAComputer.cc:186
void accumulateValueTimeSlot(float value)
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:519
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)
tuple histo
Definition: trackerHits.py:12
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)
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:1270
double getBinError(int binx) const
get uncertainty on content of bin (1-D) - See TH1::GetBinError for details
TH1F * getTH1F(void) const
int mode
Definition: AMPTWrapper.h:139
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
const std::string & pwd(void) const
Definition: DQMStore.cc:209