File indexing completed on 2024-04-06 12:15:29
0001 #include "Geometry/TrackerNumberingBuilder/plugins/CmsTrackerPhase2TPDiskBuilder.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/CmsTrackerPanelBuilder.h"
0007 #include "DataFormats/DetId/interface/DetId.h"
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 #include <vector>
0010 #include <algorithm>
0011
0012 using namespace std;
0013
0014 template <class FilteredView>
0015 bool CmsTrackerPhase2TPDiskBuilder<FilteredView>::PhiSort(const GeometricDet* Panel1, const GeometricDet* Panel2) {
0016 return (Panel1->phi() < Panel2->phi());
0017 }
0018
0019 template <class FilteredView>
0020 void CmsTrackerPhase2TPDiskBuilder<FilteredView>::PhiPosNegSplit_innerOuter(
0021 std::vector<GeometricDet const*>::iterator begin, std::vector<GeometricDet const*>::iterator end) {
0022
0023 std::sort(begin, end, PhiSort);
0024
0025
0026 std::vector<const GeometricDet*> theCompsPosNeg;
0027
0028 double theRmin = (**begin).rho();
0029 double theRmax = theRmin;
0030 for (vector<const GeometricDet*>::const_iterator it = begin; it != end; it++) {
0031 if ((**it).phi() >= 0)
0032 theCompsPosNeg.emplace_back(*it);
0033 theRmin = std::min(theRmin, (**it).rho());
0034 theRmax = std::max(theRmax, (**it).rho());
0035 }
0036 for (vector<const GeometricDet*>::const_iterator it = begin; it != end; it++) {
0037 if ((**it).phi() < 0)
0038 theCompsPosNeg.emplace_back(*it);
0039 }
0040
0041
0042
0043
0044 double radius_split = 100.;
0045 std::vector<const GeometricDet*> theCompsInnerOuter;
0046 unsigned int num_inner = 0;
0047 for (vector<const GeometricDet*>::const_iterator it = theCompsPosNeg.begin(); it != theCompsPosNeg.end(); it++) {
0048 if ((**it).rho() <= radius_split) {
0049 theCompsInnerOuter.emplace_back(*it);
0050 num_inner++;
0051 }
0052 }
0053
0054 for (vector<const GeometricDet*>::const_iterator it = theCompsPosNeg.begin(); it != theCompsPosNeg.end(); it++) {
0055 if ((**it).rho() > radius_split)
0056 theCompsInnerOuter.emplace_back(*it);
0057 }
0058
0059
0060
0061 std::rotate(
0062 theCompsInnerOuter.begin() + num_inner, theCompsInnerOuter.begin() + num_inner + 1, theCompsInnerOuter.end());
0063 std::copy(theCompsInnerOuter.begin(), theCompsInnerOuter.end(), begin);
0064 }
0065
0066 template <class FilteredView>
0067 void CmsTrackerPhase2TPDiskBuilder<FilteredView>::buildComponent(FilteredView& fv,
0068 GeometricDet* g,
0069 const std::string& s) {
0070 CmsTrackerPanelBuilder<FilteredView> theCmsTrackerPanelBuilder;
0071 GeometricDet* subdet = new GeometricDet(&fv,
0072 CmsTrackerLevelBuilder<FilteredView>::theCmsTrackerStringToEnum.type(
0073 ExtractStringFromDDD<FilteredView>::getString(s, &fv)));
0074
0075 switch (CmsTrackerLevelBuilder<FilteredView>::theCmsTrackerStringToEnum.type(
0076 ExtractStringFromDDD<FilteredView>::getString(s, &fv))) {
0077 case GeometricDet::panel:
0078 theCmsTrackerPanelBuilder.build(fv, subdet, s);
0079 break;
0080 default:
0081 edm::LogError("CmsTrackerPhase2TPDiskBuilder")
0082 << " ERROR - I was expecting a Panel, I got a " << ExtractStringFromDDD<FilteredView>::getString(s, &fv);
0083 }
0084 g->addComponent(subdet);
0085 }
0086
0087 template <class FilteredView>
0088 void CmsTrackerPhase2TPDiskBuilder<FilteredView>::sortNS(FilteredView& fv, GeometricDet* det) {
0089 GeometricDet::ConstGeometricDetContainer& comp = det->components();
0090
0091 switch (det->components().front()->type()) {
0092 case GeometricDet::panel:
0093 PhiPosNegSplit_innerOuter(comp.begin(), comp.end());
0094 break;
0095 default:
0096 edm::LogError("CmsTrackerPhase2TPDiskBuilder")
0097 << "ERROR - wrong SubDet to sort..... " << det->components().front()->type();
0098 }
0099
0100 GeometricDet::GeometricDetContainer zminpanels;
0101 GeometricDet::GeometricDetContainer zmaxpanels;
0102
0103 uint32_t totalblade = comp.size() / 2;
0104
0105
0106 zminpanels.reserve(totalblade);
0107 zmaxpanels.reserve(totalblade);
0108 for (uint32_t j = 0; j < totalblade; j++) {
0109 if (std::abs(comp[2 * j]->translation().z()) > std::abs(comp[2 * j + 1]->translation().z())) {
0110 zmaxpanels.emplace_back(det->component(2 * j));
0111 zminpanels.emplace_back(det->component(2 * j + 1));
0112
0113 } else if (std::abs(comp[2 * j]->translation().z()) < std::abs(comp[2 * j + 1]->translation().z())) {
0114 zmaxpanels.emplace_back(det->component(2 * j + 1));
0115 zminpanels.emplace_back(det->component(2 * j));
0116 } else {
0117 edm::LogWarning("CmsTrackerPhase2TPDiskBuilder") << "WARNING - The Z of both panels are equal! ";
0118 }
0119 }
0120
0121 for (uint32_t fn = 0; fn < zminpanels.size(); fn++) {
0122 uint32_t blade = fn + 1;
0123 uint32_t panel = 1;
0124 uint32_t temp = (blade << 2) | panel;
0125 zminpanels[fn]->setGeographicalID(temp);
0126 }
0127
0128 for (uint32_t bn = 0; bn < zmaxpanels.size(); bn++) {
0129 uint32_t blade = bn + 1;
0130 uint32_t panel = 2;
0131 uint32_t temp = (blade << 2) | panel;
0132 zmaxpanels[bn]->setGeographicalID(temp);
0133 }
0134
0135 det->clearComponents();
0136 det->addComponents(zminpanels);
0137 det->addComponents(zmaxpanels);
0138 }
0139
0140 template class CmsTrackerPhase2TPDiskBuilder<DDFilteredView>;
0141 template class CmsTrackerPhase2TPDiskBuilder<cms::DDFilteredView>;