CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
LaserBeamsBarrel.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  theParticleGun(0),
22  theDRand48Engine(0)
23 {
24  G4int nPhotonsGun = 1;
25  G4int nPhotonsBeam = 1;
26  G4double Energy = 1.15 * eV;
27  // call constructor with options
28  LaserBeamsBarrel(nPhotonsGun, nPhotonsBeam, Energy);
29 }
30 
31 LaserBeamsBarrel::LaserBeamsBarrel(G4int nPhotonsInGun, G4int nPhotonsInBeam, G4double PhotonEnergy) : thenParticleInGun(0),
32  thenParticle(0),
33  thePhotonEnergy(0),
34  theParticleGun(),
35  theDRand48Engine()
36 {
37  /* *********************************************************************** */
38  /* initialize and configure the particle gun */
39  /* *********************************************************************** */
40 
41  // the Photon energy
42  thePhotonEnergy = PhotonEnergy;
43 
44  // number of particles in the Laser beam
45  thenParticleInGun = nPhotonsInGun;
46 
47  // number of particles in one beam. ATTENTION: each beam contains nParticleInGun with the same
48  // startpoint and direction. nParticle gives the number of particles in the beam with a different
49  // startpoint. They are used to simulate the gaussian beamprofile of the Laser Beams.
50  thenParticle = nPhotonsInBeam;
51 
52  // create the particle gun
53  theParticleGun = new G4ParticleGun(thenParticleInGun);
54 
55  // default kinematics
56  G4ParticleTable * theParticleTable = G4ParticleTable::GetParticleTable();
57  G4ParticleDefinition * theOpticalPhoton = theParticleTable->FindParticle("opticalphoton");
58 
59  theParticleGun->SetParticleDefinition(theOpticalPhoton);
60  theParticleGun->SetParticleTime(0.0 * ns);
61  theParticleGun->SetParticlePosition(G4ThreeVector(-500.0 * cm, 0.0 * cm, 0.0 * cm));
62  theParticleGun->SetParticleMomentumDirection(G4ThreeVector(5.0, 3.0, 0.0));
63  theParticleGun->SetParticleEnergy(10.0 * keV);
64  setOptPhotonPolar(90.0);
65 
66  // initialize the random number engine
67  theDRand48Engine = new CLHEP::DRand48Engine();
68 
69 }
70 
72 {
73  if ( theParticleGun != 0 ) { delete theParticleGun; }
74  if ( theDRand48Engine != 0 ) { delete theDRand48Engine; }
75 }
76 
78 {
79  // this function is called at the beginning of an Event in LaserAlignment::upDate(const BeginOfEvent * myEvent)
80 
81  // use the random number generator service of the framework
83  unsigned int seed = rng->mySeed();
84 
85  // set the seed
86  theDRand48Engine->setSeed(seed);
87 
88  // number of LaserBeams
89  const G4int nLaserBeams = 8;
90 
91  // z position of the Laserdiodes (value from design drawings)
92  G4double LaserPositionZ = 1137.0 * mm;
93 
94  // Radius of the Laser ring
95  G4double LaserRingRadius = 564.0 * mm;
96 
97  // phi positions of the Laserdiodes (from CMS Note 2001/053 or from http://abbaneo.home.cern.ch/abbaneo/cms/layout)
98  G4double LaserPhi[nLaserBeams] = { G4double(7.0/112.0) * G4double(2.0 * M_PI),
99  G4double(23.0/112.0) * G4double(2.0 * M_PI),
100  G4double(33.0/112.0) * G4double(2.0 * M_PI),
101  G4double(49.0/112.0) * G4double(2.0 * M_PI),
102  G4double(65.0/112.0) * G4double(2.0 * M_PI),
103  G4double(77.0/112.0) * G4double(2.0 * M_PI),
104  G4double(93.0/112.0) * G4double(2.0 * M_PI),
105  G4double(103.0/112.0) * G4double(2.0 * M_PI) };
106 
107  // width of the LaserBeams
108  G4double LaserBeamSigmaX = 0.5 * mm;
109  G4double LaserBeamSigmaY = 0.5 * mm;
110 
111  // get the definition of the optical photon
112  G4ParticleTable * theParticleTable = G4ParticleTable::GetParticleTable();
113  G4ParticleDefinition * theOpticalPhoton = theParticleTable->FindParticle("opticalphoton");
114 
115  // loop over the LaserBeams
116  for (int theBeam = 0; theBeam < nLaserBeams; theBeam++)
117  {
118  // code for forward and backward beam
119  // calculate x and y position of the current laser diode
120  G4double LaserPositionX = cos(LaserPhi[theBeam]) * LaserRingRadius;
121  G4double LaserPositionY = sin(LaserPhi[theBeam]) * LaserRingRadius;
122 
123  // loop over all the particles in one beam
124  for (int theParticle = 0; theParticle < thenParticle; theParticle++)
125  {
126  // get randomnumbers and calculate the position
127  CLHEP::RandGaussQ aGaussObjX( *theDRand48Engine, LaserPositionX, LaserBeamSigmaX );
128  CLHEP::RandGaussQ aGaussObjY( *theDRand48Engine, LaserPositionY, LaserBeamSigmaY );
129 
130  G4double theXPosition = aGaussObjX.fire();
131  G4double theYPosition = aGaussObjY.fire();
132  G4double theZPosition = LaserPositionZ;
133 
134  // set the properties of the newly created particle
135  theParticleGun->SetParticleDefinition(theOpticalPhoton);
136  theParticleGun->SetParticleTime(0.0 * ns);
137  theParticleGun->SetParticlePosition(G4ThreeVector(theXPosition, theYPosition, theZPosition));
138  theParticleGun->SetParticleEnergy(thePhotonEnergy);
139 
140  // loop over both directions of the beam
141  for (int theDirection = 0; theDirection < 2; theDirection++)
142  {
143  // shoot in both beam directions ...
144  if (theDirection == 0) // shoot in forward direction (+z)
145  {
146  theParticleGun->SetParticleMomentumDirection(G4ThreeVector(0.0, 0.0, 1.0));
147  // set the polarization
148  setOptPhotonPolar(90.0);
149  // generate the particle
150  theParticleGun->GeneratePrimaryVertex(myEvent);
151  }
152  else if (theDirection == 1) // shoot in backward direction (-z)
153  {
154  theParticleGun->SetParticleMomentumDirection(G4ThreeVector(0.0, 0.0, -1.0));
155  // set the polarization
156  setOptPhotonPolar(90.0);
157  // generate the particle
158  theParticleGun->GeneratePrimaryVertex(myEvent);
159  }
160  } // end looop over both beam directions
161  } // end looop over particles in beam
162  } // end loop over beams
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:LaserBeamsBarrel") << "<LaserBeamsBarrel::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 }
void GeneratePrimaries(G4Event *myEvent)
shoot optical photons into the detector at the beginning of an event
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
G4double thePhotonEnergy
LaserBeamsBarrel()
default constructor
G4ParticleGun * theParticleGun
T sqrt(T t)
Definition: SSEVec.h:48
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
~LaserBeamsBarrel()
destructor
#define M_PI
Definition: BFit3D.cc:3
void setOptPhotonPolar(G4double Angle)
set the polarisation of the photons
Definition: Angle.h:17
CLHEP::DRand48Engine * theDRand48Engine
virtual uint32_t mySeed() const =0
Exists for backward compatibility.