Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-12-17 09:19:53

0001 #ifndef CALOBASE_RAWCLUSTERV1_H
0002 #define CALOBASE_RAWCLUSTERV1_H
0003 
0004 #include "RawCluster.h"
0005 #include "RawClusterDefs.h"
0006 
0007 #include <CLHEP/Vector/ThreeVector.h>
0008 
0009 #include <cmath>
0010 #include <cstddef>
0011 #include <cstdint>
0012 #include <iostream>
0013 #include <limits>
0014 #include <map>
0015 #include <utility>
0016 
0017 class PHObject;
0018 
0019 class RawClusterv1 : public RawCluster
0020 {
0021  public:
0022   RawClusterv1() = default;
0023   RawClusterv1(const RawCluster& cluster);
0024   ~RawClusterv1() override = default;
0025 
0026   void Reset() override;
0027   PHObject* CloneMe() const override { return new RawClusterv1(*this); }
0028   int isValid() const override { return towermap.size() > 0; }
0029   void identify(std::ostream& os = std::cout) const override;
0030 
0031   /** @defgroup getters
0032    *  @{
0033    */
0034   //! cluster ID
0035   RawClusterDefs::keytype get_id() const override { return clusterid; }
0036   //! total energy
0037   float get_energy() const override { return _energy; }
0038   //! Tower operations
0039   size_t getNTowers() const override { return towermap.size(); }
0040   RawCluster::TowerConstRange get_towers() const override { return make_pair(towermap.begin(), towermap.end()); }
0041   //! return tower map for c++11 range-based for-loop
0042   const TowerMap& get_towermap() const override { return towermap; }
0043   //
0044   //! cluster position in 3D
0045   CLHEP::Hep3Vector get_position() const override
0046   {
0047     return CLHEP::Hep3Vector(get_x(), get_y(), get_z());
0048   }
0049   //!  access to intrinsic cylindrical coordinate system
0050   float get_phi() const override { return _phi; }
0051   float get_r() const override { return _r; }
0052   float get_z() const override { return _z; }
0053   //
0054   //  //! convert cluster location to psuedo-rapidity given a user chosen z-location
0055   //  virtual float get_eta(const float z) const;
0056   //  //! convert cluster E_T given a user chosen z-location
0057   //  virtual float get_et(const float z) const;
0058   //
0059   //! access Cartesian coordinate system
0060   float get_x() const override { return get_r() * std::cos(get_phi()); }
0061   float get_y() const override { return get_r() * std::sin(get_phi()); }
0062   //
0063   //! access additional optional properties
0064   //! cluster core energy for EM shower
0065   float get_ecore() const override { return get_property_float(prop_ecore); }
0066   //! reduced chi2 for EM shower
0067   float get_chi2() const override { return get_property_float(prop_chi2); }
0068   //! cluster template probability for EM shower
0069   float get_prob() const override { return get_property_float(prop_prob); }
0070   //! cluster template merged pi0 cluster probability for EM shower
0071   float get_merged_cluster_prob() const override { return get_property_float(prop_merged_cluster_prob); }
0072   //! isolation ET default
0073   float get_et_iso() const override { return get_property_float(prop_et_iso_calotower_R03); }
0074   //! isolation ET the radius and hueristic can be specified
0075   float get_et_iso(const int radiusx10, bool subtracted, bool clusterTower) const override;
0076 
0077   //! tower-space CoG in tower units (stored via property map)
0078   float x_tower_raw() const override  { return get_property_float(prop_tower_x_raw); }
0079   float y_tower_raw() const override  { return get_property_float(prop_tower_y_raw); }
0080   float x_tower_corr() const override { return get_property_float(prop_tower_x_corr); }
0081   float y_tower_corr() const override { return get_property_float(prop_tower_y_corr); }
0082 
0083   //! energy-weighted mean time
0084   float mean_time() const override { return get_property_float(prop_tower_t_mean); }
0085 
0086   //! optional convenience accessors for mechanical incidence (return NaN if unset)
0087   float alpha_mech_phi() const { return get_property_float(prop_incidence_alpha_phi); }
0088   float alpha_mech_eta() const { return get_property_float(prop_incidence_alpha_eta); }
0089 
0090   std::vector<float> get_shower_shapes(float tower_thresh) const override;
0091   std::pair<int, int> get_lead_tower() const override;  // eta,phi of leading tower in cluster
0092 
0093   //  //! truth cluster's PHG4Particle ID
0094   //  virtual int get_truth_track_ID() const override { return get_property_int(prop_truth_track_ID); }
0095   //  //! truth cluster's PHG4Particle flavor
0096   //  virtual int get_truth_flavor() const override { return get_property_int(prop_truth_flavor); }
0097   //
0098   /** @} */  // end of getters
0099 
0100   /** @defgroup setters
0101    *  @{
0102    */
0103   //! cluster ID
0104   void set_id(const RawClusterDefs::keytype id) override { clusterid = id; }
0105   //! Tower operations
0106   void addTower(const RawClusterDefs::keytype twrid, const float etower) override;
0107   //! total energy
0108   void set_energy(const float energy) override { _energy = energy; }
0109   //!  access to intrinsic cylindrical coordinate system
0110   void set_phi(const float phi) override { _phi = phi; }
0111   void set_z(const float z) override { _z = z; }
0112   void set_r(const float r) override { _r = r; }
0113   //
0114   //! access additional optional properties
0115   //! cluster core energy for EM shower
0116   void set_ecore(const float ecore) override { set_property(prop_ecore, ecore); }
0117   //! reduced chi2 for EM shower
0118   void set_chi2(const float chi2) override { set_property(prop_chi2, chi2); }
0119   //! cluster template probability for EM shower
0120   void set_prob(const float prob) override { set_property(prop_prob, prob); }
0121   //! cluster template merged pi0 cluster probability for EM shower
0122   void set_merged_cluster_prob(const float probmergedcluster) override { set_property(prop_merged_cluster_prob, probmergedcluster); }
0123   //! isolation ET default
0124   void set_et_iso(const float e) override { set_property(prop_et_iso_calotower_R03, e); }
0125   //! isolation ET the radius and hueristic can be specified
0126   void set_et_iso(const float et_iso, const int radiusx10, bool subtracted, bool clusterTower) override;
0127 
0128   //! tower-space CoG in tower units (stored via property map)
0129   void set_tower_cog(float xr, float yr, float xc, float yc) override
0130   {
0131       set_property(prop_tower_x_raw,  xr);
0132       set_property(prop_tower_y_raw,  yr);
0133       set_property(prop_tower_x_corr, xc);
0134       set_property(prop_tower_y_corr, yc);
0135   }
0136 
0137   //! energy-weighted mean time
0138   void set_mean_time(float t) override
0139   {
0140       set_property(prop_tower_t_mean, t);
0141   }
0142   //  //! truth cluster's PHG4Particle ID
0143   //  virtual void set_truth_track_ID(const int i) override { set_property(prop_truth_track_ID, i); }
0144   //  //! truth cluster's PHG4Particle flavor
0145   //  virtual void set_truth_flavor(const int f) override { set_property(prop_truth_flavor, f); }
0146   //
0147   /*
0148    *
0149    * @} */
0150   // end of setters
0151 
0152   /** @defgroup property_map property map definitions
0153    *  @{
0154    */
0155  public:
0156   bool has_property(const PROPERTY prop_id) const override;
0157   float get_property_float(const PROPERTY prop_id) const override;
0158   int get_property_int(const PROPERTY prop_id) const override;
0159   unsigned int get_property_uint(const PROPERTY prop_id) const override;
0160   void set_property(const PROPERTY prop_id, const float value) override;
0161   void set_property(const PROPERTY prop_id, const int value) override;
0162   void set_property(const PROPERTY prop_id, const unsigned int value) override;
0163 
0164  protected:  // protected is declared twice !?
0165   unsigned int get_property_nocheck(const PROPERTY prop_id) const;
0166   void set_property_nocheck(const PROPERTY prop_id, const unsigned int ui) { prop_map[prop_id] = ui; }
0167   //! storage types for additional property
0168   typedef uint8_t prop_id_t;
0169   typedef uint32_t prop_storage_t;
0170   typedef std::map<prop_id_t, prop_storage_t> prop_map_t;
0171 
0172   //! convert between 32bit inputs and storage type prop_storage_t
0173   union u_property
0174   {
0175     float fdata;
0176     int32_t idata;
0177     uint32_t uidata;
0178 
0179     u_property(int32_t in)
0180       : idata(in)
0181     {
0182     }
0183     u_property(uint32_t in)
0184       : uidata(in)
0185     {
0186     }
0187     u_property(float in)
0188       : fdata(in)
0189     {
0190     }
0191     u_property()
0192       : uidata(0)
0193     {
0194     }
0195 
0196     prop_storage_t get_storage() const { return uidata; }
0197   };
0198 
0199   //! container for additional property
0200   prop_map_t prop_map;
0201 
0202   /** @} */  // end of property map definitions
0203 
0204  private:
0205   void copy_property_from_cluster(const RawCluster& source, const PROPERTY prop_id);
0206 
0207   //
0208  protected:
0209   //! cluster ID
0210   RawClusterDefs::keytype clusterid{0};
0211   //! total energy
0212   float _energy{std::numeric_limits<float>::quiet_NaN()};
0213   //! Tower operations
0214   TowerMap towermap;
0215 
0216   //! location of cluster in cylindrical coordinate
0217   float _r{std::numeric_limits<float>::quiet_NaN()};
0218   float _phi{std::numeric_limits<float>::quiet_NaN()};
0219   float _z{std::numeric_limits<float>::quiet_NaN()};
0220 
0221   ClassDefOverride(RawClusterv1, 3)
0222 };
0223 
0224 #endif