CMS 3D CMS Logo

EcalSignalGenerator.h
Go to the documentation of this file.
1 #ifndef EcalSimAlgos_EcalSignalGenerator_h
2 #define EcalSimAlgos_EcalSignalGenerator_h
3 
33 
38 #include <iostream>
39 #include <memory>
40 
41 namespace edm {
42  class ModuleCallingContext;
43 }
44 
45 template <class ECALDIGITIZERTRAITS>
47 public:
48  typedef typename ECALDIGITIZERTRAITS::Digi DIGI;
49  typedef typename ECALDIGITIZERTRAITS::DigiCollection COLLECTION;
50 
52 
55  const double EBs25notCont,
56  const double EEs25notCont,
57  const double peToABarrel,
58  const double peToAEndcap)
59  : EcalBaseSignalGenerator(), theEvent(nullptr), theEventPrincipal(nullptr), theInputTag(inputTag), tok_(t) {
60  EcalMGPAGainRatio* defaultRatios = new EcalMGPAGainRatio();
61  theDefaultGains[2] = defaultRatios->gain6Over1();
62  theDefaultGains[1] = theDefaultGains[2] * (defaultRatios->gain12Over6());
63  m_EBs25notCont = EBs25notCont;
64  m_EEs25notCont = EEs25notCont;
65  m_peToABarrel = peToABarrel;
66  m_peToAEndcap = peToAEndcap;
67  }
68 
69  ~EcalSignalGenerator() override {}
70 
71  void initializeEvent(const edm::Event* event, const edm::EventSetup* eventSetup) {
72  theEvent = event;
73  eventSetup->get<EcalGainRatiosRcd>().get(grHandle); // find the gains
74  // Ecal Intercalibration Constants
75  eventSetup->get<EcalIntercalibConstantsMCRcd>().get(pIcal);
76  ical = pIcal.product();
77  // adc to GeV
78  eventSetup->get<EcalADCToGeVConstantRcd>().get(pAgc);
79  agc = pAgc.product();
80 
81  m_maxEneEB = (agc->getEBValue()) * theDefaultGains[1] * MAXADC * m_EBs25notCont;
82  m_maxEneEE = (agc->getEEValue()) * theDefaultGains[1] * MAXADC * m_EEs25notCont;
83 
84  //ES
85  eventSetup->get<ESGainRcd>().get(hesgain);
86  eventSetup->get<ESMIPToGeVConstantRcd>().get(hesMIPToGeV);
87  eventSetup->get<ESIntercalibConstantsRcd>().get(hesMIPs);
88 
89  esgain = hesgain.product();
90  esmips = hesMIPs.product();
91  esMipToGeV = hesMIPToGeV.product();
92  if (1.1 > esgain->getESGain())
93  ESgain = 1;
94  else
95  ESgain = 2;
96  if (ESgain == 1)
97  ESMIPToGeV = esMipToGeV->getESValueLow();
98  else
99  ESMIPToGeV = esMipToGeV->getESValueHigh();
100  }
101 
103  void initializeEvent(const edm::EventPrincipal* eventPrincipal, const edm::EventSetup* eventSetup) {
104  theEventPrincipal = eventPrincipal;
105  eventSetup->get<EcalGainRatiosRcd>().get(grHandle); // find the gains
106  // Ecal Intercalibration Constants
107  eventSetup->get<EcalIntercalibConstantsMCRcd>().get(pIcal);
108  ical = pIcal.product();
109  // adc to GeV
110  eventSetup->get<EcalADCToGeVConstantRcd>().get(pAgc);
111  agc = pAgc.product();
112  m_maxEneEB = (agc->getEBValue()) * theDefaultGains[1] * MAXADC * m_EBs25notCont;
113  m_maxEneEE = (agc->getEEValue()) * theDefaultGains[1] * MAXADC * m_EEs25notCont;
114 
115  //ES
116  eventSetup->get<ESGainRcd>().get(hesgain);
117  eventSetup->get<ESMIPToGeVConstantRcd>().get(hesMIPToGeV);
118  eventSetup->get<ESIntercalibConstantsRcd>().get(hesMIPs);
119 
120  esgain = hesgain.product();
121  esmips = hesMIPs.product();
122  esMipToGeV = hesMIPToGeV.product();
123  if (1.1 > esgain->getESGain())
124  ESgain = 1;
125  else
126  ESgain = 2;
127  if (ESgain == 1)
128  ESMIPToGeV = esMipToGeV->getESValueLow();
129  else
130  ESMIPToGeV = esMipToGeV->getESValueHigh();
131  }
132 
133  virtual void fill(edm::ModuleCallingContext const* mcc) {
134  theNoiseSignals.clear();
136  const COLLECTION* digis = nullptr;
137  // try accessing by whatever is set, Event or EventPrincipal
138  if (theEvent) {
139  if (theEvent->getByToken(tok_, pDigis)) {
140  digis = pDigis.product(); // get a ptr to the product
141  } else {
142  throw cms::Exception("EcalSignalGenerator") << "Cannot find input data " << theInputTag;
143  }
144  } else if (theEventPrincipal) {
145  std::shared_ptr<edm::Wrapper<COLLECTION> const> digisPTR =
146  edm::getProductByTag<COLLECTION>(*theEventPrincipal, theInputTag, mcc);
147  if (digisPTR) {
148  digis = digisPTR->product();
149  }
150  } else {
151  throw cms::Exception("EcalSignalGenerator") << "No Event or EventPrincipal was set";
152  }
153 
154  if (digis) {
155  // loop over digis, adding these to the existing maps
156  for (typename COLLECTION::const_iterator it = digis->begin(); it != digis->end(); ++it) {
157  // need to convert to something useful
158  if (validDigi(*it)) {
159  theNoiseSignals.push_back(samplesInPE(*it));
160  }
161  }
162  }
163  //else { std::cout << " NO digis for this input: " << theInputTag << std::endl;}
164  }
165 
166 private:
167  bool validDigi(const DIGI& digi) {
168  int DigiSum = 0;
169  for (int id = 0; id < digi.size(); id++) {
170  if (digi[id].adc() > 0)
171  ++DigiSum;
172  }
173  return (DigiSum > 0);
174  }
175 
176  void fillNoiseSignals() override {}
177  void fillNoiseSignals(CLHEP::HepRandomEngine*) override {}
178 
179  // much of this stolen from EcalSimAlgos/EcalCoder
180 
181  enum {
182  NBITS = 12, // number of available bits
183  MAXADC = 4095, // 2^12 -1, adc max range
184  ADCGAINSWITCH = 4079, // adc gain switch
185  NGAINS = 3
186  }; // number of electronic gains
187 
188  CaloSamples samplesInPE(const DIGI& digi); // have to define this separately for ES
189 
190  const std::vector<float> GetGainRatios(const DetId& detid) {
191  std::vector<float> gainRatios(4);
192  // get gain ratios
193  EcalMGPAGainRatio theRatio = (*grHandle)[detid];
194 
195  gainRatios[0] = 0.;
196  gainRatios[3] = 1.;
197  gainRatios[2] = theRatio.gain6Over1();
198  gainRatios[1] = theRatio.gain6Over1() * theRatio.gain12Over6();
199 
200  return gainRatios;
201  }
202 
203  double fullScaleEnergy(const DetId& detId) const { return detId.subdetId() == EcalBarrel ? m_maxEneEB : m_maxEneEE; }
204 
205  double peToAConversion(const DetId& detId) const {
206  return detId.subdetId() == EcalBarrel ? m_peToABarrel : m_peToAEndcap;
207  }
208 
212 
216 
220 
224 
225  const ESGain* esgain;
228  int ESgain;
229  double ESMIPToGeV;
230 
233 
236 
237  double m_maxEneEB; // max attainable energy in the ecal barrel
238  double m_maxEneEE; // max attainable energy in the ecal endcap
239 
242 
243  double theDefaultGains[NGAINS];
244 };
245 
249 
250 #endif
const edm::Event * theEvent
these fields are set in initializeEvent()
EcalSignalGenerator< EBDigitizerTraits > EBSignalGenerator
ECALDIGITIZERTRAITS::DigiCollection COLLECTION
edm::ESHandle< ESMIPToGeVConstant > hesMIPToGeV
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
virtual void fill(edm::ModuleCallingContext const *mcc)
Definition: ESGain.h:7
void fillNoiseSignals(CLHEP::HepRandomEngine *) override
#define nullptr
const std::vector< float > GetGainRatios(const DetId &detid)
edm::EDGetTokenT< COLLECTION > tok_
const_iterator begin() const
double fullScaleEnergy(const DetId &detId) const
std::tuple< unsigned int, int, int, DigiType, int, int, int, float > Digi
Definition: GenericDigi.h:40
int size() const
Definition: EcalDataFrame.h:26
edm::ESHandle< ESIntercalibConstants > hesMIPs
edm::ESHandle< ESGain > hesgain
EcalSignalGenerator(const edm::InputTag &inputTag, const edm::EDGetTokenT< COLLECTION > &t, const double EBs25notCont, const double EEs25notCont, const double peToABarrel, const double peToAEndcap)
bool validDigi(const DIGI &digi)
const EcalIntercalibConstantsMC * ical
edm::ESHandle< EcalADCToGeVConstant > pAgc
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:41
void initializeEvent(const edm::Event *event, const edm::EventSetup *eventSetup)
float gain6Over1() const
const EcalADCToGeVConstant * agc
constexpr int adc(sample_type sample)
get the ADC sample (12 bits)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
void initializeEvent(const edm::EventPrincipal *eventPrincipal, const edm::EventSetup *eventSetup)
some users use EventPrincipals, not Events. We support both
EcalSignalGenerator< ESDigitizerTraits > ESSignalGenerator
void fillNoiseSignals() override
Definition: DetId.h:18
edm::ESHandle< EcalGainRatios > grHandle
const edm::EventPrincipal * theEventPrincipal
T const * product() const
Definition: Handle.h:74
edm::InputTag theInputTag
these come from the ParameterSet
ECALDIGITIZERTRAITS::Digi DIGI
float gain12Over6() const
const_iterator end() const
double peToAConversion(const DetId &detId) const
HLT enums.
T get() const
Definition: EventSetup.h:71
edm::ESHandle< EcalIntercalibConstantsMC > pIcal
EcalSignalGenerator< EEDigitizerTraits > EESignalGenerator
const ESIntercalibConstants * esmips
Definition: event.py:1
const ESMIPToGeVConstant * esMipToGeV