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: 2011/08/30 09:30:33 $
5  * $Revision: 1.70 $
6  * \author G. Della Ricca
7  *
8 */
9 
10 #include <iostream>
11 #include <fstream>
12 #include <string>
13 #include <cmath>
14 
18 
20 
22 
27 
30 
32 
34 
36 
37  init_ = false;
38 
40 
41  prefixME_ = ps.getUntrackedParameter<std::string>("prefixME", "");
42 
43  enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
44 
45  mergeRuns_ = ps.getUntrackedParameter<bool>("mergeRuns", false);
46 
47  energyThreshold_ = ps.getUntrackedParameter<double>("energyTreshold",1.0);
48 
49  EcalRawDataCollection_ = ps.getParameter<edm::InputTag>("EcalRawDataCollection");
50  EcalRecHitCollection_ = ps.getParameter<edm::InputTag>("EcalRecHitCollection");
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 }
63 
65 
66 }
67 
69 
70  ievt_ = 0;
71 
72  if ( dqmStore_ ) {
73  dqmStore_->setCurrentFolder(prefixME_ + "/EBTimingTask");
74  dqmStore_->rmdir(prefixME_ + "/EBTimingTask");
75  }
76 
77 }
78 
80 
81  Numbers::initGeometry(c, false);
82 
83  if ( ! mergeRuns_ ) this->reset();
84 
85 }
86 
88 
89 }
90 
91 void EBTimingTask::reset(void) {
92 
93  for (int i = 0; i < 36; i++) {
94  if ( meTime_[i] ) meTime_[i]->Reset();
95  if ( meTimeMap_[i] ) meTimeMap_[i]->Reset();
96  if ( meTimeAmpli_[i] ) meTimeAmpli_[i]->Reset();
97  }
98 
102 
103 }
104 
106 
107  init_ = true;
108 
109  std::string name;
110 
111  // for timing vs amplitude plots
112  const int nbinsE = 25;
113  const float minlogE = -0.5;
114  const float maxlogE = 2.;
115  float binEdgesE[nbinsE + 1];
116  for(int i = 0; i <= nbinsE; i++)
117  binEdgesE[i] = std::pow(10., minlogE + (maxlogE - minlogE) / nbinsE * i);
118 
119  const int nbinsT = 200;
120  const float minT = -50.;
121  const float maxT = 50.;
122  float binEdgesT[nbinsT + 1];
123  for(int i = 0; i <= nbinsT; i++)
124  binEdgesT[i] = minT + (maxT - minT) / nbinsT * i;
125 
126  if ( dqmStore_ ) {
127  dqmStore_->setCurrentFolder(prefixME_ + "/EBTimingTask");
128 
129  for (int i = 0; i < 36; i++) {
130  name = "EBTMT timing 1D " + Numbers::sEB(i+1);
131  meTime_[i] = dqmStore_->book1D(name, name, 50, -25., 25.);
132  meTime_[i]->setAxisTitle("time (ns)", 1);
133  dqmStore_->tag(meTime_[i], i+1);
134 
135  name = "EBTMT timing " + Numbers::sEB(i+1);
136  meTimeMap_[i] = dqmStore_->bookProfile2D(name, name, 85, 0., 85., 20, 0., 20., -20.+shiftProf2D_, 20.+shiftProf2D_, "s");
137  meTimeMap_[i]->setAxisTitle("ieta", 1);
138  meTimeMap_[i]->setAxisTitle("iphi", 2);
139  meTimeMap_[i]->setAxisTitle("time (ns)", 3);
140  dqmStore_->tag(meTimeMap_[i], i+1);
141 
142  name = "EBTMT timing vs amplitude " + Numbers::sEB(i+1);
143  meTimeAmpli_[i] = dqmStore_->book2D(name, name, nbinsE, binEdgesE, nbinsT, binEdgesT);
144  meTimeAmpli_[i]->setAxisTitle("energy (GeV)", 1);
145  meTimeAmpli_[i]->setAxisTitle("time (ns)", 2);
146  dqmStore_->tag(meTimeAmpli_[i], i+1);
147  }
148 
149  name = "EBTMT timing vs amplitude summary";
150  meTimeAmpliSummary_ = dqmStore_->book2D(name, name, nbinsE, binEdgesE, nbinsT, binEdgesT);
151  meTimeAmpliSummary_->setAxisTitle("energy (GeV)", 1);
152  meTimeAmpliSummary_->setAxisTitle("time (ns)", 2);
153 
154  name = "EBTMT timing 1D summary";
155  meTimeSummary1D_ = dqmStore_->book1D(name, name, 50, -25., 25.);
156  meTimeSummary1D_->setAxisTitle("time (ns)", 1);
157 
158  name = "EBTMT timing map";
159  meTimeSummaryMap_ = dqmStore_->bookProfile2D(name, name, 72, 0., 360., 34, -85, 85, -20.+shiftProf2D_, 20.+shiftProf2D_, "s");
160  meTimeSummaryMap_->setAxisTitle("jphi", 1);
161  meTimeSummaryMap_->setAxisTitle("jeta", 2);
162  meTimeSummaryMap_->setAxisTitle("time (ns)", 3);
163 
164  }
165 
166 }
167 
169 
170  if ( ! init_ ) return;
171 
172  if ( dqmStore_ ) {
173  dqmStore_->setCurrentFolder(prefixME_ + "/EBTimingTask");
174 
175  for ( int i = 0; i < 36; i++ ) {
176  if ( meTime_[i] ) dqmStore_->removeElement( meTime_[i]->getName() );
177  meTime_[i] = 0;
178 
180  meTimeMap_[i] = 0;
181 
183  meTimeAmpli_[i] = 0;
184  }
185 
188 
190  meTimeSummary1D_ = 0;
191 
193  meTimeSummaryMap_ = 0;
194 
195  }
196 
197  init_ = false;
198 
199 }
200 
202 
203  edm::LogInfo("EBTimingTask") << "analyzed " << ievt_ << " events";
204 
205  if ( enableCleanup_ ) this->cleanup();
206 
207 }
208 
210 
211  bool isData = true;
212  bool enable = false;
213  int runType[36];
214  for (int i=0; i<36; i++) runType[i] = -1;
215 
217 
218  if ( e.getByLabel(EcalRawDataCollection_, dcchs) ) {
219 
220  for ( EcalRawDataCollection::const_iterator dcchItr = dcchs->begin(); dcchItr != dcchs->end(); ++dcchItr ) {
221 
222  if ( Numbers::subDet( *dcchItr ) != EcalBarrel ) continue;
223 
224  int ism = Numbers::iSM( *dcchItr, EcalBarrel );
225 
226  runType[ism-1] = dcchItr->getRunType();
227 
228  if ( dcchItr->getRunType() == EcalDCCHeaderBlock::COSMIC ||
229  dcchItr->getRunType() == EcalDCCHeaderBlock::MTCC ||
230  dcchItr->getRunType() == EcalDCCHeaderBlock::COSMICS_GLOBAL ||
231  dcchItr->getRunType() == EcalDCCHeaderBlock::PHYSICS_GLOBAL ||
232  dcchItr->getRunType() == EcalDCCHeaderBlock::COSMICS_LOCAL ||
233  dcchItr->getRunType() == EcalDCCHeaderBlock::PHYSICS_LOCAL ) enable = true;
234 
235  }
236 
237  } else {
238 
239  isData = false; enable = true;
240  edm::LogWarning("EBTimingTask") << EcalRawDataCollection_ << " not available";
241 
242  }
243 
244  if ( ! enable ) return;
245 
246  if ( ! init_ ) this->setup();
247 
248  ievt_++;
249 
251  c.get<EcalSeverityLevelAlgoRcd>().get(sevlv);
252 
254 
255  if ( e.getByLabel(EcalRecHitCollection_, hits) ) {
256 
257  int neh = hits->size();
258  LogDebug("EBTimingTask") << "event " << ievt_ << " hits collection size " << neh;
259 
260  for ( EcalRecHitCollection::const_iterator hitItr = hits->begin(); hitItr != hits->end(); ++hitItr ) {
261 
262  EBDetId id = hitItr->id();
263 
264  int ic = id.ic();
265  int ie = (ic-1)/20 + 1;
266  int ip = (ic-1)%20 + 1;
267 
268  int ism = Numbers::iSM( id );
269 
270  float xie = ie - 0.5;
271  float xip = ip - 0.5;
272 
273  if ( isData ) {
274 
275  if ( ! ( runType[ism-1] == EcalDCCHeaderBlock::COSMIC ||
276  runType[ism-1] == EcalDCCHeaderBlock::MTCC ||
277  runType[ism-1] == EcalDCCHeaderBlock::COSMICS_GLOBAL ||
278  runType[ism-1] == EcalDCCHeaderBlock::PHYSICS_GLOBAL ||
279  runType[ism-1] == EcalDCCHeaderBlock::COSMICS_LOCAL ||
280  runType[ism-1] == EcalDCCHeaderBlock::PHYSICS_LOCAL ) ) continue;
281 
282  }
283 
284  MonitorElement* meTime = 0;
285  MonitorElement* meTimeMap = 0;
286  MonitorElement* meTimeAmpli = 0;
287 
288  meTime = meTime_[ism-1];
289  meTimeMap = meTimeMap_[ism-1];
290  meTimeAmpli = meTimeAmpli_[ism-1];
291 
292  float xval = hitItr->energy();
293  float yval = hitItr->time();
294 
295  uint32_t flag = hitItr->recoFlag();
296 
297  uint32_t sev = sevlv->severityLevel(id, *hits);
298 
299  if ( (flag == EcalRecHit::kGood || flag == EcalRecHit::kOutOfTime) && sev != EcalSeverityLevelAlgo::kWeird ) {
300  if ( meTimeAmpli ) meTimeAmpli->Fill(xval, yval);
301  if ( meTimeAmpliSummary_ ) meTimeAmpliSummary_->Fill(xval, yval);
302 
303  if ( xval > energyThreshold_ ) {
304  if ( meTime ) meTime->Fill(yval);
305  if ( meTimeMap ) meTimeMap->Fill(xie, xip, yval+shiftProf2D_);
306  if ( meTimeSummary1D_ ) meTimeSummary1D_->Fill(yval);
307 
308  float xebeta = id.ieta() - 0.5 * id.zside();
309  float xebphi = id.iphi() - 0.5;
310  if ( meTimeSummaryMap_ ) meTimeSummaryMap_->Fill(xebphi, xebeta, yval+shiftProf2D_);
311  }
312 
313  }
314  }
315 
316  } else {
317 
318  edm::LogWarning("EBTimingTask") << EcalRecHitCollection_ << " not available";
319 
320  }
321 
322 }
323 
#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:79
int i
Definition: DBlmapReader.cc:9
long int flag
Definition: mlp_lapack.h:47
static std::string sEB(const int ism)
Definition: Numbers.cc:87
void beginJob(void)
BeginJob.
Definition: EBTimingTask.cc:68
MonitorElement * meTimeAmpli_[36]
Definition: EBTimingTask.h:77
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:514
void rmdir(const std::string &fullpath)
Definition: DQMStore.cc:2311
EBTimingTask(const edm::ParameterSet &ps)
Constructor.
Definition: EBTimingTask.cc:35
Some &quot;id&quot; conversions.
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:64
void endRun(const edm::Run &r, const edm::EventSetup &c)
EndRun.
Definition: EBTimingTask.cc:87
void cleanup(void)
Cleanup.
bool enableCleanup_
Definition: EBTimingTask.h:66
float energyThreshold_
Definition: EBTimingTask.h:70
void Fill(long long x)
void setup(void)
Setup.
void tag(MonitorElement *me, unsigned int myTag)
Definition: DQMStore.cc:1151
void endJob(void)
EndJob.
static int iSM(const int ism, const EcalSubdetector subdet)
Definition: Numbers.cc:222
MonitorElement * meTimeSummaryMap_
Definition: EBTimingTask.h:81
void removeElement(const std::string &name)
Definition: DQMStore.cc:2353
MonitorElement * meTimeMap_[36]
Definition: EBTimingTask.h:76
std::string getName(Reflex::Type &cc)
Definition: ClassFiller.cc:18
edm::InputTag EcalRawDataCollection_
Definition: EBTimingTask.h:72
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:355
int ic() const
get ECAL/crystal number inside SM
Definition: EBDetId.cc:94
MonitorElement * meTimeSummary1D_
Definition: EBTimingTask.h:80
static void initGeometry(const edm::EventSetup &setup, bool verbose=false)
Definition: Numbers.cc:45
edm::InputTag EcalRecHitCollection_
Definition: EBTimingTask.h:73
const T & get() const
Definition: EventSetup.h:55
void reset(void)
Reset.
Definition: EBTimingTask.cc:91
MonitorElement * meTime_[36]
Definition: EBTimingTask.h:75
void analyze(const edm::Event &e, const edm::EventSetup &c)
Analyze.
static EcalSubdetector subDet(const EBDetId &id)
Definition: Numbers.cc:136
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:642
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:79
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:232
Definition: Run.h:32
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:972