CMS 3D CMS Logo

MTDDetLayerGeometry.cc
Go to the documentation of this file.
1 
10 
15 
18 
20 #include <algorithm>
21 
22 using namespace std;
23 using namespace geomsort;
24 using namespace edm;
25 
27 
29 
31  if (geo) {
32  // Build BTL layers
33  this->addBTLLayers(BTLDetLayerGeometryBuilder::buildLayers(*geo));
34  // Build ETL layers, depends on the scenario
35  if (mtopo) {
36  this->addETLLayers(ETLDetLayerGeometryBuilder::buildLayers(*geo, *mtopo));
37  } else {
38  LogWarning("MTDDetLayers") << "No MTD topology is available.";
39  }
40  } else {
41  LogWarning("MTDDetLayers") << "No MTD geometry is available.";
42  }
43 }
44 
45 void MTDDetLayerGeometry::addETLLayers(const pair<vector<DetLayer*>, vector<DetLayer*> >& etllayers) {
46  for (auto const it : etllayers.first) {
47  etlLayers_fw.push_back(it);
48  allForward.push_back(it);
49 
50  detLayersMap[makeDetLayerId(it)] = it;
51  }
52 
53  for (auto const it : etllayers.second) {
54  etlLayers_bk.push_back(it);
55  allBackward.push_back(it);
56 
57  detLayersMap[makeDetLayerId(it)] = it;
58  }
59 }
60 
61 void MTDDetLayerGeometry::addBTLLayers(const vector<DetLayer*>& dtlayers) {
62  for (auto const it : dtlayers) {
63  btlLayers.push_back(it);
64  allBarrel.push_back(it);
65 
66  detLayersMap[makeDetLayerId(it)] = it;
67  }
68 }
69 
71  if (detLayer->subDetector() == GeomDetEnumerators::TimingEndcap) {
72  ETLDetId id(detLayer->basicComponents().front()->geographicalId().rawId());
73  return ETLDetId(id.mtdSide(), 0, 0, 0);
74  } else if (detLayer->subDetector() == GeomDetEnumerators::TimingBarrel) {
75  BTLDetId id(detLayer->basicComponents().front()->geographicalId().rawId());
76  return BTLDetId(id.mtdSide(), 0, 0, 0, 0);
77  } else
78  throw cms::Exception("InvalidModuleIdentification"); // << detLayer->module();
79 }
80 
81 const vector<const DetLayer*>& MTDDetLayerGeometry::allBarrelLayers() const { return allBarrel; }
82 
83 const vector<const DetLayer*>& MTDDetLayerGeometry::allEndcapLayers() const { return allEndcap; }
84 
85 const vector<const DetLayer*>& MTDDetLayerGeometry::allForwardLayers() const { return allForward; }
86 
87 const vector<const DetLayer*>& MTDDetLayerGeometry::allBackwardLayers() const { return allBackward; }
88 
89 const vector<const DetLayer*>& MTDDetLayerGeometry::allBTLLayers() const { return btlLayers; }
90 
91 const vector<const DetLayer*>& MTDDetLayerGeometry::allETLLayers() const { return etlLayers_all; }
92 
93 const vector<const DetLayer*>& MTDDetLayerGeometry::allLayers() const { return allDetLayers; }
94 
96 
98  DetId idout;
99  MTDDetId detId(id);
100 
101  if (detId.mtdSubDetector() == 2) { // 2 is ETL
102  ETLDetId etlId(detId.rawId());
103  idout = ETLDetId(etlId.mtdSide(), 0, 0, 0);
104  } else if (detId.mtdSubDetector() == 1) { // 1 is BTL
105  BTLDetId btlId(detId.rawId());
106  idout = BTLDetId(btlId.mtdSide(), 0, 0, 0, 0);
107  } else
108  throw cms::Exception("InvalidSubdetId") << detId.subdetId();
109 
110  std::map<DetId, const DetLayer*>::const_iterator layer = detLayersMap.find(idout);
111  if (layer == detLayersMap.end())
112  return nullptr;
113  return layer->second;
114 }
115 
116 // Quick way to sort barrel det layers by increasing R,
117 // do not abuse!
122  const BarrelDetLayer* bdl = dynamic_cast<const BarrelDetLayer*>(p);
123  if (bdl)
124  return bdl->specificSurface().radius();
125  else
126  return -1.;
127  }
128 };
129 
131  // The following are filled inside-out, no need to re-sort
132  // precomputed_value_sort(dtLayers.begin(), dtLayers.end(),ExtractR<DetLayer,float>());
133  // precomputed_value_sort(cscLayers_fw.begin(), cscLayers_fw.end(),ExtractAbsZ<DetLayer,float>());
134  // precomputed_value_sort(cscLayers_bk.begin(), cscLayers_bk.end(),ExtractAbsZ<DetLayer,float>());
135  // precomputed_value_sort(rpcLayers_fw.begin(), rpcLayers_fw.end(),ExtractAbsZ<DetLayer,float>());
136  // precomputed_value_sort(rpcLayers_bk.begin(), rpcLayers_bk.end(),ExtractAbsZ<DetLayer,float>());
137  // precomputed_value_sort(rpcLayers_barrel.begin(), rpcLayers_barrel.end(), ExtractR<DetLayer,float>());
138 
139  // Sort these inside-out
140  precomputed_value_sort(allBarrel.begin(), allBarrel.end(), ExtractBarrelDetLayerR());
141  precomputed_value_sort(allBackward.begin(), allBackward.end(), ExtractAbsZ<DetLayer, float>());
142  precomputed_value_sort(allForward.begin(), allForward.end(), ExtractAbsZ<DetLayer, float>());
143 
144  // Build more complicated vectors with correct sorting
145 
146  //etlLayers_all: from -Z to +Z
147  etlLayers_all.reserve(etlLayers_bk.size() + etlLayers_fw.size());
148  std::copy(etlLayers_bk.begin(), etlLayers_bk.end(), back_inserter(etlLayers_all));
149  std::reverse(etlLayers_all.begin(), etlLayers_all.end());
150  std::copy(etlLayers_fw.begin(), etlLayers_fw.end(), back_inserter(etlLayers_all));
151 
152  // allEndcap: order is all bw, all fw
153  allEndcap.reserve(allBackward.size() + allForward.size());
154  std::copy(allBackward.begin(), allBackward.end(), back_inserter(allEndcap));
155  std::reverse(allEndcap.begin(), allEndcap.end());
156  std::copy(allForward.begin(), allForward.end(), back_inserter(allEndcap));
157 
158  // allDetLayers: order is all bw, all barrel, all fw
159  allDetLayers.reserve(allBackward.size() + allBarrel.size() + allForward.size());
160  std::copy(allBackward.begin(), allBackward.end(), back_inserter(allDetLayers));
161  std::reverse(allDetLayers.begin(), allDetLayers.end());
162  std::copy(allBarrel.begin(), allBarrel.end(), back_inserter(allDetLayers));
163  std::copy(allForward.begin(), allForward.end(), back_inserter(allDetLayers));
164 
165  // number layers
166  int sq = 0;
167  for (auto l : allDetLayers)
168  (*const_cast<DetLayer*>(l)).setSeqNum(sq++);
169 }
static std::vector< DetLayer * > buildLayers(const MTDGeometry &geo)
Operations.
MTDDetLayerGeometry()
Constructor.
void addBTLLayers(const std::vector< DetLayer *> &btllayers)
const std::vector< const DetLayer * > & allBackwardLayers() const
return all endcap layers
~MTDDetLayerGeometry() override
Destructor.
virtual SubDetector subDetector() const =0
The type of detector (PixelBarrel, PixelEndcap, TIB, TOB, TID, TEC, CSC, DT, RPCBarrel, RPCEndcap)
int mtdSubDetector() const
Definition: MTDDetId.h:56
Detector identifier base class for the MIP Timing Layer.
Definition: MTDDetId.h:21
constexpr std::array< uint8_t, layerIndexSize > layer
const std::vector< const DetLayer * > & allLayers() const
return all DetLayers (barrel + endcap), -Z to +Z
const std::vector< const DetLayer * > & allBarrelLayers() const
return all barrel layers
const DetLayer * idToLayer(const DetId &detId) const override
return the DetLayer which correspond to a certain DetId
void buildLayers(const MTDGeometry *geo, const MTDTopology *mtopo)
result_type operator()(const DetLayer *p) const
const std::vector< const DetLayer * > & allEndcapLayers() const
return all endcap layers
const std::vector< const DetLayer * > & allForwardLayers() const
return all endcap layers
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
const std::vector< const DetLayer * > & allBTLLayers() const
return the BTL DetLayers (barrel), inside-out
Definition: DetId.h:17
void precomputed_value_sort(RandomAccessIterator begin, RandomAccessIterator end, const Extractor &extr, const Compare &comp)
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
virtual const BoundCylinder & specificSurface() const final
Extension of the interface.
virtual const std::vector< const GeomDet * > & basicComponents() const =0
DetId makeDetLayerId(const DetLayer *detLayer) const
void addETLLayers(const std::pair< std::vector< DetLayer *>, std::vector< DetLayer *> > &etllayers)
Detector identifier class for the Endcap Timing Layer.
Definition: ETLDetId.h:15
HLT enums.
Detector identifier class for the Barrel Timing Layer. The crystal count must start from 0...
Definition: BTLDetId.h:18
static std::pair< std::vector< DetLayer * >, std::vector< DetLayer * > > buildLayers(const MTDGeometry &geo, const MTDTopology &topo)
Log< level::Warning, false > LogWarning
const std::vector< const DetLayer * > & allETLLayers() const
return the ETL DetLayers (endcap), -Z to +Z