Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Trkr_TruthReco.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Trkr_TruthReco.C
1 #ifndef MACRO_TRKRTRUTHRECO_C
2 #define MACRO_TRKRTRUTHRECO_C
3 
4 #include <GlobalVariables.C>
5 
6 #include <G4_TrkrVariables.C>
7 
8 
10 #include <trackingdiagnostics/TrackSeedTrackMapConverter.h>
11 
17 #include <trackreco/PHCASeeding.h>
30 
32 
34 
35 #include <trackermillepedealignment/MakeMilleFiles.h>
36 #include <trackermillepedealignment/HelicalFitter.h>
37 
38 #include <fun4all/Fun4AllServer.h>
39 
40 R__LOAD_LIBRARY(libTrackingDiagnostics.so)
41 R__LOAD_LIBRARY(libtrack_reco.so)
42 R__LOAD_LIBRARY(libtpccalib.so)
43 R__LOAD_LIBRARY(libtrackeralign.so)
44 R__LOAD_LIBRARY(libg4eval.so)
45 
47 {
50 
52  // Default set to full SvtxTrackSeeds. Can be set to
53  // SiliconTrackSeedContainer or TpcTrackSeedContainer
54  converter->setTrackSeedName("SvtxTrackSeedContainer");
55  converter->Verbosity(verbosity);
56  se->registerSubsystem(converter);
57 }
58 
60 {
61  // set up verbosity
63 
64  // get fun4all server instance
65  auto se = Fun4AllServer::instance();
66 
68  {
69  // Assemble silicon clusters into track stubs
71  {
72  // For the silicon, for each truth particle, create a track and associate clusters with it using truth information, write to silicon track map
73  // track stubs are given the location of the truth vertex in this module
74  auto pat_rec = new PHTruthTrackSeeding("PHTruthTrackSeedingSilicon");
75  pat_rec->Verbosity(verbosity);
76  pat_rec->set_track_map_name("SiliconTrackSeedContainer");
77  pat_rec->set_min_layer(0);
78  pat_rec->set_max_layer(G4MVTX::n_maps_layer + G4INTT::n_intt_layer);
79  se->registerSubsystem(pat_rec);
80  } else {
81  auto silicon_Seeding = new PHActsSiliconSeeding;
82  silicon_Seeding->Verbosity(verbosity);
83  std::cout << "SETTING SI SEED CV" << std::endl;
84  se->registerSubsystem(silicon_Seeding);
85 
86  auto merger = new PHSiliconSeedMerger;
87  merger->Verbosity(verbosity);
88  se->registerSubsystem(merger);
89  }
90 
91  // Assemble TPC clusters into track stubs
93  {
94  // For the TPC, for each truth particle, create a track and associate clusters with it using truth information, write to Svtx track map
95  // track stubs are given the position odf the truth vertex in this module
96  auto pat_rec = new PHTruthTrackSeeding("PHTruthTrackSeedingTpc");
97  pat_rec->Verbosity(verbosity);
98  pat_rec->set_track_map_name("TpcTrackSeedContainer");
99  pat_rec->set_min_layer(G4MVTX::n_maps_layer + G4INTT::n_intt_layer);
101  se->registerSubsystem(pat_rec);
102 
103  } else {
104 
105  auto seeder = new PHCASeeding("PHCASeeding");
106  seeder->set_field_dir(G4MAGNET::magfield_rescale); // to get charge sign right
107  if (G4MAGNET::magfield.find("3d") != std::string::npos)
108  {
109  seeder->set_field_dir(-1 * G4MAGNET::magfield_rescale);
110  }
111  seeder->Verbosity(verbosity);
112  seeder->SetLayerRange(7, 55);
113  seeder->SetSearchWindow(1.5, 0.05); // (z width, phi width)
114  seeder->SetMinHitsPerCluster(0);
115  seeder->SetMinClustersPerTrack(3);
116  seeder->useConstBField(false);
117  seeder->useFixedClusterError(true);
118  se->registerSubsystem(seeder);
119 
120  // expand stubs in the TPC using simple kalman filter
121  auto cprop = new PHSimpleKFProp("PHSimpleKFProp");
122  cprop->set_field_dir(G4MAGNET::magfield_rescale);
123  if (G4MAGNET::magfield.find("3d") != std::string::npos)
124  {
125  cprop->set_field_dir(-1 * G4MAGNET::magfield_rescale);
126  }
127  cprop->useConstBField(false);
128  cprop->useFixedClusterError(true);
129  cprop->set_max_window(5.);
130  cprop->Verbosity(verbosity);
131  se->registerSubsystem(cprop);
132  }
133 
134  // match silicon track seeds to TPC track seeds
136  {
137  std::cout << "Tracking_Reco_TrackSeed - Using truth Si matching " << std::endl;
138  // use truth particle matching in TPC to assign clusters in silicon to TPC tracks from CA seeder
139  auto silicon_assoc = new PHTruthSiliconAssociation;
140  silicon_assoc->Verbosity(verbosity);
141  se->registerSubsystem(silicon_assoc);
142  } else {
143  std::cout << "Tracking_Reco_TrackSeed - Using stub matching for Si matching " << std::endl;
144  // The normal silicon association methods
145  // Match the TPC track stubs from the CA seeder to silicon track stubs from PHSiliconTruthTrackSeeding
146  auto silicon_match = new PHSiliconTpcTrackMatching;
147  silicon_match->Verbosity(verbosity);
148  silicon_match->set_pp_mode(TRACKING::pp_mode);
149  std::cout << "PHSiliconTpcTrackMatching pp_mode set to " << TRACKING::pp_mode << std::endl;
151  {
152  // search windows for initial matching with distortions
153  // tuned values are 0.04 and 0.008 in distorted events
154  silicon_match->set_phi_search_window(0.04);
155  silicon_match->set_eta_search_window(0.008);
156  } else {
157  // after distortion corrections and rerunning clustering, default tuned values are 0.02 and 0.004 in low occupancy events
158  silicon_match->set_phi_search_window(0.03);
159  silicon_match->set_eta_search_window(0.005);
160  }
161  silicon_match->set_test_windows_printout(false); // used for tuning search windows
162  se->registerSubsystem(silicon_match);
163  }
164 
165  // Associate Micromegas clusters with the tracks
166  if( Enable::MICROMEGAS )
167  {
168  std::cout << "Tracking_Reco_TrackSeed - Using Micromegas matching " << std::endl;
169 
170  // Match TPC track stubs from CA seeder to clusters in the micromegas layers
171  auto mm_match = new PHMicromegasTpcTrackMatching;
172  mm_match->Verbosity(verbosity);
174  {
175  // configuration is potentially with different search windows
176  mm_match->set_rphi_search_window_lyr1(0.2);
177  mm_match->set_rphi_search_window_lyr2(13.0);
178  mm_match->set_z_search_window_lyr1(26.0);
179  mm_match->set_z_search_window_lyr2(0.2);
180  } else {
181  // baseline configuration is (0.2, 13.0, 26, 0.2) and is the default
182  mm_match->set_rphi_search_window_lyr1(0.2);
183  mm_match->set_rphi_search_window_lyr2(13.0);
184  mm_match->set_z_search_window_lyr1(26.0);
185  mm_match->set_z_search_window_lyr2(0.2);
186  }
187  mm_match->set_min_tpc_layer(38); // layer in TPC to start projection fit
188  mm_match->set_test_windows_printout(false); // used for tuning search windows only
189  se->registerSubsystem(mm_match);
190  }
191 
192  } else {
193 
194  // full truth track finding
195  std::cout << "Tracking_Reco_TrackSeed - Using full truth track seeding" << std::endl;
196 
197  // For each truth particle, create a track and associate clusters with it using truth information, write to Svtx track map
198  // track stubs are given the position of the truth vertex in this module, but Genfit does not care
199  // Includes clusters for TPC, silicon and MM's
200  auto pat_rec = new PHTruthTrackSeeding("PHTruthTrackSeedingFull");
201  pat_rec->Verbosity(verbosity);
202  pat_rec->set_track_map_name("SvtxTrackSeedContainer");
203  se->registerSubsystem(pat_rec);
204 
205  }
206 
207  /*
208  * all done
209  * at this stage tracks are fully assembled. They contain clusters spaning Silicon detectors, TPC and Micromegas
210  * they are ready to be fit.
211  */
213  {
214  convert_seeds();
215  }
216 }
217 
218 
219 void vertexing()
220 {
224  {
225  auto vtxing = new PHTruthVertexing;
226  vtxing->associate_tracks(true);
227  std::string trackmapnamef = "SvtxTrackMap";
228  vtxing->set_track_map_name(trackmapnamef);
229  se->registerSubsystem(vtxing);
230  } else {
231  auto vtxfinder = new PHSimpleVertexFinder;
232  vtxfinder->Verbosity(verbosity);
233  se->registerSubsystem(vtxfinder);
234  }
235 
236 }
237 
239 {
241  auto se = Fun4AllServer::instance();
242 
243  // correct clusters for particle propagation in TPC
244  auto deltazcorr = new PHTpcDeltaZCorrection;
245  deltazcorr->Verbosity(verbosity);
246  se->registerSubsystem(deltazcorr);
247 
248 
249  // perform final track fit with ACTS
250  auto actsFit = new PHActsTrkFitter;
251  actsFit->Verbosity(verbosity);
252  //actsFit->commissioning(G4TRACKING::use_alignment);
253  // in calibration mode, fit only Silicons and Micromegas hits
254  actsFit->fitSiliconMMs(G4TRACKING::SC_CALIBMODE);
255  actsFit->setUseMicromegas(G4TRACKING::SC_USE_MICROMEGAS);
256  actsFit->set_pp_mode(TRACKING::pp_mode);
257  se->registerSubsystem(actsFit);
258 
260  {
261  /*
262  * in calibration mode, calculate residuals between TPC and fitted tracks,
263  * store in dedicated structure for distortion correction
264  */
265  auto residuals = new PHTpcResiduals;
267 
268  residuals->setUseMicromegas(G4TRACKING::SC_USE_MICROMEGAS);
269  residuals->Verbosity(verbosity);
270  se->registerSubsystem(residuals);
271  } else {
272 
273  /*
274  * in full tracking mode, run track cleaner, vertex finder,
275  * propagete tracks to vertex
276  * propagate tracks to EMCAL
277  */
278 
280  {
281  // Choose the best silicon matched track for each TPC track seed
282  /* this breaks in truth_track seeding mode because there is no TpcSeed */
283  auto cleaner = new PHTrackCleaner;
284  cleaner->Verbosity(verbosity);
285  se->registerSubsystem(cleaner);
286  }
287 
288  vertexing();
289 
290  // Propagate track positions to the vertex position
291  auto vtxProp = new PHActsVertexPropagator;
292  vtxProp->Verbosity(verbosity);
293  se->registerSubsystem(vtxProp);
294 
295  // project tracks to EMCAL
296  auto projection = new PHActsTrackProjection;
297  projection->Verbosity(verbosity);
298  se->registerSubsystem(projection);
299  }
300 
301 }
302 
304 {
305  // set up verbosity
307 
308  // get fun4all server instance
309  auto se = Fun4AllServer::instance();
310 
311  auto silicon_Seeding = new PHActsSiliconSeeding;
312  silicon_Seeding->Verbosity(verbosity);
313  silicon_Seeding->sigmaScattering(50.);
314  silicon_Seeding->setRPhiSearchWindow(0.4);
315  se->registerSubsystem(silicon_Seeding);
316 
317  auto merger = new PHSiliconSeedMerger;
318  merger->Verbosity(verbosity);
319  se->registerSubsystem(merger);
320 
321  // Assemble TPC clusters into track stubs
322  auto seeder = new PHCASeeding("PHCASeeding");
323  seeder->set_field_dir(G4MAGNET::magfield_rescale); // to get charge sign right
324  if (G4MAGNET::magfield.find("3d") != std::string::npos)
325  {
326  seeder->set_field_dir(-1 * G4MAGNET::magfield_rescale);
327  }
328  seeder->Verbosity(verbosity);
329  seeder->SetLayerRange(7, 55);
330  seeder->SetSearchWindow(1.5, 0.05); // (z width, phi width)
331  seeder->SetMinHitsPerCluster(0);
332  seeder->SetMinClustersPerTrack(3);
333  seeder->useConstBField(false);
334  seeder->useFixedClusterError(true);
335  se->registerSubsystem(seeder);
336 
337  // expand stubs in the TPC using simple kalman filter
338  auto cprop = new PHSimpleKFProp("PHSimpleKFProp");
339  cprop->set_field_dir(G4MAGNET::magfield_rescale);
340  if (G4MAGNET::magfield.find("3d") != std::string::npos)
341  {
342  cprop->set_field_dir(-1 * G4MAGNET::magfield_rescale);
343  }
344  cprop->useConstBField(false);
345  cprop->useFixedClusterError(true);
346  cprop->set_max_window(5.);
347  cprop->Verbosity(verbosity);
348  se->registerSubsystem(cprop);
349 
350 
351  // match silicon track seeds to TPC track seeds
352 
353  // The normal silicon association methods
354  // Match the TPC track stubs from the CA seeder to silicon track stubs from PHSiliconTruthTrackSeeding
355  auto silicon_match = new PHSiliconTpcTrackMatching;
356  silicon_match->Verbosity(verbosity);
357  silicon_match->set_pp_mode(TRACKING::pp_mode);
358 
359  silicon_match->set_phi_search_window(0.2);
360  silicon_match->set_eta_search_window(0.015);
361  silicon_match->set_x_search_window(std::numeric_limits<double>::max());
362  silicon_match->set_y_search_window(std::numeric_limits<double>::max());
363  silicon_match->set_z_search_window(std::numeric_limits<double>::max());
364 
365  silicon_match->set_test_windows_printout(false); // used for tuning search windows
366  se->registerSubsystem(silicon_match);
367 
368 
369  // Associate Micromegas clusters with the tracks
370  if( Enable::MICROMEGAS )
371  {
372  // Match TPC track stubs from CA seeder to clusters in the micromegas layers
373  auto mm_match = new PHMicromegasTpcTrackMatching;
374  mm_match->Verbosity(verbosity);
375 
376  mm_match->set_rphi_search_window_lyr1(0.4);
377  mm_match->set_rphi_search_window_lyr2(13.0);
378  mm_match->set_z_search_window_lyr1(26.0);
379  mm_match->set_z_search_window_lyr2(0.2);
380 
381  mm_match->set_min_tpc_layer(38); // layer in TPC to start projection fit
382  mm_match->set_test_windows_printout(false); // used for tuning search windows only
383  se->registerSubsystem(mm_match);
384 
385 
386  }
388  {
389  convert_seeds();
390  }
391 }
392 
393 void alignment(std::string datafilename = "mille_output_data_file",
394  std::string steeringfilename = "mille_steer")
395 {
398 
399  auto mille = new MakeMilleFiles;
400  mille->Verbosity(verbosity);
401  mille->set_datafile_name(datafilename + ".bin");
402  mille->set_steeringfile_name(steeringfilename + ".txt");
403  se->registerSubsystem(mille);
404 
405  auto helical = new HelicalFitter;
406  helical->Verbosity(0);
407  helical->set_datafile_name(datafilename + "_helical.bin");
408  helical->set_steeringfile_name(steeringfilename + "_helical.txt");
409  se->registerSubsystem(helical);
410 
411 }
412 
414 {
415  /*
416  * just a wrapper around track seeding and track fitting methods,
417  * to minimize disruption to existing steering macros
418  */
420  {
422  }
423  else
424  {
426  }
427 
429  {
430  vertexing();
431  }
432  else
433  {
435  }
436 
438  {
439  alignment();
440  }
441 
442 }
443 
445 {
448  secvert->Verbosity(0);
449  secvert->set_write_electrons_node(true); // writes copy of filtered electron tracks to node tree
450  secvert->set_write_ntuple(false); // writes ntuple for tuning cuts
451  secvert->setDecayParticleMass( 0.000511); // for electrons
452  secvert->setOutfileName(ntuple_outfile);
453  se->registerSubsystem(secvert);
454 }
455 
456 
457 
458 #endif