#include #include #include #include #include #include #include #include #include std::vector HitTruthInfo::GetHitTruthInfo(COMET::IHandle hit){ // Check if we have MC-digit information. if(hit->GetDigitCount()){ COMET::IDigitProxy proxy = hit->GetDigit(); COMET::IMCDigit *mcDigit = proxy.As(); if(mcDigit){ return mcDigit->GetContributors(); } } // Check if this is a IMCHit. COMET::IHandle mcchit = hit; if(mcchit){ return mcchit->GetContributors(); } // Unpack multihits and use a unique set of contributors COMET::IHandle multihit = hit; if (multihit) { std::set contrset; COMET::IMultiHit::iterator hit2 = multihit->begin(); std::vector contr = GetHitTruthInfo(*hit2); for (std::vector::iterator c = contr.begin(); c != contr.end(); c++) contrset.insert(*c); std::vector result; std::copy(contrset.begin(), contrset.end(), std::back_inserter(result)); return result; } // Now check if it is a IComboHit and expand COMET::IHandle combohit(hit); if (combohit) { std::vector result; for (COMET::IHitSelection::const_iterator hit2 = combohit->GetHits().begin(); hit2 != combohit->GetHits().end(); hit2++) { // use a recursive call to get the constituents of the combo hit std::vector constituents = GetHitTruthInfo(*hit2); std::copy(constituents.begin(), constituents.end(), std::back_inserter(result)); } return result; } // Now check if it is a IReconHit and expand COMET::IHandle recohit(hit); if (recohit) { std::vector result; for ( int i=0; i < hit->GetContributorCount(); i++){ std::vector constituents = GetHitTruthInfo(hit->GetContributor(i)); std::copy(constituents.begin(), constituents.end(), std::back_inserter(result)); } return result; } return std::vector(); };