Import Geant4 11.0.0.beta source tree
This commit is contained in:
@@ -23,8 +23,14 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4VUserDetectorConstruction implementation
|
||||
//
|
||||
//
|
||||
// Original author: M.Asai, 1999
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
#include <sstream>
|
||||
#include <map>
|
||||
#include <assert.h>
|
||||
|
||||
#include "G4VUserDetectorConstruction.hh"
|
||||
#include "G4FieldManager.hh"
|
||||
@@ -35,107 +41,111 @@
|
||||
#include "G4VPhysicalVolume.hh"
|
||||
#include "G4VSensitiveDetector.hh"
|
||||
#include "G4VUserParallelWorld.hh"
|
||||
#include <assert.h>
|
||||
#include <sstream>
|
||||
#include "G4RunManager.hh"
|
||||
|
||||
G4VUserDetectorConstruction::G4VUserDetectorConstruction() { ; }
|
||||
|
||||
G4VUserDetectorConstruction::~G4VUserDetectorConstruction() { ; }
|
||||
|
||||
void G4VUserDetectorConstruction::RegisterParallelWorld(
|
||||
G4VUserParallelWorld* aPW)
|
||||
// --------------------------------------------------------------------
|
||||
G4VUserDetectorConstruction::G4VUserDetectorConstruction()
|
||||
{
|
||||
std::vector<G4VUserParallelWorld*>::iterator pwItr;
|
||||
for(pwItr = parallelWorld.begin(); pwItr != parallelWorld.end(); pwItr++)
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
G4VUserDetectorConstruction::~G4VUserDetectorConstruction()
|
||||
{
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
void G4VUserDetectorConstruction::
|
||||
RegisterParallelWorld(G4VUserParallelWorld* aPW)
|
||||
{
|
||||
auto pwItr = std::find(parallelWorld.cbegin(), parallelWorld.cend(), aPW);
|
||||
if (pwItr != parallelWorld.cend())
|
||||
{
|
||||
if((*pwItr)->GetName() == aPW->GetName())
|
||||
{
|
||||
G4String eM = "A parallel world <";
|
||||
eM += aPW->GetName();
|
||||
eM += "> is already registered to the user detector construction.";
|
||||
G4Exception("G4VUserDetectorConstruction::RegisterParallelWorld",
|
||||
"Run0051", FatalErrorInArgument, eM);
|
||||
}
|
||||
G4String eM = "A parallel world <";
|
||||
eM += aPW->GetName();
|
||||
eM += "> is already registered to the user detector construction.";
|
||||
G4Exception("G4VUserDetectorConstruction::RegisterParallelWorld",
|
||||
"Run0051", FatalErrorInArgument, eM);
|
||||
}
|
||||
parallelWorld.push_back(aPW);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
G4int G4VUserDetectorConstruction::ConstructParallelGeometries()
|
||||
{
|
||||
G4int nP = 0;
|
||||
std::vector<G4VUserParallelWorld*>::iterator pwItr;
|
||||
for(pwItr = parallelWorld.begin(); pwItr != parallelWorld.end(); pwItr++)
|
||||
for(auto pwItr = parallelWorld.cbegin();
|
||||
pwItr != parallelWorld.cend(); ++pwItr)
|
||||
{
|
||||
(*pwItr)->Construct();
|
||||
nP++;
|
||||
++nP;
|
||||
}
|
||||
return nP;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
void G4VUserDetectorConstruction::ConstructParallelSD()
|
||||
{
|
||||
std::vector<G4VUserParallelWorld*>::iterator pwItr;
|
||||
for(pwItr = parallelWorld.begin(); pwItr != parallelWorld.end(); pwItr++)
|
||||
for(auto pwItr = parallelWorld.cbegin();
|
||||
pwItr != parallelWorld.cend(); ++pwItr)
|
||||
{
|
||||
(*pwItr)->ConstructSD();
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
G4int G4VUserDetectorConstruction::GetNumberOfParallelWorld() const
|
||||
{
|
||||
return parallelWorld.size();
|
||||
}
|
||||
|
||||
G4VUserParallelWorld* G4VUserDetectorConstruction::GetParallelWorld(
|
||||
G4int i) const
|
||||
// --------------------------------------------------------------------
|
||||
G4VUserParallelWorld*
|
||||
G4VUserDetectorConstruction::GetParallelWorld(G4int i) const
|
||||
{
|
||||
if(i < 0 || i >= GetNumberOfParallelWorld())
|
||||
return 0;
|
||||
return nullptr;
|
||||
return parallelWorld[i];
|
||||
}
|
||||
|
||||
#include "G4RunManager.hh"
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
void G4VUserDetectorConstruction::ConstructSDandField()
|
||||
{
|
||||
// G4RunManager::RMType rmtype =
|
||||
// G4RunManager::GetRunManager()->GetRunManagerType(); if(rmtype !=
|
||||
// G4RunManager::sequentialRM)
|
||||
// {
|
||||
// G4cout
|
||||
// << "User-derived detector construction class does not implement \n"
|
||||
// << "ConstructSDandFiled method: i.e. workers will not have SD and
|
||||
// fields!\n"
|
||||
// << "The user can safely ignore this message if (s)he has no sensitive\n"
|
||||
// << "detector or field in her/his application." << G4endl;
|
||||
// }
|
||||
// G4RunManager::RMType rmtype =
|
||||
// G4RunManager::GetRunManager()->GetRunManagerType(); if(rmtype !=
|
||||
// G4RunManager::sequentialRM)
|
||||
// {
|
||||
// G4cout
|
||||
// << "User-derived detector construction class does not implement \n"
|
||||
// << "ConstructSDandFiled method: workers will not have SD and fields!\n"
|
||||
// << "The user can safely ignore this message if (s)he has no sensitive\n"
|
||||
// << "detector or field in her/his application." << G4endl;
|
||||
// }
|
||||
}
|
||||
|
||||
#include <map>
|
||||
// --------------------------------------------------------------------
|
||||
void G4VUserDetectorConstruction::CloneF()
|
||||
{
|
||||
typedef std::map<G4FieldManager*, G4FieldManager*> FMtoFMmap;
|
||||
typedef std::pair<G4FieldManager*, G4FieldManager*> FMpair;
|
||||
using FMtoFMmap = std::map<G4FieldManager*, G4FieldManager*>;
|
||||
using FMpair = std::pair<G4FieldManager*, G4FieldManager*>;
|
||||
|
||||
FMtoFMmap masterToWorker;
|
||||
G4LogicalVolumeStore* const logVolStore = G4LogicalVolumeStore::GetInstance();
|
||||
assert(logVolStore != NULL);
|
||||
for(G4LogicalVolumeStore::const_iterator it = logVolStore->begin();
|
||||
it != logVolStore->end(); ++it)
|
||||
for(auto it = logVolStore->cbegin(); it != logVolStore->cend(); ++it)
|
||||
{
|
||||
G4LogicalVolume* g4LogicalVolume = *it;
|
||||
// Use shadow of master to get instance of FM
|
||||
G4FieldManager* masterFM = 0; // g4LogicalVolume->fFieldManager;
|
||||
G4FieldManager* clonedFM = 0;
|
||||
if(masterFM)
|
||||
G4FieldManager* masterFM = nullptr; // g4LogicalVolume->fFieldManager;
|
||||
G4FieldManager* clonedFM = nullptr;
|
||||
if(masterFM != nullptr)
|
||||
{
|
||||
FMtoFMmap::iterator fmFound = masterToWorker.find(masterFM);
|
||||
if(fmFound == masterToWorker.end())
|
||||
auto fmFound = masterToWorker.find(masterFM);
|
||||
if(fmFound == masterToWorker.cend())
|
||||
{
|
||||
// First time we see this SD, let's clone and remember...
|
||||
try
|
||||
{
|
||||
std::pair<FMtoFMmap::iterator, bool> insertedEl =
|
||||
masterToWorker.insert(FMpair(masterFM, masterFM->Clone()));
|
||||
auto insertedEl =
|
||||
masterToWorker.insert(FMpair(masterFM, masterFM->Clone()));
|
||||
clonedFM = (insertedEl.first)->second;
|
||||
} catch(...)
|
||||
{
|
||||
@@ -143,53 +153,52 @@ void G4VUserDetectorConstruction::CloneF()
|
||||
msg << "Cloning of G4FieldManager failed."
|
||||
<< " But derived class does not implement cloning. Cannot "
|
||||
"continue.";
|
||||
G4Exception("G4VUserDetectorConstruction::CloneSD", "Run0053",
|
||||
G4Exception("G4VUserDetectorConstruction::CloneSD()", "Run0053",
|
||||
FatalException, msg);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// We have already seen this SD attached to a fifferent LogicalVolume,
|
||||
// We have already seen this SD attached to a different LogicalVolume,
|
||||
// let's re-use previous clone
|
||||
clonedFM = (*fmFound).second;
|
||||
}
|
||||
} // masterFM != 0
|
||||
// Note that we do not push FM to doughters (false argument), however, since
|
||||
// Note that we do not push FM to daughters (false argument), however, since
|
||||
// we area looping on all logical volumes and we implemented the "trick" of
|
||||
// the map master<->cloned the final effect is the same as using here the
|
||||
// correct boolean flag: log-volumes that originally were sharing the same
|
||||
// correct Boolean flag: log-volumes that originally were sharing the same
|
||||
// FM they will have cloned ones
|
||||
g4LogicalVolume->SetFieldManager(clonedFM, false);
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
void G4VUserDetectorConstruction::CloneSD()
|
||||
{
|
||||
// Loop on ALL logial volumes to search for attached SD
|
||||
G4LogicalVolumeStore* const logVolStore = G4LogicalVolumeStore::GetInstance();
|
||||
assert(logVolStore != NULL);
|
||||
|
||||
typedef std::map<G4VSensitiveDetector*, G4VSensitiveDetector*> SDtoSDmap;
|
||||
typedef std::pair<G4VSensitiveDetector*, G4VSensitiveDetector*> SDpair;
|
||||
using SDtoSDmap = std::map<G4VSensitiveDetector*, G4VSensitiveDetector*>;
|
||||
using SDpair = std::pair<G4VSensitiveDetector*, G4VSensitiveDetector*>;
|
||||
SDtoSDmap masterToWorker;
|
||||
|
||||
for(G4LogicalVolumeStore::const_iterator it = logVolStore->begin();
|
||||
it != logVolStore->end(); ++it)
|
||||
for(auto it = logVolStore->cbegin(); it != logVolStore->cend(); ++it)
|
||||
{
|
||||
G4LogicalVolume* g4LogicalVolume = *it;
|
||||
// Use shadow of master to get the instance of SD
|
||||
G4VSensitiveDetector* masterSD = 0; // g4LogicalVolume->fSensitiveDetector;
|
||||
G4VSensitiveDetector* clonedSD = 0;
|
||||
if(masterSD)
|
||||
G4VSensitiveDetector* masterSD = nullptr;
|
||||
G4VSensitiveDetector* clonedSD = nullptr;
|
||||
if(masterSD != nullptr)
|
||||
{
|
||||
SDtoSDmap::iterator sdFound = masterToWorker.find(masterSD);
|
||||
if(sdFound == masterToWorker.end())
|
||||
auto sdFound = masterToWorker.find(masterSD);
|
||||
if(sdFound == masterToWorker.cend())
|
||||
{
|
||||
// First time we see this SD, let's clone and remember...
|
||||
try
|
||||
{
|
||||
std::pair<SDtoSDmap::iterator, bool> insertedEl =
|
||||
masterToWorker.insert(SDpair(masterSD, masterSD->Clone()));
|
||||
auto insertedEl =
|
||||
masterToWorker.insert(SDpair(masterSD, masterSD->Clone()));
|
||||
clonedSD = (insertedEl.first)->second;
|
||||
} catch(...)
|
||||
{
|
||||
@@ -201,13 +210,13 @@ void G4VUserDetectorConstruction::CloneSD()
|
||||
#endif
|
||||
<< " But derived class does not implement cloning. Cannot "
|
||||
"continue.";
|
||||
G4Exception("G4VUserDetectorConstruction::CloneSD", "Run0053",
|
||||
G4Exception("G4VUserDetectorConstruction::CloneSD()", "Run0053",
|
||||
FatalException, msg);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// We have already seen this SD attached to a fifferent LogicalVolume,
|
||||
// We have already seen this SD attached to a different LogicalVolume,
|
||||
// let's re-use previous clone
|
||||
clonedSD = (*sdFound).second;
|
||||
}
|
||||
@@ -216,44 +225,48 @@ void G4VUserDetectorConstruction::CloneSD()
|
||||
}
|
||||
}
|
||||
|
||||
void G4VUserDetectorConstruction::SetSensitiveDetector(
|
||||
const G4String& logVolName, G4VSensitiveDetector* aSD, G4bool multi)
|
||||
// --------------------------------------------------------------------
|
||||
void G4VUserDetectorConstruction::
|
||||
SetSensitiveDetector(const G4String& logVolName,
|
||||
G4VSensitiveDetector* aSD, G4bool multi)
|
||||
{
|
||||
G4bool found = false;
|
||||
G4LogicalVolumeStore* store = G4LogicalVolumeStore::GetInstance();
|
||||
for(G4LogicalVolumeStore::iterator pos = store->begin(); pos != store->end();
|
||||
pos++)
|
||||
auto volmap = store->GetMap();
|
||||
auto pos = volmap.find(logVolName);
|
||||
if(pos != volmap.cend())
|
||||
{
|
||||
if((*pos)->GetName() == logVolName)
|
||||
if ((pos->second.size()>1) && !multi)
|
||||
{
|
||||
if(found && !multi)
|
||||
{
|
||||
G4String eM = "More than one logical volumes of the name <";
|
||||
eM += (*pos)->GetName();
|
||||
eM += "> are found and thus the sensitive detector <";
|
||||
eM += aSD->GetName();
|
||||
eM += "> cannot be uniquely assigned.";
|
||||
G4Exception("G4VUserDetectorConstruction::SetSensitiveDetector",
|
||||
"Run0052", FatalErrorInArgument, eM);
|
||||
}
|
||||
found = true;
|
||||
SetSensitiveDetector(*pos, aSD);
|
||||
G4String eM = "More than one logical volumes of name <";
|
||||
eM += pos->first;
|
||||
eM += "> are found and thus the sensitive detector <";
|
||||
eM += aSD->GetName();
|
||||
eM += "> cannot be uniquely assigned.";
|
||||
G4Exception("G4VUserDetectorConstruction::SetSensitiveDetector()",
|
||||
"Run0052", FatalErrorInArgument, eM);
|
||||
}
|
||||
found = true;
|
||||
for (std::size_t i = 0; i < pos->second.size(); ++i)
|
||||
{
|
||||
SetSensitiveDetector(pos->second[i], aSD);
|
||||
}
|
||||
}
|
||||
if(!found)
|
||||
{
|
||||
G4String eM2 = "No logical volume of the name <";
|
||||
G4String eM2 = "No logical volume of name <";
|
||||
eM2 += logVolName;
|
||||
eM2 += "> is found. The specified sensitive detector <";
|
||||
eM2 += aSD->GetName();
|
||||
eM2 += "> couldn't be assigned to any volume.";
|
||||
G4Exception("G4VUserDetectorConstruction::SetSensitiveDetector", "Run0053",
|
||||
FatalErrorInArgument, eM2);
|
||||
G4Exception("G4VUserDetectorConstruction::SetSensitiveDetector()",
|
||||
"Run0053", FatalErrorInArgument, eM2);
|
||||
}
|
||||
}
|
||||
|
||||
void G4VUserDetectorConstruction::SetSensitiveDetector(
|
||||
G4LogicalVolume* logVol, G4VSensitiveDetector* aSD)
|
||||
// --------------------------------------------------------------------
|
||||
void G4VUserDetectorConstruction::
|
||||
SetSensitiveDetector(G4LogicalVolume* logVol, G4VSensitiveDetector* aSD)
|
||||
{
|
||||
assert(logVol != nullptr && aSD != nullptr);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user