212 {
213 const Trk::Track&
track{**trackLink};
214 SubDetHitStatistics trackStat;
215 std::map<HepMcParticleLink,SubDetPRDs> pairStat;
216 IProxyDict *
proxy=ctx.getExtension<Atlas::ExtendedEventContext>().
proxy();
217
218
219 for (
const Trk::MeasurementBase* measurement : *
track.measurementsOnTrack()) {
220
221 const Trk::RIO_OnTrack * riontrack = dynamic_cast<const Trk::RIO_OnTrack*>(measurement);
222
223 if (!riontrack) {
224 const Trk::CompetingRIOsOnTrack* competing = dynamic_cast<const Trk::CompetingRIOsOnTrack*>(measurement);
225 if (competing) {
227 }
228 }
229 if (!riontrack){
230 continue;
231 }
233
234
235 const Trk::PrepRawData* prd = riontrack->
prepRawData();
236 if (!prd) {
238 continue;
239 }
240 const Identifier&
id = prd->
identify();
242
245 continue;
246 }
247 if (!orderedPRD_Truth[subdet]) {
249 continue;
250 }
251
252 ++trackStat[subdet];
253
254 using iprdt = PRD_MultiTruthCollection::const_iterator;
255 std::pair<iprdt, iprdt>
range = orderedPRD_Truth[subdet]->equal_range(
id);
256
258
259 for (iprdt i =
range.first; i!=
range.second; ++i) {
261 if (!pa) {
262 continue;
263 }
264
265 if (!
i->second.isValid()) {
266 ATH_MSG_WARNING(
"Unexpected invalid HepMcParticleLink in PRD_MultiTruthCollection");
267 continue;
268 }
269 pairStat[
i->second].subDetHits[subdet].insert(
id);
271 ATH_MSG_VERBOSE(
"PRD-ID:"<<
id<<
" subdet:"<<subdet<<
" number:"<<n<<
" particle link:"<<
i->second);
272 }
273 if (n == 0) {
274 ATH_MSG_VERBOSE(
"--> no link, noise ? PRD-ID:"<<
id<<
" subdet:"<<subdet);
275
277 unsigned int EV(0);
279 }
280
281 }
282
283 if (msgLvl(MSG::VERBOSE)) {
284 msg(MSG::VERBOSE)<<
"PRD truth particles = ";
285 for (std::map<HepMcParticleLink,SubDetPRDs>::const_iterator i=pairStat.begin(); i!=pairStat.end(); ++i) {
286 msg(MSG::VERBOSE)<<
i->first<<
",";
287 }
289 }
290
292
293
294
295
296 std::set<HepMcParticleLink> seeds;
297 for (std::map<HepMcParticleLink,SubDetPRDs>::const_iterator i=pairStat.begin(); i!=pairStat.end(); ++i) {
298 if (
i->first.isValid()) {
299 seeds.insert(
i->first);
300 }
301 else {
302
303 TruthTrajectory traj;
304 traj.reserve(1);
305 traj.push_back(
i->first);
306 ATH_MSG_VERBOSE(
"addTrack(): add id 0 hits (noise ?) to DetailedTrackTruthCollection.");
307
308
309 SubDetHitStatistics noiseStat = makeSubDetHitStatistics(
i->second);
310
311
312
313
314 output->insert(std::make_pair(trackLink,
315 DetailedTrackTruth(traj,
316 noiseStat,
317 trackStat,
318 noiseStat) ));
319 }
320 }
321
322
323 using SproutMap = std::map<HepMcParticleLink, Sprout>;
324 SproutMap sprouts;
325 while (!seeds.empty() ) {
327 HepMcParticleLink link = *seeds.begin();
328 Sprout current_sprout;
329 std::queue<HepMC::ConstGenParticlePtr>
tmp;
334
335 unsigned nAncestor{0};
336 do {
338 curlink.setTruthSuppressionType(truthSuppressionStatus);
340 if (!nAncestor && !seeds.count(curlink)) {
341 ATH_MSG_WARNING(
"The first link should always point to the object itself.\nHowever "<<
342 link<<"=="<<curlink<<"\n evaluates to " <<(curlink==link)<<", getTruthSuppressionType: "
344 <<
", id:"<<(curlink.id() == link.
id())
345 <<
", eventIndex: "<<(curlink.eventIndex() == link.
eventIndex()));
347 seeds.erase(link);
348
349 }
350
351 seeds.erase(curlink);
352
353
354 SproutMap::iterator p_old = sprouts.find(curlink);
355 if (p_old != sprouts.end()) {
356
357 current_sprout.splice(current_sprout.end(), p_old->second);
358 current_sprout.stat += p_old->second.stat;
359
360 sprouts.erase(p_old);
361 break;
362 }
363
364
365
366
367
368
369 current_sprout.push_back(current);
370
371 std::map<HepMcParticleLink,SubDetPRDs>::iterator p_newstat = pairStat.find(curlink);
372 if (p_newstat != pairStat.end()) {
373 current_sprout.stat += p_newstat->second;
374 }
375
376
378
379
380 sprouts.insert(std::make_pair(link, current_sprout));
381
382 }
383
384
385
386
387
388
389
390
391
392
393
394 for (SproutMap::iterator s=sprouts.begin(); s!=sprouts.end(); ++s) {
395
396
397
398
399
402 s->second.push_front(current);
403 }
404
405
406
407 TruthTrajectory traj;
408 traj.reserve(2);
409 for (Sprout::const_iterator ppart=
s->second.begin(); ppart!=
s->second.end(); ++ppart) {
410 traj.push_back(HepMcParticleLink(ExtendedEventIndex(
s->first, proxy).makeLink(
HepMC::uniqueID(*ppart), proxy)));
411 }
412
413
415
417 output->insert(std::make_pair(trackLink,
418 DetailedTrackTruth(traj,
419 makeSubDetHitStatistics(
s->second.stat),
420 trackStat,
421 truthStat) ));
422 }
423
424
426 }
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
EBC_SUPPRESSED_TRUTH getTruthSuppressionType() const
Return whether the truth particle has been suppressed, as an enum.
int id() const
Return the id of the target particle.
HepMC::ConstGenParticlePtr cptr() const
Dereference.
index_type eventIndex() const
Return the event number of the referenced GenEvent.
unsigned int indexOfMaxAssignProb() const
Index of the ROT with the highest assignment probability.
virtual const RIO_OnTrack & rioOnTrack(unsigned int) const =0
returns the RIO_OnTrack (also known as ROT) objects depending on the integer.
PublicToolHandle< Trk::ITruthTrajectoryBuilder > m_truthTrajBuilder
SubDetHitStatistics::SubDetType findSubDetType(const Identifier &id) const
SubDetHitStatistics countPRDsOnTruth(const TruthTrajectory &traj, const PRD_InverseTruth &inverseTruth) const
Identifier identify() const
return the identifier
virtual const Trk::PrepRawData * prepRawData() const =0
returns the PrepRawData (also known as RIO) object to which this RIO_OnTrack is associated.
thread_local event_number_t eventIndex
constexpr int UNDEFINED_ID
const GenParticle * ConstGenParticlePtr