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  bool abort(false);
32  if (geo == nullptr) {
33  LogError("MTDDetLayers") << "No MTD geometry is available.";
34  abort = true;
35  }
36  if (mtopo == nullptr) {
37  LogError("MTDDetLayers") << "No MTD topology is available.";
38  abort = true;
39  }
40  if (abort) {
41  throw cms::Exception("MTDDetLayers") << "No complete MTD geometry available, aborting.";
42  }
43 
44  // Build BTL layers
45  this->addBTLLayers(BTLDetLayerGeometryBuilder::buildLayers(*geo, *mtopo));
46  // Build ETL layers, depends on the scenario
47  this->addETLLayers(ETLDetLayerGeometryBuilder::buildLayers(*geo, *mtopo));
48 }
49 
50 void MTDDetLayerGeometry::addETLLayers(const pair<vector<DetLayer*>, vector<DetLayer*> >& etllayers) {
51  for (auto const it : etllayers.first) {
52  etlLayers_fw.push_back(it);
53  allForward.push_back(it);
54 
55  detLayersMap[makeDetLayerId(it)] = it;
56  }
57 
58  for (auto const it : etllayers.second) {
59  etlLayers_bk.push_back(it);
60  allBackward.push_back(it);
61 
62  detLayersMap[makeDetLayerId(it)] = it;
63  }
64 }
65 
66 void MTDDetLayerGeometry::addBTLLayers(const vector<DetLayer*>& dtlayers) {
67  for (auto const it : dtlayers) {
68  btlLayers.push_back(it);
69  allBarrel.push_back(it);
70 
71  detLayersMap[makeDetLayerId(it)] = it;
72  }
73 }
74 
76  if (detLayer->subDetector() == GeomDetEnumerators::TimingEndcap) {
77  ETLDetId id(detLayer->basicComponents().front()->geographicalId().rawId());
78  return ETLDetId(id.mtdSide(), 0, 0, 0);
79  } else if (detLayer->subDetector() == GeomDetEnumerators::TimingBarrel) {
80  BTLDetId id(detLayer->basicComponents().front()->geographicalId().rawId());
81  return BTLDetId(id.mtdSide(), 0, 0, 0, 0);
82  } else
83  throw cms::Exception("InvalidModuleIdentification"); // << detLayer->module();
84 }
85 
86 const vector<const DetLayer*>& MTDDetLayerGeometry::allBarrelLayers() const { return allBarrel; }
87 
88 const vector<const DetLayer*>& MTDDetLayerGeometry::allEndcapLayers() const { return allEndcap; }
89 
90 const vector<const DetLayer*>& MTDDetLayerGeometry::allForwardLayers() const { return allForward; }
91 
92 const vector<const DetLayer*>& MTDDetLayerGeometry::allBackwardLayers() const { return allBackward; }
93 
94 const vector<const DetLayer*>& MTDDetLayerGeometry::allBTLLayers() const { return btlLayers; }
95 
96 const vector<const DetLayer*>& MTDDetLayerGeometry::allETLLayers() const { return etlLayers_all; }
97 
98 const vector<const DetLayer*>& MTDDetLayerGeometry::allLayers() const { return allDetLayers; }
99 
101 
103  DetId idout;
104  MTDDetId detId(id);
105 
106  if (detId.mtdSubDetector() == 2) { // 2 is ETL
107  ETLDetId etlId(detId.rawId());
108  idout = ETLDetId(etlId.mtdSide(), 0, 0, 0);
109  } else if (detId.mtdSubDetector() == 1) { // 1 is BTL
110  BTLDetId btlId(detId.rawId());
111  idout = BTLDetId(btlId.mtdSide(), 0, 0, 0, 0);
112  } else
113  throw cms::Exception("InvalidSubdetId") << detId.subdetId();
114 
115  std::map<DetId, const DetLayer*>::const_iterator layer = detLayersMap.find(idout);
116  if (layer == detLayersMap.end())
117  return nullptr;
118  return layer->second;
119 }
120 
121 // Quick way to sort barrel det layers by increasing R,
122 // do not abuse!
127  const BarrelDetLayer* bdl = dynamic_cast<const BarrelDetLayer*>(p);
128  if (bdl)
129  return bdl->specificSurface().radius();
130  else
131  return -1.;
132  }
133 };
134 
136  // The following are filled inside-out, no need to re-sort
137  // precomputed_value_sort(dtLayers.begin(), dtLayers.end(),ExtractR<DetLayer,float>());
138  // precomputed_value_sort(cscLayers_fw.begin(), cscLayers_fw.end(),ExtractAbsZ<DetLayer,float>());
139  // precomputed_value_sort(cscLayers_bk.begin(), cscLayers_bk.end(),ExtractAbsZ<DetLayer,float>());
140  // precomputed_value_sort(rpcLayers_fw.begin(), rpcLayers_fw.end(),ExtractAbsZ<DetLayer,float>());
141  // precomputed_value_sort(rpcLayers_bk.begin(), rpcLayers_bk.end(),ExtractAbsZ<DetLayer,float>());
142  // precomputed_value_sort(rpcLayers_barrel.begin(), rpcLayers_barrel.end(), ExtractR<DetLayer,float>());
143 
144  // Sort these inside-out
145  precomputed_value_sort(allBarrel.begin(), allBarrel.end(), ExtractBarrelDetLayerR());
146  precomputed_value_sort(allBackward.begin(), allBackward.end(), ExtractAbsZ<DetLayer, float>());
147  precomputed_value_sort(allForward.begin(), allForward.end(), ExtractAbsZ<DetLayer, float>());
148 
149  // Build more complicated vectors with correct sorting
150 
151  //etlLayers_all: from -Z to +Z
152  etlLayers_all.reserve(etlLayers_bk.size() + etlLayers_fw.size());
153  std::copy(etlLayers_bk.begin(), etlLayers_bk.end(), back_inserter(etlLayers_all));
154  std::reverse(etlLayers_all.begin(), etlLayers_all.end());
155  std::copy(etlLayers_fw.begin(), etlLayers_fw.end(), back_inserter(etlLayers_all));
156 
157  // allEndcap: order is all bw, all fw
158  allEndcap.reserve(allBackward.size() + allForward.size());
159  std::copy(allBackward.begin(), allBackward.end(), back_inserter(allEndcap));
160  std::reverse(allEndcap.begin(), allEndcap.end());
161  std::copy(allForward.begin(), allForward.end(), back_inserter(allEndcap));
162 
163  // allDetLayers: order is all bw, all barrel, all fw
164  allDetLayers.reserve(allBackward.size() + allBarrel.size() + allForward.size());
165  std::copy(allBackward.begin(), allBackward.end(), back_inserter(allDetLayers));
166  std::reverse(allDetLayers.begin(), allDetLayers.end());
167  std::copy(allBarrel.begin(), allBarrel.end(), back_inserter(allDetLayers));
168  std::copy(allForward.begin(), allForward.end(), back_inserter(allDetLayers));
169 
170  // number layers
171  int sq = 0;
172  for (auto l : allDetLayers)
173  (*const_cast<DetLayer*>(l)).setSeqNum(sq++);
174 }
static std::vector< DetLayer * > buildLayers(const MTDGeometry &geo, const MTDTopology &topo)
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)
Log< level::Error, false > LogError
Detector identifier base class for the MIP Timing Layer.
Definition: MTDDetId.h:21
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
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)
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:19
static std::pair< std::vector< DetLayer * >, std::vector< DetLayer * > > buildLayers(const MTDGeometry &geo, const MTDTopology &topo)
const std::vector< const DetLayer * > & allETLLayers() const
return the ETL DetLayers (endcap), -Z to +Z