Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-27 09:14:59

0001 /**
0002  *  @file   LCContent/include/LCHelpers/FragmentRemovalHelper.h
0003  *
0004  *  @brief  Header file for the fragment removal helper class.
0005  *
0006  *  $Log: $
0007  */
0008 #ifndef LC_FRAGMENT_REMOVAL_HELPER_H
0009 #define LC_FRAGMENT_REMOVAL_HELPER_H 1
0010 
0011 #include "Pandora/PandoraInternal.h"
0012 #include "Pandora/StatusCodes.h"
0013 
0014 namespace lc_content {
0015 
0016 /**
0017  *  @brief  ClusterContact class, describing the interactions and proximity between parent and daughter candidate
0018  * clusters
0019  */
0020 class ClusterContact {
0021 public:
0022   /**
0023    *  @brief  Parameters class
0024    */
0025   class Parameters {
0026   public:
0027     float m_coneCosineHalfAngle1; ///< Cosine half angle for first cone comparison in cluster contact object
0028     float m_closeHitDistance1;    ///< First distance used to identify close hits in cluster contact object
0029     float m_closeHitDistance2;    ///< Second distance used to identify close hits in cluster contact object
0030     float m_minCosOpeningAngle;   ///< Min opening angle between two clusters to perform contact hit comparisons
0031     float m_distanceThreshold;    ///< Number of calorimeter cell-widths used to identify cluster contact layers
0032   };
0033 
0034   /**
0035    *  @brief  Constructor
0036    *
0037    *  @param  pandora the associated pandora instance
0038    *  @param  pDaughterCluster address of the daughter candidate cluster
0039    *  @param  pParentCluster address of the parent candidate cluster
0040    *  @param  parameters the cluster contact parameters
0041    */
0042   ClusterContact(const pandora::Pandora& pandora, const pandora::Cluster* const pDaughterCluster,
0043                  const pandora::Cluster* const pParentCluster, const Parameters& parameters);
0044 
0045   /**
0046    *  @brief  Get the address of the daughter candidate cluster
0047    *
0048    *  @return The address of the daughter candidate cluster
0049    */
0050   const pandora::Cluster* GetDaughterCluster() const;
0051 
0052   /**
0053    *  @brief  Get the address of the parent candidate cluster
0054    *
0055    *  @return The address of the parent candidate cluster
0056    */
0057   const pandora::Cluster* GetParentCluster() const;
0058 
0059   /**
0060    *  @brief  Get the number of contact layers for parent and daughter clusters two clusters
0061    *
0062    *  @return The number of contact layers
0063    */
0064   unsigned int GetNContactLayers() const;
0065 
0066   /**
0067    *  @brief  Get the ratio of the number of contact layers to the number of overlap layers
0068    *
0069    *  @return The ratio of contact layers to overlap layers
0070    */
0071   float GetContactFraction() const;
0072 
0073   /**
0074    *  @brief  Distance between closest hits in parent and daughter clusters, units mm
0075    *
0076    *  @return The distance between closest hits
0077    */
0078   float GetDistanceToClosestHit() const;
0079 
0080   /**
0081    *  @brief  Get the fraction of daughter hits that lie within sepcified distance 1 of parent cluster
0082    *
0083    *  @return The daughter close hit fraction
0084    */
0085   float GetCloseHitFraction1() const;
0086 
0087   /**
0088    *  @brief  Get the fraction of daughter hits that lie within sepcified distance 2 of parent cluster
0089    *
0090    *  @return The daughter close hit fraction
0091    */
0092   float GetCloseHitFraction2() const;
0093 
0094   /**
0095    *  @brief  Get the fraction of daughter hits that lie within specified cone 1 along parent direction
0096    *
0097    *  @return The daughter cone fraction
0098    */
0099   float GetConeFraction1() const;
0100 
0101 protected:
0102   /**
0103    *  @brief  Compare hits in daughter cluster with those in parent cluster to calculate minimum hit separation
0104    *          and close hit fractions. Calculate these properties in a single loop, for efficiency.
0105    *
0106    *  @param  pDaughterCluster address of the daughter candidate cluster
0107    *  @param  pParentCluster address of the parent candidate cluster
0108    *  @param  parameters the cluster contact parameters
0109    */
0110   void HitDistanceComparison(const pandora::Cluster* const pDaughterCluster,
0111                              const pandora::Cluster* const pParentCluster, const Parameters& parameters);
0112 
0113   const pandora::Cluster* m_pDaughterCluster; ///< Address of the daughter candidate cluster
0114   const pandora::Cluster* m_pParentCluster;   ///< Address of the parent candidate cluster
0115 
0116   unsigned int m_nContactLayers; ///< The number of contact layers for parent and daughter clusters
0117   float m_contactFraction;       ///< The ratio of the number of contact layers to the number of overlap layers
0118   float m_coneFraction1;         ///< Fraction of daughter hits that lie within specified cone 1 along parent direction
0119   float m_closeHitFraction1;     ///< Fraction of daughter hits that lie within sepcified distance 1 of parent cluster
0120   float m_closeHitFraction2;     ///< Fraction of daughter hits that lie within sepcified distance 2 of parent cluster
0121   float m_distanceToClosestHit;  ///< Distance between closest hits in parent and daughter clusters, units mm
0122 };
0123 
0124 typedef std::vector<ClusterContact> ClusterContactVector;
0125 typedef std::map<const pandora::Cluster*, ClusterContactVector> ClusterContactMap;
0126 
0127 //------------------------------------------------------------------------------------------------------------------------------------------
0128 
0129 /**
0130  *  @brief  FragmentRemovalHelper class
0131  */
0132 class FragmentRemovalHelper {
0133 public:
0134   /**
0135    *  @brief  Get the fraction of calo hits in cluster I that lie within a specified distance of a calo hit in cluster J
0136    *
0137    *  @param  pClusterI address of the cluster for which the fraction is calculated
0138    *  @param  pClusterJ address of the cluster used in the comparison
0139    *  @param  distanceThreshold the specified distance threshold
0140    *
0141    *  @return The fraction of close calo hits
0142    */
0143   static float GetFractionOfCloseHits(const pandora::Cluster* const pClusterI, const pandora::Cluster* const pClusterJ,
0144                                       const float distanceThreshold);
0145 
0146   /**
0147    *  @brief  Get the fraction of calo hits in cluster I that lie within a cone along the direction of cluster J.
0148    *          If cluster J has an associated track, it's projected position and direction at the calorimeter will be
0149    * used to define cone, otherwise cone will be radial and its axis will pass through centroid of cluster J at its
0150    * showerstart layer.
0151    *
0152    *  @param  pandora the associated pandora instance
0153    *  @param  pClusterI address of the cluster for which the fraction is calculated
0154    *  @param  pClusterJ address of the cluster used in the comparison
0155    *  @param  coneCosineHalfAngle the cone cosine half angle
0156    *
0157    *  @return The fraction of calo hits in the cone
0158    */
0159   static float GetFractionOfHitsInCone(const pandora::Pandora& pandora, const pandora::Cluster* const pClusterI,
0160                                        const pandora::Cluster* const pClusterJ, const float coneCosineHalfAngle);
0161 
0162   /**
0163    *  @brief  Get the fraction of calo hits in a cluster that lie within a cone along the direction of a specified track
0164    *
0165    *  @param  pCluster address of the cluster for which the fraction is calculated
0166    *  @param  pTrack address of the cluster used in the comparison
0167    *  @param  coneCosineHalfAngle the cone cosine half angle
0168    *
0169    *  @return The fraction of calo hits in the cone
0170    */
0171   static float GetFractionOfHitsInCone(const pandora::Cluster* const pCluster, const pandora::Track* const pTrack,
0172                                        const float coneCosineHalfAngle);
0173 
0174   /**
0175    *  @brief  Get the fraction of calo hits in a cluster that lie within a specified cone
0176    *
0177    *  @param  pCluster address of the cluster for which the fraction is calculated
0178    *  @param  coneApex position vector specifying cone apex
0179    *  @param  coneDirection unit vector specifying cone direction
0180    *  @param  coneCosineHalfAngle the cone cosine half angle
0181    *
0182    *  @return The fraction of calo hits in the cone
0183    */
0184   static float GetFractionOfHitsInCone(const pandora::Cluster* const pCluster, const pandora::CartesianVector& coneApex,
0185                                        const pandora::CartesianVector& coneDirection, const float coneCosineHalfAngle);
0186 
0187   /**
0188    *  @brief  Get the number of pseudo layers crossed by helix in specified range of z coordinates
0189    *
0190    *  @param  pandora the associated pandora instance
0191    *  @param  helix the helix
0192    *  @param  zStart start z coordinate
0193    *  @param  zEnd end z coordinate
0194    *  @param  nSamplingPoints number of points at which to sample the helix in the z interval
0195    *
0196    *  @return The number of pseudo layers crossed
0197    */
0198   static unsigned int GetNLayersCrossed(const pandora::Pandora& pandora, const pandora::Helix& helix,
0199                                         const float zStart, const float zEnd, const unsigned int nSamplingPoints = 100);
0200 
0201   /**
0202    *  @brief  Get the distance between hits in a cluster and a helix, typically the result of a fit to a track
0203    *
0204    *  @param  pCluster address of the cluster
0205    *  @param  helix the helix
0206    *  @param  startLayer the first pseudo layer of the cluster to examine
0207    *  @param  endLayer the last pseudo layer of the cluster to examine
0208    *  @param  maxOccupiedLayers the maximum number of occupied cluster pseudo layers to examine
0209    *  @param  closestDistanceToHit to receive the closest distance between the helix and a hit in the specified range of
0210    * the cluster
0211    *  @param  meanDistanceToHits to receive the mean distance between the helix and hits in the specified range of the
0212    * cluster
0213    */
0214   static pandora::StatusCode GetClusterHelixDistance(const pandora::Cluster* const pCluster,
0215                                                      const pandora::Helix& helix, const unsigned int startLayer,
0216                                                      const unsigned int endLayer, const unsigned int maxOccupiedLayers,
0217                                                      float& closestDistanceToHit, float& meanDistanceToHits);
0218 
0219   /**
0220    *  @brief  Get the number of contact layers for two clusters and also the ratio of the number of contact layers to
0221    * overlap layers
0222    *
0223    *  @param  pClusterI address of the first cluster
0224    *  @param  pClusterJ address of the second cluster
0225    *  @param  distanceThreshold number of calorimeter cell-widths used to determine whether layers are in contact
0226    *  @param  nContactLayers to receive the number of contact layers
0227    *  @param  contactFraction to receive the ratio of the number of contact layers to number of overlap layers
0228    */
0229   static pandora::StatusCode GetClusterContactDetails(const pandora::Cluster* const pClusterI,
0230                                                       const pandora::Cluster* const pClusterJ,
0231                                                       const float distanceThreshold, unsigned int& nContactLayers,
0232                                                       float& contactFraction);
0233 
0234   /**
0235    *  @brief  Get the electromagnetic energy-weighted mean common layer separation for a pair of provided clusters
0236    *          Note: energy-weighting uses only energies from cluster j
0237    *
0238    *  @param  pClusterI address of first cluster
0239    *  @param  pClusterJ address of second cluster
0240    *
0241    *  @return the energy-weighted mean common layer separation
0242    */
0243   static float GetEMEnergyWeightedLayerSeparation(const pandora::Cluster* const pClusterI,
0244                                                   const pandora::Cluster* const pClusterJ);
0245 
0246   /**
0247    *  @brief  Get the electromagnetic energy-weighted mean cluster position for a provided cluster
0248    *
0249    *  @param  pCluster address of the cluster
0250    *
0251    *  @return the electromagnetic energy-weighted mean cluster position
0252    */
0253   static pandora::CartesianVector GetEMEnergyWeightedPosition(const pandora::Cluster* const pCluster);
0254 };
0255 
0256 //------------------------------------------------------------------------------------------------------------------------------------------
0257 //------------------------------------------------------------------------------------------------------------------------------------------
0258 
0259 inline const pandora::Cluster* ClusterContact::GetDaughterCluster() const { return m_pDaughterCluster; }
0260 
0261 //------------------------------------------------------------------------------------------------------------------------------------------
0262 
0263 inline const pandora::Cluster* ClusterContact::GetParentCluster() const { return m_pParentCluster; }
0264 
0265 //------------------------------------------------------------------------------------------------------------------------------------------
0266 
0267 inline unsigned int ClusterContact::GetNContactLayers() const { return m_nContactLayers; }
0268 
0269 //------------------------------------------------------------------------------------------------------------------------------------------
0270 
0271 inline float ClusterContact::GetContactFraction() const { return m_contactFraction; }
0272 
0273 //------------------------------------------------------------------------------------------------------------------------------------------
0274 
0275 inline float ClusterContact::GetDistanceToClosestHit() const { return m_distanceToClosestHit; }
0276 
0277 //------------------------------------------------------------------------------------------------------------------------------------------
0278 
0279 inline float ClusterContact::GetCloseHitFraction1() const { return m_closeHitFraction1; }
0280 
0281 //------------------------------------------------------------------------------------------------------------------------------------------
0282 
0283 inline float ClusterContact::GetCloseHitFraction2() const { return m_closeHitFraction2; }
0284 
0285 //------------------------------------------------------------------------------------------------------------------------------------------
0286 
0287 inline float ClusterContact::GetConeFraction1() const { return m_coneFraction1; }
0288 
0289 } // namespace lc_content
0290 
0291 #endif // #ifndef LC_FRAGMENT_REMOVAL_HELPER_H