Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-26 05:06:56

0001 #include "DetectorDescription/Core/interface/DDFilteredView.h"
0002 #include "DetectorDescription/DDCMS/interface/DDFilteredView.h"
0003 #include "Geometry/TrackerNumberingBuilder/plugins/CmsDetConstruction.h"
0004 #include "Geometry/TrackerNumberingBuilder/plugins/ExtractStringFromDDD.h"
0005 #include "DataFormats/DetId/interface/DetId.h"
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 #include <memory>
0008 
0009 template <class FilteredView>
0010 void CmsDetConstruction<FilteredView>::buildSmallDetsforGlued(FilteredView& fv,
0011                                                               GeometricDet* mother,
0012                                                               const std::string& attribute) {
0013   auto det = std::make_unique<GeometricDet>(&fv,
0014                                             CmsTrackerLevelBuilder<FilteredView>::theCmsTrackerStringToEnum.type(
0015                                                 ExtractStringFromDDD<FilteredView>::getString(attribute, &fv)));
0016   if (det->stereo()) {
0017     uint32_t temp = 1;
0018     det->setGeographicalID(DetId(temp));
0019   } else {
0020     uint32_t temp = 2;
0021     det->setGeographicalID(DetId(temp));
0022   }
0023 
0024   mother->addComponent(det.release());
0025 }
0026 
0027 template <class FilteredView>
0028 void CmsDetConstruction<FilteredView>::buildSmallDetsforStack(FilteredView& fv,
0029                                                               GeometricDet* mother,
0030                                                               const std::string& attribute) {
0031   auto det = std::make_unique<GeometricDet>(&fv,
0032                                             CmsTrackerLevelBuilder<FilteredView>::theCmsTrackerStringToEnum.type(
0033                                                 ExtractStringFromDDD<FilteredView>::getString(attribute, &fv)));
0034 
0035   if (det->isLowerSensor()) {
0036     uint32_t temp = 1;
0037     det->setGeographicalID(DetId(temp));
0038   } else if (det->isUpperSensor()) {
0039     uint32_t temp = 2;
0040     det->setGeographicalID(DetId(temp));
0041   } else {
0042     edm::LogError("DetConstruction") << " module defined in a Stack but not upper either lower!? ";
0043   }
0044   mother->addComponent(det.release());
0045 }
0046 
0047 template <class FilteredView>
0048 void CmsDetConstruction<FilteredView>::buildSmallDetsfor3D(FilteredView& fv,
0049                                                            GeometricDet* mother,
0050                                                            const std::string& attribute) {
0051   auto det = std::make_unique<GeometricDet>(&fv,
0052                                             CmsTrackerLevelBuilder<FilteredView>::theCmsTrackerStringToEnum.type(
0053                                                 ExtractStringFromDDD<FilteredView>::getString(attribute, &fv)));
0054 
0055   if (det->isFirstSensor()) {
0056     uint32_t temp = 1;
0057     det->setGeographicalID(DetId(temp));
0058   } else if (det->isSecondSensor()) {
0059     uint32_t temp = 2;
0060     det->setGeographicalID(DetId(temp));
0061   } else {
0062     edm::LogError("DetConstruction") << " module defined in a 3D module but not first or second sensor!? ";
0063   }
0064   mother->addComponent(det.release());
0065 }
0066 
0067 /*
0068  * OLD DD.
0069  * Module with 2 sensors: calculate the sensor local ID, and add the sensor to its mother volume (module).
0070  * Module with 1 sensor: just add the sensor to to its mother volume (ladder).
0071  */
0072 template <>
0073 void CmsDetConstruction<DDFilteredView>::buildComponent(DDFilteredView& fv,
0074                                                         GeometricDet* mother,
0075                                                         const std::string& attribute) {
0076   // Mother volume
0077   // Module with 2 sensors: the mother volume is the module volume.
0078   // Module with 1 sensor: the mother volume is the ladder volume.
0079   const std::string& myTopologicalNameInXMLs = ExtractStringFromDDD<DDFilteredView>::getString(attribute, &fv);
0080   const GeometricDet::GDEnumType& myTopologicalType =
0081       CmsTrackerLevelBuilder<DDFilteredView>::theCmsTrackerStringToEnum.type(myTopologicalNameInXMLs);
0082 
0083   auto det = std::make_unique<GeometricDet>(&fv, myTopologicalType);
0084 
0085   const bool isPhase1ModuleWith2Sensors = (myTopologicalType == GeometricDet::mergedDet);
0086   const bool isPhase2ModuleWith2Sensors = (myTopologicalType == GeometricDet::OTPhase2Stack);
0087   const bool isPhase2BarrelModuleWith2Sensors = (myTopologicalType == GeometricDet::ITPhase2Combined);
0088 
0089   // CASE A: MODULE HAS 2 SENSORS
0090   if (isPhase1ModuleWith2Sensors || isPhase2ModuleWith2Sensors || isPhase2BarrelModuleWith2Sensors) {
0091     // Go down in hierarchy: from module to sensor
0092     bool dodets = fv.firstChild();  // very important
0093     while (dodets) {
0094       // PHASE 1 (MERGEDDET)
0095       if (isPhase1ModuleWith2Sensors) {
0096         buildSmallDetsforGlued(fv, det.get(), attribute);
0097       }
0098       // PHASE 2 (STACKDET)
0099       else if (isPhase2ModuleWith2Sensors) {
0100         buildSmallDetsforStack(fv, det.get(), attribute);
0101       } else if (isPhase2BarrelModuleWith2Sensors) {
0102         buildSmallDetsfor3D(fv, det.get(), attribute);
0103       }
0104 
0105       dodets = fv.nextSibling();
0106     }
0107 
0108     fv.parent();
0109   }
0110 
0111   // CASE B: MODULE HAS 1 SENSOR: NOTHING SPECIFIC TO DO
0112   // Indeed, we are not going to sort sensors within module, if there is only 1 sensor!
0113 
0114   // ALL CASES: add sensor to its mother volume (module or ladder).
0115   mother->addComponent(det.release());
0116 }
0117 
0118 /*
0119  * DD4hep.
0120  * Module with 2 sensors: calculate the sensor local ID, and add the sensor to its mother volume (module).
0121  * Module with 1 sensor: just add the sensor to its mother volume (ladder).
0122  */
0123 template <>
0124 void CmsDetConstruction<cms::DDFilteredView>::buildComponent(cms::DDFilteredView& fv,
0125                                                              GeometricDet* mother,
0126                                                              const std::string& attribute) {
0127   // Mother volume
0128   // Module with 2 sensors: the mother volume is the module volume.
0129   // Module with 1 sensor: the mother volume is the ladder volume.
0130   const std::string& myTopologicalNameInXMLs = ExtractStringFromDDD<cms::DDFilteredView>::getString(attribute, &fv);
0131   const GeometricDet::GDEnumType& myTopologicalType =
0132       CmsTrackerLevelBuilder<cms::DDFilteredView>::theCmsTrackerStringToEnum.type(myTopologicalNameInXMLs);
0133   auto det = std::make_unique<GeometricDet>(&fv, myTopologicalType);
0134 
0135   const bool isPhase1ModuleWith2Sensors = (myTopologicalType == GeometricDet::mergedDet);
0136   const bool isPhase2ModuleWith2Sensors = (myTopologicalType == GeometricDet::OTPhase2Stack);
0137   const bool isPhase2BarrelModuleWith2Sensors = (myTopologicalType == GeometricDet::ITPhase2Combined);
0138 
0139   // CASE A: MODULE HAS 2 SENSORS
0140   if (isPhase1ModuleWith2Sensors || isPhase2ModuleWith2Sensors || isPhase2BarrelModuleWith2Sensors) {
0141     // Go down in hierarchy: from module to sensor
0142     if (!fv.firstChild()) {  // very important
0143       edm::LogError("CmsDetConstruction::buildComponent. Cannot go down to sensor volume.");
0144       return;
0145     }
0146 
0147     // This is the sensor hierarchy level
0148     const int sensorHierarchyLevel = fv.level();
0149 
0150     // Loop on all siblings (ie, on all sensors)
0151     while (fv.level() == sensorHierarchyLevel) {
0152       // PHASE 1 (MERGEDDET)
0153       if (isPhase1ModuleWith2Sensors) {
0154         buildSmallDetsforGlued(fv, det.get(), attribute);
0155       }
0156       // PHASE 2 (STACKDET)
0157       else if (isPhase2ModuleWith2Sensors) {
0158         buildSmallDetsforStack(fv, det.get(), attribute);
0159       } else if (isPhase2BarrelModuleWith2Sensors) {
0160         buildSmallDetsfor3D(fv, det.get(), attribute);
0161       }
0162 
0163       // Go to the next volume in FilteredView.
0164       // NB: If this volume is another sensor of the same module, will stay in the loop.
0165       // Otherwise, it is very important to access the next volume to be treated anyway.
0166       fv.firstChild();
0167     }
0168   }
0169 
0170   // CASE B: MODULE HAS 1 SENSOR: NOTHING SPECIFIC TO DO
0171   // Indeed, we are not going to sort sensors within module, if there is only 1 sensor!
0172   else {
0173     // Go to the next volume in FilteredView.
0174     fv.firstChild();
0175   }
0176 
0177   // ALL CASES: add sensor to its mother volume (module or ladder).
0178   mother->addComponent(det.release());
0179 }