File indexing completed on 2025-08-03 08:20:30
0001
0002
0003
0004
0005
0006
0007 #include <fun4all/Fun4AllUtils.h>
0008 #include <G4_ActsGeom.C>
0009 #include <G4_Global.C>
0010 #include <G4_Magnet.C>
0011 #include <GlobalVariables.C>
0012 #include <QA.C>
0013 #include <Trkr_Clustering.C>
0014 #include <Trkr_Reco.C>
0015 #include <Trkr_RecoInit.C>
0016 #include <Trkr_TpcReadoutInit.C>
0017
0018 #include <ffamodules/CDBInterface.h>
0019
0020 #include <fun4all/Fun4AllDstInputManager.h>
0021 #include <fun4all/Fun4AllDstOutputManager.h>
0022 #include <fun4all/Fun4AllInputManager.h>
0023 #include <fun4all/Fun4AllOutputManager.h>
0024 #include <fun4all/Fun4AllRunNodeInputManager.h>
0025 #include <fun4all/Fun4AllServer.h>
0026
0027 #include <phool/recoConsts.h>
0028
0029 #include <cdbobjects/CDBTTree.h>
0030
0031 #include <tpccalib/PHTpcResiduals.h>
0032
0033 #include <trackingqa/SiliconSeedsQA.h>
0034 #include <trackingqa/TpcSeedsQA.h>
0035 #include <trackingqa/TpcSiliconQA.h>
0036
0037 #include <trackingdiagnostics/TrackResiduals.h>
0038 #include <trackingdiagnostics/TrkrNtuplizer.h>
0039
0040 #include <kfparticle_sphenix/KFParticle_sPHENIX.h>
0041
0042 #include <stdio.h>
0043
0044 R__LOAD_LIBRARY(libkfparticle_sphenix.so)
0045
0046 R__LOAD_LIBRARY(libfun4all.so)
0047 R__LOAD_LIBRARY(libffamodules.so)
0048 R__LOAD_LIBRARY(libphool.so)
0049 R__LOAD_LIBRARY(libcdbobjects.so)
0050 R__LOAD_LIBRARY(libTrackingDiagnostics.so)
0051 R__LOAD_LIBRARY(libtrackingqa.so)
0052 void Fun4All_TrackSeeding(
0053 const int nEvents = 5,
0054 const std::string clusterfilename = "DST_TRKR_CLUSTER_run2pp_ana494_2024p021_v001-00053877-00000.root",
0055 const std::string dir = "/sphenix/lustre01/sphnxpro/production/run2pp/physics/ana494_2024p021_v001/DST_TRKR_CLUSTER/run_00053800_00053900/dst/",
0056 const std::string outfilename = "clusters_seeds",
0057 const bool convertSeeds = false,
0058 const bool doKFParticle = false)
0059 {
0060
0061 std::string inputclusterRawHitFile = dir + clusterfilename;
0062
0063 G4TRACKING::convert_seeds_to_svtxtracks = convertSeeds;
0064 std::cout << "Converting to seeds : " << G4TRACKING::convert_seeds_to_svtxtracks << std::endl;
0065 std::pair<int, int>
0066 runseg = Fun4AllUtils::GetRunSegment(clusterfilename);
0067 int runnumber = runseg.first;
0068 int segment = runseg.second;
0069
0070 auto rc = recoConsts::instance();
0071 rc->set_IntFlag("RUNNUMBER", runnumber);
0072
0073 Enable::CDB = true;
0074 rc->set_StringFlag("CDB_GLOBALTAG", "newcdbtag");
0075 rc->set_uint64Flag("TIMESTAMP", runnumber);
0076 std::string geofile = CDBInterface::instance()->getUrl("Tracking_Geometry");
0077
0078 TpcReadoutInit(runnumber);
0079
0080
0081
0082
0083 std::cout << " run: " << runnumber
0084 << " samples: " << TRACKING::reco_tpc_maxtime_sample
0085 << " pre: " << TRACKING::reco_tpc_time_presample
0086 << " vdrift: " << G4TPC::tpc_drift_velocity_reco
0087 << std::endl;
0088
0089 string outDir = "myKShortReco/";
0090 string outputFileName = "outputKFParticle_" + to_string(runnumber) + "_" + to_string(segment) + ".root";
0091 string outputRecoDir = outDir + "inReconstruction/";
0092 string outputRecoFile = outputRecoDir + outputFileName;
0093
0094 if(doKFParticle){
0095 string makeMainDirectory = "mkdir -p " + outDir;
0096 system(makeMainDirectory.c_str());
0097 string makeDirectory = "mkdir -p " + outputRecoDir;
0098 system(makeDirectory.c_str());
0099 }
0100
0101
0102
0103
0104
0105
0106 G4TRACKING::SC_CALIBMODE = false;
0107 TRACKING::pp_mode = true;
0108
0109 Enable::MVTX_APPLYMISALIGNMENT = true;
0110 ACTSGEOM::mvtx_applymisalignment = Enable::MVTX_APPLYMISALIGNMENT;
0111
0112 TString outfile = outfilename + "_" + runnumber + "-" + segment + ".root";
0113 std::string theOutfile = outfile.Data();
0114 auto se = Fun4AllServer::instance();
0115 se->Verbosity(1);
0116
0117
0118 Fun4AllRunNodeInputManager *ingeo = new Fun4AllRunNodeInputManager("GeoIn");
0119 ingeo->AddFile(geofile);
0120 se->registerInputManager(ingeo);
0121
0122 G4TPC::ENABLE_MODULE_EDGE_CORRECTIONS = true;
0123
0124
0125 G4TPC::ENABLE_STATIC_CORRECTIONS = true;
0126 G4TPC::USE_PHI_AS_RAD_STATIC_CORRECTIONS = false;
0127
0128
0129
0130 G4TPC::ENABLE_AVERAGE_CORRECTIONS = true;
0131 G4TPC::USE_PHI_AS_RAD_AVERAGE_CORRECTIONS = false;
0132
0133 G4TPC::average_correction_filename = CDBInterface::instance()->getUrl("TPC_LAMINATION_FIT_CORRECTION");
0134
0135 G4MAGNET::magfield_rescale = 1;
0136 TrackingInit();
0137
0138 auto hitsinclus = new Fun4AllDstInputManager("ClusterInputManager");
0139 hitsinclus->fileopen(inputclusterRawHitFile);
0140 se->registerInputManager(hitsinclus);
0141
0142
0143 Reject_Laser_Events();
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153 auto silicon_Seeding = new PHActsSiliconSeeding;
0154 silicon_Seeding->Verbosity(0);
0155 silicon_Seeding->setStrobeRange(-5,5);
0156
0157 silicon_Seeding->setinttRPhiSearchWindow(0.2);
0158 silicon_Seeding->setinttZSearchWindow(1.0);
0159 silicon_Seeding->seedAnalysis(false);
0160 se->registerSubsystem(silicon_Seeding);
0161
0162 auto merger = new PHSiliconSeedMerger;
0163 merger->Verbosity(0);
0164 se->registerSubsystem(merger);
0165
0166
0167
0168
0169 auto seeder = new PHCASeeding("PHCASeeding");
0170 double fieldstrength = std::numeric_limits<double>::quiet_NaN();
0171 bool ConstField = isConstantField(G4MAGNET::magfield_tracking, fieldstrength);
0172 if (ConstField)
0173 {
0174 seeder->useConstBField(true);
0175 seeder->constBField(fieldstrength);
0176 }
0177 else
0178 {
0179 seeder->set_field_dir(-1 * G4MAGNET::magfield_rescale);
0180 seeder->useConstBField(false);
0181 seeder->magFieldFile(G4MAGNET::magfield_tracking);
0182 }
0183 seeder->Verbosity(0);
0184 seeder->SetLayerRange(7, 55);
0185 seeder->SetSearchWindow(2.,0.05);
0186 seeder->SetClusAdd_delta_window(3.0,0.06);
0187
0188 seeder->SetMinHitsPerCluster(0);
0189 seeder->SetMinClustersPerTrack(3);
0190 seeder->useFixedClusterError(true);
0191 seeder->set_pp_mode(true);
0192 seeder->reject_zsize1_clusters(true);
0193 se->registerSubsystem(seeder);
0194
0195
0196 auto cprop = new PHSimpleKFProp("PHSimpleKFProp");
0197 cprop->set_field_dir(G4MAGNET::magfield_rescale);
0198 if (ConstField)
0199 {
0200 cprop->useConstBField(true);
0201 cprop->setConstBField(fieldstrength);
0202 }
0203 else
0204 {
0205 cprop->magFieldFile(G4MAGNET::magfield_tracking);
0206 cprop->set_field_dir(-1 * G4MAGNET::magfield_rescale);
0207 }
0208 cprop->useFixedClusterError(true);
0209 cprop->set_max_window(5.);
0210 cprop->Verbosity(0);
0211 cprop->set_pp_mode(true);
0212 cprop->set_max_seeds(5000);
0213 se->registerSubsystem(cprop);
0214
0215
0216
0217 auto prelim_distcorr = new PrelimDistortionCorrection;
0218 prelim_distcorr->set_pp_mode(true);
0219 prelim_distcorr->Verbosity(0);
0220 se->registerSubsystem(prelim_distcorr);
0221
0222
0223
0224
0225
0226
0227 auto silicon_match = new PHSiliconTpcTrackMatching;
0228 silicon_match->Verbosity(0);
0229 silicon_match->set_pp_mode(TRACKING::pp_mode);
0230 if(G4TPC::ENABLE_AVERAGE_CORRECTIONS)
0231 {
0232
0233
0234
0235 silicon_match->window_deta.set_posQoverpT_maxabs({-0.014,0.0331,0.48});
0236 silicon_match->window_deta.set_negQoverpT_maxabs({-0.006,0.0235,0.52});
0237 silicon_match->set_deltaeta_min(0.03);
0238 silicon_match->window_dphi.set_QoverpT_range({-0.15,0,0}, {0.15,0,0});
0239 silicon_match->window_dx.set_QoverpT_maxabs({3.0,0,0});
0240 silicon_match->window_dy.set_QoverpT_maxabs({3.0,0,0});
0241 silicon_match->window_dz.set_posQoverpT_maxabs({1.138,0.3919,0.84});
0242 silicon_match->window_dz.set_negQoverpT_maxabs({0.719,0.6485,0.65});
0243 silicon_match->set_crossing_deltaz_max(30);
0244 silicon_match->set_crossing_deltaz_min(2);
0245
0246
0247 if (G4TRACKING::SC_CALIBMODE)
0248 {
0249 silicon_match->window_deta.set_posQoverpT_maxabs({0.016,0.0060,1.13});
0250 silicon_match->window_deta.set_negQoverpT_maxabs({0.022,0.0022,1.44});
0251 silicon_match->set_deltaeta_min(0.03);
0252 silicon_match->window_dphi.set_QoverpT_range({-0.15,0,0}, {0.09,0,0});
0253 silicon_match->window_dx.set_QoverpT_maxabs({2.0,0,0});
0254 silicon_match->window_dy.set_QoverpT_maxabs({1.5,0,0});
0255 silicon_match->window_dz.set_posQoverpT_maxabs({1.213,0.0211,2.09});
0256 silicon_match->window_dz.set_negQoverpT_maxabs({1.307,0.0001,4.52});
0257 silicon_match->set_crossing_deltaz_min(1.2);
0258 }
0259 }
0260 se->registerSubsystem(silicon_match);
0261
0262
0263 auto mm_match = new PHMicromegasTpcTrackMatching;
0264 mm_match->Verbosity(0);
0265 mm_match->set_pp_mode(TRACKING::pp_mode);
0266 mm_match->set_rphi_search_window_lyr1(3.);
0267 mm_match->set_rphi_search_window_lyr2(15.0);
0268 mm_match->set_z_search_window_lyr1(30.0);
0269 mm_match->set_z_search_window_lyr2(3.);
0270
0271 mm_match->set_min_tpc_layer(38);
0272 mm_match->set_test_windows_printout(false);
0273 se->registerSubsystem(mm_match);
0274
0275
0276
0277
0278
0279
0280
0281
0282
0283 if (G4TRACKING::convert_seeds_to_svtxtracks)
0284 {
0285 auto converter = new TrackSeedTrackMapConverter;
0286
0287
0288 converter->setTrackSeedName("SvtxTrackSeedContainer");
0289 converter->setFieldMap(G4MAGNET::magfield_tracking);
0290 converter->Verbosity(0);
0291 se->registerSubsystem(converter);
0292 }
0293 else
0294 {
0295 auto deltazcorr = new PHTpcDeltaZCorrection;
0296 deltazcorr->Verbosity(0);
0297 se->registerSubsystem(deltazcorr);
0298
0299
0300 auto actsFit = new PHActsTrkFitter;
0301 actsFit->Verbosity(0);
0302 actsFit->commissioning(G4TRACKING::use_alignment);
0303
0304 actsFit->fitSiliconMMs(G4TRACKING::SC_CALIBMODE);
0305 actsFit->setUseMicromegas(G4TRACKING::SC_USE_MICROMEGAS);
0306 actsFit->set_pp_mode(TRACKING::pp_mode);
0307 actsFit->set_use_clustermover(true);
0308 actsFit->useActsEvaluator(false);
0309 actsFit->useOutlierFinder(false);
0310 actsFit->setFieldMap(G4MAGNET::magfield_tracking);
0311 se->registerSubsystem(actsFit);
0312
0313 auto cleaner = new PHTrackCleaner();
0314 cleaner->Verbosity(0);
0315 cleaner->set_pp_mode(TRACKING::pp_mode);
0316 se->registerSubsystem(cleaner);
0317
0318 if (G4TRACKING::SC_CALIBMODE)
0319 {
0320
0321
0322
0323
0324 auto residuals = new PHTpcResiduals;
0325 const TString tpc_residoutfile = theOutfile + "_PhTpcResiduals.root";
0326 residuals->setOutputfile(tpc_residoutfile.Data());
0327 residuals->setUseMicromegas(G4TRACKING::SC_USE_MICROMEGAS);
0328
0329
0330 residuals->setMinPt(0.2);
0331
0332
0333 residuals->setGridDimensions(36, 48, 80);
0334 se->registerSubsystem(residuals);
0335 }
0336 }
0337
0338 auto finder = new PHSimpleVertexFinder;
0339 finder->Verbosity(0);
0340
0341
0342 finder->setDcaCut(0.05);
0343 finder->setTrackPtCut(0.1);
0344 finder->setBeamLineCut(1);
0345 finder->setTrackQualityCut(300);
0346 finder->setNmvtxRequired(3);
0347 finder->setOutlierPairCut(0.10);
0348
0349 se->registerSubsystem(finder);
0350
0351
0352 auto vtxProp = new PHActsVertexPropagator;
0353 vtxProp->Verbosity(0);
0354 vtxProp->fieldMap(G4MAGNET::magfield_tracking);
0355 se->registerSubsystem(vtxProp);
0356
0357
0358 if(doKFParticle){
0359 Global_Reco();
0360
0361
0362
0363 KFParticle_sPHENIX *kfparticle = new KFParticle_sPHENIX("myKShortReco");
0364 kfparticle->Verbosity(1);
0365 kfparticle->setDecayDescriptor("K_S0 -> pi^+ pi^-");
0366
0367
0368 kfparticle->magFieldFile("FIELDMAP_TRACKING");
0369 kfparticle->getAllPVInfo(false);
0370 kfparticle->allowZeroMassTracks(true);
0371 kfparticle->useFakePrimaryVertex(false);
0372 kfparticle->getDetectorInfo(true);
0373
0374 kfparticle->constrainToPrimaryVertex(true);
0375 kfparticle->setMotherIPchi2(FLT_MAX);
0376 kfparticle->setFlightDistancechi2(-1.);
0377 kfparticle->setMinDIRA(-1.1);
0378 kfparticle->setDecayLengthRange(0., FLT_MAX);
0379 kfparticle->setDecayTimeRange(-1*FLT_MAX, FLT_MAX);
0380
0381
0382 kfparticle->setMinMVTXhits(0);
0383
0384 kfparticle->setMinTPChits(20);
0385 kfparticle->setMinimumTrackPT(-1.);
0386 kfparticle->setMaximumTrackPTchi2(FLT_MAX);
0387 kfparticle->setMinimumTrackIPchi2(-1.);
0388 kfparticle->setMinimumTrackIP(-1.);
0389
0390 kfparticle->setMaximumTrackchi2nDOF(300.);
0391
0392
0393 kfparticle->setMaximumVertexchi2nDOF(50);
0394 kfparticle->setMaximumDaughterDCA(1.);
0395
0396
0397 kfparticle->setMotherPT(0);
0398 kfparticle->setMinimumMass(0.200);
0399 kfparticle->setMaximumMass(1.000);
0400 kfparticle->setMaximumMotherVertexVolume(0.1);
0401
0402 kfparticle->setOutputName(outputRecoFile);
0403
0404 se->registerSubsystem(kfparticle);
0405 }
0406
0407 TString residoutfile = theOutfile + "_resid.root";
0408 std::string residstring(residoutfile.Data());
0409
0410 auto resid = new TrackResiduals("TrackResiduals");
0411 resid->outfileName(residstring);
0412 resid->alignment(false);
0413
0414
0415 if (G4TRACKING::SC_CALIBMODE && !G4TRACKING::convert_seeds_to_svtxtracks)
0416 {
0417 resid->trackmapName("SvtxSiliconMMTrackMap");
0418 if (G4TRACKING::SC_USE_MICROMEGAS)
0419 {
0420 resid->set_doMicromegasOnly(true);
0421 }
0422 }
0423
0424 resid->clusterTree();
0425 resid->convertSeeds(G4TRACKING::convert_seeds_to_svtxtracks);
0426 resid->Verbosity(0);
0427 se->registerSubsystem(resid);
0428
0429 if (Enable::QA)
0430 {
0431 se->registerSubsystem(new SiliconSeedsQA);
0432 se->registerSubsystem(new TpcSeedsQA);
0433 se->registerSubsystem(new TpcSiliconQA);
0434 }
0435 se->run(nEvents);
0436 se->End();
0437 se->PrintTimer();
0438 CDBInterface::instance()->Print();
0439 if (Enable::QA)
0440 {
0441 TString qaname = theOutfile + "_qa.root";
0442 std::string qaOutputFileName(qaname.Data());
0443 QAHistManagerDef::saveQARootFile(qaOutputFileName);
0444 }
0445
0446 if(doKFParticle){
0447 ifstream file(outputRecoFile.c_str());
0448 if (file.good())
0449 {
0450 string moveOutput = "mv " + outputRecoFile + " " + outDir;
0451 system(moveOutput.c_str());
0452 }
0453 }
0454
0455 delete se;
0456 std::cout << "Finished" << std::endl;
0457 gSystem->Exit(0);
0458 }