|
| 1 | +#include "FWCore/Framework/interface/Frameworkfwd.h" |
| 2 | +#include "FWCore/Framework/interface/global/EDAnalyzer.h" |
| 3 | +#include "FWCore/Framework/interface/Event.h" |
| 4 | +#include "FWCore/Framework/interface/EventSetup.h" |
| 5 | +#include "FWCore/Framework/interface/ESTransientHandle.h" |
| 6 | +#include "FWCore/ParameterSet/interface/ParameterSet.h" |
| 7 | +#include "FWCore/MessageLogger/interface/MessageLogger.h" |
| 8 | +#include "FWCore/Utilities/interface/StreamID.h" |
| 9 | + |
| 10 | +#include "Geometry/MTDGeometryBuilder/interface/MTDTopology.h" |
| 11 | +#include "Geometry/Records/interface/MTDTopologyRcd.h" |
| 12 | + |
| 13 | +#include "RecoMTD/DetLayers/interface/MTDDetLayerGeometry.h" |
| 14 | +#include "RecoMTD/Records/interface/MTDRecoGeometryRecord.h" |
| 15 | + |
| 16 | +#include "RecoMTD/DetLayers/interface/MTDTrayBarrelLayer.h" |
| 17 | +#include "RecoMTD/DetLayers/interface/MTDDetTray.h" |
| 18 | + |
| 19 | +#include <DataFormats/ForwardDetId/interface/BTLDetId.h> |
| 20 | + |
| 21 | +#include <sstream> |
| 22 | + |
| 23 | +#include "DataFormats/Math/interface/Rounding.h" |
| 24 | + |
| 25 | +using namespace std; |
| 26 | +using namespace edm; |
| 27 | +using namespace cms_rounding; |
| 28 | + |
| 29 | +class TestBTLNavigation : public global::EDAnalyzer<> { |
| 30 | +public: |
| 31 | + TestBTLNavigation(const ParameterSet& pset); |
| 32 | + |
| 33 | + void analyze(edm::StreamID, edm::Event const&, edm::EventSetup const&) const override; |
| 34 | + |
| 35 | +private: |
| 36 | + inline std::string fround(const double in, const size_t prec) const { |
| 37 | + std::stringstream ss; |
| 38 | + ss << std::setprecision(prec) << std::fixed << std::setw(14) << roundIfNear0(in); |
| 39 | + return ss.str(); |
| 40 | + } |
| 41 | + |
| 42 | + inline std::string fvecround(const GlobalPoint vecin, const size_t prec) const { |
| 43 | + std::stringstream ss; |
| 44 | + ss << std::setprecision(prec) << std::fixed << std::setw(14) << roundVecIfNear0(vecin); |
| 45 | + return ss.str(); |
| 46 | + } |
| 47 | + |
| 48 | + const edm::ESInputTag tag_; |
| 49 | + edm::ESGetToken<MTDDetLayerGeometry, MTDRecoGeometryRecord> geomToken_; |
| 50 | + edm::ESGetToken<MTDTopology, MTDTopologyRcd> topoToken_; |
| 51 | +}; |
| 52 | + |
| 53 | +TestBTLNavigation::TestBTLNavigation(const ParameterSet& iConfig) : tag_(edm::ESInputTag{"", ""}) { |
| 54 | + geomToken_ = esConsumes<MTDDetLayerGeometry, MTDRecoGeometryRecord>(tag_); |
| 55 | + topoToken_ = esConsumes<MTDTopology, MTDTopologyRcd>(tag_); |
| 56 | +} |
| 57 | + |
| 58 | +void TestBTLNavigation::analyze(edm::StreamID, edm::Event const&, edm::EventSetup const& es) const { |
| 59 | + auto geo = es.getTransientHandle(geomToken_); |
| 60 | + auto topo = es.getTransientHandle(topoToken_); |
| 61 | + |
| 62 | + const vector<const DetLayer*>& layers = geo->allBTLLayers(); |
| 63 | + |
| 64 | + // dump of BTL layers structure |
| 65 | + |
| 66 | + LogVerbatim("MTDLayerDumpFull") << "\n\nTest of BTL navigation \n\n"; |
| 67 | + LogVerbatim("MTDLayerDump") << "\n\nTest of BTL navigation \n\n"; |
| 68 | + |
| 69 | + for (const auto& ilay : layers) { |
| 70 | + const MTDTrayBarrelLayer* layer = static_cast<const MTDTrayBarrelLayer*>(ilay); |
| 71 | + |
| 72 | + LogVerbatim("MTDLayerDumpFull") << std::fixed << "\nBTL layer " << std::setw(4) << layer->subDetector() |
| 73 | + << " at z = " << fround(layer->surface().position().z(), 4) |
| 74 | + << " rods = " << std::setw(14) << layer->rods().size() |
| 75 | + << " dets = " << std::setw(14) << layer->basicComponents().size(); |
| 76 | + LogVerbatim("MTDLayerDump") << std::fixed << "\nBTL layer " << std::setw(4) << layer->subDetector() |
| 77 | + << " at z = " << fround(layer->surface().position().z(), 2) |
| 78 | + << " rods = " << std::setw(14) << layer->rods().size() << " dets = " << std::setw(14) |
| 79 | + << layer->basicComponents().size(); |
| 80 | + |
| 81 | + unsigned int irodInd(0); |
| 82 | + for (const auto& irod : layer->rods()) { |
| 83 | + irodInd++; |
| 84 | + LogVerbatim("MTDLayerDumpFull") << std::fixed << "\nTray " << std::setw(4) << irodInd << "\n" |
| 85 | + << " MTDDetTray at " << std::fixed << std::setprecision(3) |
| 86 | + << roundVecIfNear0(irod->specificSurface().position()) << std::endl |
| 87 | + << " L/W/T : " << fround(irod->specificSurface().bounds().length(), 2) << " / " |
| 88 | + << fround(irod->specificSurface().bounds().width(), 2) << " / " |
| 89 | + << fround(irod->specificSurface().bounds().thickness(), 2) |
| 90 | + << " normal phi = " << fround(irod->specificSurface().normalVector().phi(), 2) |
| 91 | + << std::endl; |
| 92 | + LogVerbatim("MTDLayerDump") << std::fixed << "\nTray " << std::setw(4) << irodInd << "\n" |
| 93 | + << " MTDDetTray at " << std::fixed << std::setprecision(3) |
| 94 | + << roundVecIfNear0(irod->specificSurface().position()) << std::endl |
| 95 | + << " L/W/T : " << fround(irod->specificSurface().bounds().length(), 2) << " / " |
| 96 | + << fround(irod->specificSurface().bounds().width(), 2) << " / " |
| 97 | + << fround(irod->specificSurface().bounds().thickness(), 2) |
| 98 | + << " normal phi = " << fround(irod->specificSurface().normalVector().phi(), 2) |
| 99 | + << std::endl; |
| 100 | + unsigned int imodInd(0); |
| 101 | + for (const auto& imod : irod->basicComponents()) { |
| 102 | + imodInd++; |
| 103 | + BTLDetId modId(imod->geographicalId().rawId()); |
| 104 | + auto topoId = topo.product()->btlIndex(modId.rawId()); |
| 105 | + auto topoDetId = topo.product()->btlidFromIndex(topoId.first, topoId.second); |
| 106 | + LogVerbatim("MTDLayerDumpFull") << std::fixed << std::setw(5) << imodInd << " BTLDetId " << modId.rawId() |
| 107 | + << " iphi/ieta = " << std::setw(4) << topoId.first << " / " << std::setw(4) |
| 108 | + << topoId.second << " side = " << std::setw(4) << modId.mtdSide() |
| 109 | + << " RU = " << std::setw(4) << modId.runit() << " mod = " << std::setw(4) |
| 110 | + << modId.module() << " pos = " << fvecround(imod->position(), 4); |
| 111 | + LogVerbatim("MTDLayerDump") << std::fixed << std::setw(5) << imodInd << " BTLDetId " << modId.rawId() |
| 112 | + << " iphi/ieta = " << std::setw(4) << topoId.first << " / " << std::setw(4) |
| 113 | + << topoId.second << " side = " << std::setw(4) << modId.mtdSide() |
| 114 | + << " RU = " << std::setw(4) << modId.runit() << " mod = " << std::setw(4) |
| 115 | + << modId.module() << " pos = " << fvecround(imod->position(), 2); |
| 116 | + if (topoDetId != modId.rawId()) { |
| 117 | + LogVerbatim("MTDLayerDumpFull") |
| 118 | + << "DIFFERENCE BtlDetId " << modId.rawId() << " not equal to MTDTopology " << topoDetId; |
| 119 | + LogVerbatim("MTDLayerDump") << "DIFFERENCE BtlDetId " << modId.rawId() << " not equal to MTDTopology " |
| 120 | + << topoDetId; |
| 121 | + } |
| 122 | + for (int iside = -1; iside <= 1; iside += 2) { |
| 123 | + size_t idetNew = topo.product()->phishiftBTL(modId.rawId(), iside); |
| 124 | + if (idetNew > irod->basicComponents().size()) { |
| 125 | + LogVerbatim("MTDLayerDumpFull") |
| 126 | + << "...............phishift= " << std::fixed << std::setw(2) << iside << " out of range"; |
| 127 | + LogVerbatim("MTDLayerDump") << "...............phishift= " << std::fixed << std::setw(2) << iside |
| 128 | + << " out of range"; |
| 129 | + } else { |
| 130 | + BTLDetId newId(irod->basicComponents()[idetNew]->geographicalId().rawId()); |
| 131 | + auto newTopoId = topo.product()->btlIndex(newId.rawId()); |
| 132 | + LogVerbatim("MTDLayerDumpFull") |
| 133 | + << std::fixed << "...............phishift= " |
| 134 | + << " iphi/ieta = " << std::setw(4) << newTopoId.first << " / " << std::setw(4) << newTopoId.second |
| 135 | + << std::setw(2) << iside << " side = " << std::setw(4) << newId.mtdSide() << " RU = " << std::setw(4) |
| 136 | + << newId.runit() << " mod = " << std::setw(4) << newId.module() |
| 137 | + << " pos = " << fvecround(irod->basicComponents()[idetNew]->position(), 4); |
| 138 | + LogVerbatim("MTDLayerDump") << std::fixed << "...............phishift= " |
| 139 | + << " iphi/ieta = " << std::setw(4) << newTopoId.first << " / " << std::setw(4) |
| 140 | + << newTopoId.second << std::setw(2) << iside << " side = " << std::setw(4) |
| 141 | + << newId.mtdSide() << " RU = " << std::setw(4) << newId.runit() |
| 142 | + << " mod = " << std::setw(4) << newId.module() |
| 143 | + << " pos = " << fvecround(irod->basicComponents()[idetNew]->position(), 2); |
| 144 | + } |
| 145 | + } |
| 146 | + for (int iside = -1; iside <= 1; iside += 2) { |
| 147 | + auto idetNew = topo.product()->etashiftBTL(modId, iside); |
| 148 | + if (idetNew > irod->basicComponents().size()) { |
| 149 | + LogVerbatim("MTDLayerDumpFull") |
| 150 | + << "...............etashift= " << std::fixed << std::setw(2) << iside << " out of range"; |
| 151 | + LogVerbatim("MTDLayerDump") << "...............etashift= " << std::fixed << std::setw(2) << iside |
| 152 | + << " out of range"; |
| 153 | + } else { |
| 154 | + BTLDetId newId(irod->basicComponents()[idetNew]->geographicalId().rawId()); |
| 155 | + auto const& newTopoId = topo.product()->btlIndex(newId.rawId()); |
| 156 | + LogVerbatim("MTDLayerDumpFull") |
| 157 | + << std::fixed << "...............etashift= " |
| 158 | + << " iphi/ieta = " << std::setw(4) << newTopoId.first << " / " << std::setw(4) << newTopoId.second |
| 159 | + << std::setw(2) << iside << " side = " << std::setw(4) << newId.mtdSide() << " RU = " << std::setw(4) |
| 160 | + << newId.runit() << " mod = " << std::setw(4) << newId.module() |
| 161 | + << " pos = " << fvecround(irod->basicComponents()[idetNew]->position(), 4); |
| 162 | + LogVerbatim("MTDLayerDump") << std::fixed << "...............etashift= " |
| 163 | + << " iphi/ieta = " << std::setw(4) << newTopoId.first << " / " << std::setw(4) |
| 164 | + << newTopoId.second << std::setw(2) << iside << " side = " << std::setw(4) |
| 165 | + << newId.mtdSide() << " RU = " << std::setw(4) << newId.runit() |
| 166 | + << " mod = " << std::setw(4) << newId.module() |
| 167 | + << " pos = " << fvecround(irod->basicComponents()[idetNew]->position(), 2); |
| 168 | + } |
| 169 | + } |
| 170 | + } |
| 171 | + } |
| 172 | + } |
| 173 | +} |
| 174 | + |
| 175 | +//define this as a plug-in |
| 176 | +#include <FWCore/Framework/interface/MakerMacros.h> |
| 177 | +DEFINE_FWK_MODULE(TestBTLNavigation); |
0 commit comments