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