Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-12-13 03:12:31

0001 //#define EDM_ML_DEBUG
0002 
0003 #include "RecoMTD/DetLayers/interface/ETLDetLayerGeometryBuilder.h"
0004 
0005 #include <RecoMTD/DetLayers/interface/MTDSectorForwardDoubleLayer.h>
0006 #include <RecoMTD/DetLayers/interface/MTDDetSector.h>
0007 #include <DataFormats/ForwardDetId/interface/ETLDetId.h>
0008 #include <Geometry/CommonDetUnit/interface/GeomDet.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 #include <FWCore/MessageLogger/interface/MessageLogger.h>
0014 
0015 #include <iostream>
0016 
0017 using namespace std;
0018 
0019 pair<vector<DetLayer*>, vector<DetLayer*> > ETLDetLayerGeometryBuilder::buildLayers(const MTDGeometry& geo,
0020                                                                                     const MTDTopology& topo) {
0021   vector<DetLayer*> result[2];  // one for each endcap
0022 
0023   const int mtdTopologyMode = topo.getMTDTopologyMode();
0024   ETLDetId::EtlLayout etlL = MTDTopologyMode::etlLayoutFromTopoMode(mtdTopologyMode);
0025   // number of layers is identical for post TDR scenarios, pick v4
0026   // loop on number of sectors per face, two faces per disc (i.e. layer) taken into account in layer building (front/back)
0027   unsigned int nSector(1);
0028   if (etlL == ETLDetId::EtlLayout::v4) {
0029     nSector *= ETLDetId::kETLv4maxSector;
0030   } else if (etlL == ETLDetId::EtlLayout::v5) {
0031     nSector *= ETLDetId::kETLv5maxSector;
0032   } else if (etlL == ETLDetId::EtlLayout::v8) {
0033     nSector *= ETLDetId::kETLv5maxSector;
0034   } else {
0035     throw cms::Exception("MTDDetLayers") << "Not implemented scenario " << mtdTopologyMode;
0036   }
0037 
0038   for (unsigned endcap = 0; endcap < 2; ++endcap) {
0039     // number of layers is two, identical for post TDR scenarios, pick v4
0040     for (unsigned layer = 1; layer <= ETLDetId::kETLv4nDisc; ++layer) {
0041       vector<unsigned> sectors;
0042       sectors.reserve(nSector + 1);
0043       for (unsigned sector = 1; sector <= nSector; ++sector) {
0044         sectors.push_back(sector);
0045       }
0046       MTDSectorForwardDoubleLayer* thelayer = buildLayer(endcap, layer, sectors, geo, topo);
0047       if (thelayer)
0048         result[endcap].push_back(thelayer);
0049     }
0050   }
0051   //
0052   // the first entry is Z+ ( MTD side 1), the second is Z- (MTD side 0)
0053   //
0054   pair<vector<DetLayer*>, vector<DetLayer*> > res_pair(result[1], result[0]);
0055   return res_pair;
0056 }
0057 
0058 bool ETLDetLayerGeometryBuilder::isFront(int layer, int ring, int module) { return (module + 1) % 2; }
0059 
0060 MTDSectorForwardDoubleLayer* ETLDetLayerGeometryBuilder::buildLayer(
0061     int endcap, int layer, vector<unsigned>& sectors, const MTDGeometry& geo, const MTDTopology& topo) {
0062   MTDSectorForwardDoubleLayer* result = nullptr;
0063 
0064   std::vector<const MTDDetSector*> frontSectors, backSectors;
0065 
0066   LogDebug("MTDDetLayers") << "ETL dets array size = " << geo.detsETL().size();
0067 
0068   for (unsigned sector : sectors) {
0069     std::vector<const GeomDet*> frontGeomDets, backGeomDets;
0070     LogDebug("MTDDetLayers") << "endcap = " << endcap << " layer = " << layer << " sector = " << sector;
0071 #ifdef EDM_ML_DEBUG
0072     unsigned int nfront(0), nback(0);
0073 #endif
0074     for (auto det : geo.detsETL()) {
0075       ETLDetId theMod(det->geographicalId().rawId());
0076       if (theMod.mtdSide() == endcap && theMod.nDisc() == layer && theMod.sector() == static_cast<int>(sector)) {
0077         LogTrace("MTDLayerDump") << std::fixed << "ETLDetId " << theMod.rawId() << " side = " << std::setw(4)
0078                                  << theMod.mtdSide() << " Disc/Side/Sector = " << std::setw(4) << theMod.nDisc() << " "
0079                                  << std::setw(4) << theMod.discSide() << " " << std::setw(4) << theMod.sector()
0080                                  << " mod/type = " << std::setw(4) << theMod.module() << " " << std::setw(4)
0081                                  << theMod.modType() << " pos = " << det->position();
0082         // front layer face
0083         if (theMod.discSide() == 0) {
0084 #ifdef EDM_ML_DEBUG
0085           nfront++;
0086           LogTrace("MTDDetLayers") << "Front " << theMod.discSide() << " " << nfront;
0087 #endif
0088           frontGeomDets.emplace_back(det);
0089           // back layer face
0090         } else if (theMod.discSide() == 1) {
0091 #ifdef EDM_ML_DEBUG
0092           nback++;
0093           LogTrace("MTDDetLayers") << "Back " << theMod.discSide() << " " << nback;
0094 #endif
0095           backGeomDets.emplace_back(det);
0096         }
0097       }
0098     }
0099 
0100     if (!backGeomDets.empty()) {
0101       std::sort(backGeomDets.begin(), backGeomDets.end(), topo.orderETLSector);
0102       LogDebug("MTDDetLayers") << "backGeomDets size = " << backGeomDets.size();
0103       backSectors.emplace_back(makeDetSector(backGeomDets, topo));
0104     }
0105 
0106     if (!frontGeomDets.empty()) {
0107       std::sort(frontGeomDets.begin(), frontGeomDets.end(), topo.orderETLSector);
0108       LogDebug("MTDDetLayers") << "frontGeomDets size = " << frontGeomDets.size();
0109       frontSectors.emplace_back(makeDetSector(frontGeomDets, topo));
0110       assert(!backGeomDets.empty());
0111       float frontz = frontSectors.back()->position().z();
0112       float backz = backSectors.back()->position().z();
0113       assert(std::abs(frontz) < std::abs(backz));
0114     }
0115   }
0116 
0117   result = new MTDSectorForwardDoubleLayer(frontSectors, backSectors);
0118   LogTrace("MTDDetLayers") << "New MTDSectorForwardDoubleLayer with " << std::fixed << std::setw(14)
0119                            << frontSectors.size() << " and " << std::setw(14) << backSectors.size() << " rings, at Z "
0120                            << std::setw(14) << result->specificSurface().position().z() << " R1: " << std::setw(14)
0121                            << result->specificSurface().innerRadius() << " R2: " << std::setw(14)
0122                            << result->specificSurface().outerRadius();
0123 
0124   return result;
0125 }
0126 
0127 MTDDetSector* ETLDetLayerGeometryBuilder::makeDetSector(vector<const GeomDet*>& geomDets, const MTDTopology& topo) {
0128   MTDDetSector* result = new MTDDetSector(geomDets, topo);
0129   LogTrace("MTDDetLayers") << "ETLDetLayerGeometryBuilder::makeDetSector new MTDDetSector with " << std::fixed
0130                            << std::setw(14) << geomDets.size() << " modules \n"
0131                            << (*result);
0132 
0133   return result;
0134 }