File indexing completed on 2024-04-06 12:04:52
0001 #ifndef ParticleFlowReco_PFRecHit_h
0002 #define ParticleFlowReco_PFRecHit_h
0003
0004
0005 #include <vector>
0006 #include <map>
0007 #include <memory>
0008 #include <iostream>
0009
0010 #include "DataFormats/Math/interface/Point3D.h"
0011 #include "DataFormats/Math/interface/Vector3D.h"
0012 #include "Math/GenVector/PositionVector3D.h"
0013 #include "DataFormats/ParticleFlowReco/interface/PFLayer.h"
0014 #include "DataFormats/ParticleFlowReco/interface/PFRecHitFwd.h"
0015
0016 #include "DataFormats/CaloRecHit/interface/CaloRecHit.h"
0017 #include "DataFormats/Common/interface/RefToBase.h"
0018
0019 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
0020
0021 namespace reco {
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 class PFRecHit {
0032 public:
0033 using PositionType = GlobalPoint::BasicVectorType;
0034 using REPPoint = RhoEtaPhi;
0035 using RepCorners = CaloCellGeometry::RepCorners;
0036 using REPPointVector = RepCorners;
0037 using CornersVec = CaloCellGeometry::CornersVec;
0038
0039 struct Neighbours {
0040 using Pointer = unsigned int const*;
0041 Neighbours() {}
0042 Neighbours(Pointer ib, unsigned int n) : b(ib), e(ib + n) {}
0043 Pointer b, e;
0044 Pointer begin() const { return b; }
0045 Pointer end() const { return e; }
0046 unsigned int size() const { return e - b; }
0047 };
0048
0049 enum { NONE = 0 };
0050
0051 PFRecHit() {}
0052
0053 PFRecHit(std::shared_ptr<const CaloCellGeometry> caloCell,
0054 unsigned int detId,
0055 PFLayer::Layer layer,
0056 float energy,
0057 uint32_t flags = 0)
0058 : caloCell_(std::move(caloCell)), detId_(detId), layer_(layer), energy_(energy), flags_(flags) {}
0059
0060
0061 PFRecHit(const PFRecHit& other) = default;
0062 PFRecHit(PFRecHit&& other) = default;
0063 PFRecHit& operator=(const PFRecHit& other) = default;
0064 PFRecHit& operator=(PFRecHit&& other) = default;
0065
0066
0067 ~PFRecHit() = default;
0068
0069 void setEnergy(float energy) { energy_ = energy; }
0070
0071 void addNeighbour(short x, short y, short z, unsigned int);
0072 unsigned int getNeighbour(short x, short y, short z) const;
0073 void setTime(double time) { time_ = time; }
0074 void setDepth(int depth) { depth_ = depth; }
0075 void clearNeighbours() {
0076 neighbours_.clear();
0077 neighbourInfos_.clear();
0078 neighbours4_ = neighbours8_ = 0;
0079 }
0080
0081 Neighbours neighbours4() const { return buildNeighbours(neighbours4_); }
0082 Neighbours neighbours8() const { return buildNeighbours(neighbours8_); }
0083
0084 Neighbours neighbours() const { return buildNeighbours(neighbours_.size()); }
0085
0086 const std::vector<unsigned short>& neighbourInfos() { return neighbourInfos_; }
0087
0088
0089 CaloCellGeometry const& caloCell() const { return *(caloCell_.get()); }
0090 bool hasCaloCell() const { return (caloCell_ != nullptr); }
0091
0092
0093 unsigned detId() const { return detId_; }
0094
0095
0096 PFLayer::Layer layer() const { return layer_; }
0097
0098
0099 float energy() const { return energy_; }
0100
0101
0102 float time() const { return time_; }
0103
0104
0105 int depth() const { return depth_; }
0106
0107
0108 double pt2() const { return energy_ * energy_ * (position().perp2() / position().mag2()); }
0109
0110
0111 uint32_t flags() const { return flags_; }
0112
0113
0114 void setFlags(uint32_t flags) { flags_ = flags; }
0115
0116
0117 PositionType const& position() const { return caloCell().getPosition().basicVector(); }
0118
0119 RhoEtaPhi const& positionREP() const { return caloCell().repPos(); }
0120
0121
0122 CornersVec const& getCornersXYZ() const { return caloCell().getCorners(); }
0123
0124 RepCorners const& getCornersREP() const { return caloCell().getCornersREP(); }
0125
0126
0127 bool operator>=(const PFRecHit& rhs) const { return (energy_ >= rhs.energy_); }
0128
0129
0130 bool operator>(const PFRecHit& rhs) const { return (energy_ > rhs.energy_); }
0131
0132
0133 bool operator<=(const PFRecHit& rhs) const { return (energy_ <= rhs.energy_); }
0134
0135
0136 bool operator<(const PFRecHit& rhs) const { return (energy_ < rhs.energy_); }
0137
0138 private:
0139 Neighbours buildNeighbours(unsigned int n) const { return Neighbours(neighbours_.data(), n); }
0140
0141
0142 std::shared_ptr<const CaloCellGeometry> caloCell_ = nullptr;
0143
0144
0145 unsigned int detId_ = 0;
0146
0147
0148 PFLayer::Layer layer_ = PFLayer::NONE;
0149
0150
0151 float energy_ = 0;
0152
0153
0154 float time_ = -1;
0155
0156
0157 int depth_ = 0;
0158
0159
0160 std::vector<unsigned int> neighbours_;
0161 std::vector<unsigned short> neighbourInfos_;
0162
0163
0164 unsigned int neighbours4_ = 0;
0165 unsigned int neighbours8_ = 0;
0166
0167
0168 uint32_t flags_ = 0;
0169 };
0170
0171 }
0172 std::ostream& operator<<(std::ostream& out, const reco::PFRecHit& hit);
0173
0174 #endif