All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VertexMonitoringAlgorithm.cc
Go to the documentation of this file.
1 /**
2  * @file larpandoracontent/LArMonitoring/VertexMonitoringAlgorithm.cc
3  *
4  * @brief Implementation of the particle visualisation algorithm.
5  *
6  * $Log: $
7  */
8 
9 #include "Pandora/AlgorithmHeaders.h"
10 
12 
17 
18 using namespace pandora;
19 
20 namespace lar_content
21 {
22 
23 VertexMonitoringAlgorithm::VertexMonitoringAlgorithm() :
24  m_visualise{true},
25  m_writeFile{false},
26  m_transparencyThresholdE{-1.f},
27  m_energyScaleThresholdE{1.f},
28  m_scalingFactor{1.f}
29 {
30 }
31 
32 //------------------------------------------------------------------------------------------------------------------------------------------
33 
35 {
36  if (m_writeFile)
37  {
38  PANDORA_MONITORING_API(SaveTree(this->GetPandora(), m_treename.c_str(), m_filename.c_str(), "UPDATE"));
39  }
40 }
41 
42 //------------------------------------------------------------------------------------------------------------------------------------------
43 
45 {
46  if (m_visualise)
47  {
48  PANDORA_MONITORING_API(SetEveDisplayParameters(
49  this->GetPandora(), true, DETECTOR_VIEW_XZ, m_transparencyThresholdE, m_energyScaleThresholdE, m_scalingFactor));
50  }
51 
52  this->AssessVertices();
53 
54  if (m_visualise)
55  {
56  PANDORA_MONITORING_API(ViewEvent(this->GetPandora()));
57  }
58 
59  return STATUS_CODE_SUCCESS;
60 }
61 
62 //------------------------------------------------------------------------------------------------------------------------------------------
63 
65 {
66  const MCParticleList *pMCParticleList{nullptr};
67  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetCurrentList(*this, pMCParticleList));
68  const PfoList *pPfoList{nullptr};
69  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetCurrentList(*this, pPfoList));
70 
72  MCParticleVector primaries;
73  LArMCParticleHelper::GetPrimaryMCParticleList(pMCParticleList, primaries);
74  const MCParticle *pTrueNeutrino{nullptr};
75  const ParticleFlowObject *pRecoNeutrino{nullptr};
76  if (!primaries.empty())
77  {
78  for (const MCParticle *primary : primaries)
79  {
80  const MCParticleList &parents{primary->GetParentList()};
81  if (parents.size() == 1 && LArMCParticleHelper::IsNeutrino(parents.front()))
82  {
83  pTrueNeutrino = parents.front();
84  break;
85  }
86  }
87  }
88 
89  for (const ParticleFlowObject *pPfo : *pPfoList)
90  {
91  if (LArPfoHelper::IsNeutrino(pPfo))
92  {
93  pRecoNeutrino = pPfo;
94  break;
95  }
96  }
97 
98  if (pRecoNeutrino && pTrueNeutrino)
99  {
100  const LArTransformationPlugin *transform{this->GetPandora().GetPlugins()->GetLArTransformationPlugin()};
101  const CartesianVector &trueVertex{pTrueNeutrino->GetVertex()};
102  const CartesianVector &recoVertex{LArPfoHelper::GetVertex(pRecoNeutrino)->GetPosition()};
103  if (m_visualise)
104  {
105  const CartesianVector tu(trueVertex.GetX(), 0.f, static_cast<float>(transform->YZtoU(trueVertex.GetY(), trueVertex.GetZ())));
106  const CartesianVector tv(trueVertex.GetX(), 0.f, static_cast<float>(transform->YZtoV(trueVertex.GetY(), trueVertex.GetZ())));
107  const CartesianVector tw(trueVertex.GetX(), 0.f, static_cast<float>(transform->YZtoW(trueVertex.GetY(), trueVertex.GetZ())));
108 
109  const CartesianVector ru(recoVertex.GetX(), 0.f, static_cast<float>(transform->YZtoU(recoVertex.GetY(), recoVertex.GetZ())));
110  const CartesianVector rv(recoVertex.GetX(), 0.f, static_cast<float>(transform->YZtoV(recoVertex.GetY(), recoVertex.GetZ())));
111  const CartesianVector rw(recoVertex.GetX(), 0.f, static_cast<float>(transform->YZtoW(recoVertex.GetY(), recoVertex.GetZ())));
112 
113  const float du{(ru - tu).GetMagnitude()};
114  const float dv{(rv - tv).GetMagnitude()};
115  const float dw{(rw - tw).GetMagnitude()};
116 
117  std::cout << "delta(u, v, w): (" << du << ", " << dv << "," << dw << ")" << std::endl;
118 
119  PANDORA_MONITORING_API(AddMarkerToVisualization(this->GetPandora(), &tu, "U true vertex", BLUE, 2));
120  PANDORA_MONITORING_API(AddMarkerToVisualization(this->GetPandora(), &tv, "V true vertex", BLUE, 2));
121  PANDORA_MONITORING_API(AddMarkerToVisualization(this->GetPandora(), &tw, "W true vertex", BLUE, 2));
122  PANDORA_MONITORING_API(AddMarkerToVisualization(this->GetPandora(), &ru, "U reco vertex", RED, 2));
123  PANDORA_MONITORING_API(AddMarkerToVisualization(this->GetPandora(), &rv, "V reco vertex", RED, 2));
124  PANDORA_MONITORING_API(AddMarkerToVisualization(this->GetPandora(), &rw, "W reco vertex", RED, 2));
125  }
126 
127  if (m_writeFile && LArVertexHelper::IsInFiducialVolume(this->GetPandora(), trueVertex, "dune_fd_hd"))
128  {
129  const CartesianVector delta{recoVertex - trueVertex};
130  const float dx{delta.GetX()}, dy{delta.GetY()}, dz{delta.GetZ()}, dr{delta.GetMagnitude()};
131  const float trueNuEnergy{pTrueNeutrino->GetEnergy()};
132  const int success{1};
133  PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treename.c_str(), "success", success));
134  PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treename.c_str(), "trueNuEnergy", trueNuEnergy));
135  PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treename.c_str(), "dx", dx));
136  PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treename.c_str(), "dy", dy));
137  PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treename.c_str(), "dz", dz));
138  PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treename.c_str(), "dr", dr));
139  PANDORA_MONITORING_API(FillTree(this->GetPandora(), m_treename.c_str()));
140  }
141  }
142  else if (pTrueNeutrino)
143  {
144  const CartesianVector &trueVertex{pTrueNeutrino->GetVertex()};
145 
146  if (m_writeFile && LArVertexHelper::IsInFiducialVolume(this->GetPandora(), trueVertex, "dune_fd_hd"))
147  {
148  const int success{0};
149  const float dx{-999.f}, dy{-999.f}, dz{-999.f}, dr{-999.f};
150  const float trueNuEnergy{pTrueNeutrino->GetEnergy()};
151  PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treename.c_str(), "success", success));
152  PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treename.c_str(), "trueNuEnergy", trueNuEnergy));
153  PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treename.c_str(), "dx", dx));
154  PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treename.c_str(), "dy", dy));
155  PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treename.c_str(), "dz", dz));
156  PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treename.c_str(), "dr", dr));
157  PANDORA_MONITORING_API(FillTree(this->GetPandora(), m_treename.c_str()));
158  }
159  }
160 
161  return STATUS_CODE_SUCCESS;
162 }
163 
164 //------------------------------------------------------------------------------------------------------------------------------------------
165 
166 StatusCode VertexMonitoringAlgorithm::ReadSettings(const TiXmlHandle xmlHandle)
167 {
168  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "Visualize", m_visualise));
169  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "WriteFile", m_writeFile));
170  if (m_writeFile)
171  {
172  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "Filename", m_filename));
173  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "Treename", m_treename));
174  }
175 
176  PANDORA_RETURN_RESULT_IF_AND_IF(
177  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "TransparencyThresholdE", m_transparencyThresholdE));
178  PANDORA_RETURN_RESULT_IF_AND_IF(
179  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "EnergyScaleThresholdE", m_energyScaleThresholdE));
180  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "ScalingFactor", m_scalingFactor));
181 
182  return STATUS_CODE_SUCCESS;
183 }
184 
185 } // namespace lar_content
Header file for the pfo helper class.
std::unordered_map< const pandora::MCParticle *, pandora::CaloHitList > MCContributionMap
static constexpr Sample_t transform(Sample_t sample)
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
static const pandora::Vertex * GetVertex(const pandora::ParticleFlowObject *const pPfo)
Get the pfo vertex.
float m_energyScaleThresholdE
Cell energy for which color is at top end of continous color palette.
float m_scalingFactor
TEve works with [cm], Pandora usually works with [mm] (but LArContent went with cm too) ...
Header file for the geometry helper class.
Header file for the lar monte carlo particle helper helper class.
std::vector< art::Ptr< simb::MCParticle > > MCParticleVector
static bool IsNeutrino(const pandora::ParticleFlowObject *const pPfo)
Whether a pfo is a neutrino or (antineutrino)
static bool IsInFiducialVolume(const pandora::Pandora &pandora, const pandora::CartesianVector &vertex, const std::string &detector)
Determine if a vertex is within a detector&#39;s fiducial volume. This throws a STATUS_CODE_INVALID_PARAM...
Header file for the vertex helper class.
static void GetPrimaryMCParticleList(const pandora::MCParticleList *const pMCParticleList, pandora::MCParticleVector &mcPrimaryVector)
Get vector of primary MC particles from an input list of MC particles.
required by fuzzyCluster table::sbnd_g4_services gaushitTruthMatch pandora
Definition: reco_sbnd.fcl:182
Header file for the particle visualisation algorithm.
float m_transparencyThresholdE
Cell energy for which transparency is saturated (0%, fully opaque)
BEGIN_PROLOG could also be cout
static bool IsNeutrino(const pandora::MCParticle *const pMCParticle)
Whether a mc particle is a neutrino or antineutrino.