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 (ESDigiCollection &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 >
void add (const std::vector< PCaloHit > &hits, int bunchCrossing)
 
 EcalTDigitizer (EcalHitResponse *hitResponse, ElectronicsSim *electronicsSim, bool addNoise)
 
virtual void initializeHits ()
 
virtual void run (MixCollection< PCaloHit > &input, DigiCollection &output)
 
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:62
CLHEP::RandFlat * m_ranFlat
Definition: ESDigitizer.h:41
CLHEP::RandGeneral * m_ranGeneral
Definition: ESDigitizer.h:39
bool isAvailable() const
Definition: Service.h:46
double m_meanNoisy
Definition: ESDigitizer.h:46
double m_histoBin
Definition: ESDigitizer.h:43
double m_histoInf
Definition: ESDigitizer.h:44
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:38
const std::vector< DetId > * m_detIds
Definition: ESDigitizer.h:37
double m_histoWid
Definition: ESDigitizer.h:45
const EcalHitResponse * hitResponse() const
CLHEP::RandPoissonQ * m_ranPois
Definition: ESDigitizer.h:40
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:41
CLHEP::RandGeneral * m_ranGeneral
Definition: ESDigitizer.h:39
CLHEP::RandPoissonQ * m_ranPois
Definition: ESDigitizer.h:40

Member Function Documentation

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

Definition at line 234 of file ESDigitizer.cc.

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

Referenced by run().

235 {
236  const unsigned int nChan ( m_ranPois->fire() ) ;
237  abThreshCh.reserve( nChan ) ;
238 
239  for( unsigned int i ( 0 ) ; i != nChan ; ++i )
240  {
241  std::vector<DetId>::const_iterator idItr ( abThreshCh.end() ) ;
242  uint32_t iChan ( 0 ) ;
243  DetId id ;
244  do
245  {
246  iChan = (uint32_t) m_ranFlat->fire() ;
247  if( iChan == m_detIds->size() ) --iChan ; //protect against roundup at end
248  assert( m_detIds->size() > iChan ) ; // sanity check
249  id = (*m_detIds)[ iChan ] ;
250  idItr = find( abThreshCh.begin() ,
251  abThreshCh.end() ,
252  id ) ;
253  }
254  while( idItr != abThreshCh.end() ) ;
255 
256  abThreshCh.push_back( std::move(id) ) ;
257  }
258 }
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:41
Definition: DetId.h:18
const std::vector< DetId > * m_detIds
Definition: ESDigitizer.h:37
CLHEP::RandPoissonQ * m_ranPois
Definition: ESDigitizer.h:40
void ESDigitizer::run ( ESDigiCollection 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::finalizeEvent().

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

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.emplace_back(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:62
CLHEP::RandFlat * m_ranFlat
Definition: ESDigitizer.h:41
string histofile
Definition: jetmet_cfg.py:4
CLHEP::RandGeneral * m_ranGeneral
Definition: ESDigitizer.h:39
tuple result
Definition: query.py:137
double m_meanNoisy
Definition: ESDigitizer.h:46
double m_histoBin
Definition: ESDigitizer.h:43
double m_histoInf
Definition: ESDigitizer.h:44
CLHEP::HepRandomEngine * m_engine
Definition: ESDigitizer.h:38
const std::vector< DetId > * m_detIds
Definition: ESDigitizer.h:37
double m_histoWid
Definition: ESDigitizer.h:45
tuple status
Definition: ntuplemaker.py:245
CLHEP::RandPoissonQ * m_ranPois
Definition: ESDigitizer.h:40

Member Data Documentation

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

Definition at line 37 of file ESDigitizer.h.

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

CLHEP::HepRandomEngine* ESDigitizer::m_engine
private

Definition at line 38 of file ESDigitizer.h.

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

int ESDigitizer::m_ESGain
private

Definition at line 42 of file ESDigitizer.h.

Referenced by setGain().

double ESDigitizer::m_histoBin
private

Definition at line 43 of file ESDigitizer.h.

Referenced by setGain().

double ESDigitizer::m_histoInf
private

Definition at line 44 of file ESDigitizer.h.

Referenced by run(), and setGain().

double ESDigitizer::m_histoWid
private

Definition at line 45 of file ESDigitizer.h.

Referenced by run(), and setGain().

double ESDigitizer::m_meanNoisy
private

Definition at line 46 of file ESDigitizer.h.

Referenced by run(), and setGain().

CLHEP::RandFlat* ESDigitizer::m_ranFlat
private

Definition at line 41 of file ESDigitizer.h.

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

CLHEP::RandGeneral* ESDigitizer::m_ranGeneral
private

Definition at line 39 of file ESDigitizer.h.

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

CLHEP::RandPoissonQ* ESDigitizer::m_ranPois
private

Definition at line 40 of file ESDigitizer.h.

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

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

Definition at line 62 of file ESDigitizer.h.

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