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