Heavy ion Analysis Libriares
Loading...
Searching...
No Matches
Event.cxx
1/*
2 * Event.cxx
3 *
4 * Created on: 23-06-2014
5 * Author: Daniel Wielanek
6 * E-mail: daniel.wielanek@gmail.com
7 * Warsaw University of Technology, Faculty of Physics
8 */
9
10#include "Event.h"
11#include "DataFormat.h"
12#include "EventInterfaceAdvanced.h"
13#include "TrackInterface.h"
14#include "V0Track.h"
15
16#include "CompressionMap.h"
17#include "Cout.h"
18#include "DataManager.h"
19#include "IOManager.h"
20#include "Package.h"
21
22#include <cstdarg>
23
24#include <RtypesCore.h>
25#include <TClass.h>
26#include <TDatabasePDG.h>
27#include <TLorentzVector.h>
28#include <TParticlePDG.h>
29#include <stddef.h>
30
31namespace Hal {
33 TNamed(),
34 fTotalV0s(0),
35 fTotalXis(0),
36 fTracks(nullptr),
37 fVertex(nullptr),
38 fPhi(0),
39 fPhiError(0),
40 fEventId(0),
41 fTotalTracksNo(0),
42 fMultiplicity(0) {
43 fPDG = TDatabasePDG::Instance();
44 fVertex = new TLorentzVector();
45 fV0sHiddenInfo = new TClonesArray("Hal::V0Track");
46 fXisHiddenInfo = new TClonesArray("Hal::XiTrack");
47 }
48
49 Event::Event(TString track_class, TString v0_class, TString xi_class) :
50 fTotalV0s(0), fTotalXis(0), fPhi(0), fPhiError(0), fEventId(0), fTotalTracksNo(0), fMultiplicity(0) {
51 fPDG = TDatabasePDG::Instance();
52 fVertex = new TLorentzVector();
53 fTracks = new TClonesArray(track_class);
54 fV0sHiddenInfo = new TClonesArray(v0_class);
55 fXisHiddenInfo = new TClonesArray(xi_class);
56 }
57
58 Event::Event(const Event& other) : TNamed(other) {
59 fPDG = TDatabasePDG::Instance();
60 fTracks = new TClonesArray(*other.fTracks);
61 fVertex = new TLorentzVector(*other.fVertex);
62 fPhi = other.fPhi;
63 fPhiError = other.fPhiError;
64 fTotalTracksNo = other.fTotalTracksNo;
65 fTotalV0s = other.fTotalV0s;
66 fTotalXis = other.fTotalXis;
67 fEventId = other.fEventId;
68 fMultiplicity = other.fMultiplicity;
69 fV0sHiddenInfo = new TClonesArray(*other.fV0sHiddenInfo);
70 fXisHiddenInfo = new TClonesArray(*other.fXisHiddenInfo);
71 }
72
74 if (fTracks) {
75 delete fTracks;
76 delete fVertex;
77 delete fV0sHiddenInfo;
78 delete fXisHiddenInfo;
79 }
80 }
81
82 void Event::Clear(Option_t* opt) {
83 fTracks->Clear(opt);
84 fV0sHiddenInfo->Clear(opt);
85 fXisHiddenInfo->Clear(opt);
86 fTotalTracksNo = 0;
87 fTotalV0s = 0;
88 fTotalXis = 0;
89 }
90
91 void Event::Print(Option_t* /*opt*/) const {
92 Cout::Database({"Event Phi", "Event Multiplicity"});
93 Cout::Database({Form("%4.2f", GetPhi()), Form("%i", GetTotalTrackNo())});
94 }
95
96 void Event::Build(Event* event, const CompressionMap& map) { CopyCompress(event, map); }
97
98 void Event::Build(Event* event) { CopyData(event); }
99
101 fMultiplicity = event->GetMutliplicity();
102 *fVertex = *event->GetVertex();
103 fPhi = event->fPhi;
104 fPhiError = event->fPhiError;
105 fEventId = event->GetEventID();
106 fTotalV0s = 0; // this need to be set by user!
107 fTotalTracksNo = 0; // this also should be set by the user
108 fTotalXis = 0;
109 }
110
112 fTotalTracksNo = event->fTracks->GetEntriesFast();
113 fV0sHiddenInfo->ExpandCreateFast(event->fTotalV0s);
114 fXisHiddenInfo->ExpandCreateFast(event->fTotalXis);
115 fTracks->ExpandCreateFast(fTotalTracksNo);
116 for (int i = 0; i < fTotalTracksNo; i++) {
117 Track* to = (Track*) fTracks->UncheckedAt(i);
118 Track* from = (Track*) event->fTracks->UncheckedAt(i);
119 to->ResetTrack(i, this);
120 to->CopyData(from);
121 }
122 }
123
124 void Event::Boost(Double_t vx, Double_t vy, Double_t vz) {
125 for (int i = 0; i < fTotalTracksNo; i++) {
126 Track* track = (Track*) fTracks->UncheckedAt(i);
127 track->Boost(vx, vy, vz);
128 }
129 }
130
132 Hal::Std::CompressArray(fTracks, map);
133 fTotalTracksNo = fTracks->GetEntriesFast();
134 }
135
136 void Event::CopyData(Event* event) {
137 ShallowCopyEvent(event);
138 ShallowCopyTracks(event);
139 }
140
141 void Event::CopyCompress(Event* event, const CompressionMap& map) {
142 ShallowCopyEvent(event);
143 ShallowCopyCompressTracks(event, map);
144 }
145
146 Double_t Event::CalculateCharge(Int_t pdg) const {
147 TParticlePDG* part = fPDG->GetParticle(pdg);
148 if (part) {
149 return part->Charge() / 3.0;
150 } else {
151 return 0;
152 }
153 }
154
155 TString Event::GetFormatName() const { return ClassName(); }
156
157 void Event::Update(EventInterface* interface) {
158 fTracks->Clear();
159 fV0sHiddenInfo->Clear();
160 fXisHiddenInfo->Clear();
161 fTotalV0s = 0;
162 fTotalXis = 0;
163 EventInterfaceAdvanced* source = dynamic_cast<EventInterfaceAdvanced*>(interface);
164 if (source) {
165 fPhi = source->GetPhi();
166 fPhiError = source->GetPhiError();
167 TLorentzVector vert = source->GetVertex();
168 fVertex->SetXYZT(vert.X(), vert.Y(), vert.Z(), vert.T());
169 fTotalTracksNo = source->GetTotalTrackNo();
170 fTracks->ExpandCreateFast(fTotalTracksNo);
171 TrackInterface* trInterface = source->GetTrackInterface();
172 for (int i = 0; i < fTotalTracksNo; i++) {
173 Track* from = GetTrack(i);
174 from->ResetTrack(i, this);
175 from->SetID(trInterface->GetID());
176 source->FillTrackInterface(trInterface, i);
177 from->SetCharge(trInterface->GetCharge());
178 from->SetMotherIndex(trInterface->GetMotherIndex());
179 if (trInterface->IsPrimary()) {
180 from->SetPrimary();
181 } else {
182 from->SetSecondary(kFALSE);
183 }
184 from->EnableV0(kFALSE, kFALSE);
185 from->SetMomentum(trInterface->GetPz(), trInterface->GetPy(), trInterface->GetPz(), trInterface->GetE());
186 }
187 }
188 }
189
191 fV0sHiddenInfo->Clear();
192 fXisHiddenInfo->Clear();
193 fTotalTracksNo = map.GetNewSize();
194 fTracks->ExpandCreateFast(fTotalTracksNo);
195 for (int i = 0; i < fTotalTracksNo; i++) {
196 Track* to = (Track*) fTracks->UncheckedAt(i);
197 Track* from = (Track*) event->fTracks->UncheckedAt(map.GetOldIndex(i));
198 to->ResetTrack(i, this);
199 to->CopyData(from);
200 to->TranslateLinks(map);
201 }
202 }
203
205 TClass* cl = fTracks->GetClass();
206 return (Track*) cl->New(TClass::kClassNew);
207 }
208
210 Track* tr = (Track*) fTracks->ConstructedAt(fTotalTracksNo);
211 tr->ResetTrack(fTotalTracksNo++, this);
212 return tr;
213 }
214
216 TClass* cl = TClass::GetClass(this->ClassName(), 1, 1);
217 Event* ev = (Event*) cl->New(TClass::kClassNew);
218 return ev;
219 }
220
221 Bool_t Event::CheckBranches(Int_t n...) const {
222 va_list args;
223 va_start(args, n);
224 DataManager* mngr = DataManager::Instance();
225 for (int i = 0; i < n; i++) {
226 const char* name = va_arg(args, char*);
227 if (!mngr->CheckBranch(name)) {
228 Cout::PrintInfo(Form("Check branch: %s, branch not found", name), EInfo::kDebugInfo);
229 return kFALSE;
230 }
231 }
232 return kTRUE;
233 }
234 Bool_t Event::CheckBranches(std::initializer_list<TString> list) const {
235 DataManager* mngr = DataManager::Instance();
236 for (auto name : list) {
237 if (!mngr->CheckBranch(name)) {
238 Cout::PrintInfo(Form("Check branch: %s, branch not found", name.Data()), EInfo::kDebugInfo);
239 return kFALSE;
240 }
241 }
242 return kTRUE;
243 }
244
245 Bool_t Event::IsCompatible(const Event* non_buffered) const {
246 TString formatName = non_buffered->GetFormatName();
247 TString thisName = this->GetFormatName();
248 if (formatName == thisName) return kTRUE;
249 return kFALSE;
250 }
251
252 Package* Event::Report() const { return new Package(this); }
253
254 Float_t Event::GetFieldVal(Int_t fieldID) const {
255 switch (fieldID) {
256 case DataFieldID::Event::EBasic::kEventPhi: return GetPhi(); break;
257 case DataFieldID::Event::EBasic::kPhiError: return GetPhiError(); break;
258 case DataFieldID::Event::EBasic::kTracksNo: return GetTotalTrackNo(); break;
259 case DataFieldID::Event::EBasic::kVertexXY: return GetVertex()->Pt(); break;
260
261 case DataFieldID::Event::EBasic::kVertexX: return GetVertex()->X(); break;
262 case DataFieldID::Event::EBasic::kVertexY: return GetVertex()->Y(); break;
263 case DataFieldID::Event::EBasic::kVertexZ: return GetVertex()->Z(); break;
264 case DataFieldID::Event::EBasic::kVertexT: return GetVertex()->T(); break;
265 case DataFieldID::Event::EBasic::kEventId: return GetEventID(); break;
266 case DataFieldID::Event::EBasic::kMultiplicity: return GetMutliplicity(); break;
267 case DataFieldID::Event::EBasic::kEventZero: return 0;
268 }
269 return -FLT_MAX;
270 }
271
272 TString Event::GetFieldName(Int_t fieldID) const {
273 switch (fieldID) {
274 case DataFieldID::Event::EBasic::kEventPhi: return "#phi [rad]"; break;
275 case DataFieldID::Event::EBasic::kPhiError: return "#sigma#phi [rad]"; break;
276 case DataFieldID::Event::EBasic::kTracksNo: return "N_{tracks} [AU]"; break;
277 case DataFieldID::Event::EBasic::kVertexXY: return "V_{xy} [cm]"; break;
278
279 case DataFieldID::Event::EBasic::kVertexX: return "V_{x} [cm]"; break;
280 case DataFieldID::Event::EBasic::kVertexY: return "V_{y} [cm]"; break;
281 case DataFieldID::Event::EBasic::kVertexZ: return "V_{z} [cm]"; break;
282 case DataFieldID::Event::EBasic::kVertexT: return "V_{t} [s]"; break;
283 case DataFieldID::Event::EBasic::kEventId: return "EventID [ID]"; break;
284 case DataFieldID::Event::EBasic::kMultiplicity: return "Multiplicity [N_{tracks}]"; break;
285 }
286 Cout::PrintInfo(Form("Event::GetFieldName cannot find field with fieldID %i", fieldID), EInfo::kLowWarning);
287 return "[]";
288 }
289
290 void Event::RotateZ(Double_t phi) {
291 fPhi = TVector2::Phi_mpi_pi(fPhi + phi);
292 for (int i = 0; i < fTotalTracksNo; i++) {
293 auto track = (Track*) fTracks->UncheckedAt(i);
294 track->RotateZ(phi);
295 }
296 const Int_t nVos = fV0sHiddenInfo->GetEntriesFast();
297 for (int i = 0; i < nVos; i++) {
298 auto vo = (V0Track*) fV0sHiddenInfo->UncheckedAt(i);
299 vo->RotateZ(phi);
300 }
301 const Int_t nXis = fXisHiddenInfo->GetEntriesFast();
302 for (int i = 0; i < nXis; i++) {
303 auto vo = (XiTrack*) fXisHiddenInfo->UncheckedAt(i);
304 vo->RotateZ(phi);
305 }
306 }
307
308} // namespace Hal
Int_t GetOldIndex(Int_t new_index) const
Int_t GetNewSize() const
static void PrintInfo(TString text, Hal::EInfo status)
Definition Cout.cxx:370
static void Database(Int_t no...)
Bool_t CheckBranch(const char *BrName)
virtual Double_t GetPhiError() const
virtual Int_t GetTotalTrackNo() const =0
virtual TLorentzVector GetVertex() const
TrackInterface * GetTrackInterface() const
virtual void FillTrackInterface(TrackInterface *track, Int_t index)=0
virtual Double_t GetPhi() const
virtual void ShallowCopyTracks(Event *event)
Definition Event.cxx:111
void Build(Event *event, const CompressionMap &map)
Definition Event.cxx:96
virtual Bool_t IsCompatible(const Event *non_buffered) const
Definition Event.cxx:245
virtual void Boost(Double_t vx, Double_t vy, Double_t vz)
Definition Event.cxx:124
virtual void ShallowCopyEvent(Event *event)
Definition Event.cxx:100
virtual ~Event()
Definition Event.cxx:73
Track * GetNewTrack() const
Definition Event.cxx:204
virtual Package * Report() const
Definition Event.cxx:252
virtual void Update(EventInterface *interface)
Definition Event.cxx:157
Int_t GetTotalTrackNo() const
Definition Event.h:236
virtual void Print(Option_t *opt="") const
Definition Event.cxx:91
Double_t GetPhiError() const
Definition Event.h:256
void CopyCompress(Event *event, const CompressionMap &map)
Definition Event.cxx:141
Int_t GetMutliplicity() const
Definition Event.h:246
virtual void ShallowCopyCompressTracks(Event *event, const CompressionMap &map)
Definition Event.cxx:190
virtual void Clear(Option_t *opt=" ")
Definition Event.cxx:82
virtual Float_t GetFieldVal(Int_t fieldID) const
Definition Event.cxx:254
void CopyData(Event *event)
Definition Event.cxx:136
void Compress(TClonesArray *array, const CompressionMap &map)
Double_t CalculateCharge(Int_t pdg) const
Definition Event.cxx:146
virtual Event * GetNewEvent() const
Definition Event.cxx:215
Double_t GetPhi() const
Definition Event.h:251
TLorentzVector * GetVertex() const
Definition Event.h:261
virtual TString GetFormatName() const
Definition Event.cxx:155
virtual TString GetFieldName(Int_t fieldID) const
Definition Event.cxx:272
Bool_t CheckBranches(Int_t n...) const
Definition Event.cxx:221
Track * AddTrack()
Definition Event.cxx:209
Int_t GetEventID() const
Definition Event.h:231
virtual void RotateZ(Double_t phi)
Definition Event.cxx:290
Track * GetTrack(Int_t i) const
Definition Event.h:208
virtual Double_t GetPz() const
virtual Double_t GetCharge() const
virtual Double_t GetPy() const
virtual Int_t GetMotherIndex() const
virtual Double_t GetE() const
virtual Bool_t IsPrimary() const
virtual Int_t GetID() const
void SetCharge(Double_t charge)
Definition Track.h:134
virtual void ResetTrack(Int_t thisID=-1, Event *event=nullptr)
Definition Track.cxx:295
void EnableV0(Bool_t v0, Bool_t daughters=kTRUE)
Definition Track.cxx:192
void SetID(Int_t id)
Definition Track.h:139
void TranslateLinks(const CompressionMap &map)
Definition Track.cxx:129
void SetSecondary(Bool_t parent)
Definition Track.cxx:183
virtual void Boost(Double_t vx, Double_t vy, Double_t vz)
Definition Track.cxx:33
virtual void CopyData(Track *other)
Definition Track.cxx:40
void SetMotherIndex(Int_t index)
Definition Track.h:170
void SetMomentum(Double_t px, Double_t py, Double_t pz, Double_t e)
Definition Track.h:152
void SetPrimary()
Definition Track.cxx:35