CMS 3D CMS Logo

LaserBeamsTEC1.cc
Go to the documentation of this file.
1 
10 
14 
15 #include <CLHEP/Random/RandGaussQ.h>
16 #include <CLHEP/Units/SystemOfUnits.h>
17 #include "G4ParticleDefinition.hh"
18 #include "G4ParticleGun.hh"
19 #include "globals.hh" // Global Constants and typedefs
20 
21 LaserBeamsTEC1::LaserBeamsTEC1() : theParticleGun(nullptr), theDRand48Engine(nullptr) {
22  G4int nPhotonsGun = 1;
23  G4int nPhotonsBeam = 1;
24  G4double Energy = 1.15 * CLHEP::eV;
25  // call constructor with options
26  LaserBeamsTEC1(nPhotonsGun, nPhotonsBeam, Energy);
27 }
28 
29 LaserBeamsTEC1::LaserBeamsTEC1(G4int nPhotonsInGun, G4int nPhotonsInBeam, G4double PhotonEnergy)
30  : thenParticleInGun(0), thenParticle(0), thePhotonEnergy(0) {
31  /* *********************************************************************** */
32  /* initialize and configure the particle gun */
33  /* *********************************************************************** */
34 
35  // the Photon energy
36  thePhotonEnergy = PhotonEnergy;
37 
38  // number of particles in the Laser beam
39  thenParticleInGun = nPhotonsInGun;
40 
41  // number of particles in one beam. ATTENTION: each beam contains
42  // nParticleInGun with the same startpoint and direction. nParticle gives the
43  // number of particles in the beam with a different startpoint. They are used
44  // to simulate the gaussian beamprofile of the Laser Beams.
45  thenParticle = nPhotonsInBeam;
46 
47  // create the particle gun
48  theParticleGun = new G4ParticleGun(thenParticleInGun);
49 
50  // default kinematics
51  G4ParticleTable *theParticleTable = G4ParticleTable::GetParticleTable();
52  G4ParticleDefinition *theOpticalPhoton = theParticleTable->FindParticle("opticalphoton");
53 
54  theParticleGun->SetParticleDefinition(theOpticalPhoton);
55  theParticleGun->SetParticleTime(0.0 * CLHEP::ns);
56  theParticleGun->SetParticlePosition(G4ThreeVector(-500.0 * CLHEP::cm, 0.0 * CLHEP::cm, 0.0 * CLHEP::cm));
57  theParticleGun->SetParticleMomentumDirection(G4ThreeVector(5.0, 3.0, 0.0));
58  theParticleGun->SetParticleEnergy(10.0 * CLHEP::keV);
59  setOptPhotonPolar(90.0);
60 
61  // initialize the random number engine
62  theDRand48Engine = new CLHEP::DRand48Engine();
63 }
64 
66  if (theParticleGun != nullptr) {
67  delete theParticleGun;
68  }
69  if (theDRand48Engine != nullptr) {
70  delete theDRand48Engine;
71  }
72 }
73 
75  // this function is called at the beginning of an Event in
76  // LaserAlignment::upDate(const BeginOfEvent * myEvent)
77 
78  // use the random number generator service of the framework
80  unsigned int seed = rng->mySeed();
81 
82  // set the seed
83  theDRand48Engine->setSeed(seed);
84 
85  // number of LaserRings and Laserdiodes
86  const G4int nLaserRings = 2;
87  const G4int nLaserBeams = 8;
88 
89  // z position of the sixth Tracker Endcap Disc, where the Laserdiodes are
90  // positioned
91  using CLHEP::mm;
92  G4double LaserPositionZ = 2057.5 * mm;
93 
94  // Radius of the inner and outer Laser ring
95  G4double LaserRingRadius[nLaserRings] = {564.0 * mm, 840.0 * mm};
96 
97  // phi position of the first Laserdiode
98  G4double LaserPhi0 = 0.392699082;
99 
100  // width of the LaserBeams
101  G4double LaserRingSigmaX[nLaserRings] = {0.5 * mm, 0.5 * mm};
102  G4double LaserRingSigmaY[nLaserRings] = {0.5 * mm, 0.5 * mm};
103 
104  // get the definition of the optical photon
105  G4ParticleTable *theParticleTable = G4ParticleTable::GetParticleTable();
106  G4ParticleDefinition *theOpticalPhoton = theParticleTable->FindParticle("opticalphoton");
107 
108  // loop over the LaserRings
109  for (int theRing = 0; theRing < nLaserRings; theRing++) {
110  // loop over the LaserBeams
111  for (int theBeam = 0; theBeam < nLaserBeams; theBeam++) {
112  // code for forward and backward beam
113  // calculate the right phi for the current beam
114  G4double LaserPositionPhi = LaserPhi0 + G4double(theBeam * G4double(G4double(2 * M_PI) / nLaserBeams));
115 
116  // calculate x and y position for the current beam
117  G4double LaserPositionX = cos(LaserPositionPhi) * LaserRingRadius[theRing];
118  G4double LaserPositionY = sin(LaserPositionPhi) * LaserRingRadius[theRing];
119 
120  // loop over all the particles in one beam
121  for (int theParticle = 0; theParticle < thenParticle; theParticle++) {
122  // get randomnumbers and calculate the position
123  CLHEP::RandGaussQ aGaussObjX(*theDRand48Engine, LaserPositionX, LaserRingSigmaX[theRing]);
124  CLHEP::RandGaussQ aGaussObjY(*theDRand48Engine, LaserPositionY, LaserRingSigmaY[theRing]);
125 
126  G4double theXPosition = aGaussObjX.fire();
127  G4double theYPosition = aGaussObjY.fire();
128  G4double theZPosition = LaserPositionZ;
129 
130  // set the properties of the newly created particle
131  theParticleGun->SetParticleDefinition(theOpticalPhoton);
132  theParticleGun->SetParticleTime(0.0 * CLHEP::ns);
133  theParticleGun->SetParticlePosition(G4ThreeVector(theXPosition, theYPosition, theZPosition));
134  theParticleGun->SetParticleEnergy(thePhotonEnergy);
135 
136  // loop over both directions of the beam
137  for (int theDirection = 0; theDirection < 2; theDirection++) {
138  // shoot in both beam directions ...
139  if (theDirection == 0) // shoot in forward direction (+z)
140  {
141  theParticleGun->SetParticleMomentumDirection(G4ThreeVector(0.0, 0.0, 1.0));
142  // set the polarization
143  setOptPhotonPolar(90.0);
144  // generate the particle
145  theParticleGun->GeneratePrimaryVertex(myEvent);
146  }
147 
148  if (theDirection == 1) // shoot in backward direction (-z)
149  {
150  theParticleGun->SetParticleMomentumDirection(G4ThreeVector(0.0, 0.0, -1.0));
151  // set the polarization
152  setOptPhotonPolar(90.0);
153  // generate the particle
154  theParticleGun->GeneratePrimaryVertex(myEvent);
155  }
156  } // end loop over both beam directions
157  } // end loop over particles in beam
158  } // end loop over beams
159  } // end loop over rings
160 }
161 
162 void LaserBeamsTEC1::setOptPhotonPolar(G4double Angle) {
163  /* *********************************************************************** */
164  /* to get optical processes working properly, you have to make sure *
165  * that the photon polarisation is defined. */
166  /* *********************************************************************** */
167 
168  // first check if we have an optical photon
169  if (theParticleGun->GetParticleDefinition()->GetParticleName() != "opticalphoton") {
170  edm::LogWarning("SimLaserAlignment:LaserBeamsTEC1")
171  << "<LaserBeamsTEC1::SetOptPhotonPolar()>: WARNING! The ParticleGun is "
172  "not an optical photon";
173  return;
174  }
175 
176  // G4cout << " AC1CMS: The ParticleGun is an " <<
177  // theParticleGun->GetParticleDefinition()->GetParticleName();
178  G4ThreeVector normal(1.0, 0.0, 0.0);
179  G4ThreeVector kphoton = theParticleGun->GetParticleMomentumDirection();
180  G4ThreeVector product = normal.cross(kphoton);
181  G4double modul2 = product * product;
182 
183  G4ThreeVector e_perpendicular(0.0, 0.0, 1.0);
184 
185  if (modul2 > 0.0) {
186  e_perpendicular = (1.0 / sqrt(modul2)) * product;
187  }
188 
189  G4ThreeVector e_parallel = e_perpendicular.cross(kphoton);
190 
191  G4ThreeVector polar = cos(Angle) * e_parallel + sin(Angle) * e_perpendicular;
192 
193  // G4cout << ", the polarization = " << polar << G4endl;
194  theParticleGun->SetParticlePolarization(polar);
195 }
static const char * normal
Definition: DMRtrends.cc:35
G4double thePhotonEnergy
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
void GeneratePrimaries(G4Event *myEvent) override
shoot optical photons into the detector at the beginning of an event
virtual std::uint32_t mySeed() const =0
T sqrt(T t)
Definition: SSEVec.h:23
G4int thenParticleInGun
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
LaserBeamsTEC1()
default constructor
CLHEP::DRand48Engine * theDRand48Engine
#define M_PI
~LaserBeamsTEC1() override
destructor
Log< level::Warning, false > LogWarning
void setOptPhotonPolar(G4double Angle)
set the polarisation of the photons
G4ParticleGun * theParticleGun