CMS 3D CMS Logo

EcalSignalGenerator.h
Go to the documentation of this file.
1 #ifndef EcalSimAlgos_EcalSignalGenerator_h
2 #define EcalSimAlgos_EcalSignalGenerator_h
3 
35 
36 // needed for LC'/LC correction for time dependent MC
40 
45 //#include <iostream>
46 #include <memory>
47 
49 
50 namespace edm {
51  class ModuleCallingContext;
52 }
53 
54 template <class ECALDIGITIZERTRAITS>
56 public:
57  typedef typename ECALDIGITIZERTRAITS::Digi DIGI;
59 
60  typedef std::unordered_map<uint32_t, double> CalibCache;
61 
63 
65  const edm::InputTag& inputTag,
66  const double EBs25notCont,
67  const double EEs25notCont,
68  const double peToABarrel,
69  const double peToAEndcap,
70  const bool timeDependent = false)
78  theEvent(nullptr),
79  theEventPrincipal(nullptr),
81  m_tok(cc.consumes<COLLECTION>(inputTag)),
82  m_EBs25notCont(EBs25notCont),
83  m_EEs25notCont(EEs25notCont),
84  m_peToABarrel(peToABarrel),
85  m_peToAEndcap(peToAEndcap),
87  EcalMGPAGainRatio* defaultRatios = new EcalMGPAGainRatio();
88  theDefaultGains[2] = defaultRatios->gain6Over1();
89  theDefaultGains[1] = theDefaultGains[2] * (defaultRatios->gain12Over6());
90 
91  if (m_timeDependent) {
92  m_laserDbToken = cc.esConsumes();
93  m_laserDbMCToken = cc.esConsumes();
94  }
95  }
96 
97  ~EcalSignalGenerator() override {}
98 
100  theEvent = event;
101  m_gainRatios = &eventSetup->getData(m_gainRatiosToken); // find the gains
102  // Ecal Intercalibration Constants
104  // adc to GeV
106 
109 
110  if (m_timeDependent) {
111  //----
112  //
113  const edm::TimeValue_t eventTimeValue = theEvent->getRun().runAuxiliary().beginTime().value();
114  //
115  // The "time" will have to match in the generation of the tag
116  // for the MC from ECAL (apd/pn, alpha, whatever time dependent is needed)
117  //
118  m_iTime = eventTimeValue;
119 
120  // Ecal LaserCorrection Constants for laser correction ratio
122 
123  //
124  // the "prime" is exactly the same as the usual laser service, BUT
125  // it has only 1 IOV, so that effectively you are dividing IOV_n / IOV_0
126  // NB: in the creation of the tag make sure the "prime" (MC) tag is prepared properly!
127  // NB again: if many IOVs also in "MC" tag, then fancy things could be perfomed ... left for the future
128  //
130 
131  //clear the laser cache for each event time
133  CalibCache().swap(m_valueLCCache_LC_prime); //--- also the "prime" ... yes
134  //----
135  }
136 
137  //ES
138  esgain = &eventSetup->getData(m_esGainToken);
141  if (1.1 > esgain->getESGain())
142  ESgain = 1;
143  else
144  ESgain = 2;
145  if (ESgain == 1)
147  else
149  }
150 
152  void initializeEvent(const edm::EventPrincipal* eventPrincipal, const edm::EventSetup* eventSetup) {
153  theEventPrincipal = eventPrincipal;
154  m_gainRatios = &eventSetup->getData(m_gainRatiosToken); // find the gains
155  // Ecal Intercalibration Constants
157  // adc to GeV
161 
162  if (m_timeDependent) {
163  //----
164  edm::TimeValue_t eventTimeValue = 0;
165  if (theEventPrincipal) {
166  //
167  eventTimeValue = theEventPrincipal->runPrincipal().beginTime().value();
168  //
169  // The "time" will have to match in the generation of the tag
170  // for the MC from ECAL (apd/pn, alpha, whatever time dependent is needed)
171  //
172  } else {
173  edm::LogError("EcalSignalGenerator") << " theEventPrincipal not defined??? " << std::endl;
174  }
175  m_iTime = eventTimeValue;
176 
177  // Ecal LaserCorrection Constants for laser correction ratio
180 
181  //clear the laser cache for each event time
183  CalibCache().swap(m_valueLCCache_LC_prime); //--- also the "prime" ... yes
184  //----
185  }
186 
187  //ES
188  esgain = &eventSetup->getData(m_esGainToken);
191  if (1.1 > esgain->getESGain())
192  ESgain = 1;
193  else
194  ESgain = 2;
195  if (ESgain == 1)
197  else
199  }
200 
201  virtual void fill(edm::ModuleCallingContext const* mcc) {
202  theNoiseSignals.clear();
204  const COLLECTION* digis = nullptr;
205  // try accessing by whatever is set, Event or EventPrincipal
206  if (theEvent) {
207  if (theEvent->getByToken(m_tok, pDigis)) {
208  digis = pDigis.product(); // get a ptr to the product
209  } else {
210  throw cms::Exception("EcalSignalGenerator") << "Cannot find input data " << theInputTag;
211  }
212  } else if (theEventPrincipal) {
213  std::shared_ptr<edm::Wrapper<COLLECTION> const> digisPTR =
214  edm::getProductByTag<COLLECTION>(*theEventPrincipal, theInputTag, mcc);
215  if (digisPTR) {
216  digis = digisPTR->product();
217  }
218  } else {
219  throw cms::Exception("EcalSignalGenerator") << "No Event or EventPrincipal was set";
220  }
221 
222  if (digis) {
223  // loop over digis, adding these to the existing maps
224  for (typename COLLECTION::const_iterator it = digis->begin(); it != digis->end(); ++it) {
225  // need to convert to something useful
226  if (validDigi(*it)) {
227  theNoiseSignals.push_back(samplesInPE(*it));
228  }
229  }
230  }
231  //else { std::cout << " NO digis for this input: " << theInputTag << std::endl;}
232  }
233 
234 private:
235  bool validDigi(const DIGI& digi) {
236  int DigiSum = 0;
237  for (int id = 0; id < digi.size(); id++) {
238  if (digi[id].adc() > 0)
239  ++DigiSum;
240  }
241  return (DigiSum > 0);
242  }
243 
244  void fillNoiseSignals() override {}
245  void fillNoiseSignals(CLHEP::HepRandomEngine*) override {}
246 
247  // much of this stolen from EcalSimAlgos/EcalCoder
248 
249  enum {
250  NBITS = 12, // number of available bits
251  MAXADC = 4095, // 2^12 -1, adc max range
252  ADCGAINSWITCH = 4079, // adc gain switch
253  NGAINS = 3
254  }; // number of electronic gains
255 
256  CaloSamples samplesInPE(const DIGI& digi); // have to define this separately for ES
257 
258  //---- LC that depends with time
259  double findLaserConstant_LC(const DetId& detId) const {
260  const edm::Timestamp& evtTimeStamp = edm::Timestamp(m_iTime);
261  return (m_lasercals->getLaserCorrection(detId, evtTimeStamp));
262  }
263 
264  //---- LC at the beginning of the time (first IOV of the GT == first time)
265  //---- Using the different "tag", the one with "MC": exactly the same function as findLaserConstant_LC but with a different object
266  double findLaserConstant_LC_prime(const DetId& detId) const {
267  const edm::Timestamp& evtTimeStamp = edm::Timestamp(m_iTime);
268  return (m_lasercals_prime->getLaserCorrection(detId, evtTimeStamp));
269  }
270 
271  const std::vector<float> GetGainRatios(const DetId& detid) {
272  std::vector<float> gainRatios(4);
273  // get gain ratios
274  EcalMGPAGainRatio theRatio = (*m_gainRatios)[detid];
275 
276  gainRatios[0] = 0.;
277  gainRatios[3] = 1.;
278  gainRatios[2] = theRatio.gain6Over1();
279  gainRatios[1] = theRatio.gain6Over1() * theRatio.gain12Over6();
280 
281  return gainRatios;
282  }
283 
284  double fullScaleEnergy(const DetId& detId) const { return detId.subdetId() == EcalBarrel ? m_maxEneEB : m_maxEneEE; }
285 
286  double peToAConversion(const DetId& detId) const {
287  return detId.subdetId() == EcalBarrel ? m_peToABarrel : m_peToAEndcap;
288  }
289 
298 
302 
304 
308 
309  const ESGain* esgain;
312  int ESgain;
313  double ESMIPToGeV;
314 
315  const double m_EBs25notCont;
316  const double m_EEs25notCont;
317 
318  const double m_peToABarrel;
319  const double m_peToAEndcap;
320 
321  double m_maxEneEB; // max attainable energy in the ecal barrel
322  double m_maxEneEE; // max attainable energy in the ecal endcap
323 
326 
327  const bool m_timeDependent;
333 
335 };
336 
340 
341 #endif
const edm::Event * theEvent
these fields are set in initializeEvent()
EcalSignalGenerator< EBDigitizerTraits > EBSignalGenerator
double theDefaultGains[NGAINS]
ECALDIGITIZERTRAITS::DigiCollection COLLECTION
const edm::ESGetToken< ESIntercalibConstants, ESIntercalibConstantsRcd > m_esIntercalibConstantsToken
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
const edm::ESGetToken< EcalADCToGeVConstant, EcalADCToGeVConstantRcd > m_adcToGeVConstantToken
float getESValueHigh() const
CalibCache m_valueLCCache_LC_prime
virtual void fill(edm::ModuleCallingContext const *mcc)
const edm::InputTag theInputTag
these come from the ParameterSet
Definition: ESGain.h:7
void fillNoiseSignals(CLHEP::HepRandomEngine *) override
uint32_t cc[maxCellsPerHit]
Definition: gpuFishbone.h:49
double findLaserConstant_LC(const DetId &detId) const
const edm::ESGetToken< EcalIntercalibConstantsMC, EcalIntercalibConstantsMCRcd > m_interCalibConstantsMCToken
RunAuxiliary const & runAuxiliary() const final
Definition: Run.cc:24
T const * product() const
Definition: Handle.h:70
EcalSignalGenerator(edm::ConsumesCollector &cc, const edm::InputTag &inputTag, const double EBs25notCont, const double EEs25notCont, const double peToABarrel, const double peToAEndcap, const bool timeDependent=false)
const std::vector< float > GetGainRatios(const DetId &detid)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:540
edm::ESGetToken< EcalLaserDbService, EcalLaserDbRecordMC > m_laserDbMCToken
Log< level::Error, false > LogError
const EcalGainRatios * m_gainRatios
const edm::ESGetToken< EcalGainRatios, EcalGainRatiosRcd > m_gainRatiosToken
std::vector< CaloSamples > theNoiseSignals
edm::ESGetToken< EcalLaserDbService, EcalLaserDbRecord > m_laserDbToken
Timestamp const & beginTime() const
Definition: RunPrincipal.h:67
bool validDigi(const DIGI &digi)
const EcalIntercalibConstantsMC * ical
const edm::ESGetToken< ESMIPToGeVConstant, ESMIPToGeVConstantRcd > m_esMIPToGeVConstantToken
edm::TimeValue_t m_iTime
float getESValueLow() const
void initializeEvent(const edm::Event *event, const edm::EventSetup *eventSetup)
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
Run const & getRun() const
Definition: Event.cc:112
const EcalADCToGeVConstant * agc
float getLaserCorrection(DetId const &xid, edm::Timestamp const &iTime) const
unsigned long long TimeValue_t
Definition: Timestamp.h:21
void initializeEvent(const edm::EventPrincipal *eventPrincipal, const edm::EventSetup *eventSetup)
some users use EventPrincipals, not Events. We support both
EcalSignalGenerator< ESDigitizerTraits > ESSignalGenerator
Timestamp const & beginTime() const
Definition: RunAuxiliary.h:28
void fillNoiseSignals() override
RunPrincipal const & runPrincipal() const
float gain12Over6() const
Definition: DetId.h:17
const edm::EventPrincipal * theEventPrincipal
TimeValue_t value() const
Definition: Timestamp.h:38
CaloSamples samplesInPE(const DIGI &digi)
double findLaserConstant_LC_prime(const DetId &detId) const
ECALDIGITIZERTRAITS::Digi DIGI
float gain6Over1() const
HLT enums.
const EcalLaserDbService * m_lasercals_prime
std::unordered_map< uint32_t, double > CalibCache
const EcalLaserDbService * m_lasercals
EcalSignalGenerator< EEDigitizerTraits > EESignalGenerator
const ESIntercalibConstants * esmips
float getESGain() const
Definition: ESGain.h:13
double fullScaleEnergy(const DetId &detId) const
double peToAConversion(const DetId &detId) const
Definition: event.py:1
uint16_t *__restrict__ uint16_t const *__restrict__ adc
const edm::ESGetToken< ESGain, ESGainRcd > m_esGainToken
const edm::EDGetTokenT< COLLECTION > m_tok
const ESMIPToGeVConstant * esMipToGeV