Skip to content

Commit

Permalink
CaloRectangle finds subtopology itself
Browse files Browse the repository at this point in the history
  • Loading branch information
guitargeek committed Jan 11, 2019
1 parent 886fd37 commit 061cf33
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 112 deletions.
30 changes: 17 additions & 13 deletions RecoCaloTools/Navigation/interface/CaloRectangle.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
#define RecoCaloTools_Navigation_CaloRectangle_H

#include "Geometry/CaloTopology/interface/CaloSubdetectorTopology.h"
#include "Geometry/CaloTopology/interface/CaloTopology.h"

template<class T, class Topology=CaloSubdetectorTopology>
T offsetBy(T start, Topology const& topo, int dX, int dY)
template<class T>
T offsetBy(T start, CaloSubdetectorTopology const& topo, int dX, int dY)
{
for(int x = 0; x < std::abs(dX) && start != T(0); x++) {
// east is eta in barrel
Expand All @@ -24,8 +25,8 @@ struct CaloRectangle {
const int iyMin;
const int iyMax;

template<class T, class Topology=CaloSubdetectorTopology>
auto operator()(T home, Topology const& topology);
template<class T>
auto operator()(T home, CaloTopology const& topology);

};

Expand All @@ -37,7 +38,7 @@ inline auto makeCaloRectangle(int sizeX, int sizeY) {
return CaloRectangle{-sizeX, sizeX, -sizeY, sizeY};
}

template<class T, class Topology=CaloSubdetectorTopology>
template<class T>
class CaloRectangleRange {

public:
Expand All @@ -46,7 +47,7 @@ class CaloRectangleRange {

public:

Iterator(T const& home, int ix, int iy, CaloRectangle const rectangle, Topology const& topology)
Iterator(T const& home, int ix, int iy, CaloRectangle const rectangle, CaloSubdetectorTopology const& topology)
: home_(home)
, rectangle_(rectangle)
, topology_(topology)
Expand Down Expand Up @@ -75,15 +76,18 @@ class CaloRectangleRange {
const T home_;

const CaloRectangle rectangle_;
Topology const& topology_;
CaloSubdetectorTopology const& topology_;

int ix_;
int iy_;
};

public:
CaloRectangleRange(CaloRectangle rectangle, T home, Topology const& topology)
: home_(home), rectangle_(rectangle), topology_(topology) {}
CaloRectangleRange(CaloRectangle rectangle, T home, CaloTopology const& topology)
: home_(home)
, rectangle_(rectangle)
, topology_(*topology.getSubdetectorTopology(home))
{}

auto begin() {
return Iterator(home_, rectangle_.ixMin, rectangle_.iyMin, rectangle_, topology_);
Expand All @@ -95,12 +99,12 @@ class CaloRectangleRange {
private:
const T home_;
const CaloRectangle rectangle_;
Topology const& topology_;
CaloSubdetectorTopology const& topology_;
};

template<class T, class Topology=CaloSubdetectorTopology>
auto CaloRectangle::operator()(T home, Topology const& topology) {
return CaloRectangleRange<T, Topology>(*this, home, topology);
template<class T>
auto CaloRectangle::operator()(T home, CaloTopology const& topology) {
return CaloRectangleRange<T>(*this, home, topology);
}

#endif
6 changes: 2 additions & 4 deletions RecoEcal/EgammaClusterProducers/src/EcalDigiSelector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ void EcalDigiSelector::produce(edm::Event& evt, const edm::EventSetup& es)
std::pair<DetId, float> EDetty =
EcalClusterTools::getMaximum(*bc,rechits);
//get the 3x3 array centered on maximum detid.
std::vector<DetId> detvec =
EcalClusterTools::matrixDetId(topology,EDetty.first, -1, 1, -1, 1);
std::vector<DetId> detvec = EcalClusterTools::matrixDetId(topology,EDetty.first, 1);
//Loop over the 3x3
for (int ik = 0;ik<int(detvec.size());++ik)
saveTheseDetIds.push_back(detvec[ik]);
Expand Down Expand Up @@ -198,8 +197,7 @@ void EcalDigiSelector::produce(edm::Event& evt, const edm::EventSetup& es)
//Get the maximum detid
std::pair<DetId, float> EDetty = EcalClusterTools::getMaximum(*bc,rechits);
//get the 3x3 array centered on maximum detid.
std::vector<DetId> detvec =
EcalClusterTools::matrixDetId(topology,EDetty.first, -1, 1, -1, 1);
std::vector<DetId> detvec = EcalClusterTools::matrixDetId(topology,EDetty.first, 1);
//Loop over the 3x3
for (int ik = 0;ik<int(detvec.size());++ik)
saveTheseDetIds.insert(detvec[ik]);
Expand Down
56 changes: 29 additions & 27 deletions RecoEcal/EgammaCoreTools/interface/EcalClusterLazyTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,12 @@
#include "RecoLocalCalo/EcalRecAlgos/interface/EcalSeverityLevelAlgo.h"
#include "RecoEcal/EgammaCoreTools/interface/EcalClusterTools.h"

#include <iomanip>


class CaloTopology;
class CaloGeometry;
class CaloSubdetectorTopology;

class EcalClusterLazyToolsBase
{
class EcalClusterLazyToolsBase {
public:
EcalClusterLazyToolsBase( const edm::Event &ev, const edm::EventSetup &es, edm::EDGetTokenT<EcalRecHitCollection> token1, edm::EDGetTokenT<EcalRecHitCollection> token2);
EcalClusterLazyToolsBase( const edm::Event &ev, const edm::EventSetup &es, edm::EDGetTokenT<EcalRecHitCollection> token1, edm::EDGetTokenT<EcalRecHitCollection> token2, edm::EDGetTokenT<EcalRecHitCollection> token3);
Expand All @@ -59,14 +56,14 @@ class EcalClusterLazyToolsBase
float eseffsixix( const reco::SuperCluster &cluster );
float eseffsiyiy( const reco::SuperCluster &cluster );

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<EcalLaserDbService>& getLaserHandle(void){return laser;};
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<EcalLaserDbService> const& getLaserHandle() const { return laser; }

protected:
const EcalRecHitCollection * getEcalRecHitCollection( const reco::BasicCluster &cluster ) const;
EcalRecHitCollection const* getEcalRecHitCollection( const reco::BasicCluster &cluster ) const;

const CaloGeometry *geometry_;
const CaloTopology *topology_;
Expand Down Expand Up @@ -108,28 +105,32 @@ class EcalClusterLazyToolsT : public EcalClusterLazyToolsBase {
edm::EDGetTokenT<EcalRecHitCollection> token3)
: EcalClusterLazyToolsBase(ev,es,token1,token2,token3) {}

// Get the rec hit energies in a 5x5 matrix around the seed.
// Get the rec hit energies in a rectangle matrix around the seed.
std::vector<float> getEnergies(reco::BasicCluster const& cluster, CaloRectangle rectangle) const {

auto recHits = getEcalRecHitCollection(cluster);
DetId maxId = ClusterTools::getMaximum(cluster, recHits).first;

std::vector<float> energies;
for (auto const& detId : rectangle(maxId, *topology_->getSubdetectorTopology(maxId))) {
for (auto const& detId : rectangle(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
//
// 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 )
Expand Down Expand Up @@ -203,11 +204,14 @@ class EcalClusterLazyToolsT : public EcalClusterLazyToolsBase {
{ 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
// 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<float> localCovariances(const reco::BasicCluster &cluster, float w0 = 4.7)
{ return ClusterTools::localCovariances( cluster, getEcalRecHitCollection(cluster), topology_, w0 ); }
std::vector<float> scLocalCovariances(const reco::SuperCluster &cluster, float w0 = 4.7)
Expand All @@ -220,9 +224,7 @@ class EcalClusterLazyToolsT : public EcalClusterLazyToolsBase {
}; // class EcalClusterLazyToolsT


namespace noZS {
typedef EcalClusterLazyToolsT<noZS::EcalClusterTools> EcalClusterLazyTools;
}
namespace noZS { typedef EcalClusterLazyToolsT<noZS::EcalClusterTools> EcalClusterLazyTools; }
typedef EcalClusterLazyToolsT<::EcalClusterTools> EcalClusterLazyTools;


Expand Down
Loading

0 comments on commit 061cf33

Please sign in to comment.