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.
12 
13 #include "CLHEP/Random/RandPoissonQ.h"
14 #include "CLHEP/Units/GlobalPhysicalConstants.h"
15 #include "CLHEP/Units/GlobalSystemOfUnits.h"
16 #include<iostream>
17 
18 
19 
21  const CaloVShape* shape ,
22  DetId detId ) :
23  m_parameterMap ( parameterMap ) ,
24  m_shape ( shape ) ,
25  m_hitCorrection ( 0 ) ,
26  m_PECorrection ( 0 ) ,
27  m_hitFilter ( 0 ) ,
28  m_geometry ( 0 ) ,
29  m_minBunch ( -10 ) ,
30  m_maxBunch ( 10 ) ,
31  m_phaseShift ( 1 )
32 {
33  setupSamples( detId ) ;
34 }
35 
37 {
38 }
39 
40 const CaloSimParameters*
41 CaloHitRespoNew::params( const DetId& detId ) const
42 {
43  assert( 0 != m_parameterMap ) ;
44  return &m_parameterMap->simParameters( detId ) ;
45 }
46 
47 const CaloVShape*
49 {
50  assert( 0 != m_shape ) ;
51  return m_shape ;
52 }
53 
56 {
57  assert( 0 != m_geometry ) ;
58  return m_geometry ;
59 }
60 
61 void
63  int maxBunch )
64 {
67 }
68 
69 void
71 {
73 }
74 
75 void
76 CaloHitRespoNew::setPhaseShift( double phaseShift )
77 {
79 }
80 
81 double
83 {
84  return m_phaseShift ;
85 }
86 
87 void
89 {
91 }
92 
93 void
95 {
96  m_hitCorrection = hitCorrection ;
97 }
98 
99 void
101 {
102  m_PECorrection = peCorrection ;
103 }
104 
105 const CaloSamples&
106 CaloHitRespoNew::operator[]( unsigned int i ) const
107 {
108  assert( i < m_vSamp.size() ) ;
109  return m_vSamp[ i ] ;
110 }
111 
112 unsigned int
114 {
115  return m_vSamp.size() ;
116 }
117 
118 void
120 {
121  const CaloSimParameters& parameters ( *params( detId ) ) ;
122 
123  const unsigned int rSize ( parameters.readoutFrameSize() ) ;
124  const unsigned int nPre ( parameters.binOfMaximum() - 1 ) ;
125 
126  m_vSamp = VecSam( CaloGenericDetId( detId ).sizeForDenseIndexing() ) ;
127 
128  const unsigned int size ( m_vSamp.size() ) ;
129 
130  for( unsigned int i ( 0 ) ; i != size ; ++i )
131  {
132  m_vSamp[ i ].setDetId( CaloGenericDetId( detId.det(), detId.subdetId(), i ) ) ;
133  m_vSamp[ i ].setSize( rSize ) ;
134  m_vSamp[ i ].setPresamples( nPre ) ;
135  }
136 }
137 
138 void
139 CaloHitRespoNew::blankOutUsedSamples() // blank out previously used elements
140 {
141  const unsigned int size ( m_index.size() ) ;
142 
143  for( unsigned int i ( 0 ) ; i != size ; ++i )
144  {
145  m_vSamp[ m_index[i] ].setBlank() ;
146  }
147  m_index.erase( m_index.begin() , // done and make ready to start over
148  m_index.end() ) ;
149 }
150 
151 void
152 CaloHitRespoNew::run( MixCollection<PCaloHit>& hits, CLHEP::HepRandomEngine* engine )
153 {
154  if( 0 != m_index.size() ) blankOutUsedSamples() ;
155 
156  for( MixCollection<PCaloHit>::MixItr hitItr ( hits.begin() ) ;
157  hitItr != hits.end() ; ++hitItr )
158  {
159  if(withinBunchRange(hitItr.bunch())) {
160  add(*hitItr, engine);
161  }
162 
163  }
164 }
165 
166 void
167 CaloHitRespoNew::add( const PCaloHit& hit, CLHEP::HepRandomEngine* engine )
168 {
169  if( !edm::isNotFinite( hit.time() ) &&
170  ( 0 == m_hitFilter ||
171  m_hitFilter->accepts( hit ) ) ) putAnalogSignal( hit, engine ) ;
172 }
173 
174 void
175 CaloHitRespoNew::putAnalogSignal( const PCaloHit& hit, CLHEP::HepRandomEngine* engine )
176 {
177  const DetId detId ( hit.id() ) ;
178 
179  const CaloSimParameters* parameters ( params( detId ) ) ;
180 
181  const double signal ( analogSignalAmplitude( detId, hit.energy(), engine ) ) ;
182 
183  double time = hit.time();
184 
185  if( m_hitCorrection ) {
186  time += m_hitCorrection->delay( hit, engine ) ;
187  }
188 
189  const double jitter ( time - timeOfFlight( detId ) ) ;
190 
191  const double tzero = ( shape()->timeToRise()
192  + parameters->timePhase()
193  - jitter
194  - BUNCHSPACE*( parameters->binOfMaximum()
195  - m_phaseShift ) ) ;
196  double binTime ( tzero ) ;
197 
198  CaloSamples& result ( *findSignal( detId ) ) ;
199 
200  const unsigned int rsize ( result.size() ) ;
201 
202  for( unsigned int bin ( 0 ) ; bin != rsize ; ++bin )
203  {
204  result[ bin ] += (*shape())( binTime )*signal ;
205  binTime += BUNCHSPACE;
206  }
207 }
208 
209 CaloSamples*
211 {
212  CaloSamples& result ( m_vSamp[ CaloGenericDetId( detId ).denseIndex() ] ) ;
213  if( result.isBlank() ) m_index.push_back( &result - &m_vSamp.front() ) ;
214  return &result ;
215 }
216 
217 double
218 CaloHitRespoNew::analogSignalAmplitude( const DetId& detId, float energy, CLHEP::HepRandomEngine* engine ) const
219 {
220  const CaloSimParameters& parameters ( *params( detId ) ) ;
221 
222  // OK, the "energy" in the hit could be a real energy, deposited energy,
223  // or pe count. This factor converts to photoelectrons
224 
225  double npe ( energy*parameters.simHitToPhotoelectrons( detId ) ) ;
226 
227  // do we need to doPoisson statistics for the photoelectrons?
228  if( parameters.doPhotostatistics() ) {
229  CLHEP::RandPoissonQ randPoissonQ(*engine, npe);
230  npe = randPoissonQ.fire();
231  }
232 
233  if( 0 != m_PECorrection ) npe = m_PECorrection->correctPE( detId, npe, engine ) ;
234 
235  return npe ;
236 }
237 
238 double
239 CaloHitRespoNew::timeOfFlight( const DetId& detId ) const
240 {
241  const CaloCellGeometry* cellGeometry ( geometry()->getGeometry( detId ) ) ;
242  assert( 0 != cellGeometry ) ;
243  return cellGeometry->getPosition().mag()*cm/c_light ; // Units of c_light: mm/ns
244 }
void setupSamples(const DetId &detId)
void setHitFilter(const CaloVHitFilter *filter)
int i
Definition: DBlmapReader.cc:9
virtual void run(MixCollection< PCaloHit > &hits, CLHEP::HepRandomEngine *)
double analogSignalAmplitude(const DetId &id, float energy, CLHEP::HepRandomEngine *) const
void setHitCorrection(const CaloVHitCorrection *hitCorrection)
double time() const
Definition: PCaloHit.h:36
const CaloVPECorrection * m_PECorrection
double timeOfFlight(const DetId &detId) const
double energy() const
Definition: PCaloHit.h:29
virtual void add(const PCaloHit &hit, CLHEP::HepRandomEngine *)
int maxBunch() const
assert(m_qm.get())
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
CaloGeometry const * getGeometry()
Main class for Parameters in different subdetectors.
virtual double correctPE(const DetId &detId, double npe, CLHEP::HepRandomEngine *) const =0
tuple result
Definition: mps_fire.py:84
CaloSamples * findSignal(const DetId &detId)
double phaseShift() const
iterator end()
void setGeometry(const CaloSubdetectorGeometry *geometry)
T mag() const
Definition: PV3DBase.h:67
bool isNotFinite(T x)
Definition: isFinite.h:10
bool isBlank() const
Definition: CaloSamples.cc:90
const CaloSubdetectorGeometry * geometry() const
const CaloVSimParameterMap * m_parameterMap
std::vector< CaloSamples > VecSam
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
void setPECorrection(const CaloVPECorrection *peCorrection)
unsigned int id() const
Definition: PCaloHit.h:43
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
virtual double delay(const PCaloHit &hit, CLHEP::HepRandomEngine *) const =0
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]
virtual void putAnalogSignal(const PCaloHit &inputHit, CLHEP::HepRandomEngine *)
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