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"
11 
12 
14  const CaloVShape* shape ,
15  bool apdOnly ,
16  const APDSimParameters* apdPars = 0 ,
17  const CaloVShape* apdShape = 0 ) :
18 
19  EcalHitResponse( parameterMap, shape ) ,
20 
21  m_apdOnly ( apdOnly ) ,
22  m_apdPars ( apdPars ) ,
23  m_apdShape ( apdShape ) ,
24  m_timeOffVec ( kNOffsets, apdParameters()->timeOffset() ) ,
25  pcub ( 0 == apdPars ? 0 : apdParameters()->nonlParms()[0] ) ,
26  pqua ( 0 == apdPars ? 0 : apdParameters()->nonlParms()[1] ) ,
27  plin ( 0 == apdPars ? 0 : apdParameters()->nonlParms()[2] ) ,
28  pcon ( 0 == apdPars ? 0 : apdParameters()->nonlParms()[3] ) ,
29  pelo ( 0 == apdPars ? 0 : apdParameters()->nonlParms()[4] ) ,
30  pehi ( 0 == apdPars ? 0 : apdParameters()->nonlParms()[5] ) ,
31  pasy ( 0 == apdPars ? 0 : apdParameters()->nonlParms()[6] ) ,
32  pext ( 0 == apdPars ? 0 : nonlFunc1( pelo ) ) ,
33  poff ( 0 == apdPars ? 0 : nonlFunc1( pehi ) ) ,
34  pfac ( 0 == apdPars ? 0 : ( pasy - poff )*2./M_PI )
35 {
36  for( unsigned int i ( 0 ) ; i != kNOffsets ; ++i )
37  {
38  m_timeOffVec[ i ] +=
39  ranGauss()->fire( 0 , apdParameters()->timeOffWidth() ) ;
40  }
41 
42  const EBDetId detId ( EBDetId::detIdFromDenseIndex( 0 ) ) ;
43  const CaloSimParameters& parameters ( parameterMap->simParameters( detId ) ) ;
44 
45  const unsigned int rSize ( parameters.readoutFrameSize() ) ;
46  const unsigned int nPre ( parameters.binOfMaximum() - 1 ) ;
47 
48  const unsigned int size ( EBDetId::kSizeForDenseIndexing ) ;
49 
50  m_vSam.reserve( size ) ;
51 
52  for( unsigned int i ( 0 ) ; i != size ; ++i )
53  {
54  m_vSam.push_back(
55  EBSamples( 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 
178 void
180 {
181  if( 0 != index().size() ) blankOutUsedSamples() ;
182 
183  const unsigned int bSize ( EBDetId::kSizeForDenseIndexing ) ;
184 
185  if( 0 == m_apdNpeVec.size() )
186  {
187  m_apdNpeVec = std::vector<double>( bSize, (double)0.0 ) ;
188  m_apdTimeVec = std::vector<double>( bSize, (double)0.0 ) ;
189  }
190 
191  for( MixCollection<PCaloHit>::MixItr hitItr ( hits.begin() ) ;
192  hitItr != hits.end() ; ++hitItr )
193  {
194  const PCaloHit& hit ( *hitItr ) ;
195  const int bunch ( hitItr.bunch() ) ;
196  if( minBunch() <= bunch &&
197  maxBunch() >= bunch &&
198  !isnan( hit.time() ) &&
199  ( 0 == hitFilter() ||
200  hitFilter()->accepts( hit ) ) )
201  {
202  if( 0 == hit.depth() ) // for now take only nonAPD hits
203  {
204  if( !m_apdOnly ) putAnalogSignal( hit ) ;
205  }
206  else // APD hits here
207  {
208  if( apdParameters()->addToBarrel() ||
209  m_apdOnly )
210  {
211  const unsigned int icell ( EBDetId( hit.id() ).denseIndex() ) ;
212  m_apdNpeVec[ icell ] += apdSignalAmplitude( hit ) ;
213  if( 0 == m_apdTimeVec[ icell ] ) m_apdTimeVec[ icell ] = hit.time() ;
214  }
215  }
216  }
217  }
218 
219  if( apdParameters()->addToBarrel() ||
220  m_apdOnly )
221  {
222  for( unsigned int i ( 0 ) ; i != bSize ; ++i )
223  {
224  if( 0 < m_apdNpeVec[i] )
225  {
227  m_apdNpeVec[i] ,
228  m_apdTimeVec[i] ) ;
229 
230  // now zero out for next time
231  m_apdNpeVec[i] = 0. ;
232  m_apdTimeVec[i] = 0. ;
233  }
234  }
235  }
236 }
237 
238 unsigned int
240 {
241  return m_vSam.size() ;
242 }
243 
244 unsigned int
246 {
247  return m_vSam.size() ;
248 }
249 
251 EBHitResponse::operator[]( unsigned int i ) const
252 {
253  return &m_vSam[ i ] ;
254 }
255 
258 {
259  return &m_vSam[ i ] ;
260 }
261 
263 EBHitResponse::vSam( unsigned int i )
264 {
265  return &m_vSam[ i ] ;
266 }
267 
269 EBHitResponse::vSamAll( unsigned int i )
270 {
271  return &m_vSam[ i ] ;
272 }
273 
275 EBHitResponse::vSamAll( unsigned int i ) const
276 {
277  return &m_vSam[ i ] ;
278 }
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:87
double energy() const
Definition: PCaloHit.h:29
const CaloVShape * m_apdShape
Definition: EBHitResponse.h:77
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:45
double timeOfFlight(const DetId &detId) const
const APDSimParameters * apdParameters() const
const APDSimParameters * m_apdPars
Definition: EBHitResponse.h:76
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:98
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
iterator end()
void findIntercalibConstant(const DetId &detId, double &icalconst) const
CaloTSamples< float, 10 > EBSamples
Definition: EBHitResponse.h:14
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
bool isnan(float x)
Definition: math.h:13
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:40
virtual void putAnalogSignal(const PCaloHit &inputHit)
const EcalIntercalibConstantsMC * m_intercal
Definition: EBHitResponse.h:78
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:80
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:56
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:75
Detector det() const
get the detector field from this detid
Definition: DetId.h:37
int binOfMaximum() const
double simToPELow() const
tuple size
Write out results.
std::vector< double > m_apdTimeVec
Definition: EBHitResponse.h:83
std::vector< double > m_apdNpeVec
Definition: EBHitResponse.h:82
virtual unsigned int samplesSize() const
const CaloVShape * apdShape() const