Whether pfo is identified as a clear track.
89 object_creation::ParticleFlowObject::Metadata
metadata;
90 metadata.m_propertiesToAdd[
"TrackScore"] = -1.f;
91 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ParticleFlowObject::AlterMetadata(*
this, pPfo, metadata));
93 return (pPfo->GetParticleId() == MU_MINUS);
97 ClusterList wClusterList;
106 const MCParticleList *pMCParticleList(
nullptr);
107 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetList(*
this,
m_mcParticleListName, pMCParticleList));
109 const CaloHitList *pCaloHitList(
nullptr);
110 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetList(*
this,
m_caloHitListName, pCaloHitList));
126 if (pfoToReconstructable2DHitsMap.empty())
132 pfoToReconstructable2DHitsMap, mcParticlesToGoodHitsMaps, pfoToMCParticleHitSharingMap, mcParticleToPfoHitSharingMap);
133 if (pfoToMCParticleHitSharingMap.empty())
136 unsigned int nHitsInBestMCParticleTotal(0);
137 unsigned int nHitsSharedWithBestMCParticleTotal(0);
138 int bestMCParticlePdgCode(0);
139 CartesianVector threeDVertexPosition(0.
f, 0.
f, 0.
f);
140 float hitsShower(0), hitsTrack(0);
145 const pandora::MCParticle *
const pAssociatedMCParticle(mcParticleCaloHitListPair.first);
146 const CaloHitList &allMCHits(targetMCParticleToHitsMap.at(pAssociatedMCParticle));
147 const CaloHitList &associatedMCHits(mcParticleCaloHitListPair.second);
149 if ((
PHOTON == pAssociatedMCParticle->GetParticleId()) || (E_MINUS ==
std::abs(pAssociatedMCParticle->GetParticleId())))
150 hitsShower += associatedMCHits.size();
152 hitsTrack += associatedMCHits.size();
154 if (associatedMCHits.size() > nHitsSharedWithBestMCParticleTotal)
156 nHitsSharedWithBestMCParticleTotal = associatedMCHits.size();
157 nHitsInBestMCParticleTotal = allMCHits.size();
158 bestMCParticlePdgCode = pAssociatedMCParticle->GetParticleId();
159 threeDVertexPosition = pAssociatedMCParticle->GetVertex();
163 const float trackShowerHitsRatio((hitsTrack + hitsShower) > 0 ? hitsTrack / (hitsTrack + hitsShower) : 0.
f);
164 const bool isTrueTrack(trackShowerHitsRatio >= 0.5);
166 const int nHitsInPfoTotal(pfoToReconstructable2DHitsMap.at(pPfo).size());
167 const float purity((nHitsInPfoTotal > 0) ? nHitsSharedWithBestMCParticleTotal / static_cast<float>(nHitsInPfoTotal) : 0.
f);
168 const float completeness(
169 (nHitsInBestMCParticleTotal > 0) ? nHitsSharedWithBestMCParticleTotal / static_cast<float>(nHitsInBestMCParticleTotal) : 0.
f);
171 CaloHitList checkHitListW;
173 CaloHitList checkHitListU;
175 CaloHitList checkHitListV;
177 CaloHitList checkHitListAll;
178 checkHitListAll.splice(checkHitListAll.end(), checkHitListW);
179 checkHitListAll.splice(checkHitListAll.end(), checkHitListU);
180 checkHitListAll.splice(checkHitListAll.end(), checkHitListV);
189 unsigned int showerCount(0), allCount(0);
190 for (
const CaloHit *pHit : checkHitListAll)
192 if (hitToMCMap.find(pHit) != hitToMCMap.end())
194 const MCParticle *pHitMCParticle(hitToMCMap.at(pHit));
195 if ((
PHOTON == pHitMCParticle->GetParticleId()) || (E_MINUS ==
std::abs(pHitMCParticle->GetParticleId())))
203 const float showerProbability(showerCount / static_cast<float>(allCount));
204 const bool mischaracterisedPfo((showerProbability < 0.5
f && !isTrueTrack) || (showerProbability > 0.5 && isTrueTrack) ?
true :
false);
205 const bool isMainMCParticleSet(bestMCParticlePdgCode != 0);
207 if (isMainMCParticleSet)
212 const std::string end = ((wClusterList.empty()) ?
"noChargeInfo.txt" :
".txt");
222 bool isTrueTrack(
false);
223 bool isMainMCParticleSet(
false);
228 isTrueTrack = ((
PHOTON != pMCParticle->GetParticleId()) && (E_MINUS !=
std::abs(pMCParticle->GetParticleId())));
229 isMainMCParticleSet = (pMCParticle->GetParticleId() != 0);
231 catch (
const StatusCodeException &)
235 if (isMainMCParticleSet)
238 outputFile.append(wClusterList.empty() ?
"noChargeInfo.txt" :
".txt");
247 if (!featureValue.IsInitialized())
251 object_creation::ParticleFlowObject::Metadata
metadata;
252 metadata.m_propertiesToAdd[
"TrackScore"] = -1.f;
253 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ParticleFlowObject::AlterMetadata(*
this, pPfo, metadata));
255 return (pPfo->GetParticleId() == MU_MINUS);
267 object_creation::ParticleFlowObject::Metadata
metadata;
268 metadata.m_propertiesToAdd[
"TrackScore"] =
score;
269 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ParticleFlowObject::AlterMetadata(*
this, pPfo, metadata));
bool m_enableProbability
Whether to use probabilities instead of binary classification.
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
std::string m_trainingOutputFile
The training output file.
static double CalculateProbability(const MvaInterface &classifier, TLISTS &&...featureLists)
Use the trained mva to calculate a classification probability for an example.
static bool IsThreeD(const pandora::ParticleFlowObject *const pPfo)
Does Pfo contain 3D clusters.
std::unordered_map< const pandora::MCParticle *, pandora::CaloHitList > MCContributionMap
std::string m_caloHitListName
Name of input calo hit list.
MvaTypes::MvaFeatureVector MvaFeatureVector
std::pair< const pandora::MCParticle *, pandora::CaloHitList > MCParticleCaloHitListPair
LArMCParticleHelper::PrimaryParameters m_primaryParameters
The mc particle primary selection parameters.
static void GetClusters(const pandora::PfoList &pfoList, const pandora::HitType &hitType, pandora::ClusterList &clusterList)
Get a list of clusters of a particular hit type from a list of pfos.
std::string m_mcParticleListName
Name of input MC particle list.
PfoCharacterisationFeatureTool::FeatureToolVector m_featureToolVectorThreeD
The feature tool map for 3D info.
bool m_testBeamMode
Whether the training set is from a test beam experiment.
T m_mvaNoChargeInfo
The mva for missing W view.
static void GetPfoToReconstructable2DHitsMap(const pandora::PfoList &pfoList, const MCContributionMap &selectedMCParticleToHitsMap, PfoContributionMap &pfoToReconstructable2DHitsMap, const bool foldBackHierarchy)
Get mapping from Pfo to reconstructable 2D hits (=good hits belonging to a selected reconstructable M...
std::unordered_map< const pandora::CaloHit *, const pandora::MCParticle * > CaloHitToMCMap
bool m_applyReconstructabilityChecks
Whether to apply reconstructability checks during training.
static void GetPfoMCParticleHitSharingMaps(const PfoContributionMap &pfoToReconstructable2DHitsMap, const MCContributionMapVector &selectedMCParticleToHitsMaps, PfoToMCParticleHitSharingMap &pfoToMCParticleHitSharingMap, MCParticleToPfoHitSharingMap &mcParticleToPfoHitSharingMap)
Get the mappings from Pfo -> pair (reconstructable MCparticles, number of reconstructable 2D hits sha...
static bool Classify(const MvaInterface &classifier, TLISTS &&...featureLists)
Use the trained classifier to predict the boolean class of an example.
std::map< const pandora::MCParticle *, PfoToSharedHitsVector > MCParticleToPfoHitSharingMap
bool m_applyFiducialCut
Whether to apply a fiducial volume cut during training.
bool m_foldBackHierarchy
whether to fold the hierarchy back to the primary (neutrino) or leading particles (test beam) ...
static void GetMCPrimaryMap(const pandora::MCParticleList *const pMCParticleList, MCRelationMap &mcPrimaryMap)
Get mapping from individual mc particles (in a provided list) and their primary parent mc particles...
static const pandora::MCParticle * GetMainMCParticle(const pandora::ParticleFlowObject *const pPfo)
Find the mc particle making the largest contribution to 2D clusters in a specified pfo...
MvaTypes::MvaFeature MvaFeature
static void SelectReconstructableMCParticles(const pandora::MCParticleList *pMCParticleList, const pandora::CaloHitList *pCaloHitList, const PrimaryParameters ¶meters, std::function< bool(const pandora::MCParticle *const)> fCriteria, MCContributionMap &selectedMCParticlesToHitsMap)
Select target, reconstructable mc particles that match given criteria.
static pandora::StatusCode ProduceTrainingExample(const std::string &trainingOutputFile, const bool result, TLISTS &&...featureLists)
Produce a training example with the given features and result.
static void GetMCParticleToCaloHitMatches(const pandora::CaloHitList *const pCaloHitList, const MCRelationMap &mcToTargetMCMap, CaloHitToMCMap &hitToMCMap, MCContributionMap &mcToTrueHitListMap)
Match calo hits to their parent particles.
static bool IsBeamParticle(const pandora::MCParticle *const pMCParticle)
Returns true if passed a primary beam MCParticle.
bool PassesFiducialCut(const pandora::CartesianVector &vertex) const
Checks if the interaction vertex is within the fiducial volume.
bool m_trainingSetMode
Whether to train.
std::vector< MCContributionMap > MCContributionMapVector
float m_minProbabilityCut
The minimum probability to label a cluster as track-like.
std::vector< MvaFeatureTool< Ts... > * > FeatureToolVector
PfoCharacterisationFeatureTool::FeatureToolVector m_featureToolVectorNoChargeInfo
The feature tool map for missing W view.
static MvaFeatureVector CalculateFeatures(const MvaFeatureToolVector< Ts... > &featureToolVector, TARGS &&...args)
Calculate the features in a given feature tool vector.
std::vector< MCParticleCaloHitListPair > MCParticleToSharedHitsVector
std::unordered_map< const pandora::ParticleFlowObject *, pandora::CaloHitList > PfoContributionMap
static void GetCaloHits(const pandora::PfoList &pfoList, const pandora::HitType &hitType, pandora::CaloHitList &caloHitList)
Get a list of calo hits of a particular hit type from a list of pfos.
static bool IsBeamNeutrinoFinalState(const pandora::MCParticle *const pMCParticle)
Returns true if passed a primary neutrino final state MCParticle.
std::unordered_map< const pandora::MCParticle *, const pandora::MCParticle * > MCRelationMap
std::map< const pandora::ParticleFlowObject *, MCParticleToSharedHitsVector > PfoToMCParticleHitSharingMap