Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4Setup_fsPHENIX.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4Setup_fsPHENIX.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_cemc = true,
7  bool do_hcalin = true,
8  bool do_magnet = true,
9  bool do_hcalout = true,
10  bool do_pipe = true,
11  bool do_FGEM = true,
12  bool do_FEMC = true,
13  bool do_FHCAL = true,
14  int n_TPC_layers = 40) {
15 
16  // load detector/material macros and execute Init() function
17 
18  if (do_pipe)
19  {
20  gROOT->LoadMacro("G4_Pipe.C");
21  PipeInit();
22  }
23  if (do_svtx)
24  {
25  gROOT->LoadMacro("G4_Svtx_maps_ladders+intt_ladders+tpc_KalmanPatRec.C");
26  SvtxInit(n_TPC_layers);
27  }
28 
29  if (do_cemc)
30  {
31  gROOT->LoadMacro("G4_CEmc_Spacal.C");
32  CEmcInit(72); // make it 2*2*2*3*3 so we can try other combinations
33  }
34 
35  if (do_hcalin)
36  {
37  gROOT->LoadMacro("G4_HcalIn_ref.C");
38  HCalInnerInit();
39  }
40 
41  if (do_magnet)
42  {
43  gROOT->LoadMacro("G4_Magnet.C");
44  MagnetInit();
45  }
46  if (do_hcalout)
47  {
48  gROOT->LoadMacro("G4_HcalOut_ref.C");
49  HCalOuterInit();
50  }
51 
52  if (do_FGEM)
53  {
54  gROOT->LoadMacro("G4_FGEM_fsPHENIX.C");
55  FGEM_Init();
56  }
57 
58  if (do_FEMC)
59  {
60  gROOT->LoadMacro("G4_FEMC.C");
61  FEMCInit();
62  }
63 
64  if (do_FHCAL)
65  {
66  gROOT->LoadMacro("G4_FHCAL.C");
67  FHCALInit();
68  }
69 }
70 
71 
72 int G4Setup(const int absorberactive = 0,
73  const string &field ="1.5",
75  const bool do_svtx = true,
76  const bool do_cemc = true,
77  const bool do_hcalin = true,
78  const bool do_magnet = true,
79  const bool do_hcalout = true,
80  const bool do_pipe = true,
81  const bool do_FGEM = true,
82  const bool do_FEMC = false,
83  const bool do_FHCAL = false,
84  const float magfield_rescale = 1.0) {
85 
86  //---------------
87  // Load libraries
88  //---------------
89 
90  gSystem->Load("libg4detectors.so");
91  gSystem->Load("libg4testbench.so");
92 
93  //---------------
94  // Fun4All server
95  //---------------
96 
98 
99  // read-in HepMC events to Geant4 if there is any
100  HepMCNodeReader *hr = new HepMCNodeReader();
101  se->registerSubsystem(hr);
102 
103  PHG4Reco* g4Reco = new PHG4Reco();
104  g4Reco->save_DST_geometry(true); //Save geometry from Geant4 to DST
105  g4Reco->set_rapidity_coverage(1.1); // according to drawings
106 // uncomment to set QGSP_BERT_HP physics list for productions
107 // (default is QGSP_BERT for speed)
108  // g4Reco->SetPhysicsList("QGSP_BERT_HP");
109 
111  g4Reco->set_force_decay(decayType);
112  }
113 
114  double fieldstrength;
115  istringstream stringline(field);
116  stringline >> fieldstrength;
117  if (stringline.fail()) { // conversion to double fails -> we have a string
118 
119  if (field.find("sPHENIX.root") != string::npos) {
120  g4Reco->set_field_map(field, 1);
121  } else {
122  g4Reco->set_field_map(field, 2);
123  }
124  } else {
125  g4Reco->set_field(fieldstrength); // use const soleniodal field
126  }
128 
129  double radius = 0.;
130 
131  //----------------------------------------
132  // PIPE
133  if (do_pipe) radius = Pipe(g4Reco, radius, absorberactive);
134 
135  //----------------------------------------
136  // SVTX
137  if (do_svtx) radius = Svtx(g4Reco, radius, absorberactive);
138 
139  //----------------------------------------
140  // CEMC
141 //
142  if (do_cemc) radius = CEmc(g4Reco, radius, 8, absorberactive);
143 // if (do_cemc) radius = CEmc_Vis(g4Reco, radius, 8, absorberactive);// for visualization substructure of SPACAL, slow to render
144 
145  //----------------------------------------
146  // HCALIN
147 
148  if (do_hcalin) radius = HCalInner(g4Reco, radius, 4, absorberactive);
149 
150  //----------------------------------------
151  // MAGNET
152 
153  if (do_magnet) radius = Magnet(g4Reco, radius, 0, absorberactive);
154 
155  //----------------------------------------
156  // HCALOUT
157 
158  if (do_hcalout) radius = HCalOuter(g4Reco, radius, 4, absorberactive);
159 
160  //----------------------------------------
161  // Forward tracking
162 
163  if ( do_FGEM )
164  FGEMSetup(g4Reco);
165 
166  //----------------------------------------
167  // FEMC
168 
169  if ( do_FEMC )
170  FEMCSetup(g4Reco, absorberactive);
171 
172  //----------------------------------------
173  // FHCAL
174 
175  if ( do_FHCAL )
176  FHCALSetup(g4Reco, absorberactive);
177 
178  // sPHENIX forward flux return(s)
179  PHG4CylinderSubsystem *flux_return_plus = new PHG4CylinderSubsystem("FWDFLUXRET", 0);
180  flux_return_plus->set_int_param("lengthviarapidity",0);
181  flux_return_plus->set_double_param("length",10.2);
182  flux_return_plus->set_double_param("radius",2.1);
183  flux_return_plus->set_double_param("thickness",263.5-5.0);
184  flux_return_plus->set_double_param("place_z",335.9);
185  flux_return_plus->set_string_param("material","G4_Fe");
186  flux_return_plus->SetActive(false);
187  flux_return_plus->SuperDetector("FLUXRET_ETA_PLUS");
188  flux_return_plus->OverlapCheck(overlapcheck);
189  g4Reco->registerSubsystem(flux_return_plus);
190 
191  PHG4CylinderSubsystem *flux_return_minus = new PHG4CylinderSubsystem("FWDFLUXRET", 0);
192  flux_return_minus->set_int_param("lengthviarapidity",0);
193  flux_return_minus->set_double_param("length",10.2);
194  flux_return_minus->set_double_param("radius",2.1);
195  flux_return_minus->set_double_param("place_z",-335.9);
196  flux_return_minus->set_double_param("thickness",263.5-5.0);
197  flux_return_minus->set_string_param("material","G4_Fe");
198  flux_return_minus->SetActive(false);
199  flux_return_minus->SuperDetector("FLUXRET_ETA_MINUS");
200  flux_return_minus->OverlapCheck(overlapcheck);
201  g4Reco->registerSubsystem(flux_return_minus);
202 
203  //----------------------------------------
204  // piston magnet
205  make_piston("magpiston", g4Reco);
206 
207  //----------------------------------------
208  // BLACKHOLE
209 
210  // swallow all particles coming out of the backend of sPHENIX
211  PHG4CylinderSubsystem *blackhole = new PHG4CylinderSubsystem("BH", 1);
212 blackhole->set_double_param("radius",radius + 10); // add 10 cm
213 
214  blackhole->set_int_param("lengthviarapidity",0);
215  blackhole->set_double_param("length",g4Reco->GetWorldSizeZ() - no_overlapp); // make it cover the world in length
216  blackhole->BlackHole();
217  blackhole->set_double_param("thickness",0.1); // it needs some thickness
218  blackhole->SetActive(); // always see what leaks out
219  blackhole->OverlapCheck(overlapcheck);
220  g4Reco->registerSubsystem(blackhole);
221 
222  //----------------------------------------
223  // FORWARD BLACKHOLEs
224  // +Z
225  blackhole = new PHG4CylinderSubsystem("BH_FORWARD_PLUS", 1);
226  blackhole->SuperDetector("BH_FORWARD_PLUS");
227  blackhole->set_double_param("radius",0); // add 10 cm
228  blackhole->set_int_param("lengthviarapidity",0);
229  blackhole->set_double_param("length",0.1); // make it cover the world in length
230  blackhole->set_double_param("place_z",g4Reco->GetWorldSizeZ()/2. - 0.1 - no_overlapp);
231  blackhole->BlackHole();
232  blackhole->set_double_param("thickness",radius - no_overlapp); // it needs some thickness
233  blackhole->SetActive(); // always see what leaks out
234  blackhole->OverlapCheck(overlapcheck);
235  g4Reco->registerSubsystem(blackhole);
236 
237  blackhole = new PHG4CylinderSubsystem("BH_FORWARD_NEG", 1);
238  blackhole->SuperDetector("BH_FORWARD_NEG");
239  blackhole->set_double_param("radius",0); // add 10 cm
240  blackhole->set_int_param("lengthviarapidity",0);
241  blackhole->set_double_param("length",0.1); // make it cover the world in length
242  blackhole->set_double_param("place_z", - g4Reco->GetWorldSizeZ()/2. +0.1 + no_overlapp);
243  blackhole->BlackHole();
244  blackhole->set_double_param("thickness",radius - no_overlapp); // it needs some thickness
245  blackhole->SetActive(); // always see what leaks out
246  blackhole->OverlapCheck(overlapcheck);
247  g4Reco->registerSubsystem(blackhole);
248 
249  PHG4TruthSubsystem *truth = new PHG4TruthSubsystem();
250  g4Reco->registerSubsystem(truth);
251  se->registerSubsystem( g4Reco );
252 }
253 
254 
255 void ShowerCompress(int verbosity = 0) {
256 
257  gSystem->Load("libfun4all.so");
258  gSystem->Load("libg4eval.so");
259 
261 
262  PHG4DstCompressReco* compress = new PHG4DstCompressReco("PHG4DstCompressReco");
263  compress->AddHitContainer("G4HIT_PIPE");
264  compress->AddHitContainer("G4HIT_SVTXSUPPORT");
265  compress->AddHitContainer("G4HIT_CEMC_ELECTRONICS");
266  compress->AddHitContainer("G4HIT_CEMC");
267  compress->AddHitContainer("G4HIT_ABSORBER_CEMC");
268  compress->AddHitContainer("G4HIT_CEMC_SPT");
269  compress->AddHitContainer("G4HIT_ABSORBER_HCALIN");
270  compress->AddHitContainer("G4HIT_HCALIN");
271  compress->AddHitContainer("G4HIT_HCALIN_SPT");
272  compress->AddHitContainer("G4HIT_MAGNET");
273  compress->AddHitContainer("G4HIT_ABSORBER_HCALOUT");
274  compress->AddHitContainer("G4HIT_HCALOUT");
275  compress->AddHitContainer("G4HIT_BH_1");
276  compress->AddHitContainer("G4HIT_BH_FORWARD_PLUS");
277  compress->AddHitContainer("G4HIT_BH_FORWARD_NEG");
278  compress->AddCellContainer("G4CELL_CEMC");
279  compress->AddCellContainer("G4CELL_HCALIN");
280  compress->AddCellContainer("G4CELL_HCALOUT");
281  compress->AddTowerContainer("TOWER_SIM_CEMC");
282  compress->AddTowerContainer("TOWER_RAW_CEMC");
283  compress->AddTowerContainer("TOWER_CALIB_CEMC");
284  compress->AddTowerContainer("TOWER_SIM_HCALIN");
285  compress->AddTowerContainer("TOWER_RAW_HCALIN");
286  compress->AddTowerContainer("TOWER_CALIB_HCALIN");
287  compress->AddTowerContainer("TOWER_SIM_HCALOUT");
288  compress->AddTowerContainer("TOWER_RAW_HCALOUT");
289  compress->AddTowerContainer("TOWER_CALIB_HCALOUT");
290 
291  compress->AddHitContainer("G4HIT_FEMC");
292  compress->AddHitContainer("G4HIT_ABSORBER_FEMC");
293  compress->AddHitContainer("G4HIT_FHCAL");
294  compress->AddHitContainer("G4HIT_ABSORBER_FHCAL");
295  compress->AddCellContainer("G4CELL_FEMC");
296  compress->AddCellContainer("G4CELL_FHCAL");
297  compress->AddTowerContainer("TOWER_SIM_FEMC");
298  compress->AddTowerContainer("TOWER_RAW_FEMC");
299  compress->AddTowerContainer("TOWER_CALIB_FEMC");
300  compress->AddTowerContainer("TOWER_SIM_FHCAL");
301  compress->AddTowerContainer("TOWER_RAW_FHCAL");
302  compress->AddTowerContainer("TOWER_CALIB_FHCAL");
303 
304  se->registerSubsystem(compress);
305 
306  return;
307 }
308 
310  if (out) {
311  out->StripNode("G4HIT_PIPE");
312  out->StripNode("G4HIT_SVTXSUPPORT");
313  out->StripNode("G4HIT_CEMC_ELECTRONICS");
314  out->StripNode("G4HIT_CEMC");
315  out->StripNode("G4HIT_ABSORBER_CEMC");
316  out->StripNode("G4HIT_CEMC_SPT");
317  out->StripNode("G4HIT_ABSORBER_HCALIN");
318  out->StripNode("G4HIT_HCALIN");
319  out->StripNode("G4HIT_HCALIN_SPT");
320  out->StripNode("G4HIT_MAGNET");
321  out->StripNode("G4HIT_ABSORBER_HCALOUT");
322  out->StripNode("G4HIT_HCALOUT");
323  out->StripNode("G4HIT_BH_1");
324  out->StripNode("G4HIT_BH_FORWARD_PLUS");
325  out->StripNode("G4HIT_BH_FORWARD_NEG");
326  out->StripNode("G4CELL_CEMC");
327  out->StripNode("G4CELL_HCALIN");
328  out->StripNode("G4CELL_HCALOUT");
329 
330  out->StripNode("G4HIT_FEMC");
331  out->StripNode("G4HIT_ABSORBER_FEMC");
332  out->StripNode("G4HIT_FHCAL");
333  out->StripNode("G4HIT_ABSORBER_FHCAL");
334  out->StripNode("G4CELL_FEMC");
335  out->StripNode("G4CELL_FHCAL");
336  }
337 }
338 
339 int
340 make_piston(string name, PHG4Reco* g4Reco)
341 {
342  double be_pipe_radius = 2.16; // 2.16 cm based on spec sheet
343  double be_pipe_thickness = 0.0760; // 760 um based on spec sheet
344  double be_pipe_length = 80.0; // +/- 40 cm
345 
346  double al_pipe_radius = 2.16; // same as Be pipe
347  double al_pipe_thickness = 0.1600; // 1.6 mm based on spec
348  double al_pipe_length = 88.3; // extension beyond +/- 40 cm
349 
350  const double zpos0 = al_pipe_length + be_pipe_length * 0.5; // first large GEM station
351  const double zpos1 = 305 - 20; // front of forward ECal/MPC
352  const double zpos2 = 335.9 - 10.2 / 2.; // front of the forward field endcap
353  const double calorimeter_hole_diamater = 9.92331 *2; // side length of the middle hole of MPC that can hold the piston. Also the max diameter of the piston in that region
354 
355  const double beampipe_radius = be_pipe_radius;
356 
357  // teeth cone section specific
358  const double number_of_wteeth = 100;
359  const double teeth_thickness = 0.3504 * 2; //2 X0
360  const double eta_inner = -log(tan(atan((beampipe_radius + 0.1) / zpos0) / 2));
361  const double eta_outter = 4.2;
362  const double eta_teeth_outter = 4.05;
363  double pos = zpos0 + (zpos1 - zpos0) / 2;
364 // cout << "MAGNETIC PISTON:" << eta_inner << " " << eta_outter << " " << pos
365 // << endl;
366 
367  PHG4ConeSubsystem *magpiston = new PHG4ConeSubsystem("Piston", 0);
368  magpiston->SetZlength((zpos1 - zpos0) / 2);
369  magpiston->SetPlaceZ((zpos1 + zpos0) / 2);
370  magpiston->SetR1(beampipe_radius,
371  tan(PHG4Sector::Sector_Geometry::eta_to_polar_angle(eta_outter)) * zpos0);
372  magpiston->SetR2(beampipe_radius,
373  tan(PHG4Sector::Sector_Geometry::eta_to_polar_angle(eta_outter)) * zpos1);
374  magpiston->SetMaterial("G4_Fe");
375  magpiston->OverlapCheck(overlapcheck);
376  g4Reco->registerSubsystem(magpiston);
377 
378 // PHG4ConeSubsystem *magpiston = new PHG4ConeSubsystem(name.c_str(), 1);
379 // magpiston->SetZlength((zpos1 - zpos0) / 2);
380 // magpiston->SetPlaceZ(pos);
381 // magpiston->Set_eta_range(eta_outter, eta_inner);
382 // magpiston->SetMaterial("G4_Fe");
383 // magpiston->SuperDetector(name.c_str());
384 // magpiston->SetActive(false);
385 // g4Reco->registerSubsystem(magpiston);
386 
387  pos = zpos0 + 1.0 + teeth_thickness / 2;
388  for (int i = 0; i < number_of_wteeth; i++)
389  {
390  stringstream s;
391  s << name;
392  s << "_teeth_";
393  s << i;
394 
395  magpiston = new PHG4ConeSubsystem(s.str(), i);
396  magpiston->SuperDetector(name);
397  magpiston->SetZlength(teeth_thickness / 2);
398  magpiston->SetPlaceZ(pos);
399  magpiston->SetR1(
400  //
402  * (pos - teeth_thickness / 2), //
404  * (pos - teeth_thickness / 2) //
405  );
406  magpiston->SetR2(
407  //
409  * (pos + teeth_thickness / 2), //
411  * (pos + teeth_thickness / 2) + .1 //
412  );
413  magpiston->SetMaterial("G4_W");
414  magpiston->SuperDetector(name.c_str());
415  magpiston->SetActive(false);
416  magpiston->OverlapCheck(overlapcheck);
417  g4Reco->registerSubsystem(magpiston);
418  pos += ((zpos1 - zpos0 - 10) / number_of_wteeth);
419  }
420 
421  // last piece connect to the field return
422  PHG4CylinderSubsystem *magpiston2 = new PHG4CylinderSubsystem("Piston_EndSection", 0);
423  magpiston2->set_int_param("lengthviarapidity",0);
424  magpiston2->set_double_param("length",zpos2 - zpos1);
425  magpiston2->set_double_param("place_z", (zpos2 + zpos1) / 2.);
426  magpiston2->set_double_param("radius",beampipe_radius);
427  magpiston2->set_double_param("thickness",calorimeter_hole_diamater / 2. - beampipe_radius);
428  magpiston2->set_string_param("material","G4_Fe");
429  magpiston2->SuperDetector(name);
430  magpiston2->SetActive(false);
431  magpiston2->OverlapCheck(overlapcheck);
432  g4Reco->registerSubsystem(magpiston2);
433 
434  return 0;
435 }
436