File indexing completed on 2026-08-30 08:24:55
0001
0002
0003
0004
0005
0006
0007
0008 #include <GlobalVariables.C>
0009
0010 #include <G4_ActsGeom.C>
0011 #include <G4_Global.C>
0012 #include <G4_Magnet.C>
0013 #include <G4_Mbd.C>
0014 #include <QA.C>
0015 #include <Trkr_Clustering.C>
0016 #include <Trkr_LaserClustering.C>
0017 #include <Trkr_Reco.C>
0018 #include <Trkr_RecoInit.C>
0019 #include <Trkr_TpcReadoutInit.C>
0020
0021 #include <tpctrackreco/Tpc_ModuleTrackReco.h>
0022 #include <tpctrackreco/Tpc_AssembledTrackReco.h>
0023 #include <tpctrackreco/Tpc_PolyTrackReco.h>
0024 #include <tpctrackreco/Tpc_PolyTrackVertexer.h>
0025 #include <tpctrackreco/Tpc_PolyClusterizer.h>
0026
0027 #include <trackingdiagnostics/Tpc_ModuleTrackDisplay.h>
0028 #include <trackingdiagnostics/Tpc_AssembledTrackDisplay.h>
0029 #include <trackingdiagnostics/Tpc_PolyClusterDisplay.h>
0030 #include <trackingdiagnostics/Tpc_PolyClusterResiduals.h>
0031
0032 #include <cdbobjects/CDBTTree.h>
0033
0034 #include <ffamodules/CDBInterface.h>
0035 #include <ffamodules/FlagHandler.h>
0036
0037 #include <fun4all/Fun4AllDstInputManager.h>
0038 #include <fun4all/Fun4AllDstOutputManager.h>
0039 #include <fun4all/Fun4AllInputManager.h>
0040 #include <fun4all/Fun4AllOutputManager.h>
0041 #include <fun4all/Fun4AllRunNodeInputManager.h>
0042 #include <fun4all/Fun4AllServer.h>
0043 #include <fun4all/Fun4AllUtils.h>
0044
0045 #include <fun4all/SubsysReco.h>
0046 #include <fun4all/Fun4AllReturnCodes.h>
0047
0048 #include <phool/recoConsts.h>
0049
0050 #include <format>
0051
0052 R__LOAD_LIBRARY(libfun4all.so)
0053 R__LOAD_LIBRARY(libffamodules.so)
0054 R__LOAD_LIBRARY(libphool.so)
0055 R__LOAD_LIBRARY(libcdbobjects.so)
0056 R__LOAD_LIBRARY(libmvtx.so)
0057 R__LOAD_LIBRARY(libintt.so)
0058 R__LOAD_LIBRARY(libtpc.so)
0059 R__LOAD_LIBRARY(libmicromegas.so)
0060 R__LOAD_LIBRARY(libPHGarfield.so)
0061 R__LOAD_LIBRARY(libtpctrackreco.so)
0062 R__LOAD_LIBRARY(libTrackingDiagnostics.so)
0063
0064
0065 class SkipFirstN : public SubsysReco {
0066 public:
0067 explicit SkipFirstN(int n) : SubsysReco("SkipFirstN"), target_(n) {}
0068 int process_event(PHCompositeNode* ) override {
0069 if (count_ < target_) { ++count_; return Fun4AllReturnCodes::ABORTEVENT; }
0070 return Fun4AllReturnCodes::EVENT_OK;
0071 }
0072 private:
0073 int target_ = 0;
0074 int count_ = 0;
0075 };
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087 void Fun4All_raw_hit_TPC_reco(
0088 const int nEvents = 2,
0089 const int runnumber = 79513,
0090 const int segment = 0,
0091 const std::string& outdir = ".",
0092 const int nSkip = 0,
0093 const std::string& collision = "run3pp",
0094 const std::string& production = "ana532_nocdbtag_v001",
0095 const std::string& outfilename = "HITS_ppFieldOn",
0096 const std::string& datatype = "physics")
0097 {
0098 const bool convertSeeds = true;
0099 auto *se = Fun4AllServer::instance();
0100 se->Verbosity(1);
0101 auto *rc = recoConsts::instance();
0102 se->registerSubsystem(new SkipFirstN(nSkip));
0103
0104 const std::string dsttype = "STREAMING_EVENT";
0105 const std::string dsttype_to_save = "TPC";
0106
0107
0108 std::ostringstream runstr;
0109 runstr << std::setw(8) << std::setfill('0') << runnumber;
0110
0111 std::ostringstream segstr;
0112 segstr << std::setw(5) << std::setfill('0') << segment;
0113
0114 const int runbase = (runnumber / 100) * 100;
0115 const int runnext = runbase + 100;
0116
0117 std::ostringstream rundir;
0118 rundir << "run_" << std::setw(8) << std::setfill('0') << runbase << "_" << std::setw(8) << std::setfill('0') << runnext;
0119
0120 std::vector<std::string> streams;
0121
0122
0123 for (int ebdc = 0; ebdc < 24; ++ebdc)
0124 {
0125 for (int endpoint = 0; endpoint < 2; ++endpoint)
0126 {
0127 std::ostringstream s;
0128 s << "ebdc" << std::setw(2) << std::setfill('0') << ebdc << "_" << endpoint;
0129 streams.push_back(s.str());
0130 }
0131 }
0132 if(collision!="run3line_laser"&&collision!="run3cosmics")
0133 {
0134
0135 streams.emplace_back("ebdc39");
0136
0137
0138 for (int server = 0; server < 8; ++server)
0139 {
0140 std::ostringstream s;
0141 s << "intt" << server;
0142 streams.push_back(s.str());
0143 }
0144
0145
0146 for (int felix = 0; felix < 6; ++felix)
0147 {
0148 std::ostringstream s;
0149 s << "mvtx" << felix;
0150 streams.push_back(s.str());
0151 }
0152 }
0153
0154 int i = 0;
0155 std::stringstream nice_runnumber;
0156 nice_runnumber << std::setw(8) << std::setfill('0') << std::to_string(runnumber);
0157
0158 int rounded_up = 100 * (std::ceil((float) runnumber / 100));
0159 std::stringstream nice_rounded_up;
0160 nice_rounded_up << std::setw(8) << std::setfill('0') << std::to_string(rounded_up);
0161
0162 int rounded_down = 100 * (std::floor((float) runnumber / 100));
0163 std::stringstream nice_rounded_down;
0164 nice_rounded_down << std::setw(8) << std::setfill('0') << std::to_string(rounded_down);
0165
0166 for (auto &stream : streams)
0167 {
0168 std::string filename = std::format("DST_{}_{}_{}_{}_{:08d}-{:05d}.root", dsttype, stream, collision, production, runnumber, segment);
0169 std::string filepath = std::format("/sphenix/lustre01/sphnxpro/production/{}/{}/{}/DST_{}_{}/run_{}_{}/{}",collision, datatype, production, dsttype, stream, nice_rounded_down.str(), nice_rounded_up.str(),filename);
0170 std::cout << "Adding DST: " << filepath << std::endl;
0171 if (i == 0)
0172 {
0173 rc->set_IntFlag("RUNNUMBER", runnumber);
0174 rc->set_uint64Flag("TIMESTAMP", runnumber);
0175 }
0176
0177 std::string inputname = "InputManager" + std::to_string(i);
0178 auto *hitsin = new Fun4AllDstInputManager(inputname);
0179 hitsin->fileopen(filename);
0180 se->registerInputManager(hitsin);
0181
0182 ++i;
0183 }
0184
0185 rc->set_IntFlag("RUNNUMBER", runnumber);
0186 rc->set_IntFlag("RUNSEGMENT", segment);
0187
0188 Enable::QA = false;
0189 Enable::CDB = true;
0190 rc->set_StringFlag("CDB_GLOBALTAG", "newcdbtag");
0191 rc->set_uint64Flag("TIMESTAMP", runnumber);
0192
0193
0194
0195 G4TRACKING::convert_seeds_to_svtxtracks = convertSeeds;
0196
0197
0198 std::cout << " run: " << runnumber
0199 << " samples: " << TRACKING::reco_tpc_maxtime_sample
0200 << " pre: " << TRACKING::reco_tpc_time_presample
0201 << " vdrift: " << G4TPC::tpc_drift_velocity_reco
0202 << std::endl;
0203
0204 TRACKING::streaming_mode = true;
0205
0206 FlagHandler *flag = new FlagHandler();
0207 se->registerSubsystem(flag);
0208
0209 std::string geofile = CDBInterface::instance()->getUrl("Tracking_Geometry");
0210
0211 Fun4AllRunNodeInputManager *ingeo = new Fun4AllRunNodeInputManager("GeoIn");
0212 ingeo->AddFile(geofile);
0213 se->registerInputManager(ingeo);
0214
0215
0216
0217 TpcReadoutInit(runnumber);
0218 G4TPC::REJECT_LASER_EVENTS = true;
0219
0220 TRACKING::tpc_zero_supp = true;
0221
0222 TrackingInit();
0223
0224 for (int felix = 0; felix < 6; felix++)
0225 {
0226 Mvtx_HitUnpacking(std::to_string(felix));
0227 }
0228 for (int server = 0; server < 8; server++)
0229 {
0230 Intt_HitUnpacking(std::to_string(server));
0231 }
0232 std::ostringstream ebdcname;
0233 for (int ebdc = 0; ebdc < 24; ebdc++)
0234 {
0235 for (int endpoint = 0; endpoint < 2; endpoint++)
0236 {
0237 ebdcname.str("");
0238 if (ebdc < 10)
0239 {
0240 ebdcname << "0";
0241 }
0242 ebdcname << ebdc << "_" << endpoint;
0243 Tpc_HitUnpacking(ebdcname.str());
0244 }
0245 }
0246
0247
0248 Micromegas_HitUnpacking();
0249 Micromegas_Clustering();
0250 Intt_Clustering();
0251
0252 Tpc_LaserEventIdentifying();
0253
0254 Reject_Laser_Events();
0255
0256
0257
0258 se->registerSubsystem(new Tpc_ModuleTrackReco());
0259 se->registerSubsystem(new Tpc_AssembledTrackReco());
0260
0261 auto *cluster = new Tpc_PolyClusterizer();
0262
0263 cluster->setKEffSide0(1.0);
0264 cluster->setKEffSide1(1.6);
0265
0266 se->registerSubsystem(cluster);
0267
0268 se->registerSubsystem(new Tpc_PolyTrackReco());
0269 se->registerSubsystem(new Tpc_PolyTrackVertexer());
0270
0271
0272
0273
0274
0275
0276
0277
0278 se->registerSubsystem(new Tpc_PolyClusterDisplay("Tpc_PolyClusterDisplay", "tpc_poly_cluster_display_" + outfilename + "_" + std::to_string(runnumber) + ".root"));
0279
0280
0281 auto *resid = new Tpc_PolyClusterResiduals("Tpc_PolyClusterResiduals",
0282 outdir + "/tpc_poly_track_residuals"+ outfilename + "_" + std::to_string(runnumber) + std::to_string(segment) + ".root" );
0283 resid->setMinPt(0);
0284 resid->setMinTpcClusters(20);
0285 se->registerSubsystem(resid);
0286
0287 Fun4AllOutputManager *out = new Fun4AllDstOutputManager("out", std::format("{}/DST_{}_{}_{}-{:08d}-{:05d}.root",outdir, dsttype_to_save, collision, production, runnumber, segment));
0288
0289 out->AddNode("Sync");
0290 out->AddNode("EventHeader");
0291 out->AddRunNode("TPCGEOMCONTAINER");
0292 out->AddNode("TRKR_HITSET");
0293
0294
0295 out->AddNode("TPC_POLYCLUSTERS");
0296 out->AddNode("TPC_POLYTRACKS");
0297 out->AddNode("TPC_POLYTRACKVERTICES");
0298 out->AddNode("TRKR_CLUSTER");
0299
0300 se->registerOutputManager(out);
0301
0302 se->run(nEvents+nSkip);
0303 se->Print("NODETREE");
0304 se->End();
0305 se->PrintTimer();
0306
0307
0308 CDBInterface::instance()->Print();
0309 delete se;
0310 std::cout << "Finished" << std::endl;
0311 gSystem->Exit(0);
0312 }