CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EBHitResponse.cc
Go to the documentation of this file.
8 #include "CLHEP/Random/RandPoissonQ.h"
9 #include "CLHEP/Random/RandGaussQ.h"
12 
13 
15  const CaloVShape* shape ,
16  bool apdOnly ,
17  const APDSimParameters* apdPars = 0 ,
18  const CaloVShape* apdShape = 0 ) :
19 
20  EcalHitResponse( parameterMap, shape ) ,
21 
22  m_apdOnly ( apdOnly ) ,
23  m_apdPars ( apdPars ) ,
24  m_apdShape ( apdShape ) ,
25  m_timeOffVec ( kNOffsets, apdParameters()->timeOffset() ) ,
26  pcub ( 0 == apdPars ? 0 : apdParameters()->nonlParms()[0] ) ,
27  pqua ( 0 == apdPars ? 0 : apdParameters()->nonlParms()[1] ) ,
28  plin ( 0 == apdPars ? 0 : apdParameters()->nonlParms()[2] ) ,
29  pcon ( 0 == apdPars ? 0 : apdParameters()->nonlParms()[3] ) ,
30  pelo ( 0 == apdPars ? 0 : apdParameters()->nonlParms()[4] ) ,
31  pehi ( 0 == apdPars ? 0 : apdParameters()->nonlParms()[5] ) ,
32  pasy ( 0 == apdPars ? 0 : apdParameters()->nonlParms()[6] ) ,
33  pext ( 0 == apdPars ? 0 : nonlFunc1( pelo ) ) ,
34  poff ( 0 == apdPars ? 0 : nonlFunc1( pehi ) ) ,
35  pfac ( 0 == apdPars ? 0 : ( pasy - poff )*2./M_PI )
36 {
37  for( unsigned int i ( 0 ) ; i != kNOffsets ; ++i )
38  {
39  m_timeOffVec[ i ] +=
40  ranGauss()->fire( 0 , apdParameters()->timeOffWidth() ) ;
41  }
42 
43  const EBDetId detId ( EBDetId::detIdFromDenseIndex( 0 ) ) ;
44  const CaloSimParameters& parameters ( parameterMap->simParameters( detId ) ) ;
45 
46  const unsigned int rSize ( parameters.readoutFrameSize() ) ;
47  const unsigned int nPre ( parameters.binOfMaximum() - 1 ) ;
48 
49  const unsigned int size ( EBDetId::kSizeForDenseIndexing ) ;
50 
51  m_vSam.reserve( size ) ;
52 
53  for( unsigned int i ( 0 ) ; i != size ; ++i )
54  {
55  m_vSam.emplace_back(CaloGenericDetId( detId.det(), detId.subdetId(), i ) ,
56  rSize, nPre );
57  }
58 }
59 
61 {
62 }
63 
64 const APDSimParameters*
66 {
67  assert ( 0 != m_apdPars ) ;
68  return m_apdPars ;
69 }
70 
71 const CaloVShape*
73 {
74  assert( 0 != m_apdShape ) ;
75  return m_apdShape ;
76 }
77 
78 void
80  double npe ,
81  double time )
82 {
83  const CaloSimParameters& parameters ( *params( detId ) ) ;
84 
85  const double energyFac ( 1./parameters.simHitToPhotoelectrons( detId ) ) ;
86 
87 // std::cout<<"******** Input APD Npe="<<npe<<", Efactor="<<energyFac
88 // <<", Energy="<<npe*energyFac
89 // <<", nonlFunc="<<nonlFunc( npe*energyFac )<<std::endl ;
90 
91  const double signal ( npe*nonlFunc( npe*energyFac ) ) ;
92 
93  const double jitter ( time - timeOfFlight( detId ) ) ;
94 
95  const double tzero ( apdShape()->timeToRise()
96  - jitter
97  - offsets()[ EBDetId( detId ).denseIndex()%kNOffsets ]
98  - BUNCHSPACE*( parameters.binOfMaximum()
99  - phaseShift() ) ) ;
100 
101  double binTime ( tzero ) ;
102 
103  EcalSamples& result ( *findSignal( detId ) );
104 
105  for( unsigned int bin ( 0 ) ; bin != result.size(); ++bin )
106  {
107  result[bin] += (*apdShape())(binTime)*signal ;
108  binTime += BUNCHSPACE ;
109  }
110 }
111 
112 double
114 {
115  assert( 1 == hit.depth() ||
116  2 == hit.depth() ) ;
117 
118  double npe ( hit.energy()*( 2 == hit.depth() ?
120  apdParameters()->simToPEHigh() ) ) ;
121 
122  // do we need to do Poisson statistics for the photoelectrons?
123  if( apdParameters()->doPEStats() &&
124  !m_apdOnly ) npe = ranPois()->fire( npe ) ;
125 
126  assert( 0 != m_intercal ) ;
127  double fac ( 1 ) ;
128  findIntercalibConstant( hit.id(), fac ) ;
129 
130  npe *= fac ;
131 
132 // edm::LogError( "EBHitResponse" ) << "--- # photoelectrons for "
133 /* std::cout << "--- # photoelectrons for "
134  << EBDetId( hit.id() )
135  <<" is " << npe //;
136  <<std::endl ;*/
137 
138  return npe ;
139 }
140 
141 void
143 {
144  m_intercal = ical ;
145 }
146 
147 void
149  double& icalconst ) const
150 {
151  EcalIntercalibConstantMC thisconst ( 1. ) ;
152 
153  if( 0 == m_intercal )
154  {
155  edm::LogError( "EBHitResponse" ) <<
156  "No intercal constant defined for EBHitResponse" ;
157  }
158  else
159  {
160  const EcalIntercalibConstantMCMap& icalMap ( m_intercal->getMap() ) ;
161  EcalIntercalibConstantMCMap::const_iterator icalit ( icalMap.find( detId ) ) ;
162  if( icalit != icalMap.end() )
163  {
164  thisconst = *icalit ;
165  if ( thisconst == 0. ) thisconst = 1. ;
166  }
167  else
168  {
169  edm::LogError("EBHitResponse") << "No intercalib const found for xtal "
170  << detId.rawId()
171  << "! something wrong with EcalIntercalibConstants in your DB? ";
172  }
173  }
174  icalconst = thisconst ;
175 }
176 
177 void
179  if( 0 != index().size() ) blankOutUsedSamples() ;
180 
181  const unsigned int bSize ( EBDetId::kSizeForDenseIndexing ) ;
182 
183  if( 0 == m_apdNpeVec.size() )
184  {
185  m_apdNpeVec = std::vector<double>( bSize, (double)0.0 ) ;
186  m_apdTimeVec = std::vector<double>( bSize, (double)0.0 ) ;
187  }
188 }
189 
190 void
192  const unsigned int bSize ( EBDetId::kSizeForDenseIndexing ) ;
193  if( apdParameters()->addToBarrel() ||
194  m_apdOnly )
195  {
196  for( unsigned int i ( 0 ) ; i != bSize ; ++i )
197  {
198  if( 0 < m_apdNpeVec[i] )
199  {
201  m_apdNpeVec[i] ,
202  m_apdTimeVec[i] ) ;
203 
204  // now zero out for next time
205  m_apdNpeVec[i] = 0. ;
206  m_apdTimeVec[i] = 0. ;
207  }
208  }
209  }
210 }
211 
212 void
214 {
215  if (!edm::isNotFinite( hit.time() ) && ( 0 == hitFilter() || hitFilter()->accepts( hit ) ) ) {
216  if( 0 == hit.depth() ) // for now take only nonAPD hits
217  {
218  if( !m_apdOnly ) putAnalogSignal( hit ) ;
219  }
220  else // APD hits here
221  {
222  if( apdParameters()->addToBarrel() ||
223  m_apdOnly )
224  {
225  const unsigned int icell ( EBDetId( hit.id() ).denseIndex() ) ;
226  m_apdNpeVec[ icell ] += apdSignalAmplitude( hit ) ;
227  if( 0 == m_apdTimeVec[ icell ] ) m_apdTimeVec[ icell ] = hit.time() ;
228  }
229  }
230  }
231 }
232 
233 void
235 {
236  if( 0 != index().size() ) blankOutUsedSamples() ;
237 
238  const unsigned int bSize ( EBDetId::kSizeForDenseIndexing ) ;
239 
240  if( 0 == m_apdNpeVec.size() )
241  {
242  m_apdNpeVec = std::vector<double>( bSize, (double)0.0 ) ;
243  m_apdTimeVec = std::vector<double>( bSize, (double)0.0 ) ;
244  }
245 
246  for( MixCollection<PCaloHit>::MixItr hitItr ( hits.begin() ) ;
247  hitItr != hits.end() ; ++hitItr )
248  {
249  const PCaloHit& hit ( *hitItr ) ;
250  const int bunch ( hitItr.bunch() ) ;
251  if( minBunch() <= bunch &&
252  maxBunch() >= bunch &&
253  !edm::isNotFinite( hit.time() ) &&
254  ( 0 == hitFilter() ||
255  hitFilter()->accepts( hit ) ) )
256  {
257  if( 0 == hit.depth() ) // for now take only nonAPD hits
258  {
259  if( !m_apdOnly ) putAnalogSignal( hit ) ;
260  }
261  else // APD hits here
262  {
263  if( apdParameters()->addToBarrel() ||
264  m_apdOnly )
265  {
266  const unsigned int icell ( EBDetId( hit.id() ).denseIndex() ) ;
267  m_apdNpeVec[ icell ] += apdSignalAmplitude( hit ) ;
268  if( 0 == m_apdTimeVec[ icell ] ) m_apdTimeVec[ icell ] = hit.time() ;
269  }
270  }
271  }
272  }
273 
274  if( apdParameters()->addToBarrel() ||
275  m_apdOnly )
276  {
277  for( unsigned int i ( 0 ) ; i != bSize ; ++i )
278  {
279  if( 0 < m_apdNpeVec[i] )
280  {
282  m_apdNpeVec[i] ,
283  m_apdTimeVec[i] ) ;
284 
285  // now zero out for next time
286  m_apdNpeVec[i] = 0. ;
287  m_apdTimeVec[i] = 0. ;
288  }
289  }
290  }
291 }
292 
293 unsigned int
295 {
296  return m_vSam.size() ;
297 }
298 
299 unsigned int
301 {
302  return m_vSam.size() ;
303 }
304 
306 EBHitResponse::operator[]( unsigned int i ) const
307 {
308  return &m_vSam[ i ] ;
309 }
310 
313 {
314  return &m_vSam[ i ] ;
315 }
316 
318 EBHitResponse::vSam( unsigned int i )
319 {
320  return &m_vSam[ i ] ;
321 }
322 
324 EBHitResponse::vSamAll( unsigned int i )
325 {
326  return &m_vSam[ i ] ;
327 }
328 
330 EBHitResponse::vSamAll( unsigned int i ) const
331 {
332  return &m_vSam[ i ] ;
333 }
int i
Definition: DBlmapReader.cc:9
dictionary parameters
Definition: Parameters.py:2
double time() const
Definition: PCaloHit.h:34
double simToPEHigh() const
CLHEP::RandGaussQ * ranGauss() const
const self & getMap() const
std::vector< EBSamples > m_vSam
Definition: EBHitResponse.h:93
double energy() const
Definition: PCaloHit.h:29
virtual void add(const PCaloHit &hit)
const CaloVShape * m_apdShape
Definition: EBHitResponse.h:83
void putAPDSignal(const DetId &detId, double npe, double time)
virtual void run(MixCollection< PCaloHit > &hits)
Electronic response of the preamp.
Definition: CaloVShape.h:11
uint16_t depth() const
Definition: PCaloHit.h:47
double timeOfFlight(const DetId &detId) const
const APDSimParameters * apdParameters() const
const APDSimParameters * m_apdPars
Definition: EBHitResponse.h:82
Main class for Parameters in different subdetectors.
const CaloSimParameters * params(const DetId &detId) const
virtual EcalSamples * vSamAll(unsigned int i)
static EBDetId detIdFromDenseIndex(uint32_t di)
Definition: EBDetId.h:112
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
iterator end()
void findIntercalibConstant(const DetId &detId, double &icalconst) const
bool isNotFinite(T x)
Definition: isFinite.h:10
double phaseShift() const
void setIntercal(const EcalIntercalibConstantsMC *ical)
const CaloVHitFilter * hitFilter() const
virtual EcalSamples * operator[](unsigned int i)
const VecD & offsets() const
Definition: EBHitResponse.h:32
int maxBunch() const
tuple result
Definition: query.py:137
double simHitToPhotoelectrons() const
virtual const CaloSimParameters & simParameters(const DetId &id) const =0
virtual unsigned int samplesSizeAll() const
virtual bool accepts(const PCaloHit &hit) const =0
int minBunch() const
unsigned int id() const
Definition: PCaloHit.h:41
virtual void putAnalogSignal(const PCaloHit &inputHit)
const EcalIntercalibConstantsMC * m_intercal
Definition: EBHitResponse.h:84
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:39
std::vector< double > m_timeOffVec
Definition: EBHitResponse.h:86
EBHitResponse(const CaloVSimParameterMap *parameterMap, const CaloVShape *shape, bool apdOnly, const APDSimParameters *apdPars, const CaloVShape *apdShape)
Definition: DetId.h:20
virtual ~EBHitResponse()
iterator begin()
#define M_PI
Definition: BFit3D.cc:3
std::vector< Item >::const_iterator const_iterator
const double nonlFunc(double enr) const
Definition: EBHitResponse.h:62
uint32_t size() const
CLHEP::RandPoissonQ * ranPois() const
static const double tzero[3]
EcalSamples * findSignal(const DetId &detId)
float EcalIntercalibConstantMC
virtual EcalSamples * vSam(unsigned int i)
double apdSignalAmplitude(const PCaloHit &hit) const
const bool m_apdOnly
Definition: EBHitResponse.h:81
Detector det() const
get the detector field from this detid
Definition: DetId.h:37
int binOfMaximum() const
virtual void finalizeHits()
double simToPELow() const
tuple size
Write out results.
std::vector< double > m_apdTimeVec
Definition: EBHitResponse.h:89
std::vector< double > m_apdNpeVec
Definition: EBHitResponse.h:88
virtual unsigned int samplesSize() const
virtual void initializeHits()
const CaloVShape * apdShape() const