Geant4 VMC
Version 6.8
Toggle main menu visibility
Loading...
Searching...
No Matches
source
digits+hits
src
TG4SDManager.cxx
Go to the documentation of this file.
1
//------------------------------------------------
2
// The Geant4 Virtual Monte Carlo package
3
// Copyright (C) 2007 - 2018 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 "
TG4SDManager.h
"
16
#include "
TG4GeometryServices.h
"
17
#include "
TG4Globals.h
"
18
#include "
TG4Medium.h
"
19
#include "
TG4MediumMap.h
"
20
#include "
TG4SDConstruction.h
"
21
#include "
TG4SDServices.h
"
22
23
#include "G4MultiFunctionalDetector.hh"
24
#include "G4ScoringManager.hh"
25
#include "G4VPrimitiveScorer.hh"
26
#include "G4VScoringMesh.hh"
27
28
#include <TVirtualMC.h>
29
30
TG4SDManager
*
TG4SDManager::fgInstance
= 0;
31
32
//_____________________________________________________________________________
33
TG4SDManager::TG4SDManager
() :
fSDConstruction
(0),
fSDServices
(0),
fNameBuffer
()
34
35
{
37
38
if
(
fgInstance
)
39
TG4Globals::Exception
(
"TG4SDManager"
,
"TG4SDManager"
,
40
"Cannot create two instances of singleton."
);
41
42
fgInstance
=
this
;
43
44
fSDConstruction
=
new
TG4SDConstruction
();
45
fSDServices
=
new
TG4SDServices
();
46
}
47
48
//_____________________________________________________________________________
49
TG4SDManager::~TG4SDManager
()
50
{
52
53
delete
fSDConstruction
;
54
delete
fSDServices
;
55
56
fgInstance
= 0;
57
}
58
59
//
60
// public methods
61
//
62
63
//_____________________________________________________________________________
64
void
TG4SDManager::Initialize
()
65
{
69
70
// G4cout << "TG4SDManager::Initialize" << G4endl;
71
fSDConstruction
->Construct();
72
// G4cout << "TG4SDManager::Initialize done" << G4endl;
73
}
74
75
//_____________________________________________________________________________
76
void
TG4SDManager::LateInitialize
(
TG4ScoreWeightCalculator
swc)
77
{
78
// Apply score weight if use of Geant4 scoring is activated
79
80
auto
g4ScoringManager = G4ScoringManager::GetScoringManagerIfExist();
81
if
(g4ScoringManager ==
nullptr
)
return
;
82
83
fScoreWeightCalculator
= swc;
84
85
G4ScoreWeightCalculator g4Swc = [&calculator =
fScoreWeightCalculator
](
const
G4Step* step) -> G4double {
86
Double_t ekin = step->GetTrack()->GetKineticEnergy();
87
Int_t pdg = step->GetTrack()->GetParticleDefinition()->GetPDGEncoding();
88
return
calculator(pdg, ekin);
89
};
90
91
// Loop over existing scoring meshes
92
auto
nofMesh = g4ScoringManager->GetNumberOfMesh();
93
if
(nofMesh < 1)
return
;
94
// G4cout << "Processing scorers for " << nofMesh << " meshes" << G4endl;
95
std::size_t counter = 0;
96
for
(std::size_t i = 0; i < nofMesh; ++i) {
97
auto
mesh = g4ScoringManager->GetMesh((G4int)i);
98
const
auto
mfd = mesh->GetMFD();
99
G4int nps = mfd->GetNumberOfPrimitives();
100
for
(G4int i = 0; i < nps; ++i) {
101
auto
scorer = mfd->GetPrimitive(i);
102
// G4cout << "Looping over " << scorer->GetName() << G4endl;
103
if
(scorer->IsScoreWeighted()) {
104
// G4cout << " is weightScoring activated " << scorer->IsScoreWeighted() << G4endl;
105
scorer->SetScoreWeightCalculator(g4Swc);
106
++counter;
107
}
108
}
109
}
110
111
if
(counter > 0) {
112
G4cout <<
"### User score weight calculator set to "
<< counter <<
" scorers."
113
<< G4endl;
114
}
115
}
116
117
//_____________________________________________________________________________
118
Int_t
TG4SDManager::VolId
(
const
Text_t* volName)
const
119
{
121
122
return
fSDServices
->GetVolumeID(volName);
123
}
124
125
//_____________________________________________________________________________
126
const
char
*
TG4SDManager::VolName
(Int_t
id
)
const
127
{
130
131
fNameBuffer
=
fSDServices
->GetVolumeName(
id
).c_str();
132
return
fNameBuffer
.data();
133
}
134
135
//_____________________________________________________________________________
136
Int_t
TG4SDManager::NofVolumes
()
const
137
{
140
141
return
fSDServices
->NofSensitiveDetectors();
142
}
143
144
//_____________________________________________________________________________
145
Int_t
TG4SDManager::NofVolDaughters
(
const
char
* volName)
const
146
{
148
149
return
fSDServices
->NofVolDaughters(volName);
150
}
151
152
//_____________________________________________________________________________
153
const
char
*
TG4SDManager::VolDaughterName
(
const
char
* volName, Int_t i)
const
154
{
156
157
return
fSDServices
->VolDaughterName(volName, i);
158
}
159
160
//_____________________________________________________________________________
161
Int_t
TG4SDManager::VolDaughterCopyNo
(
const
char
* volName, Int_t i)
const
162
{
164
165
return
fSDServices
->VolDaughterCopyNo(volName, i);
166
}
167
168
//_____________________________________________________________________________
169
Int_t
TG4SDManager::VolId2Mate
(Int_t volumeId)
const
170
{
172
173
return
fSDServices
->GetMediumId(volumeId);
174
}
175
176
//_____________________________________________________________________________
177
void
TG4SDManager::SetSensitiveDetector
(
178
const
TString& volName, TVirtualMCSensitiveDetector* sd)
179
{
181
182
fSDServices
->MapUserSD(volName.Data(), sd);
183
}
184
185
//_____________________________________________________________________________
186
TVirtualMCSensitiveDetector*
TG4SDManager::GetSensitiveDetector
(
187
const
TString& volName)
const
188
{
190
191
return
fSDServices
->GetUserSD(volName.Data(),
false
);
192
}
193
194
//_____________________________________________________________________________
195
void
TG4SDManager::SetExclusiveSDScoring
(Bool_t exclusiveSDScoring)
196
{
198
199
fSDConstruction
->SetExclusiveSDScoring(exclusiveSDScoring);
200
}
TG4GeometryServices.h
Definition of the TG4GeometryServices class.
TG4Globals.h
Definition of the TG4Globals class and basic container types.
TG4MediumMap.h
Definition of the TG4MediumMap class.
TG4Medium.h
Definition of the TG4Medium class.
TG4SDConstruction.h
Definition of the TG4SDConstruction class.
TG4SDManager.h
Definition of the TG4SDManager class.
TG4SDServices.h
Definition of the TG4SDServices class.
TG4ScoreWeightCalculator
std::function< Double_t(Int_t pdg, Double_t ekin)> TG4ScoreWeightCalculator
Definition
TG4ScoreWeightCalculator.h:22
TG4Globals::Exception
static void Exception(const TString &className, const TString &methodName, const TString &text)
Definition
TG4Globals.cxx:33
TG4SDConstruction
Sensitive detector construction.
Definition
TG4SDConstruction.h:41
TG4SDManager
Geant4 implementation of the TVirtualMC interface methods for access to Geant4 geometry related with ...
Definition
TG4SDManager.h:35
TG4SDManager::fScoreWeightCalculator
TG4ScoreWeightCalculator fScoreWeightCalculator
score weight calculator
Definition
TG4SDManager.h:84
TG4SDManager::NofVolDaughters
Int_t NofVolDaughters(const char *volName) const
Definition
TG4SDManager.cxx:145
TG4SDManager::VolDaughterName
const char * VolDaughterName(const char *volName, Int_t i) const
Definition
TG4SDManager.cxx:153
TG4SDManager::GetSensitiveDetector
TVirtualMCSensitiveDetector * GetSensitiveDetector(const TString &volName) const
Definition
TG4SDManager.cxx:186
TG4SDManager::NofVolumes
Int_t NofVolumes() const
Definition
TG4SDManager.cxx:136
TG4SDManager::SetSensitiveDetector
void SetSensitiveDetector(const TString &volName, TVirtualMCSensitiveDetector *sd)
Definition
TG4SDManager.cxx:177
TG4SDManager::SetExclusiveSDScoring
void SetExclusiveSDScoring(Bool_t exclusiveSDScoring)
Definition
TG4SDManager.cxx:195
TG4SDManager::fNameBuffer
G4String fNameBuffer
buffer for volume name
Definition
TG4SDManager.h:87
TG4SDManager::~TG4SDManager
~TG4SDManager()
Definition
TG4SDManager.cxx:49
TG4SDManager::Initialize
void Initialize()
Definition
TG4SDManager.cxx:64
TG4SDManager::VolDaughterCopyNo
Int_t VolDaughterCopyNo(const char *volName, Int_t i) const
Definition
TG4SDManager.cxx:161
TG4SDManager::fSDServices
TG4SDServices * fSDServices
services related with sensitive detectors
Definition
TG4SDManager.h:81
TG4SDManager::VolName
const char * VolName(Int_t id) const
Definition
TG4SDManager.cxx:126
TG4SDManager::TG4SDManager
TG4SDManager()
Definition
TG4SDManager.cxx:33
TG4SDManager::LateInitialize
void LateInitialize(TG4ScoreWeightCalculator swc)
Definition
TG4SDManager.cxx:76
TG4SDManager::VolId
Int_t VolId(const Text_t *volName) const
Definition
TG4SDManager.cxx:118
TG4SDManager::fgInstance
static TG4SDManager * fgInstance
this instance
Definition
TG4SDManager.h:72
TG4SDManager::VolId2Mate
Int_t VolId2Mate(Int_t volumeId) const
Definition
TG4SDManager.cxx:169
TG4SDManager::fSDConstruction
TG4SDConstruction * fSDConstruction
sensitive detectors construction
Definition
TG4SDManager.h:78
TG4SDServices
Sensitive detectors services.
Definition
TG4SDServices.h:42
Generated on
for Geant4 VMC by
1.17.0