CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/RecoEcal/EgammaCoreTools/interface/EcalClusterTools.h

Go to the documentation of this file.
00001 #ifndef RecoEcal_EgammaCoreTools_EcalClusterTools_h
00002 #define RecoEcal_EgammaCoreTools_EcalClusterTools_h
00003 
00016 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
00017 #include "DataFormats/EgammaReco/interface/BasicCluster.h"
00018 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00019 
00020 //#include "DataFormats/Math/interface/Point3D.h"
00021 #include "DataFormats/Math/interface/Vector3D.h"
00022 //includes for ShowerShape function to work
00023 #include <vector>
00024 #include <math.h>
00025 #include <TMath.h>
00026 #include <TMatrixT.h>
00027 #include <TMatrixD.h>
00028 #include <TVectorT.h>
00029 #include <TVectorD.h>
00030 
00031 
00032 class DetId;
00033 class CaloTopology;
00034 class CaloGeometry;
00035 
00036 struct Cluster2ndMoments {
00037 
00038   // major and minor cluster moments wrt principale axes:
00039   float sMaj;
00040   float sMin;
00041   // angle between sMaj and phi:
00042   float alpha;
00043 
00044 };
00045 
00046 class EcalClusterTools {
00047         public:
00048                 EcalClusterTools() {};
00049                 ~EcalClusterTools() {};
00050 
00051                 // various energies in the matrix nxn surrounding the maximum energy crystal of the input cluster
00052                 //we use an eta/phi coordinate system rather than phi/eta
00053                 //note e3x2 does not have a definate eta/phi geometry, it takes the maximum 3x2 block containing the 
00054                 //seed regardless of whether that 3 in eta or phi
00055                 static float e1x3( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology );
00056                 static float e3x1( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology );
00057                 static float e1x5( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology );
00058                 static float e5x1( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology );
00059                 static float e2x2( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology );
00060                 static float e3x2( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology );
00061                 static float e3x3( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology );
00062                 static float e4x4( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology );
00063                 static float e5x5( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology );
00064                 // energy in the 2x5 strip right of the max crystal (does not contain max crystal)
00065                 // 2 crystals wide in eta, 5 wide in phi.
00066                 static float e2x5Right( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology );
00067                 // energy in the 2x5 strip left of the max crystal (does not contain max crystal)
00068                 static float e2x5Left( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology );
00069                 // energy in the 5x2 strip above the max crystal (does not contain max crystal)
00070                 // 5 crystals wide in eta, 2 wide in phi.
00071                 static float e2x5Top( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology );
00072                 // energy in the 5x2 strip below the max crystal (does not contain max crystal)                
00073                 static float e2x5Bottom( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology );
00074                 // energy in a 2x5 strip containing the seed (max) crystal.
00075                 // 2 crystals wide in eta, 5 wide in phi.
00076                 // it is the maximum of either (1x5left + 1x5center) or (1x5right + 1x5center)
00077                 static float e2x5Max( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology );
00078                 // energies in the crystal left, right, top, bottom w.r.t. to the most energetic crystal
00079                 static float eLeft( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology );
00080                 static float eRight( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology );
00081                 static float eTop( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology );
00082                 static float eBottom( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology );
00083                 // the energy of the most energetic crystal in the cluster
00084                 static float eMax( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits );
00085                 // the energy of the second most energetic crystal in the cluster
00086                 static float e2nd( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits );
00087                 // get the DetId and the energy of the maximum energy crystal of the input cluster
00088                 static std::pair<DetId, float> getMaximum( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits);
00089 
00090                 static std::vector<float> energyBasketFractionEta( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits );
00091                 static std::vector<float> energyBasketFractionPhi( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits );
00092 
00093                 // return a vector v with v[0] = etaLat, v[1] = phiLat, v[2] = lat
00094                 static std::vector<float> lat( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloGeometry *geometry, bool logW = true, float w0 = 4.7 );
00095                 // return a vector v with v[0] = covEtaEta, v[1] = covEtaPhi, v[2] = covPhiPhi
00096                 static std::vector<float> covariances(const reco::BasicCluster &cluster, const EcalRecHitCollection* recHits, const CaloTopology *topology, const CaloGeometry* geometry, float w0 = 4.7);
00097                 // return a vector v with v[0] = covIEtaIEta, v[1] = covIEtaIPhi, v[2] = covIPhiIPhi
00098                 //this function calculates differences in eta/phi in units of crystals not global eta/phi
00099                 //this is gives better performance in the crack regions of the calorimeter but gives otherwise identical results to covariances function
00100                 //   except that it doesnt need an eta based correction funtion in the endcap 
00101                 //it is multipled by an approprate crystal size to ensure it gives similar values to covariances(...)
00102                 //
00103                 //Warning: covIEtaIEta has been studied by egamma, but so far covIPhiIPhi hasnt been studied extensively so there could be a bug in 
00104                 //         the covIPhiIEta or covIPhiIPhi calculations. I dont think there is but as it hasnt been heavily used, there might be one
00105                 static std::vector<float> localCovariances(const reco::BasicCluster &cluster, const EcalRecHitCollection* recHits, const CaloTopology *topology, float w0 = 4.7);
00106                 
00107                 static std::vector<float> scLocalCovariances(const reco::SuperCluster &cluster, const EcalRecHitCollection* recHits,const CaloTopology *topology, float w0 = 4.7);
00108 
00109                 // cluster second moments with respect to principal axes:
00110                 static Cluster2ndMoments cluster2ndMoments( const reco::BasicCluster &basicCluster, const EcalRecHitCollection &recHits, double phiCorrectionFactor=0.8, double w0=4.7, bool useLogWeights=true);
00111                 static Cluster2ndMoments cluster2ndMoments( const reco::SuperCluster &superCluster, const EcalRecHitCollection &recHits, double phiCorrectionFactor=0.8, double w0=4.7, bool useLogWeights=true);
00112                 static Cluster2ndMoments cluster2ndMoments( std::vector<const EcalRecHit*> RH_ptrs, double  phiCorrectionFactor=0.8, double  w0=4.7, bool useLogWeights=true);
00113 
00114                 static double zernike20( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloGeometry *geometry, double R0 = 6.6, bool logW = true, float w0 = 4.7 );
00115                 static double zernike42( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloGeometry *geometry, double R0 = 6.6, bool logW = true, float w0 = 4.7 );
00116 
00117                 // get the detId's of a matrix centered in the maximum energy crystal = (0,0)
00118                 // the size is specified by ixMin, ixMax, iyMin, iyMax in unit of crystals
00119                 static std::vector<DetId> matrixDetId( const CaloTopology* topology, DetId id, int ixMin, int ixMax, int iyMin, int iyMax );
00120                 // get the energy deposited in a matrix centered in the maximum energy crystal = (0,0)
00121                 // the size is specified by ixMin, ixMax, iyMin, iyMax in unit of crystals
00122                 static float matrixEnergy( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology, DetId id, int ixMin, int ixMax, int iyMin, int iyMax );
00123                 // get the DetId and the energy of the maximum energy crystal in a vector of DetId
00124                 static std::pair<DetId, float> getMaximum( const std::vector< std::pair<DetId, float> > &v_id, const EcalRecHitCollection *recHits);
00125                 // get the energy of a DetId, return 0 if the DetId is not in the collection
00126                 static float recHitEnergy(DetId id, const EcalRecHitCollection *recHits);
00127 
00128                 //Shower shape variables return vector <Roundness, Angle> of a photon
00129                 static std::vector<float> roundnessBarrelSuperClusters( const reco::SuperCluster &superCluster ,const EcalRecHitCollection &recHits, int weightedPositionMethod = 0, float energyThreshold = 0.0);
00130                 static std::vector<float> roundnessBarrelSuperClustersUserExtended( const reco::SuperCluster &superCluster ,const EcalRecHitCollection &recHits, int ieta_delta=0, int iphi_delta=0, float energyRHThresh=0.00000, int weightedPositionMethod=0);
00131                 static std::vector<float> roundnessSelectedBarrelRecHits(std::vector<const EcalRecHit*>rhVector, int weightedPositionMethod = 0);
00132         private:
00133                 struct EcalClusterEnergyDeposition
00134                 { 
00135                         double deposited_energy;
00136                         double r;
00137                         double phi;
00138                 };
00139 
00140                 static std::vector<EcalClusterEnergyDeposition> getEnergyDepTopology( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloGeometry *geometry, bool logW, float w0 );
00141                 static math::XYZVector meanClusterPosition( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology, const CaloGeometry *geometry );
00142                 //return energy weighted mean distance from the seed crystal in number of crystals
00143                 //<iEta,iPhi>, iPhi is not defined for endcap and is returned as zero 
00144                 static std::pair<float,float>  mean5x5PositionInLocalCrysCoord(const reco::BasicCluster &cluster, const EcalRecHitCollection* recHits,const CaloTopology *topology);
00145                 static std::pair<float,float> mean5x5PositionInXY(const reco::BasicCluster &cluster, const EcalRecHitCollection* recHits,const CaloTopology *topology);
00146 
00147                 static double f00(double r) { return 1; }
00148                 static double f11(double r) { return r; }
00149                 static double f20(double r) { return 2.0*r*r-1.0; }
00150                 static double f22(double r) { return r*r; }
00151                 static double f31(double r) { return 3.0*r*r*r - 2.0*r; }
00152                 static double f33(double r) { return r*r*r; }
00153                 static double f40(double r) { return 6.0*r*r*r*r-6.0*r*r+1.0; }
00154                 static double f42(double r) { return 4.0*r*r*r*r-3.0*r*r; }
00155                 static double f44(double r) { return r*r*r*r; }
00156                 static double f51(double r) { return 10.0*pow(r,5)-12.0*pow(r,3)+3.0*r; }
00157                 static double f53(double r) { return 5.0*pow(r,5) - 4.0*pow(r,3); }
00158                 static double f55(double r) { return pow(r,5); }
00159 
00160                 static double absZernikeMoment( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloGeometry *geometry, int n, int m, double R0, bool logW, float w0 );
00161                 static double fast_AbsZernikeMoment(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloGeometry *geometry, int n, int m, double R0, bool logW, float w0 );
00162                 static double calc_AbsZernikeMoment(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloGeometry *geometry, int n, int m, double R0, bool logW, float w0 );
00163 
00164                 static double factorial(int n) {
00165                         double res = 1.;
00166                         for (int i = 2; i <= n; ++i) res *= i;
00167                         return res;
00168                 }
00169 
00170                 //useful functions for the localCovariances function
00171                 static float getIEta(const DetId& id);
00172                 static float getIPhi(const DetId& id);
00173                 static float getNormedIX(const DetId& id);
00174                 static float getNormedIY(const DetId& id);
00175                 static float getDPhiEndcap(const DetId& crysId,float meanX,float meanY);
00176                 static float getNrCrysDiffInEta(const DetId& crysId,const DetId& orginId);
00177                 static float getNrCrysDiffInPhi(const DetId& crysId,const DetId& orginId);
00178 
00179                                 //useful functions for showerRoundnessBarrel function
00180                                 static int deltaIEta(int seed_ieta, int rh_ieta);
00181                                 static int deltaIPhi(int seed_iphi, int rh_iphi);
00182                                 static std::vector<int> getSeedPosition(std::vector<const EcalRecHit*>RH_ptrs);
00183                                 static float getSumEnergy(std::vector<const EcalRecHit*>RH_ptrs);
00184                                 static float computeWeight(float eRH, float energyTotal, int weightedPositionMethod);
00185 
00186 };
00187 
00188 #endif