Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Trkr_Reco.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Trkr_Reco.C
1 #ifndef MACRO_TRKRRECO_C
2 #define MACRO_TRKRRECO_C
3 
4 #include <G4_TrkrVariables.C>
5 
6 #include <trackingdiagnostics/TrackSeedTrackMapConverter.h>
7 
13 #include <trackreco/PHCASeeding.h>
24 
26 
28 
29 #include <trackermillepedealignment/HelicalFitter.h>
30 #include <trackermillepedealignment/MakeMilleFiles.h>
31 
32 #include <fun4all/Fun4AllServer.h>
33 
34 #include <trackingdiagnostics/TrackContainerCombiner.h>
35 
36 #include <string>
37 
38 R__LOAD_LIBRARY(libTrackingDiagnostics.so)
39 R__LOAD_LIBRARY(libtrack_reco.so)
40 R__LOAD_LIBRARY(libtpccalib.so)
41 R__LOAD_LIBRARY(libtpc.so)
42 R__LOAD_LIBRARY(libtrackeralign.so)
43 
45 {
48 
50  // Default set to full SvtxTrackSeeds. Can be set to
51  // SiliconTrackSeedContainer or TpcTrackSeedContainer
52  converter->setTrackSeedName("SvtxTrackSeedContainer");
53  converter->setFieldMap(G4MAGNET::magfield);
54  converter->Verbosity(verbosity);
55  se->registerSubsystem(converter);
56 }
57 
59 {
60  // set up verbosity
62 
63  // get fun4all server instance
64  auto se = Fun4AllServer::instance();
65 
66  // Assemble silicon clusters into track stubs
67 
68  auto silicon_Seeding = new PHActsSiliconSeeding;
69  silicon_Seeding->Verbosity(verbosity);
70  se->registerSubsystem(silicon_Seeding);
71 
72  auto merger = new PHSiliconSeedMerger;
73  merger->Verbosity(verbosity);
74  se->registerSubsystem(merger);
75 
76  auto seeder = new PHCASeeding("PHCASeeding");
77  seeder->set_field_dir(G4MAGNET::magfield_rescale); // to get charge sign right
78 
79  if (G4MAGNET::magfield.find("3d") != std::string::npos)
80  {
81  seeder->set_field_dir(-1 * G4MAGNET::magfield_rescale);
82  seeder->useConstBField(false);
83  }
84  if (G4MAGNET::magfield.find(".root") == std::string::npos)
85  {
87  seeder->useConstBField(true);
88  seeder->constBField(std::stod(G4MAGNET::magfield));
89  }
90  seeder->Verbosity(verbosity);
91  seeder->SetLayerRange(7, 55);
92  seeder->SetSearchWindow(1.5, 0.05); // (z width, phi width)
93  seeder->SetMinHitsPerCluster(0);
94  seeder->SetMinClustersPerTrack(3);
95  seeder->useFixedClusterError(true);
96  se->registerSubsystem(seeder);
97 
98  // expand stubs in the TPC using simple kalman filter
99  auto cprop = new PHSimpleKFProp("PHSimpleKFProp");
100  cprop->set_field_dir(G4MAGNET::magfield_rescale);
101  if (G4MAGNET::magfield.find("3d") != std::string::npos)
102  {
103  cprop->set_field_dir(-1 * G4MAGNET::magfield_rescale);
104  }
105  if (G4MAGNET::magfield.find(".root") == std::string::npos)
106  {
107  cprop->useConstBField(false);
108  cprop->setConstBField(std::stod(G4MAGNET::magfield));
109  }
110  cprop->useFixedClusterError(true);
111  cprop->set_max_window(5.);
112  cprop->Verbosity(verbosity);
113  se->registerSubsystem(cprop);
114 
115  std::cout << "Tracking_Reco_TrackSeed - Using stub matching for Si matching " << std::endl;
116  // The normal silicon association methods
117  // Match the TPC track stubs from the CA seeder to silicon track stubs from PHSiliconTruthTrackSeeding
118  auto silicon_match = new PHSiliconTpcTrackMatching;
119  silicon_match->Verbosity(verbosity);
120  silicon_match->set_pp_mode(TRACKING::pp_mode);
121  std::cout << "PHSiliconTpcTrackMatching pp_mode set to " << TRACKING::pp_mode << std::endl;
123  {
124  // search windows for initial matching with distortions
125  // tuned values are 0.04 and 0.008 in distorted events
126  silicon_match->set_phi_search_window(0.04);
127  silicon_match->set_eta_search_window(0.008);
128  }
129  else
130  {
131  // after distortion corrections and rerunning clustering, default tuned values are 0.02 and 0.004 in low occupancy events
132  silicon_match->set_phi_search_window(0.03);
133  silicon_match->set_eta_search_window(0.005);
134  }
135  silicon_match->set_test_windows_printout(false); // used for tuning search windows
136  se->registerSubsystem(silicon_match);
137 
138  // Associate Micromegas clusters with the tracks
139  if (Enable::MICROMEGAS)
140  {
141  std::cout << "Tracking_Reco_TrackSeed - Using Micromegas matching " << std::endl;
142 
143  // Match TPC track stubs from CA seeder to clusters in the micromegas layers
144  auto mm_match = new PHMicromegasTpcTrackMatching;
145  mm_match->Verbosity(verbosity);
147  {
148  // configuration is potentially with different search windows
149  mm_match->set_rphi_search_window_lyr1(0.2);
150  mm_match->set_rphi_search_window_lyr2(13.0);
151  mm_match->set_z_search_window_lyr1(26.0);
152  mm_match->set_z_search_window_lyr2(0.2);
153  }
154  else
155  {
156  // baseline configuration is (0.2, 13.0, 26, 0.2) and is the default
157  mm_match->set_rphi_search_window_lyr1(0.2);
158  mm_match->set_rphi_search_window_lyr2(13.0);
159  mm_match->set_z_search_window_lyr1(26.0);
160  mm_match->set_z_search_window_lyr2(0.2);
161  }
162  mm_match->set_min_tpc_layer(38); // layer in TPC to start projection fit
163  mm_match->set_test_windows_printout(false); // used for tuning search windows only
164  se->registerSubsystem(mm_match);
165  }
166 }
167 
169 {
172 
173  TrackingIterationCounter* counter = new TrackingIterationCounter("TrkrIter1");
175  counter->iteration(0);
176  se->registerSubsystem(counter);
177 
178  PHActsSiliconSeeding* silseed = new PHActsSiliconSeeding("PHActsSiliconSeedingIt1");
179  silseed->Verbosity(verbosity);
180  silseed->searchInIntt();
181  silseed->iteration(1);
182  silseed->set_track_map_name("SiliconTrackSeedContainerIt1");
183  se->registerSubsystem(silseed);
184 
185  PHSiliconSeedMerger* merger = new PHSiliconSeedMerger("SiliconSeedMargerIt1");
186  merger->Verbosity(verbosity);
187  merger->clusterOverlap(2);
188  merger->searchIntt();
189  merger->trackMapName("SiliconTrackSeedContainerIt1");
190  se->registerSubsystem(merger);
191 
193  combiner->newContainerName("SiliconTrackSeedContainer");
194  combiner->oldContainerName("SiliconTrackSeedContainerIt1");
195  combiner->Verbosity(verbosity);
196  se->registerSubsystem(combiner);
197 }
198 
199 void vertexing()
200 {
203 
204  auto vtxfinder = new PHSimpleVertexFinder;
205  vtxfinder->Verbosity(verbosity);
206  se->registerSubsystem(vtxfinder);
207 }
208 
210 {
212  auto se = Fun4AllServer::instance();
213 
214  // correct clusters for particle propagation in TPC
215  auto deltazcorr = new PHTpcDeltaZCorrection;
216  deltazcorr->Verbosity(verbosity);
217  se->registerSubsystem(deltazcorr);
218 
219  // perform final track fit with ACTS
220  auto actsFit = new PHActsTrkFitter;
221  actsFit->Verbosity(verbosity);
222  actsFit->commissioning(G4TRACKING::use_alignment);
223  // in calibration mode, fit only Silicons and Micromegas hits
224  actsFit->fitSiliconMMs(G4TRACKING::SC_CALIBMODE);
225  actsFit->setUseMicromegas(G4TRACKING::SC_USE_MICROMEGAS);
226  actsFit->set_pp_mode(TRACKING::pp_mode);
227  actsFit->useActsEvaluator(false);
228  actsFit->useOutlierFinder(false);
229  actsFit->setFieldMap(G4MAGNET::magfield);
230  se->registerSubsystem(actsFit);
231 
233  {
234  /*
235  * in calibration mode, calculate residuals between TPC and fitted tracks,
236  * store in dedicated structure for distortion correction
237  */
238  auto residuals = new PHTpcResiduals;
240  residuals->setUseMicromegas(G4TRACKING::SC_USE_MICROMEGAS);
241  residuals->Verbosity(verbosity);
242  se->registerSubsystem(residuals);
243  }
244  else
245  {
246  /*
247  * in full tracking mode, run track cleaner, vertex finder,
248  * propagete tracks to vertex
249  * propagate tracks to EMCAL
250  */
251 
253  {
254  // Choose the best silicon matched track for each TPC track seed
255  /* this breaks in truth_track seeding mode because there is no TpcSeed */
256  auto cleaner = new PHTrackCleaner;
257  cleaner->Verbosity(verbosity);
258  se->registerSubsystem(cleaner);
259  }
260 
261  vertexing();
262 
263  // Propagate track positions to the vertex position
264  auto vtxProp = new PHActsVertexPropagator;
265  vtxProp->Verbosity(verbosity);
266  vtxProp->fieldMap(G4MAGNET::magfield);
267  se->registerSubsystem(vtxProp);
268 
269  // project tracks to EMCAL
270  auto projection = new PHActsTrackProjection;
271  projection->Verbosity(verbosity);
272  if (G4MAGNET::magfield.find(".root") == std::string::npos)
273  {
274  projection->setConstFieldVal(std::stod(G4MAGNET::magfield));
275  }
276  se->registerSubsystem(projection);
277  }
278 }
279 
281 {
282  // set up verbosity
284 
285  // get fun4all server instance
286  auto se = Fun4AllServer::instance();
287 
288  auto silicon_Seeding = new PHActsSiliconSeeding;
289  silicon_Seeding->Verbosity(verbosity);
290  silicon_Seeding->sigmaScattering(50.);
291  silicon_Seeding->setRPhiSearchWindow(2.);
292  silicon_Seeding->helixcut(0.01);
293  se->registerSubsystem(silicon_Seeding);
294 
295  auto merger = new PHSiliconSeedMerger;
296  merger->Verbosity(verbosity);
297  se->registerSubsystem(merger);
298 
299  // Assemble TPC clusters into track stubs
300  auto seeder = new PHCASeeding("PHCASeeding");
301  seeder->set_field_dir(G4MAGNET::magfield_rescale); // to get charge sign right
302  if (G4MAGNET::magfield.find("3d") != std::string::npos)
303  {
304  seeder->set_field_dir(-1 * G4MAGNET::magfield_rescale);
305  }
306  seeder->Verbosity(verbosity);
307  seeder->SetLayerRange(7, 55);
308  seeder->SetSearchWindow(1.5, 0.05); // (z width, phi width)
309  seeder->SetMinHitsPerCluster(0);
310  seeder->SetMinClustersPerTrack(3);
311  seeder->useConstBField(false);
312  seeder->useFixedClusterError(true);
313  se->registerSubsystem(seeder);
314 
315  // expand stubs in the TPC using simple kalman filter
316  auto cprop = new PHSimpleKFProp("PHSimpleKFProp");
317  cprop->set_field_dir(G4MAGNET::magfield_rescale);
318  if (G4MAGNET::magfield.find("3d") != std::string::npos)
319  {
320  cprop->set_field_dir(-1 * G4MAGNET::magfield_rescale);
321  }
322  cprop->useConstBField(false);
323  cprop->useFixedClusterError(true);
324  cprop->set_max_window(5.);
325  cprop->Verbosity(verbosity);
326  se->registerSubsystem(cprop);
327 
328  // match silicon track seeds to TPC track seeds
329 
330  // The normal silicon association methods
331  // Match the TPC track stubs from the CA seeder to silicon track stubs from PHSiliconTruthTrackSeeding
332  auto silicon_match = new PHSiliconTpcTrackMatching;
333  silicon_match->Verbosity(verbosity);
334  silicon_match->set_pp_mode(TRACKING::pp_mode);
335 
336  silicon_match->set_phi_search_window(0.2);
337  silicon_match->set_eta_search_window(0.015);
338  silicon_match->set_x_search_window(std::numeric_limits<double>::max());
339  silicon_match->set_y_search_window(std::numeric_limits<double>::max());
340  silicon_match->set_z_search_window(std::numeric_limits<double>::max());
341 
342  silicon_match->set_test_windows_printout(false); // used for tuning search windows
343  se->registerSubsystem(silicon_match);
344 
345  // Associate Micromegas clusters with the tracks
346  if (Enable::MICROMEGAS)
347  {
348  // Match TPC track stubs from CA seeder to clusters in the micromegas layers
349  auto mm_match = new PHMicromegasTpcTrackMatching;
350  mm_match->Verbosity(verbosity);
351 
352  mm_match->set_rphi_search_window_lyr1(0.4);
353  mm_match->set_rphi_search_window_lyr2(13.0);
354  mm_match->set_z_search_window_lyr1(26.0);
355  mm_match->set_z_search_window_lyr2(0.2);
356 
357  mm_match->set_min_tpc_layer(38); // layer in TPC to start projection fit
358  mm_match->set_test_windows_printout(false); // used for tuning search windows only
359  se->registerSubsystem(mm_match);
360  }
361 }
362 
363 void alignment(std::string datafilename = "mille_output_data_file",
364  std::string steeringfilename = "mille_steer")
365 {
368 
369  auto mille = new MakeMilleFiles;
370  mille->Verbosity(verbosity);
371  mille->set_datafile_name(datafilename + ".bin");
372  mille->set_steeringfile_name(steeringfilename + ".txt");
373  se->registerSubsystem(mille);
374 
375  auto helical = new HelicalFitter;
376  helical->Verbosity(0);
377  helical->set_datafile_name(datafilename + "_helical.bin");
378  helical->set_steeringfile_name(steeringfilename + "_helical.txt");
379  se->registerSubsystem(helical);
380 }
381 
383 {
384  /*
385  * just a wrapper around track seeding and track fitting methods,
386  * to minimize disruption to existing steering macros
387  */
389  {
391  }
392  else
393  {
395  }
396 
398  {
399  convert_seeds();
400  vertexing();
401  }
402  else
403  {
405  }
406 
408  {
410 
412  {
413  convert_seeds();
414  vertexing();
415  }
416  }
417 
419  {
420  alignment();
421  }
422 }
423 
425 {
428  secvert->Verbosity(0);
429  // secvert->set_write_electrons_node(true); // writes copy of filtered electron tracks to node tree
430  // secvert->set_write_ntuple(false); // writes ntuple for tuning cuts
431  secvert->setDecayParticleMass(0.000511); // for electrons
432  secvert->setOutfileName(ntuple_outfile);
433  se->registerSubsystem(secvert);
434 }
435 
436 #endif