CMS 3D CMS Logo

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