diff --git a/RecoCaloTools/Navigation/interface/CaloRectangle.h b/RecoCaloTools/Navigation/interface/CaloRectangle.h new file mode 100644 index 0000000000000..5cb5923f5a961 --- /dev/null +++ b/RecoCaloTools/Navigation/interface/CaloRectangle.h @@ -0,0 +1,112 @@ +#ifndef RecoCaloTools_Navigation_CaloRectangle_H +#define RecoCaloTools_Navigation_CaloRectangle_H + +#include "Geometry/CaloTopology/interface/CaloSubdetectorTopology.h" +#include "Geometry/CaloTopology/interface/CaloTopology.h" + +/* + * CaloRectangle is a class to create a rectangular range of DetIds around a + * central DetId. Meant to be used for range-based loops to calculate cluster + * shape variables. + */ + +struct CaloRectangle { + const int iEtaOrIXMin; + const int iEtaOrIXMax; + const int iPhiOrIYMin; + const int iPhiOrIYMax; + + template + auto operator()(T home, CaloTopology const& topology); + +}; + +template +T offsetBy(T start, CaloSubdetectorTopology const& topo, int dIEtaOrIX, int dIPhiOrIY) +{ + for(int i = 0; i < std::abs(dIEtaOrIX) && start != T(0); i++) { + start = dIEtaOrIX > 0 ? topo.goEast(start) : topo.goWest(start); + } + + for(int i = 0; i < std::abs(dIPhiOrIY) && start != T(0); i++) { + start = dIPhiOrIY > 0 ? topo.goNorth(start) : topo.goSouth(start); + } + return start; +} + +template +class CaloRectangleRange { + + public: + + class Iterator { + + public: + + Iterator(T const& home, int iEtaOrIX, int iPhiOrIY, CaloRectangle const rectangle, CaloSubdetectorTopology const& topology) + : home_(home) + , rectangle_(rectangle) + , topology_(topology) + , iEtaOrIX_(iEtaOrIX) + , iPhiOrIY_(iPhiOrIY) + {} + + Iterator& operator++() { + if(iPhiOrIY_ == rectangle_.iPhiOrIYMax) { + iPhiOrIY_ = rectangle_.iPhiOrIYMin; + iEtaOrIX_++; + } else ++iPhiOrIY_; + return *this; + } + + int iEtaOrIX() const { return iEtaOrIX_; } + int iPhiOrIY() const { return iPhiOrIY_; } + + bool operator==(Iterator const& other) const { return iEtaOrIX_ == other.iEtaOrIX() && iPhiOrIY_ == other.iPhiOrIY(); } + bool operator!=(Iterator const& other) const { return iEtaOrIX_ != other.iEtaOrIX() || iPhiOrIY_ != other.iPhiOrIY(); } + + T operator*() const { return offsetBy(home_, topology_, iEtaOrIX_, iPhiOrIY_); } + + private: + + const T home_; + + const CaloRectangle rectangle_; + CaloSubdetectorTopology const& topology_; + + int iEtaOrIX_; + int iPhiOrIY_; + }; + + public: + CaloRectangleRange(CaloRectangle rectangle, T home, CaloTopology const& topology) + : home_(home) + , rectangle_(rectangle) + , topology_(*topology.getSubdetectorTopology(home)) + {} + + CaloRectangleRange(int size, T home, CaloTopology const& topology) + : home_(home) + , rectangle_{-size, size, -size, size} + , topology_(*topology.getSubdetectorTopology(home)) + {} + + auto begin() { + return Iterator(home_, rectangle_.iEtaOrIXMin, rectangle_.iPhiOrIYMin, rectangle_, topology_); + } + auto end() { + return Iterator(home_, rectangle_.iEtaOrIXMax + 1, rectangle_.iPhiOrIYMin, rectangle_, topology_); + } + + private: + const T home_; + const CaloRectangle rectangle_; + CaloSubdetectorTopology const& topology_; +}; + +template +auto CaloRectangle::operator()(T home, CaloTopology const& topology) { + return CaloRectangleRange(*this, home, topology); +} + +#endif diff --git a/RecoEcal/EgammaClusterProducers/src/EcalDigiSelector.cc b/RecoEcal/EgammaClusterProducers/src/EcalDigiSelector.cc index 44ea306c17e10..f07c86bcc3934 100644 --- a/RecoEcal/EgammaClusterProducers/src/EcalDigiSelector.cc +++ b/RecoEcal/EgammaClusterProducers/src/EcalDigiSelector.cc @@ -134,14 +134,9 @@ void EcalDigiSelector::produce(edm::Event& evt, const edm::EventSetup& es) const CaloClusterPtr& bcref = clus1.seed(); const BasicCluster *bc = bcref.get(); //Get the maximum detid - std::pair EDetty = - EcalClusterTools::getMaximum(*bc,rechits); - //get the 3x3 array centered on maximum detid. - std::vector detvec = - EcalClusterTools::matrixDetId(topology,EDetty.first, -1, 1, -1, 1); - //Loop over the 3x3 - for (int ik = 0;ik EDetty = EcalClusterTools::getMaximum(*bc,rechits); - //get the 3x3 array centered on maximum detid. - std::vector detvec = - EcalClusterTools::matrixDetId(topology,EDetty.first, -1, 1, -1, 1); - //Loop over the 3x3 - for (int ik = 0;ikbegin(); diff --git a/RecoEcal/EgammaCoreTools/interface/EcalClusterLazyTools.h b/RecoEcal/EgammaCoreTools/interface/EcalClusterLazyTools.h index ec7302d6521aa..8115f3bd075f1 100644 --- a/RecoEcal/EgammaCoreTools/interface/EcalClusterLazyTools.h +++ b/RecoEcal/EgammaCoreTools/interface/EcalClusterLazyTools.h @@ -2,12 +2,12 @@ #define RecoEcal_EgammaCoreTools_EcalClusterLazyTools_h /** \class EcalClusterLazyTools - * + * * various cluster tools (e.g. cluster shapes) * * \author Federico Ferri - * - * \version $Id: + * + * \version $Id: * */ @@ -35,18 +35,16 @@ class EcalClusterLazyToolsBase { public: EcalClusterLazyToolsBase( const edm::Event &ev, const edm::EventSetup &es, edm::EDGetTokenT token1, edm::EDGetTokenT token2); EcalClusterLazyToolsBase( const edm::Event &ev, const edm::EventSetup &es, edm::EDGetTokenT token1, edm::EDGetTokenT token2, edm::EDGetTokenT token3); - ~EcalClusterLazyToolsBase(); - - // get time of basic cluster seed crystal + // get time of basic cluster seed crystal float BasicClusterSeedTime(const reco::BasicCluster &cluster); - // error-weighted average of time from constituents of basic cluster + // error-weighted average of time from constituents of basic cluster float BasicClusterTime(const reco::BasicCluster &cluster, const edm::Event &ev); // get BasicClusterSeedTime of the seed basic cluser of the supercluster float SuperClusterSeedTime(const reco::SuperCluster &cluster); // get BasicClusterTime of the seed basic cluser of the supercluster float SuperClusterTime(const reco::SuperCluster &cluster, const edm::Event &ev); - + // mapping for preshower rechits std::map rechits_map_; // get Preshower hit array @@ -57,30 +55,26 @@ class EcalClusterLazyToolsBase { float eseffsirir( const reco::SuperCluster &cluster ); float eseffsixix( const reco::SuperCluster &cluster ); float eseffsiyiy( const reco::SuperCluster &cluster ); - - // std::vector flagsexcl_; - //std::vector severitiesexcl_; - // const EcalSeverityLevelAlgo *sevLv; - + + EcalRecHitCollection const* getEcalEBRecHitCollection() const { return ebRecHits_; } + EcalRecHitCollection const* getEcalEERecHitCollection() const { return eeRecHits_; } + EcalRecHitCollection const* getEcalESRecHitCollection() const { return esRecHits_; } + EcalIntercalibConstants const& getEcalIntercalibConstants() const { return *icalMap; } + edm::ESHandle const& getLaserHandle() const { return laser; } + protected: - void getGeometry( const edm::EventSetup &es, bool doES=true ); - void getTopology( const edm::EventSetup &es ); - void getEBRecHits( const edm::Event &ev ); - void getEERecHits( const edm::Event &ev ); - void getESRecHits( const edm::Event &ev ); - const EcalRecHitCollection * getEcalRecHitCollection( const reco::BasicCluster &cluster ); - + EcalRecHitCollection const* getEcalRecHitCollection( const reco::BasicCluster &cluster ) const; + const CaloGeometry *geometry_; const CaloTopology *topology_; const EcalRecHitCollection *ebRecHits_; const EcalRecHitCollection *eeRecHits_; const EcalRecHitCollection *esRecHits_; - - edm::EDGetTokenT ebRHToken_, eeRHToken_, esRHToken_; + + edm::EDGetTokenT esRHToken_; std::shared_ptr ecalPS_topology_; - //const EcalIntercalibConstantMap& icalMap; edm::ESHandle ical; const EcalIntercalibConstantMap* icalMap; edm::ESHandle agc; @@ -88,319 +82,150 @@ class EcalClusterLazyToolsBase { void getIntercalibConstants( const edm::EventSetup &es ); void getADCToGeV ( const edm::EventSetup &es ); void getLaserDbService ( const edm::EventSetup &es ); - - // std::vector flagsexcl_; - // std::vector severitiesexcl_; - public: - inline const EcalRecHitCollection *getEcalEBRecHitCollection(void){return ebRecHits_;}; - inline const EcalRecHitCollection *getEcalEERecHitCollection(void){return eeRecHits_;}; - inline const EcalRecHitCollection *getEcalESRecHitCollection(void){return esRecHits_;}; - inline const EcalIntercalibConstants& getEcalIntercalibConstants(void){return *icalMap;}; - inline const edm::ESHandle& getLaserHandle(void){return laser;}; - + private: + void getESRecHits( const edm::Event &ev ); + }; // class EcalClusterLazyToolsBase -template +template class EcalClusterLazyToolsT : public EcalClusterLazyToolsBase { - public: - - EcalClusterLazyToolsT( const edm::Event &ev, const edm::EventSetup &es, edm::EDGetTokenT token1, edm::EDGetTokenT token2): - EcalClusterLazyToolsBase(ev,es,token1,token2) {} - - EcalClusterLazyToolsT( const edm::Event &ev, const edm::EventSetup &es, edm::EDGetTokenT token1, edm::EDGetTokenT token2, edm::EDGetTokenT token3): - EcalClusterLazyToolsBase(ev,es,token1,token2,token3) {} - ~EcalClusterLazyToolsT() {} - - // various energies in the matrix nxn surrounding the maximum energy crystal of the input cluster - //NOTE (29/10/08): we now use an eta/phi coordinate system rather than phi/eta - //to minmise possible screwups, for now e5x1 isnt defined all the majority of people who call it actually want e1x5 and - //it is thought it is better that their code doesnt compile rather than pick up the wrong function - //therefore in this version and later e1x5 = e5x1 in the old version - //so 1x5 is 1 crystal in eta and 5 crystals in phi - //note e3x2 does not have a definate eta/phi geometry, it takes the maximum 3x2 block containing the - //seed regardless of whether that 3 in eta or phi - float e1x3( const reco::BasicCluster &cluster ); - - float e3x1( const reco::BasicCluster &cluster ); - - float e1x5( const reco::BasicCluster &cluster ); - - float e5x1( const reco::BasicCluster &cluster ); - - float e2x2( const reco::BasicCluster &cluster ); + public: + + EcalClusterLazyToolsT( const edm::Event &ev, + const edm::EventSetup &es, + edm::EDGetTokenT token1, + edm::EDGetTokenT token2 ) + : EcalClusterLazyToolsBase(ev,es,token1,token2) {} + + EcalClusterLazyToolsT( const edm::Event &ev, + const edm::EventSetup &es, + edm::EDGetTokenT token1, + edm::EDGetTokenT token2, + edm::EDGetTokenT token3) + : EcalClusterLazyToolsBase(ev,es,token1,token2,token3) {} + + // Get the rec hit energies in a rectangle matrix around the seed. + std::vector energyMatrix(reco::BasicCluster const& cluster, int size) const { + + auto recHits = getEcalRecHitCollection(cluster); + DetId maxId = ClusterTools::getMaximum(cluster, recHits).first; + + std::vector energies; + for (auto const& detId : CaloRectangleRange(size, maxId, *topology_)) { + energies.push_back(ClusterTools::recHitEnergy( detId, recHits)); + } + + return energies; + } + + // various energies in the matrix nxn surrounding the maximum energy crystal of the input cluster + // + // NOTE (29/10/08): we now use an eta/phi coordinate system rather than + // phi/eta to minmise possible screwups, for now e5x1 isnt + // defined all the majority of people who call it actually + // want e1x5 and it is thought it is better that their code + // doesnt compile rather than pick up the wrong function + // therefore in this version and later e1x5 = e5x1 in the old + // version so 1x5 is 1 crystal in eta and 5 crystals in phi + // note e3x2 does not have a definate eta/phi geometry, it + // takes the maximum 3x2 block containing the seed regardless + // of whether that 3 in eta or phi + float e1x3( const reco::BasicCluster &cluster ) + { return ClusterTools::e1x3( cluster, getEcalRecHitCollection(cluster), topology_ ); } + float e3x1( const reco::BasicCluster &cluster ) + { return ClusterTools::e3x1( cluster, getEcalRecHitCollection(cluster), topology_ ); } + float e1x5( const reco::BasicCluster &cluster ) + { return ClusterTools::e1x5( cluster, getEcalRecHitCollection(cluster), topology_ ); } + float e5x1( const reco::BasicCluster &cluster ) + { return ClusterTools::e5x1( cluster, getEcalRecHitCollection(cluster), topology_ ); } + float e2x2( const reco::BasicCluster &cluster ) + { return ClusterTools::e2x2( cluster, getEcalRecHitCollection(cluster), topology_ ); } + float e3x2( const reco::BasicCluster &cluster ) + { return ClusterTools::e3x2( cluster, getEcalRecHitCollection(cluster), topology_ ); } + float e3x3( const reco::BasicCluster &cluster ) + { return ClusterTools::e3x3( cluster, getEcalRecHitCollection(cluster), topology_ ); } + float e4x4( const reco::BasicCluster &cluster ) + { return ClusterTools::e4x4( cluster, getEcalRecHitCollection(cluster), topology_ ); } + float e5x5( const reco::BasicCluster &cluster ) + { return ClusterTools::e5x5( cluster, getEcalRecHitCollection(cluster), topology_ ); } + int n5x5( const reco::BasicCluster &cluster ) + { return ClusterTools::n5x5( cluster, getEcalRecHitCollection(cluster), topology_ ); } + // energy in the 2x5 strip right of the max crystal (does not contain max crystal) + // 2 crystals wide in eta, 5 wide in phi. + float e2x5Right( const reco::BasicCluster &cluster ) + { return ClusterTools::e2x5Right( cluster, getEcalRecHitCollection(cluster), topology_ ); } + // energy in the 2x5 strip left of the max crystal (does not contain max crystal) + float e2x5Left( const reco::BasicCluster &cluster ) + { return ClusterTools::e2x5Left( cluster, getEcalRecHitCollection(cluster), topology_ ); } + // energy in the 5x2 strip above the max crystal (does not contain max crystal) + // 5 crystals wide in eta, 2 wide in phi. + float e2x5Top( const reco::BasicCluster &cluster ) + { return ClusterTools::e2x5Top( cluster, getEcalRecHitCollection(cluster), topology_ ); } + + // energy in the 5x2 strip below the max crystal (does not contain max crystal) + float e2x5Bottom( const reco::BasicCluster &cluster ) + { return ClusterTools::e2x5Bottom( cluster, getEcalRecHitCollection(cluster), topology_ ); } + // energy in a 2x5 strip containing the seed (max) crystal. + // 2 crystals wide in eta, 5 wide in phi. + // it is the maximum of either (1x5left + 1x5center) or (1x5right + 1x5center) + float e2x5Max( const reco::BasicCluster &cluster ) + { return ClusterTools::e2x5Max( cluster, getEcalRecHitCollection(cluster), topology_ ); } + // energies in the crystal left, right, top, bottom w.r.t. to the most energetic crystal + float eLeft( const reco::BasicCluster &cluster ) + { return ClusterTools::eLeft( cluster, getEcalRecHitCollection(cluster), topology_ ); } + float eRight( const reco::BasicCluster &cluster ) + { return ClusterTools::eRight( cluster, getEcalRecHitCollection(cluster), topology_ ); } + float eTop( const reco::BasicCluster &cluster ) + { return ClusterTools::eTop( cluster, getEcalRecHitCollection(cluster), topology_ ); } + float eBottom( const reco::BasicCluster &cluster ) + { return ClusterTools::eBottom( cluster, getEcalRecHitCollection(cluster), topology_ ); } + // the energy of the most energetic crystal in the cluster + float eMax( const reco::BasicCluster &cluster ) + { return ClusterTools::eMax( cluster, getEcalRecHitCollection(cluster) ); } + // the energy of the second most energetic crystal in the cluster + float e2nd( const reco::BasicCluster &cluster ) + { return ClusterTools::e2nd( cluster, getEcalRecHitCollection(cluster) ); } + + // get the DetId and the energy of the maximum energy crystal of the input cluster + std::pair getMaximum( const reco::BasicCluster &cluster ) + { return ClusterTools::getMaximum( cluster, getEcalRecHitCollection(cluster) ); } + std::vector energyBasketFractionEta( const reco::BasicCluster &cluster ) + { return ClusterTools::energyBasketFractionEta( cluster, getEcalRecHitCollection(cluster) ); } + std::vector energyBasketFractionPhi( const reco::BasicCluster &cluster ) + { return ClusterTools::energyBasketFractionPhi( cluster, getEcalRecHitCollection(cluster) ); } + + // return a vector v with v[0] = etaLat, v[1] = phiLat, v[2] = lat + std::vector lat( const reco::BasicCluster &cluster, bool logW = true, float w0 = 4.7 ) + { return ClusterTools::lat( cluster, getEcalRecHitCollection(cluster), geometry_, logW, w0 ); } + + // return a vector v with v[0] = covEtaEta, v[1] = covEtaPhi, v[2] = covPhiPhi + std::vector covariances(const reco::BasicCluster &cluster, float w0 = 4.7 ) + { return ClusterTools::covariances( cluster, getEcalRecHitCollection(cluster), topology_, geometry_, w0 ); } + + // return a vector v with v[0] = covIEtaIEta, v[1] = covIEtaIPhi, v[2] = covIPhiIPhi + // this function calculates differences in eta/phi in units of crystals not + // global eta/phi this is gives better performance in the crack regions of + // the calorimeter but gives otherwise identical results to covariances + // function this is only defined for the barrel, it returns covariances when + // the cluster is in the endcap Warning: covIEtaIEta has been studied by + // egamma, but so far covIPhiIPhi hasnt been studied extensively so there + // could be a bug in the covIPhiIEta or covIPhiIPhi calculations. I dont + // think there is but as it hasnt been heavily used, there might be one + std::vector localCovariances(const reco::BasicCluster &cluster, float w0 = 4.7) + { return ClusterTools::localCovariances( cluster, getEcalRecHitCollection(cluster), topology_, w0 ); } + std::vector scLocalCovariances(const reco::SuperCluster &cluster, float w0 = 4.7) + { return ClusterTools::scLocalCovariances( cluster, getEcalRecHitCollection(cluster), topology_, w0 ); } + double zernike20( const reco::BasicCluster &cluster, double R0 = 6.6, bool logW = true, float w0 = 4.7 ) + { return ClusterTools::zernike20( cluster, getEcalRecHitCollection(cluster), geometry_, R0, logW, w0 ); } + double zernike42( const reco::BasicCluster &cluster, double R0 = 6.6, bool logW = true, float w0 = 4.7 ) + { return ClusterTools::zernike42( cluster, getEcalRecHitCollection(cluster), geometry_, R0, logW, w0 ); } - float e3x2( const reco::BasicCluster &cluster ); - - float e3x3( const reco::BasicCluster &cluster ); - - float e4x4( const reco::BasicCluster &cluster ); - - float e5x5( const reco::BasicCluster &cluster ); - int n5x5( const reco::BasicCluster &cluster ); - // energy in the 2x5 strip right of the max crystal (does not contain max crystal) - // 2 crystals wide in eta, 5 wide in phi. - float e2x5Right( const reco::BasicCluster &cluster ); - // energy in the 2x5 strip left of the max crystal (does not contain max crystal) - float e2x5Left( const reco::BasicCluster &cluster ); - // energy in the 5x2 strip above the max crystal (does not contain max crystal) - // 5 crystals wide in eta, 2 wide in phi. - float e2x5Top( const reco::BasicCluster &cluster ); - - // energy in the 5x2 strip below the max crystal (does not contain max crystal) - float e2x5Bottom( const reco::BasicCluster &cluster ); - // energy in a 2x5 strip containing the seed (max) crystal. - // 2 crystals wide in eta, 5 wide in phi. - // it is the maximum of either (1x5left + 1x5center) or (1x5right + 1x5center) - float e2x5Max( const reco::BasicCluster &cluster ); - // energies in the crystal left, right, top, bottom w.r.t. to the most energetic crystal - float eLeft( const reco::BasicCluster &cluster ); - - float eRight( const reco::BasicCluster &cluster ); - - float eTop( const reco::BasicCluster &cluster ); - - float eBottom( const reco::BasicCluster &cluster ); - // the energy of the most energetic crystal in the cluster - float eMax( const reco::BasicCluster &cluster ); - // the energy of the second most energetic crystal in the cluster - float e2nd( const reco::BasicCluster &cluster ); - - // get the DetId and the energy of the maximum energy crystal of the input cluster - std::pair getMaximum( const reco::BasicCluster &cluster ); - - std::vector energyBasketFractionEta( const reco::BasicCluster &cluster ); - - std::vector energyBasketFractionPhi( const reco::BasicCluster &cluster ); - - // return a vector v with v[0] = etaLat, v[1] = phiLat, v[2] = lat - std::vector lat( const reco::BasicCluster &cluster, bool logW = true, float w0 = 4.7 ); - - // return a vector v with v[0] = covEtaEta, v[1] = covEtaPhi, v[2] = covPhiPhi - std::vector covariances(const reco::BasicCluster &cluster, float w0 = 4.7 ); - - // return a vector v with v[0] = covIEtaIEta, v[1] = covIEtaIPhi, v[2] = covIPhiIPhi - //this function calculates differences in eta/phi in units of crystals not global eta/phi - //this is gives better performance in the crack regions of the calorimeter but gives otherwise identical results to covariances function - //this is only defined for the barrel, it returns covariances when the cluster is in the endcap - //Warning: covIEtaIEta has been studied by egamma, but so far covIPhiIPhi hasnt been studied extensively so there could be a bug in - // the covIPhiIEta or covIPhiIPhi calculations. I dont think there is but as it hasnt been heavily used, there might be one - std::vector localCovariances(const reco::BasicCluster &cluster, float w0 = 4.7); - - std::vector scLocalCovariances(const reco::SuperCluster &cluster, float w0 = 4.7); - - double zernike20( const reco::BasicCluster &cluster, double R0 = 6.6, bool logW = true, float w0 = 4.7 ); - double zernike42( const reco::BasicCluster &cluster, double R0 = 6.6, bool logW = true, float w0 = 4.7 ); - - // get the detId's of a matrix centered in the maximum energy crystal = (0,0) - // the size is specified by ixMin, ixMax, iyMin, iyMax in unit of crystals - std::vector matrixDetId( DetId id, int ixMin, int ixMax, int iyMin, int iyMax ); - // get the energy deposited in a matrix centered in the maximum energy crystal = (0,0) - // the size is specified by ixMin, ixMax, iyMin, iyMax in unit of crystals - float matrixEnergy( const reco::BasicCluster &cluster, DetId id, int ixMin, int ixMax, int iyMin, int iyMax ); - }; // class EcalClusterLazyToolsT -template -float EcalClusterLazyToolsT::e1x3( const reco::BasicCluster &cluster ) -{ - return EcalClusterToolsImpl::e1x3( cluster, getEcalRecHitCollection(cluster), topology_ ); -} - - -template -float EcalClusterLazyToolsT::e3x1( const reco::BasicCluster &cluster ) -{ - return EcalClusterToolsImpl::e3x1( cluster, getEcalRecHitCollection(cluster), topology_ ); -} - -template -float EcalClusterLazyToolsT::e1x5( const reco::BasicCluster &cluster ) -{ - return EcalClusterToolsImpl::e1x5( cluster, getEcalRecHitCollection(cluster), topology_ ); -} - - -template -float EcalClusterLazyToolsT::e5x1( const reco::BasicCluster &cluster ) -{ - return EcalClusterToolsImpl::e5x1( cluster, getEcalRecHitCollection(cluster), topology_ ); -} - -template -float EcalClusterLazyToolsT::e2x2( const reco::BasicCluster &cluster ) -{ - return EcalClusterToolsImpl::e2x2( cluster, getEcalRecHitCollection(cluster), topology_ ); -} - -template -float EcalClusterLazyToolsT::e3x2( const reco::BasicCluster &cluster ) -{ - return EcalClusterToolsImpl::e3x2( cluster, getEcalRecHitCollection(cluster), topology_ ); -} - -template -float EcalClusterLazyToolsT::e3x3( const reco::BasicCluster &cluster ) -{ - return EcalClusterToolsImpl::e3x3( cluster, getEcalRecHitCollection(cluster), topology_ ); -} - -template -float EcalClusterLazyToolsT::e4x4( const reco::BasicCluster &cluster ) -{ - return EcalClusterToolsImpl::e4x4( cluster, getEcalRecHitCollection(cluster), topology_ ); -} - -template -float EcalClusterLazyToolsT::e5x5( const reco::BasicCluster &cluster ) -{ - return EcalClusterToolsImpl::e5x5( cluster, getEcalRecHitCollection(cluster), topology_ ); -} - -template -int EcalClusterLazyToolsT::n5x5( const reco::BasicCluster &cluster ) -{ - return EcalClusterToolsImpl::n5x5( cluster, getEcalRecHitCollection(cluster), topology_ ); -} - -template -float EcalClusterLazyToolsT::e2x5Right( const reco::BasicCluster &cluster ) -{ - return EcalClusterToolsImpl::e2x5Right( cluster, getEcalRecHitCollection(cluster), topology_ ); -} - -template -float EcalClusterLazyToolsT::e2x5Left( const reco::BasicCluster &cluster ) -{ - return EcalClusterToolsImpl::e2x5Left( cluster, getEcalRecHitCollection(cluster), topology_ ); -} - -template -float EcalClusterLazyToolsT::e2x5Top( const reco::BasicCluster &cluster ) -{ - return EcalClusterToolsImpl::e2x5Top( cluster, getEcalRecHitCollection(cluster), topology_ ); -} - -template -float EcalClusterLazyToolsT::e2x5Bottom( const reco::BasicCluster &cluster ) -{ - return EcalClusterToolsImpl::e2x5Bottom( cluster, getEcalRecHitCollection(cluster), topology_ ); -} - -template -float EcalClusterLazyToolsT::e2x5Max( const reco::BasicCluster &cluster ) -{ - return EcalClusterToolsImpl::e2x5Max( cluster, getEcalRecHitCollection(cluster), topology_ ); -} - -template -float EcalClusterLazyToolsT::eLeft( const reco::BasicCluster &cluster ) -{ - return EcalClusterToolsImpl::eLeft( cluster, getEcalRecHitCollection(cluster), topology_ ); -} - -template -float EcalClusterLazyToolsT::eRight( const reco::BasicCluster &cluster ) -{ - return EcalClusterToolsImpl::eRight( cluster, getEcalRecHitCollection(cluster), topology_ ); -} - -template -float EcalClusterLazyToolsT::eTop( const reco::BasicCluster &cluster ) -{ - return EcalClusterToolsImpl::eTop( cluster, getEcalRecHitCollection(cluster), topology_ ); -} - -template -float EcalClusterLazyToolsT::eBottom( const reco::BasicCluster &cluster ) -{ - return EcalClusterToolsImpl::eBottom( cluster, getEcalRecHitCollection(cluster), topology_ ); -} - -template -float EcalClusterLazyToolsT::eMax( const reco::BasicCluster &cluster ) -{ - return EcalClusterToolsImpl::eMax( cluster, getEcalRecHitCollection(cluster) ); -} - -template -float EcalClusterLazyToolsT::e2nd( const reco::BasicCluster &cluster ) -{ - return EcalClusterToolsImpl::e2nd( cluster, getEcalRecHitCollection(cluster) ); -} - -template -std::pair EcalClusterLazyToolsT::getMaximum( const reco::BasicCluster &cluster ) -{ - return EcalClusterToolsImpl::getMaximum( cluster, getEcalRecHitCollection(cluster) ); -} - -template -std::vector EcalClusterLazyToolsT::energyBasketFractionEta( const reco::BasicCluster &cluster ) -{ - return EcalClusterToolsImpl::energyBasketFractionEta( cluster, getEcalRecHitCollection(cluster) ); -} - -template -std::vector EcalClusterLazyToolsT::energyBasketFractionPhi( const reco::BasicCluster &cluster ) -{ - return EcalClusterToolsImpl::energyBasketFractionPhi( cluster, getEcalRecHitCollection(cluster) ); -} - -template -std::vector EcalClusterLazyToolsT::lat( const reco::BasicCluster &cluster, bool logW, float w0 ) -{ - return EcalClusterToolsImpl::lat( cluster, getEcalRecHitCollection(cluster), geometry_, logW, w0 ); -} - -template -std::vector EcalClusterLazyToolsT::covariances(const reco::BasicCluster &cluster, float w0 ) -{ - return EcalClusterToolsImpl::covariances( cluster, getEcalRecHitCollection(cluster), topology_, geometry_, w0 ); -} - -template -std::vector EcalClusterLazyToolsT::localCovariances(const reco::BasicCluster &cluster, float w0 ) -{ - return EcalClusterToolsImpl::localCovariances( cluster, getEcalRecHitCollection(cluster), topology_, w0 ); -} - -template -std::vector EcalClusterLazyToolsT::scLocalCovariances(const reco::SuperCluster &cluster, float w0 ) -{ - return EcalClusterToolsImpl::scLocalCovariances( cluster, getEcalRecHitCollection(cluster), topology_, w0 ); -} - -template -double EcalClusterLazyToolsT::zernike20( const reco::BasicCluster &cluster, double R0, bool logW, float w0 ) -{ - return EcalClusterToolsImpl::zernike20( cluster, getEcalRecHitCollection(cluster), geometry_, R0, logW, w0 ); -} - - -template -double EcalClusterLazyToolsT::zernike42( const reco::BasicCluster &cluster, double R0, bool logW, float w0 ) -{ - return EcalClusterToolsImpl::zernike42( cluster, getEcalRecHitCollection(cluster), geometry_, R0, logW, w0 ); -} - -template -std::vector EcalClusterLazyToolsT::matrixDetId( DetId id, int ixMin, int ixMax, int iyMin, int iyMax ) -{ - return EcalClusterToolsImpl::matrixDetId( topology_, id, ixMin, ixMax, iyMin, iyMax ); -} - -template -float EcalClusterLazyToolsT::matrixEnergy( const reco::BasicCluster &cluster, DetId id, int ixMin, int ixMax, int iyMin, int iyMax ) -{ - return EcalClusterToolsImpl::matrixEnergy( cluster, getEcalRecHitCollection(cluster), topology_, id, ixMin, ixMax, iyMin, iyMax ); -} - -namespace noZS { - typedef EcalClusterLazyToolsT EcalClusterLazyTools; -} -typedef EcalClusterLazyToolsT<::EcalClusterTools> EcalClusterLazyTools; +namespace noZS { typedef EcalClusterLazyToolsT EcalClusterLazyTools; } +typedef EcalClusterLazyToolsT<::EcalClusterTools> EcalClusterLazyTools; #endif diff --git a/RecoEcal/EgammaCoreTools/interface/EcalClusterTools.h b/RecoEcal/EgammaCoreTools/interface/EcalClusterTools.h index da0916ba86eb4..97989406aa5ac 100644 --- a/RecoEcal/EgammaCoreTools/interface/EcalClusterTools.h +++ b/RecoEcal/EgammaCoreTools/interface/EcalClusterTools.h @@ -45,7 +45,7 @@ #include "DataFormats/DetId/interface/DetId.h" #include "DataFormats/EcalDetId/interface/EBDetId.h" #include "DataFormats/EcalDetId/interface/EEDetId.h" -#include "RecoCaloTools/Navigation/interface/CaloNavigator.h" +#include "RecoCaloTools/Navigation/interface/CaloRectangle.h" #include "FWCore/MessageLogger/interface/MessageLogger.h" @@ -75,11 +75,8 @@ struct Cluster2ndMoments { template class EcalClusterToolsT { public: - EcalClusterToolsT() {}; - ~EcalClusterToolsT() {}; - // various energies in the matrix nxn surrounding the maximum energy crystal of the input cluster - //we use an eta/phi coordinate system rather than phi/eta + //we use an eta/phi coordinate system rather than phi/eta //note e3x2 does not have a definate eta/phi geometry, it takes the maximum 3x2 block containing the //seed regardless of whether that 3 in eta or phi static float e1x3( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology ); @@ -104,13 +101,13 @@ class EcalClusterToolsT { static int n5x5( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology ); // energy in the 2x5 strip right of the max crystal (does not contain max crystal) - // 2 crystals wide in eta, 5 wide in phi. + // 2 crystals wide in eta, 5 wide in phi. static float e2x5Right( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology ); // energy in the 2x5 strip left of the max crystal (does not contain max crystal) static float e2x5Left( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology ); // energy in the 5x2 strip above the max crystal (does not contain max crystal) - // 5 crystals wide in eta, 2 wide in phi. + // 5 crystals wide in eta, 2 wide in phi. static float e2x5Top( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology ); // energy in the 5x2 strip below the max crystal (does not contain max crystal) @@ -173,12 +170,14 @@ class EcalClusterToolsT { // get the detId's of a matrix centered in the maximum energy crystal = (0,0) // the size is specified by ixMin, ixMax, iyMin, iyMax in unit of crystals - static std::vector matrixDetId( const CaloTopology* topology, DetId id, int ixMin, int ixMax, int iyMin, int iyMax ); + static std::vector matrixDetId( const CaloTopology* topology, DetId id, CaloRectangle rectangle ); + static std::vector matrixDetId( const CaloTopology* topology, DetId id, int size ) + { return matrixDetId(topology, id, CaloRectangle{-size, size, -size, size}); } // get the energy deposited in a matrix centered in the maximum energy crystal = (0,0) // the size is specified by ixMin, ixMax, iyMin, iyMax in unit of crystals - static float matrixEnergy( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology, DetId id, int ixMin, int ixMax, int iyMin, int iyMax ); - static int matrixSize( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology, DetId id, int ixMin, int ixMax, int iyMin, int iyMax ); + static float matrixEnergy( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology, DetId id, CaloRectangle rectangle ); + static int matrixSize( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology, DetId id, CaloRectangle rectangle ); static float getFraction( const std::vector< std::pair > &v_id, DetId id); // get the DetId and the energy of the maximum energy crystal in a vector of DetId @@ -243,7 +242,7 @@ class EcalClusterToolsT { static float getDPhiEndcap(const DetId& crysId,float meanX,float meanY); static float getNrCrysDiffInEta(const DetId& crysId,const DetId& orginId); static float getNrCrysDiffInPhi(const DetId& crysId,const DetId& orginId); - + //useful functions for showerRoundnessBarrel function static int deltaIEta(int seed_ieta, int rh_ieta); static int deltaIPhi(int seed_iphi, int rh_iphi); @@ -256,8 +255,8 @@ class EcalClusterToolsT { // implementation template -float EcalClusterToolsT::getFraction( const std::vector< std::pair > &v_id, DetId id - ){ +float EcalClusterToolsT::getFraction( const std::vector< std::pair > &v_id, DetId id) +{ if(noZS) return 1.0; float frac = 0.0; for ( size_t i = 0; i < v_id.size(); ++i ) { @@ -300,15 +299,10 @@ float EcalClusterToolsT::recHitEnergy(DetId id, const EcalRecHitCollection EcalRecHitCollection::const_iterator it = recHits->find( id ); if ( it != recHits->end() ) { if( noZS && ( it->checkFlag(EcalRecHit::kTowerRecovered) || - it->checkFlag(EcalRecHit::kWeird) || - (it->detid().subdetId() == EcalBarrel && - it->checkFlag(EcalRecHit::kDiWeird) ) - ) - ) { - return 0.0; - } else { - return (*it).energy(); - } + it->checkFlag(EcalRecHit::kWeird) || + (it->detid().subdetId() == EcalBarrel && + it->checkFlag(EcalRecHit::kDiWeird) ))) return 0.0; + else return it->energy(); } else { //throw cms::Exception("EcalRecHitNotFound") << "The recHit corresponding to the DetId" << id.rawId() << " not found in the EcalRecHitCollection"; // the recHit is not in the collection (hopefully zero suppressed) @@ -332,61 +326,38 @@ float EcalClusterToolsT::recHitEnergy(DetId id, const EcalRecHitCollection // -2 |_|_|_|_|_| // -2 -1 0 1 2 ix template -float EcalClusterToolsT::matrixEnergy( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology, DetId id, int ixMin, int ixMax, int iyMin, int iyMax ) +float EcalClusterToolsT::matrixEnergy( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology, DetId id, CaloRectangle rectangle ) { - //take into account fractions - // fast version - CaloNavigator cursor = CaloNavigator( id, topology->getSubdetectorTopology( id ) ); float energy = 0; - const std::vector< std::pair >& v_id = cluster.hitsAndFractions(); - for ( int i = ixMin; i <= ixMax; ++i ) { - for ( int j = iyMin; j <= iyMax; ++j ) { - cursor.home(); - cursor.offsetBy( i, j ); - float frac=getFraction(v_id,*cursor); - energy += recHitEnergy( *cursor, recHits )*frac; - } + auto const& vId = cluster.hitsAndFractions(); + + for (auto const& detId : rectangle(id, *topology)) { + energy += recHitEnergy( detId, recHits ) * getFraction(vId, detId); } - // slow elegant version - //float energy = 0; - //std::vector v_id = matrixDetId( topology, id, ixMin, ixMax, iyMin, iyMax ); - //for ( std::vector::const_iterator it = v_id.begin(); it != v_id.end(); ++it ) { - // energy += recHitEnergy( *it, recHits ); - //} + return energy; } template -int EcalClusterToolsT::matrixSize( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology, DetId id, int ixMin, int ixMax, int iyMin, int iyMax ) +int EcalClusterToolsT::matrixSize( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology, DetId id, CaloRectangle rectangle ) { - // fast version - CaloNavigator cursor = CaloNavigator( id, topology->getSubdetectorTopology( id ) ); int result = 0; - const std::vector< std::pair >& v_id = cluster.hitsAndFractions(); - for ( int i = ixMin; i <= ixMax; ++i ) { - for ( int j = iyMin; j <= iyMax; ++j ) { - cursor.home(); - cursor.offsetBy( i, j ); - float frac=getFraction(v_id,*cursor); - float energy = recHitEnergy( *cursor, recHits )*frac; - if (energy > 0) result++; - } + + for (auto const& detId : rectangle(id, *topology)) { + const float energy = recHitEnergy(detId, recHits); + const float frac = getFraction(cluster.hitsAndFractions(), detId); + if(energy * frac > 0) result++; } return result; } template -std::vector EcalClusterToolsT::matrixDetId( const CaloTopology* topology, DetId id, int ixMin, int ixMax, int iyMin, int iyMax ) +std::vector EcalClusterToolsT::matrixDetId( const CaloTopology* topology, DetId id, CaloRectangle rectangle ) { - CaloNavigator cursor = CaloNavigator( id, topology->getSubdetectorTopology( id ) ); std::vector v; - for ( int i = ixMin; i <= ixMax; ++i ) { - for ( int j = iyMin; j <= iyMax; ++j ) { - cursor.home(); - cursor.offsetBy( i, j ); - if ( *cursor != DetId(0) ) v.push_back( *cursor ); - } + for (auto const& detId : rectangle(id, *topology)) { + if ( detId != DetId(0) ) v.push_back(detId); } return v; } @@ -397,10 +368,10 @@ float EcalClusterToolsT::e2x2( const reco::BasicCluster &cluster, const Ec { DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).first; std::list energies; - float max_E = matrixEnergy( cluster, recHits, topology, id, -1, 0, -1, 0 ); - max_E = std::max( max_E, matrixEnergy( cluster, recHits, topology, id, -1, 0, 0, 1 ) ); - max_E = std::max( max_E, matrixEnergy( cluster, recHits, topology, id, 0, 1, 0, 1 ) ); - max_E = std::max( max_E, matrixEnergy( cluster, recHits, topology, id, 0, 1, -1, 0 ) ); + float max_E = matrixEnergy( cluster, recHits, topology, id, {-1, 0, -1, 0} ); + max_E = std::max( max_E, matrixEnergy( cluster, recHits, topology, id, {-1, 0, 0, 1} ) ); + max_E = std::max( max_E, matrixEnergy( cluster, recHits, topology, id, { 0, 1, 0, 1} ) ); + max_E = std::max( max_E, matrixEnergy( cluster, recHits, topology, id, { 0, 1, -1, 0} ) ); return max_E; } @@ -408,10 +379,10 @@ template float EcalClusterToolsT::e3x2( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology ) { DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).first; - float max_E = matrixEnergy( cluster, recHits, topology, id, -1, 1, -1, 0 ); - max_E = std::max( max_E, matrixEnergy( cluster, recHits, topology, id, 0, 1, -1, 1 ) ); - max_E = std::max( max_E, matrixEnergy( cluster, recHits, topology, id, -1, 1, 0, 1 ) ); - max_E = std::max( max_E, matrixEnergy( cluster, recHits, topology, id, -1, 0, -1, 1 ) ); + float max_E = matrixEnergy( cluster, recHits, topology, id, {-1, 1, -1, 0} ); + max_E = std::max( max_E, matrixEnergy( cluster, recHits, topology, id, {0, 1, -1, 1} ) ); + max_E = std::max( max_E, matrixEnergy( cluster, recHits, topology, id, {-1, 1, 0, 1} ) ); + max_E = std::max( max_E, matrixEnergy( cluster, recHits, topology, id, {-1, 0, -1, 1} ) ); return max_E; } @@ -419,17 +390,17 @@ template float EcalClusterToolsT::e3x3( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology ) { DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).first; - return matrixEnergy( cluster, recHits, topology, id, -1, 1, -1, 1 ); + return matrixEnergy( cluster, recHits, topology, id, {-1, 1, -1, 1} ); } template float EcalClusterToolsT::e4x4( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology ) { DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).first; - float max_E = matrixEnergy( cluster, recHits, topology, id, -1, 2, -2, 1 ); - max_E = std::max( max_E, matrixEnergy( cluster, recHits, topology, id, -2, 1, -2, 1 ) ); - max_E = std::max( max_E, matrixEnergy( cluster, recHits, topology, id, -2, 1, -1, 2 ) ); - max_E = std::max( max_E, matrixEnergy( cluster, recHits, topology, id, -1, 2, -1, 2 ) ); + float max_E = matrixEnergy( cluster, recHits, topology, id, {-1, 2, -2, 1} ); + max_E = std::max( max_E, matrixEnergy( cluster, recHits, topology, id, {-2, 1, -2, 1} ) ); + max_E = std::max( max_E, matrixEnergy( cluster, recHits, topology, id, {-2, 1, -1, 2} ) ); + max_E = std::max( max_E, matrixEnergy( cluster, recHits, topology, id, {-1, 2, -1, 2} ) ); return max_E; } @@ -437,14 +408,14 @@ template float EcalClusterToolsT::e5x5( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology ) { DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).first; - return matrixEnergy( cluster, recHits, topology, id, -2, 2, -2, 2 ); + return matrixEnergy( cluster, recHits, topology, id, {-2, 2, -2, 2} ); } template int EcalClusterToolsT::n5x5( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology ) { DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).first; - return matrixSize( cluster, recHits, topology, id, -2, 2, -2, 2 ); + return matrixSize( cluster, recHits, topology, id, {-2, 2, -2, 2} ); } template @@ -465,36 +436,34 @@ float EcalClusterToolsT::e2nd( const reco::BasicCluster &cluster, const Ec } std::partial_sort( energies.begin(), energies.begin()+2, energies.end(), std::greater() ); return energies[1]; - - } template float EcalClusterToolsT::e2x5Right( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology ) { DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).first; - return matrixEnergy( cluster, recHits, topology, id, 1, 2, -2, 2 ); + return matrixEnergy( cluster, recHits, topology, id, {1, 2, -2, 2} ); } template float EcalClusterToolsT::e2x5Left( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology ) { DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).first; - return matrixEnergy( cluster, recHits, topology, id, -2, -1, -2, 2 ); + return matrixEnergy( cluster, recHits, topology, id, {-2, -1, -2, 2} ); } -template +template float EcalClusterToolsT::e2x5Top( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology ) { DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).first; - return matrixEnergy( cluster, recHits, topology, id, -2, 2, 1, 2 ); + return matrixEnergy( cluster, recHits, topology, id, {-2, 2, 1, 2} ); } template float EcalClusterToolsT::e2x5Bottom( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology ) { DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).first; - return matrixEnergy( cluster, recHits, topology, id, -2, 2, -2, -1 ); + return matrixEnergy( cluster, recHits, topology, id, {-2, 2, -2, -1} ); } // Energy in 2x5 strip containing the max crystal. @@ -505,11 +474,11 @@ float EcalClusterToolsT::e2x5Max( const reco::BasicCluster &cluster, const DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).first; // 1x5 strip left of seed - float left = matrixEnergy( cluster, recHits, topology, id, -1, -1, -2, 2 ); + float left = matrixEnergy( cluster, recHits, topology, id, {-1, -1, -2, 2} ); // 1x5 strip right of seed - float right = matrixEnergy( cluster, recHits, topology, id, 1, 1, -2, 2 ); + float right = matrixEnergy( cluster, recHits, topology, id, {1, 1, -2, 2} ); // 1x5 strip containing seed - float centre = matrixEnergy( cluster, recHits, topology, id, 0, 0, -2, 2 ); + float centre = matrixEnergy( cluster, recHits, topology, id, {0, 0, -2, 2} ); // Return the maximum of (left+center) or (right+center) strip return left > right ? left+centre : right+centre; @@ -519,56 +488,56 @@ template float EcalClusterToolsT::e1x5( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology ) { DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).first; - return matrixEnergy( cluster, recHits, topology, id, 0, 0, -2, 2 ); + return matrixEnergy( cluster, recHits, topology, id, {0, 0, -2, 2} ); } template float EcalClusterToolsT::e5x1( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology ) { DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).first; - return matrixEnergy( cluster, recHits, topology, id, -2, 2, 0, 0 ); + return matrixEnergy( cluster, recHits, topology, id, {-2, 2, 0, 0} ); } template float EcalClusterToolsT::e1x3( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology ) { DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).first; - return matrixEnergy( cluster, recHits, topology, id, 0, 0, -1, 1 ); + return matrixEnergy( cluster, recHits, topology, id, {0, 0, -1, 1} ); } template float EcalClusterToolsT::e3x1( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology ) { DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).first; - return matrixEnergy( cluster, recHits, topology, id, -1, 1, 0, 0 ); + return matrixEnergy( cluster, recHits, topology, id, {-1, 1, 0, 0} ); } template float EcalClusterToolsT::eLeft( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology ) { DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).first; - return matrixEnergy( cluster, recHits, topology, id, -1, -1, 0, 0 ); + return matrixEnergy( cluster, recHits, topology, id, {-1, -1, 0, 0} ); } template float EcalClusterToolsT::eRight( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology ) { DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).first; - return matrixEnergy( cluster, recHits, topology, id, 1, 1, 0, 0 ); + return matrixEnergy( cluster, recHits, topology, id, {1, 1, 0, 0} ); } template float EcalClusterToolsT::eTop( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology ) { DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).first; - return matrixEnergy( cluster, recHits, topology, id, 0, 0, 1, 1 ); + return matrixEnergy( cluster, recHits, topology, id, {0, 0, 1, 1} ); } template float EcalClusterToolsT::eBottom( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology ) { DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).first; - return matrixEnergy( cluster, recHits, topology, id, 0, 0, -1, -1 ); + return matrixEnergy( cluster, recHits, topology, id, {0, 0, -1, -1} ); } template @@ -630,12 +599,12 @@ std::vector::EcalClusterEnergyDeposition> EcalC testEcalRecHit=*itt; if(( (*posCurrent).first != DetId(0)) && (recHits->find( (*posCurrent).first ) != recHits->end())) { - clEdep.deposited_energy = testEcalRecHit.energy() * (noZS ? 1.0 : (*posCurrent).second); + clEdep.deposited_energy = testEcalRecHit.energy() * (noZS ? 1.0 : (*posCurrent).second); // if logarithmic weight is requested, apply cut on minimum energy of the recHit if(logW) { //double w0 = parameterMap_.find("W0")->second; - double weight = std::max(0.0, w0 + log(std::abs(clEdep.deposited_energy)/cluster.energy()) ); + double weight = std::max(0.0, w0 + log(std::abs(clEdep.deposited_energy)/cluster.energy()) ); if(weight==0) { LogDebug("ClusterShapeAlgo") << "Crystal has insufficient energy: E = " << clEdep.deposited_energy << " GeV; skipping... "; @@ -644,7 +613,7 @@ std::vector::EcalClusterEnergyDeposition> EcalC else LogDebug("ClusterShapeAlgo") << "===> got crystal. Energy = " << clEdep.deposited_energy << " GeV. "; } DetId id_ = (*posCurrent).first; - const CaloSubdetectorGeometry* geo = geometry->getSubdetectorGeometry(id_); + const CaloSubdetectorGeometry* geo = geometry->getSubdetectorGeometry(id_); auto this_cell = geo->getGeometry(id_); const GlobalPoint& cellPos = this_cell->getPosition(); CLHEP::Hep3Vector gblPos (cellPos.x(),cellPos.y(),cellPos.z()); //surface position? @@ -662,7 +631,7 @@ std::vector::EcalClusterEnergyDeposition> EcalC if(DigiVect.dot(phi_axis)<0) clEdep.phi = 2 * M_PI - clEdep.phi; energyDistribution.push_back(clEdep); } - } + } return energyDistribution; } @@ -679,7 +648,7 @@ std::vector EcalClusterToolsT::lat( const reco::BasicCluster &clust int clusterSize=energyDistribution.size(); float etaLat_, phiLat_, lat_; if (clusterSize<3) { - etaLat_ = 0.0 ; + etaLat_ = 0.0 ; lat_ = 0.0; lat.push_back(0.); lat.push_back(0.); @@ -734,14 +703,14 @@ math::XYZVector EcalClusterToolsT::meanClusterPosition( const reco::BasicC // find mean energy position of a 5x5 cluster around the maximum math::XYZVector meanPosition(0.0, 0.0, 0.0); const std::vector >& hsAndFs = cluster.hitsAndFractions(); - std::vector v_id = matrixDetId( topology, getMaximum( cluster, recHits ).first, -2, 2, -2, 2 ); + std::vector v_id = matrixDetId( topology, getMaximum( cluster, recHits ).first, 2 ); for( const std::pair& hitAndFrac : hsAndFs ) { for( std::vector::const_iterator it = v_id.begin(); it != v_id.end(); ++it ) { - if( hitAndFrac.first != *it && !noZS) continue; - const CaloSubdetectorGeometry* geo = geometry->getSubdetectorGeometry(*it); - GlobalPoint positionGP = geo->getGeometry( *it )->getPosition(); - math::XYZVector position(positionGP.x(),positionGP.y(),positionGP.z()); - meanPosition = meanPosition + recHitEnergy( *it, recHits ) * position * hitAndFrac.second; + if( hitAndFrac.first != *it && !noZS) continue; + const CaloSubdetectorGeometry* geo = geometry->getSubdetectorGeometry(*it); + GlobalPoint positionGP = geo->getGeometry( *it )->getPosition(); + math::XYZVector position(positionGP.x(),positionGP.y(),positionGP.z()); + meanPosition = meanPosition + recHitEnergy( *it, recHits ) * position * hitAndFrac.second; } if(noZS) break; } @@ -764,14 +733,14 @@ std::pair EcalClusterToolsT::mean5x5PositionInLocalCrysCoord float energySum=0.; const std::vector >& hsAndFs = cluster.hitsAndFractions(); - std::vector v_id = matrixDetId( topology,seedId, -2, 2, -2, 2 ); + std::vector v_id = matrixDetId( topology,seedId, 2 ); for( const std::pair& hAndF : hsAndFs ) { - for ( std::vector::const_iterator it = v_id.begin(); it != v_id.end(); ++it ) { - if( hAndF.first != *it && !noZS ) continue; + for ( std::vector::const_iterator it = v_id.begin(); it != v_id.end(); ++it ) { + if( hAndF.first != *it && !noZS ) continue; float energy = recHitEnergy(*it,recHits) * hAndF.second; if(energy<0.) continue;//skipping negative energy crystals meanDEta += energy * getNrCrysDiffInEta(*it,seedId); - meanDPhi += energy * getNrCrysDiffInPhi(*it,seedId); + meanDPhi += energy * getNrCrysDiffInPhi(*it,seedId); energySum +=energy; } if(noZS) break; @@ -798,10 +767,10 @@ std::pair EcalClusterToolsT::mean5x5PositionInXY(const reco:: float energySum=0.; const std::vector >& hsAndFs = cluster.hitsAndFractions(); - std::vector v_id = matrixDetId( topology,seedId, -2, 2, -2, 2 ); + std::vector v_id = matrixDetId( topology,seedId, 2); for( const std::pair& hAndF : hsAndFs ) { for ( std::vector::const_iterator it = v_id.begin(); it != v_id.end(); ++it ) { - if( hAndF.first != *it && !noZS) continue; + if( hAndF.first != *it && !noZS) continue; float energy = recHitEnergy(*it,recHits) * hAndF.second; if(energy<0.) continue;//skipping negative energy crystals meanXY.first += energy * getNormedIX(*it); @@ -832,32 +801,28 @@ std::vector EcalClusterToolsT::covariances(const reco::BasicCluster double denominator = 0; DetId id = getMaximum( v_id, recHits ).first; - CaloNavigator cursor = CaloNavigator( id, topology->getSubdetectorTopology( id ) ); - for ( int i = -2; i <= 2; ++i ) { - for ( int j = -2; j <= 2; ++j ) { - cursor.home(); - cursor.offsetBy( i, j ); - float frac=getFraction(v_id,*cursor); - float energy = recHitEnergy( *cursor, recHits )*frac; - - if ( energy <= 0 ) continue; - - const CaloSubdetectorGeometry* geo = geometry->getSubdetectorGeometry(*cursor); - GlobalPoint position = geo->getGeometry(*cursor)->getPosition(); - - double dPhi = position.phi() - meanPosition.phi(); - if (dPhi > + Geom::pi()) { dPhi = Geom::twoPi() - dPhi; } - if (dPhi < - Geom::pi()) { dPhi = Geom::twoPi() + dPhi; } - - double dEta = position.eta() - meanPosition.eta(); - double w = 0.; - w = std::max(0.0f, w0 + std::log( energy / e_5x5 )); - - denominator += w; - numeratorEtaEta += w * dEta * dEta; - numeratorEtaPhi += w * dEta * dPhi; - numeratorPhiPhi += w * dPhi * dPhi; - } + CaloRectangle rectangle{-2, 2, -2, 2}; + for (auto const& detId : rectangle(id, *topology)) { + float frac=getFraction(v_id,detId); + float energy = recHitEnergy( detId, recHits )*frac; + + if ( energy <= 0 ) continue; + + const CaloSubdetectorGeometry* geo = geometry->getSubdetectorGeometry(detId); + GlobalPoint position = geo->getGeometry(detId)->getPosition(); + + double dPhi = position.phi() - meanPosition.phi(); + if (dPhi > + Geom::pi()) { dPhi = Geom::twoPi() - dPhi; } + if (dPhi < - Geom::pi()) { dPhi = Geom::twoPi() + dPhi; } + + double dEta = position.eta() - meanPosition.eta(); + double w = 0.; + w = std::max(0.0f, w0 + std::log( energy / e_5x5 )); + + denominator += w; + numeratorEtaEta += w * dEta * dEta; + numeratorEtaPhi += w * dEta * dPhi; + numeratorPhiPhi += w * dPhi * dPhi; } if (denominator != 0.0) { @@ -885,7 +850,7 @@ std::vector EcalClusterToolsT::covariances(const reco::BasicCluster } //for covIEtaIEta,covIEtaIPhi and covIPhiIPhi are defined but only covIEtaIEta has been actively studied -//instead of using absolute eta/phi it counts crystals normalised so that it gives identical results to normal covariances except near the cracks where of course its better +//instead of using absolute eta/phi it counts crystals normalised so that it gives identical results to normal covariances except near the cracks where of course its better //it also does not require any eta correction function in the endcap //it is multipled by an approprate crystal size to ensure it gives similar values to covariances(...) template @@ -917,31 +882,26 @@ std::vector EcalClusterToolsT::localCovariances(const reco::BasicCl bool isBarrel=seedId.subdetId()==EcalBarrel; const double crysSize = isBarrel ? barrelCrysSize : endcapCrysSize; - CaloNavigator cursor = CaloNavigator( seedId, topology->getSubdetectorTopology( seedId ) ); - - for ( int eastNr = -2; eastNr <= 2; ++eastNr ) { //east is eta in barrel - for ( int northNr = -2; northNr <= 2; ++northNr ) { //north is phi in barrel - cursor.home(); - cursor.offsetBy( eastNr, northNr); - float frac = getFraction(v_id,*cursor); - float energy = recHitEnergy( *cursor, recHits )*frac; - if ( energy <= 0 ) continue; + CaloRectangle rectangle{-2, 2, -2, 2}; + for (auto const& detId : rectangle(seedId, *topology)) { + float frac = getFraction(v_id,detId); + float energy = recHitEnergy( detId, recHits )*frac; + if ( energy <= 0 ) continue; - float dEta = getNrCrysDiffInEta(*cursor,seedId) - mean5x5PosInNrCrysFromSeed.first; - float dPhi = 0; + float dEta = getNrCrysDiffInEta(detId,seedId) - mean5x5PosInNrCrysFromSeed.first; + float dPhi = 0; - if(isBarrel) dPhi = getNrCrysDiffInPhi(*cursor,seedId) - mean5x5PosInNrCrysFromSeed.second; - else dPhi = getDPhiEndcap(*cursor,mean5x5XYPos.first,mean5x5XYPos.second); + if(isBarrel) dPhi = getNrCrysDiffInPhi(detId,seedId) - mean5x5PosInNrCrysFromSeed.second; + else dPhi = getDPhiEndcap(detId,mean5x5XYPos.first,mean5x5XYPos.second); - double w = std::max(0.0f,w0 + std::log( energy / e_5x5 )); + double w = std::max(0.0f,w0 + std::log( energy / e_5x5 )); - denominator += w; - numeratorEtaEta += w * dEta * dEta; - numeratorEtaPhi += w * dEta * dPhi; - numeratorPhiPhi += w * dPhi * dPhi; - } //end east loop - }//end north loop + denominator += w; + numeratorEtaEta += w * dEta * dEta; + numeratorEtaPhi += w * dEta * dPhi; + numeratorPhiPhi += w * dPhi * dPhi; + } //multiplying by crysSize to make the values compariable to normal covariances @@ -1212,16 +1172,15 @@ std::vector EcalClusterToolsT::scLocalCovariances(const reco::Super const double crysSize = isBarrel ? barrelCrysSize : endcapCrysSize; for (size_t i = 0; i < v_id.size(); ++i) { - CaloNavigator cursor = CaloNavigator(v_id[i].first, topology->getSubdetectorTopology(v_id[i].first)); - float frac = getFraction(v_id,*cursor); - float energy = recHitEnergy(*cursor, recHits)*frac; + float frac = getFraction(v_id, v_id[i].first); + float energy = recHitEnergy(v_id[i].first, recHits)*frac; if (energy <= 0) continue; - float dEta = getNrCrysDiffInEta(*cursor,seedId) - mean5x5PosInNrCrysFromSeed.first; + float dEta = getNrCrysDiffInEta(v_id[i].first,seedId) - mean5x5PosInNrCrysFromSeed.first; float dPhi = 0; - if(isBarrel) dPhi = getNrCrysDiffInPhi(*cursor,seedId) - mean5x5PosInNrCrysFromSeed.second; - else dPhi = getDPhiEndcap(*cursor,mean5x5XYPos.first,mean5x5XYPos.second); + if(isBarrel) dPhi = getNrCrysDiffInPhi(v_id[i].first,seedId) - mean5x5PosInNrCrysFromSeed.second; + else dPhi = getDPhiEndcap(v_id[i].first,mean5x5XYPos.first,mean5x5XYPos.second); @@ -1366,14 +1325,14 @@ Cluster2ndMoments EcalClusterToolsT::cluster2ndMoments( const std::vector< // correct phi wrap-around: if(max_phi==359.5 && min_phi==0.5){ for(unsigned int i=0; i 0.) phiDetId[i]-=360.; - mid_phi+=phiDetId[i]*wiDetId[i]; - mid_eta+=etaDetId[i]*wiDetId[i]; + if(phiDetId[i] - 179. > 0.) phiDetId[i]-=360.; + mid_phi+=phiDetId[i]*wiDetId[i]; + mid_eta+=etaDetId[i]*wiDetId[i]; } } else{ for(unsigned int i=0; i EcalClusterToolsT::roundnessBarrelSuperClusters( const //get pointer to recHit object EcalRecHitCollection::const_iterator myRH = recHits.find(myHitsPair[i].first); if( myRH != recHits.end() && myRH->energy()*(noZS ? 1.0 : myHitsPair[i].second) > energyThreshold){ - //require rec hit to have positive energy - RH_ptrs_fracs.push_back( std::make_pair(&(*myRH) , myHitsPair[i].second) ); + //require rec hit to have positive energy + RH_ptrs_fracs.push_back( std::make_pair(&(*myRH) , myHitsPair[i].second) ); } } std::vector temp = EcalClusterToolsT::roundnessSelectedBarrelRecHits(RH_ptrs_fracs,weightedPositionMethod); @@ -1466,7 +1425,7 @@ std::vector EcalClusterToolsT::roundnessBarrelSuperClustersUserExte //get pointer to recHit object EcalRecHitCollection::const_iterator myRH = recHits.find(myHitsPair[i].first); if(myRH != recHits.end() && myRH->energy()*(noZS ? 1.0 : myHitsPair[i].second) > energyRHThresh) - RH_ptrs_fracs.push_back( std::make_pair(&(*myRH) , myHitsPair[i].second) ); + RH_ptrs_fracs.push_back( std::make_pair(&(*myRH) , myHitsPair[i].second) ); } @@ -1474,7 +1433,7 @@ std::vector EcalClusterToolsT::roundnessBarrelSuperClustersUserExte for(EcalRecHitCollection::const_iterator rh = recHits.begin(); rh != recHits.end(); rh++){ EBDetId EBdetIdi( rh->detid() ); - float the_fraction = 0; + float the_fraction = 0; //if(rh != recHits.end()) bool inEtaWindow = ( abs( deltaIEta(seedPosition[0],EBdetIdi.ieta()) ) <= ieta_delta ); bool inPhiWindow = ( abs( deltaIPhi(seedPosition[1],EBdetIdi.iphi()) ) <= iphi_delta ); @@ -1486,14 +1445,14 @@ std::vector EcalClusterToolsT::roundnessBarrelSuperClustersUserExte for(unsigned int i=0; idetid() == SCrh->detid() ) alreadyCounted = true; } }//for loop over SC's recHits if( is_SCrh_inside_recHits && !alreadyCounted && passEThresh && inEtaWindow && inPhiWindow){ - RH_ptrs_fracs.push_back( std::make_pair(&(*rh),the_fraction) ); + RH_ptrs_fracs.push_back( std::make_pair(&(*rh),the_fraction) ); } }//for loop over rh @@ -1528,7 +1487,7 @@ std::vector EcalClusterToolsT::roundnessSelectedBarrelRecHits( cons float denominator = 0.; for(std::vector >::const_iterator rhf_ptr = RH_ptrs_fracs.begin(); rhf_ptr != RH_ptrs_fracs.end(); rhf_ptr++){ - const EcalRecHit* rh_ptr = rhf_ptr->first; + const EcalRecHit* rh_ptr = rhf_ptr->first; //get iEta, iPhi EBDetId EBdetIdi( rh_ptr->detid() ); if(fabs(energyTotal) < 0.0001){ @@ -1537,7 +1496,7 @@ std::vector EcalClusterToolsT::roundnessSelectedBarrelRecHits( cons shapes.push_back( -2 ); return shapes; } - float rh_energy = rh_ptr->energy() * (noZS ? 1.0 : rhf_ptr->second); + float rh_energy = rh_ptr->energy() * (noZS ? 1.0 : rhf_ptr->second); float weight = 0; if(std::abs(weightedPositionMethod)<0.0001){ //linear weight = rh_energy/energyTotal; @@ -1545,7 +1504,7 @@ std::vector EcalClusterToolsT::roundnessSelectedBarrelRecHits( cons weight = std::max(0.0, 4.2 + log(rh_energy/energyTotal)); } denominator += weight; - centerIEta += weight*deltaIEta(seedPosition[0],EBdetIdi.ieta()); + centerIEta += weight*deltaIEta(seedPosition[0],EBdetIdi.ieta()); centerIPhi += weight*deltaIPhi(seedPosition[1],EBdetIdi.iphi()); } if(fabs(denominator) < 0.0001){ @@ -1575,7 +1534,7 @@ std::vector EcalClusterToolsT::roundnessSelectedBarrelRecHits( cons shapes.push_back( -2 ); return shapes; } - float rh_energy = rh_ptr->energy() * (noZS ? 1.0 : rhf_ptr->second); + float rh_energy = rh_ptr->energy() * (noZS ? 1.0 : rhf_ptr->second); float weight = 0; if(std::abs(weightedPositionMethod) < 0.0001){ //linear weight = rh_energy/energyTotal; @@ -1638,23 +1597,15 @@ std::vector EcalClusterToolsT::roundnessSelectedBarrelRecHits( cons template int EcalClusterToolsT::nrSaturatedCrysIn5x5(const DetId& id,const EcalRecHitCollection* recHits,const CaloTopology *topology) { - int nrSat=0; - CaloNavigator cursor = CaloNavigator( id, topology->getSubdetectorTopology( id ) ); - - for ( int eastNr = -2; eastNr <= 2; ++eastNr ) { //east is eta in barrel - for ( int northNr = -2; northNr <= 2; ++northNr ) { //north is phi in barrel - cursor.home(); - cursor.offsetBy( eastNr, northNr); - DetId id = *cursor; - auto recHitIt = recHits->find(id); - if(recHitIt!=recHits->end() && - recHitIt->checkFlag(EcalRecHit::kSaturated)){ - nrSat++; - } - + int nrSat=0; + CaloRectangle rectangle{-2, 2, -2, 2}; + for (auto const& detId : rectangle(id, *topology)) { + auto recHitIt = recHits->find(detId); + if(recHitIt!=recHits->end() && recHitIt->checkFlag(EcalRecHit::kSaturated)) { + nrSat++; + } } - } - return nrSat; + return nrSat; } @@ -1691,11 +1642,11 @@ std::vector EcalClusterToolsT::getSeedPosition(const std::vector >::const_iterator rhf_ptr = RH_ptrs_fracs.begin(); rhf_ptr != RH_ptrs_fracs.end(); rhf_ptr++){ - const EcalRecHit* rh_ptr = rhf_ptr->first; + for(auto const& rhf : RH_ptrs_fracs) { + const EcalRecHit* rh_ptr = rhf.first; //get iEta, iPhi EBDetId EBdetIdi( rh_ptr->detid() ); - float rh_energy = rh_ptr->energy() * (noZS ? 1.0 : rhf_ptr->second); + float rh_energy = rh_ptr->energy() * (noZS ? 1.0 : rhf.second); if(eSeedRH < rh_energy){ eSeedRH = rh_energy; @@ -1716,15 +1667,13 @@ float EcalClusterToolsT::getSumEnergy(const std::vectorenergy() * (noZS ? 1.0 : hAndF.second); - } + } return sumE; } typedef EcalClusterToolsT EcalClusterTools; -namespace noZS { - typedef EcalClusterToolsT EcalClusterTools; -} +namespace noZS { typedef EcalClusterToolsT EcalClusterTools; } #endif diff --git a/RecoEcal/EgammaCoreTools/src/EcalClusterLazyTools.cc b/RecoEcal/EgammaCoreTools/src/EcalClusterLazyTools.cc index 59877e57177c3..f277e08fe5810 100644 --- a/RecoEcal/EgammaCoreTools/src/EcalClusterLazyTools.cc +++ b/RecoEcal/EgammaCoreTools/src/EcalClusterLazyTools.cc @@ -22,76 +22,39 @@ #include "RecoLocalCalo/EcalRecAlgos/interface/EcalSeverityLevelAlgoRcd.h" #include "RecoLocalCalo/EcalRecAlgos/interface/EcalSeverityLevelAlgo.h" -EcalClusterLazyToolsBase::EcalClusterLazyToolsBase( const edm::Event &ev, const edm::EventSetup &es, edm::EDGetTokenT token1, edm::EDGetTokenT token2) { - - ebRHToken_ = token1; - eeRHToken_ = token2; - - getGeometry( es , false ); - getTopology( es ); - getEBRecHits( ev ); - getEERecHits( ev ); +EcalClusterLazyToolsBase::EcalClusterLazyToolsBase( const edm::Event &ev, const edm::EventSetup &es, edm::EDGetTokenT token1, edm::EDGetTokenT token2) + : geometry_(&edm::get(es)) + , topology_(&edm::get(es)) + , ebRecHits_(&edm::get(ev, token1)) + , eeRecHits_(&edm::get(ev, token2)) +{ getIntercalibConstants( es ); getADCToGeV ( es ); getLaserDbService ( es ); } -EcalClusterLazyToolsBase::EcalClusterLazyToolsBase( const edm::Event &ev, const edm::EventSetup &es, edm::EDGetTokenT token1, edm::EDGetTokenT token2, edm::EDGetTokenT token3) { +EcalClusterLazyToolsBase::EcalClusterLazyToolsBase( const edm::Event &ev, const edm::EventSetup &es, edm::EDGetTokenT token1, edm::EDGetTokenT token2, edm::EDGetTokenT token3) + : geometry_(&edm::get(es)) + , topology_(&edm::get(es)) + , ebRecHits_(&edm::get(ev, token1)) + , eeRecHits_(&edm::get(ev, token2)) +{ + const CaloSubdetectorGeometry *geometryES = geometry_->getSubdetectorGeometry(DetId::Ecal, EcalPreshower); + if (geometryES) { + ecalPS_topology_.reset(new EcalPreshowerTopology(geometry_)); + } else { + ecalPS_topology_.reset(); + edm::LogInfo("subdetector geometry not available") << "EcalPreshower geometry is missing" << std::endl; + } - ebRHToken_ = token1; - eeRHToken_ = token2; esRHToken_ = token3; - - getGeometry( es ); - getTopology( es ); - getEBRecHits( ev ); - getEERecHits( ev ); getESRecHits( ev ); + getIntercalibConstants( es ); getADCToGeV ( es ); getLaserDbService ( es ); } -EcalClusterLazyToolsBase::~EcalClusterLazyToolsBase() -{} - -void EcalClusterLazyToolsBase::getGeometry( const edm::EventSetup &es, bool doES ) { - edm::ESHandle pGeometry; - es.get().get(pGeometry); - geometry_ = pGeometry.product(); - - if(doES){ - const CaloSubdetectorGeometry *geometryES = geometry_->getSubdetectorGeometry(DetId::Ecal, EcalPreshower); - if (geometryES) { - ecalPS_topology_.reset(new EcalPreshowerTopology(geometry_)); - } else { - ecalPS_topology_.reset(); - edm::LogInfo("subdetector geometry not available") << "EcalPreshower geometry is missing" << std::endl; - } - } - else { - ecalPS_topology_.reset(); - } -} - -void EcalClusterLazyToolsBase::getTopology( const edm::EventSetup &es ) { - edm::ESHandle pTopology; - es.get().get(pTopology); - topology_ = pTopology.product(); -} - -void EcalClusterLazyToolsBase::getEBRecHits( const edm::Event &ev ) { - edm::Handle< EcalRecHitCollection > pEBRecHits; - ev.getByToken( ebRHToken_, pEBRecHits ); - ebRecHits_ = pEBRecHits.product(); -} - -void EcalClusterLazyToolsBase::getEERecHits( const edm::Event &ev ) { - edm::Handle< EcalRecHitCollection > pEERecHits; - ev.getByToken( eeRHToken_, pEERecHits ); - eeRecHits_ = pEERecHits.product(); -} - void EcalClusterLazyToolsBase::getESRecHits( const edm::Event &ev ) { edm::Handle< EcalRecHitCollection > pESRecHits; ev.getByToken( esRHToken_, pESRecHits ); @@ -147,7 +110,7 @@ void EcalClusterLazyToolsBase::getLaserDbService ( const edm::EventSetup &es } -const EcalRecHitCollection * EcalClusterLazyToolsBase::getEcalRecHitCollection( const reco::BasicCluster &cluster ) +const EcalRecHitCollection * EcalClusterLazyToolsBase::getEcalRecHitCollection( const reco::BasicCluster &cluster ) const { if ( cluster.size() == 0 ) { throw cms::Exception("InvalidCluster") << "The cluster has no crystals!"; diff --git a/RecoEcal/EgammaCoreTools/test/testEcalClusterLazyTools.cc b/RecoEcal/EgammaCoreTools/test/testEcalClusterLazyTools.cc index 9c9046a5b3983..a42c8c0af7412 100644 --- a/RecoEcal/EgammaCoreTools/test/testEcalClusterLazyTools.cc +++ b/RecoEcal/EgammaCoreTools/test/testEcalClusterLazyTools.cc @@ -2,7 +2,7 @@ // // Package: testEcalClusterLazyTools // Class: testEcalClusterLazyTools -// +// /**\class testEcalClusterLazyTools testEcalClusterLazyTools.cc Description: @@ -17,149 +17,132 @@ Description: // -// system include files -#include - -// user include files #include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/EDAnalyzer.h" - +#include "FWCore/Framework/interface/one/EDAnalyzer.h" #include "FWCore/Framework/interface/Event.h" #include "FWCore/Framework/interface/MakerMacros.h" - #include "FWCore/ParameterSet/interface/ParameterSet.h" - -// to access recHits and BasicClusters #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h" #include "DataFormats/EgammaReco/interface/BasicClusterFwd.h" - -// to use the cluster tools #include "FWCore/Framework/interface/ESHandle.h" - -//#include "RecoEcal/EgammaCoreTools/interface/EcalClusterTools.h" #include "RecoEcal/EgammaCoreTools/interface/EcalClusterLazyTools.h" - #include "Geometry/CaloGeometry/interface/CaloGeometry.h" #include "Geometry/CaloTopology/interface/CaloTopology.h" - #include "Geometry/Records/interface/IdealGeometryRecord.h" #include "Geometry/CaloEventSetup/interface/CaloTopologyRecord.h" +#include -class testEcalClusterLazyTools : public edm::EDAnalyzer { +class testEcalClusterLazyTools : public edm::one::EDAnalyzer<> { public: explicit testEcalClusterLazyTools(const edm::ParameterSet&); - ~testEcalClusterLazyTools(); - - edm::EDGetTokenT barrelClusterToken_; - edm::EDGetTokenT endcapClusterToken_; - edm::EDGetTokenT reducedBarrelRecHitToken_; - edm::EDGetTokenT reducedEndcapRecHitToken_; - + private: - virtual void analyze(const edm::Event&, const edm::EventSetup&); - -}; + virtual void analyze(const edm::Event&, const edm::EventSetup&) override; + using LazyTools = noZS::EcalClusterLazyTools; // alternatively just EcalClusterLazyTools + const edm::EDGetTokenT barrelClusterToken_; + const edm::EDGetTokenT endcapClusterToken_; + const edm::EDGetTokenT barrelRecHitToken_; + const edm::EDGetTokenT endcapRecHitToken_; -testEcalClusterLazyTools::testEcalClusterLazyTools(const edm::ParameterSet& ps) -{ - barrelClusterToken_ = consumes(ps.getParameter("barrelClusterCollection")); - endcapClusterToken_ = consumes(ps.getParameter("endcapClusterCollection")); - reducedBarrelRecHitToken_ = consumes(ps.getParameter("reducedBarrelRecHitCollection")); - reducedEndcapRecHitToken_ = consumes(ps.getParameter("reducedEndcapRecHitCollection")); -} +}; -testEcalClusterLazyTools::~testEcalClusterLazyTools() +testEcalClusterLazyTools::testEcalClusterLazyTools(const edm::ParameterSet& ps) + : barrelClusterToken_(consumes(ps.getParameter("barrelClusterCollection"))) + , endcapClusterToken_(consumes(ps.getParameter("endcapClusterCollection"))) + , barrelRecHitToken_(consumes(ps.getParameter("barrelRecHitCollection"))) + , endcapRecHitToken_(consumes(ps.getParameter("endcapRecHitCollection"))) {} - void testEcalClusterLazyTools::analyze(const edm::Event& ev, const edm::EventSetup& es) { edm::Handle< reco::BasicClusterCollection > pEBClusters; ev.getByToken( barrelClusterToken_, pEBClusters ); const reco::BasicClusterCollection *ebClusters = pEBClusters.product(); - + edm::Handle< reco::BasicClusterCollection > pEEClusters; ev.getByToken( endcapClusterToken_, pEEClusters ); const reco::BasicClusterCollection *eeClusters = pEEClusters.product(); - EcalClusterLazyTools lazyTools( ev, es, reducedBarrelRecHitToken_, reducedEndcapRecHitToken_ ); - + LazyTools lazyTools( ev, es, barrelRecHitToken_, endcapRecHitToken_ ); + std::cout << "========== BARREL ==========" << std::endl; - for (reco::BasicClusterCollection::const_iterator it = ebClusters->begin(); it != ebClusters->end(); ++it ) { + for(auto const& clus : *ebClusters) { std::cout << "----- new cluster -----" << std::endl; - std::cout << "----------------- size: " << (*it).size() << " energy: " << (*it).energy() << std::endl; - - std::cout << "e1x3..................... " << lazyTools.e1x3( *it ) << std::endl; - std::cout << "e3x1..................... " << lazyTools.e3x1( *it ) << std::endl; - std::cout << "e1x5..................... " << lazyTools.e1x5( *it ) << std::endl; - //std::cout << "e5x1..................... " << lazyTools.e5x1( *it ) << std::endl; - std::cout << "e2x2..................... " << lazyTools.e2x2( *it ) << std::endl; - std::cout << "e3x3..................... " << lazyTools.e5x5( *it ) << std::endl; - std::cout << "e4x4..................... " << lazyTools.e4x4( *it ) << std::endl; - std::cout << "e5x5..................... " << lazyTools.e3x3( *it ) << std::endl; - std::cout << "e2x5Right................ " << lazyTools.e2x5Right( *it ) << std::endl; - std::cout << "e2x5Left................. " << lazyTools.e2x5Left( *it ) << std::endl; - std::cout << "e2x5Top.................. " << lazyTools.e2x5Top( *it ) << std::endl; - std::cout << "e2x5Bottom............... " << lazyTools.e2x5Bottom( *it ) << std::endl; - std::cout << "e2x5Max.................. " << lazyTools.e2x5Max( *it ) << std::endl; - std::cout << "eMax..................... " << lazyTools.eMax( *it ) << std::endl; - std::cout << "e2nd..................... " << lazyTools.e2nd( *it ) << std::endl; - std::vector vEta = lazyTools.energyBasketFractionEta( *it ); + std::cout << "----------------- size: " << (clus).size() << " energy: " << (clus).energy() << std::endl; + + std::cout << "e1x3..................... " << lazyTools.e1x3( clus ) << std::endl; + std::cout << "e3x1..................... " << lazyTools.e3x1( clus ) << std::endl; + std::cout << "e1x5..................... " << lazyTools.e1x5( clus ) << std::endl; + std::cout << "e5x1..................... " << lazyTools.e5x1( clus ) << std::endl; + std::cout << "e2x2..................... " << lazyTools.e2x2( clus ) << std::endl; + std::cout << "e3x3..................... " << lazyTools.e3x3( clus ) << std::endl; + std::cout << "e4x4..................... " << lazyTools.e4x4( clus ) << std::endl; + std::cout << "e5x5..................... " << lazyTools.e5x5( clus ) << std::endl; + std::cout << "n5x5..................... " << lazyTools.n5x5( clus ) << std::endl; + std::cout << "e2x5Right................ " << lazyTools.e2x5Right( clus ) << std::endl; + std::cout << "e2x5Left................. " << lazyTools.e2x5Left( clus ) << std::endl; + std::cout << "e2x5Top.................. " << lazyTools.e2x5Top( clus ) << std::endl; + std::cout << "e2x5Bottom............... " << lazyTools.e2x5Bottom( clus ) << std::endl; + std::cout << "e2x5Max.................. " << lazyTools.e2x5Max( clus ) << std::endl; + std::cout << "eMax..................... " << lazyTools.eMax( clus ) << std::endl; + std::cout << "e2nd..................... " << lazyTools.e2nd( clus ) << std::endl; + std::vector vEta = lazyTools.energyBasketFractionEta( clus ); std::cout << "energyBasketFractionEta.."; for (size_t i = 0; i < vEta.size(); ++i ) { std::cout << " " << vEta[i]; } std::cout << std::endl; - std::vector vPhi = lazyTools.energyBasketFractionPhi( *it ); + std::vector vPhi = lazyTools.energyBasketFractionPhi( clus ); std::cout << "energyBasketFractionPhi.."; for (size_t i = 0; i < vPhi.size(); ++i ) { std::cout << " " << vPhi[i]; } std::cout << std::endl; - std::vector vLat = lazyTools.lat( *it ); + std::vector vLat = lazyTools.lat( clus ); std::cout << "lat...................... " << vLat[0] << " " << vLat[1] << " " << vLat[2] << std::endl; - std::vector vCov = lazyTools.covariances( *it ); - std::cout << "covariances.............. " << vCov[0] << " " << vCov[1] << " " << vCov[2] << std::endl; - std::vector vLocCov = lazyTools.localCovariances( *it ); + std::vector vCov = lazyTools.covariances( clus ); + std::cout << "covariances.............. " << vCov[0] << " " << vCov[1] << " " << vCov[2] << std::endl; + std::vector vLocCov = lazyTools.localCovariances( clus ); std::cout << "local covariances........ " << vLocCov[0] << " " << vLocCov[1] << " " << vLocCov[2] << std::endl; - std::cout << "zernike20................ " << lazyTools.zernike20( *it ) << std::endl; - std::cout << "zernike42................ " << lazyTools.zernike42( *it ) << std::endl; + std::cout << "zernike20................ " << lazyTools.zernike20( clus ) << std::endl; + std::cout << "zernike42................ " << lazyTools.zernike42( clus ) << std::endl; } - + std::cout << "========== ENDCAPS ==========" << std::endl; - for (reco::BasicClusterCollection::const_iterator it = eeClusters->begin(); it != eeClusters->end(); ++it ) { + for(auto const& clus : *eeClusters) { std::cout << "----- new cluster -----" << std::endl; - std::cout << "----------------- size: " << (*it).size() << " energy: " << (*it).energy() << std::endl; - - std::cout << "e1x3..................... " << lazyTools.e1x3( *it ) << std::endl; - std::cout << "e3x1..................... " << lazyTools.e3x1( *it ) << std::endl; - std::cout << "e1x5..................... " << lazyTools.e1x5( *it ) << std::endl; - //std::cout << "e5x1..................... " << lazyTools.e5x1( *it ) << std::endl; - std::cout << "e2x2..................... " << lazyTools.e2x2( *it ) << std::endl; - std::cout << "e3x3..................... " << lazyTools.e5x5( *it ) << std::endl; - std::cout << "e4x4..................... " << lazyTools.e4x4( *it ) << std::endl; - std::cout << "e5x5..................... " << lazyTools.e3x3( *it ) << std::endl; - std::cout << "e2x5Right................ " << lazyTools.e2x5Right( *it ) << std::endl; - std::cout << "e2x5Left................. " << lazyTools.e2x5Left( *it ) << std::endl; - std::cout << "e2x5Top.................. " << lazyTools.e2x5Top( *it ) << std::endl; - std::cout << "e2x5Bottom............... " << lazyTools.e2x5Bottom( *it ) << std::endl; - std::cout << "eMax..................... " << lazyTools.eMax( *it ) << std::endl; - std::cout << "e2nd..................... " << lazyTools.e2nd( *it ) << std::endl; - std::vector vLat = lazyTools.lat( *it ); + std::cout << "----------------- size: " << (clus).size() << " energy: " << (clus).energy() << std::endl; + + std::cout << "e1x3..................... " << lazyTools.e1x3( clus ) << std::endl; + std::cout << "e3x1..................... " << lazyTools.e3x1( clus ) << std::endl; + std::cout << "e1x5..................... " << lazyTools.e1x5( clus ) << std::endl; + std::cout << "e5x1..................... " << lazyTools.e5x1( clus ) << std::endl; + std::cout << "e2x2..................... " << lazyTools.e2x2( clus ) << std::endl; + std::cout << "e3x3..................... " << lazyTools.e3x3( clus ) << std::endl; + std::cout << "e4x4..................... " << lazyTools.e4x4( clus ) << std::endl; + std::cout << "e5x5..................... " << lazyTools.e5x5( clus ) << std::endl; + std::cout << "n5x5..................... " << lazyTools.n5x5( clus ) << std::endl; + std::cout << "e2x5Right................ " << lazyTools.e2x5Right( clus ) << std::endl; + std::cout << "e2x5Left................. " << lazyTools.e2x5Left( clus ) << std::endl; + std::cout << "e2x5Top.................. " << lazyTools.e2x5Top( clus ) << std::endl; + std::cout << "e2x5Bottom............... " << lazyTools.e2x5Bottom( clus ) << std::endl; + std::cout << "eMax..................... " << lazyTools.eMax( clus ) << std::endl; + std::cout << "e2nd..................... " << lazyTools.e2nd( clus ) << std::endl; + std::vector vLat = lazyTools.lat( clus ); std::cout << "lat...................... " << vLat[0] << " " << vLat[1] << " " << vLat[2] << std::endl; - std::vector vCov = lazyTools.covariances( *it ); - std::cout << "covariances.............. " << vCov[0] << " " << vCov[1] << " " << vCov[2] << std::endl; - std::vector vLocCov = lazyTools.localCovariances( *it ); + std::vector vCov = lazyTools.covariances( clus ); + std::cout << "covariances.............. " << vCov[0] << " " << vCov[1] << " " << vCov[2] << std::endl; + std::vector vLocCov = lazyTools.localCovariances( clus ); std::cout << "local covariances........ " << vLocCov[0] << " " << vLocCov[1] << " " << vLocCov[2] << std::endl; - std::cout << "zernike20................ " << lazyTools.zernike20( *it ) << std::endl; - std::cout << "zernike42................ " << lazyTools.zernike42( *it ) << std::endl; + std::cout << "zernike20................ " << lazyTools.zernike20( clus ) << std::endl; + std::cout << "zernike42................ " << lazyTools.zernike42( clus ) << std::endl; } } diff --git a/RecoEcal/EgammaCoreTools/test/testEcalClusterLazyTools.py b/RecoEcal/EgammaCoreTools/test/testEcalClusterLazyTools.py index 7f4b2590849d8..3211008bb8300 100644 --- a/RecoEcal/EgammaCoreTools/test/testEcalClusterLazyTools.py +++ b/RecoEcal/EgammaCoreTools/test/testEcalClusterLazyTools.py @@ -1,27 +1,26 @@ -from FWCore.ParameterSet.Config import * +import FWCore.ParameterSet.Config as cms +from Configuration.AlCa.GlobalTag import GlobalTag -process = Process("test") -process.extend(include("FWCore/MessageLogger/data/MessageLogger.cfi")) -#process.MessageLogger.cerr.FwkReport.reportEvery = 50 +process = cms.Process("test") -process.extend(include("RecoEcal/EgammaClusterProducers/data/geometryForClustering.cff")) +process.load("Configuration.StandardSequences.GeometryDB_cff") +process.load("FWCore.MessageService.MessageLogger_cfi") +process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff") -input_files = vstring() -#input_files.append( "/store/relval/2008/4/17/RelVal-RelValTTbar-1208465820/0000/0ABDA540-EE0C-DD11-BA9F-000423D94990.root" ) -input_files.append( "file:/data/ferriff/ClusterMulti5x5/CMSSW_2_1_X_2008-05-14-0200/src/reco.root" ) +input_files = cms.vstring("/store/data/Run2018A/EGamma/AOD/17Sep2018-v2/100000/01EB9686-9A6F-BF48-903A-02F7D9AEB9B9.root") -process.source = Source("PoolSource", - fileNames = untracked( input_files ) -) +process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:run2_data', '') + +process.source = cms.Source("PoolSource", fileNames = cms.untracked( input_files ) ) -process.maxEvents = untracked.PSet( input = untracked.int32( 10 ) ) +process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32( 10 ) ) -process.testEcalClusterLazyTools = EDAnalyzer("testEcalClusterLazyTools", - reducedBarrelRecHitCollection = InputTag("reducedEcalRecHitsEB"), - reducedEndcapRecHitCollection = InputTag("reducedEcalRecHitsEE"), - barrelClusterCollection = InputTag("hybridSuperClusters:"), - endcapClusterCollection = InputTag("multi5x5BasicClusters:multi5x5EndcapBasicClusters") +process.testEcalClusterLazyTools = cms.EDAnalyzer("testEcalClusterLazyTools", + barrelRecHitCollection = cms.InputTag("reducedEcalRecHitsEB"), + endcapRecHitCollection = cms.InputTag("reducedEcalRecHitsEE"), + barrelClusterCollection = cms.InputTag("hybridSuperClusters:hybridBarrelBasicClusters"), + endcapClusterCollection = cms.InputTag("multi5x5SuperClusters:multi5x5EndcapBasicClusters") ) -process.p1 = Path( process.testEcalClusterLazyTools ) +process.p1 = cms.Path( process.testEcalClusterLazyTools ) diff --git a/RecoEcal/EgammaCoreTools/test/testEcalClusterTools.cc b/RecoEcal/EgammaCoreTools/test/testEcalClusterTools.cc index 02f7cbfcc01a3..1f33a5cc68857 100644 --- a/RecoEcal/EgammaCoreTools/test/testEcalClusterTools.cc +++ b/RecoEcal/EgammaCoreTools/test/testEcalClusterTools.cc @@ -2,7 +2,7 @@ // // Package: testEcalClusterTools // Class: testEcalClusterTools -// +// /**\class testEcalClusterTools testEcalClusterTools.cc Description: @@ -16,164 +16,149 @@ Description: // // - -// system include files -#include - -// user include files #include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/EDAnalyzer.h" - +#include "FWCore/Framework/interface/one/EDAnalyzer.h" #include "FWCore/Framework/interface/Event.h" #include "FWCore/Framework/interface/MakerMacros.h" - #include "FWCore/ParameterSet/interface/ParameterSet.h" - -// to access recHits and BasicClusters #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h" #include "DataFormats/EgammaReco/interface/BasicClusterFwd.h" - -// to use the cluster tools #include "FWCore/Framework/interface/ESHandle.h" - #include "RecoEcal/EgammaCoreTools/interface/EcalClusterTools.h" - #include "Geometry/CaloGeometry/interface/CaloGeometry.h" #include "Geometry/CaloTopology/interface/CaloTopology.h" - #include "Geometry/Records/interface/CaloGeometryRecord.h" #include "Geometry/CaloEventSetup/interface/CaloTopologyRecord.h" +#include "FWCore/Utilities/interface/EDGetToken.h" +#include +class testEcalClusterTools : public edm::one::EDAnalyzer<> { + public: + explicit testEcalClusterTools(const edm::ParameterSet&); -class testEcalClusterTools : public edm::EDAnalyzer { - public: - explicit testEcalClusterTools(const edm::ParameterSet&); - ~testEcalClusterTools(); + private: + virtual void analyze(const edm::Event&, const edm::EventSetup&) override; - edm::InputTag barrelClusterCollection_; - edm::InputTag endcapClusterCollection_; - edm::InputTag reducedBarrelRecHitCollection_; - edm::InputTag reducedEndcapRecHitCollection_; + using ClusterTools = noZS::EcalClusterTools; // alternatively just EcalClusterTools - private: - virtual void analyze(const edm::Event&, const edm::EventSetup&); + const edm::EDGetToken barrelClusterToken_; + const edm::EDGetToken endcapClusterToken_; + const edm::EDGetToken barrelRecHitToken_; + const edm::EDGetToken endcapRecHitToken_; }; testEcalClusterTools::testEcalClusterTools(const edm::ParameterSet& ps) -{ - barrelClusterCollection_ = ps.getParameter("barrelClusterCollection"); - endcapClusterCollection_ = ps.getParameter("endcapClusterCollection"); - reducedBarrelRecHitCollection_ = ps.getParameter("reducedBarrelRecHitCollection"); - reducedEndcapRecHitCollection_ = ps.getParameter("reducedEndcapRecHitCollection"); -} - - - -testEcalClusterTools::~testEcalClusterTools() -{ -} + : barrelClusterToken_(consumes(ps.getParameter("barrelClusterCollection"))) + , endcapClusterToken_(consumes(ps.getParameter("endcapClusterCollection"))) + , barrelRecHitToken_(consumes(ps.getParameter("barrelRecHitCollection"))) + , endcapRecHitToken_(consumes(ps.getParameter("endcapRecHitCollection"))) +{} void testEcalClusterTools::analyze(const edm::Event& ev, const edm::EventSetup& es) { - edm::Handle< reco::BasicClusterCollection > pEBClusters; - ev.getByLabel( barrelClusterCollection_, pEBClusters ); - const reco::BasicClusterCollection *ebClusters = pEBClusters.product(); - - edm::Handle< reco::BasicClusterCollection > pEEClusters; - ev.getByLabel( endcapClusterCollection_, pEEClusters ); - const reco::BasicClusterCollection *eeClusters = pEEClusters.product(); - - edm::Handle< EcalRecHitCollection > pEBRecHits; - ev.getByLabel( reducedBarrelRecHitCollection_, pEBRecHits ); - const EcalRecHitCollection *ebRecHits = pEBRecHits.product(); - - edm::Handle< EcalRecHitCollection > pEERecHits; - ev.getByLabel( reducedEndcapRecHitCollection_, pEERecHits ); - const EcalRecHitCollection *eeRecHits = pEERecHits.product(); - - edm::ESHandle pGeometry; - es.get().get(pGeometry); - const CaloGeometry *geometry = pGeometry.product(); - - edm::ESHandle pTopology; - es.get().get(pTopology); - const CaloTopology *topology = pTopology.product(); - - std::cout << "========== BARREL ==========" << std::endl; - for (reco::BasicClusterCollection::const_iterator it = ebClusters->begin(); it != ebClusters->end(); ++it ) { - std::cout << "----- new cluster -----" << std::endl; - std::cout << "----------------- size: " << (*it).size() << " energy: " << (*it).energy() << std::endl; - - std::cout << "e1x3..................... " << EcalClusterTools::e1x3( *it, ebRecHits, topology ) << std::endl; - std::cout << "e3x1..................... " << EcalClusterTools::e3x1( *it, ebRecHits, topology ) << std::endl; - std::cout << "e1x5..................... " << EcalClusterTools::e1x5( *it, ebRecHits, topology ) << std::endl; - //std::cout << "e5x1..................... " << EcalClusterTools::e5x1( *it, ebRecHits, topology ) << std::endl; - std::cout << "e2x2..................... " << EcalClusterTools::e2x2( *it, ebRecHits, topology ) << std::endl; - std::cout << "e3x3..................... " << EcalClusterTools::e3x3( *it, ebRecHits, topology ) << std::endl; - std::cout << "e4x4..................... " << EcalClusterTools::e4x4( *it, ebRecHits, topology ) << std::endl; - std::cout << "e5x5..................... " << EcalClusterTools::e5x5( *it, ebRecHits, topology ) << std::endl; - std::cout << "e2x5Right................ " << EcalClusterTools::e2x5Right( *it, ebRecHits, topology ) << std::endl; - std::cout << "e2x5Left................. " << EcalClusterTools::e2x5Left( *it, ebRecHits, topology ) << std::endl; - std::cout << "e2x5Top.................. " << EcalClusterTools::e2x5Top( *it, ebRecHits, topology ) << std::endl; - std::cout << "e2x5Bottom............... " << EcalClusterTools::e2x5Bottom( *it, ebRecHits, topology ) << std::endl; - std::cout << "e2x5Max.................. " << EcalClusterTools::e2x5Max( *it, ebRecHits, topology ) << std::endl; - std::cout << "eMax..................... " << EcalClusterTools::eMax( *it, ebRecHits ) << std::endl; - std::cout << "e2nd..................... " << EcalClusterTools::e2nd( *it, ebRecHits ) << std::endl; - std::vector vEta = EcalClusterTools::energyBasketFractionEta( *it, ebRecHits ); - std::cout << "energyBasketFractionEta.."; - for (size_t i = 0; i < vEta.size(); ++i ) { - std::cout << " " << vEta[i]; - } - std::cout << std::endl; - std::vector vPhi = EcalClusterTools::energyBasketFractionPhi( *it, ebRecHits ); - std::cout << "energyBasketFractionPhi.."; - for (size_t i = 0; i < vPhi.size(); ++i ) { - std::cout << " " << vPhi[i]; - } - std::cout << std::endl; - std::vector vLat = EcalClusterTools::lat( *it, ebRecHits, geometry ); - std::cout << "lat...................... " << vLat[0] << " " << vLat[1] << " " << vLat[2] << std::endl; - std::vector vCov = EcalClusterTools::covariances( *it, ebRecHits, topology, geometry ); - std::cout << "covariances.............. " << vCov[0] << " " << vCov[1] << " " << vCov[2] << std::endl; - std::vector vLocCov = EcalClusterTools::localCovariances( *it, ebRecHits, topology ); - std::cout << "local covariances........ " << vLocCov[0] << " " << vLocCov[1] << " " << vLocCov[2] << std::endl; - std::cout << "zernike20................ " << EcalClusterTools::zernike20( *it, ebRecHits, geometry ) << std::endl; - std::cout << "zernike42................ " << EcalClusterTools::zernike42( *it, ebRecHits, geometry ) << std::endl; - } - - std::cout << "========== ENDCAPS ==========" << std::endl; - for (reco::BasicClusterCollection::const_iterator it = eeClusters->begin(); it != eeClusters->end(); ++it ) { - std::cout << "----- new cluster -----" << std::endl; - std::cout << "----------------- size: " << (*it).size() << " energy: " << (*it).energy() << std::endl; - - std::cout << "e1x3..................... " << EcalClusterTools::e1x3( *it, eeRecHits, topology ) << std::endl; - std::cout << "e3x1..................... " << EcalClusterTools::e3x1( *it, eeRecHits, topology ) << std::endl; - std::cout << "e1x5..................... " << EcalClusterTools::e1x5( *it, eeRecHits, topology ) << std::endl; - //std::cout << "e5x1..................... " << EcalClusterTools::e5x1( *it, eeRecHits, topology ) << std::endl; - std::cout << "e2x2..................... " << EcalClusterTools::e2x2( *it, eeRecHits, topology ) << std::endl; - std::cout << "e3x3..................... " << EcalClusterTools::e3x3( *it, eeRecHits, topology ) << std::endl; - std::cout << "e4x4..................... " << EcalClusterTools::e4x4( *it, eeRecHits, topology ) << std::endl; - std::cout << "e5x5..................... " << EcalClusterTools::e5x5( *it, eeRecHits, topology ) << std::endl; - std::cout << "e2x5Right................ " << EcalClusterTools::e2x5Right( *it, eeRecHits, topology ) << std::endl; - std::cout << "e2x5Left................. " << EcalClusterTools::e2x5Left( *it, eeRecHits, topology ) << std::endl; - std::cout << "e2x5Top.................. " << EcalClusterTools::e2x5Top( *it, eeRecHits, topology ) << std::endl; - std::cout << "e2x5Bottom............... " << EcalClusterTools::e2x5Bottom( *it, eeRecHits, topology ) << std::endl; - std::cout << "eMax..................... " << EcalClusterTools::eMax( *it, eeRecHits ) << std::endl; - std::cout << "e2nd..................... " << EcalClusterTools::e2nd( *it, eeRecHits ) << std::endl; - std::vector vLat = EcalClusterTools::lat( *it, eeRecHits, geometry ); - std::cout << "lat...................... " << vLat[0] << " " << vLat[1] << " " << vLat[2] << std::endl; - std::vector vCov = EcalClusterTools::covariances( *it, eeRecHits, topology, geometry ); - std::cout << "covariances.............. " << vCov[0] << " " << vCov[1] << " " << vCov[2] << std::endl; - std::vector vLocCov = EcalClusterTools::localCovariances( *it, eeRecHits, topology ); - std::cout << "local covariances........ " << vLocCov[0] << " " << vLocCov[1] << " " << vLocCov[2] << std::endl; - std::cout << "zernike20................ " << EcalClusterTools::zernike20( *it, eeRecHits, geometry ) << std::endl; - std::cout << "zernike42................ " << EcalClusterTools::zernike42( *it, eeRecHits, geometry ) << std::endl; - } + edm::Handle< EcalRecHitCollection > pEBRecHits; + ev.getByToken( barrelRecHitToken_, pEBRecHits ); + const EcalRecHitCollection *ebRecHits = pEBRecHits.product(); + + edm::Handle< EcalRecHitCollection > pEERecHits; + ev.getByToken( endcapRecHitToken_, pEERecHits ); + const EcalRecHitCollection *eeRecHits = pEERecHits.product(); + + edm::Handle< reco::BasicClusterCollection > pEBClusters; + ev.getByToken( barrelClusterToken_, pEBClusters ); + const reco::BasicClusterCollection *ebClusters = pEBClusters.product(); + + edm::Handle< reco::BasicClusterCollection > pEEClusters; + ev.getByToken( endcapClusterToken_, pEEClusters ); + const reco::BasicClusterCollection *eeClusters = pEEClusters.product(); + + edm::ESHandle pGeometry; + es.get().get(pGeometry); + const CaloGeometry *geometry = pGeometry.product(); + + edm::ESHandle pTopology; + es.get().get(pTopology); + const CaloTopology *topology = pTopology.product(); + + std::cout << "========== BARREL ==========" << std::endl; + for(auto const& clus : *ebClusters) { + DetId maxId = ClusterTools::getMaximum(clus, eeRecHits).first; + + std::cout << "----- new cluster -----" << std::endl; + std::cout << "----------------- size: " << clus.size() << " energy: " << clus.energy() << std::endl; + + std::cout << "e1x3..................... " << ClusterTools::e1x3( clus, ebRecHits, topology ) << std::endl; + std::cout << "e3x1..................... " << ClusterTools::e3x1( clus, ebRecHits, topology ) << std::endl; + std::cout << "e1x5..................... " << ClusterTools::e1x5( clus, ebRecHits, topology ) << std::endl; + std::cout << "e5x1..................... " << ClusterTools::e5x1( clus, ebRecHits, topology ) << std::endl; + std::cout << "e2x2..................... " << ClusterTools::e2x2( clus, ebRecHits, topology ) << std::endl; + std::cout << "e3x3..................... " << ClusterTools::e3x3( clus, ebRecHits, topology ) << std::endl; + std::cout << "e4x4..................... " << ClusterTools::e4x4( clus, ebRecHits, topology ) << std::endl; + std::cout << "e5x5..................... " << ClusterTools::e5x5( clus, ebRecHits, topology ) << std::endl; + std::cout << "n5x5..................... " << ClusterTools::n5x5( clus, eeRecHits, topology ) << std::endl; + std::cout << "e2x5Right................ " << ClusterTools::e2x5Right( clus, ebRecHits, topology ) << std::endl; + std::cout << "e2x5Left................. " << ClusterTools::e2x5Left( clus, ebRecHits, topology ) << std::endl; + std::cout << "e2x5Top.................. " << ClusterTools::e2x5Top( clus, ebRecHits, topology ) << std::endl; + std::cout << "e2x5Bottom............... " << ClusterTools::e2x5Bottom( clus, ebRecHits, topology ) << std::endl; + std::cout << "e2x5Max.................. " << ClusterTools::e2x5Max( clus, ebRecHits, topology ) << std::endl; + std::cout << "eMax..................... " << ClusterTools::eMax( clus, ebRecHits ) << std::endl; + std::cout << "e2nd..................... " << ClusterTools::e2nd( clus, ebRecHits ) << std::endl; + std::vector vEta = ClusterTools::energyBasketFractionEta( clus, ebRecHits ); + std::cout << "energyBasketFractionEta.."; + for (auto const& eta : vEta) std::cout << " " << eta; + std::cout << std::endl; + std::vector vPhi = ClusterTools::energyBasketFractionPhi( clus, ebRecHits ); + std::cout << "energyBasketFractionPhi.."; + for (auto const& phi : vPhi) std::cout << " " << phi; + std::cout << std::endl; + std::vector vLat = ClusterTools::lat( clus, ebRecHits, geometry ); + std::cout << "lat...................... " << vLat[0] << " " << vLat[1] << " " << vLat[2] << std::endl; + std::vector vCov = ClusterTools::covariances( clus, ebRecHits, topology, geometry ); + std::cout << "covariances.............. " << vCov[0] << " " << vCov[1] << " " << vCov[2] << std::endl; + std::vector vLocCov = ClusterTools::localCovariances( clus, ebRecHits, topology ); + std::cout << "local covariances........ " << vLocCov[0] << " " << vLocCov[1] << " " << vLocCov[2] << std::endl; + std::cout << "zernike20................ " << ClusterTools::zernike20( clus, ebRecHits, geometry ) << std::endl; + std::cout << "zernike42................ " << ClusterTools::zernike42( clus, ebRecHits, geometry ) << std::endl; + std::cout << "nrSaturatedCrysIn5x5..... " << ClusterTools::nrSaturatedCrysIn5x5( maxId, ebRecHits, topology) << std::endl; + } + + std::cout << "========== ENDCAPS ==========" << std::endl; + for(auto const& clus : *eeClusters) { + DetId maxId = ClusterTools::getMaximum(clus, eeRecHits).first; + + std::cout << "----- new cluster -----" << std::endl; + std::cout << "----------------- size: " << clus.size() << " energy: " << clus.energy() << std::endl; + + std::cout << "e1x3..................... " << ClusterTools::e1x3( clus, eeRecHits, topology ) << std::endl; + std::cout << "e3x1..................... " << ClusterTools::e3x1( clus, eeRecHits, topology ) << std::endl; + std::cout << "e1x5..................... " << ClusterTools::e1x5( clus, eeRecHits, topology ) << std::endl; + std::cout << "e5x1..................... " << ClusterTools::e5x1( clus, eeRecHits, topology ) << std::endl; + std::cout << "e2x2..................... " << ClusterTools::e2x2( clus, eeRecHits, topology ) << std::endl; + std::cout << "e3x3..................... " << ClusterTools::e3x3( clus, eeRecHits, topology ) << std::endl; + std::cout << "e4x4..................... " << ClusterTools::e4x4( clus, eeRecHits, topology ) << std::endl; + std::cout << "e5x5..................... " << ClusterTools::e5x5( clus, eeRecHits, topology ) << std::endl; + std::cout << "n5x5..................... " << ClusterTools::n5x5( clus, eeRecHits, topology ) << std::endl; + std::cout << "e2x5Right................ " << ClusterTools::e2x5Right( clus, eeRecHits, topology ) << std::endl; + std::cout << "e2x5Left................. " << ClusterTools::e2x5Left( clus, eeRecHits, topology ) << std::endl; + std::cout << "e2x5Top.................. " << ClusterTools::e2x5Top( clus, eeRecHits, topology ) << std::endl; + std::cout << "e2x5Bottom............... " << ClusterTools::e2x5Bottom( clus, eeRecHits, topology ) << std::endl; + std::cout << "eMax..................... " << ClusterTools::eMax( clus, eeRecHits ) << std::endl; + std::cout << "e2nd..................... " << ClusterTools::e2nd( clus, eeRecHits ) << std::endl; + std::vector vLat = ClusterTools::lat( clus, eeRecHits, geometry ); + std::cout << "lat...................... " << vLat[0] << " " << vLat[1] << " " << vLat[2] << std::endl; + std::vector vCov = ClusterTools::covariances( clus, eeRecHits, topology, geometry ); + std::cout << "covariances.............. " << vCov[0] << " " << vCov[1] << " " << vCov[2] << std::endl; + std::vector vLocCov = ClusterTools::localCovariances( clus, eeRecHits, topology ); + std::cout << "local covariances........ " << vLocCov[0] << " " << vLocCov[1] << " " << vLocCov[2] << std::endl; + std::cout << "zernike20................ " << ClusterTools::zernike20( clus, eeRecHits, geometry ) << std::endl; + std::cout << "zernike42................ " << ClusterTools::zernike42( clus, eeRecHits, geometry ) << std::endl; + std::cout << "nrSaturatedCrysIn5x5..... " << ClusterTools::nrSaturatedCrysIn5x5( maxId, eeRecHits, topology) << std::endl; + } } //define this as a plug-in diff --git a/RecoEcal/EgammaCoreTools/test/testEcalClusterTools.py b/RecoEcal/EgammaCoreTools/test/testEcalClusterTools.py index 31636aba825f7..b3b101a41e6da 100644 --- a/RecoEcal/EgammaCoreTools/test/testEcalClusterTools.py +++ b/RecoEcal/EgammaCoreTools/test/testEcalClusterTools.py @@ -1,27 +1,26 @@ -from FWCore.ParameterSet.Config import * +import FWCore.ParameterSet.Config as cms +from Configuration.AlCa.GlobalTag import GlobalTag -process = Process("test") -process.extend(include("FWCore/MessageLogger/data/MessageLogger.cfi")) -#process.MessageLogger.cerr.FwkReport.reportEvery = 50 +process = cms.Process("test") -process.extend(include("RecoEcal/EgammaClusterProducers/data/geometryForClustering.cff")) +process.load("Configuration.StandardSequences.GeometryDB_cff") +process.load("FWCore.MessageService.MessageLogger_cfi") +process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff") -input_files = vstring() -#input_files.append( "/store/relval/2008/4/17/RelVal-RelValTTbar-1208465820/0000/0ABDA540-EE0C-DD11-BA9F-000423D94990.root" ) -input_files.append( "file:/data/ferriff/ClusterMulti5x5/CMSSW_2_1_X_2008-05-14-0200/src/reco.root" ) +input_files = cms.vstring("/store/data/Run2018A/EGamma/AOD/17Sep2018-v2/100000/01EB9686-9A6F-BF48-903A-02F7D9AEB9B9.root") -process.source = Source("PoolSource", - fileNames = untracked( input_files ) -) +process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:run2_data', '') + +process.source = cms.Source("PoolSource", fileNames = cms.untracked( input_files ) ) -process.maxEvents = untracked.PSet( input = untracked.int32( 10 ) ) +process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32( 10 ) ) -process.testEcalClusterTools = EDAnalyzer("testEcalClusterTools", - reducedBarrelRecHitCollection = InputTag("reducedEcalRecHitsEB"), - reducedEndcapRecHitCollection = InputTag("reducedEcalRecHitsEE"), - barrelClusterCollection = InputTag("hybridSuperClusters"), - endcapClusterCollection = InputTag("fixedMatrixBasicClusters:fixedMatrixEndcapBasicClusters") +process.testEcalClusterTools = cms.EDAnalyzer("testEcalClusterTools", + barrelRecHitCollection = cms.InputTag("reducedEcalRecHitsEB"), + endcapRecHitCollection = cms.InputTag("reducedEcalRecHitsEE"), + barrelClusterCollection = cms.InputTag("hybridSuperClusters:hybridBarrelBasicClusters"), + endcapClusterCollection = cms.InputTag("multi5x5SuperClusters:multi5x5EndcapBasicClusters") ) -process.p1 = Path( process.testEcalClusterTools ) +process.p1 = cms.Path( process.testEcalClusterTools ) diff --git a/RecoEgamma/ElectronIdentification/plugins/ElectronMVANtuplizer.cc b/RecoEgamma/ElectronIdentification/plugins/ElectronMVANtuplizer.cc index 0816bde6e85ed..8b5c9df9e1979 100644 --- a/RecoEgamma/ElectronIdentification/plugins/ElectronMVANtuplizer.cc +++ b/RecoEgamma/ElectronIdentification/plugins/ElectronMVANtuplizer.cc @@ -25,16 +25,12 @@ #include "FWCore/Utilities/interface/InputTag.h" #include "FWCore/ServiceRegistry/interface/Service.h" #include "FWCore/Framework/interface/MakerMacros.h" - #include "CommonTools/UtilAlgos/interface/TFileService.h" - #include "DataFormats/EgammaCandidates/interface/GsfElectron.h" #include "DataFormats/PatCandidates/interface/Electron.h" - #include "RecoEgamma/EgammaTools/interface/MVAVariableManager.h" #include "RecoEgamma/EgammaTools/interface/MultiToken.h" - - +#include "RecoEcal/EgammaCoreTools/interface/EcalClusterLazyTools.h" #include "SimDataFormats/PileupSummaryInfo/interface/PileupSummaryInfo.h" #include "DataFormats/VertexReco/interface/Vertex.h" #include "DataFormats/VertexReco/interface/VertexFwd.h" @@ -47,20 +43,12 @@ // class declaration // -// If the analyzer does not use TFileService, please remove -// the template argument to the base class so the class inherits -// from edm::one::EDAnalyzer<> -// This will improve performance in multithreaded jobs. -// - class ElectronMVANtuplizer : public edm::one::EDAnalyzer { public: explicit ElectronMVANtuplizer(const edm::ParameterSet&); - ~ElectronMVANtuplizer() override; static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); - private: void analyze(const edm::Event&, const edm::EventSetup&) override; @@ -75,7 +63,9 @@ class ElectronMVANtuplizer : public edm::one::EDAnalyzer energyMatrix_; // gap variables bool eleIsEB_; @@ -123,6 +114,8 @@ class ElectronMVANtuplizer : public edm::one::EDAnalyzer> vertices_; const MultiTokenT> pileup_; const MultiTokenT> genParticles_; + const MultiTokenT ebRecHits_; + const MultiTokenT eeRecHits_; // to hold ID decisions and categories std::vector mvaPasses_; @@ -139,6 +132,8 @@ class ElectronMVANtuplizer : public edm::one::EDAnalyzer vars_; + const bool doEnergyMatrix_; + const int energyMatrixSize_; }; // @@ -152,10 +147,6 @@ enum ElectronMatchType { TRUE_NON_PROMPT_ELECTRON, }; // The last does not include tau parents -// -// static data member definitions -// - // // constructors and destructor // @@ -163,19 +154,21 @@ ElectronMVANtuplizer::ElectronMVANtuplizer(const edm::ParameterSet& iConfig) : isMC_ (iConfig.getParameter("isMC")) , deltaR_ (iConfig.getParameter("deltaR")) , ptThreshold_ (iConfig.getParameter("ptThreshold")) - , eleMapTags_ (iConfig.getUntrackedParameter>("eleMVAs")) - , eleMapBranchNames_ (iConfig.getUntrackedParameter>("eleMVALabels")) + , eleMapTags_ (iConfig.getParameter>("eleMVAs")) + , eleMapBranchNames_ (iConfig.getParameter>("eleMVALabels")) , nEleMaps_ (eleMapBranchNames_.size()) - , valMapTags_ (iConfig.getUntrackedParameter>("eleMVAValMaps")) - , valMapBranchNames_ (iConfig.getUntrackedParameter>("eleMVAValMapLabels")) + , valMapTags_ (iConfig.getParameter>("eleMVAValMaps")) + , valMapBranchNames_ (iConfig.getParameter>("eleMVAValMapLabels")) , nValMaps_ (valMapBranchNames_.size()) - , mvaCatTags_ (iConfig.getUntrackedParameter>("eleMVACats")) - , mvaCatBranchNames_ (iConfig.getUntrackedParameter>("eleMVACatLabels")) + , mvaCatTags_ (iConfig.getParameter>("eleMVACats")) + , mvaCatBranchNames_ (iConfig.getParameter>("eleMVACatLabels")) , nCats_ (mvaCatBranchNames_.size()) , src_ (consumesCollector(), iConfig, "src" , "srcMiniAOD") , vertices_ (src_, consumesCollector(), iConfig, "vertices" , "verticesMiniAOD") , pileup_ (src_, consumesCollector(), iConfig, "pileup" , "pileupMiniAOD") , genParticles_ (src_, consumesCollector(), iConfig, "genParticles", "genParticlesMiniAOD") + , ebRecHits_ (src_, consumesCollector(), iConfig, "ebReducedRecHitCollection", "ebReducedRecHitCollectionMiniAOD") + , eeRecHits_ (src_, consumesCollector(), iConfig, "eeReducedRecHitCollection", "eeReducedRecHitCollectionMiniAOD") , mvaPasses_ (nEleMaps_) , mvaValues_ (nValMaps_) , mvaCats_ (nCats_) @@ -183,6 +176,8 @@ ElectronMVANtuplizer::ElectronMVANtuplizer(const edm::ParameterSet& iConfig) , mvaVarMngr_ (iConfig.getParameter("variableDefinition")) , nVars_ (mvaVarMngr_.getNVars()) , vars_ (nVars_) + , doEnergyMatrix_ (iConfig.getParameter("doEnergyMatrix")) + , energyMatrixSize_ (iConfig.getParameter("energyMatrixSize")) { // eleMaps for (auto const& tag : eleMapTags_) { @@ -211,13 +206,11 @@ ElectronMVANtuplizer::ElectronMVANtuplizer(const edm::ParameterSet& iConfig) tree_->Branch("ele_q",&eleQ_); tree_->Branch("ele_3q",&ele3Q_); - if (isMC_) { - tree_->Branch("matchedToGenEle", &matchedToGenEle_); - } + if (doEnergyMatrix_) tree_->Branch("energyMatrix",&energyMatrix_); - for (int i = 0; i < nVars_; ++i) { - tree_->Branch(mvaVarMngr_.getName(i).c_str(), &vars_[i]); - } + if (isMC_) tree_->Branch("matchedToGenEle", &matchedToGenEle_); + + for (int i = 0; i < nVars_; ++i) tree_->Branch(mvaVarMngr_.getName(i).c_str(), &vars_[i]); tree_->Branch("ele_isEB",&eleIsEB_); tree_->Branch("ele_isEE",&eleIsEE_); @@ -244,19 +237,6 @@ ElectronMVANtuplizer::ElectronMVANtuplizer(const edm::ParameterSet& iConfig) } -ElectronMVANtuplizer::~ElectronMVANtuplizer() -{ - - // do anything here that needs to be done at desctruction time - // (e.g. close files, deallocate resources etc.) - -} - - -// -// member functions -// - // ------------ method called for each event ------------ void ElectronMVANtuplizer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) @@ -270,6 +250,14 @@ ElectronMVANtuplizer::analyze(const edm::Event& iEvent, const edm::EventSetup& i auto src = src_.getValidHandle(iEvent); auto vertices = vertices_.getValidHandle(iEvent); + // initialize cluster tools + std::unique_ptr lazyTools; + if(doEnergyMatrix_) { + // Configure Lazy Tools, which will compute 5x5 quantities + lazyTools = std::make_unique( + iEvent, iSetup, ebRecHits_.get(iEvent), eeRecHits_.get(iEvent)); + } + // Get MC only Handles, which are allowed to be non-valid auto genParticles = genParticles_.getHandle(iEvent); auto pileup = pileup_.getHandle(iEvent); @@ -310,13 +298,18 @@ ElectronMVANtuplizer::analyze(const edm::Event& iEvent, const edm::EventSetup& i eleIndex_ = src->size(); for(auto const& ele : src->ptrs()) { - eleQ_ = ele->charge(); - ele3Q_ = ele->chargeInfo().isGsfCtfScPixConsistent; + if (ele->pt() < ptThreshold_) continue; - if (ele->pt() < ptThreshold_) { - continue; + // Fill the energy matrix around the seed + if(doEnergyMatrix_) { + const auto& seed = *(ele->superCluster()->seed()); + energyMatrix_ = lazyTools->energyMatrix(seed, energyMatrixSize_); } + // Fill various tree variable + eleQ_ = ele->charge(); + ele3Q_ = ele->chargeInfo().isGsfCtfScPixConsistent; + for (int iVar = 0; iVar < nVars_; ++iVar) { std::vector extraVariables = variableHelper_.getAuxVariables(ele, iEvent); vars_[iVar] = mvaVarMngr_.getValue(iVar, *ele, extraVariables); @@ -338,18 +331,9 @@ ElectronMVANtuplizer::analyze(const edm::Event& iEvent, const edm::EventSetup& i // // Look up and save the ID decisions // - for (size_t k = 0; k < nEleMaps_; ++k) { - mvaPasses_[k] = static_cast((*decisions[k])[ele]); - } - - for (size_t k = 0; k < nValMaps_; ++k) { - mvaValues_[k] = (*values[k])[ele]; - } - - for (size_t k = 0; k < nCats_; ++k) { - mvaCats_[k] = (*mvaCats[k])[ele]; - } - + for (size_t k = 0; k < nEleMaps_; ++k) mvaPasses_[k] = static_cast((*decisions[k])[ele]); + for (size_t k = 0; k < nValMaps_; ++k) mvaValues_[k] = (*values[k])[ele]; + for (size_t k = 0; k < nCats_ ; ++k) mvaCats_[k] = (*mvaCats[k])[ele]; tree_->Fill(); } @@ -401,16 +385,22 @@ ElectronMVANtuplizer::fillDescriptions(edm::ConfigurationDescriptions& descripti desc.add("verticesMiniAOD", edm::InputTag("offlineSlimmedPrimaryVertices")); desc.add("pileupMiniAOD", edm::InputTag("slimmedAddPileupInfo")); desc.add("genParticlesMiniAOD", edm::InputTag("prunedGenParticles")); + desc.add("ebReducedRecHitCollection", edm::InputTag("reducedEcalRecHitsEB")); + desc.add("eeReducedRecHitCollection", edm::InputTag("reducedEcalRecHitsEE")); + desc.add("ebReducedRecHitCollectionMiniAOD", edm::InputTag("reducedEgamma","reducedEBRecHits")); + desc.add("eeReducedRecHitCollectionMiniAOD", edm::InputTag("reducedEgamma","reducedEERecHits")); desc.add("variableDefinition"); + desc.add("doEnergyMatrix", false); + desc.add("energyMatrixSize", 2)->setComment("extension of crystals in each direction away from the seed"); desc.add("isMC", true); desc.add("deltaR", 0.1); desc.add("ptThreshold", 5.0); - desc.addUntracked>("eleMVAs", {}); - desc.addUntracked>("eleMVALabels", {}); - desc.addUntracked>("eleMVAValMaps", {}); - desc.addUntracked>("eleMVAValMapLabels", {}); - desc.addUntracked>("eleMVACats", {}); - desc.addUntracked>("eleMVACatLabels", {}); + desc.add>("eleMVAs", {}); + desc.add>("eleMVALabels", {}); + desc.add>("eleMVAValMaps", {}); + desc.add>("eleMVAValMapLabels", {}); + desc.add>("eleMVACats", {}); + desc.add>("eleMVACatLabels", {}); descriptions.addDefault(desc); } diff --git a/RecoEgamma/ElectronIdentification/test/testElectronMVA_cfg.py b/RecoEgamma/ElectronIdentification/test/testElectronMVA_cfg.py index d552be07c746b..665bdbe491977 100644 --- a/RecoEgamma/ElectronIdentification/test/testElectronMVA_cfg.py +++ b/RecoEgamma/ElectronIdentification/test/testElectronMVA_cfg.py @@ -4,6 +4,7 @@ process = cms.Process("ElectronMVANtuplizer") +process.load("Configuration.StandardSequences.GeometryDB_cff") process.load("FWCore.MessageService.MessageLogger_cfi") process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff") @@ -50,7 +51,7 @@ process.ntuplizer = cms.EDAnalyzer('ElectronMVANtuplizer', # - eleMVAs = cms.untracked.vstring( + eleMVAs = cms.vstring( "egmGsfElectronIDs:mvaEleID-Spring16-GeneralPurpose-V1-wp80", "egmGsfElectronIDs:mvaEleID-Spring16-GeneralPurpose-V1-wp90", "egmGsfElectronIDs:mvaEleID-Spring16-HZZ-V1-wpLoose", @@ -68,7 +69,7 @@ "egmGsfElectronIDs:mvaEleID-Fall17-iso-V1-wp80", "egmGsfElectronIDs:mvaEleID-Fall17-iso-V1-wpLoose", ), - eleMVALabels = cms.untracked.vstring( + eleMVALabels = cms.vstring( "Spring16GPV1wp80", "Spring16GPV1wp90", "Spring16HZZV1wpLoose", @@ -86,7 +87,7 @@ "Fall17isoV1wp80", "Fall17isoV1wpLoose", ), - eleMVAValMaps = cms.untracked.vstring( + eleMVAValMaps = cms.vstring( "electronMVAValueMapProducer:ElectronMVAEstimatorRun2Spring16GeneralPurposeV1Values", "electronMVAValueMapProducer:ElectronMVAEstimatorRun2Spring16GeneralPurposeV1RawValues", "electronMVAValueMapProducer:ElectronMVAEstimatorRun2Spring16HZZV1Values", @@ -98,7 +99,7 @@ "electronMVAValueMapProducer:ElectronMVAEstimatorRun2Fall17IsoV1Values", "electronMVAValueMapProducer:ElectronMVAEstimatorRun2Fall17NoIsoV1Values", ), - eleMVAValMapLabels = cms.untracked.vstring( + eleMVAValMapLabels = cms.vstring( "Spring16GPV1Vals", "Spring16GPV1RawVals", "Spring16HZZV1Vals", @@ -110,19 +111,44 @@ "Fall17IsoV1Vals", "Fall17NoIsoV1Vals", ), - eleMVACats = cms.untracked.vstring( + eleMVACats = cms.vstring( "electronMVAValueMapProducer:ElectronMVAEstimatorRun2Fall17NoIsoV1Categories", ), - eleMVACatLabels = cms.untracked.vstring( + eleMVACatLabels = cms.vstring( "EleMVACats", ), # variableDefinition = cms.string(mvaVariablesFile), ptThreshold = cms.double(5.0), + # + doEnergyMatrix = cms.bool(False), # disabled by default due to large size + energyMatrixSize = cms.int32(2) # corresponding to 5x5 ) +""" +The energy matrix is for ecal driven electrons the n x n of raw +rec-hit energies around the seed crystal. + +The size of the energy matrix is controlled with the parameter +"energyMatrixSize", which controlls the extension of crystals in each +direction away from the seed, in other words n = 2 * energyMatrixSize + 1. + +The energy matrix gets saved as a vector but you can easily unroll it +to a two dimensional numpy array later, for example like that: + +>>> import uproot +>>> import numpy as np +>>> import matplotlib.pyplot as plt + +>>> tree = uproot.open("electron_ntuple.root")["ntuplizer/tree"] +>>> n = 5 + +>>> for a in tree.array("ele_energyMatrix"): +>>> a = a.reshape((n,n)) +>>> plt.imshow(np.log10(a)) +>>> plt.colorbar() +>>> plt.show() +""" -process.TFileService = cms.Service("TFileService", - fileName = cms.string( outputFile ) - ) +process.TFileService = cms.Service("TFileService", fileName = cms.string(outputFile)) process.p = cms.Path(process.egmGsfElectronIDSequence * process.ntuplizer) diff --git a/RecoEgamma/PhotonIdentification/plugins/PhotonIDValueMapProducer.cc b/RecoEgamma/PhotonIdentification/plugins/PhotonIDValueMapProducer.cc index cb15aa1fc8d41..3e4c447b56ff1 100644 --- a/RecoEgamma/PhotonIdentification/plugins/PhotonIDValueMapProducer.cc +++ b/RecoEgamma/PhotonIdentification/plugins/PhotonIDValueMapProducer.cc @@ -194,15 +194,10 @@ void PhotonIDValueMapProducer::produce(edm::StreamID, edm::Event& iEvent, const } // Configure Lazy Tools, which will compute 5x5 quantities - std::unique_ptr lazyToolnoZS; - - if (usesES_) { - lazyToolnoZS = std::make_unique( - iEvent, iSetup, ebRecHits_.get(iEvent), eeRecHits_.get(iEvent), esRecHits_.get(iEvent)); - } else { - lazyToolnoZS = std::make_unique( - iEvent, iSetup, ebRecHits_.get(iEvent), eeRecHits_.get(iEvent)); - } + auto lazyToolnoZS = usesES_ ? noZS::EcalClusterLazyTools(iEvent, iSetup, + ebRecHits_.get(iEvent), eeRecHits_.get(iEvent), esRecHits_.get(iEvent)) + : noZS::EcalClusterLazyTools(iEvent, iSetup, + ebRecHits_.get(iEvent), eeRecHits_.get(iEvent)); // Get PV if (vertices->empty()) @@ -217,20 +212,20 @@ void PhotonIDValueMapProducer::produce(edm::StreamID, edm::Event& iEvent, const // // Compute full 5x5 quantities // - const auto& theseed = *(iPho->superCluster()->seed()); + const auto& seed = *(iPho->superCluster()->seed()); // For full5x5_sigmaIetaIeta, for 720 we use: lazy tools for AOD, // and userFloats or lazy tools for miniAOD. From some point in 72X and on, one can // retrieve the full5x5 directly from the object with ->full5x5_sigmaIetaIeta() // for both formats. - std::vector vCov = lazyToolnoZS->localCovariances(theseed); + std::vector vCov = lazyToolnoZS.localCovariances(seed); vars[0].push_back(edm::isNotFinite(vCov[0]) ? 0. : sqrt(vCov[0])); vars[1].push_back(vCov[1]); - vars[2].push_back(lazyToolnoZS->e1x3(theseed)); - vars[3].push_back(lazyToolnoZS->e2x2(theseed)); - vars[4].push_back(lazyToolnoZS->e2x5Max(theseed)); - vars[5].push_back(lazyToolnoZS->e5x5(theseed)); - vars[6].push_back(lazyToolnoZS->eseffsirir(*(iPho->superCluster()))); + vars[2].push_back(lazyToolnoZS.e1x3(seed)); + vars[3].push_back(lazyToolnoZS.e2x2(seed)); + vars[4].push_back(lazyToolnoZS.e2x5Max(seed)); + vars[5].push_back(lazyToolnoZS.e5x5(seed)); + vars[6].push_back(lazyToolnoZS.eseffsirir(*(iPho->superCluster()))); vars[7].push_back(vars[2].back() / vars[5].back()); vars[8].push_back(vars[3].back() / vars[5].back()); vars[9].push_back(vars[4].back() / vars[5].back()); diff --git a/RecoEgamma/PhotonIdentification/plugins/PhotonMVANtuplizer.cc b/RecoEgamma/PhotonIdentification/plugins/PhotonMVANtuplizer.cc index 542c87ef65dd6..28a84109842df 100644 --- a/RecoEgamma/PhotonIdentification/plugins/PhotonMVANtuplizer.cc +++ b/RecoEgamma/PhotonIdentification/plugins/PhotonMVANtuplizer.cc @@ -17,28 +17,22 @@ // -// user include files #include "FWCore/Framework/interface/Frameworkfwd.h" #include "FWCore/Framework/interface/one/EDAnalyzer.h" - #include "FWCore/Framework/interface/Event.h" - #include "FWCore/ParameterSet/interface/ParameterSet.h" #include "FWCore/Utilities/interface/InputTag.h" - #include "FWCore/ServiceRegistry/interface/Service.h" #include "FWCore/Framework/interface/MakerMacros.h" #include "CommonTools/UtilAlgos/interface/TFileService.h" - #include "DataFormats/EgammaCandidates/interface/Photon.h" #include "DataFormats/PatCandidates/interface/Photon.h" - #include "RecoEgamma/EgammaTools/interface/MVAVariableManager.h" #include "RecoEgamma/EgammaTools/interface/MultiToken.h" - #include "SimDataFormats/PileupSummaryInfo/interface/PileupSummaryInfo.h" #include "DataFormats/VertexReco/interface/Vertex.h" #include "DataFormats/VertexReco/interface/VertexFwd.h" +#include "RecoEcal/EgammaCoreTools/interface/EcalClusterLazyTools.h" #include #include @@ -64,11 +58,14 @@ class PhotonMVANtuplizer : public edm::one::EDAnalyzer energyMatrix_; // photon genMatch variable int matchedToGenPh_; @@ -101,6 +98,8 @@ class PhotonMVANtuplizer : public edm::one::EDAnalyzer> vertices_; const MultiTokenT> pileup_; const MultiTokenT> genParticles_; + const MultiTokenT ebRecHits_; + const MultiTokenT eeRecHits_; // to hold ID decisions and categories std::vector mvaPasses_; @@ -115,6 +114,9 @@ class PhotonMVANtuplizer : public edm::one::EDAnalyzer vars_; + + const bool doEnergyMatrix_; + const int energyMatrixSize_; }; enum PhotonMatchType { @@ -155,14 +157,14 @@ namespace { // constructor PhotonMVANtuplizer::PhotonMVANtuplizer(const edm::ParameterSet& iConfig) - : phoMapTags_ (iConfig.getUntrackedParameter>("phoMVAs")) - , phoMapBranchNames_ (iConfig.getUntrackedParameter>("phoMVALabels")) + : phoMapTags_ (iConfig.getParameter>("phoMVAs")) + , phoMapBranchNames_ (iConfig.getParameter>("phoMVALabels")) , nPhoMaps_ (phoMapBranchNames_.size()) - , valMapTags_ (iConfig.getUntrackedParameter>("phoMVAValMaps")) - , valMapBranchNames_ (iConfig.getUntrackedParameter>("phoMVAValMapLabels")) + , valMapTags_ (iConfig.getParameter>("phoMVAValMaps")) + , valMapBranchNames_ (iConfig.getParameter>("phoMVAValMapLabels")) , nValMaps_ (valMapBranchNames_.size()) - , mvaCatTags_ (iConfig.getUntrackedParameter>("phoMVACats")) - , mvaCatBranchNames_ (iConfig.getUntrackedParameter>("phoMVACatLabels")) + , mvaCatTags_ (iConfig.getParameter>("phoMVACats")) + , mvaCatBranchNames_ (iConfig.getParameter>("phoMVACatLabels")) , nCats_ (mvaCatBranchNames_.size()) , isMC_ (iConfig.getParameter("isMC")) , ptThreshold_ (iConfig.getParameter("ptThreshold")) @@ -171,6 +173,8 @@ PhotonMVANtuplizer::PhotonMVANtuplizer(const edm::ParameterSet& iConfig) , vertices_ (src_, consumesCollector(), iConfig, "vertices", "verticesMiniAOD") , pileup_ (src_, consumesCollector(), iConfig, "pileup" , "pileupMiniAOD") , genParticles_ (src_, consumesCollector(), iConfig, "genParticles", "genParticlesMiniAOD") + , ebRecHits_ (src_, consumesCollector(), iConfig, "ebReducedRecHitCollection", "ebReducedRecHitCollectionMiniAOD") + , eeRecHits_ (src_, consumesCollector(), iConfig, "eeReducedRecHitCollection", "eeReducedRecHitCollectionMiniAOD") , mvaPasses_ (nPhoMaps_) , mvaValues_ (nValMaps_) , mvaCats_ (nCats_) @@ -178,6 +182,8 @@ PhotonMVANtuplizer::PhotonMVANtuplizer(const edm::ParameterSet& iConfig) , mvaVarMngr_ (iConfig.getParameter("variableDefinition")) , nVars_ (mvaVarMngr_.getNVars()) , vars_ (nVars_) + , doEnergyMatrix_ (iConfig.getParameter("doEnergyMatrix")) + , energyMatrixSize_ (iConfig.getParameter("energyMatrixSize")) { // phoMaps for (auto const& tag : phoMapTags_) { @@ -208,6 +214,8 @@ PhotonMVANtuplizer::PhotonMVANtuplizer(const edm::ParameterSet& iConfig) tree_->Branch("pT", &pT_); tree_->Branch("eta", &eta_); + if (doEnergyMatrix_) tree_->Branch("energyMatrix",&energyMatrix_); + for (int i = 0; i < nVars_; ++i) { tree_->Branch(mvaVarMngr_.getName(i).c_str(), &vars_[i]); } @@ -243,6 +251,14 @@ PhotonMVANtuplizer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSe vtxN_ = vertices->size(); + // initialize cluster tools + std::unique_ptr lazyTools; + if(doEnergyMatrix_) { + // Configure Lazy Tools, which will compute 5x5 quantities + lazyTools = std::make_unique( + iEvent, iSetup, ebRecHits_.get(iEvent), eeRecHits_.get(iEvent)); + } + // Fill with true number of pileup if(isMC_) { for(const auto& pu : *pileup) @@ -276,36 +292,31 @@ PhotonMVANtuplizer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSe for(auto const& pho : src->ptrs()) { - if (pho->pt() < ptThreshold_) { - continue; - } + if (pho->pt() < ptThreshold_) continue; + pT_ = pho->pt(); eta_ = pho->eta(); + // Fill the energy matrix around the seed + if(doEnergyMatrix_) { + const auto& seed = *(pho->superCluster()->seed()); + energyMatrix_ = lazyTools->energyMatrix(seed, energyMatrixSize_); + } + // variables from the text file for (int iVar = 0; iVar < nVars_; ++iVar) { std::vector extraVariables = variableHelper_.getAuxVariables(pho, iEvent); vars_[iVar] = mvaVarMngr_.getValue(iVar, *pho, extraVariables); } - if (isMC_) { - matchedToGenPh_ = matchToTruth( *pho, *genParticles, deltaR_); - } + if (isMC_) matchedToGenPh_ = matchToTruth( *pho, *genParticles, deltaR_); // // Look up and save the ID decisions // - for (size_t k = 0; k < nPhoMaps_; ++k) { - mvaPasses_[k] = static_cast((*decisions[k])[pho]); - } - - for (size_t k = 0; k < nValMaps_; ++k) { - mvaValues_[k] = (*values[k])[pho]; - } - - for (size_t k = 0; k < nCats_; ++k) { - mvaCats_[k] = (*mvaCats[k])[pho]; - } + for (size_t k = 0; k < nPhoMaps_; ++k) mvaPasses_[k] = static_cast((*decisions[k])[pho]); + for (size_t k = 0; k < nValMaps_; ++k) mvaValues_[k] = (*values[k])[pho]; + for (size_t k = 0; k < nCats_ ; ++k) mvaCats_[k] = (*mvaCats[k])[pho]; tree_->Fill(); } @@ -325,12 +336,18 @@ PhotonMVANtuplizer::fillDescriptions(edm::ConfigurationDescriptions& description desc.add("verticesMiniAOD", edm::InputTag("offlineSlimmedPrimaryVertices")); desc.add("pileupMiniAOD", edm::InputTag("slimmedAddPileupInfo")); desc.add("genParticlesMiniAOD", edm::InputTag("prunedGenParticles")); - desc.addUntracked>("phoMVAs", {}); - desc.addUntracked>("phoMVALabels", {}); - desc.addUntracked>("phoMVAValMaps", {}); - desc.addUntracked>("phoMVAValMapLabels", {}); - desc.addUntracked>("phoMVACats", {}); - desc.addUntracked>("phoMVACatLabels", {}); + desc.add("ebReducedRecHitCollection", edm::InputTag("reducedEcalRecHitsEB")); + desc.add("eeReducedRecHitCollection", edm::InputTag("reducedEcalRecHitsEE")); + desc.add("ebReducedRecHitCollectionMiniAOD", edm::InputTag("reducedEgamma","reducedEBRecHits")); + desc.add("eeReducedRecHitCollectionMiniAOD", edm::InputTag("reducedEgamma","reducedEERecHits")); + desc.add>("phoMVAs", {}); + desc.add>("phoMVALabels", {}); + desc.add>("phoMVAValMaps", {}); + desc.add>("phoMVAValMapLabels", {}); + desc.add>("phoMVACats", {}); + desc.add>("phoMVACatLabels", {}); + desc.add("doEnergyMatrix", false); + desc.add("energyMatrixSize", 2)->setComment("extension of crystals in each direction away from the seed"); desc.add("isMC", true); desc.add("ptThreshold", 15.0); desc.add("deltaR", 0.1); diff --git a/RecoEgamma/PhotonIdentification/test/testPhotonMVA_cfg.py b/RecoEgamma/PhotonIdentification/test/testPhotonMVA_cfg.py index dafe8e2ebd74d..4539215b8624b 100644 --- a/RecoEgamma/PhotonIdentification/test/testPhotonMVA_cfg.py +++ b/RecoEgamma/PhotonIdentification/test/testPhotonMVA_cfg.py @@ -48,33 +48,58 @@ setupAllVIDIdsInModule(process,idmod,setupVIDPhotonSelection) process.ntuplizer = cms.EDAnalyzer('PhotonMVANtuplizer', - phoMVAs = cms.untracked.vstring( + phoMVAs = cms.vstring( ), - phoMVALabels = cms.untracked.vstring( + phoMVALabels = cms.vstring( ), - phoMVAValMaps = cms.untracked.vstring( + phoMVAValMaps = cms.vstring( "photonMVAValueMapProducer:PhotonMVAEstimatorRun2Spring16NonTrigV1Values", "photonMVAValueMapProducer:PhotonMVAEstimatorRunIIFall17v1Values", "photonMVAValueMapProducer:PhotonMVAEstimatorRunIIFall17v1p1Values", "photonMVAValueMapProducer:PhotonMVAEstimatorRunIIFall17v2Values", ), - phoMVAValMapLabels = cms.untracked.vstring( + phoMVAValMapLabels = cms.vstring( "Spring16NonTrigV1", "Fall17v1", "Fall17v1p1", "Fall17v2", ), - phoMVACats = cms.untracked.vstring( + phoMVACats = cms.vstring( "photonMVAValueMapProducer:PhotonMVAEstimatorRunIIFall17v1Categories", ), - phoMVACatLabels = cms.untracked.vstring( + phoMVACatLabels = cms.vstring( "PhoMVACats", ), variableDefinition = cms.string(mvaVariablesFile), + # + doEnergyMatrix = cms.bool(False), # disabled by default due to large size + energyMatrixSize = cms.int32(2) # corresponding to 5x5 ) +""" +The energy matrix is the n x n of raw rec-hit energies around the seed +crystal. -process.TFileService = cms.Service("TFileService", - fileName = cms.string( outputFile ) - ) +The size of the energy matrix is controlled with the parameter +"energyMatrixSize", which controlls the extension of crystals in each +direction away from the seed, in other words n = 2 * energyMatrixSize + 1. + +The energy matrix gets saved as a vector but you can easily unroll it +to a two dimensional numpy array later, for example like that: + +>>> import uproot +>>> import numpy as np +>>> import matplotlib.pyplot as plt + +>>> tree = uproot.open("photon_ntuple.root")["ntuplizer/tree"] +>>> n = 5 + +>>> for a in tree.array("ele_energyMatrix"): +>>> a = a.reshape((n,n)) +>>> plt.imshow(np.log10(a)) +>>> plt.colorbar() +>>> plt.show() +""" + +process.TFileService = cms.Service("TFileService", fileName = cms.string(outputFile)) process.p = cms.Path(process.egmPhotonIDSequence * process.ntuplizer)