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 
66  const double EBs25notCont,
67  const double EEs25notCont,
68  const double peToABarrel,
69  const double peToAEndcap,
70  const bool timeDependent = false)
72  EcalMGPAGainRatio* defaultRatios = new EcalMGPAGainRatio();
73  theDefaultGains[2] = defaultRatios->gain6Over1();
74  theDefaultGains[1] = theDefaultGains[2] * (defaultRatios->gain12Over6());
75  m_EBs25notCont = EBs25notCont;
76  m_EEs25notCont = EEs25notCont;
77  m_peToABarrel = peToABarrel;
78  m_peToAEndcap = peToAEndcap;
80  }
81 
82  ~EcalSignalGenerator() override {}
83 
84  void initializeEvent(const edm::Event* event, const edm::EventSetup* eventSetup) {
85  theEvent = event;
86  eventSetup->get<EcalGainRatiosRcd>().get(grHandle); // find the gains
87  // Ecal Intercalibration Constants
88  eventSetup->get<EcalIntercalibConstantsMCRcd>().get(pIcal);
89  ical = pIcal.product();
90  // adc to GeV
91  eventSetup->get<EcalADCToGeVConstantRcd>().get(pAgc);
92  agc = pAgc.product();
93 
96 
97  if (m_timeDependent) {
98  //----
99  // Ecal LaserCorrection Constants for laser correction ratio
101  eventSetup->get<EcalLaserDbRecord>().get(laser);
102 
103  //
104  const edm::TimeValue_t eventTimeValue = theEvent->getRun().runAuxiliary().beginTime().value();
105  //
106  // The "time" will have to match in the generation of the tag
107  // for the MC from ECAL (apd/pn, alpha, whatever time dependent is needed)
108  //
109  m_iTime = eventTimeValue;
110 
111  m_lasercals = laser.product();
112 
113  //
114  // the "prime" is exactly the same as the usual laser service, BUT
115  // it has only 1 IOV, so that effectively you are dividing IOV_n / IOV_0
116  // NB: in the creation of the tag make sure the "prime" (MC) tag is prepared properly!
117  // NB again: if many IOVs also in "MC" tag, then fancy things could be perfomed ... left for the future
118  //
120  eventSetup->get<EcalLaserDbRecordMC>().get(laser_prime);
121  m_lasercals_prime = laser_prime.product();
122 
123  //clear the laser cache for each event time
125  CalibCache().swap(m_valueLCCache_LC_prime); //--- also the "prime" ... yes
126 
127  //----
128  }
129 
130  //ES
131  eventSetup->get<ESGainRcd>().get(hesgain);
132  eventSetup->get<ESMIPToGeVConstantRcd>().get(hesMIPToGeV);
133  eventSetup->get<ESIntercalibConstantsRcd>().get(hesMIPs);
134 
135  esgain = hesgain.product();
136  esmips = hesMIPs.product();
138  if (1.1 > esgain->getESGain())
139  ESgain = 1;
140  else
141  ESgain = 2;
142  if (ESgain == 1)
144  else
146  }
147 
149  void initializeEvent(const edm::EventPrincipal* eventPrincipal, const edm::EventSetup* eventSetup) {
150  theEventPrincipal = eventPrincipal;
151  eventSetup->get<EcalGainRatiosRcd>().get(grHandle); // find the gains
152  // Ecal Intercalibration Constants
153  eventSetup->get<EcalIntercalibConstantsMCRcd>().get(pIcal);
154  ical = pIcal.product();
155  // adc to GeV
156  eventSetup->get<EcalADCToGeVConstantRcd>().get(pAgc);
157  agc = pAgc.product();
160 
161  if (m_timeDependent) {
162  //----
163  // Ecal LaserCorrection Constants for laser correction ratio
165  eventSetup->get<EcalLaserDbRecord>().get(laser);
166  edm::TimeValue_t eventTimeValue = 0;
167  if (theEventPrincipal) {
168  //
169  eventTimeValue = theEventPrincipal->runPrincipal().beginTime().value();
170  //
171  // The "time" will have to match in the generation of the tag
172  // for the MC from ECAL (apd/pn, alpha, whatever time dependent is needed)
173  //
174  } else {
175  edm::LogError("EcalSignalGenerator") << " theEventPrincipal not defined??? " << std::endl;
176  }
177  m_iTime = eventTimeValue;
178  m_lasercals = laser.product();
179 
181  eventSetup->get<EcalLaserDbRecordMC>().get(laser_prime);
182  m_lasercals_prime = laser_prime.product();
183 
184  //clear the laser cache for each event time
186  CalibCache().swap(m_valueLCCache_LC_prime); //--- also the "prime" ... yes
187  //----
188  }
189 
190  //ES
191  eventSetup->get<ESGainRcd>().get(hesgain);
192  eventSetup->get<ESMIPToGeVConstantRcd>().get(hesMIPToGeV);
193  eventSetup->get<ESIntercalibConstantsRcd>().get(hesMIPs);
194 
195  esgain = hesgain.product();
196  esmips = hesMIPs.product();
198  if (1.1 > esgain->getESGain())
199  ESgain = 1;
200  else
201  ESgain = 2;
202  if (ESgain == 1)
204  else
206  }
207 
208  virtual void fill(edm::ModuleCallingContext const* mcc) {
209  theNoiseSignals.clear();
211  const COLLECTION* digis = nullptr;
212  // try accessing by whatever is set, Event or EventPrincipal
213  if (theEvent) {
214  if (theEvent->getByToken(tok_, pDigis)) {
215  digis = pDigis.product(); // get a ptr to the product
216  } else {
217  throw cms::Exception("EcalSignalGenerator") << "Cannot find input data " << theInputTag;
218  }
219  } else if (theEventPrincipal) {
220  std::shared_ptr<edm::Wrapper<COLLECTION> const> digisPTR =
221  edm::getProductByTag<COLLECTION>(*theEventPrincipal, theInputTag, mcc);
222  if (digisPTR) {
223  digis = digisPTR->product();
224  }
225  } else {
226  throw cms::Exception("EcalSignalGenerator") << "No Event or EventPrincipal was set";
227  }
228 
229  if (digis) {
230  // loop over digis, adding these to the existing maps
231  for (typename COLLECTION::const_iterator it = digis->begin(); it != digis->end(); ++it) {
232  // need to convert to something useful
233  if (validDigi(*it)) {
234  theNoiseSignals.push_back(samplesInPE(*it));
235  }
236  }
237  }
238  //else { std::cout << " NO digis for this input: " << theInputTag << std::endl;}
239  }
240 
241 private:
242  bool validDigi(const DIGI& digi) {
243  int DigiSum = 0;
244  for (int id = 0; id < digi.size(); id++) {
245  if (digi[id].adc() > 0)
246  ++DigiSum;
247  }
248  return (DigiSum > 0);
249  }
250 
251  void fillNoiseSignals() override {}
252  void fillNoiseSignals(CLHEP::HepRandomEngine*) override {}
253 
254  // much of this stolen from EcalSimAlgos/EcalCoder
255 
256  enum {
257  NBITS = 12, // number of available bits
258  MAXADC = 4095, // 2^12 -1, adc max range
259  ADCGAINSWITCH = 4079, // adc gain switch
260  NGAINS = 3
261  }; // number of electronic gains
262 
263  CaloSamples samplesInPE(const DIGI& digi); // have to define this separately for ES
264 
265  //---- LC that depends with time
266  double findLaserConstant_LC(const DetId& detId) const {
267  const edm::Timestamp& evtTimeStamp = edm::Timestamp(m_iTime);
268  return (m_lasercals->getLaserCorrection(detId, evtTimeStamp));
269  }
270 
271  //---- LC at the beginning of the time (first IOV of the GT == first time)
272  //---- Using the different "tag", the one with "MC": exactly the same function as findLaserConstant_LC but with a different object
273  double findLaserConstant_LC_prime(const DetId& detId) const {
274  const edm::Timestamp& evtTimeStamp = edm::Timestamp(m_iTime);
275  return (m_lasercals_prime->getLaserCorrection(detId, evtTimeStamp));
276  }
277 
278  const std::vector<float> GetGainRatios(const DetId& detid) {
279  std::vector<float> gainRatios(4);
280  // get gain ratios
281  EcalMGPAGainRatio theRatio = (*grHandle)[detid];
282 
283  gainRatios[0] = 0.;
284  gainRatios[3] = 1.;
285  gainRatios[2] = theRatio.gain6Over1();
286  gainRatios[1] = theRatio.gain6Over1() * theRatio.gain12Over6();
287 
288  return gainRatios;
289  }
290 
291  double fullScaleEnergy(const DetId& detId) const { return detId.subdetId() == EcalBarrel ? m_maxEneEB : m_maxEneEE; }
292 
293  double peToAConversion(const DetId& detId) const {
294  return detId.subdetId() == EcalBarrel ? m_peToABarrel : m_peToAEndcap;
295  }
296 
300 
304 
308 
312 
313  const ESGain* esgain;
316  int ESgain;
317  double ESMIPToGeV;
318 
321 
324 
325  double m_maxEneEB; // max attainable energy in the ecal barrel
326  double m_maxEneEE; // max attainable energy in the ecal endcap
327 
330 
337 
339 };
340 
344 
345 #endif
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
EcalSignalGenerator::theInputTag
edm::InputTag theInputTag
these come from the ParameterSet
Definition: EcalSignalGenerator.h:306
EcalIntercalibConstantsMC.h
EcalSignalGenerator::DIGI
ECALDIGITIZERTRAITS::Digi DIGI
Definition: EcalSignalGenerator.h:57
ESGain
Definition: ESGain.h:7
EcalSignalGenerator::ESgain
int ESgain
Definition: EcalSignalGenerator.h:316
Handle.h
EcalPedestals.h
MessageLogger.h
edm::Handle::product
T const * product() const
Definition: Handle.h:70
ESHandle.h
ESGainRcd
Definition: ESGainRcd.h:5
ESIntercalibConstants.h
EcalSignalGenerator::pIcal
edm::ESHandle< EcalIntercalibConstantsMC > pIcal
Definition: EcalSignalGenerator.h:302
edm::EDGetTokenT< COLLECTION >
edm
HLT enums.
Definition: AlignableModifier.h:19
EcalSignalGenerator::m_maxEneEE
double m_maxEneEE
Definition: EcalSignalGenerator.h:326
ESMIPToGeVConstantRcd
Definition: ESMIPToGeVConstantRcd.h:5
EcalSignalGenerator::grHandle
edm::ESHandle< EcalGainRatios > grHandle
Definition: EcalSignalGenerator.h:301
EBDetId.h
EEDetId.h
TrendClient_cfi.Digi
Digi
Definition: TrendClient_cfi.py:7
EcalSignalGenerator::m_EEs25notCont
double m_EEs25notCont
Definition: EcalSignalGenerator.h:320
EcalSignalGenerator::samplesInPE
CaloSamples samplesInPE(const DIGI &digi)
EcalSignalGenerator::m_iTime
edm::TimeValue_t m_iTime
Definition: EcalSignalGenerator.h:332
EcalSignalGenerator::esmips
const ESIntercalibConstants * esmips
Definition: EcalSignalGenerator.h:314
EcalADCToGeVConstant
Definition: EcalADCToGeVConstant.h:13
edm::Timestamp::value
TimeValue_t value() const
Definition: Timestamp.h:45
EcalDigitizerTraits.h
ESGain.h
ESDetId.h
EcalSignalGenerator::NBITS
Definition: EcalSignalGenerator.h:257
EcalSignalGenerator::m_EBs25notCont
double m_EBs25notCont
Definition: EcalSignalGenerator.h:319
EcalSignalGenerator::m_maxEneEB
double m_maxEneEB
Definition: EcalSignalGenerator.h:325
EcalSignalGenerator::fullScaleEnergy
double fullScaleEnergy(const DetId &detId) const
Definition: EcalSignalGenerator.h:291
EcalSignalGenerator::peToAConversion
double peToAConversion(const DetId &detId) const
Definition: EcalSignalGenerator.h:293
ESMIPToGeVConstant::getESValueHigh
float getESValueHigh() const
Definition: ESMIPToGeVConstant.h:15
EcalSignalGenerator::agc
const EcalADCToGeVConstant * agc
Definition: EcalSignalGenerator.h:328
EcalCondObjectContainer
Definition: EcalCondObjectContainer.h:13
edm::Handle
Definition: AssociativeIterator.h:50
ESGainRcd.h
EcalBarrel
Definition: EcalSubdetector.h:10
EcalSignalGenerator::initializeEvent
void initializeEvent(const edm::EventPrincipal *eventPrincipal, const edm::EventSetup *eventSetup)
some users use EventPrincipals, not Events. We support both
Definition: EcalSignalGenerator.h:149
EcalSignalGenerator::m_lasercals_prime
const EcalLaserDbService * m_lasercals_prime
Definition: EcalSignalGenerator.h:336
ecalLiteDTU::adc
constexpr int adc(sample_type sample)
get the ADC sample (12 bits)
Definition: EcalLiteDTUSample.h:12
ESDataFrame.h
ecalSimParameterMap_cff.timeDependent
timeDependent
Definition: ecalSimParameterMap_cff.py:13
DetId
Definition: DetId.h:17
EcalSignalGenerator::theDefaultGains
double theDefaultGains[NGAINS]
Definition: EcalSignalGenerator.h:338
EcalLaserDbRecordMC
Definition: EcalLaserDbRecordMC.h:16
EcalSignalGenerator::GetGainRatios
const std::vector< float > GetGainRatios(const DetId &detid)
Definition: EcalSignalGenerator.h:278
edm::RunPrincipal::beginTime
Timestamp const & beginTime() const
Definition: RunPrincipal.h:67
edm::EventPrincipal
Definition: EventPrincipal.h:46
edm::EventSetup::get
T get() const
Definition: EventSetup.h:80
EcalIntercalibConstantsMCRcd.h
EcalBaseSignalGenerator
Definition: EcalBaseSignalGenerator.h:7
EcalLaserDbService
Definition: EcalLaserDbService.h:25
EventPrincipal.h
CaloVNoiseSignalGenerator::theNoiseSignals
std::vector< CaloSamples > theNoiseSignals
Definition: CaloVNoiseSignalGenerator.h:34
EcalLaserDbService.h
EcalDigiCollections.h
Run.h
edm::ESHandle< EcalLaserDbService >
ESMIPToGeVConstantRcd.h
EcalSignalGenerator::ADCGAINSWITCH
Definition: EcalSignalGenerator.h:259
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:531
ESIntercalibConstantsRcd
Definition: ESIntercalibConstantsRcd.h:5
ESGain::getESGain
float getESGain() const
Definition: ESGain.h:13
EcalMGPAGainRatio::gain12Over6
float gain12Over6() const
Definition: EcalMGPAGainRatio.h:19
EcalLaserDbRecord
Definition: EcalLaserDbRecord.h:19
DetId::subdetId
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum)
Definition: DetId.h:48
EcalSignalGenerator::esMipToGeV
const ESMIPToGeVConstant * esMipToGeV
Definition: EcalSignalGenerator.h:315
EcalGainRatiosRcd
Definition: EcalGainRatiosRcd.h:5
CaloTSamples.h
EcalADCToGeVConstant.h
ESIntercalibConstantsRcd.h
EcalSignalGenerator::CalibCache
std::unordered_map< uint32_t, double > CalibCache
Definition: EcalSignalGenerator.h:60
EcalSignalGenerator::m_lasercals
const EcalLaserDbService * m_lasercals
Definition: EcalSignalGenerator.h:335
EcalIntercalibConstantsMCRcd
Definition: EcalIntercalibConstantsMCRcd.h:5
EcalSignalGenerator::MAXADC
Definition: EcalSignalGenerator.h:258
EcalADCToGeVConstant::getEEValue
float getEEValue() const
Definition: EcalADCToGeVConstant.h:21
ESSignalGenerator
EcalSignalGenerator< ESDigitizerTraits > ESSignalGenerator
Definition: EcalSignalGenerator.h:343
Event.h
EcalSignalGenerator::m_valueLCCache_LC_prime
CalibCache m_valueLCCache_LC_prime
Definition: EcalSignalGenerator.h:334
EcalBaseSignalGenerator.h
RunPrincipal.h
EcalSignalGenerator::pAgc
edm::ESHandle< EcalADCToGeVConstant > pAgc
Definition: EcalSignalGenerator.h:303
edmPickEvents.event
event
Definition: edmPickEvents.py:273
EcalADCToGeVConstantRcd.h
edm::RunAuxiliary::beginTime
Timestamp const & beginTime() const
Definition: RunAuxiliary.h:29
EcalSignalGenerator::fill
virtual void fill(edm::ModuleCallingContext const *mcc)
Definition: EcalSignalGenerator.h:208
EcalSignalGenerator
Definition: EcalSignalGenerator.h:55
EcalSignalGenerator::m_valueLCCache_LC
CalibCache m_valueLCCache_LC
Definition: EcalSignalGenerator.h:333
EBDataFrame.h
ESMIPToGeVConstant
Definition: ESMIPToGeVConstant.h:7
EcalSignalGenerator::m_peToAEndcap
double m_peToAEndcap
Definition: EcalSignalGenerator.h:323
edm::EventSetup
Definition: EventSetup.h:57
CaloSamples
Definition: CaloSamples.h:14
EcalGainRatiosRcd.h
EcalSignalGenerator::fillNoiseSignals
void fillNoiseSignals(CLHEP::HepRandomEngine *) override
Definition: EcalSignalGenerator.h:252
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
EcalSignalGenerator::EcalSignalGenerator
EcalSignalGenerator(const edm::InputTag &inputTag, const edm::EDGetTokenT< COLLECTION > &t, const double EBs25notCont, const double EEs25notCont, const double peToABarrel, const double peToAEndcap, const bool timeDependent=false)
Definition: EcalSignalGenerator.h:64
EcalSignalGenerator::findLaserConstant_LC
double findLaserConstant_LC(const DetId &detId) const
Definition: EcalSignalGenerator.h:266
get
#define get
ESCondObjectContainer
Definition: ESCondObjectContainer.h:11
EcalGainRatios.h
EcalSignalGenerator::m_timeDependent
bool m_timeDependent
Definition: EcalSignalGenerator.h:331
EcalSignalGenerator::theEvent
const edm::Event * theEvent
these fields are set in initializeEvent()
Definition: EcalSignalGenerator.h:298
EESignalGenerator
EcalSignalGenerator< EEDigitizerTraits > EESignalGenerator
Definition: EcalSignalGenerator.h:342
EEDataFrame.h
EcalSignalGenerator::COLLECTION
ECALDIGITIZERTRAITS::DigiCollection COLLECTION
Definition: EcalSignalGenerator.h:58
EcalLaserDbRecord.h
EcalLaserDbService::getLaserCorrection
float getLaserCorrection(DetId const &xid, edm::Timestamp const &iTime) const
Definition: EcalLaserDbService.cc:30
ESMIPToGeVConstant::getESValueLow
float getESValueLow() const
Definition: ESMIPToGeVConstant.h:13
edm::Run::runAuxiliary
RunAuxiliary const & runAuxiliary() const override
Definition: Run.h:62
siStripShotFilter_cfi.DigiCollection
DigiCollection
Definition: siStripShotFilter_cfi.py:6
EcalLaserDbRecordMC.h
EcalSignalGenerator::tok_
edm::EDGetTokenT< COLLECTION > tok_
Definition: EcalSignalGenerator.h:307
EcalSignalGenerator::validDigi
bool validDigi(const DIGI &digi)
Definition: EcalSignalGenerator.h:242
EcalSignalGenerator::theEventPrincipal
const edm::EventPrincipal * theEventPrincipal
Definition: EcalSignalGenerator.h:299
EcalSignalGenerator::EcalSignalGenerator
EcalSignalGenerator()
Definition: EcalSignalGenerator.h:62
EcalMGPAGainRatio::gain6Over1
float gain6Over1() const
Definition: EcalMGPAGainRatio.h:20
Exception
Definition: hltDiff.cc:246
EcalSignalGenerator::esgain
const ESGain * esgain
Definition: EcalSignalGenerator.h:313
ESMIPToGeVConstant.h
EcalElectronicsSim.h
EventSetup.h
EcalSignalGenerator::hesMIPs
edm::ESHandle< ESIntercalibConstants > hesMIPs
Definition: EcalSignalGenerator.h:311
EcalSignalGenerator::findLaserConstant_LC_prime
double findLaserConstant_LC_prime(const DetId &detId) const
Definition: EcalSignalGenerator.h:273
EcalSignalGenerator::initializeEvent
void initializeEvent(const edm::Event *event, const edm::EventSetup *eventSetup)
Definition: EcalSignalGenerator.h:84
EBSignalGenerator
EcalSignalGenerator< EBDigitizerTraits > EBSignalGenerator
Definition: EcalSignalGenerator.h:341
EcalSignalGenerator::m_peToABarrel
double m_peToABarrel
Definition: EcalSignalGenerator.h:322
EcalSignalGenerator::NGAINS
Definition: EcalSignalGenerator.h:260
EcalSignalGenerator::hesgain
edm::ESHandle< ESGain > hesgain
Definition: EcalSignalGenerator.h:309
EcalSignalGenerator::~EcalSignalGenerator
~EcalSignalGenerator() override
Definition: EcalSignalGenerator.h:82
SimL1EmulatorRepack_Full_cff.inputTag
inputTag
Definition: SimL1EmulatorRepack_Full_cff.py:56
event
Definition: event.py:1
EcalSignalGenerator::fillNoiseSignals
void fillNoiseSignals() override
Definition: EcalSignalGenerator.h:251
edm::Event
Definition: Event.h:73
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
edm::EventPrincipal::runPrincipal
RunPrincipal const & runPrincipal() const
Definition: EventPrincipal.cc:177
EcalADCToGeVConstant::getEBValue
float getEBValue() const
Definition: EcalADCToGeVConstant.h:20
EcalADCToGeVConstantRcd
Definition: EcalADCToGeVConstantRcd.h:5
edm::InputTag
Definition: InputTag.h:15
EcalSignalGenerator::ical
const EcalIntercalibConstantsMC * ical
Definition: EcalSignalGenerator.h:329
EcalSignalGenerator::hesMIPToGeV
edm::ESHandle< ESMIPToGeVConstant > hesMIPToGeV
Definition: EcalSignalGenerator.h:310
EcalCondDBWriter_cfi.laser
laser
Definition: EcalCondDBWriter_cfi.py:46
edm::TimeValue_t
unsigned long long TimeValue_t
Definition: Timestamp.h:28
EcalMGPAGainRatio
Definition: EcalMGPAGainRatio.h:13
edm::Event::getRun
Run const & getRun() const
Definition: Event.cc:111
EcalSignalGenerator::ESMIPToGeV
double ESMIPToGeV
Definition: EcalSignalGenerator.h:317
edm::ModuleCallingContext
Definition: ModuleCallingContext.h:29
edm::Timestamp
Definition: Timestamp.h:30