Skip to content

Commit

Permalink
Use edm::get() and ClusterTools tests to one::EDAnalyzers
Browse files Browse the repository at this point in the history
  • Loading branch information
guitargeek committed Jan 14, 2019
1 parent 9848325 commit 634f84e
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 106 deletions.
33 changes: 8 additions & 25 deletions RecoEcal/EgammaCoreTools/src/EcalClusterLazyTools.cc
Expand Up @@ -22,39 +22,22 @@
#include "RecoLocalCalo/EcalRecAlgos/interface/EcalSeverityLevelAlgoRcd.h"
#include "RecoLocalCalo/EcalRecAlgos/interface/EcalSeverityLevelAlgo.h"

namespace {

template<class T, class R>
auto getFromEventSetup(edm::EventSetup const& eventSetup) {
edm::ESHandle<T> handle;
eventSetup.get<R>().get(handle);
return handle.product();
}

auto getRecHits(edm::Event const& event, edm::EDGetTokenT<EcalRecHitCollection> const& token) {
edm::Handle< EcalRecHitCollection > recHitsHandle;
event.getByToken( token, recHitsHandle );
return recHitsHandle.product();
}

};

EcalClusterLazyToolsBase::EcalClusterLazyToolsBase( const edm::Event &ev, const edm::EventSetup &es, edm::EDGetTokenT<EcalRecHitCollection> token1, edm::EDGetTokenT<EcalRecHitCollection> token2)
: geometry_(getFromEventSetup<CaloGeometry, CaloGeometryRecord>(es))
, topology_(getFromEventSetup<CaloTopology, CaloTopologyRecord>(es))
, ebRecHits_(getRecHits(ev, token1))
, eeRecHits_(getRecHits(ev, token2))
: geometry_(&edm::get<CaloGeometry,CaloGeometryRecord>(es))
, topology_(&edm::get<CaloTopology,CaloTopologyRecord>(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<EcalRecHitCollection> token1, edm::EDGetTokenT<EcalRecHitCollection> token2, edm::EDGetTokenT<EcalRecHitCollection> token3)
: geometry_(getFromEventSetup<CaloGeometry, CaloGeometryRecord>(es))
, topology_(getFromEventSetup<CaloTopology, CaloTopologyRecord>(es))
, ebRecHits_(getRecHits(ev, token1))
, eeRecHits_(getRecHits(ev, token2))
: geometry_(&edm::get<CaloGeometry,CaloGeometryRecord>(es))
, topology_(&edm::get<CaloTopology,CaloTopologyRecord>(es))
, ebRecHits_(&edm::get(ev, token1))
, eeRecHits_(&edm::get(ev, token2))
{
const CaloSubdetectorGeometry *geometryES = geometry_->getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
if (geometryES) {
Expand Down
141 changes: 65 additions & 76 deletions RecoEcal/EgammaCoreTools/test/testEcalClusterLazyTools.cc
Expand Up @@ -2,7 +2,7 @@
//
// Package: testEcalClusterLazyTools
// Class: testEcalClusterLazyTools
//
//
/**\class testEcalClusterLazyTools testEcalClusterLazyTools.cc
Description: <one line class summary>
Expand All @@ -17,48 +17,37 @@ Description: <one line class summary>
//


// system include files
#include <memory>

// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/global/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 <memory>


class testEcalClusterLazyTools : public edm::global::EDAnalyzer<> {
class testEcalClusterLazyTools : public edm::one::EDAnalyzer<> {
public:
explicit testEcalClusterLazyTools(const edm::ParameterSet&);

private:
virtual void analyze(edm::StreamID, const edm::Event&, const edm::EventSetup&) const override;
virtual void analyze(const edm::Event&, const edm::EventSetup&) override;

using LazyTools = noZS::EcalClusterLazyTools; // alternatively just EcalClusterLazyTools

const edm::EDGetTokenT<reco::BasicClusterCollection> barrelClusterToken_;
const edm::EDGetTokenT<reco::BasicClusterCollection> endcapClusterToken_;
const edm::EDGetTokenT<EcalRecHitCollection> barrelRecHitToken_;
const edm::EDGetTokenT<EcalRecHitCollection> endcapRecHitToken_;

};


Expand All @@ -71,89 +60,89 @@ testEcalClusterLazyTools::testEcalClusterLazyTools(const edm::ParameterSet& ps)
{}


void testEcalClusterLazyTools::analyze(edm::StreamID, const edm::Event& ev, const edm::EventSetup& es) const
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, barrelRecHitToken_, endcapRecHitToken_ );
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.e3x3( *it ) << std::endl;
std::cout << "e4x4..................... " << lazyTools.e4x4( *it ) << std::endl;
std::cout << "e5x5..................... " << lazyTools.e5x5( *it ) << std::endl;
std::cout << "n5x5..................... " << lazyTools.n5x5( *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<float> 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<float> 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<float> vPhi = lazyTools.energyBasketFractionPhi( *it );
std::vector<float> 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<float> vLat = lazyTools.lat( *it );
std::vector<float> vLat = lazyTools.lat( clus );
std::cout << "lat...................... " << vLat[0] << " " << vLat[1] << " " << vLat[2] << std::endl;
std::vector<float> vCov = lazyTools.covariances( *it );
std::cout << "covariances.............. " << vCov[0] << " " << vCov[1] << " " << vCov[2] << std::endl;
std::vector<float> vLocCov = lazyTools.localCovariances( *it );
std::vector<float> vCov = lazyTools.covariances( clus );
std::cout << "covariances.............. " << vCov[0] << " " << vCov[1] << " " << vCov[2] << std::endl;
std::vector<float> 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.e3x3( *it ) << std::endl;
std::cout << "e4x4..................... " << lazyTools.e4x4( *it ) << std::endl;
std::cout << "e5x5..................... " << lazyTools.e5x5( *it ) << std::endl;
std::cout << "n5x5..................... " << lazyTools.n5x5( *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<float> 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<float> vLat = lazyTools.lat( clus );
std::cout << "lat...................... " << vLat[0] << " " << vLat[1] << " " << vLat[2] << std::endl;
std::vector<float> vCov = lazyTools.covariances( *it );
std::cout << "covariances.............. " << vCov[0] << " " << vCov[1] << " " << vCov[2] << std::endl;
std::vector<float> vLocCov = lazyTools.localCovariances( *it );
std::vector<float> vCov = lazyTools.covariances( clus );
std::cout << "covariances.............. " << vCov[0] << " " << vCov[1] << " " << vCov[2] << std::endl;
std::vector<float> 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;
}
}

Expand Down
10 changes: 5 additions & 5 deletions RecoEcal/EgammaCoreTools/test/testEcalClusterTools.cc
Expand Up @@ -17,7 +17,7 @@ Description: <one line class summary>
//

#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/global/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"
Expand All @@ -33,14 +33,14 @@ Description: <one line class summary>

#include <memory>

class testEcalClusterTools : public edm::global::EDAnalyzer<> {
class testEcalClusterTools : public edm::one::EDAnalyzer<> {
public:
explicit testEcalClusterTools(const edm::ParameterSet&);

private:
virtual void analyze(edm::StreamID, const edm::Event&, const edm::EventSetup&) const override;
virtual void analyze(const edm::Event&, const edm::EventSetup&) override;

using ClusterTools = noZS::EcalClusterTools; // alternatively noZS::EcalClusterTools
using ClusterTools = noZS::EcalClusterTools; // alternatively just EcalClusterTools

const edm::EDGetToken barrelClusterToken_;
const edm::EDGetToken endcapClusterToken_;
Expand All @@ -59,7 +59,7 @@ testEcalClusterTools::testEcalClusterTools(const edm::ParameterSet& ps)



void testEcalClusterTools::analyze(edm::StreamID, const edm::Event& ev, const edm::EventSetup& es) const
void testEcalClusterTools::analyze(const edm::Event& ev, const edm::EventSetup& es)
{
edm::Handle< EcalRecHitCollection > pEBRecHits;
ev.getByToken( barrelRecHitToken_, pEBRecHits );
Expand Down

0 comments on commit 634f84e

Please sign in to comment.