CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/DataFormats/CaloRecHit/interface/CaloCluster.h

Go to the documentation of this file.
00001 #ifndef DataFormats_CaloRecHit_CaloCluster_h
00002 #define DataFormats_CaloRecHit_CaloCluster_h
00003 
00018 #include "DataFormats/Math/interface/Point3D.h"
00019 #include "DataFormats/CaloRecHit/interface/CaloID.h"
00020 
00021 #include "DataFormats/DetId/interface/DetId.h"
00022 
00023 #include <vector>
00024 #include <string>
00025 #include <iostream>
00026 
00027 namespace reco {
00028 
00029 
00030   class CaloCluster {
00031   public:
00032     
00033     enum AlgoId { island = 0, hybrid = 1, fixedMatrix = 2, dynamicHybrid = 3, multi5x5 = 4, particleFlow = 5,  undefined = 1000};
00034 
00035     // super-cluster flags
00036     enum SCFlags { cleanOnly = 0, common = 100, uncleanOnly = 200 };
00037 
00038    //FIXME:  
00039    //temporary fix... to be removed before 310 final
00040    typedef AlgoId AlgoID ;
00041  
00043     CaloCluster() : 
00044       energy_(0), 
00045       algoID_( undefined ), flags_(0) {}
00046 
00048     CaloCluster(AlgoID algoID) : 
00049       energy_(0), 
00050       algoID_( algoID ), flags_(0) {}
00051 
00052     CaloCluster( double energy,
00053                  const math::XYZPoint& position,
00054                  const CaloID& caloID) :
00055       energy_ (energy), position_ (position), caloID_(caloID),algoID_( undefined ), flags_(0) {}
00056 
00057 
00059     void reset();
00060     
00062      CaloCluster( double energy,  
00063                  const math::XYZPoint& position ) : 
00064        energy_ (energy), position_ (position),algoID_( undefined ), flags_(0) {} 
00065 
00066 
00067     CaloCluster( double energy,
00068                  const math::XYZPoint& position,
00069                  const CaloID& caloID,
00070                  const AlgoID& algoID,
00071                  uint32_t flags = 0) :
00072       energy_ (energy), position_ (position), 
00073       caloID_(caloID), algoID_(algoID) {
00074       flags_=flags&flagsMask_;
00075     }
00076 
00077     CaloCluster( double energy,
00078                  const math::XYZPoint& position,
00079                  const CaloID& caloID,
00080                  const std::vector< std::pair< DetId, float > > &usedHitsAndFractions,
00081                  const AlgoId algoId,
00082                  const DetId seedId = DetId(0),
00083                  uint32_t flags = 0) :
00084       energy_ (energy), position_ (position), caloID_(caloID), 
00085       hitsAndFractions_(usedHitsAndFractions), algoID_(algoId),seedId_(seedId){
00086       flags_=flags&flagsMask_;
00087     }
00088 
00089    //FIXME:
00091     CaloCluster( double energy,
00092                  const math::XYZPoint& position,
00093                  float chi2,
00094                  const std::vector<DetId > &usedHits,
00095                  const AlgoId algoId,
00096                  uint32_t flags = 0) :
00097       energy_ (energy), position_ (position),  algoID_(algoId)
00098        {
00099           hitsAndFractions_.reserve(usedHits.size());
00100           for(size_t i = 0; i < usedHits.size(); i++) hitsAndFractions_.push_back(std::pair< DetId, float > ( usedHits[i],1.));
00101           flags_=flags&flagsMask_;
00102       }
00103 
00104 
00106     virtual ~CaloCluster() {}
00107 
00108 
00109     void setEnergy(double energy){energy_ = energy;}
00110     
00111     void setPosition(const math::XYZPoint& p){position_ = p;}
00112 
00113     void setCaloId(const CaloID& id) {caloID_= id;}
00114 
00115     void setAlgoId(const AlgoId& id) {algoID_=id;}
00116 
00117     void setSeed(const DetId& id) {seedId_=id;}
00118 
00120     double energy() const { return energy_; }
00121 
00123     const math::XYZPoint & position() const { return position_; }
00124     
00126     bool operator >=(const CaloCluster& rhs) const { 
00127       return (energy_>=rhs.energy_); 
00128     }
00129 
00131     bool operator > (const CaloCluster& rhs) const { 
00132       return (energy_> rhs.energy_); 
00133     }
00134 
00136     bool operator <=(const CaloCluster& rhs) const { 
00137       return (energy_<=rhs.energy_); 
00138     }
00139 
00141     bool operator < (const CaloCluster& rhs) const { 
00142       return (energy_< rhs.energy_); 
00143     }
00144 
00146      bool operator==(const CaloCluster& rhs) const { 
00147              return (energy_ == rhs.energy_); 
00148      }; 
00149 
00151     double x() const { return position_.x(); }
00152 
00154     double y() const { return position_.y(); }
00155 
00157     double z() const { return position_.z(); }
00158 
00160     double eta() const { return position_.eta(); }
00161 
00163     double phi() const { return position_.phi(); }
00164 
00166     size_t size() const { return hitsAndFractions_.size(); }
00167 
00169     AlgoId algo() const { return algoID_; }
00170     AlgoID algoID() const { return algo(); }
00171 
00172     uint32_t flags() const { return flags_&flagsMask_; }
00173     void setFlags( uint32_t flags) { 
00174       uint32_t reserved = (flags_ & ~flagsMask_);
00175       flags_ = (reserved ) | (flags & flagsMask_); 
00176     }
00177     bool isInClean()   const { return flags() < uncleanOnly; }
00178     bool isInUnclean() const { return flags() >= common; }
00179 
00180     const CaloID& caloID() const {return caloID_;}
00181 
00182     void addHitAndFraction( DetId id, float fraction ) { 
00183             hitsAndFractions_.push_back( std::pair<DetId, float>(id, fraction) );
00184     }
00185 
00189     const std::vector< std::pair<DetId, float> > & hitsAndFractions() const { return hitsAndFractions_; }
00190     
00192     std::string printHitAndFraction(unsigned i) const;
00193 
00195     friend std::ostream& operator<<(std::ostream& out, 
00196                                     const CaloCluster& cluster);
00197 
00199     DetId seed() const { return seedId_; }
00200 
00201   protected:
00202 
00204     double              energy_;
00205 
00207     math::XYZPoint      position_;
00208 
00210     CaloID              caloID_;
00211     
00212     // used hits by detId
00213     std::vector< std::pair<DetId, float> > hitsAndFractions_;
00214 
00215     // cluster algorithm Id
00216     AlgoID              algoID_;
00217 
00219     DetId               seedId_;
00220 
00224     uint32_t            flags_;
00225 
00226     static const uint32_t flagsMask_  =0x0FFFFFFF;
00227     static const uint32_t flagsOffset_=28;
00228   };
00229 
00230 }
00231 
00232 #endif