MdSimulation/Deprecated/MdEdepSimulatorAG/PrimaryGenerator.cc
Go to the documentation of this file.
1 #include "PrimaryGenerator.h"
2 #include "MdEdepSimulator.h"
3 
4 #include <det/Detector.h>
5 #include <mevt/CounterSimData.h>
6 
7 #include <mdet/Counter.h>
8 
9 #include <utl/CoordinateSystem.h>
10 #include <utl/CoordinateSystemPtr.h>
11 #include <utl/Point.h>
12 #include <utl/Particle.h>
13 #include <utl/ReferenceEllipsoid.h>
14 #include <utl/AugerCoordinateSystem.h>
15 
16 #include <cstddef>
17 #include <iostream>
18 #include <sstream>
19 
20 #include <G4Event.hh>
21 #include <G4ParticleGun.hh>
22 #include <G4ParticleDefinition.hh>
23 #include <G4ParticleTable.hh>
24 
25 #include <utl/AugerUnits.h>
26 
27 #include <fwk/CentralConfig.h>
28 #include <utl/ErrorLogger.h>
29 #include <utl/Reader.h>
30 #include <utl/MathConstants.h>
31 
32 using namespace EdepSimulatorAG;
33 using namespace fwk;
34 using namespace utl;
35 using namespace det;
36 using namespace mevt;
37 using std::cout;
38 using std::endl;
39 
41  fParticleGun(new G4ParticleGun(1)),
42  fParticleTable(G4ParticleTable::GetParticleTable())
43 {
44  CentralConfig* theConfig = CentralConfig::GetInstance();
45  Branch topB = theConfig->GetTopBranch("MdEdepSimulator");
46  std::vector<G4double> vScintiSize;
47  Branch scintillatorB = topB.GetChild("scintillator");
48  scintillatorB.GetChild("size").GetData(vScintiSize);
49  fScint_Side_Z = vScintiSize.at(2)/2;
50 }
51 
53 {
54  delete fParticleGun;
55 }
56 
57 void
59 {
60  const mdet::Scintillator* theCurrentDetectorScintillator = EdepSimulator::GetCurrentDetectorScintillator();
62 
63  //Creates coordinate system locally at scint position
64  Point scintPos = theCurrentDetectorScintillator->GetPosition();
65 
66  //Scintillator local coordinate system (particles are loaded in this CS by the MdUnderGroundInjector)
67  CoordinateSystemPtr localCS = theCurrentDetectorScintillator->GetLocalCoordinateSystem();
68  //Retrives particle coordinate system
69  CoordinateSystemPtr csDir = theCurrentParticleIt->GetDirection().GetCoordinateSystem();
70 
71  // set properties and pass to particle gun
72  G4ParticleDefinition* particleDef = fParticleTable->FindParticle(theCurrentParticleIt->GetName());
73 
74  if (!particleDef) {
75  std::ostringstream msg;
76  msg << "Undefined particle type: "
77  << theCurrentParticleIt->GetName();
78  WARNING(msg);
79  return;
80  }
81 
82  double x(0), y(0), z(0);
83  boost::tie(x, y, z) = (theCurrentParticleIt->GetPosition() - scintPos).GetCoordinates(localCS);
84  //force z to be on scintillator top
85  z = fScint_Side_Z;
86 
87  G4cerr
88  << "Scint ID = " << theCurrentDetectorScintillator->GetId()
89  << ", part. type = " << theCurrentParticleIt->GetName()
90  << ", x = " << x/utl::cm << " (cm), "
91  << "y = " << y/utl::cm << " (cm), "
92  << "z = " << z/utl::cm << " (cm), "
93  << "t = " << theCurrentParticleIt->GetTime().GetInterval()/utl::ns << " (ns)"
94  << G4endl;
95 
96  // Convert from Auger units to G4 units
97  G4ThreeVector position(x * CLHEP::m / utl::m, y * CLHEP::m / utl::m, z * CLHEP::m / utl::m);
98 
99  G4ThreeVector direction(theCurrentParticleIt->GetDirection().GetX(localCS), // JMF 01-Oct-2014 Directions should be loaded in scint CS
100  theCurrentParticleIt->GetDirection().GetY(localCS), // JMF 01-Oct-2014
101  theCurrentParticleIt->GetDirection().GetZ(localCS)); // JMF 01-Oct-2014
102 
103  fParticleGun->SetParticleDefinition(particleDef);
104  fParticleGun->SetParticlePosition(position);
105  fParticleGun->SetParticleMomentumDirection(direction);
106 
107  // Convert from Auger units to G4 units
108  fParticleGun->SetParticleEnergy(theCurrentParticleIt->GetKineticEnergy() * CLHEP::eV/utl::eV);
109  fParticleGun->SetParticleTime(theCurrentParticleIt->GetTime().GetInterval() * CLHEP::ns/utl::ns);
110 
111  fParticleGun->GeneratePrimaryVertex(theEvent);
112 }
static const mdet::Scintillator * GetCurrentDetectorScintillator()
Private members.
const double eV
Definition: GalacticUnits.h:35
constexpr double eV
Definition: AugerUnits.h:185
Point object.
Definition: Point.h:32
utl::CoordinateSystemPtr GetLocalCoordinateSystem() const
Local system based on position and configured rotations.
utl::Point GetPosition() const
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Definition: Branch.cc:211
Actual muon-sensitive objects.
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
Class representing a document branch.
Definition: Branch.h:107
boost::indirect_iterator< InternalParticleIterator, utl::Particle & > ParticleIterator
const double ns
#define WARNING(message)
Macro for logging warning messages.
Definition: ErrorLogger.h:163
void GetData(bool &b) const
Overloads of the GetData member template function.
Definition: Branch.cc:644
static mevt::ScintillatorSimData::ParticleIterator GetCurrentParticleIt()
constexpr double cm
Definition: AugerUnits.h:117
Main configuration utility.
Definition: CentralConfig.h:51
constexpr double ns
Definition: AugerUnits.h:162
int GetId() const
The id of this component.
constexpr double m
Definition: AugerUnits.h:121
utl::Branch GetTopBranch(const std::string &id)
Get top branch for moduleConfigLink with given id (XML files)

, generated on Tue Sep 26 2023.