EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Extract_ECCE_gdml.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Extract_ECCE_gdml.C
1 #ifndef EXTRACT_ECCE_GDML_C
2 #define EXTRACT_ECCE_GDML_C
3 
4 #include <GlobalVariables.C>
5 
6 #include <G4Setup_EICDetector.C>
7 #include <G4_Global.C>
8 #include <G4_Input.C>
9 #include <G4_Production.C>
10 #include <G4_User.C>
11 
12 #include <TROOT.h>
15 #include <fun4all/Fun4AllServer.h>
16 
17 #include <phool/recoConsts.h>
18 
19 #include <RooUnblindPrecision.h>
20 
21 R__LOAD_LIBRARY(libfun4all.so)
22 
23 // Get all subsystem options with
24 // grep 'if ( subsys==' Extract_ECCE_gdml.C | cut -d'"' -f 2
25 // To create them all, run
26 /*
27 foreach s ( all pipe magnet magfarfwd magfarbwd gems tracking tofs becal hcalin hcalout dirc femc drcalo lfhcal eemc ehcal )
28  root -l -b -q Extract_ECCE_gdml.C\(\"$s\"\)
29 end
30 */
31 
32 //
33 // Older GEANT versions have a bug that can be patched,
34 // see https://geant4-forum.web.cern.ch/t/are-constant-material-properties-missing-a-hash-in-the-name-for-gdml/699/4
35 // You can also fix it by hand using
36 // sed -i.bak 's/constant/matrix coldim="1"/g' *gdml
37 
38 int Extract_ECCE_gdml( string subsys="all", const string outbase="")
39 {
40 
41  // Make the subsystem case-insensitive
42  for (auto & c: subsys) c = tolower(c);
43 
44  // output filename
45  string outname = "";
46  if ( subsys=="all" ) outname = "ecce.gdml";
47 
48  //---------------
49  // Fun4All server
50  //---------------
52  se->Verbosity(0);
53 
55  // By default every random number generator uses
56  // PHRandomSeed() which reads /dev/urandom to get its seed
57  // if the RANDOMSEED flag is set its value is taken as initial seed
58  // which will produce identical results so you can debug your code
59  rc->set_IntFlag("RANDOMSEED", 42);
60 
61  //===============
62  // Input options
63  //===============
64 
65  // switching IPs by comment/uncommenting the following lines
66  // used for both beamline setting and for the event generator crossing boost
67  Enable::IP6 = true;
68  // Enable::IP8 = true;
69 
70  //======================
71  // What to run
72  //======================
73  // Global options (enabled for all subsystems - if implemented)
74  // Enable::ABSORBER = true;
75  // Enable::OVERLAPCHECK = true;
76  // Enable::VERBOSITY = 1;
77 
78  if ( subsys=="pipe" || subsys=="all" ) {
79  if (outname=="") outname = "ecce_" + subsys + ".gdml";
80  // whether to simulate the Be section of the beam pipe
81  Enable::PIPE = true;
82  // If need to disable EIC beam pipe extension beyond the Be-section:
84  //EIC hadron far forward magnets and detectors. IP6 and IP8 are incompatible (pick either or);
85  }
86 
87  if ( subsys=="magfarfwd" || subsys=="all" ) {
88  if (outname=="") outname = "ecce_" + subsys + ".gdml";
91  }
92 
93  if ( subsys=="magfarbwd" || subsys=="all" ) {
94  if (outname=="") outname = "ecce_" + subsys + ".gdml";
95  Enable::HFARBWD_MAGNETS = true;
96  Enable::HFARBWD_VIRTUAL_DETECTORS = true;
97  }
98 
99  if ( subsys=="gems" || subsys=="all" ) {
100  if (outname=="") outname = "ecce_" + subsys + ".gdml";
101  // gems
102  Enable::EGEM = true;
103  Enable::FGEM = true;
104  // Enable::BGEM = true; // not yet defined in this model
105  }
106 
107  if ( subsys=="tracking" || subsys=="all" ) {
108  if (outname=="") outname = "ecce_" + subsys + ".gdml";
109  Enable::RWELL = true;
110  // barrel tracker
112  // Enable::TrackingService_VERBOSITY = INT_MAX - 10;
113  Enable::BARREL = true;
114  // fst
115  Enable::FST = true;
116  }
117 
118  if ( subsys=="tofs" || subsys=="all" ) {
119  if (outname=="") outname = "ecce_" + subsys + ".gdml";
120  // TOFs
121  Enable::FTTL = true;
122  Enable::ETTL = true;
123  Enable::CTTL = true;
126  }
127 
128  Enable::TRACKING = true;
130  G4TRACKING::DISPLACED_VERTEX = true; // this option exclude vertex in the track fitting and use RAVE to reconstruct primary and 2ndary vertexes
131  // projections to calorimeters
133  G4TRACKING::PROJECTION_BECAL = true;
136  G4TRACKING::PROJECTION_HCALOUT = true;
139  G4TRACKING::PROJECTION_LFHCAL = true;
140 
141  if ( subsys=="becal" || subsys=="all" ) {
142  if (outname=="") outname = "ecce_" + subsys + ".gdml";
143  Enable::BECAL = true;
148  }
149 
150  if ( subsys=="hcalin" || subsys=="all" ) {
151  if (outname=="") outname = "ecce_" + subsys + ".gdml";
152  Enable::HCALIN = true;
153  // Enable::HCALIN_ABSORBER = true;
158  }
159 
160  if ( subsys=="magnet" || subsys=="all" ) {
161  if (outname=="") outname = "ecce_" + subsys + ".gdml";
162  Enable::MAGNET = true;
163  }
164 
165  if ( subsys=="hcalout" || subsys=="all" ) {
166  if (outname=="") outname = "ecce_" + subsys + ".gdml";
167  Enable::HCALOUT = true;
168  // Enable::HCALOUT_ABSORBER = true;
173  }
174 
175  if ( subsys=="dirc" || subsys=="all" ) {
176  if (outname=="") outname = "ecce_" + subsys + ".gdml";
177  // EICDetector geometry - barrel
178  Enable::DIRC = true;
179  Enable::DIRC_RECO = Enable::DIRC && true;
180  // Enable::DIRC_VERBOSITY = 2;
181 
182  // EICDetector geometry - 'hadron' direction
183  Enable::RICH = true;
184  Enable::RICH_RECO = Enable::DIRC && true;
185  // Enable::RICH_VERBOSITY = 2;
186 
187  // EICDetector geometry - 'electron' direction
188  Enable::mRICH = true;
189  Enable::mRICH_RECO = Enable::DIRC && true;
190  // Enable::mRICH_VERBOSITY = 2;
191  }
192 
193  if ( subsys=="femc" || subsys=="all" ) {
194  if (outname=="") outname = "ecce_" + subsys + ".gdml";
195  Enable::FEMC = true;
196  // Enable::FEMC_ABSORBER = true;
200  }
201 
202  // if ( subsys=="drcalo" || subsys=="all" ) {
203  if ( subsys=="drcalo" ) {
204  if (outname=="") outname = "ecce_" + subsys + ".gdml";
205  Enable::DRCALO = true;
211  }
212 
213  if ( subsys=="lfhcal" || subsys=="all" ) {
214  if (outname=="") outname = "ecce_" + subsys + ".gdml";
215  Enable::LFHCAL = true;
216  Enable::LFHCAL_ABSORBER = false;
221  }
222 
223  if ( subsys=="eemc" || subsys=="all" ) {
224  if (outname=="") outname = "ecce_" + subsys + ".gdml";
225  // EICDetector geometry - 'electron' direction
226  Enable::EEMCH = true;
231  }
232 
233  if ( subsys=="ehcal" || subsys=="all" ) {
234  if (outname=="") outname = "ecce_" + subsys + ".gdml";
235  Enable::EHCAL = true;
240  }
241 
242  Enable::FFR_EVAL = Enable::HFARFWD_MAGNETS && Enable::HFARFWD_VIRTUAL_DETECTORS && true;
243 
244  Enable::PLUGDOOR = false;
245 
246 
247  // new settings using Enable namespace in GlobalVariables.C
248  Enable::BLACKHOLE = true;
249  //Enable::BLACKHOLE_SAVEHITS = false; // turn off saving of bh hits
250  //BlackHoleGeometry::visible = true;
251 
252  // ZDC
253  // Enable::ZDC = true;
254  // Enable::ZDC_DISABLE_BLACKHOLE = true;
255 
256  // B0
257  // Enable::B0_DISABLE_HITPLANE = true;
258  // Enable::B0_FULLHITPLANE = true;
259 
260  //---------------
261  // World Settings
262  //---------------
263  // G4WORLD::PhysicsList = "FTFP_BERT"; //FTFP_BERT_HP best for calo
264  // G4WORLD::WorldMaterial = "G4_AIR"; // set to G4_GALACTIC for material scans
265 
266  //---------------
267  // Magnet Settings
268  //---------------
269 
270  // const string magfield = "1.5"; // alternatively to specify a constant magnetic field, give a float number, which will be translated to solenoidal field in T, if string use as fieldmap name (including path)
271  // G4MAGNET::magfield = string(getenv("CALIBRATIONROOT")) + string("/Field/Map/sPHENIX.2d.root"); // default map from the calibration database
272  G4MAGNET::magfield_rescale = -1.4 / 1.5; // make consistent with expected Babar field strength of 1.4T
273 
274  // At this point we better have a valid target subsystem
275  if ( outname =="" ){
276  cout << "Please specify a valid sub-system. Got:" << subsys << endl;
277  return -1;
278  }
279 
280  // Initialize the selected subsystems
281  G4Init();
282  G4Setup();
283 
284  //------------------
285  // Detector Division
286  //------------------
288 
290 
292 
293  //-----------------------------
294  // CEMC towering and clustering
295  //-----------------------------
296 
299 
300  //-----------------------------
301  // HCAL towering and clustering
302  //-----------------------------
303 
306 
309 
310  //-----------------------------
311  // e, h direction Calorimeter towering and clustering
312  //-----------------------------
313 
316 
319 
322 
325 
328 
331 
334 
337 
339 
340  // Need to run to get the full PH4Reco
341  se->run(1);
342 
343 
344  //-------
345  // Export
346  //-------
347 
348  // freaks out if the file exists
349  outname = outbase + outname;
350  gSystem->Unlink(outname.c_str());
351 
352  PHG4Reco *g4 = (PHG4Reco *) se->getSubsysReco("PHG4RECO");
353  g4->Dump_G4_GDML(outname);
354 
355  //-----
356  // Exit
357  //-----
358 
359  se->End();
360  std::cout << "All done" << std::endl;
361  delete se;
362  gSystem->Exit(0);
363  return 0;
364 }
365 #endif // EXTRACT_ECCE_GDML_C