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