CosmicRayTaggingTool.h
Go to the documentation of this file.
1 /**
2  * @file larpandoracontent/LArControlFlow/CosmicRayTaggingTool.h
3  *
4  * @brief Header file for the cosmic-ray tagging tool class.
5  *
6  * $Log: $
7  */
8 #ifndef LAR_COSMIC_RAY_TAGGING_TOOL_H
9 #define LAR_COSMIC_RAY_TAGGING_TOOL_H 1
10 
12 
14 
15 #include <unordered_map>
16 
17 namespace lar_content
18 {
19 
20 /**
21  * @brief CosmicRayTaggingTool class
22  */
24 {
25 public:
26  /**
27  * @brief Default constructor
28  */
30 
31  pandora::StatusCode Initialize();
32  void FindAmbiguousPfos(const pandora::PfoList &parentCosmicRayPfos, pandora::PfoList &ambiguousPfos, const MasterAlgorithm *const pAlgorithm);
33 
34 private:
35  /**
36  * @brief Class to encapsulate the logic required determine if a Pfo should or shouldn't be tagged as a cosmic ray
37  */
39  {
40  public:
41  /**
42  * @brief Constructor
43  *
44  * @param pandora the relevant pandora instance
45  * @param pPfo the address of the candidate pfo
46  * @param slice the slice id
47  */
48  CRCandidate(const pandora::Pandora &pandora, const pandora::ParticleFlowObject *const pPfo, const unsigned int sliceId);
49 
50  const pandora::ParticleFlowObject *const m_pPfo; ///< Address of the candidate Pfo
51  unsigned int m_sliceId; ///< Slice ID
52  bool m_canFit; ///< If there are a sufficient number of 3D hits to perform a fitting
53  pandora::CartesianVector m_endPoint1; ///< First fitted end point in 3D
54  pandora::CartesianVector m_endPoint2; ///< Second fitted end point in 3D
55  double m_length; ///< Straight line length of the linear fit
56  double m_curvature; ///< Measure of the curvature of the track
57  double m_theta; ///< Direction made with vertical
58 
59  private:
60  /**
61  * @brief Calculate all variables which require a fit
62  *
63  * @param slidingFitResult the three dimensional sliding fit result
64  */
65  void CalculateFitVariables(const ThreeDSlidingFitResult &slidingFitResult);
66  };
67 
68  typedef std::list<CRCandidate> CRCandidateList;
69 
70  /**
71  * @brief Get the 3D calo hit cluster associated with a given Pfo, and check if it has sufficient hits
72  *
73  * @param pPfo input Pfo
74  * @param pCluster3D to receive the address of the 3D cluster
75  *
76  * @return whether the Pfo has sufficient hits?
77  */
78  bool GetValid3DCluster(const pandora::ParticleFlowObject *const pPfo, const pandora::Cluster *&pCluster3D) const;
79 
80  typedef std::unordered_map<const pandora::ParticleFlowObject *, pandora::PfoList> PfoToPfoListMap;
81 
82  /**
83  * @brief Get mapping between Pfos that are associated with it other by pointing
84  *
85  * @param parentCosmicRayPfos input list of Pfos
86  * @param pfoAssociationsMap to receive the output mapping between associated Pfos
87  */
88  void GetPfoAssociations(const pandora::PfoList &parentCosmicRayPfos, PfoToPfoListMap &pfoAssociationMap) const;
89 
90  /**
91  * @brief Check whethe two Pfo endpoints are associated by distance of closest approach
92  *
93  * @param endPoint1 position vector of an endpoint of Pfo 1
94  * @param endDir1 direction vector of an endpoint of Pfo 1
95  * @param endPoint2 position vector of an endpoint of Pfo 2
96  * @param endDir2 direction vector of an endpoint of Pfos
97  *
98  * @return whether the Pfos are associated
99  */
100  bool CheckAssociation(const pandora::CartesianVector &endPoint1, const pandora::CartesianVector &endDir1,
101  const pandora::CartesianVector &endPoint2, const pandora::CartesianVector &endDir2) const;
102 
103  typedef std::unordered_map<const pandora::ParticleFlowObject *, unsigned int> PfoToSliceIdMap;
104 
105  /**
106  * @brief Break the event up into slices of associated Pfos
107  *
108  * @param parentCosmicRayPfos input list of Pfos
109  * @param pfoAssociationMap mapping between Pfos and other associated Pfos
110  * @param pfoToSliceIdMap to receive the mapping between Pfos and their slice ID
111  */
112  void SliceEvent(const pandora::PfoList &parentCosmicRayPfos, const PfoToPfoListMap &pfoAssociationMap, PfoToSliceIdMap &pfoToSliceIdMap) const;
113 
114  /**
115  * @brief Fill a slice iteratively using Pfo associations
116  *
117  * @param pPfo Pfo to add to the slice
118  * @param pfoAssociationMap mapping between Pfos and other associated Pfos
119  * @param slice the slice to add Pfos to
120  */
121  void FillSlice(const pandora::ParticleFlowObject *const pPfo, const PfoToPfoListMap &pfoAssociationMap, pandora::PfoList &slice) const;
122 
123  /**
124  * @brief Make a list of CRCandidates
125  *
126  * @param parentCosmicRayPfos input list of Pfos
127  * @param pfoToSliceIdMap input mapping between Pfos and their slice id
128  * @param candidates to receive the output list of CRCandidates
129  */
130  void GetCRCandidates(const pandora::PfoList &parentCosmicRayPfos, const PfoToSliceIdMap &pfoToSliceIdMap, CRCandidateList &candidates) const;
131 
132  typedef std::unordered_map<const pandora::ParticleFlowObject *, bool> PfoToBoolMap;
133 
134  /**
135  * @brief Check if each candidate is "in time"
136  *
137  * @param candidates input list of candidates
138  * @param pfoToInTimeMap output mapping between candidates Pfos and if they are in time
139  */
140  void CheckIfInTime(const CRCandidateList &candidates, PfoToBoolMap &pfoToInTimeMap) const;
141 
142  /**
143  * @brief Check if each candidate is "contained" (contained = no associations to Y or Z detector faces, but the Pfo could still enter or exit by and X-face)
144  *
145  * @param candidates input list of candidates
146  * @param pfoToIsContainedMap output mapping between candidates Pfos and if they are contained
147  */
148  void CheckIfContained(const CRCandidateList &candidates, PfoToBoolMap &pfoToIsContainedMap) const;
149 
150  /**
151  * @brief Check if each candidate is "top to bottom"
152  *
153  * @param candidates input list of candidates
154  * @param pfoToIsTopToBottomMap output mapping between candidates Pfos and if they are top to bottom
155  */
156  void CheckIfTopToBottom(const CRCandidateList &candidates, PfoToBoolMap &pfoToIsTopToBottomMap) const;
157 
158  typedef std::set<unsigned int> UIntSet;
159  typedef std::unordered_map<int, bool> IntBoolMap;
160 
161  /**
162  * @brief Get the slice indices which contain a likely neutrino Pfo
163  *
164  * @param candidates input list of candidates
165  * @param pfoToInTimeMap input map between Pfo and if in time
166  * @param pfoToIsContainedMap input map between Pfo and if contained
167  * @param neutrinoSliceSet output set of slice indices containing a likely neutrino Pfo
168  */
169  void GetNeutrinoSlices(const CRCandidateList &candidates, const PfoToBoolMap &pfoToInTimeMap, const PfoToBoolMap &pfoToIsContainedMap,
170  UIntSet &neutrinoSliceSet) const;
171 
172  /**
173  * @brief Tag Pfos which are likely to be a CR muon
174  *
175  * @param candidates input list of candidates
176  * @param pfoToInTimeMap input map between Pfo and if in time
177  * @param pfoToIsTopToBottomMap input mapping between candidate Pfos and if they are top to bottom
178  * @param neutrinoSliceSet input set of slice indices containing a likely neutrino Pfo
179  * @param pfoToIsLikelyCRMuonMap to receive the output mapping between Pfos and a boolean deciding if they are likely a CR muon
180  */
181  void TagCRMuons(const CRCandidateList &candidates, const PfoToBoolMap &pfoToInTimeMap, const PfoToBoolMap &pfoToIsTopToBottomMap,
182  const UIntSet &neutrinoSliceSet, PfoToBoolMap &pfoToIsLikelyCRMuonMap) const;
183 
184  pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle);
185 
186  typedef std::pair<const ThreeDSlidingFitResult, const ThreeDSlidingFitResult> SlidingFitPair;
187  typedef std::unordered_map<const pandora::ParticleFlowObject *, SlidingFitPair> PfoToSlidingFitsMap;
188  typedef std::vector<pandora::PfoList> SliceList;
189 
190  /**
191  * @brief Choose a set of cuts using a keyword - "cautious" = remove as few neutrinos as possible
192  * "nominal" = optimised to maximise CR removal whilst preserving neutrinos
193  * "aggressive" = remove CR muons and allow more neutrinos to be tagged
194  */
196 
197  float m_angularUncertainty; ///< The uncertainty in degrees for the angle of a Pfo
198  float m_positionalUncertainty; ///< The uncertainty in cm for the position of Pfo endpoint in 3D
199  float m_maxAssociationDist; ///< The maximum distance from endpoint to point of closest approach, typically a multiple of LAr radiation length
200 
201  unsigned int m_minimumHits; ///< The minimum number of hits for a Pfo to be considered
202 
203  float m_inTimeMargin; ///< The maximum distance outside of the physical detector volume that a Pfo may be to still be considered in time
204  float m_inTimeMaxX0; ///< The maximum pfo x0 (determined from shifted vertex) to allow pfo to still be considered in time
205  float m_marginY; ///< The minimum distance from a detector Y-face for a Pfo to be associated
206  float m_marginZ; ///< The minimum distance from a detector Z-face for a Pfo to be associated
207  float m_maxNeutrinoCosTheta; ///< The maximum cos(theta) that a Pfo can have to be classified as a likely neutrino
208  float m_minCosmicCosTheta; ///< The minimum cos(theta) that a Pfo can have to be classified as a likely CR muon
209  float m_maxCosmicCurvature; ///< The maximum curvature that a Pfo can have to be classified as a likely CR muon
210 
211  float m_face_Xa; ///< Anode X face
212  float m_face_Xc; ///< Cathode X face
213  float m_face_Yb; ///< Bottom Y face
214  float m_face_Yt; ///< Top Y face
215  float m_face_Zu; ///< Upstream Z face
216  float m_face_Zd; ///< Downstream Z face
217 };
218 
219 } // namespace lar_content
220 
221 #endif // #ifndef LAR_COSMIC_RAY_TAGGING_TOOL_H
std::unordered_map< const pandora::ParticleFlowObject *, pandora::PfoList > PfoToPfoListMap
std::unordered_map< const pandora::ParticleFlowObject *, bool > PfoToBoolMap
void FindAmbiguousPfos(const pandora::PfoList &parentCosmicRayPfos, pandora::PfoList &ambiguousPfos, const MasterAlgorithm *const pAlgorithm)
Find the list of ambiguous pfos (could represent cosmic-ray muons or neutrinos)
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
void TagCRMuons(const CRCandidateList &candidates, const PfoToBoolMap &pfoToInTimeMap, const PfoToBoolMap &pfoToIsTopToBottomMap, const UIntSet &neutrinoSliceSet, PfoToBoolMap &pfoToIsLikelyCRMuonMap) const
Tag Pfos which are likely to be a CR muon.
std::unordered_map< const pandora::ParticleFlowObject *, unsigned int > PfoToSliceIdMap
float m_maxNeutrinoCosTheta
The maximum cos(theta) that a Pfo can have to be classified as a likely neutrino. ...
CosmicRayTaggingBaseTool class.
std::string string
Definition: nybbler.cc:12
void SliceEvent(const pandora::PfoList &parentCosmicRayPfos, const PfoToPfoListMap &pfoAssociationMap, PfoToSliceIdMap &pfoToSliceIdMap) const
Break the event up into slices of associated Pfos.
bool CheckAssociation(const pandora::CartesianVector &endPoint1, const pandora::CartesianVector &endDir1, const pandora::CartesianVector &endPoint2, const pandora::CartesianVector &endDir2) const
Check whethe two Pfo endpoints are associated by distance of closest approach.
CosmicRayTaggingTool class.
float m_positionalUncertainty
The uncertainty in cm for the position of Pfo endpoint in 3D.
void CheckIfTopToBottom(const CRCandidateList &candidates, PfoToBoolMap &pfoToIsTopToBottomMap) const
Check if each candidate is "top to bottom".
double m_theta
Direction made with vertical.
bool m_canFit
If there are a sufficient number of 3D hits to perform a fitting.
Class to encapsulate the logic required determine if a Pfo should or shouldn&#39;t be tagged as a cosmic ...
void CheckIfContained(const CRCandidateList &candidates, PfoToBoolMap &pfoToIsContainedMap) const
Check if each candidate is "contained" (contained = no associations to Y or Z detector faces...
float m_angularUncertainty
The uncertainty in degrees for the angle of a Pfo.
CRCandidate(const pandora::Pandora &pandora, const pandora::ParticleFlowObject *const pPfo, const unsigned int sliceId)
Constructor.
void FillSlice(const pandora::ParticleFlowObject *const pPfo, const PfoToPfoListMap &pfoAssociationMap, pandora::PfoList &slice) const
Fill a slice iteratively using Pfo associations.
std::string m_cutMode
Choose a set of cuts using a keyword - "cautious" = remove as few neutrinos as possible "nominal" = o...
std::list< CRCandidate > CRCandidateList
double m_length
Straight line length of the linear fit.
float m_inTimeMaxX0
The maximum pfo x0 (determined from shifted vertex) to allow pfo to still be considered in time...
Header file for the master algorithm class.
void CheckIfInTime(const CRCandidateList &candidates, PfoToBoolMap &pfoToInTimeMap) const
Check if each candidate is "in time".
CosmicRayTaggingTool()
Default constructor.
pandora::CartesianVector m_endPoint2
Second fitted end point in 3D.
float m_inTimeMargin
The maximum distance outside of the physical detector volume that a Pfo may be to still be considered...
double m_curvature
Measure of the curvature of the track.
void CalculateFitVariables(const ThreeDSlidingFitResult &slidingFitResult)
Calculate all variables which require a fit.
void GetPfoAssociations(const pandora::PfoList &parentCosmicRayPfos, PfoToPfoListMap &pfoAssociationMap) const
Get mapping between Pfos that are associated with it other by pointing.
float m_minCosmicCosTheta
The minimum cos(theta) that a Pfo can have to be classified as a likely CR muon.
bool GetValid3DCluster(const pandora::ParticleFlowObject *const pPfo, const pandora::Cluster *&pCluster3D) const
Get the 3D calo hit cluster associated with a given Pfo, and check if it has sufficient hits...
Header file for the lar three dimensional sliding fit result class.
std::vector< pandora::PfoList > SliceList
std::unordered_map< int, bool > IntBoolMap
float m_marginZ
The minimum distance from a detector Z-face for a Pfo to be associated.
float m_marginY
The minimum distance from a detector Y-face for a Pfo to be associated.
float m_maxCosmicCurvature
The maximum curvature that a Pfo can have to be classified as a likely CR muon.
MasterAlgorithm class.
float m_maxAssociationDist
The maximum distance from endpoint to point of closest approach, typically a multiple of LAr radiatio...
unsigned int m_minimumHits
The minimum number of hits for a Pfo to be considered.
std::unordered_map< const pandora::ParticleFlowObject *, SlidingFitPair > PfoToSlidingFitsMap
std::pair< const ThreeDSlidingFitResult, const ThreeDSlidingFitResult > SlidingFitPair
void GetCRCandidates(const pandora::PfoList &parentCosmicRayPfos, const PfoToSliceIdMap &pfoToSliceIdMap, CRCandidateList &candidates) const
Make a list of CRCandidates.
void GetNeutrinoSlices(const CRCandidateList &candidates, const PfoToBoolMap &pfoToInTimeMap, const PfoToBoolMap &pfoToIsContainedMap, UIntSet &neutrinoSliceSet) const
Get the slice indices which contain a likely neutrino Pfo.
pandora::CartesianVector m_endPoint1
First fitted end point in 3D.
const pandora::ParticleFlowObject *const m_pPfo
Address of the candidate Pfo.