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  if (digitizationType == 0)
107  runSimple(digiColl, simData, theGeom, validIds, engine);
108  else
109  runDigitizer(digiColl, simData, theGeom, validIds, engine);
110 }
111 
112 void HGCDigitizerBase::runSimple(std::unique_ptr<HGCDigitizerBase::DColl>& coll,
113  HGCSimHitDataAccumulator& simData,
114  const CaloSubdetectorGeometry* theGeom,
115  const std::unordered_set<DetId>& validIds,
116  CLHEP::HepRandomEngine* engine) {
117  HGCSimHitData chargeColl, toa;
118 
119  // this represents a cell with no signal charge
120  HGCCellInfo zeroData;
121  zeroData.hit_info[0].fill(0.f); //accumulated energy
122  zeroData.hit_info[1].fill(0.f); //time-of-flight
123 
124  std::array<double, samplesize_> cellNoiseArray;
125  for (size_t i = 0; i < samplesize_; i++)
126  cellNoiseArray[i] = 0.0;
127 
128  for (const auto& id : validIds) {
129  chargeColl.fill(0.f);
130  toa.fill(0.f);
131  HGCSimHitDataAccumulator::iterator it = simData.find(id);
132  HGCCellInfo& cell = (simData.end() == it ? zeroData : it->second);
133  addCellMetadata(cell, theGeom, id);
134  if (NoiseGeneration_Method_ == true) {
135  size_t hash_index = (CLHEP::RandFlat::shootInt(engine, (NoiseArrayLength_ - 1)) + id) % NoiseArrayLength_;
136 
137  cellNoiseArray = GaussianNoiseArray_[hash_index];
138  }
139 
140  //set the noise,cce, LSB, threshold, and ADC pulse shape to be used
141  float cce(1.f), noiseWidth(0.f), lsbADC(-1.f), maxADC(-1.f);
142  // half the target mip value is the specification for ZS threshold
143  uint32_t thrADC(std::floor(myFEelectronics_->getTargetMipValue() / 2));
144  uint32_t gainIdx = 0;
145  std::array<float, 6>& adcPulse = myFEelectronics_->getDefaultADCPulse();
146 
147  double tdcOnsetAuto = -1;
148  if (scaleByDose_) {
149  if (id.det() == DetId::Forward && id.subdetId() == ForwardSubdetector::HFNose) {
151  cce = siop.cce;
152  noiseWidth = siop.noise;
154  lsbADC = scalHFNose_.getLSBPerGain()[gain];
155  maxADC = scalHFNose_.getMaxADCPerGain()[gain];
157  gainIdx = siop.gain;
158  tdcOnsetAuto = scal_.getTDCOnsetAuto(gainIdx);
160  thrADC = siop.thrADC;
161  } else {
163  cce = siop.cce;
164  noiseWidth = siop.noise;
166  lsbADC = scal_.getLSBPerGain()[gain];
167  maxADC = scal_.getMaxADCPerGain()[gain];
169  gainIdx = siop.gain;
170  tdcOnsetAuto = scal_.getTDCOnsetAuto(gainIdx);
172  thrADC = siop.thrADC;
173  }
174  } else if (noise_fC_[cell.thickness - 1] != 0) {
175  //this is kept for legacy compatibility with the TDR simulation
176  //probably should simply be removed in a future iteration
177  //note that in this legacy case, gainIdx is kept at 0, fixed
178  cce = (cce_.empty() ? 1.f : cce_[cell.thickness - 1]);
179  noiseWidth = cell.size * noise_fC_[cell.thickness - 1];
180  thrADC =
182  ? std::floor(cell.thickness * cce * myFEelectronics_->getADCThreshold() / myFEelectronics_->getADClsb())
183  : std::floor(cell.thickness * myFEelectronics_->getADCThreshold() / myFEelectronics_->getADClsb());
184  }
185 
186  //loop over time samples and add noise
187  for (size_t i = 0; i < cell.hit_info[0].size(); i++) {
188  double rawCharge(cell.hit_info[0][i]);
189 
190  //time of arrival
191  toa[i] = cell.hit_info[1][i];
192  if (myFEelectronics_->toaMode() == HGCFEElectronics<DFr>::WEIGHTEDBYE && rawCharge > 0)
193  toa[i] = cell.hit_info[1][i] / rawCharge;
194 
195  //final charge estimation
196  float noise;
197  if (NoiseGeneration_Method_ == true)
198  noise = (float)cellNoiseArray[i] * noiseWidth;
199  else
200  noise = CLHEP::RandGaussQ::shoot(engine, cellNoiseArray[i], noiseWidth);
201  float totalCharge(rawCharge * cce + noise);
202  if (totalCharge < 0.f)
203  totalCharge = 0.f;
204  chargeColl[i] = totalCharge;
205  }
206 
207  //run the shaper to create a new data frame
208  DFr rawDataFrame(id);
209  int thickness = cell.thickness > 0 ? cell.thickness : 1;
210  myFEelectronics_->runShaper(
211  rawDataFrame, chargeColl, toa, adcPulse, engine, thrADC, lsbADC, gainIdx, maxADC, thickness, tdcOnsetAuto);
212 
213  //update the output according to the final shape
214  updateOutput(coll, rawDataFrame);
215  }
216 }
217 
218 void HGCDigitizerBase::updateOutput(std::unique_ptr<HGCDigitizerBase::DColl>& coll, const DFr& rawDataFrame) {
219  // 9th is the sample of hte intime amplitudes
220  int itIdx(9);
221  if (rawDataFrame.size() <= itIdx + 2)
222  return;
223 
224  DFr dataFrame(rawDataFrame.id());
225  dataFrame.resize(5);
226 
227  // if in time amplitude is above threshold
228  // , then don't push back the dataframe
229  if ((!rawDataFrame[itIdx].threshold())) {
230  return;
231  }
232 
233  for (int it = 0; it < 5; it++) {
234  dataFrame.setSample(it, rawDataFrame[itIdx - 2 + it]);
235  }
236 
237  coll->push_back(dataFrame);
238 }
HGCalSiNoiseMap< HGCSiliconDetId > scal_
std::vector< double > cce_
void setDefaultADCPulseShape(const hgc_digi::FEADCPulseShape &adcPulse)
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
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:172
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