File indexing completed on 2025-08-05 08:21:35
0001 #ifndef MACRO_FUN4ALLG4SPHENIX_C
0002 #define MACRO_FUN4ALLG4SPHENIX_C
0003
0004 #include <GlobalVariables.C>
0005
0006 #include <DisplayOn.C>
0007 #include <G4Setup_sPHENIX.C>
0008 #include <G4_Bbc.C>
0009 #include <G4_CaloTrigger.C>
0010 #include <G4_Centrality.C>
0011 #include <G4_DSTReader.C>
0012 #include <G4_Global.C>
0013 #include <G4_HIJetReco.C>
0014 #include <G4_Input.C>
0015 #include <G4_Jets.C>
0016 #include <G4_KFParticle.C>
0017 #include <G4_ParticleFlow.C>
0018 #include <G4_Production.C>
0019 #include <G4_TopoClusterReco.C>
0020
0021 #include <Trkr_RecoInit.C>
0022 #include <Trkr_Clustering.C>
0023 #include <Trkr_LaserClustering.C>
0024 #include <Trkr_Reco.C>
0025 #include <Trkr_Eval.C>
0026 #include <Trkr_QA.C>
0027
0028 #include <Trkr_Diagnostics.C>
0029 #include <G4_User.C>
0030 #include <QA.C>
0031
0032 #include <anatutorial/AnaTutorial.h>
0033
0034 #include <ffamodules/FlagHandler.h>
0035 #include <ffamodules/HeadReco.h>
0036 #include <ffamodules/SyncReco.h>
0037 #include <ffamodules/CDBInterface.h>
0038
0039 #include <fun4all/Fun4AllDstOutputManager.h>
0040 #include <fun4all/Fun4AllOutputManager.h>
0041 #include <fun4all/Fun4AllServer.h>
0042
0043 #include <phool/PHRandomSeed.h>
0044 #include <phool/recoConsts.h>
0045
0046 R__LOAD_LIBRARY(libfun4all.so)
0047 R__LOAD_LIBRARY(libffamodules.so)
0048 R__LOAD_LIBRARY(libanatutorial.so)
0049
0050
0051
0052 int Fun4All_AnaTutorial_sPHENIX_Jets(
0053 const int nEvents = 1,
0054 const string &inputFile = "https://www.phenix.bnl.gov/WWW/publish/phnxbld/sPHENIX/files/sPHENIX_G4Hits_sHijing_9-11fm_00000_00010.root",
0055 const string &outputFile = "G4sPHENIX.root",
0056 const string &embed_input_file = "https://www.phenix.bnl.gov/WWW/publish/phnxbld/sPHENIX/files/sPHENIX_G4Hits_sHijing_9-11fm_00000_00010.root",
0057 const int skip = 0,
0058 const string &outdir = ".")
0059 {
0060 Fun4AllServer *se = Fun4AllServer::instance();
0061 se->Verbosity(0);
0062
0063
0064 PHRandomSeed::Verbosity(1);
0065
0066
0067 recoConsts *rc = recoConsts::instance();
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083 Input::VERBOSITY = 0;
0084
0085
0086
0087
0088
0089
0090 INPUTREADHITS::filename[0] = inputFile;
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100 INPUTEMBED::filename[0] = embed_input_file;
0101
0102
0103
0104 Input::SIMPLE = true;
0105
0106
0107
0108
0109
0110
0111
0112
0113 Input::PYTHIA8 = true;
0114 PYTHIA8::config_file = "phpythia8.cfg";
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131 INPUTHEPMC::filename = inputFile;
0132
0133
0134
0135
0136
0137
0138
0139
0140 InputInit();
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150 if (Input::SIMPLE)
0151 {
0152 INPUTGENERATOR::SimpleEventGenerator[0]->add_particles("pi-", 5);
0153 if (Input::HEPMC || Input::EMBED)
0154 {
0155 INPUTGENERATOR::SimpleEventGenerator[0]->set_reuse_existing_vertex(true);
0156 INPUTGENERATOR::SimpleEventGenerator[0]->set_existing_vertex_offset_vector(0.0, 0.0, 0.0);
0157 }
0158 else
0159 {
0160 INPUTGENERATOR::SimpleEventGenerator[0]->set_vertex_distribution_function(PHG4SimpleEventGenerator::Gaus,
0161 PHG4SimpleEventGenerator::Gaus,
0162 PHG4SimpleEventGenerator::Gaus);
0163 INPUTGENERATOR::SimpleEventGenerator[0]->set_vertex_distribution_mean(0., 0., 0.);
0164 INPUTGENERATOR::SimpleEventGenerator[0]->set_vertex_distribution_width(0.01, 0.01, 5.);
0165 }
0166 INPUTGENERATOR::SimpleEventGenerator[0]->set_eta_range(-1, 1);
0167 INPUTGENERATOR::SimpleEventGenerator[0]->set_phi_range(-M_PI, M_PI);
0168 INPUTGENERATOR::SimpleEventGenerator[0]->set_pt_range(0.1, 20.);
0169 }
0170
0171
0172
0173 if (Input::UPSILON)
0174 {
0175 INPUTGENERATOR::VectorMesonGenerator[0]->add_decay_particles("e", 0);
0176 INPUTGENERATOR::VectorMesonGenerator[0]->set_rapidity_range(-1, 1);
0177 INPUTGENERATOR::VectorMesonGenerator[0]->set_pt_range(0., 10.);
0178
0179 INPUTGENERATOR::VectorMesonGenerator[0]->set_upsilon_1s();
0180 if (Input::HEPMC || Input::EMBED)
0181 {
0182 INPUTGENERATOR::VectorMesonGenerator[0]->set_reuse_existing_vertex(true);
0183 INPUTGENERATOR::VectorMesonGenerator[0]->set_existing_vertex_offset_vector(0.0, 0.0, 0.0);
0184 }
0185 }
0186
0187
0188
0189 if (Input::GUN)
0190 {
0191 INPUTGENERATOR::Gun[0]->AddParticle("pi-", 0, 1, 0);
0192 INPUTGENERATOR::Gun[0]->set_vtx(0, 0, 0);
0193 }
0194
0195
0196 if (Input::PYTHIA6)
0197 {
0198
0199 Input::ApplysPHENIXBeamParameter(INPUTGENERATOR::Pythia6);
0200 }
0201
0202 if (Input::PYTHIA8)
0203 {
0204
0205 Input::ApplysPHENIXBeamParameter(INPUTGENERATOR::Pythia8);
0206 }
0207
0208
0209
0210
0211
0212
0213 if (Input::HEPMC)
0214 {
0215
0216 Input::ApplysPHENIXBeamParameter(INPUTMANAGER::HepMCInputManager);
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226
0227
0228 if (Input::PILEUPRATE > 0)
0229 {
0230
0231 INPUTMANAGER::HepMCPileupInputManager->CopyHelperSettings(INPUTMANAGER::HepMCInputManager);
0232
0233
0234 }
0235 }
0236 if (Input::PILEUPRATE > 0)
0237 {
0238
0239 Input::ApplysPHENIXBeamParameter(INPUTMANAGER::HepMCPileupInputManager);
0240 }
0241
0242 InputRegister();
0243
0244 if (! Input::READHITS)
0245 {
0246 rc->set_IntFlag("RUNNUMBER",1);
0247
0248 SyncReco *sync = new SyncReco();
0249 se->registerSubsystem(sync);
0250
0251 HeadReco *head = new HeadReco();
0252 se->registerSubsystem(head);
0253 }
0254
0255
0256
0257 FlagHandler *flag = new FlagHandler();
0258 se->registerSubsystem(flag);
0259
0260
0261
0262
0263
0264
0265
0266
0267
0268 Enable::DSTOUT_COMPRESS = false;
0269 DstOut::OutputDir = outdir;
0270 DstOut::OutputFile = outputFile;
0271
0272
0273
0274
0275
0276
0277
0278
0279
0280
0281
0282
0283 Enable::QA = true;
0284
0285
0286
0287
0288
0289
0290
0291
0292
0293 Enable::BBCFAKE = true;
0294
0295 Enable::PIPE = true;
0296 Enable::PIPE_ABSORBER = true;
0297
0298
0299 Enable::MVTX = true;
0300 Enable::MVTX_CELL = Enable::MVTX && true;
0301 Enable::MVTX_CLUSTER = Enable::MVTX_CELL && true;
0302 Enable::MVTX_QA = Enable::MVTX_CLUSTER && Enable::QA && true;
0303
0304 Enable::INTT = true;
0305
0306
0307 Enable::INTT_CELL = Enable::INTT && true;
0308 Enable::INTT_CLUSTER = Enable::INTT_CELL && true;
0309 Enable::INTT_QA = Enable::INTT_CLUSTER && Enable::QA && true;
0310
0311 Enable::TPC = true;
0312 Enable::TPC_ABSORBER = true;
0313 Enable::TPC_CELL = Enable::TPC && true;
0314 Enable::TPC_CLUSTER = Enable::TPC_CELL && true;
0315 Enable::TPC_QA = Enable::TPC_CLUSTER && Enable::QA && true;
0316
0317 Enable::MICROMEGAS = true;
0318 Enable::MICROMEGAS_CELL = Enable::MICROMEGAS && true;
0319 Enable::MICROMEGAS_CLUSTER = Enable::MICROMEGAS_CELL && true;
0320 Enable::MICROMEGAS_QA = Enable::MICROMEGAS_CLUSTER && Enable::QA && true;
0321
0322 Enable::TRACKING_TRACK = (Enable::MICROMEGAS_CLUSTER && Enable::TPC_CLUSTER && Enable::INTT_CLUSTER && Enable::MVTX_CLUSTER) && true;
0323 Enable::TRACKING_EVAL = Enable::TRACKING_TRACK && true;
0324 Enable::TRACKING_QA = Enable::TRACKING_TRACK && Enable::QA && true;
0325
0326
0327
0328
0329
0330
0331
0332
0333
0334
0335 Enable::CEMC = true;
0336 Enable::CEMC_ABSORBER = true;
0337 Enable::CEMC_CELL = Enable::CEMC && true;
0338 Enable::CEMC_TOWER = Enable::CEMC_CELL && true;
0339 Enable::CEMC_CLUSTER = Enable::CEMC_TOWER && true;
0340 Enable::CEMC_EVAL = Enable::CEMC_CLUSTER && true;
0341 Enable::CEMC_QA = Enable::CEMC_CLUSTER && Enable::QA && true;
0342
0343 Enable::HCALIN = true;
0344 Enable::HCALIN_ABSORBER = true;
0345 Enable::HCALIN_CELL = Enable::HCALIN && true;
0346 Enable::HCALIN_TOWER = Enable::HCALIN_CELL && true;
0347 Enable::HCALIN_CLUSTER = Enable::HCALIN_TOWER && true;
0348 Enable::HCALIN_EVAL = Enable::HCALIN_CLUSTER && true;
0349 Enable::HCALIN_QA = Enable::HCALIN_CLUSTER && Enable::QA && true;
0350
0351 Enable::MAGNET = true;
0352 Enable::MAGNET_ABSORBER = true;
0353
0354 Enable::HCALOUT = true;
0355 Enable::HCALOUT_ABSORBER = true;
0356 Enable::HCALOUT_CELL = Enable::HCALOUT && true;
0357 Enable::HCALOUT_TOWER = Enable::HCALOUT_CELL && true;
0358 Enable::HCALOUT_CLUSTER = Enable::HCALOUT_TOWER && true;
0359 Enable::HCALOUT_EVAL = Enable::HCALOUT_CLUSTER && true;
0360 Enable::HCALOUT_QA = Enable::HCALOUT_CLUSTER && Enable::QA && true;
0361
0362 Enable::EPD = true;
0363 Enable::EPD_TILE = Enable::EPD && true;
0364
0365 Enable::BEAMLINE = true;
0366
0367
0368 Enable::ZDC = true;
0369
0370
0371 Enable::ZDC_TOWER = Enable::ZDC && true;
0372 Enable::ZDC_EVAL = Enable::ZDC_TOWER && true;
0373
0374
0375
0376 Enable::PLUGDOOR_ABSORBER = true;
0377
0378 Enable::GLOBAL_RECO = (Enable::BBCFAKE || Enable::TRACKING_TRACK) && true;
0379
0380
0381
0382
0383
0384
0385
0386 Enable::CALOTRIGGER = Enable::CEMC_TOWER && Enable::HCALIN_TOWER && Enable::HCALOUT_TOWER && false;
0387
0388 Enable::JETS = (Enable::GLOBAL_RECO || Enable::GLOBAL_FASTSIM) && true;
0389 Enable::JETS_EVAL = Enable::JETS && true;
0390 Enable::JETS_QA = Enable::JETS && Enable::QA && true;
0391
0392
0393
0394
0395 Enable::HIJETS = Enable::JETS && Enable::CEMC_TOWER && Enable::HCALIN_TOWER && Enable::HCALOUT_TOWER && false;
0396
0397
0398 Enable::TOPOCLUSTER = Enable::CEMC_TOWER && Enable::HCALIN_TOWER && Enable::HCALOUT_TOWER && false;
0399
0400 Enable::PARTICLEFLOW = Enable::TOPOCLUSTER && true;
0401
0402 Enable::CENTRALITY = true;
0403
0404
0405 Enable::BLACKHOLE = true;
0406
0407
0408
0409
0410
0411
0412
0413
0414
0415
0416 Enable::CDB = true;
0417
0418 rc->set_StringFlag("CDB_GLOBALTAG",CDB::global_tag);
0419
0420 rc->set_uint64Flag("TIMESTAMP",CDB::timestamp);
0421
0422
0423
0424
0425
0426
0427
0428
0429
0430
0431
0432
0433
0434
0435
0436
0437
0438
0439
0440
0441
0442
0443
0444 G4Init();
0445
0446
0447
0448
0449 if (!Input::READHITS)
0450 {
0451 G4Setup();
0452 }
0453
0454
0455
0456
0457
0458 if ((Enable::BBC && Enable::BBCRECO) || Enable::BBCFAKE) Bbc_Reco();
0459
0460 if (Enable::MVTX_CELL) Mvtx_Cells();
0461 if (Enable::INTT_CELL) Intt_Cells();
0462 if (Enable::TPC_CELL) TPC_Cells();
0463 if (Enable::MICROMEGAS_CELL) Micromegas_Cells();
0464
0465 if (Enable::CEMC_CELL) CEMC_Cells();
0466
0467 if (Enable::HCALIN_CELL) HCALInner_Cells();
0468
0469 if (Enable::HCALOUT_CELL) HCALOuter_Cells();
0470
0471
0472
0473
0474
0475 if (Enable::CEMC_TOWER) CEMC_Towers();
0476 if (Enable::CEMC_CLUSTER) CEMC_Clusters();
0477
0478
0479
0480
0481
0482 if (Enable::EPD_TILE) EPD_Tiles();
0483
0484
0485
0486
0487
0488 if (Enable::HCALIN_TOWER) HCALInner_Towers();
0489 if (Enable::HCALIN_CLUSTER) HCALInner_Clusters();
0490
0491 if (Enable::HCALOUT_TOWER) HCALOuter_Towers();
0492 if (Enable::HCALOUT_CLUSTER) HCALOuter_Clusters();
0493
0494
0495 if (Enable::TOPOCLUSTER) TopoClusterReco();
0496
0497
0498
0499
0500 if(Enable::TRACKING_TRACK)
0501 {
0502 TrackingInit();
0503 }
0504 if (Enable::MVTX_CLUSTER) Mvtx_Clustering();
0505 if (Enable::INTT_CLUSTER) Intt_Clustering();
0506 if (Enable::TPC_CLUSTER)
0507 {
0508 if(G4TPC::ENABLE_DIRECT_LASER_HITS || G4TPC::ENABLE_CENTRAL_MEMBRANE_HITS)
0509 {
0510 TPC_LaserClustering();
0511 }
0512 else
0513 {
0514 TPC_Clustering();
0515 }
0516 }
0517 if (Enable::MICROMEGAS_CLUSTER) Micromegas_Clustering();
0518
0519 if (Enable::TRACKING_TRACK)
0520 {
0521 Tracking_Reco();
0522 }
0523
0524 if(Enable::TRACKING_DIAGNOSTICS)
0525 {
0526 const std::string kshortFile = "./kshort_" + outputFile;
0527 const std::string residualsFile = "./residuals_" + outputFile;
0528
0529 G4KshortReconstruction(kshortFile);
0530 seedResiduals(residualsFile);
0531 }
0532
0533
0534
0535
0536
0537 if (Enable::GLOBAL_RECO && Enable::GLOBAL_FASTSIM)
0538 {
0539 cout << "You can only enable Enable::GLOBAL_RECO or Enable::GLOBAL_FASTSIM, not both" << endl;
0540 gSystem->Exit(1);
0541 }
0542 if (Enable::GLOBAL_RECO)
0543 {
0544 Global_Reco();
0545 }
0546 else if (Enable::GLOBAL_FASTSIM)
0547 {
0548 Global_FastSim();
0549 }
0550
0551
0552
0553
0554
0555 if (Enable::CENTRALITY)
0556 {
0557 Centrality();
0558 }
0559
0560
0561
0562
0563
0564 if (Enable::CALOTRIGGER)
0565 {
0566 CaloTrigger_Sim();
0567 }
0568
0569
0570
0571
0572
0573 if (Enable::JETS) Jet_Reco();
0574 if (Enable::HIJETS) HIJetReco();
0575
0576 if (Enable::PARTICLEFLOW) ParticleFlow();
0577
0578
0579
0580
0581 string outputroot = outputFile;
0582 string remove_this = ".root";
0583 size_t pos = outputroot.find(remove_this);
0584 if (pos != string::npos)
0585 {
0586 outputroot.erase(pos, remove_this.length());
0587 }
0588
0589 if (Enable::TRACKING_EVAL) Tracking_Eval(outputroot + "_g4svtx_eval.root");
0590
0591 if (Enable::CEMC_EVAL) CEMC_Eval(outputroot + "_g4cemc_eval.root");
0592
0593 if (Enable::HCALIN_EVAL) HCALInner_Eval(outputroot + "_g4hcalin_eval.root");
0594
0595 if (Enable::HCALOUT_EVAL) HCALOuter_Eval(outputroot + "_g4hcalout_eval.root");
0596
0597 if (Enable::JETS_EVAL) Jet_Eval(outputroot + "_g4jet_eval.root");
0598
0599 if (Enable::DSTREADER) G4DSTreader(outputroot + "_DSTReader.root");
0600
0601 if (Enable::USER) UserAnalysisInit();
0602
0603 AnaTutorial *anaTutorial = new AnaTutorial("anaTutorial", outputroot + "_anaTutorial.root");
0604 anaTutorial->setMinJetPt(10.);
0605 anaTutorial->Verbosity(0);
0606 anaTutorial->analyzeTracks(true);
0607 anaTutorial->analyzeClusters(true);
0608 anaTutorial->analyzeJets(true);
0609 anaTutorial->analyzeTruth(false);
0610 se->registerSubsystem(anaTutorial);
0611
0612
0613
0614 if(G4TRACKING::filter_conversion_electrons) Filter_Conversion_Electrons(outputroot + "_secvert_ntuple.root");
0615
0616
0617
0618
0619 if (Enable::KFPARTICLE && Input::UPSILON) KFParticle_Upsilon_Reco();
0620 if (Enable::KFPARTICLE && Input::DZERO) KFParticle_D0_Reco();
0621
0622
0623
0624
0625
0626 if (Enable::CEMC_QA) CEMC_QA();
0627 if (Enable::HCALIN_QA) HCALInner_QA();
0628 if (Enable::HCALOUT_QA) HCALOuter_QA();
0629
0630 if (Enable::JETS_QA) Jet_QA();
0631
0632 if (Enable::MVTX_QA) Mvtx_QA();
0633 if (Enable::INTT_QA) Intt_QA();
0634 if (Enable::TPC_QA) TPC_QA();
0635 if (Enable::MICROMEGAS_QA) Micromegas_QA();
0636 if (Enable::TRACKING_QA) Tracking_QA();
0637
0638 if (Enable::TRACKING_QA && Enable::CEMC_QA && Enable::HCALIN_QA && Enable::HCALOUT_QA) QA_G4CaloTracking();
0639
0640
0641
0642
0643
0644 InputManagers();
0645
0646 if (Enable::PRODUCTION)
0647 {
0648 Production_CreateOutputDir();
0649 }
0650
0651 if (Enable::DSTOUT)
0652 {
0653 string FullOutFile = DstOut::OutputDir + "/" + DstOut::OutputFile;
0654 Fun4AllDstOutputManager *out = new Fun4AllDstOutputManager("DSTOUT", FullOutFile);
0655 if (Enable::DSTOUT_COMPRESS)
0656 {
0657 ShowerCompress();
0658 DstCompress(out);
0659 }
0660 se->registerOutputManager(out);
0661 }
0662
0663
0664
0665 if (Enable::DISPLAY)
0666 {
0667 DisplayOn();
0668
0669 gROOT->ProcessLine("Fun4AllServer *se = Fun4AllServer::instance();");
0670 gROOT->ProcessLine("PHG4Reco *g4 = (PHG4Reco *) se->getSubsysReco(\"PHG4RECO\");");
0671
0672 cout << "-------------------------------------------------" << endl;
0673 cout << "You are in event display mode. Run one event with" << endl;
0674 cout << "se->run(1)" << endl;
0675 cout << "Run Geant4 command with following examples" << endl;
0676 gROOT->ProcessLine("displaycmd()");
0677
0678 return 0;
0679 }
0680
0681
0682 if (nEvents < 0)
0683 {
0684 return 0;
0685 }
0686
0687
0688 if (nEvents == 0 && !Input::HEPMC && !Input::READHITS && INPUTEMBED::REPEAT)
0689 {
0690 cout << "using 0 for number of events is a bad idea when using particle generators" << endl;
0691 cout << "it will run forever, so I just return without running anything" << endl;
0692 return 0;
0693 }
0694
0695 se->skip(skip);
0696 se->run(nEvents);
0697
0698
0699
0700
0701
0702 if (Enable::QA) QA_Output(outputroot + "_qa.root");
0703
0704
0705
0706
0707
0708
0709 se->End();
0710 std::cout << "All done" << std::endl;
0711 delete se;
0712 if (Enable::PRODUCTION)
0713 {
0714 Production_MoveOutput();
0715 }
0716
0717 gSystem->Exit(0);
0718 return 0;
0719 }
0720 #endif