Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "Geometry/TrackerNumberingBuilder/plugins/CmsTrackerPhase1DiskBuilder.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 CmsTrackerPhase1DiskBuilder<FilteredView>::PhiSort(const GeometricDet* Panel1, const GeometricDet* Panel2) {
0016   return (Panel1->phi() < Panel2->phi());
0017 }
0018 
0019 template <class FilteredView>
0020 void CmsTrackerPhase1DiskBuilder<FilteredView>::PhiPosNegSplit_innerOuter(
0021     std::vector<GeometricDet const*>::iterator begin, std::vector<GeometricDet const*>::iterator end) {
0022   // first sort in phi, lowest first (-pi to +pi)
0023   std::sort(begin, end, PhiSort);
0024 
0025   // now put positive phi (in order) ahead of negative phi as in std geometry
0026   std::vector<const GeometricDet*> theCompsPosNeg;
0027   // also find the average radius (used to split inner and outer disk panels)
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   // now put inner disk panels first
0042   //  double radius_split = 0.5 * (theRmin + theRmax);
0043   // force the split radius to be 100 mm to be able to deal with disks with only outer ring
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   //  std::cout << "num of inner = " << num_inner << " with radius less than " << radius_split << std::endl;
0059   // now shift outer by one
0060 
0061   if (num_inner < theCompsInnerOuter.size()) {
0062     std::rotate(theCompsInnerOuter.begin() + num_inner, theCompsInnerOuter.end() - 1, theCompsInnerOuter.end());
0063   }
0064   if (num_inner > 0) {
0065     std::rotate(
0066         theCompsInnerOuter.begin(), theCompsInnerOuter.begin() + num_inner - 1, theCompsInnerOuter.begin() + num_inner);
0067   }
0068 
0069   if (num_inner == 0) {
0070     edm::LogError(
0071         "CmsTrackerPhase1DiskBuilder. num_inner == 0. The split of modules by radius is probably not doing what you "
0072         "expect: inner-radius group is empty.");
0073   }
0074   if (num_inner == theCompsInnerOuter.size()) {
0075     edm::LogError(
0076         "CmsTrackerPhase1DiskBuilder. num_inner == theCompsInnerOuter.size(). The split of modules by radius is "
0077         "probably not doing what you expect: outer-radius group is empty.");
0078   }
0079 
0080   std::copy(theCompsInnerOuter.begin(), theCompsInnerOuter.end(), begin);
0081 }
0082 
0083 template <class FilteredView>
0084 void CmsTrackerPhase1DiskBuilder<FilteredView>::buildComponent(FilteredView& fv,
0085                                                                GeometricDet* g,
0086                                                                const std::string& s) {
0087   CmsTrackerPanelBuilder<FilteredView> theCmsTrackerPanelBuilder;
0088   GeometricDet* subdet = new GeometricDet(&fv,
0089                                           CmsTrackerLevelBuilder<FilteredView>::theCmsTrackerStringToEnum.type(
0090                                               ExtractStringFromDDD<FilteredView>::getString(s, &fv)));
0091 
0092   switch (CmsTrackerLevelBuilder<FilteredView>::theCmsTrackerStringToEnum.type(
0093       ExtractStringFromDDD<FilteredView>::getString(s, &fv))) {
0094     case GeometricDet::panel:
0095       theCmsTrackerPanelBuilder.build(fv, subdet, s);
0096       break;
0097     default:
0098       edm::LogError("CmsTrackerPhase1DiskBuilder")
0099           << " ERROR - I was expecting a Panel, I got a " << ExtractStringFromDDD<FilteredView>::getString(s, &fv);
0100   }
0101   g->addComponent(subdet);
0102 }
0103 
0104 template <class FilteredView>
0105 void CmsTrackerPhase1DiskBuilder<FilteredView>::sortNS(FilteredView& fv, GeometricDet* det) {
0106   GeometricDet::ConstGeometricDetContainer& comp = det->components();
0107 
0108   switch (det->components().front()->type()) {
0109     case GeometricDet::panel:
0110       PhiPosNegSplit_innerOuter(comp.begin(), comp.end());
0111       break;
0112     default:
0113       edm::LogError("CmsTrackerPhase1DiskBuilder")
0114           << "ERROR - wrong SubDet to sort..... " << det->components().front()->type();
0115   }
0116 
0117   GeometricDet::GeometricDetContainer zminpanels;  // Here z refers abs(z);
0118   GeometricDet::GeometricDetContainer zmaxpanels;  // So, zmin panel is always closer to ip.
0119 
0120   uint32_t totalblade = comp.size() / 2;
0121   //  std::cout << "pixel_disk " << pixel_disk << endl;
0122 
0123   zminpanels.reserve(totalblade);
0124   zmaxpanels.reserve(totalblade);
0125   for (uint32_t j = 0; j < totalblade; j++) {
0126     if (std::abs(comp[2 * j]->translation().z()) > std::abs(comp[2 * j + 1]->translation().z())) {
0127       zmaxpanels.emplace_back(det->component(2 * j));
0128       zminpanels.emplace_back(det->component(2 * j + 1));
0129 
0130     } else if (std::abs(comp[2 * j]->translation().z()) < std::abs(comp[2 * j + 1]->translation().z())) {
0131       zmaxpanels.emplace_back(det->component(2 * j + 1));
0132       zminpanels.emplace_back(det->component(2 * j));
0133     } else {
0134       edm::LogWarning("CmsTrackerPhase1DiskBuilder") << "WARNING - The Z of  both panels are equal! ";
0135     }
0136   }
0137 
0138   for (uint32_t fn = 0; fn < zminpanels.size(); fn++) {
0139     uint32_t blade = fn + 1;
0140     uint32_t panel = 2;  // though being zmin, it is actually the one facing away the ip
0141     uint32_t temp = (blade << 2) | panel;
0142     zminpanels[fn]->setGeographicalID(temp);
0143   }
0144 
0145   for (uint32_t bn = 0; bn < zmaxpanels.size(); bn++) {
0146     uint32_t blade = bn + 1;
0147     uint32_t panel = 1;  // though being zmax, it is the one facing the ip
0148     uint32_t temp = (blade << 2) | panel;
0149     zmaxpanels[bn]->setGeographicalID(temp);
0150   }
0151 
0152   det->clearComponents();
0153   det->addComponents(zminpanels);
0154   det->addComponents(zmaxpanels);
0155 }
0156 
0157 template class CmsTrackerPhase1DiskBuilder<DDFilteredView>;
0158 template class CmsTrackerPhase1DiskBuilder<cms::DDFilteredView>;