71 const auto& rseed = getCondition<framework::RandomNumberSeedService>(
74 rseed.getSeed(
"HcalDigiProducer::NoiseGenerator"));
77 const auto& rseed = getCondition<framework::RandomNumberSeedService>(
80 rseed.getSeed(
"HcalDigiProducer::NoiseInjector"));
83 const auto& rseed = getCondition<framework::RandomNumberSeedService>(
85 hgcroc_->seedGenerator(rseed.getSeed(
"HcalDigiProducer::HgcrocEmulator"));
90 getCondition<conditions::DoubleTableCondition>(
"HcalHgcrocConditions"));
93 const auto& hcalGeometry = getCondition<ldmx::HcalGeometry>(
101 std::map<unsigned int, std::vector<const ldmx::SimCalorimeterHit*>> hitsByID;
107 for (
auto const& simHit : hcalSimHits) {
109 unsigned int hitID = simHit.
getID();
111 auto idh = hitsByID.find(hitID);
112 if (idh == hitsByID.end()) {
113 hitsByID[hitID] = std::vector<const ldmx::SimCalorimeterHit*>(1, &simHit);
115 idh->second.push_back(&simHit);
122 for (
auto const& simBar : hitsByID) {
124 int section = detID.section();
125 int layer = detID.
layer();
126 int strip = detID.
strip();
129 double half_total_width = hcalGeometry.getHalfTotalWidth(section, layer);
130 double ecal_dx = hcalGeometry.getEcalDx();
131 double ecal_dy = hcalGeometry.getEcalDy();
134 std::vector<std::pair<double, double>> pulses_posend;
135 std::vector<std::pair<double, double>> pulses_negend;
137 for (
auto psimHit : simBar.second) {
140 std::vector<float> position = simHit.
getPosition();
170 float distance_along_bar, distance_ecal;
171 float distance_close, distance_far;
173 const auto orientation{hcalGeometry.getScintillatorOrientation(detID)};
174 if (section == ldmx::HcalID::HcalSection::BACK) {
177 ldmx::HcalGeometry::ScintillatorOrientation::horizontal)
180 end_close = (distance_along_bar > 0) ? 0 : 1;
181 distance_close = half_total_width;
182 distance_far = half_total_width;
184 if ((section == ldmx::HcalID::HcalSection::TOP) ||
185 ((section == ldmx::HcalID::HcalSection::BOTTOM))) {
186 distance_along_bar = position[0];
187 distance_ecal = ecal_dx;
188 }
else if ((section == ldmx::HcalID::HcalSection::LEFT) ||
189 (section == ldmx::HcalID::HcalSection::RIGHT)) {
190 distance_along_bar = position[1];
191 distance_ecal = ecal_dy;
193 distance_along_bar = -9999.;
196 "We should never end up here "
197 "All cases of HCAL considered, end_close is meaningless");
199 end_close = (distance_along_bar > half_total_width) ? 0 : 1;
200 distance_close = (end_close == 0)
201 ? 2 * half_total_width - distance_ecal / 2
203 distance_far = (end_close == 0)
205 : 2 * half_total_width - distance_ecal / 2;
213 exp(-1. * ((distance_close - fabs(distance_along_bar)) / 1000.) /
216 exp(-1. * ((distance_far + fabs(distance_along_bar)) / 1000.) /
219 fabs((distance_close - fabs(distance_along_bar)) / v);
220 double shift_far = fabs((distance_far + fabs(distance_along_bar)) / v);
228 time -= position.at(2) /
231 if (end_close == 0) {
232 pulses_posend.emplace_back(voltage * att_close, time + shift_close);
233 pulses_negend.emplace_back(voltage * att_far, time + shift_far);
235 pulses_posend.emplace_back(voltage * att_far, time + shift_far);
236 pulses_negend.emplace_back(voltage * att_close, time + shift_close);
250 if (section == ldmx::HcalID::HcalSection::BACK) {
251 std::vector<ldmx::HgcrocDigiCollection::Sample> digiToAddPosend,
256 bool posEndActivity =
257 hgcroc_->digitize(posendID.
raw(), pulses_posend, digiToAddPosend);
258 bool negEndActivity =
259 hgcroc_->digitize(negendID.
raw(), pulses_negend, digiToAddNegend);
262 hcalDigis.
addDigi(posendID.
raw(), digiToAddPosend);
263 hcalDigis.
addDigi(negendID.
raw(), digiToAddNegend);
268 if (posEndActivity) {
269 hcalDigis.
addDigi(posendID.
raw(), digiToAddPosend);
271 std::vector<ldmx::HgcrocDigiCollection::Sample> digi =
275 if (negEndActivity) {
276 hcalDigis.
addDigi(posendID.
raw(), digiToAddPosend);
278 std::vector<ldmx::HgcrocDigiCollection::Sample> digi =
285 bool is_posend =
false;
286 std::vector<ldmx::HgcrocDigiCollection::Sample> digiToAdd;
287 if ((section == ldmx::HcalID::HcalSection::TOP) ||
288 (section == ldmx::HcalID::HcalSection::LEFT)) {
290 }
else if ((section == ldmx::HcalID::HcalSection::BOTTOM) ||
291 (section == ldmx::HcalID::HcalSection::RIGHT)) {
296 if (
hgcroc_->digitize(digiID.
raw(), pulses_posend, digiToAdd)) {
299 std::vector<ldmx::HgcrocDigiCollection::Sample> digi =
305 if (
hgcroc_->digitize(digiID.
raw(), pulses_negend, digiToAdd)) {
308 std::vector<ldmx::HgcrocDigiCollection::Sample> digi =
320 std::vector<ldmx::HcalDigiID> channelMap;
322 for (
int section = 0; section < hcalGeometry.getNumSections(); section++) {
323 int numChannelsInSection = 0;
324 for (
int layer = 1; layer <= hcalGeometry.getNumLayers(section);
326 numChannelsInSection += hcalGeometry.getNumStrips(section, layer);
328 for (
int strip = 0; strip < hcalGeometry.getNumStrips(section, layer);
330 if (section == ldmx::HcalID::HcalSection::BACK) {
333 channelMap.push_back(digiIDend0);
334 channelMap.push_back(digiIDend1);
338 channelMap.push_back(digiID);
346 int numEmptyChannels = numChannels - hcalDigis.
getNumDigis();
349 auto noiseHitAmplitudes{
351 std::vector<std::pair<double, double>> fake_pulse(1, {0., 0.});
352 for (
double noiseHit : noiseHitAmplitudes) {
355 unsigned int noiseID;
356 int sectionID, layerID, stripID, endID;
358 sectionID =
noiseInjector_->Integer(hcalGeometry.getNumSections());
363 if (layerID == 0) layerID = 1;
365 hcalGeometry.getNumStrips(sectionID, layerID));
367 if ((sectionID == ldmx::HcalID::HcalSection::TOP) ||
368 (sectionID == ldmx::HcalID::HcalSection::LEFT)) {
370 }
else if ((sectionID == ldmx::HcalID::HcalSection::BOTTOM) ||
371 (sectionID == ldmx::HcalID::HcalSection::RIGHT)) {
375 noiseID = detID.raw();
376 }
while (hitsByID.find(noiseID) != hitsByID.end());
378 std::vector<const ldmx::SimCalorimeterHit*>();
385 double gain =
hgcroc_->gain(noiseID);
386 fake_pulse[0].first = noiseHit +
387 gain *
hgcroc_->readoutThreshold(noiseID) -
388 gain *
hgcroc_->pedestal(noiseID);
390 if (sectionID == ldmx::HcalID::HcalSection::BACK) {
391 std::vector<ldmx::HgcrocDigiCollection::Sample> digiToAddPosend,
395 if (
hgcroc_->digitize(posendID.
raw(), fake_pulse, digiToAddPosend) &&
396 hgcroc_->digitize(negendID.
raw(), fake_pulse, digiToAddNegend)) {
397 hcalDigis.
addDigi(posendID.
raw(), digiToAddPosend);
398 hcalDigis.
addDigi(negendID.
raw(), digiToAddNegend);
401 std::vector<ldmx::HgcrocDigiCollection::Sample> digiToAdd;
402 if (
hgcroc_->digitize(noiseID, fake_pulse, digiToAdd)) {
403 hcalDigis.
addDigi(noiseID, digiToAdd);
409 for (
auto digiID : channelMap) {
412 ldmx::HcalID detid(digiID.section(), digiID.layer(), digiID.strip());
413 unsigned int rawdetID = detid.
raw();
414 if (hitsByID.find(rawdetID) == hitsByID.end()) {
415 std::vector<ldmx::HgcrocDigiCollection::Sample> digi =
416 hgcroc_->noiseDigi(digiID.raw(), 0.0);
417 hcalDigis.
addDigi(digiID.raw(), digi);