Back to home page

EIC code displayed by LXR

 
 

    


Warning, /geant4/examples/extended/eventgenerator/HepMC/MCTruth/README.md is written in an unsupported language. File is not indexed.

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