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 #include "G4VUserDetectorConstruction.hh"
7 #include "G4VModularPhysicsList.hh"
8 
9 #include <EicToyModel.h>
10 #include <GemGeoParData.h>
11 #include <MuMegasGeoParData.h>
12 #include <VstGeoParData.h>
13 
14 // ---------------------------------------------------------------------------------------
15 
16 class BasicDetectorConstruction : public G4VUserDetectorConstruction {
17 public:
20 
21  G4VPhysicalVolume* Construct() {
22  auto eic = EicToyModel::Instance();
23 
24  // The easiest: ask the model to build its own IR world;
25  auto expHall_phys = eic->ConstructG4World();
26  if (!expHall_phys) exit(0);
27  expHall_phys->GetLogicalVolume()->SetVisAttributes(G4VisAttributes::Invisible);
28 
29  // Construct the integration volumes geometry, internally; see scripts/eicroot.C
30  // for the volume composition;
31  eic->Construct();
32 
33  // Place them as G4 volumes into the IR world volume all at once ...
34  //eic->PlaceG4Volumes(expHall_phys);
35  eic->DefineG4World(expHall_phys->GetLogicalVolume());
36 
37  // Vertex tracker;
38  {
40  //vst.SetGeometryType(EicGeoParData::NoStructure);
41  //vst.WithEnforcementBrackets();
42  //vst.WithExternalPipes();
43 
44  auto ibcell = new MapsMimosaAssembly();
45 
46  // Compose barrel layers; parameters are:
47  // - cell assembly type;
48  // - number of staves in this layer;
49  // - number of chips in a stave;
50  // - chip center installation radius;
51  // - additional stave slope around beam line direction; [degree];
52  // - layer rotation around beam axis "as a whole"; [degree];
53  //
54  vst.AddBarrelLayer(ibcell, 3*12, 9, 3*23.4 * etm::mm, 12.0, 0.0);
55 
56  auto mid = eic->mid()->get("TRACKER")->GetG4Volume();
57  vst.PlaceG4Volume(mid, true, 0, new G4ThreeVector(0, 0, 0));
58  }
59 
60  // Forward GEM tracker module(s);
61  {
62  GemGeoParData fgt("FGT");
63  auto sbs = new GemModule();
64 
65  // Compose sectors; parameters are:
66  // - layer description (obviously can mix different geometries);
67  // - azimuthal segmentation;
68  // - gas volume center radius;
69  // - Z offset from 0.0 (default);
70  // - azimuthal rotation from 0.0 (default);
71  fgt.AddWheel(sbs, 12, 420.0 * etm::mm, -50.0 * etm::mm, 0);
72  fgt.AddWheel(sbs, 12, 420.0 * etm::mm, 50.0 * etm::mm, 0);
73 
74  auto fwd = eic->fwd()->get("MPGD") ->GetG4Volume();
75  // Build ROOT geometry, convert it to GEANT geometry, place into the mother volume;
76  fgt.PlaceG4Volume(fwd);
77  }
78  // Backward GEM tracker module(s);
79  {
80  GemGeoParData bgt("BGT");
81  GemModule *sbs = new GemModule();
82 
83  bgt.AddWheel(sbs, 12, 420.0 * etm::mm, 0.0 * etm::mm);
84 
85  bgt.SetTransparency(50);
86 
87  auto bck = eic->bck()->get("TRD") ->GetG4Volume();
88  bgt.PlaceG4Volume(bck, false, 0, new G4ThreeVector(0, 0, 50 * g4::mm));
89  }
90 
91  // Micromegas central tracker barrels;
92  {
93  MuMegasGeoParData mmt("MMT");
95  // See other MuMegasLayer class POD entries in include/MuMegasGeoParData.h;
96  //layer->SetDoubleVariable("mOuterFrameWidth", 50 * etm::mm);
97 
98  // Compose barrel layers; parameters are:
99  // - layer description (obviously can mix different geometries);
100  // - length along Z;
101  // - segmentation in Z;
102  // - radius;
103  // - segmentation in phi;
104  // - Z offset from 0.0 (default);
105  // - azimuthal rotation from 0.0 (default);
106  mmt.AddBarrel(layer, 600. * etm::mm, 2, 300. * etm::mm, 3, 0.0, 0.0);
107  //mmt.AddBarrel(layer,1800. * etm::mm, 4, 800. * etm::mm, 6, 0.0, 0.0);
108 
109  mmt.SetTransparency(50);
110 
111  auto mid = eic->mid()->get("TRACKER")->GetG4Volume();
112  mmt.PlaceG4Volume(mid, false, 0, new G4ThreeVector(0, 0, 20 * g4::mm));
113  }
114 
115  return expHall_phys;
116  };
117 };
118 
119 // ---------------------------------------------------------------------------------------
120 
121 class BasicPhysicsList : public G4VModularPhysicsList {
122  public:
125 };
126 
127 // ---------------------------------------------------------------------------------------
128 
129 int main(int argc, char** argv)
130 {
131  if (argc != 3) {
132  printf("\n\n usage: %s <EicToyModel-root-file-name> <EicRoot-media-file-name>\n\n\n", argv[0]);
133  return -1;
134  } //if
135 
136  // Import the ROOT file with an "EicToyModel" singleton class instance;
137  if ( !EicToyModel::Import( argv[1])) return -1;
138  // Import EicRoot media.geo file;
139  if (EicGeoParData::ImportMediaFile(argv[2])) return -1;
140 
141  // The rest is a usual GEANT stuff;
142  G4RunManager *runManager = new G4RunManager;
143  runManager->SetUserInitialization(new BasicDetectorConstruction());
144  runManager->SetUserInitialization(new BasicPhysicsList());
145  runManager->Initialize();
146 
147  G4VisManager *visManager = new G4VisExecutive("Quiet");
148  visManager->Initialize();
149 
150  G4UImanager *UImanager = G4UImanager::GetUIpointer();
151 
152  G4UIExecutive *ui = new G4UIExecutive(argc, argv);
153  UImanager->ApplyCommand("/vis/open OGL 600x600-0+0");
154  // Define a 3D cutaway view;
155  UImanager->ApplyCommand("/vis/viewer/set/viewpointThetaPhi 110. 150.");
156  UImanager->ApplyCommand("/vis/viewer/set/lightsThetaPhi 110. 150.");
157  UImanager->ApplyCommand("/vis/drawVolume");
158  UImanager->ApplyCommand("/vis/scene/add/axes 0 0 0 1 m");
159  UImanager->ApplyCommand("/vis/viewer/set/background white");
160  UImanager->ApplyCommand("/vis/viewer/zoom 2.0");
161  //UImanager->ApplyCommand("/geometry/test/run");
162 
163  //UImanager->ApplyCommand("/vis/viewer/clearCutawayPlanes");
164  //UImanager->ApplyCommand("/vis/viewer/addCutawayPlane 0 0 7 m 1 0 0");
165  //UImanager->ApplyCommand("/vis/viewer/addCutawayPlane 0 0 7 m 0 -1 0");
166 
167  ui->SessionStart();
168 
169  delete ui; delete visManager; delete runManager;
170 
171  return 0;
172 } // main()
173 
174 // ---------------------------------------------------------------------------------------