You are on page 1of 17

#include "ExN02ChamberParameterisation.

hh"
#include "G4VPhysicalVolume.hh" #include "G4ThreeVector.hh" #include "G4Box.hh" //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... ExN02ChamberParameterisation::ExN02ChamberParameterisation( G4int NoChambers, G4double startZ, // Z of center of first G4double spacingZ, // Z spacing of centers G4double widthChamber, G4double lengthInitial, G4double lengthFinal ) { fNoChambers = NoChambers; fStartZ = startZ; fHalfWidth = widthChamber*0.5; fSpacing = spacingZ; fHalfLengthFirst = 0.5 * lengthInitial; // fHalfLengthLast = lengthFinal; if( NoChambers > 0 ) { fHalfLengthIncr = 0.5 * (lengthFinal-lengthInitial)/NoChambers; if (spacingZ < widthChamber) { G4Exception("ExN02ChamberParameterisation construction: Width>Spacing"); } } } ExN02ChamberParameterisation::~ExN02ChamberParameterisation() {} void ExN02ChamberParameterisation::ComputeTransformation (const G4int copyNo, G4VPhysicalVolume* physVol) const { G4double Zposition= fStartZ + (copyNo+1) * fSpacing; G4ThreeVector origin(0,0,Zposition); physVol->SetTranslation(origin); physVol->SetRotation(0); } void ExN02ChamberParameterisation::ComputeDimensions (G4Box& trackerChamber, const G4int copyNo, const G4VPhysicalVolume*) const { G4double halfLength= fHalfLengthFirst + copyNo * fHalfLengthIncr; trackerChamber.SetXHalfLength(halfLength); trackerChamber.SetYHalfLength(halfLength); trackerChamber.SetZHalfLength(fHalfWidth); }

#include "ExN02DetectorConstruction.hh"
#include #include #include #include "ExN02DetectorMessenger.hh" "ExN02ChamberParameterisation.hh" "ExN02MagneticField.hh" "ExN02TrackerSD.hh"

#include "G4Material.hh" #include "G4Box.hh" #include "G4LogicalVolume.hh"

#include #include #include #include #include

"G4PVPlacement.hh" "G4PVParameterised.hh" "G4SDManager.hh" "G4GeometryTolerance.hh" "G4GeometryManager.hh"

#include "G4UserLimits.hh" #include "G4VisAttributes.hh" #include "G4Colour.hh" #include "G4ios.hh" //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... ExN02DetectorConstruction::ExN02DetectorConstruction() :solidWorld(0), logicWorld(0), physiWorld(0), solidTarget(0), logicTarget(0), physiTarget(0), solidTracker(0),logicTracker(0),physiTracker(0), solidChamber(0),logicChamber(0),physiChamber(0), TargetMater(0), ChamberMater(0),chamberParam(0), stepLimit(0), fpMagField(0), fWorldLength(0.), fTargetLength(0.), fTrackerLength(0.), NbOfChambers(0) , ChamberWidth(0.), ChamberSpacing(0.) { fpMagField = new ExN02MagneticField(); detectorMessenger = new ExN02DetectorMessenger(this); } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... ExN02DetectorConstruction::~ExN02DetectorConstruction() { delete fpMagField; delete stepLimit; delete chamberParam; delete detectorMessenger; } G4VPhysicalVolume* ExN02DetectorConstruction::Construct() { //--------- Material definition --------G4double a, z; G4double density, temperature, pressure; G4int nel; //Air G4Element* N = new G4Element("Nitrogen", "N", z=7., a= 14.01*g/mole); G4Element* O = new G4Element("Oxygen" , "O", z=8., a= 16.00*g/mole); G4Material* Air = new G4Material("Air", density= 1.29*mg/cm3, nel=2); Air->AddElement(N, 70*perCent); Air->AddElement(O, 30*perCent); //Lead G4Material* Pb = new G4Material("Lead", z=82., a= 207.19*g/mole, density= 11.35*g/cm3); //Xenon gas G4Material* Xenon = new G4Material("XenonGas", z=54., a=131.29*g/mole, density= 5.458*mg/cm3, kStateGas, temperature= 293.15*kelvin, pressure= 1*atmosphere); // Print all the materials defined.

// G4cout << G4endl << "The materials defined are : " << G4endl << G4endl; G4cout << *(G4Material::GetMaterialTable()) << G4endl; //--------- Sizes of the principal geometrical components (solids) NbOfChambers = 5; ChamberWidth = 20*cm; ChamberSpacing = 80*cm; fTrackerLength = (NbOfChambers+1)*ChamberSpacing; // Full length of Tracker fTargetLength = 5.0 * cm; // Full length of Target TargetMater = Pb; ChamberMater = Xenon; fWorldLength= 1.2 *(fTargetLength+fTrackerLength); G4double targetSize = 0.5*fTargetLength; G4double trackerSize = 0.5*fTrackerLength; // Half length of the Target // Half length of the Tracker ---------

//--------- Definitions of Solids, Logical Volumes, Physical Volumes --------//-----------------------------// World //-----------------------------G4double HalfWorldLength = 0.5*fWorldLength; G4GeometryManager::GetInstance()->SetWorldMaximumExtent(fWorldLength); G4cout << "Computed tolerance = " << G4GeometryTolerance::GetInstance()->GetSurfaceTolerance()/mm << " mm" << G4endl; solidWorld= new G4Box("world",HalfWorldLength,HalfWorldLength,HalfWorldLength); logicWorld= new G4LogicalVolume( solidWorld, Air, "World", 0, 0, 0); // Must place the World Physical volume unrotated // physiWorld = new G4PVPlacement(0, // G4ThreeVector(), // logicWorld, // "World", // its name 0, // false, // 0); // //-----------------------------// Target //-----------------------------G4ThreeVector positionTarget = G4ThreeVector(0,0,-(targetSize+trackerSize)); solidTarget = new G4Box("target",targetSize,targetSize,targetSize); logicTarget = new G4LogicalVolume(solidTarget,TargetMater,"Target",0,0,0); physiTarget = new G4PVPlacement(0, // no rotation positionTarget, // at (x,y,z) logicTarget, // its logical volume "Target", // its name logicWorld, // its mother volume false, // no boolean operations 0); // copy number G4cout << "Target is " << fTargetLength/cm << " cm of " << TargetMater->GetName() << G4endl; at (0,0,0). no rotation at (0,0,0) its logical volume its mother volume no boolean operations copy number

//-----------------------------// Tracker //-----------------------------G4ThreeVector positionTracker = G4ThreeVector(0,0,0); solidTracker = new G4Box("tracker",trackerSize,trackerSize,trackerSize); logicTracker = new G4LogicalVolume(solidTracker , Air, "Tracker",0,0,0); physiTracker = new G4PVPlacement(0, // no rotation positionTracker, // at (x,y,z) logicTracker, // its logical volume "Tracker", // its name logicWorld, // its mother volume false, // no boolean operations 0); // copy number //-----------------------------// Tracker segments //-----------------------------// // An example of Parameterised volumes // dummy values for G4Box -- modified by parameterised volume solidChamber = new G4Box("chamber", 100*cm, 100*cm, 10*cm); logicChamber = new G4LogicalVolume(solidChamber,ChamberMater,"Chamber",0,0,0); G4double firstPosition = -trackerSize + 0.5*ChamberWidth; G4double firstLength = fTrackerLength/10; G4double lastLength = fTrackerLength; chamberParam = new ExN02ChamberParameterisation( NbOfChambers, // NoChambers firstPosition, // Z of center of first ChamberSpacing, // Z spacing of centers ChamberWidth, // Width Chamber firstLength, // lengthInitial lastLength); // lengthFinal // dummy value : kZAxis -- modified by parameterised volume // physiChamber = new G4PVParameterised( "Chamber", // their name logicChamber, // their logical volume logicTracker, // Mother logical volume kZAxis, // Are placed along this axis NbOfChambers, // Number of chambers chamberParam); // The parametrisation G4cout << "There are " << NbOfChambers << " chambers in the tracker region. " << "The chambers are " << ChamberWidth/mm << " mm of " << ChamberMater->GetName() << "\n The distance between chamber is " << ChamberSpacing/cm << " cm" << G4endl; //-----------------------------------------------// Sensitive detectors //-----------------------------------------------G4SDManager* SDman = G4SDManager::GetSDMpointer(); G4String trackerChamberSDname = "ExN02/TrackerChamberSD"; ExN02TrackerSD* aTrackerSD = new ExN02TrackerSD( trackerChamberSDname ); SDman->AddNewDetector( aTrackerSD ); logicChamber->SetSensitiveDetector( aTrackerSD );

//--------- Visualization attributes ------------------------------G4VisAttributes* BoxVisAtt= new G4VisAttributes(G4Colour(1.0,1.0,1.0)); logicWorld ->SetVisAttributes(BoxVisAtt); logicTarget ->SetVisAttributes(BoxVisAtt); logicTracker->SetVisAttributes(BoxVisAtt); G4VisAttributes* ChamberVisAtt = new G4VisAttributes(G4Colour(1.0,1.0,0.0)); logicChamber->SetVisAttributes(ChamberVisAtt); //--------- example of User Limits ------------------------------// below is an example of how to set tracking constraints in a given // logical volume(see also in N02PhysicsList how to setup the processes // G4StepLimiter or G4UserSpecialCuts). // Sets a max Step length in the tracker region, with G4StepLimiter // G4double maxStep = 0.5*ChamberWidth; stepLimit = new G4UserLimits(maxStep); logicTracker->SetUserLimits(stepLimit); // Set additional contraints on the track, with G4UserSpecialCuts // // G4double maxLength = 2*fTrackerLength, maxTime = 0.1*ns, minEkin = 10*MeV; // logicTracker->SetUserLimits(new G4UserLimits(maxStep,maxLength,maxTime, // minEkin)); return physiWorld; } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void ExN02DetectorConstruction::setTargetMaterial(G4String materialName) { // search the material by its name G4Material* pttoMaterial = G4Material::GetMaterial(materialName); if (pttoMaterial) {TargetMater = pttoMaterial; logicTarget->SetMaterial(pttoMaterial); G4cout << "\n----> The target is " << fTargetLength/cm << " cm of " << materialName << G4endl; } } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void ExN02DetectorConstruction::setChamberMaterial(G4String materialName) { // search the material by its name G4Material* pttoMaterial = G4Material::GetMaterial(materialName); if (pttoMaterial) {ChamberMater = pttoMaterial; logicChamber->SetMaterial(pttoMaterial); G4cout << "\n----> The chambers are " << ChamberWidth/cm << " cm of " << materialName << G4endl; } } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void ExN02DetectorConstruction::SetMagField(G4double fieldValue) { fpMagField->SetFieldValue(fieldValue); }

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void ExN02DetectorConstruction::SetMaxStep(G4double maxStep) { if ((stepLimit)&&(maxStep>0.)) stepLimit->SetMaxAllowedStep(maxStep); }

#include "ExN02DetectorMessenger.hh"
#include #include #include #include #include "ExN02DetectorConstruction.hh" "G4UIdirectory.hh" "G4UIcmdWithAString.hh" "G4UIcmdWithADoubleAndUnit.hh" "globals.hh"

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... ExN02DetectorMessenger::ExN02DetectorMessenger(ExN02DetectorConstruction* myDet) :myDetector(myDet) { N02Dir = new G4UIdirectory("/N02/"); N02Dir->SetGuidance("UI commands specific to this example."); detDir = new G4UIdirectory("/N02/det/"); detDir->SetGuidance("detector control."); TargMatCmd = new G4UIcmdWithAString("/N02/det/setTargetMate",this); TargMatCmd->SetGuidance("Select Material of the Target."); TargMatCmd->SetParameterName("choice",false); TargMatCmd->AvailableForStates(G4State_PreInit,G4State_Idle); ChamMatCmd = new G4UIcmdWithAString("/N02/det/setChamberMate",this); ChamMatCmd->SetGuidance("Select Material of the Target."); ChamMatCmd->SetParameterName("choice",false); ChamMatCmd->AvailableForStates(G4State_PreInit,G4State_Idle); FieldCmd = new G4UIcmdWithADoubleAndUnit("/N02/det/setField",this); FieldCmd->SetGuidance("Define magnetic field."); FieldCmd->SetGuidance("Magnetic field will be in X direction."); FieldCmd->SetParameterName("Bx",false); FieldCmd->SetUnitCategory("Magnetic flux density"); FieldCmd->AvailableForStates(G4State_PreInit,G4State_Idle); StepMaxCmd = new G4UIcmdWithADoubleAndUnit("/N02/det/stepMax",this); StepMaxCmd->SetGuidance("Define a step max"); StepMaxCmd->SetParameterName("stepMax",false); StepMaxCmd->SetUnitCategory("Length"); StepMaxCmd->AvailableForStates(G4State_Idle); } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... ExN02DetectorMessenger::~ExN02DetectorMessenger() { delete TargMatCmd; delete ChamMatCmd; delete FieldCmd; delete StepMaxCmd; delete detDir; delete N02Dir; } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

void ExN02DetectorMessenger::SetNewValue(G4UIcommand* command,G4String newValue) { if( command == TargMatCmd ) { myDetector->setTargetMaterial(newValue);} if( command == ChamMatCmd ) { myDetector->setChamberMaterial(newValue);} if( command == FieldCmd ) { myDetector->SetMagField(FieldCmd->GetNewDoubleValue(newValue));} if( command == StepMaxCmd ) { myDetector->SetMaxStep(StepMaxCmd->GetNewDoubleValue(newValue));} }

#include "ExN02EventAction.hh"
#include #include #include #include #include "G4Event.hh" "G4EventManager.hh" "G4TrajectoryContainer.hh" "G4Trajectory.hh" "G4ios.hh"

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... ExN02EventAction::ExN02EventAction() {} //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... ExN02EventAction::~ExN02EventAction() {} //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void ExN02EventAction::BeginOfEventAction(const G4Event*) {} //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void ExN02EventAction::EndOfEventAction(const G4Event* evt) { G4int event_id = evt->GetEventID(); // get number of stored trajectories // G4TrajectoryContainer* trajectoryContainer = evt->GetTrajectoryContainer(); G4int n_trajectories = 0; if (trajectoryContainer) n_trajectories = trajectoryContainer->entries(); // periodic printing // if (event_id < 100 || event_id%100 == 0) { G4cout << ">>> Event " << evt->GetEventID() << G4endl; G4cout << " " << n_trajectories << " trajectories stored in this event." << G4endl; } }

#include "ExN02MagneticField.hh"
#include "G4FieldManager.hh" #include "G4TransportationManager.hh" //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

ExN02MagneticField::ExN02MagneticField() : G4UniformMagField(G4ThreeVector()) { GetGlobalFieldManager()->SetDetectorField(this); GetGlobalFieldManager()->CreateChordFinder(this); } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... ExN02MagneticField::ExN02MagneticField(G4ThreeVector fieldVector) : G4UniformMagField(fieldVector) { GetGlobalFieldManager()->SetDetectorField(this); GetGlobalFieldManager()->CreateChordFinder(this); } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... ExN02MagneticField::~ExN02MagneticField() { } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... // Set the value of the Global Field to fieldValue along X // void ExN02MagneticField::SetMagFieldValue(G4double fieldValue) { SetMagFieldValue(G4ThreeVector(fieldValue,0,0)); } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... // Set the value of the Global Field // void ExN02MagneticField::SetMagFieldValue(G4ThreeVector fieldVector) { // Find the Field Manager for the global field G4FieldManager* fieldMgr= GetGlobalFieldManager(); if(fieldVector!=G4ThreeVector(0.,0.,0.)) { SetFieldValue(fieldVector); fieldMgr->SetDetectorField(this); } else { // If the new field's value is Zero, then it is best to // insure that it is not used for propagation. G4MagneticField* magField = 0; fieldMgr->SetDetectorField(magField); } } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... G4FieldManager* ExN02MagneticField::GetGlobalFieldManager() { return G4TransportationManager::GetTransportationManager()->GetFieldManager(); }

#include "globals.hh"
#include "ExN02PhysicsList.hh" #include "G4ProcessManager.hh" #include "G4ParticleTypes.hh"

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... ExN02PhysicsList::ExN02PhysicsList(): { defaultCutValue = 1.0*cm; SetVerboseLevel(1); } G4VUserPhysicsList()

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... ExN02PhysicsList::~ExN02PhysicsList() {} //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void { // // // // ExN02PhysicsList::ConstructParticle() In this method, static member functions should be called for all particles which you want to use. This ensures that objects of these particle types will be created in the program.

ConstructBosons(); ConstructLeptons(); ConstructMesons(); ConstructBaryons(); } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void ExN02PhysicsList::ConstructBosons() { // pseudo-particles G4Geantino::GeantinoDefinition(); G4ChargedGeantino::ChargedGeantinoDefinition(); // gamma G4Gamma::GammaDefinition(); } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void ExN02PhysicsList::ConstructLeptons() { // leptons // e+/G4Electron::ElectronDefinition(); G4Positron::PositronDefinition(); // mu+/G4MuonPlus::MuonPlusDefinition(); G4MuonMinus::MuonMinusDefinition(); // nu_e G4NeutrinoE::NeutrinoEDefinition(); G4AntiNeutrinoE::AntiNeutrinoEDefinition(); // nu_mu G4NeutrinoMu::NeutrinoMuDefinition(); G4AntiNeutrinoMu::AntiNeutrinoMuDefinition(); } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void ExN02PhysicsList::ConstructMesons() { // mesons

// light mesons G4PionPlus::PionPlusDefinition(); G4PionMinus::PionMinusDefinition(); G4PionZero::PionZeroDefinition(); G4Eta::EtaDefinition(); G4EtaPrime::EtaPrimeDefinition(); G4KaonPlus::KaonPlusDefinition(); G4KaonMinus::KaonMinusDefinition(); G4KaonZero::KaonZeroDefinition(); G4AntiKaonZero::AntiKaonZeroDefinition(); G4KaonZeroLong::KaonZeroLongDefinition(); G4KaonZeroShort::KaonZeroShortDefinition(); } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void ExN02PhysicsList::ConstructBaryons() { // barions G4Proton::ProtonDefinition(); G4AntiProton::AntiProtonDefinition(); G4Neutron::NeutronDefinition(); G4AntiNeutron::AntiNeutronDefinition(); } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void ExN02PhysicsList::ConstructProcess() { AddTransportation(); ConstructEM(); ConstructGeneral(); AddStepMax(); } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... #include "G4ComptonScattering.hh" #include "G4GammaConversion.hh" #include "G4PhotoElectricEffect.hh" #include "G4eMultipleScattering.hh" #include "G4hMultipleScattering.hh" #include "G4eIonisation.hh" #include "G4eBremsstrahlung.hh" #include "G4eplusAnnihilation.hh" #include "G4MuIonisation.hh" #include "G4MuBremsstrahlung.hh" #include "G4MuPairProduction.hh" #include "G4hIonisation.hh" #include "G4hBremsstrahlung.hh" #include "G4hPairProduction.hh" #include "G4ionIonisation.hh" //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void ExN02PhysicsList::ConstructEM() { theParticleIterator->reset(); while( (*theParticleIterator)() ){

G4ParticleDefinition* particle = theParticleIterator->value(); G4ProcessManager* pmanager = particle->GetProcessManager(); G4String particleName = particle->GetParticleName(); if (particleName == "gamma") { // gamma pmanager->AddDiscreteProcess(new G4PhotoElectricEffect); pmanager->AddDiscreteProcess(new G4ComptonScattering); pmanager->AddDiscreteProcess(new G4GammaConversion); } else if (particleName == //electron pmanager->AddProcess(new pmanager->AddProcess(new pmanager->AddProcess(new } else if (particleName == //positron pmanager->AddProcess(new pmanager->AddProcess(new pmanager->AddProcess(new pmanager->AddProcess(new } else if( particleName == particleName == //muon pmanager->AddProcess(new pmanager->AddProcess(new pmanager->AddProcess(new pmanager->AddProcess(new } else if( particleName == particleName == particleName == //proton pmanager->AddProcess(new pmanager->AddProcess(new pmanager->AddProcess(new pmanager->AddProcess(new "e-") { G4eMultipleScattering, -1, 1, 1); G4eIonisation, -1, 2, 2); G4eBremsstrahlung, -1, 3, 3); "e+") { G4eMultipleScattering, -1, 1, 1); G4eIonisation, -1, 2, 2); G4eBremsstrahlung, -1, 3, 3); G4eplusAnnihilation, 0,-1, 4); "mu+" || "mu-" ) { G4hMultipleScattering, G4MuIonisation, G4MuBremsstrahlung, G4MuPairProduction, "proton" || "pi-" || "pi+" ) { G4hMultipleScattering, G4hIonisation, G4hBremsstrahlung, G4hPairProduction, -1, -1, -1, -1, 1, 2, 3, 4, 1); 2); 3); 4); -1, -1, -1, -1, 1, 2, 3, 4, 1); 2); 3); 4);

} else if( particleName == "alpha" || particleName == "He3" || particleName == "GenericIon" ) { //Ions pmanager->AddProcess(new G4hMultipleScattering, -1, 1, 1); pmanager->AddProcess(new G4ionIonisation, -1, 2, 2); } else if ((!particle->IsShortLived()) && (particle->GetPDGCharge() != 0.0) && (particle->GetParticleName() != "chargedgeantino")) { //all others charged particles except geantino pmanager->AddProcess(new G4hMultipleScattering, -1, 1, 1); pmanager->AddProcess(new G4hIonisation, -1, 2, 2); } } } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... #include "G4Decay.hh" void ExN02PhysicsList::ConstructGeneral() { // Add Decay Process G4Decay* theDecayProcess = new G4Decay();

theParticleIterator->reset(); while( (*theParticleIterator)() ){ G4ParticleDefinition* particle = theParticleIterator->value(); G4ProcessManager* pmanager = particle->GetProcessManager(); if (theDecayProcess->IsApplicable(*particle)) { pmanager ->AddProcess(theDecayProcess); // set ordering for PostStepDoIt and AtRestDoIt pmanager ->SetProcessOrdering(theDecayProcess, idxPostStep); pmanager ->SetProcessOrdering(theDecayProcess, idxAtRest); } } } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... #include "G4StepLimiter.hh" #include "G4UserSpecialCuts.hh" void ExN02PhysicsList::AddStepMax() { // Step limitation seen as a process G4StepLimiter* stepLimiter = new G4StepLimiter(); ////G4UserSpecialCuts* userCuts = new G4UserSpecialCuts(); theParticleIterator->reset(); while ((*theParticleIterator)()){ G4ParticleDefinition* particle = theParticleIterator->value(); G4ProcessManager* pmanager = particle->GetProcessManager(); if (particle->GetPDGCharge() != 0.0) { pmanager ->AddDiscreteProcess(stepLimiter); ////pmanager ->AddDiscreteProcess(userCuts); } } } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void ExN02PhysicsList::SetCuts() { //G4VUserPhysicsList::SetCutsWithDefault method sets //the default cut value for all particle types // SetCutsWithDefault(); if (verboseLevel>0) DumpCutValuesTable(); }

#include "ExN02PrimaryGeneratorAction.hh"
#include "ExN02DetectorConstruction.hh" #include #include #include #include #include "G4Event.hh" "G4ParticleGun.hh" "G4ParticleTable.hh" "G4ParticleDefinition.hh" "globals.hh"

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... ExN02PrimaryGeneratorAction::ExN02PrimaryGeneratorAction( ExN02DetectorConstruction* myDC) :myDetector(myDC) { G4int n_particle = 1;

particleGun = new G4ParticleGun(n_particle); // default particle G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable(); G4ParticleDefinition* particle = particleTable->FindParticle("proton"); particleGun->SetParticleDefinition(particle); particleGun->SetParticleMomentumDirection(G4ThreeVector(0.,0.,1.)); particleGun->SetParticleEnergy(3.0*GeV); } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... ExN02PrimaryGeneratorAction::~ExN02PrimaryGeneratorAction() { delete particleGun; } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void ExN02PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent) { G4double position = -0.5*(myDetector->GetWorldFullLength()); particleGun->SetParticlePosition(G4ThreeVector(0.*cm,0.*cm,position)); particleGun->GeneratePrimaryVertex(anEvent); }

#include "ExN02SteppingAction.hh"
#include "G4SteppingManager.hh" //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... ExN02SteppingAction::ExN02SteppingAction() { } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void ExN02SteppingAction::UserSteppingAction(const G4Step*) { } //

#include "ExN02SteppingVerbose.hh"
#include "G4SteppingManager.hh" #include "G4UnitsTable.hh" //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... ExN02SteppingVerbose::ExN02SteppingVerbose() {} //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... ExN02SteppingVerbose::~ExN02SteppingVerbose() {} //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void ExN02SteppingVerbose::StepInfo() { CopyState();

G4int prec = G4cout.precision(3); if( verboseLevel >= 1 ){ if( verboseLevel >= 4 ) VerboseTrack(); if( verboseLevel >= 3 ){ G4cout << G4endl; G4cout << std::setw( 5) << "#Step#" << " " << std::setw( 6) << "X" << " " << std::setw( 6) << "Y" << " " << std::setw( 6) << "Z" << " " << std::setw( 9) << "KineE" << " " << std::setw( 9) << "dEStep" << " " << std::setw(10) << "StepLeng" << std::setw(10) << "TrakLeng" << std::setw(10) << "Volume" << " " << std::setw(10) << "Process" << G4endl; } G4cout << std::setw(5) << fTrack->GetCurrentStepNumber() << " " << std::setw(6) << G4BestUnit(fTrack->GetPosition().x(),"Length") << std::setw(6) << G4BestUnit(fTrack->GetPosition().y(),"Length") << std::setw(6) << G4BestUnit(fTrack->GetPosition().z(),"Length") << std::setw(6) << G4BestUnit(fTrack->GetKineticEnergy(),"Energy") << std::setw(6) << G4BestUnit(fStep->GetTotalEnergyDeposit(),"Energy") << std::setw(6) << G4BestUnit(fStep->GetStepLength(),"Length") << std::setw(6) << G4BestUnit(fTrack->GetTrackLength(),"Length") << " "; // if( fStepStatus != fWorldBoundary){ if( fTrack->GetNextVolume() != 0 ) { G4cout << std::setw(10) << fTrack->GetVolume()->GetName(); } else { G4cout << std::setw(10) << "OutOfWorld"; } if(fStep->GetPostStepPoint()->GetProcessDefinedStep() != NULL){ G4cout << " " << std::setw(10) << fStep->GetPostStepPoint()->GetProcessDefinedStep() ->GetProcessName(); } else { G4cout << " UserLimit"; } G4cout << G4endl; if( verboseLevel == 2 ){ G4int tN2ndariesTot = fN2ndariesAtRestDoIt + fN2ndariesAlongStepDoIt + fN2ndariesPostStepDoIt; if(tN2ndariesTot>0){ G4cout << " :----- List of 2ndaries - " << "#SpawnInStep=" << std::setw(3) << tN2ndariesTot << "(Rest=" << std::setw(2) << fN2ndariesAtRestDoIt << ",Along=" << std::setw(2) << fN2ndariesAlongStepDoIt << ",Post=" << std::setw(2) << fN2ndariesPostStepDoIt << "), " << "#SpawnTotal=" << std::setw(3) << (*fSecondary).size() << " ---------------" << G4endl; for(size_t lp1=(*fSecondary).size()-tN2ndariesTot; lp1<(*fSecondary).size(); lp1++){ G4cout << " : " << std::setw(6) << G4BestUnit((*fSecondary)[lp1]->GetPosition().x(),"Length")

<< << << << << << << << G4cout } G4cout << << << << } }

std::setw(6) G4BestUnit((*fSecondary)[lp1]->GetPosition().y(),"Length") std::setw(6) G4BestUnit((*fSecondary)[lp1]->GetPosition().z(),"Length") std::setw(6) G4BestUnit((*fSecondary)[lp1]->GetKineticEnergy(),"Energy") std::setw(10) (*fSecondary)[lp1]->GetDefinition()->GetParticleName(); << G4endl;

" :-----------------------------" "----------------------------------" "-- EndOf2ndaries Info ---------------" G4endl;

} G4cout.precision(prec); } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void ExN02SteppingVerbose::TrackingStarted() { CopyState(); G4int prec = G4cout.precision(3); if( verboseLevel > 0 ){ G4cout << std::setw( << std::setw( << std::setw( 6) << std::setw( 6) << std::setw( 9) << std::setw( 9) << std::setw(10) << std::setw(10) << std::setw(10) << std::setw(10) 5) 6) << << << << << << << << << "Step#" << "X" "Y" "Z" "KineE" "dEStep" "StepLeng" "TrakLeng" "Volume" "Process" << " " << " " " " " " " " " "

<< << << <<

<< " " << G4endl;

G4cout << std::setw(5) << fTrack->GetCurrentStepNumber() << " " << std::setw(6) << G4BestUnit(fTrack->GetPosition().x(),"Length") << std::setw(6) << G4BestUnit(fTrack->GetPosition().y(),"Length") << std::setw(6) << G4BestUnit(fTrack->GetPosition().z(),"Length") << std::setw(6) << G4BestUnit(fTrack->GetKineticEnergy(),"Energy") << std::setw(6) << G4BestUnit(fStep->GetTotalEnergyDeposit(),"Energy") << std::setw(6) << G4BestUnit(fStep->GetStepLength(),"Length") << std::setw(6) << G4BestUnit(fTrack->GetTrackLength(),"Length") << " "; if(fTrack->GetNextVolume()){ G4cout << std::setw(10) << fTrack->GetVolume()->GetName(); } else { G4cout << std::setw(10) << "OutOfWorld"; } G4cout << " initStep" << G4endl; } G4cout.precision(prec); }

#include "ExN02TrackerHit.hh"
#include "G4UnitsTable.hh" #include "G4VVisManager.hh"

#include "G4Circle.hh" #include "G4Colour.hh" #include "G4VisAttributes.hh" G4Allocator<ExN02TrackerHit> ExN02TrackerHitAllocator; //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... ExN02TrackerHit::ExN02TrackerHit() {} //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... ExN02TrackerHit::~ExN02TrackerHit() {} //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... ExN02TrackerHit::ExN02TrackerHit(const ExN02TrackerHit& right) : G4VHit() { trackID = right.trackID; chamberNb = right.chamberNb; edep = right.edep; pos = right.pos; } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... const ExN02TrackerHit& ExN02TrackerHit::operator=(const ExN02TrackerHit& right) { trackID = right.trackID; chamberNb = right.chamberNb; edep = right.edep; pos = right.pos; return *this; } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... G4int ExN02TrackerHit::operator==(const ExN02TrackerHit& right) const { return (this==&right) ? 1 : 0; } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void ExN02TrackerHit::Draw() { G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance(); if(pVVisManager) { G4Circle circle(pos); circle.SetScreenSize(2.); circle.SetFillStyle(G4Circle::filled); G4Colour colour(1.,0.,0.); G4VisAttributes attribs(colour); circle.SetVisAttributes(attribs); pVVisManager->Draw(circle); } } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void ExN02TrackerHit::Print() { G4cout << " trackID: " << trackID << "

chamberNb: " << chamberNb

<< " energy deposit: " << G4BestUnit(edep,"Energy") << " position: " << G4BestUnit(pos,"Length") << G4endl; }

#include "ExN02TrackerSD.hh"
#include #include #include #include #include "G4HCofThisEvent.hh" "G4Step.hh" "G4ThreeVector.hh" "G4SDManager.hh" "G4ios.hh"

ExN02TrackerSD::ExN02TrackerSD(G4String name) :G4VSensitiveDetector(name) { G4String HCname; collectionName.insert(HCname="trackerCollection"); } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... ExN02TrackerSD::~ExN02TrackerSD(){ } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void ExN02TrackerSD::Initialize(G4HCofThisEvent* HCE) { trackerCollection = new ExN02TrackerHitsCollection (SensitiveDetectorName,collectionName[0]); static G4int HCID = -1; if(HCID<0) { HCID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]); } HCE->AddHitsCollection( HCID, trackerCollection ); } G4bool ExN02TrackerSD::ProcessHits(G4Step* aStep,G4TouchableHistory*) { G4double edep = aStep->GetTotalEnergyDeposit(); if(edep==0.) return false; ExN02TrackerHit* newHit = new ExN02TrackerHit(); newHit->SetTrackID (aStep->GetTrack()->GetTrackID()); newHit->SetChamberNb(aStep->GetPreStepPoint()->GetTouchableHandle() ->GetCopyNumber()); newHit->SetEdep (edep); newHit->SetPos (aStep->GetPostStepPoint()->GetPosition()); trackerCollection->insert( newHit ); //newHit->Print(); //newHit->Draw(); return true; } void ExN02TrackerSD::EndOfEvent(G4HCofThisEvent*) { if (verboseLevel>0) { G4int NbHits = trackerCollection->entries(); G4cout << "\n-------->Hits Collection: in this event they are " << NbHits << " hits in the tracker chambers: " << G4endl; for (G4int i=0;i<NbHits;i++) (*trackerCollection)[i]->Print(); } }

You might also like