Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-05-17 03:00:31

0001 /** \file
0002  *
0003  *  \author L. Gray - FNAL
0004  *
0005  */
0006 
0007 #include <RecoMTD/DetLayers/interface/MTDDetLayerGeometry.h>
0008 #include <RecoMTD/DetLayers/interface/ETLDetLayerGeometryBuilder.h>
0009 #include <RecoMTD/DetLayers/interface/BTLDetLayerGeometryBuilder.h>
0010 
0011 #include <FWCore/Utilities/interface/Exception.h>
0012 #include <TrackingTools/DetLayers/interface/DetLayer.h>
0013 #include <DataFormats/ForwardDetId/interface/BTLDetId.h>
0014 #include <DataFormats/ForwardDetId/interface/ETLDetId.h>
0015 
0016 #include <Utilities/General/interface/precomputed_value_sort.h>
0017 #include <DataFormats/GeometrySurface/interface/GeometricSorting.h>
0018 
0019 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0020 #include <algorithm>
0021 
0022 using namespace std;
0023 using namespace geomsort;
0024 using namespace edm;
0025 
0026 MTDDetLayerGeometry::MTDDetLayerGeometry() {}
0027 
0028 MTDDetLayerGeometry::~MTDDetLayerGeometry() {}
0029 
0030 void MTDDetLayerGeometry::buildLayers(const MTDGeometry* geo, const MTDTopology* mtopo) {
0031   if (geo) {
0032     // Build BTL layers
0033     this->addBTLLayers(BTLDetLayerGeometryBuilder::buildLayers(*geo));
0034     // Build ETL layers, depends on the scenario
0035     if (mtopo) {
0036       this->addETLLayers(ETLDetLayerGeometryBuilder::buildLayers(*geo, *mtopo));
0037     } else {
0038       LogWarning("MTDDetLayers") << "No MTD topology  is available.";
0039     }
0040   } else {
0041     LogWarning("MTDDetLayers") << "No MTD geometry is available.";
0042   }
0043 }
0044 
0045 void MTDDetLayerGeometry::addETLLayers(const pair<vector<DetLayer*>, vector<DetLayer*> >& etllayers) {
0046   for (auto const it : etllayers.first) {
0047     etlLayers_fw.push_back(it);
0048     allForward.push_back(it);
0049 
0050     detLayersMap[makeDetLayerId(it)] = it;
0051   }
0052 
0053   for (auto const it : etllayers.second) {
0054     etlLayers_bk.push_back(it);
0055     allBackward.push_back(it);
0056 
0057     detLayersMap[makeDetLayerId(it)] = it;
0058   }
0059 }
0060 
0061 void MTDDetLayerGeometry::addBTLLayers(const vector<DetLayer*>& dtlayers) {
0062   for (auto const it : dtlayers) {
0063     btlLayers.push_back(it);
0064     allBarrel.push_back(it);
0065 
0066     detLayersMap[makeDetLayerId(it)] = it;
0067   }
0068 }
0069 
0070 DetId MTDDetLayerGeometry::makeDetLayerId(const DetLayer* detLayer) const {
0071   if (detLayer->subDetector() == GeomDetEnumerators::TimingEndcap) {
0072     ETLDetId id(detLayer->basicComponents().front()->geographicalId().rawId());
0073     return ETLDetId(id.mtdSide(), 0, 0, 0);
0074   } else if (detLayer->subDetector() == GeomDetEnumerators::TimingBarrel) {
0075     BTLDetId id(detLayer->basicComponents().front()->geographicalId().rawId());
0076     return BTLDetId(id.mtdSide(), 0, 0, 0, 0);
0077   } else
0078     throw cms::Exception("InvalidModuleIdentification");  // << detLayer->module();
0079 }
0080 
0081 const vector<const DetLayer*>& MTDDetLayerGeometry::allBarrelLayers() const { return allBarrel; }
0082 
0083 const vector<const DetLayer*>& MTDDetLayerGeometry::allEndcapLayers() const { return allEndcap; }
0084 
0085 const vector<const DetLayer*>& MTDDetLayerGeometry::allForwardLayers() const { return allForward; }
0086 
0087 const vector<const DetLayer*>& MTDDetLayerGeometry::allBackwardLayers() const { return allBackward; }
0088 
0089 const vector<const DetLayer*>& MTDDetLayerGeometry::allBTLLayers() const { return btlLayers; }
0090 
0091 const vector<const DetLayer*>& MTDDetLayerGeometry::allETLLayers() const { return etlLayers_all; }
0092 
0093 const vector<const DetLayer*>& MTDDetLayerGeometry::allLayers() const { return allDetLayers; }
0094 
0095 ////////////////////////////////////////////////////
0096 
0097 const DetLayer* MTDDetLayerGeometry::idToLayer(const DetId& id) const {
0098   DetId idout;
0099   MTDDetId detId(id);
0100 
0101   if (detId.mtdSubDetector() == 2) {  // 2 is ETL
0102     ETLDetId etlId(detId.rawId());
0103     idout = ETLDetId(etlId.mtdSide(), 0, 0, 0);
0104   } else if (detId.mtdSubDetector() == 1) {  // 1 is BTL
0105     BTLDetId btlId(detId.rawId());
0106     idout = BTLDetId(btlId.mtdSide(), 0, 0, 0, 0);
0107   } else
0108     throw cms::Exception("InvalidSubdetId") << detId.subdetId();
0109 
0110   std::map<DetId, const DetLayer*>::const_iterator layer = detLayersMap.find(idout);
0111   if (layer == detLayersMap.end())
0112     return nullptr;
0113   return layer->second;
0114 }
0115 
0116 // Quick way to sort barrel det layers by increasing R,
0117 // do not abuse!
0118 #include <TrackingTools/DetLayers/interface/BarrelDetLayer.h>
0119 struct ExtractBarrelDetLayerR {
0120   typedef Surface::Scalar result_type;
0121   result_type operator()(const DetLayer* p) const {
0122     const BarrelDetLayer* bdl = dynamic_cast<const BarrelDetLayer*>(p);
0123     if (bdl)
0124       return bdl->specificSurface().radius();
0125     else
0126       return -1.;
0127   }
0128 };
0129 
0130 void MTDDetLayerGeometry::sortLayers() {
0131   // The following are filled inside-out, no need to re-sort
0132   // precomputed_value_sort(dtLayers.begin(), dtLayers.end(),ExtractR<DetLayer,float>());
0133   // precomputed_value_sort(cscLayers_fw.begin(), cscLayers_fw.end(),ExtractAbsZ<DetLayer,float>());
0134   // precomputed_value_sort(cscLayers_bk.begin(), cscLayers_bk.end(),ExtractAbsZ<DetLayer,float>());
0135   // precomputed_value_sort(rpcLayers_fw.begin(), rpcLayers_fw.end(),ExtractAbsZ<DetLayer,float>());
0136   // precomputed_value_sort(rpcLayers_bk.begin(), rpcLayers_bk.end(),ExtractAbsZ<DetLayer,float>());
0137   // precomputed_value_sort(rpcLayers_barrel.begin(), rpcLayers_barrel.end(), ExtractR<DetLayer,float>());
0138 
0139   // Sort these inside-out
0140   precomputed_value_sort(allBarrel.begin(), allBarrel.end(), ExtractBarrelDetLayerR());
0141   precomputed_value_sort(allBackward.begin(), allBackward.end(), ExtractAbsZ<DetLayer, float>());
0142   precomputed_value_sort(allForward.begin(), allForward.end(), ExtractAbsZ<DetLayer, float>());
0143 
0144   // Build more complicated vectors with correct sorting
0145 
0146   //etlLayers_all: from -Z to +Z
0147   etlLayers_all.reserve(etlLayers_bk.size() + etlLayers_fw.size());
0148   std::copy(etlLayers_bk.begin(), etlLayers_bk.end(), back_inserter(etlLayers_all));
0149   std::reverse(etlLayers_all.begin(), etlLayers_all.end());
0150   std::copy(etlLayers_fw.begin(), etlLayers_fw.end(), back_inserter(etlLayers_all));
0151 
0152   // allEndcap: order is  all bw, all fw
0153   allEndcap.reserve(allBackward.size() + allForward.size());
0154   std::copy(allBackward.begin(), allBackward.end(), back_inserter(allEndcap));
0155   std::reverse(allEndcap.begin(), allEndcap.end());
0156   std::copy(allForward.begin(), allForward.end(), back_inserter(allEndcap));
0157 
0158   // allDetLayers: order is  all bw, all barrel, all fw
0159   allDetLayers.reserve(allBackward.size() + allBarrel.size() + allForward.size());
0160   std::copy(allBackward.begin(), allBackward.end(), back_inserter(allDetLayers));
0161   std::reverse(allDetLayers.begin(), allDetLayers.end());
0162   std::copy(allBarrel.begin(), allBarrel.end(), back_inserter(allDetLayers));
0163   std::copy(allForward.begin(), allForward.end(), back_inserter(allDetLayers));
0164 
0165   // number layers
0166   int sq = 0;
0167   for (auto l : allDetLayers)
0168     (*const_cast<DetLayer*>(l)).setSeqNum(sq++);
0169 }