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 \n" << elemId);
350 }
351
352
353 auto newDigit = std::make_unique<TgcDigit>(newDigiId, newBcTag);
354
355
356 bool duplicate = false;
357 if (coll_hash >= collections.size()) {
358 collections.resize(coll_hash + 1);
359 }
360 digitCollection = collections[coll_hash].get();
361 if (nullptr == digitCollection) {
362 collections[coll_hash] =
363 std::make_unique<TgcDigitCollection>(elemId, coll_hash);
364 digitCollection = collections[coll_hash].get();
367 << " BC tag = " << newBcTag
368 << " Coll. key = " << coll_hash);
369 digitCollection->
push_back(std::move(newDigit));
370 } else {
371
373 for (it_tgcDigit = digitCollection->
begin();
374 it_tgcDigit != digitCollection->
end(); ++it_tgcDigit) {
375 if (newDigiId == (*it_tgcDigit)->identify() &&
376 newBcTag == (*it_tgcDigit)->bcTag()) {
377 duplicate = true;
378 IdContext context =
m_idHelper->channel_context();
381 newDigiId, &context)
382 << " BC tag = " << newBcTag);
383 newDigit.reset();
384 break;
385 }
386 }
387 if (!duplicate) {
388 digitCollection->
push_back(std::move(newDigit));
391 << " BC tag = " << newBcTag);
392 }
393 }
394
395 if (!duplicate) {
396 static const double invalid_pos = -99999.;
398 const MuonGM::TgcReadoutElement* tgcChamber =
400 if (tgcChamber) {
402 }
403
404
408 continue;
409 }
410
411
412
413 std::vector<MuonSimData::Deposit> deposits;
414 deposits.emplace_back(
416 MuonMCData(tof, 0));
417 MuonSimData
simData(deposits, 0);
420 sdoContainer->insert(std::make_pair(newDigiId,
simData));
421 }
422 }
423 delete digiHits;
424 digiHits = nullptr;
425 }
426 }
427
428 for (size_t coll_hash = 0; coll_hash < collections.size(); ++coll_hash) {
429 if (collections[coll_hash]) {
431 collections[coll_hash].release(), coll_hash));
432 }
433 }
434
435 return StatusCode::SUCCESS;
436}
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
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.