BOSS 7.1.2
BESIII Offline Software System
Loading...
Searching...
No Matches
VertexFitRefine.cxx
Go to the documentation of this file.
1/* <===<===<===<===<===<===<===<===<===~===>===>===>===>===>===>===>===>===>
2 * File Name: VertexFitRefine.cxx
3 * Author: Hao-Kai SUN
4 * Created: 2021-09-08 Wed 00:15:40 CST
5 * <<=====================================>>
6 * Last Updated: 2023-09-29 Thu 14:35:11 CST
7 * By: Hao-Kai SUN
8 * Update #: 153
9 * ============================== CODES ==============================>>> */
11
12namespace VTXPDGM {
13const double& electron = 0.0005109989461;
14const double& muon = 0.1056583745;
15const double& pion = 0.13957039;
16const double& kaon = 0.493677;
17const double& proton = 0.938272081;
18
19const double empikp[5] = {electron, muon, pion, kaon, proton};
20const double empikp2[5] = {electron * electron, muon* muon, pion* pion,
22} // namespace VTXPDGM
23
24VertexFitRefine* VertexFitRefine::m_instance = nullptr;
25
26// const double VertexFitRefine::beampipe = 3.111;
27const double VertexFitRefine::obeampipe = 3.370; // + 0.0130 * 1;
28// 6.3000 + 0.0130*3 cm inner mdc chamber wall
29// const double VertexFitRefine::innerwall = 6.290 - 0.0130 * 1;
30// const double VertexFitRefine::oinnerwall = 6.425 + 0.0130 * 1;
31
32VertexFitRefine::VertexFitRefine() {}
33
35{
36 if (m_instance == nullptr) m_instance = new VertexFitRefine();
37 return m_instance;
38}
39
41{
42 m_trkIdxOrigin.clear();
43 m_tracksOrigin.clear();
44 m_trkPidOrigin.clear();
45 m_wtrkInfit.clear();
46 m_p4Infit.clear();
47 m_x3Infit.clear();
48 m_helices.clear();
49 vtxfit = VertexFit::instance();
50 vtxfit->init();
52 m_vtxsOrigin.clear();
53 thePath = 0;
54}
55
60
61void VertexFitRefine::AddTrack(const int index, const WTrackParameter wtrk)
62{
63 m_trkIdxOrigin.push_back(index);
64 m_tracksOrigin.push_back(nullptr);
65 m_trkPidOrigin.push_back(RecMdcKalTrack::null);
66 int idx = m_trkIdxOrigin.size() - 1;
67 if (index != idx) {
68 std::cerr << "TrackPool: wrong track index " << index << ", "
69 << m_trkIdxOrigin.size() << std::endl;
70 }
71
72 m_tracksOrigin[idx]->setPidType(m_trkPidOrigin[idx]);
73 m_wtrkInfit.push_back(wtrk);
74 m_helices.push_back(HepVector(5, 0));
75 vtxfit->AddTrack(m_trkIdxOrigin[idx], m_wtrkInfit[idx]);
76}
77
80{
81 m_trkIdxOrigin.push_back(index);
82 m_tracksOrigin.push_back(p);
83 m_trkPidOrigin.push_back(pid);
84 int idx = m_trkIdxOrigin.size() - 1;
85 if (index != idx) {
86 std::cerr << "TrackPool: wrong track index " << index << ", "
87 << m_trkIdxOrigin.size() << std::endl;
88 }
89
90 m_tracksOrigin[idx]->setPidType(m_trkPidOrigin[idx]);
91 m_wtrkInfit.push_back(WTrackParameter(VTXPDGM::empikp[m_trkPidOrigin[idx]],
92 m_tracksOrigin[idx]->helix(),
93 m_tracksOrigin[idx]->err()));
94 vtxfit->AddTrack(m_trkIdxOrigin[idx], m_wtrkInfit[idx]);
95}
96
98{
99 HepPoint3D vx(0.0, 0.0, 0.0);
100
101 for (uint i = 0; i != m_trkIdxOrigin.size(); ++i) {
102 m_p4Infit.push_back(m_wtrkInfit[i].p());
103 m_x3Infit.push_back(m_wtrkInfit[i].x());
104 }
105
106 //// setup the initial vertex
107 HepPoint3D vWideVertex(0., 0., 0.);
108
109 HepSymMatrix evWideVertex(3, 0);
110 evWideVertex[0][0] = 1.0E12;
111 evWideVertex[1][1] = 1.0E12;
112 evWideVertex[2][2] = 1.0E12;
113
114 VertexParameter wideVertex;
115 wideVertex.setVx(vWideVertex);
116 wideVertex.setEvx(evWideVertex);
117
118 if (vtxfit->m_vpar_infit.size() == 0) {
119 std::cerr << "Not set Vertex?" << std::endl;
120 return false;
121 }
122
123 HepPoint3D ZDP = vtxfit->vx(0);
124 HepPoint3D ZDPE = HepPoint3D(9999.9, 9999.9, 9999.9);
125 bool ZFit = false;
126 HepVector ZVx = vtxfit->Vx(0);
127 HepSymMatrix ZEVx = evWideVertex;
128
129 //// do the fit
130 if (vtxfit->Fit(0)) {
131 vtxfit->Swim(0);
132 vtxfit->BuildVirtualParticle(0);
133
134 for (uint i = 0; i != m_trkIdxOrigin.size(); ++i) {
135 m_p4Infit[i] = vtxfit->pfit(i);
136 m_x3Infit[i] = vtxfit->xfit(i);
137 }
138
139 ZDP = vtxfit->vx(0);
140 ZVx = vtxfit->Vx(0);
141 ZEVx = vtxfit->Evx(0);
142 ZDPE.set(vtxfit->errorVx(0, 0), vtxfit->errorVx(0, 1),
143 vtxfit->errorVx(0, 2));
144 ZFit = true;
145 }
146
147 if (ZFit) {
148 if (ZDP.perp() > obeampipe) {
149 //// initialize the fitter
150 vtxfit->init();
151
152 for (uint i = 0; i != m_trkIdxOrigin.size(); ++i) {
153 m_tracksOrigin[i]->setPidType(m_trkPidOrigin[i]);
154 if (m_trkPidOrigin[i] != RecMdcKalTrack::null) {
155 m_wtrkInfit[i] = WTrackParameter(
156 VTXPDGM::empikp[m_trkPidOrigin[i]],
157 m_tracksOrigin[i]->fhelix(), m_tracksOrigin[i]->ferr());
158 }
159 vtxfit->AddTrack(i, m_wtrkInfit[i]);
160 }
161
162 wideVertex.setVx(ZVx);
163 // wideVertex.setEvx(ZEVx * 25.0); // 5 * sigma square, not good
164 wideVertex.setEvx(evWideVertex);
165
166 //// add the daughters
167 vtxfit->AddVertex(0, wideVertex, m_trkIdxOrigin);
168 //// do the fit
169 if (vtxfit->Fit(0)) {
170 vtxfit->Swim(0);
171 vtxfit->BuildVirtualParticle(0);
172 vx = vtxfit->vx(0);
173 ZVx = vtxfit->Vx(0);
174 ZEVx = vtxfit->Evx(0);
175 thePath = 3;
176 } else {
177 vx = ZDP;
178 thePath = 2;
179 }
180 } else {
181 vx = ZDP;
182 thePath = 1;
183 }
184 } else { // initial ZFit failed.
185 //// initialize the fitter
186 vtxfit->init();
187
188 for (uint i = 0; i != m_trkIdxOrigin.size(); ++i) {
189 m_tracksOrigin[i]->setPidType(m_trkPidOrigin[i]);
190 if (m_trkPidOrigin[i] != RecMdcKalTrack::null) {
191 m_wtrkInfit[i] = WTrackParameter(
192 VTXPDGM::empikp[m_trkPidOrigin[i]],
193 m_tracksOrigin[i]->fhelix(), m_tracksOrigin[i]->ferr());
194 }
195 vtxfit->AddTrack(i, m_wtrkInfit[i]);
196 }
197
198 if (vtxfit->Fit(0)) {
199 vtxfit->Swim(0);
200 vtxfit->BuildVirtualParticle(0);
201 vx = vtxfit->vx(0);
202 ZVx = vtxfit->Vx(0);
203 ZEVx = vtxfit->Evx(0);
204 thePath = 4;
205 } else {
206 thePath = 5;
207 return false;
208 }
209 }
210 //// initialize the fitter
211 vtxfit->init();
212
213 for (uint i = 0; i != m_trkIdxOrigin.size(); ++i) {
214 m_tracksOrigin[i]->setPidType(m_trkPidOrigin[i]);
215 if (m_trkPidOrigin[i] != RecMdcKalTrack::null) {
216 vtxext->KalFitExt(vx, m_tracksOrigin[i], m_trkPidOrigin[i]);
217 m_wtrkInfit[i] = WTrackParameter(VTXPDGM::empikp[m_trkPidOrigin[i]],
218 vtxext->getHelixVector(),
219 vtxext->getErrorMatrix());
220 }
221 m_p4Infit[i] = m_wtrkInfit[i].p();
222 m_x3Infit[i] = m_wtrkInfit[i].x();
223
224 vtxfit->AddTrack(i, m_wtrkInfit[i]);
225 }
226
227 wideVertex.setVx(vx);
228 // wideVertex.setEvx(ZEVx * 25.0); // 5 * sigma square, not good, why?
229 wideVertex.setEvx(evWideVertex);
230 //// add the daughters
231 vtxfit->AddVertex(0, wideVertex, m_trkIdxOrigin);
232
233 //// do the fit
234 if (vtxfit->Fit(0)) {
235 vtxfit->Swim(0);
236 vtxfit->BuildVirtualParticle(0);
237 } else {
238 thePath = 6;
239 }
240
241 return true;
242}
243
244/* ===================================================================<<< */
245/* =================== VertexFitRefine.cxx ends here ==================== */
Double_t x[10]
HepGeom::Point3D< double > HepPoint3D
Definition Gam4pikp.cxx:37
void AddTrack(const int number, const double mass, const RecMdcTrack *trk)
Definition TrackPool.cxx:22
void KalFitExt(const HepPoint3D &point, DstMdcKalTrack *kalTrack, const int pid)
const HepVector getHelixVector() const
static VertexExtrapolate * instance()
const HepSymMatrix getErrorMatrix() const
void AddTrack(const int index, RecMdcKalTrack *p, const RecMdcKalTrack::PidType pid)
WTrackParameter wtrk(int n) const
static VertexFitRefine * instance()
HepVector helix(int n) const
HepPoint3D vx(int n) const
HepVector Vx(int n) const
Definition VertexFit.h:86
void init()
Definition VertexFit.cxx:29
void AddVertex(int number, VertexParameter vpar, std::vector< int > lis)
Definition VertexFit.cxx:89
HepSymMatrix Evx(int n) const
Definition VertexFit.h:87
HepPoint3D vx(int n) const
Definition VertexFit.h:85
HepLorentzVector pfit(int n) const
Definition VertexFit.h:75
HepPoint3D xfit(int n) const
Definition VertexFit.h:76
static VertexFit * instance()
Definition VertexFit.cxx:15
void BuildVirtualParticle(int number)
void Swim(int n)
Definition VertexFit.h:59
bool Fit()
double errorVx(int n, int i) const
Definition VertexFit.h:88
void setEvx(const HepSymMatrix &eVx)
void setVx(const HepPoint3D &vx)
const double & electron
const double & muon
const double & kaon
const double empikp[5]
const double & pion
const double empikp2[5]
const double & proton