Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:59:25

0001 // -*- C++ -*-
0002 //
0003 // Package:    CaloPropagationTest
0004 // Class:      CaloPropagationTest
0005 //
0006 /**\class CaloPropagationTest CaloPropagationTest.cc test/CaloPropagationTest.cc
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 
0014 // system include files
0015 #include <memory>
0016 #include <iostream>
0017 #include <fstream>
0018 
0019 // user include files
0020 #include "FWCore/Framework/interface/Frameworkfwd.h"
0021 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0022 #include "FWCore/Framework/interface/Event.h"
0023 #include "FWCore/Framework/interface/EventSetup.h"
0024 #include "FWCore/Framework/interface/MakerMacros.h"
0025 
0026 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0027 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0028 
0029 #include "Calibration/IsolatedParticles/interface/CaloPropagateTrack.h"
0030 #include "DataFormats/CaloTowers/interface/CaloTowerDetId.h"
0031 #include "DataFormats/EcalDetId/interface/EBDetId.h"
0032 #include "DataFormats/EcalDetId/interface/EEDetId.h"
0033 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
0034 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
0035 #include "DataFormats/HcalDetId/interface/HcalSubdetector.h"
0036 
0037 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
0038 #include "Geometry/CaloTopology/interface/CaloTowerConstituentsMap.h"
0039 #include "Geometry/Records/interface/CaloGeometryRecord.h"
0040 #include "Geometry/HcalTowerAlgo/interface/HcalGeometry.h"
0041 #include "MagneticField/Engine/interface/MagneticField.h"
0042 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
0043 
0044 class CaloPropagationTest : public edm::one::EDAnalyzer<> {
0045 public:
0046   explicit CaloPropagationTest(const edm::ParameterSet&);
0047   ~CaloPropagationTest() override;
0048 
0049   void beginJob() override {}
0050   void analyze(edm::Event const& iEvent, edm::EventSetup const&) override;
0051   void endJob() override {}
0052 
0053 private:
0054   const edm::ESGetToken<CaloGeometry, CaloGeometryRecord> tok_geom_;
0055   const edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> tok_magField_;
0056   const edm::ESGetToken<CaloTowerConstituentsMap, CaloGeometryRecord> tok_ctmap_;
0057 };
0058 
0059 CaloPropagationTest::CaloPropagationTest(const edm::ParameterSet&)
0060     : tok_geom_(esConsumes<CaloGeometry, CaloGeometryRecord>()),
0061       tok_magField_(esConsumes<MagneticField, IdealMagneticFieldRecord>()),
0062       tok_ctmap_(esConsumes<CaloTowerConstituentsMap, CaloGeometryRecord>()) {}
0063 
0064 CaloPropagationTest::~CaloPropagationTest() {}
0065 
0066 // ------------ method called to produce the data  ------------
0067 void CaloPropagationTest::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0068   const CaloGeometry* geo = &iSetup.getData(tok_geom_);
0069   const HcalGeometry* gHB = (const HcalGeometry*)(geo->getSubdetectorGeometry(DetId::Hcal, HcalBarrel));
0070   const MagneticField* bField = &iSetup.getData(tok_magField_);
0071   const CaloTowerConstituentsMap* ctmap = &iSetup.getData(tok_ctmap_);
0072 
0073   const std::vector<DetId>& ids = gHB->getValidDetIds(DetId::Hcal, 0);
0074   bool debug(false);
0075   for (const auto& id : ids) {
0076     if (id.det() == DetId::Hcal && ((id.subdetId() == HcalBarrel) || (id.subdetId() == HcalEndcap))) {
0077       const HcalDetId hid(id);
0078       std::pair<DetId, bool> info = spr::propagateIdECAL(hid, geo, bField, debug);
0079       if (!info.second) {
0080         edm::LogVerbatim("IsoTrack") << "No valid Ecal Id found for " << hid;
0081       } else {
0082         CaloTowerDetId tower = ctmap->towerOf(id);
0083         std::vector<DetId> idts = ctmap->constituentsOf(tower);
0084         std::string found("not found");
0085         for (auto idt : idts) {
0086           if (info.first == idt) {
0087             found = "found";
0088             break;
0089           }
0090         }
0091         if ((info.first).subdetId() == EcalBarrel) {
0092           edm::LogVerbatim("IsoTrack") << "Find " << EBDetId(info.first) << " as partner of " << hid
0093                                        << " and mtaching with tower " << found;
0094         } else {
0095           edm::LogVerbatim("IsoTrack") << "Find " << EEDetId(info.first) << " as partner of " << hid
0096                                        << " and mtaching with tower " << found;
0097         }
0098       }
0099     }
0100   }
0101 }
0102 
0103 //define this as a plug-in
0104 DEFINE_FWK_MODULE(CaloPropagationTest);