17 #include <G4RunManager.hh>
18 #include <G4UImanager.hh>
19 #include <G4VisManager.hh>
21 #include <fwk/CentralConfig.h>
22 #include <fwk/RandomEngineRegistry.h>
24 #include <det/Detector.h>
26 #include <evt/Event.h>
27 #include <evt/ShowerSimData.h>
29 #include <sdet/SDetector.h>
30 #include <sdet/Station.h>
33 #include <sevt/PMTSimData.h>
34 #include <sevt/SEvent.h>
35 #include <sevt/Station.h>
36 #include <sevt/StationSimData.h>
38 #include <mevt/MEvent.h>
39 #include <mevt/CounterSimData.h>
40 #include <mdet/MDetector.h>
41 #include <mdet/Counter.h>
43 #include <utl/ErrorLogger.h>
44 #include <utl/Reader.h>
45 #include <utl/Particle.h>
46 #include <utl/ShowerParticleIterator.h>
47 #include <utl/TimeDistribution.h>
48 #include <utl/TimeDistributionAlgorithm.h>
49 #include <utl/ParticleCases.h>
55 #include <CLHEP/Random/Random.h>
57 #include <tls/Geant4Manager.h>
68 using namespace G4XTankSimulatorAG;
71 G4XTankPMT* G4XTankSimulator::fgPMTAction =
nullptr;
72 const sdet::Station* G4XTankSimulator::fCurrentDetectorStation =
nullptr;
76 bool G4XTankSimulator::fgMuCapture =
false;
82 switch (curParticle->GetType()) {
103 useAtt[
"use"] =
"yes";
107 fStoreOnGrdPart =
true;
108 cout <<
"Particles on ground will be stored in Counter particle list structure X-XX\n";
120 muCaptureB.
GetData(fgMuCapture);
123 if (globalPhysicsListB)
124 globalPhysicsListB.
GetData(fUseGlobalPhysicsList);
126 if ((fGeoVisOn || fTrajVisOn) && !fVisManager)
130 if (fUseGlobalPhysicsList)
131 fRunManager = tls::Geant4Manager::GetInstance().GetRunManager();
133 fRunManager =
new G4RunManager;
136 fUImanager = G4UImanager::GetUIpointer();
139 fUImanager->SetCoutDestination(logger);
142 const SDetector& sDetector = Detector::GetInstance().GetSDetector();
149 fCurrentDetectorStation = &(*sIt);
151 ss <<
"Station " << fCurrentDetectorStation->
GetId() <<
" has associated counter";
159 if (!fCurrentDetectorStation) {
160 ERROR(
"Could not find any station with an associated muon counter");
164 const MDetector& mDetector = det::Detector::GetInstance().GetMDetector();
174 "Counter depth: " << CtrDepth/CLHEP::m <<
" m\n"
175 "Module depth: " << ModDepth/CLHEP::m <<
" m\n"
176 "-> Using " << (CtrDepth>ModDepth ?
"Counter" :
"Module") <<
" depth";
179 fDepth = CtrDepth > ModDepth ? CtrDepth : ModDepth;
181 if (fUseGlobalPhysicsList) {
182 INFO(
"using global PhysicsList from Geant4Manager");
183 tls::Geant4Manager::GetInstance().AddVisManager(fVisManager);
185 fUImanager->ApplyCommand(
"/run/verbose 0");
186 fUImanager->ApplyCommand(
"/event/verbose 0");
187 fUImanager->ApplyCommand(
"/tracking/verbose 0");
188 fUImanager->ApplyCommand(
"/stepping/verbose 0");
192 INFO(
"Constructing G4XTank");
206 tls::Geant4Manager::GetInstance().AddCustomization(custom);
210 INFO(
"using PhysicsList from G4XTankPhysicsList");
216 fRunManager->SetUserAction(fStackingAction);
219 fRunManager->SetUserAction(fSteppingAction);
223 fUImanager->ApplyCommand(
"/run/verbose 0");
224 fUImanager->ApplyCommand(
"/event/verbose 0");
225 fUImanager->ApplyCommand(
"/tracking/verbose 0");
226 fUImanager->ApplyCommand(
"/stepping/verbose 0");
229 fDetectorConstructed =
false;
239 ERROR(
"SEvent does not exist.");
243 CLHEP::HepRandom::setTheEngine(&RandomEngineRegistry::GetInstance().
244 Get(RandomEngineRegistry::eDetector).
247 SEvent& sEvent =
event.GetSEvent();
251 if (!fUseGlobalPhysicsList) {
252 INFO(
"Constructing G4XTank");
256 ERROR(
"No stations!");
263 fRunManager->SetUserInitialization(fgTankConstruction);
265 fRunManager->Initialize();
268 fDetectorConstructed =
true;
270 if (fGeoVisOn || fTrajVisOn) {
271 fVisManager->Initialize();
272 fUImanager->ApplyCommand(
"/vis/open VRML2FILE");
273 fUImanager->ApplyCommand(
"/vis/scene/create");
274 fUImanager->ApplyCommand(
"/vis/sceneHandler/attach");
275 fUImanager->ApplyCommand(
"/vis/scene/add/volume");
276 fUImanager->ApplyCommand(
"/vis/viewero/set/style/wireframe");
277 fUImanager->ApplyCommand(
"/vis/drawVolume");
278 fUImanager->ApplyCommand(
"/vis/scene/notifyHandlers");
279 fUImanager->ApplyCommand(
"/vis/viewer/update");
282 fUImanager->ApplyCommand(
"/tracking/storeTrajectory 1");
283 fUImanager->ApplyCommand(
"/vis/scene/add/trajectories");
288 if (fUseGlobalPhysicsList)
289 tls::Geant4Manager::GetInstance().Customize(
"G4XTankSimulator");
291 return fFastMode ? RunFast(event) : RunFull(event);
296 G4XTankSimulator::RunFull(
Event& event)
299 SEvent& sEvent =
event.GetSEvent();
302 const SDetector& sDetector = Detector::GetInstance().GetSDetector();
308 MEvent& mEvent =
event.GetMEvent();
313 if (!fDetectorConstructed) {
314 ERROR(
"The detector hasn't been initialized when looping over stations");
318 if (sIt->HasSimData()) {
325 const int stationId = sIt->GetId();
330 G4cerr <<
"On ground -> StatId " << stationId <<
':' << numParticles <<
" particle(s)" << flush;
334 fCurrentEventStationIt = sIt;
335 fCurrentDetectorStation = &sDetector.
GetStation(stationId);
336 fStackingAction->SetStation(fCurrentDetectorStation);
338 ConstructTraces(*sIt);
341 if (!fCurrentDetectorStation->ExistsAssociatedCounter())
345 const int mId = fCurrentDetectorStation->GetAssociatedCounterId();
360 fSteppingAction->fCounterDepth = -fDepth;
366 fCurrentParticleIt = pIt;
368 fSteppingAction->SetImpingingParticle(parent);
370 if (fStoreOnGrdPart) {
371 Particle part = *fCurrentParticleIt;
375 fRunManager->BeamOn(1);
379 cout << fSteppingAction->fPartColl.size() <<
" particles underground at the counter's depth "
380 << fSteppingAction->fCounterDepth/
CLHEP::m <<
" m"
381 " on station number " << sIt->GetId() <<
" ";
386 unsigned int muons_ugrd = 0;
388 for (pCollIt = fSteppingAction->fPartColl.begin(); pCollIt != fSteppingAction->fPartColl.end(); ++pCollIt) {
416 cout <<
"out of which " << muons_ugrd <<
" are muons\n";
417 fSteppingAction->fPartColl.clear();
427 G4XTankSimulator::RunFast(
Event& event)
429 SEvent& sEvent =
event.GetSEvent();
430 const SDetector& sDetector = Detector::GetInstance().GetSDetector();
435 MEvent& mEvent =
event.GetMEvent();
440 !fCurrentEventStationIt->HasSimData(); ++fCurrentEventStationIt)
443 if (fCurrentEventStationIt == sEvent.
StationsEnd()) {
444 INFO(
"No stations with SimData found.");
445 return eContinueLoop;
448 const int id = fCurrentEventStationIt->GetId();
449 fCurrentDetectorStation = &sDetector.
GetStation(
id);
451 if (!fDetectorConstructed) {
456 fRunManager->SetUserInitialization(fgTankConstruction);
458 fRunManager->Initialize();
459 fDetectorConstructed =
true;
466 if (!sIt->HasSimData())
473 const unsigned long numParticles =
476 const int stationId = sIt->GetId();
479 G4cerr <<
"On ground -> StatId " << stationId <<
':' << numParticles <<
" particle(s)" << flush;
483 fCurrentEventStationIt = sIt;
484 fCurrentDetectorStation = &sDetector.
GetStation(stationId);
486 ConstructTraces(*sIt);
489 if (!fCurrentDetectorStation->ExistsAssociatedCounter())
493 const int mId = fCurrentDetectorStation->GetAssociatedCounterId();
511 fSteppingAction->fCounterDepth = -fDepth;
514 G4XTankFastCerenkov::GetDataFromConstruction();
519 fCurrentParticleIt = pIt;
521 fSteppingAction->SetImpingingParticle(parent);
523 fgPMTAction->SetCurrentTank(fCurrentEventStationIt);
524 fgPMTAction->SetParticle(*fCurrentParticleIt);
526 if (fStoreOnGrdPart) {
527 Particle part = *fCurrentParticleIt;
531 fRunManager->BeamOn(1);
535 cout << fSteppingAction->fPartColl.size() <<
" particles underground at the counter's depth "
536 << fSteppingAction->fCounterDepth/
CLHEP::m <<
" m"
537 " on station number " << sIt->GetId() <<
" ";
542 unsigned int muons_ugrd = 0;
544 for (pCollIt = fSteppingAction->fPartColl.begin(); pCollIt != fSteppingAction->fPartColl.end(); ++pCollIt) {
573 cout <<
"out of which " << muons_ugrd <<
" are muons\n";
574 fSteppingAction->fPartColl.clear();
581 fgPMTAction =
nullptr;
588 G4XTankSimulator::Finish()
590 if (fUseGlobalPhysicsList)
591 tls::Geant4Manager::GetInstance().NotifyDelete();
595 fRunManager =
nullptr;
613 pmtIt != station.
PMTsEnd(); ++pmtIt)
614 if (!pmtIt->HasSimData()) {
615 pmtIt->MakeSimData();
void SetRunAction(G4UserRunAction *const action)
Branch GetTopBranch() const
Geant4 Stacking user action class.
Geant4 Tracking user action class.
Station Level Simulated Data
StationIterator StationsEnd()
End of all stations.
void AddUGrdParticle(const utl::Particle &particle)
void SetPrimaryGenerator(G4VUserPrimaryGeneratorAction *const action)
Detector description interface for Station-related data.
total (shower and background)
int GetNumberOfStations() const
Get total number of stations in the event.
Counter level event data.
Interface class to access to the SD part of an event.
Describes a particle for Simulation.
PMTIterator PMTsBegin(const sdet::PMTConstants::PMTType type=sdet::PMTConstants::eWaterCherenkovLarge)
begin PMT iterator for read/write
vector< PartData >::iterator PartCollectionIt
std::map< std::string, std::string > AttributeMap
utl::CoordinateSystemPtr GetLocalCoordinateSystem() const
Local system based on position and configured rotations.
boost::shared_ptr< utl::Particle > smartPointer
void SetStackingAction(G4UserStackingAction *const action)
#define INFO(message)
Macro for logging informational messages.
utl::Point GetPosition() const
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.
boost::filter_iterator< PMTFilter, InternalPMTIterator > PMTIterator
Iterator over station for read/write.
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.
ParticleVector::iterator ParticleIterator
electrons and positrons from shower
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
Class representing a document branch.
class to hold data at Station level
void SetEventAction(G4UserEventAction *const action)
Geant4 Stepping user action class.
ParticleVector::const_iterator ConstParticleIterator
StationIterator StationsEnd() const
End of the collection of pointers to commissioned stations.
utl::CoordinateSystemPtr GetLocalCoordinateSystem() const
Get the Auger reference system centered on the tank.
PMTIterator PMTsEnd(const sdet::PMTConstants::PMTType type=sdet::PMTConstants::eWaterCherenkovLarge)
end PMT iterator for read/write
Geant4 Run user action class.
StationIterator StationsBegin() const
Beginning of the collection of pointers to commissioned stations.
bool ExistsAssociatedCounter() const
if this Station has an associated muon Counter.
Data structure to hold the different Geant4 global objects required to run a single module...
void GetData(bool &b) const
Overloads of the GetData member template function.
Root detector of the muon detector hierarchy.
ParticleIterator ParticlesBegin()
Beginning of simulated particles entering the station.
Counter level simulation data.
void SetTrackingAction(G4UserTrackingAction *const action)
void AddGrdParticle(const utl::Particle &particle)
ResultFlag
Flag returned by module methods to the RunController.
Geant4 Event user action class.
StationIterator StationsBegin()
Beginning of all stations.
ModuleConstIterator ModulesBegin() const
Begin iterator for the Modules contained in the Counter.
Detector description interface for SDetector-related data.
class that declares and registers the Geant4 physics classes
#define OFFLINE_ELECTRONS
boost::indirect_iterator< InternalStationIterator, Station & > StationIterator
Iterator over all stations.
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)
void SetParent(Particle &parent)
double GetZ(const CoordinateSystemPtr &coordinateSystem) const
const Station & GetStation(const int stationId) const
Get station by Station Id.
const Counter & GetCounter(int id) const
Retrieve Counter by id.
CounterSimData & GetSimData()
int GetId() const
Station ID.
boost::indirect_iterator< InternalConstStationIterator, const Station & > ConstStationIterator
#define ERROR(message)
Macro for logging error messages.
ParticleIterator ParticlesEnd()
End of simulated particles entering the station.
Root of the Muon event hierarchy.
mu+ and mu- (including signal from mu decay electrons) from shower
void SetSteppingAction(G4UserSteppingAction *const action)
allow customization of the standard global PhysicsList that are handled by the Geant4Manager ...