MdSimulation/Deprecated/MdGroundPropagatorAG/PrimaryGenerator.cc
Go to the documentation of this file.
1 #include "PrimaryGenerator.h"
2 #include "MdGroundPropagator.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 using namespace GroundPropagatorAG;
28 using namespace fwk;
29 using namespace det;
30 using namespace mevt;
33 using utl::Point;
34 using utl::Particle;
37 using std::cout;
38 using std::endl;
39 
40 
42  fParticleGun(new G4ParticleGun(1)),
43  fParticleTable(G4ParticleTable::GetParticleTable())
44 { }
45 
46 
48 #ifdef AMIGA_DEBUG
49  statf
50 #endif
51 ) :
52  fParticleGun(new G4ParticleGun(1)),
53  fParticleTable(G4ParticleTable::GetParticleTable())
54 {
55 #ifdef AMIGA_DEBUG
56  fStatFile.open(statf.c_str(), std::ios_base::app);
57  fStatFile << "#Id PartName X Y Z(km,SiteCoordSys) x y z(m,CounterCoordSys) Time(ns) Parent\n";
58 #endif
59 }
60 
61 
63 {
64  delete fParticleGun;
65 }
66 
67 
68 void
69 PrimaryGenerator::GeneratePrimaries(G4Event* const theEvent)
70 {
71  const mdet::Counter* theCurrentDetectorCounter = GroundPropagator::GetCurrentDetectorCounter();
73 
74  //Creates coordinate system locally at counter position
75  Point counterPos = theCurrentDetectorCounter->GetPosition();
76  //const int counterId = theCurrentDetectorCounter->GetId();
77  const utl::CoordinateSystemPtr localCS = theCurrentDetectorCounter->GetLocalCoordinateSystem();
78  CoordinateSystemPtr siteCS = det::Detector::GetInstance().GetSiteCoordinateSystem();
79 /*
80  const ReferenceEllipsoid& e = ReferenceEllipsoid::GetWGS84();
81  CoordinateSystemPtr localCS = AugerCoordinateSystem::Create(counterPos, e, siteCS);
82 */
83  //Calculates the centroid of the modules that build up the counter to fix the origin there
84  double xc(0), yc(0), areaTot(0);
85  areaTot = 0;
86  xc = yc = 0;
87  typedef mdet::Counter::ModuleConstIterator ModuleIt;
88  //typedef mdet::Module::ScintillatorConstIterator ScintiIt;
89  for( ModuleIt mIt = theCurrentDetectorCounter->ModulesBegin(); mIt != theCurrentDetectorCounter->ModulesEnd(); ++mIt ) {
90  Point mpos = mIt->GetPosition();
91 
92  double area = mIt->GetArea();
93 
94  areaTot += area;
95 
96  xc += mpos.GetX(theCurrentDetectorCounter->GetLocalCoordinateSystem()) * area;
97  yc += mpos.GetY(theCurrentDetectorCounter->GetLocalCoordinateSystem()) * area;
98  //G4cerr << "Module position ";
99  //G4cerr << "x " << mpos.GetX(theCurrentDetectorCounter->GetLocalCoordinateSystem()) / utl::m << "m, ";
100  //G4cerr << "y " << mpos.GetY(theCurrentDetectorCounter->GetLocalCoordinateSystem()) / utl::m << "m\n";
101  //G4cerr << "area " << area;
102  }
103  xc /= areaTot;
104  yc /= areaTot;
105  //G4cerr << "Centroid position ";
106  //G4cerr << "xc " << xc / utl::m << "m, ";
107  //G4cerr << "yc " << yc / utl::m << "m\n";
108 
109  //Retrives particle coordinate system
110  CoordinateSystemPtr csDir = theCurrentParticleIt->GetDirection().GetCoordinateSystem();
111 
112  // set properties and pass to particle gun
113  G4ParticleDefinition* particleDef = fParticleTable->FindParticle(theCurrentParticleIt->GetName());
114 
115  if (!particleDef) {
116  std::ostringstream msg;
117  msg << "Undefined particle type: "
118  << theCurrentParticleIt->GetName();
119  WARNING(msg);
120  return;
121  }
122 
123  double x(0), y(0), z(0);
124  boost::tie(x, y, z) = (theCurrentParticleIt->GetPosition() - counterPos).GetCoordinates(localCS);
125  x += xc;
126  y += yc;
127  //force z to be on the ground
128  z = 0;
129 
130  double xp(0), yp(0), zp(0);
131  boost::tie(xp, yp, zp) = (theCurrentParticleIt->GetPosition()).GetCoordinates(siteCS);
132  //force z to be on the ground
133  zp = 0;
134 
135 #ifdef AMIGA_DEBUG
136  fStatFile
137  << counterId << " "
138  << theCurrentParticleIt->GetName()
139  << " " << xp/ utl::km
140  << " " << yp/ utl::km
141  << " " << zp/ utl::km
142  << " " << x/ utl::m
143  << " " << y/ utl::m
144  << " " << z/ utl::m
145  << " " << theCurrentParticleIt->GetTime().GetInterval()/utl::ns
146  << " " << theCurrentParticleIt->GetParent().GetType()
147  << G4endl;
148  #endif
149 
150  // Convert from Auger units to G4 units
151  G4ThreeVector position(x * CLHEP::m / utl::m, y * CLHEP::m / utl::m, z * CLHEP::m / utl::m);
152 
153  G4ThreeVector direction(theCurrentParticleIt->GetDirection().GetX(csDir),
154  theCurrentParticleIt->GetDirection().GetY(csDir),
155  theCurrentParticleIt->GetDirection().GetZ(csDir));
156 
157  fParticleGun->SetParticleDefinition(particleDef);
158  fParticleGun->SetParticlePosition(position);
159  fParticleGun->SetParticleMomentumDirection(direction);
160 
161  // Convert from Auger units to G4 units
162  fParticleGun->SetParticleEnergy(theCurrentParticleIt->GetKineticEnergy() * CLHEP::eV/utl::eV);
163  fParticleGun->SetParticleTime(theCurrentParticleIt->GetTime().GetInterval() * CLHEP::ns/utl::ns);
164 
165  fParticleGun->GeneratePrimaryVertex(theEvent);
166 }
boost::indirect_iterator< InternalGrdParticleIterator, utl::Particle & > GrdParticleIterator
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.
constexpr double km
Definition: AugerUnits.h:125
Describes a particle for Simulation.
Definition: Particle.h:26
utl::CoordinateSystemPtr GetLocalCoordinateSystem() const
Local system based on position and configured rotations.
utl::Point GetPosition() const
ModuleConstIterator ModulesEnd() const
Begin iterator for the Modules contained in the Counter.
TransformerConstructor< DerivedCSPolicy > CoordinateSystem
The normal coordinate system type.
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
Reference ellipsoids for UTM transformations.
double GetX(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:206
const double ns
#define WARNING(message)
Macro for logging warning messages.
Definition: ErrorLogger.h:163
Root detector of the muon detector hierarchy.
double GetY(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:209
static mevt::CounterSimData::GrdParticleIterator GetCurrentParticleIt()
static const mdet::Counter * GetCurrentDetectorCounter()
ModuleConstIterator ModulesBegin() const
Begin iterator for the Modules contained in the Counter.
ModuleGroup::ConstIterator ModuleConstIterator
Convenience typedef for const iterator over the contained Module instances.
constexpr double ns
Definition: AugerUnits.h:162
constexpr double m
Definition: AugerUnits.h:121

, generated on Tue Sep 26 2023.