VMC Examples Version 6.6
Loading...
Searching...
No Matches
Ex02Particle.cxx
Go to the documentation of this file.
1//------------------------------------------------
2// The Virtual Monte Carlo examples
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
10/// \file Ex02Particle.cxx
11/// \brief Implementation of the Ex02Particle class
12///
13/// Geant4 ExampleN02 adapted to Virtual Monte Carlo
14///
15/// \date 21/04/2002
16/// \author I. Hrivnacova; IPN, Orsay
17
18#include "Ex02Particle.h"
19
20#include <TObjArray.h>
21#include <TParticle.h>
22
23#include <iostream>
24
25using namespace std;
26
27/// \cond CLASSIMP
28ClassImp(Ex02Particle)
29 /// \endcond
30
31 //_____________________________________________________________________________
32 Ex02Particle::Ex02Particle(Int_t id, TParticle* particle)
33 : fID(id), fParticle(particle), fMother(), fDaughters()
34{
35 /// Standard constructor
36 /// \param id The particle id
37 /// \param particle The particle definition (TParticle)
38}
39
40//_____________________________________________________________________________
41Ex02Particle::Ex02Particle(Int_t id, TParticle* particle, Ex02Particle* mother)
42 : fID(id), fParticle(particle), fMother(mother), fDaughters()
43{
44 /// Standard constructor
45 /// \param id The particle id
46 /// \param particle The particle definition (TParticle)
47 /// \param mother The particle mother
48}
49
50//_____________________________________________________________________________
51Ex02Particle::Ex02Particle() : fID(0), fParticle(0), fMother(), fDaughters()
52{
53 /// Default constructor
54}
55
56//_____________________________________________________________________________
58{
59 /// Destructor
60
61 delete fParticle;
62}
63
64//
65// public methods
66//
67
68//_____________________________________________________________________________
70{
71 /// Set particle mother
72 /// \param particle The mother particle
73
74 fMother.SetObject(particle);
75}
76
77//_____________________________________________________________________________
79{
80 /// Add particles daughter
81 /// \param particle The daughter particle
82
83 fDaughters.Add(particle);
84}
85
86//_____________________________________________________________________________
87void Ex02Particle::Print(Option_t* /*option*/) const
88{
89 /// Print particle properties.
90
91 cout << "Track ID: " << fID << endl;
92
93 fParticle->Print();
94
95 if (GetMother()) {
96 cout << "Mother: " << GetMother()->GetParticle()->GetName()
97 << " with ID: " << GetMother()->GetID() << endl;
98 }
99 else
100 cout << "Primary " << endl;
101
102 cout << "Number of daughters: " << GetNofDaughters() << endl;
103 cout << endl;
104}
105
106//_____________________________________________________________________________
108{
109 /// Print particles daughters.
110
111 for (Int_t i = 0; i < GetNofDaughters(); i++) {
112 cout << i << "th daughter: " << endl;
113 if (GetDaughter(i))
114 GetDaughter(i)->Print();
115 else
116 cout << "0x0";
117 }
118 cout << endl;
119}
120
121//_____________________________________________________________________________
123{
124 /// \return The particle Id.
125
126 return fID;
127}
128
129//_____________________________________________________________________________
131{
132 /// \return The particle definition (TParticle).
133
134 return fParticle;
135}
136
137//_____________________________________________________________________________
139{
140 /// \return The particle mother.
141
142 return (Ex02Particle*)fMother.GetObject();
143}
144
145//_____________________________________________________________________________
147{
148 /// \return The number of daughters.
149
150 return fDaughters.GetEntriesFast();
151}
152
153//_____________________________________________________________________________
155{
156 /// \return \em i -th daughter
157 /// \param i The daughter index
158
159 if (i < 0 || i >= GetNofDaughters())
160 Fatal("GetDaughter", "Index out of range");
161
162 return (Ex02Particle*)fDaughters.At(i);
163}
Definition of the Ex02Particle class.
Extended TParticle with pointers to mother and daughter particles.
void SetMother(Ex02Particle *particle)
virtual ~Ex02Particle()
Int_t GetID() const
Int_t GetNofDaughters() const
Ex02Particle * GetDaughter(Int_t i) const
void PrintDaughters() const
virtual void Print(Option_t *option="") const
Int_t fID
The particle Id.
Ex02Particle * GetMother() const
TRefArray fDaughters
The particle daughters.
TParticle * fParticle
The particle definition.
TParticle * GetParticle() const
TRef fMother
The particle mother.
void AddDaughter(Ex02Particle *particle)