Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-06-13 03:23:31

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       undefined = 1000
0045     };
0046 
0047     // super-cluster flags
0048     enum SCFlags { cleanOnly = 0, common = 100, uncleanOnly = 200 };
0049     // hcal cluster flags (used for pf)
0050     enum HCalFlags { badHcalMarker = 1 };
0051 
0052     //FIXME:
0053     //temporary fix... to be removed before 310 final
0054     typedef AlgoId AlgoID;
0055 
0056     /// default constructor. Sets energy and position to zero
0057     CaloCluster()
0058         : energy_(0), correctedEnergy_(-1.0), correctedEnergyUncertainty_(-1.0), algoID_(undefined), flags_(0) {}
0059 
0060     /// constructor with algoId, to be used in all child classes
0061     CaloCluster(AlgoID algoID)
0062         : energy_(0), correctedEnergy_(-1.0), correctedEnergyUncertainty_(-1.0), algoID_(algoID), flags_(0) {}
0063 
0064     CaloCluster(double energy, const math::XYZPoint& position, const CaloID& caloID)
0065         : energy_(energy),
0066           correctedEnergy_(-1.0),
0067           correctedEnergyUncertainty_(-1.0),
0068           position_(position),
0069           caloID_(caloID),
0070           algoID_(undefined),
0071           flags_(0) {}
0072 
0073     /// resets the CaloCluster (position, energy, hitsAndFractions)
0074     void reset();
0075 
0076     /// constructor from values
0077     CaloCluster(double energy, const math::XYZPoint& position)
0078         : energy_(energy),
0079           correctedEnergy_(-1.0),
0080           correctedEnergyUncertainty_(-1.0),
0081           position_(position),
0082           algoID_(undefined),
0083           flags_(0) {}
0084 
0085     CaloCluster(
0086         double energy, const math::XYZPoint& position, const CaloID& caloID, const AlgoID& algoID, uint32_t flags = 0)
0087         : energy_(energy),
0088           correctedEnergy_(-1.0),
0089           correctedEnergyUncertainty_(-1.0),
0090           position_(position),
0091           caloID_(caloID),
0092           algoID_(algoID) {
0093       flags_ = flags & flagsMask_;
0094     }
0095 
0096     CaloCluster(double energy,
0097                 const math::XYZPoint& position,
0098                 const CaloID& caloID,
0099                 const std::vector<std::pair<DetId, float> >& usedHitsAndFractions,
0100                 const AlgoId algoId,
0101                 const DetId seedId = DetId(0),
0102                 uint32_t flags = 0)
0103         : energy_(energy),
0104           correctedEnergy_(-1.0),
0105           correctedEnergyUncertainty_(-1.0),
0106           position_(position),
0107           caloID_(caloID),
0108           hitsAndFractions_(usedHitsAndFractions),
0109           algoID_(algoId),
0110           seedId_(seedId) {
0111       flags_ = flags & flagsMask_;
0112     }
0113 
0114     //FIXME:
0115     /// temporary compatibility constructor
0116     CaloCluster(double energy,
0117                 const math::XYZPoint& position,
0118                 float chi2,
0119                 const std::vector<DetId>& usedHits,
0120                 const AlgoId algoId,
0121                 uint32_t flags = 0)
0122         : energy_(energy),
0123           correctedEnergy_(-1.0),
0124           correctedEnergyUncertainty_(-1.0),
0125           position_(position),
0126           algoID_(algoId) {
0127       hitsAndFractions_.reserve(usedHits.size());
0128       for (size_t i = 0; i < usedHits.size(); i++)
0129         hitsAndFractions_.push_back(std::pair<DetId, float>(usedHits[i], 1.));
0130       flags_ = flags & flagsMask_;
0131     }
0132 
0133     /// destructor
0134     virtual ~CaloCluster() {}
0135 
0136     void setEnergy(double energy) { energy_ = energy; }
0137     void setCorrectedEnergy(double cenergy) { correctedEnergy_ = cenergy; }
0138     void setCorrectedEnergyUncertainty(float energyerr) { correctedEnergyUncertainty_ = energyerr; }
0139 
0140     void setPosition(const math::XYZPoint& p) { position_ = p; }
0141 
0142     void setCaloId(const CaloID& id) { caloID_ = id; }
0143 
0144     void setAlgoId(const AlgoId& id) { algoID_ = id; }
0145 
0146     void setSeed(const DetId& id) { seedId_ = id; }
0147 
0148     /// cluster energy
0149     double energy() const { return energy_; }
0150     double correctedEnergy() const { return correctedEnergy_; }
0151     float correctedEnergyUncertainty() const { return correctedEnergyUncertainty_; }
0152 
0153     /// cluster centroid position
0154     const math::XYZPoint& position() const { return position_; }
0155 
0156     /// comparison >= operator
0157     bool operator>=(const CaloCluster& rhs) const { return (energy_ >= rhs.energy_); }
0158 
0159     /// comparison > operator
0160     bool operator>(const CaloCluster& rhs) const { return (energy_ > rhs.energy_); }
0161 
0162     /// comparison <= operator
0163     bool operator<=(const CaloCluster& rhs) const { return (energy_ <= rhs.energy_); }
0164 
0165     /// comparison < operator
0166     bool operator<(const CaloCluster& rhs) const { return (energy_ < rhs.energy_); }
0167 
0168     /// comparison == operator
0169     bool operator==(const CaloCluster& rhs) const { return (energy_ == rhs.energy_); };
0170 
0171     /// x coordinate of cluster centroid
0172     double x() const { return position_.x(); }
0173 
0174     /// y coordinate of cluster centroid
0175     double y() const { return position_.y(); }
0176 
0177     /// z coordinate of cluster centroid
0178     double z() const { return position_.z(); }
0179 
0180     /// pseudorapidity of cluster centroid
0181     double eta() const { return position_.eta(); }
0182 
0183     /// azimuthal angle of cluster centroid
0184     double phi() const { return position_.phi(); }
0185 
0186     /// size in number of hits (e.g. in crystals for ECAL)
0187     size_t size() const { return hitsAndFractions_.size(); }
0188 
0189     /// algorithm identifier
0190     AlgoId algo() const { return algoID_; }
0191     AlgoID algoID() const { return algo(); }
0192 
0193     uint32_t flags() const { return flags_ & flagsMask_; }
0194     void setFlags(uint32_t flags) {
0195       uint32_t reserved = (flags_ & ~flagsMask_);
0196       flags_ = (reserved) | (flags & flagsMask_);
0197     }
0198     bool isInClean() const { return flags() < uncleanOnly; }
0199     bool isInUnclean() const { return flags() >= common; }
0200 
0201     const CaloID& caloID() const { return caloID_; }
0202 
0203     void addHitAndFraction(DetId id, float fraction) {
0204       hitsAndFractions_.push_back(std::pair<DetId, float>(id, fraction));
0205     }
0206 
0207     /// replace getHitsByDetId() : return hits by DetId
0208     /// and their corresponding fraction of energy considered
0209     /// to compute the total cluster energy
0210     const std::vector<std::pair<DetId, float> >& hitsAndFractions() const { return hitsAndFractions_; }
0211 
0212     /// print hitAndFraction
0213     std::string printHitAndFraction(unsigned i) const;
0214 
0215     /// print me
0216     friend std::ostream& operator<<(std::ostream& out, const CaloCluster& cluster);
0217 
0218     /// return DetId of seed
0219     DetId seed() const { return seedId_; }
0220 
0221   protected:
0222     /// cluster energy
0223     double energy_;
0224     double correctedEnergy_;
0225     float correctedEnergyUncertainty_;
0226 
0227     /// cluster centroid position
0228     math::XYZPoint position_;
0229 
0230     /// bitmask for detector information
0231     CaloID caloID_;
0232 
0233     // used hits by detId
0234     std::vector<std::pair<DetId, float> > hitsAndFractions_;
0235 
0236     // cluster algorithm Id
0237     AlgoID algoID_;
0238 
0239     /// DetId of seed
0240     DetId seedId_;
0241 
0242     /// flags (e.g. for handling of cleaned/uncleaned SC)
0243     /// 4  most significant bits  reserved
0244     /// 28 bits for handling of cleaned/uncleaned
0245     uint32_t flags_;
0246 
0247     static const uint32_t flagsMask_ = 0x0FFFFFFF;
0248     static const uint32_t flagsOffset_ = 28;
0249   };
0250 
0251 }  // namespace reco
0252 
0253 #endif