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 working example of running KFParticle over a Track DST
0003  * This has certain KFParticle features like Particle ID and trigger Info off
0004  * Because those features require other DSTs like the cluster or hit dst
0005  */
0006 
0007 #include <GlobalVariables.C>
0008 
0009 #include <G4_ActsGeom.C>
0010 #include <G4_Magnet.C>
0011 #include <QA.C>
0012 #include <Trkr_Clustering.C>
0013 #include <Trkr_Reco.C>
0014 #include <Trkr_RecoInit.C>
0015 #include <Trkr_TpcReadoutInit.C>
0016 
0017 #include <globalvertex/GlobalVertexReco.h>
0018 
0019 #include <cdbobjects/CDBTTree.h>
0020 
0021 #include <tpccalib/PHTpcResiduals.h>
0022 
0023 #include <trackingqa/SiliconSeedsQA.h>
0024 #include <trackingqa/TpcSeedsQA.h>
0025 #include <trackingqa/TpcSiliconQA.h>
0026 
0027 #include <trackingdiagnostics/TrackResiduals.h>
0028 #include <trackingdiagnostics/TrkrNtuplizer.h>
0029 
0030 #include <kfparticle_sphenix/KFParticle_sPHENIX.h>
0031 
0032 #include <ffamodules/CDBInterface.h>
0033 
0034 #include <fun4all/Fun4AllDstInputManager.h>
0035 #include <fun4all/Fun4AllDstOutputManager.h>
0036 #include <fun4all/Fun4AllInputManager.h>
0037 #include <fun4all/Fun4AllOutputManager.h>
0038 #include <fun4all/Fun4AllRunNodeInputManager.h>
0039 #include <fun4all/Fun4AllServer.h>
0040 #include <fun4all/Fun4AllUtils.h>
0041 
0042 #include <phool/recoConsts.h>
0043 
0044 R__LOAD_LIBRARY(libkfparticle_sphenix.so)
0045 R__LOAD_LIBRARY(libcalotrigger.so)
0046 
0047 R__LOAD_LIBRARY(libfun4all.so)
0048 R__LOAD_LIBRARY(libffamodules.so)
0049 R__LOAD_LIBRARY(libphool.so)
0050 R__LOAD_LIBRARY(libcdbobjects.so)
0051 R__LOAD_LIBRARY(libTrackingDiagnostics.so)
0052 R__LOAD_LIBRARY(libtrackingqa.so)
0053 
0054 void Fun4All_KShortReco(
0055     const int nEvents = 10000,
0056     const std::string &inputDST = "DST_TRKR_TRACKS_run2pp_ana475_2024p018_v001-00053877-00000.root",
0057     const std::string &inputDir = "/sphenix/lustre01/sphnxpro/production/run2pp/physics/ana475_2024p018_v001/DST_TRKR_TRACKS/run_00053800_00053900/dst/",
0058     const int nSkip = 0)
0059 {
0060   std::string inputSeedFile = inputDir + inputDST;
0061 
0062   std::pair<int, int> runseg = Fun4AllUtils::GetRunSegment(inputDST);
0063   int runnumber = runseg.first;
0064   std::stringstream nice_runnumber;
0065   nice_runnumber << std::setw(8) << std::setfill('0') << std::to_string(runnumber);
0066 
0067   int rounded_up = 100 * (std::ceil((float) runnumber / 100));
0068   std::stringstream nice_rounded_up;
0069   nice_rounded_up << std::setw(8) << std::setfill('0') << std::to_string(rounded_up);
0070 
0071   int rounded_down = 100 * (std::floor((float) runnumber / 100));
0072   std::stringstream nice_rounded_down;
0073   nice_rounded_down << std::setw(8) << std::setfill('0') << std::to_string(rounded_down);
0074 
0075   int segment = runseg.second;
0076   std::stringstream nice_segment;
0077   nice_segment << std::setw(5) << std::setfill('0') << std::to_string(segment);
0078 
0079   std::stringstream nice_skip;
0080   nice_skip << std::setw(5) << std::setfill('0') << std::to_string(nSkip);
0081 
0082   auto *rc = recoConsts::instance();
0083   rc->set_IntFlag("RUNNUMBER", runnumber);
0084 
0085   Enable::CDB = true;
0086   rc->set_StringFlag("CDB_GLOBALTAG", "newcdbtag");
0087   rc->set_uint64Flag("TIMESTAMP", runnumber);
0088   std::string geofile = CDBInterface::instance()->getUrl("Tracking_Geometry");
0089 
0090   TpcReadoutInit(runnumber);
0091   std::cout << " run: " << runnumber
0092             << " samples: " << TRACKING::reco_tpc_maxtime_sample
0093             << " pre: " << TRACKING::reco_tpc_time_presample
0094             << " vdrift: " << G4TPC::tpc_drift_velocity_reco
0095             << std::endl;
0096 
0097   std::string output_dir = "./";  // Top dir of where the output nTuples will be written
0098   std::string kfp_header = "outputKFParticle_";
0099   std::string processing_folder = "inReconstruction/";
0100   std::string trailer = "_" + nice_runnumber.str() + "_" + nice_segment.str() + "_" + nice_skip.str() + ".root";
0101   std::string pipi_reconstruction_name = "pipi_reco";  // Used for naming output folder, file and node
0102 
0103   std::string output_file_name = kfp_header + pipi_reconstruction_name + trailer;
0104   std::string pipi_output_dir = output_dir + pipi_reconstruction_name + "/";
0105   std::string output_reco_dir = pipi_output_dir + processing_folder;
0106   std::string pipi_output_reco_file = output_reco_dir + output_file_name;
0107 
0108   std::string makeDirectory = "mkdir -p " + output_reco_dir;
0109   system(makeDirectory.c_str());
0110 
0111   // distortion calibration mode
0112   /*
0113    * set to true to enable residuals in the TPC with
0114    * TPC clusters not participating to the ACTS track fit
0115    */
0116 
0117   G4TRACKING::SC_CALIBMODE = false;
0118   Enable::MVTX_APPLYMISALIGNMENT = true;
0119   ACTSGEOM::mvtx_applymisalignment = Enable::MVTX_APPLYMISALIGNMENT;
0120   TRACKING::pp_mode = true;
0121 
0122   auto *se = Fun4AllServer::instance();
0123   se->Verbosity(1);
0124 
0125   Fun4AllRunNodeInputManager *ingeo = new Fun4AllRunNodeInputManager("GeoIn");
0126   ingeo->AddFile(geofile);
0127   se->registerInputManager(ingeo);
0128 
0129   TrackingInit();
0130 
0131   auto *tracks = new Fun4AllDstInputManager("TrackInputManager");
0132   tracks->fileopen(inputSeedFile);
0133   se->registerInputManager(tracks);
0134 
0135   GlobalVertexReco *gblvertex = new GlobalVertexReco();
0136   gblvertex->Verbosity(0);
0137   se->registerSubsystem(gblvertex);
0138 
0139   KFParticle_sPHENIX *kfparticle = new KFParticle_sPHENIX("pipi_reco");
0140   kfparticle->Verbosity(0);
0141 
0142   kfparticle->setDecayDescriptor("K_S0 -> pi^+ pi^-");  // See twiki on how to set this
0143 
0144   kfparticle->usePID(false);
0145   // kfparticle->setPIDacceptFraction(pid_frac);
0146   kfparticle->dontUseGlobalVertex(true);
0147   kfparticle->requireTrackVertexBunchCrossingMatch(true);
0148   kfparticle->getAllPVInfo(true);
0149   kfparticle->allowZeroMassTracks();
0150   kfparticle->use2Dmatching(false);
0151   kfparticle->getTriggerInfo(false);
0152   kfparticle->getDetectorInfo(false);
0153   kfparticle->saveDST(false);
0154   kfparticle->setContainerName("pipi_reco");
0155   kfparticle->magFieldFile("FIELDMAP_TRACKING");
0156 
0157   // PV to SV cuts
0158   kfparticle->constrainToPrimaryVertex(true);
0159   kfparticle->setMotherIPchi2(100);
0160   kfparticle->setFlightDistancechi2(-1.);
0161   kfparticle->setMinDIRA(0.999);
0162   kfparticle->setDecayLengthRange(0.1, FLT_MAX);
0163 
0164   // Track parameters
0165   kfparticle->setMinimumTrackPT(0.0);
0166   kfparticle->setMinimumTrackIPchi2(-1.);
0167   kfparticle->setMinimumTrackIP(-1.);
0168   kfparticle->setMaximumTrackchi2nDOF(100.);
0169   kfparticle->setMinTPChits(25);
0170 
0171   // Vertex parameters
0172   kfparticle->setMaximumVertexchi2nDOF(20);
0173   kfparticle->setMaximumDaughterDCA(0.5);  // 5 mm
0174 
0175   // Set Tracker State Requirements
0176   kfparticle->setMinMVTXhits(0);
0177   kfparticle->setMinINTThits(0);
0178   kfparticle->setMinTPChits(20);
0179 
0180   // Parent parameters
0181   kfparticle->setMotherPT(0);
0182   kfparticle->setMinimumMass(0.40);  // Check mass ranges
0183   kfparticle->setMaximumMass(0.60);
0184   kfparticle->setMaximumMotherVertexVolume(0.1);
0185 
0186   kfparticle->setOutputName(pipi_output_reco_file);
0187 
0188   se->registerSubsystem(kfparticle);
0189 
0190   se->skip(nSkip);
0191   se->run(nEvents);
0192   se->End();
0193   se->PrintTimer();
0194 
0195   std::ifstream file(pipi_output_reco_file);
0196   if (file.good())
0197   {
0198     std::string moveOutput = "mv " + pipi_output_reco_file + " " + pipi_output_dir;
0199     system(moveOutput.c_str());
0200   }
0201 
0202   delete se;
0203 
0204   std::cout << "Finished" << std::endl;
0205   gSystem->Exit(0);
0206 }