Back to home page

sPhenix code displayed by LXR

 
 

    


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

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