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