Now supports creating root file for data analysis

This commit is contained in:
Gitea 2018-04-03 22:11:52 +02:00
parent 08e8b33016
commit 789d8bf0eb
7 changed files with 32 additions and 5 deletions

View File

@ -9,6 +9,8 @@
#define MedtechAnalysis_hh #define MedtechAnalysis_hh
#include <stdio.h> #include <stdio.h>
#include "G4Threading.hh"
#include "G4AutoLock.hh"
#include "TTree.h" #include "TTree.h"
#include "TFile.h" #include "TFile.h"
@ -21,9 +23,13 @@ private:
/* Private constructor to prevent instancing. */ /* Private constructor to prevent instancing. */
TTree *tree; TTree *tree;
TFile *file; TFile *file;
public:
G4Mutex MedtechAnalysisMutex;
/* Static access method. */ /* Static access method. */
MedtechAnalysis(); MedtechAnalysis();
public:
~MedtechAnalysis(); ~MedtechAnalysis();
void Fill(double, double, double); void Fill(double, double, double);

View File

@ -22,6 +22,7 @@
#include "G4UnitsTable.hh" #include "G4UnitsTable.hh"
#include "G4SystemOfUnits.hh" #include "G4SystemOfUnits.hh"
#include "MedtechRun.hh" #include "MedtechRun.hh"
#include "MedtechAnalysis.hh"
class MedtechRunAction : public G4UserRunAction class MedtechRunAction : public G4UserRunAction
{ {

View File

@ -19,7 +19,7 @@
#include "MedtechActionInitialization.hh" #include "MedtechActionInitialization.hh"
#include "Parameters.hh" #include "Parameters.hh"
#include "G4SteppingManager.hh" #include "G4SteppingManager.hh"
#include "MedtechAnalysis.hh"
int main(int argc,char** argv) int main(int argc,char** argv)
{ {

View File

@ -12,6 +12,7 @@ MedtechAnalysis::MedtechAnalysis()
tree = new TTree("tree", "tree"); tree = new TTree("tree", "tree");
file = new TFile("data.root","RECREATE"); file = new TFile("data.root","RECREATE");
instance = this; instance = this;
MedtechAnalysisMutex = G4MUTEX_INITIALIZER;
} }
MedtechAnalysis::~MedtechAnalysis() MedtechAnalysis::~MedtechAnalysis()
@ -19,14 +20,26 @@ MedtechAnalysis::~MedtechAnalysis()
} }
MedtechAnalysis* MedtechAnalysis::getInstance()
{
if (instance == 0)
{
instance = new MedtechAnalysis();
}
return instance;
}
void MedtechAnalysis::Fill(double x, double y, double e) void MedtechAnalysis::Fill(double x, double y, double e)
{ {
G4AutoLock lock(&MedtechAnalysisMutex);
tree -> Branch("x", &x, "x/D"); tree -> Branch("x", &x, "x/D");
tree -> Branch("y", &y, "y/D"); tree -> Branch("y", &y, "y/D");
tree -> Branch("e", &e, "e/D"); tree -> Branch("e", &e, "e/D");
tree -> Fill(); tree -> Fill();
//tree -> ChangeFile(file);
lock.unlock();
} }
void MedtechAnalysis::Close() void MedtechAnalysis::Close()
@ -34,3 +47,6 @@ void MedtechAnalysis::Close()
tree -> Write(); tree -> Write();
file -> Close(); file -> Close();
} }
/* Null, because instance will be initialized on demand. */
MedtechAnalysis* MedtechAnalysis::instance = 0;

View File

@ -79,7 +79,7 @@ G4VPhysicalVolume* MedtechDetectorConstruction::Construct()
G4Tet *solidTet = new G4Tet("solidTet", G4ThreeVector(0, 0, 1*cm), G4ThreeVector(-5*cm, -5*cm, 0), G4ThreeVector(5*cm, -5*cm, 0), G4ThreeVector(0, 5*cm, 0)); G4Tet *solidTet = new G4Tet("solidTet", G4ThreeVector(0, 0, 1*cm), G4ThreeVector(-5*cm, -5*cm, 0), G4ThreeVector(5*cm, -5*cm, 0), G4ThreeVector(0, 5*cm, 0));
G4LogicalVolume *logicTet = new G4LogicalVolume(solidTet, tetMaterial, "Tet", 0, 0, 0); G4LogicalVolume *logicTet = new G4LogicalVolume(solidTet, tetMaterial, "Tet", 0, 0, 0);
G4PVPlacement *physicalTet = new G4PVPlacement(0, G4PVPlacement *physicalTet = new G4PVPlacement(0,
G4ThreeVector(0,0,3*cm), G4ThreeVector(0,0,1*cm),
logicTet, logicTet,
"Tet", "Tet",
logicWorld, logicWorld,

View File

@ -19,7 +19,7 @@ MedtechRunAction::~MedtechRunAction()
void MedtechRunAction::BeginOfRunAction(const G4Run*) void MedtechRunAction::BeginOfRunAction(const G4Run*)
{ {
MedtechAnalysis *man = MedtechAnalysis::getInstance();
} }
@ -37,6 +37,8 @@ void MedtechRunAction::EndOfRunAction(const G4Run* run)
G4cout G4cout
<< G4endl << G4endl
<< "--------------------End of Global Run-----------------------"; << "--------------------End of Global Run-----------------------";
MedtechAnalysis *man = MedtechAnalysis::getInstance();
man -> Close();
} }
else { else {
G4cout G4cout

View File

@ -65,6 +65,8 @@ void MedtechSteppingAction::UserSteppingAction(const G4Step* step)
fTrack -> SetTrackStatus(fStopAndKill); fTrack -> SetTrackStatus(fStopAndKill);
} }
G4cout << "X: " << postX << " Y: " << postY << " KinE: " << postkinE << " Particle: " << fTrack -> GetDefinition() << G4endl; G4cout << "X: " << postX << " Y: " << postY << " KinE: " << postkinE << " Particle: " << fTrack -> GetDefinition() << G4endl;
MedtechAnalysis *man = MedtechAnalysis::getInstance();
man -> Fill(postX, postY, postkinE);
} }
// check if we are in scoring volume // check if we are in scoring volume