Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:08:11

0001 /*
0002  * \file GlobalTrackingGeometryTest.cc
0003  *
0004  *  \author M. Sani
0005  */
0006 
0007 #include <memory>
0008 
0009 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0010 #include "FWCore/Framework/interface/EventSetup.h"
0011 #include "FWCore/Framework/interface/ESHandle.h"
0012 #include "FWCore/Framework/interface/MakerMacros.h"
0013 
0014 #include "Geometry/CommonDetUnit/interface/GlobalTrackingGeometry.h"
0015 #include "Geometry/Records/interface/GlobalTrackingGeometryRecord.h"
0016 #include "Geometry/CSCGeometry/interface/CSCGeometry.h"
0017 #include "Geometry/DTGeometry/interface/DTGeometry.h"
0018 #include "Geometry/RPCGeometry/interface/RPCGeometry.h"
0019 #include "Geometry/GEMGeometry/interface/GEMGeometry.h"
0020 #include "Geometry/MTDGeometryBuilder/interface/MTDGeometry.h"
0021 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0022 
0023 #include "DataFormats/DetId/interface/DetId.h"
0024 
0025 #include <string>
0026 #include <cmath>
0027 #include <iomanip>
0028 #include <vector>
0029 
0030 class GlobalTrackingGeometryTest : public edm::one::EDAnalyzer<> {
0031 public:
0032   explicit GlobalTrackingGeometryTest(const edm::ParameterSet&);
0033   ~GlobalTrackingGeometryTest() override;
0034 
0035   void beginJob() override {}
0036   void analyze(edm::Event const& iEvent, edm::EventSetup const&) override;
0037   void endJob() override {}
0038 
0039 private:
0040   void analyzeCSC(const GlobalTrackingGeometry* geo, const CSCGeometry* cscGeometry);
0041   void analyzeDT(const GlobalTrackingGeometry* geo, const DTGeometry* dtGeometry);
0042   void analyzeRPC(const GlobalTrackingGeometry* geo, const RPCGeometry* rpcGeometry);
0043   void analyzeGEM(const GlobalTrackingGeometry* geo, const GEMGeometry* gemGeometry);
0044   void analyzeMTD(const GlobalTrackingGeometry* geo, const MTDGeometry* mtdGeometry);
0045   void analyzeTracker(const GlobalTrackingGeometry* geo, const TrackerGeometry* tkGeometry);
0046   const std::string& myName() { return my_name; }
0047   std::string my_name;
0048   edm::ESGetToken<GlobalTrackingGeometry, GlobalTrackingGeometryRecord> geometryToken_;
0049 };
0050 
0051 GlobalTrackingGeometryTest::GlobalTrackingGeometryTest(const edm::ParameterSet& /*iConfig*/)
0052     : my_name("GlobalTrackingGeometryTest"),
0053       geometryToken_{esConsumes<GlobalTrackingGeometry, GlobalTrackingGeometryRecord>(edm::ESInputTag{})} {}
0054 
0055 GlobalTrackingGeometryTest::~GlobalTrackingGeometryTest() {}
0056 
0057 void GlobalTrackingGeometryTest::analyzeCSC(const GlobalTrackingGeometry* geo, const CSCGeometry* cscGeometry) {
0058   for (auto& detUnit : cscGeometry->detUnits()) {
0059     const DetId detId(detUnit->geographicalId());
0060 
0061     // Check idToDetUnit
0062     const GeomDetUnit* gdu(geo->idToDetUnit(detId));
0063     assert(gdu == detUnit);
0064   }
0065   std::cout << "CSC detUnit: GlobalTrackingGeometry succesfully tested." << std::endl;
0066 
0067   for (auto& det : cscGeometry->dets()) {
0068     const DetId detId(det->geographicalId());
0069 
0070     // Check idToDet
0071     const GeomDet* gd(geo->idToDet(detId));
0072     assert(gd == det);
0073   }
0074   std::cout << "CSC det: GlobalTrackingGeometry succesfully tested." << std::endl;
0075 }
0076 
0077 void GlobalTrackingGeometryTest::analyzeDT(const GlobalTrackingGeometry* geo, const DTGeometry* dtGeometry) {
0078   for (auto& detUnit : dtGeometry->detUnits()) {
0079     const DetId detId(detUnit->geographicalId());
0080 
0081     // Check idToDetUnit
0082     const GeomDetUnit* gdu(geo->idToDetUnit(detId));
0083     assert(gdu == detUnit);
0084   }
0085   std::cout << "DT detUnit: GlobalTrackingGeometry succesfully tested." << std::endl;
0086 
0087   for (auto& det : dtGeometry->dets()) {
0088     const DetId detId(det->geographicalId());
0089 
0090     // Check idToDet
0091     const GeomDet* gd(geo->idToDet(detId));
0092     assert(gd == det);
0093   }
0094   std::cout << "DT det: GlobalTrackingGeometry succesfully tested." << std::endl;
0095 }
0096 
0097 void GlobalTrackingGeometryTest::analyzeRPC(const GlobalTrackingGeometry* geo, const RPCGeometry* rpcGeometry) {
0098   for (auto& detUnit : rpcGeometry->detUnits()) {
0099     const DetId detId(detUnit->geographicalId());
0100 
0101     // Check idToDetUnit
0102     const GeomDetUnit* gdu(geo->idToDetUnit(detId));
0103     assert(gdu == detUnit);
0104   }
0105   std::cout << "RPC detUnit: GlobalTrackingGeometry succesfully tested." << std::endl;
0106 
0107   for (auto& det : rpcGeometry->dets()) {
0108     const DetId detId(det->geographicalId());
0109 
0110     // Check idToDet
0111     const GeomDet* gd(geo->idToDet(detId));
0112     assert(gd == det);
0113   }
0114   std::cout << "RPC det: GlobalTrackingGeometry succesfully tested." << std::endl;
0115 }
0116 
0117 void GlobalTrackingGeometryTest::analyzeGEM(const GlobalTrackingGeometry* geo, const GEMGeometry* gemGeometry) {
0118   for (auto& detUnit : gemGeometry->detUnits()) {
0119     const DetId detId(detUnit->geographicalId());
0120 
0121     // Check idToDetUnit
0122     const GeomDetUnit* gdu(geo->idToDetUnit(detId));
0123     assert(gdu == detUnit);
0124   }
0125   std::cout << "GEM detUnit: GlobalTrackingGeometry succesfully tested." << std::endl;
0126 
0127   for (auto& det : gemGeometry->dets()) {
0128     const DetId detId(det->geographicalId());
0129 
0130     // Check idToDet
0131     const GeomDet* gd(geo->idToDet(detId));
0132     assert(gd == det);
0133   }
0134   std::cout << "GEM det: GlobalTrackingGeometry succesfully tested." << std::endl;
0135 }
0136 
0137 void GlobalTrackingGeometryTest::analyzeMTD(const GlobalTrackingGeometry* geo, const MTDGeometry* mtdGeometry) {
0138   for (auto& detUnit : mtdGeometry->detUnits()) {
0139     const DetId detId(detUnit->geographicalId());
0140 
0141     // Check idToDetUnit
0142     const GeomDetUnit* gdu(geo->idToDetUnit(detId));
0143     assert(gdu == detUnit);
0144   }
0145   std::cout << "MTD detUnit: GlobalTrackingGeometry succesfully tested." << std::endl;
0146 
0147   for (auto& det : mtdGeometry->dets()) {
0148     const DetId detId(det->geographicalId());
0149 
0150     // Check idToDet
0151     const GeomDet* gd(geo->idToDet(detId));
0152     assert(gd == det);
0153   }
0154   std::cout << "MTD det: GlobalTrackingGeometry succesfully tested." << std::endl;
0155 }
0156 
0157 void GlobalTrackingGeometryTest::analyzeTracker(const GlobalTrackingGeometry* geo, const TrackerGeometry* tkGeometry) {
0158   for (auto& detUnit : tkGeometry->detUnits()) {
0159     const DetId detId(detUnit->geographicalId());
0160 
0161     // Check idToDetUnit
0162     const GeomDetUnit* gdu(geo->idToDetUnit(detId));
0163     assert(gdu == detUnit);
0164   }
0165   std::cout << "Tracker detUnit: GlobalTrackingGeometry succesfully tested." << std::endl;
0166 
0167   for (auto& det : tkGeometry->dets()) {
0168     const DetId detId(det->geographicalId());
0169 
0170     // Check idToDet
0171     const GeomDet* gd(geo->idToDet(detId));
0172     assert(gd == det);
0173   }
0174   std::cout << "Tracker det: GlobalTrackingGeometry succesfully tested." << std::endl;
0175 }
0176 
0177 void GlobalTrackingGeometryTest::analyze(const edm::Event& /*iEvent*/, const edm::EventSetup& iSetup) {
0178   std::cout << myName() << ": Analyzer..." << std::endl;
0179 
0180   const auto& geo = iSetup.getData(geometryToken_);
0181 
0182   DetId detId1(DetId::Tracker, 0);
0183   const TrackerGeometry* trackerGeometry = nullptr;
0184   std::cout << "Pointer to Tracker Geometry: ";
0185   try {
0186     trackerGeometry = (const TrackerGeometry*)geo.slaveGeometry(detId1);
0187     std::cout << trackerGeometry << std::endl;
0188   } catch (...) {
0189     std::cout << "N/A" << std::endl;
0190   }
0191 
0192   DetId detId6(DetId::Forward, 1);
0193   const MTDGeometry* mtdGeometry = nullptr;
0194   std::cout << "Pointer to MTD Geometry: ";
0195   try {
0196     mtdGeometry = (const MTDGeometry*)geo.slaveGeometry(detId6);
0197     std::cout << mtdGeometry << std::endl;
0198   } catch (...) {
0199     std::cout << "N/A" << std::endl;
0200   }
0201 
0202   DetId detId2(DetId::Muon, 1);
0203   const DTGeometry* dtGeometry = nullptr;
0204   std::cout << "Pointer to DT Geometry: ";
0205   try {
0206     dtGeometry = (const DTGeometry*)geo.slaveGeometry(detId2);
0207     std::cout << dtGeometry << std::endl;
0208   } catch (...) {
0209     std::cout << "N/A" << std::endl;
0210   }
0211 
0212   DetId detId3(DetId::Muon, 2);
0213   const CSCGeometry* cscGeometry = nullptr;
0214   std::cout << "Pointer to CSC Geometry: ";
0215   try {
0216     cscGeometry = (const CSCGeometry*)geo.slaveGeometry(detId3);
0217     std::cout << cscGeometry << std::endl;
0218   } catch (...) {
0219     std::cout << "N/A" << std::endl;
0220   }
0221 
0222   DetId detId4(DetId::Muon, 3);
0223   const RPCGeometry* rpcGeometry = nullptr;
0224   std::cout << "Pointer to RPC Geometry: ";
0225   try {
0226     rpcGeometry = (const RPCGeometry*)geo.slaveGeometry(detId4);
0227     std::cout << rpcGeometry << std::endl;
0228   } catch (...) {
0229     std::cout << "N/A" << std::endl;
0230   }
0231 
0232   DetId detId5(DetId::Muon, 4);
0233   const GEMGeometry* gemGeometry = nullptr;
0234   std::cout << "Pointer to GEM Geometry: ";
0235   try {
0236     gemGeometry = (const GEMGeometry*)geo.slaveGeometry(detId5);
0237     std::cout << gemGeometry << std::endl;
0238   } catch (...) {
0239     std::cout << "N/A" << std::endl;
0240   }
0241 
0242   if (cscGeometry)
0243     analyzeCSC(&geo, cscGeometry);
0244   if (dtGeometry)
0245     analyzeDT(&geo, dtGeometry);
0246   if (rpcGeometry)
0247     analyzeRPC(&geo, rpcGeometry);
0248   if (gemGeometry)
0249     analyzeGEM(&geo, gemGeometry);
0250   if (mtdGeometry)
0251     analyzeMTD(&geo, mtdGeometry);
0252   if (trackerGeometry)
0253     analyzeTracker(&geo, trackerGeometry);
0254 }
0255 
0256 //define this as a plug-in
0257 DEFINE_FWK_MODULE(GlobalTrackingGeometryTest);