CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes
ESDigitizer Class Reference

#include <ESDigitizer.h>

Inheritance diagram for ESDigitizer:
EcalTDigitizer< ESDigitizerTraits >

Classes

class  Triplet
 

Public Types

typedef
ESDigitizerTraits::ElectronicsSim 
ElectronicsSim
 
- Public Types inherited from EcalTDigitizer< ESDigitizerTraits >
typedef ESDigitizerTraits::Digi Digi
 
typedef
ESDigitizerTraits::DigiCollection 
DigiCollection
 
typedef
ESDigitizerTraits::EcalSamples 
EcalSamples
 
typedef
ESDigitizerTraits::ElectronicsSim 
ElectronicsSim
 

Public Member Functions

 ESDigitizer (EcalHitResponse *hitResponse, ElectronicsSim *electronicsSim, bool addNoise)
 
virtual void run (MixCollection< PCaloHit > &input, DigiCollection &output)
 turns hits into digis More...
 
void setDetIds (const std::vector< DetId > &detIds)
 tell the digitizer which cells exist; cannot change during a run More...
 
void setGain (const int gain)
 
virtual ~ESDigitizer ()
 
- Public Member Functions inherited from EcalTDigitizer< ESDigitizerTraits >
 EcalTDigitizer (EcalHitResponse *hitResponse, ElectronicsSim *electronicsSim, bool addNoise)
 
virtual ~EcalTDigitizer ()
 

Private Member Functions

void createNoisyList (std::vector< DetId > &abThreshCh)
 

Private Attributes

const std::vector< DetId > * m_detIds
 
CLHEP::HepRandomEngine * m_engine
 
int m_ESGain
 
double m_histoBin
 
double m_histoInf
 
double m_histoWid
 
double m_meanNoisy
 
CLHEP::RandFlat * m_ranFlat
 
CLHEP::RandGeneral * m_ranGeneral
 
CLHEP::RandPoissonQ * m_ranPois
 
std::vector< Tripletm_trip
 

Additional Inherited Members

- Protected Member Functions inherited from EcalTDigitizer< ESDigitizerTraits >
bool addNoise () const
 
const ElectronicsSimelecSim () const
 
const EcalHitResponsehitResponse () const
 

Detailed Description

Definition at line 15 of file ESDigitizer.h.

Member Typedef Documentation

Definition at line 19 of file ESDigitizer.h.

Constructor & Destructor Documentation

ESDigitizer::ESDigitizer ( EcalHitResponse hitResponse,
ElectronicsSim electronicsSim,
bool  addNoise 
)

Definition at line 15 of file ESDigitizer.cc.

References edm::hlt::Exception, edm::RandomNumberGenerator::getEngine(), edm::Service< T >::isAvailable(), m_engine, and m_trip.

17  :
19  m_detIds ( 0 ) ,
20  m_engine ( 0 ) ,
21  m_ranGeneral ( 0 ) ,
22  m_ranPois ( 0 ) ,
23  m_ranFlat ( 0 ) ,
24  m_ESGain ( 0 ) ,
25  m_histoBin ( 0 ) ,
26  m_histoInf ( 0 ) ,
27  m_histoWid ( 0 ) ,
28  m_meanNoisy ( 0 ) ,
29  m_trip ( )
30 {
31  m_trip.reserve( 2500 ) ;
32 
34  if( !rng.isAvailable() )
35  {
36  throw cms::Exception( "Configuration" )
37  << "ESDigitizer requires the RandomNumberGeneratorService\n"
38  "which is not present in the configuration file. You must add the service\n"
39  "in the configuration file or remove the modules that require it.";
40  }
41  m_engine = &rng->getEngine() ;
42 }
std::vector< Triplet > m_trip
Definition: ESDigitizer.h:63
CLHEP::RandFlat * m_ranFlat
Definition: ESDigitizer.h:42
CLHEP::RandGeneral * m_ranGeneral
Definition: ESDigitizer.h:40
bool isAvailable() const
Definition: Service.h:47
double m_meanNoisy
Definition: ESDigitizer.h:47
double m_histoBin
Definition: ESDigitizer.h:44
double m_histoInf
Definition: ESDigitizer.h:45
virtual CLHEP::HepRandomEngine & getEngine() const =0
Use this to get the random number engine, this is the only function most users should call...
CLHEP::HepRandomEngine * m_engine
Definition: ESDigitizer.h:39
const std::vector< DetId > * m_detIds
Definition: ESDigitizer.h:38
double m_histoWid
Definition: ESDigitizer.h:46
const EcalHitResponse * hitResponse() const
CLHEP::RandPoissonQ * m_ranPois
Definition: ESDigitizer.h:41
ESDigitizer::~ESDigitizer ( )
virtual

Definition at line 44 of file ESDigitizer.cc.

References m_ranFlat, m_ranGeneral, and m_ranPois.

45 {
46  delete m_ranGeneral ;
47  delete m_ranPois ;
48  delete m_ranFlat ;
49 }
CLHEP::RandFlat * m_ranFlat
Definition: ESDigitizer.h:42
CLHEP::RandGeneral * m_ranGeneral
Definition: ESDigitizer.h:40
CLHEP::RandPoissonQ * m_ranPois
Definition: ESDigitizer.h:41

Member Function Documentation

void ESDigitizer::createNoisyList ( std::vector< DetId > &  abThreshCh)
private

Definition at line 235 of file ESDigitizer.cc.

References spr::find(), i, errorMatrix2Lands_multiChannel::id, m_detIds, m_ranFlat, and m_ranPois.

Referenced by run().

236 {
237  const unsigned int nChan ( m_ranPois->fire() ) ;
238  abThreshCh.reserve( nChan ) ;
239 
240  for( unsigned int i ( 0 ) ; i != nChan ; ++i )
241  {
242  std::vector<DetId>::const_iterator idItr ( abThreshCh.end() ) ;
243  uint32_t iChan ( 0 ) ;
244  DetId id ;
245  do
246  {
247  iChan = (uint32_t) m_ranFlat->fire() ;
248  if( iChan == m_detIds->size() ) --iChan ; //protect against roundup at end
249  assert( m_detIds->size() > iChan ) ; // sanity check
250  id = (*m_detIds)[ iChan ] ;
251  idItr = find( abThreshCh.begin() ,
252  abThreshCh.end() ,
253  id ) ;
254  }
255  while( idItr != abThreshCh.end() ) ;
256 
257  abThreshCh.push_back( id ) ;
258  }
259 }
int i
Definition: DBlmapReader.cc:9
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
CLHEP::RandFlat * m_ranFlat
Definition: ESDigitizer.h:42
Definition: DetId.h:20
const std::vector< DetId > * m_detIds
Definition: ESDigitizer.h:38
CLHEP::RandPoissonQ * m_ranPois
Definition: ESDigitizer.h:41
void ESDigitizer::run ( MixCollection< PCaloHit > &  input,
DigiCollection output 
)
virtual

turns hits into digis

Reimplemented from EcalTDigitizer< ESDigitizerTraits >.

Definition at line 189 of file ESDigitizer.cc.

References EcalTDigitizer< ESDigitizerTraits >::addNoise(), createNoisyList(), EcalTDigitizer< ESDigitizerTraits >::elecSim(), EcalHitResponse::findDetId(), EcalTDigitizer< ESDigitizerTraits >::hitResponse(), m_detIds, m_engine, m_histoInf, m_histoWid, m_meanNoisy, m_ranFlat, m_ranGeneral, m_ranPois, m_trip, ESDigiCollection::push_back(), edm::DataFrameContainer::reserve(), EcalTDigitizer< Traits >::run(), and CaloTSamplesBase< Ttype >::zero().

Referenced by EcalDigiProducer::produce().

191 {
192  assert( 0 != m_detIds &&
193  0 != m_detIds->size() &&
194  ( !addNoise() ||
195  ( 0 != m_engine &&
196  0 != m_ranPois &&
197  0 != m_ranFlat &&
198  0 != m_ranGeneral ) ) ) ; // sanity check
199 
200  // reserve space for how many digis we expect, with some cushion
201  output.reserve( 2*( (int) m_meanNoisy ) + hitResponse()->samplesSize() ) ;
202 
204 
205  // random generation of channel above threshold
206  std::vector<DetId> abThreshCh ;
207  if( addNoise() ) createNoisyList( abThreshCh ) ;
208 
209  // first make a raw digi for every cell where we have noise
210  for( std::vector<DetId>::const_iterator idItr ( abThreshCh.begin() ) ;
211  idItr != abThreshCh.end(); ++idItr )
212  {
213  if( hitResponse()->findDetId( *idItr )->zero() ) // only if no true hit!
214  {
215  ESHitResponse::ESSamples analogSignal ( *idItr, 3 ) ; // space for the noise hit
216  uint32_t myBin ( (uint32_t) m_trip.size()*m_ranGeneral->fire() ) ;
217  if( myBin == m_trip.size() ) --myBin ; // guard against roundup
218  assert( myBin < m_trip.size() ) ;
219  const Triplet& trip ( m_trip[ myBin ] ) ;
220  analogSignal[ 0 ] = m_histoInf + m_histoWid*trip.first ;
221  analogSignal[ 1 ] = m_histoInf + m_histoWid*trip.second ;
222  analogSignal[ 2 ] = m_histoInf + m_histoWid*trip.third ;
223  ESDataFrame digi( *idItr ) ;
224  const_cast<ESElectronicsSimFast*>(elecSim())->
225  analogToDigital( analogSignal ,
226  digi ,
227  true ) ;
228  output.push_back( digi ) ;
229  }
230  }
231 }
void createNoisyList(std::vector< DetId > &abThreshCh)
Definition: ESDigitizer.cc:235
std::vector< Triplet > m_trip
Definition: ESDigitizer.h:63
Definition: Triplet.h:9
CLHEP::RandFlat * m_ranFlat
Definition: ESDigitizer.h:42
const EcalSamples * findDetId(const DetId &detId) const
const ElectronicsSim * elecSim() const
CLHEP::RandGeneral * m_ranGeneral
Definition: ESDigitizer.h:40
virtual void run(MixCollection< PCaloHit > &input, DigiCollection &output)
double m_meanNoisy
Definition: ESDigitizer.h:47
double m_histoInf
Definition: ESDigitizer.h:45
CLHEP::HepRandomEngine * m_engine
Definition: ESDigitizer.h:39
const std::vector< DetId > * m_detIds
Definition: ESDigitizer.h:38
double m_histoWid
Definition: ESDigitizer.h:46
const EcalHitResponse * hitResponse() const
CLHEP::RandPoissonQ * m_ranPois
Definition: ESDigitizer.h:41
bool zero() const
void ESDigitizer::setDetIds ( const std::vector< DetId > &  detIds)

tell the digitizer which cells exist; cannot change during a run

Definition at line 53 of file ESDigitizer.cc.

References m_detIds.

Referenced by EcalDigiProducer::updateGeometry().

54 {
55  assert( 0 == m_detIds ||
56  &detIds == m_detIds ) ; // sanity check; don't allow to change midstream
57  m_detIds = &detIds ;
58 }
const std::vector< DetId > * m_detIds
Definition: ESDigitizer.h:38
void ESDigitizer::setGain ( const int  gain)

Definition at line 61 of file ESDigitizer.cc.

References EcalTDigitizer< ESDigitizerTraits >::addNoise(), dtNoiseDBValidation_cfg::cerr, edm::hlt::Exception, jetmet_cfg::histofile, edm::errors::InvalidReference, m_detIds, m_engine, m_ESGain, m_histoBin, m_histoInf, m_histoWid, m_meanNoisy, m_ranFlat, m_ranGeneral, m_ranPois, m_trip, query::result, and ntuplemaker::status.

Referenced by EcalDigiProducer::checkCalibrations().

62 {
63  if( 0 != m_ESGain )
64  {
65  assert( gain == m_ESGain ) ; // only allow one value
66  }
67  else
68  {
69  assert( 0 != m_detIds &&
70  0 != m_detIds->size() ) ; // detIds must already be set as we need size
71 
72  assert( 1 == gain ||
73  2 == gain ) ; // legal values
74 
75  m_ESGain = gain ;
76 
77  if( addNoise() )
78  {
79  assert( 0 != m_engine ) ; // sanity check
80 
81  double zsThresh ( 0. ) ;
82  std::string refFile ;
83 
84  if( 1 == m_ESGain )
85  {
86  zsThresh = 3 ;
87  refFile = "SimCalorimetry/EcalSimProducers/data/esRefHistosFile_LG.txt";
88  }
89  else
90  {
91  zsThresh = 4 ;
92  refFile = "SimCalorimetry/EcalSimProducers/data/esRefHistosFile_HG.txt";
93  }
94 
95  gsl_sf_result result ;
96  int status = gsl_sf_erf_Q_e( zsThresh, &result ) ;
97  if( status != 0 ) std::cerr << "ESDigitizer::could not compute gaussian tail probability for the threshold chosen" << std::endl ;
98 
99  const double probabilityLeft ( result.val ) ;
100  m_meanNoisy = probabilityLeft * m_detIds->size() ;
101 
102  m_ranPois = new CLHEP::RandPoissonQ( *m_engine, m_meanNoisy ) ;
103  m_ranFlat = new CLHEP::RandFlat( *m_engine, m_detIds->size() ) ;
104 
105  std::ifstream histofile ( edm::FileInPath( refFile ).fullPath().c_str() ) ;
106  if( !histofile.good() )
107  {
108  throw edm::Exception(edm::errors::InvalidReference,"NullPointer")
109  << "Reference histos file not opened" ;
110  }
111  else
112  {
113  // number of bins
114  char buffer[200] ;
115  int thisLine = 0 ;
116  while( 0 == thisLine )
117  {
118  histofile.getline( buffer, 200 ) ;
119  if( !strstr(buffer,"#") &&
120  !(strspn(buffer," ") == strlen(buffer) ) )
121  {
122  float histoBin ;
123  sscanf( buffer, "%f" , &histoBin ) ;
124  m_histoBin = (double) histoBin ;
125  ++thisLine ;
126  }
127  }
128  const uint32_t histoBin1 ( (int) m_histoBin ) ;
129  const uint32_t histoBin2 ( histoBin1*histoBin1 ) ;
130 
131  double t_histoSup ( 0 ) ;
132 
133  std::vector<double> t_refHistos ;
134  t_refHistos.reserve( 2500 ) ;
135 
136  int thisBin = -2 ;
137  while( !( histofile.eof() ) )
138  {
139  histofile.getline( buffer, 200 ) ;
140  if( !strstr( buffer, "#" ) &&
141  !( strspn( buffer, " " ) == strlen( buffer ) ) )
142  {
143  if( -2 == thisBin )
144  {
145  float histoInf ;
146  sscanf( buffer, "%f" , &histoInf ) ;
147  m_histoInf = (double) histoInf ;
148  }
149  if( -1 == thisBin )
150  {
151  float histoSup ;
152  sscanf( buffer, "%f" , &histoSup ) ;
153  t_histoSup = (double) histoSup ;
154  }
155  if( 0 <= thisBin )
156  {
157  float refBin ;
158  sscanf( buffer, "%f", &refBin ) ;
159  if( 0.5 < refBin )
160  {
161  t_refHistos.push_back( (double) refBin ) ;
162  const uint32_t i2 ( thisBin/histoBin2 ) ;
163  const uint32_t off ( i2*histoBin2 ) ;
164  const uint32_t i1 ( ( thisBin - off )/histoBin1 ) ;
165  const uint32_t i0 ( thisBin - off - i1*histoBin1 ) ;
166  m_trip.push_back( Triplet( i0, i1, i2 ) ) ;
167  }
168  }
169  ++thisBin ;
170  }
171  }
172  m_histoWid = ( t_histoSup - m_histoInf )/m_histoBin ;
173 
174  m_histoInf -= 1000. ;
175 
176  // creating the reference distribution to extract random numbers
177  m_ranGeneral = new CLHEP::RandGeneral( *m_engine ,
178  &t_refHistos.front() ,
179  t_refHistos.size() ,
180  0 ) ;
181  histofile.close();
182  }
183  }
184  }
185 }
std::vector< Triplet > m_trip
Definition: ESDigitizer.h:63
Definition: Triplet.h:9
CLHEP::RandFlat * m_ranFlat
Definition: ESDigitizer.h:42
string histofile
Definition: jetmet_cfg.py:4
CLHEP::RandGeneral * m_ranGeneral
Definition: ESDigitizer.h:40
tuple result
Definition: query.py:137
double m_meanNoisy
Definition: ESDigitizer.h:47
double m_histoBin
Definition: ESDigitizer.h:44
double m_histoInf
Definition: ESDigitizer.h:45
CLHEP::HepRandomEngine * m_engine
Definition: ESDigitizer.h:39
const std::vector< DetId > * m_detIds
Definition: ESDigitizer.h:38
double m_histoWid
Definition: ESDigitizer.h:46
tuple status
Definition: ntuplemaker.py:245
CLHEP::RandPoissonQ * m_ranPois
Definition: ESDigitizer.h:41

Member Data Documentation

const std::vector<DetId>* ESDigitizer::m_detIds
private

Definition at line 38 of file ESDigitizer.h.

Referenced by createNoisyList(), run(), setDetIds(), and setGain().

CLHEP::HepRandomEngine* ESDigitizer::m_engine
private

Definition at line 39 of file ESDigitizer.h.

Referenced by ESDigitizer(), run(), and setGain().

int ESDigitizer::m_ESGain
private

Definition at line 43 of file ESDigitizer.h.

Referenced by setGain().

double ESDigitizer::m_histoBin
private

Definition at line 44 of file ESDigitizer.h.

Referenced by setGain().

double ESDigitizer::m_histoInf
private

Definition at line 45 of file ESDigitizer.h.

Referenced by run(), and setGain().

double ESDigitizer::m_histoWid
private

Definition at line 46 of file ESDigitizer.h.

Referenced by run(), and setGain().

double ESDigitizer::m_meanNoisy
private

Definition at line 47 of file ESDigitizer.h.

Referenced by run(), and setGain().

CLHEP::RandFlat* ESDigitizer::m_ranFlat
private

Definition at line 42 of file ESDigitizer.h.

Referenced by createNoisyList(), run(), setGain(), and ~ESDigitizer().

CLHEP::RandGeneral* ESDigitizer::m_ranGeneral
private

Definition at line 40 of file ESDigitizer.h.

Referenced by run(), setGain(), and ~ESDigitizer().

CLHEP::RandPoissonQ* ESDigitizer::m_ranPois
private

Definition at line 41 of file ESDigitizer.h.

Referenced by createNoisyList(), run(), setGain(), and ~ESDigitizer().

std::vector<Triplet> ESDigitizer::m_trip
private

Definition at line 63 of file ESDigitizer.h.

Referenced by ESDigitizer(), run(), and setGain().