EICInteractionVertexBoost.cxx
Go to the documentation of this file.
1 #include "DDG4/Factories.h"
2 
3 // Framework include files
4 #include "DD4hep/Printout.h"
5 #include "DD4hep/InstanceCount.h"
6 #include "DDG4/Geant4InputHandling.h"
8 
9 #include "Math/Vector4D.h"
10 #include "Math/LorentzRotation.h"
11 #include "Math/Boost.h"
12 #include "Math/BoostX.h"
13 #include "Math/BoostX.h"
14 #include "Math/PxPyPzM4D.h"
15 
16 
17 namespace npdet::sim {
18 
19 using namespace dd4hep::sim;
20 
22 EICInteractionVertexBoost::EICInteractionVertexBoost(Geant4Context* ctxt, const std::string& nam)
23  : Geant4GeneratorAction(ctxt, nam)
24 {
26  //declareProperty("Angle", m_angle = 0);
27  declareProperty("IonCrossingAngle", m_ionCrossingAngle = 0.0166667);
28  declareProperty("ElectronCrossingAngle", m_eCrossingAngle = 0.00833333);
29  declareProperty("Mask", m_mask = 1);
30  m_needsControl = true;
31 }
32 
36 }
37 
40  using namespace ROOT::Math;
41  // boostInteraction(this, inter, m_angle);
42  // int dd4hep::sim::boostInteraction(const Geant4Action* caller,
43  // Geant4PrimaryEvent::Interaction* inter,
44  // double alpha)
45  if (inter) {
46  Geant4PrimaryEvent::Interaction::VertexMap::iterator iv;
47  Geant4PrimaryEvent::Interaction::ParticleMap::iterator ip;
48 
49  double alpha = m_ionCrossingAngle+m_eCrossingAngle;
50 
51  if (inter->locked) {
52  this->abortRun("Locked interactions may not be boosted!",
53  "Cannot boost interactions with a native G4 primary record!");
54  } else if (alpha != 0.0) {
55 
56  double tanalpha = std::tan(alpha/2.0);
57  double gamma = std::sqrt(1 + tanalpha * tanalpha);
58  double betagamma = tanalpha;
59  double beta = betagamma / gamma;
60 
61  std::cout << " beta = " << beta << "\n";
62  std::cout << " gamma = " << gamma << "\n";
63  std::cout << " alpha = " << alpha*180.0/M_PI << " deg\n";
64 
65  BoostX bst(beta);
66  LorentzRotation roty(RotationY(alpha/2.0-m_eCrossingAngle));
67 
68  // Now move begin and end-vertex of all primary vertices accordingly
69  for (iv = inter->vertices.begin(); iv != inter->vertices.end(); ++iv) {
70  for (Geant4Vertex* v : (*iv).second) {
71  XYZTVector v0(v->x,v->y,v->z,v->time);
72  auto v1 = roty(bst*v0);
73  //double t = gamma * v->time + betagamma * v->x / CLHEP::c_light;
74  //double x = gamma * v->x + betagamma * CLHEP::c_light * v->time;
75  //double y = v->y;
76  //double z = v->z;
77  v->x = v1.x();
78  v->y = v1.y();
79  v->z = v1.z();
80  v->time = v1.t();
81  }
82  }
83  // Now move begin and end-vertex of all primary and generator particles accordingly
84  for (ip = inter->particles.begin(); ip != inter->particles.end(); ++ip) {
85  Geant4ParticleHandle p = (*ip).second;
86  //double t = gamma * p->time + betagamma * p->vsx / CLHEP::c_light;
87  //double x = gamma * p->vsx + betagamma * CLHEP::c_light * p->time;
88  //double y = p->vsy;
89  //double z = p->vsz;
90 
91  XYZTVector v0{p->vsx,p->vsy,p->vsz,p->time};
92  auto v1 = roty(bst*v0);
93 
94  PxPyPzMVector p0{p->psx,p->psy,p->psz,p->mass};
95  auto p1 = roty(bst*p0);
96  //double m = p->mass;
97  //double e2 = SQR(p->psx) + SQR(p->psy) + SQR(p->psz) + SQR(m);
98  //double px = betagamma * std::sqrt(e2) + gamma * p->psx;
99  //double py = p->psy;
100  //double pz = p->psz;
101 
102  p->vsx = v1.x();
103  p->vsy = v1.y();
104  p->vsz = v1.z();
105  p->time = v1.t();
106 
107  p->psx = p1.x();
108  p->psy = p1.y();
109  p->psz = p1.z();
110 
111  std::cout << p1 << "\n";
112  std::cout << " theta = " << p1.Theta() << " \n";
113  }
114  }
115  }
116  else {
117  print("+++ No interaction of mask/type %d present.", m_mask);
118  }
119 }
120 
123  typedef std::vector<Geant4PrimaryInteraction*> _I;
124  Geant4PrimaryEvent* evt = context()->event().extension<Geant4PrimaryEvent>();
125 
126  if ( m_mask >= 0 ) {
127  std::cout << " mask is not zero\n";
128  Interaction* inter = evt->get(m_mask);
129  boost(inter);
130  return;
131  }
132  _I interactions = evt->interactions();
133  for(_I::iterator i=interactions.begin(); i != interactions.end(); ++i)
134  boost(*i);
135 }
136 
137 } // namespace npdet::sim
138 
139 namespace dd4hep::sim {
141 }
142 
143 DECLARE_GEANT4ACTION(EICInteractionVertexBoost)
detail::increment< T > increment(T &target)
makes function object that increments using operator ++
Definition: clipp.h:1119
void print(OStream &os, const parsing_result &result)
prints parsing result
Definition: clipp.h:6161
virtual ~EICInteractionVertexBoost()
Default destructor.
virtual void operator()(G4Event *event)
Callback to generate primary particles.
npdet::sim::EICInteractionVertexBoost EICInteractionVertexBoost
EICInteractionVertexBoost()=delete
Inhibit default constructor.
void boost(Interaction *interaction) const
Action routine to boost one single interaction according to the properties.
double m_ionCrossingAngle
Property: The constant Lorentz transformation angle.
Namespace for the Geant4 based simulation part of the AIDA detector description toolkit.
Action class to boost the primary vertex (and all outgoing particles) of a single interaction.
int m_mask
Property: Unique identifier of the interaction to be modified.
detail::decrement< T > decrement(T &target)
makes function object that increments by a fixed amount using operator +=
Definition: clipp.h:1141
Geant4PrimaryInteraction Interaction
Interaction definition.