File indexing completed on 2025-07-09 05:00:03
0001 #ifndef DataFormats_CaloRecHit_CaloCluster_h
0002 #define DataFormats_CaloRecHit_CaloCluster_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #include "DataFormats/Math/interface/Point3D.h"
0018 #include "DataFormats/CaloRecHit/interface/CaloID.h"
0019
0020 #include "DataFormats/DetId/interface/DetId.h"
0021
0022 #include <vector>
0023 #include <string>
0024 #include <iostream>
0025
0026 namespace reco {
0027
0028 class CaloCluster;
0029 std::ostream& operator<<(std::ostream& out, const CaloCluster& cluster);
0030
0031 class CaloCluster {
0032 public:
0033 enum AlgoId {
0034 island = 0,
0035 hybrid = 1,
0036 fixedMatrix = 2,
0037 dynamicHybrid = 3,
0038 multi5x5 = 4,
0039 particleFlow = 5,
0040 hgcal_em = 6,
0041 hgcal_had = 7,
0042 hgcal_scintillator = 8,
0043 hfnose = 9,
0044 barrel_em = 10,
0045 barrel_had = 11,
0046 undefined = 1000
0047 };
0048
0049
0050 enum SCFlags { cleanOnly = 0, common = 100, uncleanOnly = 200 };
0051
0052 enum HCalFlags { badHcalMarker = 1 };
0053
0054
0055
0056 typedef AlgoId AlgoID;
0057
0058
0059 CaloCluster()
0060 : energy_(0), correctedEnergy_(-1.0), correctedEnergyUncertainty_(-1.0), algoID_(undefined), flags_(0) {}
0061
0062
0063 CaloCluster(AlgoID algoID)
0064 : energy_(0), correctedEnergy_(-1.0), correctedEnergyUncertainty_(-1.0), algoID_(algoID), flags_(0) {}
0065
0066 CaloCluster(double energy, const math::XYZPoint& position, const CaloID& caloID)
0067 : energy_(energy),
0068 correctedEnergy_(-1.0),
0069 correctedEnergyUncertainty_(-1.0),
0070 position_(position),
0071 caloID_(caloID),
0072 algoID_(undefined),
0073 flags_(0) {}
0074
0075
0076 void reset();
0077
0078
0079 CaloCluster(double energy, const math::XYZPoint& position)
0080 : energy_(energy),
0081 correctedEnergy_(-1.0),
0082 correctedEnergyUncertainty_(-1.0),
0083 position_(position),
0084 algoID_(undefined),
0085 flags_(0) {}
0086
0087 CaloCluster(
0088 double energy, const math::XYZPoint& position, const CaloID& caloID, const AlgoID& algoID, uint32_t flags = 0)
0089 : energy_(energy),
0090 correctedEnergy_(-1.0),
0091 correctedEnergyUncertainty_(-1.0),
0092 position_(position),
0093 caloID_(caloID),
0094 algoID_(algoID) {
0095 flags_ = flags & flagsMask_;
0096 }
0097
0098 CaloCluster(double energy,
0099 const math::XYZPoint& position,
0100 const CaloID& caloID,
0101 const std::vector<std::pair<DetId, float> >& usedHitsAndFractions,
0102 const AlgoId algoId,
0103 const DetId seedId = DetId(0),
0104 uint32_t flags = 0)
0105 : energy_(energy),
0106 correctedEnergy_(-1.0),
0107 correctedEnergyUncertainty_(-1.0),
0108 position_(position),
0109 caloID_(caloID),
0110 hitsAndFractions_(usedHitsAndFractions),
0111 algoID_(algoId),
0112 seedId_(seedId) {
0113 flags_ = flags & flagsMask_;
0114 }
0115
0116
0117
0118 CaloCluster(double energy,
0119 const math::XYZPoint& position,
0120 float chi2,
0121 const std::vector<DetId>& usedHits,
0122 const AlgoId algoId,
0123 uint32_t flags = 0)
0124 : energy_(energy),
0125 correctedEnergy_(-1.0),
0126 correctedEnergyUncertainty_(-1.0),
0127 position_(position),
0128 algoID_(algoId) {
0129 hitsAndFractions_.reserve(usedHits.size());
0130 for (size_t i = 0; i < usedHits.size(); i++)
0131 hitsAndFractions_.push_back(std::pair<DetId, float>(usedHits[i], 1.));
0132 flags_ = flags & flagsMask_;
0133 }
0134
0135
0136 virtual ~CaloCluster() {}
0137
0138 void setEnergy(double energy) { energy_ = energy; }
0139 void setCorrectedEnergy(double cenergy) { correctedEnergy_ = cenergy; }
0140 void setCorrectedEnergyUncertainty(float energyerr) { correctedEnergyUncertainty_ = energyerr; }
0141
0142 void setPosition(const math::XYZPoint& p) { position_ = p; }
0143
0144 void setCaloId(const CaloID& id) { caloID_ = id; }
0145
0146 void setAlgoId(const AlgoId& id) { algoID_ = id; }
0147
0148 void setSeed(const DetId& id) { seedId_ = id; }
0149
0150
0151 double energy() const { return energy_; }
0152 double correctedEnergy() const { return correctedEnergy_; }
0153 float correctedEnergyUncertainty() const { return correctedEnergyUncertainty_; }
0154
0155
0156 const math::XYZPoint& position() const { return position_; }
0157
0158
0159 bool operator>=(const CaloCluster& rhs) const { return (energy_ >= rhs.energy_); }
0160
0161
0162 bool operator>(const CaloCluster& rhs) const { return (energy_ > rhs.energy_); }
0163
0164
0165 bool operator<=(const CaloCluster& rhs) const { return (energy_ <= rhs.energy_); }
0166
0167
0168 bool operator<(const CaloCluster& rhs) const { return (energy_ < rhs.energy_); }
0169
0170
0171 bool operator==(const CaloCluster& rhs) const { return (energy_ == rhs.energy_); };
0172
0173
0174 double x() const { return position_.x(); }
0175
0176
0177 double y() const { return position_.y(); }
0178
0179
0180 double z() const { return position_.z(); }
0181
0182
0183 double eta() const { return position_.eta(); }
0184
0185
0186 double phi() const { return position_.phi(); }
0187
0188
0189 size_t size() const { return hitsAndFractions_.size(); }
0190
0191
0192 AlgoId algo() const { return algoID_; }
0193 AlgoID algoID() const { return algo(); }
0194
0195 uint32_t flags() const { return flags_ & flagsMask_; }
0196 void setFlags(uint32_t flags) {
0197 uint32_t reserved = (flags_ & ~flagsMask_);
0198 flags_ = (reserved) | (flags & flagsMask_);
0199 }
0200 bool isInClean() const { return flags() < uncleanOnly; }
0201 bool isInUnclean() const { return flags() >= common; }
0202
0203 const CaloID& caloID() const { return caloID_; }
0204
0205 void addHitAndFraction(DetId id, float fraction) {
0206 hitsAndFractions_.push_back(std::pair<DetId, float>(id, fraction));
0207 }
0208
0209
0210
0211
0212 const std::vector<std::pair<DetId, float> >& hitsAndFractions() const { return hitsAndFractions_; }
0213
0214
0215 std::string printHitAndFraction(unsigned i) const;
0216
0217
0218 friend std::ostream& operator<<(std::ostream& out, const CaloCluster& cluster);
0219
0220
0221 DetId seed() const { return seedId_; }
0222
0223 protected:
0224
0225 double energy_;
0226 double correctedEnergy_;
0227 float correctedEnergyUncertainty_;
0228
0229
0230 math::XYZPoint position_;
0231
0232
0233 CaloID caloID_;
0234
0235
0236 std::vector<std::pair<DetId, float> > hitsAndFractions_;
0237
0238
0239 AlgoID algoID_;
0240
0241
0242 DetId seedId_;
0243
0244
0245
0246
0247 uint32_t flags_;
0248
0249 static const uint32_t flagsMask_ = 0x0FFFFFFF;
0250 static const uint32_t flagsOffset_ = 28;
0251 };
0252
0253 }
0254
0255 #endif