Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-07-09 05:00:03

0001 #ifndef DataFormats_CaloRecHit_CaloCluster_h
0002 #define DataFormats_CaloRecHit_CaloCluster_h
0003 
0004 /** \class reco::CaloCluster 
0005  *  
0006  * Base class for all types calorimeter clusters
0007  *
0008  * \author Shahram Rahatlou, INFN
0009  *
0010  * Comments:
0011  * modified AlgoId enumeration to include cleaning status flags
0012  * In summary:
0013  * algoID_ < 200 object is in clean collection
0014  * algoID_ >=100 object is in unclean collection
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     // super-cluster flags
0050     enum SCFlags { cleanOnly = 0, common = 100, uncleanOnly = 200 };
0051     // hcal cluster flags (used for pf)
0052     enum HCalFlags { badHcalMarker = 1 };
0053 
0054     //FIXME:
0055     //temporary fix... to be removed before 310 final
0056     typedef AlgoId AlgoID;
0057 
0058     /// default constructor. Sets energy and position to zero
0059     CaloCluster()
0060         : energy_(0), correctedEnergy_(-1.0), correctedEnergyUncertainty_(-1.0), algoID_(undefined), flags_(0) {}
0061 
0062     /// constructor with algoId, to be used in all child classes
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     /// resets the CaloCluster (position, energy, hitsAndFractions)
0076     void reset();
0077 
0078     /// constructor from values
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     //FIXME:
0117     /// temporary compatibility constructor
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     /// destructor
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     /// cluster energy
0151     double energy() const { return energy_; }
0152     double correctedEnergy() const { return correctedEnergy_; }
0153     float correctedEnergyUncertainty() const { return correctedEnergyUncertainty_; }
0154 
0155     /// cluster centroid position
0156     const math::XYZPoint& position() const { return position_; }
0157 
0158     /// comparison >= operator
0159     bool operator>=(const CaloCluster& rhs) const { return (energy_ >= rhs.energy_); }
0160 
0161     /// comparison > operator
0162     bool operator>(const CaloCluster& rhs) const { return (energy_ > rhs.energy_); }
0163 
0164     /// comparison <= operator
0165     bool operator<=(const CaloCluster& rhs) const { return (energy_ <= rhs.energy_); }
0166 
0167     /// comparison < operator
0168     bool operator<(const CaloCluster& rhs) const { return (energy_ < rhs.energy_); }
0169 
0170     /// comparison == operator
0171     bool operator==(const CaloCluster& rhs) const { return (energy_ == rhs.energy_); };
0172 
0173     /// x coordinate of cluster centroid
0174     double x() const { return position_.x(); }
0175 
0176     /// y coordinate of cluster centroid
0177     double y() const { return position_.y(); }
0178 
0179     /// z coordinate of cluster centroid
0180     double z() const { return position_.z(); }
0181 
0182     /// pseudorapidity of cluster centroid
0183     double eta() const { return position_.eta(); }
0184 
0185     /// azimuthal angle of cluster centroid
0186     double phi() const { return position_.phi(); }
0187 
0188     /// size in number of hits (e.g. in crystals for ECAL)
0189     size_t size() const { return hitsAndFractions_.size(); }
0190 
0191     /// algorithm identifier
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     /// replace getHitsByDetId() : return hits by DetId
0210     /// and their corresponding fraction of energy considered
0211     /// to compute the total cluster energy
0212     const std::vector<std::pair<DetId, float> >& hitsAndFractions() const { return hitsAndFractions_; }
0213 
0214     /// print hitAndFraction
0215     std::string printHitAndFraction(unsigned i) const;
0216 
0217     /// print me
0218     friend std::ostream& operator<<(std::ostream& out, const CaloCluster& cluster);
0219 
0220     /// return DetId of seed
0221     DetId seed() const { return seedId_; }
0222 
0223   protected:
0224     /// cluster energy
0225     double energy_;
0226     double correctedEnergy_;
0227     float correctedEnergyUncertainty_;
0228 
0229     /// cluster centroid position
0230     math::XYZPoint position_;
0231 
0232     /// bitmask for detector information
0233     CaloID caloID_;
0234 
0235     // used hits by detId
0236     std::vector<std::pair<DetId, float> > hitsAndFractions_;
0237 
0238     // cluster algorithm Id
0239     AlgoID algoID_;
0240 
0241     /// DetId of seed
0242     DetId seedId_;
0243 
0244     /// flags (e.g. for handling of cleaned/uncleaned SC)
0245     /// 4  most significant bits  reserved
0246     /// 28 bits for handling of cleaned/uncleaned
0247     uint32_t flags_;
0248 
0249     static const uint32_t flagsMask_ = 0x0FFFFFFF;
0250     static const uint32_t flagsOffset_ = 28;
0251   };
0252 
0253 }  // namespace reco
0254 
0255 #endif