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