Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:27:23

0001 #ifndef __RecoParticleFlow_PFClusterProducer_RealisticCluster_H__
0002 #define __RecoParticleFlow_PFClusterProducer_RealisticCluster_H__
0003 
0004 #include <array>
0005 #include <vector>
0006 #include <algorithm>
0007 
0008 class RealisticCluster {
0009   using Hit3DPosition = std::array<float, 3>;
0010 
0011 public:
0012   // for each SimCluster and for each layer, we store the position of the most energetic hit of the simcluster in the layer
0013 
0014   struct LayerInfo {
0015     Hit3DPosition centerOfGravityAtLayer_;
0016     Hit3DPosition maxHitPosAtLayer_;
0017     float maxEnergyHitAtLayer_;
0018   };
0019 
0020   RealisticCluster() : totalEnergy(0.f), exclusiveEnergy(0.f), visible(true) {}
0021 
0022   void increaseEnergy(float value) { totalEnergy += value; }
0023   void increaseExclusiveEnergy(float value) { exclusiveEnergy += value; }
0024 
0025   float getExclusiveEnergyFraction() const {
0026     float fraction = 0.f;
0027     if (totalEnergy > 0.f) {
0028       fraction = exclusiveEnergy / totalEnergy;
0029     }
0030     return fraction;
0031   }
0032 
0033   float getEnergy() const { return totalEnergy; }
0034 
0035   float getExclusiveEnergy() const { return exclusiveEnergy; }
0036 
0037   bool isVisible() const { return visible; }
0038 
0039   void setVisible(bool vis) { visible = vis; }
0040 
0041   void setCenterOfGravity(unsigned int layerId, const Hit3DPosition& position) {
0042     layerInfo_[layerId].centerOfGravityAtLayer_ = position;
0043   }
0044 
0045   Hit3DPosition getCenterOfGravity(unsigned int layerId) const { return layerInfo_[layerId].centerOfGravityAtLayer_; }
0046 
0047   bool setMaxEnergyHit(unsigned int layerId, float newEnergy, const Hit3DPosition position) {
0048     if (newEnergy > layerInfo_[layerId].maxEnergyHitAtLayer_) {
0049       layerInfo_[layerId].maxEnergyHitAtLayer_ = newEnergy;
0050       layerInfo_[layerId].maxHitPosAtLayer_ = position;
0051       return true;
0052     } else
0053       return false;
0054   }
0055 
0056   Hit3DPosition getMaxEnergyPosition(unsigned int layerId) const { return layerInfo_[layerId].maxHitPosAtLayer_; }
0057 
0058   float getMaxEnergy(unsigned int layerId) const { return layerInfo_[layerId].maxEnergyHitAtLayer_; }
0059 
0060   void setLayersNum(unsigned int numberOfLayers) { layerInfo_.resize(numberOfLayers); }
0061 
0062   unsigned int getLayersNum() const { return layerInfo_.size(); }
0063 
0064   void addHitAndFraction(unsigned int hit, float fraction) { hitIdsAndFractions_.emplace_back(hit, fraction); }
0065 
0066   void modifyFractionForHitId(float fraction, unsigned int hitId) {
0067     auto it = std::find_if(hitIdsAndFractions_.begin(),
0068                            hitIdsAndFractions_.end(),
0069                            [&hitId](const std::pair<unsigned int, float>& element) { return element.first == hitId; });
0070 
0071     it->second = fraction;
0072   }
0073 
0074   void modifyFractionByIndex(float fraction, unsigned int index) { hitIdsAndFractions_[index].second = fraction; }
0075 
0076   const std::vector<std::pair<unsigned int, float> >& hitsIdsAndFractions() const { return hitIdsAndFractions_; }
0077 
0078 private:
0079   std::vector<std::pair<unsigned int, float> > hitIdsAndFractions_;
0080   std::vector<LayerInfo> layerInfo_;
0081 
0082   float totalEnergy;
0083   float exclusiveEnergy;
0084   bool visible;
0085 };
0086 
0087 #endif