CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalMixingModuleValidation.cc
Go to the documentation of this file.
1 /*
2  * \file EcalMixingModuleValidation.cc
3  *
4  * \author F. Cossutti
5  *
6 */
7 
15 
17  HepMCToken_( consumes<edm::HepMCProduct>( edm::InputTag( ps.getParameter<std::string>( "moduleLabelMC" ) ) ) ),
18  EBdigiCollectionToken_( consumes<EBDigiCollection>( ps.getParameter<edm::InputTag>( "EBdigiCollection" ) ) ),
19  EEdigiCollectionToken_( consumes<EEDigiCollection>( ps.getParameter<edm::InputTag>( "EEdigiCollection" ) ) ),
20  ESdigiCollectionToken_( consumes<ESDigiCollection>( ps.getParameter<edm::InputTag>( "ESdigiCollection" ) ) ),
21  crossingFramePCaloHitEBToken_( consumes< CrossingFrame<PCaloHit> >( edm::InputTag( std::string( "mix" )
22  , ps.getParameter<std::string>( "hitsProducer" ) + std::string( "EcalHitsEB" )
23  )
24  )
25  ),
26  crossingFramePCaloHitEEToken_( consumes< CrossingFrame<PCaloHit> >( edm::InputTag( std::string( "mix" )
27  , ps.getParameter<std::string>( "hitsProducer" ) + std::string( "EcalHitsEE" )
28  )
29  )
30  ),
31  crossingFramePCaloHitESToken_( consumes< CrossingFrame<PCaloHit> >( edm::InputTag( std::string( "mix" )
32  , ps.getParameter<std::string>( "hitsProducer" ) + std::string( "EcalHitsES" )
33  )
34  )
35  ) {
36 
37 
38  // needed for MixingModule checks
39 
40  double simHitToPhotoelectronsBarrel = ps.getParameter<double>("simHitToPhotoelectronsBarrel");
41  double simHitToPhotoelectronsEndcap = ps.getParameter<double>("simHitToPhotoelectronsEndcap");
42  double photoelectronsToAnalogBarrel = ps.getParameter<double>("photoelectronsToAnalogBarrel");
43  double photoelectronsToAnalogEndcap = ps.getParameter<double>("photoelectronsToAnalogEndcap");
44  double samplingFactor = ps.getParameter<double>("samplingFactor");
45  double timePhase = ps.getParameter<double>("timePhase");
46  int readoutFrameSize = ps.getParameter<int>("readoutFrameSize");
47  int binOfMaximum = ps.getParameter<int>("binOfMaximum");
48  bool doPhotostatistics = ps.getParameter<bool>("doPhotostatistics");
49  bool syncPhase = ps.getParameter<bool>("syncPhase");
50 
51  doPhotostatistics = false;
52 
53  theParameterMap = new EcalSimParameterMap(simHitToPhotoelectronsBarrel, simHitToPhotoelectronsEndcap,
54  photoelectronsToAnalogBarrel, photoelectronsToAnalogEndcap,
55  samplingFactor, timePhase, readoutFrameSize, binOfMaximum,
56  doPhotostatistics, syncPhase);
57  //theEcalShape = new EcalShape(timePhase);
58 
59  //theEcalResponse = new CaloHitResponse(theParameterMap, theEcalShape);
60 
61 /*
62  int ESGain = ps.getParameter<int>("ESGain");
63  double ESNoiseSigma = ps.getParameter<double> ("ESNoiseSigma");
64  int ESBaseline = ps.getParameter<int>("ESBaseline");
65  double ESMIPADC = ps.getParameter<double>("ESMIPADC");
66  double ESMIPkeV = ps.getParameter<double>("ESMIPkeV");
67 */
68 
69  theESShape = new ESShape();
70  theEBShape = new EBShape();
71  theEEShape = new EEShape();
72 
76 
77 // double effwei = 1.;
78 
79 /*
80  if (ESGain == 0)
81  effwei = 1.45;
82  else if (ESGain == 1)
83  effwei = 0.9066;
84  else if (ESGain == 2)
85  effwei = 0.8815;
86 
87  esBaseline_ = (double)ESBaseline;
88  esADCtokeV_ = 1000000.*ESMIPADC/ESMIPkeV;
89  esThreshold_ = 3.*effwei*ESNoiseSigma/esADCtokeV_;
90 */
91  theMinBunch = -10;
92  theMaxBunch = 10;
93 
94 
95  // verbosity switch
96  verbose_ = ps.getUntrackedParameter<bool>("verbose", false);
97 
98  dbe_ = 0;
99 
100  // get hold of back-end interface
101  dbe_ = edm::Service<DQMStore>().operator->();
102 
103  if ( dbe_ ) {
104  if ( verbose_ ) {
105  dbe_->setVerbose(1);
106  } else {
107  dbe_->setVerbose(0);
108  }
109  }
110 
111  if ( dbe_ ) {
112  if ( verbose_ ) dbe_->showDirStructure();
113  }
114 
115  gainConv_[1] = 1.;
116  gainConv_[2] = 2.;
117  gainConv_[3] = 12.;
118  gainConv_[0] = 12.;
119  barrelADCtoGeV_ = 0.035;
120  endcapADCtoGeV_ = 0.06;
121 
124 
127 
128  meEBbunchCrossing_ = 0;
129  meEEbunchCrossing_ = 0;
130  meESbunchCrossing_ = 0;
131 
132  for ( int i = 0 ; i < nBunch ; i++ ) {
133  meEBBunchShape_[i] = 0;
134  meEEBunchShape_[i] = 0;
135  meESBunchShape_[i] = 0;
136  }
137 
138  meEBShape_ = 0;
139  meEEShape_ = 0;
140  meESShape_ = 0;
141 
142  meEBShapeRatio_ = 0;
143  meEEShapeRatio_ = 0;
144  meESShapeRatio_ = 0;
145 
146 
147  Char_t histo[200];
148 
149 
150  if ( dbe_ ) {
151  dbe_->setCurrentFolder("EcalDigisV/EcalDigiTask");
152 
153  sprintf (histo, "EcalDigiTask Barrel maximum Digi over sim signal ratio gt 100 ADC" ) ;
154  meEBDigiMixRatiogt100ADC_ = dbe_->book1D(histo, histo, 200, 0., 100.) ;
155 
156  sprintf (histo, "EcalDigiTask Endcap maximum Digi over sim signal ratio gt 100 ADC" ) ;
157  meEEDigiMixRatiogt100ADC_ = dbe_->book1D(histo, histo, 200, 0., 100.) ;
158 
159  sprintf (histo, "EcalDigiTask Barrel maximum Digi over sim signal ratio signal gt 50pc gun" ) ;
160  meEBDigiMixRatioOriggt50pc_ = dbe_->book1D(histo, histo, 200, 0., 100.) ;
161 
162  sprintf (histo, "EcalDigiTask Endcap maximum Digi over sim signal ratio signal gt 40pc gun" ) ;
163  meEEDigiMixRatioOriggt40pc_ = dbe_->book1D(histo, histo, 200, 0., 100.) ;
164 
165  sprintf (histo, "EcalDigiTask Barrel bunch crossing" ) ;
166  meEBbunchCrossing_ = dbe_->book1D(histo, histo, 20, -10., 10.) ;
167 
168  sprintf (histo, "EcalDigiTask Endcap bunch crossing" ) ;
169  meEEbunchCrossing_ = dbe_->book1D(histo, histo, 20, -10., 10.) ;
170 
171  sprintf (histo, "EcalDigiTask Preshower bunch crossing" ) ;
172  meESbunchCrossing_ = dbe_->book1D(histo, histo, 20, -10., 10.) ;
173 
174  for ( int i = 0 ; i < nBunch ; i++ ) {
175 
176  sprintf (histo, "EcalDigiTask Barrel shape bunch crossing %02d", i-10 );
177  meEBBunchShape_[i] = dbe_->bookProfile(histo, histo, 10, 0, 10, 4000, 0., 400.);
178 
179  sprintf (histo, "EcalDigiTask Endcap shape bunch crossing %02d", i-10 );
180  meEEBunchShape_[i] = dbe_->bookProfile(histo, histo, 10, 0, 10, 4000, 0., 400.);
181 
182  sprintf (histo, "EcalDigiTask Preshower shape bunch crossing %02d", i-10 );
183  meESBunchShape_[i] = dbe_->bookProfile(histo, histo, 3, 0, 3, 4000, 0., 400.);
184 
185  }
186 
187  sprintf (histo, "EcalDigiTask Barrel shape digi");
188  meEBShape_ = dbe_->bookProfile(histo, histo, 10, 0, 10, 4000, 0., 2000.);
189 
190  sprintf (histo, "EcalDigiTask Endcap shape digi");
191  meEEShape_ = dbe_->bookProfile(histo, histo, 10, 0, 10, 4000, 0., 2000.);
192 
193  sprintf (histo, "EcalDigiTask Preshower shape digi");
194  meESShape_ = dbe_->bookProfile(histo, histo, 3, 0, 3, 4000, 0., 2000.);
195 
196  sprintf (histo, "EcalDigiTask Barrel shape digi ratio");
197  meEBShapeRatio_ = dbe_->book1D(histo, histo, 10, 0, 10.);
198 
199  sprintf (histo, "EcalDigiTask Endcap shape digi ratio");
200  meEEShapeRatio_ = dbe_->book1D(histo, histo, 10, 0, 10.);
201 
202  sprintf (histo, "EcalDigiTask Preshower shape digi ratio");
203  meESShapeRatio_ = dbe_->book1D(histo, histo, 3, 0, 3.);
204 
205  }
206 
207 }
208 
210 
212 
214 
215 }
216 
218 }
219 
221 
222  // add shapes for each bunch crossing and divide the digi by the result
223 
224  std::vector<MonitorElement *> theBunches;
225  for ( int i = 0 ; i < nBunch ; i++ ) {
226  theBunches.push_back(meEBBunchShape_[i]);
227  }
229 
230  theBunches.clear();
231 
232  for ( int i = 0 ; i < nBunch ; i++ ) {
233  theBunches.push_back(meEEBunchShape_[i]);
234  }
236 
237  theBunches.clear();
238 
239  for ( int i = 0 ; i < nBunch ; i++ ) {
240  theBunches.push_back(meESBunchShape_[i]);
241  }
243 
244 }
245 
246 void EcalMixingModuleValidation::bunchSumTest(std::vector<MonitorElement *> & theBunches, MonitorElement* & theTotal, MonitorElement* & theRatio, int nSample)
247 {
248 
249  std::vector<double> bunchSum;
250  bunchSum.reserve(nSample);
251  std::vector<double> bunchSumErro;
252  bunchSumErro.reserve(nSample);
253  std::vector<double> total;
254  total.reserve(nSample);
255  std::vector<double> totalErro;
256  totalErro.reserve(nSample);
257  std::vector<double> ratio;
258  ratio.reserve(nSample);
259  std::vector<double> ratioErro;
260  ratioErro.reserve(nSample);
261 
262 
263  for ( int iEl = 0 ; iEl < nSample ; iEl++ ) {
264  bunchSum[iEl] = 0.;
265  bunchSumErro[iEl] = 0.;
266  total[iEl] = 0.;
267  totalErro[iEl] = 0.;
268  ratio[iEl] = 0.;
269  ratioErro[iEl] = 0.;
270  }
271 
272  for ( int iSample = 0 ; iSample < nSample ; iSample++ ) {
273 
274  total[iSample] += theTotal->getBinContent(iSample+1);
275  totalErro[iSample] += theTotal->getBinError(iSample+1);
276 
277  for ( int iBunch = theMinBunch; iBunch <= theMaxBunch; iBunch++ ) {
278 
279  int iHisto = iBunch - theMinBunch;
280 
281  bunchSum[iSample] += theBunches[iHisto]->getBinContent(iSample+1);
282  bunchSumErro[iSample] += pow(theBunches[iHisto]->getBinError(iSample+1),2);
283 
284  }
285  bunchSumErro[iSample] = sqrt(bunchSumErro[iSample]);
286 
287  if ( bunchSum[iSample] > 0. ) {
288  ratio[iSample] = total[iSample]/bunchSum[iSample];
289  ratioErro[iSample] = sqrt(pow(totalErro[iSample]/bunchSum[iSample],2)+
290  pow((total[iSample]*bunchSumErro[iSample])/(bunchSum[iSample]*bunchSum[iSample]),2));
291  }
292 
293  std::cout << " Sample = " << iSample << " Total = " << total[iSample] << " +- " << totalErro[iSample] << "\n"
294  << " Sum = " << bunchSum[iSample] << " +- " << bunchSumErro[iSample] << "\n"
295  << " Ratio = " << ratio[iSample] << " +- " << ratioErro[iSample] << std::endl;
296 
297  theRatio->setBinContent(iSample+1, (float)ratio[iSample]);
298  theRatio->setBinError(iSample+1, (float)ratioErro[iSample]);
299 
300  }
301 
302 }
303 
305 
306  //LogInfo("EventInfo") << " Run = " << e.id().run() << " Event = " << e.id().event();
307 
308  checkPedestals(c);
309 
310  std::vector<SimTrack> theSimTracks;
311  std::vector<SimVertex> theSimVertexes;
312 
314  edm::Handle<CrossingFrame<PCaloHit> > crossingFrame;
318 
319 
320  bool skipMC = false;
321  e.getByToken( HepMCToken_, MCEvt );
322  if (!MCEvt.isValid()) { skipMC = true; }
323 
324  const EBDigiCollection* EBdigis =0;
325  const EEDigiCollection* EEdigis =0;
326  const ESDigiCollection* ESdigis =0;
327 
328  bool isBarrel = true;
329  e.getByToken( EBdigiCollectionToken_, EcalDigiEB );
330  if (EcalDigiEB.isValid()) {
331  EBdigis = EcalDigiEB.product();
332  LogDebug("DigiInfo") << "total # EBdigis: " << EBdigis->size() ;
333  if ( EBdigis->size() == 0 ) isBarrel = false;
334  } else {
335  isBarrel = false;
336  }
337 
338  bool isEndcap = true;
339  e.getByToken( EEdigiCollectionToken_, EcalDigiEE );
340  if (EcalDigiEE.isValid()) {
341  EEdigis = EcalDigiEE.product();
342  LogDebug("DigiInfo") << "total # EEdigis: " << EEdigis->size() ;
343  if ( EEdigis->size() == 0 ) isEndcap = false;
344  } else {
345  isEndcap = false;
346  }
347 
348  bool isPreshower = true;
349  e.getByToken( ESdigiCollectionToken_, EcalDigiES );
350  if (EcalDigiES.isValid()) {
351  ESdigis = EcalDigiES.product();
352  LogDebug("DigiInfo") << "total # ESdigis: " << ESdigis->size() ;
353  if ( ESdigis->size() == 0 ) isPreshower = false;
354  } else {
355  isPreshower = false;
356  }
357 
358  double theGunEnergy = 0.;
359  if ( ! skipMC ) {
360  for ( HepMC::GenEvent::particle_const_iterator p = MCEvt->GetEvent()->particles_begin();
361  p != MCEvt->GetEvent()->particles_end(); ++p ) {
362 
363  theGunEnergy = (*p)->momentum().e();
364  }
365  }
366  // in case no HepMC available, assume an arbitrary average energy for an interesting "gun"
367  else {
368  edm::LogWarning("DigiInfo") << "No HepMC available, using 30 GeV as giun energy";
369  theGunEnergy = 30.;
370  }
371 
372  // BARREL
373 
374  // loop over simHits
375 
376  if ( isBarrel ) {
377 
378  e.getByToken( crossingFramePCaloHitEBToken_, crossingFrame );
379  std::auto_ptr<MixCollection<PCaloHit> >
380  barrelHits (new MixCollection<PCaloHit>(crossingFrame.product ()));
381 
382  MapType ebSignalSimMap;
383 
384  double ebSimThreshold = 0.5*theGunEnergy;
385 
386  for (MixCollection<PCaloHit>::MixItr hitItr = barrelHits->begin () ;
387  hitItr != barrelHits->end () ;
388  ++hitItr) {
389 
390  EBDetId ebid = EBDetId(hitItr->id()) ;
391 
392  LogDebug("HitInfo")
393  << " CaloHit " << hitItr->getName() << "\n"
394  << " DetID = "<<hitItr->id()<< " EBDetId = " << ebid.ieta() << " " << ebid.iphi() << "\n"
395  << " Time = " << hitItr->time() << " Event id. = " << hitItr->eventId().rawId() << "\n"
396  << " Track Id = " << hitItr->geantTrackId() << "\n"
397  << " Energy = " << hitItr->energy();
398 
399  uint32_t crystid = ebid.rawId();
400 
401  if ( hitItr->eventId().rawId() == 0 ) ebSignalSimMap[crystid] += hitItr->energy();
402 
403  if ( meEBbunchCrossing_ ) meEBbunchCrossing_->Fill(hitItr->eventId().bunchCrossing());
404 
405  }
406 
407  // loop over Digis
408 
409  const EBDigiCollection * barrelDigi = EcalDigiEB.product () ;
410 
411  std::vector<double> ebAnalogSignal ;
412  std::vector<double> ebADCCounts ;
413  std::vector<double> ebADCGains ;
414  ebAnalogSignal.reserve(EBDataFrame::MAXSAMPLES);
415  ebADCCounts.reserve(EBDataFrame::MAXSAMPLES);
416  ebADCGains.reserve(EBDataFrame::MAXSAMPLES);
417 
418  for (unsigned int digis=0; digis<EcalDigiEB->size(); ++digis) {
419 
420  EBDataFrame ebdf=(*barrelDigi)[digis];
421  int nrSamples=ebdf.size();
422 
423  EBDetId ebid = ebdf.id () ;
424 
425  double Emax = 0. ;
426  int Pmax = 0 ;
427 
428  for (int sample = 0 ; sample < nrSamples; ++sample) {
429  ebAnalogSignal[sample] = 0.;
430  ebADCCounts[sample] = 0.;
431  ebADCGains[sample] = -1.;
432  }
433 
434  for (int sample = 0 ; sample < nrSamples; ++sample) {
435 
437 
438  ebADCCounts[sample] = (mySample.adc()) ;
439  ebADCGains[sample] = (mySample.gainId ()) ;
440  ebAnalogSignal[sample] = (ebADCCounts[sample]*gainConv_[(int)ebADCGains[sample]]*barrelADCtoGeV_);
441  if (Emax < ebAnalogSignal[sample] ) {
442  Emax = ebAnalogSignal[sample] ;
443  Pmax = sample ;
444  }
445  LogDebug("DigiInfo") << "EB sample " << sample << " ADC counts = " << ebADCCounts[sample] << " Gain Id = " << ebADCGains[sample] << " Analog eq = " << ebAnalogSignal[sample];
446  }
447  double pedestalPreSampleAnalog = 0.;
448  findPedestal( ebid, (int)ebADCGains[Pmax] , pedestalPreSampleAnalog);
449  pedestalPreSampleAnalog *= gainConv_[(int)ebADCGains[Pmax]]*barrelADCtoGeV_;
450  double Erec = Emax - pedestalPreSampleAnalog;
451 
452  if ( ebSignalSimMap[ebid.rawId()] != 0. ) {
453  LogDebug("DigiInfo") << " Digi / Signal Hit = " << Erec << " / " << ebSignalSimMap[ebid.rawId()] << " gainConv " << gainConv_[(int)ebADCGains[Pmax]];
454  if ( Erec > 100.*barrelADCtoGeV_ && meEBDigiMixRatiogt100ADC_ ) meEBDigiMixRatiogt100ADC_->Fill( Erec/ebSignalSimMap[ebid.rawId()] );
455  if ( ebSignalSimMap[ebid.rawId()] > ebSimThreshold && meEBDigiMixRatioOriggt50pc_ ) meEBDigiMixRatioOriggt50pc_->Fill( Erec/ebSignalSimMap[ebid.rawId()] );
456  if ( ebSignalSimMap[ebid.rawId()] > ebSimThreshold && meEBShape_ ) {
457  for ( int i = 0; i < 10 ; i++ ) {
458  pedestalPreSampleAnalog = 0.;
459  findPedestal( ebid, (int)ebADCGains[i] , pedestalPreSampleAnalog);
460  pedestalPreSampleAnalog *= gainConv_[(int)ebADCGains[i]]*barrelADCtoGeV_;
461  meEBShape_->Fill(i, ebAnalogSignal[i]-pedestalPreSampleAnalog );
462  }
463  }
464  }
465 
466  }
467 
468  EcalSubdetector thisDet = EcalBarrel;
469  computeSDBunchDigi(c, *barrelHits, ebSignalSimMap, thisDet, ebSimThreshold);
470  }
471 
472 
473  // ENDCAP
474 
475  // loop over simHits
476 
477  if ( isEndcap ) {
478 
479  e.getByToken( crossingFramePCaloHitEEToken_, crossingFrame );
480  std::auto_ptr<MixCollection<PCaloHit> >
481  endcapHits (new MixCollection<PCaloHit>(crossingFrame.product ()));
482 
483  MapType eeSignalSimMap;
484 
485  double eeSimThreshold = 0.4*theGunEnergy;
486 
487  for (MixCollection<PCaloHit>::MixItr hitItr = endcapHits->begin () ;
488  hitItr != endcapHits->end () ;
489  ++hitItr) {
490 
491  EEDetId eeid = EEDetId(hitItr->id()) ;
492 
493  LogDebug("HitInfo")
494  << " CaloHit " << hitItr->getName() << "\n"
495  << " DetID = "<<hitItr->id()<< " EEDetId side = " << eeid.zside() << " = " << eeid.ix() << " " << eeid.iy() << "\n"
496  << " Time = " << hitItr->time() << " Event id. = " << hitItr->eventId().rawId() << "\n"
497  << " Track Id = " << hitItr->geantTrackId() << "\n"
498  << " Energy = " << hitItr->energy();
499 
500  uint32_t crystid = eeid.rawId();
501 
502  if ( hitItr->eventId().rawId() == 0 ) eeSignalSimMap[crystid] += hitItr->energy();
503 
504  if ( meEEbunchCrossing_ ) meEEbunchCrossing_->Fill(hitItr->eventId().bunchCrossing());
505 
506  }
507 
508  // loop over Digis
509 
510  const EEDigiCollection * endcapDigi = EcalDigiEE.product () ;
511 
512  std::vector<double> eeAnalogSignal ;
513  std::vector<double> eeADCCounts ;
514  std::vector<double> eeADCGains ;
515  eeAnalogSignal.reserve(EEDataFrame::MAXSAMPLES);
516  eeADCCounts.reserve(EEDataFrame::MAXSAMPLES);
517  eeADCGains.reserve(EEDataFrame::MAXSAMPLES);
518 
519  for (unsigned int digis=0; digis<EcalDigiEE->size(); ++digis) {
520 
521  EEDataFrame eedf=(*endcapDigi)[digis];
522  int nrSamples=eedf.size();
523 
524  EEDetId eeid = eedf.id () ;
525 
526  double Emax = 0. ;
527  int Pmax = 0 ;
528 
529  for (int sample = 0 ; sample < nrSamples; ++sample) {
530  eeAnalogSignal[sample] = 0.;
531  eeADCCounts[sample] = 0.;
532  eeADCGains[sample] = -1.;
533  }
534 
535  for (int sample = 0 ; sample < nrSamples; ++sample) {
536 
538 
539  eeADCCounts[sample] = (mySample.adc()) ;
540  eeADCGains[sample] = (mySample.gainId()) ;
541  eeAnalogSignal[sample] = (eeADCCounts[sample]*gainConv_[(int)eeADCGains[sample]]*endcapADCtoGeV_);
542  if (Emax < eeAnalogSignal[sample] ) {
543  Emax = eeAnalogSignal[sample] ;
544  Pmax = sample ;
545  }
546  LogDebug("DigiInfo") << "EE sample " << sample << " ADC counts = " << eeADCCounts[sample] << " Gain Id = " << eeADCGains[sample] << " Analog eq = " << eeAnalogSignal[sample];
547  }
548  double pedestalPreSampleAnalog = 0.;
549  findPedestal( eeid, (int)eeADCGains[Pmax] , pedestalPreSampleAnalog);
550  pedestalPreSampleAnalog *= gainConv_[(int)eeADCGains[Pmax]]*endcapADCtoGeV_;
551  double Erec = Emax - pedestalPreSampleAnalog;
552 
553  if ( eeSignalSimMap[eeid.rawId()] != 0. ) {
554  LogDebug("DigiInfo") << " Digi / Signal Hit = " << Erec << " / " << eeSignalSimMap[eeid.rawId()] << " gainConv " << gainConv_[(int)eeADCGains[Pmax]];
555  if ( Erec > 100.*endcapADCtoGeV_ && meEEDigiMixRatiogt100ADC_ ) meEEDigiMixRatiogt100ADC_->Fill( Erec/eeSignalSimMap[eeid.rawId()] );
556  if ( eeSignalSimMap[eeid.rawId()] > eeSimThreshold && meEEDigiMixRatioOriggt40pc_ ) meEEDigiMixRatioOriggt40pc_->Fill( Erec/eeSignalSimMap[eeid.rawId()] );
557  if ( eeSignalSimMap[eeid.rawId()] > eeSimThreshold && meEBShape_ ) {
558  for ( int i = 0; i < 10 ; i++ ) {
559  pedestalPreSampleAnalog = 0.;
560  findPedestal( eeid, (int)eeADCGains[i] , pedestalPreSampleAnalog);
561  pedestalPreSampleAnalog *= gainConv_[(int)eeADCGains[i]]*endcapADCtoGeV_;
562  meEEShape_->Fill(i, eeAnalogSignal[i]-pedestalPreSampleAnalog );
563  }
564  }
565  }
566  }
567 
568  EcalSubdetector thisDet = EcalEndcap;
569  computeSDBunchDigi(c, *endcapHits, eeSignalSimMap, thisDet, eeSimThreshold);
570  }
571 
572  if ( isPreshower) {
573 
574  e.getByToken(crossingFramePCaloHitESToken_, crossingFrame );
575  std::auto_ptr<MixCollection<PCaloHit> >
576  preshowerHits (new MixCollection<PCaloHit>(crossingFrame.product ()));
577 
578  MapType esSignalSimMap;
579 
580  for (MixCollection<PCaloHit>::MixItr hitItr = preshowerHits->begin () ;
581  hitItr != preshowerHits->end () ;
582  ++hitItr) {
583 
584  ESDetId esid = ESDetId(hitItr->id()) ;
585 
586  LogDebug("HitInfo")
587  << " CaloHit " << hitItr->getName() << "\n"
588  << " DetID = "<<hitItr->id()<< "ESDetId: z side " << esid.zside() << " plane " << esid.plane() << esid.six() << ',' << esid.siy() << ':' << esid.strip() << "\n"
589  << " Time = " << hitItr->time() << " Event id. = " << hitItr->eventId().rawId() << "\n"
590  << " Track Id = " << hitItr->geantTrackId() << "\n"
591  << " Energy = " << hitItr->energy();
592 
593  uint32_t stripid = esid.rawId();
594 
595  if ( hitItr->eventId().rawId() == 0 ) esSignalSimMap[stripid] += hitItr->energy();
596 
597  if ( meESbunchCrossing_ ) meESbunchCrossing_->Fill(hitItr->eventId().bunchCrossing());
598 
599  // loop over Digis
600 
601  const ESDigiCollection * preshowerDigi = EcalDigiES.product () ;
602 
603  std::vector<double> esADCCounts ;
604  std::vector<double> esADCAnalogSignal ;
605  esADCCounts.reserve(ESDataFrame::MAXSAMPLES);
606  esADCAnalogSignal.reserve(ESDataFrame::MAXSAMPLES);
607 
608  for (unsigned int digis=0; digis<EcalDigiES->size(); ++digis) {
609 
610  ESDataFrame esdf=(*preshowerDigi)[digis];
611  int nrSamples=esdf.size();
612 
613  ESDetId esid = esdf.id () ;
614 
615  for (int sample = 0 ; sample < nrSamples; ++sample) {
616  esADCCounts[sample] = 0.;
617  esADCAnalogSignal[sample] = 0.;
618  }
619 
620  for (int sample = 0 ; sample < nrSamples; ++sample) {
621 
622  ESSample mySample = esdf[sample];
623 
624  esADCCounts[sample] = (mySample.adc()) ;
625  esBaseline_ = m_ESpeds->find(esid)->getMean() ;
626  const double factor ( esADCtokeV_/(*(m_ESmips->getMap().find(esid)) ) ) ;
627  esThreshold_ = 3.*m_ESeffwei*( (*m_ESpeds->find(esid)).getRms())/factor;
628  esADCAnalogSignal[sample] = (esADCCounts[sample]-esBaseline_)/factor;
629  }
630  LogDebug("DigiInfo") << "Preshower Digi for ESDetId: z side " << esid.zside() << " plane " << esid.plane() << esid.six() << ',' << esid.siy() << ':' << esid.strip();
631  for ( int i = 0; i < 3 ; i++ ) {
632  LogDebug("DigiInfo") << "sample " << i << " ADC = " << esADCCounts[i] << " Analog eq = " << esADCAnalogSignal[i];
633  }
634 
635  if ( esSignalSimMap[esid.rawId()] > esThreshold_ && meESShape_ ) {
636  for ( int i = 0; i < 3 ; i++ ) {
637  meESShape_->Fill(i, esADCAnalogSignal[i] );
638  }
639  }
640 
641  }
642 
643  }
644 
645  EcalSubdetector thisDet = EcalPreshower;
646  computeSDBunchDigi(c, *preshowerHits, esSignalSimMap, thisDet, esThreshold_);
647 
648  }
649 
650 }
651 
653 
654  // ADC -> GeV Scale
656  eventSetup.get<EcalADCToGeVConstantRcd>().get(pAgc);
657  const EcalADCToGeVConstant* agc = pAgc.product();
658 
659  EcalMGPAGainRatio * defaultRatios = new EcalMGPAGainRatio();
660 
661  gainConv_[1] = 1.;
662  gainConv_[2] = defaultRatios->gain12Over6() ;
663  gainConv_[3] = gainConv_[2]*(defaultRatios->gain6Over1()) ;
664  gainConv_[0] = gainConv_[2]*(defaultRatios->gain6Over1()) ;
665 
666  LogDebug("EcalDigi") << " Gains conversions: " << "\n" << " g1 = " << gainConv_[1] << "\n" << " g2 = " << gainConv_[2] << "\n" << " g3 = " << gainConv_[3];
667 
668  delete defaultRatios;
669 
670  const double barrelADCtoGeV_ = agc->getEBValue();
671  LogDebug("EcalDigi") << " Barrel GeV/ADC = " << barrelADCtoGeV_;
672  const double endcapADCtoGeV_ = agc->getEEValue();
673  LogDebug("EcalDigi") << " Endcap GeV/ADC = " << endcapADCtoGeV_;
674 
675 
676  // ES condition objects
677  edm::ESHandle<ESGain> esgain_;
679  edm::ESHandle<ESPedestals> esPedestals_;
681 
682  eventSetup.get<ESGainRcd>().get(esgain_);
683  eventSetup.get<ESMIPToGeVConstantRcd>().get(esMIPToGeV_);
684  eventSetup.get<ESPedestalsRcd>().get(esPedestals_);
685  eventSetup.get<ESIntercalibConstantsRcd>().get(esMIPs_);
686 
687  const ESGain *esgain = esgain_.product();
688  m_ESpeds = esPedestals_.product();
689  m_ESmips = esMIPs_.product();
690  const ESMIPToGeVConstant *esMipToGeV = esMIPToGeV_.product();
691  m_ESgain = (int) esgain->getESGain();
692  const double valESMIPToGeV = (m_ESgain == 1) ? esMipToGeV->getESValueLow() : esMipToGeV->getESValueHigh();
693 
695 
696  esADCtokeV_ = 1000000.*valESMIPToGeV ;
697 
698  m_ESeffwei = ( 0 == m_ESgain ? 1.45 :
699  ( 1 == m_ESgain ? 0.9066 :
700  ( 2 == m_ESgain ? 0.8815 : 1.0 ) ) ) ;
701 
702 }
703 
705 {
706 
707  // Pedestals from event setup
708 
710  eventSetup.get<EcalPedestalsRcd>().get( dbPed );
711  thePedestals=dbPed.product();
712 
713 }
714 
715 void EcalMixingModuleValidation::findPedestal(const DetId & detId, int gainId, double & ped) const
716 {
718  = thePedestals->getMap().find(detId);
719  // should I care if it doesn't get found?
720  if(mapItr == thePedestals->getMap().end()) {
721  edm::LogError("EcalMMValid") << "Could not find pedestal for " << detId.rawId() << " among the " << thePedestals->getMap().size();
722  } else {
723  EcalPedestals::Item item = (*mapItr);
724 
725  switch(gainId) {
726  case 0:
727  ped = item.mean_x1;
728  case 1:
729  ped = item.mean_x12;
730  break;
731  case 2:
732  ped = item.mean_x6;
733  break;
734  case 3:
735  ped = item.mean_x1;
736  break;
737  default:
738  edm::LogError("EcalMMValid") << "Bad Pedestal " << gainId;
739  break;
740  }
741  LogDebug("EcalMMValid") << "Pedestals for " << detId.rawId() << " gain range " << gainId << " : \n" << "Mean = " << ped;
742  }
743 }
744 
745 void EcalMixingModuleValidation::computeSDBunchDigi(const edm::EventSetup & eventSetup, MixCollection<PCaloHit> & theHits, MapType & SignalSimMap, const EcalSubdetector & thisDet, const double & theSimThreshold)
746 {
747 
748  if ( thisDet != EcalBarrel && thisDet != EcalEndcap && thisDet != EcalPreshower ) {
749  edm::LogError("EcalMMValid") << "Invalid subdetector type";
750  return;
751  }
752  //bool isCrystal = true;
753  //if ( thisDet == EcalPreshower ) isCrystal = false;
754 
755  // load the geometry
756 
757  edm::ESHandle<CaloGeometry> hGeometry;
758  eventSetup.get<CaloGeometryRecord>().get(hGeometry);
759 
760  const CaloGeometry * pGeometry = &*hGeometry;
761 
762  // see if we need to update
763  if(pGeometry != theGeometry) {
764  theGeometry = pGeometry;
765  //theEcalResponse->setGeometry(theGeometry);
769 
770  }
771 
772  // vector of DetId with energy above a fraction of the gun's energy
773 
774  const std::vector<DetId>& theSDId = theGeometry->getValidDetIds( DetId::Ecal, thisDet );
775 
776  std::vector<DetId> theOverThresholdId;
777  for ( unsigned int i = 0 ; i < theSDId.size() ; i++ ) {
778 
779  int sdId = theSDId[i].rawId();
780  if ( SignalSimMap[sdId] > theSimThreshold ) theOverThresholdId.push_back( theSDId[i] );
781 
782  }
783 
785  if ( thisDet == EcalPreshower ) limit = ESDataFrame::MAXSAMPLES;
786 
787  for (int iBunch = theMinBunch ; iBunch <= theMaxBunch ; iBunch++ ) {
788 
789  //if ( isCrystal ) {
790  if( thisDet == EcalBarrel ) {
791  theEBResponse->setBunchRange(iBunch, iBunch);
792  theEBResponse->clear();
793  theEBResponse->run(theHits);
794  }
795  else if( thisDet == EcalEndcap ) {
796  theEEResponse->setBunchRange(iBunch, iBunch);
797  theEEResponse->clear();
798  theEEResponse->run(theHits);
799  }
800  else {
801  theESResponse->setBunchRange(iBunch, iBunch);
802  theESResponse->clear();
803  theESResponse->run(theHits);
804  }
805 
806  int iHisto = iBunch - theMinBunch;
807 
808  for ( std::vector<DetId>::const_iterator idItr = theOverThresholdId.begin() ; idItr != theOverThresholdId.end() ; ++idItr ) {
809 
810  CaloSamples * analogSignal;
811  //if ( isCrystal )
812  if( thisDet == EcalBarrel ) {
813  analogSignal = theEBResponse->findSignal(*idItr);
814  }
815  else if( thisDet == EcalEndcap ) {
816  analogSignal = theEEResponse->findSignal(*idItr);
817  }
818  else {
819  analogSignal = theESResponse->findSignal(*idItr);
820  }
821 
822  if ( analogSignal ) {
823 
824  (*analogSignal) *= theParameterMap->simParameters(analogSignal->id()).photoelectronsToAnalog();
825 
826  for ( int i = 0 ; i < limit ; i++ ) {
827  if ( thisDet == EcalBarrel ) { meEBBunchShape_[iHisto]->Fill(i,(float)(*analogSignal)[i]); }
828  else if ( thisDet == EcalEndcap ) { meEEBunchShape_[iHisto]->Fill(i,(float)(*analogSignal)[i]); }
829  else if ( thisDet == EcalPreshower ) { meESBunchShape_[iHisto]->Fill(i,(float)(*analogSignal)[i]); }
830  }
831  }
832 
833  }
834 
835  }
836 
837  }
#define LogDebug(id)
T getParameter(std::string const &) const
void setGeometry(const CaloGeometry *geometry)
geometry needed for time-of-flight
T getUntrackedParameter(std::string const &, T const &) const
void checkPedestals(const edm::EventSetup &c)
int i
Definition: DBlmapReader.cc:9
void setBinContent(int binx, double content)
set content of bin (1-D)
int strip() const
Definition: ESDetId.h:52
const ESIntercalibConstants * m_ESmips
int ix() const
Definition: EEDetId.h:76
void computeSDBunchDigi(const edm::EventSetup &eventSetup, MixCollection< PCaloHit > &theHits, MapType &ebSignalSimMap, const EcalSubdetector &thisDet, const double &theSimThreshold)
key_type id() const
Definition: EBDataFrame.h:31
edm::EDGetTokenT< CrossingFrame< PCaloHit > > crossingFramePCaloHitESToken_
void findPedestal(const DetId &detId, int gainId, double &ped) const
static const int MAXSAMPLES
Definition: CaloSamples.h:73
virtual const CaloSimParameters & simParameters(const DetId &id) const
return the sim parameters relative to the right subdet
int gainId(sample_type sample)
get the gainId (2 bits)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
Definition: ESGain.h:5
void setGain(const int gain)
Definition: ESShape.h:26
const self & getMap() const
edm::EDGetTokenT< edm::HepMCProduct > HepMCToken_
const ESDetId & id() const
Definition: ESDataFrame.h:21
const self & getMap() const
float getESValueLow() const
void checkCalibrations(edm::EventSetup const &c)
MonitorElement * meEEBunchShape_[nBunch]
edm::EDGetTokenT< EBDigiCollection > EBdigiCollectionToken_
MonitorElement * meEBBunchShape_[nBunch]
int six() const
Definition: ESDetId.h:48
int size() const
Definition: ESDataFrame.h:23
int gainId() const
get the gainId (2 bits)
int size() const
Definition: EcalDataFrame.h:26
void Fill(long long x)
int iphi() const
get the crystal iphi
Definition: EBDetId.h:53
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
edm::EDGetTokenT< CrossingFrame< PCaloHit > > crossingFramePCaloHitEEToken_
int siy() const
Definition: ESDetId.h:50
EcalPedestalsMap::const_iterator EcalPedestalsMapIterator
Definition: EcalPedestals.h:48
void bunchSumTest(std::vector< MonitorElement * > &theBunches, MonitorElement *&theTotal, MonitorElement *&theRatio, int nSample)
MonitorElement * meESBunchShape_[nBunch]
Creates electronics signals from hits.
T sqrt(T t)
Definition: SSEVec.h:48
static const int MAXSAMPLES
Definition: ESDataFrame.h:32
const_iterator find(uint32_t rawId) const
int zside() const
Definition: EEDetId.h:70
int iy() const
Definition: EEDetId.h:82
void setBinError(int binx, double error)
set uncertainty on content of bin (1-D)
float gain6Over1() const
int ieta() const
get the crystal ieta
Definition: EBDetId.h:51
int zside() const
Definition: ESDetId.h:44
bool isValid() const
Definition: HandleBase.h:76
edm::EDGetTokenT< CrossingFrame< PCaloHit > > crossingFramePCaloHitEBToken_
key_type id() const
Definition: EEDataFrame.h:28
Definition: EBShape.h:6
std::map< int, double, std::less< int > > gainConv_
void analyze(edm::Event const &e, edm::EventSetup const &c)
Analyze.
virtual void run(MixCollection< PCaloHit > &hits)
Complete cell digitization.
Definition: DetId.h:18
const EcalSimParameterMap * theParameterMap
std::map< uint32_t, float, std::less< uint32_t > > MapType
edm::EDGetTokenT< ESDigiCollection > ESdigiCollectionToken_
float getESGain() const
Definition: ESGain.h:11
double getBinError(int binx) const
get uncertainty on content of bin (1-D) - See TH1::GetBinError for details
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
float gain12Over6() const
T const * product() const
Definition: Handle.h:81
void setBunchRange(int minBunch, int maxBunch)
tells it which pileup bunches to do
std::vector< DetId > getValidDetIds() const
Get the list of all valid detector ids.
Definition: CaloGeometry.cc:90
CaloSamples * findSignal(const DetId &detId)
users can look for the signal for a given cell
double getBinContent(int binx) const
get content of bin (1-D)
void clear()
frees up memory
int plane() const
Definition: ESDetId.h:46
void endRun(const edm::Run &r, const edm::EventSetup &c)
const_iterator find(uint32_t rawId) const
void beginRun(edm::Run const &, edm::EventSetup const &c)
tuple cout
Definition: gather_cfg.py:121
const_iterator end() const
int adc() const
get the ADC sample (singed 16 bits)
Definition: ESSample.h:18
DetId id() const
get the (generic) id
Definition: CaloSamples.h:21
EcalMixingModuleValidation(const edm::ParameterSet &ps)
Constructor.
EcalSubdetector
float getESValueHigh() const
static const int MAXSAMPLES
Definition: EcalDataFrame.h:48
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
edm::EDGetTokenT< EEDigiCollection > EEdigiCollectionToken_
Definition: Run.h:41
Definition: EEShape.h:6
int adc() const
get the ADC sample (12 bits)