Geant4 VMC Version 6.8
Loading...
Searching...
No Matches
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
31
32//_____________________________________________________________________________
34
35{
37
38 if (fgInstance)
39 TG4Globals::Exception("TG4SDManager", "TG4SDManager",
40 "Cannot create two instances of singleton.");
41
42 fgInstance = this;
43
46}
47
48//_____________________________________________________________________________
50{
52
53 delete fSDConstruction;
54 delete fSDServices;
55
56 fgInstance = 0;
57}
58
59//
60// public methods
61//
62
63//_____________________________________________________________________________
65{
69
70 // G4cout << "TG4SDManager::Initialize" << G4endl;
71 fSDConstruction->Construct();
72 // G4cout << "TG4SDManager::Initialize done" << G4endl;
73}
74
75//_____________________________________________________________________________
77{
78 // Apply score weight if use of Geant4 scoring is activated
79
80 auto g4ScoringManager = G4ScoringManager::GetScoringManagerIfExist();
81 if (g4ScoringManager == nullptr ) return;
82
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//_____________________________________________________________________________
118Int_t TG4SDManager::VolId(const Text_t* volName) const
119{
121
122 return fSDServices->GetVolumeID(volName);
123}
124
125//_____________________________________________________________________________
126const char* TG4SDManager::VolName(Int_t id) const
127{
130
131 fNameBuffer = fSDServices->GetVolumeName(id).c_str();
132 return fNameBuffer.data();
133}
134
135//_____________________________________________________________________________
137{
140
141 return fSDServices->NofSensitiveDetectors();
142}
143
144//_____________________________________________________________________________
145Int_t TG4SDManager::NofVolDaughters(const char* volName) const
146{
148
149 return fSDServices->NofVolDaughters(volName);
150}
151
152//_____________________________________________________________________________
153const char* TG4SDManager::VolDaughterName(const char* volName, Int_t i) const
154{
156
157 return fSDServices->VolDaughterName(volName, i);
158}
159
160//_____________________________________________________________________________
161Int_t TG4SDManager::VolDaughterCopyNo(const char* volName, Int_t i) const
162{
164
165 return fSDServices->VolDaughterCopyNo(volName, i);
166}
167
168//_____________________________________________________________________________
169Int_t TG4SDManager::VolId2Mate(Int_t volumeId) const
170{
172
173 return fSDServices->GetMediumId(volumeId);
174}
175
176//_____________________________________________________________________________
178 const TString& volName, TVirtualMCSensitiveDetector* sd)
179{
181
182 fSDServices->MapUserSD(volName.Data(), sd);
183}
184
185//_____________________________________________________________________________
186TVirtualMCSensitiveDetector* TG4SDManager::GetSensitiveDetector(
187 const TString& volName) const
188{
190
191 return fSDServices->GetUserSD(volName.Data(), false);
192}
193
194//_____________________________________________________________________________
195void TG4SDManager::SetExclusiveSDScoring(Bool_t exclusiveSDScoring)
196{
198
199 fSDConstruction->SetExclusiveSDScoring(exclusiveSDScoring);
200}
Definition of the TG4GeometryServices class.
Definition of the TG4Globals class and basic container types.
Definition of the TG4MediumMap class.
Definition of the TG4Medium class.
Definition of the TG4SDConstruction class.
Definition of the TG4SDManager class.
Definition of the TG4SDServices class.
std::function< Double_t(Int_t pdg, Double_t ekin)> TG4ScoreWeightCalculator
static void Exception(const TString &className, const TString &methodName, const TString &text)
Sensitive detector construction.
Geant4 implementation of the TVirtualMC interface methods for access to Geant4 geometry related with ...
TG4ScoreWeightCalculator fScoreWeightCalculator
score weight calculator
Int_t NofVolDaughters(const char *volName) const
const char * VolDaughterName(const char *volName, Int_t i) const
TVirtualMCSensitiveDetector * GetSensitiveDetector(const TString &volName) const
Int_t NofVolumes() const
void SetSensitiveDetector(const TString &volName, TVirtualMCSensitiveDetector *sd)
void SetExclusiveSDScoring(Bool_t exclusiveSDScoring)
G4String fNameBuffer
buffer for volume name
Int_t VolDaughterCopyNo(const char *volName, Int_t i) const
TG4SDServices * fSDServices
services related with sensitive detectors
const char * VolName(Int_t id) const
void LateInitialize(TG4ScoreWeightCalculator swc)
Int_t VolId(const Text_t *volName) const
static TG4SDManager * fgInstance
this instance
Int_t VolId2Mate(Int_t volumeId) const
TG4SDConstruction * fSDConstruction
sensitive detectors construction
Sensitive detectors services.