EIC 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 
9 #include <GlobalVariables.C>
10 
11 #include <G4_Intt.C>
12 #include <G4_Micromegas.C>
13 #include <G4_Mvtx.C>
14 #include <G4_TPC.C>
15 #include <QA.C>
16 
17 #include <g4eval/SvtxEvaluator.h>
18 
23 #include <trackreco/PHCASeeding.h>
39 
41 
42 #include <qa_modules/QAG4SimulationTracking.h>
43 #include <qa_modules/QAG4SimulationUpsilon.h>
44 #include <qa_modules/QAG4SimulationVertex.h>
45 
46 #include <fun4all/Fun4AllServer.h>
47 
48 namespace Enable
49 {
50  bool TRACKING_TRACK = false;
51  bool TRACKING_EVAL = false;
52  int TRACKING_VERBOSITY = 0;
53  bool TRACKING_QA = false;
54 } // namespace Enable
55 
56 namespace G4TRACKING
57 {
58  // Space Charge calibration flag
59  bool SC_CALIBMODE = false; // this is anded with G4TPC::ENABLE_DISTORTIONS in TrackingInit()
60  bool SC_USE_MICROMEGAS = true;
61  bool SC_SAVEHISTOGRAMS = false;
62  double SC_COLLISIONRATE = 50e3; // leave at 50 KHz for now, scaling of distortion map not implemented yet
63  std::string SC_ROOTOUTPUT_FILENAME = "TpcSpaceChargeMatrices.root"; // space charge calibration output file
64  std::string SC_HISTOGRAMOUTPUT_FILENAME = "TpcResiduals.root"; // space charge calibration output file
65 
66  // Vertexing
67  bool g4eval_use_initial_vertex = true; // if true, g4eval uses initial vertices in SvtxVertexMap, not final vertices in SvtxVertexMapRefit
68 
69  // set to false to disable adding fake surfaces (TPC, Micromegas) to MakeActsGeom
70  bool add_fake_surfaces = true;
71 
72  // Truth seeding options for diagnostics (can use any or all)
73  bool use_truth_silicon_seeding = false; // if true runs truth silicon seeding instead of acts silicon seeding
74  bool use_truth_tpc_seeding = false; // if true runs truth silicon seeding instead of reco TPC seeding
75  bool use_truth_si_matching = false; // if true, associates silicon clusters using best truth track match to TPC seed tracks - for diagnostics only
76  // Full truth track seeding
77  bool use_full_truth_track_seeding = false; // makes track seeds using truth info, used for both Acts and Genfit
78  bool use_truth_vertexing = false; // if true runs truth vertexing, if false runs PHSimpleVertexFinder
79 
80  // Rave final vertexing (for QA)
81  bool use_rave_vertexing = true; // Use Rave to find and fit for vertex after track fitting - used for QA only
82  // This is the setup we have been using - smeared truth vertex for a single collision per event. Make it the default for now.
83  std::string vmethod("avf-smoothing:1"); // only good for 1 vertex events // vmethod is a string used to set the Rave final-vertexing method:
84 
85 } // namespace G4TRACKING
86 
88 {
89  if (!Enable::MICROMEGAS)
90  {
92  }
93 
97 
99  MakeActsGeometry* geom = new MakeActsGeometry();
100  geom->Verbosity(verbosity);
104  se->registerSubsystem(geom);
105 }
106 
108 {
111 
112  // Assemble silicon clusters into track stubs - needed for initial vertex finding
113  //============================================================
115  {
116  // For the silicon, for each truth particle, create a track and associate clusters with it using truth information, write to silicon track map
117  // track stubs are given the location of the truth vertex in this module
118  PHTruthTrackSeeding* pat_rec = new PHTruthTrackSeeding("PHTruthTrackSeedingSilicon");
119  pat_rec->Verbosity(verbosity);
120  pat_rec->set_track_map_name("SvtxSiliconTrackMap");
121  pat_rec->set_min_layer(0);
123 
124  se->registerSubsystem(pat_rec);
125  }
126  else
127  {
128  PHActsSiliconSeeding* silicon_Seeding = new PHActsSiliconSeeding();
129  silicon_Seeding->Verbosity(verbosity);
130  silicon_Seeding->fieldMapName(G4MAGNET::magfield);
131  se->registerSubsystem(silicon_Seeding);
132  }
133 
134  //================================================
135  // Section 1: Reco chain of track propagation and final fitting
136  //================================================
138  {
139  // TPC track seeding (finds all clusters in TPC for tracks)
140  //============================================
142  {
143  // For the TPC, for each truth particle, create a track and associate clusters with it using truth information, write to Svtx track map
144  // track stubs are given the position odf the truth vertex in this module
145  PHTruthTrackSeeding* pat_rec = new PHTruthTrackSeeding("PHTruthTrackSeedingTpc");
146  pat_rec->Verbosity(verbosity);
147  pat_rec->set_track_map_name("SvtxTrackMap");
150 
151  se->registerSubsystem(pat_rec);
152  }
153  else
154  {
155  auto seeder = new PHCASeeding("PHCASeeding");
156  seeder->set_field_dir(G4MAGNET::magfield_rescale); // to get charge sign right
157  if (G4MAGNET::magfield.find("3d") != std::string::npos)
158  {
159  seeder->set_field_dir(-1 * G4MAGNET::magfield_rescale);
160  }
161  seeder->Verbosity(verbosity);
162  seeder->SetLayerRange(7, 55);
163  seeder->SetSearchWindow(0.01, 0.02); // (eta width, phi width)
164  seeder->SetMinHitsPerCluster(0);
165  seeder->SetMinClustersPerTrack(3);
166  seeder->useConstBField(false);
167  seeder->useFixedClusterError(true);
168  se->registerSubsystem(seeder);
169 
170  PHTpcTrackSeedCircleFit* vtxassoc2 = new PHTpcTrackSeedCircleFit("PrePropagatorPHTpcTrackSeedCircleFit");
171  vtxassoc2->Verbosity(verbosity);
172  se->registerSubsystem(vtxassoc2);
173 
174  PHSimpleKFProp* cprop = new PHSimpleKFProp("PHSimpleKFProp");
176  if (G4MAGNET::magfield.find("3d") != std::string::npos)
177  {
179  }
180  cprop->useConstBField(false);
181  cprop->useFixedClusterError(true);
182  cprop->set_max_window(5.);
183  cprop->Verbosity(verbosity);
184  se->registerSubsystem(cprop);
185  }
186 
187  // Associate TPC track stubs with silicon and Micromegas
188  //=============================================
189 
190  /*
191  * add cluster mover to apply TPC distortion corrections to clusters belonging to tracks
192  * once the correction is applied, the cluster are moved back to TPC surfaces using local track angles
193  * moved clusters are stored in a separate map, called CORRECTED_TRKR_CLUSTER
194  */
196 
197  auto vtxassoc = new PHTpcTrackSeedCircleFit;
198  vtxassoc->Verbosity(verbosity);
199  se->registerSubsystem(vtxassoc);
200 
201  // Choose the best duplicate TPC track seed
202  auto ghosts = new PHGhostRejection;
203  ghosts->Verbosity(verbosity);
204  se->registerSubsystem(ghosts);
205 
206  // correct for particle propagation in TPC
208 
209  // Silicon cluster matching to TPC track seeds
211  {
212  std::cout << " Using truth Si matching " << std::endl;
213  // use truth particle matching in TPC to assign clusters in silicon to TPC tracks from CA seeder
214  // intended only for diagnostics
216  silicon_assoc->Verbosity(verbosity);
217  se->registerSubsystem(silicon_assoc);
218  }
219  else
220  {
221  std::cout << " Using stub matching for Si matching " << std::endl;
222 
223  // The normal silicon association methods
224  // start with a complete TPC track seed from one of the CA seeders
225 
226  // Match the TPC track stubs from the CA seeder to silicon track stubs from PHSiliconTruthTrackSeeding
228  silicon_match->Verbosity(verbosity);
229  silicon_match->set_field(G4MAGNET::magfield);
233  {
235  // search windows for initial matching with distortions
236  // tuned values are 0.04 and 0.008 in distorted events
237  silicon_match->set_phi_search_window(0.04);
238  silicon_match->set_eta_search_window(0.008);
239  }
240  else
241  {
242  // after distortion corrections and rerunning clustering, default tuned values are 0.02 and 0.004 in low occupancy events
243  silicon_match->set_phi_search_window(0.03);
244  silicon_match->set_eta_search_window(0.005);
245  }
246  silicon_match->set_test_windows_printout(false); // used for tuning search windows only
247  se->registerSubsystem(silicon_match);
248  }
249 
250  // Associate Micromegas clusters with the tracks
252  {
253  std::cout << " Using Micromegas matching " << std::endl;
254 
255  // Match TPC track stubs from CA seeder to clusters in the micromegas layers
257  mm_match->Verbosity(verbosity);
260  {
261  // calibration pass with distorted tracks
263  // configuration is potentially with different search windows
264  mm_match->set_rphi_search_window_lyr1(0.2);
265  mm_match->set_rphi_search_window_lyr2(13.0);
266  mm_match->set_z_search_window_lyr1(26.0);
267  mm_match->set_z_search_window_lyr2(0.2);
268  }
269  else
270  {
271  // baseline configuration is (0.2, 13.0, 26, 0.2) and is the default
272  mm_match->set_rphi_search_window_lyr1(0.2);
273  mm_match->set_rphi_search_window_lyr2(13.0);
274  mm_match->set_z_search_window_lyr1(26.0);
275  mm_match->set_z_search_window_lyr2(0.2);
276  }
277  mm_match->set_min_tpc_layer(38); // layer in TPC to start projection fit
278  mm_match->set_test_windows_printout(false); // used for tuning search windows only
279  se->registerSubsystem(mm_match);
280  }
281 
282  // Final fitting of tracks using Acts Kalman Filter
283  //=====================================
284 
285  std::cout << " Using Acts track fitting " << std::endl;
286 
287  PHActsTrkFitter* actsFit = new PHActsTrkFitter("PHActsFirstTrkFitter");
288  actsFit->Verbosity(verbosity);
292  se->registerSubsystem(actsFit);
293 
295  {
297  auto residuals = new PHTpcResiduals;
299  residuals->setSavehistograms( G4TRACKING::SC_SAVEHISTOGRAMS );
300  residuals->setHistogramOutputfile( G4TRACKING::SC_HISTOGRAMOUTPUT_FILENAME );
301  residuals->setUseMicromegas(G4TRACKING::SC_USE_MICROMEGAS);
302  residuals->Verbosity(verbosity);
303  se->registerSubsystem(residuals);
304  }
305 
306  // Choose the best silicon matched track for each TPC track seed
307  PHTrackCleaner* cleaner = new PHTrackCleaner();
308  cleaner->Verbosity(verbosity);
309  se->registerSubsystem(cleaner);
310 
312  {
313  PHTruthVertexing* vtxing = new PHTruthVertexing();
314  vtxing->associate_tracks(true);
315  std::string trackmapnamef = "SvtxTrackMap";
316  vtxing->set_track_map_name(trackmapnamef);
317  se->registerSubsystem(vtxing);
318  }
319  else
320  {
321  PHSimpleVertexFinder* vtxfinder = new PHSimpleVertexFinder();
322  vtxfinder->Verbosity(verbosity);
323  se->registerSubsystem(vtxfinder);
324  }
325 
328  vtxProp->Verbosity(verbosity);
329  se->registerSubsystem(vtxProp);
330  }
331 
332  //=========================================================
333  // Section 2: Full truth track finding with Acts final fitting
334  //=========================================================
336  {
337  std::cout << " Using full truth track seeding for Acts" << std::endl;
338 
339  // For each truth particle, create a track and associate clusters with it using truth information, write to Svtx track map
340  // track stubs are given the position of the truth vertex in this module, but Genfit does not care
341  // Includes clusters for TPC, silicon and MM's
342  PHTruthTrackSeeding* pat_rec = new PHTruthTrackSeeding("PHTruthTrackSeedingFull");
343  pat_rec->Verbosity(verbosity);
344  pat_rec->set_track_map_name("SvtxTrackMap");
345  se->registerSubsystem(pat_rec);
346 
347  /*
348  * add cluster mover to apply TPC distortion corrections to clusters belonging to tracks
349  * once the correction is applied, the cluster are moved back to TPC surfaces using local track angles
350  * moved clusters are stored in a separate map, called CORRECTED_TRKR_CLUSTER
351  */
353 
354  // correct for particle propagation in TPC
356 
357  // Fitting of tracks using Acts Kalman Filter
358  //==================================
359 
360  std::cout << " Using Acts track fitting " << std::endl;
361 
362  PHActsTrkFitter* actsFit = new PHActsTrkFitter("PHActsFirstTrkFitter");
363  actsFit->Verbosity(verbosity);
364  actsFit->doTimeAnalysis(false);
367  se->registerSubsystem(actsFit);
368 
370  {
372  auto residuals = new PHTpcResiduals;
374  residuals->setSavehistograms( G4TRACKING::SC_SAVEHISTOGRAMS );
375  residuals->setHistogramOutputfile( G4TRACKING::SC_HISTOGRAMOUTPUT_FILENAME );
376  residuals->setUseMicromegas(G4TRACKING::SC_USE_MICROMEGAS);
377  residuals->Verbosity(verbosity);
378  se->registerSubsystem(residuals);
379  }
380 
382  {
383  PHTruthVertexing* vtxing = new PHTruthVertexing();
384  vtxing->associate_tracks(true);
385  std::string trackmapnamef = "SvtxTrackMap";
386  vtxing->set_track_map_name(trackmapnamef);
387  se->registerSubsystem(vtxing);
388  }
389  else
390  {
391  PHSimpleVertexFinder* vtxfinder = new PHSimpleVertexFinder();
392  vtxfinder->Verbosity(verbosity);
393  se->registerSubsystem(vtxfinder);
394  }
395 
398  vtxProp->Verbosity(verbosity);
399  se->registerSubsystem(vtxProp);
400  }
401 
402  //==================================
403  // Common to all sections
404  //==================================
405 
406  // Final vertex finding and fitting with RAVE
407  //==================================
409  {
410  PHRaveVertexing* rave = new PHRaveVertexing();
411  // rave->set_vertexing_method("kalman-smoothing:1");
412  rave->set_over_write_svtxvertexmap(false);
413  rave->set_svtxvertexmaprefit_node_name("SvtxVertexMapRave");
414  rave->Verbosity(verbosity);
415  se->registerSubsystem(rave);
416  }
417 
418  // Track Projections
419  //===============
421  projection->Verbosity(verbosity);
422  se->registerSubsystem(projection);
423 
424  return;
425 }
426 
427 void Tracking_Eval(const std::string& outputfile)
428 {
430 
431  //---------------
432  // Fun4All server
433  //---------------
434 
436 
437  //----------------
438  // Tracking evaluation
439  //----------------
440  SvtxEvaluator* eval;
441  eval = new SvtxEvaluator("SVTXEVALUATOR", outputfile, "SvtxTrackMap",
446  eval->do_cluster_eval(true);
447  eval->do_g4hit_eval(true);
448  eval->do_hit_eval(true); // enable to see the hits that includes the chamber physics...
449  eval->do_gpoint_eval(true);
450  eval->do_vtx_eval_light(true);
451  eval->do_eval_light(true);
453  eval->scan_for_embedded(true); // take all tracks if false - take only embedded tracks if true
454  eval->scan_for_primaries(true); // defaults to only thrown particles for ntp_gtrack
455  eval->Verbosity(verbosity);
456  se->registerSubsystem(eval);
457 
458  return;
459 }
460 
462 {
464 
465  //---------------
466  // Fun4All server
467  //---------------
468 
470 
472  // qa->addEmbeddingID(2);
473  qa->Verbosity(verbosity);
474  se->registerSubsystem(qa);
475 
477  // qa2->addEmbeddingID(2);
478  qa2->Verbosity(verbosity);
479  se->registerSubsystem(qa2);
480 
482  {
484  // qav->addEmbeddingID(2);
485  qav->Verbosity(verbosity);
486  qav->setVertexMapName("SvtxVertexMapRave");
487  se->registerSubsystem(qav);
488  }
489 
490  // Acts Kalman Filter vertex finder
491  //=================================
493  // qav->addEmbeddingID(2);
494  qav->Verbosity(verbosity);
495  qav->setVertexMapName("SvtxVertexMapActs");
496  se->registerSubsystem(qav);
497 
498  if (Input::UPSILON)
499  {
501 
502  for (int id : Input::UPSILON_EmbedIds)
503  {
504  qa->addEmbeddingID(id);
505  }
506  se->registerSubsystem(qa);
507  }
508 }
509 
510 #endif