Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:15:28

0001 #include "DetectorDescription/Core/interface/DDFilteredView.h"
0002 #include "DetectorDescription/DDCMS/interface/DDFilteredView.h"
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 #include "Geometry/TrackerNumberingBuilder/interface/GeometricDet.h"
0005 #include "Geometry/TrackerNumberingBuilder/plugins/CmsTrackerLevelBuilder.h"
0006 #include "Geometry/TrackerNumberingBuilder/plugins/ExtractStringFromDDD.h"
0007 
0008 #include <cmath>
0009 
0010 #define DEBUG false
0011 
0012 bool CmsTrackerLevelBuilderHelper::subDetByType(const GeometricDet* a, const GeometricDet* b) {
0013   // it relies on the fact that the GeometricDet::GDEnumType enumerators used
0014   // to identify the subdetectors in the upgrade geometries are equal to the
0015   // ones of the present detector + n*100
0016   return a->type() % 100 < b->type() % 100;
0017 }
0018 
0019 // NP** Phase2 BarrelEndcap
0020 bool CmsTrackerLevelBuilderHelper::phiSortNP(const GeometricDet* a, const GeometricDet* b) {
0021   if (std::abs(a->translation().rho() - b->translation().rho()) < 0.01 &&
0022       (std::abs(a->translation().phi() - b->translation().phi()) < 0.01 ||
0023        std::abs(a->translation().phi() - b->translation().phi()) > 6.27) &&
0024       a->translation().z() * b->translation().z() > 0.0) {
0025     return (std::abs(a->translation().z()) < std::abs(b->translation().z()));
0026   } else
0027     return false;
0028 }
0029 
0030 bool CmsTrackerLevelBuilderHelper::isLessZ(const GeometricDet* a, const GeometricDet* b) {
0031   // NP** change for Phase 2 Tracker
0032   if (a->translation().z() == b->translation().z()) {
0033     return a->translation().rho() < b->translation().rho();
0034   } else {
0035     // Original version
0036     return a->translation().z() < b->translation().z();
0037   }
0038 }
0039 
0040 bool CmsTrackerLevelBuilderHelper::isLessModZ(const GeometricDet* a, const GeometricDet* b) {
0041   return std::abs(a->translation().z()) < std::abs(b->translation().z());
0042 }
0043 
0044 double CmsTrackerLevelBuilderHelper::getPhi(const GeometricDet* a) {
0045   double phi = a->phi();
0046   return (phi >= 0 ? phi : phi + 2 * M_PI);
0047 }
0048 
0049 double CmsTrackerLevelBuilderHelper::getPhiModule(const GeometricDet* a) {
0050   std::vector<const GeometricDet*> const& comp = a->components().back()->components();
0051   float phi = 0.;
0052   bool sum = true;
0053 
0054   for (auto i : comp) {
0055     if (std::abs(i->phi()) > M_PI / 2.) {
0056       sum = false;
0057       break;
0058     }
0059   }
0060 
0061   if (sum) {
0062     for (auto i : comp) {
0063       phi += i->phi();
0064     }
0065 
0066     double temp = phi / float(comp.size()) < 0. ? 2 * M_PI + phi / float(comp.size()) : phi / float(comp.size());
0067     return temp;
0068 
0069   } else {
0070     for (auto i : comp) {
0071       double phi1 = i->phi() >= 0 ? i->phi() : i->phi() + 2 * M_PI;
0072       phi += phi1;
0073     }
0074 
0075     double com = comp.front()->phi() >= 0 ? comp.front()->phi() : 2 * M_PI + comp.front()->phi();
0076     double temp =
0077         std::abs(phi / float(comp.size()) - com) > 2. ? M_PI - phi / float(comp.size()) : phi / float(comp.size());
0078     temp = temp >= 0 ? temp : 2 * M_PI + temp;
0079     return temp;
0080   }
0081 }
0082 
0083 double CmsTrackerLevelBuilderHelper::getPhiGluedModule(const GeometricDet* a) {
0084   std::vector<const GeometricDet*> comp;
0085   a->deepComponents(comp);
0086   float phi = 0.;
0087   bool sum = true;
0088 
0089   for (auto& i : comp) {
0090     if (std::abs(i->phi()) > M_PI / 2.) {
0091       sum = false;
0092       break;
0093     }
0094   }
0095 
0096   if (sum) {
0097     for (auto& i : comp) {
0098       phi += i->phi();
0099     }
0100 
0101     double temp = phi / float(comp.size()) < 0. ? 2 * M_PI + phi / float(comp.size()) : phi / float(comp.size());
0102     return temp;
0103 
0104   } else {
0105     for (auto& i : comp) {
0106       double phi1 = i->phi() >= 0 ? i->phi() : i->translation().phi() + 2 * M_PI;
0107       phi += phi1;
0108     }
0109 
0110     double com = comp.front()->phi() >= 0 ? comp.front()->phi() : 2 * M_PI + comp.front()->phi();
0111     double temp =
0112         std::abs(phi / float(comp.size()) - com) > 2. ? M_PI - phi / float(comp.size()) : phi / float(comp.size());
0113     temp = temp >= 0 ? temp : 2 * M_PI + temp;
0114     return temp;
0115   }
0116 }
0117 
0118 double CmsTrackerLevelBuilderHelper::getPhiMirror(const GeometricDet* a) {
0119   double phi = a->phi();
0120   phi = (phi >= 0 ? phi : phi + 2 * M_PI);                              // (-pi,pi] --> [0,2pi)
0121   return ((M_PI - phi) >= 0 ? (M_PI - phi) : (M_PI - phi) + 2 * M_PI);  // (-pi,pi] --> [0,2pi)
0122 }
0123 
0124 double CmsTrackerLevelBuilderHelper::getPhiModuleMirror(const GeometricDet* a) {
0125   double phi = getPhiModule(a);                // [0,2pi)
0126   phi = (phi <= M_PI ? phi : phi - 2 * M_PI);  // (-pi,pi]
0127   return (M_PI - phi);
0128 }
0129 
0130 double CmsTrackerLevelBuilderHelper::getPhiGluedModuleMirror(const GeometricDet* a) {
0131   double phi = getPhiGluedModule(a);           // [0,2pi)
0132   phi = (phi <= M_PI ? phi : phi - 2 * M_PI);  // (-pi,pi]
0133   return (M_PI - phi);
0134 }
0135 
0136 bool CmsTrackerLevelBuilderHelper::isLessRModule(const GeometricDet* a, const GeometricDet* b) {
0137   return a->deepComponents().front()->rho() < b->deepComponents().front()->rho();
0138 }
0139 
0140 bool CmsTrackerLevelBuilderHelper::isLessR(const GeometricDet* a, const GeometricDet* b) { return a->rho() < b->rho(); }
0141 
0142 /*
0143  * Old DD navigation.
0144  */
0145 template <>
0146 void CmsTrackerLevelBuilder<DDFilteredView>::build(DDFilteredView& fv,
0147                                                    GeometricDet* tracker,
0148                                                    const std::string& attribute) {
0149   if (DEBUG) {
0150     edm::LogVerbatim("CmsTrackerLevelBuilder")
0151         << "CmsTrackerLevelBuilder::build called on volume"
0152         << " tracker->name() = " << tracker->name() << " tracker->path() = " << fv.geoHistory()
0153         << " tracker->type() = " << tracker->type();
0154   }
0155 
0156   // Go down one level in hierarchy
0157   bool doLayers = fv.firstChild();
0158 
0159   while (doLayers) {
0160     if (DEBUG) {
0161       edm::LogVerbatim("CmsTrackerLevelBuilder") << "Calling buildComponent, before";
0162     }
0163 
0164     // Call build on sibling
0165     buildComponent(fv, tracker, attribute);
0166 
0167     if (DEBUG) {
0168       edm::LogVerbatim("CmsTrackerLevelBuilder") << "Calling buildComponent, after";
0169     }
0170 
0171     // Go to next sibling
0172     doLayers = fv.nextSibling();
0173   }
0174 
0175   // Come back up
0176   fv.parent();
0177 
0178   // Now that all GeometricDets of a given hierarchy level are built, sort them!
0179   sortNS(fv, tracker);
0180 
0181   if (DEBUG) {
0182     edm::LogVerbatim("CmsTrackerLevelBuilder")
0183         << "CmsTrackerLevelBuilder::build: Exit, finished all buildComponents calls.";
0184   }
0185 }
0186 
0187 /*
0188  * DD4hep navigation.
0189  */
0190 template <>
0191 void CmsTrackerLevelBuilder<cms::DDFilteredView>::build(cms::DDFilteredView& fv,
0192                                                         GeometricDet* tracker,
0193                                                         const std::string& attribute) {
0194   if (DEBUG) {
0195     edm::LogVerbatim("CmsTrackerLevelBuilder")
0196         << "CmsTrackerLevelBuilder::build called on volume"
0197         << " tracker->name() = " << tracker->name() << " tracker->path() = " << fv.geoHistory()
0198         << " tracker->type() = " << tracker->type();
0199   }
0200 
0201   // Go down one level in hierarchy
0202   fv.firstChild();
0203 
0204   // This is the siblings hierarchy level
0205   const int level = fv.level();
0206   const std::string& type = ExtractStringFromDDD<cms::DDFilteredView>::getString(attribute, &fv);
0207 
0208   // Treat all siblings of a given hierarchy level
0209   while (fv.level() == level) {
0210     if (DEBUG) {
0211       edm::LogVerbatim("CmsTrackerLevelBuilder")
0212           << "Calling buildComponent, before."
0213           << " level = " << level << " type = " << type << " fv.level() = " << fv.level()
0214           << " fv.type() = " << ExtractStringFromDDD<cms::DDFilteredView>::getString(attribute, &fv);
0215     }
0216 
0217     // Call build on sibling
0218     buildComponent(fv, tracker, attribute);
0219 
0220     if (DEBUG) {
0221       edm::LogVerbatim("CmsTrackerLevelBuilder")
0222           << "Calling buildComponent, after."
0223           << " level = " << level << " type = " << type << " fv.level() = " << fv.level()
0224           << " fv.type() = " << ExtractStringFromDDD<cms::DDFilteredView>::getString(attribute, &fv);
0225     }
0226   }
0227 
0228   // Now that all GeometricDets of a given hierarchy level are built, sort them!
0229   sortNS(fv, tracker);
0230 
0231   if (DEBUG) {
0232     edm::LogVerbatim("CmsTrackerLevelBuilder")
0233         << "CmsTrackerLevelBuilder::build: Exit, finished all buildComponents calls.";
0234   }
0235 }
0236 
0237 template class CmsTrackerLevelBuilder<DDFilteredView>;
0238 template class CmsTrackerLevelBuilder<cms::DDFilteredView>;