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.
13 #include "CLHEP/Random/RandPoissonQ.h"
15 
16 #include "CLHEP/Units/GlobalPhysicalConstants.h"
17 #include "CLHEP/Units/GlobalSystemOfUnits.h"
18 #include <iostream>
19 
20 
21 
23  const CaloVShape* shape ) :
24  m_parameterMap ( parameterMap ) ,
25  m_shape ( shape ) ,
26  m_hitCorrection ( 0 ) ,
27  m_PECorrection ( 0 ) ,
28  m_hitFilter ( 0 ) ,
29  m_geometry ( 0 ) ,
30  m_lasercals ( 0 ) ,
31  m_minBunch ( -32 ) ,
32  m_maxBunch ( 10 ) ,
33  m_phaseShift ( 1 ) ,
34  m_iTime ( 0 ) ,
35  m_useLCcorrection ( 0 )
36 {
37 }
38 
40 {
41 }
42 
43 const CaloSimParameters*
44 EcalHitResponse::params( const DetId& detId ) const
45 {
46  assert( 0 != m_parameterMap ) ;
47  return &m_parameterMap->simParameters( detId ) ;
48 }
49 
50 const CaloVShape*
52 {
53  assert( 0 != m_shape ) ;
54  return m_shape ;
55 }
56 
59 {
60  assert( 0 != m_geometry ) ;
61  return m_geometry ;
62 }
63 
64 void
66  int maxBunch )
67 {
70 }
71 
72 void
74 {
76 }
77 
78 void
79 EcalHitResponse::setPhaseShift( double phaseShift )
80 {
82 }
83 
84 double
86 {
87  return m_phaseShift ;
88 }
89 
90 void
92 {
94 }
95 
96 void
98 {
99  m_hitCorrection = hitCorrection ;
100 }
101 
102 void
104 {
105  m_PECorrection = peCorrection ;
106 }
107 
108 void
110 {
111  m_iTime = iTime;
112 }
113 
114 void
116 {
117  m_lasercals = laser;
118  m_useLCcorrection = useLCcorrection;
119 }
120 
121 void
122 EcalHitResponse::blankOutUsedSamples() // blank out previously used elements
123 {
124  const unsigned int size ( m_index.size() ) ;
125 
126  for( unsigned int i ( 0 ) ; i != size ; ++i )
127  {
128  vSamAll( m_index[i] )->setZero() ;
129  }
130  m_index.erase( m_index.begin() , // done and make ready to start over
131  m_index.end() ) ;
132 }
133 
134 void
135 EcalHitResponse::add( const PCaloHit& hit, CLHEP::HepRandomEngine* engine )
136 {
137  if (!edm::isNotFinite( hit.time() ) && ( 0 == m_hitFilter || m_hitFilter->accepts( hit ) ) ) {
138  putAnalogSignal( hit, engine ) ;
139  }
140 }
141 
142 void
144 {
145  const DetId detId ( hit.id() ) ;
146 
147  EcalSamples& result ( *findSignal( detId ) ) ;
148 
149  const int rsize ( result.size() ) ;
150 
151  if(rsize != hit.size()) {
152  throw cms::Exception("EcalDigitization")
153  << "CaloSamples and EcalSamples have different sizes. Type Mismatach";
154  }
155 
156  for( int bin ( 0 ) ; bin != rsize ; ++bin )
157  {
158  result[ bin ] += hit[ bin ] ;
159  }
160 
161 }
162 
163 
164 bool
165 EcalHitResponse::withinBunchRange(int bunchCrossing) const
166 {
167  return(m_minBunch <= bunchCrossing && m_maxBunch >= bunchCrossing);
168 }
169 
170 void
172 {
174 }
175 
176 void
178 {
179 }
180 
181 void
182 EcalHitResponse::run( MixCollection<PCaloHit>& hits, CLHEP::HepRandomEngine* engine )
183 {
185 
186  for( MixCollection<PCaloHit>::MixItr hitItr ( hits.begin() ) ;
187  hitItr != hits.end() ; ++hitItr )
188  {
189  const PCaloHit& hit ( *hitItr ) ;
190  const int bunch ( hitItr.bunch() ) ;
191  if( withinBunchRange(bunch) &&
192  !edm::isNotFinite( hit.time() ) &&
193  ( 0 == m_hitFilter ||
194  m_hitFilter->accepts( hit ) ) ) putAnalogSignal( hit, engine ) ;
195  }
196 }
197 
198 void
199 EcalHitResponse::putAnalogSignal( const PCaloHit& hit, CLHEP::HepRandomEngine* engine )
200 {
201  const DetId detId ( hit.id() ) ;
202 
203  const CaloSimParameters* parameters ( params( detId ) ) ;
204 
205  const double signal ( analogSignalAmplitude( detId, hit.energy(), engine ) ) ;
206 
207  double time = hit.time();
208 
209  if(m_hitCorrection) {
210  time += m_hitCorrection->delay( hit, engine ) ;
211  }
212 
213  const double jitter ( time - timeOfFlight( detId ) ) ;
214 
215  const double tzero = ( shape()->timeToRise()
216  + parameters->timePhase()
217  - jitter
218  - BUNCHSPACE*( parameters->binOfMaximum()
219  - m_phaseShift ) ) ;
220  double binTime ( tzero ) ;
221 
222  EcalSamples& result ( *findSignal( detId ) ) ;
223 
224  const unsigned int rsize ( result.size() ) ;
225 
226  for( unsigned int bin ( 0 ) ; bin != rsize ; ++bin )
227  {
228  result[ bin ] += (*shape())( binTime )*signal ;
229  binTime += BUNCHSPACE ;
230  }
231 }
232 
233 double
235 {
236  const edm::Timestamp& evtTimeStamp = edm::Timestamp(m_iTime);
237  return (m_lasercals->getLaserCorrection(detId, evtTimeStamp));
238 }
239 
242 {
243  const unsigned int di ( CaloGenericDetId( detId ).denseIndex() ) ;
244  EcalSamples* result ( vSamAll( di ) ) ;
245  if( result->zero() ) m_index.push_back( di ) ;
246  return result ;
247 }
248 
249 double
250 EcalHitResponse::analogSignalAmplitude( const DetId& detId, float energy, CLHEP::HepRandomEngine* engine ) const
251 {
252  const CaloSimParameters& parameters ( *params( detId ) ) ;
253 
254  // OK, the "energy" in the hit could be a real energy, deposited energy,
255  // or pe count. This factor converts to photoelectrons
256 
257  float lasercalib = 1.;
258  if(m_useLCcorrection == true && detId.subdetId() != 3) {
259  lasercalib = findLaserConstant(detId);
260  }
261 
262  double npe ( energy/lasercalib*parameters.simHitToPhotoelectrons( detId ) ) ;
263 
264  // do we need to doPoisson statistics for the photoelectrons?
265  if( parameters.doPhotostatistics() ) {
266  CLHEP::RandPoissonQ randPoissonQ(*engine, npe);
267  npe = randPoissonQ.fire();
268  }
269  if( 0 != m_PECorrection ) npe = m_PECorrection->correctPE( detId, npe, engine ) ;
270 
271  return npe ;
272 }
273 
274 double
275 EcalHitResponse::timeOfFlight( const DetId& detId ) const
276 {
277  const CaloCellGeometry* cellGeometry ( geometry()->getGeometry( detId ) ) ;
278  assert( 0 != cellGeometry ) ;
279  return cellGeometry->getPosition().mag()*cm/c_light ; // Units of c_light: mm/ns
280 }
281 
282 void
284 {
285  EcalSamples& sam ( *findSignal( pSam->id() ) ) ;
286  sam += (*pSam) ;
287 }
288 
289 int
291 {
292  return m_minBunch ;
293 }
294 
295 int
297 {
298  return m_maxBunch ;
299 }
300 
303 {
304  return m_index ;
305 }
306 
309 {
310  return m_index ;
311 }
312 
313 const CaloVHitFilter*
315 {
316  return m_hitFilter ;
317 }
318 
320 EcalHitResponse::findDetId( const DetId& detId ) const
321 {
322  const unsigned int di ( CaloGenericDetId( detId ).denseIndex() ) ;
323  return vSamAll( di ) ;
324 }
const CaloVShape * m_shape
int i
Definition: DBlmapReader.cc:9
virtual void run(MixCollection< PCaloHit > &hits, CLHEP::HepRandomEngine *)
dictionary parameters
Definition: Parameters.py:2
double time() const
Definition: PCaloHit.h:36
const CaloVShape * shape() const
double findLaserConstant(const DetId &detId) const
std::vector< unsigned int > VecInd
double analogSignalAmplitude(const DetId &id, float energy, CLHEP::HepRandomEngine *) const
void setEventTime(const edm::TimeValue_t &iTime)
double energy() const
Definition: PCaloHit.h:29
virtual ~EcalHitResponse()
edm::TimeValue_t m_iTime
assert(m_qm.get())
float getLaserCorrection(DetId const &xid, edm::Timestamp const &iTime) const
virtual void initializeHits()
virtual void putAnalogSignal(const PCaloHit &inputHit, CLHEP::HepRandomEngine *)
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
CaloGeometry const * getGeometry()
Main class for Parameters in different subdetectors.
void setHitFilter(const CaloVHitFilter *filter)
const CaloSimParameters * params(const DetId &detId) const
virtual double correctPE(const DetId &detId, double npe, CLHEP::HepRandomEngine *) const =0
void setHitCorrection(const CaloVHitCorrection *hitCorrection)
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
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:43
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:37
unsigned long long TimeValue_t
Definition: Timestamp.h:28
virtual double delay(const PCaloHit &hit, CLHEP::HepRandomEngine *) const =0
void setGeometry(const CaloSubdetectorGeometry *geometry)
Definition: DetId.h:18
const CaloSubdetectorGeometry * m_geometry
const CaloSubdetectorGeometry * geometry() const
iterator begin()
int size() const
get the size
Definition: CaloSamples.h:24
const CaloVSimParameterMap * m_parameterMap
void setPECorrection(const CaloVPECorrection *peCorrection)
const CaloVPECorrection * m_PECorrection
ESHandle< TrackerGeometry > geometry
uint32_t size() const
static const double tzero[3]
EcalSamples * findSignal(const DetId &detId)
DetId id() const
get the (generic) id
Definition: CaloSamples.h:21
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