Heavy ion Analysis Libriares
Loading...
Searching...
No Matches
ComplexEvent.cxx
1/*
2 * EventCombined.cxx
3 *
4 * Created on: 4 kwi 2017
5 * Author: Daniel Wielanek
6 * E-mail: daniel.wielanek@gmail.com
7 * Warsaw University of Technology, Faculty of Physics
8 */
9
10#include "ComplexEvent.h"
11
12
13#include <TClonesArray.h>
14#include <TMathBase.h>
15#include <TObjArray.h>
16
17#include "ComplexEventInterface.h"
18#include "ComplexTrack.h"
19#include "CompressionMap.h"
20#include "DataFormat.h"
21#include "Track.h"
22
23namespace Hal {
24 CompressionMap ComplexEvent::fgCompressionMap;
25
26 ComplexEvent::ComplexEvent(Event* real, Event* img) : ComplexEvent("Hal::ComplexTrack", real, img) {}
27
28 ComplexEvent::ComplexEvent(TString track_class, Event* real, Event* img) :
29 Event(track_class), fRealEvent(real), fImgEvent(img) {}
30
31 void ComplexEvent::Update(EventInterface* interface) {
32 ComplexEventInterface* source = (ComplexEventInterface*) interface;
33 Clear();
34 fImgEvent->Update(source->GetReal());
35 fRealEvent->Update(source->GetImag());
36 Event::ShallowCopyEvent(fRealEvent);
37 fV0sHiddenInfo->Clear();
38 if (fRealEvent->GetTotalTrackNo()) {
39 fTotalTracksNo = fRealEvent->GetTotalTrackNo();
40 fTracks->ExpandCreateFast(fTotalTracksNo);
41 for (int i = 0; i < fTotalTracksNo; i++) {
42 Track* tr = (Track*) fRealEvent->fTracks->UncheckedAt(i);
43 ComplexTrack* to = (ComplexTrack*) fTracks->UncheckedAt(i);
44 to->ResetTrack(i, this);
45 to->Track::CopyData(tr);
46 to->SetImgTrack((Track*) fImgEvent->GetTrack(i));
47 to->SetRealTrack(tr);
48 }
49 } else {
50 fTracks->Clear();
51 }
52 }
53
54 Bool_t ComplexEvent::ExistInTree() const {
55 if (fImgEvent && fRealEvent) {
56 if (fImgEvent->ExistInTree() && fRealEvent->ExistInTree()) { return kTRUE; }
57 }
58 return kFALSE;
59 }
60
61 ComplexEvent::ComplexEvent(const ComplexEvent& other) : Event(other) {
62 fImgEvent = other.fImgEvent->GetNewEvent();
63 fRealEvent = other.fRealEvent->GetNewEvent();
64 fImgEvent->CopyData(other.fImgEvent);
65 fRealEvent->CopyData(other.fRealEvent);
66 }
67
68 void ComplexEvent::Clear(Option_t* /*opt*/) {
70 fRealEvent->Clear();
71 fImgEvent->Clear();
72 }
73
75 fRealEvent->ShallowCopyEvent(((ComplexEvent*) event)->GetRealEvent());
76 fImgEvent->ShallowCopyEvent(((ComplexEvent*) event)->GetImgEvent());
77 Event::ShallowCopyEvent(((ComplexEvent*) event)->GetRealEvent());
78 }
79
81 EventInterface* re = fRealEvent->CreateInterface();
82 EventInterface* im = fImgEvent->CreateInterface();
83 return new ComplexEventInterface(re, im);
84 }
85
86 ComplexEvent::~ComplexEvent() {
87 if (fImgEvent) delete fImgEvent;
88 if (fRealEvent) delete fRealEvent;
89 }
90
92 fRealEvent->ShallowCopyTracks(((ComplexEvent*) event)->GetRealEvent());
93 fImgEvent->ShallowCopyTracks(((ComplexEvent*) event)->GetImgEvent());
94 ComplexEvent* mc_event = (ComplexEvent*) event;
95 fTotalTracksNo = mc_event->fTracks->GetEntriesFast();
96 fTracks->ExpandCreate(fTotalTracksNo);
97 fV0sHiddenInfo->ExpandCreateFast(fRealEvent->fV0sHiddenInfo->GetEntriesFast());
98 for (int i = 0; i < fTotalTracksNo; i++) {
99 ComplexTrack* to = (ComplexTrack*) fTracks->UncheckedAt(i);
100 ComplexTrack* from = (ComplexTrack*) mc_event->fTracks->UncheckedAt(i);
101 to->ResetTrack(i, this);
102 to->CopyData(from);
103 to->SetRealTrack(fRealEvent->GetTrack(i));
104 Int_t match_id = to->GetMatchID();
105 if (match_id >= 0) to->SetImgTrack(fImgEvent->GetTrack(match_id));
106 }
107 }
108
110 fRealEvent->ShallowCopyCompressTracks(((ComplexEvent*) event)->GetRealEvent(), map);
111 CalculateCompressionMapImg(map, (ComplexEvent*) event);
112 fImgEvent->ShallowCopyCompressTracks(((ComplexEvent*) event)->GetImgEvent(), fgCompressionMap);
113 ComplexEvent* mc_event = (ComplexEvent*) event;
114 fTotalTracksNo = map.GetNewSize();
115 fTracks->ExpandCreateFast(fTotalTracksNo);
116 for (int i = 0; i < fTotalTracksNo; i++) {
117 ComplexTrack* to = (ComplexTrack*) fTracks->UncheckedAt(i);
118 ComplexTrack* from = (ComplexTrack*) mc_event->fTracks->UncheckedAt(map.GetOldIndex(i));
119 to->ResetTrack(i, this);
120 to->CopyData(from);
121 to->TranslateLinks(map);
122 to->SetRealTrack(fRealEvent->GetTrack(i));
123 if (from->GetMatchID() < 0) { continue; }
124 to->SetMatchID(fgCompressionMap.GetNewIndex(from->GetMatchID()));
125 Int_t match_id = to->GetMatchID();
126 to->SetImgTrack(fImgEvent->GetTrack(match_id));
127 }
128 }
129
130 void ComplexEvent::CalculateCompressionMapImg(const CompressionMap& map, ComplexEvent* event) {
131 Event* img_event = event->GetImgEvent();
132 const Int_t sizeImg = img_event->GetTotalTrackNo();
133 const Int_t newSize = TMath::Max(sizeImg, map.GetSize());
134 fgCompressionMap.Reset(newSize);
135 std::vector<int> links;
136 links.resize(GetImgEvent()->GetMaxExpectedLinks());
137 for (int i = 0; i < map.GetNewSize(); i++) {
138 ComplexTrack* tr = (ComplexTrack*) event->GetTrack(map.GetOldIndex(i));
139 Int_t matchId = tr->GetMatchID();
140 if (matchId >= 0) {
141 // fgCompressionMap.MarkAsGood(matchId);
142 Track* mcTrack = event->GetImgEvent()->GetTrack(matchId);
143 int linksNo = mcTrack->GetLinksFast(links, kTRUE);
144 for (int iLink = 0; iLink < linksNo; iLink++) {
145 fgCompressionMap.MarkAsGood(links[iLink]);
146 }
147 }
148 }
149 fgCompressionMap.Recalculate();
150 }
151
153 if (fRealEvent->HasHiddenSettings()) return kTRUE;
154 if (fImgEvent->HasHiddenSettings()) return kTRUE;
155 return kFALSE;
156 }
157
158 Bool_t ComplexEvent::IsCompatible(const Event* non_buffered) const {
159 const ComplexEvent* ev = dynamic_cast<const ComplexEvent*>(non_buffered);
160 if (ev == nullptr) return kFALSE;
161 if (Event::IsCompatible(non_buffered)) return kTRUE;
162 if (!ev->GetImgEvent()->IsCompatible(ev->GetImgEvent())) return kFALSE;
163 if (!ev->GetRealEvent()->IsCompatible(ev->GetRealEvent())) return kFALSE;
164 return kTRUE;
165 }
166
167 Float_t ComplexEvent::GetFieldVal(Int_t fieldID) const {
168
169 if (fieldID >= DataFieldID::Internal::ImStepEvent) {
170 if (GetImgEvent() == nullptr) return FLT_MIN;
171 return GetImgEvent()->GetFieldVal(fieldID - DataFieldID::ImStep);
172 } else if (fieldID >= DataFieldID::Internal::ReStepEvent) {
173 return GetRealEvent()->GetFieldVal(fieldID - DataFieldID::ReStep);
174 }
175
176 switch (fieldID) {
177 case DataFieldID::Event::EComplex::kDeltaRPhi: return GetImgEvent()->GetPhi() - GetRealEvent()->GetPhi(); break;
178 case DataFieldID::Event::EComplex::kDeltaVertexXY: {
179 Double_t dx = GetImgEvent()->GetVertex()->X() - GetRealEvent()->GetVertex()->X();
180 Double_t dy = GetImgEvent()->GetVertex()->Y() - GetRealEvent()->GetVertex()->Y();
181 return TMath::Sqrt(dx * dx + dy * dy);
182 } break;
183 case DataFieldID::Event::EComplex::kDeltaVertexX:
184 return GetImgEvent()->GetVertex()->X() - GetRealEvent()->GetVertex()->X();
185 break;
186 case DataFieldID::Event::EComplex::kDeltaVertexY:
187 return GetImgEvent()->GetVertex()->Y() - GetRealEvent()->GetVertex()->Y();
188 break;
189 case DataFieldID::Event::EComplex::kDeltaVertexZ:
190 return GetImgEvent()->GetVertex()->Z() - GetRealEvent()->GetVertex()->Z();
191 break;
192 case DataFieldID::Event::EComplex::kDeltaVertexT:
193 return GetImgEvent()->GetVertex()->T() - GetRealEvent()->GetVertex()->T();
194 break;
195 case DataFieldID::Event::EComplex::kDeltaVertex: {
196 Double_t dx = GetImgEvent()->GetVertex()->X() - GetRealEvent()->GetVertex()->X();
197 Double_t dy = GetImgEvent()->GetVertex()->Y() - GetRealEvent()->GetVertex()->Y();
198 Double_t dz = GetImgEvent()->GetVertex()->Z() - GetRealEvent()->GetVertex()->Z();
199 return TMath::Sqrt(dx * dx + dy * dy + dz * dz);
200 } break;
201 case DataFieldID::Event::EComplex::kDeltaTracksNo:
202 return GetImgEvent()->GetTotalTrackNo() - GetRealEvent()->GetTotalTrackNo();
203 break;
204 }
205
206 return Event::GetFieldVal(fieldID);
207 }
208
209 TString ComplexEvent::GetFieldName(Int_t fieldID) const {
210 if (fieldID >= DataFieldID::Internal::ImStepEvent) {
211 if (GetImgEvent() == nullptr) return "xxx";
212 return GetImgEvent()->GetFieldName(fieldID - DataFieldID::ImStep) + " (im)";
213 } else if (fieldID >= DataFieldID::Internal::ReStepEvent) {
214 return GetRealEvent()->GetFieldName(fieldID - DataFieldID::ReStep) + " (re)";
215 }
216 switch (fieldID) {
217 case DataFieldID::Event::EComplex::kDeltaRPhi: return "#Delta #phi [rad]"; break;
218 case DataFieldID::Event::EComplex::kDeltaVertexXY: return "#Delta V_{XY} [cm]"; break;
219 case DataFieldID::Event::EComplex::kDeltaVertexX: return "#Delta V_{X} [cm]"; break;
220 case DataFieldID::Event::EComplex::kDeltaVertexY: return "#Delta V_{Y} [cm]"; break;
221 case DataFieldID::Event::EComplex::kDeltaVertexZ: return "#Delta V_{Z} [cm]"; break;
222 case DataFieldID::Event::EComplex::kDeltaVertexT: return "#Delta V_{T} [ns]"; break;
223 case DataFieldID::Event::EComplex::kDeltaVertex: return "#Delta V_{XYZ} [cm]"; break;
224 case DataFieldID::Event::EComplex::kDeltaTracksNo: return "#Delta N_{tracksNo} [AU]"; break;
225 }
226 return Event::GetFieldName(fieldID);
227 }
228} // namespace Hal
virtual Float_t GetFieldVal(Int_t fieldID) const
void ShallowCopyEvent(Event *event)
void ShallowCopyCompressTracks(Event *event, const CompressionMap &map)
virtual Bool_t IsCompatible(const Event *non_buffered) const
virtual Bool_t HasHiddenSettings() const
virtual TString GetFieldName(Int_t fieldID) const
void ShallowCopyTracks(Event *event)
virtual void Clear(Option_t *opt=" ")
EventInterface * CreateInterface() const
virtual void ResetTrack(Int_t thisId=-1, Event *event=nullptr)
virtual void CopyData(Track *other)
Int_t GetNewIndex(Int_t old_index) const
void MarkAsGood(Int_t old_index)
void Reset(Int_t size)
Int_t GetOldIndex(Int_t new_index) const
Int_t GetSize() const
Int_t GetNewSize() const
virtual void ShallowCopyTracks(Event *event)
Definition Event.cxx:111
virtual Bool_t IsCompatible(const Event *non_buffered) const
Definition Event.cxx:245
virtual void ShallowCopyEvent(Event *event)
Definition Event.cxx:100
virtual Bool_t HasHiddenSettings() const
Definition Event.h:337
Int_t GetTotalTrackNo() const
Definition Event.h:236
virtual EventInterface * CreateInterface() const =0
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
virtual Event * GetNewEvent() const
Definition Event.cxx:215
Double_t GetPhi() const
Definition Event.h:251
TLorentzVector * GetVertex() const
Definition Event.h:261
virtual Int_t GetMaxExpectedLinks() const
Definition Event.h:330
virtual TString GetFieldName(Int_t fieldID) const
Definition Event.cxx:272
Track * GetTrack(Int_t i) const
Definition Event.h:208
void TranslateLinks(const CompressionMap &map)
Definition Track.cxx:129
virtual Int_t GetLinksFast(std::vector< int > &vec, Bool_t fast=kTRUE) const
Definition Track.cxx:84