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