Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-23 03:28:57

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 #include <optional>
0025 
0026 typedef std::map<DetId, EcalRecHit> RecHitsMap;
0027 
0028 class Multi5x5ClusterAlgo {
0029 public:
0030   //the 5x5 clustering algo by default makes basic clusters which may not contain their seed crystal if they are close by to other clusters
0031   //however we would like to post-fix the basic clusters to ensure they always contain their seed crystal
0032   //so we define a proto basic cluster class which contains all the information which would be in a basic cluster
0033   //which allows the addition of its seed and the removal of a seed of another cluster easily
0034   class ProtoBasicCluster {
0035     std::vector<std::pair<DetId, float> > hits_;
0036     EcalRecHit seed_;
0037     float energy_;
0038     bool containsSeed_;
0039 
0040   public:
0041     ProtoBasicCluster();
0042     ProtoBasicCluster(float iEnergy, const EcalRecHit &iSeed, std::vector<std::pair<DetId, float> > iHits)
0043         : hits_(std::move(iHits)), seed_(iSeed), energy_(iEnergy), containsSeed_{isSeedCrysInHits_()} {}
0044 
0045     float energy() const { return energy_; }
0046     const EcalRecHit &seed() const { return seed_; }
0047     const std::vector<std::pair<DetId, float> > &hits() const { return hits_; }
0048     bool containsSeed() const { return containsSeed_; }
0049 
0050     bool removeHit(const EcalRecHit &hitToRM);
0051     bool addSeed();
0052 
0053   private:
0054     bool isSeedCrysInHits_() const;
0055   };
0056 
0057   Multi5x5ClusterAlgo() {}
0058 
0059   Multi5x5ClusterAlgo(double ebst,
0060                       double ecst,
0061                       const std::vector<int> &v_chstatus,
0062                       const PositionCalc &posCalc,
0063                       bool reassignSeedCrysToClusterItSeeds = false)
0064       : ecalBarrelSeedThreshold_(ebst),
0065         ecalEndcapSeedThreshold_(ecst),
0066         v_chstatus_(v_chstatus),
0067         reassignSeedCrysToClusterItSeeds_(reassignSeedCrysToClusterItSeeds) {
0068     posCalculator_ = posCalc;
0069     std::sort(v_chstatus_.begin(), v_chstatus_.end());
0070   }
0071 
0072   virtual ~Multi5x5ClusterAlgo() {}
0073 
0074   // this is the method that will start the clusterisation
0075   std::vector<reco::BasicCluster> makeClusters(
0076       const EcalRecHitCollection *hits,
0077       const CaloSubdetectorGeometry *geometry,
0078       const CaloSubdetectorTopology *topology_p,
0079       const CaloSubdetectorGeometry *geometryES_p,
0080       reco::CaloID::Detectors detector,
0081       bool regional = false,
0082       const std::vector<RectangularEtaPhiRegion> &regions = std::vector<RectangularEtaPhiRegion>());
0083 
0084   /// point in the space
0085   typedef math::XYZPoint Point;
0086 
0087 private:
0088   //algo to compute position of clusters
0089   PositionCalc posCalculator_;
0090 
0091   /// The ecal region used
0092   reco::CaloID::Detectors detector_;
0093 
0094   // Energy required for a seed:
0095   double ecalBarrelSeedThreshold_;
0096   double ecalEndcapSeedThreshold_;
0097 
0098   // recHit flag to be excluded from seeding
0099   std::vector<int> v_chstatus_;
0100 
0101   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
0102 
0103   std::vector<reco::BasicCluster> mainSearch(const EcalRecHitCollection *hits,
0104                                              const CaloSubdetectorGeometry *geometry_p,
0105                                              const CaloSubdetectorTopology *topology_p,
0106                                              const CaloSubdetectorGeometry *geometryES_p,
0107                                              const std::vector<EcalRecHit> &seeds);
0108 
0109   // Is the crystal at the navigator position a
0110   // local maxiumum in energy?
0111   bool checkMaxima(CaloNavigator<DetId> &navigator, const EcalRecHitCollection *hits) const;
0112 
0113   // prepare the 5x5 taking care over which crystals
0114   // are allowed to seed new clusters and which are not
0115   // after the preparation is complete
0116   std::vector<std::pair<DetId, float> > prepareCluster(CaloNavigator<DetId> &navigator,
0117                                                        const EcalRecHitCollection *hits,
0118                                                        const CaloSubdetectorGeometry *geometry,
0119                                                        std::set<DetId> &used_seeds,
0120                                                        std::set<DetId> &canSeed_s) const;
0121 
0122   // Add the crystal with DetId det to the current
0123   // vector of crystals if it meets certain criteria
0124   static bool addCrystal(const DetId &det, const EcalRecHitCollection &recHits);
0125 
0126   // take the crystals in the current_v and build
0127   // them into a BasicCluster
0128   // NOTE: this can't be const because of posCalculator_
0129   std::optional<ProtoBasicCluster> makeCluster(const EcalRecHitCollection *hits,
0130                                                const CaloSubdetectorGeometry *geometry_p,
0131                                                const CaloSubdetectorGeometry *geometryES_p,
0132                                                const EcalRecHitCollection::const_iterator &seedIt,
0133                                                bool seedOutside,
0134                                                std::vector<std::pair<DetId, float> > &current_v);
0135 };
0136 
0137 #endif