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"
28#include "G4RunManagerKernel.hh"
40 bes3WorldVolume = bes3DetectorConstruction->Construct();
42 extTrack =
new G4Track;
45 extTrackingManager =
new G4TrackingManager;
47 extRunManagerKernel =
new G4RunManagerKernel;
50Ext_track::Ext_track(
const bool msgFlag,
const bool BFieldOn,
const bool GeomOptimization,
const int m_detVer,
const bool aUseMucKal,
const int aMucWindow) : myMsgFlag(msgFlag),myBFieldOn(BFieldOn),myGeomOptimization(GeomOptimization),m_dir(0),myUseMucKal(aUseMucKal),myMucWindow(aMucWindow)
54 bes3WorldVolume = bes3DetectorConstruction->Construct();
56 extTrack =
new G4Track;
59 extTrackingManager =
new G4TrackingManager;
61 extRunManagerKernel =
new G4RunManagerKernel;
68 if(extRunManagerKernel)
delete extRunManagerKernel;
69 if(extTrackingManager)
delete extTrackingManager;
71 if(extTrack)
delete extTrack;
72 if(bes3DetectorConstruction)
delete bes3DetectorConstruction;
73 if(extPhysicsList)
delete extPhysicsList;
76 G4GeometryManager::GetInstance()->OpenGeometry();
79 G4SDManager* fSDM = G4SDManager::GetSDMpointerIfExist();
93 myGeomOptimization = GeomOptimization;
95 myUseMucKal=aUseMucKal;
96 myMucWindow = aMucWindow;
98 G4ParticleTable::GetParticleTable()->SetReadiness();
99 extPhysicsList->ConstructParticle();
101 if(myMsgFlag) cout <<
"Ext_track::Init will execute geant initialization." << endl;
102 if(!GeometryInitialization()) cout <<
"Error in Ext_track::GeometryInitialization()" << endl;
103 PhysicsInitialization();
110 extTrackingManager->SetUserAction(extSteppingAction);
119bool Ext_track::GeometryInitialization()
121 if(myMsgFlag) cout <<
"Ext_track::GeometryInitialization()." << endl;
131 G4Region *defaultRegion=
new G4Region(
"DefaultRegionForBesWorld");
132 defaultRegion->SetProductionCuts(G4ProductionCutsTable::GetProductionCutsTable()->GetDefaultProductionCuts());
135 if(bes3WorldVolume->GetLogicalVolume()->GetRegion())
137 if(bes3WorldVolume->GetLogicalVolume()->GetRegion()!=defaultRegion)
139 cout <<
"The world volume has a user-defined region <"
140 << bes3WorldVolume->GetLogicalVolume()->GetRegion()->GetName()
147 if(defaultRegion->GetNumberOfRootVolumes())
149 if(defaultRegion->GetNumberOfRootVolumes()>
size_t(1))
151 cout <<
"DefaultRegionHasMoreThanOneVolume,Default world region should have a unique logical volume."<<endl;
154 std::vector<G4LogicalVolume*>::iterator lvItr = defaultRegion->GetRootLogicalVolumeIterator();
155 defaultRegion->RemoveRootLogicalVolume(*lvItr);
156 cout << (*lvItr)->GetName()
157 <<
" is removed from the default region." << endl;
161 G4LogicalVolume* bes3WorldLog = bes3WorldVolume->GetLogicalVolume();
162 bes3WorldLog->SetRegion(defaultRegion);
163 defaultRegion->AddRootLogicalVolume(bes3WorldLog);
166 G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->SetWorldVolume(bes3WorldVolume);
173bool Ext_track::PhysicsInitialization()
175 if(myMsgFlag) cout<<
"Ext_track::PhysicsInitialization()."<<endl;
180 extPhysicsList->Construct();
181 extPhysicsList->SetCuts();
186 G4RegionStore::GetInstance()->UpdateMaterialList(bes3WorldVolume);
187 G4ProductionCutsTable::GetProductionCutsTable()->UpdateCoupleTable(bes3WorldVolume);
190 if(myMsgFlag) cout<<
"Build PhysicsTables"<<endl;
191 extPhysicsList->BuildPhysicsTable();
192 if(myMsgFlag) cout<<
"Build PhysicsTables end."<<endl;
193 G4ProductionCutsTable::GetProductionCutsTable()->PhysicsTableUpdated();
194 extPhysicsList->DumpCutValuesTableIfRequested();
197 if(myGeomOptimization)
199 cout<<
"Geometry Optimization,please wait for a few minutes."<<endl;
200 G4GeometryManager* geomManager = G4GeometryManager::GetInstance();
201 geomManager->OpenGeometry();
202 geomManager->CloseGeometry(
true,
false);
211void Ext_track::CheckRegions()
214 G4RegionStore::GetInstance()->SetWorldVolume();
216 for(
size_t i=0;i<G4RegionStore::GetInstance()->size();i++)
218 G4Region* region = (*(G4RegionStore::GetInstance()))[i];
220 if(region->GetWorldPhysical()!=bes3WorldVolume)
continue;
221 G4ProductionCuts* cuts = region->GetProductionCuts();
224 region->SetProductionCuts(G4ProductionCutsTable::GetProductionCutsTable()->GetDefaultProductionCuts());
235bool Ext_track::Set(
const Hep3Vector &xv3,
const Hep3Vector &pv3,
const HepSymMatrix &err,
const std::string &particleName,
const double pathInMDC,
const double tofInMdc)
237 if( err.num_row() != 6 ){
238 std::cerr <<
"%ERROR at Ext_track::Set. Dimension of error matrix: "
239 << err.num_row() <<
" should be 6" << std::endl;
252 if(!CheckVertexInsideWorld(xv3))
return 0;
254 float p( pv3.mag() );
255 m_vect[3] = pv3.x()/p;
256 m_vect[4] = pv3.y()/p;
257 m_vect[5] = pv3.z()/p;
261 if(particleName!=
"e+"&&particleName!=
"e-"&&
262 particleName!=
"mu+"&&particleName!=
"mu-"&&
263 particleName!=
"pi+"&&particleName!=
"pi-"&&
264 particleName!=
"kaon+"&&particleName!=
"kaon-"&&
265 particleName!=
"proton"&&particleName!=
"anti_proton"&&
266 particleName!=
"gamma")
268 std::cerr <<
"Unknown or unconstructed Particle."<< std::endl;
276 G4ParticleDefinition* particleDefinition=G4ParticleTable::GetParticleTable()->FindParticle(particleName);
277 Q = particleDefinition->GetPDGCharge();
278 mass = particleDefinition->GetPDGMass();
281 Hep3Vector xv( m_vect[0], m_vect[1], m_vect[2] );
282 Hep3Vector pv(m_vect[3]*m_vect[6], m_vect[4]*m_vect[6], m_vect[5]*m_vect[6]);
290 double betaInMDC = p/sqrt(
mass*
mass+p*p);
309 G4DynamicParticle* DP =
new G4DynamicParticle(particleDefinition,pv);
312 extTrack =
new G4Track(DP,0.0,xv3);
316 Hep3Vector center(0,0,0);
317 G4Navigator* navigator= G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking();
318 navigator->LocateGlobalPointAndSetup(center,0,
false);
325bool Ext_track::CheckVertexInsideWorld(
const Hep3Vector& pos)
327 G4Navigator* navigator= G4TransportationManager::GetTransportationManager()-> GetNavigatorForTracking();
329 G4VPhysicalVolume* world= navigator-> GetWorldVolume();
330 G4VSolid* solid= world-> GetLogicalVolume()-> GetSolid();
331 EInside qinside= solid-> Inside(pos);
333 if( qinside != kInside)
return false;
345 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)