22#include <G4LogicalVolume.hh>
23#include <G4LogicalVolumeStore.hh>
24#include <G4SDManager.hh>
25#include <G4Threading.hh>
27#include <TGeoManager.h>
28#include <TGeoVolume.h>
29#include <TVirtualMCApplication.h>
30#include <TVirtualMCSensitiveDetector.h>
32#include <TVirtualMC.h>
40 fExclusiveSDScoring(false),
41 fSelectionFromTGeo(false),
42 fSVLabel(fgkDefaultSVLabel),
61 G4LogicalVolume* lv, TVirtualMCSensitiveDetector* userSD)
const
66 G4cout <<
"TG4SDConstruction::CreateSD: lv=" << lv->GetName()
67 <<
" userSD=" << userSD << G4endl;
71 G4SDManager* pSDManager = G4SDManager::GetSDMpointer();
75 sdName = userSD->GetName();
78 G4String lvName = lv->GetName();
79 sdName =
"/" + lvName;
86 sd = pSDManager->FindSensitiveDetector(sdName,
false);
95 G4cout <<
"Created TG4GflashSensitiveDetector with sdName=" << sdName
96 <<
" mediumId=" << mediumId << G4endl;
102 G4cout <<
"Created TG4SensitiveDetector with userSD=" << userSD
103 <<
" mediumId=" << mediumId
110 G4cout <<
"Created TG4SensitiveDetector with sdName=" << sdName
111 <<
" mediumId=" << mediumId << G4endl;
114 pSDManager->AddNewDetector(newSD);
116 G4cout <<
"Sensitive detector " << sdName <<
" ID=" << newSD->
GetID()
117 <<
" medium ID=" << newSD->
GetMediumID() <<
" has been created."
122 G4cout <<
"Sensitive detector " << sdName <<
", " << sd
123 <<
" already exists." << G4endl;
128 lv->SetSensitiveDetector(sd);
140 "TG4SDServices",
"FillSDSelectionFromTGeo",
"TGeo manager not defined.");
143 TObjArray* volumes = gGeoManager->GetListOfVolumes();
144 TIterator* it = volumes->MakeIterator();
145 TGeoVolume* volume = 0;
146 while ((volume = (
static_cast<TGeoVolume*
>(it->Next())))) {
147 if (TString(volume->GetOption()) == TString(
fSVLabel.data())) {
148 G4cout <<
"Adding volume " << volume->GetName() <<
" in SD selection"
155 TString text =
"No volumes with the option = \"";
157 text +=
"\" were found in TGeo geometry.\n";
158 text +=
" The SD selection will not be applied.";
175 G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance();
176 for (G4int i = 0; i < G4int(lvStore->size()); i++) {
177 G4LogicalVolume* lv = (*lvStore)[i];
180 G4cout <<
"Setting volId as instance Id "
182 <<
" to " << lv->GetName() << G4endl;
201 G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance();
202 for (G4int i = 0; i < G4int(lvStore->size()); i++) {
203 G4LogicalVolume* lv = (*lvStore)[i];
206 if (lv->GetSensitiveDetector()) {
215 G4cout <<
"Setting volId as SD id " <<
id <<
" to " << lv->GetName()
233 if (
VerboseLevel() > 1) G4cout <<
"TG4SDConstruction::Construct" << G4endl;
235 G4bool isMaster = !G4Threading::IsWorkerThread();
242 TVirtualMCApplication::Instance()->ConstructSensitiveDetectors();
245 G4bool isUserSD =
false;
246 G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance();
248 for (G4int i = 0; i < G4int(lvStore->size()); i++) {
249 G4LogicalVolume* lv = (*lvStore)[i];
252 TVirtualMCSensitiveDetector* userSD =
289 TVirtualMCApplication::Instance()->InitGeometry();
295 userSD->Initialize();
311 G4cout <<
"TG4SDConstruction::Construct done" << G4endl;
320 std::istringstream is(selection);
322 while (is >> token) {
324 G4cout <<
"Adding volume " << token <<
" in SD selection." << G4endl;
Definition of the TG4GeometryServices class.
Definition of the TG4GflashSensitiveDetector class.
Definition of the TG4SDConstruction class.
Definition of the TG4SDServices class.
Definition of the TG4SensitiveDetector class.
Definition of the TG4StateManager class.
Services for accessing to Geant4 geometry.
G4int GetMediumId(G4LogicalVolume *lv) const
const G4String & UserVolumeName(const G4String &name) const
static TG4GeometryServices * Instance()
Sensitive detector with Gflash.
static void Warning(const TString &className, const TString &methodName, const TString &text)
static void Exception(const TString &className, const TString &methodName, const TString &text)
void CreateSD(G4LogicalVolume *lv, TVirtualMCSensitiveDetector *userSD) const
void FillSDSelectionFromTGeo()
G4String fSVLabel
the label used to flag sensitive volumes in TGeo
std::set< G4String > fSelection
the set of volumes names which are selected as sensitive
void AddSelection(const G4String &selection)
G4bool fIsGflash
the flag to acivate creating Gflash sensitive detectors
void MapVolumesToInstanceIds()
static const G4String fgkDefaultSVLabel
default value of the sensitive volumes label
G4bool fExclusiveSDScoring
the flag to activate new scoring via user defined sensitive detectors
virtual ~TG4SDConstruction()
G4bool fSelectionFromTGeo
the flag to activate retrieving sensitive volumes from TGeo
TVirtualMCSensitiveDetector * GetUserSD(G4String volumeName, G4bool warn=true) const
void PrintUserSensitiveDetectors() const
void PrintSensitiveVolumes() const
void PrintVolNameToIdMap() const
void MapVolume(G4LogicalVolume *lv, G4int id, G4bool fillLVToVolIdMap)
void PrintVolIdToLVMap() const
static TG4SDServices * Instance()
static G4int GetFirstVolumeId()
Sensitive detector class for calling a user defined stepping function.
static G4int GetTotalNofSensitiveDetectors()
G4int GetMediumID() const
void SetNewState(TG4ApplicationState state)
static TG4StateManager * Instance()
Base class for defining the verbose level and a common messenger.
virtual G4int VerboseLevel() const
@ kConstructSD
in ConstructSensitiveDetectors
@ kNotInApplication
not in VMC application
@ kInitGeometry
in InitGeometry