10#include "VertexFitRefine/VertexExtrapolate.h"
12#include "G4Geo/BesG4Geo.h"
13#include "G4Geo/MdcG4Geo.h"
14#include "KalFitAlg/KalFitTrack.h"
16#include "GaudiKernel/Bootstrap.h"
17#include "GaudiKernel/ISvcLocator.h"
19#include "MagneticFieldSvc/IBesMagFieldSvc.h"
21static const char* matNames[9] = {
22 "MDCGas",
"LogicalMdcInnerFilm1",
"logicalMdcSegment2",
"LogicalMdcInnerFilm0",
23 "logicalWorld",
"logicalouterBe",
"logicaloilLayer",
"logicalinnerBe",
29 if ( m_instance ==
nullptr ) m_instance =
new VertexExtrapolate();
33VertexExtrapolate::VertexExtrapolate() {
34 m_BesKalmanExtMaterials.clear();
35 m_BesKalmanExtWalls.clear();
37 constructWallsFromGdml();
39 m_helixVector = CLHEP::Hep3Vector( 5, 0 );
40 m_errorMatrix = CLHEP::HepSymMatrix( 5, 0 );
42 ISvcLocator* svcLocator = Gaudi::svcLocator();
46 StatusCode sc = svcLocator->service(
"MagneticFieldSvc", IMFSvc );
48 { std::cerr << MSG::ERROR <<
"Unable to open Magnetic field service" << std::endl; }
56void VertexExtrapolate::G4MtovKalFitM( G4Material* g4m,
const std::string& name ) {
59 for (
unsigned i = 0; i != g4m->GetElementVector()->size(); ++i )
61 Z += ( g4m->GetElement( i )->GetZ() ) * ( g4m->GetFractionVector()[i] );
62 A += ( g4m->GetElement( i )->GetA() ) * ( g4m->GetFractionVector()[i] );
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 );
74void VertexExtrapolate::AddWalls(
int index,
double radius,
double thick,
double length,
76 std::cout <<
" " << matNames[index] <<
": radius: " << radius <<
", thick: " << thick
77 <<
", length: " << length << std::endl;
79 KalFitMaterial& tmp = m_BesKalmanExtMaterials[index];
80 KalFitCylinder innerwallCylinder( &tmp, radius, thick, length, z0 );
81 m_BesKalmanExtWalls.push_back( innerwallCylinder );
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 );
91 AddWalls( index, radius, thick, length, z0 );
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()
103void VertexExtrapolate::constructWallsFromGdml(
void ) {
105 G4LogicalVolume* logicalMdc = 0;
106 MdcG4Geo* aMdcG4Geo =
new MdcG4Geo();
108 G4Material* mat = logicalMdc->GetMaterial();
110 G4MtovKalFitM( mat,
"MDCGas" );
112 BesG4Geo* aBesG4Geo =
new BesG4Geo();
115 for (
int i = 1; i != 9; ++i )
117 G4LogicalVolume* logicalAirVolume =
const_cast<G4LogicalVolume*
>(
118 GDMLProcessor::GetInstance()->GetLogicalVolume( matNames[i] ) );
119 mat = logicalAirVolume->GetMaterial();
120 G4MtovKalFitM( mat, matNames[i] );
124 for (
int i = 1; i != 4; ++i ) AddWalls( i );
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 );
133 AddWalls( 4, radius, thick, length, z0 );
135 for (
int i = 5; i != 9; ++i ) AddWalls( i );
138 G4Tubs* goldLayerTub = getTubs(
"logicalgoldLayer" );
140 thick = goldLayerTub->GetInnerRadius() / ( cm );
141 length = 2.0 * goldLayerTub->GetZHalfLength() / ( cm );
143 AddWalls( 4, radius, thick, length, z0 );
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;
158 const int index = getWallMdcNumber( point );
161 if ( index == -1 )
return;
165 for (
int j = 0; j < index; j++ ) m_BesKalmanExtWalls[j].updateTrack( track, 1 );
167 int size = m_BesKalmanExtWalls.size() - 1;
170 const KalFitMaterial& material = m_BesKalmanExtWalls[index].material();
173 double path = m_BesKalmanExtWalls[index].intersect( track,
x, point );
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 );
190 HepVector tdsHelix = kalTrack->
getFHelix( pid );
191 HepSymMatrix tdsMatrix = kalTrack->
getFError( pid );
195 KalFitTrack fitTrack( IP, tdsHelix, tdsMatrix, pid, 0, 0 );
198 const double rp = point.perp();
201 const double radius = m_BesKalmanExtWalls[0].radius();
204 fitTrack.
pivot( lastPivot );
205 if ( rp <= radius ) extToAnyPoint( fitTrack, point );
209 fitTrack.
pivot( IP );
210 setHelixVector( fitTrack.
a() );
211 setErrorMatrix( fitTrack.
Ea() );
HepGeom::Point3D< double > HepPoint3D
const HepSymMatrix & getFError(const int pid) const
const HepVector & getFHelix(const int pid) const
double X0(void) const
Extractor.
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.
static double mdcGasRadlen_
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;.