Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-27 09:15:00

0001 /**
0002  *  @file   LCContent/include/LCPlugins/LCShowerProfilePlugin.h
0003  *
0004  *  @brief  Header file for the lc shower profile plugin class.
0005  *
0006  *  $Log: $
0007  */
0008 #ifndef LC_SHOWER_PROFILE_PLUGIN_H
0009 #define LC_SHOWER_PROFILE_PLUGIN_H 1
0010 
0011 #include "Plugins/ShowerProfilePlugin.h"
0012 
0013 namespace lc_content {
0014 /**
0015  *  @brief  LCShowerProfilePlugin class
0016  */
0017 class LCShowerProfilePlugin : public pandora::ShowerProfilePlugin {
0018 public:
0019   /**
0020    *  @brief  Default constructor
0021    */
0022   LCShowerProfilePlugin();
0023 
0024   void CalculateShowerStartLayer(const pandora::Cluster* const pCluster, unsigned int& showerStartLayer) const;
0025   void CalculateLongitudinalProfile(const pandora::Cluster* const pCluster, float& profileStart,
0026                                     float& profileDiscrepancy) const;
0027   void CalculateTransverseProfile(const pandora::Cluster* const pCluster, const unsigned int maxPseudoLayer,
0028                                   ShowerPeakList& showerPeakList) const;
0029   void CalculateTransverseProfile(const pandora::Cluster* const pCluster, const unsigned int maxPseudoLayer,
0030                                   ShowerPeakList& showerPeakList, const bool inclusiveMode) const;
0031   void CalculateTrackBasedTransverseProfile(const pandora::Cluster* const pCluster, const unsigned int maxPseudoLayer,
0032                                             const pandora::Track* const pMinTrack,
0033                                             const pandora::TrackVector& trackVector,
0034                                             ShowerPeakList& showerPeakListPhoton,
0035                                             ShowerPeakList& showerPeakListNonPhoton) const;
0036 
0037 private:
0038   /**
0039    *  @brief  ShowerProfileEntry class
0040    */
0041   class ShowerProfileEntry {
0042   public:
0043     /**
0044      *  @brief  Default constructor
0045      */
0046     ShowerProfileEntry();
0047 
0048     bool m_isAvailable;                 ///< Whether shower profile entry is available (prevent double counting)
0049     float m_energy;                     ///< The energy associated with the shower profile entry
0050     pandora::CaloHitList m_caloHitList; ///< The list of calo hits associated with the shower profile entry
0051     bool m_potentialPeak;               ///< Whether the shower profile is a potential peak (to speed up looping)
0052     pandora::CaloHitList
0053         m_unusedCaloHitList; ///< The list of calo hits unused for shower peak finding, needed for inclusive mode
0054   };
0055 
0056   typedef std::pair<int, int> TwoDBin;        ///< The two dimensional bin typedef
0057   typedef std::vector<TwoDBin> TwoDBinVector; ///< The two dimensional bin vector typedef
0058 
0059   /**
0060    *  @brief  ShowerPeakObject class
0061    */
0062   class ShowerPeakObject {
0063   public:
0064     /**
0065      *  @brief  Default constructor
0066      */
0067     ShowerPeakObject(const float energy, const int uBin, const int vBin);
0068 
0069     /**
0070      *  @brief  Get peak energy
0071      *
0072      *  @return the peak energy
0073      */
0074     float GetPeakEnergy() const;
0075 
0076     /**
0077      *  @brief  Get peak u bin
0078      *
0079      *  @return the peak u bin
0080      */
0081     int GetPeakUBin() const;
0082 
0083     /**
0084      *  @brief  Get peak v bin
0085      *
0086      *  @return the peak v bin
0087      */
0088     int GetPeakVBin() const;
0089 
0090     TwoDBinVector m_associatedBins; ///< The bins associated to this peak
0091     bool m_isAvailable;             ///< Whether this is avaiable
0092     bool m_isPhotonCandidate;       ///< Whether this is photon candidate
0093 
0094   private:
0095     float m_energy; ///< The energy associated with the shower profile entry
0096     int m_uBin;     ///< The u bin of the peak
0097     int m_vBin;     ///< The u bin of the peak
0098   };
0099 
0100   typedef std::vector<ShowerProfileEntry> ShowerProfile;        ///< The shower profile typedef
0101   typedef std::vector<ShowerProfile> TwoDShowerProfile;         ///< The two dimensional shower profile typedef
0102   typedef std::vector<ShowerPeakObject> ShowerPeakObjectVector; ///< The shower peak object vector
0103 
0104   /**
0105    *  @brief  Calculate transverse shower peak objects for a cluster and get the list of peaks identified in the
0106    * profile, for clusters without tracks
0107    *
0108    *  @param  pCluster the address of the cluster
0109    *  @param  maxPseudoLayer the maximum pseudo layer to consider
0110    *  @param  showerProfile two dimensional shower profile to consider
0111    *  @param  showerPeakObjectVector to receive the shower peak objects
0112    */
0113   void CalculateTracklessTransverseShowers(const pandora::Cluster* const pCluster, const unsigned int maxPseudoLayer,
0114                                            TwoDShowerProfile& showerProfile,
0115                                            ShowerPeakObjectVector& showerPeakObjectVector) const;
0116 
0117   /**
0118    *  @brief  Calculate transverse shower peak objects for a cluster and get the list of peaks identified in the
0119    * profile, for clusters close to tracks
0120    *
0121    *  @param  pCluster the address of the cluster
0122    *  @param  maxPseudoLayer the maximum pseudo layer to consider
0123    *  @param  pMinTrack the closest track to the shower profile to speed up calculation
0124    *  @param  trackVector the vector of tracks to speed up calculation
0125    *  @param  showerProfile two dimensional shower profile to consider
0126    *  @param  showerPeakObjectVector to receive the shower peak objects
0127    *  @param  trackProjectionVector the 2D positions of track projections to receive and speed up subsequent calculation
0128    */
0129   void CalculateTrackNearbyTransverseShowers(const pandora::Cluster* const pCluster, const unsigned int maxPseudoLayer,
0130                                              const pandora::Track* const pMinTrack,
0131                                              const pandora::TrackVector& trackVector, TwoDShowerProfile& showerProfile,
0132                                              ShowerPeakObjectVector& showerPeakObjectVector,
0133                                              TwoDBinVector& trackProjectionVector) const;
0134 
0135   /**
0136    *  @brief  Calculate empty 2D shower profile
0137    *
0138    *  @param  showerProfile two dimensional shower profile to receive
0139    */
0140   void CreateEmptyTwoDShowerProfile(TwoDShowerProfile& showerProfile) const;
0141 
0142   /**
0143    *  @brief  Initialise 2D shower profile for clusters not close to tracks
0144    *
0145    *  @param  pCluster the address of the cluster
0146    *  @param  maxPseudoLayer the maximum pseudo layer to consider
0147    *  @param  showerProfile two dimensional shower profile to consider
0148    */
0149   void InitialiseTransverseProfile(const pandora::Cluster* const pCluster, const unsigned int maxPseudoLayer,
0150                                    TwoDShowerProfile& showerProfile) const;
0151 
0152   /**
0153    *  @brief  Initialise 2D shower profile for clusters close to tracks
0154    *
0155    *  @param  pCluster the address of the cluster
0156    *  @param  maxPseudoLayer the maximum pseudo layer to consider
0157    *  @param  pMinTrack the closest track to the shower profile to speed up calculation
0158    *  @param  trackVector the vector of tracks to speed up calculation
0159    *  @param  showerProfile two dimensional shower profile to consider
0160    *  @param  trackProjectionVector the 2D positions of track projections to receive and speed up subsequent calculation
0161    */
0162   void InitialiseTransverseProfileWithTracks(const pandora::Cluster* const pCluster, const unsigned int maxPseudoLayer,
0163                                              const pandora::Track* const pMinTrack,
0164                                              const pandora::TrackVector& trackVector, TwoDShowerProfile& showerProfile,
0165                                              TwoDBinVector& trackProjectionVector) const;
0166 
0167   /**
0168    *  @brief  Find axes of projection
0169    *
0170    *  @param  pCluster the address of the cluster
0171    *  @param  innerLayerCentroid the inner layer centroid to receive
0172    *  @param  uAxis u axis to receive
0173    *  @param  vAxis v axis to receive
0174    *  @param  pMinTrack the closest track to the shower profile to speed up calculation
0175    */
0176   void CalculateProjectionAxes(const pandora::Cluster* const pCluster, pandora::CartesianVector& innerLayerCentroid,
0177                                pandora::CartesianVector& uAxis, pandora::CartesianVector& vAxis,
0178                                const pandora::Track* const pMinTrack = NULL) const;
0179 
0180   /**
0181    *  @brief  Initialise 2D shower profile implementation given porject axes
0182    *
0183    *  @param  pCluster the address of the cluster
0184    *  @param  maxPseudoLayer the maximum pseudo layer to consider
0185    *  @param  innerLayerCentroid the inner layer centroid to consider
0186    *  @param  uAxis u axis to consider
0187    *  @param  vAxis v axis to consider
0188    *  @param  showerProfile two dimensional shower profile to receive
0189    */
0190   void InitialiseTwoDShowerProfile(const pandora::Cluster* const pCluster, const unsigned int maxPseudoLayer,
0191                                    const pandora::CartesianVector& innerLayerCentroid,
0192                                    const pandora::CartesianVector& uAxis, const pandora::CartesianVector& vAxis,
0193                                    TwoDShowerProfile& showerProfile) const;
0194 
0195   /**
0196    *  @brief  Find all tracks projections on 2D shower profile
0197    *
0198    *  @param  pCluster the address of the cluster
0199    *  @param  trackVector the vector of address of all tracks
0200    *  @param  innerLayerCentroid the inner layer centroid to consider
0201    *  @param  uAxis u axis to consider
0202    *  @param  vAxis v axis to consider
0203    *  @param  trackProjectionVector the 2D positions of track projections to receive and speed up subsequent calculation
0204    */
0205   void FindTracksProjection(const pandora::Cluster* const pCluster, const pandora::TrackVector& trackVector,
0206                             const pandora::CartesianVector& innerLayerCentroid, const pandora::CartesianVector& uAxis,
0207                             const pandora::CartesianVector& vAxis, TwoDBinVector& trackProjectionVector) const;
0208 
0209   /**
0210    *  @brief  Get cell length scale
0211    *
0212    *  @param  pCluster the address of the cluster
0213    *
0214    *  @return Cell length scale
0215    */
0216   float GetCellLengthScale(const pandora::Cluster* const pCluster) const;
0217 
0218   /**
0219    *  @brief  Mark region with low height unavailable
0220    *
0221    *  @param  showerProfile two dimensional shower profile to consider
0222    */
0223   void MaskLowHeightRegions(TwoDShowerProfile& showerProfile) const;
0224 
0225   /**
0226    *  @brief  Find raw peaks in 2D profile, based on local maxima
0227    *
0228    *  @param  showerProfile two dimensional shower profile to consider
0229    *  @param  showerPeakObjectVector the 2D peak object to receive
0230    */
0231   void FindRawPeaksInTwoDShowerProfile(TwoDShowerProfile& showerProfile,
0232                                        ShowerPeakObjectVector& showerPeakObjectVector) const;
0233 
0234   /**
0235    *  @brief  Associate unavailable bins to peaks, using TwoDShowerProfile, for inclusive modes
0236    *
0237    *  @param  showerProfile two dimensional shower profile to consider
0238    *  @param  showerPeakObjectVector the 2D peak object to receive
0239    */
0240   void AssociateUnavailableBinsToPeaks(const TwoDShowerProfile& showerProfile,
0241                                        ShowerPeakObjectVector& showerPeakObjectVector) const;
0242 
0243   /**
0244    *  @brief  Associate bins to peaks, using TwoDShowerProfile
0245    *
0246    *  @param  showerProfile two dimensional shower profile to consider
0247    *  @param  showerPeakObjectVector the 2D peak object to receive
0248    */
0249   void AssociateBinsToPeaks(const TwoDShowerProfile& showerProfile,
0250                             ShowerPeakObjectVector& showerPeakObjectVector) const;
0251 
0252   /**
0253    *  @brief  Associate bins to peaks, using TwoDBinVector
0254    *
0255    *  @param  twoDBinVector two dimensional bins
0256    *  @param  showerPeakObjectVector the 2D peak object to receive
0257    */
0258   void AssociateBinsToPeaks(const TwoDBinVector& twoDBinVector, ShowerPeakObjectVector& showerPeakObjectVector) const;
0259 
0260   /**
0261    *  @brief  Apply quality cuts to peaks
0262    *
0263    *  @param  showerPeakObjectVector the 2D peak object to modify
0264    *  @param  twoDBinVector the discared two dimensional bins to receive
0265    */
0266   void ApplyQualityCutPeakNBin(ShowerPeakObjectVector& showerPeakObjectVector, TwoDBinVector& twoDBinVector) const;
0267 
0268   /**
0269    *  @brief  True for passing the quality cuts for minimum number of bins
0270    *
0271    *  @param  showerPeakObject the 2D peak object to consider
0272    *
0273    *  @return True for passing the quality cuts for minimum number of bins
0274    */
0275   bool PassQualityCutPeakNBin(const ShowerPeakObject& showerPeakObject) const;
0276 
0277   /**
0278    *  @brief  Mark bins close to tracks not photon candidate
0279    *
0280    *  @param  trackProjectionVector the all track projections in the 2D plane
0281    *  @param  showerPeakObjectVector the 2D peak object vector to modify
0282    */
0283   void MarkPeaksCloseToTracks(const TwoDBinVector& trackProjectionVector,
0284                               ShowerPeakObjectVector& showerPeakObjectVector) const;
0285 
0286   /**
0287    *  @brief  Mark bins shifted too much between slices not photon candidate
0288    *
0289    *  @param  showerPeakObjectVectorFirst the 2D peak object vector from previous slice
0290    *  @param  showerPeakObjectVectorNext the 2D peak object vector from next slice to modify
0291    */
0292   void MatchPeaksInTwoSlices(const ShowerPeakObjectVector& showerPeakObjectVectorFirst,
0293                              ShowerPeakObjectVector& showerPeakObjectVectorNext) const;
0294 
0295   /**
0296    *  @brief  Process the quality cuts and association of bins to peaks
0297    *
0298    *  @param  showerProfile the 2D shower profile to modify
0299    *  @param  showerPeakObjectVector the 2D peak object vector to modify
0300    */
0301   void ProcessShowerProfile(TwoDShowerProfile& showerProfile, ShowerPeakObjectVector& showerPeakObjectVector) const;
0302 
0303   /**
0304    *  @brief  Convert 2D bins to shower lists
0305    *
0306    *  @param  showerProfile the 2D shower profile to consider
0307    *  @param  showerPeakObjectVector the 2D peak object vector to consider
0308    *  @param  showerPeakListPhoton shower peak list of photon candidates
0309    *  @param  showerPeakListNonPhoton shower peak list of non photon candidates
0310    *  @param  inclusiveMode inclusive mode to add all calo hits to peaks
0311    */
0312   void ConvertBinsToShowerLists(const TwoDShowerProfile& showerProfile,
0313                                 const ShowerPeakObjectVector& showerPeakObjectVector,
0314                                 ShowerPeakList& showerPeakListPhoton, ShowerPeakList& showerPeakListNonPhoton,
0315                                 const bool inclusiveMode) const;
0316 
0317   /**
0318    *  @brief  Find projection of a 3D point
0319    *
0320    *  @param  hitPosition the 3D position
0321    *  @param  innerLayerCentroid the inner layer centroid to consider
0322    *  @param  uAxis u axis to consider
0323    *  @param  vAxis v axis to consider
0324    *  @param  nOffsetBins the number of offset bins
0325    *  @param  cellLengthScale cell length scale
0326    *  @param  uBin projection in u direction
0327    *  @param  vBin projection in v direction
0328    */
0329   void FindHitPositionProjection(const pandora::CartesianVector& hitPosition,
0330                                  const pandora::CartesianVector& innerLayerCentroid,
0331                                  const pandora::CartesianVector& uAxis, const pandora::CartesianVector& vAxis,
0332                                  const int nOffsetBins, const float cellLengthScale, int& uBin, int& vBin) const;
0333 
0334   /**
0335    *  @brief  Find the cloest boundary bin for a point outside the square
0336    *
0337    *  @param  uBin u bin
0338    *  @param  vBin v bin
0339    *  @param  uEdgeLow u bin low edge
0340    *  @param  uEdgeHigh u bin high edge
0341    *  @param  vEdgeLow v bin low edge
0342    *  @param  vEdgeHigh v bin high edge
0343    *  @param  uEdgeBin cloest edge u bin
0344    *  @param  vEdgeBin cloest edge v bin
0345    */
0346   void FindBoundaryBins(const int uBin, const int vBin, const int uEdgeLow, const int uEdgeHigh, const int vEdgeLow,
0347                         const int vEdgeHigh, int& uEdgeBin, int& vEdgeBin) const;
0348 
0349   /**
0350    *  @brief  True if the peak is a local maxima
0351    *
0352    *  @param  showerProfile the 2D shower profile to modify
0353    *  @param  uBin projection in u direction
0354    *  @param  vBin projection in v direction
0355    *
0356    *  @return True if the peak is a local maxima
0357    */
0358   bool IsPeak(TwoDShowerProfile& showerProfile, const int uBin, const int vBin) const;
0359 
0360   /**
0361    *  @brief  True if the peak is a local maxima implementaion
0362    *
0363    *  @param  showerProfile the 2D shower profile to modify
0364    *  @param  uBin projection in u direction
0365    *  @param  vBin projection in v direction
0366    *
0367    *  @return True if the peak is a local maxima
0368    */
0369   bool Check8NeighbourFull(TwoDShowerProfile& showerProfile, const int uBin, const int vBin) const;
0370 
0371   /**
0372    *  @brief  True if the peak is a local maxima implementaion, fast
0373    *
0374    *  @param  showerProfile the 2D shower profile to modify
0375    *  @param  uBin projection in u direction
0376    *  @param  vBin projection in v direction
0377    *
0378    *  @return True if the peak is a local maxima
0379    */
0380   bool Check8NeighbourFast(TwoDShowerProfile& showerProfile, const int uBin, const int vBin) const;
0381 
0382   /**
0383    *  @brief  Calculate the metric for peak association
0384    *
0385    *  @param  distance the distance to the peak
0386    *  @param  energy energy of the peak
0387    *
0388    *  @return the metric for peak association
0389    */
0390   float CalculatePeakFindingMetric(const float distance, const float energy) const;
0391 
0392   /**
0393    *  @brief  Find the best shower peak to associate bins
0394    *
0395    *  @param  showerPeakObjectVector shower peak obejct vectors for all peaks
0396    *  @param  uBin position of bin
0397    *  @param  vBin position of bin
0398    *  @param  bestShowerPeakObject address of best peak object to receive
0399    */
0400   void CalculateBestPeakUsingMetric(ShowerPeakObjectVector& showerPeakObjectVector, const int uBin, const int vBin,
0401                                     ShowerPeakObject*& bestShowerPeakObject) const;
0402 
0403   /**
0404    *  @brief  True for showerPeakObjectVector contains photon candiates
0405    *
0406    *  @param  showerPeakObjectVector shower peak obejct vectors for all peaks
0407    *
0408    *  @return True for showerPeakObjectVector contains photon candiates
0409    */
0410   bool HasPhotonCandidate(const ShowerPeakObjectVector& showerPeakObjectVector) const;
0411 
0412   /**
0413    *  @brief  Sort shower peak list by desending energy
0414    *
0415    *  @param  lhs first shower peak for comparison
0416    *  @param  rhs second shower peak for comparison
0417    *
0418    *  @return boolean
0419    */
0420   static bool SortShowerPeakListByEnergy(const ShowerPeak& lhs, const ShowerPeak& rhs);
0421 
0422   pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle);
0423 
0424   float m_showerStartMipFraction;         ///< Max layer mip-fraction to declare layer as shower-like
0425   unsigned int m_showerStartNonMipLayers; ///< Number of successive shower-like layers to identify shower start
0426 
0427   float m_longProfileBinWidth;       ///< Bin width used to construct longitudinal profile, units radiation lengths
0428   unsigned int m_longProfileNBins;   ///< Number of bins used to construct longitudinal profile
0429   float m_longProfileMinCosAngle;    ///< Min angular correction used to adjust radiation length measures
0430   float m_longProfileCriticalEnergy; ///< Critical energy, used to calculate argument for gamma function
0431   float m_longProfileParameter0;     ///< Parameter0, used to calculate argument for gamma function
0432   float m_longProfileParameter1;     ///< Parameter1, used to calculate argument for gamma function
0433   float m_longProfileMaxDifference;  ///< Max difference between current and best longitudinal profile comparisons
0434 
0435   int m_transProfileNBins;                       ///< Number of bins used to construct transverse profile
0436   float m_transProfilePeakThreshold;             ///< Minimum energy for a bin to consider
0437   unsigned int m_transProfilePeakFindingMetric;  ///< The metric for peak association
0438   unsigned int m_transProfileMinNBinsCut;        ///< The minimum number for bins of a substantial peak
0439   unsigned int m_transProfileTrackNearbyNSlices; ///< The number of slices to analyse the EM shower
0440   float m_transProfileMinTrackToPeakCut;         ///< The minimum 2D distance of a track to the peak postion
0441   float m_transProfileMinDisTrackMatch; ///< The maximum allowed shift of 2D distance of the peak position through the
0442                                         ///< slices
0443 };
0444 
0445 //------------------------------------------------------------------------------------------------------------------------------------------
0446 
0447 inline void LCShowerProfilePlugin::CalculateTransverseProfile(const pandora::Cluster* const pCluster,
0448                                                               const unsigned int maxPseudoLayer,
0449                                                               ShowerPeakList& showerPeakList) const {
0450   return CalculateTransverseProfile(pCluster, maxPseudoLayer, showerPeakList, false);
0451 }
0452 
0453 //------------------------------------------------------------------------------------------------------------------------------------------
0454 
0455 inline LCShowerProfilePlugin::ShowerProfileEntry::ShowerProfileEntry()
0456     : m_isAvailable(true), m_energy(0.f), m_potentialPeak(true) {}
0457 
0458 //------------------------------------------------------------------------------------------------------------------------------------------
0459 
0460 inline LCShowerProfilePlugin::ShowerPeakObject::ShowerPeakObject(const float energy, const int uBin, const int vBin)
0461     : m_isAvailable(true), m_isPhotonCandidate(true), m_energy(energy), m_uBin(uBin), m_vBin(vBin) {
0462   m_associatedBins.push_back(std::make_pair(uBin, vBin));
0463 }
0464 
0465 //------------------------------------------------------------------------------------------------------------------------------------------
0466 
0467 inline float LCShowerProfilePlugin::ShowerPeakObject::GetPeakEnergy() const { return m_energy; }
0468 
0469 //------------------------------------------------------------------------------------------------------------------------------------------
0470 
0471 inline int LCShowerProfilePlugin::ShowerPeakObject::GetPeakUBin() const { return m_uBin; }
0472 
0473 //------------------------------------------------------------------------------------------------------------------------------------------
0474 
0475 inline int LCShowerProfilePlugin::ShowerPeakObject::GetPeakVBin() const { return m_vBin; }
0476 
0477 } // namespace lc_content
0478 
0479 #endif // #ifndef LC_SHOWER_PROFILE_PLUGIN_H