Core part of digitization used by processAllSubEvents and mergeEvent.
Since not every hit might end up resulting in a digit, this construction might take place after the hit loop in a loop of its own!
252 {
253
254 ATHRNG::RNGWrapper* rngWrapper =
m_rndmSvc->getEngine(
this);
256 CLHEP::HepRandomEngine* rndmEngine = rngWrapper->
getEngine(ctx);
257
258
259 SG::WriteHandle<TgcDigitContainer> digitContainer(
262 std::make_unique<TgcDigitContainer>(
m_idHelper->module_hash_max())));
264
265
266 SG::WriteHandle<MuonSimDataCollection> sdoContainer(
268 ATH_CHECK(sdoContainer.record(std::make_unique<MuonSimDataCollection>()));
270
271
272
273 IdContext tgcContext =
m_idHelper->module_context();
274
275
276 const TgcDigitASDposData* ASDpos{};
278 SG::ReadCondHandle<TgcDigitASDposData> readHandle_ASDpos{
280 ASDpos = readHandle_ASDpos.
cptr();
281 } else {
283 "ASD Position parameters /TGC/DIGIT/ASDPOS must be available for "
284 "TGC_Digitization. Check the configuration!");
285 }
286 const TgcDigitTimeOffsetData* TOffset{};
288 SG::ReadCondHandle<TgcDigitTimeOffsetData> readHandle_TimeOffset{
290 TOffset = readHandle_TimeOffset.
cptr();
291 } else {
293 "Timing Offset parameters /TGC/DIGIT/TOFFSET must be available for "
294 "TGC_Digitization. Check the configuration!");
295 }
296 const TgcDigitCrosstalkData* Crosstalk{};
298 SG::ReadCondHandle<TgcDigitCrosstalkData> readHandle_Crosstalk{
300 Crosstalk = readHandle_Crosstalk.
cptr();
301 } else {
303 "/TGC/DIGIT/XTALK is not provided. Probabilities of TGC channel "
304 "crosstalk will be zero.");
305 }
306
307 std::vector<std::unique_ptr<TgcDigitCollection> > collections;
308
310 while (
m_thpcTGC->nextDetectorElement(i, e)) {
311 ATH_MSG_DEBUG(
"TgcDigitizationTool::digitizeCore next element");
312
313
314 while (i != e) {
315 TimedHitPtr<TGCSimHit> phit = *
i++;
316 const TGCSimHit& hit = *phit;
317 double globalHitTime =
hitTime(phit);
318 double tof = phit->globalTime();
319 TgcDigitCollection* digiHits =
m_digitizer->executeDigi(
320 &hit, globalHitTime, ASDpos, TOffset, Crosstalk, rndmEngine);
321
322 if (!digiHits)
323 continue;
324
326 for (it_digiHits = digiHits->
begin();
327 it_digiHits != digiHits->
end(); ++it_digiHits) {
328
336
337 Identifier newDigiId = (*it_digiHits)->identify();
338 uint16_t newBcTag = (*it_digiHits)->bcTag();
339 Identifier elemId =
m_idHelper->elementID(newDigiId);
340
341 TgcDigitCollection* digitCollection = nullptr;
342
343 IdentifierHash coll_hash;
344 if (
m_idHelper->get_hash(elemId, coll_hash, &tgcContext)) {
346 "Unable to get TGC hash id from TGC Digit collection "
347 <<
"context begin_index = " << tgcContext.
begin_index()
348 <<
" context end_index = " << tgcContext.
end_index()
349 << " the identifier is ");
351 }
352
353
354 auto newDigit = std::make_unique<TgcDigit>(newDigiId, newBcTag);
355
356
357 bool duplicate = false;
358 if (coll_hash >= collections.size()) {
359 collections.resize(coll_hash + 1);
360 }
361 digitCollection = collections[coll_hash].get();
362 if (nullptr == digitCollection) {
363 collections[coll_hash] =
364 std::make_unique<TgcDigitCollection>(elemId, coll_hash);
365 digitCollection = collections[coll_hash].get();
368 << " BC tag = " << newBcTag
369 << " Coll. key = " << coll_hash);
370 digitCollection->
push_back(std::move(newDigit));
371 } else {
372
374 for (it_tgcDigit = digitCollection->
begin();
375 it_tgcDigit != digitCollection->
end(); ++it_tgcDigit) {
376 if (newDigiId == (*it_tgcDigit)->identify() &&
377 newBcTag == (*it_tgcDigit)->bcTag()) {
378 duplicate = true;
379 IdContext context =
m_idHelper->channel_context();
382 newDigiId, &context)
383 << " BC tag = " << newBcTag);
384 newDigit.reset();
385 break;
386 }
387 }
388 if (!duplicate) {
389 digitCollection->
push_back(std::move(newDigit));
392 << " BC tag = " << newBcTag);
393 }
394 }
395
396 if (!duplicate) {
397 static const double invalid_pos = -99999.;
399 const MuonGM::TgcReadoutElement* tgcChamber =
401 if (tgcChamber) {
403 }
404
405
409 continue;
410 }
411
412
413
414 std::vector<MuonSimData::Deposit> deposits;
415 deposits.emplace_back(
417 MuonMCData(tof, 0));
418 MuonSimData
simData(deposits, 0);
421 sdoContainer->insert(std::make_pair(newDigiId,
simData));
422 }
423 }
424 delete digiHits;
425 digiHits = nullptr;
426 }
427 }
428
429 for (size_t coll_hash = 0; coll_hash < collections.size(); ++coll_hash) {
430 if (collections[coll_hash]) {
432 collections[coll_hash].release(), coll_hash));
433 }
434 }
435
436 return StatusCode::SUCCESS;
437}
float hitTime(const AFP_SIDSimHit &hit)
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
void setSeed(const std::string &algName, const EventContext &ctx)
Set the random seed using a string (e.g.
CLHEP::HepRandomEngine * getEngine(const EventContext &ctx) const
Retrieve the random engine corresponding to the provided EventContext.
DataModel_detail::const_iterator< DataVector > const_iterator
value_type push_back(value_type pElem)
Add an element to the end of the collection.
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
static HepMcParticleLink getRedirectedLink(const HepMcParticleLink &particleLink, uint32_t eventIndex, const EventContext &ctx)
Return a HepMcParticleLink pointing at the same particle, but in a different GenEvent.
size_type begin_index() const
size_type end_index() const
void show() const
Print out in hex form.
const Amg::Transform3D & localToGlobalTransf(const Identifier &id) const
Returns the local -> global transformation x-axis: Parallel to the wires (strips) if the Identifier b...
const_pointer_type cptr()
const Amg::Vector3D & localPosition() const
TimedVector::const_iterator const_iterator
unsigned short eventId() const
the index of the component event in PileUpEventInfo.
Eigen::Matrix< double, 3, 1 > Vector3D
bool ignoreTruthLink(const T &p, bool vetoPileUp)
Helper function for SDO creation in PileUpTools.