Project
Loading...
Searching...
No Matches
FastSimRegions.cxx
Go to the documentation of this file.
1// Copyright 2019-2026 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
13
14#include "TG4GeometryManager.h"
15#include "TG4ModelConfigurationManager.h"
16
17#include <TGeoManager.h>
18#include <TGeoMedium.h>
19#include <TGeoNode.h>
20#include <TGeoVolume.h>
21
22#include <fairlogger/Logger.h>
23
24namespace o2::fastsim
25{
26
27namespace
28{
29void collect(TGeoVolume* volume, std::set<std::string>& media, std::set<TGeoVolume*>& seen)
30{
31 if (volume == nullptr || !seen.insert(volume).second) {
32 return; // a volume can be placed many times; visit it once
33 }
34 if (const TGeoMedium* medium = volume->GetMedium()) {
35 media.insert(medium->GetName());
36 }
37 TObjArray* nodes = volume->GetNodes();
38 if (nodes == nullptr) {
39 return;
40 }
41 for (int i = 0; i < nodes->GetEntriesFast(); ++i) {
42 auto* node = static_cast<TGeoNode*>(nodes->UncheckedAt(i));
43 if (node != nullptr) {
44 collect(node->GetVolume(), media, seen);
45 }
46 }
47}
48} // namespace
49
50//_____________________________________________________________________________
51std::set<std::string> mediaInSubtree(TGeoVolume* volume)
52{
53 std::set<std::string> media;
54 std::set<TGeoVolume*> seen;
55 collect(volume, media, seen);
56 return media;
57}
58
59//_____________________________________________________________________________
60std::set<std::string> mediaInSubtree(const std::string& volumeName)
61{
62 if (gGeoManager == nullptr) {
63 LOG(error) << "fast simulation: no TGeo geometry when resolving '" << volumeName << "'";
64 return {};
65 }
66 auto* volume = gGeoManager->GetVolume(volumeName.c_str());
67 if (volume == nullptr) {
68 LOG(error) << "fast simulation: no volume named '" << volumeName << "' in the geometry";
69 return {};
70 }
71 return mediaInSubtree(volume);
72}
73
74//_____________________________________________________________________________
76 : mModels(std::move(models))
77{
78}
79
80//_____________________________________________________________________________
82{
87 auto* manager = TG4GeometryManager::Instance()->GetFastModelsManager();
88
89 for (const auto& model : mModels) {
90 std::string regions = model.regions;
91 if (regions.empty()) {
92 const auto media = mediaInSubtree(model.envelope);
93 for (const auto& medium : media) {
94 // The setter tokenizes on whitespace, so a medium whose name contains a
95 // space cannot go through it. O2 composes medium names as
96 // <MODULE>_<name> and none contain spaces, but say so if that changes
97 // rather than silently selecting the wrong thing.
98 if (medium.find(' ') != std::string::npos) {
99 LOG(warn) << "fast simulation: medium '" << medium << "' contains a space and cannot "
100 << "be selected; it is skipped";
101 continue;
102 }
103 regions += (regions.empty() ? "" : " ") + medium;
104 }
105 LOG(info) << "fast simulation: model " << model.model << " covers " << media.size()
106 << " media found under '" << model.envelope << "'";
107 }
108 if (regions.empty()) {
109 LOG(error) << "fast simulation: model " << model.model << " ended up with no regions";
110 continue;
111 }
112 LOG(debug) << "fast simulation: regions for " << model.model << ": " << regions;
113 manager->SetModelRegions(model.model, regions);
114 }
115}
116
117} // namespace o2::fastsim
std::ostringstream debug
std::unique_ptr< expressions::Node > node
int32_t i
FastSimRegionConstruction(std::vector< ModelRegions > models)
std::set< std::string > mediaInSubtree(TGeoVolume *volume)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"