Skip to content

Commit

Permalink
moving initialization of AdePT to BuildPhysicsTable and other cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Witold Pokorski committed Oct 19, 2023
1 parent 9cd9d37 commit 0896faf
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 46 deletions.
1 change: 1 addition & 0 deletions examples/Example21/AdeptIntegration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ adeptint::VolAuxData *AdeptIntegration::CreateVolAuxData(const G4VPhysicalVolume
nphysical++;

// Check if the volume belongs to the interesting region
// I am commenting out this 'if' because (for the moment) we don't want any particles leaking out from AdePT
//if (g4vol->GetRegion() == fRegion) {
auxData[vol->id()].fGPUregion = 1;
ninregion++;
Expand Down
8 changes: 2 additions & 6 deletions examples/Example21/include/AdePTTrackingManager.hh
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,17 @@ public:
/// Set buffer threshold for AdePT
void SetBufferThreshold(int value) { fBufferThreshold = value; }

/// Initialized VecGeom, etc.

void Initialize();

void SetSensitiveVolumes(std::unordered_map<std::string, int> *sv) { sensitive_volume_index = sv; }

void SetScoringMap(std::unordered_map<const G4VPhysicalVolume *, int> *sm) { fScoringMap = sm; }

// Set total number of track slots on GPU
void SetTrackSlots(double value) { fTrackSlotsGPU = value; }

/// AdePT integration
AdeptIntegration *fAdept;

private:
/// AdePT integration
AdeptIntegration *fAdept;

/// Region where it applies
G4Region *fRegion{nullptr};
Expand Down
54 changes: 24 additions & 30 deletions examples/Example21/src/AdePTTrackingManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,30 @@ AdePTTrackingManager::~AdePTTrackingManager() {
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

void AdePTTrackingManager::BuildPhysicsTable(const G4ParticleDefinition &part) {
fAdept = new AdeptIntegration;

fAdept->SetDebugLevel(fVerbosity);
fAdept->SetBufferThreshold(fBufferThreshold);
fAdept->SetMaxBatch(2 * fBufferThreshold);

G4RunManager::RMType rmType = G4RunManager::GetRunManager()->GetRunManagerType();
bool sequential = (rmType == G4RunManager::sequentialRM);

fAdept->SetSensitiveVolumes(sensitive_volume_index);
fAdept->SetScoringMap(fScoringMap);
fAdept->SetRegion(fRegion);

auto tid = G4Threading::G4GetThreadId();
if (tid < 0) {
// This is supposed to set the max batching for Adept to allocate properly the memory
int num_threads = G4RunManager::GetRunManager()->GetNumberOfThreads();
int capacity = 1024 * 1024 * fTrackSlotsGPU / num_threads;
AdeptIntegration::SetTrackCapacity(capacity);
fAdept->Initialize(true /*common_data*/);
if (sequential) fAdept->Initialize();
} else {
fAdept->Initialize();
}
}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Expand All @@ -42,8 +66,6 @@ void AdePTTrackingManager::HandOverOneTrack(G4Track *aTrack) {
G4double energy = aTrack->GetKineticEnergy();
auto pdg = aTrack->GetParticleDefinition()->GetPDGEncoding();

//int tid = G4Threading::G4GetThreadId();

fAdept->AddTrack(pdg, energy, particlePosition[0], particlePosition[1], particlePosition[2], particleDirection[0],
particleDirection[1], particleDirection[2]);

Expand All @@ -60,31 +82,3 @@ void AdePTTrackingManager::FlushEvent() {
fAdept->Shower(G4EventManager::GetEventManager()->GetConstCurrentEvent()->GetEventID());
}

void AdePTTrackingManager::Initialize()
{

fAdept = new AdeptIntegration;

fAdept->SetDebugLevel(fVerbosity);
fAdept->SetBufferThreshold(fBufferThreshold);
fAdept->SetMaxBatch(2 * fBufferThreshold);

G4RunManager::RMType rmType = G4RunManager::GetRunManager()->GetRunManagerType();
bool sequential = (rmType == G4RunManager::sequentialRM);

fAdept->SetSensitiveVolumes(sensitive_volume_index);
fAdept->SetScoringMap(fScoringMap);
fAdept->SetRegion(fRegion);

auto tid = G4Threading::G4GetThreadId();
if (tid < 0) {
// This is supposed to set the max batching for Adept to allocate properly the memory
int num_threads = G4RunManager::GetRunManager()->GetNumberOfThreads();
int capacity = 1024 * 1024 * fTrackSlotsGPU / num_threads;
AdeptIntegration::SetTrackCapacity(capacity);
fAdept->Initialize(true /*common_data*/);
if (sequential) fAdept->Initialize();
} else {
fAdept->Initialize();
}
}
16 changes: 8 additions & 8 deletions examples/Example21/src/DetectorConstruction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ void DetectorConstruction::ConstructSDandField()
SensitiveDetector *caloSD = new SensitiveDetector("AdePTDetector", numSensitive);
caloSD->fScoringMap = &gScoringMap;
G4SDManager::GetSDMpointer()->AddNewDetector(caloSD);

auto const &store = *G4LogicalVolumeStore::GetInstance();

// maybe we can resurect this code later if we want to run AdePT only in a part of the detector
// for the moment, I removed also check for AdePT region inside AdePT code
/*
auto detectorRegion = G4RegionStore::GetInstance()->GetRegion(fRegion_name);
// attaching sensitive detector to the volumes on sentitive_volumes list
Expand All @@ -153,6 +159,8 @@ void DetectorConstruction::ConstructSDandField()
}
}
}
*/

int index = 1;
for (auto name : fSensitive_volumes) {
G4cout << "Making " << name << " sensitive with index " << index << G4endl;
Expand All @@ -170,14 +178,6 @@ void DetectorConstruction::ConstructSDandField()
adeptTrMgr->SetVerbosity(fVerbosity);
adeptTrMgr->SetBufferThreshold(fBufferThreshold);
adeptTrMgr->SetTrackSlots(fTrackSlotsGPU);

try {
adeptTrMgr->Initialize();
} catch (const std::runtime_error &ex) {
std::cerr << ex.what() << "\n";
exit(EXIT_FAILURE);
return;
}
}
}

Expand Down
5 changes: 3 additions & 2 deletions examples/Example21/src/TrackingAction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@
TrackingAction::TrackingAction(DetectorConstruction* aDetector) : G4UserTrackingAction(),
fDetector(aDetector),
fCurrentRegion(nullptr),
fCurrentVolume(nullptr),
fGPURegion(G4RegionStore::GetInstance()->GetRegion(aDetector->getRegionName())){}
fCurrentVolume(nullptr)
//, fGPURegion(G4RegionStore::GetInstance()->GetRegion(aDetector->getRegionName()))
{}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

Expand Down

0 comments on commit 0896faf

Please sign in to comment.