Skip to content

Commit 22af3ca

Browse files
Benedikt Volkelsawenzel
authored andcommitted
Various updates and fixes
* store TGeoManager::GetPath() in MCStepLogger if track enters to restore geometry in replay. This is necessary in particular in case of steps on or in the vincinity of boundaries. Floating point precision might not be enough to find a node based on spatial coordinates. In addition, restoring from the path makes navigation and node finding obsolete during replay * extract TGEoVolume ID to VMC volume ID mapping. These are not the same for Geant4_VMC hence it is necessary. Mapping is required in replay, otheriwse, hit processing can fail. Mapping during replay is skipped if it is the identity. * make replay work for Geant4_VMC. This works thanks to above additions. * add possibility to load a custom user keepStep function from a ROOT macro * update MCReplay/README.md * additional small fixes
1 parent 5a7a825 commit 22af3ca

File tree

9 files changed

+203
-130
lines changed

9 files changed

+203
-130
lines changed

MCReplay/README.md

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,36 @@ This is a pseudo-detector-simulation engine based on the [Virtual Monte Carlo (V
44

55
The main objective is to be able to provide an engine to study the impact of parameter variations with. Eventually, this can be used to optimise (full-)simulation parameters in view of enhancing their speed and efficiency.
66

7-
The functionality is compiled into a separate library `libTMCReplay` which also allows to use the `libMCStepLoggerIntercept` which also allows to run the step logging against the `TMCReplay` engine.
7+
The functionality is compiled into a separate library `libMCReplayCore`. Hence, `libMCStepLoggerIntercept` is completely independent which also allows to run the step logging against the `MCReplayEngine` engine.
8+
9+
The replay has been tested and is verified against [GEANT3_VMC](https://github.com/vmc-project/geant3) and [GEANT4_VMC](https://github.com/vmc-project/geant4_vmc) VMC interfaces.
810

911
## Setting parameters
1012

11-
The list of tunable parameters is foreseen to correspond to the possible settings implemented for [GEANT3_VMC]() and [GEANT4_VMC](https://github.com/vmc-project/geant4_vmc) and can be found [here](include/TMCReplay/Physics.h). The parameters can be set via the usual interfaces
12-
* `TVirtualMC::SetCut` and `TVirtualMC::SetProcess` to set global cut and process values
13-
* `TVirtualMC::Gstpar` to set parameters depending on a certain medium
13+
The list of tunable parameters is foreseen to correspond to the possible settings implemented for GEANT3_VMC and GEANT4_VMC and can be found [here](include/MCReplay/MCReplayPhysics.h). The parameters can be set via the usual interfaces
14+
* `TVirtualMC::SetCut` and `TVirtualMC::SetProcess` to set global cut and process values,
15+
* `TVirtualMC::Gstpar` to set parameters depending on a certain medium.
16+
The cut parameters act like production cuts.
1417

1518
**Please note** that the parameters can be set but at the moment nothing is actually applied. Therefore, the exact same steps would be reproduced regardless of the parameters. Of course, this is the next major development as it is one of the core objectives of this engine.
19+
**On the other hand**, there is one special parameter called `CUTALLE` which is an energy production cut on **any** PDG which can also be set through the aforementioned interfaces. Note, that this parameter has no meaning to GEANT3_VMC or GEANT4_VMC.
1620

1721
## Testing different parameter settings
1822

19-
**Note that this section becomes actually meaningful when the aforementioned functionality will have been implemented.** However, in the current state it can already be verified that the `TMCReplay` engine does what it is supposed to do.
23+
**Note that this section becomes actually meaningful when the aforementioned functionality will have been implemented.** However, in the current state it can already be verified that the `MCReplayEngine` engine does what it is supposed to do.
2024

21-
### Running/testing on step level only (`TMCReplayDummyApplication` and `TMCReplayDummyStack`)
25+
### Running/testing on step level only (`MCReplayGenericApplication` and `MCReplayGenericStack`)
2226

23-
If only the impact on the steps is desired, all required functionality is already included here. Simply have a look at [this executable](src/replay.cxx). It makes use of the `TMCReplayDummyApplication` and `TMCReplayDummyStack` just to replay the steps. Once implemented, the impact of the parameters on the stepping can be evaluated with this tool alone. To do so, just run the `MCStepLogger` together with the replay, for instance as follows
27+
If only the replay of steps is desired, all required functionality is already included here, completely independent of any environment the reference run was done. Simply have a look at [this code](src/replay.cxx) serving as the source for the executable `mcreplay`. It makes use of the `MCReplayGenericApplication` and `MCReplayGenericStack` just to replay the steps. Once implemented, the impact of the parameters on the stepping can be evaluated with this tool alone. To do so, just run the `MCStepLogger` followed by the replay, for instance as follows (assuming everything was setup with `aliBuild`)
2428

2529
```bash
26-
MCSTEPLOG_TTREE=1 LD_PRELOAD=$MCSTEPLOGGER_ROOT/lib/libMCStepLoggerIntercept.so tmcreplay
30+
MCSTEPLOG_TTREE=1 LD_PRELOAD=$MCSTEPLOGGER_ROOT/lib/libMCStepLoggerIntercept.so mcreplay
2731
```
2832

2933
That will pick up the step file `MCStepLoggerOutput.root`. If you gave that a different name (or in case also your contained tree has another name), you will find the following help message useful:
3034

3135
```bash
32-
> tmcreplay --help
36+
> mcreplay --help
3337
Replaying a previously recorded particle transport step-by-step. Mainly meant for checking and performance measurements/optimisation of the transport:
3438
--help show this help message and exit
3539
--stepfilename arg (=MCStepLoggerOutput.root)
@@ -40,13 +44,18 @@ Replaying a previously recorded particle transport step-by-step. Mainly meant fo
4044
ROOT geometry filename
4145
--geokeyname arg (=FAIRGeom) key name inside geo file where to find
4246
geometry tree
43-
47+
-n [ --nevents ] arg (=-1) number of events to replay
48+
-e [ --energycut ] arg (=-1) energy cut to be applied [GeV]
4449
```
4550

46-
As you can see the geometry is required by this executable as well since it has otherwise no idea what geometry was used for the original simulation.
51+
As you can see the geometry is required by this executable as well since it has otherwise no idea what the geometry should look like from the `MCStepLoggerOutput.root` file alone.
4752

4853
### Running in another environment
4954

5055
In that case the geometry construction is assumed to implemented by that environment's implementation of `TVirtualMCApplication`. Also, no stack is constructed automatically and it has to be constructed and passed by the user.
5156

5257
Such a scenario is useful to evaluate the impact of parameter variation on hits or even digits.
58+
59+
## Using the engine as a full simulation engine
60+
61+
The `MCReplayEngine` has been tested with the [ALICE O2 framework](https://github.com/AliceO2Group/AliceO2) and also hits can be reproduced sufficiently which allows for realistic parameter tuning.

MCReplay/include/MCReplay/MCReplayEngine.h

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#define MC_REPLAY_ENGINE_H
1414

1515
#include <vector>
16-
#include <unordered_map>
1716
#include <string>
1817

1918
#include <TString.h>
@@ -36,6 +35,8 @@ class TGeoNode;
3635
namespace mcreplay
3736
{
3837

38+
typedef bool (*user_keep_step_type)(const o2::StepInfo&, const o2::StepLookups*);
39+
3940
class MCReplayEngine : public TVirtualMC
4041
{
4142

@@ -1092,13 +1093,20 @@ class MCReplayEngine : public TVirtualMC
10921093
mStepLoggerTreename = treename;
10931094
}
10941095

1096+
// aacept a macro path from where to load a custom function whether or not to keep a step
1097+
void setUserKeepStepMacroPath(const std::string& path)
1098+
{
1099+
mUserKeepStepMacroPath = path;
1100+
}
1101+
10951102
private:
10961103
// init the run, used to guarantee that both ProcessRun and ProcessEvent
10971104
// work just fine
10981105
bool initRun();
10991106

1100-
// TODO Can most likely be removed
1101-
void adaptToTGeoName(const char* nameIn, char* nameOut) const;
1107+
// map volume IDs assigned by the TGeoManager (replay engine) to those assigned by the engine used in the reference run
1108+
Int_t correctGeoVolID(Int_t geoVolId) const;
1109+
Int_t correctVMCVolID(Int_t vmcVolId) const;
11021110

11031111
// That is just a helper function to address some of the
11041112
// interactions with the TGeoManager
@@ -1130,7 +1138,6 @@ class MCReplayEngine : public TVirtualMC
11301138
{
11311139
auto paramIndex = physics::paramToIndex(allParamsNames, paramName);
11321140
if (paramIndex < 0) {
1133-
Warning("Could not set parameter %s, unknown and therefore skipped", paramName);
11341141
return false;
11351142
}
11361143

@@ -1151,7 +1158,6 @@ class MCReplayEngine : public TVirtualMC
11511158
{
11521159
auto paramIndex = physics::paramToIndex(allParamsNames, paramName);
11531160
if (paramIndex < 0) {
1154-
Warning("Could not set parameter %s, unknown and therefore skipped", paramName);
11551161
return false;
11561162
}
11571163
insertInto[paramIndex] = parval;
@@ -1174,6 +1180,11 @@ class MCReplayEngine : public TVirtualMC
11741180
std::string mStepLoggerFilename;
11751181
std::string mStepLoggerTreename;
11761182

1183+
// mapping volume IDs correctly; a reference run might assign other volume IDs than those which would be assigned only by the TGeoManager. Hence, we need to make sure that - whatever engine was used before - we mimic the exact same volume IDs. Otherwise, the logged IDs and those assigned by this engine based on the TGeoManager are not aligned
1184+
std::vector<int> mVolIDMap;
1185+
std::vector<int> mVolIDMapInverse;
1186+
bool mNeedVolIdMapping = false;
1187+
11771188
// pointer to opened step file
11781189
TFile* mStepFile = nullptr;
11791190

@@ -1190,6 +1201,11 @@ class MCReplayEngine : public TVirtualMC
11901201
o2::StepLookups* mCurrentLookups = nullptr;
11911202
o2::StepInfo* mCurrentStep = nullptr;
11921203

1204+
// keep track of tracks to be skipped
1205+
std::vector<bool> mSkipTrack;
1206+
// keep track of track ID assigned by user stack
1207+
std::vector<int> mUserTrackId;
1208+
11931209
// current event ID
11941210
int mCurrentEvent = 0;
11951211

@@ -1209,6 +1225,10 @@ class MCReplayEngine : public TVirtualMC
12091225
// point to the current map of cuts
12101226
std::vector<Double_t>* mCurrentCuts = nullptr;
12111227

1228+
// a user defined cut function, return true if step should be kept, false otherwise
1229+
std::string mUserKeepStepMacroPath;
1230+
user_keep_step_type* mUserKeepStep = nullptr;
1231+
12121232
// local pointer to ROOT's geometry manager
12131233
TGeoManager* mGeoManager = nullptr;
12141234
// current TGeoVolume

MCReplay/include/MCReplay/MCReplayPhysics.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ namespace physics
2323
constexpr std::array<const char*, 15> namesProcesses = {"PAIR", "COMP", "PHOT", "PFIS", "DRAY", "ANNI", "BREM", "HADR", "MUNU", "DCAY", "LOSS", "MULS", "CKOV", "RAYL", "LABS"};
2424
// standard GEANT cut parameter names (1-11)
2525
// additional Replay cut parameter names (12-n):
26-
// ALLE: energy cut applying to all tracks independent of PDG
27-
constexpr std::array<const char*, 12> namesCuts = {"CUTGAM", "CUTELE", "CUTNEU", "CUTHAD", "CUTMUO", "NCUTE", "BCUTM", "DCUTE", "DCUTM", "PPCUTM", "TOFMAX", "ALLE"};
26+
// CUTALLE: energy cut applying to all tracks independent of PDG
27+
constexpr std::array<const char*, 12> namesCuts = {"CUTGAM", "CUTELE", "CUTNEU", "CUTHAD", "CUTMUO", "NCUTE", "BCUTM", "DCUTE", "DCUTM", "PPCUTM", "TOFMAX", "CUTALLE"};
2828
constexpr const char* unknownParam = "UNKNOWN";
2929

3030
template <typename T, std::size_t N>

0 commit comments

Comments
 (0)