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 
40 namespace edm {
41  class ModuleCallingContext;
42 }
43 
44 template<class ECALDIGITIZERTRAITS>
46 {
47 public:
48  typedef typename ECALDIGITIZERTRAITS::Digi DIGI;
49  typedef typename ECALDIGITIZERTRAITS::DigiCollection COLLECTION;
50 
52 
53  EcalSignalGenerator(const edm::InputTag & inputTag, const edm::EDGetTokenT<COLLECTION> &t, const double EBs25notCont, const double EEs25notCont, const double peToABarrel, const double peToAEndcap)
55  theEvent(0),
57  theInputTag(inputTag),
58  tok_(t)
59  {
60  EcalMGPAGainRatio * defaultRatios = new EcalMGPAGainRatio();
61  theDefaultGains[2] = defaultRatios->gain6Over1() ;
62  theDefaultGains[1] = theDefaultGains[2]*(defaultRatios->gain12Over6()) ;
63  m_EBs25notCont = EBs25notCont;
64  m_EEs25notCont = EEs25notCont;
65  m_peToABarrel = peToABarrel;
66  m_peToAEndcap = peToAEndcap;
67 
68  }
69 
70  virtual ~EcalSignalGenerator() {}
71 
72 
73  void initializeEvent(const edm::Event * event, const edm::EventSetup * eventSetup)
74  {
75  theEvent = event;
76  eventSetup->get<EcalGainRatiosRcd>().get(grHandle); // find the gains
77  // Ecal Intercalibration Constants
78  eventSetup->get<EcalIntercalibConstantsMCRcd>().get( pIcal ) ;
79  ical = pIcal.product();
80  // adc to GeV
81  eventSetup->get<EcalADCToGeVConstantRcd>().get(pAgc);
82  agc = pAgc.product();
83 
86 
87  //ES
88  eventSetup->get<ESGainRcd>(). get( hesgain ) ;
89  eventSetup->get<ESMIPToGeVConstantRcd>(). get( hesMIPToGeV ) ;
90  eventSetup->get<ESIntercalibConstantsRcd>().get( hesMIPs ) ;
91 
92  esgain = hesgain.product() ;
93  esmips = hesMIPs.product() ;
95  if( 1.1 > esgain->getESGain() ) ESgain = 1;
96  else ESgain = 2;
99  }
100 
102  void initializeEvent(const edm::EventPrincipal * eventPrincipal, const edm::EventSetup * eventSetup)
103  {
104  theEventPrincipal = eventPrincipal;
105  eventSetup->get<EcalGainRatiosRcd>().get(grHandle); // find the gains
106  // Ecal Intercalibration Constants
107  eventSetup->get<EcalIntercalibConstantsMCRcd>().get( pIcal ) ;
108  ical = pIcal.product();
109  // adc to GeV
110  eventSetup->get<EcalADCToGeVConstantRcd>().get(pAgc);
111  agc = pAgc.product();
114 
115  //ES
116  eventSetup->get<ESGainRcd>(). get( hesgain ) ;
117  eventSetup->get<ESMIPToGeVConstantRcd>(). get( hesMIPToGeV ) ;
118  eventSetup->get<ESIntercalibConstantsRcd>().get( hesMIPs ) ;
119 
120  esgain = hesgain.product() ;
121  esmips = hesMIPs.product() ;
123  if( 1.1 > esgain->getESGain() ) ESgain = 1;
124  else ESgain = 2;
125  if( ESgain ==1 ) ESMIPToGeV = esMipToGeV->getESValueLow();
127  }
128 
129  virtual void fill(edm::ModuleCallingContext const* mcc)
130  {
131 
132  theNoiseSignals.clear();
134  const COLLECTION * digis = 0;
135  // try accessing by whatever is set, Event or EventPrincipal
136  if(theEvent)
137  {
138  if( theEvent->getByToken(tok_, pDigis) ) {
139  digis = pDigis.product(); // get a ptr to the product
140  //LogTrace("EcalSignalGenerator") << "total # digis for " << theInputTag << " " << digis->size();
141  }
142  else
143  {
144  throw cms::Exception("EcalSignalGenerator") << "Cannot find input data " << theInputTag;
145  }
146  }
147  else if(theEventPrincipal)
148  {
149  boost::shared_ptr<edm::Wrapper<COLLECTION> const> digisPTR =
150  edm::getProductByTag<COLLECTION>(*theEventPrincipal, theInputTag, mcc );
151  if(digisPTR) {
152  digis = digisPTR->product();
153  }
154  }
155  else
156  {
157  throw cms::Exception("EcalSignalGenerator") << "No Event or EventPrincipal was set";
158  }
159 
160  if (digis)
161  {
162  // loop over digis, adding these to the existing maps
163  for(typename COLLECTION::const_iterator it = digis->begin();
164  it != digis->end(); ++it)
165  {
166  // need to convert to something useful
167  if(validDigi(*it)){
168  theNoiseSignals.push_back(samplesInPE(*it));
169  }
170  }
171  }
172  //else { std::cout << " NO digis for this input: " << theInputTag << std::endl;}
173  }
174 
175 private:
176 
177  bool validDigi(const DIGI & digi)
178  {
179  int DigiSum = 0;
180  for(int id = 0; id<digi.size(); id++) {
181  if(digi[id].adc() > 0) ++DigiSum;
182  }
183  return(DigiSum>0);
184  }
185 
186  // much of this stolen from EcalSimAlgos/EcalCoder
187 
188  enum { NBITS = 12 , // number of available bits
189  MAXADC = 4095 , // 2^12 -1, adc max range
190  ADCGAINSWITCH = 4079 , // adc gain switch
191  NGAINS = 3 }; // number of electronic gains
192 
193  CaloSamples samplesInPE(const DIGI & digi); // have to define this separately for ES
194 
195  const std::vector<float> GetGainRatios(const DetId& detid) {
196 
197  std::vector<float> gainRatios(4);
198  // get gain ratios
199  EcalMGPAGainRatio theRatio= (*grHandle)[detid];
200 
201  gainRatios[0] = 0.;
202  gainRatios[3] = 1.;
203  gainRatios[2] = theRatio.gain6Over1();
204  gainRatios[1] = theRatio.gain6Over1() * theRatio.gain12Over6();
205 
206  return gainRatios;
207  }
208 
209 
210  double fullScaleEnergy( const DetId & detId ) const
211  {
212  return detId.subdetId() == EcalBarrel ? m_maxEneEB : m_maxEneEE ;
213  }
214 
215 
216  double peToAConversion( const DetId & detId ) const
217  {
218  return detId.subdetId() == EcalBarrel ? m_peToABarrel : m_peToAEndcap ;
219  }
220 
221 
231 
235 
236  const ESGain* esgain;
239  int ESgain ;
240  double ESMIPToGeV;
241 
244 
247 
248  double m_maxEneEB ; // max attainable energy in the ecal barrel
249  double m_maxEneEE ; // max attainable energy in the ecal endcap
250 
253 
255 
256 };
257 
261 
262 #endif
263 
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 fill(edm::ModuleCallingContext const *mcc)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
Definition: ESGain.h:5
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
float getESGain() const
Definition: ESGain.h:11
CaloSamples samplesInPE(const DIGI &digi)
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
edm::InputTag theInputTag
these come from the ParameterSet
ECALDIGITIZERTRAITS::Digi DIGI
float gain12Over6() const
T const * product() const
Definition: Handle.h:81
const_iterator end() const
double peToAConversion(const DetId &detId) const
edm::ESHandle< EcalIntercalibConstantsMC > pIcal
EcalSignalGenerator< EEDigitizerTraits > EESignalGenerator
float getESValueHigh() const
const ESIntercalibConstants * esmips
const ESMIPToGeVConstant * esMipToGeV