Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:33:52

0001 #ifndef RecoECAL_ECALClusters_Multi5x5ClusterAlgo_h
0002 #define RecoECAL_ECALClusters_Multi5x5ClusterAlgo_h
0003 
0004 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
0005 
0006 #include "DataFormats/Math/interface/Point3D.h"
0007 #include "DataFormats/EcalRecHit/interface/EcalRecHit.h"
0008 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
0009 #include "DataFormats/EcalDetId/interface/EBDetId.h"
0010 #include "DataFormats/EgammaReco/interface/BasicCluster.h"
0011 #include "DataFormats/Math/interface/RectangularEtaPhiRegion.h"
0012 
0013 #include "RecoCaloTools/Navigation/interface/CaloNavigator.h"
0014 #include "RecoCaloTools/Navigation/interface/EcalBarrelNavigator.h"
0015 #include "RecoCaloTools/Navigation/interface/EcalEndcapNavigator.h"
0016 #include "Geometry/CaloTopology/interface/EcalBarrelHardcodedTopology.h"
0017 #include "RecoEcal/EgammaCoreTools/interface/PositionCalc.h"
0018 #include "DataFormats/CaloRecHit/interface/CaloID.h"
0019 
0020 // C/C++ headers
0021 #include <string>
0022 #include <vector>
0023 #include <set>
0024 
0025 typedef std::map<DetId, EcalRecHit> RecHitsMap;
0026 
0027 class Multi5x5ClusterAlgo {
0028 public:
0029   //the 5x5 clustering algo by default makes basic clusters which may not contain their seed crystal if they are close by to other clusters
0030   //however we would like to post-fix the basic clusters to ensure they always contain their seed crystal
0031   //so we define a proto basic cluster class which contains all the information which would be in a basic cluster
0032   //which allows the addition of its seed and the removal of a seed of another cluster easily
0033   class ProtoBasicCluster {
0034     float energy_;
0035     EcalRecHit seed_;
0036     std::vector<std::pair<DetId, float> > hits_;
0037     bool containsSeed_;
0038 
0039   public:
0040     ProtoBasicCluster();
0041     ProtoBasicCluster(float iEnergy, const EcalRecHit &iSeed, std::vector<std::pair<DetId, float> > &iHits)
0042         : energy_(iEnergy), seed_(iSeed) {
0043       hits_.swap(iHits);
0044       containsSeed_ = isSeedCrysInHits_();
0045     }
0046 
0047     float energy() const { return energy_; }
0048     const EcalRecHit &seed() const { return seed_; }
0049     const std::vector<std::pair<DetId, float> > &hits() const { return hits_; }
0050     bool containsSeed() const { return containsSeed_; }
0051 
0052     bool removeHit(const EcalRecHit &hitToRM);
0053     bool addSeed();
0054 
0055   private:
0056     bool isSeedCrysInHits_() const;
0057   };
0058 
0059   Multi5x5ClusterAlgo() {}
0060 
0061   Multi5x5ClusterAlgo(double ebst,
0062                       double ecst,
0063                       const std::vector<int> &v_chstatus,
0064                       const PositionCalc &posCalc,
0065                       bool reassignSeedCrysToClusterItSeeds = false)
0066       : ecalBarrelSeedThreshold(ebst),
0067         ecalEndcapSeedThreshold(ecst),
0068         v_chstatus_(v_chstatus),
0069         reassignSeedCrysToClusterItSeeds_(reassignSeedCrysToClusterItSeeds) {
0070     posCalculator_ = posCalc;
0071     std::sort(v_chstatus_.begin(), v_chstatus_.end());
0072   }
0073 
0074   virtual ~Multi5x5ClusterAlgo() {}
0075 
0076   // this is the method that will start the clusterisation
0077   std::vector<reco::BasicCluster> makeClusters(
0078       const EcalRecHitCollection *hits,
0079       const CaloSubdetectorGeometry *geometry,
0080       const CaloSubdetectorTopology *topology_p,
0081       const CaloSubdetectorGeometry *geometryES_p,
0082       reco::CaloID::Detectors detector,
0083       bool regional = false,
0084       const std::vector<RectangularEtaPhiRegion> &regions = std::vector<RectangularEtaPhiRegion>());
0085 
0086   /// point in the space
0087   typedef math::XYZPoint Point;
0088 
0089 private:
0090   //algo to compute position of clusters
0091   PositionCalc posCalculator_;
0092 
0093   /// The ecal region used
0094   reco::CaloID::Detectors detector_;
0095 
0096   // Energy required for a seed:
0097   double ecalBarrelSeedThreshold;
0098   double ecalEndcapSeedThreshold;
0099 
0100   // collection of all rechits
0101   const EcalRecHitCollection *recHits_;
0102 
0103   // The vector of seeds:
0104   std::vector<EcalRecHit> seeds;
0105 
0106   std::vector<std::pair<DetId, int> > whichClusCrysBelongsTo_;
0107 
0108   // The set of used DetID's
0109   std::set<DetId> used_s;
0110   std::set<DetId> canSeed_s;  // set of crystals not to be added but which can seed
0111   // a new 3x3 (e.g. the outer crystals in a 5x5)
0112 
0113   // The vector of DetId's in the cluster currently reconstructed
0114   std::vector<std::pair<DetId, float> > current_v;
0115 
0116   // The vector of clusters
0117   std::vector<reco::BasicCluster> clusters_v;
0118   std::vector<ProtoBasicCluster> protoClusters_;
0119   // recHit flag to be excluded from seeding
0120   std::vector<int> v_chstatus_;
0121 
0122   bool reassignSeedCrysToClusterItSeeds_;  //the seed of the 5x5 crystal is sometimes in another basic cluster, however we may want to put it back into the cluster it seeds
0123 
0124   void mainSearch(const EcalRecHitCollection *hits,
0125                   const CaloSubdetectorGeometry *geometry_p,
0126                   const CaloSubdetectorTopology *topology_p,
0127                   const CaloSubdetectorGeometry *geometryES_p);
0128 
0129   // Is the crystal at the navigator position a
0130   // local maxiumum in energy?
0131   bool checkMaxima(CaloNavigator<DetId> &navigator, const EcalRecHitCollection *hits);
0132 
0133   // prepare the 5x5 taking care over which crystals
0134   // are allowed to seed new clusters and which are not
0135   // after the preparation is complete
0136   void prepareCluster(CaloNavigator<DetId> &navigator,
0137                       const EcalRecHitCollection *hits,
0138                       const CaloSubdetectorGeometry *geometry);
0139 
0140   // Add the crystal with DetId det to the current
0141   // vector of crystals if it meets certain criteria
0142   void addCrystal(const DetId &det);
0143 
0144   // take the crystals in the current_v and build
0145   // them into a BasicCluster
0146   void makeCluster(const EcalRecHitCollection *hits,
0147                    const CaloSubdetectorGeometry *geometry_p,
0148                    const CaloSubdetectorGeometry *geometryES_p,
0149                    const EcalRecHitCollection::const_iterator &seedIt,
0150                    bool seedOutside);
0151 };
0152 
0153 #endif