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  if (scaleByDose_) {
148  if (id.det() == DetId::Forward && id.subdetId() == ForwardSubdetector::HFNose) {
150  cce = siop.cce;
151  noiseWidth = siop.noise;
153  lsbADC = scalHFNose_.getLSBPerGain()[gain];
154  maxADC = scalHFNose_.getMaxADCPerGain()[gain];
156  gainIdx = siop.gain;
158  thrADC = siop.thrADC;
159  } else {
161  cce = siop.cce;
162  noiseWidth = siop.noise;
164  lsbADC = scal_.getLSBPerGain()[gain];
165  maxADC = scal_.getMaxADCPerGain()[gain];
167  gainIdx = siop.gain;
169  thrADC = siop.thrADC;
170  }
171  } else if (noise_fC_[cell.thickness - 1] != 0) {
172  //this is kept for legacy compatibility with the TDR simulation
173  //probably should simply be removed in a future iteration
174  //note that in this legacy case, gainIdx is kept at 0, fixed
175  cce = (cce_.empty() ? 1.f : cce_[cell.thickness - 1]);
176  noiseWidth = cell.size * noise_fC_[cell.thickness - 1];
177  thrADC =
179  ? std::floor(cell.thickness * cce * myFEelectronics_->getADCThreshold() / myFEelectronics_->getADClsb())
180  : std::floor(cell.thickness * myFEelectronics_->getADCThreshold() / myFEelectronics_->getADClsb());
181  }
182 
183  //loop over time samples and add noise
184  for (size_t i = 0; i < cell.hit_info[0].size(); i++) {
185  double rawCharge(cell.hit_info[0][i]);
186 
187  //time of arrival
188  toa[i] = cell.hit_info[1][i];
189  if (myFEelectronics_->toaMode() == HGCFEElectronics<DFr>::WEIGHTEDBYE && rawCharge > 0)
190  toa[i] = cell.hit_info[1][i] / rawCharge;
191 
192  //final charge estimation
193  float noise;
194  if (NoiseGeneration_Method_ == true)
195  noise = (float)cellNoiseArray[i] * noiseWidth;
196  else
197  noise = CLHEP::RandGaussQ::shoot(engine, cellNoiseArray[i], noiseWidth);
198  float totalCharge(rawCharge * cce + noise);
199  if (totalCharge < 0.f)
200  totalCharge = 0.f;
201  chargeColl[i] = totalCharge;
202  }
203 
204  //run the shaper to create a new data frame
205  DFr rawDataFrame(id);
206  int thickness = cell.thickness > 0 ? cell.thickness : 1;
207  myFEelectronics_->runShaper(
208  rawDataFrame, chargeColl, toa, adcPulse, engine, thrADC, lsbADC, gainIdx, maxADC, thickness);
209 
210  //update the output according to the final shape
211  updateOutput(coll, rawDataFrame);
212  }
213 }
214 
215 void HGCDigitizerBase::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 }
DigiToRawDM_cff.digiColl
digiColl
Definition: DigiToRawDM_cff.py:32
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
HGCDigitizerBase::samplesize_
static const size_t samplesize_
Definition: HGCDigitizerBase.h:167
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
funct::false
false
Definition: Factorize.h:29
HGCalSiNoiseMap::getLSBPerGain
std::vector< double > & getLSBPerGain()
Definition: HGCalSiNoiseMap.h:95
HGCDigitizerBase::GaussianNoiseArray_
std::array< std::array< double, samplesize_ >, NoiseArrayLength_ > GaussianNoiseArray_
Definition: HGCDigitizerBase.h:168
ForwardEmpty
Definition: ForwardSubdetector.h:5
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...
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
HGCDigitizerBase::doTimeSamples_
bool doTimeSamples_
Definition: HGCDigitizerBase.h:147
HGCalSiNoiseMap::setDefaultADCPulseShape
void setDefaultADCPulseShape(const hgc_digi::FEADCPulseShape &adcPulse)
Definition: HGCalSiNoiseMap.h:96
ForwardSubdetector
ForwardSubdetector
Definition: ForwardSubdetector.h:4
HGCDigitizerBase::scaleByDoseFactor_
double scaleByDoseFactor_
Definition: HGCDigitizerBase.h:131
HGCDigitizerBase::NoiseStd_
const double NoiseStd_
Definition: HGCDigitizerBase.h:165
hgcalDigitizer_cfi.scaleByDoseAlgo
scaleByDoseAlgo
Definition: hgcalDigitizer_cfi.py:51
HGCDigitizerBase::doseMapFile_
std::string doseMapFile_
Definition: HGCDigitizerBase.h:134
if
if(0==first)
Definition: CAHitNtupletGeneratorKernelsImpl.h:48
HGCalSiNoiseMap::setDoseMap
void setDoseMap(const std::string &, const unsigned int &)
overrides base class method with specifics for the configuration of the algo
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:90
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
HGCDataFrame::size
int size() const
total number of samples in the digi
Definition: HGCDataFrame.h:36
HGCDataFrame::resize
void resize(size_t s)
allow to set size
Definition: HGCDataFrame.h:41
hgc_digi_utils
Definition: HGCDigitizerBase.h:28
HGCDigitizerBase::thresholdFollowsMIP_
bool thresholdFollowsMIP_
Definition: HGCDigitizerBase.h:150
HGCDigitizerBase::NoiseGeneration_Method_
bool NoiseGeneration_Method_
Definition: HGCDigitizerBase.h:171
hgc_digi::HGCCellInfo::size
double size
Definition: HGCDigitizerTypes.h:35
hgc_digi
Definition: HGCDigitizerTypes.h:10
DetId
Definition: DetId.h:17
HGCDigitizerBase::bxTime_
double bxTime_
Definition: HGCDigitizerBase.h:144
HGCalSiNoiseMap::setGeometry
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...
hgcalDigitizer_cfi.feCfg
feCfg
Definition: hgcalDigitizer_cfi.py:99
Calorimetry_cff.thickness
thickness
Definition: Calorimetry_cff.py:115
HFNose
Definition: ForwardSubdetector.h:11
hgc_digi::HGCSimHitData
std::array< HGCSimData_t, nSamples > HGCSimHitData
Definition: HGCDigitizerTypes.h:17
HGCalSiNoiseMap::adcPulseForGain
const hgc_digi::FEADCPulseShape & adcPulseForGain(GainRange_t gain)
Definition: HGCalSiNoiseMap.h:97
HGCDigitizerBase::scal_
HGCalSiNoiseMap< HGCSiliconDetId > scal_
Definition: HGCDigitizerBase.h:137
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::GenerateGaussianNoise
void GenerateGaussianNoise(CLHEP::HepRandomEngine *engine, const double NoiseMean, const double NoiseStd)
Gaussian Noise Generation Member Function.
Definition: HGCDigitizerBase.cc:80
HGCDigitizerBase::keV2fC_
float keV2fC_
Definition: HGCDigitizerBase.h:119
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
HGCDataFrame
Readout digi for HGC.
Definition: HGCDataFrame.h:14
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
Definition: HGCDigitizerBase.cc:112
hgc_digi::HGCCellInfo::hit_info
std::array< HGCSimHitData, 2 > hit_info
Definition: HGCDigitizerTypes.h:33
HGCDigitizerBase::scalHFNose_
HGCalSiNoiseMap< HFNoseDetId > scalHFNose_
Definition: HGCDigitizerBase.h:138
HGCDigitizerBase.h
gpuVertexFinder::noise
__shared__ int noise
Definition: gpuFitVertices.h:50
hgc_digi::HGCSimHitDataAccumulator
std::unordered_map< uint32_t, HGCCellInfo > HGCSimHitDataAccumulator
Definition: HGCDigitizerTypes.h:38
HGCDigitizerBase::cce_
std::vector< double > cce_
Definition: HGCDigitizerBase.h:125
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::runDigitizer
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
HGCDigitizerBase::HGCDigitizerBase
HGCDigitizerBase(const edm::ParameterSet &ps)
CTOR.
Definition: HGCDigitizerBase.cc:9
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
hgc_digi_utils::addCellMetadata
void addCellMetadata(HGCCellInfo &info, const HGCalGeometry *geom, const DetId &detid)
Definition: HGCDigitizerBase.h:31
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::noise_fC_
std::vector< float > noise_fC_
Definition: HGCDigitizerBase.h:122
HGCDigitizerBase::myFEelectronics_
std::unique_ptr< HGCFEElectronics< DFr > > myFEelectronics_
Definition: HGCDigitizerBase.h:141
CaloSubdetectorGeometry
Definition: CaloSubdetectorGeometry.h:22
HGCDigitizerBase::NoiseArrayLength_
static const size_t NoiseArrayLength_
Definition: HGCDigitizerBase.h:166
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
HGCDigitizerBase::RandNoiseGenerationFlag_
bool RandNoiseGenerationFlag_
Definition: HGCDigitizerBase.h:169
HGCDigitizerBase::NoiseMean_
const double NoiseMean_
Definition: HGCDigitizerBase.h:165
HGCalSiNoiseMap::getMaxADCPerGain
std::vector< double > & getMaxADCPerGain()
Definition: HGCalSiNoiseMap.h:102
HGCDataFrame::id
const D & id() const
det id
Definition: HGCDataFrame.h:31
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:430
HGCDigitizerBase::scaleByDose_
bool scaleByDose_
Definition: HGCDigitizerBase.h:128
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
HLTEgPhaseIITestSequence_cff.noises
noises
Definition: HLTEgPhaseIITestSequence_cff.py:1348
HGCDigitizerBase::det
DetId::Detector det() const
Definition: HGCDigitizerBase.h:84
HGCDigitizerBase::myCfg_
edm::ParameterSet myCfg_
Definition: HGCDigitizerBase.h:112