test
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_EBCorrNoise[0].get() ,
250  m_EECorrNoise[0].get() ,
251  m_EBCorrNoise[1].get() ,
252  m_EECorrNoise[1].get() ,
253  m_EBCorrNoise[2].get() ,
254  m_EECorrNoise[2].get() ) );
255 
256  m_APDElectronicsSim.reset( new EcalElectronicsSim( m_ParameterMap.get() ,
257  m_APDCoder.get() ,
258  applyConstantTerm ,
259  rmsConstantTerm ) );
260 
261  m_APDDigitizer.reset( new EBDigitizer( m_APDResponse.get() ,
262  m_APDElectronicsSim.get() ,
263  false ) );
264  }
265 
266  if( m_doEB ) {
267  m_BarrelDigitizer.reset( new EBDigitizer( m_EBResponse.get() ,
268  m_ElectronicsSim.get() ,
269  addNoise ) );
270  }
271 
272  if ( m_doEE ) {
273  m_EndcapDigitizer.reset( new EEDigitizer( m_EEResponse.get() ,
274  m_ElectronicsSim.get() ,
275  addNoise ) );
276  }
277 }
278 
279 
280 // duplicate version for Pre-Mixing, for use outside of MixingModule
283  m_APDShape ( params.getParameter<double>( "apdShapeTstart" ) ,
284  params.getParameter<double>( "apdShapeTau" ) ) ,
285  m_EBShape ( ) ,
286  m_EEShape ( ) ,
287  m_ESShape ( ) ,
288  m_EBdigiCollection ( params.getParameter<std::string>("EBdigiCollection") ) ,
289  m_EEdigiCollection ( params.getParameter<std::string>("EEdigiCollection") ) ,
290  m_ESdigiCollection ( params.getParameter<std::string>("ESdigiCollection") ) ,
291  m_hitsProducerTag ( params.getParameter<std::string>("hitsProducer" ) ) ,
292  m_useLCcorrection ( params.getUntrackedParameter<bool>("UseLCcorrection") ) ,
293  m_apdSeparateDigi ( params.getParameter<bool> ("apdSeparateDigi") ) ,
294 
295  m_EBs25notCont ( params.getParameter<double> ("EBs25notContainment") ) ,
296  m_EEs25notCont ( params.getParameter<double> ("EEs25notContainment") ) ,
297 
298  m_readoutFrameSize ( params.getParameter<int> ("readoutFrameSize") ) ,
299  m_ParameterMap ( new EcalSimParameterMap(
300  params.getParameter<double> ("simHitToPhotoelectronsBarrel") ,
301  params.getParameter<double> ("simHitToPhotoelectronsEndcap") ,
302  params.getParameter<double> ("photoelectronsToAnalogBarrel") ,
303  params.getParameter<double> ("photoelectronsToAnalogEndcap") ,
304  params.getParameter<double> ("samplingFactor") ,
305  params.getParameter<double> ("timePhase") ,
306  m_readoutFrameSize ,
307  params.getParameter<int> ("binOfMaximum") ,
308  params.getParameter<bool> ("doPhotostatistics") ,
309  params.getParameter<bool> ("syncPhase") ) ) ,
310 
311  m_apdDigiTag ( params.getParameter<std::string> ("apdDigiTag" ) ) ,
312  m_apdParameters ( new APDSimParameters(
313  params.getParameter<bool> ("apdAddToBarrel" ) ,
314  m_apdSeparateDigi ,
315  params.getParameter<double> ("apdSimToPELow" ) ,
316  params.getParameter<double> ("apdSimToPEHigh" ) ,
317  params.getParameter<double> ("apdTimeOffset" ) ,
318  params.getParameter<double> ("apdTimeOffWidth" ) ,
319  params.getParameter<bool> ("apdDoPEStats" ) ,
320  m_apdDigiTag ,
321  params.getParameter<std::vector<double> > ( "apdNonlParms" ) ) ) ,
322 
323  m_APDResponse ( !m_apdSeparateDigi ? nullptr :
324  new EBHitResponse( m_ParameterMap.get() ,
325  &m_EBShape ,
326  true ,
327  m_apdParameters.get() ,
328  &m_APDShape ) ) ,
329 
330  m_EBResponse ( new EBHitResponse( m_ParameterMap.get() ,
331  &m_EBShape ,
332  false , // barrel
333  m_apdParameters.get() ,
334  &m_APDShape ) ) ,
335 
336  m_EEResponse ( new EEHitResponse( m_ParameterMap.get(),
337  &m_EEShape ) ) ,
338  m_ESResponse ( new ESHitResponse( m_ParameterMap.get(), &m_ESShape ) ) ,
339  m_ESOldResponse ( new CaloHitResponse( m_ParameterMap.get(), &m_ESShape ) ) ,
340 
341  m_addESNoise ( params.getParameter<bool> ("doESNoise") ) ,
342  m_PreMix1 ( params.getParameter<bool> ("EcalPreMixStage1") ) ,
343  m_PreMix2 ( params.getParameter<bool> ("EcalPreMixStage2") ) ,
344 
345  m_doFastES ( params.getParameter<bool> ("doFast" ) ) ,
346 
347  m_doEB ( params.getParameter<bool> ("doEB" ) ) ,
348  m_doEE ( params.getParameter<bool> ("doEE" ) ) ,
349  m_doES ( params.getParameter<bool> ("doES" ) ) ,
350 
351  m_ESElectronicsSim ( m_doFastES ? nullptr :
352  new ESElectronicsSim( m_addESNoise ) ) ,
353 
354  m_ESOldDigitizer ( m_doFastES ? nullptr :
355  new ESOldDigitizer( m_ESOldResponse.get() ,
356  m_ESElectronicsSim.get() ,
357  m_addESNoise ) ) ,
358 
359  m_ESElectronicsSimFast ( !m_doFastES ? nullptr :
360  new ESElectronicsSimFast( m_addESNoise,
361  m_PreMix1 ) ) ,
362 
363  m_ESDigitizer ( !m_doFastES ? nullptr :
364  new ESDigitizer( m_ESResponse.get() ,
365  m_ESElectronicsSimFast.get() ,
366  m_addESNoise ) ) ,
367 
368  m_APDDigitizer ( nullptr ) ,
369  m_BarrelDigitizer ( nullptr ) ,
370  m_EndcapDigitizer ( nullptr ) ,
371  m_ElectronicsSim ( nullptr ) ,
372  m_Coder ( nullptr ) ,
373  m_APDElectronicsSim ( nullptr ) ,
374  m_APDCoder ( nullptr ) ,
375  m_Geometry ( nullptr ) ,
376  m_EBCorrNoise ( { {nullptr, nullptr, nullptr} } ) ,
377  m_EECorrNoise ( { {nullptr, nullptr, nullptr} } )
378 {
379  // "produces" statements taken care of elsewhere.
380  // if(m_apdSeparateDigi) mixMod.produces<EBDigiCollection>(m_apdDigiTag);
381  // mixMod.produces<EBDigiCollection>(m_EBdigiCollection);
382  // mixMod.produces<EEDigiCollection>(m_EEdigiCollection);
383  // mixMod.produces<ESDigiCollection>(m_ESdigiCollection);
384  if ( m_doEB ) iC.consumes<std::vector<PCaloHit> >(edm::InputTag(m_hitsProducerTag, "EcalHitsEB"));
385  if ( m_doEE ) iC.consumes<std::vector<PCaloHit> >(edm::InputTag(m_hitsProducerTag, "EcalHitsEE"));
386  if ( m_doES ) iC.consumes<std::vector<PCaloHit> >(edm::InputTag(m_hitsProducerTag, "EcalHitsES"));
387 
388  const std::vector<double> ebCorMatG12 = params.getParameter< std::vector<double> >("EBCorrNoiseMatrixG12");
389  const std::vector<double> eeCorMatG12 = params.getParameter< std::vector<double> >("EECorrNoiseMatrixG12");
390  const std::vector<double> ebCorMatG06 = params.getParameter< std::vector<double> >("EBCorrNoiseMatrixG06");
391  const std::vector<double> eeCorMatG06 = params.getParameter< std::vector<double> >("EECorrNoiseMatrixG06");
392  const std::vector<double> ebCorMatG01 = params.getParameter< std::vector<double> >("EBCorrNoiseMatrixG01");
393  const std::vector<double> eeCorMatG01 = params.getParameter< std::vector<double> >("EECorrNoiseMatrixG01");
394 
395  const bool applyConstantTerm = params.getParameter<bool> ("applyConstantTerm");
396  const double rmsConstantTerm = params.getParameter<double> ("ConstantTerm");
397 
398  const bool addNoise = params.getParameter<bool> ("doENoise");
399  const bool cosmicsPhase = params.getParameter<bool> ("cosmicsPhase");
400  const double cosmicsShift = params.getParameter<double> ("cosmicsShift");
401 
402 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
403 
404  // further phase for cosmics studies
405  if( cosmicsPhase )
406  {
407  if( m_doEB ) m_EBResponse->setPhaseShift( 1. + cosmicsShift ) ;
408  if( m_doEE ) m_EEResponse->setPhaseShift( 1. + cosmicsShift ) ;
409  }
410 
411  EcalCorrMatrix ebMatrix[ 3 ] ;
412  EcalCorrMatrix eeMatrix[ 3 ] ;
413 
414  assert( ebCorMatG12.size() == m_readoutFrameSize ) ;
415  assert( eeCorMatG12.size() == m_readoutFrameSize ) ;
416  assert( ebCorMatG06.size() == m_readoutFrameSize ) ;
417  assert( eeCorMatG06.size() == m_readoutFrameSize ) ;
418  assert( ebCorMatG01.size() == m_readoutFrameSize ) ;
419  assert( eeCorMatG01.size() == m_readoutFrameSize ) ;
420 
421  assert( 1.e-7 > fabs( ebCorMatG12[0] - 1.0 ) ) ;
422  assert( 1.e-7 > fabs( ebCorMatG06[0] - 1.0 ) ) ;
423  assert( 1.e-7 > fabs( ebCorMatG01[0] - 1.0 ) ) ;
424  assert( 1.e-7 > fabs( eeCorMatG12[0] - 1.0 ) ) ;
425  assert( 1.e-7 > fabs( eeCorMatG06[0] - 1.0 ) ) ;
426  assert( 1.e-7 > fabs( eeCorMatG01[0] - 1.0 ) ) ;
427 
428  for ( unsigned int row ( 0 ) ; row != m_readoutFrameSize ; ++row )
429  {
430  assert( 0 == row || 1. >= ebCorMatG12[row] ) ;
431  assert( 0 == row || 1. >= ebCorMatG06[row] ) ;
432  assert( 0 == row || 1. >= ebCorMatG01[row] ) ;
433  assert( 0 == row || 1. >= eeCorMatG12[row] ) ;
434  assert( 0 == row || 1. >= eeCorMatG06[row] ) ;
435  assert( 0 == row || 1. >= eeCorMatG01[row] ) ;
436  for ( unsigned int column ( 0 ) ; column <= row ; ++column )
437  {
438  const unsigned int index ( row - column ) ;
439  ebMatrix[0]( row, column ) = ebCorMatG12[ index ] ;
440  eeMatrix[0]( row, column ) = eeCorMatG12[ index ] ;
441  ebMatrix[1]( row, column ) = ebCorMatG06[ index ] ;
442  eeMatrix[1]( row, column ) = eeCorMatG06[ index ] ;
443  ebMatrix[2]( row, column ) = ebCorMatG01[ index ] ;
444  eeMatrix[2]( row, column ) = eeCorMatG01[ index ] ;
445  }
446  }
447 
448  m_EBCorrNoise[0].reset( new CorrelatedNoisifier<EcalCorrMatrix>( ebMatrix[0] ) );
449  m_EECorrNoise[0].reset( new CorrelatedNoisifier<EcalCorrMatrix>( eeMatrix[0] ) );
450  m_EBCorrNoise[1].reset( new CorrelatedNoisifier<EcalCorrMatrix>( ebMatrix[1] ) );
451  m_EECorrNoise[1].reset( new CorrelatedNoisifier<EcalCorrMatrix>( eeMatrix[1] ) );
452  m_EBCorrNoise[2].reset( new CorrelatedNoisifier<EcalCorrMatrix>( ebMatrix[2] ) );
453  m_EECorrNoise[2].reset( new CorrelatedNoisifier<EcalCorrMatrix>( eeMatrix[2] ) );
454 
455  m_Coder.reset( new EcalCoder( addNoise ,
456  m_PreMix1 ,
457  m_EBCorrNoise[0].get() ,
458  m_EECorrNoise[0].get() ,
459  m_EBCorrNoise[1].get() ,
460  m_EECorrNoise[1].get() ,
461  m_EBCorrNoise[2].get() ,
462  m_EECorrNoise[2].get() ) );
463 
464  m_ElectronicsSim.reset( new EcalElectronicsSim( m_ParameterMap.get() ,
465  m_Coder.get() ,
466  applyConstantTerm ,
467  rmsConstantTerm ) );
468 
469  if( m_apdSeparateDigi )
470  {
471  m_APDCoder.reset( new EcalCoder( false ,
472  m_EBCorrNoise[0].get() ,
473  m_EECorrNoise[0].get() ,
474  m_EBCorrNoise[1].get() ,
475  m_EECorrNoise[1].get() ,
476  m_EBCorrNoise[2].get() ,
477  m_EECorrNoise[2].get() ) );
478 
479  m_APDElectronicsSim.reset( new EcalElectronicsSim( m_ParameterMap.get() ,
480  m_APDCoder.get() ,
481  applyConstantTerm ,
482  rmsConstantTerm ) );
483 
484  m_APDDigitizer.reset( new EBDigitizer( m_APDResponse.get() ,
485  m_APDElectronicsSim.get() ,
486  false ) );
487  }
488 
489  if( m_doEB ) {
490  m_BarrelDigitizer.reset( new EBDigitizer( m_EBResponse.get() ,
491  m_ElectronicsSim.get() ,
492  addNoise ) );
493  }
494 
495  if( m_doEE ) {
496  m_EndcapDigitizer.reset( new EEDigitizer( m_EEResponse.get() ,
497  m_ElectronicsSim.get() ,
498  addNoise ) );
499  }
500 }
501 
502 
504 {}
505 
506 void
508  checkGeometry( eventSetup );
509  checkCalibrations( event, eventSetup );
510  if( m_doEB ) {
511  m_BarrelDigitizer->initializeHits();
512  if(m_apdSeparateDigi) {
513  m_APDDigitizer->initializeHits();
514  }
515  }
516  if( m_doEE ) {
517  m_EndcapDigitizer->initializeHits();
518  }
519  if( m_doES ) {
520  if(m_doFastES) {
521  m_ESDigitizer->initializeHits();
522  } else {
523  m_ESOldDigitizer->initializeHits();
524  }
525  }
526 }
527 
528 void
529 EcalDigiProducer::accumulateCaloHits(HitsHandle const& ebHandle, HitsHandle const& eeHandle, HitsHandle const& esHandle, int bunchCrossing, CLHEP::HepRandomEngine* engine) {
530  if(m_doEB && ebHandle.isValid()) {
531  m_BarrelDigitizer->add(*ebHandle.product(), bunchCrossing, engine);
532 
533  if(m_apdSeparateDigi) {
534  m_APDDigitizer->add(*ebHandle.product(), bunchCrossing, engine);
535  }
536  }
537 
538  if(m_doEE && eeHandle.isValid()) {
539  m_EndcapDigitizer->add(*eeHandle.product(), bunchCrossing, engine);
540  }
541 
542  if(m_doES && esHandle.isValid()) {
543  if(m_doFastES) {
544  m_ESDigitizer->add(*esHandle.product(), bunchCrossing, engine);
545  } else {
546  m_ESOldDigitizer->add(*esHandle.product(), bunchCrossing, engine);
547  }
548  }
549 }
550 
551 void
553  // Step A: Get Inputs
554  edm::InputTag ebTag(m_hitsProducerTag, "EcalHitsEB");
556  e.getByLabel(ebTag, ebHandle);
557 
558  edm::InputTag eeTag(m_hitsProducerTag, "EcalHitsEE");
560  e.getByLabel(eeTag, eeHandle);
561 
562  edm::InputTag esTag(m_hitsProducerTag, "EcalHitsES");
564  e.getByLabel(esTag, esHandle);
565 
566  accumulateCaloHits(ebHandle, eeHandle, esHandle, 0, randomEngine(e.streamID()));
567 }
568 
569 void
571  // Step A: Get Inputs
572  edm::InputTag ebTag(m_hitsProducerTag, "EcalHitsEB");
574  e.getByLabel(ebTag, ebHandle);
575 
576  edm::InputTag eeTag(m_hitsProducerTag, "EcalHitsEE");
578  e.getByLabel(eeTag, eeHandle);
579 
580  edm::InputTag esTag(m_hitsProducerTag, "EcalHitsES");
582  e.getByLabel(esTag, esHandle);
583 
584  accumulateCaloHits(ebHandle, eeHandle, esHandle, e.bunchCrossing(), randomEngine(streamID));
585 }
586 
587 void
589  // Step B: Create empty output
590  std::unique_ptr<EBDigiCollection> apdResult ( !m_apdSeparateDigi || !m_doEB ? nullptr :
591  new EBDigiCollection() ) ;
592  std::unique_ptr<EBDigiCollection> barrelResult ( new EBDigiCollection() ) ;
593  std::unique_ptr<EEDigiCollection> endcapResult ( new EEDigiCollection() ) ;
594  std::unique_ptr<ESDigiCollection> preshowerResult( new ESDigiCollection() ) ;
595 
596  // run the algorithm
597 
598  if( m_doEB ) {
599  m_BarrelDigitizer->run( *barrelResult, randomEngine(event.streamID()) ) ;
600  cacheEBDigis( &*barrelResult ) ;
601 
602  edm::LogInfo("DigiInfo") << "EB Digis: " << barrelResult->size() ;
603 
604  if( m_apdSeparateDigi ) {
605  m_APDDigitizer->run( *apdResult, randomEngine(event.streamID()) ) ;
606  edm::LogInfo("DigiInfo") << "APD Digis: " << apdResult->size() ;
607  }
608  }
609 
610  if( m_doEE ) {
611  m_EndcapDigitizer->run( *endcapResult, randomEngine(event.streamID()) ) ;
612  edm::LogInfo("EcalDigi") << "EE Digis: " << endcapResult->size() ;
613  cacheEEDigis( &*endcapResult ) ;
614  }
615  if( m_doES ) {
616  if(m_doFastES) {
617  m_ESDigitizer->run( *preshowerResult, randomEngine(event.streamID()) ) ;
618  } else {
619  m_ESOldDigitizer->run( *preshowerResult, randomEngine(event.streamID()) ) ;
620  }
621  edm::LogInfo("EcalDigi") << "ES Digis: " << preshowerResult->size();
622  }
623 
624 
625  // Step D: Put outputs into event
626  if( m_apdSeparateDigi ) {
627  //event.put(std::move(apdResult), m_apdDigiTag ) ;
628  }
629 
630  event.put(std::move(barrelResult), m_EBdigiCollection ) ;
631  event.put(std::move(endcapResult), m_EEdigiCollection ) ;
632  event.put(std::move(preshowerResult), m_ESdigiCollection ) ;
633 }
634 
635 void
637 {
639  if ( ! rng.isAvailable() ) {
640  throw cms::Exception("Configuration") <<
641  "RandomNumberGenerator service is not available.\n"
642  "You must add the service in the configuration file\n"
643  "or remove the module that requires it.";
644  }
645  CLHEP::HepRandomEngine* engine = &rng->getEngine(lumi.index());
646 
647  if( m_doEB ) {
648  if( nullptr != m_APDResponse ) m_APDResponse->initialize(engine);
649  m_EBResponse->initialize(engine);
650  }
651 }
652 
653 void
655 {
656  // Pedestals from event setup
657 
659  eventSetup.get<EcalPedestalsRcd>().get( dbPed ) ;
660  const EcalPedestals* pedestals ( dbPed.product() ) ;
661 
662  m_Coder->setPedestals( pedestals ) ;
663  if( nullptr != m_APDCoder ) m_APDCoder->setPedestals( pedestals ) ;
664 
665  // Ecal Intercalibration Constants
667  eventSetup.get<EcalIntercalibConstantsMCRcd>().get( pIcal ) ;
668  const EcalIntercalibConstantsMC* ical ( pIcal.product() ) ;
669 
670  m_Coder->setIntercalibConstants( ical ) ;
671  if( nullptr != m_APDCoder) m_APDCoder->setIntercalibConstants( ical ) ;
672 
673  m_EBResponse->setIntercal( ical ) ;
674  if( nullptr != m_APDResponse ) m_APDResponse->setIntercal( ical ) ;
675 
676  // Ecal LaserCorrection Constants
678  eventSetup.get<EcalLaserDbRecord>().get(laser);
679  const edm::TimeValue_t eventTimeValue = event.time().value();
680 
681  m_EBResponse->setEventTime(eventTimeValue);
682  m_EBResponse->setLaserConstants(laser.product(), m_useLCcorrection);
683 
684  m_EEResponse->setEventTime(eventTimeValue);
685  m_EEResponse->setLaserConstants(laser.product(), m_useLCcorrection);
686 
687  // ADC -> GeV Scale
689  eventSetup.get<EcalADCToGeVConstantRcd>().get(pAgc);
690  const EcalADCToGeVConstant* agc = pAgc.product();
691 
692  // Gain Ratios
694  eventSetup.get<EcalGainRatiosRcd>().get(pRatio);
695  const EcalGainRatios* gr = pRatio.product();
696 
697  m_Coder->setGainRatios( gr );
698  if( nullptr != m_APDCoder) m_APDCoder->setGainRatios( gr );
699 
700  EcalMGPAGainRatio * defaultRatios = new EcalMGPAGainRatio();
701 
702  double theGains[m_Coder->NGAINS+1];
703  theGains[0] = 0.;
704  theGains[3] = 1.;
705  theGains[2] = defaultRatios->gain6Over1() ;
706  theGains[1] = theGains[2]*(defaultRatios->gain12Over6()) ;
707 
708  LogDebug("EcalDigi") << " Gains: " << "\n" << " g1 = " << theGains[1]
709  << "\n" << " g2 = " << theGains[2]
710  << "\n" << " g3 = " << theGains[3] ;
711 
712  delete defaultRatios;
713 
714  const double EBscale (
715  ( agc->getEBValue())*theGains[1]*(m_Coder->MAXADC)*m_EBs25notCont ) ;
716 
717  LogDebug("EcalDigi") << " GeV/ADC = " << agc->getEBValue()
718  << "\n" << " notCont = " << m_EBs25notCont
719  << "\n" << " saturation for EB = " << EBscale
720  << ", " << m_EBs25notCont ;
721 
722  const double EEscale (
723  (agc->getEEValue())*theGains[1]*(m_Coder->MAXADC)*m_EEs25notCont ) ;
724 
725  LogDebug("EcalDigi") << " GeV/ADC = " << agc->getEEValue()
726  << "\n" << " notCont = " << m_EEs25notCont
727  << "\n" << " saturation for EB = " << EEscale
728  << ", " << m_EEs25notCont ;
729 
730  m_Coder->setFullScaleEnergy( EBscale ,
731  EEscale ) ;
732  if( nullptr != m_APDCoder ) m_APDCoder->setFullScaleEnergy( EBscale ,
733  EEscale ) ;
734 
735  if( nullptr != m_ESOldDigitizer ||
736  nullptr != m_ESDigitizer )
737  {
738  // ES condition objects
739  edm::ESHandle<ESGain> hesgain ;
741  edm::ESHandle<ESPedestals> hesPedestals ;
743 
744  eventSetup.get<ESGainRcd>(). get( hesgain ) ;
745  eventSetup.get<ESMIPToGeVConstantRcd>(). get( hesMIPToGeV ) ;
746  eventSetup.get<ESPedestalsRcd>(). get( hesPedestals ) ;
747  eventSetup.get<ESIntercalibConstantsRcd>().get( hesMIPs ) ;
748 
749  const ESGain* esgain ( hesgain.product() ) ;
750  const ESPedestals* espeds ( hesPedestals.product() ) ;
751  const ESIntercalibConstants* esmips ( hesMIPs.product() ) ;
752  const ESMIPToGeVConstant* esMipToGeV ( hesMIPToGeV.product() ) ;
753  const int ESGain ( 1.1 > esgain->getESGain() ? 1 : 2 ) ;
754  const double ESMIPToGeV ( ( 1 == ESGain ) ?
755  esMipToGeV->getESValueLow() :
756  esMipToGeV->getESValueHigh() ) ;
757 
758  if( m_doES ) {
760  if( !m_doFastES )
761  {
762  m_ESElectronicsSim->setGain( ESGain ) ;
763  m_ESElectronicsSim->setPedestals( espeds ) ;
764  m_ESElectronicsSim->setMIPs( esmips ) ;
765  m_ESElectronicsSim->setMIPToGeV( ESMIPToGeV ) ;
766  }
767  else
768  {
769  m_ESDigitizer->setGain( ESGain ) ;
770  m_ESElectronicsSimFast->setPedestals( espeds ) ;
771  m_ESElectronicsSimFast->setMIPs( esmips ) ;
772  m_ESElectronicsSimFast->setMIPToGeV( ESMIPToGeV ) ;
773  }
774  }
775  }
776 }
777 
778 void
780 {
781  // TODO find a way to avoid doing this every event
782  edm::ESHandle<CaloGeometry> hGeometry ;
783  eventSetup.get<CaloGeometryRecord>().get( hGeometry ) ;
784 
785  const CaloGeometry* pGeometry = &*hGeometry;
786 
787  if( pGeometry != m_Geometry )
788  {
789  m_Geometry = pGeometry;
790  updateGeometry();
791  }
792 }
793 
794 void
796 {
797  if( m_doEB ) {
798  if( nullptr != m_APDResponse ) m_APDResponse->setGeometry(
800  m_EBResponse->setGeometry(
802  }
803  if( m_doEE ) {
804  m_EEResponse->setGeometry(
806  }
807  if( m_doES ) {
808  m_ESResponse->setGeometry(
810  m_ESOldResponse->setGeometry( m_Geometry ) ;
811 
812  const std::vector<DetId>* theESDets (
815 
816  if( !m_doFastES )
817  {
818  if( nullptr != m_ESOldDigitizer &&
819  nullptr != theESDets )
820  m_ESOldDigitizer->setDetIds( *theESDets ) ;
821  }
822  else
823  {
824  if( nullptr != m_ESDigitizer &&
825  nullptr != theESDets )
826  m_ESDigitizer->setDetIds( *theESDets ) ;
827  }
828  }
829 }
830 
831 CLHEP::HepRandomEngine* EcalDigiProducer::randomEngine(edm::StreamID const& streamID) {
832  unsigned int index = streamID.value();
833  if(index >= randomEngines_.size()) {
834  randomEngines_.resize(index + 1, nullptr);
835  }
836  CLHEP::HepRandomEngine* ptr = randomEngines_[index];
837  if(!ptr) {
839  ptr = &rng->getEngine(streamID);
840  randomEngines_[index] = ptr;
841  }
842  return ptr;
843 }
844 
846  //noiseGenerator->setParameterMap(theParameterMap);
847  if(nullptr != m_BarrelDigitizer) m_BarrelDigitizer->setNoiseSignalGenerator(noiseGenerator);
848 }
849 
851  //noiseGenerator->setParameterMap(theParameterMap);
852  if(nullptr != m_EndcapDigitizer) m_EndcapDigitizer->setNoiseSignalGenerator(noiseGenerator);
853 }
854 
856  //noiseGenerator->setParameterMap(theParameterMap);
857  if(nullptr != m_ESDigitizer) m_ESDigitizer->setNoiseSignalGenerator(noiseGenerator);
858 }
859 
860 
#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