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:
Inheritance graph
[legend]
Collaboration diagram for Detector:
Collaboration graph
[legend]

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 506 of file gears.cc.

Constructor & Destructor Documentation

◆ Detector()

Detector::Detector ( )

Definition at line 526 of file gears.cc.

527  : G4VUserDetectorConstruction(), G4UImessenger(), fWorld(0) {
528 #ifdef hasGDML
529  fCmdOut = new G4UIcmdWithAString("/geometry/export", this);
530  fCmdOut->SetGuidance("Export geometry gdml file name");
531  fCmdOut->SetParameterName("gdml geometry output", false);
532  fCmdOut->AvailableForStates(G4State_Idle);
533 #else
534  fCmdOut = 0;
535 #endif
536 
537  fCmdSrc = new G4UIcmdWithAString("/geometry/source", this);
538  fCmdSrc->SetGuidance("Set geometry source file name");
539  fCmdSrc->SetParameterName("text geometry input", false);
540  fCmdSrc->AvailableForStates(G4State_PreInit);
541 
542  fCmdLmt = new G4UIcommand("/tracking/setStepLimit", this);
543  fCmdLmt->SetGuidance("set max step length for a logical volume");
544  fCmdLmt->AvailableForStates(G4State_Idle);
545  G4UIparameter *p0 = new G4UIparameter("logical volume name", 's', false);
546  G4UIparameter *p1 = new G4UIparameter("step length in mm", 'd', false);
547  fCmdLmt->SetParameter(p0);
548  fCmdLmt->SetParameter(p1);
549 
550  fCmdSetB = new G4UIcmdWith3VectorAndUnit("/geometry/SetB", this);
551  fCmdSetB->SetGuidance("Set uniform magnetic field value.");
552  fCmdSetB->SetParameterName("Bx", "By", "Bz", false);
553  fCmdSetB->SetUnitCategory("Magnetic flux density");
554 }

◆ ~Detector()

Detector::~Detector ( )
inline

Definition at line 509 of file gears.cc.

509  {
510  delete fCmdSetB;
511  delete fCmdSrc;
512  delete fCmdOut;
513  }

Member Function Documentation

◆ Construct()

G4VPhysicalVolume * Detector::Construct ( )

called at /run/initialize

Definition at line 609 of file gears.cc.

609  {
610  if (fWorld == NULL) {
611  G4cout << "GEARS: no detector specified, set to a 10x10x10 m^3 box."
612  << G4endl;
613  auto box = new G4Box("hall", 5 * CLHEP::m, 5 * CLHEP::m, 5 * CLHEP::m);
614  G4NistManager *nist = G4NistManager::Instance();
615  G4Material *vacuum = nist->FindOrBuildMaterial("G4_Galactic");
616  auto v = new G4LogicalVolume(box, vacuum, "hall");
617  fWorld = new G4PVPlacement(0, G4ThreeVector(), v, "hall", 0, 0, 0);
618  }
619  return fWorld;
620 }

◆ SetNewValue()

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

for G4UI

Definition at line 565 of file gears.cc.

565  {
566  if (cmd == fCmdSetB) {
567  auto field = new G4UniformMagField(0, 0, 0);
568  field->SetFieldValue(fCmdSetB->GetNew3VectorValue(value));
569  G4FieldManager *mgr =
570  G4TransportationManager::GetTransportationManager()->GetFieldManager();
571  mgr->SetDetectorField(field);
572  mgr->CreateChordFinder(field);
573  G4cout << "GEARS: Magnetic field is set to " << value << G4endl;
574 #ifdef hasGDML
575  } else if (cmd == fCmdOut) {
576  G4GDMLParser paser;
577  paser.Write(value, fWorld);
578 #endif
579  } else if (cmd == fCmdLmt) {
580  istringstream iss(value);
581  G4String vlm, limit;
582  iss >> vlm >> limit;
583  auto v = G4LogicalVolumeStore::GetInstance()->GetVolume(vlm);
584  if (v) {
585  v->SetUserLimits(new G4UserLimits(stof(limit)));
586  G4cout << "GEARS: max step length in " << vlm << ": " << limit << " mm"
587  << G4endl;
588  }
589  } else { // cmd==fCmdSrc
590  if (value.substr(value.length() - 4) != "gdml") { // text geometry input
591  G4tgbVolumeMgr *mgr = G4tgbVolumeMgr::GetInstance();
592  mgr->AddTextFile(value);
593  auto tgb = new TextDetectorBuilder;
594  mgr->SetDetectorBuilder(tgb);
595  fWorld = mgr->ReadAndConstructDetector();
596 #ifdef hasGDML
597  } else { // GDML input
598  G4GDMLParser parser;
599  parser.Read(value);
600  fWorld = parser.GetWorldVolume();
601 #endif
602  }
603  }
604 }
Construct detector based on text geometry description.
Definition: gears.cc:419

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