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 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 #include <G4_ActsGeom.C>
0007 #include <G4_Global.C>
0008 #include <G4_Magnet.C>
0009 #include <GlobalVariables.C>
0010 #include <Trkr_Clustering.C>
0011 #include <Trkr_Reco.C>
0012 #include <Trkr_RecoInit.C>
0013 #include <Trkr_TpcReadoutInit.C>
0014 #include <QA.C>
0015 
0016 #include <ffamodules/CDBInterface.h>
0017 
0018 #include <fun4all/Fun4AllDstInputManager.h>
0019 #include <fun4all/Fun4AllDstOutputManager.h>
0020 #include <fun4all/Fun4AllInputManager.h>
0021 #include <fun4all/Fun4AllUtils.h>
0022 #include <fun4all/Fun4AllOutputManager.h>
0023 #include <fun4all/Fun4AllRunNodeInputManager.h>
0024 #include <fun4all/Fun4AllServer.h>
0025 
0026 #include <phool/recoConsts.h>
0027 
0028 #include <trackreco/PHActsTrackProjection.h>
0029 
0030 #include <trackbase_historic/SvtxTrack.h>
0031 
0032 #include <stdio.h>
0033 #include <iostream>
0034 #include <filesystem>
0035 
0036 R__LOAD_LIBRARY(libfun4all.so)
0037 R__LOAD_LIBRARY(libffamodules.so)
0038 R__LOAD_LIBRARY(libphool.so)
0039 R__LOAD_LIBRARY(libcdbobjects.so)
0040 R__LOAD_LIBRARY(libtrack_reco.so)
0041 R__LOAD_LIBRARY(libcalo_reco.so)
0042 R__LOAD_LIBRARY(libcalotrigger.so)
0043 R__LOAD_LIBRARY(libcentrality.so)
0044 R__LOAD_LIBRARY(libmbd.so)
0045 R__LOAD_LIBRARY(libepd.so)
0046 R__LOAD_LIBRARY(libzdcinfo.so)
0047 void Fun4All_TrackCaloAnalysis(
0048     const int nEvents = 10,
0049     const std::string trackfilename = "DST_TRKR_TRACKS_run2pp_ana475_2024p017_v001-00053877-00000.root",
0050     const std::string trackdir = "/sphenix/lustre01/sphnxpro/production/run2pp/physics/ana475_2024p017_v001/DST_TRKR_TRACKS/run_00053800_00053900/dst/",
0051     const std::string calofilename = "DST_CALO_run2pp_ana468_2024p012_v001-00053877-00000.root",
0052     const std::string calodir = "/sphenix/lustre01/sphnxpro/production/run2pp/physics/ana468_2024p012_v001/DST_CALO/run_00053800_00053900/dst/",
0053     const std::string outfilename = "tracks_calos",
0054     const std::string outdir = "./")
0055 {
0056   std::string inputTrackFile = trackdir + trackfilename;
0057   std::string inputCaloFile = calodir + calofilename;
0058 
0059   std::pair<int, int>
0060       runseg = Fun4AllUtils::GetRunSegment(trackfilename);
0061   int runnumber = runseg.first;
0062   int segment = runseg.second;
0063 
0064   TString outfileheader = outdir + outfilename + "_" + runnumber + "-" + segment;
0065   std::cout<<"outfile header: "<<outfileheader<<std::endl;
0066   std::string theOutfileheader = outfileheader.Data();
0067 
0068   Enable::MVTX_APPLYMISALIGNMENT = true;
0069   ACTSGEOM::mvtx_applymisalignment = Enable::MVTX_APPLYMISALIGNMENT;
0070   TRACKING::pp_mode = true;
0071 
0072   auto se = Fun4AllServer::instance();
0073   se->Verbosity(1);
0074 
0075   int verbosity = 0;
0076 
0077   auto rc = recoConsts::instance();
0078   rc->set_IntFlag("RUNNUMBER", runnumber);
0079   rc->set_IntFlag("RUNSEGMENT", segment);
0080 
0081   Enable::CDB = true;
0082   rc->set_StringFlag("CDB_GLOBALTAG", "ProdA_2024");
0083   rc->set_uint64Flag("TIMESTAMP", runnumber);
0084   std::string geofile = CDBInterface::instance()->getUrl("Tracking_Geometry");
0085 
0086   Fun4AllRunNodeInputManager *ingeo = new Fun4AllRunNodeInputManager("GeoIn");
0087   ingeo->AddFile(geofile);
0088   se->registerInputManager(ingeo);
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   G4TPC::ENABLE_MODULE_EDGE_CORRECTIONS = true;
0098 
0099   // to turn on the default static corrections, enable the two lines below
0100   G4TPC::ENABLE_STATIC_CORRECTIONS = true;
0101   G4TPC::USE_PHI_AS_RAD_STATIC_CORRECTIONS = false;
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   G4TPC::USE_PHI_AS_RAD_AVERAGE_CORRECTIONS = false;
0107    // to use a custom file instead of the database file:
0108   G4TPC::average_correction_filename = CDBInterface::instance()->getUrl("TPC_LAMINATION_FIT_CORRECTION");
0109 
0110   G4MAGNET::magfield_rescale = 1;
0111   TrackingInit();
0112 
0113   auto trackin = new Fun4AllDstInputManager("TrackInManager");
0114   trackin->fileopen(inputTrackFile);
0115   se->registerInputManager(trackin);
0116 
0117   auto caloin = new Fun4AllDstInputManager("CaloInManager");
0118   caloin->fileopen(inputCaloFile);
0119   se->registerInputManager(caloin);
0120 
0121   Global_Reco();
0122 
0123   auto projection = new PHActsTrackProjection("CaloProjection");
0124   float new_cemc_rad = 99; // from DetailedCalorimeterGeometry, project to inner surface
0125   bool doEMcalRadiusCorr = true;
0126   if (doEMcalRadiusCorr)
0127   {
0128     projection->setLayerRadius(SvtxTrack::CEMC, new_cemc_rad);
0129   }
0130   se->registerSubsystem(projection);
0131 
0132   //add your analysis module here
0133   TString ananame = theOutfileheader + "_ana.root";
0134   std::string anaOutputFileName(ananame.Data());
0135 
0136   if (Enable::DSTOUT)
0137   {
0138     TString dstname = theOutfileheader + "_dst.root";
0139     std::string dstOutputFileName(dstname.Data());
0140     Fun4AllDstOutputManager *out = new Fun4AllDstOutputManager("DSTOUT", dstOutputFileName);
0141     out->AddNode("Sync");
0142     out->AddNode("EventHeader");
0143     out->AddNode("SvtxTrackMap");
0144     out->AddNode("GlobalVertexMap");
0145     out->AddNode("CLUSTERINFO_CEMC");
0146     se->registerOutputManager(out);
0147   }
0148 
0149   se->run(nEvents);
0150   se->End();
0151   se->PrintTimer();
0152 
0153   if(Enable::QA)
0154   {
0155     TString qaname = theOutfileheader + "_qa.root";
0156     std::string qaOutputFileName(qaname.Data());
0157     QAHistManagerDef::saveQARootFile(qaOutputFileName);
0158   }
0159 
0160   CDBInterface::instance()->Print();
0161   delete se;
0162   std::cout << "Finished" << std::endl;
0163   gSystem->Exit(0);
0164 
0165   return;
0166 }
0167 
0168 std::string GetFirstLine(std::string listname)
0169 {
0170   std::ifstream file(listname);
0171 
0172   std::string firstLine = "";
0173   if (file.is_open()) {
0174       if (std::getline(file, firstLine)) {
0175           std::cout << "First Line: " << firstLine << std::endl;
0176       } else {
0177           std::cerr << "Unable to read first line of file" << std::endl;
0178       }
0179       file.close();
0180   } else {
0181       std::cerr << "Unable to open file" << std::endl;
0182   }
0183   return firstLine;
0184 }