Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-15 23:34:17

0001 // -*- C++ -*-
0002 //
0003 // Package:    testEcalClusterTools
0004 // Class:      testEcalClusterTools
0005 //
0006 /**\class testEcalClusterTools testEcalClusterTools.cc
0007 
0008 Description: <one line class summary>
0009 
0010 Implementation:
0011 <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  "Federico Ferri federi
0015 //         Created:  Mon Apr  7 14:11:00 CEST 2008
0016 //
0017 //
0018 
0019 #include "FWCore/Framework/interface/Frameworkfwd.h"
0020 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0021 #include "FWCore/Framework/interface/Event.h"
0022 #include "FWCore/Framework/interface/MakerMacros.h"
0023 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0024 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
0025 #include "DataFormats/EgammaReco/interface/BasicClusterFwd.h"
0026 #include "RecoEcal/EgammaCoreTools/interface/EcalClusterTools.h"
0027 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
0028 #include "Geometry/CaloTopology/interface/CaloTopology.h"
0029 #include "Geometry/Records/interface/CaloGeometryRecord.h"
0030 #include "Geometry/Records/interface/CaloTopologyRecord.h"
0031 #include "FWCore/Utilities/interface/EDGetToken.h"
0032 
0033 #include <memory>
0034 
0035 class testEcalClusterTools : public edm::one::EDAnalyzer<> {
0036 public:
0037   explicit testEcalClusterTools(const edm::ParameterSet&);
0038   ~testEcalClusterTools() override = default;
0039 
0040   void analyze(const edm::Event&, const edm::EventSetup&) override;
0041 
0042 private:
0043   using ClusterTools = noZS::EcalClusterTools;  // alternatively just EcalClusterTools
0044 
0045   const edm::EDGetToken barrelClusterToken_;
0046   const edm::EDGetToken endcapClusterToken_;
0047   const edm::EDGetToken barrelRecHitToken_;
0048   const edm::EDGetToken endcapRecHitToken_;
0049   const edm::ESGetToken<CaloGeometry, CaloGeometryRecord> geometryToken_;
0050   const edm::ESGetToken<CaloTopology, CaloTopologyRecord> topologyToken_;
0051 };
0052 
0053 testEcalClusterTools::testEcalClusterTools(const edm::ParameterSet& ps)
0054     : barrelClusterToken_(
0055           consumes<reco::BasicClusterCollection>(ps.getParameter<edm::InputTag>("barrelClusterCollection"))),
0056       endcapClusterToken_(
0057           consumes<reco::BasicClusterCollection>(ps.getParameter<edm::InputTag>("endcapClusterCollection"))),
0058       barrelRecHitToken_(consumes<EcalRecHitCollection>(ps.getParameter<edm::InputTag>("barrelRecHitCollection"))),
0059       endcapRecHitToken_(consumes<EcalRecHitCollection>(ps.getParameter<edm::InputTag>("endcapRecHitCollection"))),
0060       geometryToken_(esConsumes()),
0061       topologyToken_(esConsumes()) {}
0062 
0063 void testEcalClusterTools::analyze(const edm::Event& ev, const edm::EventSetup& es) {
0064   edm::Handle<EcalRecHitCollection> pEBRecHits;
0065   ev.getByToken(barrelRecHitToken_, pEBRecHits);
0066   const EcalRecHitCollection* ebRecHits = pEBRecHits.product();
0067 
0068   edm::Handle<EcalRecHitCollection> pEERecHits;
0069   ev.getByToken(endcapRecHitToken_, pEERecHits);
0070   const EcalRecHitCollection* eeRecHits = pEERecHits.product();
0071 
0072   edm::Handle<reco::BasicClusterCollection> pEBClusters;
0073   ev.getByToken(barrelClusterToken_, pEBClusters);
0074   const reco::BasicClusterCollection* ebClusters = pEBClusters.product();
0075 
0076   edm::Handle<reco::BasicClusterCollection> pEEClusters;
0077   ev.getByToken(endcapClusterToken_, pEEClusters);
0078   const reco::BasicClusterCollection* eeClusters = pEEClusters.product();
0079 
0080   const auto* geometry = &es.getData(geometryToken_);
0081   const auto* topology = &es.getData(topologyToken_);
0082 
0083   std::cout << "========== BARREL ==========" << std::endl;
0084   for (auto const& clus : *ebClusters) {
0085     DetId maxId = ClusterTools::getMaximum(clus, eeRecHits).first;
0086 
0087     std::cout << "----- new cluster -----" << std::endl;
0088     std::cout << "----------------- size: " << clus.size() << " energy: " << clus.energy() << std::endl;
0089 
0090     std::cout << "e1x3..................... " << ClusterTools::e1x3(clus, ebRecHits, topology) << std::endl;
0091     std::cout << "e3x1..................... " << ClusterTools::e3x1(clus, ebRecHits, topology) << std::endl;
0092     std::cout << "e1x5..................... " << ClusterTools::e1x5(clus, ebRecHits, topology) << std::endl;
0093     std::cout << "e5x1..................... " << ClusterTools::e5x1(clus, ebRecHits, topology) << std::endl;
0094     std::cout << "e2x2..................... " << ClusterTools::e2x2(clus, ebRecHits, topology) << std::endl;
0095     std::cout << "e3x3..................... " << ClusterTools::e3x3(clus, ebRecHits, topology) << std::endl;
0096     std::cout << "e4x4..................... " << ClusterTools::e4x4(clus, ebRecHits, topology) << std::endl;
0097     std::cout << "e5x5..................... " << ClusterTools::e5x5(clus, ebRecHits, topology) << std::endl;
0098     std::cout << "n5x5..................... " << ClusterTools::n5x5(clus, eeRecHits, topology) << std::endl;
0099     std::cout << "e2x5Right................ " << ClusterTools::e2x5Right(clus, ebRecHits, topology) << std::endl;
0100     std::cout << "e2x5Left................. " << ClusterTools::e2x5Left(clus, ebRecHits, topology) << std::endl;
0101     std::cout << "e2x5Top.................. " << ClusterTools::e2x5Top(clus, ebRecHits, topology) << std::endl;
0102     std::cout << "e2x5Bottom............... " << ClusterTools::e2x5Bottom(clus, ebRecHits, topology) << std::endl;
0103     std::cout << "e2x5Max.................. " << ClusterTools::e2x5Max(clus, ebRecHits, topology) << std::endl;
0104     std::cout << "eMax..................... " << ClusterTools::eMax(clus, ebRecHits) << std::endl;
0105     std::cout << "e2nd..................... " << ClusterTools::e2nd(clus, ebRecHits) << std::endl;
0106     std::vector<float> vEta = ClusterTools::energyBasketFractionEta(clus, ebRecHits);
0107     std::cout << "energyBasketFractionEta..";
0108     for (auto const& eta : vEta)
0109       std::cout << " " << eta;
0110     std::cout << std::endl;
0111     std::vector<float> vPhi = ClusterTools::energyBasketFractionPhi(clus, ebRecHits);
0112     std::cout << "energyBasketFractionPhi..";
0113     for (auto const& phi : vPhi)
0114       std::cout << " " << phi;
0115     std::cout << std::endl;
0116     std::vector<float> vLat = ClusterTools::lat(clus, ebRecHits, geometry);
0117     std::cout << "lat...................... " << vLat[0] << " " << vLat[1] << " " << vLat[2] << std::endl;
0118     const auto& vCov = ClusterTools::covariances(clus, ebRecHits, topology, geometry);
0119     std::cout << "covariances.............. " << vCov[0] << " " << vCov[1] << " " << vCov[2] << std::endl;
0120     const auto& vLocCov = ClusterTools::localCovariances(clus, ebRecHits, topology);
0121     std::cout << "local covariances........ " << vLocCov[0] << " " << vLocCov[1] << " " << vLocCov[2] << std::endl;
0122     std::cout << "zernike20................ " << ClusterTools::zernike20(clus, ebRecHits, geometry) << std::endl;
0123     std::cout << "zernike42................ " << ClusterTools::zernike42(clus, ebRecHits, geometry) << std::endl;
0124     std::cout << "nrSaturatedCrysIn5x5..... " << ClusterTools::nrSaturatedCrysIn5x5(maxId, ebRecHits, topology)
0125               << std::endl;
0126   }
0127 
0128   std::cout << "========== ENDCAPS ==========" << std::endl;
0129   for (auto const& clus : *eeClusters) {
0130     DetId maxId = ClusterTools::getMaximum(clus, eeRecHits).first;
0131 
0132     std::cout << "----- new cluster -----" << std::endl;
0133     std::cout << "----------------- size: " << clus.size() << " energy: " << clus.energy() << std::endl;
0134 
0135     std::cout << "e1x3..................... " << ClusterTools::e1x3(clus, eeRecHits, topology) << std::endl;
0136     std::cout << "e3x1..................... " << ClusterTools::e3x1(clus, eeRecHits, topology) << std::endl;
0137     std::cout << "e1x5..................... " << ClusterTools::e1x5(clus, eeRecHits, topology) << std::endl;
0138     std::cout << "e5x1..................... " << ClusterTools::e5x1(clus, eeRecHits, topology) << std::endl;
0139     std::cout << "e2x2..................... " << ClusterTools::e2x2(clus, eeRecHits, topology) << std::endl;
0140     std::cout << "e3x3..................... " << ClusterTools::e3x3(clus, eeRecHits, topology) << std::endl;
0141     std::cout << "e4x4..................... " << ClusterTools::e4x4(clus, eeRecHits, topology) << std::endl;
0142     std::cout << "e5x5..................... " << ClusterTools::e5x5(clus, eeRecHits, topology) << std::endl;
0143     std::cout << "n5x5..................... " << ClusterTools::n5x5(clus, eeRecHits, topology) << std::endl;
0144     std::cout << "e2x5Right................ " << ClusterTools::e2x5Right(clus, eeRecHits, topology) << std::endl;
0145     std::cout << "e2x5Left................. " << ClusterTools::e2x5Left(clus, eeRecHits, topology) << std::endl;
0146     std::cout << "e2x5Top.................. " << ClusterTools::e2x5Top(clus, eeRecHits, topology) << std::endl;
0147     std::cout << "e2x5Bottom............... " << ClusterTools::e2x5Bottom(clus, eeRecHits, topology) << std::endl;
0148     std::cout << "eMax..................... " << ClusterTools::eMax(clus, eeRecHits) << std::endl;
0149     std::cout << "e2nd..................... " << ClusterTools::e2nd(clus, eeRecHits) << std::endl;
0150     std::vector<float> vLat = ClusterTools::lat(clus, eeRecHits, geometry);
0151     std::cout << "lat...................... " << vLat[0] << " " << vLat[1] << " " << vLat[2] << std::endl;
0152     const auto& vCov = ClusterTools::covariances(clus, eeRecHits, topology, geometry);
0153     std::cout << "covariances.............. " << vCov[0] << " " << vCov[1] << " " << vCov[2] << std::endl;
0154     const auto& vLocCov = ClusterTools::localCovariances(clus, eeRecHits, topology);
0155     std::cout << "local covariances........ " << vLocCov[0] << " " << vLocCov[1] << " " << vLocCov[2] << std::endl;
0156     std::cout << "zernike20................ " << ClusterTools::zernike20(clus, eeRecHits, geometry) << std::endl;
0157     std::cout << "zernike42................ " << ClusterTools::zernike42(clus, eeRecHits, geometry) << std::endl;
0158     std::cout << "nrSaturatedCrysIn5x5..... " << ClusterTools::nrSaturatedCrysIn5x5(maxId, eeRecHits, topology)
0159               << std::endl;
0160   }
0161 }
0162 
0163 //define this as a plug-in
0164 DEFINE_FWK_MODULE(testEcalClusterTools);