test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalSignalGenerator.h
Go to the documentation of this file.
1 #ifndef HcalSimAlgos_HcalSignalGenerator_h
2 #define HcalSimAlgos_HcalSignalGenerator_h
3 
17 
22 #include <iostream>
23 
24 namespace edm {
25  class ModuleCallingContext;
26 }
27 
28 template<class HCALDIGITIZERTRAITS>
30 {
31 public:
32  typedef typename HCALDIGITIZERTRAITS::Digi DIGI;
33  typedef typename HCALDIGITIZERTRAITS::DigiCollection COLLECTION;
34 
36 
39  { }
40 
41  virtual ~HcalSignalGenerator() {}
42 
43 
44  void initializeEvent(const edm::Event * event, const edm::EventSetup * eventSetup)
45  {
46  theEvent = event;
47  eventSetup->get<HcalDbRecord>().get(theConditions);
49  }
50 
52  void initializeEvent(const edm::EventPrincipal * eventPrincipal, const edm::EventSetup * eventSetup)
53  {
54  theEventPrincipal = eventPrincipal;
55  eventSetup->get<HcalDbRecord>().get(theConditions);
57  }
58 
59  virtual void fill(edm::ModuleCallingContext const* mcc)
60  {
61 
62  theNoiseSignals.clear();
64  const COLLECTION * digis = 0;
65  // try accessing by whatever is set, Event or EventPrincipal
66  if(theEvent)
67  {
68  if( theEvent->getByToken(tok_, pDigis) ) {
69  digis = pDigis.product(); // get a ptr to the product
70  LogTrace("HcalSignalGenerator") << "total # digis for " << theInputTag << " " << digis->size();
71  }
72  else
73  {
74  throw cms::Exception("HcalSignalGenerator") << "Cannot find input data " << theInputTag;
75  }
76  }
77  else if(theEventPrincipal)
78  {
79  boost::shared_ptr<edm::Wrapper<COLLECTION> const> digisPTR =
80  edm::getProductByTag<COLLECTION>(*theEventPrincipal, theInputTag, mcc );
81  if(digisPTR) {
82  digis = digisPTR->product();
83  }
84  }
85  else
86  {
87  throw cms::Exception("HcalSignalGenerator") << "No Event or EventPrincipal was set";
88  }
89 
90  if (digis)
91  {
92 
93  // loop over digis, adding these to the existing maps
94  for(typename COLLECTION::const_iterator it = digis->begin();
95  it != digis->end(); ++it)
96  {
97  // for the first signal, set the starting cap id
98  if((it == digis->begin()) && theElectronicsSim)
99  {
100  int startingCapId = (*it)[0].capid();
101  theElectronicsSim->setStartingCapId(startingCapId);
102  // theParameterMap->setFrameSize(it->id(), it->size()); //don't need this
103  }
104  if(validDigi(*it)) {
105  theNoiseSignals.push_back(samplesInPE(*it));
106  }
107  }
108  }
109  }
110 
111 private:
112 
113 
114  virtual void fillNoiseSignals(CLHEP::HepRandomEngine*) override {}
115  virtual void fillNoiseSignals() override {}
116 
117  bool validDigi(const DIGI & digi)
118  {
119  int DigiSum = 0;
120  for(int id = 0; id<digi.size(); id++) {
121  if(digi[id].adc() > 0) ++DigiSum;
122  }
123  return(DigiSum>0);
124  }
125 
126 
128  {
129  // calibration, for future reference: (same block for all Hcal types)
130  HcalDetId cell = digi.id();
131  // const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
132  const HcalQIECoder* channelCoder = theConditions->getHcalCoder (cell);
133  const HcalQIEShape* channelShape = theConditions->getHcalShape (cell);
134  HcalCoderDb coder (*channelCoder, *channelShape);
136  coder.adc2fC(digi, result);
137 
138  // first, check if there was an overflow in this fake digi:
139  bool overflow = false;
140  // find and list them
141 
142  for(int isample=0; isample<digi.size(); ++isample) {
143  if(digi[isample].er()) overflow = true;
144  }
145 
146  if(overflow) { // do full conversion, go back and overwrite fake entries
147 
148  const HcalQIECoder* channelCoder = theConditions->getHcalCoder (cell);
149  const HcalQIEShape* channelShape = theConditions->getHcalShape (cell);
150  HcalCoderDb coder (*channelCoder, *channelShape);
151  coder.adc2fC(digi, result);
152 
153  // overwrite with coded information
154  for(int isample=0; isample<digi.size(); ++isample) {
155  if(!digi[isample].er()) result[isample] = float(digi[isample].adc())/10.;
156  }
157  }
158  else { // saves creating the coder, etc., every time
159  // use coded information
160  for(int isample=0; isample<digi.size(); ++isample) {
161  result[isample] = float(digi[isample].adc())/10.;
162  }
163  result.setPresamples(digi.presamples());
164  }
165  fC2pe(result);
166 
167  return result;
168  }
169 
177 };
178 
183 
184 #endif
185 
int adc(sample_type sample)
get the ADC sample (12 bits)
edm::InputTag theInputTag
these come from the ParameterSet
void setStartingCapId(int startingCapId)
HcalSignalGenerator(const edm::InputTag &inputTag, const edm::EDGetTokenT< COLLECTION > &t)
void fC2pe(CaloSamples &samples) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
HCALDIGITIZERTRAITS::Digi DIGI
int size() const
total number of samples in the digi
Definition: HBHEDataFrame.h:26
std::vector< HBHEDataFrame >::const_iterator const_iterator
HCALDIGITIZERTRAITS::DigiCollection COLLECTION
virtual void fillNoiseSignals(CLHEP::HepRandomEngine *) override
const edm::Event * theEvent
these fields are set in initializeEvent()
CaloSamples samplesInPE(const DIGI &digi)
void initializeEvent(const edm::EventPrincipal *eventPrincipal, const edm::EventSetup *eventSetup)
some users use EventPrincipals, not Events. We support both
edm::ESHandle< HcalDbService > theConditions
std::vector< CaloSamples > theNoiseSignals
virtual void fill(edm::ModuleCallingContext const *mcc)
virtual void adc2fC(const HBHEDataFrame &df, CaloSamples &lf) const
Definition: HcalCoderDb.cc:44
const edm::EventPrincipal * theEventPrincipal
HcalSignalGenerator< HFDigitizerTraits > HFSignalGenerator
tuple result
Definition: query.py:137
HcalSimParameterMap * theParameterMap
void setPresamples(int pre)
set presample information
Definition: CaloSamples.cc:29
edm::EDGetTokenT< COLLECTION > tok_
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:28
#define LogTrace(id)
HcalElectronicsSim * theElectronicsSim
const_iterator end() const
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
T const * product() const
Definition: Handle.h:81
HcalSignalGenerator< HODigitizerTraits > HOSignalGenerator
size_type size() const
HcalSignalGenerator< ZDCDigitizerTraits > ZDCSignalGenerator
virtual void fillNoiseSignals() override
HcalSignalGenerator< HBHEDigitizerTraits > HBHESignalGenerator
const HcalDetId & id() const
Definition: HBHEDataFrame.h:22
bool validDigi(const DIGI &digi)
void initializeEvent(const edm::Event *event, const edm::EventSetup *eventSetup)
void setDbService(const HcalDbService *service)
const_iterator begin() const