Deprecated/UpgradeASCIITests/G4TankSimulatorASCII/G4TankPrimaryGenerator.cc
Go to the documentation of this file.
2 #include "G4TankSimulator.h"
3 
4 #include <det/Detector.h>
5 
6 #include <sevt/StationSimData.h>
7 
8 #include <sdet/Station.h>
9 
10 #include <utl/CoordinateSystem.h>
11 #include <utl/CoordinateSystemPtr.h>
12 #include <utl/Point.h>
13 #include <utl/Particle.h>
14 #include <utl/ReferenceEllipsoid.h>
15 #include <utl/AugerCoordinateSystem.h>
16 
17 #include <cstddef>
18 #include <iostream>
19 #include <sstream>
20 
21 #include <G4Event.hh>
22 #include <G4ParticleGun.hh>
23 #include <G4ParticleDefinition.hh>
24 #include <G4ParticleTable.hh>
25 
26 #include <utl/AugerUnits.h>
27 
28 using namespace G4TankSimulatorASCII;
29 using namespace fwk;
30 using namespace det;
31 using namespace sevt;
34 using utl::Point;
35 using utl::Particle;
38 using std::cout;
39 using std::endl;
40 
41 
43  fParticleGun(new G4ParticleGun(1)),
44  fParticleTable(G4ParticleTable::GetParticleTable())
45 {
46 }
47 
48 
50 {
51  delete fParticleGun;
52 }
53 
54 
55 void
57 {
58  const sdet::Station* theCurrentDetectorStation =
60 
61  sevt::StationSimData::ParticleIterator theCurrentParticleIt =
63 
64 // // temp
65 // sevt::StationSimData::ParticleIterator testit = G4TankSimulator::GetCurrentParticleIt(); // temp
66 // if (testit->GetWeight() > 2)
67 // cout << "testit = " << testit->GetWeight() << endl;
68 // // end temp
69 
70  // Iterate over the particles in the hit station and pass their
71  // properties to the G4ParticleGun:
72 
73  CoordinateSystemPtr siteCS =
74  det::Detector::GetInstance().GetSiteCoordinateSystem();
75 
76  const ReferenceEllipsoid& e = ReferenceEllipsoid::GetWGS84();
77 
78  Point stationPos = theCurrentDetectorStation->GetPosition();
79 
80  CoordinateSystemPtr localCS =
81  AugerCoordinateSystem::Create(stationPos, e, siteCS);
82 
83  CoordinateSystemPtr csDir =
84  theCurrentParticleIt->GetDirection().GetCoordinateSystem();
85 
86  // set properties and pass to particle gun
87 
88  G4ParticleDefinition* particleDef =
89  fParticleTable->FindParticle(theCurrentParticleIt->GetName());
90 
91  if (!particleDef) {
92  std::ostringstream msg;
93  msg << "Undefined particle type: "
94  << theCurrentParticleIt->GetName();
95  WARNING(msg);
96  return;
97  }
98 
99  double x, y, z;
100  boost::tie(x, y, z) =
101  (theCurrentParticleIt->GetPosition() - stationPos).GetCoordinates(localCS);
102 
103  // Convert from Auger units to G4 units
104  G4ThreeVector position(x * CLHEP::m / utl::m, y * CLHEP::m / utl::m, z * CLHEP::m / utl::m);
105 
106  G4ThreeVector direction(theCurrentParticleIt->GetDirection().GetX(csDir),
107  theCurrentParticleIt->GetDirection().GetY(csDir),
108  theCurrentParticleIt->GetDirection().GetZ(csDir));
109 
110  fParticleGun->SetParticleDefinition(particleDef);
111  fParticleGun->SetParticlePosition(position);
112  fParticleGun->SetParticleMomentumDirection(direction);
113 
114  // Convert from Auger units to G4 units
115  fParticleGun->SetParticleEnergy(theCurrentParticleIt->GetKineticEnergy() * CLHEP::eV / utl::eV);
116  fParticleGun->SetParticleTime(theCurrentParticleIt->GetTime().GetInterval());
117 
118  fParticleGun->GeneratePrimaryVertex(theEvent);
119 }
const double eV
Definition: GalacticUnits.h:35
constexpr double eV
Definition: AugerUnits.h:185
Point object.
Definition: Point.h:32
AugerCoordinateSystemConstructor< DerivedCSPolicy > AugerCoordinateSystem
The normal coordinate system type.
Detector description interface for Station-related data.
Describes a particle for Simulation.
Definition: Particle.h:26
TransformerConstructor< DerivedCSPolicy > CoordinateSystem
The normal coordinate system type.
utl::Point GetPosition() const
Tank position.
ParticleVector::iterator ParticleIterator
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
Reference ellipsoids for UTM transformations.
#define WARNING(message)
Macro for logging warning messages.
Definition: ErrorLogger.h:163
constexpr double m
Definition: AugerUnits.h:121

, generated on Tue Sep 26 2023.