CMS 3D CMS Logo

EcalDigisValidation.cc
Go to the documentation of this file.
1 /*
2  * \file EcalDigisValidation.cc
3  *
4  * \author F. Cossutti
5  *
6 */
7 
8 #include "EcalDigisValidation.h"
13 
15  : HepMCToken_(consumes<edm::HepMCProduct>(edm::InputTag(ps.getParameter<std::string>("moduleLabelMC")))),
16  g4TkInfoToken_(consumes<edm::SimTrackContainer>(edm::InputTag(ps.getParameter<std::string>("moduleLabelG4")))),
17  g4VtxInfoToken_(consumes<edm::SimVertexContainer>(edm::InputTag(ps.getParameter<std::string>("moduleLabelG4")))),
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  pAgc(esConsumes<edm::Transition::BeginRun>()),
22  crossingFramePCaloHitEBToken_(consumes<CrossingFrame<PCaloHit> >(edm::InputTag(
23  std::string("mix"), ps.getParameter<std::string>("moduleLabelG4") + std::string("EcalHitsEB")))),
24  crossingFramePCaloHitEEToken_(consumes<CrossingFrame<PCaloHit> >(edm::InputTag(
25  std::string("mix"), ps.getParameter<std::string>("moduleLabelG4") + std::string("EcalHitsEE")))),
26  crossingFramePCaloHitESToken_(consumes<CrossingFrame<PCaloHit> >(edm::InputTag(
27  std::string("mix"), ps.getParameter<std::string>("moduleLabelG4") + std::string("EcalHitsES")))) {
28  // DQM ROOT output
29  outputFile_ = ps.getUntrackedParameter<std::string>("outputFile", "");
30 
31  if (!outputFile_.empty()) {
32  edm::LogInfo("OutputInfo") << " Ecal Digi Task histograms will be saved to '" << outputFile_.c_str() << "'";
33  } else {
34  edm::LogInfo("OutputInfo") << " Ecal Digi Task histograms will NOT be saved";
35  }
36 
37  // verbosity switch
38  verbose_ = ps.getUntrackedParameter<bool>("verbose", false);
39 
40  gainConv_[1] = 1.;
41  gainConv_[2] = 2.;
42  gainConv_[3] = 12.;
43  gainConv_[0] = 12.; // saturated channels
44  barrelADCtoGeV_ = 0.035;
45  endcapADCtoGeV_ = 0.06;
46 
47  meGunEnergy_ = nullptr;
48  meGunEta_ = nullptr;
49  meGunPhi_ = nullptr;
50 
51  meEBDigiSimRatio_ = nullptr;
52  meEEDigiSimRatio_ = nullptr;
53 
54  meEBDigiSimRatiogt10ADC_ = nullptr;
55  meEEDigiSimRatiogt20ADC_ = nullptr;
56 
57  meEBDigiSimRatiogt100ADC_ = nullptr;
58  meEEDigiSimRatiogt100ADC_ = nullptr;
59 }
60 
62 
64 
66  Char_t histo[200];
67 
68  ibooker.setCurrentFolder("EcalDigisV/EcalDigiTask");
69 
70  sprintf(histo, "EcalDigiTask Gun Momentum");
71  meGunEnergy_ = ibooker.book1D(histo, histo, 100, 0., 1000.);
72 
73  sprintf(histo, "EcalDigiTask Gun Eta");
74  meGunEta_ = ibooker.book1D(histo, histo, 700, -3.5, 3.5);
75 
76  sprintf(histo, "EcalDigiTask Gun Phi");
77  meGunPhi_ = ibooker.book1D(histo, histo, 360, 0., 360.);
78 
79  sprintf(histo, "EcalDigiTask Barrel maximum Digi over Sim ratio");
80  meEBDigiSimRatio_ = ibooker.book1D(histo, histo, 100, 0., 2.);
81 
82  sprintf(histo, "EcalDigiTask Endcap maximum Digi over Sim ratio");
83  meEEDigiSimRatio_ = ibooker.book1D(histo, histo, 100, 0., 2.);
84 
85  sprintf(histo, "EcalDigiTask Barrel maximum Digi over Sim ratio gt 10 ADC");
86  meEBDigiSimRatiogt10ADC_ = ibooker.book1D(histo, histo, 100, 0., 2.);
87 
88  sprintf(histo, "EcalDigiTask Endcap maximum Digi over Sim ratio gt 20 ADC");
89  meEEDigiSimRatiogt20ADC_ = ibooker.book1D(histo, histo, 100, 0., 2.);
90 
91  sprintf(histo, "EcalDigiTask Barrel maximum Digi over Sim ratio gt 100 ADC");
92  meEBDigiSimRatiogt100ADC_ = ibooker.book1D(histo, histo, 100, 0., 2.);
93 
94  sprintf(histo, "EcalDigiTask Endcap maximum Digi over Sim ratio gt 100 ADC");
95  meEEDigiSimRatiogt100ADC_ = ibooker.book1D(histo, histo, 100, 0., 2.);
96 }
97 
99  edm::LogInfo("EventInfo") << " Run = " << e.id().run() << " Event = " << e.id().event();
100 
101  std::vector<SimTrack> theSimTracks;
102  std::vector<SimVertex> theSimVertexes;
103 
107  edm::Handle<CrossingFrame<PCaloHit> > crossingFrame;
111 
112  bool skipMC = false;
113  e.getByToken(HepMCToken_, MCEvt);
114  if (!MCEvt.isValid()) {
115  skipMC = true;
116  }
117  e.getByToken(g4TkInfoToken_, SimTk);
118  e.getByToken(g4VtxInfoToken_, SimVtx);
119 
120  const EBDigiCollection* EBdigis = nullptr;
121  const EEDigiCollection* EEdigis = nullptr;
122  const ESDigiCollection* ESdigis = nullptr;
123 
124  bool isBarrel = true;
125  e.getByToken(EBdigiCollectionToken_, EcalDigiEB);
126  if (EcalDigiEB.isValid()) {
127  EBdigis = EcalDigiEB.product();
128  LogDebug("DigiInfo") << "total # EBdigis: " << EBdigis->size();
129  if (EBdigis->empty())
130  isBarrel = false;
131  } else {
132  isBarrel = false;
133  }
134 
135  bool isEndcap = true;
136  e.getByToken(EEdigiCollectionToken_, EcalDigiEE);
137  if (EcalDigiEE.isValid()) {
138  EEdigis = EcalDigiEE.product();
139  LogDebug("DigiInfo") << "total # EEdigis: " << EEdigis->size();
140  if (EEdigis->empty())
141  isEndcap = false;
142  } else {
143  isEndcap = false;
144  }
145 
146  bool isPreshower = true;
147  e.getByToken(ESdigiCollectionToken_, EcalDigiES);
148  if (EcalDigiES.isValid()) {
149  ESdigis = EcalDigiES.product();
150  LogDebug("DigiInfo") << "total # ESdigis: " << ESdigis->size();
151  if (ESdigis->empty())
152  isPreshower = false;
153  } else {
154  isPreshower = false;
155  }
156 
157  theSimTracks.insert(theSimTracks.end(), SimTk->begin(), SimTk->end());
158  theSimVertexes.insert(theSimVertexes.end(), SimVtx->begin(), SimVtx->end());
159 
160  if (!skipMC) {
161  double theGunEnergy = 0.;
162  for (HepMC::GenEvent::particle_const_iterator p = MCEvt->GetEvent()->particles_begin();
163  p != MCEvt->GetEvent()->particles_end();
164  ++p) {
165  theGunEnergy = (*p)->momentum().e();
166  double htheta = (*p)->momentum().theta();
167  double heta = -log(tan(htheta * 0.5));
168  double hphi = (*p)->momentum().phi();
169  hphi = (hphi >= 0) ? hphi : hphi + 2 * M_PI;
170  hphi = hphi / M_PI * 180.;
171  LogDebug("EventInfo") << "Particle gun type form MC = " << abs((*p)->pdg_id()) << "\n"
172  << "Energy = " << (*p)->momentum().e() << " Eta = " << heta << " Phi = " << hphi;
173 
174  if (meGunEnergy_)
175  meGunEnergy_->Fill(theGunEnergy);
176  if (meGunEta_)
177  meGunEta_->Fill(heta);
178  if (meGunPhi_)
179  meGunPhi_->Fill(hphi);
180  }
181  }
182 
183  int nvtx = 0;
184  for (std::vector<SimVertex>::iterator isimvtx = theSimVertexes.begin(); isimvtx != theSimVertexes.end(); ++isimvtx) {
185  LogDebug("EventInfo") << " Vertex index = " << nvtx << " event Id = " << isimvtx->eventId().rawId() << "\n"
186  << " vertex dump: " << *isimvtx;
187  ++nvtx;
188  }
189 
190  int ntrk = 0;
191  for (std::vector<SimTrack>::iterator isimtrk = theSimTracks.begin(); isimtrk != theSimTracks.end(); ++isimtrk) {
192  LogDebug("EventInfo") << " Track index = " << ntrk << " track Id = " << isimtrk->trackId()
193  << " event Id = " << isimtrk->eventId().rawId() << "\n"
194  << " track dump: " << *isimtrk;
195  ++ntrk;
196  }
197 
198  // BARREL
199 
200  // loop over simHits
201 
202  if (isBarrel) {
203  e.getByToken(crossingFramePCaloHitEBToken_, crossingFrame);
204  const MixCollection<PCaloHit> barrelHits(crossingFrame.product());
205 
206  MapType ebSimMap;
207  for (auto const& iHit : barrelHits) {
208  EBDetId ebid = EBDetId(iHit.id());
209 
210  LogDebug("HitInfo") << " CaloHit " << iHit.getName() << "\n"
211  << " DetID = " << iHit.id() << " EBDetId = " << ebid.ieta() << " " << ebid.iphi() << "\n"
212  << " Time = " << iHit.time() << " Event id. = " << iHit.eventId().rawId() << "\n"
213  << " Track Id = " << iHit.geantTrackId() << "\n"
214  << " Energy = " << iHit.energy();
215 
216  uint32_t crystid = ebid.rawId();
217  ebSimMap[crystid] += iHit.energy();
218  }
219 
220  // loop over Digis
221 
222  const EBDigiCollection* barrelDigi = EcalDigiEB.product();
223 
224  std::vector<double> ebAnalogSignal;
225  std::vector<double> ebADCCounts;
226  std::vector<double> ebADCGains;
227  ebAnalogSignal.reserve(EBDataFrame::MAXSAMPLES);
228  ebADCCounts.reserve(EBDataFrame::MAXSAMPLES);
229  ebADCGains.reserve(EBDataFrame::MAXSAMPLES);
230 
231  for (unsigned int digis = 0; digis < EcalDigiEB->size(); ++digis) {
232  EBDataFrame ebdf = (*barrelDigi)[digis];
233  int nrSamples = ebdf.size();
234 
235  EBDetId ebid = ebdf.id();
236 
237  double Emax = 0.;
238  int Pmax = 0;
239  double pedestalPreSample = 0.;
240  double pedestalPreSampleAnalog = 0.;
241 
242  for (int sample = 0; sample < nrSamples; ++sample) {
243  ebAnalogSignal[sample] = 0.;
244  ebADCCounts[sample] = 0.;
245  ebADCGains[sample] = -1.;
246  }
247 
248  for (int sample = 0; sample < nrSamples; ++sample) {
250 
251  ebADCCounts[sample] = (mySample.adc());
252  ebADCGains[sample] = (mySample.gainId());
253  ebAnalogSignal[sample] = (ebADCCounts[sample] * gainConv_[(int)ebADCGains[sample]] * barrelADCtoGeV_);
254  if (Emax < ebAnalogSignal[sample]) {
255  Emax = ebAnalogSignal[sample];
256  Pmax = sample;
257  }
258  if (sample < 3) {
259  pedestalPreSample += ebADCCounts[sample];
260  pedestalPreSampleAnalog += ebADCCounts[sample] * gainConv_[(int)ebADCGains[sample]] * barrelADCtoGeV_;
261  }
262  LogDebug("DigiInfo") << "EB sample " << sample << " ADC counts = " << ebADCCounts[sample]
263  << " Gain Id = " << ebADCGains[sample] << " Analog eq = " << ebAnalogSignal[sample];
264  }
265 
266  pedestalPreSample /= 3.;
267  pedestalPreSampleAnalog /= 3.;
268  double Erec = Emax - pedestalPreSampleAnalog * gainConv_[(int)ebADCGains[Pmax]];
269 
270  if (ebSimMap[ebid.rawId()] != 0.) {
271  LogDebug("DigiInfo") << " Digi / Hit = " << Erec << " / " << ebSimMap[ebid.rawId()] << " gainConv "
272  << gainConv_[(int)ebADCGains[Pmax]];
273  if (meEBDigiSimRatio_)
274  meEBDigiSimRatio_->Fill(Erec / ebSimMap[ebid.rawId()]);
275  if (Erec > 10. * barrelADCtoGeV_ && meEBDigiSimRatiogt10ADC_)
276  meEBDigiSimRatiogt10ADC_->Fill(Erec / ebSimMap[ebid.rawId()]);
277  if (Erec > 100. * barrelADCtoGeV_ && meEBDigiSimRatiogt100ADC_)
278  meEBDigiSimRatiogt100ADC_->Fill(Erec / ebSimMap[ebid.rawId()]);
279  }
280  }
281  }
282 
283  // ENDCAP
284 
285  // loop over simHits
286 
287  if (isEndcap) {
288  e.getByToken(crossingFramePCaloHitEEToken_, crossingFrame);
289  const MixCollection<PCaloHit> endcapHits(crossingFrame.product());
290 
291  MapType eeSimMap;
292  for (auto const& iHit : endcapHits) {
293  EEDetId eeid = EEDetId(iHit.id());
294 
295  LogDebug("HitInfo") << " CaloHit " << iHit.getName() << "\n"
296  << " DetID = " << iHit.id() << " EEDetId side = " << eeid.zside() << " = " << eeid.ix() << " "
297  << eeid.iy() << "\n"
298  << " Time = " << iHit.time() << " Event id. = " << iHit.eventId().rawId() << "\n"
299  << " Track Id = " << iHit.geantTrackId() << "\n"
300  << " Energy = " << iHit.energy();
301 
302  uint32_t crystid = eeid.rawId();
303  eeSimMap[crystid] += iHit.energy();
304  }
305 
306  // loop over Digis
307 
308  const EEDigiCollection* endcapDigi = EcalDigiEE.product();
309 
310  std::vector<double> eeAnalogSignal;
311  std::vector<double> eeADCCounts;
312  std::vector<double> eeADCGains;
313  eeAnalogSignal.reserve(EEDataFrame::MAXSAMPLES);
314  eeADCCounts.reserve(EEDataFrame::MAXSAMPLES);
315  eeADCGains.reserve(EEDataFrame::MAXSAMPLES);
316 
317  for (unsigned int digis = 0; digis < EcalDigiEE->size(); ++digis) {
318  EEDataFrame eedf = (*endcapDigi)[digis];
319  int nrSamples = eedf.size();
320 
321  EEDetId eeid = eedf.id();
322 
323  double Emax = 0.;
324  int Pmax = 0;
325  double pedestalPreSample = 0.;
326  double pedestalPreSampleAnalog = 0.;
327 
328  for (int sample = 0; sample < nrSamples; ++sample) {
329  eeAnalogSignal[sample] = 0.;
330  eeADCCounts[sample] = 0.;
331  eeADCGains[sample] = -1.;
332  }
333 
334  for (int sample = 0; sample < nrSamples; ++sample) {
336 
337  eeADCCounts[sample] = (mySample.adc());
338  eeADCGains[sample] = (mySample.gainId());
339  eeAnalogSignal[sample] = (eeADCCounts[sample] * gainConv_[(int)eeADCGains[sample]] * endcapADCtoGeV_);
340  if (Emax < eeAnalogSignal[sample]) {
341  Emax = eeAnalogSignal[sample];
342  Pmax = sample;
343  }
344  if (sample < 3) {
345  pedestalPreSample += eeADCCounts[sample];
346  pedestalPreSampleAnalog += eeADCCounts[sample] * gainConv_[(int)eeADCGains[sample]] * endcapADCtoGeV_;
347  }
348  LogDebug("DigiInfo") << "EE sample " << sample << " ADC counts = " << eeADCCounts[sample]
349  << " Gain Id = " << eeADCGains[sample] << " Analog eq = " << eeAnalogSignal[sample];
350  }
351  pedestalPreSample /= 3.;
352  pedestalPreSampleAnalog /= 3.;
353  double Erec = Emax - pedestalPreSampleAnalog * gainConv_[(int)eeADCGains[Pmax]];
354 
355  if (eeSimMap[eeid.rawId()] != 0.) {
356  LogDebug("DigiInfo") << " Digi / Hit = " << Erec << " / " << eeSimMap[eeid.rawId()] << " gainConv "
357  << gainConv_[(int)eeADCGains[Pmax]];
358  if (meEEDigiSimRatio_)
359  meEEDigiSimRatio_->Fill(Erec / eeSimMap[eeid.rawId()]);
360  if (Erec > 20. * endcapADCtoGeV_ && meEEDigiSimRatiogt20ADC_)
361  meEEDigiSimRatiogt20ADC_->Fill(Erec / eeSimMap[eeid.rawId()]);
362  if (Erec > 100. * endcapADCtoGeV_ && meEEDigiSimRatiogt100ADC_)
363  meEEDigiSimRatiogt100ADC_->Fill(Erec / eeSimMap[eeid.rawId()]);
364  }
365  }
366  }
367 
368  if (isPreshower) {
369  e.getByToken(crossingFramePCaloHitESToken_, crossingFrame);
370  const MixCollection<PCaloHit> preshowerHits(crossingFrame.product());
371  for (auto const& iHit : preshowerHits) {
372  ESDetId esid = ESDetId(iHit.id());
373 
374  LogDebug("HitInfo") << " CaloHit " << iHit.getName() << "\n"
375  << " DetID = " << iHit.id() << "ESDetId: z side " << esid.zside() << " plane "
376  << esid.plane() << esid.six() << ',' << esid.siy() << ':' << esid.strip() << "\n"
377  << " Time = " << iHit.time() << " Event id. = " << iHit.eventId().rawId() << "\n"
378  << " Track Id = " << iHit.geantTrackId() << "\n"
379  << " Energy = " << iHit.energy();
380  }
381  }
382 }
383 
385  // ADC -> GeV Scale
386  const EcalADCToGeVConstant* agc = &eventSetup.getData(pAgc);
387 
388  EcalMGPAGainRatio* defaultRatios = new EcalMGPAGainRatio();
389 
390  gainConv_[1] = 1.;
391  gainConv_[2] = defaultRatios->gain12Over6();
392  gainConv_[3] = gainConv_[2] * (defaultRatios->gain6Over1());
393  gainConv_[0] = gainConv_[2] * (defaultRatios->gain6Over1()); // saturated channels
394 
395  LogDebug("EcalDigi") << " Gains conversions: "
396  << "\n"
397  << " g1 = " << gainConv_[1] << "\n"
398  << " g2 = " << gainConv_[2] << "\n"
399  << " g3 = " << gainConv_[3];
400  LogDebug("EcalDigi") << " Gains conversions: "
401  << "\n"
402  << " saturation = " << gainConv_[0];
403 
404  delete defaultRatios;
405 
406  const double barrelADCtoGeV_ = agc->getEBValue();
407  LogDebug("EcalDigi") << " Barrel GeV/ADC = " << barrelADCtoGeV_;
408  const double endcapADCtoGeV_ = agc->getEEValue();
409  LogDebug("EcalDigi") << " Endcap GeV/ADC = " << endcapADCtoGeV_;
410 }
edm::EDGetTokenT< EEDigiCollection > EEdigiCollectionToken_
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
edm::EDGetTokenT< CrossingFrame< PCaloHit > > crossingFramePCaloHitESToken_
~EcalDigisValidation() override
Destructor.
std::map< uint32_t, float, std::less< uint32_t > > MapType
edm::EDGetTokenT< EBDigiCollection > EBdigiCollectionToken_
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
int iphi() const
get the crystal iphi
Definition: EBDetId.h:51
T const * product() const
Definition: Handle.h:70
int ix() const
Definition: EEDetId.h:77
edm::EDGetTokenT< edm::SimVertexContainer > g4VtxInfoToken_
key_type id() const
Definition: EBDataFrame.h:28
int zside() const
Definition: ESDetId.h:39
void dqmBeginRun(edm::Run const &, edm::EventSetup const &) override
MonitorElement * meEEDigiSimRatiogt100ADC_
key_type id() const
Definition: EEDataFrame.h:24
std::map< int, double, std::less< int > > gainConv_
MonitorElement * meGunEnergy_
int size() const
Definition: EcalDataFrame.h:26
int ieta() const
get the crystal ieta
Definition: EBDetId.h:49
T getUntrackedParameter(std::string const &, T const &) const
void Fill(long long x)
MonitorElement * meEBDigiSimRatiogt10ADC_
void analyze(edm::Event const &e, edm::EventSetup const &c) override
Analyze.
MonitorElement * meEBDigiSimRatio_
int plane() const
Definition: ESDetId.h:41
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Transition
Definition: Transition.h:12
MonitorElement * meGunEta_
bool isEndcap(GeomDetEnumerators::SubDetector m)
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:37
#define M_PI
void reserve(size_t isize)
Log< level::Info, false > LogInfo
float gain12Over6() const
edm::EDGetTokenT< CrossingFrame< PCaloHit > > crossingFramePCaloHitEEToken_
int zside() const
Definition: EEDetId.h:71
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
std::vector< SimVertex > SimVertexContainer
EcalDigisValidation(const edm::ParameterSet &ps)
Constructor.
int siy() const
Definition: ESDetId.h:45
float gain6Over1() const
MonitorElement * meEEDigiSimRatio_
bool isValid() const
Definition: HandleBase.h:70
edm::EDGetTokenT< CrossingFrame< PCaloHit > > crossingFramePCaloHitEBToken_
HLT enums.
int six() const
Definition: ESDetId.h:43
int strip() const
Definition: ESDetId.h:47
MonitorElement * meGunPhi_
edm::ESGetToken< EcalADCToGeVConstant, EcalADCToGeVConstantRcd > pAgc
edm::EDGetTokenT< ESDigiCollection > ESdigiCollectionToken_
MonitorElement * meEEDigiSimRatiogt20ADC_
static constexpr int MAXSAMPLES
Definition: EcalDataFrame.h:48
edm::EDGetTokenT< edm::HepMCProduct > HepMCToken_
void checkCalibrations(edm::EventSetup const &c)
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
void bookHistograms(DQMStore::IBooker &i, edm::Run const &, edm::EventSetup const &) override
std::vector< SimTrack > SimTrackContainer
MonitorElement * meEBDigiSimRatiogt100ADC_
edm::EDGetTokenT< edm::SimTrackContainer > g4TkInfoToken_
Definition: Run.h:45
int iy() const
Definition: EEDetId.h:83
#define LogDebug(id)