Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:22:09

0001 #ifndef FUN4ALL_G4_MOMENTUM_C
0002 #define FUN4ALL_G4_MOMENTUM_C
0003 
0004 #include <g4detectors/PHG4CylinderSubsystem.h>
0005 
0006 #include <g4trackfastsim/PHG4TrackFastSim.h>
0007 #include <g4trackfastsim/PHG4TrackFastSimEval.h>
0008 
0009 #include <g4main/PHG4ParticleGenerator.h>
0010 #include <g4main/PHG4Reco.h>
0011 #include <g4main/PHG4TruthSubsystem.h>
0012 
0013 #include <fun4all/Fun4AllDstOutputManager.h>
0014 #include <fun4all/Fun4AllDummyInputManager.h>
0015 #include <fun4all/Fun4AllInputManager.h>
0016 #include <fun4all/Fun4AllOutputManager.h>
0017 #include <fun4all/Fun4AllServer.h>
0018 #include <fun4all/SubsysReco.h>
0019 
0020 #include <phool/recoConsts.h>
0021 
0022 #include <cmath>
0023 
0024 R__LOAD_LIBRARY(libfun4all.so)
0025 R__LOAD_LIBRARY(libg4testbench.so)
0026 R__LOAD_LIBRARY(libg4detectors.so)
0027 R__LOAD_LIBRARY(libg4trackfastsim.so)
0028 
0029 int Fun4All_G4_Momentum(const int nEvents = 1000, const string &evalfile = "FastTrackingEval.root", const string &outfile = "")
0030 {
0031   ///////////////////////////////////////////
0032   // Make the Server
0033   //////////////////////////////////////////
0034   Fun4AllServer *se = Fun4AllServer::instance();
0035   se->Verbosity(0);
0036 
0037   recoConsts *rc = recoConsts::instance();
0038   // if you want to use a fixed seed for reproducible results
0039   //  rc->set_IntFlag("RANDOMSEED", 12345);
0040 
0041   // PHG4ParticleGenerator generates particle
0042   // distributions in eta/phi/mom range
0043   PHG4ParticleGenerator *gen = new PHG4ParticleGenerator("PGENERATOR");
0044   gen->set_name("pi-");
0045   gen->set_vtx(0, 0, 0);
0046   gen->set_eta_range(-0.05, 0.05);            // around midrapidity
0047   gen->set_mom_range(4, 4);                   // fixed 4 GeV/c
0048   gen->set_phi_range(0., 90. / 180. * M_PI);  // 0-90 deg
0049   se->registerSubsystem(gen);
0050 
0051   PHG4Reco *g4Reco = new PHG4Reco();
0052   g4Reco->set_field(1.5);  // 1.5 T constant solenoidal field
0053 
0054   double si_thickness[6] = {0.02, 0.02, 0.0625, 0.032, 0.032, 0.032};
0055   double svxrad[6] = {2.71, 4.63, 11.765, 25.46, 41.38, 63.66};
0056   double length[6] = {20., 20., 36., -1., -1., -1.};  // -1 use eta coverage to determine length
0057   PHG4CylinderSubsystem *cyl;
0058   // here is our silicon:
0059   for (int ilayer = 0; ilayer < 6; ilayer++)
0060   {
0061     cyl = new PHG4CylinderSubsystem("SVTX", ilayer);
0062     cyl->set_double_param("radius", svxrad[ilayer]);
0063     cyl->set_string_param("material", "G4_Si");  // Silicon (G4 definition)
0064     cyl->set_double_param("thickness", si_thickness[ilayer]);
0065     cyl->SetActive();
0066     cyl->SuperDetector("SVTX");
0067     if (length[ilayer] > 0)
0068     {
0069       cyl->set_double_param("length", length[ilayer]);
0070     }
0071     g4Reco->registerSubsystem(cyl);
0072   }
0073 
0074   // Black hole swallows everything - prevent loopers from returning
0075   // to inner detectors, length is given by default eta = +-1.1 range
0076   cyl = new PHG4CylinderSubsystem("BlackHole", 0);
0077   cyl->set_double_param("radius", 80);      // 80 cm - everything stops here
0078   cyl->set_double_param("thickness", 0.1);  // does not matter (but > 0)
0079   cyl->SetActive();
0080   cyl->BlackHole();  // eats everything
0081   g4Reco->registerSubsystem(cyl);
0082 
0083   PHG4TruthSubsystem *truth = new PHG4TruthSubsystem();
0084   g4Reco->registerSubsystem(truth);
0085 
0086   se->registerSubsystem(g4Reco);
0087 
0088   //---------------------------
0089   // fast pattern recognition and full Kalman filter
0090   // output evaluation file for truth track and reco tracks are PHG4TruthInfoContainer
0091   //---------------------------
0092   PHG4TrackFastSim *kalman = new PHG4TrackFastSim("PHG4TrackFastSim");
0093   kalman->set_use_vertex_in_fitting(false);
0094   kalman->set_sub_top_node_name("SVTX");
0095   kalman->set_trackmap_out_name("SvtxTrackMap");
0096 
0097   //  add Si Trtacker
0098   kalman->add_phg4hits(
0099       "G4HIT_SVTX",                //      const std::string& phg4hitsNames,
0100       PHG4TrackFastSim::Cylinder,  //      const DETECTOR_TYPE phg4dettype,
0101       300e-4,                      //       radial-resolution [cm]
0102       30e-4,                       //        azimuthal-resolution [cm]
0103       1,                           //      z-resolution [cm]
0104       1,                           //      efficiency,
0105       0                            //      noise hits
0106   );
0107 
0108   se->registerSubsystem(kalman);
0109 
0110   PHG4TrackFastSimEval *fast_sim_eval = new PHG4TrackFastSimEval("FastTrackingEval");
0111   fast_sim_eval->set_filename(evalfile);
0112   se->registerSubsystem(fast_sim_eval);
0113   //---------------------------
0114 
0115   //---------------------------
0116   // output DST file for further offline analysis
0117   //---------------------------
0118   if (!outfile.empty())
0119   {
0120     Fun4AllOutputManager *out = new Fun4AllDstOutputManager("DSTOUT", outfile);
0121     se->registerOutputManager(out);
0122   }
0123   Fun4AllInputManager *in = new Fun4AllDummyInputManager("JADE");
0124   se->registerInputManager(in);
0125 
0126   if (nEvents > 0)
0127   {
0128     se->run(nEvents);
0129     // finish job - close and save output files
0130     se->End();
0131     std::cout << "All done" << std::endl;
0132 
0133     // cleanup - delete the server and exit
0134     delete se;
0135     gSystem->Exit(0);
0136   }
0137   return 0;
0138 }
0139 
0140 PHG4ParticleGenerator *get_gen(const char *name = "PGENERATOR")
0141 {
0142   Fun4AllServer *se = Fun4AllServer::instance();
0143   PHG4ParticleGenerator *pgun = (PHG4ParticleGenerator *) se->getSubsysReco(name);
0144   return pgun;
0145 }
0146 
0147 #endif