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"
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  assert( 1 == hit.depth() ||
128  2 == hit.depth() ) ;
129 
130  double npe ( hit.energy()*( 2 == hit.depth() ?
132  apdParameters()->simToPEHigh() ) ) ;
133 
134  // do we need to do Poisson statistics for the photoelectrons?
135  if( apdParameters()->doPEStats() &&
136  !m_apdOnly ) {
137 
138  CLHEP::RandPoissonQ randPoissonQ(*engine, npe);
139  npe = randPoissonQ.fire();
140  }
141  assert( 0 != m_intercal ) ;
142  double fac ( 1 ) ;
143  findIntercalibConstant( hit.id(), fac ) ;
144 
145  npe *= fac ;
146 
147 // edm::LogError( "EBHitResponse" ) << "--- # photoelectrons for "
148 /* std::cout << "--- # photoelectrons for "
149  << EBDetId( hit.id() )
150  <<" is " << npe //;
151  <<std::endl ;*/
152 
153  return npe ;
154 }
155 
156 void
158 {
159  m_intercal = ical ;
160 }
161 
162 void
164  double& icalconst ) const
165 {
166  EcalIntercalibConstantMC thisconst ( 1. ) ;
167 
168  if( 0 == m_intercal )
169  {
170  edm::LogError( "EBHitResponse" ) <<
171  "No intercal constant defined for EBHitResponse" ;
172  }
173  else
174  {
175  const EcalIntercalibConstantMCMap& icalMap ( m_intercal->getMap() ) ;
176  EcalIntercalibConstantMCMap::const_iterator icalit ( icalMap.find( detId ) ) ;
177  if( icalit != icalMap.end() )
178  {
179  thisconst = *icalit ;
180  if ( thisconst == 0. ) thisconst = 1. ;
181  }
182  else
183  {
184  edm::LogError("EBHitResponse") << "No intercalib const found for xtal "
185  << detId.rawId()
186  << "! something wrong with EcalIntercalibConstants in your DB? ";
187  }
188  }
189  icalconst = thisconst ;
190 }
191 
192 void
194  if( 0 != index().size() ) blankOutUsedSamples() ;
195 
196  const unsigned int bSize ( EBDetId::kSizeForDenseIndexing ) ;
197 
198  if( 0 == m_apdNpeVec.size() )
199  {
200  m_apdNpeVec = std::vector<double>( bSize, (double)0.0 ) ;
201  m_apdTimeVec = std::vector<double>( bSize, (double)0.0 ) ;
202  }
203 }
204 
205 void
207  const unsigned int bSize ( EBDetId::kSizeForDenseIndexing ) ;
208  if( apdParameters()->addToBarrel() ||
209  m_apdOnly )
210  {
211  for( unsigned int i ( 0 ) ; i != bSize ; ++i )
212  {
213  if( 0 < m_apdNpeVec[i] )
214  {
216  m_apdNpeVec[i] ,
217  m_apdTimeVec[i] ) ;
218 
219  // now zero out for next time
220  m_apdNpeVec[i] = 0. ;
221  m_apdTimeVec[i] = 0. ;
222  }
223  }
224  }
225 }
226 
227 void
228 EBHitResponse::add( const PCaloHit& hit, CLHEP::HepRandomEngine* engine )
229 {
230  if (!edm::isNotFinite( hit.time() ) && ( 0 == hitFilter() || hitFilter()->accepts( hit ) ) ) {
231  if( 0 == hit.depth() ) // for now take only nonAPD hits
232  {
233  if( !m_apdOnly ) putAnalogSignal( hit, engine ) ;
234  }
235  else // APD hits here
236  {
237  if( apdParameters()->addToBarrel() ||
238  m_apdOnly )
239  {
240  const unsigned int icell ( EBDetId( hit.id() ).denseIndex() ) ;
241  m_apdNpeVec[ icell ] += apdSignalAmplitude( hit, engine ) ;
242  if( 0 == m_apdTimeVec[ icell ] ) m_apdTimeVec[ icell ] = hit.time() ;
243  }
244  }
245  }
246 }
247 
248 void
249 EBHitResponse::run( MixCollection<PCaloHit>& hits, CLHEP::HepRandomEngine* engine )
250 {
251  if( 0 != index().size() ) blankOutUsedSamples() ;
252 
253  const unsigned int bSize ( EBDetId::kSizeForDenseIndexing ) ;
254 
255  if( 0 == m_apdNpeVec.size() )
256  {
257  m_apdNpeVec = std::vector<double>( bSize, (double)0.0 ) ;
258  m_apdTimeVec = std::vector<double>( bSize, (double)0.0 ) ;
259  }
260 
261  for( MixCollection<PCaloHit>::MixItr hitItr ( hits.begin() ) ;
262  hitItr != hits.end() ; ++hitItr )
263  {
264  const PCaloHit& hit ( *hitItr ) ;
265  const int bunch ( hitItr.bunch() ) ;
266  if( minBunch() <= bunch &&
267  maxBunch() >= bunch &&
268  !edm::isNotFinite( hit.time() ) &&
269  ( 0 == hitFilter() ||
270  hitFilter()->accepts( hit ) ) )
271  {
272  if( 0 == hit.depth() ) // for now take only nonAPD hits
273  {
274  if( !m_apdOnly ) putAnalogSignal( hit, engine ) ;
275  }
276  else // APD hits here
277  {
278  if( apdParameters()->addToBarrel() ||
279  m_apdOnly )
280  {
281  const unsigned int icell ( EBDetId( hit.id() ).denseIndex() ) ;
282  m_apdNpeVec[ icell ] += apdSignalAmplitude( hit, engine ) ;
283  if( 0 == m_apdTimeVec[ icell ] ) m_apdTimeVec[ icell ] = hit.time() ;
284  }
285  }
286  }
287  }
288 
289  if( apdParameters()->addToBarrel() ||
290  m_apdOnly )
291  {
292  for( unsigned int i ( 0 ) ; i != bSize ; ++i )
293  {
294  if( 0 < m_apdNpeVec[i] )
295  {
297  m_apdNpeVec[i] ,
298  m_apdTimeVec[i] ) ;
299 
300  // now zero out for next time
301  m_apdNpeVec[i] = 0. ;
302  m_apdTimeVec[i] = 0. ;
303  }
304  }
305  }
306 }
307 
308 unsigned int
310 {
311  return m_vSam.size() ;
312 }
313 
314 unsigned int
316 {
317  return m_vSam.size() ;
318 }
319 
321 EBHitResponse::operator[]( unsigned int i ) const
322 {
323  return &m_vSam[ i ] ;
324 }
325 
328 {
329  return &m_vSam[ i ] ;
330 }
331 
333 EBHitResponse::vSam( unsigned int i )
334 {
335  return &m_vSam[ i ] ;
336 }
337 
339 EBHitResponse::vSamAll( unsigned int i )
340 {
341  return &m_vSam[ i ] ;
342 }
343 
345 EBHitResponse::vSamAll( unsigned int i ) const
346 {
347  return &m_vSam[ i ] ;
348 }
int i
Definition: DBlmapReader.cc:9
dictionary parameters
Definition: Parameters.py:2
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
assert(m_qm.get())
const CaloVShape * m_apdShape
Definition: EBHitResponse.h:90
void putAPDSignal(const DetId &detId, double npe, double time)
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
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
const VecD & offsets() const
Definition: EBHitResponse.h:67
virtual void initializeHits() override
int maxBunch() const
tuple result
Definition: query.py:137
double apdSignalAmplitude(const PCaloHit &hit, CLHEP::HepRandomEngine *) const
double simHitToPhotoelectrons() const
virtual const CaloSimParameters & simParameters(const DetId &id) const =0
virtual unsigned int samplesSize() const override
virtual bool accepts(const PCaloHit &hit) const =0
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
EBHitResponse(const CaloVSimParameterMap *parameterMap, const CaloVShape *shape, bool apdOnly, const APDSimParameters *apdPars, const CaloVShape *apdShape)
Definition: DetId.h:18
virtual ~EBHitResponse()
iterator begin()
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
virtual unsigned int samplesSizeAll() const override
volatile std::atomic< bool > shutdown_flag false
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
tuple size
Write out results.
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