CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EBTimingTask.cc
Go to the documentation of this file.
1 /*
2  * \file EBTimingTask.cc
3  *
4  * \author G. Della Ricca
5  *
6 */
7 
8 #include <iostream>
9 #include <fstream>
10 #include <string>
11 #include <cmath>
12 
16 
18 
20 
23 
26 
28 
30 
32 
33  init_ = 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>("energyTreshold",1.0);
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 < 36; i++) {
53  meTime_[i] = 0;
54  meTimeMap_[i] = 0;
55  meTimeAmpli_[i] = 0;
56  }
57 
59  meTimeSummary1D_ = 0;
61 
62  stableBeamsDeclared_ = false;
63 
64 }
65 
67 
68 }
69 
71 
72  ievt_ = 0;
73 
74  if ( dqmStore_ ) {
75  dqmStore_->setCurrentFolder(prefixME_ + "/EBTimingTask");
76  dqmStore_->rmdir(prefixME_ + "/EBTimingTask");
77  }
78 
79 }
80 
82 
83  Numbers::initGeometry(c, false);
84 
85  if ( ! mergeRuns_ ) this->reset();
86 
87  stableBeamsDeclared_ = false;
88 
89 }
90 
92 
93 }
94 
95 void EBTimingTask::reset(void) {
96 
97  for (int i = 0; i < 36; i++) {
98  if ( meTime_[i] ) meTime_[i]->Reset();
99  if ( meTimeMap_[i] ) meTimeMap_[i]->Reset();
100  if ( meTimeAmpli_[i] ) meTimeAmpli_[i]->Reset();
101  }
102 
106 
107 }
108 
110 
111  init_ = true;
112 
114 
115  // for timing vs amplitude plots
116  const int nbinsE = 25;
117  const float minlogE = -0.5;
118  const float maxlogE = 2.;
119  float binEdgesE[nbinsE + 1];
120  for(int i = 0; i <= nbinsE; i++)
121  binEdgesE[i] = std::pow((float)10., minlogE + (maxlogE - minlogE) / nbinsE * i);
122 
123  const int nbinsT = 200;
124  const float minT = -50.;
125  const float maxT = 50.;
126  float binEdgesT[nbinsT + 1];
127  for(int i = 0; i <= nbinsT; i++)
128  binEdgesT[i] = minT + (maxT - minT) / nbinsT * i;
129 
130  if ( dqmStore_ ) {
131  dqmStore_->setCurrentFolder(prefixME_ + "/EBTimingTask");
132 
133  for (int i = 0; i < 36; i++) {
134  name = "EBTMT timing 1D " + Numbers::sEB(i+1);
135  meTime_[i] = dqmStore_->book1D(name, name, 50, -25., 25.);
136  meTime_[i]->setAxisTitle("time (ns)", 1);
137  dqmStore_->tag(meTime_[i], i+1);
138 
139  name = "EBTMT timing " + Numbers::sEB(i+1);
140  meTimeMap_[i] = dqmStore_->bookProfile2D(name, name, 85, 0., 85., 20, 0., 20., -20.+shiftProf2D_, 20.+shiftProf2D_, "s");
141  meTimeMap_[i]->setAxisTitle("ieta", 1);
142  meTimeMap_[i]->setAxisTitle("iphi", 2);
143  meTimeMap_[i]->setAxisTitle("time (ns)", 3);
144  dqmStore_->tag(meTimeMap_[i], i+1);
145 
146  name = "EBTMT timing vs amplitude " + Numbers::sEB(i+1);
147  meTimeAmpli_[i] = dqmStore_->book2D(name, name, nbinsE, binEdgesE, nbinsT, binEdgesT);
148  meTimeAmpli_[i]->setAxisTitle("energy (GeV)", 1);
149  meTimeAmpli_[i]->setAxisTitle("time (ns)", 2);
150  dqmStore_->tag(meTimeAmpli_[i], i+1);
151  }
152 
153  name = "EBTMT timing vs amplitude summary";
154  meTimeAmpliSummary_ = dqmStore_->book2D(name, name, nbinsE, binEdgesE, nbinsT, binEdgesT);
155  meTimeAmpliSummary_->setAxisTitle("energy (GeV)", 1);
156  meTimeAmpliSummary_->setAxisTitle("time (ns)", 2);
157 
158  name = "EBTMT timing 1D summary";
159  meTimeSummary1D_ = dqmStore_->book1D(name, name, 50, -25., 25.);
160  meTimeSummary1D_->setAxisTitle("time (ns)", 1);
161 
162  name = "EBTMT timing map";
163  meTimeSummaryMap_ = dqmStore_->bookProfile2D(name, name, 72, 0., 360., 34, -85, 85, -20.+shiftProf2D_, 20.+shiftProf2D_, "s");
164  meTimeSummaryMap_->setAxisTitle("jphi", 1);
165  meTimeSummaryMap_->setAxisTitle("jeta", 2);
166  meTimeSummaryMap_->setAxisTitle("time (ns)", 3);
167 
168  }
169 
170 }
171 
173 
174  if ( ! init_ ) return;
175 
176  if ( dqmStore_ ) {
177  dqmStore_->setCurrentFolder(prefixME_ + "/EBTimingTask");
178 
179  for ( int i = 0; i < 36; i++ ) {
180  if ( meTime_[i] ) dqmStore_->removeElement( meTime_[i]->getName() );
181  meTime_[i] = 0;
182 
183  if ( meTimeMap_[i] ) dqmStore_->removeElement( meTimeMap_[i]->getName() );
184  meTimeMap_[i] = 0;
185 
186  if ( meTimeAmpli_[i] ) dqmStore_->removeElement( meTimeAmpli_[i]->getName() );
187  meTimeAmpli_[i] = 0;
188  }
189 
192 
194  meTimeSummary1D_ = 0;
195 
197  meTimeSummaryMap_ = 0;
198 
199  }
200 
201  init_ = false;
202 
203 }
204 
206 
207  edm::LogInfo("EBTimingTask") << "analyzed " << ievt_ << " events";
208 
209  if ( enableCleanup_ ) this->cleanup();
210 
211 }
212 
214 
215  const unsigned STABLE_BEAMS = 11;
216 
217  bool isData = true;
218  bool enable = false;
219  int runType[36];
220  for (int i=0; i<36; i++) runType[i] = -1;
221 
223 
224  if ( e.getByToken(EcalRawDataCollection_, dcchs) ) {
225 
226  for ( EcalRawDataCollection::const_iterator dcchItr = dcchs->begin(); dcchItr != dcchs->end(); ++dcchItr ) {
227 
228  if ( Numbers::subDet( *dcchItr ) != EcalBarrel ) continue;
229 
230  int ism = Numbers::iSM( *dcchItr, EcalBarrel );
231 
232  runType[ism-1] = dcchItr->getRunType();
233 
234  if ( dcchItr->getRunType() == EcalDCCHeaderBlock::COSMIC ||
235  dcchItr->getRunType() == EcalDCCHeaderBlock::MTCC ||
236  dcchItr->getRunType() == EcalDCCHeaderBlock::COSMICS_GLOBAL ||
237  dcchItr->getRunType() == EcalDCCHeaderBlock::PHYSICS_GLOBAL ||
238  dcchItr->getRunType() == EcalDCCHeaderBlock::COSMICS_LOCAL ||
239  dcchItr->getRunType() == EcalDCCHeaderBlock::PHYSICS_LOCAL ) enable = true;
240 
241  }
242 
243  } else {
244 
245  isData = false; enable = true;
246  edm::LogWarning("EBTimingTask") << "EcalRawDataCollection not available";
247 
248  }
249 
250  if ( ! enable ) return;
251 
252  if ( ! init_ ) this->setup();
253 
254  ievt_++;
255 
256  // resetting plots when stable beam is declared
259  if( e.getByToken(L1GtEvmReadoutRecord_, gtRecord) ) {
260 
261  unsigned lhcBeamMode = gtRecord->gtfeWord().beamMode();
262 
263  if( lhcBeamMode == STABLE_BEAMS ){
264 
265  reset();
266 
267  stableBeamsDeclared_ = true;
268 
269  }
270  }
271  }
272 
274  c.get<EcalSeverityLevelAlgoRcd>().get(sevlv);
275 
277 
278  if ( e.getByToken(EcalRecHitCollection_, hits) ) {
279 
280  int neh = hits->size();
281  LogDebug("EBTimingTask") << "event " << ievt_ << " hits collection size " << neh;
282 
283  for ( EcalRecHitCollection::const_iterator hitItr = hits->begin(); hitItr != hits->end(); ++hitItr ) {
284 
285  EBDetId id = hitItr->id();
286 
287  int ic = id.ic();
288  int ie = (ic-1)/20 + 1;
289  int ip = (ic-1)%20 + 1;
290 
291  int ism = Numbers::iSM( id );
292 
293  float xie = ie - 0.5;
294  float xip = ip - 0.5;
295 
296  if ( isData ) {
297 
298  if ( ! ( runType[ism-1] == EcalDCCHeaderBlock::COSMIC ||
299  runType[ism-1] == EcalDCCHeaderBlock::MTCC ||
300  runType[ism-1] == EcalDCCHeaderBlock::COSMICS_GLOBAL ||
301  runType[ism-1] == EcalDCCHeaderBlock::PHYSICS_GLOBAL ||
302  runType[ism-1] == EcalDCCHeaderBlock::COSMICS_LOCAL ||
303  runType[ism-1] == EcalDCCHeaderBlock::PHYSICS_LOCAL ) ) continue;
304 
305  }
306 
307  MonitorElement* meTime = 0;
308  MonitorElement* meTimeMap = 0;
309  MonitorElement* meTimeAmpli = 0;
310 
311  meTime = meTime_[ism-1];
312  meTimeMap = meTimeMap_[ism-1];
313  meTimeAmpli = meTimeAmpli_[ism-1];
314 
315  float xval = hitItr->energy();
316  float yval = hitItr->time();
317 
318  uint32_t flag = hitItr->recoFlag();
319 
320  uint32_t sev = sevlv->severityLevel(id, *hits);
321 
322  if ( (flag == EcalRecHit::kGood || flag == EcalRecHit::kOutOfTime) && sev != EcalSeverityLevel::kWeird ) {
323  if ( meTimeAmpli ) meTimeAmpli->Fill(xval, yval);
324  if ( meTimeAmpliSummary_ ) meTimeAmpliSummary_->Fill(xval, yval);
325 
326  if ( xval > energyThreshold_ ) {
327  if ( meTime ) meTime->Fill(yval);
328  if ( meTimeMap ) meTimeMap->Fill(xie, xip, yval+shiftProf2D_);
329  if ( meTimeSummary1D_ ) meTimeSummary1D_->Fill(yval);
330 
331  float xebeta = id.ieta() - 0.5 * id.zside();
332  float xebphi = id.iphi() - 0.5;
333  if ( meTimeSummaryMap_ ) meTimeSummaryMap_->Fill(xebphi, xebeta, yval+shiftProf2D_);
334  }
335 
336  }
337  }
338 
339  } else {
340 
341  edm::LogWarning("EBTimingTask") << "EcalRecHitCollection not available";
342 
343  }
344 
345 }
346 
#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
void beginRun(const edm::Run &r, const edm::EventSetup &c)
BeginRun.
Definition: EBTimingTask.cc:81
int i
Definition: DBlmapReader.cc:9
void beginJob(void)
BeginJob.
Definition: EBTimingTask.cc:70
MonitorElement * meTimeAmpli_[36]
Definition: EBTimingTask.h:80
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
EBTimingTask(const edm::ParameterSet &ps)
Constructor.
Definition: EBTimingTask.cc:31
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
Some &quot;id&quot; conversions.
static std::string sEB(const unsigned ism)
Definition: Numbers.cc:91
DQMStore * dqmStore_
Definition: EBTimingTask.h:64
std::string prefixME_
Definition: EBTimingTask.h:66
std::vector< EcalDCCHeaderBlock >::const_iterator const_iterator
virtual ~EBTimingTask()
Destructor.
Definition: EBTimingTask.cc:66
void endRun(const edm::Run &r, const edm::EventSetup &c)
EndRun.
Definition: EBTimingTask.cc:91
void cleanup(void)
Cleanup.
bool enableCleanup_
Definition: EBTimingTask.h:68
float energyThreshold_
Definition: EBTimingTask.h:72
bool stableBeamsDeclared_
Definition: EBTimingTask.h:89
void Fill(long long x)
void setup(void)
Setup.
void tag(MonitorElement *me, unsigned int myTag)
Definition: DQMStore.cc:1509
void endJob(void)
EndJob.
MonitorElement * meTimeSummaryMap_
Definition: EBTimingTask.h:84
void removeElement(const std::string &name)
Definition: DQMStore.cc:2772
MonitorElement * meTimeMap_[36]
Definition: EBTimingTask.h:79
edm::EDGetTokenT< L1GlobalTriggerEvmReadoutRecord > L1GtEvmReadoutRecord_
Definition: EBTimingTask.h:76
int ic() const
get ECAL/crystal number inside SM
Definition: EBDetId.cc:46
MonitorElement * meTimeSummary1D_
Definition: EBTimingTask.h:83
bool useBeamStatus_
Definition: EBTimingTask.h:88
edm::EDGetTokenT< EcalRecHitCollection > EcalRecHitCollection_
Definition: EBTimingTask.h:75
static void initGeometry(const edm::EventSetup &setup, bool verbose=false)
Definition: Numbers.cc:47
const T & get() const
Definition: EventSetup.h:55
void reset(void)
Reset.
Definition: EBTimingTask.cc:95
edm::EDGetTokenT< EcalRawDataCollection > EcalRawDataCollection_
Definition: EBTimingTask.h:74
MonitorElement * meTime_[36]
Definition: EBTimingTask.h:78
static unsigned iSM(const unsigned ism, const EcalSubdetector subdet)
Definition: Numbers.cc:243
void analyze(const edm::Event &e, const edm::EventSetup &c)
Analyze.
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
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)
MonitorElement * meTimeAmpliSummary_
Definition: EBTimingTask.h:82
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
static const float shiftProf2D_
Definition: EBTimingTask.h:32
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