CMS 3D CMS Logo

HGCDigitizerBase.cc
Go to the documentation of this file.
4 
5 using namespace hgc_digi;
6 using namespace hgc_digi_utils;
7 
8 template <class DFr>
10  : scaleByDose_(false), NoiseMean_(0.0), NoiseStd_(1.0) {
11  bxTime_ = ps.getParameter<double>("bxTime");
12  myCfg_ = ps.getParameter<edm::ParameterSet>("digiCfg");
13  NoiseGeneration_Method_ = ps.getParameter<bool>("NoiseGeneration_Method");
14  doTimeSamples_ = myCfg_.getParameter<bool>("doTimeSamples");
15  thresholdFollowsMIP_ = myCfg_.getParameter<bool>("thresholdFollowsMIP");
16  if (myCfg_.exists("keV2fC"))
17  keV2fC_ = myCfg_.getParameter<double>("keV2fC");
18  else
19  keV2fC_ = 1.0;
20 
21  if (myCfg_.existsAs<edm::ParameterSet>("chargeCollectionEfficiencies")) {
22  cce_ = myCfg_.getParameter<edm::ParameterSet>("chargeCollectionEfficiencies")
23  .template getParameter<std::vector<double>>("values");
24  }
25 
26  if (myCfg_.existsAs<double>("noise_fC")) {
27  noise_fC_.reserve(1);
28  noise_fC_.push_back(myCfg_.getParameter<double>("noise_fC"));
29  } else if (myCfg_.existsAs<std::vector<double>>("noise_fC")) {
30  const auto& noises = myCfg_.getParameter<std::vector<double>>("noise_fC");
31  noise_fC_ = std::vector<float>(noises.begin(), noises.end());
32  } else if (myCfg_.existsAs<edm::ParameterSet>("noise_fC")) {
33  const auto& noises =
34  myCfg_.getParameter<edm::ParameterSet>("noise_fC").template getParameter<std::vector<double>>("values");
35  noise_fC_ = std::vector<float>(noises.begin(), noises.end());
36  scaleByDose_ = myCfg_.getParameter<edm::ParameterSet>("noise_fC").template getParameter<bool>("scaleByDose");
37  int scaleByDoseAlgo =
38  myCfg_.getParameter<edm::ParameterSet>("noise_fC").template getParameter<uint32_t>("scaleByDoseAlgo");
39  doseMapFile_ = myCfg_.getParameter<edm::ParameterSet>("noise_fC").template getParameter<std::string>("doseMap");
40  scal_.setDoseMap(doseMapFile_, scaleByDoseAlgo);
41  } else {
42  noise_fC_.resize(1, 1.f);
43  }
44  if (myCfg_.existsAs<edm::ParameterSet>("ileakParam")) {
46  myCfg_.getParameter<edm::ParameterSet>("ileakParam").template getParameter<std::vector<double>>("ileakParam"));
47  }
48  if (myCfg_.existsAs<edm::ParameterSet>("cceParams")) {
50  myCfg_.getParameter<edm::ParameterSet>("cceParams").template getParameter<std::vector<double>>("cceParamFine"),
51  myCfg_.getParameter<edm::ParameterSet>("cceParams").template getParameter<std::vector<double>>("cceParamThin"),
52  myCfg_.getParameter<edm::ParameterSet>("cceParams").template getParameter<std::vector<double>>("cceParamThick"));
53  }
54  edm::ParameterSet feCfg = myCfg_.getParameter<edm::ParameterSet>("feCfg");
55  myFEelectronics_ = std::unique_ptr<HGCFEElectronics<DFr>>(new HGCFEElectronics<DFr>(feCfg));
56  myFEelectronics_->SetNoiseValues(noise_fC_);
58 }
59 
60 template <class DFr>
61 void HGCDigitizerBase<DFr>::GenerateGaussianNoise(CLHEP::HepRandomEngine* engine,
62  const double NoiseMean,
63  const double NoiseStd) {
64  for (size_t i = 0; i < NoiseArrayLength_; i++) {
65  for (size_t j = 0; j < samplesize_; j++) {
66  GaussianNoiseArray_[i][j] = CLHEP::RandGaussQ::shoot(engine, NoiseMean, NoiseStd);
67  }
68  }
69 }
70 
71 template <class DFr>
72 void HGCDigitizerBase<DFr>::run(std::unique_ptr<HGCDigitizerBase::DColl>& digiColl,
73  HGCSimHitDataAccumulator& simData,
74  const CaloSubdetectorGeometry* theGeom,
75  const std::unordered_set<DetId>& validIds,
76  uint32_t digitizationType,
77  CLHEP::HepRandomEngine* engine) {
78  if (scaleByDose_)
79  scal_.setGeometry(theGeom);
80  if (NoiseGeneration_Method_ == true) {
81  if (RandNoiseGenerationFlag_ == false) {
84  }
85  }
86  if (digitizationType == 0)
87  runSimple(digiColl, simData, theGeom, validIds, engine);
88  else
89  runDigitizer(digiColl, simData, theGeom, validIds, digitizationType, engine);
90 }
91 
92 template <class DFr>
93 void HGCDigitizerBase<DFr>::runSimple(std::unique_ptr<HGCDigitizerBase::DColl>& coll,
94  HGCSimHitDataAccumulator& simData,
95  const CaloSubdetectorGeometry* theGeom,
96  const std::unordered_set<DetId>& validIds,
97  CLHEP::HepRandomEngine* engine) {
98  HGCSimHitData chargeColl, toa;
99 
100  // this represents a cell with no signal charge
101  HGCCellInfo zeroData;
102  zeroData.hit_info[0].fill(0.f); //accumulated energy
103  zeroData.hit_info[1].fill(0.f); //time-of-flight
104  std::array<double, samplesize_> cellNoiseArray;
105  for (size_t i = 0; i < samplesize_; i++)
106  cellNoiseArray[i] = 0.0;
107  for (const auto& id : validIds) {
108  chargeColl.fill(0.f);
109  toa.fill(0.f);
110  HGCSimHitDataAccumulator::iterator it = simData.find(id);
111  HGCCellInfo& cell = (simData.end() == it ? zeroData : it->second);
112  addCellMetadata(cell, theGeom, id);
113  if (NoiseGeneration_Method_ == true) {
114  size_t hash_index = (CLHEP::RandFlat::shootInt(engine, (NoiseArrayLength_ - 1)) + id) % NoiseArrayLength_;
115 
116  cellNoiseArray = GaussianNoiseArray_[hash_index];
117  }
118  //set the noise,cce, LSB and threshold to be used
119  float cce(1.f), noiseWidth(0.f), lsbADC(-1.f), maxADC(-1.f);
120  // half the target mip value is the specification for ZS threshold
121  uint32_t thrADC(std::floor(myFEelectronics_->getTargetMipValue() / 2));
122  uint32_t gainIdx = 0;
123  if (scaleByDose_) {
124  HGCSiliconDetId detId(id);
127  cce = siop.cce;
128  noiseWidth = siop.noise;
131  gainIdx = siop.gain;
132 
134  thrADC = siop.thrADC;
135  } else if (noise_fC_[cell.thickness - 1] != 0) {
136  //this is kept for legacy compatibility with the TDR simulation
137  //probably should simply be removed in a future iteration
138  //note that in this legacy case, gainIdx is kept at 0, fixed
139  cce = (cce_.empty() ? 1.f : cce_[cell.thickness - 1]);
140  noiseWidth = cell.size * noise_fC_[cell.thickness - 1];
141  thrADC =
143  ? std::floor(cell.thickness * cce * myFEelectronics_->getADCThreshold() / myFEelectronics_->getADClsb())
144  : std::floor(cell.thickness * myFEelectronics_->getADCThreshold() / myFEelectronics_->getADClsb());
145  }
146 
147  //loop over time samples and add noise
148  for (size_t i = 0; i < cell.hit_info[0].size(); i++) {
149  double rawCharge(cell.hit_info[0][i]);
150 
151  //time of arrival
152  toa[i] = cell.hit_info[1][i];
153  if (myFEelectronics_->toaMode() == HGCFEElectronics<DFr>::WEIGHTEDBYE && rawCharge > 0)
154  toa[i] = cell.hit_info[1][i] / rawCharge;
155 
156  //final charge estimation
157  float noise;
158  if (NoiseGeneration_Method_ == true)
159  noise = (float)cellNoiseArray[i] * noiseWidth;
160  else
161  noise = CLHEP::RandGaussQ::shoot(engine, cellNoiseArray[i], noiseWidth);
162  float totalCharge(rawCharge * cce + noise);
163  if (totalCharge < 0.f)
164  totalCharge = 0.f;
165  chargeColl[i] = totalCharge;
166  }
167 
168  //run the shaper to create a new data frame
169  DFr rawDataFrame(id);
170  int thickness = cell.thickness > 0 ? cell.thickness : 1;
171  myFEelectronics_->runShaper(rawDataFrame, chargeColl, toa, engine, thrADC, lsbADC, gainIdx, maxADC, thickness);
172 
173  //update the output according to the final shape
174  updateOutput(coll, rawDataFrame);
175  }
176 }
177 
178 template <class DFr>
179 void HGCDigitizerBase<DFr>::updateOutput(std::unique_ptr<HGCDigitizerBase::DColl>& coll, const DFr& rawDataFrame) {
180  int itIdx(9);
181  if (rawDataFrame.size() <= itIdx + 2)
182  return;
183 
184  DFr dataFrame(rawDataFrame.id());
185  dataFrame.resize(5);
186  bool putInEvent(false);
187  for (int it = 0; it < 5; it++) {
188  dataFrame.setSample(it, rawDataFrame[itIdx - 2 + it]);
189  if (it == 2)
190  putInEvent = rawDataFrame[itIdx - 2 + it].threshold();
191  }
192 
193  if (putInEvent) {
194  coll->push_back(dataFrame);
195  }
196 }
197 
198 // cause the compiler to generate the appropriate code
200 template class HGCDigitizerBase<HGCEEDataFrame>;
201 template class HGCDigitizerBase<HGCBHDataFrame>;
202 template class HGCDigitizerBase<HGCalDataFrame>;
void setIleakParam(const std::vector< double > &pars)
set the ileak parameters to use
std::vector< float > noise_fC_
T getParameter(std::string const &) const
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 without noise
void updateOutput(std::unique_ptr< DColl > &coll, const DFr &rawDataFrame)
prepares the output according to the number of time samples to produce
HGCalSiNoiseMap scal_
void setGeometry(const CaloSubdetectorGeometry *)
std::unordered_map< uint32_t, HGCCellInfo > HGCSimHitDataAccumulator
std::vector< double > & getMaxADCPerGain()
void addCellMetadata(HGCCellInfo &info, const HcalGeometry *geom, const DetId &detid)
std::vector< double > & getLSBPerGain()
std::array< HGCSimData_t, nSamples > HGCSimHitData
const double NoiseMean_
edm::ParameterSet myCfg_
void setDoseMap(const std::string &, const unsigned int &)
overrides base class method with specifics for the configuration of the algo
SiCellOpCharacteristics getSiCellOpCharacteristics(const HGCSiliconDetId &did, GainRange_t gain=GainRange_t::AUTO, int aimMIPtoADC=10)
returns the charge collection efficiency and noise if gain range is set to auto, it will find the mos...
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
std::array< HGCSimHitData, 2 > hit_info
const double NoiseStd_
std::unique_ptr< HGCFEElectronics< DFr > > myFEelectronics_
double f[11][100]
void setCceParam(const std::vector< double > &parsFine, const std::vector< double > &parsThin, const std::vector< double > &parsThick)
set the cce parameters to use
std::array< std::array< double, samplesize_ >, NoiseArrayLength_ > GaussianNoiseArray_
HGCDigitizerBase(const edm::ParameterSet &ps)
CTOR.
std::vector< double > cce_
JetCorrectorParametersCollection coll
Definition: classes.h:10
void GenerateGaussianNoise(CLHEP::HepRandomEngine *engine, const double NoiseMean, const double NoiseStd)
Gaussian Noise Generation Member Function.
virtual void runDigitizer(std::unique_ptr< DColl > &coll, hgc::HGCSimHitDataAccumulator &simData, const CaloSubdetectorGeometry *theGeom, const std::unordered_set< DetId > &validIds, uint32_t digitizerType, CLHEP::HepRandomEngine *engine)
to be specialized by top class
static const size_t NoiseArrayLength_
std::string doseMapFile_
models the behavior of the front-end electronics
static const size_t samplesize_