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