EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
main.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file main.cc
1 
2 #include "G4RunManager.hh"
3 #include "G4UImanager.hh"
4 #include "G4VisExecutive.hh"
5 #include "G4UIExecutive.hh"
6 
7 #include "G4VUserDetectorConstruction.hh"
8 #include "G4VModularPhysicsList.hh"
9 #include "G4GDMLParser.hh"
10 #include "G4GDMLReadStructure.hh"
11 #include "G4AssemblyVolume.hh"
12 #include "G4PVPlacement.hh"
13 #include "G4NistManager.hh"
14 
15 #include <TROOT.h>
16 #include <TFile.h>
17 #include <TColor.h>
18 
19 #include <EicToyModel.h>
20 
21 // ---------------------------------------------------------------------------------------
22 
23 class BasicDetectorConstruction : public G4VUserDetectorConstruction {
24 public:
27 
28  G4VPhysicalVolume* Construct() {
29  auto eic = EicToyModel::Instance();
30 
31  // Print IR dimensions;
32  printf("\n\nIR box size: Z +/- %.2f [cm], R ~ %.2f [cm]\n\n",
33  eic->GetIrRegionLength()/2, eic->GetIrRegionRadius());
34 
35  // The easiest: ask the model to build its own IR world;
36  auto expHall_phys = eic->ConstructG4World();
37  if (!expHall_phys) exit(0);
38  expHall_phys->GetLogicalVolume()->SetVisAttributes(G4VisAttributes::Invisible);
39 
40  // Construct the integration volumes geometry, internally;
41  eic->Construct();
42 
43  // Place them as G4 volumes into the IR world volume all at once ...
44  eic->PlaceG4Volumes(expHall_phys);
45  // ... or just a single "EmCal" volume of the h-endcap, under "MyEmCal" name;
46  /*auto emcal =*/ //eic->fwd()->get("EmCal")->PlaceG4Volume(expHall_phys, "MyEmCal");
47 
48 #if _OK_
49  {
50  auto GDMLRS = new G4GDMLReadStructure();
51  G4GDMLParser gdmlParser(GDMLRS);
52  //gdmlParser.SetOverlapCheck(true);
53  // FIXME: may as well import from the same ROOT file ("VC.GDML" TObjString);
54  gdmlParser.Read("../../../build/example.vc.gdml", false);
55  G4AssemblyVolume *avol = GDMLRS->GetAssembly("VC.ASSEMBLY");
56  if (avol) {
57  G4VisAttributes* visAttg = new G4VisAttributes();
58  visAttg->SetColor(.5, .5, .5);
59  visAttg->SetVisibility(true);
60  visAttg->SetForceWireframe(false);
61  visAttg->SetForceSolid(true);
62 
63  std::vector<G4VPhysicalVolume *>::iterator it = avol->GetVolumesIterator();
64  for (unsigned int i = 0; i < avol->TotalImprintedVolumes(); i++) {
65  //printf("@@@ %30s ... %d\n", (*it)->GetName().data(), (*it)->GetLogicalVolume()->GetNoDaughters());
66  (*it)->GetLogicalVolume()->SetVisAttributes(visAttg);
67  //InsertVolumes(*it);
68  ++it;
69  }
70 
71  //G4RotationMatrix *g4rot = new G4RotationMatrix();
72  G4ThreeVector g4vec;
73  avol->MakeImprint(expHall_phys->GetLogicalVolume(), g4vec,
74  new G4RotationMatrix(), 0, true);
75  } //if
76  }
77 #endif
78 
79  return expHall_phys;
80  };
81 };
82 
83 // ---------------------------------------------------------------------------------------
84 
85 class BasicPhysicsList : public G4VModularPhysicsList {
86  public:
89 };
90 
91 // ---------------------------------------------------------------------------------------
92 
93 int main(int argc, char** argv)
94 {
95  if (argc != 2) {
96  printf("\n\n usage: %s <EicToyModel-root-file-name>\n\n\n", argv[0]);
97  return -1;
98  } //if
99 
100  // Import the ROOT file with an "EicToyModel" singleton class instance;
101  if (!EicToyModel::Import(argv[1])) return -1;
102 
103  // The rest is a usual GEANT stuff;
104  G4RunManager *runManager = new G4RunManager;
105  runManager->SetUserInitialization(new BasicDetectorConstruction());
106  runManager->SetUserInitialization(new BasicPhysicsList());
107  runManager->Initialize();
108 
109  G4VisManager *visManager = new G4VisExecutive("Quiet");
110  visManager->Initialize();
111 
112  G4UImanager *UImanager = G4UImanager::GetUIpointer();
113 
114  G4UIExecutive *ui = new G4UIExecutive(argc, argv);
115  UImanager->ApplyCommand("/vis/open OGL 600x600-0+0");
116  // Define a 3D cutaway view;
117  UImanager->ApplyCommand("/vis/viewer/set/viewpointThetaPhi 110. 150.");
118  UImanager->ApplyCommand("/vis/viewer/set/lightsThetaPhi 110. 150.");
119  UImanager->ApplyCommand("/vis/drawVolume ! ! ! -box m -10 0 0 10 -10 10");
120  //UImanager->ApplyCommand("/vis/drawVolume ! ! ! -box m -10 10 0 10 -10 10");
121  //UImanager->ApplyCommand("/vis/drawVolume");
122  //UImanager->ApplyCommand("/vis/scene/add/axes 0 0 0 1 m");
123  UImanager->ApplyCommand("/vis/viewer/set/background white");
124  UImanager->ApplyCommand("/vis/viewer/zoom 2.0");
125  //UImanager->ApplyCommand("/geometry/test/run");
126 
127  //UImanager->ApplyCommand("/vis/viewer/clearCutawayPlanes");
128  //UImanager->ApplyCommand("/vis/viewer/addCutawayPlane 0 0 7 m 1 0 0");
129  //UImanager->ApplyCommand("/vis/viewer/addCutawayPlane 0 0 7 m 0 -1 0");
130 
131  ui->SessionStart();
132 
133  delete ui; delete visManager; delete runManager;
134 
135  return 0;
136 } // main()
137 
138 // ---------------------------------------------------------------------------------------