9 #include "Pandora/AlgorithmHeaders.h" 11 #include "Persistency/BinaryFileWriter.h" 12 #include "Persistency/XmlFileWriter.h" 27 EventWritingAlgorithm::EventWritingAlgorithm() :
28 m_geometryFileType(UNKNOWN_FILE_TYPE),
29 m_eventFileType(UNKNOWN_FILE_TYPE),
30 m_pEventFileWriter(nullptr),
31 m_pGeometryFileWriter(nullptr),
32 m_shouldWriteGeometry(false),
33 m_writtenGeometry(false),
34 m_shouldWriteEvents(true),
35 m_shouldWriteMCRelationships(true),
36 m_shouldWriteTrackRelationships(true),
37 m_shouldOverwriteEventFile(false),
38 m_shouldOverwriteGeometryFile(false),
39 m_useLArCaloHits(true),
40 m_larCaloHitVersion(1),
41 m_useLArMCParticles(true),
42 m_shouldFilterByNuanceCode(false),
43 m_filterNuanceCode(0),
44 m_shouldFilterByMCParticles(false),
45 m_neutrinoInducedOnly(false),
46 m_matchingMinPrimaryHits(15),
53 m_shouldFilterByNeutrinoVertex(false),
54 m_detectorHalfLengthX(-1.
f),
55 m_detectorHalfLengthY(-1.
f),
56 m_detectorHalfLengthZ(-1.
f),
57 m_coordinateOffsetX(0.
f),
58 m_coordinateOffsetY(0.
f),
59 m_coordinateOffsetZ(0.
f),
60 m_selectedBorderX(-1.
f),
61 m_selectedBorderY(-1.
f),
62 m_selectedBorderZ(-1.
f)
92 return STATUS_CODE_FAILURE;
110 return STATUS_CODE_FAILURE;
120 return STATUS_CODE_SUCCESS;
140 const CaloHitList *pCaloHitList =
nullptr;
141 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetCurrentList(*
this, pCaloHitList));
143 const TrackList *pTrackList =
nullptr;
144 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetCurrentList(*
this, pTrackList));
146 const MCParticleList *pMCParticleList =
nullptr;
147 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetCurrentList(*
this, pMCParticleList));
149 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=,
153 return STATUS_CODE_SUCCESS;
160 const MCParticleList *pMCParticleList =
nullptr;
161 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetCurrentList(*
this, pMCParticleList));
166 for (
const MCParticle *
const pMCNeutrino : mcNeutrinoList)
181 const MCParticleList *pMCParticleList =
nullptr;
182 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetCurrentList(*
this, pMCParticleList));
184 const CaloHitList *pCaloHitList =
nullptr;
185 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetCurrentList(*
this, pCaloHitList));
200 unsigned int nNonNeutrons(0), nMuons(0), nElectrons(0), nProtons(0), nPhotons(0), nChargedPions(0);
203 for (
const auto &mapEntry : mcParticlesToGoodHitsMap)
204 mcPrimaryVector.push_back(mapEntry.first);
207 for (
const MCParticle *
const pMCPrimary : mcPrimaryVector)
209 const unsigned int particleId(
std::abs(pMCPrimary->GetParticleId()));
210 if (NEUTRON != particleId)
213 if (MU_MINUS == particleId)
215 else if (E_MINUS == particleId)
217 else if (PROTON == particleId)
219 else if (PHOTON == particleId)
221 else if (PI_PLUS == particleId)
238 const MCParticleList *pMCParticleList =
nullptr;
239 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetCurrentList(*
this, pMCParticleList));
244 for (
const MCParticle *
const pMCNeutrino : mcNeutrinoVector)
246 const CartesianVector &neutrinoInteractionVertex(pMCNeutrino->GetEndpoint());
266 PANDORA_RETURN_RESULT_IF_AND_IF(
267 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"ShouldWriteGeometry",
m_shouldWriteGeometry));
271 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
"GeometryFileName",
m_geometryFileName));
274 std::transform(fileExtension.begin(), fileExtension.end(), fileExtension.begin(), ::tolower);
276 if (std::string(
".xml") == fileExtension)
280 else if (std::string(
".pndr") == fileExtension)
286 std::cout <<
"EventReadingAlgorithm: Unknown geometry file type specified " << std::endl;
287 return STATUS_CODE_INVALID_PARAMETER;
291 PANDORA_RETURN_RESULT_IF_AND_IF(
292 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"ShouldWriteEvents",
m_shouldWriteEvents));
296 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
"EventFileName",
m_eventFileName));
299 std::transform(fileExtension.begin(), fileExtension.end(), fileExtension.begin(), ::tolower);
301 if (std::string(
".xml") == fileExtension)
305 else if (std::string(
".pndr") == fileExtension)
311 std::cout <<
"EventReadingAlgorithm: Unknown event file type specified " << std::endl;
312 return STATUS_CODE_INVALID_PARAMETER;
316 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
319 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
322 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
325 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
328 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"UseLArCaloHits",
m_useLArCaloHits));
330 PANDORA_RETURN_RESULT_IF_AND_IF(
331 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"LArCaloHitVersion",
m_larCaloHitVersion));
333 PANDORA_RETURN_RESULT_IF_AND_IF(
334 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"UseLArMCParticles",
m_useLArMCParticles));
336 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
339 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
342 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
347 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
"FilterNuanceCode",
m_filterNuanceCode));
352 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
"NeutrinoInducedOnly",
m_neutrinoInducedOnly));
353 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
"MatchingMinPrimaryHits",
m_matchingMinPrimaryHits));
354 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
"NNonNeutrons",
m_nNonNeutrons));
355 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
"NMuons",
m_nMuons));
356 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
"NElectrons",
m_nElectrons));
357 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
"NProtons",
m_nProtons));
358 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
"NPhotons",
m_nPhotons));
359 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
"NChargedPions",
m_nChargedPions));
364 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
"DetectorHalfLengthX",
m_detectorHalfLengthX));
365 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
"DetectorHalfLengthY",
m_detectorHalfLengthY));
366 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
"DetectorHalfLengthZ",
m_detectorHalfLengthZ));
367 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
"CoordinateOffsetX",
m_coordinateOffsetX));
368 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
"CoordinateOffsetY",
m_coordinateOffsetY));
369 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
"CoordinateOffsetZ",
m_coordinateOffsetZ));
370 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
"SelectedBorderX",
m_selectedBorderX));
371 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
"SelectedBorderY",
m_selectedBorderY));
372 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
"SelectedBorderZ",
m_selectedBorderZ));
375 return STATUS_CODE_SUCCESS;
float m_detectorHalfLengthZ
Half length of detector in z dimension.
unsigned int m_matchingMinPrimaryHits
The minimum number of mc primary hits used in matching scheme.
bool m_shouldWriteMCRelationships
Whether to write mc relationship information to the events file.
pandora::FileWriter * m_pEventFileWriter
Address of the event file writer.
Header file for the event writing algorithm class.
std::unordered_map< const pandora::MCParticle *, pandora::CaloHitList > MCContributionMap
bool m_shouldFilterByMCParticles
Whether to filter output by mc particle constituents.
bool m_shouldWriteEvents
Whether to write events to a specified file.
Header file for the lar calo hit class.
bool PassNeutrinoVertexFilter() const
Whether current event passes neutrino vertex position filter (e.g. fiducial volume cut) ...
bool m_useLArCaloHits
Whether to write lar calo hits, or standard pandora calo hits.
float m_coordinateOffsetY
Origin offset (from detector corner) in y dimension.
int GetNuanceCode() const
Get the nuance code.
bool m_neutrinoInducedOnly
Whether to consider only mc particles that were neutrino induced.
unsigned int m_larCaloHitVersion
LArCaloHit version for LArCaloHitFactory.
unsigned int m_nPhotons
The requested number of mc primaries that are photons.
unsigned int m_nProtons
The requested number of mc primaries that are protons.
constexpr auto abs(T v)
Returns the absolute value of the argument.
float m_selectedBorderY
Required distance from detector edge in y dimension.
float m_detectorHalfLengthY
Half length of detector in y dimension.
float m_selectedBorderZ
Required distance from detector edge in z dimension.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
std::string m_eventFileName
Name of the output event file.
Header file for the lar monitoring helper helper class.
pandora::FileType m_geometryFileType
The geometry file type.
~EventWritingAlgorithm()
Destructor.
unsigned int m_nChargedPions
The requested number of mc primaries that are charged pions.
bool PassNuanceCodeFilter() const
Whether current event passes nuance code filter.
bool m_shouldWriteTrackRelationships
Whether to write track relationship information to the events file.
bool m_useLArMCParticles
Whether to write lar mc particles, or standard pandora mc particles.
static bool SortByMomentum(const pandora::MCParticle *const pLhs, const pandora::MCParticle *const pRhs)
Sort mc particles by their momentum.
static bool IsCosmicRay(const pandora::MCParticle *const pMCParticle)
Return true if passed a primary cosmic ray MCParticle.
pandora::FileWriter * m_pGeometryFileWriter
Address of the geometry file writer.
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.
unsigned int m_nNonNeutrons
The requested number of mc primaries that are not neutrons.
Header file for the lar monte carlo particle helper helper class.
static bool IsBeamParticle(const pandora::MCParticle *const pMCParticle)
Returns true if passed a primary beam MCParticle.
float m_selectedBorderX
Required distance from detector edge in x dimension.
bool m_shouldFilterByNeutrinoVertex
Whether to filter output by neutrino vertex position (e.g. fiducial volume cut)
std::vector< art::Ptr< simb::MCParticle > > MCParticleVector
bool PassMCParticleFilter() const
Whether current event passes mc particle constituent filter.
int m_filterNuanceCode
The filter nuance code (required if specify filter by nuance code)
float m_detectorHalfLengthX
Half length of detector in x dimension.
Header file for the lar mc particle class.
unsigned int m_nElectrons
The requested number of mc primaries that are electrons.
LArMCParticleFactory responsible for object creation.
std::string m_geometryFileName
Name of the output geometry file.
static void GetTrueNeutrinos(const pandora::MCParticleList *const pMCParticleList, pandora::MCParticleVector &trueNeutrinos)
Get neutrino MC particles from an input MC particle list.
pandora::FileType m_eventFileType
The event file type.
bool m_shouldFilterByNuanceCode
Whether to filter output by nuance code.
bool m_shouldOverwriteEventFile
Whether to overwrite existing event file with specified name, or append.
pandora::StatusCode Initialize()
unsigned int m_nMuons
The requested number of mc primaries that are muons.
LArCaloHitFactory responsible for object creation.
bool m_shouldWriteGeometry
Whether to write geometry to a specified file.
bool m_shouldOverwriteGeometryFile
Whether to overwrite existing geometry file with specified name, or append.
float m_coordinateOffsetZ
Origin offset (from detector corner) in z dimension.
pandora::StatusCode Run()
static bool IsBeamNeutrinoFinalState(const pandora::MCParticle *const pMCParticle)
Returns true if passed a primary neutrino final state MCParticle.
bool m_writtenGeometry
Whether geometry has been written.
float m_coordinateOffsetX
Origin offset (from detector corner) in x dimension.