Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:50:15

0001 #include "Geometry/VeryForwardGeometryBuilder/interface/DetGeomDescBuilder.h"
0002 
0003 #include "DataFormats/CTPPSDetId/interface/CTPPSDetId.h"
0004 #include "DetectorDescription/DDCMS/interface/DDDetector.h"
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 
0007 /*
0008  * Generic function to build geo (tree of DetGeomDesc) from old DD compact view.
0009  */
0010 std::unique_ptr<DetGeomDesc> detgeomdescbuilder::buildDetGeomDescFromCompactView(const DDCompactView& myCompactView,
0011                                                                                  const bool isRun2) {
0012   // Create DDFilteredView (no filter!!)
0013   DDPassAllFilter filter;
0014   DDFilteredView fv(myCompactView, filter);
0015 
0016   // Geo info: root node.
0017   auto geoInfoRoot = std::make_unique<DetGeomDesc>(fv, isRun2);
0018 
0019   // Construct the tree of children geo info (DetGeomDesc).
0020   detgeomdescbuilder::buildDetGeomDescDescendants(fv, geoInfoRoot.get(), isRun2);
0021 
0022   edm::LogInfo("PPSGeometryESProducer") << "Successfully built geometry.";
0023 
0024   return geoInfoRoot;
0025 }
0026 
0027 /*
0028  * Depth-first search recursion.
0029  * Construct the tree of children geo info (DetGeomDesc) (old DD).
0030  */
0031 void detgeomdescbuilder::buildDetGeomDescDescendants(DDFilteredView& fv, DetGeomDesc* geoInfo, const bool isRun2) {
0032   // Leaf
0033   if (!fv.firstChild())
0034     return;
0035 
0036   do {
0037     // Create node
0038     DetGeomDesc* child = new DetGeomDesc(fv, isRun2);
0039 
0040     // legacy Run2 z sign fix for diamond detectors
0041     const auto& detId = child->geographicalID();
0042     if (isRun2 && detId.subdetId() == CTPPSDetId::sdTimingDiamond)
0043       child->invertZSign();
0044 
0045     // add the to the geoInfoParent's list.
0046     geoInfo->addComponent(child);
0047 
0048     // Recursion
0049     buildDetGeomDescDescendants(fv, child, isRun2);
0050   } while (fv.nextSibling());
0051 
0052   fv.parent();
0053 }
0054 
0055 /*
0056  * Generic function to build geo (tree of DetGeomDesc) from DD4hep compact view.
0057  */
0058 std::unique_ptr<DetGeomDesc> detgeomdescbuilder::buildDetGeomDescFromCompactView(
0059     const cms::DDCompactView& myCompactView, const bool isRun2) {
0060   // create DDFilteredView (no filter!!)
0061   const cms::DDDetector* mySystem = myCompactView.detector();
0062   const dd4hep::Volume& worldVolume = mySystem->worldVolume();
0063   cms::DDFilteredView fv(mySystem, worldVolume);
0064   if (fv.next(0) == false) {
0065     edm::LogError("PPSGeometryESProducer") << "Filtered view is empty. Cannot build.";
0066   }
0067 
0068   // Geo info: root node.
0069   auto geoInfoRoot = std::make_unique<DetGeomDesc>(fv, isRun2);
0070 
0071   // Construct the tree of children geo info (DetGeomDesc).
0072   do {
0073     // Create node
0074     DetGeomDesc* child = new DetGeomDesc(fv, isRun2);
0075 
0076     // legacy Run2 z sign fix for diamond detectors
0077     const auto& detId = child->geographicalID();
0078     if (isRun2 && detId.subdetId() == CTPPSDetId::sdTimingDiamond)
0079       child->invertZSign();
0080 
0081     // add the node to the geoInfoRoot's list.
0082     geoInfoRoot->addComponent(child);
0083   } while (fv.next(0));
0084 
0085   edm::LogInfo("PPSGeometryESProducer") << "Successfully built geometry, it has " << (geoInfoRoot->components()).size()
0086                                         << " DetGeomDesc nodes.";
0087 
0088   return geoInfoRoot;
0089 }