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