Geant4 VMC Version 6.6
Loading...
Searching...
No Matches
TG4BiasingManager.cxx
Go to the documentation of this file.
1//------------------------------------------------
2// The Geant4 Virtual Monte Carlo package
3// Copyright (C) 2007 - 2019 Ivana Hrivnacova
4// All rights reserved.
5//
6// For the licensing terms see geant4_vmc/LICENSE.
7// Contact: root-vmc@cern.ch
8//-------------------------------------------------
9
14
15#include "TG4BiasingManager.h"
16#include "TG4BiasingOperator.h"
18
19#include <G4AnalysisUtilities.hh>
20#include <G4LogicalVolume.hh>
21#include <G4LogicalVolumeStore.hh>
22#include <G4Material.hh>
23
24#ifdef G4MULTITHREADED
25namespace
26{
27// Mutex to lock creating regions
28G4Mutex createBiasingOperatorMutex = G4MUTEX_INITIALIZER;
29} // namespace
30#endif
31
32//_____________________________________________________________________________
34 const G4String& name, const G4String& availableModels)
35 : TG4ModelConfigurationManager(name, availableModels)
36{
38
39 if (VerboseLevel() > 1) {
40 G4cout << "TG4BiasingManager::TG4BiasingManager" << G4endl;
41 }
42}
43
44//_____________________________________________________________________________
49
50//
51// public methods
52//
53
54//_____________________________________________________________________________
56{
58
59 if (VerboseLevel() > 1) {
60 G4cout << "TG4BiasingManager::CreateBiasingOperator" << G4endl;
61 }
62
63 // Return if no models are registered
64 if (!GetVector().size()) return;
65
66 // Only one "model" is currently supported
67 if (GetVector().size() > 1) {
68 // Add warning
69 return;
70 }
71
72 // Generate new regions names based on material names
74
75#ifdef G4MULTITHREADED
76 G4AutoLock lm(&createBiasingOperatorMutex);
77#endif
78
79 // Get biasing "model" configuration
80 // (only one "model" is currently supported)
81 TG4ModelConfiguration* modelConfiguration = GetVector().at(0);
82
83 // Get particles as a vector
84 std::vector<G4String> particlesVector;
85 if (modelConfiguration->GetParticles().size()) {
86 // use analysis utility to tokenize regions
87 G4Analysis::Tokenize(modelConfiguration->GetParticles(), particlesVector);
88 }
89
90 // Create biasingOperator
91 TG4BiasingOperator* biasingOperator = new TG4BiasingOperator();
92
93 // Add particles
94 for (auto it = particlesVector.begin(); it != particlesVector.end(); it++) {
95 biasingOperator->AddParticle((*it));
96 }
97
98 // Loop over logical volumes
99 G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance();
100 for (G4int i = 0; i < G4int(lvStore->size()); i++) {
101 G4LogicalVolume* lv = (*lvStore)[i];
102 G4String materialName = lv->GetMaterial()->GetName();
103
104 if (VerboseLevel() > 2) {
105 G4cout << "Biasing manager: processing volume " << lv->GetName()
106 << ", material " << materialName << G4endl;
107 }
108
109 // Skip volumes with materials which are not in the regions list
110 if (!modelConfiguration->HasRegion(materialName)) {
111 if (VerboseLevel() > 2) {
112 G4cout << " Material " << materialName << " is not in selection"
113 << G4endl;
114 }
115 continue;
116 }
117
118 // Attach biasing operator to the logical volume
119 biasingOperator->AttachTo(lv);
120
121 if (VerboseLevel() > 1) {
122 G4cout << "Biasing operator attached to lv " << lv->GetName() << G4endl;
123 }
124 }
125#ifdef G4MULTITHREADED
126 lm.unlock();
127#endif
128}
Definition of the TG4BiasingManager class.
Definition of the TG4BiasingOperator class.
Definition of the TG4ModelConfiguration class.
TG4BiasingManager(const G4String &name, const G4String &availableModels="")
void AddParticle(G4String particleName)
The model configuration vector with suitable setters and a messenger.
const ModelConfigurationVector & GetVector() const
A helper class to hold a configuration of a special physics model.
const G4String & GetParticles() const
G4bool HasRegion(const G4String &regionName)
virtual G4int VerboseLevel() const
Definition TG4Verbose.h:78