Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:24:06

0001 #ifndef MACRO_TRKRTRUTHRECO_C
0002 #define MACRO_TRKRTRUTHRECO_C
0003 
0004 #include <GlobalVariables.C>
0005 
0006 #include <G4_TrkrVariables.C>
0007 
0008 #include <g4eval/SvtxTruthRecoTableEval.h>
0009 
0010 #include <trackingdiagnostics/TrackSeedTrackMapConverter.h>
0011 
0012 #include <trackreco/MakeActsGeometry.h>
0013 #include <trackreco/PHActsSiliconSeeding.h>
0014 #include <trackreco/PHActsTrackProjection.h>
0015 #include <trackreco/PHActsTrkFitter.h>
0016 #include <trackreco/PHActsVertexPropagator.h>
0017 #include <trackreco/PHCASeeding.h>
0018 #include <trackreco/PHGenFitTrkFitter.h>
0019 #include <trackreco/PHMicromegasTpcTrackMatching.h>
0020 #include <trackreco/PHSiliconSeedMerger.h>
0021 #include <trackreco/PHSiliconTpcTrackMatching.h>
0022 #include <trackreco/PHSimpleKFProp.h>
0023 #include <trackreco/PHSimpleVertexFinder.h>
0024 #include <trackreco/PHTpcDeltaZCorrection.h>
0025 #include <trackreco/PHTrackCleaner.h>
0026 #include <trackreco/PHTrackSeeding.h>
0027 #include <trackreco/PHTruthSiliconAssociation.h>
0028 #include <trackreco/PHTruthTrackSeeding.h>
0029 #include <trackreco/PHTruthVertexing.h>
0030 #include <trackreco/SecondaryVertexFinder.h>
0031 
0032 #include <tpc/TpcLoadDistortionCorrection.h>
0033 
0034 #include <tpccalib/PHTpcResiduals.h>
0035 
0036 #include <trackermillepedealignment/HelicalFitter.h>
0037 #include <trackermillepedealignment/MakeMilleFiles.h>
0038 
0039 #include <fun4all/Fun4AllServer.h>
0040 
0041 R__LOAD_LIBRARY(libTrackingDiagnostics.so)
0042 R__LOAD_LIBRARY(libtrack_reco.so)
0043 R__LOAD_LIBRARY(libtpccalib.so)
0044 R__LOAD_LIBRARY(libtrackeralign.so)
0045 R__LOAD_LIBRARY(libg4eval.so)
0046 
0047 void convert_seeds()
0048 {
0049   Fun4AllServer *se = Fun4AllServer::instance();
0050   int verbosity = std::max(Enable::VERBOSITY, Enable::TRACKING_VERBOSITY);
0051 
0052   TrackSeedTrackMapConverter *converter = new TrackSeedTrackMapConverter();
0053   // Default set to full SvtxTrackSeeds. Can be set to
0054   // SiliconTrackSeedContainer or TpcTrackSeedContainer
0055   converter->setTrackSeedName("SvtxTrackSeedContainer");
0056   converter->Verbosity(verbosity);
0057   se->registerSubsystem(converter);
0058 }
0059 
0060 void Tracking_Reco_TrackSeed()
0061 {
0062   // set up verbosity
0063   int verbosity = std::max(Enable::VERBOSITY, Enable::TRACKING_VERBOSITY);
0064 
0065   // get fun4all server instance
0066   auto *se = Fun4AllServer::instance();
0067 
0068   if (!G4TRACKING::use_full_truth_track_seeding)
0069   {
0070     // Assemble silicon clusters into track stubs
0071     if (G4TRACKING::use_truth_silicon_seeding)
0072     {
0073       // For the silicon, for each truth particle, create a track and associate clusters with it using truth information, write to silicon track map
0074       // track stubs are given the location of the truth vertex in this module
0075       auto *pat_rec = new PHTruthTrackSeeding("PHTruthTrackSeedingSilicon");
0076       pat_rec->Verbosity(verbosity);
0077       pat_rec->set_track_map_name("SiliconTrackSeedContainer");
0078       pat_rec->set_min_layer(0);
0079       pat_rec->set_max_layer(G4MVTX::n_maps_layer + G4INTT::n_intt_layer);
0080       se->registerSubsystem(pat_rec);
0081     }
0082     else
0083     {
0084       auto *silicon_Seeding = new PHActsSiliconSeeding;
0085       silicon_Seeding->Verbosity(verbosity);
0086       std::cout << "SETTING SI SEED CV" << std::endl;
0087       se->registerSubsystem(silicon_Seeding);
0088 
0089       auto *merger = new PHSiliconSeedMerger;
0090       merger->Verbosity(verbosity);
0091       se->registerSubsystem(merger);
0092     }
0093 
0094     // Assemble TPC clusters into track stubs
0095     if (G4TRACKING::use_truth_tpc_seeding)
0096     {
0097       // For the TPC, for each truth particle, create a track and associate clusters with it using truth information, write to Svtx track map
0098       // track stubs are given the position odf the truth vertex in this module
0099       auto *pat_rec = new PHTruthTrackSeeding("PHTruthTrackSeedingTpc");
0100       pat_rec->Verbosity(verbosity);
0101       pat_rec->set_track_map_name("TpcTrackSeedContainer");
0102       pat_rec->set_min_layer(G4MVTX::n_maps_layer + G4INTT::n_intt_layer);
0103       pat_rec->set_max_layer(G4MVTX::n_maps_layer + G4INTT::n_intt_layer + G4TPC::n_gas_layer);
0104       se->registerSubsystem(pat_rec);
0105     }
0106     else
0107     {
0108       auto *seeder = new PHCASeeding("PHCASeeding");
0109       seeder->set_field_dir(G4MAGNET::magfield_rescale);                // to get charge sign right
0110       double fieldstrength = std::numeric_limits<double>::quiet_NaN();  // set by isConstantField if constant
0111       bool ConstField = isConstantField(G4MAGNET::magfield_tracking, fieldstrength);
0112 
0113       if (!ConstField)
0114       {
0115         seeder->set_field_dir(-1 * G4MAGNET::magfield_rescale);
0116         seeder->useConstBField(false);
0117       }
0118       seeder->Verbosity(verbosity);
0119       seeder->SetLayerRange(7, 55);
0120       seeder->SetSearchWindow(1.5, 0.05);  // (z width, phi width)
0121       seeder->SetMinHitsPerCluster(0);
0122       seeder->SetMinClustersPerTrack(3);
0123       seeder->useFixedClusterError(true);
0124 
0125       if (G4TPC::TPC_GAS_MIXTURE == "NeCF4")
0126       {
0127         seeder->setNeonFraction(G4TPC::NeCF4_Ne_frac);
0128         seeder->setArgonFraction(G4TPC::NeCF4_Ar_frac);
0129         seeder->setCF4Fraction(G4TPC::NeCF4_CF4_frac);
0130         seeder->setNitrogenFraction(G4TPC::NeCF4_N2_frac);
0131         seeder->setIsobutaneFraction(G4TPC::NeCF4_isobutane_frac);
0132       }
0133       else if (G4TPC::TPC_GAS_MIXTURE == "ArCF4")
0134       {
0135         seeder->setNeonFraction(G4TPC::ArCF4_Ne_frac);
0136         seeder->setArgonFraction(G4TPC::ArCF4_Ar_frac);
0137         seeder->setCF4Fraction(G4TPC::ArCF4_CF4_frac);
0138         seeder->setNitrogenFraction(G4TPC::ArCF4_N2_frac);
0139         seeder->setIsobutaneFraction(G4TPC::ArCF4_isobutane_frac);
0140       }
0141       else if (G4TPC::TPC_GAS_MIXTURE == "ArCF4N2")
0142       {
0143         seeder->setNeonFraction(G4TPC::ArCF4N2_Ne_frac);
0144         seeder->setArgonFraction(G4TPC::ArCF4N2_Ar_frac);
0145         seeder->setCF4Fraction(G4TPC::ArCF4N2_CF4_frac);
0146         seeder->setNitrogenFraction(G4TPC::ArCF4N2_N2_frac);
0147         seeder->setIsobutaneFraction(G4TPC::ArCF4N2_isobutane_frac);
0148       }
0149       else if (G4TPC::TPC_GAS_MIXTURE == "ArCF4Isobutane")
0150       {
0151         seeder->setNeonFraction(G4TPC::ArCF4Isobutane_Ne_frac);
0152         seeder->setArgonFraction(G4TPC::ArCF4Isobutane_Ar_frac);
0153         seeder->setCF4Fraction(G4TPC::ArCF4Isobutane_CF4_frac);
0154         seeder->setNitrogenFraction(G4TPC::ArCF4Isobutane_N2_frac);
0155         seeder->setIsobutaneFraction(G4TPC::ArCF4Isobutane_isobutane_frac);
0156       }
0157       else
0158       {
0159       }
0160 
0161       se->registerSubsystem(seeder);
0162 
0163       // expand stubs in the TPC using simple kalman filter
0164       auto *cprop = new PHSimpleKFProp("PHSimpleKFProp");
0165       cprop->set_field_dir(G4MAGNET::magfield_rescale);
0166       if (!ConstField)
0167       {
0168         cprop->set_field_dir(-1 * G4MAGNET::magfield_rescale);
0169         cprop->useConstBField(false);
0170       }
0171       cprop->useFixedClusterError(true);
0172       cprop->set_max_window(5.);
0173       cprop->Verbosity(verbosity);
0174 
0175       if (G4TPC::TPC_GAS_MIXTURE == "NeCF4")
0176       {
0177         cprop->setNeonFraction(G4TPC::NeCF4_Ne_frac);
0178         cprop->setArgonFraction(G4TPC::NeCF4_Ar_frac);
0179         cprop->setCF4Fraction(G4TPC::NeCF4_CF4_frac);
0180         cprop->setNitrogenFraction(G4TPC::NeCF4_N2_frac);
0181         cprop->setIsobutaneFraction(G4TPC::NeCF4_isobutane_frac);
0182       }
0183       else if (G4TPC::TPC_GAS_MIXTURE == "ArCF4")
0184       {
0185         cprop->setNeonFraction(G4TPC::ArCF4_Ne_frac);
0186         cprop->setArgonFraction(G4TPC::ArCF4_Ar_frac);
0187         cprop->setCF4Fraction(G4TPC::ArCF4_CF4_frac);
0188         cprop->setNitrogenFraction(G4TPC::ArCF4_N2_frac);
0189         cprop->setIsobutaneFraction(G4TPC::ArCF4_isobutane_frac);
0190       }
0191       else if (G4TPC::TPC_GAS_MIXTURE == "ArCF4N2")
0192       {
0193         cprop->setNeonFraction(G4TPC::ArCF4N2_Ne_frac);
0194         cprop->setArgonFraction(G4TPC::ArCF4N2_Ar_frac);
0195         cprop->setCF4Fraction(G4TPC::ArCF4N2_CF4_frac);
0196         cprop->setNitrogenFraction(G4TPC::ArCF4N2_N2_frac);
0197         cprop->setIsobutaneFraction(G4TPC::ArCF4N2_isobutane_frac);
0198       }
0199       else if (G4TPC::TPC_GAS_MIXTURE == "ArCF4Isobutane")
0200       {
0201         cprop->setNeonFraction(G4TPC::ArCF4Isobutane_Ne_frac);
0202         cprop->setArgonFraction(G4TPC::ArCF4Isobutane_Ar_frac);
0203         cprop->setCF4Fraction(G4TPC::ArCF4Isobutane_CF4_frac);
0204         cprop->setNitrogenFraction(G4TPC::ArCF4Isobutane_N2_frac);
0205         cprop->setIsobutaneFraction(G4TPC::ArCF4Isobutane_isobutane_frac);
0206       }
0207       else
0208       {
0209       }
0210 
0211       se->registerSubsystem(cprop);
0212     }
0213 
0214     // match silicon track seeds to TPC track seeds
0215     if (G4TRACKING::use_truth_si_matching)
0216     {
0217       std::cout << "Tracking_Reco_TrackSeed - Using truth Si matching " << std::endl;
0218       // use truth particle matching in TPC to assign clusters in silicon to TPC tracks from CA seeder
0219       auto *silicon_assoc = new PHTruthSiliconAssociation;
0220       silicon_assoc->Verbosity(verbosity);
0221       se->registerSubsystem(silicon_assoc);
0222     }
0223     else
0224     {
0225       std::cout << "Tracking_Reco_TrackSeed - Using stub matching for Si matching " << std::endl;
0226       // The normal silicon association methods
0227       // Match the TPC track stubs from the CA seeder to silicon track stubs from PHSiliconTruthTrackSeeding
0228       auto *silicon_match = new PHSiliconTpcTrackMatching;
0229       silicon_match->Verbosity(verbosity);
0230       silicon_match->set_pp_mode(TRACKING::pp_mode);
0231       std::cout << "PHSiliconTpcTrackMatching pp_mode set to " << TRACKING::pp_mode << std::endl;
0232       if (G4TRACKING::SC_CALIBMODE)
0233       {
0234         // search windows for initial matching with distortions
0235         // tuned values are 0.04 and 0.008 in distorted events
0236         silicon_match->set_phi_search_window(0.04);
0237         silicon_match->set_eta_search_window(0.008);
0238       }
0239       else
0240       {
0241         // after distortion corrections and rerunning clustering, default tuned values are 0.02 and 0.004 in low occupancy events
0242         silicon_match->set_phi_search_window(0.03);
0243         silicon_match->set_eta_search_window(0.005);
0244       }
0245       silicon_match->set_test_windows_printout(false);  // used for tuning search windows
0246       se->registerSubsystem(silicon_match);
0247     }
0248 
0249     // Associate Micromegas clusters with the tracks
0250     if (Enable::MICROMEGAS)
0251     {
0252       std::cout << "Tracking_Reco_TrackSeed - Using Micromegas matching " << std::endl;
0253 
0254       // Match TPC track stubs from CA seeder to clusters in the micromegas layers
0255       auto *mm_match = new PHMicromegasTpcTrackMatching;
0256       mm_match->Verbosity(verbosity);
0257 
0258       mm_match->set_rphi_search_window_lyr1(0.2);
0259       mm_match->set_rphi_search_window_lyr2(13.0);
0260       mm_match->set_z_search_window_lyr1(26.0);
0261       mm_match->set_z_search_window_lyr2(0.2);
0262 
0263       mm_match->set_min_tpc_layer(38);             // layer in TPC to start projection fit
0264       mm_match->set_test_windows_printout(false);  // used for tuning search windows only
0265       se->registerSubsystem(mm_match);
0266     }
0267   }
0268   else
0269   {
0270     // full truth track finding
0271     std::cout << "Tracking_Reco_TrackSeed - Using full truth track seeding" << std::endl;
0272 
0273     // For each truth particle, create a track and associate clusters with it using truth information, write to Svtx track map
0274     // track stubs are given the position of the truth vertex in this module, but Genfit does not care
0275     // Includes clusters for TPC, silicon and MM's
0276     auto *pat_rec = new PHTruthTrackSeeding("PHTruthTrackSeedingFull");
0277     pat_rec->Verbosity(verbosity);
0278     pat_rec->set_track_map_name("SvtxTrackSeedContainer");
0279     se->registerSubsystem(pat_rec);
0280   }
0281 
0282   /*
0283    * all done
0284    * at this stage tracks are fully assembled. They contain clusters spaning Silicon detectors, TPC and Micromegas
0285    * they are ready to be fit.
0286    */
0287   if (G4TRACKING::convert_seeds_to_svtxtracks)
0288   {
0289     convert_seeds();
0290   }
0291 }
0292 
0293 void vertexing()
0294 {
0295   Fun4AllServer *se = Fun4AllServer::instance();
0296   int verbosity = std::max(Enable::VERBOSITY, Enable::TRACKING_VERBOSITY);
0297   if (G4TRACKING::use_truth_vertexing)
0298   {
0299     auto *vtxing = new PHTruthVertexing;
0300     vtxing->associate_tracks(true);
0301     std::string trackmapnamef = "SvtxTrackMap";
0302     vtxing->set_track_map_name(trackmapnamef);
0303     se->registerSubsystem(vtxing);
0304   }
0305   else
0306   {
0307     auto *vtxfinder = new PHSimpleVertexFinder;
0308     vtxfinder->Verbosity(verbosity);
0309     se->registerSubsystem(vtxfinder);
0310   }
0311 }
0312 
0313 void Tracking_Reco_TrackFit()
0314 {
0315   int verbosity = std::max(Enable::VERBOSITY, Enable::TRACKING_VERBOSITY);
0316   auto *se = Fun4AllServer::instance();
0317 
0318   // correct clusters for particle propagation in TPC
0319   auto *deltazcorr = new PHTpcDeltaZCorrection;
0320   deltazcorr->Verbosity(verbosity);
0321   se->registerSubsystem(deltazcorr);
0322 
0323   if (G4TRACKING::use_genfit_track_fitter)
0324   {
0325     // perform final track fit with GENFIT
0326     auto *genfitFit = new PHGenFitTrkFitter;
0327     genfitFit->Verbosity(verbosity);
0328     genfitFit->set_fit_silicon_mms(G4TRACKING::SC_CALIBMODE);
0329     se->registerSubsystem(genfitFit);
0330 
0331     if (G4TRACKING::SC_CALIBMODE)
0332     {
0333       /*
0334       * in calibration mode, calculate residuals between TPC and fitted tracks,
0335       * store in dedicated structure for distortion correction
0336       */
0337       auto *residuals = new PHTpcResiduals;
0338       residuals->setTrackMapName("SvtxTrackMap");
0339       residuals->setOutputfile(G4TRACKING::SC_ROOTOUTPUT_FILENAME);
0340       residuals->setUseMicromegas(G4TRACKING::SC_USE_MICROMEGAS);
0341       // reconstructed distortion grid size (phi, r, z)
0342       residuals->setGridDimensions(36, 48, 80);
0343       residuals->Verbosity(verbosity);
0344       se->registerSubsystem(residuals);
0345     }
0346   }
0347   else
0348   {
0349     // perform final track fit with ACTS
0350     auto *actsFit = new PHActsTrkFitter;
0351     actsFit->Verbosity(verbosity);
0352     // actsFit->commissioning(G4TRACKING::use_alignment);
0353 
0354     // in calibration mode, fit only Silicons and Micromegas hits
0355     actsFit->fitSiliconMMs(G4TRACKING::SC_CALIBMODE);
0356     actsFit->setUseMicromegas(G4TRACKING::SC_USE_MICROMEGAS);
0357     actsFit->set_pp_mode(TRACKING::pp_mode);
0358     actsFit->set_use_clustermover(true);
0359     actsFit->useActsEvaluator(false);
0360     actsFit->useOutlierFinder(false);
0361     actsFit->setFieldMap(G4MAGNET::magfield_tracking);
0362     se->registerSubsystem(actsFit);
0363 
0364     if (G4TRACKING::SC_CALIBMODE)
0365     {
0366       /*
0367        * in calibration mode, calculate residuals between TPC and fitted tracks,
0368        * store in dedicated structure for distortion correction
0369        */
0370       auto *residuals = new PHTpcResiduals;
0371       residuals->setOutputfile(G4TRACKING::SC_ROOTOUTPUT_FILENAME);
0372       residuals->setUseMicromegas(G4TRACKING::SC_USE_MICROMEGAS);
0373       // reconstructed distortion grid size (phi, r, z)
0374       residuals->setGridDimensions(36, 48, 80);
0375       residuals->Verbosity(verbosity);
0376       se->registerSubsystem(residuals);
0377     }
0378   }
0379 
0380   if (!G4TRACKING::SC_CALIBMODE)
0381   {
0382     /*
0383      * in full tracking mode, run track cleaner, vertex finder,
0384      * propagete tracks to vertex
0385      * propagate tracks to EMCAL
0386      */
0387 
0388     if (!G4TRACKING::use_full_truth_track_seeding)
0389     {
0390       // Choose the best silicon matched track for each TPC track seed
0391       /* this breaks in truth_track seeding mode because there is no TpcSeed */
0392       auto *cleaner = new PHTrackCleaner;
0393       cleaner->Verbosity(verbosity);
0394       se->registerSubsystem(cleaner);
0395     }
0396 
0397     vertexing();
0398 
0399     if (!G4TRACKING::use_genfit_track_fitter)
0400     {
0401       // Propagate track positions to the vertex position
0402       auto *vtxProp = new PHActsVertexPropagator;
0403       vtxProp->Verbosity(verbosity);
0404       vtxProp->fieldMap(G4MAGNET::magfield_tracking);
0405       se->registerSubsystem(vtxProp);
0406 
0407       // project tracks to EMCAL
0408       auto *projection = new PHActsTrackProjection;
0409       projection->Verbosity(verbosity);
0410       double fieldstrength = std::numeric_limits<double>::quiet_NaN();
0411       if (isConstantField(G4MAGNET::magfield_tracking, fieldstrength))
0412       {
0413         projection->setConstFieldVal(fieldstrength);
0414       }
0415       se->registerSubsystem(projection);
0416     }
0417   }
0418 }
0419 
0420 void Tracking_Reco_CommissioningTrackSeed()
0421 {
0422   // set up verbosity
0423   int verbosity = std::max(Enable::VERBOSITY, Enable::TRACKING_VERBOSITY);
0424 
0425   // get fun4all server instance
0426   auto *se = Fun4AllServer::instance();
0427 
0428   auto *silicon_Seeding = new PHActsSiliconSeeding;
0429   silicon_Seeding->Verbosity(verbosity);
0430   silicon_Seeding->sigmaScattering(50.);
0431   silicon_Seeding->setinttRPhiSearchWindow(0.4);
0432   se->registerSubsystem(silicon_Seeding);
0433 
0434   auto *merger = new PHSiliconSeedMerger;
0435   merger->Verbosity(verbosity);
0436   se->registerSubsystem(merger);
0437 
0438   // Assemble TPC clusters into track stubs
0439   auto *seeder = new PHCASeeding("PHCASeeding");
0440   seeder->set_field_dir(G4MAGNET::magfield_rescale);                // to get charge sign right
0441   double fieldstrength = std::numeric_limits<double>::quiet_NaN();  // set by isConstantField if constant
0442   bool ConstField = isConstantField(G4MAGNET::magfield_tracking, fieldstrength);
0443   if (!ConstField)
0444   {
0445     seeder->magFieldFile(G4MAGNET::magfield_tracking);
0446     seeder->set_field_dir(-1 * G4MAGNET::magfield_rescale);
0447   }
0448   seeder->Verbosity(verbosity);
0449   seeder->SetLayerRange(7, 55);
0450   seeder->SetSearchWindow(1.5, 0.05);  // (z width, phi width)
0451   seeder->SetMinHitsPerCluster(0);
0452   seeder->SetMinClustersPerTrack(3);
0453   seeder->useConstBField(false);
0454   seeder->useFixedClusterError(true);
0455 
0456   if (G4TPC::TPC_GAS_MIXTURE == "NeCF4")
0457   {
0458     seeder->setNeonFraction(G4TPC::NeCF4_Ne_frac);
0459     seeder->setArgonFraction(G4TPC::NeCF4_Ar_frac);
0460     seeder->setCF4Fraction(G4TPC::NeCF4_CF4_frac);
0461     seeder->setNitrogenFraction(G4TPC::NeCF4_N2_frac);
0462     seeder->setIsobutaneFraction(G4TPC::NeCF4_isobutane_frac);
0463   }
0464   else if (G4TPC::TPC_GAS_MIXTURE == "ArCF4")
0465   {
0466     seeder->setNeonFraction(G4TPC::ArCF4_Ne_frac);
0467     seeder->setArgonFraction(G4TPC::ArCF4_Ar_frac);
0468     seeder->setCF4Fraction(G4TPC::ArCF4_CF4_frac);
0469     seeder->setNitrogenFraction(G4TPC::ArCF4_N2_frac);
0470     seeder->setIsobutaneFraction(G4TPC::ArCF4_isobutane_frac);
0471   }
0472   else if (G4TPC::TPC_GAS_MIXTURE == "ArCF4N2")
0473   {
0474     seeder->setNeonFraction(G4TPC::ArCF4N2_Ne_frac);
0475     seeder->setArgonFraction(G4TPC::ArCF4N2_Ar_frac);
0476     seeder->setCF4Fraction(G4TPC::ArCF4N2_CF4_frac);
0477     seeder->setNitrogenFraction(G4TPC::ArCF4N2_N2_frac);
0478     seeder->setIsobutaneFraction(G4TPC::ArCF4N2_isobutane_frac);
0479   }
0480   else if (G4TPC::TPC_GAS_MIXTURE == "ArCF4Isobutane")
0481   {
0482     seeder->setNeonFraction(G4TPC::ArCF4Isobutane_Ne_frac);
0483     seeder->setArgonFraction(G4TPC::ArCF4Isobutane_Ar_frac);
0484     seeder->setCF4Fraction(G4TPC::ArCF4Isobutane_CF4_frac);
0485     seeder->setNitrogenFraction(G4TPC::ArCF4Isobutane_N2_frac);
0486     seeder->setIsobutaneFraction(G4TPC::ArCF4Isobutane_isobutane_frac);
0487   }
0488   else
0489   {
0490   }
0491 
0492   se->registerSubsystem(seeder);
0493 
0494   // expand stubs in the TPC using simple kalman filter
0495   auto *cprop = new PHSimpleKFProp("PHSimpleKFProp");
0496   cprop->set_field_dir(G4MAGNET::magfield_rescale);
0497   if (!ConstField)
0498   {
0499     cprop->set_field_dir(-1 * G4MAGNET::magfield_rescale);
0500   }
0501   cprop->useConstBField(false);
0502   cprop->useFixedClusterError(true);
0503   cprop->set_max_window(5.);
0504   cprop->Verbosity(verbosity);
0505 
0506   if (G4TPC::TPC_GAS_MIXTURE == "NeCF4")
0507   {
0508     cprop->setNeonFraction(G4TPC::NeCF4_Ne_frac);
0509     cprop->setArgonFraction(G4TPC::NeCF4_Ar_frac);
0510     cprop->setCF4Fraction(G4TPC::NeCF4_CF4_frac);
0511     cprop->setNitrogenFraction(G4TPC::NeCF4_N2_frac);
0512     cprop->setIsobutaneFraction(G4TPC::NeCF4_isobutane_frac);
0513   }
0514   else if (G4TPC::TPC_GAS_MIXTURE == "ArCF4")
0515   {
0516     cprop->setNeonFraction(G4TPC::ArCF4_Ne_frac);
0517     cprop->setArgonFraction(G4TPC::ArCF4_Ar_frac);
0518     cprop->setCF4Fraction(G4TPC::ArCF4_CF4_frac);
0519     cprop->setNitrogenFraction(G4TPC::ArCF4_N2_frac);
0520     cprop->setIsobutaneFraction(G4TPC::ArCF4_isobutane_frac);
0521   }
0522   else if (G4TPC::TPC_GAS_MIXTURE == "ArCF4N2")
0523   {
0524     cprop->setNeonFraction(G4TPC::ArCF4N2_Ne_frac);
0525     cprop->setArgonFraction(G4TPC::ArCF4N2_Ar_frac);
0526     cprop->setCF4Fraction(G4TPC::ArCF4N2_CF4_frac);
0527     cprop->setNitrogenFraction(G4TPC::ArCF4N2_N2_frac);
0528     cprop->setIsobutaneFraction(G4TPC::ArCF4N2_isobutane_frac);
0529   }
0530   else if (G4TPC::TPC_GAS_MIXTURE == "ArCF4Isobutane")
0531   {
0532     cprop->setNeonFraction(G4TPC::ArCF4Isobutane_Ne_frac);
0533     cprop->setArgonFraction(G4TPC::ArCF4Isobutane_Ar_frac);
0534     cprop->setCF4Fraction(G4TPC::ArCF4Isobutane_CF4_frac);
0535     cprop->setNitrogenFraction(G4TPC::ArCF4Isobutane_N2_frac);
0536     cprop->setIsobutaneFraction(G4TPC::ArCF4Isobutane_isobutane_frac);
0537   }
0538   else
0539   {
0540   }
0541 
0542   se->registerSubsystem(cprop);
0543 
0544   // match silicon track seeds to TPC track seeds
0545 
0546   // The normal silicon association methods
0547   // Match the TPC track stubs from the CA seeder to silicon track stubs from PHSiliconTruthTrackSeeding
0548   auto *silicon_match = new PHSiliconTpcTrackMatching;
0549   silicon_match->Verbosity(verbosity);
0550   silicon_match->set_pp_mode(TRACKING::pp_mode);
0551 
0552   silicon_match->set_phi_search_window(0.2);
0553   silicon_match->set_eta_search_window(0.015);
0554   silicon_match->set_x_search_window(std::numeric_limits<double>::max());
0555   silicon_match->set_y_search_window(std::numeric_limits<double>::max());
0556   silicon_match->set_z_search_window(std::numeric_limits<double>::max());
0557 
0558   silicon_match->set_test_windows_printout(false);  // used for tuning search windows
0559   se->registerSubsystem(silicon_match);
0560 
0561   // Associate Micromegas clusters with the tracks
0562   if (Enable::MICROMEGAS)
0563   {
0564     // Match TPC track stubs from CA seeder to clusters in the micromegas layers
0565     auto *mm_match = new PHMicromegasTpcTrackMatching;
0566     mm_match->Verbosity(verbosity);
0567 
0568     mm_match->set_rphi_search_window_lyr1(0.4);
0569     mm_match->set_rphi_search_window_lyr2(13.0);
0570     mm_match->set_z_search_window_lyr1(26.0);
0571     mm_match->set_z_search_window_lyr2(0.2);
0572 
0573     mm_match->set_min_tpc_layer(38);             // layer in TPC to start projection fit
0574     mm_match->set_test_windows_printout(false);  // used for tuning search windows only
0575     se->registerSubsystem(mm_match);
0576   }
0577   if (G4TRACKING::convert_seeds_to_svtxtracks)
0578   {
0579     convert_seeds();
0580   }
0581 }
0582 
0583 void alignment(const std::string &datafilename = "mille_output_data_file",
0584                const std::string &steeringfilename = "mille_steer")
0585 {
0586   Fun4AllServer *se = Fun4AllServer::instance();
0587   int verbosity = std::max(Enable::VERBOSITY, Enable::TRACKING_VERBOSITY);
0588 
0589   auto *mille = new MakeMilleFiles;
0590   mille->Verbosity(verbosity);
0591   mille->set_datafile_name(datafilename + ".bin");
0592   mille->set_steeringfile_name(steeringfilename + ".txt");
0593   se->registerSubsystem(mille);
0594 
0595   auto *helical = new HelicalFitter;
0596   helical->Verbosity(0);
0597   helical->set_datafile_name(datafilename + "_helical.bin");
0598   helical->set_steeringfile_name(steeringfilename + "_helical.txt");
0599   se->registerSubsystem(helical);
0600 }
0601 
0602 void Tracking_Reco()
0603 {
0604   /*
0605    * just a wrapper around track seeding and track fitting methods,
0606    * to minimize disruption to existing steering macros
0607    */
0608   if (G4TRACKING::use_alignment)
0609   {
0610     Tracking_Reco_CommissioningTrackSeed();
0611   }
0612   else
0613   {
0614     Tracking_Reco_TrackSeed();
0615   }
0616 
0617   if (G4TRACKING::convert_seeds_to_svtxtracks)
0618   {
0619     vertexing();
0620   }
0621   else
0622   {
0623     Tracking_Reco_TrackFit();
0624   }
0625 
0626   if (G4TRACKING::use_alignment)
0627   {
0628     alignment();
0629   }
0630 }
0631 
0632 void Filter_Conversion_Electrons(const std::string &ntuple_outfile)
0633 {
0634   Fun4AllServer *se = Fun4AllServer::instance();
0635   SecondaryVertexFinder *secvert = new SecondaryVertexFinder;
0636   secvert->Verbosity(0);
0637   secvert->set_write_electrons_node(true);  // writes copy of filtered electron tracks to node tree
0638   secvert->set_write_ntuple(false);         // writes ntuple for tuning cuts
0639   secvert->setDecayParticleMass(0.000511);  // for electrons
0640   secvert->setOutfileName(ntuple_outfile);
0641   se->registerSubsystem(secvert);
0642 }
0643 
0644 #endif