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