35 template<
class Map>
void printMap(
const Map& m) {
36 std::cout<<
"printMap(): [";
37 for (
typename Map::const_iterator i=
m.begin(); i!=
m.end(); ++i) {
38 std::cout<<
"("<<
i->first<<
","<<
i->second<<
"), ";
40 std::cout<<
"]"<<std::endl;
47 SubDetPRDs& operator+=(SubDetPRDs&
a,
const SubDetPRDs& b) {
49 const std::set<Identifier>& bset =
b.subDetHits[
i];
50 for (std::set<Identifier>::const_iterator pb=bset.begin(); pb!=bset.end(); ++pb) {
51 a.subDetHits[
i].insert(*pb);
66 class Sprout :
public std::list<HepMC::ConstGenParticlePtr> {
82 return StatusCode::SUCCESS;
89 const std::vector<const PRD_MultiTruthCollection*>& prdTruth,
90 const EventContext& ctx)
const
92 ATH_MSG_VERBOSE(
"DetailedTrackTruthBuilder::buildDetailedTrackTruth() ");
94 if (!output) {
return; }
103 if (prdTruthColl->empty()) {
110 orderedPRD_Truth[subdet] = prdTruthColl;
121 for (
unsigned itrack=0; itrack<tracks.
size(); ++itrack) {
123 addTrack(output, ptrack, orderedPRD_Truth, inverseTruth, ctx);
129 " Entries with TruthTrajectories of more then one particle shown at the DEBUG level.\n"
130 " Use VERBOSE level for complete dump.");
132 for (DetailedTrackTruthCollection::const_iterator i=output->begin(); i!=output->end(); ++i) {
133 bool interesting = (i->second.trajectory().size() > 1);
135 msg(interesting ? MSG::DEBUG : MSG::VERBOSE)
136 <<
"out: trk="<<i->first.index()<<
" => "<<i->second<<
endmsg;
140 msg(MSG::VERBOSE)<<
"Particles on the trajectory:\n";
141 for (
unsigned k=0; k<t.size(); ++k) {
142 msg(MSG::VERBOSE)<<t[k]<<
"\n";
185 class ExtendedEventIndex {
188 : m_eventIndex(source.eventIndex()),
192 m_eventIndex = source.getEventPositionInCollection(proxy);
209 const std::vector<const PRD_MultiTruthCollection*>& orderedPRD_Truth,
211 const EventContext& ctx)
const
215 std::map<HepMcParticleLink,SubDetPRDs> pairStat;
247 if (!orderedPRD_Truth[subdet]) {
254 using iprdt = PRD_MultiTruthCollection::const_iterator;
255 std::pair<iprdt, iprdt> range = orderedPRD_Truth[subdet]->equal_range(
id);
259 for (iprdt i = range.first; i!= range.second; ++i) {
265 if (!i->second.isValid()) {
266 ATH_MSG_WARNING(
"Unexpected invalid HepMcParticleLink in PRD_MultiTruthCollection");
269 pairStat[i->second].subDetHits[subdet].insert(
id);
271 ATH_MSG_VERBOSE(
"PRD-ID:"<<
id<<
" subdet:"<<subdet<<
" number:"<<n<<
" particle link:"<<i->second);
274 ATH_MSG_VERBOSE(
"--> no link, noise ? PRD-ID:"<<
id<<
" subdet:"<<subdet);
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<<
",";
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);
305 traj.push_back(i->first);
306 ATH_MSG_VERBOSE(
"addTrack(): add id 0 hits (noise ?) to DetailedTrackTruthCollection.");
314 output->insert(std::make_pair(trackLink,
323 using SproutMap = std::map<HepMcParticleLink, Sprout>;
325 while (!seeds.empty() ) {
328 Sprout current_sprout;
329 std::queue<HepMC::ConstGenParticlePtr> tmp;
330 ExtendedEventIndex eventIndex(link, proxy);
335 unsigned nAncestor{0};
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())
351 seeds.erase(curlink);
354 SproutMap::iterator p_old = sprouts.find(curlink);
355 if (p_old != sprouts.end()) {
357 current_sprout.splice(current_sprout.end(), p_old->second);
358 current_sprout.stat += p_old->second.stat;
360 sprouts.erase(p_old);
369 current_sprout.push_back(current);
371 std::map<HepMcParticleLink,SubDetPRDs>::iterator p_newstat = pairStat.find(curlink);
372 if (p_newstat != pairStat.end()) {
373 current_sprout.stat += p_newstat->second;
380 sprouts.insert(std::make_pair(link, current_sprout));
394 for (SproutMap::iterator s=sprouts.begin(); s!=sprouts.end(); ++s) {
400 auto current = *s->second.begin();
402 s->second.push_front(current);
409 for (Sprout::const_iterator ppart=s->second.begin(); ppart!=s->second.end(); ++ppart) {
417 output->insert(std::make_pair(trackLink,
419 makeSubDetHitStatistics(s->second.stat),
425 ATH_MSG_VERBOSE(
"addTrack(): #sprouts = "<<sprouts.size()<<
", output->size() = "<<output->size());
433 for (
const auto& i : rec2truth ) {
436 auto pa = i.second.cptr();
446 result.insert(std::make_pair(i.second, i.first));
459 for (TruthTrajectory::const_iterator p = traj.begin(); p != traj.end(); ++p) {
465 ATH_MSG_WARNING(
"HepMcParticleLink " << *p <<
" in truth trajectory does not point to a valid GenParticle.");
469 using iter = PRD_InverseTruth::const_iterator;
470 std::pair<iter,iter> range = inverseTruth.equal_range(*p);
471 for (iter i = range.first; i != range.second; ++i) {
478 return makeSubDetHitStatistics(prds);
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
An STL vector of pointers that by default owns its pointed-to elements.
ATLAS-specific HepMC functions.
std::pair< std::vector< unsigned int >, bool > res
DataVector< Trk::Track > TrackCollection
This typedef represents a collection of Trk::Track objects.
size_type size() const noexcept
Returns the number of elements in the collection.
ElementLink implementation for ROOT usage.
a link optimized in size for a GenParticle in a McEventCollection
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.
void setTruthSuppressionType(EBC_SUPPRESSED_TRUTH truthSupp)
Return whether the truth particle has been suppressed.
A PRD is mapped onto all contributing particles.
Base class for all CompetingRIOsOnTack implementations, extends the common MeasurementBase.
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
virtual void buildDetailedTrackTruth(DetailedTrackTruthCollection *output, const TrackCollection &tracks, const std::vector< const PRD_MultiTruthCollection * > &prdTruth, const EventContext &ctx) const override
See description for IDetailedTrackTruthBuilder::buildDetailedTrackTruth()
InverseMultiMap< PRD_MultiTruthCollection > PRD_InverseTruth
SubDetHitStatistics::SubDetType findSubDetType(const Identifier &id) const
void makeTruthToRecMap(PRD_InverseTruth &result, const PRD_MultiTruthCollection &rec2truth) const
const AtlasDetectorID * m_idHelper
SubDetHitStatistics countPRDsOnTruth(const TruthTrajectory &traj, const PRD_InverseTruth &inverseTruth) const
virtual StatusCode initialize() override
void addTrack(DetailedTrackTruthCollection *output, const ElementLink< DataVector< Trk::Track > > &track, const std::vector< const PRD_MultiTruthCollection * > &orderedPRD_Truth, const PRD_InverseTruth &inverseTruth, const EventContext &ctx) const
This class is the pure abstract base class for all fittable tracking measurements.
Identifier identify() const
return the identifier
Class to handle RIO On Tracks ROT) for InDet and Muons, it inherits from the common MeasurementBase.
virtual const Trk::PrepRawData * prepRawData() const =0
returns the PrepRawData (also known as RIO) object to which this RIO_OnTrack is associated.
A TruthTrajectory is a chain of charged MC particles connected through the mother-daughter relationsh...
constexpr int UNDEFINED_ID
bool is_truth_suppressed_pileup(const T &p)
Method to establish if a particle (or barcode) corresponds to truth-suppressed pile-up (TODO update t...
const GenParticle * ConstGenParticlePtr
bool isGeantino(const T &p)
Ensure that the ATLAS eigen extensions are properly loaded.
ElementLink< T > makeLink(const SG::View *view, const SG::ReadHandle< T > &handle, size_t index)
Create EL to a collection in view.