CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/SimG4Core/CustomPhysics/src/DummyChargeFlipProcess.cc

Go to the documentation of this file.
00001 #include <iostream>
00002 #include "G4ParticleTable.hh"
00003 #include "Randomize.hh"
00004 
00005 #include "SimG4Core/CustomPhysics/interface/DummyChargeFlipProcess.h"
00006 
00007 DummyChargeFlipProcess::
00008 DummyChargeFlipProcess(const G4String& processName) : 
00009       G4HadronicProcess(processName)
00010 {
00011   AddDataSet(new G4HadronElasticDataSet);
00012 }
00013 
00014 DummyChargeFlipProcess::~DummyChargeFlipProcess()
00015 {
00016 }
00017  
00018 
00019 void DummyChargeFlipProcess::
00020 BuildPhysicsTable(const G4ParticleDefinition& aParticleType)
00021 {
00022    if (!G4HadronicProcess::GetCrossSectionDataStore()) {
00023       return;
00024    }
00025    G4HadronicProcess::GetCrossSectionDataStore()->BuildPhysicsTable(aParticleType);
00026 }
00027 
00028 
00029 G4double DummyChargeFlipProcess::
00030 GetMicroscopicCrossSection(
00031       const G4DynamicParticle* /*aParticle*/, const G4Element* element, G4double /*aTemp*/)
00032 {
00033 
00034    return 30*millibarn*element->GetN(); 
00035 }
00036 
00037 
00038 G4bool
00039 DummyChargeFlipProcess::
00040 IsApplicable(const G4ParticleDefinition& aParticleType)
00041 {
00042    if(aParticleType.GetParticleType()  == "rhadron")
00043     return true;
00044   else
00045     return false;
00046 }
00047 
00048 
00049 void 
00050 DummyChargeFlipProcess::
00051 DumpPhysicsTable(const G4ParticleDefinition& /*aParticleType*/)
00052 {
00053 
00054 }
00055 
00056 
00057 G4VParticleChange *DummyChargeFlipProcess::PostStepDoIt(
00058   const G4Track &aTrack, const G4Step &/*aStep*/)
00059 {
00060   G4ParticleChange * pc = new G4ParticleChange();
00061   pc->Initialize(aTrack);
00062   const G4DynamicParticle* aParticle = aTrack.GetDynamicParticle();
00063   G4ParticleDefinition* aParticleDef = aParticle->GetDefinition();
00064 
00065   G4double   ParentEnergy  = aParticle->GetTotalEnergy();
00066   G4ThreeVector ParentDirection(aParticle->GetMomentumDirection());
00067 
00068   G4double energyDeposit = 0.0;
00069   G4double finalGlobalTime = aTrack.GetGlobalTime();
00070 
00071   G4int numberOfSecondaries = 1;
00072   pc->SetNumberOfSecondaries(numberOfSecondaries);
00073   const G4TouchableHandle thand = aTrack.GetTouchableHandle();
00074 
00075      // get current position of the track
00076      aTrack.GetPosition();
00077      // create a new track object
00078       G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
00079       float randomParticle = G4UniformRand();
00080       G4ParticleDefinition * newType = aParticleDef;
00081       if(randomParticle < 0.333)
00082         newType=particleTable->FindParticle(1009213);
00083       else if(randomParticle > 0.667)
00084         newType=particleTable->FindParticle(-1009213);
00085       else
00086         newType=particleTable->FindParticle(1009113);
00087      
00088       std::cout << "RHADRON: New charge = " << newType->GetPDGCharge() << std::endl;
00089        
00090      G4DynamicParticle * newP =  new G4DynamicParticle(newType,ParentDirection,ParentEnergy);
00091      G4Track* secondary = new G4Track( newP ,
00092                                       finalGlobalTime ,
00093                                        aTrack.GetPosition()
00094      );
00095      // switch on good for tracking flag
00096      secondary->SetGoodForTrackingFlag();
00097      secondary->SetTouchableHandle(thand);
00098      // add the secondary track in the List
00099      pc->AddSecondary(secondary);
00100 
00101   // Kill the parent particle
00102   pc->ProposeTrackStatus( fStopAndKill ) ;
00103   pc->ProposeLocalEnergyDeposit(energyDeposit); 
00104   pc->ProposeGlobalTime( finalGlobalTime );
00105   // Clear NumberOfInteractionLengthLeft
00106   ClearNumberOfInteractionLengthLeft();
00107 
00108 
00109 
00110    return pc;
00111 
00112 }
00113