Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001  /*
0002  * This macro shows a minimum working example of running the tracking
0003  * hit unpackers with some basic seeding algorithms to try to put together
0004  * tracks. There are some analysis modules run at the end which package
0005  * hits, clusters, and clusters on tracks into trees for analysis.
0006  */
0007 
0008 #include <fun4all/Fun4AllUtils.h>
0009 #include <G4_ActsGeom.C>
0010 #include <G4_Global.C>
0011 #include <G4_Magnet.C>
0012 #include <G4_Mbd.C>
0013 #include <GlobalVariables.C>
0014 #include <QA.C>
0015 #include <Trkr_RecoInit.C>
0016 #include <Trkr_Clustering.C>
0017 #include <Trkr_Reco.C>
0018 #include <Trkr_TpcReadoutInit.C>
0019 
0020 #include <ffamodules/CDBInterface.h>
0021 #include <fun4all/Fun4AllDstInputManager.h>
0022 #include <fun4all/Fun4AllDstOutputManager.h>
0023 #include <fun4all/Fun4AllInputManager.h>
0024 #include <fun4all/Fun4AllOutputManager.h>
0025 #include <fun4all/Fun4AllRunNodeInputManager.h>
0026 #include <fun4all/Fun4AllServer.h>
0027 
0028 #include <eventdisplay/TrackerEventDisplay.h>
0029 #include <phool/recoConsts.h>
0030 #include <trackingqa/InttClusterQA.h>
0031 
0032 #include <cdbobjects/CDBTTree.h>
0033 
0034 #include <trackingqa/MicromegasClusterQA.h>
0035 
0036 #include <trackingqa/MvtxClusterQA.h>
0037 
0038 #include <trackingdiagnostics/TrackResiduals.h>
0039 #include <trackingdiagnostics/TrkrNtuplizer.h>
0040 #include <trackingqa/TpcClusterQA.h>
0041 #include <trackreco/AzimuthalSeeder.h>
0042 
0043 #include <stdio.h>
0044 
0045 R__LOAD_LIBRARY(libfun4all.so)
0046 R__LOAD_LIBRARY(libffamodules.so)
0047 R__LOAD_LIBRARY(libphool.so)
0048 R__LOAD_LIBRARY(libcdbobjects.so)
0049 R__LOAD_LIBRARY(libmvtx.so)
0050 R__LOAD_LIBRARY(libintt.so)
0051 R__LOAD_LIBRARY(libtpc.so)
0052 R__LOAD_LIBRARY(libmicromegas.so)
0053 R__LOAD_LIBRARY(libTrackingDiagnostics.so)
0054 R__LOAD_LIBRARY(libtrackingqa.so)
0055 R__LOAD_LIBRARY(libEventDisplay.so)
0056 void Fun4All_ZFAllTrackers(
0057     const int nEvents = 0,
0058     const std::string tpcfilename = "DST_TRKR_CLUSTER_run2pp_ana466_2024p012_v001-00052077-00000.root",
0059     const std::string tpcdir = "/sphenix/lustre01/sphnxpro/production/run2pp/physics/ana466_2024p012_v001/DST_TRKR_CLUSTER/run_00052000_00052100/dst/",
0060     const std::string outfilename = "clusters_seeds",
0061     const bool convertSeeds = true)
0062 {
0063   std::string inputtpcRawHitFile = tpcdir + tpcfilename;
0064 
0065   G4TRACKING::convert_seeds_to_svtxtracks = convertSeeds;
0066   std::cout << "Converting to seeds : " << G4TRACKING::convert_seeds_to_svtxtracks << std::endl;
0067   std::pair<int, int>
0068       runseg = Fun4AllUtils::GetRunSegment(tpcfilename);
0069   int runnumber = runseg.first;
0070   int segment = runseg.second;
0071 
0072   G4TRACKING::SC_CALIBMODE = false;
0073   Enable::MVTX_APPLYMISALIGNMENT = true;
0074   ACTSGEOM::mvtx_applymisalignment = Enable::MVTX_APPLYMISALIGNMENT;
0075   TRACKING::pp_mode = true;
0076 
0077   auto rc = recoConsts::instance();
0078   rc->set_IntFlag("RUNNUMBER", runnumber);
0079   Enable::CDB = true;
0080   rc->set_StringFlag("CDB_GLOBALTAG", "ProdA_2024");
0081   rc->set_uint64Flag("TIMESTAMP", runnumber);
0082   std::string geofile = CDBInterface::instance()->getUrl("Tracking_Geometry");
0083 
0084   TpcReadoutInit( runnumber );
0085   std::cout<< " run: " << runnumber
0086        << " samples: " << TRACKING::reco_tpc_maxtime_sample
0087        << " pre: " << TRACKING::reco_tpc_time_presample
0088        << " vdrift: " << G4TPC::tpc_drift_velocity_reco
0089        << std::endl;
0090 
0091 
0092   TString outfile = outfilename + "_" + runnumber + "-" + segment + ".root";
0093   std::string theOutfile = outfile.Data();
0094   auto se = Fun4AllServer::instance();
0095   se->Verbosity(1);
0096 
0097   Fun4AllRunNodeInputManager *ingeo = new Fun4AllRunNodeInputManager("GeoIn");
0098   ingeo->AddFile(geofile);
0099   se->registerInputManager(ingeo);
0100 
0101   G4MAGNET::magfield = "0.01";
0102   G4MAGNET::magfield_tracking = G4MAGNET::magfield;
0103   G4MAGNET::magfield_rescale = 1;
0104   TrackingInit();
0105 
0106   auto hitsin = new Fun4AllDstInputManager("InputManager");
0107   hitsin->fileopen(inputtpcRawHitFile);
0108   // hitsin->AddFile(inputMbd);
0109   se->registerInputManager(hitsin);
0110 
0111   TRACKING::tpc_zero_supp = true;
0112   /*
0113   Mvtx_HitUnpacking();
0114   Intt_HitUnpacking();
0115   Tpc_HitUnpacking();
0116   Micromegas_HitUnpacking();
0117 
0118   Mvtx_Clustering();
0119   Intt_Clustering();
0120 
0121   auto tpcclusterizer = new TpcClusterizer;
0122   tpcclusterizer->Verbosity(0);
0123   tpcclusterizer->set_do_hit_association(G4TPC::DO_HIT_ASSOCIATION);
0124   tpcclusterizer->set_rawdata_reco();
0125   se->registerSubsystem(tpcclusterizer);
0126 
0127   Micromegas_Clustering();
0128   */
0129 
0130   // this now does Si and TPC seeding only
0131   Tracking_Reco_TrackSeed_ZeroField();
0132 
0133   auto silicon_match = new PHSiliconTpcTrackMatching;
0134   silicon_match->Verbosity(0);
0135   // set search windows matching Silicon to TPC seeds
0136   // Selected for tracks with ntpc>34,|z_Si-z_TPC|<30,crossing==0
0137   // see https://indico.bnl.gov/event/26202/attachments/59703/102575/2025_01_31_ZeroField.pdf
0138   // Will probably be narrowed from improved alignment soon.
0139   silicon_match->window_dx.set_QoverpT_maxabs({2.6,0,0});
0140   silicon_match->window_dy.set_QoverpT_maxabs({2.3,0,0});
0141   silicon_match->window_dz.set_QoverpT_range({-2.9,0,0},{4.2,0,0});
0142   silicon_match->window_deta.set_QoverpT_maxabs({0.06,0,0});
0143   silicon_match->window_dphi.set_QoverpT_maxabs({0.11,0,0});
0144   silicon_match->set_test_windows_printout(false);
0145   silicon_match->set_pp_mode(TRACKING::pp_mode);
0146   silicon_match->zeroField(true);
0147   se->registerSubsystem(silicon_match);
0148 
0149   auto mm_match = new PHMicromegasTpcTrackMatching;
0150   mm_match->Verbosity(0);
0151   mm_match->set_pp_mode(TRACKING::pp_mode);
0152 
0153   mm_match->set_rphi_search_window_lyr1(3.);
0154   mm_match->set_rphi_search_window_lyr2(15.0);
0155   mm_match->set_z_search_window_lyr1(30.0);
0156   mm_match->set_z_search_window_lyr2(3.);
0157 
0158   mm_match->set_min_tpc_layer(38);            // layer in TPC to start projection fit
0159   mm_match->set_test_windows_printout(true);  // used for tuning search windows only
0160   mm_match->zeroField(true);
0161   se->registerSubsystem(mm_match);
0162 
0163   if (G4TRACKING::convert_seeds_to_svtxtracks)
0164   {
0165 
0166     auto converter = new TrackSeedTrackMapConverter;
0167     // Default set to full SvtxTrackSeeds. Can be set to
0168     // SiliconTrackSeedContainer or TpcTrackSeedContainer
0169     converter->setTrackSeedName("SvtxTrackSeedContainer");
0170     converter->setFieldMap(G4MAGNET::magfield_tracking);
0171     converter->Verbosity(0);
0172     converter->constField();
0173     se->registerSubsystem(converter);
0174   }
0175   else
0176   {
0177     auto deltazcorr = new PHTpcDeltaZCorrection;
0178     deltazcorr->Verbosity(0);
0179     se->registerSubsystem(deltazcorr);
0180 
0181     // perform final track fit with ACTS
0182     auto actsFit = new PHActsTrkFitter;
0183     actsFit->Verbosity(0);
0184     actsFit->commissioning(G4TRACKING::use_alignment);
0185     // in calibration mode, fit only Silicons and Micromegas hits
0186     actsFit->fitSiliconMMs(G4TRACKING::SC_CALIBMODE);
0187     actsFit->setUseMicromegas(G4TRACKING::SC_USE_MICROMEGAS);
0188     actsFit->set_pp_mode(TRACKING::pp_mode);
0189     actsFit->set_use_clustermover(true);  // default is true for now
0190     actsFit->useActsEvaluator(false);
0191     actsFit->useOutlierFinder(false);
0192     actsFit->setFieldMap(G4MAGNET::magfield_tracking);
0193     se->registerSubsystem(actsFit);
0194   }
0195 
0196 
0197 
0198   PHSimpleVertexFinder *finder = new PHSimpleVertexFinder;
0199   finder->zeroField(true);
0200   finder->Verbosity(0);
0201   finder->setDcaCut(0.5);
0202   finder->setTrackPtCut(-99999.);
0203   finder->setBeamLineCut(1);
0204   finder->setTrackQualityCut(1000000000);
0205   finder->setNmvtxRequired(3);
0206   finder->setOutlierPairCut(0.1);
0207   se->registerSubsystem(finder);
0208 
0209   TString residoutfile = theOutfile + "_resid.root";
0210   std::string residstring(residoutfile.Data());
0211 
0212   auto resid = new TrackResiduals("TrackResiduals");
0213   resid->outfileName(residstring);
0214   resid->alignment(false);
0215   resid->clusterTree();
0216   resid->hitTree();
0217   resid->zeroField();
0218   resid->convertSeeds(G4TRACKING::convert_seeds_to_svtxtracks);
0219   resid->Verbosity(0);
0220   se->registerSubsystem(resid);
0221 
0222   // Fun4AllOutputManager *out = new Fun4AllDstOutputManager("out", "/sphenix/tg/tg01/hf/jdosbo/tracking_development/Run24/Beam/41626/hitsets.root");
0223   // se->registerOutputManager(out);
0224   if (Enable::QA)
0225   {
0226     se->registerSubsystem(new MvtxClusterQA);
0227     se->registerSubsystem(new InttClusterQA);
0228     se->registerSubsystem(new TpcClusterQA);
0229     se->registerSubsystem(new MicromegasClusterQA);
0230   }
0231   se->run(nEvents);
0232   se->End();
0233   se->PrintTimer();
0234 
0235   if (Enable::QA)
0236   {
0237     TString qaname = theOutfile + "_qa.root";
0238     std::string qaOutputFileName(qaname.Data());
0239     QAHistManagerDef::saveQARootFile(qaOutputFileName);
0240   }
0241 
0242   delete se;
0243   std::cout << "Finished" << std::endl;
0244   gSystem->Exit(0);
0245 }