CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MESetTrend.cc
Go to the documentation of this file.
2 
4 
5 namespace ecaldqm {
6 
7  MESetTrend::MESetTrend(std::string const& _fullpath, MEData const& _data, bool _readOnly/* = false*/) :
8  MESetEcal(_fullpath, _data, 1, _readOnly),
9  t0_(0),
10  minutely_(false),
11  tLow_(0)
12  {
13  if(!_data.xaxis || _data.xaxis->edges)
14  throw cms::Exception("InvalidConfiguration") << "MESetTrend";
15  }
16 
18  {
19  }
20 
21  void
23  {
24  int conversion(minutely_ ? 60 : 3600);
25  time_t width((data_->xaxis->high - data_->xaxis->low) * conversion);
26 
27  tLow_ = t0_;
28 
29  MEData const* temp(data_);
30  BinService::AxisSpecs xaxis(*temp->xaxis);
31  xaxis.low = tLow_;
32  xaxis.high = tLow_ + width;
33 
34  data_ = new MEData(temp->pathName, temp->otype, temp->btype, temp->kind, &xaxis, temp->yaxis, temp->zaxis);
35 
37 
38  delete data_;
39  data_ = temp;
40 
41  // if yaxis was variable bin size, xaxis will be booked as variable too
42 
43  for(unsigned iME(0); iME < mes_.size(); iME++){
44  TAxis* axis(mes_[iME]->getTH1()->GetXaxis());
45  if(axis->IsVariableBinSize())
46  axis->Set(data_->xaxis->nbins, data_->xaxis->low, data_->xaxis->high);
47  }
48  }
49 
50  void
51  MESetTrend::fill(DetId const& _id, double _t, double _wy/* = 1.*/, double _w/* = 1.*/)
52  {
53  if(!active_) return;
54 
55  unsigned offset(binService_->findOffset(data_->otype, _id));
56 
57  if(shift_(time_t(_t)))
58  MESet::fill_(offset, _t, _wy, _w);
59  }
60 
61  void
62  MESetTrend::fill(unsigned _dcctccid, double _t, double _wy/* = 1.*/, double _w/* = 1.*/)
63  {
64  if(!active_) return;
65 
66  unsigned offset(binService_->findOffset(data_->otype, data_->btype, _dcctccid));
67 
68  if(shift_(time_t(_t)))
69  MESet::fill_(offset, _t, _wy, _w);
70  }
71 
72  void
73  MESetTrend::fill(double _t, double _wy/* = 1.*/, double _w/* = 1.*/)
74  {
75  if(!active_) return;
76  if(mes_.size() != 1)
77  throw cms::Exception("InvalidCall") << "MESet type incompatible" << std::endl;
78 
79  if(shift_(time_t(_t)))
80  MESet::fill_(0, _t, _wy, _w);
81  }
82 
83  bool
84  MESetTrend::shift_(time_t _t)
85  {
86  int conversion(minutely_ ? 60 : 3600);
87  time_t width((data_->xaxis->high - data_->xaxis->low) * conversion);
88 
89  time_t tHigh(tLow_ + width);
90  int nbinsX(data_->xaxis->nbins);
92 
93  int dtPerBin(width / nbinsX);
94  int dBin(0);
95 
96  if(_t >= tLow_ && _t < tHigh)
97  return true;
98  else if(_t >= tHigh)
99  dBin = (_t - tHigh) / dtPerBin + 1;
100  else if(_t < tLow_){
101  int maxBin(0);
102 
103  for(unsigned iME(0); iME < mes_.size(); iME++){
104  MonitorElement* me(mes_[iME]);
105 
106  bool filled(false);
107  int iMax(nbinsX + 1);
108  while(--iMax > 0 && !filled){
109  switch(kind){
111  if(me->getBinContent(iMax) != 0) filled = true;
112  break;
114  if(me->getBinEntries(iMax) != 0) filled = true;
115  break;
117  for(int iy(1); iy <= me->getNbinsY(); iy++)
118  if(me->getBinContent(iMax, iy) != 0) filled = true;
119  break;
120  default:
121  return false;
122  }
123  }
124 
125  if(iMax > maxBin) maxBin = iMax;
126  }
127 
128  if(_t < tLow_ - (nbinsX - maxBin) * dtPerBin) return false;
129 
130  dBin = (_t - dtPerBin - tLow_) / dtPerBin;
131  }
132 
133  int start(dBin > 0 ? dBin + 1 : nbinsX + dBin);
134  int end(dBin > 0 ? nbinsX + 1 : 0);
135  int step(dBin > 0 ? 1 : -1);
136 
137  tLow_ += dBin * dtPerBin;
138  tHigh += dBin * dtPerBin;
139 
140  for(unsigned iME(0); iME < mes_.size(); iME++){
141  MonitorElement* me(mes_[iME]);
142 
143  me->setEntries(0.);
144 
145  double entries(0.);
146 
147  for(int ix(start); (dBin > 0 ? (ix < end) : (ix > end)); ix += step){
148  switch(kind){
150  entries += me->getBinContent(ix);
151  me->setBinContent(ix - dBin, me->getBinContent(ix));
152  me->setBinError(ix - dBin, me->getBinError(ix));
153  me->setBinContent(ix, 0.);
154  me->setBinError(ix, 0.);
155  break;
157  entries += me->getBinEntries(ix);
158  me->setBinEntries(ix - dBin, me->getBinEntries(ix));
159  me->setBinContent(ix - dBin, me->getBinContent(ix) * me->getBinEntries(ix));
160  if(me->getBinEntries(ix) > 0){
161  double rms(me->getBinError(ix) * std::sqrt(me->getBinEntries(ix)));
162  double sumw2((rms * rms + me->getBinContent(ix) * me->getBinContent(ix)) * me->getBinEntries(ix));
163  me->setBinError(ix - dBin, std::sqrt(sumw2));
164  }
165  me->setBinEntries(ix, 0.);
166  me->setBinContent(ix, 0.);
167  me->setBinError(ix, 0.);
168  break;
170  for(int iy(1); iy <= me->getNbinsY(); iy++){
171  int orig(me->getTH1()->GetBin(ix, iy));
172  int dest(me->getTH1()->GetBin(ix - dBin, iy));
173  entries += me->getBinContent(orig);
174  me->setBinContent(dest, me->getBinContent(orig));
175  me->setBinError(dest, me->getBinError(orig));
176  me->setBinContent(orig, 0.);
177  me->setBinError(orig, 0.);
178  }
179  break;
180  default:
181  break;
182  }
183  }
184 
185  me->setEntries(entries);
186  me->getTH1()->GetXaxis()->SetLimits(tLow_, tHigh);
187  }
188 
189  return true;
190  }
191 
192 }
BinService::ObjectType otype
Definition: MESet.h:22
void setBinContent(int binx, double content)
set content of bin (1-D)
void fill(DetId const &, double, double _wy=1., double _w=1.)
Definition: MESetTrend.cc:51
std::string pathName
Definition: MESet.h:21
list step
Definition: launcher.py:15
BinService::AxisSpecs * yaxis
Definition: MESet.h:26
MonitorElement::Kind kind
Definition: MESet.h:24
int getNbinsY(void) const
get # of bins in Y-axis
BinService::AxisSpecs * xaxis
Definition: MESet.h:25
std::vector< MonitorElement * > mes_
Definition: MESet.h:129
T sqrt(T t)
Definition: SSEVec.h:46
MESetTrend(std::string const &, MEData const &, bool _readOnly=false)
Definition: MESetTrend.cc:7
unsigned findOffset(ObjectType, const DetId &) const
BinService::BinningType btype
Definition: MESet.h:23
TH1 * getTH1(void) const
void setBinError(int binx, double error)
set uncertainty on content of bin (1-D)
#define end
Definition: vmac.h:38
void setEntries(double nentries)
set # of entries
unsigned int offset(bool)
virtual void fill_(unsigned, int, double)
Definition: MESet.cc:262
Definition: DetId.h:20
void conversion(EventAux const &from, EventAuxiliary &to)
Definition: EventAux.cc:9
double getBinError(int binx) const
get uncertainty on content of bin (1-D) - See TH1::GetBinError for details
static BinService const * binService_
Definition: MESet.h:126
BinService::AxisSpecs * zaxis
Definition: MESet.h:27
bool active_
Definition: MESet.h:135
double getBinContent(int binx) const
get content of bin (1-D)
MEData const * data_
Definition: MESet.h:133
bool shift_(time_t)
Definition: MESetTrend.cc:84
double getBinEntries(int bin) const
get # of bin entries (for profiles)
void setBinEntries(int bin, double nentries)
set # of bin entries (to be used for profiles)