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  scaleByDoseFactor_ = myCfg_.getParameter<edm::ParameterSet>("noise_fC").getParameter<double>("scaleByDoseFactor");
40  doseMapFile_ = myCfg_.getParameter<edm::ParameterSet>("noise_fC").template getParameter<std::string>("doseMap");
45  } else {
46  noise_fC_.resize(1, 1.f);
47  }
48  if (myCfg_.existsAs<edm::ParameterSet>("ileakParam")) {
50  myCfg_.getParameter<edm::ParameterSet>("ileakParam").template getParameter<std::vector<double>>("ileakParam"));
52  myCfg_.getParameter<edm::ParameterSet>("ileakParam").template getParameter<std::vector<double>>("ileakParam"));
53  }
54  if (myCfg_.existsAs<edm::ParameterSet>("cceParams")) {
56  myCfg_.getParameter<edm::ParameterSet>("cceParams").template getParameter<std::vector<double>>("cceParamFine"),
57  myCfg_.getParameter<edm::ParameterSet>("cceParams").template getParameter<std::vector<double>>("cceParamThin"),
58  myCfg_.getParameter<edm::ParameterSet>("cceParams").template getParameter<std::vector<double>>("cceParamThick"));
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"));
63  }
64 
66  myFEelectronics_ = std::unique_ptr<HGCFEElectronics<DFr>>(new HGCFEElectronics<DFr>(feCfg));
67  myFEelectronics_->SetNoiseValues(noise_fC_);
68 
69  //override the "default ADC pulse" with the one with which was configured the FE electronics class
70  scal_.setDefaultADCPulseShape(myFEelectronics_->getDefaultADCPulse());
72 
74 }
75 
76 template <class DFr>
77 void HGCDigitizerBase<DFr>::GenerateGaussianNoise(CLHEP::HepRandomEngine* engine,
78  const double NoiseMean,
79  const double NoiseStd) {
80  for (size_t i = 0; i < NoiseArrayLength_; i++) {
81  for (size_t j = 0; j < samplesize_; j++) {
82  GaussianNoiseArray_[i][j] = CLHEP::RandGaussQ::shoot(engine, NoiseMean, NoiseStd);
83  }
84  }
85 }
86 
87 template <class DFr>
88 void HGCDigitizerBase<DFr>::run(std::unique_ptr<HGCDigitizerBase::DColl>& digiColl,
89  HGCSimHitDataAccumulator& simData,
90  const CaloSubdetectorGeometry* theGeom,
91  const std::unordered_set<DetId>& validIds,
92  uint32_t digitizationType,
93  CLHEP::HepRandomEngine* engine) {
94  if (scaleByDose_) {
95  scal_.setGeometry(theGeom, HGCalSiNoiseMap<HGCSiliconDetId>::AUTO, myFEelectronics_->getTargetMipValue());
96  scalHFNose_.setGeometry(theGeom, HGCalSiNoiseMap<HFNoseDetId>::AUTO, myFEelectronics_->getTargetMipValue());
97  }
98  if (NoiseGeneration_Method_ == true) {
99  if (RandNoiseGenerationFlag_ == false) {
100  GenerateGaussianNoise(engine, NoiseMean_, NoiseStd_);
101  RandNoiseGenerationFlag_ = true;
102  }
103  }
104  if (digitizationType == 0)
105  runSimple(digiColl, simData, theGeom, validIds, engine);
106  else
107  runDigitizer(digiColl, simData, theGeom, validIds, digitizationType, engine);
108 }
109 
110 template <class DFr>
111 void HGCDigitizerBase<DFr>::runSimple(std::unique_ptr<HGCDigitizerBase::DColl>& coll,
112  HGCSimHitDataAccumulator& simData,
113  const CaloSubdetectorGeometry* theGeom,
114  const std::unordered_set<DetId>& validIds,
115  CLHEP::HepRandomEngine* engine) {
116  HGCSimHitData chargeColl, toa;
117 
118  // this represents a cell with no signal charge
119  HGCCellInfo zeroData;
120  zeroData.hit_info[0].fill(0.f); //accumulated energy
121  zeroData.hit_info[1].fill(0.f); //time-of-flight
122 
123  std::array<double, samplesize_> cellNoiseArray;
124  for (size_t i = 0; i < samplesize_; i++)
125  cellNoiseArray[i] = 0.0;
126 
127  for (const auto& id : validIds) {
128  chargeColl.fill(0.f);
129  toa.fill(0.f);
130  HGCSimHitDataAccumulator::iterator it = simData.find(id);
131  HGCCellInfo& cell = (simData.end() == it ? zeroData : it->second);
132  addCellMetadata(cell, theGeom, id);
133  if (NoiseGeneration_Method_ == true) {
134  size_t hash_index = (CLHEP::RandFlat::shootInt(engine, (NoiseArrayLength_ - 1)) + id) % NoiseArrayLength_;
135 
136  cellNoiseArray = GaussianNoiseArray_[hash_index];
137  }
138 
139  //set the noise,cce, LSB, threshold, and ADC pulse shape to be used
140  float cce(1.f), noiseWidth(0.f), lsbADC(-1.f), maxADC(-1.f);
141  // half the target mip value is the specification for ZS threshold
142  uint32_t thrADC(std::floor(myFEelectronics_->getTargetMipValue() / 2));
143  uint32_t gainIdx = 0;
144  std::array<float, 6>& adcPulse = myFEelectronics_->getDefaultADCPulse();
145 
146  if (scaleByDose_) {
147  if (id.det() == DetId::Forward && id.subdetId() == ForwardSubdetector::HFNose) {
149  cce = siop.cce;
150  noiseWidth = siop.noise;
152  lsbADC = scalHFNose_.getLSBPerGain()[gain];
153  maxADC = scalHFNose_.getMaxADCPerGain()[gain];
154  adcPulse = scalHFNose_.adcPulseForGain(gain);
155  gainIdx = siop.gain;
156  if (thresholdFollowsMIP_)
157  thrADC = siop.thrADC;
158  } else {
160  cce = siop.cce;
161  noiseWidth = siop.noise;
163  lsbADC = scal_.getLSBPerGain()[gain];
164  maxADC = scal_.getMaxADCPerGain()[gain];
165  adcPulse = scal_.adcPulseForGain(gain);
166  gainIdx = siop.gain;
167  if (thresholdFollowsMIP_)
168  thrADC = siop.thrADC;
169  }
170  } else if (noise_fC_[cell.thickness - 1] != 0) {
171  //this is kept for legacy compatibility with the TDR simulation
172  //probably should simply be removed in a future iteration
173  //note that in this legacy case, gainIdx is kept at 0, fixed
174  cce = (cce_.empty() ? 1.f : cce_[cell.thickness - 1]);
175  noiseWidth = cell.size * noise_fC_[cell.thickness - 1];
176  thrADC =
177  thresholdFollowsMIP_
178  ? std::floor(cell.thickness * cce * myFEelectronics_->getADCThreshold() / myFEelectronics_->getADClsb())
179  : std::floor(cell.thickness * myFEelectronics_->getADCThreshold() / myFEelectronics_->getADClsb());
180  }
181 
182  //loop over time samples and add noise
183  for (size_t i = 0; i < cell.hit_info[0].size(); i++) {
184  double rawCharge(cell.hit_info[0][i]);
185 
186  //time of arrival
187  toa[i] = cell.hit_info[1][i];
188  if (myFEelectronics_->toaMode() == HGCFEElectronics<DFr>::WEIGHTEDBYE && rawCharge > 0)
189  toa[i] = cell.hit_info[1][i] / rawCharge;
190 
191  //final charge estimation
192  float noise;
193  if (NoiseGeneration_Method_ == true)
194  noise = (float)cellNoiseArray[i] * noiseWidth;
195  else
196  noise = CLHEP::RandGaussQ::shoot(engine, cellNoiseArray[i], noiseWidth);
197  float totalCharge(rawCharge * cce + noise);
198  if (totalCharge < 0.f)
199  totalCharge = 0.f;
200  chargeColl[i] = totalCharge;
201  }
202 
203  //run the shaper to create a new data frame
204  DFr rawDataFrame(id);
205  int thickness = cell.thickness > 0 ? cell.thickness : 1;
206  myFEelectronics_->runShaper(
207  rawDataFrame, chargeColl, toa, adcPulse, engine, thrADC, lsbADC, gainIdx, maxADC, thickness);
208 
209  //update the output according to the final shape
210  updateOutput(coll, rawDataFrame);
211  }
212 }
213 
214 template <class DFr>
215 void HGCDigitizerBase<DFr>::updateOutput(std::unique_ptr<HGCDigitizerBase::DColl>& coll, const DFr& rawDataFrame) {
216  // 9th is the sample of hte intime amplitudes
217  int itIdx(9);
218  if (rawDataFrame.size() <= itIdx + 2)
219  return;
220 
221  DFr dataFrame(rawDataFrame.id());
222  dataFrame.resize(5);
223 
224  // if in time amplitude is above threshold
225  // , then don't push back the dataframe
226  if ((!rawDataFrame[itIdx].threshold())) {
227  return;
228  }
229 
230  for (int it = 0; it < 5; it++) {
231  dataFrame.setSample(it, rawDataFrame[itIdx - 2 + it]);
232  }
233 
234  coll->push_back(dataFrame);
235 }
236 
237 // cause the compiler to generate the appropriate code
239 template class HGCDigitizerBase<HGCEEDataFrame>;
240 template class HGCDigitizerBase<HGCBHDataFrame>;
241 template class HGCDigitizerBase<HGCalDataFrame>;
HGCDigitizerBase::bxTime_
double bxTime_
Definition: HGCDigitizerBase.h:154
DigiToRawDM_cff.digiColl
digiColl
Definition: DigiToRawDM_cff.py:32
HGCDigitizerBase::HGCDigitizerBase
HGCDigitizerBase(const edm::ParameterSet &ps)
CTOR.
Definition: HGCDigitizerBase.cc:9
HGCalSiNoiseMap::setIleakParam
void setIleakParam(const std::vector< double > &pars)
set the ileak parameters to use
Definition: HGCalSiNoiseMap.h:42
mps_fire.i
i
Definition: mps_fire.py:428
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
funct::false
false
Definition: Factorize.h:29
HGCalSiNoiseMap::getSiCellOpCharacteristicsCore
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...
HGCDigitizerBase::run
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
Definition: HGCDigitizerBase.cc:88
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
HGCalSiNoiseMap::setDefaultADCPulseShape
void setDefaultADCPulseShape(const hgc_digi::FEADCPulseShape &adcPulse)
Definition: HGCalSiNoiseMap.h:96
HGCDigitizerBase::RandNoiseGenerationFlag_
bool RandNoiseGenerationFlag_
Definition: HGCDigitizerBase.h:168
hgcalDigitizer_cfi.scaleByDoseAlgo
scaleByDoseAlgo
Definition: hgcalDigitizer_cfi.py:51
HGCDigitizerBase::NoiseGeneration_Method_
bool NoiseGeneration_Method_
Definition: HGCDigitizerBase.h:170
HGCDigitizerBase::scaleByDose_
bool scaleByDose_
Definition: HGCDigitizerBase.h:138
HGCalSiNoiseMap::setDoseMap
void setDoseMap(const std::string &, const unsigned int &)
overrides base class method with specifics for the configuration of the algo
edm::ParameterSet::existsAs
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:171
hgc_digi_utils
Definition: HGCDigitizerBase.h:28
HcalGeometry.h
hgc_digi::HGCCellInfo::size
double size
Definition: HGCDigitizerTypes.h:35
hgc_digi
Definition: HGCDigitizerTypes.h:10
HGCDigitizerBase::GenerateGaussianNoise
void GenerateGaussianNoise(CLHEP::HepRandomEngine *engine, const double NoiseMean, const double NoiseStd)
Gaussian Noise Generation Member Function.
Definition: HGCDigitizerBase.cc:77
HGCDigitizerBase::doseMapFile_
std::string doseMapFile_
Definition: HGCDigitizerBase.h:144
hgc_digi_utils::addCellMetadata
void addCellMetadata(HGCCellInfo &info, const HcalGeometry *geom, const DetId &detid)
Definition: HGCDigitizerBase.h:31
hgcalDigitizer_cfi.feCfg
feCfg
Definition: hgcalDigitizer_cfi.py:99
Calorimetry_cff.thickness
thickness
Definition: Calorimetry_cff.py:114
HFNose
Definition: ForwardSubdetector.h:11
hgc_digi::HGCSimHitData
std::array< HGCSimData_t, nSamples > HGCSimHitData
Definition: HGCDigitizerTypes.h:17
HGCDigitizerBase::updateOutput
void updateOutput(std::unique_ptr< DColl > &coll, const DFr &rawDataFrame)
prepares the output according to the number of time samples to produce
Definition: HGCDigitizerBase.cc:215
HGCDigitizerBase::runSimple
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
Definition: HGCDigitizerBase.cc:111
HGCDigitizerBase::noise_fC_
std::vector< float > noise_fC_
Definition: HGCDigitizerBase.h:132
hgcROCParameters_cfi.adcPulse
adcPulse
Definition: hgcROCParameters_cfi.py:10
HGCFEElectronics
models the behavior of the front-end electronics
Definition: HGCFEElectronics.h:24
hgc_digi::HGCCellInfo
Definition: HGCDigitizerTypes.h:31
HGCDigitizerBase::keV2fC_
float keV2fC_
Definition: HGCDigitizerBase.h:129
HGCDigitizerBase::scal_
HGCalSiNoiseMap< HGCSiliconDetId > scal_
Definition: HGCDigitizerBase.h:147
edm::ParameterSet::exists
bool exists(std::string const &parameterName) const
checks if a parameter exists
Definition: ParameterSet.cc:681
HGCalSiNoiseMap
derives from HGCalRadiation map to parse fluence parameters, provides Si-specific functions; see DN-1...
Definition: HGCalSiNoiseMap.h:18
HGCalGeometry.h
edm::ParameterSet
Definition: ParameterSet.h:47
hgcalDigitizer_cfi.digitizationType
digitizationType
Definition: hgcalDigitizer_cfi.py:84
HGCDigitizerBase::doTimeSamples_
bool doTimeSamples_
Definition: HGCDigitizerBase.h:157
hgcalDigitizer_cfi.noise
noise
Definition: hgcalDigitizer_cfi.py:155
hgc_digi::HGCCellInfo::hit_info
std::array< HGCSimHitData, 2 > hit_info
Definition: HGCDigitizerTypes.h:33
HGCDigiCollections.h
HGCDigitizerBase.h
hgc_digi::HGCSimHitDataAccumulator
std::unordered_map< uint32_t, HGCCellInfo > HGCSimHitDataAccumulator
Definition: HGCDigitizerTypes.h:38
hgc_digi::HGCCellInfo::thickness
int thickness
Definition: HGCDigitizerTypes.h:34
HGCalRadiationMap::setFluenceScaleFactor
void setFluenceScaleFactor(double val)
Definition: HGCalRadiationMap.h:41
PedestalClient_cfi.gain
gain
Definition: PedestalClient_cfi.py:37
HGCDigitizerBase
Definition: HGCDigitizerBase.h:61
HGCDigitizerBase::thresholdFollowsMIP_
bool thresholdFollowsMIP_
Definition: HGCDigitizerBase.h:160
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:31
CaloSubdetectorGeometry
Definition: CaloSubdetectorGeometry.h:22
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
HGCDigitizerBase::scalHFNose_
HGCalSiNoiseMap< HFNoseDetId > scalHFNose_
Definition: HGCDigitizerBase.h:148
DetId::Forward
Definition: DetId.h:30
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
remoteMonitoring_LED_IterMethod_cfg.threshold
threshold
Definition: remoteMonitoring_LED_IterMethod_cfg.py:426
HGCDigitizerBase::scaleByDoseFactor_
double scaleByDoseFactor_
Definition: HGCDigitizerBase.h:141
HGCalSiNoiseMap::setCceParam
void setCceParam(const std::vector< double > &parsFine, const std::vector< double > &parsThin, const std::vector< double > &parsThick)
set the cce parameters to use
Definition: HGCalSiNoiseMap.h:47
HGCDigitizerBase::myCfg_
edm::ParameterSet myCfg_
Definition: HGCDigitizerBase.h:122
HLTEgPhaseIITestSequence_cff.noises
noises
Definition: HLTEgPhaseIITestSequence_cff.py:1348
HGCDigitizerBase::cce_
std::vector< double > cce_
Definition: HGCDigitizerBase.h:135
HGCDigitizerBase::myFEelectronics_
std::unique_ptr< HGCFEElectronics< DFr > > myFEelectronics_
Definition: HGCDigitizerBase.h:151