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 pedestalPreSampleAnalog = 0.;
240 
241  for (int sample = 0; sample < nrSamples; ++sample) {
242  ebAnalogSignal[sample] = 0.;
243  ebADCCounts[sample] = 0.;
244  ebADCGains[sample] = -1.;
245  }
246 
247  for (int sample = 0; sample < nrSamples; ++sample) {
249 
250  ebADCCounts[sample] = (mySample.adc());
251  ebADCGains[sample] = (mySample.gainId());
252  ebAnalogSignal[sample] = (ebADCCounts[sample] * gainConv_[(int)ebADCGains[sample]] * barrelADCtoGeV_);
253  if (Emax < ebAnalogSignal[sample]) {
254  Emax = ebAnalogSignal[sample];
255  Pmax = sample;
256  }
257  if (sample < 3) {
258  pedestalPreSampleAnalog += ebADCCounts[sample] * gainConv_[(int)ebADCGains[sample]] * barrelADCtoGeV_;
259  }
260  LogDebug("DigiInfo") << "EB sample " << sample << " ADC counts = " << ebADCCounts[sample]
261  << " Gain Id = " << ebADCGains[sample] << " Analog eq = " << ebAnalogSignal[sample];
262  }
263 
264  pedestalPreSampleAnalog /= 3.;
265  double Erec = Emax - pedestalPreSampleAnalog * gainConv_[(int)ebADCGains[Pmax]];
266 
267  if (ebSimMap[ebid.rawId()] != 0.) {
268  LogDebug("DigiInfo") << " Digi / Hit = " << Erec << " / " << ebSimMap[ebid.rawId()] << " gainConv "
269  << gainConv_[(int)ebADCGains[Pmax]];
270  if (meEBDigiSimRatio_)
271  meEBDigiSimRatio_->Fill(Erec / ebSimMap[ebid.rawId()]);
272  if (Erec > 10. * barrelADCtoGeV_ && meEBDigiSimRatiogt10ADC_)
273  meEBDigiSimRatiogt10ADC_->Fill(Erec / ebSimMap[ebid.rawId()]);
274  if (Erec > 100. * barrelADCtoGeV_ && meEBDigiSimRatiogt100ADC_)
275  meEBDigiSimRatiogt100ADC_->Fill(Erec / ebSimMap[ebid.rawId()]);
276  }
277  }
278  }
279 
280  // ENDCAP
281 
282  // loop over simHits
283 
284  if (isEndcap) {
285  e.getByToken(crossingFramePCaloHitEEToken_, crossingFrame);
286  const MixCollection<PCaloHit> endcapHits(crossingFrame.product());
287 
288  MapType eeSimMap;
289  for (auto const& iHit : endcapHits) {
290  EEDetId eeid = EEDetId(iHit.id());
291 
292  LogDebug("HitInfo") << " CaloHit " << iHit.getName() << "\n"
293  << " DetID = " << iHit.id() << " EEDetId side = " << eeid.zside() << " = " << eeid.ix() << " "
294  << eeid.iy() << "\n"
295  << " Time = " << iHit.time() << " Event id. = " << iHit.eventId().rawId() << "\n"
296  << " Track Id = " << iHit.geantTrackId() << "\n"
297  << " Energy = " << iHit.energy();
298 
299  uint32_t crystid = eeid.rawId();
300  eeSimMap[crystid] += iHit.energy();
301  }
302 
303  // loop over Digis
304 
305  const EEDigiCollection* endcapDigi = EcalDigiEE.product();
306 
307  std::vector<double> eeAnalogSignal;
308  std::vector<double> eeADCCounts;
309  std::vector<double> eeADCGains;
310  eeAnalogSignal.reserve(EEDataFrame::MAXSAMPLES);
311  eeADCCounts.reserve(EEDataFrame::MAXSAMPLES);
312  eeADCGains.reserve(EEDataFrame::MAXSAMPLES);
313 
314  for (unsigned int digis = 0; digis < EcalDigiEE->size(); ++digis) {
315  EEDataFrame eedf = (*endcapDigi)[digis];
316  int nrSamples = eedf.size();
317 
318  EEDetId eeid = eedf.id();
319 
320  double Emax = 0.;
321  int Pmax = 0;
322  double pedestalPreSampleAnalog = 0.;
323 
324  for (int sample = 0; sample < nrSamples; ++sample) {
325  eeAnalogSignal[sample] = 0.;
326  eeADCCounts[sample] = 0.;
327  eeADCGains[sample] = -1.;
328  }
329 
330  for (int sample = 0; sample < nrSamples; ++sample) {
332 
333  eeADCCounts[sample] = (mySample.adc());
334  eeADCGains[sample] = (mySample.gainId());
335  eeAnalogSignal[sample] = (eeADCCounts[sample] * gainConv_[(int)eeADCGains[sample]] * endcapADCtoGeV_);
336  if (Emax < eeAnalogSignal[sample]) {
337  Emax = eeAnalogSignal[sample];
338  Pmax = sample;
339  }
340  if (sample < 3) {
341  pedestalPreSampleAnalog += eeADCCounts[sample] * gainConv_[(int)eeADCGains[sample]] * endcapADCtoGeV_;
342  }
343  LogDebug("DigiInfo") << "EE sample " << sample << " ADC counts = " << eeADCCounts[sample]
344  << " Gain Id = " << eeADCGains[sample] << " Analog eq = " << eeAnalogSignal[sample];
345  }
346  pedestalPreSampleAnalog /= 3.;
347  double Erec = Emax - pedestalPreSampleAnalog * gainConv_[(int)eeADCGains[Pmax]];
348 
349  if (eeSimMap[eeid.rawId()] != 0.) {
350  LogDebug("DigiInfo") << " Digi / Hit = " << Erec << " / " << eeSimMap[eeid.rawId()] << " gainConv "
351  << gainConv_[(int)eeADCGains[Pmax]];
352  if (meEEDigiSimRatio_)
353  meEEDigiSimRatio_->Fill(Erec / eeSimMap[eeid.rawId()]);
354  if (Erec > 20. * endcapADCtoGeV_ && meEEDigiSimRatiogt20ADC_)
355  meEEDigiSimRatiogt20ADC_->Fill(Erec / eeSimMap[eeid.rawId()]);
356  if (Erec > 100. * endcapADCtoGeV_ && meEEDigiSimRatiogt100ADC_)
357  meEEDigiSimRatiogt100ADC_->Fill(Erec / eeSimMap[eeid.rawId()]);
358  }
359  }
360  }
361 
362  if (isPreshower) {
363  e.getByToken(crossingFramePCaloHitESToken_, crossingFrame);
364  const MixCollection<PCaloHit> preshowerHits(crossingFrame.product());
365  for (auto const& iHit : preshowerHits) {
366  ESDetId esid = ESDetId(iHit.id());
367 
368  LogDebug("HitInfo") << " CaloHit " << iHit.getName() << "\n"
369  << " DetID = " << iHit.id() << "ESDetId: z side " << esid.zside() << " plane "
370  << esid.plane() << esid.six() << ',' << esid.siy() << ':' << esid.strip() << "\n"
371  << " Time = " << iHit.time() << " Event id. = " << iHit.eventId().rawId() << "\n"
372  << " Track Id = " << iHit.geantTrackId() << "\n"
373  << " Energy = " << iHit.energy();
374  }
375  }
376 }
377 
379  // ADC -> GeV Scale
380  const EcalADCToGeVConstant* agc = &eventSetup.getData(pAgc);
381 
382  EcalMGPAGainRatio* defaultRatios = new EcalMGPAGainRatio();
383 
384  gainConv_[1] = 1.;
385  gainConv_[2] = defaultRatios->gain12Over6();
386  gainConv_[3] = gainConv_[2] * (defaultRatios->gain6Over1());
387  gainConv_[0] = gainConv_[2] * (defaultRatios->gain6Over1()); // saturated channels
388 
389  LogDebug("EcalDigi") << " Gains conversions: "
390  << "\n"
391  << " g1 = " << gainConv_[1] << "\n"
392  << " g2 = " << gainConv_[2] << "\n"
393  << " g3 = " << gainConv_[3];
394  LogDebug("EcalDigi") << " Gains conversions: "
395  << "\n"
396  << " saturation = " << gainConv_[0];
397 
398  delete defaultRatios;
399 
400  const double barrelADCtoGeV_ = agc->getEBValue();
401  LogDebug("EcalDigi") << " Barrel GeV/ADC = " << barrelADCtoGeV_;
402  const double endcapADCtoGeV_ = agc->getEEValue();
403  LogDebug("EcalDigi") << " Endcap GeV/ADC = " << endcapADCtoGeV_;
404 }
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:36
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)