Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-01 07:56:33

0001 // Copyright 2022, David Lawrence
0002 // Subject to the terms in the LICENSE file found in the top-level directory.
0003 //
0004 //
0005 
0006 #include "ACTSGeo_service.h"
0007 
0008 #include <Acts/Visualization/ViewConfig.hpp>
0009 #include <JANA/JApplication.h>
0010 #include <JANA/JException.h>
0011 #include <array>
0012 #include <exception>
0013 #include <gsl/pointers>
0014 #include <stdexcept>
0015 #include <string>
0016 
0017 #include "ActsGeometryProvider.h"
0018 #include "services/geometry/dd4hep/DD4hep_service.h"
0019 #include "services/log/Log_service.h"
0020 
0021 // Virtual destructor implementation to pin vtable and typeinfo to this
0022 // translation unit
0023 ACTSGeo_service::~ACTSGeo_service() = default;
0024 
0025 //----------------------------------------------------------------
0026 // detector
0027 //
0028 /// Return pointer to the dd4hep::Detector object.
0029 /// Call Initialize if needed.
0030 //----------------------------------------------------------------
0031 std::shared_ptr<const ActsGeometryProvider> ACTSGeo_service::actsGeoProvider() {
0032 
0033   try {
0034     std::call_once(m_init_flag, [this]() {
0035       // Assemble everything on the first call
0036 
0037       if (m_dd4hepGeo == nullptr) {
0038         throw JException("ACTSGeo_service m_dd4hepGeo==null which should never be!");
0039       }
0040 
0041       // Get material map from user parameter
0042       std::string material_map_file;
0043       try {
0044         material_map_file = m_dd4hepGeo->constant<std::string>("material-map");
0045       } catch (const std::runtime_error& e) {
0046         material_map_file = "calibrations/materials-map.cbor";
0047       }
0048       m_app->SetDefaultParameter("acts:MaterialMap", material_map_file,
0049                                  "JSON/CBOR material map file path");
0050 
0051       // Reading the geometry may take a long time and if the JANA ticker is enabled, it will keep printing
0052       // while no other output is coming which makes it look like something is wrong. Disable the ticker
0053       // while parsing and loading the geometry
0054       auto tickerEnabled = m_app->IsTickerEnabled();
0055       m_app->SetTicker(false);
0056 
0057       // Create default m_acts_provider
0058       m_acts_provider = std::make_shared<ActsGeometryProvider>();
0059 
0060       // Set ActsGeometryProvider parameters
0061       bool objWriteIt = m_acts_provider->getObjWriteIt();
0062       bool plyWriteIt = m_acts_provider->getPlyWriteIt();
0063       m_app->SetDefaultParameter("acts:WriteObj", objWriteIt,
0064                                  "Write tracking geometry as obj files");
0065       m_app->SetDefaultParameter("acts:WritePly", plyWriteIt,
0066                                  "Write tracking geometry as ply files");
0067       m_acts_provider->setObjWriteIt(objWriteIt);
0068       m_acts_provider->setPlyWriteIt(plyWriteIt);
0069 
0070       std::string outputTag = m_acts_provider->getOutputTag();
0071       std::string outputDir = m_acts_provider->getOutputDir();
0072       m_app->SetDefaultParameter("acts:OutputTag", outputTag, "Obj and ply output file tag");
0073       m_app->SetDefaultParameter("acts:OutputDir", outputDir, "Obj and ply output file dir");
0074       m_acts_provider->setOutputTag(outputTag);
0075       m_acts_provider->setOutputDir(outputDir);
0076 
0077 #if Acts_VERSION_MAJOR >= 37
0078       std::array<int, 3> containerView = m_acts_provider->getContainerView().color.rgb;
0079       std::array<int, 3> volumeView    = m_acts_provider->getVolumeView().color.rgb;
0080       std::array<int, 3> sensitiveView = m_acts_provider->getSensitiveView().color.rgb;
0081       std::array<int, 3> passiveView   = m_acts_provider->getPassiveView().color.rgb;
0082       std::array<int, 3> gridView      = m_acts_provider->getGridView().color.rgb;
0083 #else
0084             std::array<int,3> containerView = m_acts_provider->getContainerView().color;
0085             std::array<int,3> volumeView = m_acts_provider->getVolumeView().color;
0086             std::array<int,3> sensitiveView = m_acts_provider->getSensitiveView().color;
0087             std::array<int,3> passiveView = m_acts_provider->getPassiveView().color;
0088             std::array<int,3> gridView = m_acts_provider->getGridView().color;
0089 #endif
0090       m_app->SetDefaultParameter("acts:ContainerView", containerView, "RGB for container views");
0091       m_app->SetDefaultParameter("acts:VolumeView", volumeView, "RGB for volume views");
0092       m_app->SetDefaultParameter("acts:SensitiveView", sensitiveView, "RGB for sensitive views");
0093       m_app->SetDefaultParameter("acts:PassiveView", passiveView, "RGB for passive views");
0094       m_app->SetDefaultParameter("acts:GridView", gridView, "RGB for grid views");
0095       m_acts_provider->setContainerView(containerView);
0096       m_acts_provider->setVolumeView(volumeView);
0097       m_acts_provider->setSensitiveView(sensitiveView);
0098       m_acts_provider->setPassiveView(passiveView);
0099       m_acts_provider->setGridView(gridView);
0100 
0101       // Initialize m_acts_provider
0102       m_acts_provider->initialize(m_dd4hepGeo, material_map_file, m_log, m_log);
0103 
0104       // Enable ticker back
0105       m_app->SetTicker(tickerEnabled);
0106     });
0107   } catch (std::exception& ex) {
0108     throw JException(ex.what());
0109   }
0110 
0111   return m_acts_provider;
0112 }
0113 
0114 void ACTSGeo_service::acquire_services(JServiceLocator* srv_locator) {
0115 
0116   auto log_service = srv_locator->get<Log_service>();
0117   m_log            = log_service->logger("acts");
0118 
0119   // DD4Hep geometry
0120   auto dd4hep_service = srv_locator->get<DD4hep_service>();
0121   m_dd4hepGeo         = dd4hep_service->detector();
0122 }