CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EETimingTask.cc
Go to the documentation of this file.
1 /*
2  * \file EETimingTask.cc
3  *
4  * $Date: 2012/04/27 13:46:16 $
5  * $Revision: 1.85 $
6  * \author G. Della Ricca
7  *
8 */
9 
10 #include <iostream>
11 #include <fstream>
12 
16 
18 
20 
26 
29 
31 
33 
35 
36  init_ = false;
37 
38  initCaloGeometry_ = false;
39 
41 
42  prefixME_ = ps.getUntrackedParameter<std::string>("prefixME", "");
43 
44  enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
45 
46  mergeRuns_ = ps.getUntrackedParameter<bool>("mergeRuns", false);
47 
48  energyThreshold_ = ps.getUntrackedParameter<double>("energyThreshold", 3.);
49 
50  EcalRawDataCollection_ = ps.getParameter<edm::InputTag>("EcalRawDataCollection");
51  EcalRecHitCollection_ = ps.getParameter<edm::InputTag>("EcalRecHitCollection");
52 
53  L1GtEvmReadoutRecord_ = ps.getParameter<edm::InputTag>("L1GtEvmReadoutRecord");
54 
55  useBeamStatus_ = ps.getUntrackedParameter<bool>("useBeamStatus", false);
56 
57  for (int i = 0; i < 18; i++) {
58  meTime_[i] = 0;
59  meTimeMap_[i] = 0;
60  meTimeAmpli_[i] = 0;
61  }
62 
63  for (int i = 0; i < 2; i++) {
65  meTimeSummary1D_[i] = 0;
66  meTimeSummaryMap_[i] = 0;
67  }
68 
69  meTimeDelta_ = 0;
70  meTimeDelta2D_ = 0;
71 
72  stableBeamsDeclared_ = false;
73 
74 }
75 
77 
78 }
79 
81 
82  ievt_ = 0;
83 
84  if ( dqmStore_ ) {
85  dqmStore_->setCurrentFolder(prefixME_ + "/EETimingTask");
86  dqmStore_->rmdir(prefixME_ + "/EETimingTask");
87  }
88 
89 }
90 
92 
93  Numbers::initGeometry(c, true);
94 
95  if( !initCaloGeometry_ ) {
97  initCaloGeometry_ = true;
98  }
99 
100  if ( ! mergeRuns_ ) this->reset();
101 
102  stableBeamsDeclared_ = false;
103 
104 }
105 
107 
108 }
109 
111 
112  for (int i = 0; i < 18; i++) {
113  if ( meTime_[i] ) meTime_[i]->Reset();
114  if ( meTimeMap_[i] ) meTimeMap_[i]->Reset();
115  if ( meTimeAmpli_[i] ) meTimeAmpli_[i]->Reset();
116  }
117 
118  for (int i = 0; i < 2; i++) {
122  }
123 
124  if ( meTimeDelta_ ) meTimeDelta_->Reset();
126 
127 }
128 
130 
131  init_ = true;
132 
134 
135  //for timing vs amplitude plots
136  const int nbinsE = 25;
137  const float minlogE = -0.5;
138  const float maxlogE = 2.;
139  float binEdgesE[nbinsE + 1];
140  for(int i = 0; i <= nbinsE; i++)
141  binEdgesE[i] = std::pow((float)10., minlogE + (maxlogE - minlogE) / nbinsE * i);
142 
143  const int nbinsT = 200;
144  const float minT = -50.;
145  const float maxT = 50.;
146  float binEdgesT[nbinsT + 1];
147  for(int i = 0; i <= nbinsT; i++)
148  binEdgesT[i] = minT + (maxT - minT) / nbinsT * i;
149 
150  if ( dqmStore_ ) {
151  dqmStore_->setCurrentFolder(prefixME_ + "/EETimingTask");
152 
153  for (int i = 0; i < 18; i++) {
154  name = "EETMT timing 1D " + Numbers::sEE(i+1);
155  meTime_[i] = dqmStore_->book1D(name, name, 50, -25., 25.);
156  meTime_[i]->setAxisTitle("time (ns)", 1);
157  dqmStore_->tag(meTime_[i], i+1);
158 
159  name = "EETMT timing " + Numbers::sEE(i+1);
160  meTimeMap_[i] = dqmStore_->bookProfile2D(name, name, 50, Numbers::ix0EE(i+1)+0., Numbers::ix0EE(i+1)+50., 50, Numbers::iy0EE(i+1)+0., Numbers::iy0EE(i+1)+50., -20.+shiftProf2D, 20.+shiftProf2D, "s");
161  meTimeMap_[i]->setAxisTitle("ix", 1);
162  if ( i+1 >= 1 && i+1 <= 9 ) meTimeMap_[i]->setAxisTitle("101-ix", 1);
163  meTimeMap_[i]->setAxisTitle("iy", 2);
164  meTimeMap_[i]->setAxisTitle("time (ns)", 3);
165  dqmStore_->tag(meTimeMap_[i], i+1);
166 
167  name = "EETMT timing vs amplitude " + Numbers::sEE(i+1);
168  meTimeAmpli_[i] = dqmStore_->book2D(name, name, nbinsE, binEdgesE, nbinsT, binEdgesT);
169  meTimeAmpli_[i]->setAxisTitle("energy (GeV)", 1);
170  meTimeAmpli_[i]->setAxisTitle("time (ns)", 2);
171  dqmStore_->tag(meTimeAmpli_[i], i+1);
172  }
173 
174  name = "EETMT timing vs amplitude summary EE -";
175  meTimeAmpliSummary_[0] = dqmStore_->book2D(name, name, nbinsE, binEdgesE, nbinsT, binEdgesT);
176  meTimeAmpliSummary_[0]->setAxisTitle("energy (GeV)", 1);
177  meTimeAmpliSummary_[0]->setAxisTitle("time (ns)", 2);
178 
179  name = "EETMT timing vs amplitude summary EE +";
180  meTimeAmpliSummary_[1] = dqmStore_->book2D(name, name, nbinsE, binEdgesE, nbinsT, binEdgesT);
181  meTimeAmpliSummary_[1]->setAxisTitle("energy (GeV)", 1);
182  meTimeAmpliSummary_[1]->setAxisTitle("time (ns)", 2);
183 
184  name = "EETMT timing 1D summary EE -";
185  meTimeSummary1D_[0] = dqmStore_->book1D(name, name, 50, -25., 25.);
186  meTimeSummary1D_[0]->setAxisTitle("time (ns)", 1);
187 
188  name = "EETMT timing 1D summary EE +";
189  meTimeSummary1D_[1] = dqmStore_->book1D(name, name, 50, -25., 25.);
190  meTimeSummary1D_[1]->setAxisTitle("time (ns)", 1);
191 
192  name = "EETMT timing map EE -";
193  meTimeSummaryMap_[0] = dqmStore_->bookProfile2D(name, name, 20, 0., 100., 20, 0., 100., -20.+shiftProf2D, 20.+shiftProf2D, "s");
194  meTimeSummaryMap_[0]->setAxisTitle("ix'", 1);
195  meTimeSummaryMap_[0]->setAxisTitle("101-iy'", 2);
196  meTimeSummaryMap_[0]->setAxisTitle("time (ns)", 3);
197 
198  name = "EETMT timing map EE +";
199  meTimeSummaryMap_[1] = dqmStore_->bookProfile2D(name, name, 20, 0., 100., 20, 0., 100., -20.+shiftProf2D, 20.+shiftProf2D, "s");
200  meTimeSummaryMap_[1]->setAxisTitle("ix'", 1);
201  meTimeSummaryMap_[1]->setAxisTitle("iy'", 2);
202  meTimeSummaryMap_[1]->setAxisTitle("time (ns)", 3);
203 
204  name = "EETMT timing EE+ - EE-";
205  meTimeDelta_ = dqmStore_->book1D(name, name, 100, -3., 3.);
206  meTimeDelta_->setAxisTitle("time (ns)", 1);
207 
208  name = "EETMT timing EE+ vs EE-";
209  meTimeDelta2D_ = dqmStore_->book2D(name, name, 50, -25., 25., 50, -25., 25.);
210  meTimeDelta2D_->setAxisTitle("EE+ average time (ns)", 1);
211  meTimeDelta2D_->setAxisTitle("EE- average time (ns)", 2);
212 
213  }
214 
215 }
216 
218 
219  if ( ! init_ ) return;
220 
221  if ( dqmStore_ ) {
222  dqmStore_->setCurrentFolder(prefixME_ + "/EETimingTask");
223 
224  for ( int i = 0; i < 18; i++ ) {
225  if ( meTime_[i] ) dqmStore_->removeElement( meTime_[i]->getName() );
226  meTime_[i] = 0;
227 
228  if ( meTimeMap_[i] ) dqmStore_->removeElement( meTimeMap_[i]->getName() );
229  meTimeMap_[i] = 0;
230 
231  if ( meTimeAmpli_[i] ) dqmStore_->removeElement( meTimeAmpli_[i]->getName() );
232  meTimeAmpli_[i] = 0;
233  }
234 
235  for (int i = 0; i < 2; i++) {
237  meTimeAmpliSummary_[i] = 0;
238 
239  if ( meTimeSummary1D_[i] ) dqmStore_->removeElement( meTimeSummary1D_[i]->getName() );
240  meTimeSummary1D_[i] = 0;
241 
242  if ( meTimeSummaryMap_[i] ) dqmStore_->removeElement( meTimeSummaryMap_[i]->getName() );
243  meTimeSummaryMap_[i] = 0;
244 
245  }
246 
248  meTimeDelta_ = 0;
249 
251  meTimeDelta2D_ = 0;
252 
253  }
254 
255  init_ = false;
256 
257 }
258 
260 
261  edm::LogInfo("EETimingTask") << "analyzed " << ievt_ << " events";
262 
263  if ( enableCleanup_ ) this->cleanup();
264 
265 }
266 
268 
269  const unsigned STABLE_BEAMS = 11;
270 
271  bool isData = true;
272  bool enable = false;
273  int runType[18];
274  for (int i=0; i<18; i++) runType[i] = -1;
275 
277 
278  if ( e.getByLabel(EcalRawDataCollection_, dcchs) ) {
279 
280  for ( EcalRawDataCollection::const_iterator dcchItr = dcchs->begin(); dcchItr != dcchs->end(); ++dcchItr ) {
281 
282  if ( Numbers::subDet( *dcchItr ) != EcalEndcap ) continue;
283 
284  int ism = Numbers::iSM( *dcchItr, EcalEndcap );
285 
286  runType[ism-1] = dcchItr->getRunType();
287 
288  if ( dcchItr->getRunType() == EcalDCCHeaderBlock::COSMIC ||
289  dcchItr->getRunType() == EcalDCCHeaderBlock::MTCC ||
290  dcchItr->getRunType() == EcalDCCHeaderBlock::COSMICS_GLOBAL ||
291  dcchItr->getRunType() == EcalDCCHeaderBlock::PHYSICS_GLOBAL ||
292  dcchItr->getRunType() == EcalDCCHeaderBlock::COSMICS_LOCAL ||
293  dcchItr->getRunType() == EcalDCCHeaderBlock::PHYSICS_LOCAL ) enable = true;
294 
295  }
296 
297  } else {
298 
299  isData = false; enable = true;
300  edm::LogWarning("EETimingTask") << EcalRawDataCollection_ << " not available";
301 
302  }
303 
304  if ( ! enable ) return;
305 
306  if ( ! init_ ) this->setup();
307 
308  ievt_++;
309 
310  // resetting plots when stable beam is declared
313  if( e.getByLabel(L1GtEvmReadoutRecord_, gtRecord) ) {
314 
315  unsigned lhcBeamMode = gtRecord->gtfeWord().beamMode();
316 
317  if( lhcBeamMode == STABLE_BEAMS ){
318 
319  reset();
320 
321  stableBeamsDeclared_ = true;
322 
323  }
324  }
325  }
326 
327  float sumTime_hithr[2] = {0.,0.};
328  int n_hithr[2] = {0,0};
329 
331  c.get<EcalSeverityLevelAlgoRcd>().get(sevlv);
332 
334 
335  if ( e.getByLabel(EcalRecHitCollection_, hits) ) {
336 
337  int neh = hits->size();
338  LogDebug("EETimingTask") << "event " << ievt_ << " hits collection size " << neh;
339 
340  for ( EcalRecHitCollection::const_iterator hitItr = hits->begin(); hitItr != hits->end(); ++hitItr ) {
341 
342  EEDetId id = hitItr->id();
343 
344  int ix = id.ix();
345  int iy = id.iy();
346  int iz = ( id.positiveZ() ) ? 1 : 0;
347 
348  int ism = Numbers::iSM( id );
349 
350  if ( ism >= 1 && ism <= 9 ) ix = 101 - ix;
351 
352  float xix = ix - 0.5;
353  float xiy = iy - 0.5;
354 
355  if ( isData ) {
356 
357  if ( ! ( runType[ism-1] == EcalDCCHeaderBlock::COSMIC ||
358  runType[ism-1] == EcalDCCHeaderBlock::MTCC ||
359  runType[ism-1] == EcalDCCHeaderBlock::COSMICS_GLOBAL ||
360  runType[ism-1] == EcalDCCHeaderBlock::PHYSICS_GLOBAL ||
361  runType[ism-1] == EcalDCCHeaderBlock::COSMICS_LOCAL ||
362  runType[ism-1] == EcalDCCHeaderBlock::PHYSICS_LOCAL ) ) continue;
363 
364  }
365 
366  MonitorElement* meTime = 0;
367  MonitorElement* meTimeMap = 0;
368  MonitorElement* meTimeAmpli = 0;
369 
370  meTime = meTime_[ism-1];
371  meTimeMap = meTimeMap_[ism-1];
372  meTimeAmpli = meTimeAmpli_[ism-1];
373 
374  float xval = hitItr->energy();
375  float yval = hitItr->time();
376 
377  uint32_t flag = hitItr->recoFlag();
378 
379  uint32_t sev = sevlv->severityLevel(id, *hits );
380 
381  if ( (flag == EcalRecHit::kGood || flag == EcalRecHit::kOutOfTime) && sev != EcalSeverityLevel::kWeird ) {
382  if ( meTimeAmpli ) meTimeAmpli->Fill(xval, yval);
383  if ( meTimeAmpliSummary_[iz] ) meTimeAmpliSummary_[iz]->Fill(xval, yval);
384  if ( hitItr->energy() > energyThreshold_ ) {
385  if ( meTimeMap ) meTimeMap->Fill(xix, xiy, yval+shiftProf2D);
386  if ( meTime ) meTime->Fill(yval);
387  if ( meTimeSummary1D_[iz] ) meTimeSummary1D_[iz]->Fill(yval);
388 
389  if ( meTimeSummaryMap_[iz] ) meTimeSummaryMap_[iz]->Fill(id.ix()-0.5, xiy, yval+shiftProf2D);
390 
391  sumTime_hithr[iz] += yval;
392  n_hithr[iz]++;
393  }
394  } // good rh for timing
395  } // loop over rh
396 
397  if (n_hithr[0] > 0 && n_hithr[1] > 0 ) {
398  if ( meTimeDelta_ ) meTimeDelta_->Fill( sumTime_hithr[1]/n_hithr[1] - sumTime_hithr[0]/n_hithr[0] );
399  if ( meTimeDelta2D_ ) meTimeDelta2D_->Fill( sumTime_hithr[1]/n_hithr[1], sumTime_hithr[0]/n_hithr[0] );
400  }
401 
402  } else {
403 
404  edm::LogWarning("EETimingTask") << EcalRecHitCollection_ << " not available";
405 
406  }
407 
408 }
409 
#define LogDebug(id)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
const std::string & getName(void) const
get name of ME
MonitorElement * meTimeDelta2D_
Definition: EETimingTask.h:89
static std::string sEE(const unsigned ism)
Definition: Numbers.cc:226
EETimingTask(const edm::ParameterSet &ps)
Constructor.
Definition: EETimingTask.cc:34
int i
Definition: DBlmapReader.cc:9
void cleanup(void)
Cleanup.
long int flag
Definition: mlp_lapack.h:47
edm::InputTag EcalRawDataCollection_
Definition: EETimingTask.h:78
int ix() const
Definition: EEDetId.h:77
std::string prefixME_
Definition: EETimingTask.h:70
MonitorElement * meTimeMap_[18]
Definition: EETimingTask.h:83
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:722
void rmdir(const std::string &fullpath)
Definition: DQMStore.cc:2535
void endJob(void)
EndJob.
Some &quot;id&quot; conversions.
MonitorElement * meTimeSummary1D_[2]
Definition: EETimingTask.h:87
edm::ESHandle< CaloGeometry > pGeometry_
Definition: EETimingTask.h:91
std::vector< T >::const_iterator const_iterator
static int ix0EE(const unsigned ism)
Definition: Numbers.cc:773
MonitorElement * meTimeSummaryMap_[2]
Definition: EETimingTask.h:88
virtual ~EETimingTask()
Destructor.
Definition: EETimingTask.cc:76
static int iy0EE(const unsigned ism)
Definition: Numbers.cc:812
DQMStore * dqmStore_
Definition: EETimingTask.h:68
void Fill(long long x)
void tag(MonitorElement *me, unsigned int myTag)
Definition: DQMStore.cc:1359
bool useBeamStatus_
Definition: EETimingTask.h:96
void setup(void)
Setup.
void analyze(const edm::Event &e, const edm::EventSetup &c)
Analyze.
bool initCaloGeometry_
Definition: EETimingTask.h:94
void removeElement(const std::string &name)
Definition: DQMStore.cc:2577
MonitorElement * meTimeDelta_
Definition: EETimingTask.h:89
MonitorElement * meTimeAmpliSummary_[2]
Definition: EETimingTask.h:86
void beginRun(const edm::Run &r, const edm::EventSetup &c)
BeginRun.
Definition: EETimingTask.cc:91
edm::InputTag L1GtEvmReadoutRecord_
Definition: EETimingTask.h:80
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
float energyThreshold_
Definition: EETimingTask.h:76
static void initGeometry(const edm::EventSetup &setup, bool verbose=false)
Definition: Numbers.cc:50
const T & get() const
Definition: EventSetup.h:55
static const float shiftProf2D
Definition: EETimingTask.h:36
bool stableBeamsDeclared_
Definition: EETimingTask.h:97
static unsigned iSM(const unsigned ism, const EcalSubdetector subdet)
Definition: Numbers.cc:246
void reset(void)
Reset.
bool enableCleanup_
Definition: EETimingTask.h:72
static EcalSubdetector subDet(const EBDetId &id)
Definition: Numbers.cc:145
MonitorElement * book2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2D histogram.
Definition: DQMStore.cc:850
void beginJob(void)
BeginJob.
Definition: EETimingTask.cc:80
int ism(int ieta, int iphi)
Definition: EcalPyUtils.cc:56
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
void Reset(void)
reset ME (ie. contents, errors, etc)
void endRun(const edm::Run &r, const edm::EventSetup &c)
EndRun.
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:434
Definition: Run.h:36
edm::InputTag EcalRecHitCollection_
Definition: EETimingTask.h:79
MonitorElement * meTime_[18]
Definition: EETimingTask.h:82
MonitorElement * meTimeAmpli_[18]
Definition: EETimingTask.h:84
MonitorElement * bookProfile2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, int nchZ, double lowZ, double highZ, const char *option="s")
Definition: DQMStore.cc:1180