EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Fun4All_G4_simplified_v2_DIRC_barrel_GEM.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Fun4All_G4_simplified_v2_DIRC_barrel_GEM.C
1 /*
2 ================================================================================================================
3 The purpose of this code is to have a version of the all-silicon tracker that is simplified so that we can study
4 different variations of the geometry quickly. Specifically, I wrote this code to study the impact that adding a
5 cylindrical GEM outside the DIRC can have on tracking.
6 ================================================================================================================
7 */
8 #pragma once
9 #include <phgenfit/Track.h>
16 #include <fun4all/Fun4AllServer.h>
17 #include <fun4all/SubsysReco.h>
20 #include <g4histos/G4HitNtuple.h>
23 #include <g4main/PHG4Reco.h>
27 #include <phool/recoConsts.h>
30 #include "G4_BlackHole.C"
31 //#include "../../G4_DIRC.C"
32 #include "G4_DIRC_SMALL.C"
33 
34 R__LOAD_LIBRARY(libfun4all.so)
35 R__LOAD_LIBRARY(libg4detectors.so)
36 R__LOAD_LIBRARY(libg4lblvtx.so)
37 R__LOAD_LIBRARY(libg4trackfastsim.so)
38 
40  int nEvents = -1, // number of events
41  double vtx_matBud = 0.05, // % X/X0 (material budget of vertexing layers)
42  double barr_matBud = 0.55, // % X/X0 (material budget of middle layers)
43  double disk_matBud = 0.25, // % X/X0 (material budget of disk layers)
44  double pmin = 0., // GeV/c
45  double pmax = 30., // GeV/c
46  int magnetic_field = 4, // Magnetic field setting
47  TString out_name = "out_vtx_study") // output filename
48 {
49  // ======================================================================================================
50  // Input from the user
51  const int particle_gen = 1;// 1 = particle generator, 2 = particle gun, 3 = simple event generator, 4 = pythia8 e+p collision, 5 = particle generator flat in pT
52  double pix_size_vtx = 10.; // um - size of pixels in vertexing layers
53  double pix_size_bar = 10.; // um - size of pixels in barrel layers
54  double pix_size_dis = 10.; // um - size of pixels in disk layers
55  bool use_blackhole = false;
56  bool use_barrel_GEM = false;
57  bool use_DIRC = false;
58  // ======================================================================================================
59  // Make the Server
61  // If you want to fix the random seed for reproducibility
62  // recoConsts *rc = recoConsts::instance();
63  // rc->set_IntFlag("RANDOMSEED", 12345);
64  // ======================================================================================================
65  // Particle Generator Setup
67  gen->set_name(std::string("pi-")); // geantino, pi-, pi+, mu-, mu+, e-., e+, proton, ... (currently passed as an input)
68  gen->set_vtx(0,0,0); // Vertex generation range
69  gen->set_mom_range(pmin,pmax); // Momentum generation range in GeV/c
70  gen->set_z_range(0.,0.);
71  gen->set_eta_range(-1.2,1.2);
72  gen->set_phi_range(0,2.*TMath::Pi());
73  // --------------------------------------------------------------------------------------
74  // Particle generator flat in pT
76  gen_pT->set_name(std::string("pi-")); // geantino, pi-, pi+, mu-, mu+, e-., e+, proton, ... (currently passed as an input)
77  gen_pT->set_vtx(0,0,0); // Vertex generation range
78  gen_pT->set_pT_range(.00001,5.); // Momentum generation range in GeV/c
79  gen_pT->set_z_range(0.,0.);
80  gen_pT->set_eta_range(-4,4); // Detector coverage corresponds to |η|< 4
81  gen_pT->set_phi_range(0.,2.*TMath::Pi());
82  // ======================================================================================================
83  if (particle_gen==1){se->registerSubsystem( gen); cout << "Using particle generator" << endl;}
84  else if(particle_gen==5){se->registerSubsystem(gen_pT); cout << "Using particle generator flat in pT" << endl;}
85  else{ cout << "Particle generator option requested has not been implemented. Bailing out!" << endl; exit(0); }
86  // ======================================================================================================
87  if(use_DIRC)
88  DIRCInit();
89  // ======================================================================================================
90  PHG4Reco *g4Reco = new PHG4Reco();
91  //g4Reco->SetWorldMaterial("G4_Galactic");
92  // ======================================================================================================
93  // Magnetic field setting
94  TString B_label;
95  if(magnetic_field==1){ // uniform 1.5T
96  B_label = "_B_1.5T";
97  g4Reco->set_field(1.5);
98  }
99  else if(magnetic_field==2){ // uniform 3.0T
100  B_label = "_B_3.0T";
101  g4Reco->set_field(3.0);
102  }
103  else if(magnetic_field==3){ // sPHENIX 1.4T map
104  B_label = "_sPHENIX";
105  g4Reco->set_field_map(string(getenv("CALIBRATIONROOT")) + string("/Field/Map/sPHENIX.2d.root"), PHFieldConfig::kField2D);
106  g4Reco->set_field_rescale(-1.4/1.5);
107  }
108  else if(magnetic_field==4){ // Beast 3.0T map
109  B_label = "_Beast";
110  g4Reco->set_field_map(string(getenv("CALIBRATIONROOT")) + string("/Field/Map/mfield.4col.dat"), PHFieldConfig::kFieldBeast);
111  }
112  else{ // The user did not provide a valid B field setting
113  cout << "User did not provide a valid magnetic field setting. Set 'magnetic_field'. Bailing out!" << endl;
114  }
115  // ======================================================================================================
116  // Detector setup
118  //---------------------------
119  // Vertexing
120  double si_vtx_r_pos[] = {3.30,5.70};
121  const int nVtxLayers = sizeof(si_vtx_r_pos)/sizeof(*si_vtx_r_pos);
122  double si_z_vtxlength[] = {30.,30.};
123  double si_thick_vtx = vtx_matBud/100.*9.37;
124 
125  for (int ilayer = 0; ilayer < nVtxLayers ; ilayer++){
126  cyl = new PHG4CylinderSubsystem("SVTX", ilayer);
127  cyl->set_string_param("material" , "G4_Si" );
128  cyl->set_double_param("radius" , si_vtx_r_pos[ilayer] );
129  cyl->set_double_param("thickness", si_thick_vtx );
130  cyl->set_double_param("place_z" , 0 );
131  cyl->set_double_param("length" , si_z_vtxlength[ilayer]);
132  cyl->SetActive();
133  cyl->SuperDetector("SVTX");
134  cyl->set_color(0,0.8,0.1);
135  g4Reco->registerSubsystem(cyl);
136  }
137  //---------------------------
138  // Barrel
139  double si_r_pos[] = {21.,22.68,39.3,43.23};
140  const int nTrckLayers = sizeof(si_r_pos)/sizeof(*si_r_pos);
141  double si_z_length[] = {54.,60.,105.,114.};
142  double si_thick_bar = barr_matBud/100.*9.37;
143 
144  for (int ilayer = 0; ilayer < nTrckLayers ; ilayer++){
145  cyl = new PHG4CylinderSubsystem("BARR", ilayer);
146  cyl->set_string_param("material" , "G4_Si" );
147  cyl->set_double_param("radius" , si_r_pos[ilayer] );
148  cyl->set_double_param("thickness", si_thick_bar );
149  cyl->set_double_param("place_z" , 0 );
150  cyl->set_double_param("length" , si_z_length[ilayer]);
151  cyl->SetActive();
152  cyl->SuperDetector("BARR");
153  cyl->set_color(0,0.5,1);
154  g4Reco->registerSubsystem(cyl);
155  }
156  //---------------------------
157  // Disks
158  double si_z_pos[] = {-121.,-97.,-73.,-49.,-25.,25.,49.,73.,97.,121.};
159  double si_r_max[10] = {0};
160  double si_r_min[10] = {0};
161  double si_thick_disk = disk_matBud/100.*9.37;
162  for(int i = 0 ; i < 10 ; i++){
163  si_r_max[i] = TMath::Min(43.23,18.5*abs(si_z_pos[i])/si_z_pos[5]);
164 
165  if(si_z_pos[i]>66.8&&si_z_pos[i]>0) si_r_min[i] = (0.05025461*si_z_pos[i]-0.180808);
166  else if(si_z_pos[i]>0) si_r_min[i] = 3.18;
167  else if(si_z_pos[i]<-79.8&&si_z_pos[i]<0) si_r_min[i] = (-0.0297039*si_z_pos[i]+0.8058281);
168  else si_r_min[i] = 3.18;
169 
170  si_r_max[i] -= si_r_min[i];
171  }
172  for (int ilayer = 0; ilayer < 10; ilayer++){
173  cyl = new PHG4CylinderSubsystem("FBVS", ilayer);
174  cyl->set_string_param("material" , "G4_Si" );
175  cyl->set_double_param("radius" , si_r_min[ilayer]);
176  cyl->set_double_param("thickness", si_r_max[ilayer]);
177  cyl->set_double_param("place_z" , si_z_pos[ilayer]);
178  cyl->set_double_param("length" , si_thick_disk );
179  cyl->SetActive();
180  cyl->SuperDetector("FBST");
181  cyl->set_color(1,0,0);
182  g4Reco->registerSubsystem(cyl);
183  }
184  //---------------------------
185  // Cylindrical GEM outside DIRC
186  double barrel_GEM_inner_radius = 60.; // GEM radius
187  double barrel_GEM_radial_thick = si_thick_bar*3.;
188  double barrel_GEM_z_length = 121.;
189  cyl = new PHG4CylinderSubsystem("BARR_GEM",1);
190  cyl->set_string_param("material" , "G4_Si" );
191  cyl->set_double_param("radius" , barrel_GEM_inner_radius);
192  cyl->set_double_param("thickness", barrel_GEM_radial_thick);
193  cyl->set_double_param("place_z" , 0 );
194  cyl->set_double_param("length" , 2.*barrel_GEM_z_length );
195  cyl->SetActive();
196  cyl->SuperDetector("BARR_GEM");
197  cyl->set_color(0,0.5,1);
198  g4Reco->registerSubsystem(cyl);
199  //---------------------------
200  // Black hole to suck loopers out of their misery
201  double BH_r = si_r_pos[nTrckLayers-1]+2;
202  double BH_zmin = si_z_pos[0]-2;
203  double BH_zmax = si_z_pos[sizeof(si_z_pos)/sizeof(*si_z_pos)-1]+2;
204  if(use_blackhole)
205  wrap_with_cylindrical_blackhole(g4Reco,BH_r,BH_zmin,BH_zmax);
206 
207  //---------------------------
208  // mid-rapidity beryllium pipe
209  double be_pipe_radius = 3.1000;
210  double be_pipe_thickness = 3.1762 - be_pipe_radius; // 760 um for sPHENIX
211  double be_pipe_length_plus = 66.8; // +z beam pipe extend.
212  double be_pipe_length_neg = -79.8; // -z beam pipe extend.
213  double be_pipe_length = be_pipe_length_plus - be_pipe_length_neg;
214  double be_pipe_center = 0.5 * (be_pipe_length_plus + be_pipe_length_neg);
215 
216  cyl = new PHG4CylinderSubsystem("BE_PIPE", 1);
217  cyl->set_double_param("radius", be_pipe_radius);
218  cyl->set_int_param("lengthviarapidity", 0);
219  cyl->set_double_param("length", be_pipe_length);
220  cyl->set_double_param("place_z", be_pipe_center);
221  cyl->set_string_param("material", "G4_Be");
222  cyl->set_double_param("thickness", be_pipe_thickness);
223  cyl->SuperDetector("PIPE");
224  g4Reco->registerSubsystem(cyl);
225  //---------------------------
226 
227  // ------------
228  // Al Support Structure
229  AllSi_Al_support_Subsystem *Al_supp = new AllSi_Al_support_Subsystem("Al_supp");
230  g4Reco->registerSubsystem(Al_supp);
231  // ------------
232  if(use_DIRC)
233  double dirc_out_skin = DIRCSetup(g4Reco);
234  // ------------
235 
236  PHG4TruthSubsystem *truth = new PHG4TruthSubsystem();
237  g4Reco->registerSubsystem(truth);
238 
239  se->registerSubsystem(g4Reco);
240 
241  //---------------------------
242  // fast pattern recognition and full Kalman filter
243  // output evaluation file for truth track and reco tracks are PHG4TruthInfoContainer
244  //---------------------------
245  PHG4TrackFastSim *kalman = new PHG4TrackFastSim("PHG4TrackFastSim");
246  kalman->set_use_vertex_in_fitting(false);
247  kalman->set_sub_top_node_name("BARR");
248  kalman->set_trackmap_out_name("SvtxTrackMap");
249 
250  // add Vertexing Layers
251  kalman->add_phg4hits(
252  "G4HIT_SVTX", // const std::string& phg4hitsNames,
254  999., // radial-resolution [cm]
255  pix_size_vtx/10000./sqrt(12.), // azimuthal-resolution [cm]
256  pix_size_vtx/10000./sqrt(12.), // z-resolution [cm]
257  1, // efficiency,
258  0 // noise hits
259  );
260 
261  // add Barrel Layers
262  kalman->add_phg4hits(
263  "G4HIT_BARR", // const std::string& phg4hitsNames,
265  999., // radial-resolution [cm]
266  pix_size_bar/10000./sqrt(12.), // azimuthal-resolution [cm]
267  pix_size_bar/10000./sqrt(12.), // z-resolution [cm]
268  1, // efficiency,
269  0 // noise hits
270  );
271 
272  // add Disk Layers
273  kalman->add_phg4hits(
274  "G4HIT_FBST", // const std::string& phg4hitsNames,
276  pix_size_dis/10000./sqrt(12.), // radial-resolution [cm]
277  pix_size_dis/10000./sqrt(12.), // azimuthal-resolution [cm]
278  999., // z-resolution [cm]
279  1, // efficiency,
280  0 // noise hits
281  );
282 
283  // add barrel GEM layer
284  if(use_barrel_GEM){
285  kalman->add_phg4hits(
286  "G4HIT_BARR_GEM", // const std::string& phg4hitsNames,
288  999., // radial-resolution [cm]
289  50e-4, // azimuthal-resolution [cm]
290  50e-4, // z-resolution [cm]
291  1, // efficiency,
292  0
293  );
294  }
295  // Mom. res.
296  //kalman->set_use_vertex_in_fitting(true);
297  //kalman->set_vertex_xy_resolution(50e-4);
298  //kalman->set_vertex_z_resolution(50e-4);
299  //kalman->enable_vertexing(false); // this is false by default
300  //kalman->set_vertex_min_ndf(10);
301 
302  //kalman->Verbosity(10);
303  kalman->set_use_vertex_in_fitting(false);
304  kalman->set_vertex_xy_resolution(0);
305  kalman->set_vertex_z_resolution(0);
306  kalman->enable_vertexing(false); // this is false by default
307  kalman->set_vertex_min_ndf(2);
308 
309  se->registerSubsystem(kalman);
310 
311  std::string outputFile = (std::string)(out_name)+std::string(B_label)+"_FastSimEval.root";
312 
313  PHG4TrackFastSimEval *fast_sim_eval = new PHG4TrackFastSimEval("FastTrackingEval");
314  fast_sim_eval->set_filename(outputFile);
315  se->registerSubsystem(fast_sim_eval);
316 
317  // ======================================================================================================
318  // IOManagers...
319  const std::string dst_name = std::string(out_name)+std::string(B_label)+"_G4LBLVtx.root";
320  Fun4AllDstOutputManager *out = new Fun4AllDstOutputManager("DSTOUT",dst_name);
321  out->Verbosity(0);
322  se->registerOutputManager(out);
323 
325  se->registerInputManager(in);
326 
327  if (nEvents <= 0) return;
328 
329  se->run(nEvents);
330  se->End();
331  delete se;
332 
333  gSystem->Exit(0);
334 }