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;
48 extRunManagerKernel =
new G4RunManagerKernel;
49 extRunManagerKernel->DefineWorldVolume(bes3WorldVolume);
50 extRunManagerKernel->SetPhysics(extPhysicsList);
51 extTrackingManager=extRunManagerKernel->GetTrackingManager();
54Ext_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)
58 bes3WorldVolume = bes3DetectorConstruction->Construct();
60 extTrack =
new G4Track;
65 extRunManagerKernel =
new G4RunManagerKernel;
66 extTrackingManager=extRunManagerKernel->GetTrackingManager();
67 extRunManagerKernel->DefineWorldVolume(bes3WorldVolume);
68 extRunManagerKernel->SetPhysics(extPhysicsList);
69 extTrackingManager=extRunManagerKernel->GetTrackingManager();
81 if(extTrack)
delete extTrack;
83 if(bes3DetectorConstruction)
delete bes3DetectorConstruction;
85 if(extPhysicsList)
delete extPhysicsList;
89 G4GeometryManager::GetInstance()->OpenGeometry();
92 G4SDManager* fSDM = G4SDManager::GetSDMpointerIfExist();
107 myGeomOptimization = GeomOptimization;
109 myUseMucKal=aUseMucKal;
110 myMucWindow = aMucWindow;
115 if(myMsgFlag) cout <<
"Ext_track::Init will execute geant initialization." << endl;
118 extRunManagerKernel->InitializePhysics();
119 G4cout<<
"dzy add output before extRunManagerKernel->RunInitialization()"<<G4endl;
120 extRunManagerKernel->RunInitialization();
121 G4cout<<
"dzy add output after extRunManagerKernel->RunInitialization()"<<G4endl;
128 extTrackingManager->SetUserAction(extSteppingAction);
137bool Ext_track::GeometryInitialization()
139 if(myMsgFlag) cout <<
"Ext_track::GeometryInitialization()." << endl;
149 G4Region *defaultRegion=
new G4Region(
"DefaultRegionForBesWorld");
150 defaultRegion->SetProductionCuts(G4ProductionCutsTable::GetProductionCutsTable()->GetDefaultProductionCuts());
153 if(bes3WorldVolume->GetLogicalVolume()->GetRegion())
155 if(bes3WorldVolume->GetLogicalVolume()->GetRegion()!=defaultRegion)
157 cout <<
"The world volume has a user-defined region <"
158 << bes3WorldVolume->GetLogicalVolume()->GetRegion()->GetName()
165 if(defaultRegion->GetNumberOfRootVolumes())
167 if(defaultRegion->GetNumberOfRootVolumes()>
size_t(1))
169 cout <<
"DefaultRegionHasMoreThanOneVolume,Default world region should have a unique logical volume."<<endl;
172 std::vector<G4LogicalVolume*>::iterator lvItr = defaultRegion->GetRootLogicalVolumeIterator();
173 defaultRegion->RemoveRootLogicalVolume(*lvItr);
174 cout << (*lvItr)->GetName()
175 <<
" is removed from the default region." << endl;
179 G4LogicalVolume* bes3WorldLog = bes3WorldVolume->GetLogicalVolume();
180 bes3WorldLog->SetRegion(defaultRegion);
181 defaultRegion->AddRootLogicalVolume(bes3WorldLog);
184 G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->SetWorldVolume(bes3WorldVolume);
191bool Ext_track::PhysicsInitialization()
193 if(myMsgFlag) cout<<
"Ext_track::PhysicsInitialization()."<<endl;
198 extPhysicsList->Construct();
199 extPhysicsList->CheckParticleList();
200 extPhysicsList->SetCuts();
205 G4RegionStore::GetInstance()->UpdateMaterialList(bes3WorldVolume);
206 G4ProductionCutsTable::GetProductionCutsTable()->UpdateCoupleTable(bes3WorldVolume);
209 if(myMsgFlag) cout<<
"Build PhysicsTables"<<endl;
210 extPhysicsList->BuildPhysicsTable();
211 if(myMsgFlag) cout<<
"Build PhysicsTables end."<<endl;
212 G4ProductionCutsTable::GetProductionCutsTable()->PhysicsTableUpdated();
213 extPhysicsList->DumpCutValuesTableIfRequested();
216 if(myGeomOptimization)
218 cout<<
"Geometry Optimization,please wait for a few minutes."<<endl;
219 G4GeometryManager* geomManager = G4GeometryManager::GetInstance();
220 geomManager->OpenGeometry();
221 geomManager->CloseGeometry(
true,
false);
230void Ext_track::CheckRegions()
233 G4RegionStore::GetInstance()->SetWorldVolume();
235 for(
size_t i=0;i<G4RegionStore::GetInstance()->size();i++)
237 G4Region* region = (*(G4RegionStore::GetInstance()))[i];
239 if(region->GetWorldPhysical()!=bes3WorldVolume)
continue;
240 G4ProductionCuts* cuts = region->GetProductionCuts();
243 region->SetProductionCuts(G4ProductionCutsTable::GetProductionCutsTable()->GetDefaultProductionCuts());
254bool Ext_track::Set(
const Hep3Vector &xv3,
const Hep3Vector &pv3,
const HepSymMatrix &err,
const std::string &particleName,
const double pathInMDC,
const double tofInMdc)
256 if( err.num_row() != 6 ){
257 std::cerr <<
"%ERROR at Ext_track::Set. Dimension of error matrix: "
258 << err.num_row() <<
" should be 6" << std::endl;
271 if(!CheckVertexInsideWorld(xv3))
return 0;
273 float p( pv3.mag() );
274 m_vect[3] = pv3.x()/p;
275 m_vect[4] = pv3.y()/p;
276 m_vect[5] = pv3.z()/p;
280 if(particleName!=
"e+"&&particleName!=
"e-"&&
281 particleName!=
"mu+"&&particleName!=
"mu-"&&
282 particleName!=
"pi+"&&particleName!=
"pi-"&&
283 particleName!=
"kaon+"&&particleName!=
"kaon-"&&
284 particleName!=
"proton"&&particleName!=
"anti_proton"&&
285 particleName!=
"gamma")
287 std::cerr <<
"Unknown or unconstructed Particle."<< std::endl;
295 G4ParticleDefinition* particleDefinition=G4ParticleTable::GetParticleTable()->FindParticle(particleName);
296 Q = particleDefinition->GetPDGCharge();
297 mass = particleDefinition->GetPDGMass();
300 Hep3Vector xv( m_vect[0], m_vect[1], m_vect[2] );
301 Hep3Vector pv(m_vect[3]*m_vect[6], m_vect[4]*m_vect[6], m_vect[5]*m_vect[6]);
309 double betaInMDC = p/sqrt(
mass*
mass+p*p);
328 G4DynamicParticle* DP =
new G4DynamicParticle(particleDefinition,pv);
331 extTrack =
new G4Track(DP,0.0,xv3);
335 Hep3Vector center(0,0,0);
336 G4Navigator* navigator= G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking();
337 navigator->LocateGlobalPointAndSetup(center,0,
false);
344bool Ext_track::CheckVertexInsideWorld(
const Hep3Vector& pos)
346 G4Navigator* navigator= G4TransportationManager::GetTransportationManager()-> GetNavigatorForTracking();
348 G4VPhysicalVolume* world= navigator-> GetWorldVolume();
349 G4VSolid* solid= world-> GetLogicalVolume()-> GetSolid();
350 EInside qinside= solid-> Inside(pos);
352 if( qinside != kInside)
return false;
364 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)