[807] | 1 | $Id: README,v 1.1 2006/11/22 14:51:26 gcosmo Exp $ |
---|
| 2 | ------------------------------------------------------------------- |
---|
| 3 | |
---|
| 4 | ========================================================= |
---|
| 5 | Geant4 - an Object-Oriented Toolkit for Simulation in HEP |
---|
| 6 | ========================================================= |
---|
| 7 | |
---|
| 8 | MCTRUTH using HepMC |
---|
| 9 | ------------------- |
---|
| 10 | |
---|
| 11 | This example demonstrates a mechanism for Monte Carlo truth handling |
---|
| 12 | using HepMC as the event record. The user does not interact directly |
---|
| 13 | with the HepMC classes but with the MCTruthManager class which takes |
---|
| 14 | care with storing all the necessary information about particles, |
---|
| 15 | vertices and relations between them. A specialized tracking action is |
---|
| 16 | used to test whether given particle is to be stored or not. The |
---|
| 17 | decision criteria for storing particle are configurable via the |
---|
| 18 | MCTruthConfig class. |
---|
| 19 | |
---|
| 20 | HOW TO BUILD THE EXAMPLE ? |
---|
| 21 | |
---|
| 22 | - install HepMC event record (version 1.27) |
---|
| 23 | |
---|
| 24 | - set HEPMC_DIR variable to point to the directory where HepMC is installed; |
---|
| 25 | add the path "$HEPMC_DIR/lib" to your LD_LIBRARY_PATH variable. |
---|
| 26 | |
---|
| 27 | - compile and link to generate the executable: |
---|
| 28 | % gmake |
---|
| 29 | |
---|
| 30 | - execute the application: |
---|
| 31 | % mctruthex |
---|
| 32 | |
---|
| 33 | DESCRIPTION OF THE MCTRUTH HANDLING MECHANISM |
---|
| 34 | |
---|
| 35 | The main element of the MC truth handling machinery is the |
---|
| 36 | MCTruthManager class. This class is responsible for all the |
---|
| 37 | interaction with the HepMC event and does not depend on Geant4. It is |
---|
| 38 | a singleton, therefore it is guaranteed to be instanciated only once |
---|
| 39 | and the static 'GetInstance' method allows to access it from anywhere |
---|
| 40 | in the code. It contains methods like 'NewEvent' to start a new event, |
---|
| 41 | 'AddParticle' to add particle to the current event, as well as |
---|
| 42 | 'PrintEvent' for the purpose of the debugging. The core of the |
---|
| 43 | algorithm which deals with building up the MC truth event tree within |
---|
| 44 | the HepMC event is implemented in AddParticle method. |
---|
| 45 | |
---|
| 46 | The AddParticle method is called with the following arguments: |
---|
| 47 | four-momentum, production position and 'end' position of the particle, |
---|
| 48 | PDG code of the particle, as well as the particle ID (unique identifier, |
---|
| 49 | as we will see later, corresponding to Geant4 TrackID) and the ID of |
---|
| 50 | the mother. Finally, there is a boolean flag specifying whether the |
---|
| 51 | direct mother of the given particle has been stored, or not. |
---|
| 52 | |
---|
| 53 | The first step, which always takes place, is to instanciate a new |
---|
| 54 | HepMC::GenParticle with the barcode corresponding to particle ID, as |
---|
| 55 | well as to instanciate a new HepMC::GenVertex which will represent the |
---|
| 56 | 'end' vertex of the particle. The barcode of the 'end vertex' is equal |
---|
| 57 | to minus the barcode of the particle. |
---|
| 58 | |
---|
| 59 | We can now distinguish several cases: |
---|
| 60 | |
---|
| 61 | 1) the particle is a primary in the Geant4 language, i.e. its |
---|
| 62 | mother ID is 0 |
---|
| 63 | |
---|
| 64 | This is the simplest case, we just instanciate a new 'primary' |
---|
| 65 | (without any incoming particles) GenVertex, we add to it the |
---|
| 66 | particle and we put it all in the event. Additionally we store the |
---|
| 67 | ID of the particle in a special vector, where all the IDs of |
---|
| 68 | primary particles will be stored, allowing quick access to each of |
---|
| 69 | the main 'branches' of the event. We return from the method. |
---|
| 70 | |
---|
| 71 | 2) the particle is not a primary |
---|
| 72 | |
---|
| 73 | We use the 'event->barcode_to_particle(motherID)' method to get the |
---|
| 74 | pointer to its mother. |
---|
| 75 | |
---|
| 76 | We check if the 'end vertex' of the mother corresponds to the |
---|
| 77 | 'production vertex' of the particle in question. |
---|
| 78 | |
---|
| 79 | 2.1) If the two vertices do match, we attach the new particle to |
---|
| 80 | the 'end vertex' of the mother. We return from the method. |
---|
| 81 | |
---|
| 82 | 2.2) If the two vertices do not match, i.e. the new particle is not |
---|
| 83 | a product of the 'end vertex' of the mother particle, we can |
---|
| 84 | have two cases: |
---|
| 85 | |
---|
| 86 | 2.2.1) The boolean flag says that the direct mother of the |
---|
| 87 | particle has _not_ been stored. This means that the |
---|
| 88 | particle has been 'adopted' by one of its ancestors, or |
---|
| 89 | in other words, the mother ID of the particle does not |
---|
| 90 | correspond to its direct mother (so clearly the |
---|
| 91 | vertices cannot match). This for instance could happen |
---|
| 92 | if we decided not to store gamma coming from pi0 decay |
---|
| 93 | but did decide to store e+/- coming from the gamma |
---|
| 94 | conversion (so the gamma between pi0 and e+/- was |
---|
| 95 | missing). In such a case we instanciate (or use one of |
---|
| 96 | the existing ones, if vertices match) a 'dummy' |
---|
| 97 | particle (with pdg = -999999) which then acts as the |
---|
| 98 | link between the 'adopted' particle and the |
---|
| 99 | (non-direct) mother. In such a way, the navigability up |
---|
| 100 | in the event is still possible, but in the same time, |
---|
| 101 | we can clearly see that the link is not a direct |
---|
| 102 | one. We return from the method. |
---|
| 103 | |
---|
| 104 | 2.2.2) The boolean flag says that direct mother of the |
---|
| 105 | particle _has_ been stored. Taking into account that |
---|
| 106 | the vertices do not match, it can mean only one |
---|
| 107 | thing. The new particle has been produced 'on the |
---|
| 108 | flight', i.e. somewhere 'before' the 'end vertex' of |
---|
| 109 | the mother. This can be the case, for instace, for |
---|
| 110 | delta electrons, bremsstrahlung gammas, etc. In such a |
---|
| 111 | situation, we 'split' the mother particle in two |
---|
| 112 | particles and create a new vertex from which the |
---|
| 113 | secondary will be going out. The complication, however, |
---|
| 114 | arises when we have more than one generated 'on the |
---|
| 115 | flight' particle attached to the same mother. In such a |
---|
| 116 | case, for each secondary we need to locate the right |
---|
| 117 | 'segment' of the mother particle (i.e. we need to find |
---|
| 118 | between which two vertices we need to add a new |
---|
| 119 | one). To keep track of those segmentations we introduce |
---|
| 120 | a map where each particle ID we map into the number of |
---|
| 121 | existing segments (in the normal case one). Each new |
---|
| 122 | 'segment' gets barcode equal to the barcode of the |
---|
| 123 | original particle + N*10000000, where N is the segment |
---|
| 124 | number. In such a way, one can easily follow the |
---|
| 125 | 'segmentation' (if any) of each particle. We return |
---|
| 126 | from the method. |
---|
| 127 | |
---|
| 128 | This concludes the description of MCTruthManager. The MCTruthConfig |
---|
| 129 | class is a collection of criteria (minimal energy, PDG, creator |
---|
| 130 | process, etc) that we want to apply when deciding whether to store or |
---|
| 131 | not given particle. These values are used by the |
---|
| 132 | 'MCTruthTrackingAction' which we describe below. This class can |
---|
| 133 | certainly be extended with other members. |
---|
| 134 | |
---|
| 135 | The actual Geant4-dependent part of the MCTruth handling machinery |
---|
| 136 | consists of a few 'G4 user actions' as well as an implementation of |
---|
| 137 | G4VUserTrackInformation. The later one is, for the moment, used only |
---|
| 138 | to store one boolean flag indicating whether the direct mother of the |
---|
| 139 | given track has been stored or not. |
---|
| 140 | |
---|
| 141 | The first user action is MCTruthEventAction which is only reponsible |
---|
| 142 | for calling MCTruthManager::GetInstance()->NewEvent() at the beginning |
---|
| 143 | of each event. It can also be used for printing out events for the |
---|
| 144 | purpose of debugging. |
---|
| 145 | |
---|
| 146 | The actual 'decision making' concerning which particle to store is |
---|
| 147 | done in MCTruthTrackingAction. At the end of each track the method |
---|
| 148 | trackToBeStored(track) is called to check for various characteristics |
---|
| 149 | of the particle. These, for instance can be energy, particle ID, |
---|
| 150 | creator process, etc. |
---|
| 151 | |
---|
| 152 | If the particle satisfies the conditions the |
---|
| 153 | MCTruthManager::GetInstance()->AddParticle is called and all the |
---|
| 154 | procedure described above is performed. The important element here is |
---|
| 155 | that the Geant4 TrackID is used as the unique particle ID in |
---|
| 156 | MCTruthManager and eventually as the barcode of the |
---|
| 157 | HepMC::GenParticle. |
---|
| 158 | |
---|
| 159 | If the particle does not qualify to be stored, there are two actions |
---|
| 160 | performed. First the 'ParentID' of the _daughters_ is set to the |
---|
| 161 | 'ParentID' of the currenly processed particle. In other words, the |
---|
| 162 | 'ParentID' of the daughters is set to the ID of the last stored |
---|
| 163 | particle. Second, the 'directParent' flag from MCTruthTrackInformation |
---|
| 164 | of the __daughters__ is set to FALSE. In such a way, one is still able |
---|
| 165 | to navigate up in the event (to get the ancestors of the particle), |
---|
| 166 | but in the same time, the particle is flagged as 'not having direct |
---|
| 167 | parent'. |
---|