File indexing completed on 2025-08-05 08:12:47
0001
0002 int Fun4All_G4_sPHENIX(
0003 const int nEvents = 10000,
0004 const char * inputFile = "/sphenix/sim//sim01/production/2016-07-21/single_particle/spacal2d/fieldmap/G4Hits_sPHENIX_e-_eta0_8GeV-0002.root",
0005 const char * outputFile = "G4sPHENIXCells.root",
0006 const char * embed_input_file = "/sphenix/sim/sim01/production/2016-07-12/sHijing/spacal2d/G4Hits_sPHENIX_sHijing-0-4.4fm.list"
0007 )
0008 {
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 const bool readhits = false;
0022
0023
0024 const bool readhepmc = false;
0025
0026
0027 const bool runpythia8 = true;
0028 const bool runpythia6 = false;
0029
0030
0031
0032
0033 const bool do_embedding = false;
0034
0035
0036
0037
0038
0039 bool do_bbc = false;
0040
0041 bool do_pipe = false;
0042
0043 bool do_svtx = false;
0044 bool do_svtx_cell = false;
0045 bool do_svtx_track = false;
0046 bool do_svtx_eval = false;
0047
0048 bool do_preshower = false;
0049
0050 bool do_cemc = false;
0051 bool do_cemc_cell = false;
0052 bool do_cemc_twr = false;
0053 bool do_cemc_cluster = false;
0054 bool do_cemc_eval = false;
0055
0056 bool do_hcalin = false;
0057 bool do_hcalin_cell = false;
0058 bool do_hcalin_twr = false;
0059 bool do_hcalin_cluster = false;
0060 bool do_hcalin_eval = false;
0061
0062 bool do_magnet = false;
0063
0064 bool do_hcalout = false;
0065 bool do_hcalout_cell = false;
0066 bool do_hcalout_twr = false;
0067 bool do_hcalout_cluster = false;
0068 bool do_hcalout_eval = false;
0069
0070 bool do_global = false;
0071 bool do_global_fastsim = false;
0072
0073 bool do_jet_reco = true;
0074 bool do_jet_eval = false;
0075
0076 bool do_dst_compress = false;
0077
0078
0079 bool do_DSTReader = true;
0080
0081
0082
0083
0084 gSystem->Load("libfun4all.so");
0085 gSystem->Load("libg4detectors.so");
0086 gSystem->Load("libphhepmc.so");
0087 gSystem->Load("libg4testbench.so");
0088 gSystem->Load("libg4hough.so");
0089 gSystem->Load("libg4calo.so");
0090 gSystem->Load("libg4eval.so");
0091
0092
0093 gROOT->LoadMacro("G4Setup_sPHENIX.C");
0094 G4Init(do_svtx,do_preshower,do_cemc,do_hcalin,do_magnet,do_hcalout,do_pipe);
0095
0096 int absorberactive = 1;
0097 const string magfield = "0";
0098
0099 const float magfield_rescale = 1.4/1.5;
0100
0101
0102
0103
0104
0105 Fun4AllServer *se = Fun4AllServer::instance();
0106 se->Verbosity(1);
0107
0108 recoConsts *rc = recoConsts::instance();
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123 if (readhits)
0124 {
0125
0126
0127
0128 if (do_embedding)
0129 {
0130 cout <<"Do not support read hits and embed background at the same time."<<endl;
0131 exit(1);
0132 }
0133
0134 }
0135 else if (readhepmc)
0136 {
0137
0138
0139 HepMCNodeReader *hr = new HepMCNodeReader();
0140 se->registerSubsystem(hr);
0141 }
0142 else if (runpythia8)
0143 {
0144 gSystem->Load("libPHPythia8.so");
0145
0146
0147 PHPy8JetTrigger *theTrigger = new PHPy8JetTrigger();
0148
0149 theTrigger->SetEtaHighLow(-1, 1);
0150 theTrigger->SetJetR(.4);
0151 theTrigger->SetMinJetPt(25);
0152
0153 PHPythia8* pythia8 = new PHPythia8();
0154
0155 pythia8->set_config_file("phpythia8.cfg");
0156
0157 pythia8->beam_vertex_parameters(0,0,0,0,0,5);
0158 pythia8->register_trigger(theTrigger);
0159
0160
0161 se->registerSubsystem(pythia8);
0162 pythia8->print_config();
0163
0164
0165 HepMCNodeReader *hr = new HepMCNodeReader();
0166 se->registerSubsystem(hr);
0167 }
0168 else if (runpythia6)
0169 {
0170 gSystem->Load("libPHPythia6.so");
0171
0172 PHPythia6 *pythia6 = new PHPythia6();
0173 pythia6->set_config_file("phpythia6.cfg");
0174 se->registerSubsystem(pythia6);
0175
0176 HepMCNodeReader *hr = new HepMCNodeReader();
0177 se->registerSubsystem(hr);
0178 }
0179 else
0180 {
0181
0182 PHG4SimpleEventGenerator *gen = new PHG4SimpleEventGenerator();
0183 gen->add_particles("e-",1);
0184
0185 if (readhepmc || do_embedding) {
0186 gen->set_reuse_existing_vertex(true);
0187 gen->set_existing_vertex_offset_vector(0.0,0.0,0.0);
0188 } else {
0189 gen->set_vertex_distribution_function(PHG4SimpleEventGenerator::Uniform,
0190 PHG4SimpleEventGenerator::Uniform,
0191 PHG4SimpleEventGenerator::Uniform);
0192 gen->set_vertex_distribution_mean(0.0,0.0,0.0);
0193 gen->set_vertex_distribution_width(0.0,0.0,5.0);
0194 }
0195 gen->set_vertex_size_function(PHG4SimpleEventGenerator::Uniform);
0196 gen->set_vertex_size_parameters(10.0,0.0);
0197 gen->set_eta_range(-0.1, 0.1);
0198 gen->set_phi_range(-1.0*TMath::Pi(), 1.0*TMath::Pi());
0199 gen->set_pt_range(24, 24);
0200 gen->Embed(1);
0201 gen->Verbosity(0);
0202 se->registerSubsystem(gen);
0203 }
0204
0205 if (!readhits)
0206 {
0207
0208
0209
0210
0211 G4Setup(absorberactive, magfield, TPythia6Decayer::kAll,
0212 do_svtx, do_preshower, do_cemc, do_hcalin, do_magnet, do_hcalout, do_pipe, magfield_rescale);
0213 }
0214
0215
0216
0217
0218
0219 if (do_bbc)
0220 {
0221 gROOT->LoadMacro("G4_Bbc.C");
0222 BbcInit();
0223 Bbc_Reco();
0224 }
0225
0226
0227
0228
0229 if (do_svtx_cell) Svtx_Cells();
0230
0231 if (do_cemc_cell) CEMC_Cells();
0232
0233 if (do_hcalin_cell) HCALInner_Cells();
0234
0235 if (do_hcalout_cell) HCALOuter_Cells();
0236
0237
0238
0239
0240
0241 if (do_cemc_twr) CEMC_Towers();
0242 if (do_cemc_cluster) CEMC_Clusters();
0243
0244
0245
0246
0247
0248 if (do_hcalin_twr) HCALInner_Towers();
0249 if (do_hcalin_cluster) HCALInner_Clusters();
0250
0251 if (do_hcalout_twr) HCALOuter_Towers();
0252 if (do_hcalout_cluster) HCALOuter_Clusters();
0253
0254 if (do_dst_compress) ShowerCompress();
0255
0256
0257
0258
0259
0260 if (do_svtx_track) Svtx_Reco();
0261
0262
0263
0264
0265
0266 if (do_global)
0267 {
0268 gROOT->LoadMacro("G4_Global.C");
0269 Global_Reco();
0270 }
0271
0272 else if (do_global_fastsim)
0273 {
0274 gROOT->LoadMacro("G4_Global.C");
0275 Global_FastSim();
0276 }
0277
0278
0279
0280
0281
0282 if (do_jet_reco)
0283 {
0284 gROOT->LoadMacro("G4_Jets.C");
0285 Jet_Reco();
0286 }
0287
0288
0289
0290
0291 if (do_svtx_eval) Svtx_Eval("g4svtx_eval.root");
0292
0293 if (do_cemc_eval) CEMC_Eval("g4cemc_eval.root");
0294
0295 if (do_hcalin_eval) HCALInner_Eval("g4hcalin_eval.root");
0296
0297 if (do_hcalout_eval) HCALOuter_Eval("g4hcalout_eval.root");
0298
0299 if (do_jet_eval) Jet_Eval("g4jet_eval.root");
0300
0301
0302
0303
0304
0305
0306
0307 if (readhits)
0308 {
0309
0310 Fun4AllInputManager *hitsin = new Fun4AllDstInputManager("DSTin");
0311 hitsin->fileopen(inputFile);
0312 se->registerInputManager(hitsin);
0313 }
0314 if (do_embedding)
0315 {
0316 if (embed_input_file == NULL)
0317 {
0318 cout << "Missing embed_input_file! Exit";
0319 exit(3);
0320 }
0321
0322 Fun4AllDstInputManager *in1 = new Fun4AllNoSyncDstInputManager("DSTinEmbed");
0323
0324 in1->AddListFile(embed_input_file);
0325 se->registerInputManager(in1);
0326 }
0327 if (readhepmc)
0328 {
0329 Fun4AllInputManager *in = new Fun4AllHepMCInputManager( "DSTIN");
0330 se->registerInputManager( in );
0331 se->fileopen( in->Name().c_str(), inputFile );
0332 }
0333 else
0334 {
0335
0336
0337 Fun4AllInputManager *in = new Fun4AllDummyInputManager( "JADE");
0338 se->registerInputManager( in );
0339 }
0340
0341
0342 {
0343
0344 gSystem->Load("libqa_modules");
0345
0346 if (do_jet_reco)
0347 {
0348 QAG4SimulationJet * calo_jet7 = new QAG4SimulationJet(
0349 "AntiKt_Truth_r07",QAG4SimulationJet:: kProcessTruthSpectrum);
0350 se->registerSubsystem(calo_jet7);
0351
0352 QAG4SimulationJet * calo_jet7 = new QAG4SimulationJet(
0353 "AntiKt_Truth_r04", QAG4SimulationJet::kProcessTruthSpectrum);
0354 se->registerSubsystem(calo_jet7);
0355
0356 QAG4SimulationJet * calo_jet7 = new QAG4SimulationJet(
0357 "AntiKt_Truth_r02",QAG4SimulationJet:: kProcessTruthSpectrum);
0358 se->registerSubsystem(calo_jet7);
0359 }
0360 }
0361
0362
0363 assert (gSystem->Load("libHFJetTruthGeneration") == 0);
0364 {
0365 if (do_jet_reco)
0366 {
0367 HFJetTruthTrigger * jt = new HFJetTruthTrigger(
0368 "HFJetTruthTrigger.root",5 , "AntiKt_Truth_r07");
0369
0370 se->registerSubsystem(jt);
0371
0372 HFJetTruthTrigger * jt = new HFJetTruthTrigger(
0373 "HFJetTruthTrigger.root",5 , "AntiKt_Truth_r04");
0374
0375 se->registerSubsystem(jt);
0376
0377 HFJetTruthTrigger * jt = new HFJetTruthTrigger(
0378 "HFJetTruthTrigger.root",5 , "AntiKt_Truth_r02");
0379
0380 se->registerSubsystem(jt);
0381 }
0382 }
0383
0384
0385 if (gSystem->Load("libslt") == 0)
0386 {
0387
0388
0389 if (do_jet_reco)
0390 {
0391 SoftLeptonTaggingTruth * slt = new SoftLeptonTaggingTruth(
0392 "AntiKt_Truth_r07");
0393 se->registerSubsystem(slt);
0394
0395 SoftLeptonTaggingTruth * slt = new SoftLeptonTaggingTruth(
0396 "AntiKt_Truth_r04");
0397
0398 se->registerSubsystem(slt);
0399
0400 SoftLeptonTaggingTruth * slt = new SoftLeptonTaggingTruth(
0401 "AntiKt_Truth_r02");
0402 se->registerSubsystem(slt);
0403 }
0404 }
0405
0406
0407 if (do_DSTReader)
0408 {
0409
0410 gROOT->LoadMacro("G4_DSTReader.C");
0411
0412 G4DSTreader( outputFile,
0413 absorberactive ,
0414 do_svtx ,
0415 do_preshower ,
0416 do_cemc ,
0417 do_hcalin ,
0418 do_magnet ,
0419 do_hcalout ,
0420 do_cemc_twr ,
0421 do_hcalin_twr ,
0422 do_magnet ,
0423 do_hcalout_twr
0424 );
0425 }
0426
0427
0428 Fun4AllDstOutputManager *out = new Fun4AllDstOutputManager("DSTOUT", outputFile);
0429 if (do_dst_compress) DstCompress(out);
0430 se->registerOutputManager(out);
0431
0432
0433
0434
0435 if (nEvents < 0)
0436 {
0437 return;
0438 }
0439
0440 if (nEvents == 0 && !readhits && !readhepmc)
0441 {
0442 cout << "using 0 for number of events is a bad idea when using particle generators" << endl;
0443 cout << "it will run forever, so I just return without running anything" << endl;
0444 return;
0445 }
0446
0447 se->run(nEvents);
0448
0449 {
0450
0451 gSystem->Load("libqa_modules");
0452 QAHistManagerDef::saveQARootFile(string(outputFile) + "_qa.root");
0453
0454 if (gSystem->Load("libslt") == 0)
0455 {
0456 SoftLeptonTaggingTruth::getHistoManager()->dumpHistos(
0457 string(outputFile) + "_slt.root");
0458 }
0459 }
0460
0461
0462
0463
0464 gSystem->Exec("ps -o sid,ppid,pid,user,comm,vsize,rssize,time");
0465 se->End();
0466 std::cout << "All done" << std::endl;
0467 delete se;
0468 gSystem->Exit(0);
0469 }