Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:26:49

0001 //#define EDM_ML_DEBUG
0002 
0003 #include "RecoMTD/DetLayers/interface/BTLDetLayerGeometryBuilder.h"
0004 
0005 #include <DataFormats/ForwardDetId/interface/BTLDetId.h>
0006 #include <Geometry/CommonDetUnit/interface/GeomDet.h>
0007 #include <RecoMTD/DetLayers/interface/MTDTrayBarrelLayer.h>
0008 #include <RecoMTD/DetLayers/interface/MTDDetTray.h>
0009 #include <Geometry/MTDCommonData/interface/MTDTopologyMode.h>
0010 
0011 #include <Utilities/General/interface/precomputed_value_sort.h>
0012 #include <Geometry/CommonDetUnit/interface/DetSorting.h>
0013 
0014 #include <FWCore/MessageLogger/interface/MessageLogger.h>
0015 
0016 #include <iostream>
0017 
0018 using namespace std;
0019 
0020 BTLDetLayerGeometryBuilder::BTLDetLayerGeometryBuilder() {}
0021 
0022 BTLDetLayerGeometryBuilder::~BTLDetLayerGeometryBuilder() {}
0023 
0024 vector<DetLayer*> BTLDetLayerGeometryBuilder::buildLayers(const MTDGeometry& geo, const MTDTopology& topo) {
0025   vector<DetLayer*> detlayers;
0026   vector<MTDTrayBarrelLayer*> result;
0027 
0028   vector<const DetRod*> btlDetTrays;
0029 
0030   const int mtdTopologyMode = topo.getMTDTopologyMode();
0031   BTLDetId::CrysLayout btlL = MTDTopologyMode::crysLayoutFromTopoMode(mtdTopologyMode);
0032 
0033   if (btlL != BTLDetId::CrysLayout::v2 && btlL != BTLDetId::CrysLayout::v3) {
0034     for (unsigned tray = 1; tray <= BTLDetId::HALF_ROD; ++tray) {
0035       vector<const GeomDet*> geomDets;
0036       for (unsigned module = 1; module <= BTLDetId::kModulesPerRODBarPhiFlat; ++module) {
0037         for (unsigned side = 0; side <= 1; ++side) {
0038           const GeomDet* geomDet = geo.idToDet(BTLDetId(side, tray, module, 0, 1));
0039           if (geomDet != nullptr) {
0040             geomDets.push_back(geomDet);
0041             LogTrace("MTDDetLayers") << "get BTL module " << std::hex << BTLDetId(side, tray, module, 0, 1).rawId()
0042                                      << std::dec << " at R=" << geomDet->position().perp()
0043                                      << ", phi=" << geomDet->position().phi();
0044           }
0045         }
0046       }
0047 
0048       if (!geomDets.empty()) {
0049         precomputed_value_sort(geomDets.begin(), geomDets.end(), geomsort::DetZ());
0050         btlDetTrays.push_back(new MTDDetTray(geomDets));
0051         LogTrace("MTDDetLayers") << "  New BTLDetTray with " << geomDets.size()
0052                                  << " modules at R=" << btlDetTrays.back()->position().perp()
0053                                  << ", phi=" << btlDetTrays.back()->position().phi();
0054       }
0055     }
0056 
0057     precomputed_value_sort(btlDetTrays.begin(), btlDetTrays.end(), geomsort::ExtractPhi<GeometricSearchDet, float>());
0058     result.push_back(new MTDTrayBarrelLayer(btlDetTrays));
0059     LogTrace("MTDDetLayers") << "BTLDetLayerGeometryBuilder: new MTDTrayBarrelLayer with " << btlDetTrays.size()
0060                              << " rods, at R " << result.back()->specificSurface().radius();
0061   } else {
0062     vector<const GeomDet*> geomDets;
0063 
0064     // logical tracking trays are now rows along z of modules, 3 per each mechanical tray, running from -z to z
0065     // MTDGeometry is already built with the proper ordering, it is enough to exploit that
0066     const uint32_t modulesPerDetTray =
0067         2 * BTLDetId::kRUPerTypeV2 * BTLDetId::kCrystalTypes * BTLDetId::kModulesPerRUV2 / BTLDetId::kModulesPerTrkV2;
0068     geomDets.reserve(modulesPerDetTray);
0069 
0070     uint32_t index(0);
0071     for (const auto& det : geo.detsBTL()) {
0072       index++;
0073       geomDets.emplace_back(det);
0074       if (index == modulesPerDetTray) {
0075         btlDetTrays.emplace_back(new MTDDetTray(geomDets));
0076         LogTrace("MTDDetLayers") << "  New BTLDetTray with " << geomDets.size()
0077                                  << " modules at R=" << btlDetTrays.back()->position().perp()
0078                                  << ", phi=" << btlDetTrays.back()->position().phi();
0079         index = 0;
0080         geomDets.clear();
0081       }
0082     }
0083 
0084     result.emplace_back(new MTDTrayBarrelLayer(btlDetTrays));
0085     LogTrace("MTDDetLayers") << "BTLDetLayerGeometryBuilder: new MTDTrayBarrelLayer with " << btlDetTrays.size()
0086                              << " rods, at R " << result.back()->specificSurface().radius();
0087   }
0088 
0089   for (vector<MTDTrayBarrelLayer*>::const_iterator it = result.begin(); it != result.end(); it++)
0090     detlayers.push_back((DetLayer*)(*it));
0091 
0092   return detlayers;
0093 }