GEARS
Geant4 Example Application with Rich features and Small footprints
Public Member Functions | List of all members
Detector Class Reference

Construct detector geometry. More...

Inheritance diagram for Detector:

Public Member Functions

 Detector ()
 
 ~Detector ()
 
G4VPhysicalVolume * Construct ()
 called at /run/initialize More...
 
void SetNewValue (G4UIcommand *cmd, G4String value)
 for G4UI More...
 

Detailed Description

Construct detector geometry.

This uses two types of instructions to construct a detector:

It won't work together with HP neutron simulation if Geant4 version is lower than 10 because of this bug: http://hypernews.slac.stanford.edu/HyperNews/geant4/get/hadronprocess/1242.html?inline=-1

Definition at line 401 of file gears.cc.

Constructor & Destructor Documentation

§ Detector()

Detector::Detector ( )

Definition at line 417 of file gears.cc.

417  : G4VUserDetectorConstruction(), G4UImessenger(), fWorld(0)
418 {
419 #ifdef hasGDML
420  fCmdOut = new G4UIcmdWithAString("/geometry/export",this);
421  fCmdOut->SetGuidance("Export geometry gdml file name");
422  fCmdOut->SetParameterName("gdml geometry output",false);
423  fCmdOut->AvailableForStates(G4State_Idle);
424 #else
425  fCmdOut=0;
426 #endif
427 
428  fCmdSrc = new G4UIcmdWithAString("/geometry/source",this);
429  fCmdSrc->SetGuidance("Set geometry source file name");
430  fCmdSrc->SetParameterName("text geometry input",false);
431  fCmdSrc->AvailableForStates(G4State_PreInit);
432 
433  fCmdSetB = new G4UIcmdWith3VectorAndUnit("/geometry/SetB",this);
434  fCmdSetB->SetGuidance("Set uniform magnetic field value.");
435  fCmdSetB->SetParameterName("Bx", "By", "Bz", false);
436  fCmdSetB->SetUnitCategory("Magnetic flux density");
437 }

§ ~Detector()

Detector::~Detector ( )
inline

Definition at line 405 of file gears.cc.

405 { delete fCmdSetB; delete fCmdSrc; delete fCmdOut; }

Member Function Documentation

§ Construct()

G4VPhysicalVolume * Detector::Construct ( )

called at /run/initialize

Definition at line 481 of file gears.cc.

482 {
483  if (fWorld==NULL) {
484  G4cout<<"GEARS: no detector specified, set to a 10x10x10 m^3 box."<<G4endl;
485  G4Box* box = new G4Box("hall", 5*CLHEP::m, 5*CLHEP::m, 5*CLHEP::m);
486  G4NistManager *nist = G4NistManager::Instance();
487  G4Material *vacuum = nist->FindOrBuildMaterial("G4_Galactic");
488  G4LogicalVolume *v = new G4LogicalVolume(box, vacuum, "hall");
489  fWorld = new G4PVPlacement(0, G4ThreeVector(), v, "hall", 0, 0, 0);
490  }
491  return fWorld;
492 }

§ SetNewValue()

void Detector::SetNewValue ( G4UIcommand *  cmd,
G4String  value 
)

for G4UI

Definition at line 446 of file gears.cc.

447 {
448  if (cmd==fCmdSetB) {
449  G4UniformMagField* field = new G4UniformMagField(0,0,0);
450  field->SetFieldValue(fCmdSetB->GetNew3VectorValue(value));
451  G4FieldManager* mgr =
452  G4TransportationManager::GetTransportationManager()->GetFieldManager();
453  mgr->SetDetectorField(field);
454  mgr->CreateChordFinder(field);
455  G4cout<<"GEARS: Magnetic field is set to "<<value<<G4endl;
456 #ifdef hasGDML
457  } else if(cmd==fCmdOut) {
458  G4GDMLParser paser;
459  paser.Write(value,fWorld);
460 #endif
461  } else { // cmd==fCmdSrc
462  if (value.substr(value.length()-4)!="gdml") { // text geometry input
463  G4tgbVolumeMgr* mgr = G4tgbVolumeMgr::GetInstance();
464  mgr->AddTextFile(value);
466  mgr->SetDetectorBuilder(tgb);
467  fWorld = mgr->ReadAndConstructDetector();
468 #ifdef hasGDML
469  } else { // GDML input
470  G4GDMLParser parser;
471  parser.Read(value);
472  fWorld=parser.GetWorldVolume();
473 #endif
474  }
475  }
476 }
Construct detector based on text geometry description.
Definition: gears.cc:316

The documentation for this class was generated from the following file: