File indexing completed on 2025-08-05 08:14:29
0001 #include <iostream>
0002 using namespace std;
0003 int Fun4All_G4_sPHENIX_photons(
0004 const int nEvents = 2,
0005 const int jobnum = 0,
0006 const float photenergy = 10,
0007 const int doembedding = 0,
0008 const char *inputFile = "/sphenix/data/data02/review_2017-08-02/single_particle/spacal2d/fieldmap/G4Hits_sPHENIX_e-_eta0_8GeV-0002.root",
0009 const char *outputFile = "G4sPHENIX.root",
0010 const char *embed_input_file = "/sphenix/data/data02/review_2017-08-02/sHijing/fm_0-4.list")
0011 {
0012
0013 const int n_TPC_layers = 40;
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026 const bool readhits = false;
0027
0028
0029 const bool readhepmc = false && doembedding;
0030
0031
0032 const bool runpythia8 = false;
0033 const bool runpythia6 = false;
0034
0035
0036
0037
0038
0039 const bool do_embedding = doembedding && false;
0040
0041
0042
0043 const bool particles = true && !readhits;
0044
0045 const bool usegun = false && !readhits;
0046
0047 const bool upsilons = false && !readhits;
0048
0049
0050 const double pileup_collision_rate = 0;
0051
0052
0053
0054
0055
0056 bool do_bbc = true;
0057
0058 bool do_pipe = true;
0059
0060 bool do_svtx = true;
0061 bool do_svtx_cell = do_svtx && true;
0062 bool do_svtx_track = do_svtx_cell && false;
0063 bool do_svtx_eval = do_svtx_track && false;
0064
0065 bool do_pstof = false;
0066
0067 bool do_cemc = true;
0068 bool do_cemc_cell = do_cemc && true;
0069 bool do_cemc_twr = do_cemc_cell && true;
0070 bool do_cemc_cluster = do_cemc_twr && true;
0071 bool do_cemc_eval = do_cemc_cluster && false;
0072
0073 bool do_hcalin = true;
0074 bool do_hcalin_cell = do_hcalin && true;
0075 bool do_hcalin_twr = do_hcalin_cell && true;
0076 bool do_hcalin_cluster = do_hcalin_twr && true;
0077 bool do_hcalin_eval = do_hcalin_cluster && false;
0078
0079 bool do_magnet = true;
0080
0081 bool do_hcalout = true;
0082 bool do_hcalout_cell = do_hcalout && true;
0083 bool do_hcalout_twr = do_hcalout_cell && true;
0084 bool do_hcalout_cluster = do_hcalout_twr && true;
0085 bool do_hcalout_eval = do_hcalout_cluster && false;
0086
0087
0088 bool do_plugdoor = false;
0089
0090 bool do_global = true;
0091 bool do_global_fastsim = true;
0092
0093 bool do_calotrigger = true && do_cemc_twr && do_hcalin_twr && do_hcalout_twr;
0094
0095 bool do_jet_reco = false;
0096 bool do_jet_eval = do_jet_reco && false;
0097
0098
0099
0100
0101 bool do_HIjetreco = false && do_cemc_twr && do_hcalin_twr && do_hcalout_twr;
0102
0103 bool do_dst_compress = false;
0104
0105
0106 bool do_DSTReader = false;
0107
0108
0109
0110
0111 gSystem->Load("libfun4all.so");
0112 gSystem->Load("libg4detectors.so");
0113 gSystem->Load("libphhepmc.so");
0114 gSystem->Load("libg4testbench.so");
0115 gSystem->Load("libg4hough.so");
0116 gSystem->Load("libg4eval.so");
0117
0118
0119 gROOT->LoadMacro("G4Setup_sPHENIX.C");
0120 G4Init(do_svtx, do_pstof, do_cemc, do_hcalin, do_magnet, do_hcalout, do_pipe, do_plugdoor, n_TPC_layers);
0121
0122 int absorberactive = 1;
0123
0124 const string magfield = "/phenix/upgrades/decadal/fieldmaps/sPHENIX.2d.root";
0125 const float magfield_rescale = -1.4 / 1.5;
0126
0127
0128
0129
0130
0131 Fun4AllServer *se = Fun4AllServer::instance();
0132 se->Verbosity(0);
0133
0134 recoConsts *rc = recoConsts::instance();
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149 if (readhits)
0150 {
0151
0152
0153
0154 if (do_embedding)
0155 {
0156 cout << "Do not support read hits and embed background at the same time." << endl;
0157 exit(1);
0158 }
0159 }
0160 else
0161 {
0162
0163
0164 if (readhepmc)
0165 {
0166
0167 }
0168
0169 if (runpythia8)
0170 {
0171 gSystem->Load("libPHPythia8.so");
0172
0173 PHPythia8 *pythia8 = new PHPythia8();
0174
0175 pythia8->set_config_file("phpythia8.cfg");
0176 if (readhepmc)
0177 pythia8->set_reuse_vertex(0);
0178
0179 se->registerSubsystem(pythia8);
0180 }
0181
0182 if (runpythia6)
0183 {
0184 gSystem->Load("libPHPythia6.so");
0185
0186 PHPythia6 *pythia6 = new PHPythia6();
0187 pythia6->set_config_file("phpythia6.cfg");
0188 if (readhepmc)
0189 pythia6->set_reuse_vertex(0);
0190
0191 se->registerSubsystem(pythia6);
0192 }
0193
0194
0195 if (particles)
0196 {
0197
0198 PHG4SimpleEventGenerator *gen = new PHG4SimpleEventGenerator();
0199 gen->add_particles(22, 1);
0200
0201 if (readhepmc || do_embedding || runpythia8 || runpythia6)
0202 {
0203 gen->set_reuse_existing_vertex(true);
0204 gen->set_existing_vertex_offset_vector(0.0, 0.0, 0.0);
0205 }
0206 else
0207 {
0208 gen->set_vertex_distribution_function(PHG4SimpleEventGenerator::Uniform,
0209 PHG4SimpleEventGenerator::Uniform,
0210 PHG4SimpleEventGenerator::Uniform);
0211 gen->set_vertex_distribution_mean(0.0, 0.0, 0.0);
0212 gen->set_vertex_distribution_width(0.0, 0.0, 5.0);
0213 }
0214 gen->set_vertex_size_function(PHG4SimpleEventGenerator::Uniform);
0215 gen->set_vertex_size_parameters(0.0, 0.0);
0216 gen->set_eta_range(0.5, 0.7);
0217 gen->set_phi_range(0.2,0.4);
0218
0219 gen->set_p_range(photenergy, photenergy);
0220 if(doembedding)
0221 gen->Embed(1);
0222 gen->Verbosity(0);
0223
0224 se->registerSubsystem(gen);
0225 }
0226
0227 if (usegun)
0228 {
0229 PHG4ParticleGun *gun = new PHG4ParticleGun();
0230
0231 gun->set_name("geantino");
0232 gun->set_vtx(0, 0, 0);
0233 gun->set_mom(10, 0, 0.01);
0234
0235
0236
0237
0238
0239 PHG4ParticleGenerator *pgen = new PHG4ParticleGenerator();
0240 pgen->set_name("geantino");
0241 pgen->set_z_range(0, 0);
0242 pgen->set_eta_range(0.01, 0.01);
0243 pgen->set_mom_range(10, 10);
0244 pgen->set_phi_range(5.3 / 180. * TMath::Pi(), 5.7 / 180. * TMath::Pi());
0245 se->registerSubsystem(pgen);
0246 }
0247
0248
0249 if (upsilons)
0250 {
0251
0252
0253 PHG4ParticleGeneratorVectorMeson *vgen = new PHG4ParticleGeneratorVectorMeson();
0254 vgen->add_decay_particles("e+", "e-", 0);
0255
0256 if (readhepmc || do_embedding || particles || runpythia8 || runpythia6)
0257 {
0258 vgen->set_reuse_existing_vertex(true);
0259 }
0260 else
0261 {
0262 vgen->set_vtx_zrange(-10.0, +10.0);
0263 }
0264
0265
0266 vgen->set_rapidity_range(-1.0, +1.0);
0267 vgen->set_pt_range(0.0, 10.0);
0268
0269 int istate = 1;
0270
0271 if (istate == 1)
0272 {
0273
0274 vgen->set_mass(9.46);
0275 vgen->set_width(54.02e-6);
0276 }
0277 else if (istate == 2)
0278 {
0279
0280 vgen->set_mass(10.0233);
0281 vgen->set_width(31.98e-6);
0282 }
0283 else
0284 {
0285
0286 vgen->set_mass(10.3552);
0287 vgen->set_width(20.32e-6);
0288 }
0289
0290 vgen->Verbosity(0);
0291 vgen->Embed(3);
0292 se->registerSubsystem(vgen);
0293
0294 cout << "Upsilon generator for istate = " << istate << " created and registered " << endl;
0295 }
0296 }
0297
0298 if (!readhits)
0299 {
0300
0301
0302
0303
0304 G4Setup(absorberactive, magfield, TPythia6Decayer::kAll,
0305 do_svtx, do_pstof, do_cemc, do_hcalin, do_magnet, do_hcalout, do_pipe,do_plugdoor, magfield_rescale);
0306 }
0307
0308
0309
0310
0311
0312 if (do_bbc)
0313 {
0314 gROOT->LoadMacro("G4_Bbc.C");
0315 BbcInit();
0316 Bbc_Reco();
0317 }
0318
0319
0320
0321
0322 if (do_svtx_cell) Svtx_Cells();
0323
0324 if (do_cemc_cell) CEMC_Cells();
0325
0326 if (do_hcalin_cell) HCALInner_Cells();
0327
0328 if (do_hcalout_cell) HCALOuter_Cells();
0329
0330
0331
0332
0333
0334 if (do_cemc_twr) CEMC_Towers();
0335 if (do_cemc_cluster) CEMC_Clusters();
0336
0337
0338
0339
0340
0341 if (do_hcalin_twr) HCALInner_Towers();
0342 if (do_hcalin_cluster) HCALInner_Clusters();
0343
0344 if (do_hcalout_twr) HCALOuter_Towers();
0345 if (do_hcalout_cluster) HCALOuter_Clusters();
0346
0347 if (do_dst_compress) ShowerCompress();
0348
0349
0350
0351
0352
0353 if (do_svtx_track) Svtx_Reco();
0354
0355
0356
0357
0358
0359 if (do_global)
0360 {
0361 gROOT->LoadMacro("G4_Global.C");
0362 Global_Reco();
0363 }
0364
0365 else if (do_global_fastsim)
0366 {
0367 gROOT->LoadMacro("G4_Global.C");
0368 Global_FastSim();
0369 }
0370
0371
0372
0373
0374
0375 if (do_calotrigger)
0376 {
0377 gROOT->LoadMacro("G4_CaloTrigger.C");
0378 CaloTrigger_Sim();
0379 }
0380
0381
0382
0383
0384
0385 if (do_jet_reco)
0386 {
0387 gROOT->LoadMacro("G4_Jets.C");
0388 Jet_Reco();
0389 }
0390
0391 if (do_HIjetreco)
0392 {
0393 gROOT->LoadMacro("G4_HIJetReco.C");
0394 HIJetReco();
0395 }
0396
0397
0398
0399
0400
0401 if (do_svtx_eval) Svtx_Eval(string(outputFile) + "_g4svtx_eval.root");
0402
0403 if (do_cemc_eval) CEMC_Eval(string(outputFile) + "_g4cemc_eval.root");
0404
0405 if (do_hcalin_eval) HCALInner_Eval(string(outputFile) + "_g4hcalin_eval.root");
0406
0407 if (do_hcalout_eval) HCALOuter_Eval(string(outputFile) + "_g4hcalout_eval.root");
0408
0409 if (do_jet_eval) Jet_Eval(string(outputFile) + "_g4jet_eval.root");
0410
0411 gSystem->Load("libPhotons.so");
0412 Photons *photons = new Photons(outputFile);
0413 photons->Verbosity(0);
0414
0415 photons->set_cluspt_mincut(0.5);
0416 photons->set_eta_lowhigh(-1.05,1.05);
0417 if(doembedding)
0418 photons->use_embedding(1);
0419 if(!doembedding)
0420 photons->use_embedding(0);
0421 se->registerSubsystem(photons);
0422
0423
0424 gSystem->ListLibraries();
0425
0426
0427
0428
0429
0430
0431
0432 if (readhits)
0433 {
0434
0435 gSystem->Load("libg4dst.so");
0436
0437
0438 Fun4AllInputManager *hitsin = new Fun4AllDstInputManager("DSTin");
0439 hitsin->fileopen(inputFile);
0440 se->registerInputManager(hitsin);
0441 }
0442
0443 if (do_embedding)
0444 {
0445 if (embed_input_file == NULL)
0446 {
0447 cout << "Missing embed_input_file! Exit";
0448 exit(3);
0449 }
0450
0451
0452 gSystem->Load("libg4dst.so");
0453
0454 Fun4AllDstInputManager *in1 = new Fun4AllNoSyncDstInputManager("DSTinEmbed");
0455
0456 in1->AddListFile(embed_input_file);
0457 se->registerInputManager(in1);
0458 }
0459
0460 if (readhepmc)
0461 {
0462
0463 gSystem->Load("libg4dst.so");
0464
0465 Fun4AllHepMCInputManager *in = new Fun4AllHepMCInputManager("HepMCInput_1");
0466 se->registerInputManager(in);
0467 se->fileopen(in->Name().c_str(), inputFile);
0468
0469
0470
0471
0472
0473
0474
0475
0476
0477 }
0478 else
0479 {
0480
0481
0482 Fun4AllInputManager *in = new Fun4AllDummyInputManager("JADE");
0483 se->registerInputManager(in);
0484 }
0485
0486 if (pileup_collision_rate > 0)
0487 {
0488
0489
0490 Fun4AllHepMCPileupInputManager *pileup = new Fun4AllHepMCPileupInputManager("HepMCPileupInput");
0491 se->registerInputManager(pileup);
0492
0493 const string pileupfile("/sphenix/sim/sim01/sHijing/sHijing_0-12fm.dat");
0494 pileup->AddFile(pileupfile);
0495
0496
0497 pileup->set_collision_rate(pileup_collision_rate);
0498
0499 double time_window_minus = -35000;
0500 double time_window_plus = 35000;
0501
0502 if (do_svtx)
0503 {
0504
0505 time_window_minus = -105.5 / TPCDriftVelocity;
0506 time_window_plus = 105.5 / TPCDriftVelocity;
0507 }
0508 pileup->set_time_window(time_window_minus, time_window_plus);
0509 cout << "Collision pileup enabled using file " << pileupfile << " with collision rate " << pileup_collision_rate
0510 << " and time window " << time_window_minus << " to " << time_window_plus << endl;
0511 }
0512
0513 if (do_DSTReader)
0514 {
0515
0516 gROOT->LoadMacro("G4_DSTReader.C");
0517
0518 G4DSTreader(outputFile,
0519 absorberactive,
0520 do_svtx,
0521 do_pstof,
0522 do_cemc,
0523 do_hcalin,
0524 do_magnet,
0525 do_hcalout,
0526 do_cemc_twr,
0527 do_hcalin_twr,
0528 do_magnet,
0529 do_hcalout_twr);
0530 }
0531
0532
0533
0534
0535
0536
0537
0538
0539 if (nEvents < 0)
0540 {
0541 return;
0542 }
0543
0544 if (nEvents == 0 && !readhits && !readhepmc)
0545 {
0546 cout << "using 0 for number of events is a bad idea when using particle generators" << endl;
0547 cout << "it will run forever, so I just return without running anything" << endl;
0548 return;
0549 }
0550
0551 se->run(nEvents);
0552
0553
0554
0555
0556
0557 se->End();
0558 std::cout << "All done" << std::endl;
0559 delete se;
0560 gSystem->Exit(0);
0561 }