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_TpcReadoutInit.C>
0016 #include <Trkr_Clustering.C>
0017 #include <Trkr_LaserClustering.C>
0018 #include <Trkr_Reco.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 
0031 #include <cdbobjects/CDBTTree.h>
0032 
0033 #include <trackingqa/InttClusterQA.h>
0034 
0035 #include <trackingqa/MicromegasClusterQA.h>
0036 
0037 #include <trackingqa/MvtxClusterQA.h>
0038 
0039 #include <trackingdiagnostics/TrackResiduals.h>
0040 #include <trackingdiagnostics/TrkrNtuplizer.h>
0041 #include <trackingqa/TpcClusterQA.h>
0042 #include <trackreco/AzimuthalSeeder.h>
0043 
0044 #include <stdio.h>
0045 #include <float.h>
0046 
0047 #pragma GCC diagnostic push
0048 
0049 #pragma GCC diagnostic ignored "-Wundefined-internal"
0050 
0051 #include <kfparticle_sphenix/KFParticle_sPHENIX.h>
0052 
0053 #pragma GCC diagnostic pop
0054 
0055 R__LOAD_LIBRARY(libkfparticle_sphenix.so)
0056 
0057 R__LOAD_LIBRARY(libfun4all.so)
0058 R__LOAD_LIBRARY(libffamodules.so)
0059 R__LOAD_LIBRARY(libphool.so)
0060 R__LOAD_LIBRARY(libcdbobjects.so)
0061 R__LOAD_LIBRARY(libmvtx.so)
0062 R__LOAD_LIBRARY(libintt.so)
0063 R__LOAD_LIBRARY(libtpc.so)
0064 R__LOAD_LIBRARY(libmicromegas.so)
0065 R__LOAD_LIBRARY(libTrackingDiagnostics.so)
0066 R__LOAD_LIBRARY(libtrackingqa.so)
0067 R__LOAD_LIBRARY(libEventDisplay.so)
0068 
0069 void Fun4All_FieldOnAllTrackers_KFP(
0070     const int nEvents = 0,
0071     const std::string tpcfilename = "DST_BEAM_run2pp_new_2023p013-00041989-0000.root",
0072     const std::string tpcdir = "/sphenix/lustre01/sphnxpro/commissioning/slurp/tpcbeam/run_00041900_00042000/",
0073     const std::string outfilename = "clusters_seeds",
0074     const bool convertSeeds = false)
0075 {
0076 
0077   G4TRACKING::convert_seeds_to_svtxtracks = convertSeeds;
0078   std::cout << "Converting to seeds : " << G4TRACKING::convert_seeds_to_svtxtracks << std::endl;
0079   std::pair<int, int>
0080       runseg = Fun4AllUtils::GetRunSegment(tpcfilename);
0081   int runnumber = runseg.first;
0082   int segment = runseg.second;
0083   TpcReadoutInit( runnumber );
0084   std::cout<< " run: " << runnumber
0085        << " samples: " << TRACKING::reco_tpc_maxtime_sample
0086        << " pre: " << TRACKING::reco_tpc_time_presample
0087        << " vdrift: " << G4TPC::tpc_drift_velocity_reco
0088        << std::endl;
0089 
0090   string outDir = "myKShortReco/";
0091   string outputFileName = "outputFile_" + to_string(runnumber) + "_" + to_string(segment) + ".root";
0092 
0093   string outputRecoDir = outDir + "inReconstruction/";
0094   string makeDirectory = "mkdir -p " + outputRecoDir;
0095   system(makeDirectory.c_str());
0096   string outputRecoFile = outputRecoDir + outputFileName;
0097 
0098   std::string inputtpcRawHitFile = tpcdir + tpcfilename;
0099   ACTSGEOM::mvtxMisalignment = 100;
0100   ACTSGEOM::inttMisalignment = 100.;
0101   ACTSGEOM::tpotMisalignment = 100.;
0102   TString outfile = outfilename + "_" + runnumber + "-" + segment + ".root";
0103   std::string theOutfile = outfile.Data();
0104 
0105   auto se = Fun4AllServer::instance();
0106   se->Verbosity(1);
0107   auto rc = recoConsts::instance();
0108   rc->set_IntFlag("RUNNUMBER", runnumber);
0109 
0110   Enable::CDB = true;
0111   rc->set_StringFlag("CDB_GLOBALTAG", "ProdA_2024");
0112   rc->set_uint64Flag("TIMESTAMP", runnumber);
0113   std::string geofile = CDBInterface::instance()->getUrl("Tracking_Geometry");
0114 
0115   Fun4AllRunNodeInputManager *ingeo = new Fun4AllRunNodeInputManager("GeoIn");
0116   ingeo->AddFile(geofile);
0117   se->registerInputManager(ingeo);
0118 
0119   CDBInterface *cdb = CDBInterface::instance();
0120   std::string tpc_dv_calib_dir = cdb->getUrl("TPC_DRIFT_VELOCITY");
0121   if (tpc_dv_calib_dir.empty())
0122   {
0123     std::cout << "No calibrated TPC drift velocity for Run " << runnumber << ". Use default value " << G4TPC::tpc_drift_velocity_reco << " cm/ns" << std::endl;
0124   }
0125   else
0126   {
0127     CDBTTree *cdbttree = new CDBTTree(tpc_dv_calib_dir);
0128     cdbttree->LoadCalibrations();
0129     G4TPC::tpc_drift_velocity_reco = cdbttree->GetSingleFloatValue("tpc_drift_velocity");
0130     std::cout << "Use calibrated TPC drift velocity for Run " << runnumber << ": " << G4TPC::tpc_drift_velocity_reco << " cm/ns" << std::endl;
0131   }
0132 
0133   G4MAGNET::magfield_rescale = 1;
0134   ACTSGEOM::ActsGeomInit();
0135 
0136   auto hitsin = new Fun4AllDstInputManager("InputManager");
0137   hitsin->fileopen(inputtpcRawHitFile);
0138   se->registerInputManager(hitsin);
0139 
0140   //Mvtx_HitUnpacking();
0141   //Intt_HitUnpacking();
0142   Tpc_HitUnpacking();
0143   Micromegas_HitUnpacking();
0144 
0145   //Mvtx_Clustering();
0146   //Intt_Clustering();
0147 
0148   auto tpcclusterizer = new TpcClusterizer;
0149   tpcclusterizer->Verbosity(0);
0150   tpcclusterizer->set_do_hit_association(G4TPC::DO_HIT_ASSOCIATION);
0151   tpcclusterizer->set_rawdata_reco();
0152   se->registerSubsystem(tpcclusterizer);
0153 
0154   Tpc_LaserEventIdentifying();
0155 
0156   Micromegas_Clustering();
0157 
0158   Tracking_Reco_TrackSeed();
0159 
0160   if (G4TRACKING::convert_seeds_to_svtxtracks)
0161   {
0162     auto converter = new TrackSeedTrackMapConverter;
0163     // Default set to full SvtxTrackSeeds. Can be set to
0164     // SiliconTrackSeedContainer or TpcTrackSeedContainer
0165     converter->setTrackSeedName("TpcTrackSeedContainer");
0166     converter->setFieldMap(G4MAGNET::magfield_tracking);
0167     converter->Verbosity(0);
0168     se->registerSubsystem(converter);
0169   }
0170   else
0171   {
0172     auto deltazcorr = new PHTpcDeltaZCorrection;
0173     deltazcorr->Verbosity(0);
0174     se->registerSubsystem(deltazcorr);
0175 
0176     // perform final track fit with ACTS
0177     auto actsFit = new PHActsTrkFitter;
0178     actsFit->Verbosity(0);
0179     actsFit->commissioning(G4TRACKING::use_alignment);
0180     // in calibration mode, fit only Silicons and Micromegas hits
0181     actsFit->fitSiliconMMs(G4TRACKING::SC_CALIBMODE);
0182     actsFit->setUseMicromegas(G4TRACKING::SC_USE_MICROMEGAS);
0183     actsFit->set_pp_mode(TRACKING::pp_mode);
0184     actsFit->set_use_clustermover(true);  // default is true for now
0185     actsFit->useActsEvaluator(false);
0186     actsFit->useOutlierFinder(false);
0187     actsFit->setFieldMap(G4MAGNET::magfield_tracking);
0188     se->registerSubsystem(actsFit);
0189   }
0190 
0191   PHSimpleVertexFinder *finder = new PHSimpleVertexFinder;
0192   finder->Verbosity(0);
0193   finder->setDcaCut(0.5);
0194   finder->setTrackPtCut(-99999.);
0195   finder->setBeamLineCut(1);
0196   finder->setTrackQualityCut(1000000000);
0197   finder->setNmvtxRequired(3);
0198   finder->setOutlierPairCut(0.1);
0199   se->registerSubsystem(finder);
0200 
0201   // Propagate track positions to the vertex position
0202   auto vtxProp = new PHActsVertexPropagator;
0203   vtxProp->Verbosity(0);
0204   vtxProp->fieldMap(G4MAGNET::magfield_tracking);
0205   se->registerSubsystem(vtxProp);
0206   
0207   //KFParticle setup
0208   KFParticle_sPHENIX *kfparticle = new KFParticle_sPHENIX("myKShortReco");
0209   kfparticle->Verbosity(1);
0210   kfparticle->setDecayDescriptor("K_S0 -> pi^+ pi^-");
0211 
0212   //Basic node selection and configuration
0213   kfparticle->magFieldFile("FIELDMAP_TRACKING");
0214   kfparticle->getAllPVInfo(false);
0215   kfparticle->allowZeroMassTracks(); // true
0216   kfparticle->useFakePrimaryVertex(); // true
0217 
0218   kfparticle->constrainToPrimaryVertex(false);
0219   kfparticle->setMotherIPchi2(FLT_MAX);
0220   kfparticle->setFlightDistancechi2(-1.);
0221   kfparticle->setMinDIRA(-1.1);
0222   kfparticle->setDecayLengthRange(0., FLT_MAX);
0223   kfparticle->setDecayTimeRange(-1*FLT_MAX, FLT_MAX);
0224 
0225   //Track parameters
0226   kfparticle->setMinMVTXhits(0);
0227   kfparticle->setMinTPChits(20);
0228   kfparticle->setMinimumTrackPT(-1.);
0229   kfparticle->setMaximumTrackPTchi2(FLT_MAX);
0230   kfparticle->setMinimumTrackIPchi2(-1.);
0231   kfparticle->setMinimumTrackIP(-1.);
0232   kfparticle->setMaximumTrackchi2nDOF(20.);
0233 
0234   //Vertex parameters
0235   kfparticle->setMaximumVertexchi2nDOF(50);
0236   kfparticle->setMaximumDaughterDCA(1.);
0237 
0238   //Parent parameters
0239   kfparticle->setMotherPT(0);
0240   kfparticle->setMinimumMass(0.300);
0241   kfparticle->setMaximumMass(0.700);
0242   kfparticle->setMaximumMotherVertexVolume(0.1);
0243 
0244   kfparticle->setOutputName(outputRecoFile);
0245 
0246   se->registerSubsystem(kfparticle);
0247 
0248   se->run(nEvents);
0249   se->End();
0250 
0251   ifstream file(outputRecoFile.c_str());
0252   if (file.good())
0253   {
0254     string moveOutput = "mv " + outputRecoFile + " " + outDir;
0255     system(moveOutput.c_str());
0256   }
0257 
0258   delete se;
0259   std::cout << "Finished" << std::endl;
0260   gSystem->Exit(0);
0261 }