Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:49:08

0001 #include "Geometry/TrackerNumberingBuilder/plugins/CmsTrackerLayerBuilder.h"
0002 #include "DetectorDescription/Core/interface/DDFilteredView.h"
0003 #include "DetectorDescription/DDCMS/interface/DDFilteredView.h"
0004 #include "Geometry/TrackerNumberingBuilder/interface/GeometricDet.h"
0005 #include "Geometry/TrackerNumberingBuilder/plugins/ExtractStringFromDDD.h"
0006 #include "Geometry/TrackerNumberingBuilder/plugins/CmsTrackerStringBuilder.h"
0007 #include "Geometry/TrackerNumberingBuilder/plugins/CmsTrackerRodBuilder.h"
0008 #include "Geometry/TrackerNumberingBuilder/plugins/CmsTrackerLadderBuilder.h"
0009 #include "Geometry/TrackerNumberingBuilder/interface/trackerStablePhiSort.h"
0010 #include "DataFormats/DetId/interface/DetId.h"
0011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0012 
0013 #include <vector>
0014 #include <bitset>
0015 
0016 template <class FilteredView>
0017 void CmsTrackerLayerBuilder<FilteredView>::buildComponent(FilteredView& fv, GeometricDet* g, const std::string& s) {
0018   CmsTrackerStringBuilder<FilteredView> theCmsTrackerStringBuilder;
0019   CmsTrackerRodBuilder<FilteredView> theCmsTrackerRodBuilder;
0020   CmsTrackerLadderBuilder<FilteredView> theCmsTrackerLadderBuilder;
0021 
0022   GeometricDet* subdet = new GeometricDet(&fv,
0023                                           CmsTrackerLevelBuilder<FilteredView>::theCmsTrackerStringToEnum.type(
0024                                               ExtractStringFromDDD<FilteredView>::getString(s, &fv)));
0025   switch (CmsTrackerLevelBuilder<FilteredView>::theCmsTrackerStringToEnum.type(
0026       ExtractStringFromDDD<FilteredView>::getString(s, &fv))) {
0027     case GeometricDet::strng:
0028       theCmsTrackerStringBuilder.build(fv, subdet, s);
0029       break;
0030     case GeometricDet::rod:
0031       theCmsTrackerRodBuilder.build(fv, subdet, s);
0032       break;
0033     case GeometricDet::ladder:
0034       theCmsTrackerLadderBuilder.build(fv, subdet, s);
0035       break;
0036     default:
0037       edm::LogError("CmsTrackerLayerBuilder") << " ERROR - I was expecting a String, Rod or Ladder, I got a "
0038                                               << ExtractStringFromDDD<FilteredView>::getString(s, &fv);
0039   }
0040   g->addComponent(subdet);
0041 }
0042 
0043 template <class FilteredView>
0044 void CmsTrackerLayerBuilder<FilteredView>::sortNS(FilteredView& fv, GeometricDet* det) {
0045   GeometricDet::ConstGeometricDetContainer& comp = det->components();
0046 
0047   // TIB
0048   // SubDetector Side: 2 bits [TIB-:1 TIB+:2]
0049   // Layer Part      : 2 bits [internal:1 external:0]
0050   // String Number   : 6 bits [1,...,56 (at most)]
0051   //
0052   if (comp.front()->type() == GeometricDet::strng) {
0053     float layerRadius = (det->params()[2] + det->params()[1]) / 2.;
0054 
0055     GeometricDet::GeometricDetContainer neg;
0056     GeometricDet::GeometricDetContainer pos;
0057     GeometricDet::GeometricDetContainer extneg;
0058     GeometricDet::GeometricDetContainer intneg;
0059     GeometricDet::GeometricDetContainer extpos;
0060     GeometricDet::GeometricDetContainer intpos;
0061     neg.clear();
0062     pos.clear();
0063     extneg.clear();
0064     intneg.clear();
0065     extpos.clear();
0066     intpos.clear();
0067 
0068     for (size_t i = 0; i < comp.size(); ++i) {
0069       auto component = det->component(i);
0070       if (component->translation().z() < 0.) {
0071         neg.emplace_back(component);
0072       } else {
0073         pos.emplace_back(component);
0074       }
0075     }
0076 
0077     for (auto& i : neg) {
0078       double rPos = i->translation().Rho();
0079       if (rPos > layerRadius) {
0080         extneg.emplace_back(i);
0081       } else {
0082         intneg.emplace_back(i);
0083       }
0084     }
0085 
0086     for (auto& po : pos) {
0087       double rPos = po->translation().Rho();
0088       if (rPos > layerRadius) {
0089         extpos.emplace_back(po);
0090       } else {
0091         intpos.emplace_back(po);
0092       }
0093     }
0094 
0095     trackerStablePhiSort(extneg.begin(), extneg.end(), CmsTrackerLevelBuilderHelper::getPhi);
0096     trackerStablePhiSort(extpos.begin(), extpos.end(), CmsTrackerLevelBuilderHelper::getPhi);
0097     trackerStablePhiSort(intneg.begin(), intneg.end(), CmsTrackerLevelBuilderHelper::getPhi);
0098     trackerStablePhiSort(intpos.begin(), intpos.end(), CmsTrackerLevelBuilderHelper::getPhi);
0099 
0100     for (uint32_t i = 0; i < intneg.size(); i++) {
0101       uint32_t temp = i + 1;
0102       temp |= (1 << 8);  // 1 : SubDetector Side TIB-
0103       temp |= (1 << 6);  // 1 : Layer Part int
0104       intneg[i]->setGeographicalID(DetId(temp));
0105     }
0106 
0107     for (uint32_t i = 0; i < extneg.size(); i++) {
0108       uint32_t temp = i + 1;
0109       temp |= (1 << 8);  // 1 : SubDetector Side TIB-
0110       temp |= (2 << 6);  // 2 : Layer Part ext
0111       extneg[i]->setGeographicalID(DetId(temp));
0112     }
0113 
0114     for (uint32_t i = 0; i < intpos.size(); i++) {
0115       uint32_t temp = i + 1;
0116       temp |= (2 << 8);  // 2 : SubDetector Side TIB+
0117       temp |= (1 << 6);  // 1 : Layer Part int
0118       intpos[i]->setGeographicalID(DetId(temp));
0119     }
0120 
0121     for (uint32_t i = 0; i < extpos.size(); i++) {
0122       uint32_t temp = i + 1;
0123       temp |= (2 << 8);  // 2 : SubDetector Side TIB+
0124       temp |= (2 << 6);  // 2 : Layer Part ext
0125       extpos[i]->setGeographicalID(DetId(temp));
0126     }
0127 
0128     det->clearComponents();
0129     det->addComponents(intneg);
0130     det->addComponents(extneg);
0131     det->addComponents(intpos);
0132     det->addComponents(extpos);
0133 
0134   } else if (comp.front()->type() == GeometricDet::rod) {
0135     GeometricDet::GeometricDetContainer neg;
0136     GeometricDet::GeometricDetContainer pos;
0137     neg.clear();
0138     pos.clear();
0139 
0140     for (size_t i = 0; i < comp.size(); ++i) {
0141       auto component = det->component(i);
0142       if (component->translation().z() < 0.) {
0143         neg.emplace_back(component);
0144       } else {
0145         pos.emplace_back(component);
0146       }
0147     }
0148 
0149     trackerStablePhiSort(neg.begin(), neg.end(), CmsTrackerLevelBuilderHelper::getPhi);
0150     trackerStablePhiSort(pos.begin(), pos.end(), CmsTrackerLevelBuilderHelper::getPhi);
0151 
0152     for (uint32_t i = 0; i < neg.size(); i++) {
0153       uint32_t temp = i + 1;
0154       temp |= (1 << 7);
0155       neg[i]->setGeographicalID(DetId(temp));
0156     }
0157 
0158     for (uint32_t i = 0; i < pos.size(); i++) {
0159       uint32_t temp = i + 1;
0160       temp |= (2 << 7);
0161       pos[i]->setGeographicalID(DetId(temp));
0162     }
0163 
0164     det->clearComponents();
0165     det->addComponents(neg);
0166     det->addComponents(pos);
0167 
0168   } else if (det->components().front()->type() == GeometricDet::ladder) {
0169     trackerStablePhiSort(comp.begin(), comp.end(), CmsTrackerLevelBuilderHelper::getPhi);
0170 
0171     for (uint32_t i = 0; i < comp.size(); i++) {
0172       det->component(i)->setGeographicalID(DetId(i + 1));
0173     }
0174 
0175   } else {
0176     edm::LogError("CmsTrackerLayerBuilder")
0177         << "ERROR - wrong SubDet to sort..... " << det->components().front()->type();
0178   }
0179 }
0180 
0181 template class CmsTrackerLayerBuilder<DDFilteredView>;
0182 template class CmsTrackerLayerBuilder<cms::DDFilteredView>;