CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ESTrendTask.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <fstream>
3 #include <vector>
4 #include <math.h>
5 
20 
21 using namespace cms;
22 using namespace edm;
23 using namespace std;
24 
26 
27  init_ = false;
28 
29  dqmStore_ = Service<DQMStore>().operator->();
30 
31  prefixME_ = ps.getUntrackedParameter<string>("prefixME", "EcalPreshower");
32  enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
33  mergeRuns_ = ps.getUntrackedParameter<bool>("mergeRuns", false);
34  rechitlabel_ = ps.getParameter<InputTag>("RecHitLabel");
35  dccCollections_ = ps.getParameter<InputTag>("ESDCCCollections");
36 
37  for (int i=0; i<2; ++i)
38  for (int j=0; j<2; ++j) {
39  hESRecHitTrend_[i][j] = 0;
40  hESRecHitTrendHr_[i][j] = 0;
41  }
42 
43  hESSLinkErrTrend_ = 0;
44  hESFiberErrTrend_ = 0;
45  hESSLinkErrTrendHr_ = 0;
46  hESFiberErrTrendHr_ = 0;
47 
48  start_time_ = 0;
49  current_time_ = 0;
50  last_time_ = 0;
51 
52 }
53 
55 }
56 
58 
59  ievt_ = 0;
60 
61  if ( dqmStore_ ) {
62  dqmStore_->setCurrentFolder(prefixME_ + "/ESTrendTask");
63  dqmStore_->rmdir(prefixME_ + "/ESTrendTask");
64  }
65 
66 }
67 
68 void ESTrendTask::beginRun(const Run& r, const EventSetup& c) {
69 
70  if ( ! mergeRuns_ ) this->reset();
71 
72  start_time_ = (r.beginTime()).unixTime();
73 
74  //std::cout << "start time : " << start_time_ << std::endl;
75 
76 }
77 
78 void ESTrendTask::endRun(const Run& r, const EventSetup& c) {
79 
80 }
81 
82 void ESTrendTask::reset(void) {
83 
84  for (int i=0 ; i<2; ++i)
85  for (int j=0 ; j<2; ++j) {
86  if (hESRecHitTrend_[i][j]) hESRecHitTrend_[i][j]->Reset();
87  if (hESRecHitTrendHr_[i][j]) hESRecHitTrendHr_[i][j]->Reset();
88  }
89 
90  if (hESSLinkErrTrend_) hESSLinkErrTrend_->Reset();
91  if (hESFiberErrTrend_) hESFiberErrTrend_->Reset();
92  if (hESSLinkErrTrendHr_) hESSLinkErrTrendHr_->Reset();
93  if (hESFiberErrTrendHr_) hESFiberErrTrendHr_->Reset();
94 
95 }
96 
97 void ESTrendTask::setup(void) {
98 
99  init_ = true;
100 
101  char histo[200];
102 
103  if ( dqmStore_ ) {
104  dqmStore_->setCurrentFolder(prefixME_ + "/ESTrendTask");
105 
106  for (int i=0 ; i<2; ++i)
107  for (int j=0 ; j<2; ++j) {
108  int iz = (i==0)? 1:-1;
109  sprintf(histo, "ES Trending RH Occ per 5 mins Z %d P %d", iz, j+1);
110  hESRecHitTrend_[i][j] = dqmStore_->bookProfile(histo, histo, 36, 0.0, 180.0, 100, 0.0, 1.0e6, "s");
111  hESRecHitTrend_[i][j]->setAxisTitle("Elapse time (Minutes)", 1);
112  hESRecHitTrend_[i][j]->setAxisTitle("ES RecHit Occupancy / 5 minutes", 2);
113 
114  sprintf(histo, "ES Trending RH Occ per hour Z %d P %d", iz, j+1);
115  hESRecHitTrendHr_[i][j] = dqmStore_->bookProfile(histo, histo, 24, 0.0, 24.0, 100, 0.0, 1.0e6, "s");
116  hESRecHitTrendHr_[i][j]->setAxisTitle("Elapse time (Hours)", 1);
117  hESRecHitTrendHr_[i][j]->setAxisTitle("ES RecHit Occupancy / hour", 2);
118  }
119 
120  sprintf(histo, "ES Trending SLink CRC Error per 5 mins");
121  hESSLinkErrTrend_ = dqmStore_->bookProfile(histo, histo, 36, 0.0, 180.0, 100, 0.0, 1.0e6, "s");
122  hESSLinkErrTrend_->setAxisTitle("Elapse time (Minutes)", 1);
123  hESSLinkErrTrend_->setAxisTitle("ES SLink CRC Err / 5 minutes", 2);
124 
125  sprintf(histo, "ES Trending Fiber Error per 5 mins");
126  hESFiberErrTrend_ = dqmStore_->bookProfile(histo, histo, 36, 0.0, 180.0, 100, 0.0, 1.0e6, "s");
127  hESFiberErrTrend_->setAxisTitle("Elapse time (Minutes)", 1);
128  hESFiberErrTrend_->setAxisTitle("ES Fiber Err / 5 minutes", 2);
129 
130  sprintf(histo, "ES Trending SLink CRC Error per hour");
131  hESSLinkErrTrendHr_ = dqmStore_->bookProfile(histo, histo, 24, 0.0, 24.0, 100, 0.0, 1.0e6, "s");
132  hESSLinkErrTrendHr_->setAxisTitle("Elapse time (Hours)", 1);
133  hESSLinkErrTrendHr_->setAxisTitle("ES SLink CRC Err / hour", 2);
134 
135  sprintf(histo, "ES Trending Fiber Error per hour");
136  hESFiberErrTrendHr_ = dqmStore_->bookProfile(histo, histo, 24, 0.0, 24.0, 100, 0.0, 1.0e6, "s");
137  hESFiberErrTrendHr_->setAxisTitle("Elapse time (Hours)", 1);
138  hESFiberErrTrendHr_->setAxisTitle("ES Fiber Err / hour", 2);
139  }
140 
141 }
142 
144 
145  if ( ! init_ ) return;
146 
147  if ( dqmStore_ ) {
148  dqmStore_->setCurrentFolder(prefixME_ + "/ESTrendTask");
149 
150  for (int i=0 ; i<2; ++i)
151  for (int j=0 ; j<2; ++j) {
152  if (hESRecHitTrend_[i][j]) dqmStore_->removeElement(hESRecHitTrend_[i][j]->getName());
153  hESRecHitTrend_[i][j] = 0;
154  if (hESRecHitTrendHr_[i][j]) dqmStore_->removeElement(hESRecHitTrendHr_[i][j]->getName());
155  hESRecHitTrendHr_[i][j] = 0;
156  }
157 
158  if (hESSLinkErrTrend_) dqmStore_->removeElement(hESSLinkErrTrend_->getName());
159  hESSLinkErrTrend_ = 0;
160  if (hESFiberErrTrend_) dqmStore_->removeElement(hESFiberErrTrend_->getName());
161  hESFiberErrTrend_ = 0;
162  if (hESSLinkErrTrendHr_) dqmStore_->removeElement(hESSLinkErrTrendHr_->getName());
163  hESSLinkErrTrendHr_ = 0;
164  if (hESFiberErrTrendHr_) dqmStore_->removeElement(hESFiberErrTrendHr_->getName());
165  hESFiberErrTrendHr_ = 0;
166  }
167 
168  init_ = false;
169 
170 }
171 
173 
174  LogInfo("ESTrendTask") << "analyzed " << ievt_ << " events";
175 
176  if ( enableCleanup_ ) this->cleanup();
177 
178 }
179 
180 void ESTrendTask::analyze(const Event& e, const EventSetup& c) {
181 
182  if ( ! init_ ) this->setup();
183 
184  ievt_++;
185 
186  // Collect time information
187  updateTime(e);
188 
189  long int diff_current_start = current_time_ - start_time_;
190  long int diff_last_start = last_time_ - start_time_;
191  //LogInfo("ESTrendTask") << "time difference is negative in " << ievt_ << " events\n"
192  //<< "\tcurrent - start time = " << diff_current_start
193  //<< ", \tlast - start time = " << diff_last_start << endl;
194 
195  // std::cout << "current_time : " << current_time_ << ", diff : " << diff_current_start << std::endl;
196 
197  // Calculate time interval and bin width
198  // int minuteBinWidth = int(nBasicClusterMinutely_->getTProfile()->GetXaxis()->GetBinWidth(1));
199  int minuteBinWidth = 5;
200  long int minuteBinDiff = diff_current_start/60/minuteBinWidth - diff_last_start/60/minuteBinWidth;
201  long int minuteDiff = (current_time_ - last_time_)/60;
202 
203  // int hourBinWidth = int(nBasicClusterHourly_->getTProfile()->GetXaxis()->GetBinWidth(1));
204  int hourBinWidth = 1;
205  long int hourBinDiff = diff_current_start/3600/hourBinWidth - diff_last_start/3600/hourBinWidth;
206  long int hourDiff = (current_time_ - last_time_)/3600;
207 
208  if (minuteDiff >= minuteBinWidth) {
209  while (minuteDiff >= minuteBinWidth) minuteDiff -= minuteBinWidth;
210  }
211  if (hourDiff >= hourBinWidth) {
212  while (hourDiff >= hourBinWidth) hourDiff -= hourBinWidth;
213  }
214 
215  // ES DCC
216  Int_t slinkCRCErr = 0;
217  Int_t fiberErr = 0;
218  vector<int> fiberStatus;
220  if ( e.getByLabel(dccCollections_, dccs) ) {
221  for (ESRawDataCollection::const_iterator dccItr = dccs->begin(); dccItr != dccs->end(); ++dccItr) {
222  ESDCCHeaderBlock dcc = (*dccItr);
223 
224  if (dcc.getDCCErrors() == 101) slinkCRCErr++;
225 
226  fiberStatus = dcc.getFEChannelStatus();
227  for (unsigned int i=0; i<fiberStatus.size(); ++i) {
228  if (fiberStatus[i]==4 || fiberStatus[i]==8 || fiberStatus[i]==10 || fiberStatus[i]==11 || fiberStatus[i]==12)
229  fiberErr++;
230  }
231 
232  }
233  }
234 
235  shift2Right(hESSLinkErrTrend_->getTProfile(), minuteBinDiff);
236  hESSLinkErrTrend_->Fill(minuteDiff, slinkCRCErr);
237 
238  shift2Right(hESFiberErrTrend_->getTProfile(), minuteBinDiff);
239  hESFiberErrTrend_->Fill(minuteDiff, fiberErr);
240 
241  shift2Right(hESSLinkErrTrendHr_->getTProfile(), hourBinDiff);
242  hESSLinkErrTrendHr_->Fill(hourDiff, slinkCRCErr);
243 
244  shift2Right(hESFiberErrTrendHr_->getTProfile(), hourBinDiff);
245  hESFiberErrTrendHr_->Fill(hourDiff, fiberErr);
246 
247  // ES RecHits
248  int zside, plane;
249  int nrh[2][2];
250  for (int i = 0; i < 2; i++ )
251  for( int j = 0; j < 2; j++) {
252  nrh[i][j] = 0;
253  }
254 
256  if ( e.getByLabel(rechitlabel_, ESRecHit) ) {
257 
258  for (ESRecHitCollection::const_iterator hitItr = ESRecHit->begin(); hitItr != ESRecHit->end(); ++hitItr) {
259 
260  ESDetId id = ESDetId(hitItr->id());
261 
262  zside = id.zside();
263  plane = id.plane();
264 
265  int i = (zside==1)? 0:1;
266  int j = plane-1;
267 
268  nrh[i][j]++;
269  }
270  } else {
271  LogWarning("ESTrendTask") << rechitlabel_ << " not available";
272  }
273 
274  for (int i=0; i<2; ++i)
275  for (int j=0; j<2; ++j) {
276  shift2Right(hESRecHitTrend_[i][j]->getTProfile(), minuteBinDiff);
277  hESRecHitTrend_[i][j]->Fill(minuteDiff, nrh[i][j]/(1072*32.));
278 
279  shift2Right(hESRecHitTrendHr_[i][j]->getTProfile(), hourBinDiff);
280  hESRecHitTrendHr_[i][j]->Fill(hourDiff, nrh[i][j]/(1072*32.));
281  }
282 
283 }
284 
286 
287  last_time_ = current_time_;
288  current_time_ = e.time().unixTime();
289 
290 }
291 
292 void ESTrendTask::shift2Right(TProfile* p, int bins) {
293 
294  if(bins <= 0) return;
295 
296  if(!p->GetSumw2()) p->Sumw2();
297  int nBins = p->GetXaxis()->GetNbins();
298 
299  // by shifting n bin to the right, the number of entries are
300  // reduced by the number in n bins including the overflow bin.
301  double nentries = p->GetEntries();
302  for(int i=0; i<bins; i++) nentries -= p->GetBinEntries(nBins+1-bins);
303  p->SetEntries(nentries);
304 
305  // the last bin goes to overflow
306  // each bin moves to the right
307 
308  TArrayD* sumw2 = p->GetSumw2();
309 
310  for(int i=nBins+1; i>bins; i--) {
311  // GetBinContent return binContent/binEntries
312  p->SetBinContent(i, p->GetBinContent(i-bins)*p->GetBinEntries(i-bins));
313  p->SetBinEntries(i,p->GetBinEntries(i-bins));
314  sumw2->SetAt(sumw2->GetAt(i-bins),i);
315  }
316 
317 }
318 
319 void ESTrendTask::shift2Left(TProfile* p, int bins) {
320 
321  if(bins <= 0) return;
322 
323  if(!p->GetSumw2()) p->Sumw2();
324  int nBins = p->GetXaxis()->GetNbins();
325 
326  // by shifting n bin to the left, the number of entries are
327  // reduced by the number in n bins including the underflow bin.
328  double nentries = p->GetEntries();
329  for(int i=0; i<bins; i++) nentries -= p->GetBinEntries(i);
330  p->SetEntries(nentries);
331 
332  // the first bin goes to underflow
333  // each bin moves to the right
334 
335  TArrayD* sumw2 = p->GetSumw2();
336 
337  for(int i=0; i<=nBins+1-bins; i++) {
338  // GetBinContent return binContent/binEntries
339  p->SetBinContent(i, p->GetBinContent(i+bins)*p->GetBinEntries(i+bins));
340  p->SetBinEntries(i,p->GetBinEntries(i+bins));
341  sumw2->SetAt(sumw2->GetAt(i+bins),i);
342  }
343 
344 }
345 
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
TProfile * getTProfile(std::string name, std::string process, std::string rootfolder, DQMStore *dbe_, bool verb, bool clone)
virtual ~ESTrendTask()
Definition: ESTrendTask.cc:54
void beginJob(void)
Definition: ESTrendTask.cc:57
void endJob(void)
Definition: ESTrendTask.cc:172
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< T >::const_iterator const_iterator
static void cleanup(const Factory::MakerMap::value_type &v)
Definition: Factory.cc:12
void shift2Right(TProfile *p, int bins=1)
Definition: ESTrendTask.cc:292
const std::vector< int > & getFEChannelStatus() const
void shift2Left(TProfile *p, int bins=1)
Definition: ESTrendTask.cc:319
void setup(void)
Definition: ESTrendTask.cc:97
void beginRun(const edm::Run &r, const edm::EventSetup &c)
Definition: ESTrendTask.cc:68
void analyze(const edm::Event &e, const edm::EventSetup &c)
Definition: ESTrendTask.cc:180
int j
Definition: DBlmapReader.cc:9
unsigned int unixTime() const
Time in seconds since January 1, 1970.
Definition: Timestamp.h:39
std::string getName(Reflex::Type &cc)
Definition: ClassFiller.cc:18
int zside() const
Definition: ESDetId.h:33
void reset(void)
Definition: ESTrendTask.cc:82
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
void endRun(const edm::Run &r, const edm::EventSetup &c)
Definition: ESTrendTask.cc:78
ESTrendTask(const edm::ParameterSet &ps)
Definition: ESTrendTask.cc:25
Timestamp const & beginTime() const
Definition: RunBase.h:43
int getDCCErrors() const
void shift2Right(TH1 *h, int bins)
void cleanup(void)
Definition: ESTrendTask.cc:143
void reset(double vett[256])
Definition: TPedValues.cc:11
void updateTime(const edm::Event &)
Definition: ESTrendTask.cc:285
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
edm::Timestamp time() const
Definition: EventBase.h:57
Definition: Run.h:33