Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:18:53

0001 #ifndef MACRO_FUN4ALLG4MYDETECTOR_C
0002 #define MACRO_FUN4ALLG4MYDETECTOR_C
0003 
0004 #include <mydetector/MyDetectorSubsystem.h>
0005 
0006 #include <g4detectors/PHG4DetectorSubsystem.h>
0007 
0008 #include <g4histos/G4HitNtuple.h>
0009 
0010 #include <g4main/PHG4ParticleGenerator.h>
0011 #include <g4main/PHG4ParticleGeneratorBase.h>
0012 #include <g4main/PHG4ParticleGun.h>
0013 #include <g4main/PHG4Reco.h>
0014 #include <g4main/PHG4SimpleEventGenerator.h>
0015 
0016 #include <fun4all/Fun4AllDstOutputManager.h>
0017 #include <fun4all/Fun4AllDummyInputManager.h>
0018 #include <fun4all/Fun4AllInputManager.h>
0019 #include <fun4all/Fun4AllOutputManager.h>
0020 #include <fun4all/Fun4AllServer.h>
0021 #include <fun4all/SubsysReco.h>
0022 
0023 #include <phool/recoConsts.h>
0024 
0025 R__LOAD_LIBRARY(libfun4all.so)
0026 R__LOAD_LIBRARY(libg4detectors.so)
0027 R__LOAD_LIBRARY(libMyDetector.so)
0028 R__LOAD_LIBRARY(libg4histos.so)
0029 
0030 // needs 10000 geantinos to make a decent scan plot
0031 void Fun4All_G4_MyDetector(int nEvents = 10000)
0032 {
0033   ///////////////////////////////////////////
0034   // Make the Server
0035   //////////////////////////////////////////
0036   Fun4AllServer *se = Fun4AllServer::instance();
0037   recoConsts *rc = recoConsts::instance();
0038   // if you want to fix the random seed to reproduce results
0039   // set this flag
0040   // nail this down so I know what the first event looks like...
0041   //  rc->set_IntFlag("RANDOMSEED",12345);
0042 
0043   //
0044   // Particle Generator
0045   //
0046 
0047   // the PHG4ParticleGenerator makes cones using phi and eta
0048   PHG4ParticleGenerator *gen = new PHG4ParticleGenerator();
0049   gen->set_name("geantino");
0050   gen->set_mom_range(1.0, 1.0);
0051   gen->set_z_range(0., 0.);
0052   // experimentally found ranges, they cover the original block
0053   gen->set_vtx(-50, 0, 0);
0054   gen->set_phi_range(-14.5 / 180 * TMath::Pi(), 14.5 / 180 * TMath::Pi());
0055   gen->set_eta_range(-0.26, 0.26);
0056   se->registerSubsystem(gen);
0057 
0058   // ParticleGun shoots right into the original MyDetector volume
0059   PHG4ParticleGun *gun = new PHG4ParticleGun();
0060   //   gun->set_name("pi-");
0061   gun->set_name("geantino");
0062   gun->set_vtx(0, 0, -20);
0063   gun->set_mom(0, 0, 1);
0064   //   se->registerSubsystem(gun);
0065 
0066   //
0067   // Geant4 setup
0068   //
0069   PHG4Reco *g4Reco = new PHG4Reco();
0070   // setup of G4:
0071   //   no field
0072   //   no saving of geometry: it takes time and we do not do tracking
0073   //   so we do not need the geometry
0074   g4Reco->set_field(0);
0075   g4Reco->save_DST_geometry(false);
0076 
0077   MyDetectorSubsystem *mydet = new MyDetectorSubsystem("MyDetector1");
0078   mydet->SetActive();
0079   g4Reco->registerSubsystem(mydet);
0080 
0081   // mydet = new MyDetectorSubsystem("MyDetector2");
0082   // mydet->set_double_param("place_x",40.);
0083   // mydet->set_double_param("place_y",40.);
0084   // mydet->set_double_param("rot_x",45.);
0085   // mydet->set_string_param("material","G4_Fe");
0086   // mydet->SetActive();
0087   // g4Reco->registerSubsystem(mydet);
0088 
0089   se->registerSubsystem(g4Reco);
0090 
0091   ///////////////////////////////////////////
0092   // Fun4All modules
0093   ///////////////////////////////////////////
0094 
0095   G4HitNtuple *hits = new G4HitNtuple("Hits");
0096   hits->AddNode("MyDetector1_0", 0);
0097   se->registerSubsystem(hits);
0098 
0099   ///////////////////////////////////////////
0100   // IOManagers...
0101   ///////////////////////////////////////////
0102 
0103   // Fun4AllDstOutputManager *out = new Fun4AllDstOutputManager("DSTOUT","G4Example02.root");
0104   // out->Verbosity(10);
0105   // se->registerOutputManager(out);
0106 
0107   // this (dummy) input manager just drives the event loop
0108   Fun4AllInputManager *in = new Fun4AllDummyInputManager("Dummy");
0109   se->registerInputManager(in);
0110   // events = 0 => run forever
0111   if (nEvents <= 0)
0112   {
0113     return 0;
0114   }
0115   se->run(nEvents);
0116   cout << "Print out Detector parameters" << endl;
0117   mydet->Print();
0118   se->End();
0119   delete se;
0120   cout << endl
0121        << endl;
0122   cout << "Now open the ntuple file with " << endl;
0123   cout << "  root.exe G4HitNtuple.root" << endl;
0124   cout << "and draw the 3d hit distribution," << endl;
0125   cout << "exit hits in black, entry hits in red:" << endl;
0126   cout << "  hitntup->Draw(\"x1:y1:z1\")" << endl;
0127   cout << "  hitntup->SetMarkerColor(2)" << endl;
0128   cout << "  hitntup->Draw(\"x0:y0:z0\",\"\",\"same\")" << endl;
0129   cout << endl;
0130   gSystem->Exit(0);
0131 }
0132 
0133 #endif