CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalDigiProducer.cc
Go to the documentation of this file.
14 //#include "SimCalorimetry/EcalSimAlgos/interface/ESFastTDigitizer.h"
45 
55 
56 
59  m_APDShape ( params.getParameter<double>( "apdShapeTstart" ) ,
60  params.getParameter<double>( "apdShapeTau" ) ) ,
61  m_EBShape ( ) ,
62  m_EEShape ( ) ,
63  m_ESShape ( ) ,
64  m_EBdigiCollection ( params.getParameter<std::string>("EBdigiCollection") ) ,
65  m_EEdigiCollection ( params.getParameter<std::string>("EEdigiCollection") ) ,
66  m_ESdigiCollection ( params.getParameter<std::string>("ESdigiCollection") ) ,
67  m_hitsProducerTag ( params.getParameter<std::string>("hitsProducer" ) ) ,
68  m_useLCcorrection ( params.getUntrackedParameter<bool>("UseLCcorrection") ) ,
69  m_apdSeparateDigi ( params.getParameter<bool> ("apdSeparateDigi") ) ,
70 
71  m_EBs25notCont ( params.getParameter<double> ("EBs25notContainment") ) ,
72  m_EEs25notCont ( params.getParameter<double> ("EEs25notContainment") ) ,
73 
74  m_readoutFrameSize ( params.getParameter<int> ("readoutFrameSize") ) ,
75  m_ParameterMap ( new EcalSimParameterMap(
76  params.getParameter<double> ("simHitToPhotoelectronsBarrel") ,
77  params.getParameter<double> ("simHitToPhotoelectronsEndcap") ,
78  params.getParameter<double> ("photoelectronsToAnalogBarrel") ,
79  params.getParameter<double> ("photoelectronsToAnalogEndcap") ,
80  params.getParameter<double> ("samplingFactor") ,
81  params.getParameter<double> ("timePhase") ,
82  m_readoutFrameSize ,
83  params.getParameter<int> ("binOfMaximum") ,
84  params.getParameter<bool> ("doPhotostatistics") ,
85  params.getParameter<bool> ("syncPhase") ) ) ,
86 
87  m_apdDigiTag ( params.getParameter<std::string> ("apdDigiTag" ) ) ,
88  m_apdParameters ( new APDSimParameters(
89  params.getParameter<bool> ("apdAddToBarrel" ) ,
90  m_apdSeparateDigi ,
91  params.getParameter<double> ("apdSimToPELow" ) ,
92  params.getParameter<double> ("apdSimToPEHigh" ) ,
93  params.getParameter<double> ("apdTimeOffset" ) ,
94  params.getParameter<double> ("apdTimeOffWidth" ) ,
95  params.getParameter<bool> ("apdDoPEStats" ) ,
96  m_apdDigiTag ,
97  params.getParameter<std::vector<double> > ( "apdNonlParms" ) ) ) ,
98 
99  m_APDResponse ( !m_apdSeparateDigi ? nullptr :
100  new EBHitResponse( m_ParameterMap.get() ,
101  &m_EBShape ,
102  true ,
103  m_apdParameters.get() ,
104  &m_APDShape ) ) ,
105 
106  m_EBResponse ( new EBHitResponse( m_ParameterMap.get() ,
107  &m_EBShape ,
108  false , // barrel
109  m_apdParameters.get() ,
110  &m_APDShape ) ) ,
111 
112  m_EEResponse ( new EEHitResponse( m_ParameterMap.get(),
113  &m_EEShape ) ) ,
114  m_ESResponse ( new ESHitResponse( m_ParameterMap.get(), &m_ESShape ) ) ,
115  m_ESOldResponse ( new CaloHitResponse( m_ParameterMap.get(), &m_ESShape ) ) ,
116 
117  m_addESNoise ( params.getParameter<bool> ("doESNoise") ) ,
118  m_PreMix1 ( params.getParameter<bool> ("EcalPreMixStage1") ) ,
119  m_PreMix2 ( params.getParameter<bool> ("EcalPreMixStage2") ) ,
120 
121  m_doFastES ( params.getParameter<bool> ("doFast" ) ) ,
122 
123  m_doEB ( params.getParameter<bool> ("doEB" ) ) ,
124  m_doEE ( params.getParameter<bool> ("doEE" ) ) ,
125  m_doES ( params.getParameter<bool> ("doES" ) ) ,
126 
127  m_ESElectronicsSim ( m_doFastES ? nullptr :
128  new ESElectronicsSim( m_addESNoise ) ) ,
129 
130  m_ESOldDigitizer ( m_doFastES ? nullptr :
131  new ESOldDigitizer( m_ESOldResponse.get() ,
132  m_ESElectronicsSim.get() ,
133  m_addESNoise ) ) ,
134 
135  m_ESElectronicsSimFast ( !m_doFastES ? nullptr :
136  new ESElectronicsSimFast( m_addESNoise ,
137  m_PreMix1) ) ,
138 
139  m_ESDigitizer ( !m_doFastES ? nullptr :
140  new ESDigitizer( m_ESResponse.get() ,
141  m_ESElectronicsSimFast.get() ,
142  m_addESNoise ) ) ,
143 
144  m_APDDigitizer ( nullptr ) ,
145  m_BarrelDigitizer ( nullptr ) ,
146  m_EndcapDigitizer ( nullptr ) ,
147  m_ElectronicsSim ( nullptr ) ,
148  m_Coder ( nullptr ) ,
149  m_APDElectronicsSim ( nullptr ) ,
150  m_APDCoder ( nullptr ) ,
151  m_Geometry ( nullptr ) ,
152  m_EBCorrNoise ( { {nullptr, nullptr, nullptr} } ) ,
153  m_EECorrNoise ( { {nullptr, nullptr, nullptr} } )
154 {
155  if(m_apdSeparateDigi) mixMod.produces<EBDigiCollection>(m_apdDigiTag);
156 
157  mixMod.produces<EBDigiCollection>(m_EBdigiCollection);
158  mixMod.produces<EEDigiCollection>(m_EEdigiCollection);
159  mixMod.produces<ESDigiCollection>(m_ESdigiCollection);
160 
161  if( m_doEB ) iC.consumes<std::vector<PCaloHit> >(edm::InputTag(m_hitsProducerTag, "EcalHitsEB"));
162  if( m_doEE ) iC.consumes<std::vector<PCaloHit> >(edm::InputTag(m_hitsProducerTag, "EcalHitsEE"));
163  if( m_doES ) iC.consumes<std::vector<PCaloHit> >(edm::InputTag(m_hitsProducerTag, "EcalHitsES"));
164 
165  const std::vector<double> ebCorMatG12 = params.getParameter< std::vector<double> >("EBCorrNoiseMatrixG12");
166  const std::vector<double> eeCorMatG12 = params.getParameter< std::vector<double> >("EECorrNoiseMatrixG12");
167  const std::vector<double> ebCorMatG06 = params.getParameter< std::vector<double> >("EBCorrNoiseMatrixG06");
168  const std::vector<double> eeCorMatG06 = params.getParameter< std::vector<double> >("EECorrNoiseMatrixG06");
169  const std::vector<double> ebCorMatG01 = params.getParameter< std::vector<double> >("EBCorrNoiseMatrixG01");
170  const std::vector<double> eeCorMatG01 = params.getParameter< std::vector<double> >("EECorrNoiseMatrixG01");
171 
172  const bool applyConstantTerm = params.getParameter<bool> ("applyConstantTerm");
173  const double rmsConstantTerm = params.getParameter<double> ("ConstantTerm");
174 
175  const bool addNoise = params.getParameter<bool> ("doENoise");
176  const bool cosmicsPhase = params.getParameter<bool> ("cosmicsPhase");
177  const double cosmicsShift = params.getParameter<double> ("cosmicsShift");
178 
179 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
180 
181  // further phase for cosmics studies
182  if( cosmicsPhase )
183  {
184  if( m_doEB ) m_EBResponse->setPhaseShift( 1. + cosmicsShift ) ;
185  if( m_doEE ) m_EEResponse->setPhaseShift( 1. + cosmicsShift ) ;
186  }
187 
188  EcalCorrMatrix ebMatrix[ 3 ] ;
189  EcalCorrMatrix eeMatrix[ 3 ] ;
190 
191  assert( ebCorMatG12.size() == m_readoutFrameSize ) ;
192  assert( eeCorMatG12.size() == m_readoutFrameSize ) ;
193  assert( ebCorMatG06.size() == m_readoutFrameSize ) ;
194  assert( eeCorMatG06.size() == m_readoutFrameSize ) ;
195  assert( ebCorMatG01.size() == m_readoutFrameSize ) ;
196  assert( eeCorMatG01.size() == m_readoutFrameSize ) ;
197 
198  assert( 1.e-7 > fabs( ebCorMatG12[0] - 1.0 ) ) ;
199  assert( 1.e-7 > fabs( ebCorMatG06[0] - 1.0 ) ) ;
200  assert( 1.e-7 > fabs( ebCorMatG01[0] - 1.0 ) ) ;
201  assert( 1.e-7 > fabs( eeCorMatG12[0] - 1.0 ) ) ;
202  assert( 1.e-7 > fabs( eeCorMatG06[0] - 1.0 ) ) ;
203  assert( 1.e-7 > fabs( eeCorMatG01[0] - 1.0 ) ) ;
204 
205  for ( unsigned int row ( 0 ) ; row != m_readoutFrameSize ; ++row )
206  {
207  assert( 0 == row || 1. >= ebCorMatG12[row] ) ;
208  assert( 0 == row || 1. >= ebCorMatG06[row] ) ;
209  assert( 0 == row || 1. >= ebCorMatG01[row] ) ;
210  assert( 0 == row || 1. >= eeCorMatG12[row] ) ;
211  assert( 0 == row || 1. >= eeCorMatG06[row] ) ;
212  assert( 0 == row || 1. >= eeCorMatG01[row] ) ;
213  for ( unsigned int column ( 0 ) ; column <= row ; ++column )
214  {
215  const unsigned int index ( row - column ) ;
216  ebMatrix[0]( row, column ) = ebCorMatG12[ index ] ;
217  eeMatrix[0]( row, column ) = eeCorMatG12[ index ] ;
218  ebMatrix[1]( row, column ) = ebCorMatG06[ index ] ;
219  eeMatrix[1]( row, column ) = eeCorMatG06[ index ] ;
220  ebMatrix[2]( row, column ) = ebCorMatG01[ index ] ;
221  eeMatrix[2]( row, column ) = eeCorMatG01[ index ] ;
222  }
223  }
224 
225  m_EBCorrNoise[0].reset( new CorrelatedNoisifier<EcalCorrMatrix>( ebMatrix[0] ) );
226  m_EECorrNoise[0].reset( new CorrelatedNoisifier<EcalCorrMatrix>( eeMatrix[0] ) );
227  m_EBCorrNoise[1].reset( new CorrelatedNoisifier<EcalCorrMatrix>( ebMatrix[1] ) );
228  m_EECorrNoise[1].reset( new CorrelatedNoisifier<EcalCorrMatrix>( eeMatrix[1] ) );
229  m_EBCorrNoise[2].reset( new CorrelatedNoisifier<EcalCorrMatrix>( ebMatrix[2] ) );
230  m_EECorrNoise[2].reset( new CorrelatedNoisifier<EcalCorrMatrix>( eeMatrix[2] ) );
231 
232  m_Coder.reset( new EcalCoder( addNoise ,
233  m_PreMix1 ,
234  m_EBCorrNoise[0].get() ,
235  m_EECorrNoise[0].get() ,
236  m_EBCorrNoise[1].get() ,
237  m_EECorrNoise[1].get() ,
238  m_EBCorrNoise[2].get() ,
239  m_EECorrNoise[2].get() ) );
240 
241  m_ElectronicsSim.reset( new EcalElectronicsSim( m_ParameterMap.get() ,
242  m_Coder.get() ,
243  applyConstantTerm ,
244  rmsConstantTerm ) );
245 
246  if( m_apdSeparateDigi )
247  {
248  m_APDCoder.reset( new EcalCoder( false ,
249  m_PreMix1 ,
250  m_EBCorrNoise[0].get() ,
251  m_EECorrNoise[0].get() ,
252  m_EBCorrNoise[1].get() ,
253  m_EECorrNoise[1].get() ,
254  m_EBCorrNoise[2].get() ,
255  m_EECorrNoise[2].get() ) );
256 
257  m_APDElectronicsSim.reset( new EcalElectronicsSim( m_ParameterMap.get() ,
258  m_APDCoder.get() ,
259  applyConstantTerm ,
260  rmsConstantTerm ) );
261 
262  m_APDDigitizer.reset( new EBDigitizer( m_APDResponse.get() ,
263  m_APDElectronicsSim.get() ,
264  false ) );
265  }
266 
267  if( m_doEB ) {
268  m_BarrelDigitizer.reset( new EBDigitizer( m_EBResponse.get() ,
269  m_ElectronicsSim.get() ,
270  addNoise ) );
271  }
272 
273  if ( m_doEE ) {
274  m_EndcapDigitizer.reset( new EEDigitizer( m_EEResponse.get() ,
275  m_ElectronicsSim.get() ,
276  addNoise ) );
277  }
278 }
279 
280 
281 // duplicate version for Pre-Mixing, for use outside of MixingModule
284  m_APDShape ( params.getParameter<double>( "apdShapeTstart" ) ,
285  params.getParameter<double>( "apdShapeTau" ) ) ,
286  m_EBShape ( ) ,
287  m_EEShape ( ) ,
288  m_ESShape ( ) ,
289  m_EBdigiCollection ( params.getParameter<std::string>("EBdigiCollection") ) ,
290  m_EEdigiCollection ( params.getParameter<std::string>("EEdigiCollection") ) ,
291  m_ESdigiCollection ( params.getParameter<std::string>("ESdigiCollection") ) ,
292  m_hitsProducerTag ( params.getParameter<std::string>("hitsProducer" ) ) ,
293  m_useLCcorrection ( params.getUntrackedParameter<bool>("UseLCcorrection") ) ,
294  m_apdSeparateDigi ( params.getParameter<bool> ("apdSeparateDigi") ) ,
295 
296  m_EBs25notCont ( params.getParameter<double> ("EBs25notContainment") ) ,
297  m_EEs25notCont ( params.getParameter<double> ("EEs25notContainment") ) ,
298 
299  m_readoutFrameSize ( params.getParameter<int> ("readoutFrameSize") ) ,
300  m_ParameterMap ( new EcalSimParameterMap(
301  params.getParameter<double> ("simHitToPhotoelectronsBarrel") ,
302  params.getParameter<double> ("simHitToPhotoelectronsEndcap") ,
303  params.getParameter<double> ("photoelectronsToAnalogBarrel") ,
304  params.getParameter<double> ("photoelectronsToAnalogEndcap") ,
305  params.getParameter<double> ("samplingFactor") ,
306  params.getParameter<double> ("timePhase") ,
307  m_readoutFrameSize ,
308  params.getParameter<int> ("binOfMaximum") ,
309  params.getParameter<bool> ("doPhotostatistics") ,
310  params.getParameter<bool> ("syncPhase") ) ) ,
311 
312  m_apdDigiTag ( params.getParameter<std::string> ("apdDigiTag" ) ) ,
313  m_apdParameters ( new APDSimParameters(
314  params.getParameter<bool> ("apdAddToBarrel" ) ,
315  m_apdSeparateDigi ,
316  params.getParameter<double> ("apdSimToPELow" ) ,
317  params.getParameter<double> ("apdSimToPEHigh" ) ,
318  params.getParameter<double> ("apdTimeOffset" ) ,
319  params.getParameter<double> ("apdTimeOffWidth" ) ,
320  params.getParameter<bool> ("apdDoPEStats" ) ,
321  m_apdDigiTag ,
322  params.getParameter<std::vector<double> > ( "apdNonlParms" ) ) ) ,
323 
324  m_APDResponse ( !m_apdSeparateDigi ? nullptr :
325  new EBHitResponse( m_ParameterMap.get() ,
326  &m_EBShape ,
327  true ,
328  m_apdParameters.get() ,
329  &m_APDShape ) ) ,
330 
331  m_EBResponse ( new EBHitResponse( m_ParameterMap.get() ,
332  &m_EBShape ,
333  false , // barrel
334  m_apdParameters.get() ,
335  &m_APDShape ) ) ,
336 
337  m_EEResponse ( new EEHitResponse( m_ParameterMap.get(),
338  &m_EEShape ) ) ,
339  m_ESResponse ( new ESHitResponse( m_ParameterMap.get(), &m_ESShape ) ) ,
340  m_ESOldResponse ( new CaloHitResponse( m_ParameterMap.get(), &m_ESShape ) ) ,
341 
342  m_addESNoise ( params.getParameter<bool> ("doESNoise") ) ,
343  m_PreMix1 ( params.getParameter<bool> ("EcalPreMixStage1") ) ,
344  m_PreMix2 ( params.getParameter<bool> ("EcalPreMixStage2") ) ,
345 
346  m_doFastES ( params.getParameter<bool> ("doFast" ) ) ,
347 
348  m_doEB ( params.getParameter<bool> ("doEB" ) ) ,
349  m_doEE ( params.getParameter<bool> ("doEE" ) ) ,
350  m_doES ( params.getParameter<bool> ("doES" ) ) ,
351 
352  m_ESElectronicsSim ( m_doFastES ? nullptr :
353  new ESElectronicsSim( m_addESNoise ) ) ,
354 
355  m_ESOldDigitizer ( m_doFastES ? nullptr :
356  new ESOldDigitizer( m_ESOldResponse.get() ,
357  m_ESElectronicsSim.get() ,
358  m_addESNoise ) ) ,
359 
360  m_ESElectronicsSimFast ( !m_doFastES ? nullptr :
361  new ESElectronicsSimFast( m_addESNoise,
362  m_PreMix1 ) ) ,
363 
364  m_ESDigitizer ( !m_doFastES ? nullptr :
365  new ESDigitizer( m_ESResponse.get() ,
366  m_ESElectronicsSimFast.get() ,
367  m_addESNoise ) ) ,
368 
369  m_APDDigitizer ( nullptr ) ,
370  m_BarrelDigitizer ( nullptr ) ,
371  m_EndcapDigitizer ( nullptr ) ,
372  m_ElectronicsSim ( nullptr ) ,
373  m_Coder ( nullptr ) ,
374  m_APDElectronicsSim ( nullptr ) ,
375  m_APDCoder ( nullptr ) ,
376  m_Geometry ( nullptr ) ,
377  m_EBCorrNoise ( { {nullptr, nullptr, nullptr} } ) ,
378  m_EECorrNoise ( { {nullptr, nullptr, nullptr} } )
379 {
380  // "produces" statements taken care of elsewhere.
381  // if(m_apdSeparateDigi) mixMod.produces<EBDigiCollection>(m_apdDigiTag);
382  // mixMod.produces<EBDigiCollection>(m_EBdigiCollection);
383  // mixMod.produces<EEDigiCollection>(m_EEdigiCollection);
384  // mixMod.produces<ESDigiCollection>(m_ESdigiCollection);
385  if ( m_doEB ) iC.consumes<std::vector<PCaloHit> >(edm::InputTag(m_hitsProducerTag, "EcalHitsEB"));
386  if ( m_doEE ) iC.consumes<std::vector<PCaloHit> >(edm::InputTag(m_hitsProducerTag, "EcalHitsEE"));
387  if ( m_doES ) iC.consumes<std::vector<PCaloHit> >(edm::InputTag(m_hitsProducerTag, "EcalHitsES"));
388 
389  const std::vector<double> ebCorMatG12 = params.getParameter< std::vector<double> >("EBCorrNoiseMatrixG12");
390  const std::vector<double> eeCorMatG12 = params.getParameter< std::vector<double> >("EECorrNoiseMatrixG12");
391  const std::vector<double> ebCorMatG06 = params.getParameter< std::vector<double> >("EBCorrNoiseMatrixG06");
392  const std::vector<double> eeCorMatG06 = params.getParameter< std::vector<double> >("EECorrNoiseMatrixG06");
393  const std::vector<double> ebCorMatG01 = params.getParameter< std::vector<double> >("EBCorrNoiseMatrixG01");
394  const std::vector<double> eeCorMatG01 = params.getParameter< std::vector<double> >("EECorrNoiseMatrixG01");
395 
396  const bool applyConstantTerm = params.getParameter<bool> ("applyConstantTerm");
397  const double rmsConstantTerm = params.getParameter<double> ("ConstantTerm");
398 
399  const bool addNoise = params.getParameter<bool> ("doENoise");
400  const bool cosmicsPhase = params.getParameter<bool> ("cosmicsPhase");
401  const double cosmicsShift = params.getParameter<double> ("cosmicsShift");
402 
403 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
404 
405  // further phase for cosmics studies
406  if( cosmicsPhase )
407  {
408  if( m_doEB ) m_EBResponse->setPhaseShift( 1. + cosmicsShift ) ;
409  if( m_doEE ) m_EEResponse->setPhaseShift( 1. + cosmicsShift ) ;
410  }
411 
412  EcalCorrMatrix ebMatrix[ 3 ] ;
413  EcalCorrMatrix eeMatrix[ 3 ] ;
414 
415  assert( ebCorMatG12.size() == m_readoutFrameSize ) ;
416  assert( eeCorMatG12.size() == m_readoutFrameSize ) ;
417  assert( ebCorMatG06.size() == m_readoutFrameSize ) ;
418  assert( eeCorMatG06.size() == m_readoutFrameSize ) ;
419  assert( ebCorMatG01.size() == m_readoutFrameSize ) ;
420  assert( eeCorMatG01.size() == m_readoutFrameSize ) ;
421 
422  assert( 1.e-7 > fabs( ebCorMatG12[0] - 1.0 ) ) ;
423  assert( 1.e-7 > fabs( ebCorMatG06[0] - 1.0 ) ) ;
424  assert( 1.e-7 > fabs( ebCorMatG01[0] - 1.0 ) ) ;
425  assert( 1.e-7 > fabs( eeCorMatG12[0] - 1.0 ) ) ;
426  assert( 1.e-7 > fabs( eeCorMatG06[0] - 1.0 ) ) ;
427  assert( 1.e-7 > fabs( eeCorMatG01[0] - 1.0 ) ) ;
428 
429  for ( unsigned int row ( 0 ) ; row != m_readoutFrameSize ; ++row )
430  {
431  assert( 0 == row || 1. >= ebCorMatG12[row] ) ;
432  assert( 0 == row || 1. >= ebCorMatG06[row] ) ;
433  assert( 0 == row || 1. >= ebCorMatG01[row] ) ;
434  assert( 0 == row || 1. >= eeCorMatG12[row] ) ;
435  assert( 0 == row || 1. >= eeCorMatG06[row] ) ;
436  assert( 0 == row || 1. >= eeCorMatG01[row] ) ;
437  for ( unsigned int column ( 0 ) ; column <= row ; ++column )
438  {
439  const unsigned int index ( row - column ) ;
440  ebMatrix[0]( row, column ) = ebCorMatG12[ index ] ;
441  eeMatrix[0]( row, column ) = eeCorMatG12[ index ] ;
442  ebMatrix[1]( row, column ) = ebCorMatG06[ index ] ;
443  eeMatrix[1]( row, column ) = eeCorMatG06[ index ] ;
444  ebMatrix[2]( row, column ) = ebCorMatG01[ index ] ;
445  eeMatrix[2]( row, column ) = eeCorMatG01[ index ] ;
446  }
447  }
448 
449  m_EBCorrNoise[0].reset( new CorrelatedNoisifier<EcalCorrMatrix>( ebMatrix[0] ) );
450  m_EECorrNoise[0].reset( new CorrelatedNoisifier<EcalCorrMatrix>( eeMatrix[0] ) );
451  m_EBCorrNoise[1].reset( new CorrelatedNoisifier<EcalCorrMatrix>( ebMatrix[1] ) );
452  m_EECorrNoise[1].reset( new CorrelatedNoisifier<EcalCorrMatrix>( eeMatrix[1] ) );
453  m_EBCorrNoise[2].reset( new CorrelatedNoisifier<EcalCorrMatrix>( ebMatrix[2] ) );
454  m_EECorrNoise[2].reset( new CorrelatedNoisifier<EcalCorrMatrix>( eeMatrix[2] ) );
455 
456  m_Coder.reset( new EcalCoder( addNoise ,
457  m_PreMix1 ,
458  m_EBCorrNoise[0].get() ,
459  m_EECorrNoise[0].get() ,
460  m_EBCorrNoise[1].get() ,
461  m_EECorrNoise[1].get() ,
462  m_EBCorrNoise[2].get() ,
463  m_EECorrNoise[2].get() ) );
464 
465  m_ElectronicsSim.reset( new EcalElectronicsSim( m_ParameterMap.get() ,
466  m_Coder.get() ,
467  applyConstantTerm ,
468  rmsConstantTerm ) );
469 
470  if( m_apdSeparateDigi )
471  {
472  m_APDCoder.reset( new EcalCoder( false ,
473  m_EBCorrNoise[0].get() ,
474  m_EECorrNoise[0].get() ,
475  m_EBCorrNoise[1].get() ,
476  m_EECorrNoise[1].get() ,
477  m_EBCorrNoise[2].get() ,
478  m_EECorrNoise[2].get() ) );
479 
480  m_APDElectronicsSim.reset( new EcalElectronicsSim( m_ParameterMap.get() ,
481  m_APDCoder.get() ,
482  applyConstantTerm ,
483  rmsConstantTerm ) );
484 
485  m_APDDigitizer.reset( new EBDigitizer( m_APDResponse.get() ,
486  m_APDElectronicsSim.get() ,
487  false ) );
488  }
489 
490  if( m_doEB ) {
491  m_BarrelDigitizer.reset( new EBDigitizer( m_EBResponse.get() ,
492  m_ElectronicsSim.get() ,
493  addNoise ) );
494  }
495 
496  if( m_doEE ) {
497  m_EndcapDigitizer.reset( new EEDigitizer( m_EEResponse.get() ,
498  m_ElectronicsSim.get() ,
499  addNoise ) );
500  }
501 }
502 
503 
505 {}
506 
507 void
509  checkGeometry( eventSetup );
510  checkCalibrations( event, eventSetup );
511  if( m_doEB ) {
512  m_BarrelDigitizer->initializeHits();
513  if(m_apdSeparateDigi) {
514  m_APDDigitizer->initializeHits();
515  }
516  }
517  if( m_doEE ) {
518  m_EndcapDigitizer->initializeHits();
519  }
520  if( m_doES ) {
521  if(m_doFastES) {
522  m_ESDigitizer->initializeHits();
523  } else {
524  m_ESOldDigitizer->initializeHits();
525  }
526  }
527 }
528 
529 void
530 EcalDigiProducer::accumulateCaloHits(HitsHandle const& ebHandle, HitsHandle const& eeHandle, HitsHandle const& esHandle, int bunchCrossing, CLHEP::HepRandomEngine* engine) {
531  if(m_doEB && ebHandle.isValid()) {
532  m_BarrelDigitizer->add(*ebHandle.product(), bunchCrossing, engine);
533 
534  if(m_apdSeparateDigi) {
535  m_APDDigitizer->add(*ebHandle.product(), bunchCrossing, engine);
536  }
537  }
538 
539  if(m_doEE && eeHandle.isValid()) {
540  m_EndcapDigitizer->add(*eeHandle.product(), bunchCrossing, engine);
541  }
542 
543  if(m_doES && esHandle.isValid()) {
544  if(m_doFastES) {
545  m_ESDigitizer->add(*esHandle.product(), bunchCrossing, engine);
546  } else {
547  m_ESOldDigitizer->add(*esHandle.product(), bunchCrossing, engine);
548  }
549  }
550 }
551 
552 void
554  // Step A: Get Inputs
555  edm::InputTag ebTag(m_hitsProducerTag, "EcalHitsEB");
557  e.getByLabel(ebTag, ebHandle);
558 
559  edm::InputTag eeTag(m_hitsProducerTag, "EcalHitsEE");
561  e.getByLabel(eeTag, eeHandle);
562 
563  edm::InputTag esTag(m_hitsProducerTag, "EcalHitsES");
565  e.getByLabel(esTag, esHandle);
566 
567  accumulateCaloHits(ebHandle, eeHandle, esHandle, 0, randomEngine(e.streamID()));
568 }
569 
570 void
572  // Step A: Get Inputs
573  edm::InputTag ebTag(m_hitsProducerTag, "EcalHitsEB");
575  e.getByLabel(ebTag, ebHandle);
576 
577  edm::InputTag eeTag(m_hitsProducerTag, "EcalHitsEE");
579  e.getByLabel(eeTag, eeHandle);
580 
581  edm::InputTag esTag(m_hitsProducerTag, "EcalHitsES");
583  e.getByLabel(esTag, esHandle);
584 
585  accumulateCaloHits(ebHandle, eeHandle, esHandle, e.bunchCrossing(), randomEngine(streamID));
586 }
587 
588 void
590  // Step B: Create empty output
591  std::unique_ptr<EBDigiCollection> apdResult ( !m_apdSeparateDigi || !m_doEB ? nullptr :
592  new EBDigiCollection() ) ;
593  std::unique_ptr<EBDigiCollection> barrelResult ( new EBDigiCollection() ) ;
594  std::unique_ptr<EEDigiCollection> endcapResult ( new EEDigiCollection() ) ;
595  std::unique_ptr<ESDigiCollection> preshowerResult( new ESDigiCollection() ) ;
596 
597  // run the algorithm
598 
599  if( m_doEB ) {
600  m_BarrelDigitizer->run( *barrelResult, randomEngine(event.streamID()) ) ;
601  cacheEBDigis( &*barrelResult ) ;
602 
603  edm::LogInfo("DigiInfo") << "EB Digis: " << barrelResult->size() ;
604 
605  if( m_apdSeparateDigi ) {
606  m_APDDigitizer->run( *apdResult, randomEngine(event.streamID()) ) ;
607  edm::LogInfo("DigiInfo") << "APD Digis: " << apdResult->size() ;
608  }
609  }
610 
611  if( m_doEE ) {
612  m_EndcapDigitizer->run( *endcapResult, randomEngine(event.streamID()) ) ;
613  edm::LogInfo("EcalDigi") << "EE Digis: " << endcapResult->size() ;
614  cacheEEDigis( &*endcapResult ) ;
615  }
616  if( m_doES ) {
617  if(m_doFastES) {
618  m_ESDigitizer->run( *preshowerResult, randomEngine(event.streamID()) ) ;
619  } else {
620  m_ESOldDigitizer->run( *preshowerResult, randomEngine(event.streamID()) ) ;
621  }
622  edm::LogInfo("EcalDigi") << "ES Digis: " << preshowerResult->size();
623  }
624 
625 
626  // Step D: Put outputs into event
627  if( m_apdSeparateDigi ) {
628  //event.put(std::move(apdResult), m_apdDigiTag ) ;
629  }
630 
631  event.put(std::move(barrelResult), m_EBdigiCollection ) ;
632  event.put(std::move(endcapResult), m_EEdigiCollection ) ;
633  event.put(std::move(preshowerResult), m_ESdigiCollection ) ;
634 }
635 
636 void
638 {
640  if ( ! rng.isAvailable() ) {
641  throw cms::Exception("Configuration") <<
642  "RandomNumberGenerator service is not available.\n"
643  "You must add the service in the configuration file\n"
644  "or remove the module that requires it.";
645  }
646  CLHEP::HepRandomEngine* engine = &rng->getEngine(lumi.index());
647 
648  if( m_doEB ) {
649  if( nullptr != m_APDResponse ) m_APDResponse->initialize(engine);
650  m_EBResponse->initialize(engine);
651  }
652 }
653 
654 void
656 {
657  // Pedestals from event setup
658 
660  eventSetup.get<EcalPedestalsRcd>().get( dbPed ) ;
661  const EcalPedestals* pedestals ( dbPed.product() ) ;
662 
663  m_Coder->setPedestals( pedestals ) ;
664  if( nullptr != m_APDCoder ) m_APDCoder->setPedestals( pedestals ) ;
665 
666  // Ecal Intercalibration Constants
668  eventSetup.get<EcalIntercalibConstantsMCRcd>().get( pIcal ) ;
669  const EcalIntercalibConstantsMC* ical ( pIcal.product() ) ;
670 
671  m_Coder->setIntercalibConstants( ical ) ;
672  if( nullptr != m_APDCoder) m_APDCoder->setIntercalibConstants( ical ) ;
673 
674  m_EBResponse->setIntercal( ical ) ;
675  if( nullptr != m_APDResponse ) m_APDResponse->setIntercal( ical ) ;
676 
677  // Ecal LaserCorrection Constants
679  eventSetup.get<EcalLaserDbRecord>().get(laser);
680  const edm::TimeValue_t eventTimeValue = event.time().value();
681 
682  m_EBResponse->setEventTime(eventTimeValue);
683  m_EBResponse->setLaserConstants(laser.product(), m_useLCcorrection);
684 
685  m_EEResponse->setEventTime(eventTimeValue);
686  m_EEResponse->setLaserConstants(laser.product(), m_useLCcorrection);
687 
688  // ADC -> GeV Scale
690  eventSetup.get<EcalADCToGeVConstantRcd>().get(pAgc);
691  const EcalADCToGeVConstant* agc = pAgc.product();
692 
693  // Gain Ratios
695  eventSetup.get<EcalGainRatiosRcd>().get(pRatio);
696  const EcalGainRatios* gr = pRatio.product();
697 
698  m_Coder->setGainRatios( gr );
699  if( nullptr != m_APDCoder) m_APDCoder->setGainRatios( gr );
700 
701  EcalMGPAGainRatio * defaultRatios = new EcalMGPAGainRatio();
702 
703  double theGains[m_Coder->NGAINS+1];
704  theGains[0] = 0.;
705  theGains[3] = 1.;
706  theGains[2] = defaultRatios->gain6Over1() ;
707  theGains[1] = theGains[2]*(defaultRatios->gain12Over6()) ;
708 
709  LogDebug("EcalDigi") << " Gains: " << "\n" << " g1 = " << theGains[1]
710  << "\n" << " g2 = " << theGains[2]
711  << "\n" << " g3 = " << theGains[3] ;
712 
713  delete defaultRatios;
714 
715  const double EBscale (
716  ( agc->getEBValue())*theGains[1]*(m_Coder->MAXADC)*m_EBs25notCont ) ;
717 
718  LogDebug("EcalDigi") << " GeV/ADC = " << agc->getEBValue()
719  << "\n" << " notCont = " << m_EBs25notCont
720  << "\n" << " saturation for EB = " << EBscale
721  << ", " << m_EBs25notCont ;
722 
723  const double EEscale (
724  (agc->getEEValue())*theGains[1]*(m_Coder->MAXADC)*m_EEs25notCont ) ;
725 
726  LogDebug("EcalDigi") << " GeV/ADC = " << agc->getEEValue()
727  << "\n" << " notCont = " << m_EEs25notCont
728  << "\n" << " saturation for EB = " << EEscale
729  << ", " << m_EEs25notCont ;
730 
731  m_Coder->setFullScaleEnergy( EBscale ,
732  EEscale ) ;
733  if( nullptr != m_APDCoder ) m_APDCoder->setFullScaleEnergy( EBscale ,
734  EEscale ) ;
735 
736  if( nullptr != m_ESOldDigitizer ||
737  nullptr != m_ESDigitizer )
738  {
739  // ES condition objects
740  edm::ESHandle<ESGain> hesgain ;
742  edm::ESHandle<ESPedestals> hesPedestals ;
744 
745  eventSetup.get<ESGainRcd>(). get( hesgain ) ;
746  eventSetup.get<ESMIPToGeVConstantRcd>(). get( hesMIPToGeV ) ;
747  eventSetup.get<ESPedestalsRcd>(). get( hesPedestals ) ;
748  eventSetup.get<ESIntercalibConstantsRcd>().get( hesMIPs ) ;
749 
750  const ESGain* esgain ( hesgain.product() ) ;
751  const ESPedestals* espeds ( hesPedestals.product() ) ;
752  const ESIntercalibConstants* esmips ( hesMIPs.product() ) ;
753  const ESMIPToGeVConstant* esMipToGeV ( hesMIPToGeV.product() ) ;
754  const int ESGain ( 1.1 > esgain->getESGain() ? 1 : 2 ) ;
755  const double ESMIPToGeV ( ( 1 == ESGain ) ?
756  esMipToGeV->getESValueLow() :
757  esMipToGeV->getESValueHigh() ) ;
758 
759  if( m_doES ) {
761  if( !m_doFastES )
762  {
763  m_ESElectronicsSim->setGain( ESGain ) ;
764  m_ESElectronicsSim->setPedestals( espeds ) ;
765  m_ESElectronicsSim->setMIPs( esmips ) ;
766  m_ESElectronicsSim->setMIPToGeV( ESMIPToGeV ) ;
767  }
768  else
769  {
770  m_ESDigitizer->setGain( ESGain ) ;
771  m_ESElectronicsSimFast->setPedestals( espeds ) ;
772  m_ESElectronicsSimFast->setMIPs( esmips ) ;
773  m_ESElectronicsSimFast->setMIPToGeV( ESMIPToGeV ) ;
774  }
775  }
776  }
777 }
778 
779 void
781 {
782  // TODO find a way to avoid doing this every event
783  edm::ESHandle<CaloGeometry> hGeometry ;
784  eventSetup.get<CaloGeometryRecord>().get( hGeometry ) ;
785 
786  const CaloGeometry* pGeometry = &*hGeometry;
787 
788  if( pGeometry != m_Geometry )
789  {
790  m_Geometry = pGeometry;
791  updateGeometry();
792  }
793 }
794 
795 void
797 {
798  if( m_doEB ) {
799  if( nullptr != m_APDResponse ) m_APDResponse->setGeometry(
801  m_EBResponse->setGeometry(
803  }
804  if( m_doEE ) {
805  m_EEResponse->setGeometry(
807  }
808  if( m_doES ) {
809  m_ESResponse->setGeometry(
811  m_ESOldResponse->setGeometry( m_Geometry ) ;
812 
813  const std::vector<DetId>* theESDets (
816 
817  if( !m_doFastES )
818  {
819  if( nullptr != m_ESOldDigitizer &&
820  nullptr != theESDets )
821  m_ESOldDigitizer->setDetIds( *theESDets ) ;
822  }
823  else
824  {
825  if( nullptr != m_ESDigitizer &&
826  nullptr != theESDets )
827  m_ESDigitizer->setDetIds( *theESDets ) ;
828  }
829  }
830 }
831 
832 CLHEP::HepRandomEngine* EcalDigiProducer::randomEngine(edm::StreamID const& streamID) {
833  unsigned int index = streamID.value();
834  if(index >= randomEngines_.size()) {
835  randomEngines_.resize(index + 1, nullptr);
836  }
837  CLHEP::HepRandomEngine* ptr = randomEngines_[index];
838  if(!ptr) {
840  ptr = &rng->getEngine(streamID);
841  randomEngines_[index] = ptr;
842  }
843  return ptr;
844 }
845 
847  //noiseGenerator->setParameterMap(theParameterMap);
848  if(nullptr != m_BarrelDigitizer) m_BarrelDigitizer->setNoiseSignalGenerator(noiseGenerator);
849 }
850 
852  //noiseGenerator->setParameterMap(theParameterMap);
853  if(nullptr != m_EndcapDigitizer) m_EndcapDigitizer->setNoiseSignalGenerator(noiseGenerator);
854 }
855 
857  //noiseGenerator->setParameterMap(theParameterMap);
858  if(nullptr != m_ESDigitizer) m_ESDigitizer->setNoiseSignalGenerator(noiseGenerator);
859 }
860 
861 
#define LogDebug(id)
std::unique_ptr< EcalCoder > m_APDCoder
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:45
adds noise to the given frame.
Definition: EcalCoder.h:11
virtual ~EcalDigiProducer()
EcalTDigitizer< EEDigitizerTraits > EEDigitizer
std::unique_ptr< ESDigitizer > m_ESDigitizer
edm::Service< edm::RandomNumberGenerator > rng
LuminosityBlockIndex index() const
const std::string m_ESdigiCollection
std::unique_ptr< EEDigitizer > m_EndcapDigitizer
Definition: ESGain.h:7
void setGain(const int gain)
Definition: ESShape.h:26
std::unique_ptr< EBHitResponse > m_APDResponse
tuple lumi
Definition: fjr2json.py:35
const std::string m_hitsProducerTag
assert(m_qm.get())
std::unique_ptr< EcalCoder > m_Coder
#define nullptr
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
const std::string m_EEdigiCollection
std::unique_ptr< ESHitResponse > m_ESResponse
virtual const std::vector< DetId > & getValidDetIds(DetId::Detector det=DetId::Detector(0), int subdet=0) const
Get a list of valid detector ids (for the given subdetector)
void setEENoiseSignalGenerator(EcalBaseSignalGenerator *noiseGenerator)
virtual void initializeEvent(edm::Event const &e, edm::EventSetup const &c) override
void setEBNoiseSignalGenerator(EcalBaseSignalGenerator *noiseGenerator)
void setESNoiseSignalGenerator(EcalBaseSignalGenerator *noiseGenerator)
virtual void accumulate(edm::Event const &e, edm::EventSetup const &c) override
Creates electronics signals from hits.
const double m_EBs25notCont
def move
Definition: eostools.py:510
bool isAvailable() const
Definition: Service.h:46
std::unique_ptr< CaloHitResponse > m_ESOldResponse
virtual void beginLuminosityBlock(edm::LuminosityBlock const &lumi, edm::EventSetup const &setup) override
EcalDigiProducer(const edm::ParameterSet &params, edm::stream::EDProducerBase &mixMod, edm::ConsumesCollector &iC)
float gain6Over1() const
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
math::ErrorD< CaloSamples::MAXSAMPLES >::type EcalCorrMatrix
bool isValid() const
Definition: HandleBase.h:75
unsigned long long TimeValue_t
Definition: Timestamp.h:28
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:413
const CaloGeometry * m_Geometry
void checkCalibrations(const edm::Event &event, const edm::EventSetup &eventSetup)
void checkGeometry(const edm::EventSetup &eventSetup)
std::unique_ptr< EBDigitizer > m_BarrelDigitizer
std::unique_ptr< ESElectronicsSimFast > m_ESElectronicsSimFast
unsigned int value() const
Definition: StreamID.h:46
T const * product() const
Definition: Handle.h:81
virtual void cacheEBDigis(const EBDigiCollection *ebDigiPtr) const
std::unique_ptr< EEHitResponse > m_EEResponse
EcalTDigitizer< EBDigitizerTraits > EBDigitizer
const T & get() const
Definition: EventSetup.h:56
T const * product() const
Definition: ESHandle.h:86
m_EECorrNoise({{0, 0, 0}})
float gain12Over6() const
const bool m_apdSeparateDigi
CLHEP::HepRandomEngine * randomEngine(edm::StreamID const &streamID)
void accumulateCaloHits(HitsHandle const &ebHandle, HitsHandle const &eeHandle, HitsHandle const &esHandle, int bunchCrossing, CLHEP::HepRandomEngine *)
std::unique_ptr< ESElectronicsSim > m_ESElectronicsSim
bool getByLabel(edm::InputTag const &tag, edm::Handle< T > &result) const
StreamID streamID() const
Definition: Event.h:81
std::unique_ptr< EBHitResponse > m_EBResponse
std::unique_ptr< ESOldDigitizer > m_ESOldDigitizer
std::vector< CLHEP::HepRandomEngine * > randomEngines_
volatile std::atomic< bool > shutdown_flag false
virtual void cacheEEDigis(const EEDigiCollection *eeDigiPtr) const
const std::string m_EBdigiCollection
std::unique_ptr< EBDigitizer > m_APDDigitizer
virtual void finalizeEvent(edm::Event &e, edm::EventSetup const &c) override
T get(const Candidate &c)
Definition: component.h:55
const double m_EEs25notCont