CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ESElectronicsSimFast.cc
Go to the documentation of this file.
3 
6 #include "CLHEP/Random/RandGaussQ.h"
8 
9 #include <iostream>
10 
11 ESElectronicsSimFast::ESElectronicsSimFast( bool addNoise , bool PreMix1 ) :
12  m_addNoise ( addNoise ) ,
13  m_PreMix1 ( PreMix1 ) ,
14  m_MIPToGeV ( 0 ) ,
15  m_peds ( 0 ) ,
16  m_mips ( 0 ) ,
17  m_ranGau ( 0 )
18 {
19  // Preshower "Fast" Electronics Simulation
20  // gain = 1 : low gain for data taking
21  // gain = 2 : high gain for calibration and low energy runs
22  // For 300(310/320) um Si, the MIP is 78.47(81.08/83.7) keV
23 
24  if( m_addNoise )
25  {
27  if( !rng.isAvailable() )
28  {
29  throw cms::Exception("Configuration")
30  << "ESElectroncSimFast requires the RandomNumberGeneratorService\n"
31  "which is not present in the configuration file. You must add the service\n"
32  "in the configuration file or remove the modules that require it.";
33  }
34  m_ranGau = new CLHEP::RandGaussQ( rng->getEngine(), 0, 1 ) ;
35  }
36 }
37 
39 {
40  delete m_ranGau ;
41 }
42 
43 void
45 {
46  m_peds = peds ;
47 }
48 
49 void
51 {
52  m_mips = mips ;
53 }
54 
55 void
57 {
58  m_MIPToGeV = MIPToGeV ;
59 }
60 
61 void
63  ESDataFrame& df,
64  bool isNoise ) const
65 {
66  assert( 0 != m_peds &&
67  0 != m_mips &&
68  0 < m_MIPToGeV ) ; // sanity check
69 
70  assert( ( !m_addNoise ) ||
71  0 != m_ranGau ) ; // sanity check
72 
73  df.setSize( cs.size() ) ;
74 
75  const DetId id ( cs.id() ) ;
76  ESPedestals::const_iterator it_ped ( m_peds->find( id ) ) ;
78  isNoise ? m_mips->getMap().end() : m_mips->getMap().find( id ) ) ;
79 
80  const double baseline ( (double) it_ped->getMean() ) ;
81  const double sigma ( isNoise ? 0. : (double) it_ped->getRms() ) ;
82  const double MIPADC ( isNoise ? 0. : (double) (*it_mip) ) ;
83  const double ADCGeV ( isNoise ? 1. : MIPADC/m_MIPToGeV ) ;
84 
85  int adc = 0 ;
86 // std::cout<<" **Id="<<ESDetId(df.id())<<", size="<<df.size();
87  for( unsigned int i ( 0 ) ; i != cs.size(); ++i )
88  {
89  const double noi ( isNoise || (!m_addNoise) ? 0 :
90  sigma*m_ranGau->fire() ) ;
91  double signal;
92 
93  if(!m_PreMix1) signal = cs[i]*ADCGeV + noi + baseline ;
94  else signal = cs[i]*ADCGeV ;
95 
96  if( 0 <= signal )
97  {
98  signal += 0.5 ;
99  }
100  else
101  {
102  signal -= 0.5 ;
103  }
104 
105  adc = int( signal ) ;
106 
107  if(!m_PreMix1) assert( 0 < adc ) ;
108 
109  if( 0.5 < signal - adc ) ++adc ;
110 
111  if( MAXADC < adc )
112  {
113  adc = MAXADC ;
114  }
115  else
116  {
117  if( MINADC > adc ) adc = MINADC ;
118  }
119 
120  df.setSample( i, ESSample( adc ) ) ;
121 // std::cout<<", "<<df[i];
122  }
123 // std::cout<<std::endl ;
124 }
int adc(sample_type sample)
get the ADC sample (12 bits)
int i
Definition: DBlmapReader.cc:9
void setMIPToGeV(double MIPToGeV)
auto_ptr< ClusterSequence > cs
const ESIntercalibConstants * m_mips
const_iterator end() const
const self & getMap() const
void setPedestals(const ESPedestals *peds)
CLHEP::RandGaussQ * m_ranGau
void setSize(int size)
Definition: ESDataFrame.cc:27
DetId id() const
const_iterator find(uint32_t rawId) const
bool isAvailable() const
Definition: Service.h:46
virtual CLHEP::HepRandomEngine & getEngine() const =0
Use this to get the random number engine, this is the only function most users should call...
void setSample(int i, const ESSample &sam)
Definition: ESDataFrame.h:30
void analogToDigital(ESSamples &cs, ESDataFrame &df, bool isNoise=false) const
Definition: DetId.h:18
ESElectronicsSimFast(bool addNoise, bool PreMix1)
const ESPedestals * m_peds
std::vector< Item >::const_iterator const_iterator
uint32_t size() const
void setMIPs(const ESIntercalibConstants *mips)