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 16 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  m_detIds(nullptr),
16  m_ranGeneral(nullptr),
17  m_ESGain(0),
18  m_histoBin(0),
19  m_histoInf(0),
20  m_histoWid(0),
21  m_meanNoisy(0),
22  m_trip() {
23  m_trip.reserve(2500);
24 }
std::vector< Triplet > m_trip
Definition: ESDigitizer.h:49
CLHEP::RandGeneral * m_ranGeneral
Definition: ESDigitizer.h:32
double m_meanNoisy
Definition: ESDigitizer.h:37
double m_histoBin
Definition: ESDigitizer.h:34
double m_histoInf
Definition: ESDigitizer.h:35
const std::vector< DetId > * m_detIds
Definition: ESDigitizer.h:31
double m_histoWid
Definition: ESDigitizer.h:36
const EcalHitResponse * hitResponse() const
ESDigitizer::~ESDigitizer ( )
override

Definition at line 26 of file ESDigitizer.cc.

References m_ranGeneral.

26 { delete m_ranGeneral; }
CLHEP::RandGeneral * m_ranGeneral
Definition: ESDigitizer.h:32

Member Function Documentation

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

Definition at line 164 of file ESDigitizer.cc.

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

Referenced by run().

164  {
165  CLHEP::RandPoissonQ randPoissonQ(*engine, m_meanNoisy);
166  const unsigned int nChan(randPoissonQ.fire());
167  abThreshCh.reserve(nChan);
168 
169  for (unsigned int i(0); i != nChan; ++i) {
170  std::vector<DetId>::const_iterator idItr(abThreshCh.end());
171  uint32_t iChan(0);
172  DetId id;
173  do {
174  iChan = (uint32_t)CLHEP::RandFlat::shoot(engine, m_detIds->size());
175  if (iChan == m_detIds->size())
176  --iChan; //protect against roundup at end
177  assert(m_detIds->size() > iChan); // sanity check
178  id = (*m_detIds)[iChan];
179  idItr = find(abThreshCh.begin(), abThreshCh.end(), id);
180  } while (idItr != abThreshCh.end());
181 
182  abThreshCh.push_back(std::move(id));
183  }
184 }
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:37
Definition: DetId.h:18
const std::vector< DetId > * m_detIds
Definition: ESDigitizer.h:31
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 130 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().

130  {
131  assert(nullptr != m_detIds && !m_detIds->empty() && (!addNoise() || nullptr != m_ranGeneral)); // sanity check
132 
133  // reserve space for how many digis we expect, with some cushion
134  output.reserve(2 * ((int)m_meanNoisy) + hitResponse()->samplesSize());
135 
137 
138  // random generation of channel above threshold
139  std::vector<DetId> abThreshCh;
140  if (addNoise())
141  createNoisyList(abThreshCh, engine);
142 
143  // first make a raw digi for every cell where we have noise
144  for (std::vector<DetId>::const_iterator idItr(abThreshCh.begin()); idItr != abThreshCh.end(); ++idItr) {
145  if (hitResponse()->findDetId(*idItr)->zero()) // only if no true hit!
146  {
147  ESHitResponse::ESSamples analogSignal(*idItr, 3); // space for the noise hit
148  uint32_t myBin((uint32_t)m_trip.size() * m_ranGeneral->shoot(engine));
149  if (myBin == m_trip.size())
150  --myBin; // guard against roundup
151  assert(myBin < m_trip.size());
152  const Triplet& trip(m_trip[myBin]);
153  analogSignal[0] = m_histoInf + m_histoWid * trip.first;
154  analogSignal[1] = m_histoInf + m_histoWid * trip.second;
155  analogSignal[2] = m_histoInf + m_histoWid * trip.third;
156  ESDataFrame digi(*idItr);
157  const_cast<ESElectronicsSimFast*>(elecSim())->analogToDigital(engine, analogSignal, digi, true);
158  output.push_back(std::move(digi));
159  }
160  }
161 }
std::vector< Triplet > m_trip
Definition: ESDigitizer.h:49
const EcalSamples * findDetId(const DetId &detId) const
const ElectronicsSim * elecSim() const
CLHEP::RandGeneral * m_ranGeneral
Definition: ESDigitizer.h:32
void createNoisyList(std::vector< DetId > &abThreshCh, CLHEP::HepRandomEngine *)
Definition: ESDigitizer.cc:164
double m_meanNoisy
Definition: ESDigitizer.h:37
double m_histoInf
Definition: ESDigitizer.h:35
void reserve(size_t isize)
const std::vector< DetId > * m_detIds
Definition: ESDigitizer.h:31
void push_back(unsigned int i)
virtual void run(DigiCollection &output, CLHEP::HepRandomEngine *)
double m_histoWid
Definition: ESDigitizer.h:36
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 29 of file ESDigitizer.cc.

References m_detIds.

29  {
30  assert(nullptr == m_detIds || &detIds == m_detIds); // sanity check; don't allow to change midstream
31  m_detIds = &detIds;
32 }
const std::vector< DetId > * m_detIds
Definition: ESDigitizer.h:31
void ESDigitizer::setGain ( const int  gain)

Definition at line 34 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.

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

Member Data Documentation

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

Definition at line 31 of file ESDigitizer.h.

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

int ESDigitizer::m_ESGain
private

Definition at line 33 of file ESDigitizer.h.

Referenced by setGain().

double ESDigitizer::m_histoBin
private

Definition at line 34 of file ESDigitizer.h.

Referenced by setGain().

double ESDigitizer::m_histoInf
private

Definition at line 35 of file ESDigitizer.h.

Referenced by run(), and setGain().

double ESDigitizer::m_histoWid
private

Definition at line 36 of file ESDigitizer.h.

Referenced by run(), and setGain().

double ESDigitizer::m_meanNoisy
private

Definition at line 37 of file ESDigitizer.h.

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

CLHEP::RandGeneral* ESDigitizer::m_ranGeneral
private

Definition at line 32 of file ESDigitizer.h.

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

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

Definition at line 49 of file ESDigitizer.h.

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