CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalSignalGenerator.h
Go to the documentation of this file.
1 #ifndef EcalSimAlgos_EcalSignalGenerator_h
2 #define EcalSimAlgos_EcalSignalGenerator_h
3 
33 
38 #include <iostream>
39 #include <memory>
40 
41 namespace edm {
42  class ModuleCallingContext;
43 }
44 
45 template<class ECALDIGITIZERTRAITS>
47 {
48 public:
49  typedef typename ECALDIGITIZERTRAITS::Digi DIGI;
50  typedef typename ECALDIGITIZERTRAITS::DigiCollection COLLECTION;
51 
53 
54  EcalSignalGenerator(const edm::InputTag & inputTag, const edm::EDGetTokenT<COLLECTION> &t, const double EBs25notCont, const double EEs25notCont, const double peToABarrel, const double peToAEndcap)
56  theEvent(0),
58  theInputTag(inputTag),
59  tok_(t)
60  {
61  EcalMGPAGainRatio * defaultRatios = new EcalMGPAGainRatio();
62  theDefaultGains[2] = defaultRatios->gain6Over1() ;
63  theDefaultGains[1] = theDefaultGains[2]*(defaultRatios->gain12Over6()) ;
64  m_EBs25notCont = EBs25notCont;
65  m_EEs25notCont = EEs25notCont;
66  m_peToABarrel = peToABarrel;
67  m_peToAEndcap = peToAEndcap;
68 
69  }
70 
71  virtual ~EcalSignalGenerator() {}
72 
73 
74  void initializeEvent(const edm::Event * event, const edm::EventSetup * eventSetup)
75  {
76  theEvent = event;
77  eventSetup->get<EcalGainRatiosRcd>().get(grHandle); // find the gains
78  // Ecal Intercalibration Constants
79  eventSetup->get<EcalIntercalibConstantsMCRcd>().get( pIcal ) ;
80  ical = pIcal.product();
81  // adc to GeV
82  eventSetup->get<EcalADCToGeVConstantRcd>().get(pAgc);
83  agc = pAgc.product();
84 
87 
88  //ES
89  eventSetup->get<ESGainRcd>(). get( hesgain ) ;
90  eventSetup->get<ESMIPToGeVConstantRcd>(). get( hesMIPToGeV ) ;
91  eventSetup->get<ESIntercalibConstantsRcd>().get( hesMIPs ) ;
92 
93  esgain = hesgain.product() ;
94  esmips = hesMIPs.product() ;
96  if( 1.1 > esgain->getESGain() ) ESgain = 1;
97  else ESgain = 2;
100  }
101 
103  void initializeEvent(const edm::EventPrincipal * eventPrincipal, const edm::EventSetup * eventSetup)
104  {
105  theEventPrincipal = eventPrincipal;
106  eventSetup->get<EcalGainRatiosRcd>().get(grHandle); // find the gains
107  // Ecal Intercalibration Constants
108  eventSetup->get<EcalIntercalibConstantsMCRcd>().get( pIcal ) ;
109  ical = pIcal.product();
110  // adc to GeV
111  eventSetup->get<EcalADCToGeVConstantRcd>().get(pAgc);
112  agc = pAgc.product();
115 
116  //ES
117  eventSetup->get<ESGainRcd>(). get( hesgain ) ;
118  eventSetup->get<ESMIPToGeVConstantRcd>(). get( hesMIPToGeV ) ;
119  eventSetup->get<ESIntercalibConstantsRcd>().get( hesMIPs ) ;
120 
121  esgain = hesgain.product() ;
122  esmips = hesMIPs.product() ;
124  if( 1.1 > esgain->getESGain() ) ESgain = 1;
125  else ESgain = 2;
126  if( ESgain ==1 ) ESMIPToGeV = esMipToGeV->getESValueLow();
128  }
129 
130  virtual void fill(edm::ModuleCallingContext const* mcc)
131  {
132 
133  theNoiseSignals.clear();
135  const COLLECTION * digis = 0;
136  // try accessing by whatever is set, Event or EventPrincipal
137  if(theEvent)
138  {
139  if( theEvent->getByToken(tok_, pDigis) ) {
140  digis = pDigis.product(); // get a ptr to the product
141  //LogTrace("EcalSignalGenerator") << "total # digis for " << theInputTag << " " << digis->size();
142  }
143  else
144  {
145  throw cms::Exception("EcalSignalGenerator") << "Cannot find input data " << theInputTag;
146  }
147  }
148  else if(theEventPrincipal)
149  {
150  std::shared_ptr<edm::Wrapper<COLLECTION> const> digisPTR =
151  edm::getProductByTag<COLLECTION>(*theEventPrincipal, theInputTag, mcc );
152  if(digisPTR) {
153  digis = digisPTR->product();
154  }
155  }
156  else
157  {
158  throw cms::Exception("EcalSignalGenerator") << "No Event or EventPrincipal was set";
159  }
160 
161  if (digis)
162  {
163  // loop over digis, adding these to the existing maps
164  for(typename COLLECTION::const_iterator it = digis->begin();
165  it != digis->end(); ++it)
166  {
167  // need to convert to something useful
168  if(validDigi(*it)){
169  theNoiseSignals.push_back(samplesInPE(*it));
170  }
171  }
172  }
173  //else { std::cout << " NO digis for this input: " << theInputTag << std::endl;}
174  }
175 
176 private:
177 
178  bool validDigi(const DIGI & digi)
179  {
180  int DigiSum = 0;
181  for(int id = 0; id<digi.size(); id++) {
182  if(digi[id].adc() > 0) ++DigiSum;
183  }
184  return(DigiSum>0);
185  }
186 
187  virtual void fillNoiseSignals() override {}
188  virtual void fillNoiseSignals(CLHEP::HepRandomEngine*) override {}
189 
190 
191  // much of this stolen from EcalSimAlgos/EcalCoder
192 
193  enum { NBITS = 12 , // number of available bits
194  MAXADC = 4095 , // 2^12 -1, adc max range
195  ADCGAINSWITCH = 4079 , // adc gain switch
196  NGAINS = 3 }; // number of electronic gains
197 
198  CaloSamples samplesInPE(const DIGI & digi); // have to define this separately for ES
199 
200  const std::vector<float> GetGainRatios(const DetId& detid) {
201 
202  std::vector<float> gainRatios(4);
203  // get gain ratios
204  EcalMGPAGainRatio theRatio= (*grHandle)[detid];
205 
206  gainRatios[0] = 0.;
207  gainRatios[3] = 1.;
208  gainRatios[2] = theRatio.gain6Over1();
209  gainRatios[1] = theRatio.gain6Over1() * theRatio.gain12Over6();
210 
211  return gainRatios;
212  }
213 
214 
215  double fullScaleEnergy( const DetId & detId ) const
216  {
217  return detId.subdetId() == EcalBarrel ? m_maxEneEB : m_maxEneEE ;
218  }
219 
220 
221  double peToAConversion( const DetId & detId ) const
222  {
223  return detId.subdetId() == EcalBarrel ? m_peToABarrel : m_peToAEndcap ;
224  }
225 
226 
236 
240 
241  const ESGain* esgain;
244  int ESgain ;
245  double ESMIPToGeV;
246 
249 
252 
253  double m_maxEneEB ; // max attainable energy in the ecal barrel
254  double m_maxEneEE ; // max attainable energy in the ecal endcap
255 
258 
260 
261 };
262 
266 
267 #endif
268 
int adc(sample_type sample)
get the ADC sample (12 bits)
const edm::Event * theEvent
these fields are set in initializeEvent()
EcalSignalGenerator< EBDigitizerTraits > EBSignalGenerator
double theDefaultGains[NGAINS]
ECALDIGITIZERTRAITS::DigiCollection COLLECTION
edm::ESHandle< ESMIPToGeVConstant > hesMIPToGeV
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
virtual void fillNoiseSignals() override
virtual void fill(edm::ModuleCallingContext const *mcc)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:446
Definition: ESGain.h:7
float getESValueLow() const
const std::vector< float > GetGainRatios(const DetId &detid)
edm::EDGetTokenT< COLLECTION > tok_
const_iterator begin() const
double fullScaleEnergy(const DetId &detId) const
int size() const
Definition: EcalDataFrame.h:26
edm::ESHandle< ESIntercalibConstants > hesMIPs
std::vector< CaloSamples > theNoiseSignals
edm::ESHandle< ESGain > hesgain
EcalSignalGenerator(const edm::InputTag &inputTag, const edm::EDGetTokenT< COLLECTION > &t, const double EBs25notCont, const double EEs25notCont, const double peToABarrel, const double peToAEndcap)
bool validDigi(const DIGI &digi)
const EcalIntercalibConstantsMC * ical
edm::ESHandle< EcalADCToGeVConstant > pAgc
void initializeEvent(const edm::Event *event, const edm::EventSetup *eventSetup)
float gain6Over1() const
const EcalADCToGeVConstant * agc
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 subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
void initializeEvent(const edm::EventPrincipal *eventPrincipal, const edm::EventSetup *eventSetup)
some users use EventPrincipals, not Events. We support both
EcalSignalGenerator< ESDigitizerTraits > ESSignalGenerator
Definition: DetId.h:18
edm::ESHandle< EcalGainRatios > grHandle
const edm::EventPrincipal * theEventPrincipal
T const * product() const
Definition: Handle.h:81
float getESGain() const
Definition: ESGain.h:13
CaloSamples samplesInPE(const DIGI &digi)
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:86
edm::InputTag theInputTag
these come from the ParameterSet
ECALDIGITIZERTRAITS::Digi DIGI
float gain12Over6() const
const_iterator end() const
double peToAConversion(const DetId &detId) const
edm::ESHandle< EcalIntercalibConstantsMC > pIcal
EcalSignalGenerator< EEDigitizerTraits > EESignalGenerator
virtual void fillNoiseSignals(CLHEP::HepRandomEngine *) override
float getESValueHigh() const
const ESIntercalibConstants * esmips
const ESMIPToGeVConstant * esMipToGeV