CMS 3D CMS Logo

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)
 
void run (ESDigiCollection &output, CLHEP::HepRandomEngine *) override
 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)
 
 ~ESDigitizer () override
 
- Public Member Functions inherited from EcalTDigitizer< ESDigitizerTraits >
void add (const std::vector< PCaloHit > &hits, int bunchCrossing, CLHEP::HepRandomEngine *)
 
void addNoiseSignals ()
 
 EcalTDigitizer (EcalHitResponse *hitResponse, ElectronicsSim *electronicsSim, bool addNoise)
 
virtual void initializeHits ()
 
virtual void run (MixCollection< PCaloHit > &input, DigiCollection &output)
 
void setNoiseSignalGenerator (EcalBaseSignalGenerator *noiseSignalGenerator)
 
virtual ~EcalTDigitizer ()
 

Private Member Functions

void createNoisyList (std::vector< DetId > &abThreshCh, CLHEP::HepRandomEngine *)
 

Private Attributes

const std::vector< DetId > * m_detIds
 
int m_ESGain
 
double m_histoBin
 
double m_histoInf
 
double m_histoWid
 
double m_meanNoisy
 
CLHEP::RandGeneral * m_ranGeneral
 
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 14 of file ESDigitizer.h.

Member Typedef Documentation

Definition at line 18 of file ESDigitizer.h.

Constructor & Destructor Documentation

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

Definition at line 13 of file ESDigitizer.cc.

References m_trip.

15  :
17  m_detIds ( nullptr ) ,
18  m_ranGeneral ( nullptr ) ,
19  m_ESGain ( 0 ) ,
20  m_histoBin ( 0 ) ,
21  m_histoInf ( 0 ) ,
22  m_histoWid ( 0 ) ,
23  m_meanNoisy ( 0 ) ,
24  m_trip ( )
25 {
26  m_trip.reserve( 2500 ) ;
27 }
std::vector< Triplet > m_trip
Definition: ESDigitizer.h:61
CLHEP::RandGeneral * m_ranGeneral
Definition: ESDigitizer.h:37
double m_meanNoisy
Definition: ESDigitizer.h:42
double m_histoBin
Definition: ESDigitizer.h:39
double m_histoInf
Definition: ESDigitizer.h:40
const std::vector< DetId > * m_detIds
Definition: ESDigitizer.h:36
double m_histoWid
Definition: ESDigitizer.h:41
const EcalHitResponse * hitResponse() const
ESDigitizer::~ESDigitizer ( )
override

Definition at line 29 of file ESDigitizer.cc.

References m_ranGeneral.

30 {
31  delete m_ranGeneral ;
32 }
CLHEP::RandGeneral * m_ranGeneral
Definition: ESDigitizer.h:37

Member Function Documentation

void ESDigitizer::createNoisyList ( std::vector< DetId > &  abThreshCh,
CLHEP::HepRandomEngine *  engine 
)
private

Definition at line 210 of file ESDigitizer.cc.

References spr::find(), mps_fire::i, triggerObjects_cff::id, m_detIds, m_meanNoisy, and eostools::move().

Referenced by run().

211 {
212  CLHEP::RandPoissonQ randPoissonQ(*engine, m_meanNoisy);
213  const unsigned int nChan (randPoissonQ.fire());
214  abThreshCh.reserve( nChan ) ;
215 
216  for( unsigned int i ( 0 ) ; i != nChan ; ++i )
217  {
218  std::vector<DetId>::const_iterator idItr ( abThreshCh.end() ) ;
219  uint32_t iChan ( 0 ) ;
220  DetId id ;
221  do
222  {
223  iChan = (uint32_t) CLHEP::RandFlat::shoot(engine, m_detIds->size());
224  if( iChan == m_detIds->size() ) --iChan ; //protect against roundup at end
225  assert( m_detIds->size() > iChan ) ; // sanity check
226  id = (*m_detIds)[ iChan ] ;
227  idItr = find( abThreshCh.begin() ,
228  abThreshCh.end() ,
229  id ) ;
230  }
231  while( idItr != abThreshCh.end() ) ;
232 
233  abThreshCh.push_back( std::move(id) ) ;
234  }
235 }
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
double m_meanNoisy
Definition: ESDigitizer.h:42
Definition: DetId.h:18
const std::vector< DetId > * m_detIds
Definition: ESDigitizer.h:36
def move(src, dest)
Definition: eostools.py:511
void ESDigitizer::run ( ESDigiCollection output,
CLHEP::HepRandomEngine *  engine 
)
overridevirtual

turns hits into digis

Reimplemented from EcalTDigitizer< ESDigitizerTraits >.

Definition at line 167 of file ESDigitizer.cc.

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

168 {
169  assert( nullptr != m_detIds &&
170  !m_detIds->empty() &&
171  ( !addNoise() ||
172  nullptr != m_ranGeneral ) ) ; // sanity check
173 
174  // reserve space for how many digis we expect, with some cushion
175  output.reserve( 2*( (int) m_meanNoisy ) + hitResponse()->samplesSize() ) ;
176 
177  EcalTDigitizer< ESDigitizerTraits >::run( output, engine ) ;
178 
179  // random generation of channel above threshold
180  std::vector<DetId> abThreshCh ;
181  if( addNoise() ) createNoisyList( abThreshCh, engine ) ;
182 
183  // first make a raw digi for every cell where we have noise
184  for( std::vector<DetId>::const_iterator idItr ( abThreshCh.begin() ) ;
185  idItr != abThreshCh.end(); ++idItr )
186  {
187  if( hitResponse()->findDetId( *idItr )->zero() ) // only if no true hit!
188  {
189  ESHitResponse::ESSamples analogSignal ( *idItr, 3 ) ; // space for the noise hit
190  uint32_t myBin ( (uint32_t) m_trip.size()*m_ranGeneral->shoot(engine) ) ;
191  if( myBin == m_trip.size() ) --myBin ; // guard against roundup
192  assert( myBin < m_trip.size() ) ;
193  const Triplet& trip ( m_trip[ myBin ] ) ;
194  analogSignal[ 0 ] = m_histoInf + m_histoWid*trip.first ;
195  analogSignal[ 1 ] = m_histoInf + m_histoWid*trip.second ;
196  analogSignal[ 2 ] = m_histoInf + m_histoWid*trip.third ;
197  ESDataFrame digi( *idItr ) ;
198  const_cast<ESElectronicsSimFast*>(elecSim())->
199  analogToDigital( engine,
200  analogSignal ,
201  digi ,
202  true ) ;
203  output.push_back( std::move(digi) ) ;
204  }
205  }
206 }
std::vector< Triplet > m_trip
Definition: ESDigitizer.h:61
const EcalSamples * findDetId(const DetId &detId) const
const ElectronicsSim * elecSim() const
CLHEP::RandGeneral * m_ranGeneral
Definition: ESDigitizer.h:37
void createNoisyList(std::vector< DetId > &abThreshCh, CLHEP::HepRandomEngine *)
Definition: ESDigitizer.cc:210
double m_meanNoisy
Definition: ESDigitizer.h:42
double m_histoInf
Definition: ESDigitizer.h:40
void reserve(size_t isize)
const std::vector< DetId > * m_detIds
Definition: ESDigitizer.h:36
void push_back(unsigned int i)
virtual void run(DigiCollection &output, CLHEP::HepRandomEngine *)
double m_histoWid
Definition: ESDigitizer.h:41
const EcalHitResponse * hitResponse() const
def move(src, dest)
Definition: eostools.py:511
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 36 of file ESDigitizer.cc.

References m_detIds.

37 {
38  assert( nullptr == m_detIds ||
39  &detIds == m_detIds ) ; // sanity check; don't allow to change midstream
40  m_detIds = &detIds ;
41 }
const std::vector< DetId > * m_detIds
Definition: ESDigitizer.h:36
void ESDigitizer::setGain ( const int  gain)

Definition at line 44 of file ESDigitizer.cc.

References EcalTDigitizer< ESDigitizerTraits >::addNoise(), edmScanValgrind::buffer, MessageLogger_cfi::cerr, Exception, muonCSCDigis_cfi::gain, edm::errors::InvalidReference, m_detIds, m_ESGain, m_histoBin, m_histoInf, m_histoWid, m_meanNoisy, m_ranGeneral, m_trip, mps_fire::result, mps_update::status, and AlCaHLTBitMon_QueryRunRegistry::string.

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

Member Data Documentation

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

Definition at line 36 of file ESDigitizer.h.

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

int ESDigitizer::m_ESGain
private

Definition at line 38 of file ESDigitizer.h.

Referenced by setGain().

double ESDigitizer::m_histoBin
private

Definition at line 39 of file ESDigitizer.h.

Referenced by setGain().

double ESDigitizer::m_histoInf
private

Definition at line 40 of file ESDigitizer.h.

Referenced by run(), and setGain().

double ESDigitizer::m_histoWid
private

Definition at line 41 of file ESDigitizer.h.

Referenced by run(), and setGain().

double ESDigitizer::m_meanNoisy
private

Definition at line 42 of file ESDigitizer.h.

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

CLHEP::RandGeneral* ESDigitizer::m_ranGeneral
private

Definition at line 37 of file ESDigitizer.h.

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

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

Definition at line 61 of file ESDigitizer.h.

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