BOSS 8.0.0
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 ==============================>>> */
10#include "VertexFitRefine/VertexExtrapolate.h"
11
12#include "G4Geo/BesG4Geo.h"
13#include "G4Geo/MdcG4Geo.h"
14#include "KalFitAlg/KalFitTrack.h"
15
16#include "GaudiKernel/Bootstrap.h"
17#include "GaudiKernel/ISvcLocator.h"
18
19#include "MagneticFieldSvc/IBesMagFieldSvc.h"
20
21static const char* matNames[9] = {
22 "MDCGas", "LogicalMdcInnerFilm1", "logicalMdcSegment2", "LogicalMdcInnerFilm0",
23 "logicalWorld", "logicalouterBe", "logicaloilLayer", "logicalinnerBe",
24 "logicalgoldLayer" };
25
26VertexExtrapolate* VertexExtrapolate::m_instance = nullptr;
27
28VertexExtrapolate* VertexExtrapolate::instance() {
29 if ( m_instance == nullptr ) m_instance = new VertexExtrapolate();
30 return m_instance;
31}
32
33VertexExtrapolate::VertexExtrapolate() {
34 m_BesKalmanExtMaterials.clear();
35 m_BesKalmanExtWalls.clear();
36
37 constructWallsFromGdml();
38
39 m_helixVector = CLHEP::Hep3Vector( 5, 0 );
40 m_errorMatrix = CLHEP::HepSymMatrix( 5, 0 );
41
42 ISvcLocator* svcLocator = Gaudi::svcLocator();
43
44 IBesMagFieldSvc* IMFSvc = nullptr;
45
46 StatusCode sc = svcLocator->service( "MagneticFieldSvc", IMFSvc );
47 if ( sc.isFailure() )
48 { std::cerr << MSG::ERROR << "Unable to open Magnetic field service" << std::endl; }
49 KalFitTrack::numf_ = 21; // ???
53 KalFitTrack::Bznom_ = -10.; // ???
54}
55
56void VertexExtrapolate::G4MtovKalFitM( G4Material* g4m, const std::string& name ) {
57 double Z = 0.0;
58 double A = 0.0;
59 for ( unsigned i = 0; i != g4m->GetElementVector()->size(); ++i )
60 {
61 Z += ( g4m->GetElement( i )->GetZ() ) * ( g4m->GetFractionVector()[i] );
62 A += ( g4m->GetElement( i )->GetA() ) * ( g4m->GetFractionVector()[i] );
63 }
64 double Ionization = g4m->GetIonisation()->GetMeanExcitationEnergy();
65 double Density = g4m->GetDensity() / ( g / cm3 );
66 double Radlen = g4m->GetRadlen();
67 std::cout << " " << name << ": Z: " << Z << " A: " << ( A / ( g / mole ) )
68 << " Ionization: " << ( Ionization / eV ) << " Density: " << Density
69 << " Radlen: " << Radlen << std::endl;
70 KalFitMaterial FitMdcMaterial( Z, A / g / mole, Ionization / eV, Density, Radlen / 10. );
71 m_BesKalmanExtMaterials.push_back( FitMdcMaterial );
72}
73
74void VertexExtrapolate::AddWalls( int index, double radius, double thick, double length,
75 double z0 ) {
76 std::cout << " " << matNames[index] << ": radius: " << radius << ", thick: " << thick
77 << ", length: " << length << std::endl;
78
79 KalFitMaterial& tmp = m_BesKalmanExtMaterials[index];
80 KalFitCylinder innerwallCylinder( &tmp, radius, thick, length, z0 );
81 m_BesKalmanExtWalls.push_back( innerwallCylinder );
82}
83
84void VertexExtrapolate::AddWalls( int index ) {
85 G4Tubs* g4t = getTubs( matNames[index] );
86 double radius = g4t->GetInnerRadius() / ( cm );
87 double thick = g4t->GetOuterRadius() / (cm)-g4t->GetInnerRadius() / ( cm );
88 double length = 2.0 * g4t->GetZHalfLength() / ( cm );
89 double z0 = 0.0;
90
91 AddWalls( index, radius, thick, length, z0 );
92}
93
94void VertexExtrapolate::testMW( int index ) {
95 KalFitMaterial m = m_BesKalmanExtMaterials[index];
96 KalFitCylinder w = m_BesKalmanExtWalls[index];
97 std::cout << index << " ==========================" << std::endl;
98 std::cout << "TEST==Radlen: " << m.X0() << std::endl;
99 std::cout << "TEST==Radlen: " << w.material().X0() << " radius: " << w.radius()
100 << std::endl;
101}
102
103void VertexExtrapolate::constructWallsFromGdml( void ) {
104 /// mdcgas
105 G4LogicalVolume* logicalMdc = 0;
106 MdcG4Geo* aMdcG4Geo = new MdcG4Geo();
107 logicalMdc = aMdcG4Geo->GetTopVolume();
108 G4Material* mat = logicalMdc->GetMaterial();
109 KalFitTrack::mdcGasRadlen_ = mat->GetRadlen() / 10.;
110 G4MtovKalFitM( mat, "MDCGas" );
111
112 BesG4Geo* aBesG4Geo = new BesG4Geo();
113 // G4LogicalVolume* logicalBes = aBesG4Geo->GetTopVolume();
114
115 for ( int i = 1; i != 9; ++i )
116 {
117 G4LogicalVolume* logicalAirVolume = const_cast<G4LogicalVolume*>(
118 GDMLProcessor::GetInstance()->GetLogicalVolume( matNames[i] ) );
119 mat = logicalAirVolume->GetMaterial();
120 G4MtovKalFitM( mat, matNames[i] );
121 }
122 delete aMdcG4Geo;
123 delete aBesG4Geo;
124 for ( int i = 1; i != 4; ++i ) AddWalls( i );
125
126 /// air cylinder is special
127 G4Tubs* innerwallTub = getTubs( "LogicalMdcInnerFilm0" );
128 G4Tubs* outerBeTub = getTubs( "logicalouterBe" );
129 double radius = outerBeTub->GetOuterRadius() / ( cm );
130 double thick = innerwallTub->GetInnerRadius() / (cm)-outerBeTub->GetOuterRadius() / ( cm );
131 double length = 2.0 * innerwallTub->GetZHalfLength() / ( cm );
132 double z0 = 0.0;
133 AddWalls( 4, radius, thick, length, z0 );
134
135 for ( int i = 5; i != 9; ++i ) AddWalls( i );
136
137 /// the air in the innermost of the pipe
138 G4Tubs* goldLayerTub = getTubs( "logicalgoldLayer" );
139 radius = 0.;
140 thick = goldLayerTub->GetInnerRadius() / ( cm );
141 length = 2.0 * goldLayerTub->GetZHalfLength() / ( cm );
142 z0 = 0.0;
143 AddWalls( 4, radius, thick, length, z0 );
144 // // debug
145 // for (int i = 0; i < 9; ++i)
146 // testMW(i);
147}
148
149int VertexExtrapolate::getWallMdcNumber( const HepPoint3D& point ) const {
150 int i = m_BesKalmanExtWalls.size() - 1;
151 for ( ; i != -1; --i )
152 if ( m_BesKalmanExtWalls[i].isInside2( point ) ) break;
153
154 return i;
155}
156
157void VertexExtrapolate::extToAnyPoint( KalFitTrack& track, const HepPoint3D& point ) {
158 const int index = getWallMdcNumber( point );
159
160 // outside the inner MDC wall Film1
161 if ( index == -1 ) return;
162 // in the innermost pipe
163 if ( index > 0 )
164 {
165 for ( int j = 0; j < index; j++ ) m_BesKalmanExtWalls[j].updateTrack( track, 1 );
166 }
167 int size = m_BesKalmanExtWalls.size() - 1;
168 if ( index != size )
169 {
170 const KalFitMaterial& material = m_BesKalmanExtWalls[index].material();
172
173 double path = m_BesKalmanExtWalls[index].intersect( track, x, point );
174
175 if ( path > 0 )
176 {
177 // move pivot
178 track.pivot_numf( x );
179 // multiple scattering and energy loss
180 int index_element( index );
181 if ( index_element == 0 ) index_element = 1;
182 track.ms( path, material, index_element );
183 track.eloss( path, material, index_element );
184 }
185 }
186}
187
189 const int pid ) {
190 HepVector tdsHelix = kalTrack->getFHelix( pid );
191 HepSymMatrix tdsMatrix = kalTrack->getFError( pid );
192
193 HepPoint3D IP( 0., 0., 0. );
194 // construct a KalFitTrack
195 KalFitTrack fitTrack( IP, tdsHelix, tdsMatrix, pid, 0, 0 );
196
197 // const double radius = 7.885; // centimeter first MDC wire?
198 const double rp = point.perp();
199 // const double radius = m_BesKalmanExtWalls[m_BesKalmanExtWalls.size() - 1]
200 // .radius(); // outer radius
201 const double radius = m_BesKalmanExtWalls[0].radius(); // outer radius
202 const double dphi = fitTrack.intersect_cylinder( std::max( rp, radius ) );
203 const HepPoint3D lastPivot = fitTrack.x( dphi );
204 fitTrack.pivot( lastPivot );
205 if ( rp <= radius ) extToAnyPoint( fitTrack, point );
206
207 ///////// why pivot to IP? ///////
208 // // set the pivot back to IP
209 fitTrack.pivot( IP ); // for convention?
210 setHelixVector( fitTrack.a() );
211 setErrorMatrix( fitTrack.Ea() );
212}
213/* ===================================================================<<< */
214/* ================== VertexExtrapolate.cxx ends here =================== */
HepGeom::Point3D< double > HepPoint3D
Double_t x[10]
double w
const HepSymMatrix & getFError(const int pid) const
const HepVector & getFHelix(const int pid) const
static int muls(void)
static int loss(void)
Description of a track class (<- Helix.cc).
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.
void eloss(double path, const KalFitMaterial &m, int index)
Calculate total energy lost in material.
static void setMagneticFieldSvc(IBesMagFieldSvc *)
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()