14 #include <G4RunManager.hh>
15 #include <G4UImanager.hh>
16 #include <G4VisManager.hh>
18 #include <fwk/CentralConfig.h>
19 #include <fwk/RandomEngineRegistry.h>
21 #include <det/Detector.h>
23 #include <evt/Event.h>
24 #include <evt/ShowerSimData.h>
26 #include <sdet/SDetector.h>
27 #include <sdet/Station.h>
28 #include <sdet/PMTConstants.h>
31 #include <mdet/MDetector.h>
32 #include <mdet/Counter.h>
35 #include <sevt/PMTSimData.h>
36 #include <sevt/SEvent.h>
37 #include <sevt/Station.h>
38 #include <sevt/StationSimData.h>
40 #include <utl/ErrorLogger.h>
41 #include <utl/Reader.h>
42 #include <utl/Particle.h>
43 #include <utl/ParticleCases.h>
44 #include <utl/ShowerParticleIterator.h>
45 #include <utl/TimeDistribution.h>
46 #include <utl/TimeDistributionAlgorithm.h>
64 namespace G4StationSimulatorOG {
66 bool G4StationSimulator::Setup::fgLock =
false;
68 G4StationSimulator::Current G4StationSimulator::fgCurrent;
69 bool G4StationSimulator::fgMuCapture =
false;
110 INFO(
"MARTA RPC G4 simulation has been activated");
122 INFO(
"UMD tank+ground G4 simulation has been activated");
124 fSimulationRadius += 1*
utl::cm;
148 muCaptureB.
GetData(fgMuCapture);
150 const auto sepMode = topB.
GetChild(
"signalSeparationMode").
Get<
string>();
151 if (sepMode ==
"Standard")
153 else if (sepMode ==
"Universality")
156 if ((fGeoVisOn || fTrajVisOn) && !fVisManager)
160 fRunManager =
new G4RunManager;
162 fUImanager = G4UImanager::GetUIpointer();
165 fUImanager->SetCoutDestination(logger);
172 fRunManager->SetUserAction(fStackingAction);
178 switch (fVerbosity) {
180 fUImanager->ApplyCommand(
"/run/verbose 1");
181 fUImanager->ApplyCommand(
"/event/verbose 0");
182 fUImanager->ApplyCommand(
"/tracking/verbose 0");
185 fUImanager->ApplyCommand(
"/run/verbose 1");
186 fUImanager->ApplyCommand(
"/event/verbose 1");
187 fUImanager->ApplyCommand(
"/tracking/verbose 0");
190 fUImanager->ApplyCommand(
"/run/verbose 1");
191 fUImanager->ApplyCommand(
"/event/verbose 1");
192 fUImanager->ApplyCommand(
"/tracking/verbose 1");
195 fUImanager->ApplyCommand(
"/run/verbose 0");
196 fUImanager->ApplyCommand(
"/event/verbose 0");
197 fUImanager->ApplyCommand(
"/tracking/verbose 0");
200 fDetectorConstructed =
false;
207 G4StationSimulator::Run(
Event& event)
210 ERROR(
"SEvent does not exist.");
214 if (fMARTAEnabled && !event.
HasCEvent()) {
221 SEvent& sEvent =
event.GetSEvent();
225 INFO(
"Constructing G4Station");
229 ERROR(
"No stations!");
233 Setup setup(Detector::GetInstance().GetSDetector().GetStation(sIt->GetId()));
236 fRunManager->SetUserInitialization(
new G4StationConstruction(fSimulationRadius, fUMDEnabled, fScintYield, fMARTAEnabled));
238 fRunManager->Initialize();
240 fDetectorConstructed =
true;
242 if (fGeoVisOn || fTrajVisOn) {
243 fVisManager->Initialize();
244 fUImanager->ApplyCommand((
"/vis/open " + fRenderFile).c_str());
245 fUImanager->ApplyCommand(
"/vis/scene/create");
246 fUImanager->ApplyCommand(
"/vis/sceneHandler/attach");
247 fUImanager->ApplyCommand(
"/vis/scene/add/volume");
248 fUImanager->ApplyCommand(
"/vis/viewer/set/viewpointThetaPhi 0. 0.");
249 fUImanager->ApplyCommand(
"/vis/viewer/set/targetPoint 0 0 0");
250 fUImanager->ApplyCommand(
"/vis/viewer/zoom 1");
251 fUImanager->ApplyCommand(
"/vis/viewero/set/style/wireframe");
252 fUImanager->ApplyCommand(
"/vis/drawVolume");
253 fUImanager->ApplyCommand(
"/vis/scene/notifyHandlers");
254 fUImanager->ApplyCommand(
"/vis/viewer/update");
257 fUImanager->ApplyCommand(
"/tracking/storeTrajectory 1");
258 fUImanager->ApplyCommand(
"/vis/scene/add/trajectories");
263 return fFastMode ? RunFast(event) : RunFull(event);
268 G4StationSimulator::RunFull(
Event& event)
273 fSimulatorSignature =
"G4StationSimulatorFullTrackOG";
277 fSimulatorSignature =
"G4StationSimulatorFullOG";
280 INFO(fSimulatorSignature);
283 SEvent& sEvent =
event.GetSEvent();
289 const SDetector& sDetector = Detector::GetInstance().GetSDetector();
291 for (
auto& station : sEvent.StationsRange()) {
293 if (!fDetectorConstructed) {
294 ERROR(
"The detector hasn't been initialized when looping over stations");
298 const int stationId = station.GetId();
302 CEvent& cEvent =
event.GetCEvent();
309 if (station.HasSimData()) {
316 G4cerr << stationId <<
':' << numParticles <<
' ' << flush;
325 if (!nParticlesAlreadySimulated)
334 if (fUMDEnabled && fgCurrent.GetDetectorStation().ExistsAssociatedCounter()) {
335 const auto counterId = fgCurrent.GetDetectorStation().GetAssociatedCounterId();
337 MEvent& mEvent =
event.GetMEvent();
342 const MDetector& mDetector = Detector::GetInstance().GetMDetector();
346 ConstructTraces(station);
348 for (
auto&
particle : simData.ParticlesRange()) {
350 fRunManager->BeamOn(1);
353 CEvent& cEvent =
event.GetCEvent();
355 FillRPCSimData(martaSimData);
366 G4StationSimulator::RunFast(
Event& event)
368 fSimulatorSignature =
"G4StationSimulatorOG";
369 INFO(fSimulatorSignature);
372 SEvent& sEvent =
event.GetSEvent();
378 const SDetector& sDetector = Detector::GetInstance().GetSDetector();
380 if (!fDetectorConstructed) {
383 for (
auto&
s : sEvent.StationsRange())
384 if (
s.HasSimData()) {
389 INFO(
"No stations with SimData found.");
394 fStationConstruction =
new G4StationConstruction(fSimulationRadius, fUMDEnabled, fScintYield, fMARTAEnabled);
395 fRunManager->SetUserInitialization(fStationConstruction);
396 fRunManager->Initialize();
397 fDetectorConstructed =
true;
400 for (
auto& station : sEvent.StationsRange()) {
402 const int stationId = station.GetId();
406 CEvent& cEvent =
event.GetCEvent();
413 if (!station.HasSimData())
423 cerr <<
"StationId " << stationId <<
" : Particles " << numParticles << endl;
432 if (!nParticlesAlreadySimulated)
442 if (fgCurrent.GetDetectorStation().ExistsAssociatedCounter()) {
443 const auto counterId = fgCurrent.GetDetectorStation().GetAssociatedCounterId();
444 MEvent& mEvent =
event.GetMEvent();
448 const MDetector& mDetector = Detector::GetInstance().GetMDetector();
453 ConstructTraces(station);
456 G4StationFastCerenkov::GetDataFromConstruction();
458 for (
auto&
particle : simData.ParticlesRange()) {
460 fRunManager->BeamOn(1);
463 CEvent& cEvent =
event.GetCEvent();
465 FillRPCSimData(martaSimData);
479 G4StationSimulator::Finish()
482 fRunManager =
nullptr;
499 if (!pmt.HasSimData())
508 if (!fgCurrent.GetEventUMDCounter().HasSimData())
509 fgCurrent.GetEventUMDCounter().MakeSimData();
511 if (!fgCurrent.GetEventUMDCounter().HasModule(modId))
512 fgCurrent.GetEventUMDCounter().MakeModule(modId);
514 mevt::Module& module = fgCurrent.GetEventUMDCounter().GetModule(modId);
533 const auto type = particle.
GetType();
545 G4StationSimulator::AddUMDPhoton(
const size_t modId,
const size_t stripId,
const double peTime)
550 auto& counter = fgCurrent.GetEventUMDCounter();
551 if (!counter.HasSimData())
552 counter.MakeSimData();
554 if (!counter.HasModule(modId))
555 counter.MakeModule(modId);
574 G4StationSimulator::AddPhoton(
const int nPMT,
const double peTime)
581 if (!fgCurrent.GetEventStation().HasPMT(nPMT)) {
582 WARNING(
"Attempt to add photoelectron to PMT that does not exist. Doing nothing.");
586 PMTSimData& pmtSim = fgCurrent.GetEventStation().GetPMT(nPMT).GetSimData();
588 const auto type = fgCurrent.GetParticle().GetType();
589 const auto source = fgCurrent.GetParticle().GetSource();
594 switch (fSignalSeparationMode) {
614 cerr <<
"Unknown particle type" << endl;
643 cerr <<
"Unknown particle type" << endl;
669 auto& rpcParticleListMap = G4StationSteppingAction::fgRPCParticleListMap;
670 for (
const auto& rpcParticleList : rpcParticleListMap) {
671 const auto& particleList = rpcParticleList.second;
672 for (
const auto&
p : particleList)
675 rpcParticleListMap.clear();
677 G4StationSteppingAction::fgRPCTrackIDListMap.clear();
Branch GetTopBranch() const
Station Level Simulated Data
StationIterator StationsEnd()
End of all stations.
void AddParticle(const utl::Particle &particle)
Add a simulated particle to the station.
Station Level Simulated Data
total (shower and background)
bool HasScintillator(const int sId) const
void MakeScintillator(const int sId)
int GetNumberOfStations() const
Get total number of stations in the event.
Interface class to access to the SD part of an event.
Describes a particle for Simulation.
void IncrementNumberOfElectrons()
Geant4 Stepping user action class.
void Set(const sdet::Station &s) const
#define INFO(message)
Macro for logging informational messages.
void AddParticle(const utl::Particle &particle)
electrons produced by hadrons close to the detector
void Init()
Initialise the registry.
bool HasCounter(const int cId) const
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Station & GetStation(const int stationId)
retrieve station by id throw utl::NonExistentComponentException if n.a.
implementation of G4 visualization manager
Detector associated to muon detector hierarchy.
void SetSimulatorSignature(const std::string &name)
Set name of the tank simulator module used to simulate this station.
bool HasPETimeDistribution(const StationConstants::SignalComponent source=StationConstants::eTotal) const
Check if a PE release time distribution exists (optionally for a given source)
void IncrementNumberOfInjectedMuons()
electrons and positrons from shower
Scintillator & GetScintillator(const int sId)
Scintillator level event data.
Class representing a document branch.
class to hold data at Station level
Geant4 Event user action class.
#define WARNING(message)
Macro for logging warning messages.
void GetData(bool &b) const
Overloads of the GetData member template function.
void IncrementNumberOfCornerClippingMuons()
photons from muon decay in shower
ParticleIterator ParticlesBegin()
Beginning of simulated particles entering the station.
Geant4 Stacking user action class.
Scintillator level simulation data.
ResultFlag
Flag returned by module methods to the RunController.
unsigned int GetTotalSimParticleCount() const
Get the total number of particles that were actually simulated (after thinning)
void AddPhotonTime(const double t0)
static CentralConfig * GetInstance()
Use this the first time you get an instance of central configuration.
void SetTotalSimParticleCount(const unsigned int n)
StationIterator StationsBegin()
Beginning of all stations.
Source GetSource() const
Source of the particle (eg. shower or background)
Class to hold simulated data at PMT level.
struct particle_info particle[80]
void MakeStation(const int stationId)
make a station with specifying Id, throw if invalid stationId
Geant4 Tracking user action class.
bool HasStation(const int stationId) const
Check whether station exists.
Detector description interface for SDetector-related data.
#define OFFLINE_ELECTRONS
void MakeCounter(const int cId)
sevt::StationSimData & GetSimData()
Get simulated data at station level.
utl::CoordinateSystemPtr Get(const std::string &id)
Get a well-known Coordinate System.
Counter & GetCounter(const int cId)
unsigned int GetNParticles() const
utl::TimeDistributionI & GetPETimeDistribution(const StationConstants::SignalComponent source=StationConstants::eTotal)
Simulated photoelectron time distribution.
const Station & GetStation(const int stationId) const
Get station by Station Id.
const Counter & GetCounter(int id) const
Retrieve Counter by id.
#define ERROR(message)
Macro for logging error messages.
ParticleIterator ParticlesEnd()
End of simulated particles entering the station.
void AddTime(const double time, const T weight=T(1))
Add an entry (optionally weighted) for the given time. Slot will be computed.
Root of the Muon event hierarchy.
mu+ and mu- (including signal from mu decay electrons) from shower
StationSimData & GetSimData()
Get simulated data at station level.
ScintillatorSimData & GetSimData()
electrons from muon decay in shower
void MakePETimeDistribution(const StationConstants::SignalComponent source=StationConstants::eTotal)
Create a PE release time distribution (optionally for given source)
Interface class to access to the SD part of an event.
void MakeSimData()
Make station simulated data object.