CbmRoot
UEvent.cxx
Go to the documentation of this file.
1 #include "UEvent.h"
2 
3 #include "UParticle.h"
4 
5 #include "TClonesArray.h"
6 #include "TString.h"
7 
8 #include <iostream>
9 using namespace std;
10 
11 //____________________________________________________________________
12 //
13 // UEvent
14 //
15 // Class for event description. Contains the particle array
16 //
17 
18 
19 //--------------------------------------------------------------------
21  : TObject()
22  , fEventNr(0)
23  , fB(0.)
24  , fPhi(0.)
25  , fNes(1)
26  , fStepNr(0)
27  , fStepT(0.)
28  , fNpa(0)
29  , fComment("")
30  , fParticles(new TClonesArray("UParticle", 100)) {}
31 //--------------------------------------------------------------------
32 
33 
34 //--------------------------------------------------------------------
35 UEvent::UEvent(const UEvent& right)
36  : TObject(right)
37  , fEventNr(right.fEventNr)
38  , fB(right.fB)
39  , fPhi(right.fPhi)
40  , fNes(right.fNes)
41  , fStepNr(right.fStepNr)
42  , fStepT(right.fStepT)
43  , fNpa(right.fNpa)
44  , fComment(right.fComment)
45  , fParticles(new TClonesArray("UParticle", 100)) {
46  UParticle* p;
47  for (Int_t i = 0; i < fNpa; i++) {
48  p = (UParticle*) right.fParticles->At(i);
49  new ((*fParticles)[i]) UParticle(*p);
50  }
51 }
52 //--------------------------------------------------------------------
53 
54 
55 //--------------------------------------------------------------------
57  // Destructor
58  Clear();
59  delete fParticles;
60 }
61 //--------------------------------------------------------------------
62 
63 
64 //--------------------------------------------------------------------
65 void UEvent::Print(Option_t* option) const {
66  // Print data members to the standard output
67  cout << "---------------------------------------------" << endl
68  << "-I- Event -I-" << endl
69  << "Event number : " << fEventNr << endl
70  << "Impact parameter (fm) : " << fB << endl
71  << "Reaction plane angle (rad) : " << fPhi << endl
72  << "Number of time steps : " << fNes << endl
73  << "Time step number : " << fStepNr << endl
74  << "Time of the time step (fm) : " << fStepT << endl
75  << "Number of particles : " << fNpa << endl
76  << "Comment :\n"
77  << fComment << endl;
78  TString opt = option;
79  if (opt.Contains("all")) {
80  UParticle* particle;
81  for (Int_t iPa = 0; iPa < fNpa; iPa++) {
82  particle = (UParticle*) fParticles->At(iPa);
83  particle->Print(option);
84  }
85  }
86  cout << "---------------------------------------------" << endl;
87 }
88 //--------------------------------------------------------------------
89 
90 
91 //--------------------------------------------------------------------
92 UParticle* UEvent::GetParticle(Int_t index) const {
93  // Get pointer to the particle.
94  // index - index of the particle
95  if (index < 0) { return nullptr; }
96  if (index >= fNpa) { return nullptr; }
97  return ((UParticle*) fParticles->At(index));
98 }
99 //--------------------------------------------------------------------
100 
101 
102 //--------------------------------------------------------------------
103 void UEvent::AddParticle(Int_t index,
104  Int_t pdg,
105  Int_t status,
106  Int_t parent,
107  Int_t parentDecay,
108  Int_t mate,
109  Int_t decay,
110  Int_t child[2],
111  Double_t px,
112  Double_t py,
113  Double_t pz,
114  Double_t e,
115  Double_t x,
116  Double_t y,
117  Double_t z,
118  Double_t t,
119  Double_t weight) {
120  // Add particle to the array
121  new ((*fParticles)[fNpa]) UParticle(index,
122  pdg,
123  status,
124  parent,
125  parentDecay,
126  mate,
127  decay,
128  child,
129  px,
130  py,
131  pz,
132  e,
133  x,
134  y,
135  z,
136  t,
137  weight);
138  fNpa += 1;
139 }
140 //--------------------------------------------------------------------
141 
142 
143 //--------------------------------------------------------------------
144 void UEvent::AddParticle(Int_t index,
145  Int_t pdg,
146  Int_t status,
147  Int_t parent,
148  Int_t parentDecay,
149  Int_t mate,
150  Int_t decay,
151  Int_t child[2],
152  TLorentzVector mom,
153  TLorentzVector pos,
154  Double_t weight) {
155  // Add particle to the array
156  new ((*fParticles)[fNpa]) UParticle(index,
157  pdg,
158  status,
159  parent,
160  parentDecay,
161  mate,
162  decay,
163  child,
164  mom,
165  pos,
166  weight);
167  fNpa += 1;
168 }
169 //--------------------------------------------------------------------
170 
171 
172 //--------------------------------------------------------------------
173 void UEvent::AddParticle(const UParticle& particle) {
174  // Add particle to the array
175  new ((*fParticles)[fNpa]) UParticle(particle);
176  fNpa += 1;
177 }
178 //--------------------------------------------------------------------
180  if (this != &right) {
181  fEventNr = right.fEventNr;
182  fB = right.fB;
183  fPhi = right.fPhi;
184  fNes = right.fNes;
185  fStepNr = right.fStepNr;
186  fStepT = right.fStepT;
187  fNpa = right.fNpa;
188  fComment = right.fComment;
189  fParticles->Clear();
190  UParticle* p;
191  for (Int_t i = 0; i < fNpa; i++) {
192  p = (UParticle*) right.fParticles->At(i);
193  new ((*fParticles)[i]) UParticle(*p);
194  }
195  }
196  return *this;
197 }
198 //--------------------------------------------------------------------
199 
200 //--------------------------------------------------------------------
201 void UEvent::SetParameters(Int_t eventNr,
202  Double_t b,
203  Double_t phi,
204  Int_t nes,
205  Int_t stepNr,
206  Double_t stepT,
207  const char* comment) {
208  // Set the event parameters
209  fEventNr = eventNr;
210  fB = b;
211  fPhi = phi;
212  fNes = nes;
213  fStepNr = stepNr;
214  fStepT = stepT;
215  fComment = comment;
216 }
217 //--------------------------------------------------------------------
218 
219 
220 //--------------------------------------------------------------------
221 void UEvent::Clear(Option_t*) {
222  // Remove the particles from the array and reset counter
223  fParticles->Clear();
224  fNpa = 0;
225 }
226 //--------------------------------------------------------------------
227 
228 
229 //--------------------------------------------------------------------
230 void UEvent::RemoveAt(Int_t i) {
231  // Remove one particle from the array.
232  // i - index of the particle.
233  // Array is automaticaly compressed afterwards, mind the indexing
234  fParticles->RemoveAt(i);
235  fParticles->Compress();
236 }
237 //--------------------------------------------------------------------
238 
239 
UParticle
Definition: UParticle.h:10
UEvent::Print
void Print(Option_t *option="") const
Definition: UEvent.cxx:65
UEvent::fComment
TString fComment
Definition: UEvent.h:22
i
int i
Definition: L1/vectors/P4_F32vec4.h:25
UEvent::fStepT
Double_t fStepT
Definition: UEvent.h:20
ClassImp
ClassImp(UEvent)
UEvent::AddParticle
void AddParticle(Int_t index, Int_t pdg, Int_t status, Int_t parent, Int_t parentDecay, Int_t mate, Int_t decay, Int_t child[2], Double_t px, Double_t py, Double_t pz, Double_t e, Double_t x, Double_t y, Double_t z, Double_t t, Double_t weight)
Definition: UEvent.cxx:103
UParticle.h
UEvent
Definition: UEvent.h:12
UEvent::RemoveAt
void RemoveAt(Int_t i)
Definition: UEvent.cxx:230
UEvent.h
UEvent::fParticles
TClonesArray * fParticles
Definition: UEvent.h:23
UEvent::fPhi
Double_t fPhi
Definition: UEvent.h:17
UEvent::fEventNr
Int_t fEventNr
Definition: UEvent.h:15
UEvent::operator=
UEvent & operator=(const UEvent &right)
Definition: UEvent.cxx:179
UParticle::Print
void Print(Option_t *="") const
Definition: UParticle.cxx:257
UEvent::GetParticle
UParticle * GetParticle(Int_t index) const
Definition: UEvent.cxx:92
UEvent::fB
Double_t fB
Definition: UEvent.h:16
UEvent::SetParameters
void SetParameters(Int_t eventNr, Double_t b, Double_t phi, Int_t nes, Int_t stepNr, Double_t stepT, const char *comment="")
Definition: UEvent.cxx:201
UEvent::fNpa
Int_t fNpa
Definition: UEvent.h:21
UEvent::~UEvent
virtual ~UEvent()
Definition: UEvent.cxx:56
UEvent::UEvent
UEvent()
Definition: UEvent.cxx:20
UEvent::fStepNr
Int_t fStepNr
Definition: UEvent.h:19
x
Double_t x
Definition: CbmMvdSensorDigiToHitTask.cxx:68
y
Double_t y
Definition: CbmMvdSensorDigiToHitTask.cxx:68
UEvent::fNes
Int_t fNes
Definition: UEvent.h:18
pos
TVector3 pos
Definition: CbmMvdSensorDigiToHitTask.cxx:60
UEvent::Clear
void Clear(Option_t *="")
Definition: UEvent.cxx:221