CMS 3D CMS Logo

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