Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4_Tracking_Cosmics.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4_Tracking_Cosmics.C
1 #ifndef MACRO_G4TRACKING_C
2 #define MACRO_G4TRACKING_C
3 
4 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! NOTICE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
5 // To use, this must be included in BOTH your Fun4All macro AND common/G4_Micromegas.C!
6 
7 R__LOAD_LIBRARY(libg4eval.so)
8 R__LOAD_LIBRARY(libtrack_reco.so)
9 R__LOAD_LIBRARY(libtpccalib.so)
10 R__LOAD_LIBRARY(libqa_modules.so)
11 
12 #include <G4_ActsGeom.C>
13 #include <G4_TPC.C>
14 #include <G4_Mvtx.C>
15 #include <G4_Intt.C>
16 #include <G4_Magnet.C>
17 #include <G4_Micromegas.C>
18 
19 #include <g4eval/SvtxEvaluator.h>
21 #include <g4eval/TrackSeedTrackMapConverter.h>
22 
25 #include <trackreco/PHCASeeding.h>
33 
35 
36 #include <trackermillepedealignment/MakeMilleFiles.h>
37 #include <trackermillepedealignment/HelicalFitter.h>
38 
39 #include <qa_modules/QAG4SimulationTracking.h>
40 #include <qa_modules/QAG4SimulationUpsilon.h>
41 #include <qa_modules/QAG4SimulationVertex.h>
42 
43 #include <fun4all/Fun4AllServer.h>
44 
45 namespace Enable
46 {
47  bool TRACKING_TRACK = false;
48  bool TRACKING_EVAL = false;
50  bool TRACKING_QA = false;
51 } // namespace Enable
52 
53 namespace G4TRACKING
54 {
55  bool use_alignment = false;
57  bool use_truth_tpc_seeding = false;
59  bool SC_CALIBMODE = false;
60 }
61 
63 {
65  // space charge correction
66  /* corrections are applied in the track finding, and via TpcClusterMover before the final track fit */
68  {
69  auto se = Fun4AllServer::instance();
70  auto tpcLoadDistortionCorrection = new TpcLoadDistortionCorrection;
71  tpcLoadDistortionCorrection->set_distortion_filename( G4TPC::correction_filename );
72  se->registerSubsystem(tpcLoadDistortionCorrection);
73  }
74 }
75 
77 {
80 
82  // Default set to full SvtxTrackSeeds. Can be set to
83  // SiliconTrackSeedContainer or TpcTrackSeedContainer
84  converter->setTrackSeedName("SvtxTrackSeedContainer");
85  converter->Verbosity(verbosity);
86  se->registerSubsystem(converter);
87 }
88 
90 {
91  // set up verbosity
93 
94  // get fun4all server instance
95  auto se = Fun4AllServer::instance();
96 
98  {
99  // Assemble TPC clusters into track stubs
101  {
102  // For the TPC, for each truth particle, create a track and associate clusters with it using truth information, write to Svtx track map
103  // track stubs are given the position odf the truth vertex in this module
104  auto pat_rec = new PHTruthTrackSeeding("PHTruthTrackSeedingTpc");
105  pat_rec->Verbosity(verbosity);
106  pat_rec->set_track_map_name("TpcTrackSeedContainer");
107  pat_rec->set_min_layer(G4MVTX::n_maps_layer + G4INTT::n_intt_layer);
109  se->registerSubsystem(pat_rec);
110 
111  } else {
112 
113  auto seeder = new PHCASeeding("PHCASeeding");
114  seeder->set_field_dir(G4MAGNET::magfield_rescale); // to get charge sign right
115  if (G4MAGNET::magfield.find("3d") != std::string::npos)
116  {
117  seeder->set_field_dir(-1 * G4MAGNET::magfield_rescale);
118  }
119  seeder->Verbosity(verbosity);
120  seeder->SetLayerRange(7, 55);
121  seeder->SetSearchWindow(50., 1.); // (z width, phi width)
122  seeder->SetMinHitsPerCluster(0);
123  seeder->SetMinClustersPerTrack(3);
124  seeder->useConstBField(false);
125  seeder->useFixedClusterError(true);
126  se->registerSubsystem(seeder);
127 
128  // expand stubs in the TPC using simple kalman filter
129  auto cprop = new PHSimpleKFProp("PHSimpleKFProp");
130  cprop->set_field_dir(G4MAGNET::magfield_rescale);
131  if (G4MAGNET::magfield.find("3d") != std::string::npos)
132  {
133  cprop->set_field_dir(-1 * G4MAGNET::magfield_rescale);
134  }
135  cprop->useConstBField(false);
136  cprop->useFixedClusterError(true);
137  cprop->set_max_window(5.);
138  cprop->set_cluster_version(G4TRACKING::cluster_version);
139  cprop->Verbosity(verbosity);
140  se->registerSubsystem(cprop);
141  }
142 
143  PHSiliconHelicalPropagator* hprop = new PHSiliconHelicalPropagator("HelicalPropagator");
144  hprop->Verbosity(verbosity);
145  se->registerSubsystem(hprop);
146 
147  // Associate Micromegas clusters with the tracks
148  if( Enable::MICROMEGAS )
149  {
150  std::cout << "Tracking_Reco_TrackSeed - Using Micromegas matching " << std::endl;
151 
152  // Match TPC track stubs from CA seeder to clusters in the micromegas layers
153  auto mm_match = new PHMicromegasTpcTrackMatching;
154  mm_match->Verbosity(verbosity);
156  {
157  // configuration is potentially with different search windows
158  mm_match->set_rphi_search_window_lyr1(0.2);
159  mm_match->set_rphi_search_window_lyr2(13.0);
160  mm_match->set_z_search_window_lyr1(26.0);
161  mm_match->set_z_search_window_lyr2(0.2);
162  } else {
163  // baseline configuration is (0.2, 13.0, 26, 0.2) and is the default
164  mm_match->set_rphi_search_window_lyr1(0.2);
165  mm_match->set_rphi_search_window_lyr2(13.0);
166  mm_match->set_z_search_window_lyr1(26.0);
167  mm_match->set_z_search_window_lyr2(0.2);
168  }
169  mm_match->set_min_tpc_layer(38); // layer in TPC to start projection fit
170  mm_match->set_test_windows_printout(false); // used for tuning search windows only
171  se->registerSubsystem(mm_match);
172  }
173 
174  } else {
175 
176  // full truth track finding
177  std::cout << "Tracking_Reco_TrackSeed - Using full truth track seeding" << std::endl;
178 
179  // For each truth particle, create a track and associate clusters with it using truth information, write to Svtx track map
180  // track stubs are given the position of the truth vertex in this module, but Genfit does not care
181  // Includes clusters for TPC, silicon and MM's
182  auto pat_rec = new PHTruthTrackSeeding("PHTruthTrackSeedingFull");
183  pat_rec->Verbosity(verbosity);
184  pat_rec->set_track_map_name("SvtxTrackSeedContainer");
185  se->registerSubsystem(pat_rec);
186 
187  }
188 
189  /*
190  * all done
191  * at this stage tracks are fully assembled. They contain clusters spaning Silicon detectors, TPC and Micromegas
192  * they are ready to be fit.
193  */
194  convert_seeds();
195 }
196 
197 void vertexing()
198 {
199  // SvtxEvaluator will not run without vertexing, even though it produces nothing useful in this case
202  auto vtxfinder = new PHSimpleVertexFinder;
203  vtxfinder->Verbosity(verbosity);
204  se->registerSubsystem(vtxfinder);
205 }
206 
207 void alignment(std::string datafilename = "mille_output_data_file",
208  std::string steeringfilename = "mille_steer")
209 {
212 
213  auto mille = new MakeMilleFiles;
214  mille->Verbosity(verbosity);
215  mille->set_datafile_name(datafilename + ".bin");
216  mille->set_steeringfile_name(steeringfilename + ".txt");
217  se->registerSubsystem(mille);
218 
219  auto helical = new HelicalFitter;
220  helical->Verbosity(verbosity);
221  helical->set_datafile_name(datafilename + "_helical.bin");
222  helical->set_steeringfile_name(steeringfilename + "_helical.txt");
223  se->registerSubsystem(helical);
224 
225 }
226 
228 {
230  vertexing();
232 }
233 
235 {
238 
239  // this module builds high level truth track association table.
240  // If this module is used, this table should be called before any evaluator calls.
241  // Removing this module, evaluation will still work but trace truth association through the layers of G4-hit-cluster
243  tables->Verbosity(verbosity);
244  se->registerSubsystem(tables);
245 
246  return;
247 }
248 
249 void Tracking_Eval(const std::string& outputfile)
250 {
252 
253  //---------------
254  // Fun4All server
255  //---------------
256 
259 
260  //----------------
261  // Tracking evaluation
262  //----------------
263  SvtxEvaluator* eval;
264  eval = new SvtxEvaluator("SVTXEVALUATOR", outputfile, "SvtxTrackMap",
269  eval->do_cluster_eval(true);
270  eval->do_g4hit_eval(true);
271  eval->do_hit_eval(true); // enable to see the hits that includes the chamber physics...
272  eval->do_gpoint_eval(true);
273  eval->do_vtx_eval_light(true);
274  eval->do_eval_light(true);
276  bool embed_scan = true;
277  if(TRACKING::pp_mode) embed_scan = false;
278  eval->scan_for_embedded(embed_scan); // take all tracks if false - take only embedded tracks if true
279  eval->scan_for_primaries(embed_scan); // defaults to only thrown particles for ntp_gtrack
280  std::cout << "SvtxEvaluator: pp_mode set to " << TRACKING::pp_mode << " and scan_for_embedded set to " << embed_scan << std::endl;
281  eval->Verbosity(verbosity);
282  eval->set_cluster_version(G4TRACKING::cluster_version);
283 
284  se->registerSubsystem(eval);
285 
286  return;
287 }
288 
290 {
292 
293  //---------------
294  // Fun4All server
295  //---------------
296 
298 
300 
302  // qa->addEmbeddingID(2);
303  qa->Verbosity(verbosity);
304  se->registerSubsystem(qa);
305 
307  // qa2->addEmbeddingID(2);
308  qa2->Verbosity(verbosity);
309  se->registerSubsystem(qa2);
310 
311  // Acts Kalman Filter vertex finder
312  //=================================
314  // qav->addEmbeddingID(2);
315  qav->Verbosity(verbosity);
316  qav->setVertexMapName("SvtxVertexMapActs");
317  se->registerSubsystem(qav);
318 
319  if (Input::UPSILON)
320  {
322 
323  for (int id : Input::UPSILON_EmbedIds)
324  {
325  qa->addEmbeddingID(id);
326  }
327  se->registerSubsystem(qa);
328  }
329 }
330 
331 
332 #endif // MACRO_G4TRACKING_C