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