Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:20:27

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