8 #include <G4RunManager.hh>
9 #include <G4UImanager.hh>
10 #include <G4VisManager.hh>
11 #include <G4VisExecutive.hh>
13 #include <fwk/CentralConfig.h>
14 #include <fwk/RandomEngineRegistry.h>
16 #include <det/Detector.h>
17 #include <mdet/Counter.h>
18 #include <mdet/Module.h>
19 #include <mdet/Scintillator.h>
21 #include <evt/Event.h>
22 #include <mevt/Counter.h>
23 #include <mevt/Module.h>
24 #include <mevt/Scintillator.h>
25 #include <mevt/CounterSimData.h>
26 #include <mevt/ScintillatorSimData.h>
28 #include <utl/ErrorLogger.h>
29 #include <utl/Reader.h>
30 #include <utl/Particle.h>
31 #include <utl/ShowerParticleIterator.h>
32 #include <utl/TimeDistribution.h>
33 #include <utl/TimeDistributionAlgorithm.h>
34 #include <utl/AugerUnits.h>
36 #include <utl/TabularStream.h>
37 #include <utl/ConfigUtils.h>
44 #include <CLHEP/Random/Random.h>
46 #include <tls/Geant4Manager.h>
55 using namespace EdepSimulatorAG;
61 EdepSimulator::EdepSimulator() :
99 fRunManager = tls::Geant4Manager::GetInstance().GetRunManager();
121 tls::Geant4Manager::GetInstance().AddVisManager(
fVisManager);
123 INFO(
"using global PhysicsList from Geant4Manager");
126 INFO(
"\n++++\nConstructing G4 ground");
131 INFO(
"\n++++\nInitializing G4 stepping action");
135 INFO(
"\n++++\nInitializing G4 primary generator");
138 tls::Geant4Manager::GetInstance().AddCustomization(custom);
141 INFO(
"using PhysicsList from MdEdepSimulator");
144 INFO(
"\n++++\nConstructing G4 ground");
147 INFO(
"\n++++\nInitializing G4 stepping action");
151 INFO(
"\n++++\nInitializing G4 primary generator");
154 fUImanager->ApplyCommand(
"/physlist/CutsAll 1 mm");
158 oss <<
"/physlist/Physics " << physList;
164 fUImanager->ApplyCommand(
"/vis/open HepRepFile");
165 fUImanager->ApplyCommand(
"/vis/scene/create");
166 fUImanager->ApplyCommand(
"/vis/sceneHandler/attach");
167 fUImanager->ApplyCommand(
"/vis/scene/add/volume");
169 fUImanager->ApplyCommand(
"/vis/scene/notifyHandlers");
170 fUImanager->ApplyCommand(
"/vis/viewer/update");
173 fUImanager->ApplyCommand(
"/tracking/storeTrajectory 1");
174 fUImanager->ApplyCommand(
"/vis/scene/add/trajectories rich");
184 int PDGCode(0), ParentID(0), TrackID(0);
186 double x(0), y(0), z(0);
188 double px(0), py(0), pz(0);
190 double KinE(0), Time(0);
193 DataCollection::iterator dIt;
197 for ( sstepIt = sstepMap.begin(); sstepIt != sstepMap.end(); ++sstepIt ) {
202 double totalEdep = 0;
203 bool first_particle =
true;
205 for ( dIt = cur.begin(); dIt != cur.end(); ++dIt ) {
208 totalEdep += data.
Edep;
210 if ( first_particle ){
224 first_particle =
false;
242 if ( scintMap.find( (*sstepIt).first ) == scintMap.end()){
245 scintMap[ (*sstepIt).first] = nuovo;
249 partdata.
Sname = Sname;
250 partdata.
Pname = Pname;
260 partdata.
KinE = KinE;
261 partdata.
Edep = totalEdep;
262 partdata.
Time = Time;
265 scintMap[(*sstepIt).first].push_back( partdata );
275 ERROR(
"\nMEvent does not exist.");
280 MEvent& mEvent =
event.GetMEvent();
283 INFO(
"\n++++\nActivating G4 for this run");
287 tls::Geant4Manager::GetInstance().Customize(
"MdEdepSimulator");
292 const MDetector& mDetector = Detector::GetInstance().GetMDetector();
296 const int counterId = cIt->GetId();
300 const int modId = im->
GetId();
307 if (
is->HasSimData()) {
311 const int scintId =
is->GetId();
315 fLog(
"Counter ", 1,
false)( counterId )(
" ");
316 fLog(
"Module ", 1,
false)( modId )(
" ");
350 const unsigned int particleTableLogLevel = 2;
351 std::unique_ptr<utl::TabularStream> table;
355 fLog.ApplyConfigurationOn(*table);
372 for ( scintIt = scintMap.begin(); scintIt != scintMap.end(); ++scintIt ) {
374 DataCollection::iterator dIt;
376 int ScIdx = (*scintIt).first;
381 if (!im->HasScintillator(ScIdx)) {
382 im->MakeScintillator(ScIdx);
383 im->GetScintillator(ScIdx).MakeSimData();
389 const int scintId =
is->GetId();
391 if( (*scintIt).first != scintId )
397 fLog(
"Particles that deposited energy in scintillator ", 5 )(scintId)(
" : ")( cur.size() );
400 for ( dIt = cur.begin(); dIt != cur.end(); ++dIt, ++n ) {
421 Vector pDir( data.
px, data.
py, data.
pz, ScintillatorCS );
437 scintMap.erase( scintMap.begin(), scintMap.end() );
441 fLog(
"Particle table after G4 Scintillator simulation:", particleTableLogLevel);
442 fLog(table->Str(), particleTableLogLevel);
455 tls::Geant4Manager::GetInstance().NotifyDelete();
Branch GetTopBranch() const
int GetNumberOfCounters() const
const Module & GetModule(const int mId) const
Retrieve by id a constant module.
CounterConstIterator CountersBegin() const
fwk::VModule::ResultFlag Finish()
Finish: invoked at end of the run (NOT end of the event)
void SetScintillatorId(int id)
void SetPrimaryGenerator(G4VUserPrimaryGeneratorAction *const action)
Report success to RunController.
double GetLengthUnit() const
Describes a particle for Simulation.
const std::string & GetLengthName() const
void SetEnergyDefault(const double unit, const std::string &name)
bool is(const double a, const double b)
const ScintMap & GetScintMap()
utl::CoordinateSystemPtr GetLocalCoordinateSystem() const
Local system based on position and configured rotations.
static const mdet::Scintillator * fCurrentDetectorScintillator
#define INFO(message)
Macro for logging informational messages.
void AddParticle(const utl::Particle &particle)
vector< t2list > out
output of the algorithm: a list of clusters
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Detector associated to muon detector hierarchy.
fwk::VModule::ResultFlag Run(evt::Event &theEvent)
Run: invoked once per event.
bool fUseGlobalPhysicsList
G4VisManager * fVisManager
Actual muon-sensitive objects.
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
utl::MessageLoggerConfig fLog
Output messages handler.
Class representing a document branch.
boost::indirect_iterator< InternalParticleIterator, utl::Particle & > ParticleIterator
static mevt::ScintillatorSimData::ParticleIterator fCurrentParticleIt
void Configure(const utl::Branch &config)
Configure units (values and defaults) given a branch.
allow customization of the standard global PhysicsList that are handled by the Geant4Manager ...
ScintMap::iterator ScintMapIt
void SetImpingingParticle(utl::Particle *p)
const unsigned int & GetLevel() const
Retrieve (read-only) the current level of verbosity.
friend class PrimaryGenerator
void SetLengthDefault(const double unit, const std::string &name)
utl::Particle * GetImpingingParticle()
void Configure(const Branch &config)
SteppingAction * fSteppingAction
class to format data in tabular form
Data structure to hold the different Geant4 global objects required to run a single module...
void AddUpContributions(SteppingAction::ScintMap &)
utl::UnitsConfig fUnits
Units configuration.
static mevt::Module::ScintillatorIterator fCurrentEventScintillatorIt
InternalModuleCollection::ComponentIterator ModuleIterator
G4RunManager * fRunManager
Private G4 members.
Root detector of the muon detector hierarchy.
const std::string & GetEnergyName() const
fwk::VModule::ResultFlag Init()
Initialize: invoked at beginning of run (NOT beginning of event)
Scintillator level simulation data.
ResultFlag
Flag returned by module methods to the RunController.
double GetEnergyUnit() const
InternalCounterCollection::ComponentIterator CounterIterator
InternalScintillatorCollection::ComponentIterator ScintillatorIterator
void LoadConfig(const utl::Branch &b, const std::string &tag, T1 &var, const T2 &defaultValue)
Helper method to load a particular configuration parameter.
map< int, DataCollection > ScintMap
Report failure to RunController, causing RunController to terminate execution.
CounterConstIterator CountersEnd() const
ParticleIterator ParticlesEnd()
int GetId() const
The id of this component.
void SetParent(Particle &parent)
unsigned int GetNumberOfParticles() const
ParticleIterator ParticlesBegin()
const Scintillator & GetScintillator(int sId) const
Direct accesor by id.
const Counter & GetCounter(int id) const
Retrieve Counter by id.
#define ERROR(message)
Macro for logging error messages.
Root of the Muon event hierarchy.
void SetSteppingAction(G4UserSteppingAction *const action)