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"
16 
17 #include "CLHEP/Units/GlobalPhysicalConstants.h"
18 #include "CLHEP/Units/GlobalSystemOfUnits.h"
19 #include<iostream>
20 
21 
22 
24  const CaloVShape* shape ,
25  DetId detId ) :
26  m_parameterMap ( parameterMap ) ,
27  m_shape ( shape ) ,
28  m_hitCorrection ( 0 ) ,
29  m_PECorrection ( 0 ) ,
30  m_hitFilter ( 0 ) ,
31  m_geometry ( 0 ) ,
32  m_RandPoisson ( 0 ) ,
33  m_RandGauss ( 0 ) ,
34  m_minBunch ( -10 ) ,
35  m_maxBunch ( 10 ) ,
36  m_phaseShift ( 1 )
37 {
38  setupSamples( detId ) ;
39 }
40 
42 {
43  delete m_RandPoisson ;
44  delete m_RandGauss ;
45 }
46 
47 CLHEP::RandPoissonQ*
49 {
50  if( 0 == m_RandPoisson )
51  {
53  if ( !rng.isAvailable() )
54  {
55  throw cms::Exception("Configuration")
56  << "CaloHitRespoNew requires the RandomNumberGeneratorService\n"
57  "which is not present in the configuration file. You must add the service\n"
58  "in the configuration file or remove the modules that require it.";
59  }
60  m_RandPoisson = new CLHEP::RandPoissonQ( rng->getEngine() );
61  }
62  return m_RandPoisson ;
63 }
64 
65 CLHEP::RandGaussQ*
67 {
68  if( 0 == m_RandGauss )
69  {
71  if ( !rng.isAvailable() )
72  {
73  throw cms::Exception("Configuration")
74  << "CaloHitRespoNew requires the RandomNumberGeneratorService\n"
75  "which is not present in the configuration file. You must add the service\n"
76  "in the configuration file or remove the modules that require it.";
77  }
78  m_RandGauss = new CLHEP::RandGaussQ( rng->getEngine() );
79  }
80  return m_RandGauss ;
81 }
82 
83 const CaloSimParameters*
84 CaloHitRespoNew::params( const DetId& detId ) const
85 {
86  assert( 0 != m_parameterMap ) ;
87  return &m_parameterMap->simParameters( detId ) ;
88 }
89 
90 const CaloVShape*
92 {
93  assert( 0 != m_shape ) ;
94  return m_shape ;
95 }
96 
99 {
100  assert( 0 != m_geometry ) ;
101  return m_geometry ;
102 }
103 
104 void
106  int maxBunch )
107 {
108  m_minBunch = minBunch ;
109  m_maxBunch = maxBunch ;
110 }
111 
112 void
114 {
115  m_geometry = geometry ;
116 }
117 
118 void
119 CaloHitRespoNew::setPhaseShift( double phaseShift )
120 {
122 }
123 
124 double
126 {
127  return m_phaseShift ;
128 }
129 
130 void
132 {
133  m_hitFilter = filter ;
134 }
135 
136 void
138 {
139  m_hitCorrection = hitCorrection ;
140 }
141 
142 void
144 {
145  m_PECorrection = peCorrection ;
146 }
147 
148 void
149 CaloHitRespoNew::setRandomEngine( CLHEP::HepRandomEngine& engine ) const
150 {
151  m_RandPoisson = new CLHEP::RandPoissonQ( engine ) ;
152  m_RandGauss = new CLHEP::RandGaussQ( engine ) ;
153 }
154 
155 const CaloSamples&
156 CaloHitRespoNew::operator[]( unsigned int i ) const
157 {
158  assert( i < m_vSamp.size() ) ;
159  return m_vSamp[ i ] ;
160 }
161 
162 unsigned int
164 {
165  return m_vSamp.size() ;
166 }
167 
168 void
170 {
171  const CaloSimParameters& parameters ( *params( detId ) ) ;
172 
173  const unsigned int rSize ( parameters.readoutFrameSize() ) ;
174  const unsigned int nPre ( parameters.binOfMaximum() - 1 ) ;
175 
176  m_vSamp = VecSam( CaloGenericDetId( detId ).sizeForDenseIndexing() ) ;
177 
178  const unsigned int size ( m_vSamp.size() ) ;
179 
180  for( unsigned int i ( 0 ) ; i != size ; ++i )
181  {
182  m_vSamp[ i ].setDetId( CaloGenericDetId( detId.det(), detId.subdetId(), i ) ) ;
183  m_vSamp[ i ].setSize( rSize ) ;
184  m_vSamp[ i ].setPresamples( nPre ) ;
185  }
186 }
187 
188 void
189 CaloHitRespoNew::blankOutUsedSamples() // blank out previously used elements
190 {
191  const unsigned int size ( m_index.size() ) ;
192 
193  for( unsigned int i ( 0 ) ; i != size ; ++i )
194  {
195  m_vSamp[ m_index[i] ].setBlank() ;
196  }
197  m_index.erase( m_index.begin() , // done and make ready to start over
198  m_index.end() ) ;
199 }
200 
201 void
203 {
204  if( 0 != m_index.size() ) blankOutUsedSamples() ;
205 
206  for( MixCollection<PCaloHit>::MixItr hitItr ( hits.begin() ) ;
207  hitItr != hits.end() ; ++hitItr )
208  {
209  const PCaloHit& hit ( *hitItr ) ;
210  const int bunch ( hitItr.bunch() ) ;
211  if( m_minBunch <= bunch &&
212  m_maxBunch >= bunch &&
213  !isnan( hit.time() ) &&
214  ( 0 == m_hitFilter ||
215  m_hitFilter->accepts( hit ) ) ) putAnalogSignal( hit ) ;
216  }
217 }
218 
219 void
221 {
222  PCaloHit hit ( inputHit ) ;
223 
224  if( 0 != m_hitCorrection ) m_hitCorrection->correct( hit ) ;
225 
226  const DetId detId ( hit.id() ) ;
227 
228  const CaloSimParameters* parameters ( params( detId ) ) ;
229 
230  const double signal ( analogSignalAmplitude( hit ) ) ;
231 
232  const double jitter ( hit.time() - timeOfFlight( detId ) ) ;
233 
234  const double tzero = ( shape()->timeToRise()
235  + parameters->timePhase()
236  - jitter
237  - BUNCHSPACE*( parameters->binOfMaximum()
238  - m_phaseShift ) ) ;
239  double binTime ( tzero ) ;
240 
241  CaloSamples& result ( *findSignal( detId ) ) ;
242 
243  const unsigned int rsize ( result.size() ) ;
244 
245  for( unsigned int bin ( 0 ) ; bin != rsize ; ++bin )
246  {
247  result[ bin ] += (*shape())( binTime )*signal ;
248  binTime += BUNCHSPACE;
249  }
250 }
251 
252 CaloSamples*
254 {
255  CaloSamples& result ( m_vSamp[ CaloGenericDetId( detId ).denseIndex() ] ) ;
256  if( result.isBlank() ) m_index.push_back( &result - &m_vSamp.front() ) ;
257  return &result ;
258 }
259 
260 double
262 {
263  const DetId& detId ( hit.id() ) ;
264 
265  const CaloSimParameters& parameters ( *params( detId ) ) ;
266 
267  // OK, the "energy" in the hit could be a real energy, deposited energy,
268  // or pe count. This factor converts to photoelectrons
269 
270  double npe ( hit.energy()*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 CaloHitRespoNew::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 }
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:34
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)
Electronic response of the preamp.
Definition: CaloVShape.h:11
const GlobalPoint & getPosition() const
Returns the position of reference for this cell.
virtual void run(MixCollection< PCaloHit > &hits)
Main class for Parameters in different subdetectors.
CaloSamples * findSignal(const DetId &detId)
double phaseShift() const
iterator end()
CLHEP::RandGaussQ * ranGauss() const
void setGeometry(const CaloSubdetectorGeometry *geometry)
virtual void putAnalogSignal(const PCaloHit &inputHit)
T mag() const
Definition: PV3DBase.h:66
bool isBlank() const
Definition: CaloSamples.cc:56
const CaloSubdetectorGeometry * geometry() const
const CaloVSimParameterMap * m_parameterMap
virtual void correct(PCaloHit &hit) const =0
bool isnan(float x)
Definition: math.h:13
std::vector< CaloSamples > VecSam
tuple result
Definition: query.py:137
bool isAvailable() const
Definition: Service.h:47
virtual void setRandomEngine(CLHEP::HepRandomEngine &engine) const
virtual double timeToRise() const =0
virtual const CaloSimParameters & simParameters(const DetId &id) const =0
double analogSignalAmplitude(const PCaloHit &hit) const
virtual bool accepts(const PCaloHit &hit) const =0
void setPECorrection(const CaloVPECorrection *peCorrection)
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...
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:39
void setPhaseShift(double phaseShift)
const CaloSamples & operator[](unsigned int i) const
CaloHitRespoNew(const CaloVSimParameterMap *parameterMap, const CaloVShape *shape, const DetId detId)
Definition: DetId.h:20
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:37
int minBunch() const
int binOfMaximum() const
const CaloVHitCorrection * m_hitCorrection
tuple size
Write out results.
const CaloVHitFilter * m_hitFilter