CMS 3D CMS Logo

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