BOSS 7.1.0
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: 2022-01-06 Thu 13:33:25 CST
7 * By: Hao-Kai SUN
8 * Update #: 149
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 vtxfit = VertexFit::instance();
49 vtxfit->init();
51 m_vtxsOrigin.clear();
52 thePath = 0;
53}
54
56{
57 vtxfit->init();
58}
59
60void VertexFitRefine::AddTrack(const int index, const WTrackParameter wtrk)
61{
62 m_trkIdxOrigin.push_back(index);
63 m_tracksOrigin.push_back(nullptr);
64 m_trkPidOrigin.push_back(RecMdcKalTrack::null);
65 int idx = m_trkIdxOrigin.size() - 1;
66 if (index != idx) {
67 std::cerr << "TrackPool: wrong track index " << index << ", "
68 << m_trkIdxOrigin.size() << std::endl;
69 }
70
71 m_tracksOrigin[idx]->setPidType(m_trkPidOrigin[idx]);
72 m_wtrkInfit.push_back(wtrk);
73 vtxfit->AddTrack(m_trkIdxOrigin[idx], m_wtrkInfit[idx]);
74}
75
78{
79 m_trkIdxOrigin.push_back(index);
80 m_tracksOrigin.push_back(p);
81 m_trkPidOrigin.push_back(pid);
82 int idx = m_trkIdxOrigin.size() - 1;
83 if (index != idx) {
84 std::cerr << "TrackPool: wrong track index " << index << ", "
85 << m_trkIdxOrigin.size() << std::endl;
86 }
87
88 m_tracksOrigin[idx]->setPidType(m_trkPidOrigin[idx]);
89 m_wtrkInfit.push_back(WTrackParameter(VTXPDGM::empikp[m_trkPidOrigin[idx]],
90 m_tracksOrigin[idx]->helix(),
91 m_tracksOrigin[idx]->err()));
92 vtxfit->AddTrack(m_trkIdxOrigin[idx], m_wtrkInfit[idx]);
93}
94
96{
97 HepPoint3D vx(0.0, 0.0, 0.0);
98
99 for (uint i = 0; i != m_trkIdxOrigin.size(); ++i) {
100 m_p4Infit.push_back(m_wtrkInfit[i].p());
101 m_x3Infit.push_back(m_wtrkInfit[i].x());
102 }
103
104 //// setup the initial vertex
105 HepPoint3D vWideVertex(0., 0., 0.);
106
107 HepSymMatrix evWideVertex(3, 0);
108 evWideVertex[0][0] = 1.0E12;
109 evWideVertex[1][1] = 1.0E12;
110 evWideVertex[2][2] = 1.0E12;
111
112 VertexParameter wideVertex;
113 wideVertex.setVx(vWideVertex);
114 wideVertex.setEvx(evWideVertex);
115
116 if (vtxfit->m_vpar_infit.size() == 0) {
117 std::cerr << "Not set Vertex?" << std::endl;
118 return false;
119 }
120
121 HepPoint3D ZDP = vtxfit->vx(0);
122 HepPoint3D ZDPE = HepPoint3D(9999.9, 9999.9, 9999.9);
123 bool ZFit = false;
124 HepVector ZVx = vtxfit->Vx(0);
125 HepSymMatrix ZEVx = evWideVertex;
126
127 //// do the fit
128 if (vtxfit->Fit(0)) {
129 vtxfit->Swim(0);
130 vtxfit->BuildVirtualParticle(0);
131
132 for (uint i = 0; i != m_trkIdxOrigin.size(); ++i) {
133 m_p4Infit[i] = vtxfit->pfit(i);
134 m_x3Infit[i] = vtxfit->xfit(i);
135 }
136
137 ZDP = vtxfit->vx(0);
138 ZVx = vtxfit->Vx(0);
139 ZEVx = vtxfit->Evx(0);
140 ZDPE.set(vtxfit->errorVx(0, 0), vtxfit->errorVx(0, 1),
141 vtxfit->errorVx(0, 2));
142 ZFit = true;
143 }
144
145 if (ZFit) {
146 if (ZDP.perp() > obeampipe) {
147 //// initialize the fitter
148 vtxfit->init();
149
150 for (uint i = 0; i != m_trkIdxOrigin.size(); ++i) {
151 m_tracksOrigin[i]->setPidType(m_trkPidOrigin[i]);
152 if (m_trkPidOrigin[i] != RecMdcKalTrack::null) {
153 m_wtrkInfit[i] = WTrackParameter(
154 VTXPDGM::empikp[m_trkPidOrigin[i]],
155 m_tracksOrigin[i]->fhelix(), m_tracksOrigin[i]->ferr());
156 }
157 vtxfit->AddTrack(i, m_wtrkInfit[i]);
158 }
159
160 wideVertex.setVx(ZVx);
161 // wideVertex.setEvx(ZEVx * 25.0); // 5 * sigma square, not good
162 wideVertex.setEvx(evWideVertex);
163
164 //// add the daughters
165 vtxfit->AddVertex(0, wideVertex, m_trkIdxOrigin);
166 //// do the fit
167 if (vtxfit->Fit(0)) {
168 vtxfit->Swim(0);
169 vtxfit->BuildVirtualParticle(0);
170 vx = vtxfit->vx(0);
171 ZVx = vtxfit->Vx(0);
172 ZEVx = vtxfit->Evx(0);
173 thePath = 3;
174 } else {
175 vx = ZDP;
176 thePath = 2;
177 }
178 } else {
179 vx = ZDP;
180 thePath = 1;
181 }
182 } else { // initial ZFit failed.
183 //// initialize the fitter
184 vtxfit->init();
185
186 for (uint i = 0; i != m_trkIdxOrigin.size(); ++i) {
187 m_tracksOrigin[i]->setPidType(m_trkPidOrigin[i]);
188 if (m_trkPidOrigin[i] != RecMdcKalTrack::null) {
189 m_wtrkInfit[i] = WTrackParameter(
190 VTXPDGM::empikp[m_trkPidOrigin[i]],
191 m_tracksOrigin[i]->fhelix(), m_tracksOrigin[i]->ferr());
192 }
193 vtxfit->AddTrack(i, m_wtrkInfit[i]);
194 }
195
196 if (vtxfit->Fit(0)) {
197 vtxfit->Swim(0);
198 vtxfit->BuildVirtualParticle(0);
199 vx = vtxfit->vx(0);
200 ZVx = vtxfit->Vx(0);
201 ZEVx = vtxfit->Evx(0);
202 thePath = 4;
203 } else {
204 thePath = 5;
205 return false;
206 }
207 }
208 //// initialize the fitter
209 vtxfit->init();
210
211 for (uint i = 0; i != m_trkIdxOrigin.size(); ++i) {
212 m_tracksOrigin[i]->setPidType(m_trkPidOrigin[i]);
213 if (m_trkPidOrigin[i] != RecMdcKalTrack::null) {
214 vtxext->KalFitExt(vx, m_tracksOrigin[i], m_trkPidOrigin[i]);
215 m_wtrkInfit[i] = WTrackParameter(VTXPDGM::empikp[m_trkPidOrigin[i]],
216 vtxext->getHelixVector(),
217 vtxext->getErrorMatrix());
218 }
219 m_p4Infit[i] = m_wtrkInfit[i].p();
220 m_x3Infit[i] = m_wtrkInfit[i].x();
221
222 vtxfit->AddTrack(i, m_wtrkInfit[i]);
223 }
224
225 wideVertex.setVx(vx);
226 // wideVertex.setEvx(ZEVx * 25.0); // 5 * sigma square, not good, why?
227 wideVertex.setEvx(evWideVertex);
228 //// add the daughters
229 vtxfit->AddVertex(0, wideVertex, m_trkIdxOrigin);
230
231 //// do the fit
232 if (vtxfit->Fit(0)) {
233 vtxfit->Swim(0);
234 vtxfit->BuildVirtualParticle(0);
235 } else {
236 thePath = 6;
237 }
238
239 return true;
240}
241
242/* ===================================================================<<< */
243/* =================== 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()
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)
Definition: VertexFit.cxx:619
void Swim(int n)
Definition: VertexFit.h:59
bool Fit()
Definition: VertexFit.cxx:301
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