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  m_parameterMap ( parameterMap ) ,
26  m_shape ( shape ) ,
27  m_hitCorrection ( 0 ) ,
28  m_PECorrection ( 0 ) ,
29  m_hitFilter ( 0 ) ,
30  m_geometry ( 0 ) ,
31  m_RandPoisson ( 0 ) ,
32  m_RandGauss ( 0 ) ,
33  m_minBunch ( -10 ) ,
34  m_maxBunch ( 10 ) ,
35  m_phaseShift ( 1 ) ,
36  m_setup ( false )
37 {
38 }
39 
41 {
42  delete m_RandPoisson ;
43  delete m_RandGauss ;
44 }
45 
46 CLHEP::RandPoissonQ*
48 {
49  if( 0 == m_RandPoisson )
50  {
52  if ( !rng.isAvailable() )
53  {
54  throw cms::Exception("Configuration")
55  << "CaloHitRespoNew requires the RandomNumberGeneratorService\n"
56  "which is not present in the configuration file. You must add the service\n"
57  "in the configuration file or remove the modules that require it.";
58  }
59  m_RandPoisson = new CLHEP::RandPoissonQ( rng->getEngine() );
60  }
61  return m_RandPoisson ;
62 }
63 
64 CLHEP::RandGaussQ*
66 {
67  if( 0 == m_RandGauss )
68  {
70  if ( !rng.isAvailable() )
71  {
72  throw cms::Exception("Configuration")
73  << "CaloHitRespoNew requires the RandomNumberGeneratorService\n"
74  "which is not present in the configuration file. You must add the service\n"
75  "in the configuration file or remove the modules that require it.";
76  }
77  m_RandGauss = new CLHEP::RandGaussQ( rng->getEngine() );
78  }
79  return m_RandGauss ;
80 }
81 
82 const CaloSimParameters*
83 CaloHitRespoNew::params( const DetId& detId ) const
84 {
85  assert( 0 != m_parameterMap ) ;
86  return &m_parameterMap->simParameters( detId ) ;
87 }
88 
89 const CaloVShape*
91 {
92  assert( 0 != m_shape ) ;
93  return m_shape ;
94 }
95 
98 {
99  assert( 0 != m_geometry ) ;
100  return m_geometry ;
101 }
102 
103 void
105  int maxBunch )
106 {
107  m_minBunch = minBunch ;
108  m_maxBunch = maxBunch ;
109 }
110 
111 void
113 {
114  m_geometry = geometry ;
115 }
116 
117 void
118 CaloHitRespoNew::setPhaseShift( double phaseShift )
119 {
121 }
122 
123 double
125 {
126  return m_phaseShift ;
127 }
128 
129 void
131 {
132  m_hitFilter = filter ;
133 }
134 
135 void
137 {
138  m_hitCorrection = hitCorrection ;
139 }
140 
141 void
143 {
144  m_PECorrection = peCorrection ;
145 }
146 
147 void
148 CaloHitRespoNew::setRandomEngine( CLHEP::HepRandomEngine& engine ) const
149 {
150  m_RandPoisson = new CLHEP::RandPoissonQ( engine ) ;
151  m_RandGauss = new CLHEP::RandGaussQ( engine ) ;
152 }
153 
154 const CaloSamples&
155 CaloHitRespoNew::operator[]( unsigned int i ) const
156 {
157  assert( i < m_vSamp.size() ) ;
158  return m_vSamp[ i ] ;
159 }
160 
161 unsigned int
163 {
164  return m_vSamp.size() ;
165 }
166 
167 void
169 {
170  const CaloSimParameters& parameters ( *params( detId ) ) ;
171 
172  const unsigned int rSize ( parameters.readoutFrameSize() ) ;
173  const unsigned int nPre ( parameters.binOfMaximum() - 1 ) ;
174 
175  m_vSamp = VecSam( CaloGenericDetId( detId ).sizeForDenseIndexing() ) ;
176 
177  const unsigned int size ( m_vSamp.size() ) ;
178 
179  for( unsigned int i ( 0 ) ; i != size ; ++i )
180  {
181  m_vSamp[ i ].setDetId( CaloGenericDetId( detId.det(), detId.subdetId(), i ) ) ;
182  m_vSamp[ i ].setSize( rSize ) ;
183  m_vSamp[ i ].setPresamples( nPre ) ;
184  }
185  m_setup = true ;
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( !m_setup &&
205  0 < hits.size() ) setupSamples( hits.begin()->id() ) ;
206 
207  if( 0 != m_index.size() ) blankOutUsedSamples() ;
208 
209  for( MixCollection<PCaloHit>::MixItr hitItr ( hits.begin() ) ;
210  hitItr != hits.end() ; ++hitItr )
211  {
212  const PCaloHit& hit ( *hitItr ) ;
213  const int bunch ( hitItr.bunch() ) ;
214  if( m_minBunch <= bunch &&
215  m_maxBunch >= bunch &&
216  !isnan( hit.time() ) &&
217  ( 0 == m_hitFilter ||
218  m_hitFilter->accepts( hit ) ) ) putAnalogSignal( hit ) ;
219  }
220 }
221 
222 void
224 {
225  PCaloHit hit ( inputHit ) ;
226 
227  if( 0 != m_hitCorrection ) m_hitCorrection->correct( hit ) ;
228 
229  const DetId detId ( hit.id() ) ;
230 
231  const CaloSimParameters* parameters ( params( detId ) ) ;
232 
233  const double signal ( analogSignalAmplitude( hit ) ) ;
234 
235  const double jitter ( hit.time() - timeOfFlight( detId ) ) ;
236 
237  const double tzero = ( shape()->timeToRise()
238  + parameters->timePhase()
239  - jitter
240  - BUNCHSPACE*( parameters->binOfMaximum()
241  - m_phaseShift ) ) ;
242  double binTime ( tzero ) ;
243 
244  CaloSamples& result ( *findSignal( detId ) ) ;
245 
246  const unsigned int rsize ( result.size() ) ;
247 
248  for( unsigned int bin ( 0 ) ; bin != rsize ; ++bin )
249  {
250  result[ bin ] += (*shape())( binTime )*signal ;
251  binTime += BUNCHSPACE;
252  }
253 }
254 
255 CaloSamples*
257 {
258  CaloSamples& result ( m_vSamp[ CaloGenericDetId( detId ).denseIndex() ] ) ;
259  if( result.isBlank() ) m_index.push_back( &result - &m_vSamp.front() ) ;
260  return &result ;
261 }
262 
263 double
265 {
266  const DetId& detId ( hit.id() ) ;
267 
268  const CaloSimParameters& parameters ( *params( detId ) ) ;
269 
270  // OK, the "energy" in the hit could be a real energy, deposited energy,
271  // or pe count. This factor converts to photoelectrons
272 
273  double npe ( hit.energy()*parameters.simHitToPhotoelectrons( detId ) ) ;
274 
275  // do we need to doPoisson statistics for the photoelectrons?
276  if( parameters.doPhotostatistics() ) npe = ranPois()->fire( npe ) ;
277 
278  if( 0 != m_PECorrection ) npe = m_PECorrection->correctPE( detId, npe ) ;
279 
280  return npe ;
281 }
282 
283 double
284 CaloHitRespoNew::timeOfFlight( const DetId& detId ) const
285 {
286  const CaloCellGeometry* cellGeometry ( geometry()->getGeometry( detId ) ) ;
287  assert( 0 != cellGeometry ) ;
288  return cellGeometry->getPosition().mag()*cm/c_light ; // Units of c_light: mm/ns
289 }
void setupSamples(const DetId &detId)
CLHEP::RandPoissonQ * m_RandPoisson
void setHitFilter(const CaloVHitFilter *filter)
int i
Definition: DBlmapReader.cc:9
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
const CaloVShape * shape() const
void setBunchRange(int minBunch, int maxBunch)
Electronic response of the preamp.
Definition: CaloVShape.h:11
virtual void run(MixCollection< PCaloHit > &hits)
Main class for Parameters in different subdetectors.
int size() const
Definition: MixCollection.h:23
CaloHitRespoNew(const CaloVSimParameterMap *parameterMap, const CaloVShape *shape)
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:61
bool isBlank() const
Definition: CaloSamples.cc:35
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
Definition: DetId.h:20
iterator begin()
virtual ~CaloHitRespoNew()
tuple filter
USE THIS FOR SKIMMED TRACKS process.p = cms.Path(process.hltLevel1GTSeed*process.skimming*process.offlineBeamSpot*process.TrackRefitter2) OTHERWISE USE THIS.
Definition: align_tpl.py:86
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
const GlobalPoint & getPosition() const
int binOfMaximum() const
const CaloVHitCorrection * m_hitCorrection
tuple size
Write out results.
const CaloVHitFilter * m_hitFilter