Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-10-17 22:58:45

0001 #include <iostream>
0002 #include <sstream>
0003 #include <string>
0004 #include <vector>
0005 
0006 #include "FWCore/Framework/interface/Frameworkfwd.h"
0007 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0008 #include "FWCore/Framework/interface/Event.h"
0009 #include "FWCore/Framework/interface/EventSetup.h"
0010 #include "FWCore/Framework/interface/ESTransientHandle.h"
0011 #include "FWCore/Framework/interface/MakerMacros.h"
0012 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0014 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0015 
0016 #include "Geometry/Records/interface/HcalRecNumberingRecord.h"
0017 #include "Geometry/ForwardGeometry/interface/ZdcTopology.h"
0018 #include "DataFormats/HcalDetId/interface/HcalZDCDetId.h"
0019 
0020 class ZdcTopologyTester : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
0021 public:
0022   explicit ZdcTopologyTester(const edm::ParameterSet&);
0023 
0024   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0025 
0026 private:
0027   void analyze(edm::Event const&, edm::EventSetup const&) override;
0028   void beginJob() override {}
0029   void beginRun(edm::Run const&, edm::EventSetup const&) override {}
0030   void endRun(edm::Run const&, edm::EventSetup const&) override {}
0031   void doTest(const ZdcTopology& topology);
0032 
0033   // ----------member data ---------------------------
0034   const edm::ESGetToken<ZdcTopology, HcalRecNumberingRecord> tokTopo_;
0035 };
0036 
0037 ZdcTopologyTester::ZdcTopologyTester(const edm::ParameterSet&)
0038     : tokTopo_{esConsumes<ZdcTopology, HcalRecNumberingRecord>(edm::ESInputTag{})} {}
0039 
0040 void ZdcTopologyTester::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0041   edm::ParameterSetDescription desc;
0042   desc.setUnknown();
0043   descriptions.add("zdcTopologyTester", desc);
0044 }
0045 
0046 void ZdcTopologyTester::analyze(edm::Event const&, edm::EventSetup const& iSetup) { doTest(iSetup.getData(tokTopo_)); }
0047 
0048 void ZdcTopologyTester::doTest(const ZdcTopology& topology) {
0049   // Total number of valid cells
0050   for (int idet = 0; idet < 4; idet++) {
0051     int ndet(0);
0052     std::string det = "EM";
0053     HcalZDCDetId::Section section = HcalZDCDetId::EM;
0054     if (idet == 1) {
0055       det = "HAD";
0056       section = HcalZDCDetId::HAD;
0057     } else if (idet == 2) {
0058       det = "LUM";
0059       section = HcalZDCDetId::LUM;
0060     } else if (idet == 3) {
0061       det = "RPD";
0062       section = HcalZDCDetId::RPD;
0063     }
0064     for (int depth = 1; depth <= HcalZDCDetId::kDepTot; ++depth) {
0065       for (int zside = 0; zside <= 1; ++zside) {
0066         bool forward = (zside == 0) ? true : false;
0067         const HcalZDCDetId id(section, forward, depth);
0068         if (topology.valid(id))
0069           ++ndet;
0070       }
0071     }
0072     edm::LogVerbatim("HCalGeom") << "Number of valid cells in " << det << ": " << ndet;
0073   }
0074 
0075   // First test on movements along eta/phi directions
0076   edm::LogVerbatim("HCalGeom") << "\nTest on movements along transverse/longiudnal directions"
0077                                << "\n========================================================";
0078   for (int idet = 0; idet < 4; idet++) {
0079     HcalZDCDetId::Section section = HcalZDCDetId::EM;
0080     if (idet == 1)
0081       section = HcalZDCDetId::HAD;
0082     else if (idet == 2)
0083       section = HcalZDCDetId::LUM;
0084     else if (idet == 3)
0085       section = HcalZDCDetId::RPD;
0086     for (int depth = 1; depth <= HcalZDCDetId::kDepTot; ++depth) {
0087       for (int zside = 0; zside <= 1; ++zside) {
0088         bool forward = (zside == 0) ? true : false;
0089         const HcalZDCDetId id(section, forward, depth);
0090         if (topology.valid(id)) {
0091           std::vector<DetId> idT = topology.transverse(id);
0092           std::vector<DetId> idL = topology.longitudinal(id);
0093           edm::LogVerbatim("HCalGeom") << "Neighbours for : Tower " << id;
0094           std::ostringstream st1;
0095           st1 << "          " << idT.size() << " sets transverse:";
0096           for (auto& i : idT)
0097             st1 << " " << (HcalZDCDetId)(i());
0098           edm::LogVerbatim("HCalGeom") << st1.str();
0099           std::ostringstream st2;
0100           st2 << "          " << idL.size() << " sets along Longitunal:";
0101           for (auto& i : idL)
0102             st2 << " " << (HcalZDCDetId)(i());
0103           edm::LogVerbatim("HCalGeom") << st2.str();
0104         }
0105       }
0106     }
0107   }
0108 
0109   // Check on Dense Index
0110   edm::LogVerbatim("HCalGeom") << "\nCheck on Dense Index"
0111                                << "\n=====================";
0112   for (int idet = 0; idet < 4; idet++) {
0113     HcalZDCDetId::Section section = HcalZDCDetId::EM;
0114     if (idet == 1)
0115       section = HcalZDCDetId::HAD;
0116     else if (idet == 2)
0117       section = HcalZDCDetId::LUM;
0118     else if (idet == 3)
0119       section = HcalZDCDetId::RPD;
0120     for (int depth = 1; depth <= HcalZDCDetId::kDepTot; ++depth) {
0121       for (int zside = 0; zside <= 1; ++zside) {
0122         bool forward = (zside == 0) ? true : false;
0123         HcalZDCDetId cell(section, forward, depth);
0124         if (topology.valid(cell)) {
0125           unsigned int dense = topology.detId2DenseIndex(DetId(cell));
0126           DetId id = topology.denseId2detId(dense);
0127           std::string cherr = (cell.rawId() != id.rawId()) ? " **** ERROR *****" : "";
0128           edm::LogVerbatim("HCalGeom") << cell << " Dense " << std::hex << dense << std::dec << " o/p "
0129                                        << HcalZDCDetId(id) << cherr;
0130         }
0131       }
0132     }
0133   }
0134 }
0135 
0136 //define this as a plug-in
0137 DEFINE_FWK_MODULE(ZdcTopologyTester);