Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2026-08-31 08:24:38

0001 /*
0002  * This macro shows a minimum working example of running over the production track and calo DSTs.
0003  * You can add some analysis modules at the end which package tracks and calo clusters into trees for analysis.
0004  */
0005 
0006 // leave the GlobalVariables.C at the beginning, an empty line afterwards
0007 // protects its position against reshuffling by clang-format
0008 #include <GlobalVariables.C>
0009 
0010 #include <G4_ActsGeom.C>
0011 #include <G4_Global.C>
0012 #include <G4_Magnet.C>
0013 #include <Trkr_Clustering.C>
0014 #include <Trkr_Reco.C>
0015 #include <Trkr_RecoInit.C>
0016 #include <Trkr_TpcReadoutInit.C>
0017 #include <QA.C>
0018 
0019 #include <trackreco/PHActsTrackProjection.h>
0020 
0021 #include <trackbase_historic/SvtxTrack.h>
0022 
0023 #include <ffamodules/CDBInterface.h>
0024 
0025 #include <fun4all/Fun4AllDstInputManager.h>
0026 #include <fun4all/Fun4AllDstOutputManager.h>
0027 #include <fun4all/Fun4AllInputManager.h>
0028 #include <fun4all/Fun4AllUtils.h>
0029 #include <fun4all/Fun4AllOutputManager.h>
0030 #include <fun4all/Fun4AllRunNodeInputManager.h>
0031 #include <fun4all/Fun4AllServer.h>
0032 
0033 #include <phool/recoConsts.h>
0034 
0035 #include <iostream>
0036 #include <filesystem>
0037 
0038 #include <mbd/MbdReco.h>
0039 #include <mbdcalib/MbdTrackVertex.h>
0040 
0041 R__LOAD_LIBRARY(libfun4all.so)
0042 R__LOAD_LIBRARY(libffamodules.so)
0043 R__LOAD_LIBRARY(libphool.so)
0044 R__LOAD_LIBRARY(libcdbobjects.so)
0045 R__LOAD_LIBRARY(libtrack_reco.so)
0046 R__LOAD_LIBRARY(libcalo_reco.so)
0047 R__LOAD_LIBRARY(libcalotrigger.so)
0048 R__LOAD_LIBRARY(libcentrality.so)
0049 R__LOAD_LIBRARY(libmbd.so)
0050 R__LOAD_LIBRARY(libepd.so)
0051 R__LOAD_LIBRARY(libzdcinfo.so)
0052 R__LOAD_LIBRARY(libmbd.so)
0053 R__LOAD_LIBRARY(libmbdcalib.so)
0054 
0055 void Fun4All_MBD_TrackVertex(
0056     const int nEvents = 10,
0057     const std::string& trackfilename = "DST_TRKR_TRACKS_run2pp_ana475_2024p017_v001-00053877-00000.root",
0058     const std::string& calofilename = "DST_CALO_run2pp_ana468_2024p012_v001-00053877-00000.root",
0059     const std::string& outfilename = "mbd_trkvtx",
0060     const std::string& outdir = "./")
0061 {
0062   const std::string& inputTrackFile = trackfilename;
0063   const std::string& inputCaloFile = calofilename;
0064 
0065   std::pair<int, int> runseg = Fun4AllUtils::GetRunSegment(trackfilename);
0066   int runnumber = runseg.first;
0067   int segment = runseg.second;
0068 
0069   std::string theOutfileheader = outdir + outfilename + "_" + std::to_string(runnumber) + "-" + std::to_string(segment);
0070 
0071   Enable::MVTX_APPLYMISALIGNMENT = true;
0072   ACTSGEOM::mvtx_applymisalignment = Enable::MVTX_APPLYMISALIGNMENT;
0073   TRACKING::streaming_mode = true;
0074 
0075   auto *se = Fun4AllServer::instance();
0076   se->Verbosity(1);
0077 
0078   auto *rc = recoConsts::instance();
0079   rc->set_IntFlag("RUNNUMBER", runnumber);
0080   rc->set_IntFlag("RUNSEGMENT", segment);
0081 
0082   Enable::CDB = true;
0083   rc->set_StringFlag("CDB_GLOBALTAG", "newcdbtag");
0084   rc->set_uint64Flag("TIMESTAMP", runnumber);
0085   std::string geofile = CDBInterface::instance()->getUrl("Tracking_Geometry");
0086 
0087   Fun4AllRunNodeInputManager *ingeo = new Fun4AllRunNodeInputManager("GeoIn");
0088   ingeo->AddFile(geofile);
0089   se->registerInputManager(ingeo);
0090 
0091   TpcReadoutInit( runnumber );
0092   std::cout << " run: " << runnumber
0093             << " samples: " << TRACKING::reco_tpc_maxtime_sample
0094             << " pre: " << TRACKING::reco_tpc_time_presample
0095             << " vdrift: " << G4TPC::tpc_drift_velocity_reco
0096             << std::endl;
0097 
0098   G4TPC::ENABLE_MODULE_EDGE_CORRECTIONS = true;
0099 
0100   // to turn on the default static corrections, enable the two lines below
0101   G4TPC::ENABLE_STATIC_CORRECTIONS = true;
0102 
0103   //to turn on the average corrections, enable the three lines below
0104   //note: these are designed to be used only if static corrections are also applied
0105   G4TPC::ENABLE_AVERAGE_CORRECTIONS = true;
0106 
0107   G4MAGNET::magfield_rescale = 1;
0108   TrackingInit();
0109 
0110   auto *trackin = new Fun4AllDstInputManager("TrackInManager");
0111   trackin->fileopen(inputTrackFile);
0112   //trackin->AddListFile(inputTrackFile);
0113   se->registerInputManager(trackin);
0114 
0115   auto *caloin = new Fun4AllDstInputManager("CaloInManager");
0116   caloin->fileopen(inputCaloFile);
0117   //caloin->AddListFile(inputCaloFile);
0118   se->registerInputManager(caloin);
0119 
0120   /*
0121   auto *projection = new PHActsTrackProjection("CaloProjection");
0122   float new_cemc_rad = 99; // from DetailedCalorimeterGeometry, project to inner surface
0123   bool doEMcalRadiusCorr = true;
0124   if (doEMcalRadiusCorr)
0125   {
0126     projection->setLayerRadius(SvtxTrack::CEMC, new_cemc_rad);
0127   }
0128   se->registerSubsystem(projection);
0129   */
0130 
0131   // MBD/BBC Reconstruction
0132   MbdReco *mbdreco = new MbdReco();
0133   //const int calpass = 2;  // if we want to use local calibs
0134   //mbdreco->SetCalPass(calpass);
0135   rc->set_StringFlag("MBD_TT_T0", "mbd_tt_t0.calib");
0136   rc->set_StringFlag("MBD_TQ_T0", "mbd_tq_t0.calib");
0137   se->registerSubsystem(mbdreco);
0138 
0139   Global_Reco();
0140 
0141   MbdTrackVertex *mbdtrkvtx = new MbdTrackVertex();
0142   se->registerSubsystem( mbdtrkvtx );
0143 
0144   if (Enable::DSTOUT)
0145   {
0146     std::string dstOutputFileName= theOutfileheader + "_dst.root";
0147     Fun4AllDstOutputManager *out = new Fun4AllDstOutputManager("DSTOUT", dstOutputFileName);
0148     out->AddNode("Sync");
0149     out->AddNode("EventHeader");
0150     out->AddNode("SvtxTrackMap");
0151     out->AddNode("GlobalVertexMap");
0152     out->AddNode("CLUSTERINFO_CEMC");
0153     se->registerOutputManager(out);
0154   }
0155 
0156   se->run(nEvents);
0157   se->End();
0158   se->PrintTimer();
0159 
0160   if(Enable::QA)
0161   {
0162     std::string qaOutputFileName = theOutfileheader + "_qa.root";
0163     QAHistManagerDef::saveQARootFile(qaOutputFileName);
0164   }
0165 
0166   CDBInterface::instance()->Print();
0167   delete se;
0168   std::cout << "Finished" << std::endl;
0169   gSystem->Exit(0);
0170 
0171   return;
0172 }
0173 
0174 std::string GetFirstLine(const std::string& listname)
0175 {
0176   std::ifstream file(listname);
0177 
0178   std::string firstLine;
0179   if (file.is_open()) {
0180       if (std::getline(file, firstLine)) {
0181           std::cout << "First Line: " << firstLine << std::endl;
0182       } else {
0183           std::cerr << "Unable to read first line of file" << std::endl;
0184       }
0185       file.close();
0186   } else {
0187       std::cerr << "Unable to open file" << std::endl;
0188   }
0189   return firstLine;
0190 }