CbmRoot
Loading...
Searching...
No Matches
HalCbmEvent.cxx
Go to the documentation of this file.
1/* Copyright (C) 2023-2023 Warsaw University of Technology, Warsaw
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Daniel Wielanek [committer] */
4
5#include "HalCbmEvent.h"
6
8#include "CbmGlobalTrack.h"
9#include "CbmHit.h"
10#include "CbmStsTrack.h"
11#include "CbmTofHit.h"
12#include "CbmTrackParam.h"
13#include "HalCbmDetectorID.h"
15#include "HalCbmV0TempTrack.h"
16
17#include <FairTrackParam.h>
18
19#include <TClonesArray.h>
20#include <TLorentzVector.h>
21#include <TMath.h>
22#include <TObjArray.h>
23
24#include <AnalysisTree/Constants.hpp>
25#include <AnalysisTree/Detector.hpp>
26#include <AnalysisTree/Hit.hpp>
27#include <AnalysisTree/Matching.hpp>
28#include <AnalysisTree/Track.hpp>
29
30#include <Hal/DataFormat.h>
31#include <Hal/DetectorTrack.h>
32#include <Hal/ExpTrack.h>
33#include <Hal/ToFTrack.h>
34#include <Hal/Track.h>
35
36HalCbmEvent::HalCbmEvent() : Hal::ExpEvent("HalCbmTrack", "HalCbmV0Track") {}
37
38HalCbmEvent::HalCbmEvent(const HalCbmEvent& other) : Hal::ExpEvent(other) {}
39
40void HalCbmEvent::Update(Hal::EventInterface* interface)
41{
42 Clear();
43 fVertexTracks = 0;
44 HalCbmEventInterface* source = (HalCbmEventInterface*) interface;
45
46 switch (source->fFormatType) {
48 UpdateAnaTree(source);
49 UpdateV0(source);
50 } break;
52 UpdateDST(source);
53 } break;
54 default: break;
55 }
56}
57
58HalCbmEvent::HalCbmEvent(TString classname) : Hal::ExpEvent(classname) {}
59
61{
62 if (!ei->fTempV0) return;
63 auto clones = ei->fTempV0;
64 int nv = clones->GetEntriesFast();
65 fTotalTracksNo += nv;
66 fTracks->ExpandCreateFast(fTotalTracksNo);
67 for (int i = 0; i < nv; i++) {
68 auto temp = (HalCbmV0TempTrack*) clones->UncheckedAt(i);
69 HalCbmTrack* track = (HalCbmTrack*) fTracks->UncheckedAt(i + fVertexTracks);
70 track->ResetTrack(i + fVertexTracks, this);
71 track->Hal::ExpTrack::CopyData(&temp->GetTrack());
72 track->BuildHelix();
73 track->EnableV0(kTRUE, kTRUE);
74#ifdef DEBUG_EXTR
75 auto vecpos = temp->GetV0().GetMomPos(); //copy at-data
76 auto vecneg = temp->GetV0().GetMomNeg();
77#endif
78 temp->ComputeStuff(this, track);
79 //new track momenta calculated !
80 auto recalcmom1 = temp->GetV0().GetMomPos();
81 auto recalcmom2 = temp->GetV0().GetMomNeg();
82 track->GetV0Info()->SetMomPos(recalcmom1.X(), recalcmom1.Y(), recalcmom1.Z());
83 track->GetV0Info()->SetMomNeg(recalcmom2.X(), recalcmom2.Y(), recalcmom2.Z());
84
85
86#ifdef DEBUG_EXTR
87 //recomputed data present print them
88 auto vecpos1 = temp->GetV0().GetMomPos();
89 auto vecpos2 = temp->GetV0().GetMomNeg();
90 std::cout << __FILE__ << "____" << std::endl;
91 auto print = [](TString t, TVector3 x) {
92 std::cout << Form("%4.4f %4.4f %4.4f %s", x.X(), x.Y(), x.Z(), t.Data()) << std::endl;
93 };
94 auto raw1 = GetTrack(temp->GetV0().GetPosId())->GetMomentum().Vect();
95 auto raw2 = GetTrack(temp->GetV0().GetNegId())->GetMomentum().Vect();
96 /*print("pos ori", vecpos);
97 print("pos com", vecpos1);
98 print("neg ori", vecneg);
99 print("neg com", vecpos2);*/
100 print("p1", raw1);
101 print("p2", raw2);
102 print("p1c", vecpos1);
103 print("p1x", vecpos);
104 print("p2c", vecpos2);
105 print("p2x", vecneg);
106 print("sum com", (vecpos1 + vecpos2));
107 print("sum raw", (raw1 + raw2));
108 print("tot v0m", track->GetMomentum().Vect());
109
110#else
111
112#endif
113 track->GetV0Info()->CopyData(&temp->GetV0());
114 }
115}
116
118
120{
121 Bool_t exist = CheckBranches({"CbmAnaTreeSourceContainer."});
122 Bool_t exist2 = CheckBranches({"GlobalTrack"});
123 if (exist || exist2) return kTRUE;
124 return kFALSE;
125}
126
128{
129 fTotalTracksNo = ei->GetTotalTrackNo();
130 TLorentzVector start = ei->GetVertex();
131 fVertex->SetXYZT(start.X(), start.Y(), start.Z(), start.T());
132 fTracks->ExpandCreateFast(fTotalTracksNo);
134 for (int i = 0; i < fTotalTracksNo; i++) {
135 HalCbmTrack* track = (HalCbmTrack*) fTracks->UncheckedAt(i);
136 track->ResetTrack(i, this);
137 CbmGlobalTrack* glob = (CbmGlobalTrack*) ei->fGlobalTracks->UncheckedAt(i);
138 track->SetChi2(glob->GetChi2());
139 track->SetVertexChi2(0);
140 track->SetTrackLenght(glob->GetLength());
141
142 const CbmTrackParam* track_param = glob->GetParamVertex();
143 track->SetMomentum(track_param->GetPx(), track_param->GetPy(), track_param->GetPz(), 0);
144 track->SetDCA(track_param->GetX() - fVertex->X(), track_param->GetY() - fVertex->Y(),
145 track_param->GetZ() - fVertex->Z());
146 Int_t sts_index = glob->GetStsTrackIndex();
147 Int_t tof_index = glob->GetTofHitIndex();
148 if (track_param->GetQp() > 0) {
149 track->SetCharge(1);
150 }
151 else {
152 track->SetCharge(-1);
153 }
154 if (sts_index >= 0) {
155 CbmStsTrack* sts = (CbmStsTrack*) ei->fStsTracks->UncheckedAt(sts_index);
156 track->SetNMvdHits(sts->GetNofMvdHits());
157 track->SetNStsHits(sts->GetNofStsHits());
158 }
159 else {
160 track->SetNMvdHits(0);
161 track->SetNStsHits(0);
162 }
163 track->BuildHelix();
164 Hal::ToFTrack* tof = (Hal::ToFTrack*) track->GetDetTrack(Hal::DetectorID::kTOF);
165
166 if (tof_index >= 0) {
167 CbmTofHit* hit = (CbmTofHit*) ei->fTofHits->UncheckedAt(tof_index);
168 Double_t t = hit->GetTime();
169 Double_t beta = track->GetTrackLenght() / t / (29.9792458);
170 Double_t p = track->GetMomentum().P();
171 Double_t m2 = p * p * (1. / beta / beta - 1.);
172 tof->SetMass2(m2);
173 tof->SetBeta(beta);
174 tof->SetFlag(1);
175 }
176 else {
177 tof->SetMass2(Hal::ToFTrack::DummyVal());
178 tof->SetBeta(Hal::ToFTrack::DummyVal());
179 tof->SetFlag(0);
180 }
181 }
182}
183
185{
186 CbmAnaTreeRecoContainer* container = ei->GetContainer();
187 fTotalTracksNo = fVertexTracks = ei->GetTotalTrackNo(); //number of vtx tracks
188 TLorentzVector start = ei->GetVertex();
189 fVertex->SetXYZT(start.X(), start.Y(), start.Z(), start.T());
190 fTracks->ExpandCreateFast(fTotalTracksNo);
191 AnaTreeRecoIds ids = container->GetFieldIds();
192 for (int i = 0; i < fTotalTracksNo; i++) {
193 AnalysisTree::Track p = container->GetVtxTracks()->GetChannel(i);
194 AnalysisTree::ShortInt_t match = container->GetVtx2ToFMatch()->GetMatchDirect(i);
195 HalCbmTrack* track = (HalCbmTrack*) fTracks->UncheckedAt(i);
196 track->ResetTrack(i, this);
197 track->SetChi2(p.GetField<float>(ids.vtx_chi2));
198 track->SetVertexChi2(p.GetField<float>(ids.vtx_vtxchi2));
199 track->SetMomentum(p.GetPx(), p.GetPy(), p.GetPz(), 0);
200 track->SetDCA(p.GetField<float>(ids.vtx_dcax), p.GetField<float>(ids.vtx_dcay), p.GetField<float>(ids.vtx_dcaz));
201 track->SetNMvdHits(p.GetField<int>(ids.vtx_mvdhits));
202 track->SetNStsHits(p.GetField<int>(ids.vtx_nhits) - track->GetNMvdHits());
203 track->SetCharge(p.GetField<int>(ids.vtx_q));
204 track->BuildHelix();
205 Hal::ToFTrack* tof = (Hal::ToFTrack*) track->GetDetTrack(Hal::DetectorID::kTOF);
206 if (match == AnalysisTree::UndefValueShort) {
207 /*no tof*/
208 tof->SetMass2(Hal::ToFTrack::DummyVal());
209 tof->SetBeta(Hal::ToFTrack::DummyVal());
210 tof->SetFlag(0);
211 }
212 else {
213 AnalysisTree::Hit tof_hit = container->GetTofHits()->GetChannel(match);
214 Double_t P = track->GetMomentum().P();
215 Double_t m2 = tof_hit.GetField<float>(ids.tof_mass2);
216 const TLorentzVector& vec = track->GetMomentum();
217 Double_t mom2 = vec.Px() * vec.Px() + vec.Py() * vec.Py() + vec.Pz() * vec.Pz();
218 Double_t E = TMath::Sqrt(mom2 + m2);
219 Double_t beta = P / E;
220 tof->SetMass2(m2);
221 tof->SetBeta(beta);
222 tof->SetFlag(1);
223 }
224 }
225}
226
227Hal::EventInterface* HalCbmEvent::CreateInterface() const { return new HalCbmEventInterface(); }
228
229void HalCbmEvent::ShallowCopyEvent(Hal::Event* event)
230{
231 Hal::ExpEvent::ShallowCopyEvent(event);
232 auto ev = (HalCbmEvent*) event;
233 fVertexTracks = ev->fVertexTracks;
234}
Data class for STS tracks.
int Int_t
bool Bool_t
AnalysisTree::TrackDetector * GetVtxTracks() const
AnaTreeRecoIds & GetFieldIds()
AnalysisTree::HitDetector * GetTofHits() const
AnalysisTree::Matching * GetVtx2ToFMatch() const
int32_t GetStsTrackIndex() const
const CbmTrackParam * GetParamVertex() const
double GetChi2() const
int32_t GetTofHitIndex() const
double GetLength() const
double GetTime() const
Definition CbmHit.h:79
int32_t GetNofMvdHits() const
Definition CbmStsTrack.h:87
int32_t GetNofStsHits() const
Definition CbmStsTrack.h:93
double GetPz() const
double GetPx() const
double GetPy() const
HalCbm::DataFormat fFormatType
virtual Int_t GetTotalTrackNo() const
virtual TLorentzVector GetVertex() const
CbmAnaTreeRecoContainer * GetContainer() const
Int_t fVertexTracks
Definition HalCbmEvent.h:26
void UpdateDST(HalCbmEventInterface *ei)
virtual ~HalCbmEvent()
void UpdateV0(HalCbmEventInterface *ei)
void UpdateAnaTree(HalCbmEventInterface *ei)
virtual Bool_t ExistInTree() const
virtual Hal::EventInterface * CreateInterface() const
HalCbmEvent(TString classname)
virtual void Update(Hal::EventInterface *interface)
virtual void ShallowCopyEvent(Hal::Event *event)
virtual Hal::DetectorTrack * GetDetTrack(const UInt_t detID) const
void SetNMvdHits(Int_t h)
Definition HalCbmTrack.h:45
void SetVertexChi2(Double_t v)
Definition HalCbmTrack.h:44
virtual void CopyData(Hal::Track *other)
Int_t GetNMvdHits() const
Definition HalCbmTrack.h:40
void BuildHelix()
void SetNStsHits(Int_t h)
Definition HalCbmTrack.h:46