Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:03:47

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