MvaPfoCharacterisationAlgorithm.cc
Go to the documentation of this file.
1 /**
2  * @file larpandoracontent/LArTrackShowerId/MvaPfoCharacterisationAlgorithm.cc
3  *
4  * @brief Implementation of the mva pfo characterisation algorithm class.
5  *
6  * $Log: $
7  */
8 
9 #include "Pandora/AlgorithmHeaders.h"
10 
13 
15 
17 
18 using namespace pandora;
19 
20 namespace lar_content
21 {
22 
23 template <typename T>
25  m_trainingSetMode(false),
26  m_testBeamMode(false),
27  m_enableProbability(true),
28  m_useThreeDInformation(true),
29  m_minProbabilityCut(0.5f),
30  m_minCaloHitsCut(5),
31  m_applyFiducialCut(false),
32  m_fiducialMinX(-std::numeric_limits<float>::max()),
33  m_fiducialMaxX(std::numeric_limits<float>::max()),
34  m_fiducialMinY(-std::numeric_limits<float>::max()),
35  m_fiducialMaxY(std::numeric_limits<float>::max()),
36  m_fiducialMinZ(-std::numeric_limits<float>::max()),
37  m_fiducialMaxZ(std::numeric_limits<float>::max()),
38  m_applyReconstructabilityChecks(false),
39  m_filePathEnvironmentVariable("FW_SEARCH_PATH")
40 {
41 }
42 
43 //------------------------------------------------------------------------------------------------------------------------------------------
44 
45 template <typename T>
46 bool MvaPfoCharacterisationAlgorithm<T>::IsClearTrack(const Cluster *const pCluster) const
47 {
48  if (pCluster->GetNCaloHits() < m_minCaloHitsCut)
49  return false;
50 
52 
54  {
55  bool isTrueTrack(false);
56 
57  try
58  {
59  const MCParticle *const pMCParticle(MCParticleHelper::GetMainMCParticle(pCluster));
60  isTrueTrack = ((PHOTON != pMCParticle->GetParticleId()) && (E_MINUS != std::abs(pMCParticle->GetParticleId())));
61  }
62  catch (const StatusCodeException &)
63  {
64  }
65 
67  return isTrueTrack;
68  }
69 
71  {
72  return LArMvaHelper::Classify(m_mva, featureVector);
73  }
74  else
75  {
77  }
78 }
79 
80 //------------------------------------------------------------------------------------------------------------------------------------------
81 
82 template <typename T>
83 bool MvaPfoCharacterisationAlgorithm<T>::IsClearTrack(const pandora::ParticleFlowObject *const pPfo) const
84 {
85  if (!LArPfoHelper::IsThreeD(pPfo))
86  {
88  {
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));
92  }
93  return (pPfo->GetParticleId() == MU_MINUS);
94  }
95 
96  // Charge related features are only calculated using hits in W view
97  ClusterList wClusterList;
98  LArPfoHelper::GetClusters(pPfo, TPC_VIEW_W, wClusterList);
99 
100  const PfoCharacterisationFeatureTool::FeatureToolVector &chosenFeatureToolVector(
102  const LArMvaHelper::MvaFeatureVector featureVector(LArMvaHelper::CalculateFeatures(chosenFeatureToolVector, this, pPfo));
103 
105  {
106  const MCParticleList *pMCParticleList(nullptr);
107  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetList(*this, m_mcParticleListName, pMCParticleList));
108 
109  const CaloHitList *pCaloHitList(nullptr);
110  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetList(*this, m_caloHitListName, pCaloHitList));
111 
112  // Mapping target MCParticles -> truth associated Hits
113  LArMCParticleHelper::MCContributionMap targetMCParticleToHitsMap;
114  if (!m_testBeamMode)
116  LArMCParticleHelper::IsBeamNeutrinoFinalState, targetMCParticleToHitsMap);
117  else
119  pMCParticleList, pCaloHitList, m_primaryParameters, LArMCParticleHelper::IsBeamParticle, targetMCParticleToHitsMap);
120 
121  LArMCParticleHelper::MCContributionMapVector mcParticlesToGoodHitsMaps({targetMCParticleToHitsMap});
122 
123  LArMCParticleHelper::PfoContributionMap pfoToReconstructable2DHitsMap;
125  PfoList(1, pPfo), mcParticlesToGoodHitsMaps, pfoToReconstructable2DHitsMap, m_primaryParameters.m_foldBackHierarchy);
126  if (pfoToReconstructable2DHitsMap.empty())
127  return false;
128 
129  LArMCParticleHelper::PfoToMCParticleHitSharingMap pfoToMCParticleHitSharingMap;
130  LArMCParticleHelper::MCParticleToPfoHitSharingMap mcParticleToPfoHitSharingMap;
132  pfoToReconstructable2DHitsMap, mcParticlesToGoodHitsMaps, pfoToMCParticleHitSharingMap, mcParticleToPfoHitSharingMap);
133  if (pfoToMCParticleHitSharingMap.empty())
134  return false;
135 
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);
141  const LArMCParticleHelper::MCParticleToSharedHitsVector &mcParticleToSharedHitsVector(pfoToMCParticleHitSharingMap.at(pPfo));
142 
143  for (const LArMCParticleHelper::MCParticleCaloHitListPair &mcParticleCaloHitListPair : mcParticleToSharedHitsVector)
144  {
145  const pandora::MCParticle *const pAssociatedMCParticle(mcParticleCaloHitListPair.first);
146  const CaloHitList &allMCHits(targetMCParticleToHitsMap.at(pAssociatedMCParticle));
147  const CaloHitList &associatedMCHits(mcParticleCaloHitListPair.second);
148 
149  if ((PHOTON == pAssociatedMCParticle->GetParticleId()) || (E_MINUS == std::abs(pAssociatedMCParticle->GetParticleId())))
150  hitsShower += associatedMCHits.size();
151  else
152  hitsTrack += associatedMCHits.size();
153 
154  if (associatedMCHits.size() > nHitsSharedWithBestMCParticleTotal)
155  {
156  nHitsSharedWithBestMCParticleTotal = associatedMCHits.size();
157  nHitsInBestMCParticleTotal = allMCHits.size();
158  bestMCParticlePdgCode = pAssociatedMCParticle->GetParticleId();
159  threeDVertexPosition = pAssociatedMCParticle->GetVertex();
160  }
161  }
162 
163  const float trackShowerHitsRatio((hitsTrack + hitsShower) > 0 ? hitsTrack / (hitsTrack + hitsShower) : 0.f);
164  const bool isTrueTrack(trackShowerHitsRatio >= 0.5);
165 
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);
170 
171  CaloHitList checkHitListW;
172  LArPfoHelper::GetCaloHits(pPfo, TPC_VIEW_W, checkHitListW);
173  CaloHitList checkHitListU;
174  LArPfoHelper::GetCaloHits(pPfo, TPC_VIEW_U, checkHitListU);
175  CaloHitList checkHitListV;
176  LArPfoHelper::GetCaloHits(pPfo, TPC_VIEW_V, checkHitListV);
177  CaloHitList checkHitListAll;
178  checkHitListAll.splice(checkHitListAll.end(), checkHitListW);
179  checkHitListAll.splice(checkHitListAll.end(), checkHitListU);
180  checkHitListAll.splice(checkHitListAll.end(), checkHitListV);
181 
183  LArMCParticleHelper::GetMCPrimaryMap(pMCParticleList, mcPrimaryMap);
184 
185  LArMCParticleHelper::MCContributionMap mcToTrueHitListMap;
187  LArMCParticleHelper::GetMCParticleToCaloHitMatches(&checkHitListAll, mcPrimaryMap, hitToMCMap, mcToTrueHitListMap);
188 
189  unsigned int showerCount(0), allCount(0);
190  for (const CaloHit *pHit : checkHitListAll)
191  {
192  if (hitToMCMap.find(pHit) != hitToMCMap.end())
193  {
194  const MCParticle *pHitMCParticle(hitToMCMap.at(pHit));
195  if ((PHOTON == pHitMCParticle->GetParticleId()) || (E_MINUS == std::abs(pHitMCParticle->GetParticleId())))
196  ++showerCount;
197  ++allCount;
198  }
199  }
200 
201  if (allCount == 0)
202  return false;
203  const float showerProbability(showerCount / static_cast<float>(allCount));
204  const bool mischaracterisedPfo((showerProbability < 0.5f && !isTrueTrack) || (showerProbability > 0.5 && isTrueTrack) ? true : false);
205  const bool isMainMCParticleSet(bestMCParticlePdgCode != 0);
206 
207  if (isMainMCParticleSet)
208  {
209  if (completeness >= 0.f && purity >= 0.f && !mischaracterisedPfo && (!m_applyFiducialCut || this->PassesFiducialCut(threeDVertexPosition)))
210  {
212  const std::string end = ((wClusterList.empty()) ? "noChargeInfo.txt" : ".txt");
213  outputFile.append(end);
214  LArMvaHelper::ProduceTrainingExample(outputFile, isTrueTrack, featureVector);
215  }
216  }
217 
218  return isTrueTrack;
219  }
220  else if (m_trainingSetMode)
221  {
222  bool isTrueTrack(false);
223  bool isMainMCParticleSet(false);
224 
225  try
226  {
227  const MCParticle *const pMCParticle(LArMCParticleHelper::GetMainMCParticle(pPfo));
228  isTrueTrack = ((PHOTON != pMCParticle->GetParticleId()) && (E_MINUS != std::abs(pMCParticle->GetParticleId())));
229  isMainMCParticleSet = (pMCParticle->GetParticleId() != 0);
230  }
231  catch (const StatusCodeException &)
232  {
233  }
234 
235  if (isMainMCParticleSet)
236  {
238  outputFile.append(wClusterList.empty() ? "noChargeInfo.txt" : ".txt");
239  LArMvaHelper::ProduceTrainingExample(outputFile, isTrueTrack, featureVector);
240  }
241 
242  return isTrueTrack;
243  }
244 
245  for (const LArMvaHelper::MvaFeature &featureValue : featureVector)
246  {
247  if (!featureValue.IsInitialized())
248  {
250  {
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));
254  }
255  return (pPfo->GetParticleId() == MU_MINUS);
256  }
257  }
258 
259  // If no failures, proceed with MvaPfoCharacterisationAlgorithm classification
260  if (!m_enableProbability)
261  {
262  return LArMvaHelper::Classify((wClusterList.empty() ? m_mvaNoChargeInfo : m_mva), featureVector);
263  }
264  else
265  {
266  const double score(LArMvaHelper::CalculateProbability((wClusterList.empty() ? m_mvaNoChargeInfo : m_mva), featureVector));
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));
270  return (m_minProbabilityCut <= score);
271  }
272 }
273 
274 //------------------------------------------------------------------------------------------------------------------------------------------
275 
276 template <typename T>
277 StatusCode MvaPfoCharacterisationAlgorithm<T>::ReadSettings(const TiXmlHandle xmlHandle)
278 {
279  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
280  XmlHelper::ReadValue(xmlHandle, "MinPrimaryGoodHits", m_primaryParameters.m_minPrimaryGoodHits));
281 
282  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
283  XmlHelper::ReadValue(xmlHandle, "MinHitsForGoodView", m_primaryParameters.m_minHitsForGoodView));
284 
285  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
286  XmlHelper::ReadValue(xmlHandle, "MinPrimaryGoodViews", m_primaryParameters.m_minPrimaryGoodViews));
287 
288  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
289  XmlHelper::ReadValue(xmlHandle, "SelectInputHits", m_primaryParameters.m_selectInputHits));
290 
291  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
292  XmlHelper::ReadValue(xmlHandle, "MinHitSharingFraction", m_primaryParameters.m_minHitSharingFraction));
293 
294  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
295  XmlHelper::ReadValue(xmlHandle, "MaxPhotonPropagation", m_primaryParameters.m_maxPhotonPropagation));
296 
297  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
298  XmlHelper::ReadValue(xmlHandle, "FoldToPrimaries", m_primaryParameters.m_foldBackHierarchy));
299 
300  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "TrainingSetMode", m_trainingSetMode));
301 
302  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MinCaloHitsCut", m_minCaloHitsCut));
303 
304  PANDORA_RETURN_RESULT_IF_AND_IF(
305  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "UseThreeDInformation", m_useThreeDInformation));
306 
307  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
308  XmlHelper::ReadValue(xmlHandle, "FilePathEnvironmentVariable", m_filePathEnvironmentVariable));
309 
310  // ATTN Support legacy XML configurations (note an order of precedence of XML keys exists)
311  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "BdtFileName", m_mvaFileName));
312  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "SvmFileName", m_mvaFileName));
313  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MvaFileName", m_mvaFileName));
314 
315  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "BdtName", m_mvaName));
316  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "SvmName", m_mvaName));
317  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MvaName", m_mvaName));
318 
320  {
321  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
322  XmlHelper::ReadValue(xmlHandle, "BdtFileNameNoChargeInfo", m_mvaFileNameNoChargeInfo));
323  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
324  XmlHelper::ReadValue(xmlHandle, "SvmFileNameNoChargeInfo", m_mvaFileNameNoChargeInfo));
325  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
326  XmlHelper::ReadValue(xmlHandle, "MvaFileNameNoChargeInfo", m_mvaFileNameNoChargeInfo));
327 
328  PANDORA_RETURN_RESULT_IF_AND_IF(
329  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "BdtNameNoChargeInfo", m_mvaNameNoChargeInfo));
330  PANDORA_RETURN_RESULT_IF_AND_IF(
331  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "SvmNameNoChargeInfo", m_mvaNameNoChargeInfo));
332  PANDORA_RETURN_RESULT_IF_AND_IF(
333  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MvaNameNoChargeInfo", m_mvaNameNoChargeInfo));
334  }
335 
336  PANDORA_RETURN_RESULT_IF_AND_IF(
337  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "EnableProbability", m_enableProbability));
338 
339  PANDORA_RETURN_RESULT_IF_AND_IF(
340  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MinProbabilityCut", m_minProbabilityCut));
341 
342  if (m_trainingSetMode)
343  {
344  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "CaloHitListName", m_caloHitListName));
345  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "MCParticleListName", m_mcParticleListName));
346  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "TrainingOutputFileName", m_trainingOutputFile));
347  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "TestBeamMode", m_testBeamMode));
348  PANDORA_RETURN_RESULT_IF_AND_IF(
349  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "ApplyFiducialCut", m_applyFiducialCut));
350  if (m_applyFiducialCut)
351  {
352  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "FiducialCutMinX", m_fiducialMinX));
353  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "FiducialCutMaxX", m_fiducialMaxX));
354  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "FiducialCutMinY", m_fiducialMinY));
355  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "FiducialCutMaxY", m_fiducialMaxY));
356  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "FiducialCutMinZ", m_fiducialMinZ));
357  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "FiducialCutMaxZ", m_fiducialMaxZ));
358  }
359  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
360  XmlHelper::ReadValue(xmlHandle, "ApplyReconstructabilityChecks", m_applyReconstructabilityChecks));
361  }
362  else
363  {
364  if (m_mvaFileName.empty() || m_mvaName.empty())
365  {
366  std::cout << "MvaPfoCharacterisationAlgorithm: MvaFileName and MvaName must be set if in classification mode " << std::endl;
367  return STATUS_CODE_INVALID_PARAMETER;
368  }
369 
371  m_mva.Initialize(fullMvaFileName, m_mvaName);
372 
374  {
375  if (m_mvaFileNameNoChargeInfo.empty() || m_mvaNameNoChargeInfo.empty())
376  {
377  std::cout << "MvaPfoCharacterisationAlgorithm: MvaFileNameNoChargeInfo and MvaNameNoChargeInfo must be set if in classification mode for no charge info in 3D mode "
378  << std::endl;
379  return STATUS_CODE_INVALID_PARAMETER;
380  }
382  m_mvaNoChargeInfo.Initialize(fullMvaFileNameNoChargeInfo, m_mvaNameNoChargeInfo);
383  }
384  }
385 
386  AlgorithmToolVector algorithmToolVector;
387  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ProcessAlgorithmToolList(*this, xmlHandle, "FeatureTools", algorithmToolVector));
388 
390  {
391  AlgorithmToolVector algorithmToolVectorNoChargeInfo;
392  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=,
393  XmlHelper::ProcessAlgorithmToolList(*this, xmlHandle, "FeatureToolsNoChargeInfo", algorithmToolVectorNoChargeInfo));
394 
395  for (AlgorithmTool *const pAlgorithmTool : algorithmToolVector)
396  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, LArMvaHelper::AddFeatureToolToVector(pAlgorithmTool, m_featureToolVectorThreeD));
397 
398  for (AlgorithmTool *const pAlgorithmTool : algorithmToolVectorNoChargeInfo)
399  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, LArMvaHelper::AddFeatureToolToVector(pAlgorithmTool, m_featureToolVectorNoChargeInfo));
400  }
401  else
402  {
403  for (AlgorithmTool *const pAlgorithmTool : algorithmToolVector)
404  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, LArMvaHelper::AddFeatureToolToVector(pAlgorithmTool, m_featureToolVector));
405  }
406 
408 }
409 
410 //------------------------------------------------------------------------------------------------------------------------------------------
411 
412 template <typename T>
414 {
415  const float vx(vertex.GetX()), vy(vertex.GetY()), vz(vertex.GetZ());
416  return m_fiducialMinX <= vx && vx <= m_fiducialMaxX && m_fiducialMinY <= vy && vy <= m_fiducialMaxY && m_fiducialMinZ <= vz && vz <= m_fiducialMaxZ;
417 }
418 
421 
422 } // namespace lar_content
Header file for the mva pfo characterisation algorithm class.
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.
Definition: LArMvaHelper.h:236
unsigned int m_minPrimaryGoodViews
the minimum number of primary good views
static bool IsThreeD(const pandora::ParticleFlowObject *const pPfo)
Does Pfo contain 3D clusters.
Header file for the pfo helper class.
std::unordered_map< const pandora::MCParticle *, pandora::CaloHitList > MCContributionMap
std::string m_caloHitListName
Name of input calo hit list.
bool m_selectInputHits
whether to select input hits
MvaTypes::MvaFeatureVector MvaFeatureVector
Definition: LArMvaHelper.h:58
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 string
Definition: nybbler.cc:12
std::string m_mcParticleListName
Name of input MC particle list.
PfoCharacterisationFeatureTool::FeatureToolVector m_featureToolVectorThreeD
The feature tool map for 3D info.
unsigned int m_minCaloHitsCut
The minimum number of calo hits to qualify as a track.
bool m_testBeamMode
Whether the training set is from a test beam experiment.
unsigned int m_minPrimaryGoodHits
the minimum number of primary good Hits
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...
STL namespace.
static bool Classify(const MvaInterface &classifier, TLISTS &&...featureLists)
Use the trained classifier to predict the boolean class of an example.
Definition: LArMvaHelper.h:220
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...
unsigned int m_minHitsForGoodView
the minimum number of Hits for a good view
float m_maxPhotonPropagation
the maximum photon propagation length
T abs(T value)
static void SelectReconstructableMCParticles(const pandora::MCParticleList *pMCParticleList, const pandora::CaloHitList *pCaloHitList, const PrimaryParameters &parameters, 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.
Definition: LArMvaHelper.h:197
InitializedDouble class used to define mva features.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
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.
std::string m_mvaNameNoChargeInfo
The name of the mva to find for PFOs missing the W view, and thus charge info.
Header file for the lar two dimensional sliding fit result class.
ClusterCharacterisationFeatureTool::FeatureToolVector m_featureToolVector
The feature tool map.
bool PassesFiducialCut(const pandora::CartesianVector &vertex) const
Checks if the interaction vertex is within the fiducial volume.
std::string m_mvaName
The name of the mva to find.
static pandora::StatusCode AddFeatureToolToVector(pandora::AlgorithmTool *const pFeatureTool, MvaFeatureToolVector< Ts... > &featureToolVector)
Add a feature tool to a vector of feature tools.
Definition: LArMvaHelper.h:274
static std::string FindFileInPath(const std::string &unqualifiedFileName, const std::string &environmentVariable, const std::string &delimiter=":")
Find the fully-qualified file name by searching through a list of delimiter-separated paths in a name...
Header file for the file helper class.
static int max(int a, int b)
float m_minHitSharingFraction
the minimum Hit sharing fraction
std::vector< MCContributionMap > MCContributionMapVector
float m_minProbabilityCut
The minimum probability to label a cluster as track-like.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
std::string m_mvaFileNameNoChargeInfo
The mva input file for PFOs missing the W view, and thus charge info.
virtual bool IsClearTrack(const pandora::ParticleFlowObject *const pPfo) const
Whether pfo is identified as a clear track.
std::vector< MvaFeatureTool< Ts... > * > FeatureToolVector
Definition: LArMvaHelper.h:30
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.
Definition: LArMvaHelper.h:244
std::vector< MCParticleCaloHitListPair > MCParticleToSharedHitsVector
std::string m_filePathEnvironmentVariable
The environment variable providing a list of paths to mva files.
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
bool m_useThreeDInformation
Whether to use 3D information.
QTextStream & endl(QTextStream &s)
vertex reconstruction