Import Geant4 11.2.0.beta source tree

This commit is contained in:
Gabriele Cosmo
2023-06-30 09:09:57 +02:00
parent aef78ca386
commit dd1f179cda
3780 changed files with 212808 additions and 142780 deletions
@@ -33,29 +33,22 @@
// ----------------------------------------------------------------------
#include "G4CellScoreComposer.hh"
#include "G4Step.hh"
G4CellScoreComposer::G4CellScoreComposer()
: fSCScoreValues()
{}
G4CellScoreComposer::~G4CellScoreComposer() {}
void G4CellScoreComposer::EstimatorCalculation(const G4Step& aStep)
{
G4StepPoint* p = aStep.GetPreStepPoint();
if(!p)
{
G4Exception("G4CellScoreComposer::EstimatorCalculation", "Det0191",
FatalException, " no pointer to pre PreStepPoint!");
if (p == nullptr) {
G4Exception("G4CellScoreComposer::EstimatorCalculation", "Det0191", FatalException,
" no pointer to pre PreStepPoint!");
}
G4double sl = aStep.GetStepLength();
G4double slw = sl * p->GetWeight();
G4double sl = aStep.GetStepLength();
G4double slw = sl * p->GetWeight();
G4double slwe = slw * p->GetKineticEnergy();
G4double v = p->GetVelocity();
if(!(v > 0.))
{
if (! (v > 0.)) {
v = 10e-9;
}
@@ -76,17 +69,13 @@ void G4CellScoreComposer::SetCollisionWeight(G4double weight)
const G4CellScoreValues& G4CellScoreComposer::GetStandardCellScoreValues() const
{
if(fSCScoreValues.fSumSLW > 0.)
{
if (fSCScoreValues.fSumSLW > 0.) {
// divide by SumSLW or SumSLW_v ?
fSCScoreValues.fNumberWeightedEnergy =
fSCScoreValues.fSumSLWE_v / fSCScoreValues.fSumSLW_v;
fSCScoreValues.fNumberWeightedEnergy = fSCScoreValues.fSumSLWE_v / fSCScoreValues.fSumSLW_v;
fSCScoreValues.fFluxWeightedEnergy =
fSCScoreValues.fSumSLWE / fSCScoreValues.fSumSLW;
fSCScoreValues.fFluxWeightedEnergy = fSCScoreValues.fSumSLWE / fSCScoreValues.fSumSLW;
fSCScoreValues.fAverageTrackWeight =
fSCScoreValues.fSumSLW / fSCScoreValues.fSumSL;
fSCScoreValues.fAverageTrackWeight = fSCScoreValues.fSumSLW / fSCScoreValues.fSumSL;
}
return fSCScoreValues;
}
@@ -105,7 +94,6 @@ std::ostream& operator<<(std::ostream& out, const G4CellScoreComposer& ps)
out << "Collisions*Wgt: " << scores.fSumCollisionsWeight << G4endl;
out << "NumWGTedEnergy: " << scores.fNumberWeightedEnergy << G4endl;
out << "FluxWGTedEnergy: " << scores.fFluxWeightedEnergy << G4endl;
out << "Aver.TrackWGT*I: " << scores.fAverageTrackWeight * scores.fImportance
<< G4endl;
out << "Aver.TrackWGT*I: " << scores.fAverageTrackWeight * scores.fImportance << G4endl;
return out;
}
+16 -33
View File
@@ -27,18 +27,13 @@
//
#include "G4HCtable.hh"
#include "G4VSensitiveDetector.hh"
G4HCtable::G4HCtable() { ; }
G4HCtable::~G4HCtable() { ; }
G4int G4HCtable::Registor(G4String SDname, G4String HCname)
{
for(std::size_t i = 0; i < HClist.size(); ++i)
{
if(HClist[i] == HCname && SDlist[i] == SDname)
return -1;
for (std::size_t i = 0; i < HClist.size(); ++i) {
if (HClist[i] == HCname && SDlist[i] == SDname) return -1;
}
HClist.push_back(HCname);
SDlist.push_back(SDname);
@@ -48,29 +43,22 @@ G4int G4HCtable::Registor(G4String SDname, G4String HCname)
G4int G4HCtable::GetCollectionID(G4String HCname) const
{
G4int i = -1;
if(HCname.find("/") == std::string::npos) // HCname only
if (HCname.find('/') == std::string::npos) // HCname only
{
for(std::size_t j = 0; j < HClist.size(); ++j)
{
if(HClist[j] == HCname)
{
if(i >= 0)
return -2;
for (std::size_t j = 0; j < HClist.size(); ++j) {
if (HClist[j] == HCname) {
if (i >= 0) return -2;
i = (G4int)j;
}
}
}
else
{
for(std::size_t j = 0; j < HClist.size(); ++j)
{
else {
for (std::size_t j = 0; j < HClist.size(); ++j) {
G4String tgt = SDlist[j];
tgt += "/";
tgt += HClist[j];
if(tgt == HCname)
{
if(i >= 0)
return -2;
if (tgt == HCname) {
if (i >= 0) return -2;
i = (G4int)j;
}
}
@@ -80,28 +68,23 @@ G4int G4HCtable::GetCollectionID(G4String HCname) const
G4int G4HCtable::GetCollectionID(G4VSensitiveDetector* aSD) const
{
if(aSD->GetNumberOfCollections() < 1)
{
if (aSD->GetNumberOfCollections() < 1) {
G4cerr << "Sensitive detector <" << aSD->GetName()
<< "> does not have a registered hits collection." << G4endl;
return -1;
}
if(aSD->GetNumberOfCollections() > 1)
{
if (aSD->GetNumberOfCollections() > 1) {
G4cerr << "Sensitive detector <" << aSD->GetName()
<< "> has more than one registered hits collections." << G4endl;
G4cerr << "Candidates are : ";
for(G4int j = 0; j < aSD->GetNumberOfCollections(); ++j)
{
for (G4int j = 0; j < aSD->GetNumberOfCollections(); ++j) {
G4cerr << aSD->GetCollectionName(j) << " ";
}
G4cerr << G4endl;
return -1;
}
for(std::size_t k = 0; k < SDlist.size(); ++k)
{
if(SDlist[k] == aSD->GetName())
return (G4int)k;
for (std::size_t k = 0; k < SDlist.size(); ++k) {
if (SDlist[k] == aSD->GetName()) return (G4int)k;
}
return -1;
}
@@ -31,29 +31,26 @@
//
//
#include "G4MultiFunctionalDetector.hh"
#include "G4SDManager.hh"
#include "G4VPrimitiveScorer.hh"
G4MultiFunctionalDetector::G4MultiFunctionalDetector(G4String name)
: G4VSensitiveDetector(name)
G4MultiFunctionalDetector::G4MultiFunctionalDetector(G4String name) : G4VSensitiveDetector(name)
{
;
}
G4MultiFunctionalDetector::~G4MultiFunctionalDetector()
{
for(auto pr : primitives)
for (auto pr : primitives)
delete pr;
primitives.clear();
}
G4bool G4MultiFunctionalDetector::ProcessHits(G4Step* aStep,
G4TouchableHistory* aTH)
G4bool G4MultiFunctionalDetector::ProcessHits(G4Step* aStep, G4TouchableHistory* aTH)
{
if(aStep->GetStepLength() > 0. || aStep->GetTotalEnergyDeposit() > 0.)
{
for(auto pr : primitives)
{
if (aStep->GetStepLength() > 0. || aStep->GetTotalEnergyDeposit() > 0.) {
for (auto pr : primitives) {
pr->HitPrimitive(aStep, aTH);
}
}
@@ -62,29 +59,23 @@ G4bool G4MultiFunctionalDetector::ProcessHits(G4Step* aStep,
G4bool G4MultiFunctionalDetector::RegisterPrimitive(G4VPrimitiveScorer* aPS)
{
for(auto pr : primitives)
{
if(pr == aPS)
{
for (auto pr : primitives) {
if (pr == aPS) {
G4ExceptionDescription ED;
ED << "Primitive <" << aPS->GetName() << "> is already defined in <"
<< SensitiveDetectorName << ">." << G4endl
<< "Method RegisterPrimitive() is ignored." << G4endl;
G4Exception("G4MultiFunctionalDetector::RegisterPrimitive", "Det0101",
JustWarning, ED);
ED << "Primitive <" << aPS->GetName() << "> is already defined in <" << SensitiveDetectorName
<< ">." << G4endl << "Method RegisterPrimitive() is ignored." << G4endl;
G4Exception("G4MultiFunctionalDetector::RegisterPrimitive", "Det0101", JustWarning, ED);
return false;
}
}
primitives.push_back(aPS);
aPS->SetMultiFunctionalDetector(this);
collectionName.insert(aPS->GetName());
if(G4SDManager::GetSDMpointer()->FindSensitiveDetector(SensitiveDetectorName,
false))
if (G4SDManager::GetSDMpointer()->FindSensitiveDetector(SensitiveDetectorName, false) != nullptr)
{
// This G4MultiFunctionalDetector has already been registered to
// G4SDManager. Make sure this new primitive is registered as well.
G4SDManager::GetSDMpointer()->AddNewCollection(SensitiveDetectorName,
aPS->GetName());
G4SDManager::GetSDMpointer()->AddNewCollection(SensitiveDetectorName, aPS->GetName());
}
return true;
}
@@ -92,54 +83,47 @@ G4bool G4MultiFunctionalDetector::RegisterPrimitive(G4VPrimitiveScorer* aPS)
G4bool G4MultiFunctionalDetector::RemovePrimitive(G4VPrimitiveScorer* aPS)
{
auto pr = std::find(primitives.begin(), primitives.end(), aPS);
if(pr != primitives.end())
{
if (pr != primitives.end()) {
primitives.erase(pr);
aPS->SetMultiFunctionalDetector(nullptr);
return true;
}
G4cerr << "Primitive <" << aPS->GetName() << "> is not defined in <"
<< SensitiveDetectorName << ">." << G4endl
<< "Method RemovePrimitive() is ignored." << G4endl;
G4cerr << "Primitive <" << aPS->GetName() << "> is not defined in <" << SensitiveDetectorName
<< ">." << G4endl << "Method RemovePrimitive() is ignored." << G4endl;
return false;
}
void G4MultiFunctionalDetector::Initialize(G4HCofThisEvent* HC)
{
for(auto pr : primitives)
{
for (auto pr : primitives) {
pr->Initialize(HC);
}
}
void G4MultiFunctionalDetector::EndOfEvent(G4HCofThisEvent* HC)
{
for(auto pr : primitives)
{
for (auto pr : primitives) {
pr->EndOfEvent(HC);
}
}
void G4MultiFunctionalDetector::clear()
{
for(auto pr : primitives)
{
for (auto pr : primitives) {
pr->clear();
}
}
void G4MultiFunctionalDetector::DrawAll()
{
for(auto pr : primitives)
{
for (auto pr : primitives) {
pr->DrawAll();
}
}
void G4MultiFunctionalDetector::PrintAll()
{
for(auto pr : primitives)
{
for (auto pr : primitives) {
pr->PrintAll();
}
}
@@ -26,56 +26,11 @@
// G4MultiSensitiveDetector
#include "G4MultiSensitiveDetector.hh"
#include "G4SDManager.hh"
#include <sstream>
//#define MSDDEBUG
#ifdef MSDDEBUG
# define DBG(msg) G4cout << msg << G4endl
#else
# define DBG(msg)
#endif
#define VDBG(vl, msg) \
if(vl <= verboseLevel) \
G4cout << msg << G4endl
G4MultiSensitiveDetector::G4MultiSensitiveDetector(G4String name)
: G4VSensitiveDetector(name)
{
#ifdef MSDDEBUG
verboseLevel = 3;
#endif
VDBG(1, "Creating G4MultiSenstiveDetector with name: " << name);
}
G4MultiSensitiveDetector::~G4MultiSensitiveDetector()
{
VDBG(2, GetName() << " : Destructing G4MultiSensitiveDetector");
ClearSDs();
}
G4MultiSensitiveDetector::G4MultiSensitiveDetector(
const G4MultiSensitiveDetector& rhs)
: G4VSensitiveDetector(rhs)
, fSensitiveDetectors(rhs.fSensitiveDetectors)
{
VDBG(3, GetName() << " : Copy constructor called.");
}
G4MultiSensitiveDetector& G4MultiSensitiveDetector::operator=(
const G4MultiSensitiveDetector& rhs)
{
if(this != &rhs)
{
// G4VSensitiveDetector::operator=(static_cast<const
// G4VSensitiveDetector&>(rhs));
G4VSensitiveDetector::operator=(
static_cast<const G4VSensitiveDetector&>(rhs));
fSensitiveDetectors = rhs.fSensitiveDetectors;
}
return *this;
}
void G4MultiSensitiveDetector::Initialize(G4HCofThisEvent*)
{
// SDManager is resposnsible for calling this since the granular SDs
@@ -92,28 +47,26 @@ void G4MultiSensitiveDetector::EndOfEvent(G4HCofThisEvent*)
void G4MultiSensitiveDetector::clear()
{
for(auto sd : fSensitiveDetectors)
for (auto sd : fSensitiveDetectors)
sd->clear();
}
void G4MultiSensitiveDetector::DrawAll()
{
for(auto sd : fSensitiveDetectors)
for (auto sd : fSensitiveDetectors)
sd->DrawAll();
}
void G4MultiSensitiveDetector::PrintAll()
{
for(auto sd : fSensitiveDetectors)
for (auto sd : fSensitiveDetectors)
sd->PrintAll();
}
G4bool G4MultiSensitiveDetector::ProcessHits(G4Step* aStep, G4TouchableHistory*)
{
VDBG(2, GetName() << " : Called processHits: " << aStep
<< " with Edep: " << aStep->GetTotalEnergyDeposit());
G4bool result = true;
for(auto sd : fSensitiveDetectors)
for (auto sd : fSensitiveDetectors)
result &= sd->Hit(aStep);
return result;
}
@@ -127,18 +80,15 @@ G4int G4MultiSensitiveDetector::GetCollectionID(G4int)
<< " First retrieve a contained G4VSensitiveDetector with. i.e. GetSD "
"and then "
<< " call this method.";
G4Exception("G4MultiSensitiveDetector::GetCollectionID", "Det0011",
FatalException, msg);
G4Exception("G4MultiSensitiveDetector::GetCollectionID", "Det0011", FatalException, msg);
return -1;
}
// This method requires all contained SD to be clonable
G4VSensitiveDetector* G4MultiSensitiveDetector::Clone() const
{
VDBG(2, GetName() << "Cloning an instance of G4MultiSensitiveDetector");
G4MultiSensitiveDetector* newInst =
new G4MultiSensitiveDetector(this->GetName());
for(auto sd : fSensitiveDetectors)
auto newInst = new G4MultiSensitiveDetector(this->GetName());
for (auto sd : fSensitiveDetectors)
newInst->AddSD(sd->Clone());
return newInst;
}
+37 -61
View File
@@ -27,8 +27,9 @@
//
#include "G4SDManager.hh"
#include "G4SDmessenger.hh"
#include "G4HCofThisEvent.hh"
#include "G4SDmessenger.hh"
#include "G4VHitsCollection.hh"
#include "G4VSensitiveDetector.hh"
#include "G4ios.hh"
@@ -37,8 +38,7 @@ G4ThreadLocal G4SDManager* G4SDManager::fSDManager = nullptr;
G4SDManager* G4SDManager::GetSDMpointer()
{
if(!fSDManager)
{
if (fSDManager == nullptr) {
fSDManager = new G4SDManager;
}
return fSDManager;
@@ -47,12 +47,11 @@ G4SDManager* G4SDManager::GetSDMpointer()
G4SDManager* G4SDManager::GetSDMpointerIfExist() { return fSDManager; }
G4SDManager::G4SDManager()
: verboseLevel(0)
{
G4String topName = "/";
treeTop = new G4SDStructure(topName);
theMessenger = new G4SDmessenger(this);
HCtable = new G4HCtable;
treeTop = new G4SDStructure(topName);
theMessenger = new G4SDmessenger(this);
HCtable = new G4HCtable;
}
G4SDManager::~G4SDManager()
@@ -62,92 +61,76 @@ G4SDManager::~G4SDManager()
delete treeTop;
DestroyFilters();
theMessenger = nullptr;
HCtable = nullptr;
treeTop = nullptr;
fSDManager = nullptr;
HCtable = nullptr;
treeTop = nullptr;
fSDManager = nullptr;
}
void G4SDManager::AddNewDetector(G4VSensitiveDetector* aSD)
{
G4int numberOfCollections = aSD->GetNumberOfCollections();
G4String pathName = aSD->GetPathName();
if(pathName[0] != '/')
pathName.insert(0, "/");
if(pathName.back() != '/')
pathName += "/";
G4String pathName = aSD->GetPathName();
if (pathName[0] != '/') pathName.insert(0, "/");
if (pathName.back() != '/') pathName += "/";
treeTop->AddNewDetector(aSD, pathName);
if(numberOfCollections < 1)
return;
for(G4int i = 0; i < numberOfCollections; i++)
{
if (numberOfCollections < 1) return;
for (G4int i = 0; i < numberOfCollections; i++) {
G4String SDname = aSD->GetName();
G4String DCname = aSD->GetCollectionName(i);
AddNewCollection(SDname, DCname);
}
if(verboseLevel > 0)
{
G4cout << "New sensitive detector <" << aSD->GetName()
<< "> is registered at " << pathName << G4endl;
if (verboseLevel > 0) {
G4cout << "New sensitive detector <" << aSD->GetName() << "> is registered at " << pathName
<< G4endl;
}
}
void G4SDManager::AddNewCollection(G4String SDname, G4String DCname)
{
G4int i = HCtable->Registor(SDname, DCname);
if(verboseLevel > 0)
{
if(i < 0)
{
if(verboseLevel > 1)
G4cout << "G4SDManager::AddNewCollection : the collection <" << SDname
<< "/" << DCname << "> has already been reginstered." << G4endl;
if (verboseLevel > 0) {
if (i < 0) {
if (verboseLevel > 1)
G4cout << "G4SDManager::AddNewCollection : the collection <" << SDname << "/" << DCname
<< "> has already been reginstered." << G4endl;
}
else
{
G4cout << "G4SDManager::AddNewCollection : the collection <" << SDname
<< "/" << DCname << "> is registered at " << i << G4endl;
else {
G4cout << "G4SDManager::AddNewCollection : the collection <" << SDname << "/" << DCname
<< "> is registered at " << i << G4endl;
}
}
}
G4HCofThisEvent* G4SDManager::PrepareNewEvent()
{
G4HCofThisEvent* HCE = new G4HCofThisEvent(HCtable->entries());
auto HCE = new G4HCofThisEvent(HCtable->entries());
treeTop->Initialize(HCE);
return HCE;
}
void G4SDManager::TerminateCurrentEvent(G4HCofThisEvent* HCE)
{
treeTop->Terminate(HCE);
}
void G4SDManager::TerminateCurrentEvent(G4HCofThisEvent* HCE) { treeTop->Terminate(HCE); }
void G4SDManager::Activate(G4String dName, G4bool activeFlag)
{
G4String pathName = dName;
if(pathName[0] != '/')
pathName.insert(0, "/");
if (pathName[0] != '/') pathName.insert(0, "/");
treeTop->Activate(pathName, activeFlag);
}
G4VSensitiveDetector* G4SDManager::FindSensitiveDetector(G4String dName,
G4bool warning)
G4VSensitiveDetector* G4SDManager::FindSensitiveDetector(G4String dName, G4bool warning)
{
G4String pathName = dName;
if(pathName[0] != '/')
pathName.insert(0, "/");
if (pathName[0] != '/') pathName.insert(0, "/");
return treeTop->FindSensitiveDetector(pathName, warning);
}
G4int G4SDManager::GetCollectionID(G4String colName)
{
G4int id = HCtable->GetCollectionID(colName);
if(id == -1)
{
if (id == -1) {
G4cout << "<" << colName << "> is not found." << G4endl;
}
else if(id == -2)
{
else if (id == -2) {
G4cout << "<" << colName << "> is ambiguous." << G4endl;
}
return id;
@@ -161,17 +144,12 @@ G4int G4SDManager::GetCollectionID(G4VHitsCollection* aHC)
return GetCollectionID(HCname);
}
void G4SDManager::RegisterSDFilter(G4VSDFilter* filter)
{
FilterList.push_back(filter);
}
void G4SDManager::RegisterSDFilter(G4VSDFilter* filter) { FilterList.push_back(filter); }
void G4SDManager::DeRegisterSDFilter(G4VSDFilter* filter)
{
for(auto f = FilterList.begin(); f != FilterList.end(); f++)
{
if(*f == filter)
{
for (auto f = FilterList.begin(); f != FilterList.end(); f++) {
if (*f == filter) {
FilterList.erase(f);
break;
}
@@ -181,10 +159,8 @@ void G4SDManager::DeRegisterSDFilter(G4VSDFilter* filter)
void G4SDManager::DestroyFilters()
{
auto f = FilterList.begin();
while(f != FilterList.end())
{
if(verboseLevel > 0)
G4cout << "### deleting " << (*f)->GetName() << " " << (*f) << G4endl;
while (f != FilterList.end()) {
if (verboseLevel > 0) G4cout << "### deleting " << (*f)->GetName() << " " << (*f) << G4endl;
delete *f;
f = FilterList.begin();
}
@@ -28,16 +28,15 @@
// G4SDStructure
#include "G4SDStructure.hh"
#include "G4ios.hh"
G4SDStructure::G4SDStructure(const G4String& aPath)
: verboseLevel(0)
{
pathName = aPath;
dirName = aPath;
auto i = dirName.length();
if(i > 1)
{
dirName = aPath;
auto i = dirName.length();
if (i > 1) {
dirName.erase(i - 1);
auto isl = dirName.rfind('/');
dirName.erase(0, isl + 1);
@@ -47,54 +46,44 @@ G4SDStructure::G4SDStructure(const G4String& aPath)
G4SDStructure::~G4SDStructure()
{
for(auto st : structure)
for (auto st : structure)
delete st;
structure.clear();
for(auto dt : detector)
for (auto dt : detector)
delete dt;
detector.clear();
}
G4bool G4SDStructure::operator==(const G4SDStructure& right) const
{
return (this == &right);
}
G4bool G4SDStructure::operator==(const G4SDStructure& right) const { return (this == &right); }
void G4SDStructure::AddNewDetector(G4VSensitiveDetector* aSD,
const G4String& treeStructure)
void G4SDStructure::AddNewDetector(G4VSensitiveDetector* aSD, const G4String& treeStructure)
{
G4String remainingPath = treeStructure;
remainingPath.erase(0, pathName.length());
if(!remainingPath.empty())
{ // The detector should be kept in subdirectory.
// First, check if the subdirectoy exists.
G4String subD = ExtractDirName(remainingPath);
if (! remainingPath.empty()) { // The detector should be kept in subdirectory.
// First, check if the subdirectoy exists.
G4String subD = ExtractDirName(remainingPath);
G4SDStructure* tgtSDS = FindSubDirectory(subD);
if(tgtSDS == nullptr)
{ // Subdirectory not found. Create a new directory.
if (tgtSDS == nullptr) { // Subdirectory not found. Create a new directory.
subD.insert(0, pathName);
tgtSDS = new G4SDStructure(subD);
structure.push_back(tgtSDS);
}
tgtSDS->AddNewDetector(aSD, treeStructure);
}
else
{ // The sensitive detector should be kept in this directory.
else { // The sensitive detector should be kept in this directory.
G4VSensitiveDetector* tgtSD = GetSD(aSD->GetName());
if(!tgtSD)
{
if (tgtSD == nullptr) {
detector.push_back(aSD);
}
else if(tgtSD != aSD)
{
else if (tgtSD != aSD) {
#ifdef G4VERBOSE
G4ExceptionDescription ed;
ed << aSD->GetName() << " had already been stored in " << pathName
<< ". Object pointer is overwritten.\n";
ed << "It's users' responsibility to delete the old sensitive detector "
"object.";
G4Exception("G4SDStructure::AddNewDetector()", "DET1010", JustWarning,
ed);
G4Exception("G4SDStructure::AddNewDetector()", "DET1010", JustWarning, ed);
#endif
RemoveSD(tgtSD);
detector.push_back(aSD);
@@ -104,20 +93,16 @@ void G4SDStructure::AddNewDetector(G4VSensitiveDetector* aSD,
G4SDStructure* G4SDStructure::FindSubDirectory(const G4String& subD)
{
for(auto st : structure)
{
if(subD == st->dirName)
return st;
for (auto st : structure) {
if (subD == st->dirName) return st;
}
return nullptr;
}
G4VSensitiveDetector* G4SDStructure::GetSD(const G4String& aSDName)
{
for(auto det : detector)
{
if(aSDName == det->GetName())
return det;
for (auto det : detector) {
if (aSDName == det->GetName()) return det;
}
return nullptr;
}
@@ -125,16 +110,14 @@ G4VSensitiveDetector* G4SDStructure::GetSD(const G4String& aSDName)
void G4SDStructure::RemoveSD(G4VSensitiveDetector* sd)
{
auto det = std::find(detector.begin(), detector.end(), sd);
if(det != detector.end())
detector.erase(det);
if (det != detector.end()) detector.erase(det);
}
G4String G4SDStructure::ExtractDirName(const G4String& aName)
{
G4String subD = aName;
auto i = aName.find('/');
if(i != G4String::npos)
subD.erase(i + 1);
auto i = aName.find('/');
if (i != G4String::npos) subD.erase(i + 1);
return subD;
}
@@ -142,118 +125,93 @@ void G4SDStructure::Activate(const G4String& aName, G4bool sensitiveFlag)
{
G4String aPath = aName;
aPath.erase(0, pathName.length());
if(aPath.find('/') != std::string::npos)
{ // Command is ordered for a subdirectory.
G4String subD = ExtractDirName(aPath);
if (aPath.find('/') != std::string::npos) { // Command is ordered for a subdirectory.
G4String subD = ExtractDirName(aPath);
G4SDStructure* tgtSDS = FindSubDirectory(subD);
if(tgtSDS == nullptr)
{ // The subdirectory is not found
if (tgtSDS == nullptr) { // The subdirectory is not found
G4cout << subD << " is not found in " << pathName << G4endl;
}
else
{
else {
tgtSDS->Activate(aName, sensitiveFlag);
}
}
else if(aPath.empty())
{ // Command is ordered for all detectors in this directory.
for(auto det : detector)
else if (aPath.empty()) { // Command is ordered for all detectors in this directory.
for (auto det : detector)
det->Activate(sensitiveFlag);
for(auto st : structure)
for (auto st : structure)
st->Activate(G4String("/"), sensitiveFlag);
}
else
{ // Command is ordered to a particular detector.
else { // Command is ordered to a particular detector.
G4VSensitiveDetector* tgtSD = GetSD(aPath);
if(tgtSD == nullptr)
{ // The detector is not found.
if (tgtSD == nullptr) { // The detector is not found.
G4cout << aPath << " is not found in " << pathName << G4endl;
}
else
{
else {
tgtSD->Activate(sensitiveFlag);
}
}
}
G4VSensitiveDetector* G4SDStructure::FindSensitiveDetector(
const G4String& aName, G4bool warning)
G4VSensitiveDetector* G4SDStructure::FindSensitiveDetector(const G4String& aName, G4bool warning)
{
G4String aPath = aName;
aPath.erase(0, pathName.length());
if(aPath.find('/') != std::string::npos)
{ // SD exists in sub-directory
G4String subD = ExtractDirName(aPath);
if (aPath.find('/') != std::string::npos) { // SD exists in sub-directory
G4String subD = ExtractDirName(aPath);
G4SDStructure* tgtSDS = FindSubDirectory(subD);
if(tgtSDS == nullptr)
{ // The subdirectory is not found
if(warning)
G4cout << subD << " is not found in " << pathName << G4endl;
if (tgtSDS == nullptr) { // The subdirectory is not found
if (warning) G4cout << subD << " is not found in " << pathName << G4endl;
return nullptr;
}
else
{
return tgtSDS->FindSensitiveDetector(aName, warning);
}
return tgtSDS->FindSensitiveDetector(aName, warning);
}
else
{ // SD must exist in this directory
G4VSensitiveDetector* tgtSD = GetSD(aPath);
if(tgtSD == nullptr)
{ // The detector is not found.
if(warning)
G4cout << aPath << " is not found in " << pathName << G4endl;
}
return tgtSD;
// SD must exist in this directory
G4VSensitiveDetector* tgtSD = GetSD(aPath);
if (tgtSD == nullptr) { // The detector is not found.
if (warning) G4cout << aPath << " is not found in " << pathName << G4endl;
}
return tgtSD;
}
void G4SDStructure::Initialize(G4HCofThisEvent* HCE)
{
// Broadcast to subdirectories.
for(auto st : structure)
{
for (auto st : structure) {
st->Initialize(HCE);
}
// Initialize all detectors in this directory.
for(auto dt : detector)
{
if(dt->isActive())
dt->Initialize(HCE);
for (auto dt : detector) {
if (dt->isActive()) dt->Initialize(HCE);
}
}
void G4SDStructure::Terminate(G4HCofThisEvent* HCE)
{
// Broadcast to subdirectories.
for(auto st : structure)
{
for (auto st : structure) {
st->Terminate(HCE);
}
// Terminate all detectors in this directory.
for(auto dt : detector)
{
if(dt->isActive())
dt->EndOfEvent(HCE);
for (auto dt : detector) {
if (dt->isActive()) dt->EndOfEvent(HCE);
}
}
void G4SDStructure::ListTree()
{
G4cout << pathName << G4endl;
for(auto sd : detector)
{
for (auto sd : detector) {
G4cout << pathName << sd->GetName();
if(sd->isActive())
{
if (sd->isActive()) {
G4cout << " *** Active ";
}
else
{
else {
G4cout << " XXX Inactive ";
}
G4cout << G4endl;
}
for(auto st : structure)
for (auto st : structure)
st->ListTree();
}
@@ -28,14 +28,14 @@
// ---------------------------------------------------------------------
#include "G4SDmessenger.hh"
#include "G4SDManager.hh"
#include "G4UIdirectory.hh"
#include "G4UIcmdWithoutParameter.hh"
#include "G4UIcmdWithAString.hh"
#include "G4UIcmdWithAnInteger.hh"
#include "G4UIcmdWithoutParameter.hh"
#include "G4UIdirectory.hh"
G4SDmessenger::G4SDmessenger(G4SDManager* SDManager)
: fSDMan(SDManager)
G4SDmessenger::G4SDmessenger(G4SDManager* SDManager) : fSDMan(SDManager)
{
hitsDir = new G4UIdirectory("/hits/");
hitsDir->SetGuidance("Sensitive detectors and Hits");
@@ -69,20 +69,16 @@ G4SDmessenger::~G4SDmessenger()
void G4SDmessenger::SetNewValue(G4UIcommand* command, G4String newVal)
{
if(command == listCmd)
{
if (command == listCmd) {
fSDMan->ListTree();
}
if(command == activeCmd)
{
fSDMan->Activate(newVal, 1);
if (command == activeCmd) {
fSDMan->Activate(newVal, true);
}
if(command == inactiveCmd)
{
fSDMan->Activate(newVal, 0);
if (command == inactiveCmd) {
fSDMan->Activate(newVal, false);
}
if(command == verboseCmd)
{
if (command == verboseCmd) {
fSDMan->SetVerboseLevel(verboseCmd->GetNewIntValue(newVal));
}
return;
@@ -35,57 +35,30 @@
#include "G4SensitiveVolumeList.hh"
// Constructors
G4SensitiveVolumeList::G4SensitiveVolumeList() {}
G4SensitiveVolumeList::G4SensitiveVolumeList(const G4SensitiveVolumeList& right)
{
thePhysicalVolumeList = right.thePhysicalVolumeList;
theLogicalVolumeList = right.theLogicalVolumeList;
}
// Destructor
G4SensitiveVolumeList::~G4SensitiveVolumeList() {}
// Assignment Operation
G4SensitiveVolumeList& G4SensitiveVolumeList::operator=(
const G4SensitiveVolumeList& right)
{
thePhysicalVolumeList = right.thePhysicalVolumeList;
theLogicalVolumeList = right.theLogicalVolumeList;
return *this;
}
// Equality Operations
G4bool G4SensitiveVolumeList::operator==(
const G4SensitiveVolumeList& right) const
G4bool G4SensitiveVolumeList::operator==(const G4SensitiveVolumeList& right) const
{
return (this == (G4SensitiveVolumeList*) &right);
return (this == (G4SensitiveVolumeList*)&right);
}
G4bool G4SensitiveVolumeList::operator!=(
const G4SensitiveVolumeList& right) const
G4bool G4SensitiveVolumeList::operator!=(const G4SensitiveVolumeList& right) const
{
return (this != (G4SensitiveVolumeList*) &right);
return (this != (G4SensitiveVolumeList*)&right);
}
// Other Operations
G4bool G4SensitiveVolumeList::CheckPV(const G4VPhysicalVolume* pvp) const
{
for(auto pv : thePhysicalVolumeList)
{
if(pv == pvp)
return true;
for (auto pv : thePhysicalVolumeList) {
if (pv == pvp) return true;
}
return false;
}
G4bool G4SensitiveVolumeList::CheckLV(const G4LogicalVolume* lvp) const
{
for(auto lv : theLogicalVolumeList)
{
if(lv == lvp)
return true;
for (auto lv : theLogicalVolumeList) {
if (lv == lvp) return true;
}
return false;
}
@@ -34,16 +34,9 @@
#include "G4TrackLogger.hh"
G4TrackLogger::G4TrackLogger()
: fPreviousEventID(-1)
{}
G4TrackLogger::~G4TrackLogger() {}
void G4TrackLogger::SetEventID(G4int id)
{
if(id != fPreviousEventID)
{
if (id != fPreviousEventID) {
fTrackIDsSet.clear();
fPreviousEventID = id;
}
@@ -52,17 +45,14 @@ void G4TrackLogger::SetEventID(G4int id)
G4bool G4TrackLogger::FirstEnterance(G4int trid)
{
G4bool first = true;
auto n = fTrackIDsSet.count(trid);
if(n == 1)
{
auto n = fTrackIDsSet.count(trid);
if (n == 1) {
first = false;
}
else if(n == 0)
{
else if (n == 0) {
fTrackIDsSet.insert(trid);
}
else if(n > 1)
{
else if (n > 1) {
G4cout << "Error G4TrackLogger::FirstEnterance: "
<< "more than one elm in set!" << G4endl;
}
@@ -27,98 +27,75 @@
//
// G4VPrimitiveScorer
#include "G4VPrimitiveScorer.hh"
#include "G4MultiFunctionalDetector.hh"
#include "G4SDManager.hh"
#include "G4Step.hh"
#include "G4TouchableHistory.hh"
#include "G4UnitsTable.hh"
#include "G4VSolid.hh"
#include "G4VPVParameterisation.hh"
#include "G4VSolid.hh"
G4VPrimitiveScorer::G4VPrimitiveScorer(G4String name, G4int depth)
: primitiveName(name)
, detector(nullptr)
, filter(nullptr)
, verboseLevel(0)
, indexDepth(depth)
, unitName("NoUnit")
, unitValue(1.0)
, fNi(0)
, fNj(0)
, fNk(0)
{
;
}
G4VPrimitiveScorer::~G4VPrimitiveScorer() { ; }
: primitiveName(name), indexDepth(depth)
{}
G4int G4VPrimitiveScorer::GetCollectionID(G4int)
{
if(detector)
return G4SDManager::GetSDMpointer()->GetCollectionID(detector->GetName() +
"/" + primitiveName);
else
return -1;
if (detector != nullptr)
return G4SDManager::GetSDMpointer()->GetCollectionID(detector->GetName() + "/" + primitiveName);
return -1;
}
void G4VPrimitiveScorer::Initialize(G4HCofThisEvent*) { ; }
void G4VPrimitiveScorer::Initialize(G4HCofThisEvent*) {}
void G4VPrimitiveScorer::EndOfEvent(G4HCofThisEvent*) { ; }
void G4VPrimitiveScorer::EndOfEvent(G4HCofThisEvent*) {}
void G4VPrimitiveScorer::clear() { ; }
void G4VPrimitiveScorer::clear() {}
void G4VPrimitiveScorer::DrawAll() { ; }
void G4VPrimitiveScorer::DrawAll() {}
void G4VPrimitiveScorer::PrintAll() { ; }
void G4VPrimitiveScorer::PrintAll() {}
G4int G4VPrimitiveScorer::GetIndex(G4Step* aStep)
{
G4StepPoint* preStep = aStep->GetPreStepPoint();
G4TouchableHistory* th = (G4TouchableHistory*) (preStep->GetTouchable());
G4StepPoint* preStep = aStep->GetPreStepPoint();
auto th = (G4TouchableHistory*)(preStep->GetTouchable());
return th->GetReplicaNumber(indexDepth);
}
void G4VPrimitiveScorer::CheckAndSetUnit(const G4String& unit,
const G4String& category)
void G4VPrimitiveScorer::CheckAndSetUnit(const G4String& unit, const G4String& category)
{
if(G4UnitDefinition::GetCategory(unit) == category)
{
unitName = unit;
if (G4UnitDefinition::GetCategory(unit) == category) {
unitName = unit;
unitValue = G4UnitDefinition::GetValueOf(unit);
}
else
{
G4String msg = "Invalid unit [" + unit + "] (Current unit is [" +
GetUnit() + "] ) requested for " + GetName();
G4Exception("G4VPrimitiveScorer::CheckAndSetUnit", "Det0151", JustWarning,
msg);
else {
G4String msg = "Invalid unit [" + unit + "] (Current unit is [" + GetUnit() +
"] ) requested for " + GetName();
G4Exception("G4VPrimitiveScorer::CheckAndSetUnit", "Det0151", JustWarning, msg);
}
}
G4VSolid* G4VPrimitiveScorer::ComputeSolid(G4Step* aStep, G4int replicaIdx)
{
G4VSolid* solid = nullptr;
G4VSolid* solid = nullptr;
G4StepPoint* preStep = aStep->GetPreStepPoint();
auto physVol = preStep->GetPhysicalVolume();
auto physVol = preStep->GetPhysicalVolume();
G4VPVParameterisation* physParam = physVol->GetParameterisation();
if(physParam)
{ // for parameterized volume
if(replicaIdx < 0)
{
if (physParam != nullptr) { // for parameterized volume
if (replicaIdx < 0) {
G4ExceptionDescription desc;
desc << "Incorrect replica number --- GetReplicaNumber : " << replicaIdx
<< G4endl;
G4Exception("G4VPrimitiveScorer::ComputeSolid", "DetPS0001", JustWarning,
desc);
desc << "Incorrect replica number --- GetReplicaNumber : " << replicaIdx << G4endl;
G4Exception("G4VPrimitiveScorer::ComputeSolid", "DetPS0001", JustWarning, desc);
// replicaIdx= 0; // You must ensure that it's in range !!!
}
solid = physParam->ComputeSolid(replicaIdx, physVol);
solid->ComputeDimensions(physParam, replicaIdx, physVol);
}
else
{ // for ordinary volume
else { // for ordinary volume
solid = physVol->GetLogicalVolume()->GetSolid();
}
@@ -130,8 +107,7 @@ G4VSolid* G4VPrimitiveScorer::ComputeCurrentSolid(G4Step* aStep)
G4StepPoint* preStep = aStep->GetPreStepPoint();
// The only difference: did not know the replica number
G4int replicaIdx =
(static_cast<const G4TouchableHistory*>(preStep->GetTouchable()))
->GetReplicaNumber(indexDepth);
(static_cast<const G4TouchableHistory*>(preStep->GetTouchable()))->GetReplicaNumber(indexDepth);
return ComputeSolid(aStep, replicaIdx);
}
@@ -27,61 +27,57 @@
//
#include "G4VReadOutGeometry.hh"
#include "G4Navigator.hh"
G4VReadOutGeometry::G4VReadOutGeometry()
: ROworld(nullptr)
, fincludeList(nullptr)
, fexcludeList(nullptr)
, touchableHistory(nullptr)
: ROworld(nullptr), fincludeList(nullptr), fexcludeList(nullptr), touchableHistory(nullptr)
{
name = "unknown";
name = "unknown";
ROnavigator = new G4Navigator();
G4ExceptionDescription ed;
ed
<< "The concept and the functionality of Readout Geometry has been merged\n"
<< "into Parallel World. This G4VReadOutGeometry is kept for the sake of\n"
<< "not breaking the commonly-used interface in the sensitive detector "
"class.\n"
<< "But this functionality of G4VReadOutGeometry class is no longer "
"tested\n"
<< "and thus may not be working well. We strongly recommend our customers "
"to\n"
<< "migrate to Parallel World scheme.";
ed << "The concept and the functionality of Readout Geometry has been merged\n"
<< "into Parallel World. This G4VReadOutGeometry is kept for the sake of\n"
<< "not breaking the commonly-used interface in the sensitive detector "
"class.\n"
<< "But this functionality of G4VReadOutGeometry class is no longer "
"tested\n"
<< "and thus may not be working well. We strongly recommend our customers "
"to\n"
<< "migrate to Parallel World scheme.";
G4Exception("G4VReadOutGeometry", "DIGIHIT1001", JustWarning, ed);
}
G4VReadOutGeometry::G4VReadOutGeometry(const G4VReadOutGeometry& right)
{
fincludeList = nullptr;
fexcludeList = nullptr;
name = right.name;
ROworld = right.ROworld;
fincludeList = nullptr;
fexcludeList = nullptr;
name = right.name;
ROworld = right.ROworld;
touchableHistory = nullptr;
ROnavigator = new G4Navigator();
ROnavigator = new G4Navigator();
// COPY CONSTRUCTOR NOT STRAIGHT FORWARD: need to copy the touchabelHistory
// VALUE, same for navigator and same for the World+Geom hierachy
}
G4VReadOutGeometry::G4VReadOutGeometry(G4String n)
: ROworld(nullptr)
, fincludeList(nullptr)
, fexcludeList(nullptr)
, name(n)
, touchableHistory(nullptr)
: ROworld(nullptr),
fincludeList(nullptr),
fexcludeList(nullptr),
name(n),
touchableHistory(nullptr)
{
ROnavigator = new G4Navigator();
G4ExceptionDescription ed;
ed
<< "The concept and the functionality of Readout Geometry has been merged\n"
<< "into Parallel World. This G4VReadOutGeometry is kept for the sake of\n"
<< "not breaking the commonly-used interface in the sensitive detector "
"class.\n"
<< "But this functionality of G4VReadOutGeometry class is no longer "
"tested\n"
<< "and thus may not be working well. We strongly recommend our customers "
"to\n"
<< "migrate to Parallel World scheme.";
ed << "The concept and the functionality of Readout Geometry has been merged\n"
<< "into Parallel World. This G4VReadOutGeometry is kept for the sake of\n"
<< "not breaking the commonly-used interface in the sensitive detector "
"class.\n"
<< "But this functionality of G4VReadOutGeometry class is no longer "
"tested\n"
<< "and thus may not be working well. We strongly recommend our customers "
"to\n"
<< "migrate to Parallel World scheme.";
G4Exception("G4VReadOutGeometry", "DIGIHIT1001", JustWarning, ed);
}
@@ -89,27 +85,21 @@ G4VReadOutGeometry::~G4VReadOutGeometry()
{
// if(ROworld) delete ROworld; //should we do ? will it delete the goem tree
// also ?
if(fincludeList)
delete fincludeList;
if(fexcludeList)
delete fexcludeList;
if(touchableHistory)
delete touchableHistory;
if(ROnavigator)
delete ROnavigator;
delete fincludeList;
delete fexcludeList;
delete touchableHistory;
delete ROnavigator;
}
G4VReadOutGeometry& G4VReadOutGeometry::operator=(
const G4VReadOutGeometry& right)
G4VReadOutGeometry& G4VReadOutGeometry::operator=(const G4VReadOutGeometry& right)
{
if(this == &right)
return *this;
if (this == &right) return *this;
delete fincludeList;
fincludeList = nullptr;
delete fexcludeList;
fexcludeList = nullptr;
name = right.name;
ROworld = right.ROworld;
name = right.name;
ROworld = right.ROworld;
delete touchableHistory;
touchableHistory = nullptr;
delete ROnavigator;
@@ -119,12 +109,12 @@ G4VReadOutGeometry& G4VReadOutGeometry::operator=(
G4bool G4VReadOutGeometry::operator==(const G4VReadOutGeometry& right) const
{
return (this == (G4VReadOutGeometry*) &right);
return (this == (G4VReadOutGeometry*)&right);
}
G4bool G4VReadOutGeometry::operator!=(const G4VReadOutGeometry& right) const
{
return (this != (G4VReadOutGeometry*) &right);
return (this != (G4VReadOutGeometry*)&right);
}
void G4VReadOutGeometry::BuildROGeometry()
@@ -133,37 +123,29 @@ void G4VReadOutGeometry::BuildROGeometry()
ROnavigator->SetWorldVolume(ROworld);
}
G4bool G4VReadOutGeometry::CheckROVolume(G4Step* currentStep,
G4TouchableHistory*& ROhist)
G4bool G4VReadOutGeometry::CheckROVolume(G4Step* currentStep, G4TouchableHistory*& ROhist)
{
ROhist = nullptr;
ROhist = nullptr;
G4bool incFlg = true;
auto PV = currentStep->GetPreStepPoint()->GetPhysicalVolume();
if((fexcludeList) && (fexcludeList->CheckPV(PV)))
{
auto PV = currentStep->GetPreStepPoint()->GetPhysicalVolume();
if (((fexcludeList) != nullptr) && (fexcludeList->CheckPV(PV))) {
incFlg = false;
}
else if((fincludeList) && (fincludeList->CheckPV(PV)))
{
else if (((fincludeList) != nullptr) && (fincludeList->CheckPV(PV))) {
incFlg = true;
}
else if((fexcludeList) && (fexcludeList->CheckLV(PV->GetLogicalVolume())))
{
else if (((fexcludeList) != nullptr) && (fexcludeList->CheckLV(PV->GetLogicalVolume()))) {
incFlg = false;
}
else if((fincludeList) && (fincludeList->CheckLV(PV->GetLogicalVolume())))
{
else if (((fincludeList) != nullptr) && (fincludeList->CheckLV(PV->GetLogicalVolume()))) {
incFlg = true;
}
if(!incFlg)
return false;
if (! incFlg) return false;
if(ROworld)
{
if (ROworld != nullptr) {
incFlg = FindROTouchable(currentStep);
}
if(incFlg)
{
if (incFlg) {
ROhist = touchableHistory;
}
return incFlg;
@@ -179,19 +161,14 @@ G4bool G4VReadOutGeometry::FindROTouchable(G4Step* currentStep)
// At first invokation, creates the touchable history. Note
// that default value (false) of Locate method is used.
// ---------> But the default Value is TRUE <-------------------- J.A.
if(!touchableHistory)
{
if (touchableHistory == nullptr) {
touchableHistory = new G4TouchableHistory();
ROnavigator->LocateGlobalPointAndUpdateTouchable(
currentStep->GetPreStepPoint()->GetPosition(),
ROnavigator->LocateGlobalPointAndUpdateTouchable(currentStep->GetPreStepPoint()->GetPosition(),
currentStep->GetPreStepPoint()->GetMomentumDirection(), touchableHistory);
}
else
{
ROnavigator->LocateGlobalPointAndUpdateTouchable(
currentStep->GetPreStepPoint()->GetPosition(),
currentStep->GetPreStepPoint()->GetMomentumDirection(), touchableHistory,
true);
else {
ROnavigator->LocateGlobalPointAndUpdateTouchable(currentStep->GetPreStepPoint()->GetPosition(),
currentStep->GetPreStepPoint()->GetMomentumDirection(), touchableHistory, true);
}
// Can the above be improved by the use of an isotropic safety
// in order to avoid LocateGlobalPointAndUpdateTouchable
@@ -203,9 +180,8 @@ G4bool G4VReadOutGeometry::FindROTouchable(G4Step* currentStep)
// checks if volume is sensitive:
auto currentVolume = touchableHistory->GetVolume();
// checks first if a physical volume exists here:
if(currentVolume)
{
return currentVolume->GetLogicalVolume()->GetSensitiveDetector() != 0;
if (currentVolume != nullptr) {
return currentVolume->GetLogicalVolume()->GetSensitiveDetector() != nullptr;
}
// no sensitive volume found: returns false
return false;
@@ -27,15 +27,12 @@
//
// G4VSensitiveDetector
#include "G4VSDFilter.hh"
#include "G4SDManager.hh"
G4VSDFilter::G4VSDFilter(G4String name)
: filterName(name)
G4VSDFilter::G4VSDFilter(G4String name) : filterName(name)
{
G4SDManager::GetSDMpointer()->RegisterSDFilter(this);
}
G4VSDFilter::~G4VSDFilter()
{
G4SDManager::GetSDMpointer()->DeRegisterSDFilter(this);
}
G4VSDFilter::~G4VSDFilter() { G4SDManager::GetSDMpointer()->DeRegisterSDFilter(this); }
@@ -37,7 +37,7 @@
#include "G4VScoreHistFiller.hh"
G4VScoreHistFiller* G4VScoreHistFiller::fgMasterInstance = nullptr;
G4VScoreHistFiller* G4VScoreHistFiller::fgMasterInstance = nullptr;
G4ThreadLocal G4VScoreHistFiller* G4VScoreHistFiller::fgInstance = nullptr;
G4VScoreHistFiller* G4VScoreHistFiller::Instance()
@@ -46,12 +46,10 @@ G4VScoreHistFiller* G4VScoreHistFiller::Instance()
// The master instance should be created by the user
// via the concrete class constructor
G4bool isMaster = !G4Threading::IsWorkerThread();
G4bool isMaster = ! G4Threading::IsWorkerThread();
if((!isMaster) && (!fgInstance))
{
if(fgMasterInstance)
{
if ((! isMaster) && (fgInstance == nullptr)) {
if (fgMasterInstance != nullptr) {
fgInstance = fgMasterInstance->CreateInstance();
}
}
@@ -61,29 +59,26 @@ G4VScoreHistFiller* G4VScoreHistFiller::Instance()
G4VScoreHistFiller::G4VScoreHistFiller()
{
G4bool isMaster = !G4Threading::IsWorkerThread();
G4bool isMaster = ! G4Threading::IsWorkerThread();
if(isMaster && fgMasterInstance)
{
if (isMaster && (fgMasterInstance != nullptr)) {
G4ExceptionDescription description;
description << " "
<< "G4VScoreHistFiller on master already exists."
<< "Cannot create another instance.";
G4Exception("G4VScoreHistFiller::G4VScoreHistFiller()", "Analysis_F001",
FatalException, description);
G4Exception(
"G4VScoreHistFiller::G4VScoreHistFiller()", "Analysis_F001", FatalException, description);
}
if(fgInstance)
{
if (fgInstance != nullptr) {
G4ExceptionDescription description;
description << " "
<< "G4VScoreHistFiller on worker already exists."
<< "Cannot create another instance.";
G4Exception("G4VScoreHistFiller::G4VScoreHistFiller()", "Analysis_F001",
FatalException, description);
G4Exception(
"G4VScoreHistFiller::G4VScoreHistFiller()", "Analysis_F001", FatalException, description);
}
if(isMaster)
fgMasterInstance = this;
if (isMaster) fgMasterInstance = this;
fgInstance = this;
}
G4VScoreHistFiller::~G4VScoreHistFiller() { fgInstance = 0; }
G4VScoreHistFiller::~G4VScoreHistFiller() { fgInstance = nullptr; }
@@ -27,28 +27,22 @@
//
// G4VSensitiveDetector
#include "G4VSensitiveDetector.hh"
#include "G4SDManager.hh"
G4VSensitiveDetector::G4VSensitiveDetector(G4String name)
: verboseLevel(0)
, active(true)
, ROgeometry(nullptr)
, filter(nullptr)
{
size_t sLast = name.rfind('/');
if(sLast == std::string::npos)
{ // detector name only
if (sLast == std::string::npos) { // detector name only
SensitiveDetectorName = name;
thePathName = "/";
thePathName = "/";
}
else
{ // name conatin the directory path
else { // name conatin the directory path
SensitiveDetectorName = name;
SensitiveDetectorName.erase(0, sLast + 1);
thePathName = name;
thePathName.erase(sLast + 1);
if(thePathName[0] != '/')
thePathName.insert(0, "/");
if (thePathName[0] != '/') thePathName.insert(0, "/");
}
fullPathName = thePathName + SensitiveDetectorName;
}
@@ -56,16 +50,14 @@ G4VSensitiveDetector::G4VSensitiveDetector(G4String name)
G4VSensitiveDetector::G4VSensitiveDetector(const G4VSensitiveDetector& right)
{
SensitiveDetectorName = right.SensitiveDetectorName;
thePathName = right.thePathName;
fullPathName = right.fullPathName;
verboseLevel = right.verboseLevel;
active = right.active;
ROgeometry = right.ROgeometry;
filter = right.filter;
thePathName = right.thePathName;
fullPathName = right.fullPathName;
verboseLevel = right.verboseLevel;
active = right.active;
ROgeometry = right.ROgeometry;
filter = right.filter;
}
G4VSensitiveDetector::~G4VSensitiveDetector() {}
G4VSensitiveDetector* G4VSensitiveDetector::Clone() const
{
G4ExceptionDescription msg;
@@ -76,18 +68,16 @@ G4VSensitiveDetector* G4VSensitiveDetector::Clone() const
return nullptr;
}
G4VSensitiveDetector& G4VSensitiveDetector::operator=(
const G4VSensitiveDetector& right)
G4VSensitiveDetector& G4VSensitiveDetector::operator=(const G4VSensitiveDetector& right)
{
if(this == &right)
return *this;
if (this == &right) return *this;
SensitiveDetectorName = right.SensitiveDetectorName;
thePathName = right.thePathName;
fullPathName = right.fullPathName;
verboseLevel = right.verboseLevel;
active = right.active;
ROgeometry = right.ROgeometry;
filter = right.filter;
thePathName = right.thePathName;
fullPathName = right.fullPathName;
verboseLevel = right.verboseLevel;
active = right.active;
ROgeometry = right.ROgeometry;
filter = right.filter;
return *this;
}
@@ -103,19 +93,6 @@ G4bool G4VSensitiveDetector::operator!=(const G4VSensitiveDetector& right) const
G4int G4VSensitiveDetector::GetCollectionID(G4int i)
{
return G4SDManager::GetSDMpointer()->GetCollectionID(SensitiveDetectorName +
"/" + collectionName[i]);
return G4SDManager::GetSDMpointer()->GetCollectionID(
SensitiveDetectorName + "/" + collectionName[i]);
}
//----- following methoods are abstract methods to be
//----- implemented in the concrete classes
void G4VSensitiveDetector::Initialize(G4HCofThisEvent*) {}
void G4VSensitiveDetector::EndOfEvent(G4HCofThisEvent*) {}
void G4VSensitiveDetector::clear() {}
void G4VSensitiveDetector::DrawAll() {}
void G4VSensitiveDetector::PrintAll() {}