8#include "TrkExtAlg/Ext_track.h"
10#include "G4ParticleTable.hh"
11#include "G4Navigator.hh"
12#include "G4VPhysicalVolume.hh"
14#include "G4GeometryManager.hh"
15#include "G4RegionStore.hh"
16#include "G4ProductionCuts.hh"
18#include "G4LogicalVolume.hh"
19#include "G4TransportationManager.hh"
20#include "G4PrimaryParticle.hh"
21#include "G4DynamicParticle.hh"
22#include "G4SDManager.hh"
23#include "G4SteppingManager.hh"
26#include "TrkExtAlg/ExtBesDetectorConstruction.h"
27#include "TrkExtAlg/ExtPhysicsList.h"
28#include "G4RunManagerKernel.hh"
39 bes3WorldVolume = bes3DetectorConstruction->Construct();
41 extTrack =
new G4Track;
44 extTrackingManager =
new G4TrackingManager;
46 extRunManagerKernel =
new G4RunManagerKernel;
49Ext_track::Ext_track(
const bool msgFlag,
const bool BFieldOn,
const bool GeomOptimization,
const int m_tofversion,
const bool aUseMucKal,
const int aMucWindow) : myMsgFlag(msgFlag),myBFieldOn(BFieldOn),myGeomOptimization(GeomOptimization),m_dir(0),myUseMucKal(aUseMucKal),myMucWindow(aMucWindow)
53 bes3WorldVolume = bes3DetectorConstruction->Construct();
55 extTrack =
new G4Track;
58 extTrackingManager =
new G4TrackingManager;
60 extRunManagerKernel =
new G4RunManagerKernel;
67 if(extRunManagerKernel)
delete extRunManagerKernel;
68 if(extTrackingManager)
delete extTrackingManager;
70 if(extTrack)
delete extTrack;
71 if(bes3DetectorConstruction)
delete bes3DetectorConstruction;
72 if(extPhysicsList)
delete extPhysicsList;
75 G4GeometryManager::GetInstance()->OpenGeometry();
78 G4SDManager* fSDM = G4SDManager::GetSDMpointerIfExist();
92 myGeomOptimization = GeomOptimization;
94 myUseMucKal=aUseMucKal;
95 myMucWindow = aMucWindow;
97 G4ParticleTable::GetParticleTable()->SetReadiness();
98 extPhysicsList->ConstructParticle();
100 if(myMsgFlag) cout <<
"Ext_track::Init will execute geant initialization." << endl;
101 if(!GeometryInitialization()) cout <<
"Error in Ext_track::GeometryInitialization()" << endl;
102 PhysicsInitialization();
109 extTrackingManager->SetUserAction(extSteppingAction);
118bool Ext_track::GeometryInitialization()
120 if(myMsgFlag) cout <<
"Ext_track::GeometryInitialization()." << endl;
130 G4Region *defaultRegion=
new G4Region(
"DefaultRegionForBesWorld");
131 defaultRegion->SetProductionCuts(G4ProductionCutsTable::GetProductionCutsTable()->GetDefaultProductionCuts());
134 if(bes3WorldVolume->GetLogicalVolume()->GetRegion())
136 if(bes3WorldVolume->GetLogicalVolume()->GetRegion()!=defaultRegion)
138 cout <<
"The world volume has a user-defined region <"
139 << bes3WorldVolume->GetLogicalVolume()->GetRegion()->GetName()
146 if(defaultRegion->GetNumberOfRootVolumes())
148 if(defaultRegion->GetNumberOfRootVolumes()>
size_t(1))
150 cout <<
"DefaultRegionHasMoreThanOneVolume,Default world region should have a unique logical volume."<<endl;
153 std::vector<G4LogicalVolume*>::iterator lvItr = defaultRegion->GetRootLogicalVolumeIterator();
154 defaultRegion->RemoveRootLogicalVolume(*lvItr);
155 cout << (*lvItr)->GetName()
156 <<
" is removed from the default region." << endl;
160 G4LogicalVolume* bes3WorldLog = bes3WorldVolume->GetLogicalVolume();
161 bes3WorldLog->SetRegion(defaultRegion);
162 defaultRegion->AddRootLogicalVolume(bes3WorldLog);
165 G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->SetWorldVolume(bes3WorldVolume);
172bool Ext_track::PhysicsInitialization()
174 if(myMsgFlag) cout<<
"Ext_track::PhysicsInitialization()."<<endl;
179 extPhysicsList->Construct();
180 extPhysicsList->SetCuts();
185 G4RegionStore::GetInstance()->UpdateMaterialList(bes3WorldVolume);
186 G4ProductionCutsTable::GetProductionCutsTable()->UpdateCoupleTable(bes3WorldVolume);
189 if(myMsgFlag) cout<<
"Build PhysicsTables"<<endl;
190 extPhysicsList->BuildPhysicsTable();
191 if(myMsgFlag) cout<<
"Build PhysicsTables end."<<endl;
192 G4ProductionCutsTable::GetProductionCutsTable()->PhysicsTableUpdated();
193 extPhysicsList->DumpCutValuesTableIfRequested();
196 if(myGeomOptimization)
198 cout<<
"Geometry Optimization,please wait for a few minutes."<<endl;
199 G4GeometryManager* geomManager = G4GeometryManager::GetInstance();
200 geomManager->OpenGeometry();
201 geomManager->CloseGeometry(
true,
false);
210void Ext_track::CheckRegions()
213 G4RegionStore::GetInstance()->SetWorldVolume();
215 for(
size_t i=0;i<G4RegionStore::GetInstance()->size();i++)
217 G4Region* region = (*(G4RegionStore::GetInstance()))[i];
219 if(region->GetWorldPhysical()!=bes3WorldVolume)
continue;
220 G4ProductionCuts* cuts = region->GetProductionCuts();
223 region->SetProductionCuts(G4ProductionCutsTable::GetProductionCutsTable()->GetDefaultProductionCuts());
234bool Ext_track::Set(
const Hep3Vector &xv3,
const Hep3Vector &pv3,
const HepSymMatrix &err,
const std::string &particleName,
const double pathInMDC,
const double tofInMdc)
236 if( err.num_row() != 6 ){
237 std::cerr <<
"%ERROR at Ext_track::Set. Dimension of error matrix: "
238 << err.num_row() <<
" should be 6" << std::endl;
251 if(!CheckVertexInsideWorld(xv3))
return 0;
253 float p( pv3.mag() );
254 m_vect[3] = pv3.x()/p;
255 m_vect[4] = pv3.y()/p;
256 m_vect[5] = pv3.z()/p;
260 if(particleName!=
"e+"&&particleName!=
"e-"&&
261 particleName!=
"mu+"&&particleName!=
"mu-"&&
262 particleName!=
"pi+"&&particleName!=
"pi-"&&
263 particleName!=
"kaon+"&&particleName!=
"kaon-"&&
264 particleName!=
"proton"&&particleName!=
"anti_proton"&&
265 particleName!=
"gamma")
267 std::cerr <<
"Unknown or unconstructed Particle."<< std::endl;
275 G4ParticleDefinition* particleDefinition=G4ParticleTable::GetParticleTable()->FindParticle(particleName);
276 Q = particleDefinition->GetPDGCharge();
277 mass = particleDefinition->GetPDGMass();
280 Hep3Vector xv( m_vect[0], m_vect[1], m_vect[2] );
281 Hep3Vector pv(m_vect[3]*m_vect[6], m_vect[4]*m_vect[6], m_vect[5]*m_vect[6]);
289 double betaInMDC = p/sqrt(
mass*
mass+p*p);
308 G4DynamicParticle* DP =
new G4DynamicParticle(particleDefinition,pv);
311 extTrack =
new G4Track(DP,0.0,xv3);
315 Hep3Vector center(0,0,0);
316 G4Navigator* navigator= G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking();
317 navigator->LocateGlobalPointAndSetup(center,0,
false);
324bool Ext_track::CheckVertexInsideWorld(
const Hep3Vector& pos)
326 G4Navigator* navigator= G4TransportationManager::GetTransportationManager()-> GetNavigatorForTracking();
328 G4VPhysicalVolume* world= navigator-> GetWorldVolume();
329 G4VSolid* solid= world-> GetLogicalVolume()-> GetSolid();
330 EInside qinside= solid-> Inside(pos);
332 if( qinside != kInside)
return false;
344 extTrackingManager->ProcessOneTrack(extTrack);
void SetMsgFlag(bool aMsgFalg)
void SetMucWindow(int aMucWindow)
void SetBetaInMDC(double aBeta)
void SetMucKalFlag(bool aMucKalFlag)
void SetInitialPath(double aPath)
void SetInitialTof(double aTof)
void SetXpErrPointer(Ext_xp_err *xpErr)
void TrackExtrapotation()
void Initialization(const bool aMsgFlag, const bool Bfield, const bool GeomOptimization, const bool aUseMucKal, const int aMucWindow)
bool Set(const Hep3Vector &xv3, const Hep3Vector &pv3, const HepSymMatrix &err, const std::string &particleName, const double pathInMDC, const double tofInMdc)
void set_err(const HepSymMatrix &err, const Hep3Vector &xv, const Hep3Vector &pv, const double &q, const double &mass)