BOSS 7.1.1
BESIII Offline Software System
Loading...
Searching...
No Matches
VertexExtrapolate.cxx
Go to the documentation of this file.
1/* <===<===<===<===<===<===<===<===<===~===>===>===>===>===>===>===>===>===>
2 * File Name: VertexExtrapolate.cxx
3 * Author: Hao-Kai SUN
4 * Created: 2021-09-06 Mon 18:05:16 CST
5 * <<=====================================>>
6 * Last Updated: 2023-09-29 Thu 14:24:20 CST
7 * By: Hao-Kai SUN
8 * Update #: 213
9 * ============================== CODES ==============================>>> */
11
12#include "G4Geo/BesG4Geo.h"
13#include "G4Geo/MdcG4Geo.h"
15
16#include "GaudiKernel/Bootstrap.h"
17#include "GaudiKernel/ISvcLocator.h"
18
20
21static const char* matNames[9] = {"MDCGas",
22 "LogicalMdcInnerFilm1",
23 "logicalMdcSegment2",
24 "LogicalMdcInnerFilm0",
25 "logicalWorld",
26 "logicalouterBe",
27 "logicaloilLayer",
28 "logicalinnerBe",
29 "logicalgoldLayer"};
30
31VertexExtrapolate* VertexExtrapolate::m_instance = nullptr;
32
34{
35 if (m_instance == nullptr) m_instance = new VertexExtrapolate();
36 return m_instance;
37}
38
39VertexExtrapolate::VertexExtrapolate()
40{
41 m_BesKalmanExtMaterials.clear();
42 m_BesKalmanExtWalls.clear();
43
44 constructWallsFromGdml();
45
46 m_helixVector = CLHEP::Hep3Vector(5, 0);
47 m_errorMatrix = CLHEP::HepSymMatrix(5, 0);
48
49 ISvcLocator* svcLocator = Gaudi::svcLocator();
50
51 IMagneticFieldSvc* IMFSvc = nullptr;
52
53 StatusCode sc = svcLocator->service("MagneticFieldSvc", IMFSvc);
54 if (sc.isFailure()) {
55 std::cerr << MSG::ERROR << "Unable to open Magnetic field service"
56 << std::endl;
57 }
58 KalFitTrack::numf_ = 21; // ???
62 KalFitTrack::Bznom_ = -10.; // ???
63}
64
65void VertexExtrapolate::G4MtovKalFitM(G4Material* g4m, const std::string& name)
66{
67 double Z = 0.0;
68 double A = 0.0;
69 for (unsigned i = 0; i != g4m->GetElementVector()->size(); ++i) {
70 Z += (g4m->GetElement(i)->GetZ()) * (g4m->GetFractionVector()[i]);
71 A += (g4m->GetElement(i)->GetA()) * (g4m->GetFractionVector()[i]);
72 }
73 double Ionization = g4m->GetIonisation()->GetMeanExcitationEnergy();
74 double Density = g4m->GetDensity() / (g / cm3);
75 double Radlen = g4m->GetRadlen();
76 std::cout << " " << name << ": Z: " << Z << " A: " << (A / (g / mole))
77 << " Ionization: " << (Ionization / eV) << " Density: " << Density
78 << " Radlen: " << Radlen << std::endl;
79 KalFitMaterial FitMdcMaterial(Z, A / g / mole, Ionization / eV, Density,
80 Radlen / 10.);
81 m_BesKalmanExtMaterials.push_back(FitMdcMaterial);
82}
83
84void VertexExtrapolate::AddWalls(int index, double radius, double thick,
85 double length, double z0)
86{
87 std::cout << " " << matNames[index] << ": radius: " << radius
88 << ", thick: " << thick << ", length: " << length << std::endl;
89
90 KalFitMaterial& tmp = m_BesKalmanExtMaterials[index];
91 KalFitCylinder innerwallCylinder(&tmp, radius, thick, length, z0);
92 m_BesKalmanExtWalls.push_back(innerwallCylinder);
93}
94
95void VertexExtrapolate::AddWalls(int index)
96{
97 G4Tubs* g4t = getTubs(matNames[index]);
98 double radius = g4t->GetInnerRadius() / (cm);
99 double thick = g4t->GetOuterRadius() / (cm)-g4t->GetInnerRadius() / (cm);
100 double length = 2.0 * g4t->GetZHalfLength() / (cm);
101 double z0 = 0.0;
102
103 AddWalls(index, radius, thick, length, z0);
104}
105
106void VertexExtrapolate::testMW(int index)
107{
108 KalFitMaterial m = m_BesKalmanExtMaterials[index];
109 KalFitCylinder w = m_BesKalmanExtWalls[index];
110 std::cout << index << " ==========================" << std::endl;
111 std::cout << "TEST==Radlen: " << m.X0() << std::endl;
112 std::cout << "TEST==Radlen: " << w.material().X0()
113 << " radius: " << w.radius() << std::endl;
114}
115
116void VertexExtrapolate::constructWallsFromGdml(void)
117{
118 /// mdcgas
119 G4LogicalVolume* logicalMdc = 0;
120 MdcG4Geo* aMdcG4Geo = new MdcG4Geo();
121 logicalMdc = aMdcG4Geo->GetTopVolume();
122 G4Material* mat = logicalMdc->GetMaterial();
123 KalFitTrack::mdcGasRadlen_ = mat->GetRadlen() / 10.;
124 G4MtovKalFitM(mat, "MDCGas");
125
126 BesG4Geo* aBesG4Geo = new BesG4Geo();
127 // G4LogicalVolume* logicalBes = aBesG4Geo->GetTopVolume();
128
129 for (int i = 1; i != 9; ++i) {
130 G4LogicalVolume* logicalAirVolume = const_cast<G4LogicalVolume*>(
131 GDMLProcessor::GetInstance()->GetLogicalVolume(matNames[i]));
132 mat = logicalAirVolume->GetMaterial();
133 G4MtovKalFitM(mat, matNames[i]);
134 }
135 delete aMdcG4Geo;
136 delete aBesG4Geo;
137 for (int i = 1; i != 4; ++i)
138 AddWalls(i);
139
140 /// air cylinder is special
141 G4Tubs* innerwallTub = getTubs("LogicalMdcInnerFilm0");
142 G4Tubs* outerBeTub = getTubs("logicalouterBe");
143 double radius = outerBeTub->GetOuterRadius() / (cm);
144 double thick = innerwallTub->GetInnerRadius() /
145 (cm)-outerBeTub->GetOuterRadius() / (cm);
146 double length = 2.0 * innerwallTub->GetZHalfLength() / (cm);
147 double z0 = 0.0;
148 AddWalls(4, radius, thick, length, z0);
149
150 for (int i = 5; i != 9; ++i)
151 AddWalls(i);
152
153 /// the air in the innermost of the pipe
154 G4Tubs* goldLayerTub = getTubs("logicalgoldLayer");
155 radius = 0.;
156 thick = goldLayerTub->GetInnerRadius() / (cm);
157 length = 2.0 * goldLayerTub->GetZHalfLength() / (cm);
158 z0 = 0.0;
159 AddWalls(4, radius, thick, length, z0);
160 // // debug
161 // for (int i = 0; i < 9; ++i)
162 // testMW(i);
163}
164
165int VertexExtrapolate::getWallMdcNumber(const HepPoint3D& point) const
166{
167 int i = m_BesKalmanExtWalls.size() - 1;
168 for (; i != -1; --i)
169 if (m_BesKalmanExtWalls[i].isInside2(point)) break;
170
171 return i;
172}
173
174void VertexExtrapolate::extToAnyPoint(KalFitTrack& track,
175 const HepPoint3D& point)
176{
177 const int index = getWallMdcNumber(point);
178
179 // outside the inner MDC wall Film1
180 if (index == -1) return;
181 // in the innermost pipe
182 if (index > 0) {
183 for (int j = 0; j < index; j++)
184 m_BesKalmanExtWalls[j].updateTrack(track, 1);
185 }
186 int size = m_BesKalmanExtWalls.size() - 1;
187 if (index != size) {
188 const KalFitMaterial& material = m_BesKalmanExtWalls[index].material();
190
191 double path = m_BesKalmanExtWalls[index].intersect(track, x, point);
192
193 if (path > 0) {
194 // move pivot
195 track.pivot_numf(x);
196 // multiple scattering and energy loss
197 int index_element(index);
198 if (index_element == 0) index_element = 1;
199 track.ms(path, material, index_element);
200 track.eloss(path, material, index_element);
201 }
202 }
203}
204
206 DstMdcKalTrack* kalTrack, const int pid)
207{
208 HepVector tdsHelix = kalTrack->getFHelix(pid);
209 HepSymMatrix tdsMatrix = kalTrack->getFError(pid);
210
211 HepPoint3D IP(0., 0., 0.);
212 // construct a KalFitTrack
213 KalFitTrack fitTrack(IP, tdsHelix, tdsMatrix, pid, 0, 0);
214
215 // const double radius = 7.885; // centimeter first MDC wire?
216 const double rp = point.perp();
217 // const double radius = m_BesKalmanExtWalls[m_BesKalmanExtWalls.size() - 1]
218 // .radius(); // outer radius
219 const double radius = m_BesKalmanExtWalls[0].radius(); // outer radius
220 const double dphi = fitTrack.intersect_cylinder(std::max(rp, radius));
221 const HepPoint3D lastPivot = fitTrack.x(dphi);
222 fitTrack.pivot(lastPivot);
223 if (rp <= radius) extToAnyPoint(fitTrack, point);
224
225 ///////// why pivot to IP? ///////
226 // // set the pivot back to IP
227 fitTrack.pivot(IP); // for convention?
228 setHelixVector(fitTrack.a());
229 setErrorMatrix(fitTrack.Ea());
230}
231/* ===================================================================<<< */
232/* ================== VertexExtrapolate.cxx ends here =================== */
Double_t x[10]
double w
const HepSymMatrix & getFError(const int pid) const
const HepVector & getFHelix(const int pid) const
Cylinder is an Element whose shape is a cylinder.
static int muls(void)
static int loss(void)
double X0(void) const
Extractor.
Description of a track class (<- Helix.cc)
Definition KalFitTrack.h:35
static double Bznom_
const HepPoint3D & pivot_numf(const HepPoint3D &newPivot)
Sets pivot position in a given mag field.
void ms(double path, const KalFitMaterial &m, int index)
double intersect_cylinder(double r) const
Intersection with different geometry.
static int numf_
Flag for treatment of non-uniform mag field.
static double mdcGasRadlen_
void eloss(double path, const KalFitMaterial &m, int index)
Calculate total energy lost in material.
static void setMagneticFieldSvc(IMagneticFieldSvc *)
const HepSymMatrix & Ea(void) const
returns error matrix.
HepPoint3D x(double dPhi=0.) const
returns position after rotating angle dPhi in phi direction.
const HepVector & a(void) const
returns helix parameters.
const HepPoint3D & pivot(void) const
returns pivot position.
G4LogicalVolume * GetTopVolume()
Get the top(world) volume;.
void KalFitExt(const HepPoint3D &point, DstMdcKalTrack *kalTrack, const int pid)
static VertexExtrapolate * instance()