Skip to content

Commit e0a28e8

Browse files
Update benchmark example (apt-sim#314)
1 parent b0d1967 commit e0a28e8

22 files changed

+192
-323
lines changed

examples/Example1/macros/example1_ttbar.mac.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
## Total number of GPU track slots (not per thread)
2626
/adept/setMillionsOfTrackSlots 8
2727
/adept/setMillionsOfHitSlots 1
28-
# /adept/setCUDAStackLimit 4096
28+
# /adept/setCUDAStackLimit 8192
2929

3030
# If true, particles are transported on the GPU across the whole geometry, GPU regions are ignored
3131
/adept/setTrackInAllRegions true

examples/IntegrationBenchmark/CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# SPDX-FileCopyrightText: 2023 CERN
22
# SPDX-License-Identifier: Apache-2.0
33

4+
SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--disable-new-dtags")
5+
46
if(NOT TARGET G4HepEm::g4HepEm)
57
message(STATUS "Disabling integrationBenchmark (needs G4HepEm)")
68
return()
@@ -67,3 +69,6 @@ target_link_libraries(integrationBenchmark
6769
configure_file("macros/integrationbenchmark.mac.in" "${CMAKE_BINARY_DIR}/integrationbenchmark.mac")
6870

6971
# Tests
72+
add_test(NAME integrationBenchmark
73+
COMMAND $<TARGET_FILE:integrationBenchmark> -m ${PROJECT_BINARY_DIR}/example1_large_stack.mac
74+
)

examples/IntegrationBenchmark/include/DetectorConstruction.hh

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#define DETECTORCONSTRUCTION_H
66

77
#include "G4VUserDetectorConstruction.hh"
8-
#include "G4SystemOfUnits.hh"
98
#include "G4Material.hh"
109
#include "G4ThreeVector.hh"
1110

@@ -31,7 +30,7 @@ class DetectorMessenger;
3130

3231
class DetectorConstruction : public G4VUserDetectorConstruction {
3332
public:
34-
DetectorConstruction();
33+
DetectorConstruction(bool allSensitive = false);
3534
virtual ~DetectorConstruction();
3635

3736
virtual G4VPhysicalVolume *Construct() final;
@@ -58,6 +57,7 @@ private:
5857
G4ThreeVector fMagFieldVector;
5958

6059
G4GDMLParser fParser;
60+
bool fAllSensitive;
6161
};
6262

6363
#endif /* DETECTORCONSTRUCTION_H */

examples/IntegrationBenchmark/include/EventAction.hh

+4-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
#include "G4UserEventAction.hh"
3232
#include "G4Timer.hh"
3333

34+
#include "RunAction.hh"
35+
3436
class DetectorConstruction;
3537
class EventActionMessenger;
3638

@@ -45,7 +47,7 @@ class EventActionMessenger;
4547

4648
class EventAction : public G4UserEventAction {
4749
public:
48-
EventAction();
50+
EventAction(RunAction *aRunAction);
4951
virtual ~EventAction();
5052

5153
/// Timer is started
@@ -69,6 +71,7 @@ private:
6971
G4Timer fTimer;
7072
/// Messenger for this
7173
EventActionMessenger *fMessenger{nullptr};
74+
RunAction *fRunAction{nullptr};
7275
};
7376

7477
#endif /* EVENTACTION_HH */

examples/IntegrationBenchmark/include/Run.hh

+5-8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
#include "G4Run.hh"
88

9+
#include "RunAction.hh"
10+
911
#define TAG_TYPE int
1012

1113
template <class TTag>
@@ -17,20 +19,16 @@ class TestManager;
1719
class Run : public G4Run {
1820

1921
public:
20-
Run();
22+
Run(RunAction *aRunAction);
2123
~Run();
2224

2325
/** @brief Merge the results of the worker threads */
2426
void Merge(const G4Run *run) override;
2527

2628
TestManager<TAG_TYPE> *GetTestManager() const { return fTestManager; }
27-
void SetDoBenchmark(bool aDoBenchmark) { fDoBenchmark = aDoBenchmark; }
28-
bool GetDoBenchmark() { return fDoBenchmark; }
29-
void SetDoValidation(bool aDoValidation) { fDoValidation = aDoValidation; }
30-
bool GetDoValidation() { return fDoValidation; }
3129

3230
/** @brief Compute and display collected metrics */
33-
void EndOfRunSummary(G4String aOutputDirectory, G4String aOutputFilename);
31+
void EndOfRunSummary(G4String aOutputDirectory, G4String aOutputFilenam);
3432

3533
/**
3634
* @brief Enum defining the timers that we can use for benchmarking
@@ -66,8 +64,7 @@ public:
6664

6765
private:
6866
TestManager<TAG_TYPE> *fTestManager;
69-
bool fDoBenchmark;
70-
bool fDoValidation;
67+
RunAction *fRunAction;
7168
};
7269

7370
#endif

examples/IntegrationBenchmark/include/RunAction.hh

+5
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ public:
5858

5959
G4Run *GenerateRun() override;
6060

61+
bool &GetDoBenchmark(){return fDoBenchmark;};
62+
bool &GetDoValidation(){return fDoValidation;};
63+
const G4String &GetOutputDirectory(){return fOutputDirectory;};
64+
const G4String &GetOutputFilename(){return fOutputFilename;};
65+
6166
private:
6267
/// Pointer to detector construction to retrieve the detector dimensions to
6368
/// setup the histograms

examples/IntegrationBenchmark/include/SensitiveDetector.hh

-8
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#include <set>
3333
#include "SimpleHit.hh"
3434

35-
#include "G4VFastSimSensitiveDetector.hh"
3635
#include "G4VSensitiveDetector.hh"
3736
#include <set>
3837

@@ -43,13 +42,6 @@ class G4TouchableHistory;
4342
* @brief Sensitive detector.
4443
*
4544
* Describes how to store the energy deposited within the detector.
46-
* It derives from two classes: G4VSensitiveDetector and
47-
* G4VFastSimSensitiveDetector. Addition of G4VFastSimSensitiveDetector is
48-
* necessary in order to handle the energy deposits from the fast simulation.
49-
*
50-
* Two ProcessHits() methods are introduced to handle energy deposited from full
51-
* (detailed) simulation, and from fast simulation. The common part is handled
52-
* by RetrieveAdnSetupHit() method.
5345
*
5446
*/
5547
class G4VPhysicalVolume;

examples/IntegrationBenchmark/include/SimpleHit.hh

+5-1
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,14 @@ public:
8484
inline void SetType(G4int aType) { fType = aType; }
8585
/// Get type (0 = full sim, 1 = fast sim)
8686
inline G4int GetType() const { return fType; }
87-
8887
/// Set PhysicalVolumeName
8988
inline void SetPhysicalVolumeName(G4String aPhysicalVolumeName) { fPhysicalVolumeName = aPhysicalVolumeName; }
9089
/// Get PhysicalVolumeName
9190
inline G4String GetPhysicalVolumeName() const { return fPhysicalVolumeName; }
91+
/// Set PhysicalVolumeId
92+
inline void SetPhysicalVolumeId(G4int aPhysicalVolumeId) { fPhysicalVolumeId = aPhysicalVolumeId; }
93+
/// Get PhysicalVolumeId
94+
inline G4int GetPhysicalVolumeId() const { return fPhysicalVolumeId; }
9295

9396
public:
9497
/// Energy deposit
@@ -101,6 +104,7 @@ public:
101104
G4int fType = -1;
102105
/// These hits will be associated to PhysicalVolumes
103106
G4String fPhysicalVolumeName = "";
107+
G4int fPhysicalVolumeId = -1;
104108
};
105109

106110
typedef G4THitsCollection<SimpleHit> SimpleHitsCollection;

examples/IntegrationBenchmark/include/SteppingAction.hh

+1-3
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,13 @@ class TrackingAction;
1515
class SteppingAction : public G4UserSteppingAction {
1616

1717
public:
18-
SteppingAction(TrackingAction *aTrackingAction, bool aDoBenchmark);
18+
SteppingAction();
1919
~SteppingAction() override;
2020
void UserSteppingAction(const G4Step *step) override;
2121
void SetNumSteps(int aNumSteps) { fNumSteps = aNumSteps; }
2222

2323
private:
24-
TrackingAction *fTrackingAction;
2524
int fNumSteps{0};
26-
bool fDoBenchmark{false};
2725
};
2826

2927
#endif

examples/IntegrationBenchmark/include/TrackingAction.hh

-13
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
// * acceptance of all terms of the Geant4 Software license. *
2525
// ********************************************************************
2626
//
27-
/// \file electromagnetic/TestEm1/include/TrackingAction.hh
2827
/// \brief Definition of the TrackingAction class
2928
//
3029
//
@@ -51,21 +50,9 @@ public:
5150
virtual void PreUserTrackingAction(const G4Track *);
5251
virtual void PostUserTrackingAction(const G4Track *);
5352

54-
void setInsideEcal(bool insideEcal) { fInsideEcal = insideEcal; }
55-
bool getInsideEcal() { return fInsideEcal; }
56-
57-
inline G4Region *getGPURegion() { return fGPURegion; }
58-
inline G4Region *getCurrentRegion() { return fCurrentRegion; }
59-
inline void setCurrentRegion(G4Region *aCurrentRegion) { fCurrentRegion = aCurrentRegion; }
60-
inline G4VPhysicalVolume *getCurrentVolume() { return fCurrentVolume; }
61-
inline void setCurrentVolume(G4VPhysicalVolume *aCurrentVolume) { fCurrentVolume = aCurrentVolume; }
6253
inline void setSteppingAction(SteppingAction *aSteppingAction) { fSteppingAction = aSteppingAction; }
6354

6455
private:
65-
bool fInsideEcal;
66-
G4Region *fCurrentRegion;
67-
G4VPhysicalVolume *fCurrentVolume;
68-
G4Region *fGPURegion;
6956
SteppingAction *fSteppingAction;
7057
};
7158

examples/IntegrationBenchmark/integrationBenchmark.cpp

+26-26
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
#include "G4UIExecutive.hh"
1717
#include <sstream>
1818

19-
#include <AdePT/integration/AdePTTrackingManager.hh>
20-
2119
int main(int argc, char **argv)
2220
{
2321
// Macro name from arguments
@@ -28,6 +26,8 @@ int main(int argc, char **argv)
2826
bool doValidation = false;
2927
G4bool useInteractiveMode = true;
3028
G4bool useAdePT = true;
29+
G4bool allSensitive = false; // If set, ignores the sensitive detector flags in the GDML and marks all volumes as
30+
// sensitive. Useful for validation of geometries with no SD info
3131
G4String helpMsg("Usage: " + G4String(argv[0]) +
3232
" [option(s)] \n No additional arguments triggers an interactive mode "
3333
"executing vis.mac macro. \n Options:\n\t-h\t\tdisplay this help "
@@ -50,9 +50,11 @@ int main(int argc, char **argv)
5050
} else if (argument == "--do_benchmark") {
5151
doBenchmark = true;
5252
} else if (argument == "--do_validation") {
53-
doValidation = true;
54-
} else if (argument == "--no_AdePT") {
53+
doValidation = true;
54+
} else if (argument == "--noadept") {
5555
useAdePT = false;
56+
} else if (argument == "--allsensitive") {
57+
allSensitive = true;
5658
} else {
5759
G4Exception("main", "Unknown argument", FatalErrorInArgument,
5860
("Unknown argument passed to " + G4String(argv[0]) + " : " + argument + "\n" + helpMsg).c_str());
@@ -65,44 +67,42 @@ int main(int argc, char **argv)
6567
"The options --do_benchmark and --do_validation are mutually exclusive! --do_benchmark will be ignored");
6668
}
6769
if (!doBenchmark && !doValidation) {
68-
G4Exception(
69-
"main()", "Notification", JustWarning,
70-
"Testing is enabled but no option has been selected, data will not be collected for this run.\n"
71-
"Available options are:\n"
72-
"--do_benchmark\n"
73-
"--do_validation");
70+
G4Exception("main()", "Notification", JustWarning,
71+
"Testing is enabled but no option has been selected, data will not be collected for this run.\n"
72+
"Available options are:\n"
73+
"--do_benchmark\n"
74+
"--do_validation");
7475
}
7576

7677
// Initialization of default Run manager
7778
auto *runManager = G4RunManagerFactory::CreateRunManager(G4RunManagerType::Default);
78-
//auto *runManager = G4RunManagerFactory::CreateRunManager(G4RunManagerType::Serial);
79+
// auto *runManager = G4RunManagerFactory::CreateRunManager(G4RunManagerType::Serial);
7980

8081
// Detector geometry:
81-
auto detector = new DetectorConstruction();
82+
auto detector = new DetectorConstruction(allSensitive);
8283
runManager->SetUserInitialization(detector);
8384

84-
// Physics list
85-
//
86-
G4VUserPhysicsList *physicsList;
85+
// Physics list
86+
//
87+
G4VUserPhysicsList *physicsList;
8788

88-
if(useAdePT){
89-
physicsList = new FTFP_BERT_AdePT();
90-
}
91-
else{
92-
physicsList = new FTFP_BERT_HepEm();
93-
}
89+
if (useAdePT) {
90+
physicsList = new FTFP_BERT_AdePT();
91+
} else {
92+
physicsList = new FTFP_BERT_HepEm();
93+
}
9494

95-
runManager->SetUserInitialization(physicsList);
95+
runManager->SetUserInitialization(physicsList);
9696

97-
// reduce verbosity of physics lists
98-
G4EmParameters::Instance()->SetVerbose(0);
99-
G4HadronicProcessStore::Instance()->SetVerbose(0);
97+
// reduce verbosity of physics lists
98+
G4EmParameters::Instance()->SetVerbose(0);
99+
G4HadronicProcessStore::Instance()->SetVerbose(0);
100100

101101
//-------------------------------
102102
// UserAction classes
103103
//-------------------------------
104104
runManager->SetUserInitialization(
105-
new ActionInitialisation(outputDirectory, outputFilename, doBenchmark, doValidation));
105+
new ActionInitialisation(outputDirectory, outputFilename, doBenchmark, doValidation));
106106

107107
G4UImanager *UImanager = G4UImanager::GetUIpointer();
108108
G4String command = "/control/execute ";

examples/IntegrationBenchmark/macros/integrationbenchmark.mac.in

+17-20
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
## Geant4 macro for modelling simplified sampling calorimeters
88
## =============================================================================
99
##
10-
/run/numberOfThreads 1
10+
/run/numberOfThreads 8
1111
/control/verbose 0
1212
/run/verbose 0
1313
/process/verbose 0
@@ -21,10 +21,18 @@
2121
/adept/setVecGeomGDML cms2018_sd.gdml
2222
/adept/setVerbosity 0
2323
## Threshold for buffering tracks before sending to GPU
24-
/adept/setTransportBufferThreshold 200
24+
/adept/setTransportBufferThreshold 2000
2525
## Total number of GPU track slots (not per thread)
26-
/adept/setMillionsOfTrackSlots 1
26+
/adept/setMillionsOfTrackSlots 8
2727
/adept/setMillionsOfHitSlots 1
28+
/adept/setCUDAStackLimit 8192
29+
30+
# If true, particles are transported on the GPU across the whole geometry, GPU regions are ignored
31+
/adept/setTrackInAllRegions true
32+
# In order to do the GPU transport only in specific regions
33+
#/adept/addGPURegion EcalRegion
34+
#/adept/addGPURegion HcalRegion
35+
2836

2937
## -----------------------------------------------------------------------------
3038
## Optionally, set a constant magnetic filed:
@@ -41,22 +49,11 @@
4149
## User-defined Event verbosity: 1 = total edep, 2 = energy deposit per placed sensitive volume
4250
/eventAction/verbose 2
4351

44-
/gun/setDefault
45-
/gun/particle e-
46-
/gun/energy 10 GeV
47-
/gun/number 200
48-
/gun/position 0 0 0
49-
/gun/print true
50-
51-
#If false, the following parameters are ignored
52-
/gun/randomizeGun true
53-
#Usage: /gun/addParticle type ["weight" weight] ["energy" energy unit]
54-
/gun/addParticle e- weight 1 energy 10 GeV
55-
/gun/addParticle proton weight 0 energy 10 GeV
56-
/gun/minPhi 0 deg
57-
/gun/maxPhi 360 deg
58-
/gun/minTheta 10 deg
59-
/gun/maxTheta 170 deg
52+
/gun/hepmc
53+
/generator/hepmcAscii/maxevents 256
54+
/generator/hepmcAscii/firstevent 0
55+
/generator/hepmcAscii/open ppttbar.hepmc3
56+
/generator/hepmcAscii/verbose 0
6057

6158
## -----------------------------------------------------------------------------
6259
## Run the simulation with the given number of events and print list of processes
@@ -66,5 +63,5 @@
6663

6764
# run events with parametrised simulation
6865
# by default all created models are active
69-
/run/beamOn 1
66+
/run/beamOn 8
7067

0 commit comments

Comments
 (0)