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");
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  }
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) {
82  GenerateGaussianNoise(engine, NoiseMean_, NoiseStd_);
83  RandNoiseGenerationFlag_ = true;
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);
126  scal_.getSiCellOpCharacteristics(detId, HGCalSiNoiseMap::AUTO, myFEelectronics_->getTargetMipValue());
127  cce = siop.cce;
128  noiseWidth = siop.noise;
129  lsbADC = scal_.getLSBPerGain()[(HGCalSiNoiseMap::GainRange_t)siop.gain];
130  maxADC = scal_.getMaxADCPerGain()[(HGCalSiNoiseMap::GainRange_t)siop.gain];
131  gainIdx = siop.gain;
132 
133  if (thresholdFollowsMIP_)
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 =
142  thresholdFollowsMIP_
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>;
HGCDigitizerBase::bxTime_
double bxTime_
Definition: HGCDigitizerBase.h:150
DigiToRawDM_cff.digiColl
digiColl
Definition: DigiToRawDM_cff.py:32
HGCalSiNoiseMap::SiCellOpCharacteristics
Definition: HGCalSiNoiseMap.h:19
HGCDigitizerBase::HGCDigitizerBase
HGCDigitizerBase(const edm::ParameterSet &ps)
CTOR.
Definition: HGCDigitizerBase.cc:9
mps_fire.i
i
Definition: mps_fire.py:355
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
funct::false
false
Definition: Factorize.h:34
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:72
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
HGCDigitizerBase::RandNoiseGenerationFlag_
bool RandNoiseGenerationFlag_
Definition: HGCDigitizerBase.h:164
hgcalDigitizer_cfi.scaleByDoseAlgo
scaleByDoseAlgo
Definition: hgcalDigitizer_cfi.py:48
HGCDigitizerBase::NoiseGeneration_Method_
bool NoiseGeneration_Method_
Definition: HGCDigitizerBase.h:166
HGCDigitizerBase::scaleByDose_
bool scaleByDose_
Definition: HGCDigitizerBase.h:138
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:160
HGCalSiNoiseMap::AUTO
Definition: HGCalSiNoiseMap.h:16
hgc_digi_utils
Definition: HGCDigitizerBase.h:28
HGCSiliconDetId
Definition: HGCSiliconDetId.h:22
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:61
HGCDigitizerBase::doseMapFile_
std::string doseMapFile_
Definition: HGCDigitizerBase.h:141
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:94
Calorimetry_cff.thickness
thickness
Definition: Calorimetry_cff.py:114
HGCalSiNoiseMap::SiCellOpCharacteristics::cce
double cce
Definition: HGCalSiNoiseMap.h:22
HGCalSiNoiseMap::GainRange_t
GainRange_t
Definition: HGCalSiNoiseMap.h:16
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:179
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:93
HGCDigitizerBase::noise_fC_
std::vector< float > noise_fC_
Definition: HGCDigitizerBase.h:132
HGCFEElectronics
models the behavior of the front-end electronics
Definition: HGCFEElectronics.h:20
hgc_digi::HGCCellInfo
Definition: HGCDigitizerTypes.h:31
HGCalSiNoiseMap::setIleakParam
void setIleakParam(const std::vector< double > &pars)
set the ileak parameters to use
Definition: HGCalSiNoiseMap.h:32
HGCDigitizerBase::keV2fC_
float keV2fC_
Definition: HGCDigitizerBase.h:129
edm::ParameterSet::exists
bool exists(std::string const &parameterName) const
checks if a parameter exists
Definition: ParameterSet.cc:674
HGCalGeometry.h
edm::ParameterSet
Definition: ParameterSet.h:36
hgcalDigitizer_cfi.digitizationType
digitizationType
Definition: hgcalDigitizer_cfi.py:79
HGCDigitizerBase::doTimeSamples_
bool doTimeSamples_
Definition: HGCDigitizerBase.h:153
hgcalDigitizer_cfi.noise
noise
Definition: hgcalDigitizer_cfi.py:150
HGCalSiNoiseMap::setDoseMap
void setDoseMap(const std::string &, const unsigned int &)
overrides base class method with specifics for the configuration of the algo
Definition: HGCalSiNoiseMap.cc:48
HGCDigitizerBase::scal_
HGCalSiNoiseMap scal_
Definition: HGCDigitizerBase.h:144
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:37
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
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
HGCDigitizerBase
Definition: HGCDigitizerBase.h:61
HGCDigitizerBase::thresholdFollowsMIP_
bool thresholdFollowsMIP_
Definition: HGCDigitizerBase.h:156
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:31
CaloSubdetectorGeometry
Definition: CaloSubdetectorGeometry.h:22
HGCalSiNoiseMap::SiCellOpCharacteristics::thrADC
unsigned int thrADC
Definition: HGCalSiNoiseMap.h:23
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
HGCalSiNoiseMap::SiCellOpCharacteristics::noise
double noise
Definition: HGCalSiNoiseMap.h:22
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:147
HGCalSiNoiseMap::SiCellOpCharacteristics::gain
unsigned int gain
Definition: HGCalSiNoiseMap.h:23