CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalHitResponse.cc
Go to the documentation of this file.
15 #include "CLHEP/Random/RandPoissonQ.h"
16 #include "CLHEP/Random/RandGaussQ.h"
19 
20 #include "CLHEP/Units/GlobalPhysicalConstants.h"
21 #include "CLHEP/Units/GlobalSystemOfUnits.h"
22 #include <iostream>
23 
24 
25 
27  const CaloVShape* shape ) :
28  m_parameterMap ( parameterMap ) ,
29  m_shape ( shape ) ,
30  m_hitCorrection ( 0 ) ,
31  m_PECorrection ( 0 ) ,
32  m_hitFilter ( 0 ) ,
33  m_geometry ( 0 ) ,
34  m_lasercals ( 0 ) ,
35  m_RandPoisson ( 0 ) ,
36  m_RandGauss ( 0 ) ,
37  m_minBunch ( -10 ) ,
38  m_maxBunch ( 10 ) ,
39  m_phaseShift ( 1 ) ,
40  m_iTime ( 0 ) ,
41  m_useLCcorrection ( 0 )
42 {
44  if ( !rng.isAvailable() )
45  {
46  throw cms::Exception("Configuration")
47  << "EcalHitResponse requires the RandomNumberGeneratorService\n"
48  "which is not present in the configuration file. You must add the service\n"
49  "in the configuration file or remove the modules that require it.";
50  }
51  m_RandPoisson = new CLHEP::RandPoissonQ( rng->getEngine() ) ;
52  m_RandGauss = new CLHEP::RandGaussQ( rng->getEngine() ) ;
53 }
54 
56 {
57  delete m_RandPoisson ;
58  delete m_RandGauss ;
59 }
60 
61 CLHEP::RandPoissonQ*
63 {
64  return m_RandPoisson ;
65 }
66 
67 CLHEP::RandGaussQ*
69 {
70  return m_RandGauss ;
71 }
72 
73 const CaloSimParameters*
74 EcalHitResponse::params( const DetId& detId ) const
75 {
76  assert( 0 != m_parameterMap ) ;
77  return &m_parameterMap->simParameters( detId ) ;
78 }
79 
80 const CaloVShape*
82 {
83  assert( 0 != m_shape ) ;
84  return m_shape ;
85 }
86 
89 {
90  assert( 0 != m_geometry ) ;
91  return m_geometry ;
92 }
93 
94 void
96  int maxBunch )
97 {
100 }
101 
102 void
104 {
105  m_geometry = geometry ;
106 }
107 
108 void
109 EcalHitResponse::setPhaseShift( double phaseShift )
110 {
112 }
113 
114 double
116 {
117  return m_phaseShift ;
118 }
119 
120 void
122 {
123  m_hitFilter = filter ;
124 }
125 
126 void
128 {
129  m_hitCorrection = hitCorrection ;
130 }
131 
132 void
134 {
135  m_PECorrection = peCorrection ;
136 }
137 
138 void
140 {
141  m_iTime = iTime;
142 }
143 
144 void
145 EcalHitResponse::setLaserConstants(const EcalLaserDbService* laser, bool& useLCcorrection)
146 {
147  m_lasercals = laser;
148  m_useLCcorrection = useLCcorrection;
149 }
150 
151 void
152 EcalHitResponse::blankOutUsedSamples() // blank out previously used elements
153 {
154  const unsigned int size ( m_index.size() ) ;
155 
156  for( unsigned int i ( 0 ) ; i != size ; ++i )
157  {
158  vSamAll( m_index[i] )->setZero() ;
159  }
160  m_index.erase( m_index.begin() , // done and make ready to start over
161  m_index.end() ) ;
162 }
163 
164 void
166 {
167  if (!edm::isNotFinite( hit.time() ) && ( 0 == m_hitFilter || m_hitFilter->accepts( hit ) ) ) {
168  putAnalogSignal( hit ) ;
169  }
170 }
171 
172 bool
173 EcalHitResponse::withinBunchRange(int bunchCrossing) const
174 {
175  return(m_minBunch <= bunchCrossing && m_maxBunch >= bunchCrossing);
176 }
177 
178 void
180 {
182 }
183 
184 void
186 {
187 }
188 
189 void
191 {
193 
194  for( MixCollection<PCaloHit>::MixItr hitItr ( hits.begin() ) ;
195  hitItr != hits.end() ; ++hitItr )
196  {
197  const PCaloHit& hit ( *hitItr ) ;
198  const int bunch ( hitItr.bunch() ) ;
199  if( withinBunchRange(bunch) &&
200  !edm::isNotFinite( hit.time() ) &&
201  ( 0 == m_hitFilter ||
202  m_hitFilter->accepts( hit ) ) ) putAnalogSignal( hit ) ;
203  }
204 }
205 
206 void
208 {
209  const DetId detId ( hit.id() ) ;
210 
211  const CaloSimParameters* parameters ( params( detId ) ) ;
212 
213  const double signal ( analogSignalAmplitude( detId, hit.energy() ) ) ;
214 
215  double time = hit.time();
216 
217  if(m_hitCorrection) {
218  time += m_hitCorrection->delay( hit ) ;
219  }
220 
221  const double jitter ( time - timeOfFlight( detId ) ) ;
222 
223  const double tzero = ( shape()->timeToRise()
224  + parameters->timePhase()
225  - jitter
226  - BUNCHSPACE*( parameters->binOfMaximum()
227  - m_phaseShift ) ) ;
228  double binTime ( tzero ) ;
229 
230  EcalSamples& result ( *findSignal( detId ) ) ;
231 
232  const unsigned int rsize ( result.size() ) ;
233 
234  for( unsigned int bin ( 0 ) ; bin != rsize ; ++bin )
235  {
236  result[ bin ] += (*shape())( binTime )*signal ;
237  binTime += BUNCHSPACE ;
238  }
239 }
240 
241 double
243 {
244  const edm::Timestamp& evtTimeStamp = edm::Timestamp(m_iTime);
245  return (m_lasercals->getLaserCorrection(detId, evtTimeStamp));
246 }
247 
250 {
251  const unsigned int di ( CaloGenericDetId( detId ).denseIndex() ) ;
252  EcalSamples* result ( vSamAll( di ) ) ;
253  if( result->zero() ) m_index.push_back( di ) ;
254  return result ;
255 }
256 
257 double
259 {
260  const CaloSimParameters& parameters ( *params( detId ) ) ;
261 
262  // OK, the "energy" in the hit could be a real energy, deposited energy,
263  // or pe count. This factor converts to photoelectrons
264 
265  float lasercalib = 1.;
266  if(m_useLCcorrection == true && detId.subdetId() != 3) {
267  lasercalib = findLaserConstant(detId);
268  }
269 
270  double npe ( energy/lasercalib*parameters.simHitToPhotoelectrons( detId ) ) ;
271 
272  // do we need to doPoisson statistics for the photoelectrons?
273  if( parameters.doPhotostatistics() ) npe = ranPois()->fire( npe ) ;
274 
275  if( 0 != m_PECorrection ) npe = m_PECorrection->correctPE( detId, npe ) ;
276 
277  return npe ;
278 }
279 
280 double
281 EcalHitResponse::timeOfFlight( const DetId& detId ) const
282 {
283  const CaloCellGeometry* cellGeometry ( geometry()->getGeometry( detId ) ) ;
284  assert( 0 != cellGeometry ) ;
285  return cellGeometry->getPosition().mag()*cm/c_light ; // Units of c_light: mm/ns
286 }
287 
288 void
290 {
291  EcalSamples& sam ( *findSignal( pSam->id() ) ) ;
292  sam += (*pSam) ;
293 }
294 
295 int
297 {
298  return m_minBunch ;
299 }
300 
301 int
303 {
304  return m_maxBunch ;
305 }
306 
309 {
310  return m_index ;
311 }
312 
315 {
316  return m_index ;
317 }
318 
319 const CaloVHitFilter*
321 {
322  return m_hitFilter ;
323 }
324 
326 EcalHitResponse::findDetId( const DetId& detId ) const
327 {
328  const unsigned int di ( CaloGenericDetId( detId ).denseIndex() ) ;
329  return vSamAll( di ) ;
330 }
const CaloVShape * m_shape
int i
Definition: DBlmapReader.cc:9
dictionary parameters
Definition: Parameters.py:2
double time() const
Definition: PCaloHit.h:34
const CaloVShape * shape() const
double findLaserConstant(const DetId &detId) const
CLHEP::RandGaussQ * ranGauss() const
std::vector< unsigned int > VecInd
CLHEP::RandGaussQ * m_RandGauss
void setEventTime(const edm::TimeValue_t &iTime)
double energy() const
Definition: PCaloHit.h:29
virtual ~EcalHitResponse()
edm::TimeValue_t m_iTime
float getLaserCorrection(DetId const &xid, edm::Timestamp const &iTime) const
virtual void initializeHits()
double analogSignalAmplitude(const DetId &id, float energy) const
bool doPhotostatistics() const
whether or not to apply Poisson statistics to photoelectrons
Electronic response of the preamp.
Definition: CaloVShape.h:11
double timeOfFlight(const DetId &detId) const
Main class for Parameters in different subdetectors.
void setHitFilter(const CaloVHitFilter *filter)
const CaloSimParameters * params(const DetId &detId) const
virtual double delay(const PCaloHit &hit) const =0
void setHitCorrection(const CaloVHitCorrection *hitCorrection)
virtual void run(MixCollection< PCaloHit > &hits)
iterator end()
void setBunchRange(int minBunch, int maxBunch)
void setLaserConstants(const EcalLaserDbService *laser, bool &useLCcorrection)
const EcalSamples * findDetId(const DetId &detId) const
T mag() const
Definition: PV3DBase.h:67
bool isNotFinite(T x)
Definition: isFinite.h:10
double phaseShift() const
const CaloVHitFilter * hitFilter() const
EcalHitResponse(const CaloVSimParameterMap *parameterMap, const CaloVShape *shape)
DetId id() const
int maxBunch() const
tuple result
Definition: query.py:137
void setPhaseShift(double phaseShift)
const CaloVHitCorrection * m_hitCorrection
bool isAvailable() const
Definition: Service.h:47
double simHitToPhotoelectrons() const
virtual double timeToRise() const =0
virtual const CaloSimParameters & simParameters(const DetId &id) const =0
virtual bool accepts(const PCaloHit &hit) const =0
int minBunch() const
unsigned int id() const
Definition: PCaloHit.h:41
virtual CLHEP::HepRandomEngine & getEngine() const =0
Use this to get the random number engine, this is the only function most users should call...
virtual void putAnalogSignal(const PCaloHit &inputHit)
const EcalLaserDbService * m_lasercals
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:39
unsigned long long TimeValue_t
Definition: Timestamp.h:27
void setGeometry(const CaloSubdetectorGeometry *geometry)
Definition: DetId.h:20
const CaloSubdetectorGeometry * m_geometry
const CaloSubdetectorGeometry * geometry() const
iterator begin()
const CaloVSimParameterMap * m_parameterMap
void setPECorrection(const CaloVPECorrection *peCorrection)
const CaloVPECorrection * m_PECorrection
ESHandle< TrackerGeometry > geometry
uint32_t size() const
CLHEP::RandPoissonQ * ranPois() const
static const double tzero[3]
CLHEP::RandPoissonQ * m_RandPoisson
EcalSamples * findSignal(const DetId &detId)
virtual double correctPE(const DetId &detId, double npe) const =0
virtual EcalSamples * vSamAll(unsigned int i)=0
const GlobalPoint & getPosition() const
Returns the position of reference for this cell.
void add(const EcalSamples *pSam)
const CaloVHitFilter * m_hitFilter
bool withinBunchRange(int bunchCrossing) const
tuple size
Write out results.
virtual void finalizeHits()
bool zero() const