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"
18 
19 #include "CLHEP/Units/GlobalPhysicalConstants.h"
20 #include "CLHEP/Units/GlobalSystemOfUnits.h"
21 #include <iostream>
22 
23 
24 
26  const CaloVShape* shape ) :
27  m_parameterMap ( parameterMap ) ,
28  m_shape ( shape ) ,
29  m_hitCorrection ( 0 ) ,
30  m_PECorrection ( 0 ) ,
31  m_hitFilter ( 0 ) ,
32  m_geometry ( 0 ) ,
33  m_lasercals ( 0 ) ,
34  m_RandPoisson ( 0 ) ,
35  m_RandGauss ( 0 ) ,
36  m_minBunch ( -10 ) ,
37  m_maxBunch ( 10 ) ,
38  m_phaseShift ( 1 ) ,
39  m_iTime ( 0 ) ,
40  m_useLCcorrection ( 0 )
41 {
43  if ( !rng.isAvailable() )
44  {
45  throw cms::Exception("Configuration")
46  << "EcalHitResponse requires the RandomNumberGeneratorService\n"
47  "which is not present in the configuration file. You must add the service\n"
48  "in the configuration file or remove the modules that require it.";
49  }
50  m_RandPoisson = new CLHEP::RandPoissonQ( rng->getEngine() ) ;
51  m_RandGauss = new CLHEP::RandGaussQ( rng->getEngine() ) ;
52 }
53 
55 {
56  delete m_RandPoisson ;
57  delete m_RandGauss ;
58 }
59 
60 CLHEP::RandPoissonQ*
62 {
63  return m_RandPoisson ;
64 }
65 
66 CLHEP::RandGaussQ*
68 {
69  return m_RandGauss ;
70 }
71 
72 const CaloSimParameters*
73 EcalHitResponse::params( const DetId& detId ) const
74 {
75  assert( 0 != m_parameterMap ) ;
76  return &m_parameterMap->simParameters( detId ) ;
77 }
78 
79 const CaloVShape*
81 {
82  assert( 0 != m_shape ) ;
83  return m_shape ;
84 }
85 
88 {
89  assert( 0 != m_geometry ) ;
90  return m_geometry ;
91 }
92 
93 void
95  int maxBunch )
96 {
99 }
100 
101 void
103 {
104  m_geometry = geometry ;
105 }
106 
107 void
108 EcalHitResponse::setPhaseShift( double phaseShift )
109 {
111 }
112 
113 double
115 {
116  return m_phaseShift ;
117 }
118 
119 void
121 {
122  m_hitFilter = filter ;
123 }
124 
125 void
127 {
128  m_hitCorrection = hitCorrection ;
129 }
130 
131 void
133 {
134  m_PECorrection = peCorrection ;
135 }
136 
137 void
139 {
140  m_iTime = iTime;
141 }
142 
143 void
144 EcalHitResponse::setLaserConstants(const EcalLaserDbService* laser, bool& useLCcorrection)
145 {
146  m_lasercals = laser;
147  m_useLCcorrection = useLCcorrection;
148 }
149 
150 void
151 EcalHitResponse::blankOutUsedSamples() // blank out previously used elements
152 {
153  const unsigned int size ( m_index.size() ) ;
154 
155  for( unsigned int i ( 0 ) ; i != size ; ++i )
156  {
157  vSamAll( m_index[i] )->setZero() ;
158  }
159  m_index.erase( m_index.begin() , // done and make ready to start over
160  m_index.end() ) ;
161 }
162 
163 void
165 {
167 
168  for( MixCollection<PCaloHit>::MixItr hitItr ( hits.begin() ) ;
169  hitItr != hits.end() ; ++hitItr )
170  {
171  const PCaloHit& hit ( *hitItr ) ;
172  const int bunch ( hitItr.bunch() ) ;
173  if( m_minBunch <= bunch &&
174  m_maxBunch >= bunch &&
175  !isnan( hit.time() ) &&
176  ( 0 == m_hitFilter ||
177  m_hitFilter->accepts( hit ) ) ) putAnalogSignal( hit ) ;
178  }
179 }
180 
181 void
183 {
184  PCaloHit hit ( inputHit ) ;
185 
186  if( 0 != m_hitCorrection ) m_hitCorrection->correct( hit ) ;
187 
188  const DetId detId ( hit.id() ) ;
189 
190  const CaloSimParameters* parameters ( params( detId ) ) ;
191 
192  const double signal ( analogSignalAmplitude( hit ) ) ;
193 
194  const double jitter ( hit.time() - timeOfFlight( detId ) ) ;
195 
196  const double tzero = ( shape()->timeToRise()
197  + parameters->timePhase()
198  - jitter
199  - BUNCHSPACE*( parameters->binOfMaximum()
200  - m_phaseShift ) ) ;
201  double binTime ( tzero ) ;
202 
203  EcalSamples& result ( *findSignal( detId ) ) ;
204 
205  const unsigned int rsize ( result.size() ) ;
206 
207  for( unsigned int bin ( 0 ) ; bin != rsize ; ++bin )
208  {
209  result[ bin ] += (*shape())( binTime )*signal ;
210  binTime += BUNCHSPACE ;
211  }
212 }
213 
214 double
216 {
217  const edm::Timestamp& evtTimeStamp = edm::Timestamp(m_iTime);
218  return (m_lasercals->getLaserCorrection(detId, evtTimeStamp));
219 }
220 
221 
224 {
225  const unsigned int di ( CaloGenericDetId( detId ).denseIndex() ) ;
226  EcalSamples* result ( vSamAll( di ) ) ;
227  if( result->zero() ) m_index.push_back( di ) ;
228  return result ;
229 }
230 
231 double
233 {
234  const DetId& detId ( hit.id() ) ;
235 
236  const CaloSimParameters& parameters ( *params( detId ) ) ;
237 
238  // OK, the "energy" in the hit could be a real energy, deposited energy,
239  // or pe count. This factor converts to photoelectrons
240 
241  float lasercalib = 1.;
242  if(m_useLCcorrection == true && detId.subdetId() != 3) {
243  lasercalib = findLaserConstant(detId);
244  }
245 
246  double npe ( hit.energy()/lasercalib*parameters.simHitToPhotoelectrons( detId ) ) ;
247 
248  // do we need to doPoisson statistics for the photoelectrons?
249  if( parameters.doPhotostatistics() ) npe = ranPois()->fire( npe ) ;
250 
251  if( 0 != m_PECorrection ) npe = m_PECorrection->correctPE( detId, npe ) ;
252 
253  return npe ;
254 }
255 
256 double
257 EcalHitResponse::timeOfFlight( const DetId& detId ) const
258 {
259  const CaloCellGeometry* cellGeometry ( geometry()->getGeometry( detId ) ) ;
260  assert( 0 != cellGeometry ) ;
261  return cellGeometry->getPosition().mag()*cm/c_light ; // Units of c_light: mm/ns
262 }
263 
264 void
266 {
267  EcalSamples& sam ( *findSignal( pSam->id() ) ) ;
268  sam += (*pSam) ;
269 }
270 
271 int
273 {
274  return m_minBunch ;
275 }
276 
277 int
279 {
280  return m_maxBunch ;
281 }
282 
285 {
286  return m_index ;
287 }
288 
291 {
292  return m_index ;
293 }
294 
295 const CaloVHitFilter*
297 {
298  return m_hitFilter ;
299 }
300 
302 EcalHitResponse::findDetId( const DetId& detId ) const
303 {
304  const unsigned int di ( CaloGenericDetId( detId ).denseIndex() ) ;
305  return vSamAll( di ) ;
306 }
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
Electronic response of the preamp.
Definition: CaloVShape.h:11
double timeOfFlight(const DetId &detId) const
const GlobalPoint & getPosition() const
Returns the position of reference for this cell.
Main class for Parameters in different subdetectors.
void setHitFilter(const CaloVHitFilter *filter)
const CaloSimParameters * params(const DetId &detId) const
double analogSignalAmplitude(const PCaloHit &hit) const
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:66
double phaseShift() const
const CaloVHitFilter * hitFilter() const
EcalHitResponse(const CaloVSimParameterMap *parameterMap, const CaloVShape *shape)
DetId id() const
virtual void correct(PCaloHit &hit) const =0
bool isnan(float x)
Definition: math.h:13
int maxBunch() const
tuple result
Definition: query.py:137
void setPhaseShift(double phaseShift)
const CaloVHitCorrection * m_hitCorrection
bool isAvailable() const
Definition: Service.h:47
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:40
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
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
void add(const EcalSamples *pSam)
const CaloVHitFilter * m_hitFilter
tuple size
Write out results.
bool zero() const