CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/Alignment/LaserAlignmentSimulation/src/LaserBeamsBarrel.cc

Go to the documentation of this file.
00001 
00009 #include "Alignment/LaserAlignmentSimulation/interface/LaserBeamsBarrel.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"                        // Global Constants and typedefs
00017 #include "G4ParticleDefinition.hh"
00018 #include "G4ParticleGun.hh"
00019 
00020 LaserBeamsBarrel::LaserBeamsBarrel() :
00021   theParticleGun(0),
00022   theDRand48Engine(0)
00023 {
00024   G4int nPhotonsGun = 1;
00025   G4int nPhotonsBeam = 1;
00026   G4double Energy = 1.15 * eV;
00027   // call constructor with options
00028   LaserBeamsBarrel(nPhotonsGun, nPhotonsBeam, Energy);
00029 }
00030 
00031 LaserBeamsBarrel::LaserBeamsBarrel(G4int nPhotonsInGun, G4int nPhotonsInBeam, G4double PhotonEnergy) : thenParticleInGun(0),
00032                                                                                                        thenParticle(0),
00033                                                                                                        thePhotonEnergy(0),
00034                                                                                                        theParticleGun(),
00035                                                                                                        theDRand48Engine()
00036 {
00037   /* *********************************************************************** */
00038   /*  initialize and configure the particle gun                              */
00039   /* *********************************************************************** */
00040 
00041   // the Photon energy
00042   thePhotonEnergy = PhotonEnergy;
00043 
00044   // number of particles in the Laser beam
00045   thenParticleInGun = nPhotonsInGun;
00046 
00047   // number of particles in one beam. ATTENTION: each beam contains nParticleInGun with the same
00048   // startpoint and direction. nParticle gives the number of particles in the beam with a different
00049   // startpoint. They are used to simulate the gaussian beamprofile of the Laser Beams.
00050   thenParticle = nPhotonsInBeam;
00051 
00052   // create the particle gun
00053   theParticleGun = new G4ParticleGun(thenParticleInGun);
00054 
00055   // default kinematics
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   // initialize the random number engine
00067   theDRand48Engine = new CLHEP::DRand48Engine();
00068 
00069 }
00070 
00071 LaserBeamsBarrel::~LaserBeamsBarrel()
00072 {
00073   if ( theParticleGun != 0 ) { delete theParticleGun; }
00074   if ( theDRand48Engine != 0 ) { delete theDRand48Engine; }
00075 }
00076 
00077 void LaserBeamsBarrel::GeneratePrimaries(G4Event * myEvent)
00078 {
00079   // this function is called at the beginning of an Event in LaserAlignment::upDate(const BeginOfEvent * myEvent)
00080 
00081   // use the random number generator service of the framework
00082   edm::Service<edm::RandomNumberGenerator> rng;
00083   unsigned int seed = rng->mySeed();
00084 
00085   // set the seed
00086   theDRand48Engine->setSeed(seed);
00087 
00088   // number of LaserBeams
00089   const G4int nLaserBeams = 8;
00090 
00091   // z position of the Laserdiodes (value from design drawings)
00092   G4double LaserPositionZ = 1137.0 * mm; 
00093 
00094   // Radius of the Laser ring
00095   G4double LaserRingRadius = 564.0 * mm;
00096 
00097   // phi positions of the Laserdiodes (from CMS Note 2001/053 or from https://abbaneo.home.cern.ch/abbaneo/cms/layout)
00098   G4double LaserPhi[nLaserBeams] = { G4double(7.0/112.0)   * G4double(2.0 * M_PI),
00099                                      G4double(23.0/112.0)  * G4double(2.0 * M_PI),
00100                                      G4double(33.0/112.0)  * G4double(2.0 * M_PI),
00101                                      G4double(49.0/112.0)  * G4double(2.0 * M_PI),
00102                                      G4double(65.0/112.0)  * G4double(2.0 * M_PI),
00103                                      G4double(77.0/112.0)  * G4double(2.0 * M_PI),
00104                                      G4double(93.0/112.0)  * G4double(2.0 * M_PI),
00105                                      G4double(103.0/112.0) * G4double(2.0 * M_PI) };
00106 
00107   // width of the LaserBeams
00108   G4double LaserBeamSigmaX = 0.5 * mm;
00109   G4double LaserBeamSigmaY = 0.5 * mm;
00110 
00111   // get the definition of the optical photon
00112   G4ParticleTable * theParticleTable = G4ParticleTable::GetParticleTable();
00113   G4ParticleDefinition * theOpticalPhoton = theParticleTable->FindParticle("opticalphoton");
00114 
00115   // loop over the LaserBeams
00116   for (int theBeam = 0; theBeam < nLaserBeams; theBeam++)
00117     {
00118       // code for forward and backward beam
00119       // calculate x and y position of the current laser diode
00120       G4double LaserPositionX = cos(LaserPhi[theBeam]) * LaserRingRadius;
00121       G4double LaserPositionY = sin(LaserPhi[theBeam]) * LaserRingRadius;
00122 
00123       // loop over all the particles in one beam
00124       for (int theParticle = 0; theParticle < thenParticle; theParticle++)
00125         {
00126           // get randomnumbers  and calculate the position
00127           CLHEP::RandGaussQ aGaussObjX( *theDRand48Engine, LaserPositionX, LaserBeamSigmaX );
00128           CLHEP::RandGaussQ aGaussObjY( *theDRand48Engine, LaserPositionY, LaserBeamSigmaY );
00129           
00130           G4double theXPosition = aGaussObjX.fire();
00131           G4double theYPosition = aGaussObjY.fire();
00132           G4double theZPosition = LaserPositionZ;
00133 
00134           // set the properties of the newly created particle
00135           theParticleGun->SetParticleDefinition(theOpticalPhoton);
00136           theParticleGun->SetParticleTime(0.0 * ns);
00137           theParticleGun->SetParticlePosition(G4ThreeVector(theXPosition, theYPosition, theZPosition));
00138           theParticleGun->SetParticleEnergy(thePhotonEnergy);
00139 
00140           // loop over both directions of the beam
00141           for (int theDirection = 0; theDirection < 2; theDirection++)
00142             {
00143               // shoot in both beam directions ...
00144               if (theDirection == 0) // shoot in forward direction (+z)
00145                 {
00146                   theParticleGun->SetParticleMomentumDirection(G4ThreeVector(0.0, 0.0, 1.0));
00147                   // set the polarization
00148                   setOptPhotonPolar(90.0);
00149                   // generate the particle
00150                   theParticleGun->GeneratePrimaryVertex(myEvent);
00151                 }
00152               else if (theDirection == 1) // shoot in backward direction (-z)
00153                 {
00154                   theParticleGun->SetParticleMomentumDirection(G4ThreeVector(0.0, 0.0, -1.0));
00155                   // set the polarization
00156                   setOptPhotonPolar(90.0);
00157                   // generate the particle
00158                   theParticleGun->GeneratePrimaryVertex(myEvent);
00159                 }
00160             } // end looop over both beam directions
00161         } // end looop over particles in beam
00162     } // end loop over beams
00163 }
00164 
00165 void LaserBeamsBarrel::setOptPhotonPolar(G4double Angle)
00166 {
00167   /* *********************************************************************** */
00168   /*   to get optical processes working properly, you have to make sure      *
00169    *   that the photon polarisation is defined.                              */
00170   /* *********************************************************************** */
00171 
00172   // first check if we have an optical photon
00173   if ( theParticleGun->GetParticleDefinition()->GetParticleName() != "opticalphoton" )
00174     { 
00175       edm::LogWarning("SimLaserAlignment:LaserBeamsBarrel") << "<LaserBeamsBarrel::setOptPhotonPolar()>: WARNING! The ParticleGun is not an optical photon";
00176       return;
00177     }
00178 
00179 //   G4cout << "  AC1CMS: The ParticleGun is an " << theParticleGun->GetParticleDefinition()->GetParticleName();
00180   G4ThreeVector normal(1.0, 0.0, 0.0);
00181   G4ThreeVector kphoton = theParticleGun->GetParticleMomentumDirection();
00182   G4ThreeVector product = normal.cross(kphoton);
00183   G4double modul2 = product * product;
00184 
00185   G4ThreeVector e_perpendicular(0.0, 0.0, 1.0);
00186   
00187   if ( modul2 > 0.0 ) { e_perpendicular = (1.0 / sqrt(modul2)) * product; }
00188   
00189   G4ThreeVector e_parallel = e_perpendicular.cross(kphoton);
00190 
00191   G4ThreeVector polar = cos(Angle) * e_parallel + sin(Angle) * e_perpendicular;
00192   
00193 //   G4cout << ", the polarization = " << polar << G4endl;
00194   theParticleGun->SetParticlePolarization(polar);
00195 }