Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:12:04

0001 int Fun4All_EICAnalysis_DVCS(
0002              const int nEvents = 10,
0003              const char * inputFile = "example_tesst.dat",
0004              const char * outputFile = "G4sPHENIXCells.root",
0005              const char * embed_input_file = "/sphenix/sim/sim01/production/2016-07-12/sHijing/spacal2d/G4Hits_sPHENIX_sHijing-0-4.4fm.list"
0006                )
0007 {
0008   //===============
0009   // Input options
0010   //===============
0011 
0012   // Either:
0013   // read previously generated g4-hits files, in this case it opens a DST and skips
0014   // the simulations step completely. The G4Setup macro is only loaded to get information
0015   // about the number of layers used for the cell reco code
0016   //
0017   // In case reading production output, please double check your G4Setup_sPHENIX.C and G4_*.C consistent with those in the production macro folder
0018   // E.g. /sphenix/sim//sim01/production/2016-07-21/single_particle/spacal2d/
0019   const bool readhits = false;
0020   // Or:
0021   // read files in HepMC format (typically output from event generators like hijing or pythia)
0022   const bool readhepmc = false; // read HepMC files
0023   // Or:
0024   // Use pythia
0025   const bool runpythia8 = false;
0026   const bool runpythia6 = false;
0027   const bool runhepgen = true;
0028   // else
0029   // Use particle generator (default simple generator)
0030   // or gun/ very simple generator
0031   const bool usegun = false;
0032 
0033   const bool readeictree = false;
0034 
0035   gSystem->Load("libfun4all.so");
0036   //  gSystem->Load("libg4detectors.so");
0037   gSystem->Load("libphhepmc.so");
0038   gSystem->Load("libg4testbench.so");
0039   gSystem->Load("libg4hough.so");
0040   //  gSystem->Load("libg4eval.so");
0041   gSystem->Load("libeicana.so");
0042 
0043   // establish the geometry and reconstruction setup
0044   //  gROOT->LoadMacro("G4Setup_sPHENIX.C");
0045   //  G4Init(do_svtx,do_preshower,do_cemc,do_hcalin,do_magnet,do_hcalout,do_pipe);
0046 
0047   //  int absorberactive = 1; // set to 1 to make all absorbers active volumes
0048   //  const string magfield = "1.5"; // if like float -> solenoidal field in T, if string use as fieldmap name (including path)
0049   const string magfield = "/phenix/upgrades/decadal/fieldmaps/sPHENIX.2d.root"; // if like float -> solenoidal field in T, if string use as fieldmap name (including path)
0050   const float magfield_rescale = 1.4/1.5; // scale the map to a 1.4 T field
0051 
0052   //---------------
0053   // Fun4All server
0054   //---------------
0055 
0056   Fun4AllServer *se = Fun4AllServer::instance();
0057   se->Verbosity(0);
0058   // just if we set some flags somewhere in this macro
0059   //  recoConsts *rc = recoConsts::instance();
0060   // By default every random number generator uses
0061   // PHRandomSeed() which reads /dev/urandom to get its seed
0062   // if the RANDOMSEED flag is set its value is taken as seed
0063   // You ca neither set this to a random value using PHRandomSeed()
0064   // which will make all seeds identical (not sure what the point of
0065   // this would be:
0066   //  rc->set_IntFlag("RANDOMSEED",PHRandomSeed());
0067   // or set it to a fixed value so you can debug your code
0068   //  rc->set_IntFlag("RANDOMSEED", 12345);
0069 
0070   //-----------------
0071   // Event generation
0072   //-----------------
0073 
0074   if (readhits)
0075     {
0076       // Get the hits from a file
0077       // The input manager is declared later
0078     }
0079   else if (readhepmc)
0080     {
0081       // this module is needed to read the HepMC records into our G4 sims
0082       // but only if you read HepMC input files
0083       HepMCNodeReader *hr = new HepMCNodeReader();
0084       se->registerSubsystem(hr);
0085     }
0086   /* Read EICTree files */
0087   else if (readeictree)
0088     {
0089       // this module is needed to read the EICTree style records into our G4 sims
0090       ReadEICFiles *eicr = new ReadEICFiles();
0091       eicr->OpenInputFile(inputFile);
0092 
0093       se->registerSubsystem(eicr);
0094 
0095       HepMCNodeReader *hr = new HepMCNodeReader();
0096       se->registerSubsystem(hr);
0097 
0098     }
0099   else if (runpythia8)
0100     {
0101       gSystem->Load("libPHPythia8.so");
0102       
0103       PHPythia8* pythia8 = new PHPythia8();
0104       // see coresoftware/generators/PHPythia8 for example config
0105       pythia8->set_config_file("phpythia8.cfg"); 
0106       se->registerSubsystem(pythia8);
0107 
0108       HepMCNodeReader *hr = new HepMCNodeReader();
0109       se->registerSubsystem(hr);
0110     }
0111   else if (runpythia6)
0112     {
0113       gSystem->Load("libPHPythia6.so");
0114 
0115       PHPythia6 *pythia6 = new PHPythia6();
0116       pythia6->set_config_file("phpythia6.cfg");
0117       se->registerSubsystem(pythia6);
0118 
0119       HepMCNodeReader *hr = new HepMCNodeReader();
0120       se->registerSubsystem(hr);
0121     }
0122   else if (runhepgen)
0123     {
0124       gSystem->Load("libsHEPGen.so");
0125 
0126       sHEPGen *hepgen = new sHEPGen();
0127       hepgen->set_datacard_file("hepgen_dvcs.data");
0128       hepgen->set_momentum_electron(20);
0129       hepgen->set_momentum_hadron(250);
0130       se->registerSubsystem(hepgen);
0131 
0132       //      HepMCNodeReader *hr = new HepMCNodeReader();
0133       //      se->registerSubsystem(hr);
0134     }
0135   else
0136     {
0137       // toss low multiplicity dummy events
0138       PHG4SimpleEventGenerator *gen = new PHG4SimpleEventGenerator();
0139       gen->add_particles("e-",1); // mu+,e+,proton,pi+,Upsilon
0140       // gen->add_particles("e+",5); // mu-,e-,anti_proton,pi-
0141       if (readhepmc)
0142     {
0143       gen->set_reuse_existing_vertex(true);
0144       gen->set_existing_vertex_offset_vector(0.0, 0.0, 0.0);
0145     }
0146       else
0147     {
0148       gen->set_vertex_distribution_function(PHG4SimpleEventGenerator::Uniform,
0149                         PHG4SimpleEventGenerator::Uniform,
0150                         PHG4SimpleEventGenerator::Uniform);
0151       gen->set_vertex_distribution_mean(0.0, 0.0, 0.0);
0152       gen->set_vertex_distribution_width(0.0, 0.0, 5.0);
0153     }
0154       gen->set_vertex_size_function(PHG4SimpleEventGenerator::Uniform);
0155       gen->set_vertex_size_parameters(0.0, 0.0);
0156       gen->set_eta_range(-0.5, 0.5);
0157       gen->set_phi_range(-1.0 * TMath::Pi(), 1.0 * TMath::Pi());
0158       gen->set_pt_range(0.1, 10.0);
0159       gen->Embed(1);
0160       gen->Verbosity(0);
0161       if (! usegun)
0162     {
0163       se->registerSubsystem(gen);
0164     }
0165       else
0166     {
0167       PHG4ParticleGun *gun = new PHG4ParticleGun();
0168       //  gun->set_name("anti_proton");
0169       gun->set_name("geantino");
0170       gun->set_vtx(0, 0, 0);
0171       gun->set_mom(10, 0, 0.01);
0172       // gun->AddParticle("geantino",1.7776,-0.4335,0.);
0173       // gun->AddParticle("geantino",1.7709,-0.4598,0.);
0174       // gun->AddParticle("geantino",2.5621,0.60964,0.);
0175       // gun->AddParticle("geantino",1.8121,0.253,0.);
0176       //      se->registerSubsystem(gun);
0177       PHG4ParticleGenerator *pgen = new PHG4ParticleGenerator();
0178           pgen->set_name("geantino");
0179       pgen->set_z_range(0,0);
0180       pgen->set_eta_range(0.01,0.01);
0181       pgen->set_mom_range(10,10);
0182       pgen->set_phi_range(5.3./180.*TMath::Pi(),5.7./180.*TMath::Pi());
0183       se->registerSubsystem(pgen);
0184       pgen = new PHG4ParticleGenerator();
0185           pgen->set_name("geantino");
0186       pgen->set_z_range(0,0);
0187       pgen->set_eta_range(0.01,0.01);
0188       pgen->set_mom_range(10,10);
0189       pgen->set_phi_range(-0.2./180.*TMath::Pi(),0.2./180.*TMath::Pi());
0190       se->registerSubsystem(pgen);
0191     }
0192     }
0193 
0194 
0195   if (readhits)
0196     {
0197       // Hits file
0198       Fun4AllInputManager *hitsin = new Fun4AllDstInputManager("DSTin");
0199       hitsin->fileopen(inputFile);
0200       se->registerInputManager(hitsin);
0201     }
0202   if (readhepmc)
0203     {
0204       Fun4AllInputManager *in = new Fun4AllHepMCInputManager( "DSTIN");
0205       se->registerInputManager( in );
0206       se->fileopen( in->Name().c_str(), inputFile );
0207     }
0208   else
0209     {
0210       // for single particle generators we just need something which drives
0211       // the event loop, the Dummy Input Mgr does just that
0212       //      Fun4AllInputManager *in = new Fun4AllDummyInputManager( "JADE");
0213       //      se->registerInputManager( in );
0214     }
0215 
0216 
0217   //--------------
0218   // Analysis modules
0219   //--------------
0220   DISKinematics *mcana = new DISKinematics(outputFile);
0221   se->registerSubsystem( mcana );
0222 
0223 
0224   //-----------------
0225   // Event processing
0226   //-----------------
0227   if (nEvents < 0)
0228     {
0229       return;
0230     }
0231   // if we run the particle generator and use 0 it'll run forever
0232   if (nEvents == 0 && !readhits && !readhepmc)
0233     {
0234       cout << "using 0 for number of events is a bad idea when using particle generators" << endl;
0235       cout << "it will run forever, so I just return without running anything" << endl;
0236       return;
0237     }
0238 
0239   se->run(nEvents);
0240 
0241   //-----
0242   // Exit
0243   //-----
0244 
0245   se->End();
0246   std::cout << "All done" << std::endl;
0247   delete se;
0248   gSystem->Exit(0);
0249 }