Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:17:46

0001 /*!
0002  * \file    Jetv2.h
0003  * \brief   Version of Jet.h updated to include data in vector<float> instead of map<int,float>
0004  * \author  David Stewart <jhuang@bnl.gov>
0005  * \version $Revision:   $
0006  * \date    $Date: $
0007  */
0008 
0009 #ifndef JETBASE_JETV2_H
0010 #define JETBASE_JETV2_H
0011 
0012 #include "Jet.h"
0013 
0014 #include <array>
0015 #include <cmath>
0016 #include <cstddef>  // for size_t
0017 #include <iostream>
0018 #include <map>
0019 #include <utility>  // for pair, make_pair
0020 
0021 class PHObject;
0022 
0023 /*!
0024  * \brief Jetv2
0025  */
0026 class Jetv2 : public Jet
0027 {
0028  public:
0029   Jetv2() = default;
0030   Jetv2(unsigned int);
0031   /* ~Jetv2() override = default; //{} */
0032   /* Jetv2(const Jetv2&) = default; */
0033   /* Jetv2(Jetv2&) = default; */
0034   /* Jetv2& operator=(const Jetv2&) = default; */
0035 
0036   // method used to sort the consistuents of the jet -- to be used when generating the jets only
0037   struct CompareSRC
0038   {
0039     bool operator()(const std::pair<Jet::SRC, int>& lhs, const unsigned int rhs)
0040     {
0041       return static_cast<unsigned int>(lhs.first) < rhs;
0042     }
0043     bool operator()(const unsigned int lhs, const std::pair<Jet::SRC, int>& rhs)
0044     {
0045       return lhs < static_cast<unsigned int>(rhs.first);
0046     }
0047     bool operator()(const std::pair<Jet::SRC, int>& lhs, const std::pair<Jet::SRC, int>& rhs)
0048     {
0049       return static_cast<unsigned int>(lhs.first) < static_cast<unsigned int>(rhs.first);
0050     }
0051     /* static void sort_comp_ids(Jetv2* jet); */
0052   };
0053 
0054   // PHObject virtual overloads
0055 
0056   void identify(std::ostream& os = std::cout) const override;
0057   void Reset() override;
0058   int isValid() const override;
0059   PHObject* CloneMe() const override;
0060 
0061   // jet info
0062 
0063   unsigned int get_id() const override { return _id; }
0064   void set_id(unsigned int id) override { _id = id; }
0065 
0066   float get_px() const override { return _mom[0]; }
0067   void set_px(float px) override { _mom[0] = px; }
0068 
0069   float get_py() const override { return _mom[1]; }
0070   void set_py(float py) override { _mom[1] = py; }
0071 
0072   float get_pz() const override { return _mom[2]; }
0073   void set_pz(float pz) override { _mom[2] = pz; }
0074 
0075   float get_e() const override { return _e; }
0076   void set_e(float e) override { _e = e; }
0077 
0078   float get_eta() const override;
0079 
0080   int get_isCalib()  override {return _isCalib;}
0081   void set_isCalib(int calib) override {_isCalib = calib;}
0082   
0083   float get_p() const override;
0084   float get_pt() const override;
0085   float get_et() const override;
0086   float get_phi() const override;
0087   float get_mass() const override;
0088   float get_mass2() const override;
0089 
0090   // Jet properties
0091   void resize_properties(size_t size) override { _properties.resize(size, std::numeric_limits<float>::quiet_NaN()); };
0092   std::vector<float>& get_property_vec() override { return _properties; }  // new in v2
0093   size_t size_properties() const override { return _properties.size(); }   // implemented in v1 and v2
0094 
0095   float get_property(Jet::PROPERTY index) const override { return _properties[static_cast<int>(index)]; };
0096   inline void set_property(Jet::PROPERTY index, float value) override
0097   {
0098     _properties[static_cast<int>(index)] = value;
0099   };
0100 
0101   // Jet components
0102   size_t size_comp() const override { return _comp_ids.size(); }
0103   void clear_comp() override { _comp_ids.clear(); }
0104   void insert_comp(SRC iSRC, unsigned int compid) override;
0105   void insert_comp(Jet::SRC, unsigned int compid, bool) override;  // skips setting _is_sorted flag
0106   void insert_comp(TYPE_comp_vec&) override;
0107   void insert_comp(TYPE_comp_vec&, bool) override;
0108   void set_comp_sort_flag(bool f = false) override { _is_sorted = f; };
0109 
0110   void print_comp(std::ostream& os = std::cout, bool single_line = false) override;
0111   size_t num_comp(SRC iSRC = Jet::SRC::VOID) override;
0112   std::vector<Jet::SRC> comp_src_vec() override;
0113   std::map<Jet::SRC, size_t> comp_src_sizemap() override;  // map of Jet::SRC to number of entries
0114 
0115   // FYI: ITER_comp_vec = vector<pair<Jet::SRC, unsigned int>>::iterator
0116   ITER_comp_vec comp_begin() override { return _comp_ids.begin(); }  // new in v2
0117   ITER_comp_vec comp_begin(Jet::SRC) override;                       // new in v2
0118   ITER_comp_vec comp_end() override { return _comp_ids.end(); }      // new in v2
0119   ITER_comp_vec comp_end(Jet::SRC) override;                         // new in v2
0120   TYPE_comp_vec& get_comp_vec() override { return _comp_ids; };      // new in v2
0121 
0122   inline void Clear(Option_t* = nullptr) override { Reset(); }
0123 
0124  private:
0125   /// unique identifier within container
0126   unsigned int _id = ~0x0;
0127   void ensure_sorted();
0128   bool _is_sorted{false};
0129 
0130   /// jet momentum vector (px,py,pz)
0131   std::array<float, 3> _mom{{std::numeric_limits<float>::quiet_NaN(), std::numeric_limits<float>::quiet_NaN(), std::numeric_limits<float>::quiet_NaN()}};
0132 
0133   /// jet energy
0134   float _e {std::numeric_limits<float>::quiet_NaN()};
0135 
0136   /// calibration flag
0137   int _isCalib{0};
0138   /// source id -> component id
0139   /* typ_comp_ids _comp_ids; */
0140   std::vector<std::pair<Jet::SRC, unsigned int>> _comp_ids;
0141 
0142   std::vector<float> _properties{};
0143 
0144   bool empty_comp() const override;
0145   size_t count_comp(SRC source /**/) const override;
0146 
0147   // only in v1 msg
0148   static void msg_dep_fn(const std::string& fn_name) ;
0149 
0150   // functions deprecated in this Jet Version
0151   bool has_property(Jet::PROPERTY /*prop_id*/) const override;
0152   void print_property(std::ostream& /**/) const override;
0153   ConstIter begin_comp() const override;
0154   ConstIter lower_bound_comp(SRC source) const override;
0155   ConstIter upper_bound_comp(SRC source) const override;
0156   ConstIter find(Jet::SRC source) const override;
0157   ConstIter end_comp() const override;
0158 
0159   Iter begin_comp() override;
0160   Iter lower_bound_comp(SRC source) override;
0161   Iter upper_bound_comp(SRC source) override;
0162   Iter find(SRC source) override;
0163   Iter end_comp() override;
0164 
0165   size_t erase_comp(Jet::SRC /**/) override;
0166   void erase_comp(Iter /*iter*/) override;
0167   void erase_comp(Iter /*first*/, Iter /*last*/) override;
0168 
0169   ClassDefOverride(Jetv2, 1);
0170 };
0171 
0172 #endif  // JETBASE_JETV2_H