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#include "HalCbmEvent.h"
5
7#include "CbmGlobalTrack.h"
8#include "CbmTofHit.h"
10#include "HalCbmTrack.h"
11
12#include <TLorentzVector.h>
13#include <TMath.h>
14
15#include <AnalysisTree/Constants.hpp>
16#include <AnalysisTree/Matching.hpp>
17
18#include <Hal/DataFormat.h>
19#include <Hal/Event.h>
20#include <Hal/ExpEvent.h>
21
22HalCbmEvent::HalCbmEvent() : Hal::ExpEvent("HalCbmTrack") {}
23
24HalCbmEvent::HalCbmEvent(const HalCbmEvent& other) : Hal::ExpEvent(other) {}
25
26void HalCbmEvent::Update(Hal::EventInterface* interface)
27{
28 fTracks->Clear();
29 HalCbmEventInterface* source = (HalCbmEventInterface*) interface;
30
31 switch (source->fFormatType) {
33 UpdateAnaTree(source);
34 } break;
36 UpdateDST(source);
37 } break;
38 default: break;
39 }
40}
41
42HalCbmEvent::HalCbmEvent(TString classname) : Hal::ExpEvent(classname) {}
43
45
47{
48 Bool_t exist = CheckBranches(1, "CbmAnaTreeSourceContainer.");
49 Bool_t exist2 = CheckBranches(1, "GlobalTrack");
50 if (exist || exist2) return kTRUE;
51 return kFALSE;
52}
53
55{
56 fTotalTracksNo = ei->GetTotalTrackNo();
57 TLorentzVector start = ei->GetVertex();
58 fVertex->SetXYZT(start.X(), start.Y(), start.Z(), start.T());
59 fTracks->ExpandCreateFast(fTotalTracksNo);
60 for (int i = 0; i < fTotalTracksNo; i++) {
61 HalCbmTrack* track = (HalCbmTrack*) fTracks->UncheckedAt(i);
62 track->ResetTrack(i, this);
63 CbmGlobalTrack* glob = (CbmGlobalTrack*) ei->fGlobalTracks->UncheckedAt(i);
64 track->SetChi2(glob->GetChi2());
65 track->SetVertexChi2(0);
66 track->SetTrackLenght(glob->GetLength());
67
68 const CbmTrackParam* track_param = glob->GetParamVertex();
69 track->SetMomentum(track_param->GetPx(), track_param->GetPy(), track_param->GetPz(), 0);
70 track->SetDCA(track_param->GetX() - fVertex->X(), track_param->GetY() - fVertex->Y(),
71 track_param->GetZ() - fVertex->Z());
72 Int_t sts_index = glob->GetStsTrackIndex();
73 Int_t tof_index = glob->GetTofHitIndex();
74 if (track_param->GetQp() > 0) {
75 track->SetCharge(1);
76 }
77 else {
78 track->SetCharge(-1);
79 }
80 if (sts_index >= 0) {
81 CbmStsTrack* sts = (CbmStsTrack*) ei->fStsTracks->UncheckedAt(sts_index);
82 track->SetNMvdHits(sts->GetNofMvdHits());
83 track->SetNStsHits(sts->GetNofStsHits());
84 }
85 else {
86 track->SetNMvdHits(0);
87 track->SetNStsHits(0);
88 }
89 track->BuildHelix();
90 Hal::ToFTrack* tof = (Hal::ToFTrack*) track->GetDetTrack(Hal::DetectorID::kTOF);
91
92 if (tof_index >= 0) {
93 CbmTofHit* hit = (CbmTofHit*) ei->fTofHits->UncheckedAt(tof_index);
94 Double_t t = hit->GetTime();
95 Double_t beta = track->GetTrackLenght() / t / (29.9792458);
96 Double_t p = track->GetMomentum().P();
97 Double_t m2 = p * p * (1. / beta / beta - 1.);
98 tof->SetMass2(m2);
99 tof->SetBeta(beta);
100 tof->SetFlag(1);
101 }
102 else {
103 tof->SetMass2(Hal::ToFTrack::DummyVal());
104 tof->SetBeta(Hal::ToFTrack::DummyVal());
105 tof->SetFlag(0);
106 }
107 }
108}
109
111{
113 fTotalTracksNo = ei->GetTotalTrackNo();
114 TLorentzVector start = ei->GetVertex();
115 fVertex->SetXYZT(start.X(), start.Y(), start.Z(), start.T());
116 fTracks->ExpandCreateFast(fTotalTracksNo);
117 AnaTreeRecoIds ids = container->GetFieldIds();
118 for (int i = 0; i < fTotalTracksNo; i++) {
119 AnalysisTree::Track p = container->GetVtxTracks()->GetChannel(i);
120 AnalysisTree::ShortInt_t match = container->GetVtx2ToFMatch()->GetMatchDirect(i);
121 HalCbmTrack* track = (HalCbmTrack*) fTracks->UncheckedAt(i);
122 track->ResetTrack(i, this);
123 track->SetChi2(p.GetField<float>(ids.vtx_chi2));
124 track->SetVertexChi2(p.GetField<float>(ids.vtx_vtxchi2));
125 track->SetMomentum(p.GetPx(), p.GetPy(), p.GetPz(), 0);
126 track->SetDCA(p.GetField<float>(ids.vtx_dcax), p.GetField<float>(ids.vtx_dcay), p.GetField<float>(ids.vtx_dcaz));
127 track->SetNMvdHits(p.GetField<int>(ids.vtx_mvdhits));
128 track->SetNStsHits(p.GetField<int>(ids.vtx_nhits) - track->GetNMvdHits());
129 track->SetCharge(p.GetField<int>(ids.vtx_q));
130 track->BuildHelix();
131 Hal::ToFTrack* tof = (Hal::ToFTrack*) track->GetDetTrack(Hal::DetectorID::kTOF);
132 if (match == AnalysisTree::UndefValueShort) {
133 /*no tof*/
134 tof->SetMass2(Hal::ToFTrack::DummyVal());
135 tof->SetBeta(Hal::ToFTrack::DummyVal());
136 tof->SetFlag(0);
137 }
138 else {
139 AnalysisTree::Hit tof_hit = container->GetTofHits()->GetChannel(match);
140 Double_t P = track->GetMomentum().P();
141 Double_t m2 = tof_hit.GetField<float>(ids.tof_mass2);
142 const TLorentzVector& vec = track->GetMomentum();
143 Double_t mom2 = vec.Px() * vec.Px() + vec.Py() * vec.Py() + vec.Pz() * vec.Pz();
144 Double_t E = TMath::Sqrt(mom2 + m2);
145 Double_t beta = P / E;
146 tof->SetMass2(m2);
147 tof->SetBeta(beta);
148 tof->SetFlag(1);
149 }
150 }
151}
152
153Hal::EventInterface* HalCbmEvent::CreateInterface() const { return new HalCbmEventInterface(); }
AnalysisTree::TrackDetector * GetVtxTracks() const
AnalysisTree::Matching * GetVtx2ToFMatch() const
AnalysisTree::HitDetector * GetTofHits() 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:76
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
CbmAnaTreeRecoSourceContainer * GetContainer() const
HalCbm::DataFormat fFormatType
virtual Int_t GetTotalTrackNo() const
virtual TLorentzVector GetVertex() const
void UpdateDST(HalCbmEventInterface *ei)
virtual ~HalCbmEvent()
void UpdateAnaTree(HalCbmEventInterface *ei)
virtual Bool_t ExistInTree() const
virtual Hal::EventInterface * CreateInterface() const
virtual void Update(Hal::EventInterface *interface)
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
Int_t GetNMvdHits() const
Definition HalCbmTrack.h:40
void BuildHelix()
void SetNStsHits(Int_t h)
Definition HalCbmTrack.h:46