CMS 3D CMS Logo

HcalSignalGenerator.h
Go to the documentation of this file.
1 #ifndef HcalSimAlgos_HcalSignalGenerator_h
2 #define HcalSimAlgos_HcalSignalGenerator_h
3 
18 
23 #include <iostream>
24 
25 namespace edm {
26  class ModuleCallingContext;
27 }
28 
29 template <class Traits>
31 public:
32  typedef typename Traits::Digi DIGI;
34 
36 
39 
40  ~HcalSignalGenerator() override {}
41 
45  theEvent = event;
46  theConditions = &(eventSetup->getData(tok));
48  }
49 
51  void initializeEvent(const edm::EventPrincipal* eventPrincipal,
54  theEventPrincipal = eventPrincipal;
55  theConditions = &(eventSetup->getData(tok));
57  }
58 
59  virtual void fill(edm::ModuleCallingContext const* mcc) {
60  theNoiseSignals.clear();
62  const COLLECTION* digis = nullptr;
63  // try accessing by whatever is set, Event or EventPrincipal
64  if (theEvent) {
65  if (theEvent->getByToken(tok_, pDigis)) {
66  digis = pDigis.product(); // get a ptr to the product
67  LogTrace("HcalSignalGenerator") << "total # digis for " << theInputTag << " " << digis->size();
68  } else {
69  throw cms::Exception("HcalSignalGenerator") << "Cannot find input data " << theInputTag;
70  }
71  } else if (theEventPrincipal) {
72  std::shared_ptr<edm::Wrapper<COLLECTION> const> digisPTR =
73  edm::getProductByTag<COLLECTION>(*theEventPrincipal, theInputTag, mcc);
74  if (digisPTR) {
75  digis = digisPTR->product();
76  }
77  } else {
78  throw cms::Exception("HcalSignalGenerator") << "No Event or EventPrincipal was set";
79  }
80 
81  if (digis)
82  fillDigis(digis);
83  }
84 
85 private:
86  virtual void fillDigis(const COLLECTION* digis) {
87  // loop over digis, adding these to the existing maps
88  for (typename COLLECTION::const_iterator it = digis->begin(); it != digis->end(); ++it) {
89  // for the first signal, set the starting cap id
90  if ((it == digis->begin()) && theElectronicsSim) {
91  int startingCapId = (*it)[0].capid();
92  theElectronicsSim->setStartingCapId(startingCapId);
93  // theParameterMap->setFrameSize(it->id(), it->size()); //don't need this
94  }
95  if (validDigi(*it)) {
96  theNoiseSignals.push_back(samplesInPE(*it));
97  }
98  }
99  }
100 
101  void fillNoiseSignals(CLHEP::HepRandomEngine*) override {}
102  void fillNoiseSignals() override {}
103 
104  bool validDigi(const DIGI& digi) {
105  int DigiSum = 0;
106  for (int id = 0; id < digi.size(); id++) {
107  if (digi[id].adc() > 0)
108  ++DigiSum;
109  }
110  return (DigiSum > 0);
111  }
112 
113  CaloSamples samplesInPE(const DIGI& digi) {
114  // For PreMixing, (Note that modifications will need to be made for DataMixing) the
115  // energy for each channel is kept as fC*10, but stored as an integer in ADC. If this
116  // results in an overflow, the "standard" ADC conversion is used and that channel is marked
117  // with an error that allows the "standard" decoding to convert ADC back to fC. So, most
118  // channels get to fC by just dividing ADC/10; some require special treatment.
119 
120  // calibration, for future reference: (same block for all Hcal types)
121  HcalDetId cell = digi.id();
122  CaloSamples result = CaloSamples(cell, digi.size());
123 
124  // first, check if there was an overflow in this fake digi:
125  bool overflow = false;
126  // find and list them
127 
128  for (int isample = 0; isample < digi.size(); ++isample) {
129  if (digi[isample].er())
130  overflow = true;
131  }
132 
133  if (overflow) { // do full conversion, go back and overwrite fake entries
134 
135  const HcalQIECoder* channelCoder = theConditions->getHcalCoder(cell);
136  const HcalQIEShape* channelShape = theConditions->getHcalShape(cell);
137  HcalCoderDb coder(*channelCoder, *channelShape);
138  coder.adc2fC(digi, result);
139 
140  // overwrite with coded information
141  for (int isample = 0; isample < digi.size(); ++isample) {
142  if (!digi[isample].er())
143  result[isample] = float(digi[isample].adc()) / Traits::PreMixFactor;
144  }
145  } else { // saves creating the coder, etc., every time
146  // use coded information
147  for (int isample = 0; isample < digi.size(); ++isample) {
148  result[isample] = float(digi[isample].adc()) / Traits::PreMixFactor;
149  }
150  result.setPresamples(digi.presamples());
151  }
152 
153  // translation done in fC, convert to pe:
154  fC2pe(result);
155 
156  return result;
157  }
158 
166 };
167 
168 //forward declarations of specializations
169 template <>
172 template <>
175 template <>
178 template <>
181 template <>
184 template <>
187 
194 
195 #endif
void initializeEvent(const edm::Event *event, const edm::EventSetup *eventSetup, const edm::ESGetToken< HcalDbService, HcalDbRecord > &tok)
CaloSamples samplesInPE(const DIGI &digi)
void setStartingCapId(int startingCapId)
HcalSignalGenerator< HcalQIE10DigitizerTraits > QIE10SignalGenerator
HcalSignalGenerator< HcalQIE11DigitizerTraits > QIE11SignalGenerator
T const * product() const
Definition: Handle.h:70
bool validDigi(const DIGI &digi)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:528
void fillNoiseSignals(CLHEP::HepRandomEngine *) override
const edm::EventPrincipal * theEventPrincipal
#define LogTrace(id)
virtual void fill(edm::ModuleCallingContext const *mcc)
std::vector< CaloSamples > theNoiseSignals
void adc2fC(const HBHEDataFrame &df, CaloSamples &lf) const override
Definition: HcalCoderDb.cc:73
const edm::Event * theEvent
these fields are set in initializeEvent()
HcalSignalGenerator< HFDigitizerTraits > HFSignalGenerator
HcalSimParameterMap * theParameterMap
HcalElectronicsSim * theElectronicsSim
void fillNoiseSignals() override
Traits::DigiCollection COLLECTION
HcalSignalGenerator(const edm::InputTag &inputTag, const edm::EDGetTokenT< COLLECTION > &t)
HcalSignalGenerator< HODigitizerTraits > HOSignalGenerator
edm::InputTag theInputTag
these come from the ParameterSet
void initializeEvent(const edm::EventPrincipal *eventPrincipal, const edm::EventSetup *eventSetup, const edm::ESGetToken< HcalDbService, HcalDbRecord > &tok)
some users use EventPrincipals, not Events. We support both
const HcalQIEShape * getHcalShape(const HcalGenericDetId &fId) const
HLT enums.
HcalSignalGenerator< ZDCDigitizerTraits > ZDCSignalGenerator
const HcalQIECoder * getHcalCoder(const HcalGenericDetId &fId) const
HcalSignalGenerator< HBHEDigitizerTraits > HBHESignalGenerator
virtual void fillDigis(const COLLECTION *digis)
void fC2pe(CaloSamples &samples) const
edm::EDGetTokenT< COLLECTION > tok_
void setDbService(const HcalDbService *service)
Definition: event.py:1
uint16_t *__restrict__ uint16_t const *__restrict__ adc
const HcalDbService * theConditions