CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/Alignment/LaserAlignmentSimulation/src/LaserPrimaryGeneratorAction.cc

Go to the documentation of this file.
00001 
00009 #include "Alignment/LaserAlignmentSimulation/interface/LaserPrimaryGeneratorAction.h"
00010 #include "SimG4Core/Notification/interface/GenParticleInfo.h"
00011 
00012 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00013 
00014 LaserPrimaryGeneratorAction::LaserPrimaryGeneratorAction(edm::ParameterSet const& theConf) 
00015   : thePhotonEnergy(0),
00016     thenParticleInGun(0),
00017     thenParticle(0),
00018     theLaserBeamsInTEC1(),
00019     theLaserBeamsInTEC2(),
00020     theLaserBeamsInTECTIBTOBTEC()
00021 {
00022   // {{{ LaserPrimaryGeneratorAction constructor
00023 
00024   // get the PhotonEnergy from the parameter set
00025   thePhotonEnergy = theConf.getUntrackedParameter<double>("PhotonEnergy",1.15) * eV;
00026 
00027   // number of particles in the Laser beam
00028   thenParticleInGun = theConf.getUntrackedParameter<int>("NumberOfPhotonsInParticleGun",1);
00029 
00030   // number of particles in one beam. ATTENTION: each beam contains nParticleInGun with the same
00031   // startpoint and direction. nParticle gives the number of particles in the beam with a different
00032   // startpoint. They are used to simulate the gaussian beamprofile of the Laser Beams.
00033   thenParticle = theConf.getUntrackedParameter<int>("NumberOfPhotonsInEachBeam",1);
00034 
00035   // create a messenger for this class
00036 //   theGunMessenger = new LaserPrimaryGeneratorMessenger(this);
00037   
00038   // create the beams in the right endcap
00039   theLaserBeamsInTEC1 = new LaserBeamsTEC1(thenParticleInGun, thenParticle, thePhotonEnergy);
00040 
00041   // create the beams in the left endcap
00042   theLaserBeamsInTEC2 = new LaserBeamsTEC2(thenParticleInGun, thenParticle, thePhotonEnergy);
00043 
00044   // create the beams to connect the TECs with TOB and TIB
00045   theLaserBeamsInTECTIBTOBTEC = new LaserBeamsBarrel(thenParticleInGun, thenParticle, thePhotonEnergy);
00046   // }}}
00047 }
00048 
00049 LaserPrimaryGeneratorAction::~LaserPrimaryGeneratorAction()
00050 {
00051   // {{{ LaserPrimaryGeneratorAction destructor
00052 
00053   if ( theLaserBeamsInTEC1 != 0 ) { delete theLaserBeamsInTEC1; }
00054   if ( theLaserBeamsInTEC2 != 0 ) { delete theLaserBeamsInTEC2; }
00055   if ( theLaserBeamsInTECTIBTOBTEC != 0 ) { delete theLaserBeamsInTECTIBTOBTEC; }
00056   // }}}
00057 }
00058 
00059 void LaserPrimaryGeneratorAction::GeneratePrimaries(G4Event* myEvent)
00060 {
00061   // {{{ GeneratePrimaries (G4Event * myEvent)
00062 
00063   // this function is called at the beginning of an Event in LaserAlignment::upDate(const BeginOfEvent * myEvent)
00064   LogDebug("LaserPrimaryGeneratorAction") << "<LaserPrimaryGeneratorAction::GeneratePrimaries(G4Event*)>: create a new Laser Event";
00065 
00066   // shoot in the right endcap
00067   theLaserBeamsInTEC1->GeneratePrimaries(myEvent);
00068 
00069   // shoot in the left endcap
00070   theLaserBeamsInTEC2->GeneratePrimaries(myEvent);
00071 
00072   // shoot in the barrel
00073   theLaserBeamsInTECTIBTOBTEC->GeneratePrimaries(myEvent);
00074 
00075   // loop over all the generated vertices, get the primaries and set the user information
00076   int theID = 0;
00077 
00078   for (int i = 1; i < myEvent->GetNumberOfPrimaryVertex(); i++)
00079     {
00080       G4PrimaryVertex * theVertex = myEvent->GetPrimaryVertex(i);
00081 
00082       for (int j = 0; j < theVertex->GetNumberOfParticle(); j++)
00083         {
00084           G4PrimaryParticle * thePrimary = theVertex->GetPrimary(j);
00085           
00086           setGeneratorId(thePrimary, theID);
00087           theID++;
00088         }
00089     }
00090   // }}}
00091 }
00092 
00093 void LaserPrimaryGeneratorAction::setGeneratorId(G4PrimaryParticle * aParticle, int ID) const
00094 {
00095   // {{{ SetGeneratorId(G4PrimaryParticle * aParticle, int ID) const
00096 
00097   /* *********************************************************************** */
00098   /*   OSCAR expacts each G4PrimaryParticle to have some User Information    *
00099    *   therefore this function have been implemented                         */
00100   /* *********************************************************************** */
00101 
00102   aParticle->SetUserInformation(new GenParticleInfo(ID));
00103   // }}}
00104 }