CMS 3D CMS Logo

HGCDigitizerBase.cc
Go to the documentation of this file.
1 #include <memory>
2 
5 
6 using namespace hgc_digi;
7 using namespace hgc_digi_utils;
8 
10  : scaleByDose_(false),
11  det_(DetId::Forward),
13  NoiseMean_(0.0),
14  NoiseStd_(1.0) {
15  bxTime_ = ps.getParameter<double>("bxTime");
16  myCfg_ = ps.getParameter<edm::ParameterSet>("digiCfg");
17  NoiseGeneration_Method_ = ps.getParameter<bool>("NoiseGeneration_Method");
18  doTimeSamples_ = myCfg_.getParameter<bool>("doTimeSamples");
19  thresholdFollowsMIP_ = myCfg_.getParameter<bool>("thresholdFollowsMIP");
20  if (myCfg_.exists("keV2fC"))
21  keV2fC_ = myCfg_.getParameter<double>("keV2fC");
22  else
23  keV2fC_ = 1.0;
24 
25  if (myCfg_.existsAs<edm::ParameterSet>("chargeCollectionEfficiencies")) {
26  cce_ = myCfg_.getParameter<edm::ParameterSet>("chargeCollectionEfficiencies")
27  .template getParameter<std::vector<double>>("values");
28  }
29 
30  if (myCfg_.existsAs<double>("noise_fC")) {
31  noise_fC_.reserve(1);
32  noise_fC_.push_back(myCfg_.getParameter<double>("noise_fC"));
33  } else if (myCfg_.existsAs<std::vector<double>>("noise_fC")) {
34  const auto& noises = myCfg_.getParameter<std::vector<double>>("noise_fC");
35  noise_fC_ = std::vector<float>(noises.begin(), noises.end());
36  } else if (myCfg_.existsAs<edm::ParameterSet>("noise_fC")) {
37  const auto& noises =
38  myCfg_.getParameter<edm::ParameterSet>("noise_fC").template getParameter<std::vector<double>>("values");
39  noise_fC_ = std::vector<float>(noises.begin(), noises.end());
40  scaleByDose_ = myCfg_.getParameter<edm::ParameterSet>("noise_fC").template getParameter<bool>("scaleByDose");
41  int scaleByDoseAlgo =
42  myCfg_.getParameter<edm::ParameterSet>("noise_fC").template getParameter<uint32_t>("scaleByDoseAlgo");
43  scaleByDoseFactor_ = myCfg_.getParameter<edm::ParameterSet>("noise_fC").getParameter<double>("scaleByDoseFactor");
44  doseMapFile_ = myCfg_.getParameter<edm::ParameterSet>("noise_fC").template getParameter<std::string>("doseMap");
49  } else {
50  noise_fC_.resize(1, 1.f);
51  }
52  if (myCfg_.existsAs<edm::ParameterSet>("ileakParam")) {
54  myCfg_.getParameter<edm::ParameterSet>("ileakParam").template getParameter<std::vector<double>>("ileakParam"));
56  myCfg_.getParameter<edm::ParameterSet>("ileakParam").template getParameter<std::vector<double>>("ileakParam"));
57  }
58  if (myCfg_.existsAs<edm::ParameterSet>("cceParams")) {
60  myCfg_.getParameter<edm::ParameterSet>("cceParams").template getParameter<std::vector<double>>("cceParamFine"),
61  myCfg_.getParameter<edm::ParameterSet>("cceParams").template getParameter<std::vector<double>>("cceParamThin"),
62  myCfg_.getParameter<edm::ParameterSet>("cceParams").template getParameter<std::vector<double>>("cceParamThick"));
64  myCfg_.getParameter<edm::ParameterSet>("cceParams").template getParameter<std::vector<double>>("cceParamFine"),
65  myCfg_.getParameter<edm::ParameterSet>("cceParams").template getParameter<std::vector<double>>("cceParamThin"),
66  myCfg_.getParameter<edm::ParameterSet>("cceParams").template getParameter<std::vector<double>>("cceParamThick"));
67  }
68 
70  myFEelectronics_ = std::make_unique<HGCFEElectronics<DFr>>(feCfg);
71  myFEelectronics_->SetNoiseValues(noise_fC_);
72 
73  //override the "default ADC pulse" with the one with which was configured the FE electronics class
74  scal_.setDefaultADCPulseShape(myFEelectronics_->getDefaultADCPulse());
76 
78 }
79 
80 void HGCDigitizerBase::GenerateGaussianNoise(CLHEP::HepRandomEngine* engine,
81  const double NoiseMean,
82  const double NoiseStd) {
83  for (size_t i = 0; i < NoiseArrayLength_; i++) {
84  for (size_t j = 0; j < samplesize_; j++) {
85  GaussianNoiseArray_[i][j] = CLHEP::RandGaussQ::shoot(engine, NoiseMean, NoiseStd);
86  }
87  }
88 }
89 
90 void HGCDigitizerBase::run(std::unique_ptr<HGCDigitizerBase::DColl>& digiColl,
91  HGCSimHitDataAccumulator& simData,
92  const CaloSubdetectorGeometry* theGeom,
93  const std::unordered_set<DetId>& validIds,
94  uint32_t digitizationType,
95  CLHEP::HepRandomEngine* engine) {
96  if (scaleByDose_) {
99  }
100  if (NoiseGeneration_Method_ == true) {
101  if (RandNoiseGenerationFlag_ == false) {
104  }
105  }
106  myFEelectronics_->generateTimeOffset(engine);
107  if (digitizationType == 0)
108  runSimple(digiColl, simData, theGeom, validIds, engine);
109  else
110  runDigitizer(digiColl, simData, theGeom, validIds, engine);
111 }
112 
113 void HGCDigitizerBase::runSimple(std::unique_ptr<HGCDigitizerBase::DColl>& coll,
114  HGCSimHitDataAccumulator& simData,
115  const CaloSubdetectorGeometry* theGeom,
116  const std::unordered_set<DetId>& validIds,
117  CLHEP::HepRandomEngine* engine) {
118  HGCSimHitData chargeColl, toa;
119 
120  // this represents a cell with no signal charge
121  HGCCellInfo zeroData;
122  zeroData.hit_info[0].fill(0.f); //accumulated energy
123  zeroData.hit_info[1].fill(0.f); //time-of-flight
124 
125  std::array<double, samplesize_> cellNoiseArray;
126  for (size_t i = 0; i < samplesize_; i++)
127  cellNoiseArray[i] = 0.0;
128 
129  for (const auto& id : validIds) {
130  chargeColl.fill(0.f);
131  toa.fill(0.f);
132  HGCSimHitDataAccumulator::iterator it = simData.find(id);
133  HGCCellInfo& cell = (simData.end() == it ? zeroData : it->second);
134  addCellMetadata(cell, theGeom, id);
135  if (NoiseGeneration_Method_ == true) {
136  size_t hash_index = (CLHEP::RandFlat::shootInt(engine, (NoiseArrayLength_ - 1)) + id) % NoiseArrayLength_;
137 
138  cellNoiseArray = GaussianNoiseArray_[hash_index];
139  }
140 
141  //set the noise,cce, LSB, threshold, and ADC pulse shape to be used
142  float cce(1.f), noiseWidth(0.f), lsbADC(-1.f), maxADC(-1.f);
143  // half the target mip value is the specification for ZS threshold
144  uint32_t thrADC(std::floor(myFEelectronics_->getTargetMipValue() / 2));
145  uint32_t gainIdx = 0;
146  std::array<float, 6>& adcPulse = myFEelectronics_->getDefaultADCPulse();
147 
148  double tdcOnsetAuto = -1;
149  if (scaleByDose_) {
150  if (id.det() == DetId::Forward && id.subdetId() == ForwardSubdetector::HFNose) {
152  cce = siop.cce;
153  noiseWidth = siop.noise;
155  lsbADC = scalHFNose_.getLSBPerGain()[gain];
156  maxADC = scalHFNose_.getMaxADCPerGain()[gain];
158  gainIdx = siop.gain;
159  tdcOnsetAuto = scal_.getTDCOnsetAuto(gainIdx);
161  thrADC = siop.thrADC;
162  } else {
164  cce = siop.cce;
165  noiseWidth = siop.noise;
167  lsbADC = scal_.getLSBPerGain()[gain];
168  maxADC = scal_.getMaxADCPerGain()[gain];
170  gainIdx = siop.gain;
171  tdcOnsetAuto = scal_.getTDCOnsetAuto(gainIdx);
173  thrADC = siop.thrADC;
174  }
175  } else if (noise_fC_[cell.thickness - 1] != 0) {
176  //this is kept for legacy compatibility with the TDR simulation
177  //probably should simply be removed in a future iteration
178  //note that in this legacy case, gainIdx is kept at 0, fixed
179  cce = (cce_.empty() ? 1.f : cce_[cell.thickness - 1]);
180  noiseWidth = cell.size * noise_fC_[cell.thickness - 1];
181  thrADC =
183  ? std::floor(cell.thickness * cce * myFEelectronics_->getADCThreshold() / myFEelectronics_->getADClsb())
184  : std::floor(cell.thickness * myFEelectronics_->getADCThreshold() / myFEelectronics_->getADClsb());
185  }
186 
187  //loop over time samples and add noise
188  for (size_t i = 0; i < cell.hit_info[0].size(); i++) {
189  double rawCharge(cell.hit_info[0][i]);
190 
191  //time of arrival
192  toa[i] = cell.hit_info[1][i];
193  if (myFEelectronics_->toaMode() == HGCFEElectronics<DFr>::WEIGHTEDBYE && rawCharge > 0)
194  toa[i] = cell.hit_info[1][i] / rawCharge;
195 
196  //final charge estimation
197  float noise;
198  if (NoiseGeneration_Method_ == true)
199  noise = (float)cellNoiseArray[i] * noiseWidth;
200  else
201  noise = CLHEP::RandGaussQ::shoot(engine, cellNoiseArray[i], noiseWidth);
202  float totalCharge(rawCharge * cce + noise);
203  if (totalCharge < 0.f)
204  totalCharge = 0.f;
205  chargeColl[i] = totalCharge;
206  }
207 
208  //run the shaper to create a new data frame
209  DFr rawDataFrame(id);
210  int thickness = cell.thickness > 0 ? cell.thickness : 1;
211  myFEelectronics_->runShaper(rawDataFrame,
212  chargeColl,
213  toa,
214  adcPulse,
215  engine,
216  thrADC,
217  lsbADC,
218  gainIdx,
219  maxADC,
220  thickness,
221  tdcOnsetAuto,
222  noiseWidth);
223 
224  //update the output according to the final shape
225  updateOutput(coll, rawDataFrame);
226  }
227 }
228 
229 void HGCDigitizerBase::updateOutput(std::unique_ptr<HGCDigitizerBase::DColl>& coll, const DFr& rawDataFrame) {
230  // 9th is the sample of hte intime amplitudes
231  int itIdx(9);
232  if (rawDataFrame.size() <= itIdx + 2)
233  return;
234 
235  DFr dataFrame(rawDataFrame.id());
236  dataFrame.resize(5);
237 
238  // if in time amplitude is above threshold
239  // , then don't push back the dataframe
240  if ((!rawDataFrame[itIdx].threshold())) {
241  return;
242  }
243 
244  for (int it = 0; it < 5; it++) {
245  dataFrame.setSample(it, rawDataFrame[itIdx - 2 + it]);
246  }
247 
248  coll->push_back(dataFrame);
249 }
HGCalSiNoiseMap< HGCSiliconDetId > scal_
std::vector< double > cce_
void setDefaultADCPulseShape(const hgc_digi::FEADCPulseShape &adcPulse)
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void runSimple(std::unique_ptr< DColl > &coll, hgc::HGCSimHitDataAccumulator &simData, const CaloSubdetectorGeometry *theGeom, const std::unordered_set< DetId > &validIds, CLHEP::HepRandomEngine *engine)
a trivial digitization: sum energies and digitize
HGCalSiNoiseMap< HFNoseDetId > scalHFNose_
int size() const
total number of samples in the digi
Definition: HGCDataFrame.h:36
HGCDigitizerBase(const edm::ParameterSet &ps)
CTOR.
void GenerateGaussianNoise(CLHEP::HepRandomEngine *engine, const double NoiseMean, const double NoiseStd)
Gaussian Noise Generation Member Function.
static const size_t NoiseArrayLength_
void updateOutput(std::unique_ptr< DColl > &coll, const DFr &rawDataFrame)
prepares the output according to the number of time samples to produce
bool exists(std::string const &parameterName) const
checks if a parameter exists
std::unordered_map< uint32_t, HGCCellInfo > HGCSimHitDataAccumulator
void setCceParam(const std::vector< double > &parsFine, const std::vector< double > &parsThin, const std::vector< double > &parsThick)
set the cce parameters to use
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:171
std::unique_ptr< HGCFEElectronics< DFr > > myFEelectronics_
ForwardSubdetector
std::array< HGCSimData_t, nSamples > HGCSimHitData
void resize(size_t s)
allow to set size
Definition: HGCDataFrame.h:41
const double NoiseMean_
const D & id() const
det id
Definition: HGCDataFrame.h:31
derives from HGCalRadiation map to parse fluence parameters, provides Si-specific functions; see DN-1...
const hgc_digi::FEADCPulseShape & adcPulseForGain(GainRange_t gain)
virtual void runDigitizer(std::unique_ptr< DColl > &coll, hgc::HGCSimHitDataAccumulator &simData, const CaloSubdetectorGeometry *theGeom, const std::unordered_set< DetId > &validIds, CLHEP::HepRandomEngine *engine)=0
to be specialized by top class
DetId::Detector det() const
std::vector< float > noise_fC_
std::array< HGCSimHitData, 2 > hit_info
void setDoseMap(const std::string &, const unsigned int &)
overrides base class method with specifics for the configuration of the algo
double getTDCOnsetAuto(uint32_t gainIdx)
double f[11][100]
std::string doseMapFile_
void addCellMetadata(HGCCellInfo &info, const HGCalGeometry *geom, const DetId &detid)
void setFluenceScaleFactor(double val)
static const size_t samplesize_
edm::ParameterSet myCfg_
Definition: DetId.h:17
const double NoiseStd_
std::array< std::array< double, samplesize_ >, NoiseArrayLength_ > GaussianNoiseArray_
void setIleakParam(const std::vector< double > &pars)
set the ileak parameters to use
Readout digi for HGC.
Definition: HGCDataFrame.h:14
std::vector< double > & getLSBPerGain()
const SiCellOpCharacteristicsCore getSiCellOpCharacteristicsCore(const T &did, GainRange_t gain, int aimMIPtoADC)
returns the charge collection efficiency and noise if gain range is set to auto, it will find the mos...
std::vector< double > & getMaxADCPerGain()
void setGeometry(const CaloSubdetectorGeometry *, GainRange_t gain=GainRange_t::AUTO, int aimMIPtoADC=10)
specialization of the base class method which sets the geometry so that it can instantiate an operati...
void run(std::unique_ptr< DColl > &digiColl, hgc::HGCSimHitDataAccumulator &simData, const CaloSubdetectorGeometry *theGeom, const std::unordered_set< DetId > &validIds, uint32_t digitizationType, CLHEP::HepRandomEngine *engine)
steer digitization mode
models the behavior of the front-end electronics