CbmRoot
Loading...
Searching...
No Matches
HalCbmV0Builder.cxx
Go to the documentation of this file.
1/* Copyright (C) 2025-2025 Warsaw University of Technology, Warsaw
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Daniel Wielanek [committer] */
4#include "HalCbmV0Builder.h"
5
7#include "HalCbmDetectorID.h"
8#include "HalCbmTrack.h"
9#include "HalCbmV0TempTrack.h"
10#include "HalCbmV0Track.h"
11
12#include <TClonesArray.h>
13#include <TDatabasePDG.h>
14#include <TParticlePDG.h>
15
16#include <Hal/Cout.h>
17#include <Hal/DataManager.h>
18
19namespace Hal
20{
21
22} /* namespace Hal */
23
25{
27 v0Info.chi2geo = p.GetField<float>(fV0Container->GetFieldIds().chi2geo);
28 v0Info.chi2_prim_first = p.GetField<float>(fV0Container->GetFieldIds().chi2_prim_first);
29 v0Info.chi2_prim_second = p.GetField<float>(fV0Container->GetFieldIds().chi2_prim_second);
30 v0Info.chi2_topo = p.GetField<float>(fV0Container->GetFieldIds().chi2_topo);
31 v0Info.cosine_first = p.GetField<float>(fV0Container->GetFieldIds().cosine_first);
32 v0Info.cosine_second = p.GetField<float>(fV0Container->GetFieldIds().cosine_second);
33 v0Info.cosine_topo = p.GetField<float>(fV0Container->GetFieldIds().cosine_topo);
34 v0Info.distance = p.GetField<float>(fV0Container->GetFieldIds().distance);
35 v0Info.l = p.GetField<float>(fV0Container->GetFieldIds().l);
36 v0Info.l_dl = p.GetField<float>(fV0Container->GetFieldIds().l_over_dl);
37 v0Info.mass = p.GetField<float>(fV0Container->GetFieldIds().mass);
38 v0Info.px = p.GetField<float>(fV0Container->GetFieldIds().px);
39 v0Info.py = p.GetField<float>(fV0Container->GetFieldIds().py);
40 v0Info.pz = p.GetField<float>(fV0Container->GetFieldIds().pz);
41 v0Info.x = p.GetField<float>(fV0Container->GetFieldIds().x);
42 v0Info.y = p.GetField<float>(fV0Container->GetFieldIds().y);
43 v0Info.z = p.GetField<float>(fV0Container->GetFieldIds().z);
44 v0Info.pid = p.GetField<int>(fV0Container->GetFieldIds().pdg);
45 v0Info.dau1id = p.GetField<int>(fV0Container->GetFieldIds().dau1id);
46 v0Info.dau2id = p.GetField<int>(fV0Container->GetFieldIds().dau2id);
47
48#ifdef DEBUG_EXTR
49 v0Info.dau1px = p.GetField<float>(fV0Container->GetFieldIds().dau1px);
50 v0Info.dau1py = p.GetField<float>(fV0Container->GetFieldIds().dau1py);
51 v0Info.dau1pz = p.GetField<float>(fV0Container->GetFieldIds().dau1pz);
52 v0Info.dau1x = p.GetField<float>(fV0Container->GetFieldIds().dau1x);
53 v0Info.dau1y = p.GetField<float>(fV0Container->GetFieldIds().dau1y);
54 v0Info.dau1z = p.GetField<float>(fV0Container->GetFieldIds().dau1z);
55
56 v0Info.dau2px = p.GetField<float>(fV0Container->GetFieldIds().dau2px);
57 v0Info.dau2py = p.GetField<float>(fV0Container->GetFieldIds().dau2py);
58 v0Info.dau2pz = p.GetField<float>(fV0Container->GetFieldIds().dau2pz);
59 v0Info.dau2x = p.GetField<float>(fV0Container->GetFieldIds().dau2x);
60 v0Info.dau2y = p.GetField<float>(fV0Container->GetFieldIds().dau2y);
61 v0Info.dau2z = p.GetField<float>(fV0Container->GetFieldIds().dau2z);
62#endif
63 return v0Info;
64}
65
67 : fPidMom(motherPid)
68 , fPidPosDau(posdau)
69 , fPidNegDau(negdau)
70{
71}
72
73HalCbmV0Builder::EInitFlag HalCbmV0Builder::Init()
74{
75 fSimContainer = (CbmAnaTreeMcContainer*) Hal::DataManager::Instance()->GetObject(HalCbm::GetContainerName("mc"));
76 fRecoContainer = (CbmAnaTreeRecoContainer*) Hal::DataManager::Instance()->GetObject(HalCbm::GetContainerName("reco"));
77 fV0Container = (CbmAnaTreeV0Container*) Hal::DataManager::Instance()->GetObject(HalCbm::GetContainerName("v0"));
78 auto trk = TDatabasePDG::Instance()->GetParticle(fPidMom);
79 if (!trk) {
80 Hal::Cout::PrintInfo(Form("HalCbmV0Builder::Init cannot find selected mother PID=%i", fPidMom), Hal::EInfo::kError);
81 return EInitFlag::kERROR;
82 }
83 fMass = trk->Mass();
84 if (!fV0Container) {
85 Hal::Cout::PrintInfo("HalCbmV0Builder::Init cannot find V0 data", Hal::EInfo::kError);
86 return EInitFlag::kERROR;
87 }
88 if (!fRecoContainer) {
89 Hal::Cout::PrintInfo("HalCbmV0Builder::Init cannot find reco data", Hal::EInfo::kError);
90 return EInitFlag::kERROR;
91 }
92 fV0Temp = (TClonesArray*) Hal::DataManager::Instance()->GetObject("TempV0.");
93 if (!fV0Temp) {
94 fV0Temp = new TClonesArray("HalCbmV0TempTrack");
95 Hal::DataManager::Instance()->Register("TempV0.", "TempV0", fV0Temp, kFALSE);
96 fOwner = kTRUE;
97 }
98 return EInitFlag::kSUCCESS;
99}
100
101void HalCbmV0Builder::Exec(Option_t* /*option*/)
102{
103 auto recoCont = fRecoContainer->GetVtxTracks();
104 auto recoMatch = fRecoContainer->GetVtx2Sim();
105 auto sim = fSimContainer->GetParticles();
106 int charge_field = fRecoContainer->GetFieldIds().vtx_q;
107 int nv0s = fV0Container->GetParticles()->GetNumberOfChannels();
108 int mother_field = fSimContainer->GetFieldIds().motherId;
109 int ent = 0;
110 if (fOwner) {
111 fV0Temp->Clear("");
112 fV0Temp->ExpandCreateFast(nv0s);
113 }
114 else {
115 ent = fV0Temp->GetEntriesFast();
116 fV0Temp->ExpandCreateFast(ent + nv0s);
117 }
118 for (int i = 0; i < nv0s; i++) {
119 auto particleV0 = fV0Container->GetParticles()->GetChannel(i);
120 auto v0struct = Convert(particleV0);
121 auto dau1 = recoCont->GetChannel(v0struct.dau1id);
122 auto dau2 = recoCont->GetChannel(v0struct.dau2id);
123 int ch1 = dau1.GetField<int>(charge_field);
124 int ch2 = dau2.GetField<int>(charge_field);
125 AnalysisTree::Track daupos = dau1, dauneg = dau2;
126 if (ch1 < 0 && ch2 > 0) { // daughters swap
127 daupos = dau2;
128 dauneg = dau1;
129 int temp = v0struct.dau1id;
130 v0struct.dau1id = v0struct.dau2id;
131 v0struct.dau2id = temp;
132 }
133 auto v0Track = (HalCbmV0TempTrack*) fV0Temp->ConstructedAt(ent + i);
134 v0Track->GetTrack().SetVertexChi2(v0struct.chi2_topo);
135 double e = TMath::Sqrt(v0struct.px * v0struct.px + v0struct.py * v0struct.py + v0struct.pz * v0struct.pz
136 + v0struct.mass * v0struct.mass);
137 v0Track->GetTrack().SetMomentum(v0struct.px, v0struct.py, v0struct.pz, e);
138 v0Track->GetTrack().SetDCA(v0struct.x, v0struct.y, v0struct.z);
139 int field_hit = fRecoContainer->GetFieldIds().vtx_mvdhits;
140 int field_sts = fRecoContainer->GetFieldIds().vtx_nhits;
141 v0Track->GetTrack().SetNMvdHits(daupos.GetField<int>(field_hit) + dauneg.GetField<int>(field_hit));
142 v0Track->GetTrack().SetNStsHits(daupos.GetField<int>(field_sts) + dauneg.GetField<int>(field_sts)
143 - daupos.GetField<int>(field_hit) - dauneg.GetField<int>(field_hit));
144 v0Track->GetV0().SetPdgDaughters(fPidPosDau, fPidNegDau);
145 v0Track->GetV0().SetPosId(v0struct.dau1id);
146 v0Track->GetV0().SetNegId(v0struct.dau2id);
147 v0Track->GetV0().SetDecLenght(v0struct.l);
148 v0Track->GetV0().SetDecDl(v0struct.l_dl);
149 v0Track->GetV0().SetDauDist(v0struct.distance);
150
151#ifdef DEBUG_EXTR
152 v0Track->GetV0().SetMomentumPos(TVector3(v0struct.dau1px, v0struct.dau1py, v0struct.dau1pz));
153 v0Track->GetV0().SetMomentumNeg(TVector3(v0struct.dau2px, v0struct.dau2py, v0struct.dau2pz));
154#else
155 v0Track->GetV0().SetMomentumPos(TVector3(daupos.GetPx(), daupos.GetPy(), daupos.GetPz()));
156 v0Track->GetV0().SetMomentumNeg(TVector3(dauneg.GetPx(), dauneg.GetPy(), dauneg.GetPz()));
157#endif
158 v0Track->GetV0().SetMcId(v0struct.pid);
159 v0Track->SetMcId(-1);
160 //mc matching
161 if (!recoMatch) continue;
162 int mc1 = recoMatch->GetMatchDirect(v0struct.dau1id);
163 int mc2 = recoMatch->GetMatchDirect(v0struct.dau2id);
164 if (fBeFriendly) {
165 if (mc1 >= 0 && mc2 >= 0) {
166 auto mctrack1 = sim->GetChannel(mc1);
167 auto mctrack2 = sim->GetChannel(mc2);
168 int mom1 = mctrack1.GetField<int>(mother_field);
169 v0Track->SetMcId(mom1);
170 }
171 else if (mc1 >= 0) {
172 auto mctrack = sim->GetChannel(mc1);
173 v0Track->SetMcId(mctrack.GetField<int>(mother_field));
174 }
175 else if (mc2 >= 0) {
176 auto mctrack = sim->GetChannel(mc2);
177 v0Track->SetMcId(mctrack.GetField<int>(mother_field));
178 }
179 }
180 else {
181 if (mc1 < 0) continue;
182 if (mc2 < 0) continue;
183 auto mctrack1 = sim->GetChannel(mc1);
184 auto mctrack2 = sim->GetChannel(mc2);
185 int mom1 = mctrack1.GetField<int>(mother_field);
186 int mom2 = mctrack2.GetField<int>(mother_field);
187 if (mom1 == mom2) {
188 v0Track->SetMcId(mom1);
189 }
190 }
191 }
192}
193
int Int_t
CbmAnaTreeV0Container * fV0Container
virtual void Exec(Option_t *option="")
virtual EInitFlag Init()
HalCbmV0Builder(Int_t motherPid=3321, Int_t posdau=2212, Int_t negdau=-211)
TClonesArray * fV0Temp
CbmAnaTreeMcContainer * fSimContainer
CbmAnaTreeRecoContainer * fRecoContainer
v0rawInfo Convert(const AnalysisTree::Particle &p)
TString GetContainerName(TString name)