CMS 3D CMS Logo

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