Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4Setup_sPHENIX.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4Setup_sPHENIX.C
1 
2 double no_overlapp = 0.0001; // added to radii to avoid overlapping volumes
3 bool overlapcheck = false; // set to true if you want to check for overlaps
4 
5 void G4Init(bool do_svtx = true,
6  bool do_pstof = true,
7  bool do_cemc = true,
8  bool do_hcalin = true,
9  bool do_magnet = true,
10  bool do_hcalout = true,
11  bool do_pipe = true,
12  int n_TPC_layers = 40)
13  {
14 
15  // load detector/material macros and execute Init() function
16 
17  if (do_pipe)
18  {
19  gROOT->LoadMacro("G4_Pipe.C");
20  PipeInit();
21  }
22  if (do_svtx)
23  {
24  gROOT->LoadMacro("G4_Svtx_maps_ladders+intt_ladders+tpc_KalmanPatRec.C");
25  SvtxInit(n_TPC_layers);
26  }
27 
28  if (do_pstof)
29  {
30  gROOT->LoadMacro("G4_PSTOF.C");
31  PSTOFInit();
32  }
33 
34  if (do_cemc)
35  {
36  gROOT->LoadMacro("G4_CEmc_Spacal.C");
37  CEmcInit(72); // make it 2*2*2*3*3 so we can try other combinations
38  }
39 
40  if (do_hcalin)
41  {
42  gROOT->LoadMacro("G4_HcalIn_ref.C");
43  HCalInnerInit();
44  }
45 
46  if (do_magnet)
47  {
48  gROOT->LoadMacro("G4_Magnet.C");
49  MagnetInit();
50  }
51  if (do_hcalout)
52  {
53  gROOT->LoadMacro("G4_HcalOut_ref.C");
54  HCalOuterInit();
55  }
56 
57 }
58 
59 
60 int G4Setup(const int absorberactive = 0,
61  const string &field ="1.5",
63  const bool do_svtx = true,
64  const bool do_pstof = true,
65  const bool do_cemc = true,
66  const bool do_hcalin = true,
67  const bool do_magnet = true,
68  const bool do_hcalout = true,
69  const bool do_pipe = true,
70  const float magfield_rescale = 1.0) {
71 
72  //---------------
73  // Load libraries
74  //---------------
75 
76  gSystem->Load("libg4detectors.so");
77  gSystem->Load("libg4testbench.so");
78 
79  //---------------
80  // Fun4All server
81  //---------------
82 
84 
85  // read-in HepMC events to Geant4 if there is any
86  HepMCNodeReader *hr = new HepMCNodeReader();
87  se->registerSubsystem(hr);
88 
89  PHG4Reco* g4Reco = new PHG4Reco();
90  g4Reco->set_rapidity_coverage(1.1); // according to drawings
91 // uncomment to set QGSP_BERT_HP physics list for productions
92 // (default is QGSP_BERT for speed)
93  // g4Reco->SetPhysicsList("QGSP_BERT_HP");
95  g4Reco->set_force_decay(decayType);
96  }
97 
98  double fieldstrength;
99  istringstream stringline(field);
100  stringline >> fieldstrength;
101  if (stringline.fail()) { // conversion to double fails -> we have a string
102 
103  if (field.find("sPHENIX.root") != string::npos) {
104  g4Reco->set_field_map(field, 1);
105  } else {
106  g4Reco->set_field_map(field, 2);
107  }
108  } else {
109  g4Reco->set_field(fieldstrength); // use const soleniodal field
110  }
112 
113  double radius = 0.;
114 
115  //----------------------------------------
116  // PIPE
117  if (do_pipe) radius = Pipe(g4Reco, radius, absorberactive);
118 
119  //----------------------------------------
120  // SVTX
121  if (do_svtx) radius = Svtx(g4Reco, radius, absorberactive);
122 
123  //----------------------------------------
124  // PSTOF
125 
126  if (do_pstof) radius = PSTOF(g4Reco, radius, absorberactive);
127 
128  //----------------------------------------
129  // CEMC
130 //
131  if (do_cemc) radius = CEmc(g4Reco, radius, 8, absorberactive);
132 // if (do_cemc) radius = CEmc_Vis(g4Reco, radius, 8, absorberactive);// for visualization substructure of SPACAL, slow to render
133 
134  //----------------------------------------
135  // HCALIN
136 
137  if (do_hcalin) radius = HCalInner(g4Reco, radius, 4, absorberactive);
138 
139  //----------------------------------------
140  // MAGNET
141 
142  if (do_magnet) radius = Magnet(g4Reco, radius, 0, absorberactive);
143 
144  //----------------------------------------
145  // HCALOUT
146 
147  if (do_hcalout) radius = HCalOuter(g4Reco, radius, 4, absorberactive);
148 
149  //----------------------------------------
150  // BLACKHOLE
151 
152  // swallow all particles coming out of the backend of sPHENIX
153  PHG4CylinderSubsystem *blackhole = new PHG4CylinderSubsystem("BH", 1);
154 blackhole->set_double_param("radius",radius + 10); // add 10 cm
155 
156  blackhole->set_int_param("lengthviarapidity",0);
157  blackhole->set_double_param("length",g4Reco->GetWorldSizeZ() - no_overlapp); // make it cover the world in length
158  blackhole->BlackHole();
159  blackhole->set_double_param("thickness",0.1); // it needs some thickness
160  blackhole->SetActive(); // always see what leaks out
161  blackhole->OverlapCheck(overlapcheck);
162  g4Reco->registerSubsystem(blackhole);
163 
164  //----------------------------------------
165  // FORWARD BLACKHOLEs
166  // +Z
167  blackhole = new PHG4CylinderSubsystem("BH_FORWARD_PLUS", 1);
168  blackhole->SuperDetector("BH_FORWARD_PLUS");
169  blackhole->set_double_param("radius",0); // add 10 cm
170  blackhole->set_int_param("lengthviarapidity",0);
171  blackhole->set_double_param("length",0.1); // make it cover the world in length
172  blackhole->set_double_param("place_z",g4Reco->GetWorldSizeZ()/2. - 0.1 - no_overlapp);
173  blackhole->BlackHole();
174  blackhole->set_double_param("thickness",radius - no_overlapp); // it needs some thickness
175  blackhole->SetActive(); // always see what leaks out
176  blackhole->OverlapCheck(overlapcheck);
177  g4Reco->registerSubsystem(blackhole);
178 
179  blackhole = new PHG4CylinderSubsystem("BH_FORWARD_NEG", 1);
180  blackhole->SuperDetector("BH_FORWARD_NEG");
181  blackhole->set_double_param("radius",0); // add 10 cm
182  blackhole->set_int_param("lengthviarapidity",0);
183  blackhole->set_double_param("length",0.1); // make it cover the world in length
184  blackhole->set_double_param("place_z", - g4Reco->GetWorldSizeZ()/2. +0.1 + no_overlapp);
185  blackhole->BlackHole();
186  blackhole->set_double_param("thickness",radius - no_overlapp); // it needs some thickness
187  blackhole->SetActive(); // always see what leaks out
188  blackhole->OverlapCheck(overlapcheck);
189  g4Reco->registerSubsystem(blackhole);
190 
191  PHG4TruthSubsystem *truth = new PHG4TruthSubsystem();
192  g4Reco->registerSubsystem(truth);
193  se->registerSubsystem( g4Reco );
194 }
195 
196 void ShowerCompress(int verbosity = 0) {
197 
198  gSystem->Load("libfun4all.so");
199  gSystem->Load("libg4eval.so");
200 
202 
203  PHG4DstCompressReco* compress = new PHG4DstCompressReco("PHG4DstCompressReco");
204  compress->AddHitContainer("G4HIT_PIPE");
205  compress->AddHitContainer("G4HIT_SVTXSUPPORT");
206  compress->AddHitContainer("G4HIT_CEMC_ELECTRONICS");
207  compress->AddHitContainer("G4HIT_CEMC");
208  compress->AddHitContainer("G4HIT_ABSORBER_CEMC");
209  compress->AddHitContainer("G4HIT_CEMC_SPT");
210  compress->AddHitContainer("G4HIT_ABSORBER_HCALIN");
211  compress->AddHitContainer("G4HIT_HCALIN");
212  compress->AddHitContainer("G4HIT_HCALIN_SPT");
213  compress->AddHitContainer("G4HIT_MAGNET");
214  compress->AddHitContainer("G4HIT_ABSORBER_HCALOUT");
215  compress->AddHitContainer("G4HIT_HCALOUT");
216  compress->AddHitContainer("G4HIT_BH_1");
217  compress->AddHitContainer("G4HIT_BH_FORWARD_PLUS");
218  compress->AddHitContainer("G4HIT_BH_FORWARD_NEG");
219  compress->AddCellContainer("G4CELL_CEMC");
220  compress->AddCellContainer("G4CELL_HCALIN");
221  compress->AddCellContainer("G4CELL_HCALOUT");
222  compress->AddTowerContainer("TOWER_SIM_CEMC");
223  compress->AddTowerContainer("TOWER_RAW_CEMC");
224  compress->AddTowerContainer("TOWER_CALIB_CEMC");
225  compress->AddTowerContainer("TOWER_SIM_HCALIN");
226  compress->AddTowerContainer("TOWER_RAW_HCALIN");
227  compress->AddTowerContainer("TOWER_CALIB_HCALIN");
228  compress->AddTowerContainer("TOWER_SIM_HCALOUT");
229  compress->AddTowerContainer("TOWER_RAW_HCALOUT");
230  compress->AddTowerContainer("TOWER_CALIB_HCALOUT");
231  se->registerSubsystem(compress);
232 
233  return;
234 }
235 
237  if (out) {
238  out->StripNode("G4HIT_PIPE");
239  out->StripNode("G4HIT_SVTXSUPPORT");
240  out->StripNode("G4HIT_CEMC_ELECTRONICS");
241  out->StripNode("G4HIT_CEMC");
242  out->StripNode("G4HIT_ABSORBER_CEMC");
243  out->StripNode("G4HIT_CEMC_SPT");
244  out->StripNode("G4HIT_ABSORBER_HCALIN");
245  out->StripNode("G4HIT_HCALIN");
246  out->StripNode("G4HIT_HCALIN_SPT");
247  out->StripNode("G4HIT_MAGNET");
248  out->StripNode("G4HIT_ABSORBER_HCALOUT");
249  out->StripNode("G4HIT_HCALOUT");
250  out->StripNode("G4HIT_BH_1");
251  out->StripNode("G4HIT_BH_FORWARD_PLUS");
252  out->StripNode("G4HIT_BH_FORWARD_NEG");
253  out->StripNode("G4CELL_CEMC");
254  out->StripNode("G4CELL_HCALIN");
255  out->StripNode("G4CELL_HCALOUT");
256  }
257 }