Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tonne rock #28

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
98 changes: 98 additions & 0 deletions source/actions/LowMemoryTrackingAction.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// ----------------------------------------------------------------------------
// nexus | LowMemoryTrackingAction.cc
//
// This class is a tracking action of the NEXT simulation.
// It stores in memory the trajectories of particles -- with the exception of
// optical photons, ionization electrons, and electrons starting in
// Rock or water -- with the relevant tracking information that will be
// saved to the output file. First version useful for TonneScale with no
// Cerenkov studies (June 2020).
//
// The NEXT Collaboration
// ----------------------------------------------------------------------------


#include "LowMemoryTrackingAction.h"

#include "Trajectory.h"
#include "TrajectoryMap.h"
#include "IonizationElectron.h"

#include <G4Track.hh>
#include <G4TrackingManager.hh>
#include <G4Trajectory.hh>
#include <G4ParticleDefinition.hh>
#include <G4OpticalPhoton.hh>
#include <G4Neutron.hh>



using namespace nexus;



LowMemoryTrackingAction::LowMemoryTrackingAction(): G4UserTrackingAction()
{
}



LowMemoryTrackingAction::~LowMemoryTrackingAction()
{
}



void LowMemoryTrackingAction::PreUserTrackingAction(const G4Track* track)
{
// Do nothing if the track is an optical photon or an ionization electron
if (track->GetDefinition() == G4OpticalPhoton::Definition() ||
track->GetDefinition() == IonizationElectron::Definition()) {
fpTrackingManager->SetStoreTrajectory(false);
return;
}

if (track->GetParentID() == 0 ||
track->GetParticleDefinition() == G4Neutron::Definition() ||
track->GetParticleDefinition()->IsGeneralIon() ){

// Create a new trajectory associated to the track.
// N.B. If the processesing of a track is interrupted to be resumed
// later on (to process, for instance, its secondaries) more than
// one trajectory associated to the track will be created, but
// the event manager will merge them at some point.
G4VTrajectory* trj = new Trajectory(track);

// Set the trajectory in the tracking manager
fpTrackingManager->SetStoreTrajectory(true);
fpTrackingManager->SetTrajectory(trj);
return;
}

fpTrackingManager->SetStoreTrajectory(false);
}



void LowMemoryTrackingAction::PostUserTrackingAction(const G4Track* track)
{
// Do nothing if the track is an optical photon or an ionization electron
if (track->GetDefinition() == G4OpticalPhoton::Definition() ||
track->GetDefinition() == IonizationElectron::Definition()) return;

Trajectory* trj = (Trajectory*) TrajectoryMap::Get(track->GetTrackID());

// Do nothing if the track has no associated trajectory in the map
if (!trj) return;

// Record final time and position of the track
trj->SetFinalPosition(track->GetPosition());
trj->SetFinalTime(track->GetGlobalTime());
trj->SetTrackLength(track->GetTrackLength());
trj->SetFinalVolume(track->GetVolume()->GetName());
trj->SetFinalMomentum(track->GetMomentum());

// Record last process of the track
G4String proc_name = track->GetStep()->GetPostStepPoint()->GetProcessDefinedStep()->GetProcessName();
trj->SetFinalProcess(proc_name);
}
40 changes: 40 additions & 0 deletions source/actions/LowMemoryTrackingAction.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// ----------------------------------------------------------------------------
// nexus | LowMemoryTrackingAction.h
//
// This class is a tracking action of the NEXT simulation.
// It stores in memory the trajectories of particles -- with the exception of
// optical photons, ionization electrons, and electrons starting in
// Rock or water -- with the relevant tracking information that will be
// saved to the output file. First version useful for TonneScale with no
// Cerenkov studies (June 2020).
//
// The NEXT Collaboration
// ----------------------------------------------------------------------------

#ifndef LOW_MEMORY_TRACKING_ACTION_H
#define LOW_MEMORY_TRACKING_ACTION_H

#include <G4UserTrackingAction.hh>

class G4Track;


namespace nexus {

// Low memory usage user tracking action

class LowMemoryTrackingAction: public G4UserTrackingAction
{
public:
/// Constructor
LowMemoryTrackingAction();
/// Destructor
virtual ~LowMemoryTrackingAction();

virtual void PreUserTrackingAction(const G4Track*);
virtual void PostUserTrackingAction(const G4Track*);
};

}

#endif
35 changes: 35 additions & 0 deletions source/actions/NoSaveEventAction.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "NoSaveEventAction.h"

#include "PersistencyManager.h"

#include <G4Event.hh>


namespace nexus {


NoSaveEventAction::NoSaveEventAction():
G4UserEventAction()
{

}



NoSaveEventAction::~NoSaveEventAction()
{
}



void NoSaveEventAction::BeginOfEventAction(const G4Event* /*event*/)
{
PersistencyManager* pm = dynamic_cast<PersistencyManager*>
(G4VPersistencyManager::GetPersistencyManager());
pm->StoreCurrentEvent(false);
}

void NoSaveEventAction::EndOfEventAction(const G4Event* event)
{
}
}
39 changes: 39 additions & 0 deletions source/actions/NoSaveEventAction.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// ----------------------------------------------------------------------------
// nexus | NoSaveEventAction.h
//
// This event action saves no event information to file
//
// The NEXT Collaboration
// ----------------------------------------------------------------------------

#ifndef NOSAVE_EVENT_ACTION_H
#define NOSAVE_EVENT_ACTION_H

#include <G4UserEventAction.hh>
#include <globals.hh>

class G4Event;

namespace nexus {

/// This class is an Event Action which forces nexus
/// Not to store any event information

class NoSaveEventAction: public G4UserEventAction
{
public:
/// Constructor
NoSaveEventAction();
/// Destructor
~NoSaveEventAction();

/// Hook at the beginning of the event loop
void BeginOfEventAction(const G4Event*);
/// Hook at the end of the event loop
void EndOfEventAction(const G4Event*);

};

} // namespace nexus

#endif
5 changes: 5 additions & 0 deletions source/base/ActionsFactory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ G4UserRunAction* ActionsFactory::CreateRunAction() const
#include "DefaultEventAction.h"
#include "SaveAllEventAction.h"
#include "MuonsEventAction.h"
#include "NoSaveEventAction.h"

G4UserEventAction* ActionsFactory::CreateEventAction() const
{
Expand All @@ -69,6 +70,7 @@ G4UserEventAction* ActionsFactory::CreateEventAction() const

else if (evtact_name_ == "MUONS") p = new MuonsEventAction();

else if (evtact_name_ == "NO_SAVE") p = new NoSaveEventAction();
else {
G4String err = "Unknown user event action: " + evtact_name_;
G4Exception("[ActionsFactory]", "CreateEventAction()", JustWarning, err);
Expand All @@ -82,6 +84,7 @@ G4UserEventAction* ActionsFactory::CreateEventAction() const
#include "DefaultTrackingAction.h"
#include "ValidationTrackingAction.h"
#include "OpticalTrackingAction.h"
#include "LowMemoryTrackingAction.h"

G4UserTrackingAction* ActionsFactory::CreateTrackingAction() const
{
Expand All @@ -93,6 +96,8 @@ G4UserTrackingAction* ActionsFactory::CreateTrackingAction() const

else if (trkact_name_ == "OPTICAL") p = new OpticalTrackingAction();

else if (trkact_name_ == "LOW_MEMORY") p = new LowMemoryTrackingAction();

else {
G4String err = "Unknown user tracking action: " + trkact_name_;
G4Exception("[ActionsFactory]", "CreateTrackingAction()",
Expand Down
65 changes: 61 additions & 4 deletions source/geometries/NextTonScale.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include <G4VisAttributes.hh>
#include <G4UserLimits.hh>
#include <G4SDManager.hh>
#include <G4Region.hh>
#include <G4ProductionCuts.hh>

using namespace nexus;

Expand All @@ -33,6 +35,7 @@ NextTonScale::NextTonScale():
msg_(nullptr),
gas_("naturalXe"), gas_pressure_(15.*bar), gas_temperature_(300.*kelvin),
detector_diam_(0.), detector_length_(0.),
rock_thickn_(2.*m), rock_diam_(0.),
tank_size_(0.), tank_thickn_(1.*cm), water_thickn_(3.*m),
vessel_thickn_(1.5*mm), ics_thickn_(12.*cm), endcap_hollow_(20.*cm),
fcage_thickn_(1.*cm),
Expand Down Expand Up @@ -73,12 +76,13 @@ void NextTonScale::Construct()
2.*ics_thickn_ + 2.*endcap_hollow_ + 2.*vessel_thickn_;
tank_size_ = std::max(detector_diam_, detector_length_) +
2.*water_thickn_ + 2.*tank_thickn_;
rock_diam_ = tank_size_ + 2. * cm + 2. *m;

// LABORATORY ////////////////////////////////////////////
// Volume of air that contains all other detector volumes.

G4String lab_name = "LABORATORY";
G4double lab_size = tank_size_ + 4.*m; // Clearance of 2 m around water tank
G4double lab_size = rock_diam_ + 6.*m; // Clearance of 2 m around water tank and rock

G4Material* lab_material =
G4NistManager::Instance()->FindOrBuildMaterial("G4_AIR");
Expand All @@ -96,12 +100,57 @@ void NextTonScale::Construct()

G4LogicalVolume* mother_logic_vol = lab_logic_vol;

mother_logic_vol = ConstructLabRock(mother_logic_vol);
mother_logic_vol = ConstructWaterTank(mother_logic_vol);
mother_logic_vol = ConstructVesselAndICS(mother_logic_vol);
mother_logic_vol = ConstructFieldCageAndReadout(mother_logic_vol);
}


G4LogicalVolume* NextTonScale::ConstructLabRock(G4LogicalVolume* mother_logic_vol)
{
// Lab rock //
// Tube of rock (Standard or G4_CONCRETE) with additional cylinder above tank
G4String top_rock_name = "LAB_ROCK_TOP";
G4String side_rock_name = "LAB_ROCK_SURROUND";
G4Material* rock_material = MaterialsList::StandardRock();

G4Tubs* top_rock_solid =
new G4Tubs(top_rock_name, 0, rock_diam_ / 2.,
rock_thickn_ / 2., 0., 360. * deg);
G4double side_rock_height = tank_size_ + 1. * cm;
G4double side_rock_inner_diam = tank_size_ + 2. * cm;
G4Tubs* side_rock_solid =
new G4Tubs(side_rock_name, side_rock_inner_diam / 2., rock_diam_ / 2.,
side_rock_height / 2., 0., 360. * deg);

G4Region *rock_region = new G4Region("LAB_ROCK");
G4ProductionCuts *rock_prod_cut = new G4ProductionCuts();
rock_prod_cut->SetProductionCut(50. * cm);
G4LogicalVolume* top_rock_logic =
new G4LogicalVolume(top_rock_solid, rock_material, top_rock_name);
rock_region->AddRootLogicalVolume(top_rock_logic);

G4LogicalVolume* side_rock_logic =
new G4LogicalVolume(side_rock_solid, rock_material, side_rock_name);
rock_region->AddRootLogicalVolume(side_rock_logic);
rock_region->SetProductionCuts(rock_prod_cut);

G4RotationMatrix* rock_rotation = new G4RotationMatrix();
rock_rotation->rotateX(90. * deg);
G4double top_rock_y = tank_size_ / 2. + 1.*cm + rock_thickn_ / 2;
G4ThreeVector top_rock_pos(0., top_rock_y, 0.);
new G4PVPlacement(rock_rotation, top_rock_pos, top_rock_logic,
top_rock_name, mother_logic_vol, false, 0, true);

G4double side_rock_y = 0.5 * cm;
new G4PVPlacement(rock_rotation, G4ThreeVector(0., side_rock_y, 0.),
side_rock_logic, side_rock_name, mother_logic_vol,
false, 0, true);
return mother_logic_vol;
}


G4LogicalVolume* NextTonScale::ConstructWaterTank(G4LogicalVolume* mother_logic_vol)
{
// WATER TANK ////////////////////////////////////////////
Expand Down Expand Up @@ -146,9 +195,10 @@ G4LogicalVolume* NextTonScale::ConstructWaterTank(G4LogicalVolume* mother_logic_

//////////////////////////////////////////////////////////

muon_gen_ = new MuonsPointSampler(tank_size_/2. + 50. * cm,
tank_size_/2. + 1. * cm,
tank_size_/2. + 50. * cm);
G4double mu_gen_x = rock_diam_ / 2.;
G4double mu_gen_y = tank_size_/2. + rock_thickn_ + 2. * cm;
G4double mu_gen_z = rock_diam_ / 2.;
muon_gen_ = new MuonsPointSampler(mu_gen_x, mu_gen_y, mu_gen_z, true);

// Primarily for neutron generation
external_gen_ = new CylinderPointSampler(tank_size_/2. + 1 * cm,
Expand Down Expand Up @@ -482,6 +532,13 @@ void NextTonScale::DefineConfigurationParameters()
gas_temperature_cmd.SetParameterName("gas_temperature", false);
gas_temperature_cmd.SetRange("gas_temperature>0.");

G4GenericMessenger::Command& rock_thickn_cmd =
msg_->DeclareProperty("rock_thickness", rock_thickn_,
"Thickness of surrounding rock to simulate.");
rock_thickn_cmd.SetUnitCategory("Length");
rock_thickn_cmd.SetParameterName("rock_thickness", false);
rock_thickn_cmd.SetRange("rock_thickness>=0.");

G4GenericMessenger::Command& active_diam_cmd =
msg_->DeclareProperty("active_diam", active_diam_,
"Diameter of the active diameter of the detector.");
Expand Down
2 changes: 2 additions & 0 deletions source/geometries/NextTonScale.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace nexus {

private:
//
G4LogicalVolume* ConstructLabRock(G4LogicalVolume*);
G4LogicalVolume* ConstructWaterTank(G4LogicalVolume*);
G4LogicalVolume* ConstructVesselAndICS(G4LogicalVolume*);
G4LogicalVolume* ConstructFieldCageAndReadout(G4LogicalVolume*);
Expand All @@ -50,6 +51,7 @@ namespace nexus {
G4String gas_;
G4double gas_pressure_, gas_temperature_;
G4double detector_diam_, detector_length_;
G4double rock_thickn_, rock_diam_;
G4double tank_size_, tank_thickn_, water_thickn_;
G4double vessel_thickn_, ics_thickn_, endcap_hollow_;
G4double fcage_thickn_, active_diam_, active_length_;
Expand Down
Loading