CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CaloHitRespoNew.cc
Go to the documentation of this file.
13 #include "CLHEP/Random/RandPoissonQ.h"
14 #include "CLHEP/Random/RandGaussQ.h"
17 
18 #include "CLHEP/Units/GlobalPhysicalConstants.h"
19 #include "CLHEP/Units/GlobalSystemOfUnits.h"
20 #include<iostream>
21 
22 
23 
25  const CaloVShape* shape ,
26  DetId detId ) :
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_RandPoisson ( 0 ) ,
34  m_RandGauss ( 0 ) ,
35  m_minBunch ( -10 ) ,
36  m_maxBunch ( 10 ) ,
37  m_phaseShift ( 1 )
38 {
39  setupSamples( detId ) ;
40 }
41 
43 {
44  delete m_RandPoisson ;
45  delete m_RandGauss ;
46 }
47 
48 CLHEP::RandPoissonQ*
50 {
51  if( 0 == m_RandPoisson )
52  {
54  if ( !rng.isAvailable() )
55  {
56  throw cms::Exception("Configuration")
57  << "CaloHitRespoNew requires the RandomNumberGeneratorService\n"
58  "which is not present in the configuration file. You must add the service\n"
59  "in the configuration file or remove the modules that require it.";
60  }
61  m_RandPoisson = new CLHEP::RandPoissonQ( rng->getEngine() );
62  }
63  return m_RandPoisson ;
64 }
65 
66 CLHEP::RandGaussQ*
68 {
69  if( 0 == m_RandGauss )
70  {
72  if ( !rng.isAvailable() )
73  {
74  throw cms::Exception("Configuration")
75  << "CaloHitRespoNew requires the RandomNumberGeneratorService\n"
76  "which is not present in the configuration file. You must add the service\n"
77  "in the configuration file or remove the modules that require it.";
78  }
79  m_RandGauss = new CLHEP::RandGaussQ( rng->getEngine() );
80  }
81  return m_RandGauss ;
82 }
83 
84 const CaloSimParameters*
85 CaloHitRespoNew::params( const DetId& detId ) const
86 {
87  assert( 0 != m_parameterMap ) ;
88  return &m_parameterMap->simParameters( detId ) ;
89 }
90 
91 const CaloVShape*
93 {
94  assert( 0 != m_shape ) ;
95  return m_shape ;
96 }
97 
100 {
101  assert( 0 != m_geometry ) ;
102  return m_geometry ;
103 }
104 
105 void
107  int maxBunch )
108 {
109  m_minBunch = minBunch ;
110  m_maxBunch = maxBunch ;
111 }
112 
113 void
115 {
116  m_geometry = geometry ;
117 }
118 
119 void
120 CaloHitRespoNew::setPhaseShift( double phaseShift )
121 {
123 }
124 
125 double
127 {
128  return m_phaseShift ;
129 }
130 
131 void
133 {
134  m_hitFilter = filter ;
135 }
136 
137 void
139 {
140  m_hitCorrection = hitCorrection ;
141 }
142 
143 void
145 {
146  m_PECorrection = peCorrection ;
147 }
148 
149 void
150 CaloHitRespoNew::setRandomEngine( CLHEP::HepRandomEngine& engine ) const
151 {
152  m_RandPoisson = new CLHEP::RandPoissonQ( engine ) ;
153  m_RandGauss = new CLHEP::RandGaussQ( engine ) ;
154 }
155 
156 const CaloSamples&
157 CaloHitRespoNew::operator[]( unsigned int i ) const
158 {
159  assert( i < m_vSamp.size() ) ;
160  return m_vSamp[ i ] ;
161 }
162 
163 unsigned int
165 {
166  return m_vSamp.size() ;
167 }
168 
169 void
171 {
172  const CaloSimParameters& parameters ( *params( detId ) ) ;
173 
174  const unsigned int rSize ( parameters.readoutFrameSize() ) ;
175  const unsigned int nPre ( parameters.binOfMaximum() - 1 ) ;
176 
177  m_vSamp = VecSam( CaloGenericDetId( detId ).sizeForDenseIndexing() ) ;
178 
179  const unsigned int size ( m_vSamp.size() ) ;
180 
181  for( unsigned int i ( 0 ) ; i != size ; ++i )
182  {
183  m_vSamp[ i ].setDetId( CaloGenericDetId( detId.det(), detId.subdetId(), i ) ) ;
184  m_vSamp[ i ].setSize( rSize ) ;
185  m_vSamp[ i ].setPresamples( nPre ) ;
186  }
187 }
188 
189 void
190 CaloHitRespoNew::blankOutUsedSamples() // blank out previously used elements
191 {
192  const unsigned int size ( m_index.size() ) ;
193 
194  for( unsigned int i ( 0 ) ; i != size ; ++i )
195  {
196  m_vSamp[ m_index[i] ].setBlank() ;
197  }
198  m_index.erase( m_index.begin() , // done and make ready to start over
199  m_index.end() ) ;
200 }
201 
202 void
204 {
205  if( 0 != m_index.size() ) blankOutUsedSamples() ;
206 
207  for( MixCollection<PCaloHit>::MixItr hitItr ( hits.begin() ) ;
208  hitItr != hits.end() ; ++hitItr )
209  {
210  if(withinBunchRange(hitItr.bunch())) {
211  add(*hitItr);
212  }
213 
214  }
215 }
216 
217 void
219 {
220  if( !edm::isNotFinite( hit.time() ) &&
221  ( 0 == m_hitFilter ||
222  m_hitFilter->accepts( hit ) ) ) putAnalogSignal( hit ) ;
223 }
224 
225 void
227 {
228  const DetId detId ( hit.id() ) ;
229 
230  const CaloSimParameters* parameters ( params( detId ) ) ;
231 
232  const double signal ( analogSignalAmplitude( detId, hit.energy() ) ) ;
233 
234  double time = hit.time();
235 
236  if( m_hitCorrection ) {
237  time += m_hitCorrection->delay( hit ) ;
238  }
239 
240  const double jitter ( time - timeOfFlight( detId ) ) ;
241 
242  const double tzero = ( shape()->timeToRise()
243  + parameters->timePhase()
244  - jitter
245  - BUNCHSPACE*( parameters->binOfMaximum()
246  - m_phaseShift ) ) ;
247  double binTime ( tzero ) ;
248 
249  CaloSamples& result ( *findSignal( detId ) ) ;
250 
251  const unsigned int rsize ( result.size() ) ;
252 
253  for( unsigned int bin ( 0 ) ; bin != rsize ; ++bin )
254  {
255  result[ bin ] += (*shape())( binTime )*signal ;
256  binTime += BUNCHSPACE;
257  }
258 }
259 
260 CaloSamples*
262 {
263  CaloSamples& result ( m_vSamp[ CaloGenericDetId( detId ).denseIndex() ] ) ;
264  if( result.isBlank() ) m_index.push_back( &result - &m_vSamp.front() ) ;
265  return &result ;
266 }
267 
268 double
270 {
271  const CaloSimParameters& parameters ( *params( detId ) ) ;
272 
273  // OK, the "energy" in the hit could be a real energy, deposited energy,
274  // or pe count. This factor converts to photoelectrons
275 
276  double npe ( energy*parameters.simHitToPhotoelectrons( detId ) ) ;
277 
278  // do we need to doPoisson statistics for the photoelectrons?
279  if( parameters.doPhotostatistics() ) npe = ranPois()->fire( npe ) ;
280 
281  if( 0 != m_PECorrection ) npe = m_PECorrection->correctPE( detId, npe ) ;
282 
283  return npe ;
284 }
285 
286 double
287 CaloHitRespoNew::timeOfFlight( const DetId& detId ) const
288 {
289  const CaloCellGeometry* cellGeometry ( geometry()->getGeometry( detId ) ) ;
290  assert( 0 != cellGeometry ) ;
291  return cellGeometry->getPosition().mag()*cm/c_light ; // Units of c_light: mm/ns
292 }
void setupSamples(const DetId &detId)
CLHEP::RandPoissonQ * m_RandPoisson
void setHitFilter(const CaloVHitFilter *filter)
int i
Definition: DBlmapReader.cc:9
dictionary parameters
Definition: Parameters.py:2
void setHitCorrection(const CaloVHitCorrection *hitCorrection)
double time() const
Definition: PCaloHit.h:36
const CaloVPECorrection * m_PECorrection
CLHEP::RandGaussQ * m_RandGauss
double timeOfFlight(const DetId &detId) const
double energy() const
Definition: PCaloHit.h:29
int maxBunch() const
const CaloVShape * shape() const
void setBunchRange(int minBunch, int maxBunch)
bool doPhotostatistics() const
whether or not to apply Poisson statistics to photoelectrons
Electronic response of the preamp.
Definition: CaloVShape.h:11
bool withinBunchRange(int bunchCrossing) const
virtual void run(MixCollection< PCaloHit > &hits)
Main class for Parameters in different subdetectors.
virtual double delay(const PCaloHit &hit) const =0
virtual void add(const PCaloHit &hit)
CaloSamples * findSignal(const DetId &detId)
double phaseShift() const
iterator end()
CLHEP::RandGaussQ * ranGauss() const
void setGeometry(const CaloSubdetectorGeometry *geometry)
double analogSignalAmplitude(const DetId &id, float energy) const
virtual void putAnalogSignal(const PCaloHit &inputHit)
T mag() const
Definition: PV3DBase.h:67
bool isNotFinite(T x)
Definition: isFinite.h:10
bool isBlank() const
Definition: CaloSamples.cc:88
const CaloSubdetectorGeometry * geometry() const
const CaloVSimParameterMap * m_parameterMap
std::vector< CaloSamples > VecSam
tuple result
Definition: query.py:137
bool isAvailable() const
Definition: Service.h:46
double simHitToPhotoelectrons() const
virtual void setRandomEngine(CLHEP::HepRandomEngine &engine) const
virtual double timeToRise() const =0
virtual const CaloSimParameters & simParameters(const DetId &id) const =0
virtual bool accepts(const PCaloHit &hit) const =0
void setPECorrection(const CaloVPECorrection *peCorrection)
unsigned int id() const
Definition: PCaloHit.h:43
virtual CLHEP::HepRandomEngine & getEngine() const =0
Use this to get the random number engine, this is the only function most users should call...
int readoutFrameSize() const
for now, the LinearFrames and trhe digis will be one-to-one.
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
void setPhaseShift(double phaseShift)
const CaloSamples & operator[](unsigned int i) const
CaloHitRespoNew(const CaloVSimParameterMap *parameterMap, const CaloVShape *shape, const DetId detId)
Definition: DetId.h:18
iterator begin()
virtual ~CaloHitRespoNew()
int size() const
get the size
Definition: CaloSamples.h:24
const CaloSubdetectorGeometry * m_geometry
unsigned int samplesSize() const
ESHandle< TrackerGeometry > geometry
const CaloSimParameters * params(const DetId &detId) const
const CaloVShape * m_shape
static const double tzero[3]
CLHEP::RandPoissonQ * ranPois() const
virtual double correctPE(const DetId &detId, double npe) const =0
Detector det() const
get the detector field from this detid
Definition: DetId.h:35
const GlobalPoint & getPosition() const
Returns the position of reference for this cell.
int minBunch() const
int binOfMaximum() const
const CaloVHitCorrection * m_hitCorrection
tuple size
Write out results.
const CaloVHitFilter * m_hitFilter