Skip to content

Commit

Permalink
Merge pull request #121 from rest-for-physics/jgalan_cry
Browse files Browse the repository at this point in the history
Implementing the CRY generator into restG4
  • Loading branch information
jgalan authored Nov 20, 2023
2 parents 8604185 + 7cc144d commit dc3a8f4
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/pr-badge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
message: "Ok: $additions"
color: "green"
when: "$additions < 100"
- imageUrl: "https://github.com/rest-for-physics/restG4/actions/workflows/validation.yml/badge.svg?branch=$branchName"
- imageUrl: "https://github.com/rest-for-physics/restG4/actions/workflows/frameworkValidation.yml/badge.svg?branch=$branchName"
url: "https://github.com/rest-for-physics/restG4/commits/$branchName"
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ endif ()

# Add the executable
add_executable(${PROJECT_NAME} main.cxx)

target_link_libraries(${PROJECT_NAME} PUBLIC ${LIBRARY})

file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/examples
Expand Down
57 changes: 57 additions & 0 deletions examples/12.Generators/CryGenerator.rml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>

<restG4>
<globals>
<parameter name="mainDataPath" value=""/>
<parameter name="verboseLevel" value="essential"/>
</globals>

<TRestRun>
<parameter name="experimentName" value="CryGenerator"/>
<parameter name="runType" value="simulation"/>
<parameter name="runNumber" value="1"/>
<parameter name="runTag" value="CryGenerator"/>
<parameter name="outputFileName" value="CryGenerator.root"/>
<parameter name="runDescription" value=""/>
<parameter name="user" value="${USER}"/>
<parameter name="overwrite" value="off"/>
<parameter name="readOnly" value="false"/>
</TRestRun>

<TRestGeant4Metadata name="crySimulation">
<parameter name="gdmlFile" value="geometry/setup.gdml"/>
<parameter name="seed" value="137"/>
<parameter name="nRequestedEntries" value="10"/>
<parameter name="saveAllEvents" value="true"/>

<generator type="source">
<source use="cry" returnNeutrons="1" returnProtons="1" returnGammas="1" returnElectrons="1"
returnPions="1" returnKaons="1" returnMuons="1"
nParticlesMin="1" nParticlesMax="1000"
subboxLength="100" xoffset="0" yoffset="0" zoffset="0"
date="07\01\2012" latitude="90.0" altitude="2100" />
</generator>

<detector>
<volume name="gasVolume" sensitive="true" maxStepSize="1mm"/>
</detector>

</TRestGeant4Metadata>

<TRestGeant4PhysicsLists name="physList" title="EM physics lists. No hadron physics!">

<physicsList name="G4EmLivermorePhysics">
<option name="pixe" value="false"/>
</physicsList>

<physicsList name="G4EmExtraPhysics"/>

<physicsList name="G4DecayPhysics"/>
<physicsList name="G4RadioactiveDecayPhysics"/>
<physicsList name="G4RadioactiveDecay">
<option name="ICM" value="true"/>
<option name="ARM" value="true"/>
</physicsList>

</TRestGeant4PhysicsLists>
</restG4>
11 changes: 11 additions & 0 deletions src/PrimaryGeneratorAction.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -271,17 +271,25 @@ void PrimaryGeneratorAction::GeneratePrimaries(G4Event* event) {

for (int i = 0; i < restG4Metadata->GetNumberOfSources(); i++) {
vector<TRestGeant4Particle> particles = restG4Metadata->GetParticleSource(i)->GetParticles();
// std::cout << "Source : " << i << std::endl;
for (const auto& p : particles) {
// ParticleDefinition should be always declared first (after position).
SetParticleDefinition(i, p);
SetParticleEnergyAndDirection(i, p);

// p.Print();

if (spatialGeneratorTypeEnum == SpatialGeneratorTypes::COSMIC) {
const auto position = ComputeCosmicPosition(fParticleGun.GetParticleMomentumDirection(),
fCosmicCircumscribedSphereRadius);
fParticleGun.SetParticlePosition(position);
}

if (spatialGeneratorTypeEnum == SpatialGeneratorTypes::SOURCE) {
G4ThreeVector position = {p.GetOrigin().X(), p.GetOrigin().Y(), p.GetOrigin().Z()};
fParticleGun.SetParticlePosition(position);
}

fParticleGun.GeneratePrimaryVertex(event);
}
}
Expand All @@ -304,6 +312,7 @@ G4ParticleDefinition* PrimaryGeneratorAction::SetParticleDefinition(Int_t partic
}

G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
fParticle = particleTable->FindParticle(particleName);
if (!fParticle) {
fParticle = particleTable->FindParticle(particleName);

Expand Down Expand Up @@ -542,6 +551,8 @@ void PrimaryGeneratorAction::SetParticlePosition() {
}
} else if (spatialGeneratorTypeEnum == SpatialGeneratorTypes::COSMIC) {
// position will be defined after direction
} else if (spatialGeneratorTypeEnum == SpatialGeneratorTypes::SOURCE) {
// position will be defined by the source generator
} else {
G4cout << "WARNING! Generator type \"" << spatialGeneratorTypeName
<< "\" was not recognized. Launching particle "
Expand Down

0 comments on commit dc3a8f4

Please sign in to comment.