Warning, /geant4/examples/extended/eventgenerator/HepMC/MCTruth/README is written in an unsupported language. File is not indexed.
0001 -------------------------------------------------------------------
0002
0003 =========================================================
0004 Geant4 - an Object-Oriented Toolkit for Simulation in HEP
0005 =========================================================
0006
0007 MCTRUTH using HepMC
0008 -------------------
0009
0010 This example demonstrates a mechanism for Monte Carlo truth handling
0011 using HepMC as the event record. The user does not interact directly
0012 with the HepMC classes but with the MCTruthManager class which takes
0013 care with storing all the necessary information about particles,
0014 vertices and relations between them. A specialized tracking action is
0015 used to test whether given particle is to be stored or not. The
0016 decision criteria for storing particle are configurable via the
0017 MCTruthConfig class.
0018
0019 HOW TO BUILD THE EXAMPLE ?
0020
0021 - if you do not have it yet, install HepMC event record (tested with version 2.06.08)
0022
0023 - set HEPMC_ROOT_DIR variable to point to the directory where HepMC is installed;
0024 if the HepMC is installed in your system directory (/usr/local) you do not need to set anything
0025
0026 - run the CMake configuration and build mctruthex target in your build directory
0027
0028 - execute the application:
0029 % your_binary_directory/mctruthex
0030
0031 DESCRIPTION OF THE MCTRUTH HANDLING MECHANISM
0032
0033 The main element of the MC truth handling machinery is the
0034 MCTruthManager class. This class is responsible for all the
0035 interaction with the HepMC event and does not depend on Geant4. It is
0036 a singleton, therefore it is guaranteed to be instanciated only once
0037 and the static 'GetInstance' method allows to access it from anywhere
0038 in the code. It contains methods like 'NewEvent' to start a new event,
0039 'AddParticle' to add particle to the current event, as well as
0040 'PrintEvent' for the purpose of the debugging. The core of the
0041 algorithm which deals with building up the MC truth event tree within
0042 the HepMC event is implemented in AddParticle method.
0043
0044 The AddParticle method is called with the following arguments:
0045 four-momentum, production position and 'end' position of the particle,
0046 PDG code of the particle, as well as the particle ID (unique identifier,
0047 as we will see later, corresponding to Geant4 TrackID) and the ID of
0048 the mother. Finally, there is a boolean flag specifying whether the
0049 direct mother of the given particle has been stored, or not.
0050
0051 The first step, which always takes place, is to instanciate a new
0052 HepMC::GenParticle with the barcode corresponding to particle ID, as
0053 well as to instanciate a new HepMC::GenVertex which will represent the
0054 'end' vertex of the particle. The barcode of the 'end vertex' is equal
0055 to minus the barcode of the particle.
0056
0057 We can now distinguish several cases:
0058
0059 1) the particle is a primary in the Geant4 language, i.e. its
0060 mother ID is 0
0061
0062 This is the simplest case, we just instanciate a new 'primary'
0063 (without any incoming particles) GenVertex, we add to it the
0064 particle and we put it all in the event. Additionally we store the
0065 ID of the particle in a special vector, where all the IDs of
0066 primary particles will be stored, allowing quick access to each of
0067 the main 'branches' of the event. We return from the method.
0068
0069 2) the particle is not a primary
0070
0071 We use the 'event->barcode_to_particle(motherID)' method to get the
0072 pointer to its mother.
0073
0074 We check if the 'end vertex' of the mother corresponds to the
0075 'production vertex' of the particle in question.
0076
0077 2.1) If the two vertices do match, we attach the new particle to
0078 the 'end vertex' of the mother. We return from the method.
0079
0080 2.2) If the two vertices do not match, i.e. the new particle is not
0081 a product of the 'end vertex' of the mother particle, we can
0082 have two cases:
0083
0084 2.2.1) The boolean flag says that the direct mother of the
0085 particle has _not_ been stored. This means that the
0086 particle has been 'adopted' by one of its ancestors, or
0087 in other words, the mother ID of the particle does not
0088 correspond to its direct mother (so clearly the
0089 vertices cannot match). This for instance could happen
0090 if we decided not to store gamma coming from pi0 decay
0091 but did decide to store e+/- coming from the gamma
0092 conversion (so the gamma between pi0 and e+/- was
0093 missing). In such a case we instanciate (or use one of
0094 the existing ones, if vertices match) a 'dummy'
0095 particle (with pdg = -999999) which then acts as the
0096 link between the 'adopted' particle and the
0097 (non-direct) mother. In such a way, the navigability up
0098 in the event is still possible, but in the same time,
0099 we can clearly see that the link is not a direct
0100 one. We return from the method.
0101
0102 2.2.2) The boolean flag says that direct mother of the
0103 particle _has_ been stored. Taking into account that
0104 the vertices do not match, it can mean only one
0105 thing. The new particle has been produced 'on the
0106 flight', i.e. somewhere 'before' the 'end vertex' of
0107 the mother. This can be the case, for instace, for
0108 delta electrons, bremsstrahlung gammas, etc. In such a
0109 situation, we 'split' the mother particle in two
0110 particles and create a new vertex from which the
0111 secondary will be going out. The complication, however,
0112 arises when we have more than one generated 'on the
0113 flight' particle attached to the same mother. In such a
0114 case, for each secondary we need to locate the right
0115 'segment' of the mother particle (i.e. we need to find
0116 between which two vertices we need to add a new
0117 one). To keep track of those segmentations we introduce
0118 a map where each particle ID we map into the number of
0119 existing segments (in the normal case one). Each new
0120 'segment' gets barcode equal to the barcode of the
0121 original particle + N*10000000, where N is the segment
0122 number. In such a way, one can easily follow the
0123 'segmentation' (if any) of each particle. We return
0124 from the method.
0125
0126 This concludes the description of MCTruthManager. The MCTruthConfig
0127 class is a collection of criteria (minimal energy, PDG, creator
0128 process, etc) that we want to apply when deciding whether to store or
0129 not given particle. These values are used by the
0130 'MCTruthTrackingAction' which we describe below. This class can
0131 certainly be extended with other members.
0132
0133 The actual Geant4-dependent part of the MCTruth handling machinery
0134 consists of a few 'G4 user actions' as well as an implementation of
0135 G4VUserTrackInformation. The later one is, for the moment, used only
0136 to store one boolean flag indicating whether the direct mother of the
0137 given track has been stored or not.
0138
0139 The first user action is MCTruthEventAction which is only reponsible
0140 for calling MCTruthManager::GetInstance()->NewEvent() at the beginning
0141 of each event. It can also be used for printing out events for the
0142 purpose of debugging.
0143
0144 The actual 'decision making' concerning which particle to store is
0145 done in MCTruthTrackingAction. At the end of each track the method
0146 trackToBeStored(track) is called to check for various characteristics
0147 of the particle. These, for instance can be energy, particle ID,
0148 creator process, etc.
0149
0150 If the particle satisfies the conditions the
0151 MCTruthManager::GetInstance()->AddParticle is called and all the
0152 procedure described above is performed. The important element here is
0153 that the Geant4 TrackID is used as the unique particle ID in
0154 MCTruthManager and eventually as the barcode of the
0155 HepMC::GenParticle.
0156
0157 If the particle does not qualify to be stored, there are two actions
0158 performed. First the 'ParentID' of the _daughters_ is set to the
0159 'ParentID' of the currenly processed particle. In other words, the
0160 'ParentID' of the daughters is set to the ID of the last stored
0161 particle. Second, the 'directParent' flag from MCTruthTrackInformation
0162 of the __daughters__ is set to FALSE. In such a way, one is still able
0163 to navigate up in the event (to get the ancestors of the particle),
0164 but in the same time, the particle is flagged as 'not having direct
0165 parent'.