4 // See the class description in the header file.
6 #include "AliDecayer.h"
8 #include "TG4ExtDecayer.h"
9 #include "TG4ParticlesManager.h"
10 #include "TG4G3Units.h"
12 #include <G4DynamicParticle.hh>
13 #include <G4DecayProducts.hh>
14 #include <G4DecayTable.hh>
15 #include <G4ParticleTable.hh>
16 #include <G4DynamicParticle.hh>
19 #include <TParticle.h>
20 #include <TLorentzVector.h>
21 #include <TClonesArray.h>
25 //_____________________________________________________________________________
26 TG4ExtDecayer::TG4ExtDecayer(AliDecayer* externalDecayer)
27 : G4VExtDecayer("TG4ExtDecayer"),
28 fExternalDecayer(externalDecayer),
31 fDecayProductsArray = new TClonesArray("TParticle", 1000);
32 fParticlesManager = TG4ParticlesManager::Instance();
35 //_____________________________________________________________________________
36 TG4ExtDecayer::TG4ExtDecayer(const TG4ExtDecayer& right) {
38 TG4Globals::Exception(
39 "TG4ExtDecayer is protected from copying.");
42 //_____________________________________________________________________________
43 TG4ExtDecayer::~TG4ExtDecayer() {
45 delete fDecayProductsArray;
51 //_____________________________________________________________________________
52 TG4ExtDecayer& TG4ExtDecayer::operator=(const TG4ExtDecayer& right)
54 // check assignement to self
55 if (this == &right) return *this;
57 TG4Globals::Exception(
58 "TG4ExtDecayer is protected from assigning.");
65 //_____________________________________________________________________________
66 G4DecayProducts* TG4ExtDecayer::ImportDecayProducts(const G4Track& track)
68 // check if external decayer is defined
69 if (!fExternalDecayer) {
71 G4cerr << "TG4ExtDecayer::ImportDecayProducts: " << G4endl
72 << " No fExternalDecayer is defined." << G4endl;
77 // get particle momentum
78 G4ThreeVector momentum = track.GetMomentum();
79 G4double mag = momentum.mag();
81 p[0] = momentum.x()/mag;
82 p[1] = momentum.x()/mag;
83 p[2] = momentum.x()/mag;
84 p[3] = mag/TG4G3Units::Energy();
87 // ask TG4ParticlesManager to get PDG encoding
88 // (in order to get PDG from extended TDatabasePDG
89 // in case the standard PDG code is not defined)
90 G4ParticleDefinition* particleDef = track.GetDefinition();
91 G4int pdgEncoding = fParticlesManager->GetPDGEncodingFast(particleDef);
93 // let AliDecayer decay the particle
94 // and import the decay products
95 fExternalDecayer->Decay(pdgEncoding, &p);
97 = fExternalDecayer->ImportParticles(fDecayProductsArray);
100 G4cout << "nofParticles: " << nofParticles << G4endl;
102 // convert decay products TParticle type
103 // to G4DecayProducts
104 G4DecayProducts* decayProducts
105 = new G4DecayProducts(*(track.GetDynamicParticle()));
108 for (G4int i=0; i<nofParticles; i++) {
110 // get particle from TClonesArray
112 = fParticlesManager->GetParticle(fDecayProductsArray, i);
114 G4int status = particle->GetStatusCode();
115 G4int pdg = particle->GetPdgCode();
116 if ( status>0 && status<11 &&
117 abs(pdg)!=12 && abs(pdg)!=14 && abs(pdg)!=16 ) {
118 // pass to tracking final particles only;
122 G4cout << " " << i << "th particle PDG: " << pdg << " ";
124 // create G4DynamicParticle
125 G4DynamicParticle* dynamicParticle
126 = fParticlesManager->CreateDynamicParticle(particle);
128 if (dynamicParticle) {
131 G4cout << " G4 particle name: "
132 << dynamicParticle->GetDefinition()->GetParticleName()
135 // add dynamicParticle to decayProducts
136 decayProducts->PushProducts(dynamicParticle);
143 G4cout << "nofParticles for tracking: " << counter << G4endl;
145 return decayProducts;