Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4_Tracking.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4_Tracking.C
1 #ifndef MACRO_G4TRACKING_C
2 #define MACRO_G4TRACKING_C
3 
4 R__LOAD_LIBRARY(libg4eval.so)
5 R__LOAD_LIBRARY(libtrack_reco.so)
6 R__LOAD_LIBRARY(libtpccalib.so)
7 R__LOAD_LIBRARY(libqa_modules.so)
8 R__LOAD_LIBRARY(libtrackeralign.so)
9 
10 #include <GlobalVariables.C>
11 
12 #include <G4_ActsGeom.C>
13 #include <G4_Intt.C>
14 #include <G4_Micromegas.C>
15 #include <G4_Mvtx.C>
16 #include <G4_TPC.C>
17 #include <QA.C>
18 
19 #include <g4eval/SvtxEvaluator.h>
21 #include <g4eval/TrackSeedTrackMapConverter.h>
22 
28 #include <trackreco/PHCASeeding.h>
41 
43 
45 
46 #include <trackermillepedealignment/MakeMilleFiles.h>
47 #include <trackermillepedealignment/HelicalFitter.h>
48 
49 #include <qa_modules/QAG4SimulationTracking.h>
50 #include <qa_modules/QAG4SimulationUpsilon.h>
51 #include <qa_modules/QAG4SimulationVertex.h>
52 #include <qa_modules/QAG4SimulationDistortions.h>
53 
54 #include <fun4all/Fun4AllServer.h>
55 
57 {
58 
59  std::cout << "G4_Tracking is now obsolete as of macros PR612. "
60  << std::endl << "Please switch to the new scheme for tracking, which is demosntrated in the PR at the following link: www.github.com/sPHENIX-Collaboration/macros/pull/612"
61  << std::endl
62  << "The switch is not difficult and just requires updating your macros repo and adding the new relevant tracking includes into your main Fun4All macro instead of G4_Tracking."
63  << std::endl;
64  gSystem->Exit(1);
65 
67  // space charge correction
68  /* corrections are applied in the track finding, and via TpcClusterMover before the final track fit */
70  {
71  auto se = Fun4AllServer::instance();
72  auto tpcLoadDistortionCorrection = new TpcLoadDistortionCorrection;
73  tpcLoadDistortionCorrection->set_distortion_filename( G4TPC::correction_filename );
74  se->registerSubsystem(tpcLoadDistortionCorrection);
75  }
76 
77 }
78 
80 {
83 
85  // Default set to full SvtxTrackSeeds. Can be set to
86  // SiliconTrackSeedContainer or TpcTrackSeedContainer
87  converter->setTrackSeedName("SvtxTrackSeedContainer");
88  converter->Verbosity(verbosity);
89  se->registerSubsystem(converter);
90 }
91 
93 {
94 
95  // set up verbosity
97 
98  // get fun4all server instance
99  auto se = Fun4AllServer::instance();
100 
102  {
103  // Assemble silicon clusters into track stubs
105  {
106  // For the silicon, for each truth particle, create a track and associate clusters with it using truth information, write to silicon track map
107  // track stubs are given the location of the truth vertex in this module
108  auto pat_rec = new PHTruthTrackSeeding("PHTruthTrackSeedingSilicon");
109  pat_rec->Verbosity(verbosity);
110  pat_rec->set_track_map_name("SiliconTrackSeedContainer");
111  pat_rec->set_min_layer(0);
112  pat_rec->set_max_layer(G4MVTX::n_maps_layer + G4INTT::n_intt_layer);
113  se->registerSubsystem(pat_rec);
114  } else {
115  auto silicon_Seeding = new PHActsSiliconSeeding;
116  silicon_Seeding->Verbosity(verbosity);
117  std::cout << "SETTING SI SEED CV" << std::endl;
118  silicon_Seeding->set_cluster_version(G4TRACKING::cluster_version);
119  se->registerSubsystem(silicon_Seeding);
120 
121  auto merger = new PHSiliconSeedMerger;
122  merger->Verbosity(verbosity);
123  se->registerSubsystem(merger);
124  }
125 
126  // Assemble TPC clusters into track stubs
128  {
129  // For the TPC, for each truth particle, create a track and associate clusters with it using truth information, write to Svtx track map
130  // track stubs are given the position odf the truth vertex in this module
131  auto pat_rec = new PHTruthTrackSeeding("PHTruthTrackSeedingTpc");
132  pat_rec->Verbosity(verbosity);
133  pat_rec->set_track_map_name("TpcTrackSeedContainer");
134  pat_rec->set_min_layer(G4MVTX::n_maps_layer + G4INTT::n_intt_layer);
136  se->registerSubsystem(pat_rec);
137 
138  } else {
139 
140  auto seeder = new PHCASeeding("PHCASeeding");
141  seeder->set_field_dir(G4MAGNET::magfield_rescale); // to get charge sign right
142  if (G4MAGNET::magfield.find("3d") != std::string::npos)
143  {
144  seeder->set_field_dir(-1 * G4MAGNET::magfield_rescale);
145  }
146  seeder->Verbosity(verbosity);
147  seeder->SetLayerRange(7, 55);
148  seeder->SetSearchWindow(1.5, 0.05); // (z width, phi width)
149  seeder->SetMinHitsPerCluster(0);
150  seeder->SetMinClustersPerTrack(3);
151  seeder->useConstBField(false);
152  seeder->useFixedClusterError(true);
153  se->registerSubsystem(seeder);
154 
155  // expand stubs in the TPC using simple kalman filter
156  auto cprop = new PHSimpleKFProp("PHSimpleKFProp");
157  cprop->set_field_dir(G4MAGNET::magfield_rescale);
158  if (G4MAGNET::magfield.find("3d") != std::string::npos)
159  {
160  cprop->set_field_dir(-1 * G4MAGNET::magfield_rescale);
161  }
162  cprop->useConstBField(false);
163  cprop->useFixedClusterError(true);
164  cprop->set_max_window(5.);
165  cprop->set_cluster_version(G4TRACKING::cluster_version);
166  cprop->Verbosity(verbosity);
167  se->registerSubsystem(cprop);
168  }
169 
170  // match silicon track seeds to TPC track seeds
172  {
173  std::cout << "Tracking_Reco_TrackSeed - Using truth Si matching " << std::endl;
174  // use truth particle matching in TPC to assign clusters in silicon to TPC tracks from CA seeder
175  auto silicon_assoc = new PHTruthSiliconAssociation;
176  silicon_assoc->Verbosity(verbosity);
177  se->registerSubsystem(silicon_assoc);
178  } else {
179  std::cout << "Tracking_Reco_TrackSeed - Using stub matching for Si matching " << std::endl;
180  // The normal silicon association methods
181  // Match the TPC track stubs from the CA seeder to silicon track stubs from PHSiliconTruthTrackSeeding
182  auto silicon_match = new PHSiliconTpcTrackMatching;
183  silicon_match->Verbosity(verbosity);
184  silicon_match->set_pp_mode(TRACKING::pp_mode);
185  std::cout << "PHSiliconTpcTrackMatching pp_mode set to " << TRACKING::pp_mode << std::endl;
187  {
188  // search windows for initial matching with distortions
189  // tuned values are 0.04 and 0.008 in distorted events
190  silicon_match->set_phi_search_window(0.04);
191  silicon_match->set_eta_search_window(0.008);
192  } else {
193  // after distortion corrections and rerunning clustering, default tuned values are 0.02 and 0.004 in low occupancy events
194  silicon_match->set_phi_search_window(0.03);
195  silicon_match->set_eta_search_window(0.005);
196  }
197  silicon_match->set_test_windows_printout(false); // used for tuning search windows
198  se->registerSubsystem(silicon_match);
199  }
200 
201  // Associate Micromegas clusters with the tracks
202  if( Enable::MICROMEGAS )
203  {
204  std::cout << "Tracking_Reco_TrackSeed - Using Micromegas matching " << std::endl;
205 
206  // Match TPC track stubs from CA seeder to clusters in the micromegas layers
207  auto mm_match = new PHMicromegasTpcTrackMatching;
208  mm_match->Verbosity(verbosity);
210  {
211  // configuration is potentially with different search windows
212  mm_match->set_rphi_search_window_lyr1(0.2);
213  mm_match->set_rphi_search_window_lyr2(13.0);
214  mm_match->set_z_search_window_lyr1(26.0);
215  mm_match->set_z_search_window_lyr2(0.2);
216  } else {
217  // baseline configuration is (0.2, 13.0, 26, 0.2) and is the default
218  mm_match->set_rphi_search_window_lyr1(0.2);
219  mm_match->set_rphi_search_window_lyr2(13.0);
220  mm_match->set_z_search_window_lyr1(26.0);
221  mm_match->set_z_search_window_lyr2(0.2);
222  }
223  mm_match->set_min_tpc_layer(38); // layer in TPC to start projection fit
224  mm_match->set_test_windows_printout(false); // used for tuning search windows only
225  se->registerSubsystem(mm_match);
226  }
227 
228  } else {
229 
230  // full truth track finding
231  std::cout << "Tracking_Reco_TrackSeed - Using full truth track seeding" << std::endl;
232 
233  // For each truth particle, create a track and associate clusters with it using truth information, write to Svtx track map
234  // track stubs are given the position of the truth vertex in this module, but Genfit does not care
235  // Includes clusters for TPC, silicon and MM's
236  auto pat_rec = new PHTruthTrackSeeding("PHTruthTrackSeedingFull");
237  pat_rec->Verbosity(verbosity);
238  pat_rec->set_track_map_name("SvtxTrackSeedContainer");
239  se->registerSubsystem(pat_rec);
240 
241  }
242 
243  /*
244  * all done
245  * at this stage tracks are fully assembled. They contain clusters spaning Silicon detectors, TPC and Micromegas
246  * they are ready to be fit.
247  */
249  {
250  convert_seeds();
251  }
252 }
253 
254 
255 void vertexing()
256 {
260  {
261  auto vtxing = new PHTruthVertexing;
262  vtxing->associate_tracks(true);
263  std::string trackmapnamef = "SvtxTrackMap";
264  vtxing->set_track_map_name(trackmapnamef);
265  se->registerSubsystem(vtxing);
266  } else {
267  auto vtxfinder = new PHSimpleVertexFinder;
268  vtxfinder->Verbosity(verbosity);
269  se->registerSubsystem(vtxfinder);
270  }
271 }
272 
274 {
276  auto se = Fun4AllServer::instance();
277 
278  // correct clusters for particle propagation in TPC
279  auto deltazcorr = new PHTpcDeltaZCorrection;
280  deltazcorr->Verbosity(verbosity);
281  se->registerSubsystem(deltazcorr);
282 
283 
284  // perform final track fit with ACTS
285  auto actsFit = new PHActsTrkFitter;
286  actsFit->Verbosity(verbosity);
287  //actsFit->commissioning(G4TRACKING::use_alignment);
288  actsFit->set_cluster_version(G4TRACKING::cluster_version);
289  // in calibration mode, fit only Silicons and Micromegas hits
290  actsFit->fitSiliconMMs(G4TRACKING::SC_CALIBMODE);
291  actsFit->set_pp_mode(TRACKING::pp_mode);
292  se->registerSubsystem(actsFit);
293 
294 
296  {
297  /*
298  * in calibration mode, calculate residuals between TPC and fitted tracks,
299  * store in dedicated structure for distortion correction
300  */
301  auto residuals = new PHTpcResiduals;
302  residuals->setClusterVersion(G4TRACKING::cluster_version);
304  residuals->setUseMicromegas(G4TRACKING::SC_USE_MICROMEGAS);
305  residuals->Verbosity(verbosity);
306  se->registerSubsystem(residuals);
307  } else {
308 
309  /*
310  * in full tracking mode, run track cleaner, vertex finder,
311  * propagete tracks to vertex
312  * propagate tracks to EMCAL
313  */
314 
316  {
317  // Choose the best silicon matched track for each TPC track seed
318  /* this breaks in truth_track seeding mode because there is no TpcSeed */
319  auto cleaner = new PHTrackCleaner;
320  cleaner->Verbosity(verbosity);
321  se->registerSubsystem(cleaner);
322  }
323 
324  vertexing();
325 
326  // Propagate track positions to the vertex position
327  auto vtxProp = new PHActsVertexPropagator;
328  vtxProp->Verbosity(verbosity);
329  se->registerSubsystem(vtxProp);
330 
331  // project tracks to EMCAL
332  auto projection = new PHActsTrackProjection;
333  projection->Verbosity(verbosity);
334  se->registerSubsystem(projection);
335 
336 
337  }
338 
339 }
340 
342 {
343  // set up verbosity
345 
346  // get fun4all server instance
347  auto se = Fun4AllServer::instance();
348 
349  auto silicon_Seeding = new PHActsSiliconSeeding;
350  silicon_Seeding->Verbosity(verbosity);
351  silicon_Seeding->set_cluster_version(G4TRACKING::cluster_version);
352  silicon_Seeding->sigmaScattering(50.);
353  silicon_Seeding->setRPhiSearchWindow(0.4);
354  se->registerSubsystem(silicon_Seeding);
355 
356  auto merger = new PHSiliconSeedMerger;
357  merger->Verbosity(verbosity);
358  se->registerSubsystem(merger);
359 
360  // Assemble TPC clusters into track stubs
361  auto seeder = new PHCASeeding("PHCASeeding");
362  seeder->set_field_dir(G4MAGNET::magfield_rescale); // to get charge sign right
363  if (G4MAGNET::magfield.find("3d") != std::string::npos)
364  {
365  seeder->set_field_dir(-1 * G4MAGNET::magfield_rescale);
366  }
367  seeder->Verbosity(verbosity);
368  seeder->SetLayerRange(7, 55);
369  seeder->SetSearchWindow(1.5, 0.05); // (z width, phi width)
370  seeder->SetMinHitsPerCluster(0);
371  seeder->SetMinClustersPerTrack(3);
372  seeder->useConstBField(false);
373  seeder->useFixedClusterError(true);
374  se->registerSubsystem(seeder);
375 
376  // expand stubs in the TPC using simple kalman filter
377  auto cprop = new PHSimpleKFProp("PHSimpleKFProp");
378  cprop->set_field_dir(G4MAGNET::magfield_rescale);
379  if (G4MAGNET::magfield.find("3d") != std::string::npos)
380  {
381  cprop->set_field_dir(-1 * G4MAGNET::magfield_rescale);
382  }
383  cprop->useConstBField(false);
384  cprop->useFixedClusterError(true);
385  cprop->set_max_window(5.);
386  cprop->set_cluster_version(G4TRACKING::cluster_version);
387  cprop->Verbosity(verbosity);
388  se->registerSubsystem(cprop);
389 
390 
391  // match silicon track seeds to TPC track seeds
392 
393  // The normal silicon association methods
394  // Match the TPC track stubs from the CA seeder to silicon track stubs from PHSiliconTruthTrackSeeding
395  auto silicon_match = new PHSiliconTpcTrackMatching;
396  silicon_match->Verbosity(verbosity);
397  silicon_match->set_pp_mode(TRACKING::pp_mode);
398 
399  silicon_match->set_phi_search_window(0.2);
400  silicon_match->set_eta_search_window(0.015);
401  silicon_match->set_x_search_window(std::numeric_limits<double>::max());
402  silicon_match->set_y_search_window(std::numeric_limits<double>::max());
403  silicon_match->set_z_search_window(std::numeric_limits<double>::max());
404 
405  silicon_match->set_test_windows_printout(false); // used for tuning search windows
406  se->registerSubsystem(silicon_match);
407 
408 
409  // Associate Micromegas clusters with the tracks
410  if( Enable::MICROMEGAS )
411  {
412  // Match TPC track stubs from CA seeder to clusters in the micromegas layers
413  auto mm_match = new PHMicromegasTpcTrackMatching;
414  mm_match->Verbosity(verbosity);
415 
416  mm_match->set_rphi_search_window_lyr1(0.4);
417  mm_match->set_rphi_search_window_lyr2(13.0);
418  mm_match->set_z_search_window_lyr1(26.0);
419  mm_match->set_z_search_window_lyr2(0.2);
420 
421  mm_match->set_min_tpc_layer(38); // layer in TPC to start projection fit
422  mm_match->set_test_windows_printout(false); // used for tuning search windows only
423  se->registerSubsystem(mm_match);
424 
425 
426  }
428  {
429  convert_seeds();
430  }
431 }
432 
433 void alignment(std::string datafilename = "mille_output_data_file",
434  std::string steeringfilename = "mille_steer")
435 {
438 
439  auto mille = new MakeMilleFiles;
440  mille->Verbosity(verbosity);
441  mille->set_datafile_name(datafilename + ".bin");
442  mille->set_steeringfile_name(steeringfilename + ".txt");
443  mille->set_cluster_version(G4TRACKING::cluster_version);
444  se->registerSubsystem(mille);
445 
446  auto helical = new HelicalFitter;
447  helical->Verbosity(0);
448  helical->set_datafile_name(datafilename + "_helical.bin");
449  helical->set_steeringfile_name(steeringfilename + "_helical.txt");
450  helical->set_cluster_version(G4TRACKING::cluster_version);
451  se->registerSubsystem(helical);
452 
453 }
454 
456 {
457 
458  std::cout << "G4_Tracking is now obsolete as of macros PR612. "
459  << std::endl << "Please switch to the new scheme for tracking, which is demosntrated in the PR at the following link: www.github.com/sPHENIX-Collaboration/macros/pull/612"
460  << std::endl
461  << "The switch is not difficult and just requires updating your macros repo and adding the new relevant tracking includes into your main Fun4All macro instead of G4_Tracking."
462  << std::endl;
463  gSystem->Exit(1);
464 
465  /*
466  * just a wrapper around track seeding and track fitting methods,
467  * to minimize disruption to existing steering macros
468  */
470  {
472  }
473  else
474  {
476  }
477 
479  {
480  vertexing();
481  }
482  else
483  {
485  }
486 
487 
489  {
490  alignment();
491  }
492 
493 }
494 
496 {
497  std::cout << "G4_Tracking is now obsolete as of macros PR612. "
498  << std::endl << "Please switch to the new scheme for tracking, which is demosntrated in the PR at the following link: www.github.com/sPHENIX-Collaboration/macros/pull/612"
499  << std::endl
500  << "The switch is not difficult and just requires updating your macros repo and adding the new relevant tracking includes into your main Fun4All macro instead of G4_Tracking."
501  << std::endl;
502  gSystem->Exit(1);
505  secvert->Verbosity(0);
506  secvert->set_write_electrons_node(true); // writes copy of filtered electron tracks to node tree
507  secvert->set_write_ntuple(false); // writes ntuple for tuning cuts
508  secvert->setDecayParticleMass( 0.000511); // for electrons
509  secvert->setOutfileName(ntuple_outfile);
510  se->registerSubsystem(secvert);
511 }
512 
513 
515 {
518 
519  // this module builds high level truth track association table.
520  // If this module is used, this table should be called before any evaluator calls.
521  // Removing this module, evaluation will still work but trace truth association through the layers of G4-hit-cluster
523  tables->Verbosity(verbosity);
524  se->registerSubsystem(tables);
525 
526  return;
527 }
528 
529 void Tracking_Eval(const std::string& outputfile)
530 {
531 
532  std::cout << "G4_Tracking is now obsolete as of macros PR612. "
533  << std::endl << "Please switch to the new scheme for tracking, which is demosntrated in the PR at the following link: www.github.com/sPHENIX-Collaboration/macros/pull/612"
534  << std::endl
535  << "The switch is not difficult and just requires updating your macros repo and adding the new relevant tracking includes into your main Fun4All macro instead of G4_Tracking."
536  << std::endl;
537  gSystem->Exit(1);
538 
540 
541  //---------------
542  // Fun4All server
543  //---------------
544 
547 
548  //----------------
549  // Tracking evaluation
550  //----------------
551  SvtxEvaluator* eval;
552  eval = new SvtxEvaluator("SVTXEVALUATOR", outputfile, "SvtxTrackMap",
557  eval->do_cluster_eval(true);
558  eval->do_g4hit_eval(false);
559  eval->do_hit_eval(false); // enable to see the hits that includes the chamber physics...
560  eval->do_gpoint_eval(true);
561  eval->do_vtx_eval_light(true);
562  eval->do_eval_light(true);
564  bool embed_scan = true;
565  if(TRACKING::pp_mode) embed_scan = false;
566  eval->scan_for_embedded(embed_scan); // take all tracks if false - take only embedded tracks if true
567  eval->scan_for_primaries(embed_scan); // defaults to only thrown particles for ntp_gtrack
568  std::cout << "SvtxEvaluator: pp_mode set to " << TRACKING::pp_mode << " and scan_for_embedded set to " << embed_scan << std::endl;
569  eval->Verbosity(verbosity);
570  eval->set_cluster_version(G4TRACKING::cluster_version);
571 
572  se->registerSubsystem(eval);
573 
574  return;
575 }
576 
578 {
579 
580  std::cout << "G4_Tracking is now obsolete as of macros PR612. "
581  << std::endl << "Please switch to the new scheme for tracking, which is demosntrated in the PR at the following link: www.github.com/sPHENIX-Collaboration/macros/pull/612"
582  << std::endl
583  << "The switch is not difficult and just requires updating your macros repo and adding the new relevant tracking includes into your main Fun4All macro instead of G4_Tracking."
584  << std::endl;
585  gSystem->Exit(1);
586 
588 
589  //---------------
590  // Fun4All server
591  //---------------
592 
594 
596 
598  // qa->addEmbeddingID(2);
599  qa->Verbosity(verbosity);
600  se->registerSubsystem(qa);
601 
603  // qa2->addEmbeddingID(2);
604  qa2->Verbosity(verbosity);
605  se->registerSubsystem(qa2);
606 
607  // Acts Kalman Filter vertex finder
608  //=================================
610  // qav->addEmbeddingID(2);
611  qav->Verbosity(verbosity);
612  qav->setVertexMapName("SvtxVertexMapActs");
613  se->registerSubsystem(qav);
614 
615  if (Input::UPSILON)
616  {
618 
619  for (int id : Input::UPSILON_EmbedIds)
620  {
621  qa->addEmbeddingID(id);
622  }
623  se->registerSubsystem(qa);
624  }
625 }
626 
628 {
630 
631  //---------------
632  // Fun4All server
633  //---------------
634 
636 
637  auto qa = new QAG4SimulationDistortions();
638  qa->Verbosity(verbosity);
639  se->registerSubsystem(qa);
640 
641 }
642 #endif