Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-05-05 02:47:37

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