CMS 3D CMS Logo

ETLDetLayerGeometryBuilder.cc
Go to the documentation of this file.
1 //#define EDM_ML_DEBUG
2 
4 
12 
16 
17 #include <iostream>
18 
19 using namespace std;
20 
21 pair<vector<DetLayer*>, vector<DetLayer*> > ETLDetLayerGeometryBuilder::buildLayers(const MTDGeometry& geo,
22  const MTDTopology& topo) {
23  vector<DetLayer*> result[2]; // one for each endcap
24 
25  const int mtdTopologyMode = topo.getMTDTopologyMode();
27  if (etlL == ETLDetId::EtlLayout::tp) {
28  for (unsigned endcap = 0; endcap < 2; ++endcap) {
29  // there is only one layer for ETL right now, maybe more later
30  for (unsigned layer = 0; layer < ETLDetId::kETLv1nDisc; ++layer) {
31  vector<unsigned> rings;
32  rings.reserve(ETLDetId::kETLv1maxRing + 1);
33  for (unsigned ring = 1; ring <= ETLDetId::kETLv1maxRing; ++ring) {
34  rings.push_back(ring);
35  }
36  MTDRingForwardDoubleLayer* thelayer = buildLayer(endcap, layer, rings, geo);
37  if (thelayer)
38  result[endcap].push_back(thelayer);
39  }
40  }
41  } else {
42  // number of layers is identical for post TDR scenarios, pick v4
43  // loop on number of sectors per face, two faces per disc (i.e. layer) taken into account in layer building (front/back)
44  unsigned int nSector(1);
45  if (etlL == ETLDetId::EtlLayout::v4) {
46  nSector *= ETLDetId::kETLv4maxSector;
47  } else if (etlL == ETLDetId::EtlLayout::v5) {
48  nSector *= ETLDetId::kETLv5maxSector;
49  } else {
50  throw cms::Exception("MTDDetLayers") << "Not implemented scenario " << mtdTopologyMode;
51  }
52 
53  for (unsigned endcap = 0; endcap < 2; ++endcap) {
54  // number of layers is two, identical for post TDR scenarios, pick v4
55  for (unsigned layer = 1; layer <= ETLDetId::kETLv4nDisc; ++layer) {
56  vector<unsigned> sectors;
57  sectors.reserve(nSector + 1);
58  for (unsigned sector = 1; sector <= nSector; ++sector) {
59  sectors.push_back(sector);
60  }
61  MTDSectorForwardDoubleLayer* thelayer = buildLayerNew(endcap, layer, sectors, geo, topo);
62  if (thelayer)
63  result[endcap].push_back(thelayer);
64  }
65  }
66  }
67  //
68  // the first entry is Z+ ( MTD side 1), the second is Z- (MTD side 0)
69  //
70  pair<vector<DetLayer*>, vector<DetLayer*> > res_pair(result[1], result[0]);
71  return res_pair;
72 }
73 
75  int layer,
76  vector<unsigned>& rings,
77  const MTDGeometry& geo) {
79 
80  vector<const ForwardDetRing*> frontRings, backRings;
81 
82  for (unsigned ring : rings) {
83  vector<const GeomDet*> frontGeomDets, backGeomDets;
84  for (unsigned module = 1; module <= ETLDetId::kETLmoduleMask; ++module) {
86  const GeomDet* geomDet = geo.idToDet(detId);
87  // we sometimes loop over more chambers than there are in ring
88  bool isInFront = isFront(layer, ring, module);
89  if (geomDet != nullptr) {
90  if (isInFront) {
91  frontGeomDets.push_back(geomDet);
92  } else {
93  backGeomDets.push_back(geomDet);
94  }
95  LogTrace("MTDDetLayers") << "get ETL module " << std::hex << ETLDetId(endcap, layer, ring, module).rawId()
96  << std::dec << " at R=" << geomDet->position().perp()
97  << ", phi=" << geomDet->position().phi() << ", z= " << geomDet->position().z()
98  << " isFront? " << isInFront;
99  }
100  }
101 
102  if (!backGeomDets.empty()) {
103  backRings.push_back(makeDetRing(backGeomDets));
104  }
105 
106  if (!frontGeomDets.empty()) {
107  frontRings.push_back(makeDetRing(frontGeomDets));
108  assert(!backGeomDets.empty());
109  float frontz = frontRings[0]->position().z();
110  float backz = backRings[0]->position().z();
111  assert(std::abs(frontz) < std::abs(backz));
112  }
113  }
114 
115  // How should they be sorted?
116  // precomputed_value_sort(muDetRods.begin(), muDetRods.end(), geomsort::ExtractZ<GeometricSearchDet,float>());
117  result = new MTDRingForwardDoubleLayer(frontRings, backRings);
118  LogTrace("MTDDetLayers") << "New MTDRingForwardLayer with " << frontRings.size() << " and " << backRings.size()
119  << " rings, at Z " << result->position().z()
120  << " R1: " << result->specificSurface().innerRadius()
121  << " R2: " << result->specificSurface().outerRadius();
122  return result;
123 }
124 
125 bool ETLDetLayerGeometryBuilder::isFront(int layer, int ring, int module) { return (module + 1) % 2; }
126 
127 MTDDetRing* ETLDetLayerGeometryBuilder::makeDetRing(vector<const GeomDet*>& geomDets) {
128  precomputed_value_sort(geomDets.begin(), geomDets.end(), geomsort::DetPhi());
129  MTDDetRing* result = new MTDDetRing(geomDets);
130  LogTrace("MTDDetLayers") << "ETLDetLayerGeometryBuilder: new MTDDetRing with " << geomDets.size()
131  << " chambers at z=" << result->position().z()
132  << " R1: " << result->specificSurface().innerRadius()
133  << " R2: " << result->specificSurface().outerRadius();
134  return result;
135 }
136 
138  int endcap, int layer, vector<unsigned>& sectors, const MTDGeometry& geo, const MTDTopology& topo) {
140 
141  std::vector<const MTDDetSector*> frontSectors, backSectors;
142 
143  LogDebug("MTDDetLayers") << "ETL dets array size = " << geo.detsETL().size();
144 
145  for (unsigned sector : sectors) {
146  std::vector<const GeomDet*> frontGeomDets, backGeomDets;
147  LogDebug("MTDDetLayers") << "endcap = " << endcap << " layer = " << layer << " sector = " << sector;
148 #ifdef EDM_ML_DEBUG
149  unsigned int nfront(0), nback(0);
150 #endif
151  for (auto det : geo.detsETL()) {
152  ETLDetId theMod(det->geographicalId().rawId());
153  if (theMod.mtdSide() == endcap && theMod.nDisc() == layer && theMod.sector() == static_cast<int>(sector)) {
154  LogTrace("MTDLayerDump") << std::fixed << "ETLDetId " << theMod.rawId() << " side = " << std::setw(4)
155  << theMod.mtdSide() << " Disc/Side/Sector = " << std::setw(4) << theMod.nDisc() << " "
156  << std::setw(4) << theMod.discSide() << " " << std::setw(4) << theMod.sector()
157  << " mod/type = " << std::setw(4) << theMod.module() << " " << std::setw(4)
158  << theMod.modType() << " pos = " << det->position();
159  // front layer face
160  if (theMod.discSide() == 0) {
161 #ifdef EDM_ML_DEBUG
162  nfront++;
163  LogTrace("MTDDetLayers") << "Front " << theMod.discSide() << " " << nfront;
164 #endif
165  frontGeomDets.emplace_back(det);
166  // back layer face
167  } else if (theMod.discSide() == 1) {
168 #ifdef EDM_ML_DEBUG
169  nback++;
170  LogTrace("MTDDetLayers") << "Back " << theMod.discSide() << " " << nback;
171 #endif
172  backGeomDets.emplace_back(det);
173  }
174  }
175  }
176 
177  if (!backGeomDets.empty()) {
178  std::sort(backGeomDets.begin(), backGeomDets.end(), topo.orderETLSector);
179  LogDebug("MTDDetLayers") << "backGeomDets size = " << backGeomDets.size();
180  backSectors.emplace_back(makeDetSector(backGeomDets, topo));
181  }
182 
183  if (!frontGeomDets.empty()) {
184  std::sort(frontGeomDets.begin(), frontGeomDets.end(), topo.orderETLSector);
185  LogDebug("MTDDetLayers") << "frontGeomDets size = " << frontGeomDets.size();
186  frontSectors.emplace_back(makeDetSector(frontGeomDets, topo));
187  assert(!backGeomDets.empty());
188  float frontz = frontSectors.back()->position().z();
189  float backz = backSectors.back()->position().z();
190  assert(std::abs(frontz) < std::abs(backz));
191  }
192  }
193 
194  result = new MTDSectorForwardDoubleLayer(frontSectors, backSectors);
195  LogTrace("MTDDetLayers") << "New MTDSectorForwardDoubleLayer with " << std::fixed << std::setw(14)
196  << frontSectors.size() << " and " << std::setw(14) << backSectors.size() << " rings, at Z "
197  << std::setw(14) << result->specificSurface().position().z() << " R1: " << std::setw(14)
198  << result->specificSurface().innerRadius() << " R2: " << std::setw(14)
199  << result->specificSurface().outerRadius();
200 
201  return result;
202 }
203 
204 MTDDetSector* ETLDetLayerGeometryBuilder::makeDetSector(vector<const GeomDet*>& geomDets, const MTDTopology& topo) {
205  MTDDetSector* result = new MTDDetSector(geomDets, topo);
206  LogTrace("MTDDetLayers") << "ETLDetLayerGeometryBuilder::makeDetSector new MTDDetSector with " << std::fixed
207  << std::setw(14) << geomDets.size() << " modules \n"
208  << (*result);
209 
210  return result;
211 }
static MTDDetSector * makeDetSector(std::vector< const GeomDet *> &geomDets, const MTDTopology &topo)
int getMTDTopologyMode() const
Definition: MTDTopology.h:27
T perp() const
Definition: PV3DBase.h:69
ExtractPhi< GeomDet, float > DetPhi
Definition: DetSorting.h:37
T z() const
Definition: PV3DBase.h:61
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
const DetContainer & detsETL() const
Definition: MTDGeometry.cc:161
assert(be >=bs)
#define LogTrace(id)
static bool isFront(int layer, int ring, int module)
const MTDGeomDet * idToDet(DetId) const override
Definition: MTDGeometry.cc:171
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
static bool orderETLSector(const GeomDet *&gd1, const GeomDet *&gd2)
Definition: MTDTopology.cc:7
static constexpr int kETLv1maxRing
Definition: ETLDetId.h:28
static constexpr int kETLv5maxSector
Definition: ETLDetId.h:45
ETLDetId::EtlLayout etlLayoutFromTopoMode(const int &topoMode)
void precomputed_value_sort(RandomAccessIterator begin, RandomAccessIterator end, const Extractor &extr, const Compare &comp)
static constexpr int kETLv4maxSector
Definition: ETLDetId.h:40
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
static constexpr uint32_t kETLmoduleMask
Definition: ETLDetId.h:24
const Surface::PositionType & position() const
The position (origin of the R.F.)
Definition: GeomDet.h:43
Detector identifier class for the Endcap Timing Layer.
Definition: ETLDetId.h:15
static MTDDetRing * makeDetRing(std::vector< const GeomDet *> &geomDets)
static std::pair< std::vector< DetLayer * >, std::vector< DetLayer * > > buildLayers(const MTDGeometry &geo, const MTDTopology &topo)
static constexpr int kETLv4nDisc
Definition: ETLDetId.h:42
static MTDRingForwardDoubleLayer * buildLayer(int endcap, int layer, std::vector< unsigned > &rings, const MTDGeometry &geo)
static constexpr int kETLv1nDisc
Definition: ETLDetId.h:30
static MTDSectorForwardDoubleLayer * buildLayerNew(int endcap, int layer, std::vector< unsigned > &sectors, const MTDGeometry &geo, const MTDTopology &topo)
#define LogDebug(id)