StitchingCosmicRayMergingTool.h
Go to the documentation of this file.
1 /**
2  * @file LArContent/include/LArControlFlow/StitchingCosmicRayMergingTool.h
3  *
4  * @brief Header file for the stitching cosmic ray merging tool class.
5  *
6  * $Log: $
7  */
8 #ifndef LAR_STITCHING_COSMIC_RAY_MERGING_TOOL_H
9 #define LAR_STITCHING_COSMIC_RAY_MERGING_TOOL_H 1
10 
12 
14 
15 #include <unordered_map>
16 
17 namespace lar_content
18 {
19 
20 /**
21  * @brief StitchingCosmicRayMergingTool class
22  */
24 {
25 public:
26  /**
27  * @brief Default constructor
28  */
30 
31  void Run(const MasterAlgorithm *const pAlgorithm, const pandora::PfoList *const pMultiPfoList, PfoToLArTPCMap &pfoToLArTPCMap,
32  PfoToFloatMap &stitchedPfosToX0Map);
33 
34  /**
35  * @brief PfoAssociation class
36  */
38  {
39  public:
40  /**
41  * @brief Vertex enumeration
42  */
44  {
45  UNDEFINED = 0,
46  INNER = 1,
47  OUTER = 2
48  };
49 
50  /**
51  * @brief Constructor
52  *
53  * @param parent the parent vertex type
54  * @param daughter the daughter vertex type
55  * @param fom the figure of merit
56  */
57  PfoAssociation(const VertexType parent, const VertexType daughter, const float fom);
58 
59  /**
60  * @brief Get parent
61  *
62  * @return the parent
63  */
64  VertexType GetParent() const;
65 
66  /**
67  * @brief Get daughter
68  *
69  * @return the daughter
70  */
71  VertexType GetDaughter() const;
72 
73  /**
74  * @brief Get figure of merit
75  *
76  * @return the figure of merit
77  */
78  float GetFigureOfMerit() const;
79 
80  private:
81  VertexType m_parent; ///< The parent vertex type
82  VertexType m_daughter; ///< The daughter vertex type
83  float m_fom; ///< The figure of merit
84  };
85 
86 private:
87  pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle);
88 
89  /**
90  * @brief Select primary Pfos from the input list of Pfos
91  *
92  * @param pInputPfoList the input list of Pfos
93  * @param pfoToLArTPCMap the input mapping between Pfos and tpc
94  * @param outputPfoList the output list of Pfos
95  */
96  void SelectPrimaryPfos(const pandora::PfoList *pInputPfoList, const PfoToLArTPCMap &pfoToLArTPCMap, pandora::PfoList &outputPfoList) const;
97 
98  typedef std::unordered_map<const pandora::ParticleFlowObject *, LArPointingCluster> ThreeDPointingClusterMap;
99 
100  /**
101  * @brief Build a 3D pointing cluster for each Pfo
102  *
103  * @param inputPfoList the input list of Pfos
104  * @param pfoToLArTPCMap the input mapping between Pfos and tpc
105  * @param pointingClusterMap the mapping between Pfos and their corresponding 3D pointing clusters
106  */
108  const pandora::PfoList &inputPfoList, const PfoToLArTPCMap &pfoToLArTPCMap, ThreeDPointingClusterMap &pointingClusterMap) const;
109 
110  typedef std::unordered_map<const pandora::LArTPC *, pandora::PfoList> LArTPCToPfoMap;
111 
112  /**
113  * @brief Build a list of Pfos for each tpc
114  *
115  * @param inputPfoList the input list of Pfos
116  * @param pfoToLArTPCMap the input mapping between Pfos and tpc
117  * @param larTPCToPfoMap the output mapping between tpc and Pfos
118  */
119  void BuildTPCMaps(const pandora::PfoList &inputPfoList, const PfoToLArTPCMap &pfoToLArTPCMap, LArTPCToPfoMap &larTPCToPfoMap) const;
120 
121  typedef std::unordered_map<const pandora::ParticleFlowObject *, PfoAssociation> PfoAssociationMap;
122  typedef std::unordered_map<const pandora::ParticleFlowObject *, PfoAssociationMap> PfoAssociationMatrix;
123 
124  /**
125  * @brief Create associations between Pfos using 3D pointing clusters
126  *
127  * @param larTPCToPfoMap the input mapping between tpc and Pfos
128  * @param pointingClusterMap the input mapping between Pfos and their corresponding 3D pointing clusters
129  * @param pfoAssociationMatrix the output matrix of associations between Pfos
130  */
131  void CreatePfoMatches(const LArTPCToPfoMap &larTPCToPfoMap, const ThreeDPointingClusterMap &pointingClusterMap,
132  PfoAssociationMatrix &pfoAssociationMatrix) const;
133 
134  /**
135  * @brief Create associations between Pfos using 3D pointing clusters
136  *
137  * @param larTPC1 the tpc description for the first Pfo
138  * @param larTPC2 the tpc description for the second Pfo
139  * @param pPfo1 the first Pfo
140  * @param pPfo2 the second Pfo
141  * @param pointingClusterMap the input mapping between Pfos and their corresponding 3D pointing clusters
142  * @param pfoAssociationMatrix the output matrix of associations between Pfos
143  */
144  void CreatePfoMatches(const pandora::LArTPC &larTPC1, const pandora::LArTPC &larTPC2, const pandora::ParticleFlowObject *const pPfo1,
145  const pandora::ParticleFlowObject *const pPfo2, const ThreeDPointingClusterMap &pointingClusterMap,
146  PfoAssociationMatrix &pfoAssociationMatrix) const;
147 
148  typedef std::unordered_map<const pandora::ParticleFlowObject *, pandora::PfoList> PfoMergeMap;
149 
150  /**
151  * @brief Select the best associations between Pfos; create a mapping between associated Pfos, handling any ambiguities
152  *
153  * @param pfoAssociationMatrix the input list of all associations between Pfos
154  * @param pfoSelectedMatches the output list of good associations between pfos (candidates for merging)
155  */
156  void SelectPfoMatches(const PfoAssociationMatrix &pfoAssociationMatrix, PfoMergeMap &pfoSelectedMatches) const;
157 
158  /**
159  * @brief Create an initial map of Pfo merges to be made
160  *
161  * @param pfoMatches the input list of associated Pfos
162  * @param pfoMerges the output mapping between Pfos to enlarge and Pfos to delete
163  */
164  void SelectPfoMerges(const PfoMergeMap &pfoMatches, PfoMergeMap &pfoMerges) const;
165 
166  /**
167  * @brief Collect up associations between Pfos
168  *
169  * @param pSeedPfo the seed Pfo (will be enlarged after merging)
170  * @param pCurrentPfo the target Pfo (will be deleted after merging)
171  * @param pfoMerges the list of associations between Pfos
172  * @param vetoSet the set of associated Pfos that have already been considered
173  * @param associatedList the output list of associated Pfos
174  */
175  void CollectAssociatedPfos(const pandora::ParticleFlowObject *const pSeedPfo, const pandora::ParticleFlowObject *const pCurrentPfo,
176  const PfoMergeMap &pfoMerges, const pandora::PfoSet &vetoSet, pandora::PfoList &associatedList) const;
177 
178  /**
179  * @brief Identify the vertex Pfo and then re-order the map of merges so that the vertex Pfo will be enlarged
180  *
181  * @param pfoToLArTPCMap the mapping between pfos and tpc
182  * @param pointingClusterMap the mapping between Pfos and their corresponding 3D pointing clusters
183  * @param inputPfoMerges the input map of Pfo merges
184  * @param outputPfoMerges the re-ordered map of Pfo merges
185  */
186  void OrderPfoMerges(const PfoToLArTPCMap &pfoToLArTPCMap, const ThreeDPointingClusterMap &pointingClusterMap,
187  const PfoMergeMap &inputPfoMerges, PfoMergeMap &outputPfoMerges) const;
188 
189  /**
190  * @brief Apply X0 corrections, and then stitch together Pfos
191  *
192  * @param pAlgorithm the address of the parent stitching algorithm
193  * @param pointingClusterMap the mapping between Pfos and their corresponding 3D pointing clusters
194  * @param pfoMerges the input map of Pfo merges
195  * @param pfoToLArTPCMap the pfo to lar tpc map
196  * @param stitchedPfosToX0Map a map of cosmic-ray pfos that have been stitched between lar tpcs to the X0 shift
197  */
198  void StitchPfos(const MasterAlgorithm *const pAlgorithm, const ThreeDPointingClusterMap &pointingClusterMap,
199  const PfoMergeMap &pfoMerges, PfoToLArTPCMap &pfoToLArTPCMap, PfoToFloatMap &stitchedPfosToX0Map) const;
200 
201  typedef std::unordered_map<const pandora::ParticleFlowObject *, LArPointingCluster::Vertex> PfoToPointingVertexMap;
202  typedef std::unordered_map<const pandora::ParticleFlowObject *, PfoToPointingVertexMap> PfoToPointingVertexMatrix;
203 
204  /**
205  * @brief Shift a pfo given its pfo stitching pair
206  *
207  * @param pPfoToShift the pfo of the stitching pair to shift
208  * @param pMatchedPfo the pfo of the stitching pair to remain stationary
209  * @param x0 the distance by which pPfoToShift is to be shifted (direction of shift is determined in method)
210  * @param pfoToLArTPCMap the pfo to lar tpc map
211  * @param pfoToPointingVertexMatrix the map [pfo -> map [matched pfo -> pfo stitching vertex]]
212  */
213  void ShiftPfo(const MasterAlgorithm *const pAlgorithm, const pandora::ParticleFlowObject *const pPfoToShift,
214  const pandora::ParticleFlowObject *const pMatchedPfo, const float x0, const PfoToLArTPCMap &pfoToLArTPCMap,
215  const PfoToPointingVertexMatrix &pfoToPointingVertexMatrix) const;
216 
217  /**
218  * @brief Calculate x0 shift for a group of associated Pfos
219  *
220  * @param pfoToLArTPCMap the mapping between pfos and tpc
221  * @param pointingClusterMap the mapping between Pfos and their corresponding 3D pointing clusters
222  * @param pfoVector the vector of parent Pfos to stitch together
223  * @param x0 the output x0 value
224  * @param pfoToPointingVertexMatrix map of pfo to a map of matched pfo and the corresponding pointing vertex used in stitching
225  *
226  * @return bool true if all x0 contributions were consistent, false otherwise
227  */
228  bool CalculateX0(const PfoToLArTPCMap &pfoToLArTPCMap, const ThreeDPointingClusterMap &pointingClusterMap,
229  const pandora::PfoVector &pfoVector, float &x0, PfoToPointingVertexMatrix &pfoToPointingVertexMatrix) const;
230 
236  float m_relaxMinLongitudinalDisplacement; ///< The minimum value of the longitudinal impact parameter for association if both verticies fall in the detector gap
241  unsigned int m_minNCaloHits3D;
242  float m_maxX0FractionalDeviation; ///< The maximum allowed fractional difference of an X0 contribution for matches to be stitched
243  float m_boundaryToleranceWidth; ///< The distance from the APA/CPA boundary inside which the deviation consideration is ignored
244 };
245 
246 } // namespace lar_content
247 
248 #endif // #ifndef LAR_STITCHING_COSMIC_RAY_MERGING_TOOL_H
std::unordered_map< const pandora::ParticleFlowObject *, float > PfoToFloatMap
void SelectPrimaryPfos(const pandora::PfoList *pInputPfoList, const PfoToLArTPCMap &pfoToLArTPCMap, pandora::PfoList &outputPfoList) const
Select primary Pfos from the input list of Pfos.
std::unordered_map< const pandora::ParticleFlowObject *, PfoToPointingVertexMap > PfoToPointingVertexMatrix
Header file for the lar pointing cluster class.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
PfoAssociation(const VertexType parent, const VertexType daughter, const float fom)
Constructor.
void CollectAssociatedPfos(const pandora::ParticleFlowObject *const pSeedPfo, const pandora::ParticleFlowObject *const pCurrentPfo, const PfoMergeMap &pfoMerges, const pandora::PfoSet &vetoSet, pandora::PfoList &associatedList) const
Collect up associations between Pfos.
bool CalculateX0(const PfoToLArTPCMap &pfoToLArTPCMap, const ThreeDPointingClusterMap &pointingClusterMap, const pandora::PfoVector &pfoVector, float &x0, PfoToPointingVertexMatrix &pfoToPointingVertexMatrix) const
Calculate x0 shift for a group of associated Pfos.
void CreatePfoMatches(const LArTPCToPfoMap &larTPCToPfoMap, const ThreeDPointingClusterMap &pointingClusterMap, PfoAssociationMatrix &pfoAssociationMatrix) const
Create associations between Pfos using 3D pointing clusters.
std::unordered_map< const pandora::ParticleFlowObject *, pandora::PfoList > PfoMergeMap
std::unordered_map< const pandora::ParticleFlowObject *, PfoAssociationMap > PfoAssociationMatrix
void BuildTPCMaps(const pandora::PfoList &inputPfoList, const PfoToLArTPCMap &pfoToLArTPCMap, LArTPCToPfoMap &larTPCToPfoMap) const
Build a list of Pfos for each tpc.
float m_boundaryToleranceWidth
The distance from the APA/CPA boundary inside which the deviation consideration is ignored...
void OrderPfoMerges(const PfoToLArTPCMap &pfoToLArTPCMap, const ThreeDPointingClusterMap &pointingClusterMap, const PfoMergeMap &inputPfoMerges, PfoMergeMap &outputPfoMerges) const
Identify the vertex Pfo and then re-order the map of merges so that the vertex Pfo will be enlarged...
float m_maxX0FractionalDeviation
The maximum allowed fractional difference of an X0 contribution for matches to be stitched...
void ShiftPfo(const MasterAlgorithm *const pAlgorithm, const pandora::ParticleFlowObject *const pPfoToShift, const pandora::ParticleFlowObject *const pMatchedPfo, const float x0, const PfoToLArTPCMap &pfoToLArTPCMap, const PfoToPointingVertexMatrix &pfoToPointingVertexMatrix) const
Shift a pfo given its pfo stitching pair.
Header file for the master algorithm class.
void StitchPfos(const MasterAlgorithm *const pAlgorithm, const ThreeDPointingClusterMap &pointingClusterMap, const PfoMergeMap &pfoMerges, PfoToLArTPCMap &pfoToLArTPCMap, PfoToFloatMap &stitchedPfosToX0Map) const
Apply X0 corrections, and then stitch together Pfos.
void BuildPointingClusterMaps(const pandora::PfoList &inputPfoList, const PfoToLArTPCMap &pfoToLArTPCMap, ThreeDPointingClusterMap &pointingClusterMap) const
Build a 3D pointing cluster for each Pfo.
StitchingBaseTool class.
std::unordered_map< const pandora::ParticleFlowObject *, const pandora::LArTPC * > PfoToLArTPCMap
void SelectPfoMatches(const PfoAssociationMatrix &pfoAssociationMatrix, PfoMergeMap &pfoSelectedMatches) const
Select the best associations between Pfos; create a mapping between associated Pfos, handling any ambiguities.
std::unordered_map< const pandora::ParticleFlowObject *, LArPointingCluster::Vertex > PfoToPointingVertexMap
MasterAlgorithm class.
std::unordered_map< const pandora::ParticleFlowObject *, PfoAssociation > PfoAssociationMap
float m_relaxMinLongitudinalDisplacement
The minimum value of the longitudinal impact parameter for association if both verticies fall in the ...
void Run(const MasterAlgorithm *const pAlgorithm, const pandora::PfoList *const pMultiPfoList, PfoToLArTPCMap &pfoToLArTPCMap, PfoToFloatMap &stitchedPfosToX0Map)
Run the algorithm tool.
std::unordered_map< const pandora::LArTPC *, pandora::PfoList > LArTPCToPfoMap
void SelectPfoMerges(const PfoMergeMap &pfoMatches, PfoMergeMap &pfoMerges) const
Create an initial map of Pfo merges to be made.
def parent(G, child, parent_type)
Definition: graph.py:67
std::unordered_map< const pandora::ParticleFlowObject *, LArPointingCluster > ThreeDPointingClusterMap