CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/RecoEcal/EgammaClusterAlgos/interface/Multi5x5ClusterAlgo.h

Go to the documentation of this file.
00001 #ifndef RecoECAL_ECALClusters_Multi5x5ClusterAlgo_h
00002 #define RecoECAL_ECALClusters_Multi5x5ClusterAlgo_h
00003 
00004 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
00005 
00006 #include "DataFormats/Math/interface/Point3D.h"
00007 #include "DataFormats/EcalRecHit/interface/EcalRecHit.h"
00008 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00009 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00010 #include "DataFormats/EgammaReco/interface/BasicCluster.h"
00011 
00012 #include "RecoCaloTools/Navigation/interface/CaloNavigator.h"
00013 #include "RecoCaloTools/Navigation/interface/EcalBarrelNavigator.h"
00014 #include "RecoCaloTools/Navigation/interface/EcalEndcapNavigator.h"
00015 #include "Geometry/CaloTopology/interface/EcalBarrelHardcodedTopology.h"
00016 #include "RecoEcal/EgammaCoreTools/interface/PositionCalc.h"
00017 #include "RecoEcal/EgammaCoreTools/interface/EcalEtaPhiRegion.h"
00018 #include "RecoEcal/EgammaCoreTools/interface/EcalRecHitLess.h"
00019 #include "DataFormats/CaloRecHit/interface/CaloID.h"
00020 
00021 // C/C++ headers
00022 #include <string>
00023 #include <vector>
00024 #include <set>
00025 
00026 typedef std::map<DetId, EcalRecHit> RecHitsMap;
00027 
00028 class Multi5x5ClusterAlgo 
00029 {
00030     public:
00031   //the 5x5 clustering algo by default makes basic clusters which may not contain their seed crystal if they are close by to other clusters 
00032   //however we would like to post-fix the basic clusters to ensure they always contain their seed crystal
00033   //so we define a proto basic cluster class which contains all the information which would be in a basic cluster 
00034   //which allows the addition of its seed and the removal of a seed of another cluster easily
00035   class ProtoBasicCluster {
00036     float energy_;
00037     EcalRecHit seed_;
00038     std::vector<std::pair<DetId,float> > hits_;
00039     bool containsSeed_;
00040   public:
00041     ProtoBasicCluster();
00042     ProtoBasicCluster(float iEnergy,const EcalRecHit& iSeed,std::vector<std::pair<DetId,float> >& iHits):energy_(iEnergy),seed_(iSeed){hits_.swap(iHits);containsSeed_=isSeedCrysInHits_();}
00043     
00044     float energy()const{return energy_;}
00045     const EcalRecHit& seed()const{return seed_;}
00046     const std::vector<std::pair<DetId,float> >& hits()const{return hits_;}
00047     bool containsSeed()const{return containsSeed_;}
00048 
00049     bool removeHit(const EcalRecHit& hitToRM);
00050     bool addSeed();
00051   private:
00052     bool isSeedCrysInHits_()const; 
00053 
00054   };
00055     
00056 
00057   Multi5x5ClusterAlgo() {
00058         }
00059 
00060   Multi5x5ClusterAlgo(double ebst, double ecst, std::vector<int> v_chstatus, const PositionCalc& posCalc,bool reassignSeedCrysToClusterItSeeds=false) : 
00061           ecalBarrelSeedThreshold(ebst), ecalEndcapSeedThreshold(ecst),  v_chstatus_(v_chstatus) ,reassignSeedCrysToClusterItSeeds_(reassignSeedCrysToClusterItSeeds) {
00062                 posCalculator_ = posCalc;
00063                 std::sort( v_chstatus_.begin(), v_chstatus_.end() );
00064             }
00065 
00066         virtual ~Multi5x5ClusterAlgo()
00067         {
00068         }
00069 
00070 
00071         // this is the method that will start the clusterisation
00072         std::vector<reco::BasicCluster> makeClusters(const EcalRecHitCollection* hits,
00073                 const CaloSubdetectorGeometry *geometry,
00074                 const CaloSubdetectorTopology *topology_p,
00075                 const CaloSubdetectorGeometry *geometryES_p,
00076                 reco::CaloID::Detectors detector,
00077                 bool regional = false,
00078                 const std::vector<EcalEtaPhiRegion>& regions = std::vector<EcalEtaPhiRegion>());
00079 
00081         typedef math::XYZPoint Point;
00082 
00083     private: 
00084 
00085         //algo to compute position of clusters
00086         PositionCalc posCalculator_;
00087 
00089         reco::CaloID::Detectors detector_;
00090 
00091         // Energy required for a seed:
00092         double ecalBarrelSeedThreshold;
00093         double ecalEndcapSeedThreshold;
00094 
00095         // collection of all rechits
00096         const EcalRecHitCollection *recHits_;
00097 
00098         // The vector of seeds:
00099         std::vector<EcalRecHit> seeds;
00100 
00101         std::vector<std::pair<DetId,int> > whichClusCrysBelongsTo_;
00102 
00103         // The set of used DetID's
00104         std::set<DetId> used_s;
00105         std::set<DetId> canSeed_s; // set of crystals not to be added but which can seed
00106         // a new 3x3 (e.g. the outer crystals in a 5x5)
00107 
00108 
00109         // The vector of DetId's in the cluster currently reconstructed
00110         std::vector<std::pair<DetId, float> > current_v;
00111 
00112         // The vector of clusters
00113         std::vector<reco::BasicCluster> clusters_v;
00114         std::vector<ProtoBasicCluster> protoClusters_; 
00115         // recHit flag to be excluded from seeding
00116         std::vector<int> v_chstatus_; 
00117 
00118         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
00119 
00120  
00121 
00122         void mainSearch(const EcalRecHitCollection* hits,
00123                 const CaloSubdetectorGeometry *geometry_p,
00124                 const CaloSubdetectorTopology *topology_p,
00125                 const CaloSubdetectorGeometry *geometryES_p);
00126 
00127         // Is the crystal at the navigator position a 
00128         // local maxiumum in energy?
00129         bool checkMaxima(CaloNavigator<DetId> &navigator,
00130                 const EcalRecHitCollection *hits);
00131 
00132         // prepare the 5x5 taking care over which crystals
00133         // are allowed to seed new clusters and which are not
00134         // after the preparation is complete
00135         void prepareCluster(CaloNavigator<DetId> &navigator,
00136                 const EcalRecHitCollection *hits,
00137                 const CaloSubdetectorGeometry *geometry);
00138 
00139         // Add the crystal with DetId det to the current
00140         // vector of crystals if it meets certain criteria
00141         void addCrystal(const DetId &det);
00142 
00143 
00144         // take the crystals in the current_v and build 
00145         // them into a BasicCluster
00146         void makeCluster(const EcalRecHitCollection* hits,
00147                 const CaloSubdetectorGeometry *geometry_p,
00148                 const CaloSubdetectorGeometry *geometryES_p, 
00149                 const EcalRecHitCollection::const_iterator &seedIt,
00150                 bool seedOutside);
00151 
00152 };
00153 
00154 #endif