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 ( -10 ) ,
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 
139  putAnalogSignal( hit, engine ) ;
140 
141  }
142 }
143 
144 void
146 {
147  const DetId detId ( hit.id() ) ;
148 
149  EcalSamples& result ( *findSignal( detId ) ) ;
150 
151  const int rsize ( result.size() ) ;
152 
153  if(rsize != hit.size()) {
154  throw cms::Exception("EcalDigitization")
155  << "CaloSamples and EcalSamples have different sizes. Type Mismatach";
156  }
157 
158  for( int bin ( 0 ) ; bin != rsize ; ++bin )
159  {
160  result[ bin ] += hit[ bin ] ;
161  }
162 
163 }
164 
165 
166 bool
167 EcalHitResponse::withinBunchRange(int bunchCrossing) const
168 {
169  return(m_minBunch <= bunchCrossing && m_maxBunch >= bunchCrossing);
170 }
171 
172 void
174 {
176 }
177 
178 void
180 {
181 }
182 
183 void
184 EcalHitResponse::run( MixCollection<PCaloHit>& hits, CLHEP::HepRandomEngine* engine )
185 {
187 
188  for( MixCollection<PCaloHit>::MixItr hitItr ( hits.begin() ) ;
189  hitItr != hits.end() ; ++hitItr )
190  {
191  const PCaloHit& hit ( *hitItr ) ;
192  const int bunch ( hitItr.bunch() ) ;
193  if( withinBunchRange(bunch) &&
194  !edm::isNotFinite( hit.time() ) &&
195  ( 0 == m_hitFilter ||
196  m_hitFilter->accepts( hit ) ) ) putAnalogSignal( hit, engine ) ;
197  }
198 }
199 
200 void
201 EcalHitResponse::putAnalogSignal( const PCaloHit& hit, CLHEP::HepRandomEngine* engine )
202 {
203  const DetId detId ( hit.id() ) ;
204 
205  const CaloSimParameters* parameters ( params( detId ) ) ;
206 
207  const double signal ( analogSignalAmplitude( detId, hit.energy(), engine ) ) ;
208 
209  double time = hit.time();
210 
211  if(m_hitCorrection) {
212  time += m_hitCorrection->delay( hit, engine ) ;
213  }
214 
215  const double jitter ( time - timeOfFlight( detId ) ) ;
216 
217  const double tzero = ( shape()->timeToRise()
218  + parameters->timePhase()
219  - jitter
220  - BUNCHSPACE*( parameters->binOfMaximum()
221  - m_phaseShift ) ) ;
222  double binTime ( tzero ) ;
223 
224  EcalSamples& result ( *findSignal( detId ) ) ;
225 
226  const unsigned int rsize ( result.size() ) ;
227 
228  for( unsigned int bin ( 0 ) ; bin != rsize ; ++bin )
229  {
230  result[ bin ] += (*shape())( binTime )*signal ;
231  binTime += BUNCHSPACE ;
232  }
233 }
234 
235 double
237 {
238  const edm::Timestamp& evtTimeStamp = edm::Timestamp(m_iTime);
239  return (m_lasercals->getLaserCorrection(detId, evtTimeStamp));
240 }
241 
244 {
245  const unsigned int di ( CaloGenericDetId( detId ).denseIndex() ) ;
246  EcalSamples* result ( vSamAll( di ) ) ;
247  if( result->zero() ) m_index.push_back( di ) ;
248  return result ;
249 }
250 
251 double
252 EcalHitResponse::analogSignalAmplitude( const DetId& detId, float energy, CLHEP::HepRandomEngine* engine ) const
253 {
254  const CaloSimParameters& parameters ( *params( detId ) ) ;
255 
256  // OK, the "energy" in the hit could be a real energy, deposited energy,
257  // or pe count. This factor converts to photoelectrons
258 
259  float lasercalib = 1.;
260  if(m_useLCcorrection == true && detId.subdetId() != 3) {
261  lasercalib = findLaserConstant(detId);
262  }
263 
264  double npe ( energy/lasercalib*parameters.simHitToPhotoelectrons( detId ) ) ;
265 
266  // do we need to doPoisson statistics for the photoelectrons?
267  if( parameters.doPhotostatistics() ) {
268  CLHEP::RandPoissonQ randPoissonQ(*engine, npe);
269  npe = randPoissonQ.fire();
270  }
271  if( 0 != m_PECorrection ) npe = m_PECorrection->correctPE( detId, npe, engine ) ;
272 
273  return npe ;
274 }
275 
276 double
277 EcalHitResponse::timeOfFlight( const DetId& detId ) const
278 {
279  const CaloCellGeometry* cellGeometry ( geometry()->getGeometry( detId ) ) ;
280  assert( 0 != cellGeometry ) ;
281  return cellGeometry->getPosition().mag()*cm/c_light ; // Units of c_light: mm/ns
282 }
283 
284 void
286 {
287  EcalSamples& sam ( *findSignal( pSam->id() ) ) ;
288  sam += (*pSam) ;
289 }
290 
291 int
293 {
294  return m_minBunch ;
295 }
296 
297 int
299 {
300  return m_maxBunch ;
301 }
302 
305 {
306  return m_index ;
307 }
308 
311 {
312  return m_index ;
313 }
314 
315 const CaloVHitFilter*
317 {
318  return m_hitFilter ;
319 }
320 
322 EcalHitResponse::findDetId( const DetId& detId ) const
323 {
324  const unsigned int di ( CaloGenericDetId( detId ).denseIndex() ) ;
325  return vSamAll( di ) ;
326 }
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
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