Go to the documentation of this file.00001
00009 #include "Alignment/LaserAlignmentSimulation/interface/LaserBeamsTEC1.h"
00010
00011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00012 #include "FWCore/ServiceRegistry/interface/Service.h"
00013 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
00014
00015 #include "CLHEP/Random/RandGaussQ.h"
00016 #include "globals.hh"
00017 #include "G4ParticleDefinition.hh"
00018 #include "G4ParticleGun.hh"
00019
00020 LaserBeamsTEC1::LaserBeamsTEC1() :
00021 theParticleGun(0),
00022 theDRand48Engine(0)
00023 {
00024 G4int nPhotonsGun = 1;
00025 G4int nPhotonsBeam = 1;
00026 G4double Energy = 1.15 * eV;
00027
00028 LaserBeamsTEC1(nPhotonsGun, nPhotonsBeam, Energy);
00029 }
00030
00031 LaserBeamsTEC1::LaserBeamsTEC1(G4int nPhotonsInGun, G4int nPhotonsInBeam, G4double PhotonEnergy) : thenParticleInGun(0),
00032 thenParticle(0),
00033 thePhotonEnergy(0),
00034 theParticleGun(),
00035 theDRand48Engine()
00036 {
00037
00038
00039
00040
00041
00042 thePhotonEnergy = PhotonEnergy;
00043
00044
00045 thenParticleInGun = nPhotonsInGun;
00046
00047
00048
00049
00050 thenParticle = nPhotonsInBeam;
00051
00052
00053 theParticleGun = new G4ParticleGun(thenParticleInGun);
00054
00055
00056 G4ParticleTable * theParticleTable = G4ParticleTable::GetParticleTable();
00057 G4ParticleDefinition * theOpticalPhoton = theParticleTable->FindParticle("opticalphoton");
00058
00059 theParticleGun->SetParticleDefinition(theOpticalPhoton);
00060 theParticleGun->SetParticleTime(0.0 * ns);
00061 theParticleGun->SetParticlePosition(G4ThreeVector(-500.0 * cm, 0.0 * cm, 0.0 * cm));
00062 theParticleGun->SetParticleMomentumDirection(G4ThreeVector(5.0, 3.0, 0.0));
00063 theParticleGun->SetParticleEnergy(10.0 * keV);
00064 setOptPhotonPolar(90.0);
00065
00066
00067 theDRand48Engine = new CLHEP::DRand48Engine();
00068
00069 }
00070
00071 LaserBeamsTEC1::~LaserBeamsTEC1()
00072 {
00073 if ( theParticleGun != 0 ) { delete theParticleGun; }
00074 if ( theDRand48Engine != 0 ) { delete theDRand48Engine; }
00075 }
00076
00077 void LaserBeamsTEC1::GeneratePrimaries(G4Event* myEvent)
00078 {
00079
00080
00081
00082 edm::Service<edm::RandomNumberGenerator> rng;
00083 unsigned int seed = rng->mySeed();
00084
00085
00086 theDRand48Engine->setSeed(seed);
00087
00088
00089 const G4int nLaserRings = 2;
00090 const G4int nLaserBeams = 8;
00091
00092
00093 G4double LaserPositionZ = 2057.5 * mm;
00094
00095
00096 G4double LaserRingRadius[nLaserRings] = {564.0 * mm, 840.0 * mm};
00097
00098
00099 G4double LaserPhi0 = 0.392699082;
00100
00101
00102 G4double LaserRingSigmaX[nLaserRings] = {0.5 * mm, 0.5 * mm};
00103 G4double LaserRingSigmaY[nLaserRings] = {0.5 * mm, 0.5 * mm};
00104
00105
00106 G4ParticleTable * theParticleTable = G4ParticleTable::GetParticleTable();
00107 G4ParticleDefinition * theOpticalPhoton= theParticleTable->FindParticle("opticalphoton");
00108
00109
00110 for (int theRing = 0; theRing < nLaserRings; theRing++)
00111 {
00112
00113 for (int theBeam = 0; theBeam < nLaserBeams; theBeam++)
00114 {
00115
00116
00117 G4double LaserPositionPhi = LaserPhi0 + G4double(theBeam * G4double(G4double(2 * M_PI) / nLaserBeams));
00118
00119
00120 G4double LaserPositionX = cos(LaserPositionPhi) * LaserRingRadius[theRing];
00121 G4double LaserPositionY = sin(LaserPositionPhi) * LaserRingRadius[theRing];
00122
00123
00124 for (int theParticle = 0; theParticle < thenParticle; theParticle++)
00125 {
00126
00127 CLHEP::RandGaussQ aGaussObjX( *theDRand48Engine, LaserPositionX, LaserRingSigmaX[theRing] );
00128 CLHEP::RandGaussQ aGaussObjY( *theDRand48Engine, LaserPositionY, LaserRingSigmaY[theRing] );
00129
00130 G4double theXPosition = aGaussObjX.fire();
00131 G4double theYPosition = aGaussObjY.fire();
00132 G4double theZPosition = LaserPositionZ;
00133
00134
00135 theParticleGun->SetParticleDefinition(theOpticalPhoton);
00136 theParticleGun->SetParticleTime(0.0 * ns);
00137 theParticleGun->SetParticlePosition(G4ThreeVector(theXPosition, theYPosition, theZPosition));
00138 theParticleGun->SetParticleEnergy(thePhotonEnergy);
00139
00140
00141 for (int theDirection = 0; theDirection < 2; theDirection++)
00142 {
00143
00144 if (theDirection == 0)
00145 {
00146 theParticleGun->SetParticleMomentumDirection(G4ThreeVector(0.0, 0.0, 1.0));
00147
00148 setOptPhotonPolar(90.0);
00149
00150 theParticleGun->GeneratePrimaryVertex(myEvent);
00151 }
00152
00153 if (theDirection == 1)
00154 {
00155 theParticleGun->SetParticleMomentumDirection(G4ThreeVector(0.0, 0.0, -1.0));
00156
00157 setOptPhotonPolar(90.0);
00158
00159 theParticleGun->GeneratePrimaryVertex(myEvent);
00160 }
00161 }
00162 }
00163 }
00164 }
00165 }
00166
00167 void LaserBeamsTEC1::setOptPhotonPolar(G4double Angle)
00168 {
00169
00170
00171
00172
00173
00174
00175 if ( theParticleGun->GetParticleDefinition()->GetParticleName() != "opticalphoton" )
00176 {
00177 edm::LogWarning("SimLaserAlignment:LaserBeamsTEC1") << "<LaserBeamsTEC1::SetOptPhotonPolar()>: WARNING! The ParticleGun is not an optical photon";
00178 return;
00179 }
00180
00181
00182 G4ThreeVector normal(1.0, 0.0, 0.0);
00183 G4ThreeVector kphoton = theParticleGun->GetParticleMomentumDirection();
00184 G4ThreeVector product = normal.cross(kphoton);
00185 G4double modul2 = product * product;
00186
00187 G4ThreeVector e_perpendicular(0.0, 0.0, 1.0);
00188
00189 if ( modul2 > 0.0 ) { e_perpendicular = (1.0 / sqrt(modul2)) * product; }
00190
00191 G4ThreeVector e_parallel = e_perpendicular.cross(kphoton);
00192
00193 G4ThreeVector polar = cos(Angle) * e_parallel + sin(Angle) * e_perpendicular;
00194
00195
00196 theParticleGun->SetParticlePolarization(polar);
00197 }
00198