Geant4 VMC Version 6.6
Loading...
Searching...
No Matches
TG4ExtDecayer.cxx
Go to the documentation of this file.
1//------------------------------------------------
2// The Geant4 Virtual Monte Carlo package
3// Copyright (C) 2007 - 2014 Ivana Hrivnacova
4// All rights reserved.
5//
6// For the licensing terms see geant4_vmc/LICENSE.
7// Contact: root-vmc@cern.ch
8//-------------------------------------------------
9
14
15#include "TG4ExtDecayer.h"
16#include "TG4G3Units.h"
17#include "TG4ParticlesManager.h"
18
19#include <G4DecayProducts.hh>
20#include <G4DecayTable.hh>
21#include <G4DynamicParticle.hh>
22#include <G4ParticleTable.hh>
23#include <G4Track.hh>
24
25#include <TClonesArray.h>
26#include <TLorentzVector.h>
27#include <TParticle.h>
28#include <TVirtualMCDecayer.h>
29
30#include <math.h>
31
32//_____________________________________________________________________________
33TG4ExtDecayer::TG4ExtDecayer(TVirtualMCDecayer* externalDecayer)
34 : G4VExtDecayer("TG4ExtDecayer"),
35 TG4Verbose("extDecayer"),
36 fParticlesManager(TG4ParticlesManager::Instance()),
37 fExternalDecayer(externalDecayer),
38 fDecayProductsArray(0),
39 fSkipNeutrino(false)
40{
42
43 fDecayProductsArray = new TClonesArray("TParticle", 1000);
44}
45
46//_____________________________________________________________________________
53
54//
55// public methods
56//
57
58//_____________________________________________________________________________
59G4DecayProducts* TG4ExtDecayer::ImportDecayProducts(const G4Track& track)
60{
62
63 // check if external decayer is defined
64 if (!fExternalDecayer) {
65 G4cerr << "TG4ExtDecayer::ImportDecayProducts: " << G4endl
66 << " No fExternalDecayer is defined." << G4endl;
67 return 0;
68 }
69
70 // get particle momentum
71 G4ThreeVector momentum = track.GetMomentum();
72 G4double etot = track.GetDynamicParticle()->GetTotalEnergy();
73 ;
74 TLorentzVector p;
75 p[0] = momentum.x() * TG4G3Units::InverseEnergy();
76 p[1] = momentum.y() * TG4G3Units::InverseEnergy();
77 p[2] = momentum.z() * TG4G3Units::InverseEnergy();
78 p[3] = etot * TG4G3Units::InverseEnergy();
79
80 // get particle PDG
81 // ask TG4ParticlesManager to get PDG encoding
82 // (in order to get PDG from extended TDatabasePDG
83 // in case the standard PDG code is not defined)
84 G4ParticleDefinition* particleDef = track.GetDefinition();
85 G4int pdgEncoding = fParticlesManager->GetPDGEncoding(particleDef);
86
87 // let TVirtualMCDecayer decay the particle
88 // and import the decay products
89 fExternalDecayer->Decay(pdgEncoding, &p);
90 G4int nofParticles = fExternalDecayer->ImportParticles(fDecayProductsArray);
91
92 if (VerboseLevel() > 1) {
93 G4cout << "nofParticles: " << nofParticles << G4endl;
94 }
95
96 // convert decay products TParticle type
97 // to G4DecayProducts
98 G4DecayProducts* decayProducts =
99 new G4DecayProducts(*(track.GetDynamicParticle()));
100
101 G4int counter = 0;
102 for (G4int i = 0; i < nofParticles; i++) {
103
104 // get particle from TClonesArray
105 TParticle* particle =
107
108 G4int status = particle->GetStatusCode();
109 G4int pdg = particle->GetPdgCode();
110 if ((status > 0 && status < 11) &&
111 ((!fSkipNeutrino) ||
112 (abs(pdg) != 12 && abs(pdg) != 14 && abs(pdg) != 16))) {
113 // pass to tracking final particles only;
114 // skip neutrinos if skipping option is active
115
116 if (VerboseLevel() > 1) {
117 G4cout << " " << i << "th particle PDG: " << pdg << " ";
118 }
119
120 // create G4DynamicParticle
121 G4DynamicParticle* dynamicParticle =
123
124 if (dynamicParticle) {
125
126 if (VerboseLevel() > 1) {
127 G4cout << " G4 particle name: "
128 << dynamicParticle->GetDefinition()->GetParticleName()
129 << G4endl;
130 }
131
132 // add dynamicParticle to decayProducts
133 decayProducts->PushProducts(dynamicParticle);
134
135 counter++;
136 }
137 }
138 }
139 if (VerboseLevel() > 1) {
140 G4cout << "nofParticles for tracking: " << counter << G4endl;
141 }
142
143 return decayProducts;
144}
Definition of the TG4ExtDecayer class.
Definition of the TG4G3Units class.
Definition of the TG4ParticlesManager class.
virtual G4DecayProducts * ImportDecayProducts(const G4Track &track)
TClonesArray * fDecayProductsArray
array of decay products
TG4ParticlesManager * fParticlesManager
particles manager
TG4ExtDecayer(TVirtualMCDecayer *externalDecayer)
virtual ~TG4ExtDecayer()
G4bool fSkipNeutrino
option to skip importing neutrinos
TVirtualMCDecayer * fExternalDecayer
the external decayer
static G4double InverseEnergy()
Definition TG4G3Units.h:157
Provides mapping between TDatabasePDG and Geant4 particles.
G4DynamicParticle * CreateDynamicParticle(const TParticle *particle) const
G4int GetPDGEncoding(G4ParticleDefinition *particle)
TParticle * GetParticle(const TClonesArray *particles, G4int index) const
Base class for defining the verbose level and a common messenger.
Definition TG4Verbose.h:36
virtual G4int VerboseLevel() const
Definition TG4Verbose.h:78