CMS 3D CMS Logo

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