Import Geant4 11.1.0.beta source tree

This commit is contained in:
Gabriele Cosmo
2022-07-01 10:44:02 +02:00
parent b3bf75a2a1
commit c07cea1fe0
2172 changed files with 183300 additions and 123938 deletions
@@ -46,6 +46,7 @@
#include "G4SDManager.hh" // for G4SDManager
#include "Par04DetectorConstruction.hh" // for Par04DetectorConstruction
#include "Par04Hit.hh" // for Par04Hit, Par04HitsCollection
#include <cmath> // for log10
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -100,6 +101,7 @@ void Par04EventAction::EndOfEventAction(const G4Event* aEvent)
if(fCellSizeZ == 0)
{
fCellSizeZ = fDetector->GetMeshSizeOfCells().z();
fCellSizePhi = fDetector->GetMeshSizeOfCells().y();
fCellSizeRho = fDetector->GetMeshSizeOfCells().x();
fCellNbRho = fDetector->GetMeshNbOfCells().x();
fCellNbPhi = fDetector->GetMeshNbOfCells().y();
@@ -133,9 +135,10 @@ void Par04EventAction::EndOfEventAction(const G4Event* aEvent)
G4int hitPhi = -1;
G4int hitType = -1;
G4int numNonZeroThresholdCells = 0;
G4double tDistance = 0., rDistance = 0.;
G4double tDistance = 0., rDistance = 0., phiDistance = 0.;
G4double tFirstMoment = 0., tSecondMoment = 0.;
G4double rFirstMoment = 0., rSecondMoment = 0.;
G4double phiMean = 0.;
for(size_t iHit = 0; iHit < hitsCollection->entries(); iHit++)
{
hit = static_cast<Par04Hit*>(hitsCollection->GetHit(iHit));
@@ -149,8 +152,10 @@ void Par04EventAction::EndOfEventAction(const G4Event* aEvent)
totalEnergy += hitEn;
tDistance = hitZ * fCellSizeZ;
rDistance = hitRho * fCellSizeRho;
phiDistance = hitPhi * fCellSizePhi;
tFirstMoment += hitEn * tDistance;
rFirstMoment += hitEn * rDistance;
phiMean += hitEn * phiDistance;
analysisManager->FillH1(4, tDistance, hitEn);
analysisManager->FillH1(5, rDistance, hitEn);
analysisManager->FillH1(10, hitType);
@@ -161,17 +166,20 @@ void Par04EventAction::EndOfEventAction(const G4Event* aEvent)
fCalPhi[numNonZeroThresholdCells] = hitPhi;
fCalZ[numNonZeroThresholdCells] = hitZ;
numNonZeroThresholdCells++;
analysisManager->FillH1(13, std::log10(hitEn));
}
}
}
tFirstMoment /= totalEnergy;
rFirstMoment /= totalEnergy;
phiMean /= totalEnergy;
analysisManager->FillH1(0, primaryEnergy / GeV);
analysisManager->FillH1(1, totalEnergy / GeV);
analysisManager->FillH1(2, totalEnergy / primaryEnergy);
analysisManager->FillH1(3, fTimer.GetRealElapsed());
analysisManager->FillH1(6, tFirstMoment);
analysisManager->FillH1(7, rFirstMoment);
analysisManager->FillH1(12, numNonZeroThresholdCells);
// Resize to store only energy hits above threshold
fCalEdep.resize(numNonZeroThresholdCells);
fCalRho.resize(numNonZeroThresholdCells);
@@ -187,12 +195,15 @@ void Par04EventAction::EndOfEventAction(const G4Event* aEvent)
hitEn = hit->GetEdep();
hitZ = hit->GetZid();
hitRho = hit->GetRhoId();
hitPhi = hit->GetPhiId();
if(hitEn > 0)
{
tDistance = hitZ * fCellSizeZ;
rDistance = hitRho * fCellSizeRho;
phiDistance = hitPhi * fCellSizePhi;
tSecondMoment += hitEn * std::pow(tDistance - tFirstMoment, 2);
rSecondMoment += hitEn * std::pow(rDistance - rFirstMoment, 2);
analysisManager->FillH1(11, phiDistance - phiMean, hitEn);
}
}
tSecondMoment /= totalEnergy;
@@ -43,6 +43,7 @@
#include "G4UnitsTable.hh" // for G4BestUnit
#include "G4VVisManager.hh" // for G4VVisManager
#include "G4VisAttributes.hh" // for G4VisAttributes
#include <cmath> // for log10
template <class Type> class G4Allocator;
G4ThreadLocal G4Allocator<Par04Hit>* Par04HitAllocator;
@@ -100,7 +101,7 @@ int Par04Hit::operator==(const Par04Hit& aRight) const
void Par04Hit::Draw()
{
/// TOFIX do not hardcode size
/// Arbitrary size corresponds to the example macros
G4ThreeVector meshSize(2.325 * mm, 2 * CLHEP::pi / 50. * CLHEP::rad, 3.4 * mm);
G4int numPhiCells = CLHEP::pi * 2. / meshSize.y();
G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
@@ -123,7 +124,11 @@ void Par04Hit::Draw()
G4double colR = fType == 0 ? 0 : 1;
G4double colG = fType == 0 ? 1 : 0;
G4double colB = 0;
G4Colour colour(colR, colG, colB, 0.5);
// Set transparency depending on the energy
// Arbitrary formula
G4double alpha = 2 * std::log10(fEdep + 1);
G4cout << "alpha = " << alpha << G4endl;
G4Colour colour(colR, colG, colB, alpha);
attribs.SetColour(colour);
attribs.SetForceSolid(true);
pVVisManager->Draw(solid, attribs, trans);
@@ -163,6 +168,7 @@ std::vector<G4AttValue>* Par04Hit::CreateAttValues() const
void Par04Hit::Print()
{
std::cout << "\tHit " << fEdep / MeV << " MeV at " << fPos / cm << " cm (R,phi,z)= (" << fRhoId
<< ", " << fPhiId << ", " << fZId << "), " << fTime << " ns" << std::endl;
std::cout << "\tHit " << fEdep / MeV << " MeV at " << fPos / cm << " cm rotation " << fRot
<< " (R,phi,z)= (" << fRhoId << ", " << fPhiId << ", " << fZId << "), " << fTime << " ns"
<< std::endl;
}
@@ -25,12 +25,17 @@
//
#ifdef USE_INFERENCE
#include "Par04InferenceMessenger.hh"
#include "Par04InferenceSetup.hh"
#include "G4UIdirectory.hh"
#include "G4UIcmdWithoutParameter.hh"
#include "G4UIcmdWithAnInteger.hh"
#include "G4UIcmdWithADoubleAndUnit.hh"
#include "G4UIcmdWithAString.hh"
#include <CLHEP/Units/SystemOfUnits.h> // for pi
#include <G4ApplicationState.hh> // for G4State_Idle
#include <G4ThreeVector.hh> // for G4ThreeVector
#include <G4UImessenger.hh> // for G4UImessenger
#include <string> // for stoi
#include "G4UIcmdWithADoubleAndUnit.hh" // for G4UIcmdWithADoubleAndUnit
#include "G4UIcmdWithAString.hh" // for G4UIcmdWithAString
#include "G4UIcmdWithAnInteger.hh" // for G4UIcmdWithAnInteger
#include "G4UIdirectory.hh" // for G4UIdirectory
#include "Par04InferenceSetup.hh" // for Par04InferenceSetup
class G4UIcommand;
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -246,4 +251,4 @@ G4String Par04InferenceMessenger::GetCurrentValue(G4UIcommand* aCommand)
return cv;
}
#endif
#endif
@@ -25,16 +25,26 @@
//
#ifdef USE_INFERENCE
#include "Par04InferenceSetup.hh"
#include "Par04InferenceInterface.hh"
#include "Par04InferenceInterface.hh" // for Par04InferenceInterface
#include "Par04InferenceMessenger.hh" // for Par04InferenceMessenger
#ifdef USE_INFERENCE_ONNX
#include "Par04OnnxInference.hh"
#include "Par04OnnxInference.hh" // for Par04OnnxInference
#endif
#ifdef USE_INFERENCE_LWTNN
#include "Par04LwtnnInference.hh"
#include "Par04LwtnnInference.hh" // for Par04LwtnnInference
#endif
#include "G4RotationMatrix.hh"
#include "CLHEP/Random/RandGauss.h"
#include <CLHEP/Units/SystemOfUnits.h> // for pi, GeV, deg
#include <CLHEP/Vector/Rotation.h> // for HepRotation
#include <CLHEP/Vector/ThreeVector.h> // for Hep3Vector
#include <G4Exception.hh> // for G4Exception
#include <G4ExceptionSeverity.hh> // for FatalException
#include <G4ThreeVector.hh> // for G4ThreeVector
#include "CLHEP/Random/RandGauss.h" // for RandGauss
#include "G4RotationMatrix.hh" // for G4RotationMatrix
#include <algorithm> // for max, copy
#include <string> // for char_traits, basic_string
#include <ext/alloc_traits.h> // for __alloc_traits<>::value_type
#include <cmath> // for cos, sin
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -53,6 +63,7 @@ G4bool Par04InferenceSetup::IfTrigger(G4double aEnergy)
/// Energy of electrons used in training dataset
if(aEnergy > 1 * CLHEP::GeV || aEnergy < 1024 * CLHEP::GeV)
return true;
return false;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -24,8 +24,10 @@
// ********************************************************************
//
#ifdef USE_INFERENCE_LWTNN
#include "Par04InferenceInterface.hh"
#include "Par04LwtnnInference.hh"
#include <fstream> // for ifstream
#include <lwtnn/parse_json.hh> // for parse_json_graph
#include "Par04InferenceInterface.hh" // for Par04InferenceInterface
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -41,12 +43,12 @@ Par04LwtnnInference::Par04LwtnnInference(G4String modelPath)
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void Par04LwtnnInference::RunInference(vector<float> aGenVector, std::vector<G4double>& aEnergies,
void Par04LwtnnInference::RunInference(std::vector<float> aGenVector, std::vector<G4double>& aEnergies,
int aSize)
{
// generation vector
fNetworkInputs inputs;
for(int i = 0; i < (unsigned) (aGenVector.size()); ++i)
for(std::size_t i = 0; i < aGenVector.size(); ++i)
{
inputs["node_0"]["variable_" + std::to_string(i)] = aGenVector[i];
}
@@ -25,16 +25,19 @@
//
#ifdef USE_INFERENCE
#include "Par04MLFastSimModel.hh"
#include "G4Electron.hh"
#include "G4Positron.hh"
#include "G4Gamma.hh"
#include "G4SystemOfUnits.hh"
#include "G4UnitsTable.hh"
#include "G4FastHit.hh"
#include "G4FastSimHitMaker.hh"
#include "Randomize.hh"
#include "CLHEP/Units/SystemOfUnits.h"
#include <numeric>
#include <stddef.h> // for size_t
#include <G4FastStep.hh> // for G4FastStep
#include <G4FastTrack.hh> // for G4FastTrack
#include <G4Track.hh> // for G4Track
#include <G4VFastSimulationModel.hh> // for G4VFastSimulationModel
#include "G4Electron.hh" // for G4Electron
#include "G4FastHit.hh" // for G4FastHit
#include "G4FastSimHitMaker.hh" // for G4FastSimHitMaker
#include "G4Gamma.hh" // for G4Gamma
#include "G4Positron.hh" // for G4Positron
#include "Par04InferenceSetup.hh" // for Par04InferenceSetup
class G4ParticleDefinition;
class G4Region;
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -24,10 +24,15 @@
// ********************************************************************
//
#ifdef USE_INFERENCE_ONNX
#include "Par04InferenceInterface.hh"
#include "G4RotationMatrix.hh"
#include "Par04OnnxInference.hh"
#include <cassert>
#include <core/session/onnxruntime_cxx_api.h> // for Value, Session, Env
#include <algorithm> // for copy, max
#include <cassert> // for assert
#include <cstddef> // for size_t
#include <cstdint> // for int64_t
#include <utility> // for move
#include "Par04InferenceInterface.hh" // for Par04InferenceInterface
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -61,7 +66,7 @@ Par04OnnxInference::Par04OnnxInference(G4String modelPath, G4int profileFlag, G4
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void Par04OnnxInference::RunInference(vector<float> aGenVector, std::vector<G4double>& aEnergies,
void Par04OnnxInference::RunInference(std::vector<float> aGenVector, std::vector<G4double>& aEnergies,
int aSize)
{
// input nodes
@@ -76,9 +81,8 @@ void Par04OnnxInference::RunInference(vector<float> aGenVector, std::vector<G4do
input_node_names[i] = input_name;
Ort::TypeInfo type_info = fSession->GetInputTypeInfo(i);
auto tensor_info = type_info.GetTensorTypeAndShapeInfo();
ONNXTensorElementDataType type = tensor_info.GetElementType();
input_node_dims = tensor_info.GetShape();
for(int j = 0; j < input_node_dims.size(); j++)
for(std::size_t j = 0; j < input_node_dims.size(); j++)
{
if(input_node_dims[j] < 0)
input_node_dims[j] = 1;
@@ -94,9 +98,8 @@ void Par04OnnxInference::RunInference(vector<float> aGenVector, std::vector<G4do
output_node_names[i] = output_name;
Ort::TypeInfo type_info = fSession->GetOutputTypeInfo(i);
auto tensor_info = type_info.GetTensorTypeAndShapeInfo();
ONNXTensorElementDataType type = tensor_info.GetElementType();
output_node_dims = tensor_info.GetShape();
for(int j = 0; j < output_node_dims.size(); j++)
for(std::size_t j = 0; j < output_node_dims.size(); j++)
{
if(output_node_dims[j] < 0)
output_node_dims[j] = 1;
@@ -104,13 +107,9 @@ void Par04OnnxInference::RunInference(vector<float> aGenVector, std::vector<G4do
}
// create input tensor object from data values
float genVector[(unsigned) (aGenVector.size())];
for(int i = 0; i < (unsigned) (aGenVector.size()); i++)
genVector[i] = aGenVector[i];
int values_length = sizeof(genVector) / sizeof(genVector[0]);
std::vector<int64_t> dims = { 1, (unsigned) (aGenVector.size()) };
Ort::Value Input_noise_tensor =
Ort::Value::CreateTensor<float>(fInfo, genVector, values_length, dims.data(), dims.size());
Ort::Value::CreateTensor<float>(fInfo, aGenVector.data(), aGenVector.size(), dims.data(), dims.size());
assert(Input_noise_tensor.IsTensor());
std::vector<Ort::Value> ort_inputs;
ort_inputs.push_back(std::move(Input_noise_tensor));
@@ -59,14 +59,16 @@ void Par04RunAction::BeginOfRunAction(const G4Run*)
G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
// Create directories
analysisManager->SetNtupleMerging(false);
analysisManager->SetNtupleMerging(true);
analysisManager->SetVerboseLevel(0);
// Get detector dimensions
G4int cellNumZ = fDetector->GetMeshNbOfCells().z();
G4int cellNumRho = fDetector->GetMeshNbOfCells().x();
G4int cellNumPhi = fDetector->GetMeshNbOfCells().y();
G4double cellSizeZ = fDetector->GetMeshSizeOfCells().z();
G4double cellSizeRho = fDetector->GetMeshSizeOfCells().x();
G4double cellSizePhi = fDetector->GetMeshSizeOfCells().y();
// Default max value of energy stored in histogram (in GeV)
G4double maxEnergy = 1000;
@@ -101,6 +103,10 @@ void Par04RunAction::BeginOfRunAction(const G4Run*)
"transSecondMoment", "Second moment of transverse distribution;#LTr^{2}#GT (mm^{2});Entries",
1024, 0, std::pow(cellNumRho * cellSizeRho, 2) / 5); // arbitrary scaling of max value on axis
analysisManager->CreateH1("hitType", "hit type;type (0=full, 1= fast);Entries", 2, -0.5, 1.5);
analysisManager->CreateH1("phiProfile", "Azimuthal angle profile, centred at mean;phi;#LTE#GT (MeV)", cellNumPhi,
- (cellNumPhi - 0.5) * cellSizePhi, (cellNumPhi - 0.5) * cellSizePhi);
analysisManager->CreateH1("numHits", "Number of hits above 0.5 keV", 4048, 0, 40500);
analysisManager->CreateH1("cellEnergy", "Cell energy distribution;log10(E/MeV);Entries", 1024, -4, 2);
// Creating ntuple
analysisManager->CreateNtuple("events", "per event data");
@@ -185,8 +185,8 @@ Par04Hit* Par04SensitiveDetector::RetrieveAndSetupHit(G4ThreeVector aGlobalPosit
std::size_t hitID =
fMeshNbOfCells.x() * fMeshNbOfCells.z() * phiNo + fMeshNbOfCells.z() * rhoNo + zNo;
if(hitID >= fHitsCollection->entries() || zNo > fMeshNbOfCells.z() ||
rhoNo > fMeshNbOfCells.x() || zNo < 0)
if(hitID >= fHitsCollection->entries() || zNo >= fMeshNbOfCells.z() ||
rhoNo >= fMeshNbOfCells.x() || zNo < 0)
{
return nullptr;
}