Compare commits
No commits in common. "f003c1697a2406fe8c4ec219f7ebc09e4a4d8c7c" and "6c121232f836bf89afe8eb0ca4623e0d2007e635" have entirely different histories.
f003c1697a
...
6c121232f8
11 changed files with 121 additions and 201 deletions
|
|
@ -5,19 +5,15 @@ project(Tutorial)
|
||||||
find_package(Geant4 REQUIRED ui_all vis_all)
|
find_package(Geant4 REQUIRED ui_all vis_all)
|
||||||
|
|
||||||
include(${Geant4_USE_FILE})
|
include(${Geant4_USE_FILE})
|
||||||
|
|
||||||
include_directories(${PROJECT_SOURCE_DIR}/include)
|
include_directories(${PROJECT_SOURCE_DIR}/include)
|
||||||
|
|
||||||
# Sammle alle .cc Dateien
|
|
||||||
file(GLOB sources ${PROJECT_SOURCE_DIR}/src/*.cc)
|
file(GLOB sources ${PROJECT_SOURCE_DIR}/src/*.cc)
|
||||||
|
|
||||||
# Entferne unerwünschte Dateien
|
|
||||||
list(REMOVE_ITEM sources ${PROJECT_SOURCE_DIR}/src/ADetectorConstructionv2.cc)
|
|
||||||
list(REMOVE_ITEM sources ${PROJECT_SOURCE_DIR}/src/ASensitiveDetectorv2.cc)
|
|
||||||
list(REMOVE_ITEM sources ${PROJECT_SOURCE_DIR}/src/ARunMessenger.cc)
|
|
||||||
list(REMOVE_ITEM sources ${PROJECT_SOURCE_DIR}/src/ARunActionv2.cc)
|
|
||||||
|
|
||||||
file(GLOB MACRO_FILES "macros/*.mac")
|
file(GLOB MACRO_FILES "macros/*.mac")
|
||||||
file(COPY ${MACRO_FILES} DESTINATION ${CMAKE_BINARY_DIR}/)
|
file(COPY ${MACRO_FILES} DESTINATION ${CMAKE_BINARY_DIR}/)
|
||||||
|
|
||||||
add_executable(sim sim.cc ${sources})
|
add_executable(sim sim.cc ${sources})
|
||||||
target_link_libraries(sim ${Geant4_LIBRARIES})
|
target_link_libraries(sim ${Geant4_LIBRARIES})
|
||||||
|
|
||||||
|
add_custom_target(Tutorial DEPENDS sim)
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,18 @@
|
||||||
#ifndef AACTIONINITIALIZATION_H
|
#ifndef AACTIONINITIALIZATION_HH
|
||||||
#define AACTIONINITIALIZATION_H
|
#define AACTIONINITIALIZATION_HH
|
||||||
|
|
||||||
#include "G4VUserActionInitialization.hh"
|
#include "G4VUserActionInitialization.hh"
|
||||||
|
#include "APrimaryGenerator.hh"
|
||||||
|
#include "ARunAction.hh"
|
||||||
|
|
||||||
class AActionInitialization : public G4VUserActionInitialization
|
class AActionInitialization : public G4VUserActionInitialization
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AActionInitialization();
|
AActionInitialization();
|
||||||
virtual ~AActionInitialization();
|
~AActionInitialization();
|
||||||
|
|
||||||
virtual void Build() const override;
|
virtual void BuildForMaster() const;
|
||||||
virtual void BuildForMaster() const override;
|
virtual void Build() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include "G4VUserDetectorConstruction.hh"
|
#include "G4VUserDetectorConstruction.hh"
|
||||||
#include "G4UImessenger.hh"
|
#include "G4UImessenger.hh"
|
||||||
|
#include "G4Cache.hh"
|
||||||
|
|
||||||
#include "G4Box.hh"
|
#include "G4Box.hh"
|
||||||
#include "G4LogicalVolume.hh"
|
#include "G4LogicalVolume.hh"
|
||||||
|
|
@ -19,24 +20,30 @@
|
||||||
#include "G4SDManager.hh"
|
#include "G4SDManager.hh"
|
||||||
|
|
||||||
#include "ASensitiveDetector.hh"
|
#include "ASensitiveDetector.hh"
|
||||||
#include "AMessenger.hh"
|
#include "G4UImessenger.hh"
|
||||||
|
#include "G4Cache.hh"
|
||||||
|
|
||||||
|
#include "G4UImessenger.hh"
|
||||||
|
#include "G4Cache.hh"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
class ADetectorConstruction : public G4VUserDetectorConstruction
|
//#include "G4GDMLParser.hh"
|
||||||
|
|
||||||
|
|
||||||
|
class ADetectorConstruction : public G4VUserDetectorConstruction, public G4UImessenger
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ADetectorConstruction();
|
ADetectorConstruction();
|
||||||
virtual ~ADetectorConstruction();
|
virtual ~ADetectorConstruction();
|
||||||
|
|
||||||
virtual G4VPhysicalVolume* Construct();
|
virtual G4VPhysicalVolume *Construct();
|
||||||
|
|
||||||
void ConstructSDandField();
|
void ConstructSDandField();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<G4LogicalVolume*> detectorVolumes;
|
std::vector<G4LogicalVolume*> detectorVolumes;
|
||||||
|
|
||||||
// Hier fSD als Member speichern
|
|
||||||
ASensitiveDetector* fSD;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
||||||
#ifndef AMESSENGER_HH
|
|
||||||
#define AMESSENGER_HH
|
|
||||||
|
|
||||||
#include "G4UImessenger.hh"
|
|
||||||
#include "G4UIcmdWithAString.hh"
|
|
||||||
|
|
||||||
class ASensitiveDetector;
|
|
||||||
|
|
||||||
class AMessenger : public G4UImessenger
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
AMessenger(ASensitiveDetector* sd);
|
|
||||||
~AMessenger();
|
|
||||||
|
|
||||||
virtual void SetNewValue(G4UIcommand* cmd, G4String value) override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
ASensitiveDetector* fSD;
|
|
||||||
G4UIcmdWithAString* fOutputFileCmd;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
@ -8,14 +8,10 @@
|
||||||
#include "G4Track.hh"
|
#include "G4Track.hh"
|
||||||
#include "G4SystemOfUnits.hh"
|
#include "G4SystemOfUnits.hh"
|
||||||
#include "G4UnitsTable.hh"
|
#include "G4UnitsTable.hh"
|
||||||
#include "G4UImessenger.hh"
|
|
||||||
#include "G4UIcmdWithAString.hh"
|
|
||||||
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
class AMessenger;
|
|
||||||
|
|
||||||
class ASensitiveDetector : public G4VSensitiveDetector
|
class ASensitiveDetector : public G4VSensitiveDetector
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
@ -25,17 +21,8 @@ public:
|
||||||
virtual void Initialize(G4HCofThisEvent* hce) override;
|
virtual void Initialize(G4HCofThisEvent* hce) override;
|
||||||
virtual void EndOfEvent(G4HCofThisEvent* hce) override;
|
virtual void EndOfEvent(G4HCofThisEvent* hce) override;
|
||||||
virtual G4bool ProcessHits(G4Step* step, G4TouchableHistory* touchHist) override;
|
virtual G4bool ProcessHits(G4Step* step, G4TouchableHistory* touchHist) override;
|
||||||
//Filename
|
|
||||||
void SetOutputFilename(const G4String& name) { fOutputFilename = name; }
|
|
||||||
void SetMessenger(AMessenger* messenger) { fMessenger = messenger; }
|
|
||||||
void RegisterVolumeName(G4LogicalVolume* lv, const std::string& cleanName) {
|
|
||||||
fCleanNames[lv] = cleanName;}
|
|
||||||
|
|
||||||
private:
|
|
||||||
AMessenger* fMessenger = nullptr; // jetzt optional
|
|
||||||
G4String fOutputFilename = "outfiles/shower_setup.txt";
|
|
||||||
G4int fCurrentEventID = -1; // speichert die aktuelle Event-ID
|
|
||||||
|
|
||||||
|
private:
|
||||||
struct HitInfo {
|
struct HitInfo {
|
||||||
G4int eventID;
|
G4int eventID;
|
||||||
G4int trackID;
|
G4int trackID;
|
||||||
|
|
@ -46,16 +33,13 @@ private:
|
||||||
G4double primaryEnergy;
|
G4double primaryEnergy;
|
||||||
G4double energyDeposited;
|
G4double energyDeposited;
|
||||||
G4String detectorName;
|
G4String detectorName;
|
||||||
G4String cleanDetectorName;
|
|
||||||
|
|
||||||
HitInfo()
|
HitInfo()
|
||||||
: trackID(-1), parentID(-1), particleEnergy(0.), primaryEnergy(0.), energyDeposited(0.) {}
|
: trackID(-1), parentID(-1), particleEnergy(0.), primaryEnergy(0.), energyDeposited(0.) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
G4String fDetectorName;
|
G4String fDetectorName;
|
||||||
std::unordered_map<G4LogicalVolume*, std::string> fCleanNames;
|
|
||||||
std::unordered_map<G4int, HitInfo> fTrackHitMap; // TrackID → HitInfo
|
std::unordered_map<G4int, HitInfo> fTrackHitMap; // TrackID → HitInfo
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
66
sim.cc
66
sim.cc
|
|
@ -1,4 +1,7 @@
|
||||||
|
//Including header files
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
// Including Geant4 stuff, G4MT is for multithreading
|
||||||
#include "G4RunManager.hh"
|
#include "G4RunManager.hh"
|
||||||
#include "G4MTRunManager.hh"
|
#include "G4MTRunManager.hh"
|
||||||
#include "G4UImanager.hh"
|
#include "G4UImanager.hh"
|
||||||
|
|
@ -12,49 +15,52 @@
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
// UI
|
//G4UIExecutive *ui = new G4UIExecutive(argc, argv);
|
||||||
G4UIExecutive* ui = nullptr;
|
G4UIExecutive *ui = 0;
|
||||||
if (argc == 1) ui = new G4UIExecutive(argc, argv);
|
if (argc == 1)
|
||||||
|
{
|
||||||
|
ui = new G4UIExecutive(argc, argv);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef G4MULTITHREADED
|
||||||
|
G4MTRunManager *runManager = new G4MTRunManager;
|
||||||
|
#else
|
||||||
|
G4RunManager *runManager = new G4RunManager;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Physics list
|
||||||
|
runManager->SetUserInitialization(static_cast<G4VUserPhysicsList*>(new APhysicsList()));
|
||||||
|
// Detector Construction
|
||||||
|
runManager->SetUserInitialization(static_cast<G4VUserDetectorConstruction*>(new ADetectorConstruction()));
|
||||||
|
// Action initialization
|
||||||
|
runManager->SetUserInitialization(static_cast<G4VUserActionInitialization*>(new AActionInitialization()));
|
||||||
|
|
||||||
|
|
||||||
#ifdef G4MULTITHREADED
|
|
||||||
G4MTRunManager* runManager = new G4MTRunManager;
|
G4VisManager *visManager = new G4VisExecutive();
|
||||||
#else
|
|
||||||
G4RunManager* runManager = new G4RunManager;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Physics
|
|
||||||
runManager->SetUserInitialization(new APhysicsList());
|
|
||||||
|
|
||||||
// Detector
|
|
||||||
runManager->SetUserInitialization(new ADetectorConstruction());
|
|
||||||
|
|
||||||
// Actions
|
|
||||||
runManager->SetUserInitialization(new AActionInitialization());
|
|
||||||
|
|
||||||
// Visualization
|
|
||||||
G4VisManager* visManager = new G4VisExecutive();
|
|
||||||
visManager->Initialize();
|
visManager->Initialize();
|
||||||
|
|
||||||
// UI manager
|
G4UImanager *UImanager = G4UImanager::GetUIpointer();
|
||||||
G4UImanager* UImanager = G4UImanager::GetUIpointer();
|
|
||||||
|
|
||||||
if (ui)
|
if (ui)
|
||||||
{
|
{
|
||||||
G4cout << "UI exists" << G4endl;
|
G4cout << "ui exists" << G4endl;
|
||||||
UImanager->ApplyCommand("/control/execute vis.mac");
|
UImanager->ApplyCommand("/control/execute vis.mac");
|
||||||
ui->SessionStart();
|
ui->SessionStart();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
G4cout << "ui does not exists" << G4endl;
|
||||||
G4String command = "/control/execute ";
|
G4String command = "/control/execute ";
|
||||||
G4String fileName = argv[1];
|
G4String fileName = argv[1];
|
||||||
UImanager->ApplyCommand(command + fileName);
|
UImanager->ApplyCommand(command + fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clean up
|
//clean up
|
||||||
delete runManager;
|
delete runManager;
|
||||||
delete visManager;
|
delete visManager;
|
||||||
if (ui) delete ui;
|
if (ui) delete ui;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
}
|
||||||
|
|
@ -1,24 +1,40 @@
|
||||||
#include "AActionInitialization.hh"
|
#include "AActionInitialization.hh"
|
||||||
#include "APrimaryGenerator.hh"
|
//#include "PrimaryGeneratorAction.hh"
|
||||||
#include "ARunAction.hh"
|
|
||||||
|
|
||||||
AActionInitialization::AActionInitialization()
|
AActionInitialization::AActionInitialization()
|
||||||
: G4VUserActionInitialization()
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
AActionInitialization::~AActionInitialization() {}
|
AActionInitialization::~AActionInitialization()
|
||||||
|
|
||||||
void AActionInitialization::Build() const
|
|
||||||
{
|
{
|
||||||
// Primärgenerator
|
|
||||||
SetUserAction(new APrimaryGenerator());
|
|
||||||
|
|
||||||
// RunAction
|
|
||||||
SetUserAction(new ARunAction());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AActionInitialization::BuildForMaster() const
|
void AActionInitialization::BuildForMaster() const
|
||||||
{
|
{
|
||||||
SetUserAction(new ARunAction());
|
// This is needed to avoid problems due to multithreading when writing the data.
|
||||||
|
ARunAction *runAction = new ARunAction();
|
||||||
|
SetUserAction(runAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AActionInitialization::Build() const
|
||||||
|
{
|
||||||
|
// PrimaryGenerator and SteppingAction do not have to be set in BuildForMaster because they only
|
||||||
|
// regard individual threads.
|
||||||
|
|
||||||
|
APrimaryGenerator *generator = new APrimaryGenerator();
|
||||||
|
SetUserAction(generator);
|
||||||
|
|
||||||
|
ARunAction *runAction = new ARunAction();
|
||||||
|
SetUserAction(runAction);
|
||||||
|
|
||||||
|
// SteppingAction *steppingAction = new SteppingAction();
|
||||||
|
// SetUserAction(steppingAction);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// void UserActionInitialization::Build() const {
|
||||||
|
// SetUserAction(new PrimaryGeneratorAction);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// void UserActionInitialization::BuildForMaster() const {
|
||||||
|
// }
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
#include "ADetectorConstruction.hh"
|
#include "ADetectorConstruction.hh"
|
||||||
#include "ASensitiveDetector.hh"
|
#include "ASensitiveDetector.hh"
|
||||||
#include "AMessenger.hh"
|
|
||||||
|
|
||||||
#include "G4Box.hh"
|
#include "G4Box.hh"
|
||||||
#include "G4PVPlacement.hh"
|
#include "G4PVPlacement.hh"
|
||||||
|
|
@ -11,20 +10,9 @@
|
||||||
#include "G4SDManager.hh"
|
#include "G4SDManager.hh"
|
||||||
#include "G4SystemOfUnits.hh"
|
#include "G4SystemOfUnits.hh"
|
||||||
|
|
||||||
ADetectorConstruction::ADetectorConstruction()
|
ADetectorConstruction::ADetectorConstruction() {}
|
||||||
{
|
|
||||||
//Ein einziges SensitiveDetector erzeugen
|
|
||||||
fSD = new ASensitiveDetector("shower_setup");
|
|
||||||
|
|
||||||
//Messenger für den SD erzeugen
|
ADetectorConstruction::~ADetectorConstruction() {}
|
||||||
AMessenger* messenger = new AMessenger(fSD);
|
|
||||||
fSD->SetMessenger(messenger);
|
|
||||||
}
|
|
||||||
|
|
||||||
ADetectorConstruction::~ADetectorConstruction()
|
|
||||||
{
|
|
||||||
delete fSD; // SD + Messenger werden hier aufgeräumt
|
|
||||||
}
|
|
||||||
|
|
||||||
G4VPhysicalVolume* ADetectorConstruction::Construct()
|
G4VPhysicalVolume* ADetectorConstruction::Construct()
|
||||||
{
|
{
|
||||||
|
|
@ -105,12 +93,15 @@ G4VPhysicalVolume* ADetectorConstruction::Construct()
|
||||||
// --- SensitiveDetector zuweisen ---
|
// --- SensitiveDetector zuweisen ---
|
||||||
void ADetectorConstruction::ConstructSDandField()
|
void ADetectorConstruction::ConstructSDandField()
|
||||||
{
|
{
|
||||||
// SD bei Geant4 registrieren
|
// Ein einziger SensitiveDetector für alle Layer
|
||||||
G4SDManager::GetSDMpointer()->AddNewDetector(fSD);
|
G4String sdName = "shower_setup";
|
||||||
|
ASensitiveDetector* sd = new ASensitiveDetector(sdName);
|
||||||
|
|
||||||
|
G4SDManager::GetSDMpointer()->AddNewDetector(sd);
|
||||||
|
|
||||||
// Alle Layer bekommen denselben SD
|
// Alle Layer bekommen denselben SD
|
||||||
for(auto lv : detectorVolumes)
|
for(auto lv : detectorVolumes)
|
||||||
{
|
{
|
||||||
lv->SetSensitiveDetector(fSD);
|
lv->SetSensitiveDetector(sd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
||||||
#include "AMessenger.hh"
|
|
||||||
#include "ASensitiveDetector.hh"
|
|
||||||
|
|
||||||
AMessenger::AMessenger(ASensitiveDetector* sd)
|
|
||||||
: fSD(sd)
|
|
||||||
{
|
|
||||||
// eigenes UI Kommando
|
|
||||||
fOutputFileCmd = new G4UIcmdWithAString("/my/outputFilename", this);
|
|
||||||
fOutputFileCmd->SetGuidance("Set output filename for SD text output.");
|
|
||||||
fOutputFileCmd->SetParameterName("filename", false);
|
|
||||||
}
|
|
||||||
|
|
||||||
AMessenger::~AMessenger()
|
|
||||||
{
|
|
||||||
delete fOutputFileCmd;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AMessenger::SetNewValue(G4UIcommand* cmd, G4String value)
|
|
||||||
{
|
|
||||||
if (cmd == fOutputFileCmd)
|
|
||||||
{
|
|
||||||
fSD->SetOutputFilename(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -31,7 +31,7 @@ void ARunAction::BeginOfRunAction(const G4Run *run)
|
||||||
std::stringstream strRunID;
|
std::stringstream strRunID;
|
||||||
strRunID << runID;
|
strRunID << runID;
|
||||||
|
|
||||||
analysisManager->OpenFile("output" + strRunID.str() + ".root");
|
//analysisManager->OpenFile("output" + strRunID.str() + ".root");
|
||||||
}
|
}
|
||||||
|
|
||||||
void ARunAction::EndOfRunAction(const G4Run *run)
|
void ARunAction::EndOfRunAction(const G4Run *run)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
#include "ASensitiveDetector.hh"
|
#include "ASensitiveDetector.hh"
|
||||||
#include "AMessenger.hh"
|
|
||||||
#include "G4RunManager.hh"
|
#include "G4RunManager.hh"
|
||||||
#include "G4Event.hh"
|
#include "G4Event.hh"
|
||||||
#include "G4PrimaryVertex.hh"
|
#include "G4PrimaryVertex.hh"
|
||||||
|
|
@ -11,14 +10,9 @@
|
||||||
ASensitiveDetector::ASensitiveDetector(G4String name)
|
ASensitiveDetector::ASensitiveDetector(G4String name)
|
||||||
: G4VSensitiveDetector(name), fDetectorName(name)
|
: G4VSensitiveDetector(name), fDetectorName(name)
|
||||||
{
|
{
|
||||||
fOutputFilename = "outfiles/shower_setup.txt";
|
|
||||||
std::filesystem::create_directories("outfiles");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ASensitiveDetector::~ASensitiveDetector()
|
ASensitiveDetector::~ASensitiveDetector() {}
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void ASensitiveDetector::Initialize(G4HCofThisEvent* /*hce*/)
|
void ASensitiveDetector::Initialize(G4HCofThisEvent* /*hce*/)
|
||||||
{
|
{
|
||||||
|
|
@ -28,12 +22,6 @@ void ASensitiveDetector::Initialize(G4HCofThisEvent* /*hce*/)
|
||||||
G4bool ASensitiveDetector::ProcessHits(G4Step* step, G4TouchableHistory* /*touchHist*/)
|
G4bool ASensitiveDetector::ProcessHits(G4Step* step, G4TouchableHistory* /*touchHist*/)
|
||||||
{
|
{
|
||||||
const G4Event* event = G4RunManager::GetRunManager()->GetCurrentEvent();
|
const G4Event* event = G4RunManager::GetRunManager()->GetCurrentEvent();
|
||||||
|
|
||||||
if (!event) return false;
|
|
||||||
|
|
||||||
// Event-ID direkt hier setzen
|
|
||||||
fCurrentEventID = event->GetEventID();
|
|
||||||
|
|
||||||
G4Track* track = step->GetTrack();
|
G4Track* track = step->GetTrack();
|
||||||
G4int trackID = track->GetTrackID();
|
G4int trackID = track->GetTrackID();
|
||||||
|
|
||||||
|
|
@ -41,26 +29,26 @@ G4bool ASensitiveDetector::ProcessHits(G4Step* step, G4TouchableHistory* /*touch
|
||||||
if (it == fTrackHitMap.end())
|
if (it == fTrackHitMap.end())
|
||||||
{
|
{
|
||||||
HitInfo hit;
|
HitInfo hit;
|
||||||
hit.eventID = fCurrentEventID;
|
hit.eventID = event->GetEventID();
|
||||||
hit.trackID = trackID;
|
hit.trackID = trackID;
|
||||||
hit.parentID = track->GetParentID();
|
hit.parentID = track->GetParentID();
|
||||||
hit.particleName = track->GetDefinition()->GetParticleName();
|
hit.particleName = track->GetDefinition()->GetParticleName();
|
||||||
hit.particleEnergy = track->GetVertexKineticEnergy();
|
hit.particleEnergy = track->GetVertexKineticEnergy();
|
||||||
hit.detectorName = step->GetPreStepPoint()->GetTouchable()->GetVolume()->GetName();
|
hit.detectorName = step->GetPreStepPoint()->GetTouchable()->GetVolume()->GetName();
|
||||||
std::string detNameStr = hit.detectorName;
|
|
||||||
size_t pos = detNameStr.find("_phys");
|
|
||||||
if (pos != std::string::npos)
|
|
||||||
detNameStr = detNameStr.substr(0, pos); // nur Basisname
|
|
||||||
hit.cleanDetectorName = detNameStr;
|
|
||||||
// Primary particle info
|
// Primary particle info
|
||||||
G4PrimaryVertex* pv = event->GetPrimaryVertex();
|
const G4Event* event = G4RunManager::GetRunManager()->GetCurrentEvent();
|
||||||
if (pv)
|
if (event)
|
||||||
{
|
{
|
||||||
G4PrimaryParticle* pp = pv->GetPrimary();
|
G4PrimaryVertex* pv = event->GetPrimaryVertex();
|
||||||
if (pp && pp->GetG4code())
|
if (pv)
|
||||||
hit.primaryParticleName = pp->GetG4code()->GetParticleName();
|
{
|
||||||
if (pp)
|
G4PrimaryParticle* pp = pv->GetPrimary();
|
||||||
hit.primaryEnergy = pp->GetKineticEnergy();
|
if (pp && pp->GetG4code())
|
||||||
|
hit.primaryParticleName = pp->GetG4code()->GetParticleName();
|
||||||
|
if (pp)
|
||||||
|
hit.primaryEnergy = pp->GetKineticEnergy();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
hit.energyDeposited = step->GetTotalEnergyDeposit();
|
hit.energyDeposited = step->GetTotalEnergyDeposit();
|
||||||
|
|
@ -74,39 +62,22 @@ G4bool ASensitiveDetector::ProcessHits(G4Step* step, G4TouchableHistory* /*touch
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ASensitiveDetector::EndOfEvent(G4HCofThisEvent* /*hce*/)
|
void ASensitiveDetector::EndOfEvent(G4HCofThisEvent* /*hce*/)
|
||||||
{
|
{
|
||||||
if (fOutputFilename.empty()) fOutputFilename = "outfiles/shower_setup.txt";
|
|
||||||
std::filesystem::create_directories("outfiles");
|
std::filesystem::create_directories("outfiles");
|
||||||
|
|
||||||
std::ofstream out(fOutputFilename, std::ios::app);
|
std::string filename = "outfiles/shower_setup.txt";
|
||||||
if (!out.is_open()) {
|
std::ofstream out(filename, std::ios::app);
|
||||||
G4cerr << "Cannot open file " << fOutputFilename << "!" << G4endl;
|
if (!out.is_open())
|
||||||
|
{
|
||||||
|
G4cerr << "Cannot open file " << filename << "!" << G4endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool headerWritten = false;
|
out << "eventID\ttrackID\tparantID\tparticle\tEpart\tPrimparticle\tEprim\tDname\tEdep";
|
||||||
if (!headerWritten) {
|
out << "\n";
|
||||||
out << "eventID\ttrackID\tparentID\tparticle\tEpart\tPrimparticle\tEprim\tDname\tEdep\n";
|
|
||||||
headerWritten = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Hits nur für das aktuelle Event
|
for (const auto& [trackID, hit] : fTrackHitMap)
|
||||||
std::vector<HitInfo> hits;
|
|
||||||
for (const auto& [trackID, hit] : fTrackHitMap) {
|
|
||||||
hits.push_back(hit);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sortieren: parentID -> trackID
|
|
||||||
std::sort(hits.begin(), hits.end(), [](const HitInfo& a, const HitInfo& b) {
|
|
||||||
if (a.parentID != b.parentID)
|
|
||||||
return a.parentID < b.parentID;
|
|
||||||
return a.trackID < b.trackID;
|
|
||||||
});
|
|
||||||
|
|
||||||
// Schreiben
|
|
||||||
for (const auto& hit : hits)
|
|
||||||
{
|
{
|
||||||
out << hit.eventID
|
out << hit.eventID
|
||||||
<< "\t" << hit.trackID
|
<< "\t" << hit.trackID
|
||||||
|
|
@ -115,17 +86,10 @@ void ASensitiveDetector::EndOfEvent(G4HCofThisEvent* /*hce*/)
|
||||||
<< "\t" << hit.particleEnergy / MeV
|
<< "\t" << hit.particleEnergy / MeV
|
||||||
<< "\t" << hit.primaryParticleName
|
<< "\t" << hit.primaryParticleName
|
||||||
<< "\t" << hit.primaryEnergy / MeV
|
<< "\t" << hit.primaryEnergy / MeV
|
||||||
<< "\t" << hit.cleanDetectorName
|
<< "\t" << hit.detectorName
|
||||||
<< "\t" << hit.energyDeposited / MeV
|
<< "\t" << hit.energyDeposited / MeV
|
||||||
<< "\n";
|
<< "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
out.close();
|
out.close();
|
||||||
|
|
||||||
// Map leeren für nächstes Event
|
|
||||||
fTrackHitMap.clear();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue