Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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