Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:20:28

0001 #ifndef MACRO_G4SETUPSPHENIX_C
0002 #define MACRO_G4SETUPSPHENIX_C
0003 
0004 #include <GlobalVariables.C>
0005 
0006 #include <G4_BeamLine.C>
0007 #include <G4_BlackHole.C>
0008 #include <G4_CEmc_Albedo.C>
0009 #include <G4_CEmc_Spacal.C>
0010 #include <G4_EPD.C>
0011 #include <G4_HcalIn_ref.C>
0012 #include <G4_HcalOut_ref.C>
0013 #include <G4_Magnet.C>
0014 #include <G4_Mbd.C>
0015 #include <G4_PSTOF.C>
0016 #include <G4_Pipe.C>
0017 #include <G4_PlugDoor.C>
0018 #include <G4_TrkrSimulation.C>
0019 #include <G4_User.C>
0020 #include <G4_World.C>
0021 #include <G4_ZDC.C>
0022 
0023 #include <g4detectors/PHG4CylinderSubsystem.h>
0024 
0025 #include <g4eval/PHG4DstCompressReco.h>
0026 
0027 #include <g4main/PHG4Reco.h>
0028 #include <g4main/PHG4TruthSubsystem.h>
0029 
0030 #include <phfield/PHFieldConfig.h>
0031 
0032 #include <g4decayer/EDecayType.hh>
0033 
0034 #include <fun4all/Fun4AllDstOutputManager.h>
0035 #include <fun4all/Fun4AllServer.h>
0036 
0037 R__LOAD_LIBRARY(libg4decayer.so)
0038 R__LOAD_LIBRARY(libg4detectors.so)
0039 
0040 void G4Init()
0041 {
0042   // Check on invalid combinations
0043   if (Enable::CEMC && Enable::CEMCALBEDO)
0044   {
0045     cout << "Enable::CEMCALBEDO and Enable::CEMC cannot be set simultanously" << endl;
0046     gSystem->Exit(1);
0047   }
0048   // load detector/material macros and execute Init() function
0049 
0050   if (Enable::PIPE) PipeInit();
0051   if (Enable::MVTX) MvtxInit();
0052   if (Enable::INTT) InttInit();
0053   if (Enable::TPC) TPCInit();
0054   if (Enable::MICROMEGAS) MicromegasInit();
0055   if (Enable::MBD) MbdInit();
0056   if (Enable::CEMCALBEDO) CEmcAlbedoInit();
0057   if (Enable::CEMC) CEmcInit();
0058   if (Enable::HCALIN) HCalInnerInit();
0059   if (Enable::MAGNET) MagnetInit();
0060   MagnetFieldInit();  // We want the field - even if the magnet volume is disabled
0061   if (Enable::HCALOUT) HCalOuterInit();
0062   if (Enable::PLUGDOOR) PlugDoorInit();
0063   if (Enable::EPD) EPDInit();
0064   if (Enable::BEAMLINE)
0065   {
0066     BeamLineInit();
0067     if (Enable::ZDC)
0068     {
0069       ZDCInit();
0070     }
0071   }
0072   if (Enable::USER) UserInit();
0073   if (Enable::BLACKHOLE) BlackHoleInit();
0074 }
0075 
0076 int G4Setup()
0077 {
0078   //---------------
0079   // Fun4All server
0080   //---------------
0081 
0082   Fun4AllServer *se = Fun4AllServer::instance();
0083 
0084   PHG4Reco *g4Reco = new PHG4Reco();
0085   g4Reco->set_rapidity_coverage(1.1);  // according to drawings
0086   WorldInit(g4Reco);
0087   // PYTHIA 6
0088   if (G4P6DECAYER::decayType != EDecayType::kAll)
0089   {
0090     g4Reco->set_force_decay(G4P6DECAYER::decayType);
0091   }
0092   // EvtGen
0093   g4Reco->CustomizeEvtGenDecay(EVTGENDECAYER::DecayFile);
0094 
0095   double fieldstrength;
0096   istringstream stringline(G4MAGNET::magfield);
0097   stringline >> fieldstrength;
0098   if (stringline.fail())
0099   {  // conversion to double fails -> we have a string
0100 
0101     if (G4MAGNET::magfield.find("sphenix3dbigmapxyz") != string::npos ||
0102         G4MAGNET::magfield == "CDB")
0103     {
0104       g4Reco->set_field_map(G4MAGNET::magfield, PHFieldConfig::Field3DCartesian);
0105     }
0106     else
0107     {
0108       g4Reco->set_field_map(G4MAGNET::magfield, PHFieldConfig::kField2D);
0109     }
0110   }
0111   else
0112   {
0113     g4Reco->set_field(fieldstrength);  // use const soleniodal field
0114   }
0115   g4Reco->set_field_rescale(G4MAGNET::magfield_rescale);
0116 
0117   // the radius is an older protection against overlaps, it is not
0118   // clear how well this works nowadays but it doesn't hurt either
0119   double radius = 0.;
0120 
0121   if (Enable::PIPE) radius = Pipe(g4Reco, radius);
0122   if (Enable::MVTX) radius = Mvtx(g4Reco, radius);
0123   if (Enable::INTT) radius = Intt(g4Reco, radius);
0124   if (Enable::TPC) radius = TPC(g4Reco, radius);
0125   if (Enable::MICROMEGAS) Micromegas(g4Reco);
0126   if (Enable::MBD) Mbd(g4Reco);
0127   if (Enable::CEMCALBEDO) CEmcAlbedo(g4Reco);
0128   if (Enable::CEMC) radius = CEmc(g4Reco, radius, 8);
0129   if (Enable::HCALIN) radius = HCalInner(g4Reco, radius, 4);
0130   if (Enable::MAGNET) radius = Magnet(g4Reco, radius);
0131   if (Enable::HCALOUT) radius = HCalOuter(g4Reco, radius, 4);
0132   if (Enable::PLUGDOOR) PlugDoor(g4Reco);
0133   if (Enable::EPD) EPD(g4Reco);
0134   if (Enable::BEAMLINE)
0135   {
0136     BeamLineDefineMagnets(g4Reco);
0137     BeamLineDefineBeamPipe(g4Reco);
0138     if (Enable::ZDC)
0139     {
0140       ZDCSetup(g4Reco);
0141     }
0142   }
0143   if (Enable::USER) UserDetector(g4Reco);
0144 
0145   //----------------------------------------
0146   // BLACKHOLE
0147 
0148   if (Enable::BLACKHOLE) BlackHole(g4Reco, radius);
0149 
0150   PHG4TruthSubsystem *truth = new PHG4TruthSubsystem();
0151   g4Reco->registerSubsystem(truth);
0152 
0153   // finally adjust the world size in case the default is too small
0154   WorldSize(g4Reco, radius);
0155 
0156   se->registerSubsystem(g4Reco);
0157   return 0;
0158 }
0159 
0160 void ShowerCompress(int verbosity = 0)
0161 {
0162   Fun4AllServer *se = Fun4AllServer::instance();
0163 
0164   PHG4DstCompressReco *compress = new PHG4DstCompressReco("PHG4DstCompressReco");
0165   compress->AddHitContainer("G4HIT_PIPE");
0166   compress->AddHitContainer("G4HIT_SVTXSUPPORT");
0167   compress->AddHitContainer("G4HIT_CEMC_ELECTRONICS");
0168   compress->AddHitContainer("G4HIT_CEMC");
0169   compress->AddHitContainer("G4HIT_ABSORBER_CEMC");
0170   compress->AddHitContainer("G4HIT_CEMC_SPT");
0171   compress->AddHitContainer("G4HIT_ABSORBER_HCALIN");
0172   compress->AddHitContainer("G4HIT_HCALIN");
0173   compress->AddHitContainer("G4HIT_HCALIN_SPT");
0174   compress->AddHitContainer("G4HIT_MAGNET");
0175   compress->AddHitContainer("G4HIT_ABSORBER_HCALOUT");
0176   compress->AddHitContainer("G4HIT_HCALOUT");
0177   compress->AddHitContainer("G4HIT_BH_1");
0178   compress->AddHitContainer("G4HIT_BH_FORWARD_PLUS");
0179   compress->AddHitContainer("G4HIT_BH_FORWARD_NEG");
0180   compress->AddHitContainer("G4HIT_BBC");
0181   compress->AddCellContainer("G4CELL_CEMC");
0182   compress->AddCellContainer("G4CELL_HCALIN");
0183   compress->AddCellContainer("G4CELL_HCALOUT");
0184   compress->AddTowerContainer("TOWER_SIM_CEMC");
0185   compress->AddTowerContainer("TOWER_RAW_CEMC");
0186   compress->AddTowerContainer("TOWER_CALIB_CEMC");
0187   compress->AddTowerContainer("TOWER_SIM_HCALIN");
0188   compress->AddTowerContainer("TOWER_RAW_HCALIN");
0189   compress->AddTowerContainer("TOWER_CALIB_HCALIN");
0190   compress->AddTowerContainer("TOWER_SIM_HCALOUT");
0191   compress->AddTowerContainer("TOWER_RAW_HCALOUT");
0192   compress->AddTowerContainer("TOWER_CALIB_HCALOUT");
0193   se->registerSubsystem(compress);
0194 
0195   return;
0196 }
0197 
0198 void DstCompress(Fun4AllDstOutputManager *out)
0199 {
0200   if (out)
0201   {
0202     out->StripNode("G4HIT_PIPE");
0203     out->StripNode("G4HIT_SVTXSUPPORT");
0204     out->StripNode("G4HIT_CEMC_ELECTRONICS");
0205     out->StripNode("G4HIT_CEMC");
0206     out->StripNode("G4HIT_ABSORBER_CEMC");
0207     out->StripNode("G4HIT_CEMC_SPT");
0208     out->StripNode("G4HIT_ABSORBER_HCALIN");
0209     out->StripNode("G4HIT_HCALIN");
0210     out->StripNode("G4HIT_HCALIN_SPT");
0211     out->StripNode("G4HIT_MAGNET");
0212     out->StripNode("G4HIT_ABSORBER_HCALOUT");
0213     out->StripNode("G4HIT_HCALOUT");
0214     out->StripNode("G4HIT_BH_1");
0215     out->StripNode("G4HIT_BH_FORWARD_PLUS");
0216     out->StripNode("G4HIT_BH_FORWARD_NEG");
0217     out->StripNode("G4HIT_BBC");
0218     out->StripNode("G4CELL_CEMC");
0219     out->StripNode("G4CELL_HCALIN");
0220     out->StripNode("G4CELL_HCALOUT");
0221   }
0222 }
0223 #endif