Memory leak fix

This commit is contained in:
Gitea 2018-04-03 23:30:20 +02:00
parent 789d8bf0eb
commit 07feee174a
6 changed files with 17 additions and 7 deletions

View File

@ -9,6 +9,7 @@
#define MedtechAnalysis_hh
#include <stdio.h>
#include <iostream>
#include "G4Threading.hh"
#include "G4AutoLock.hh"
#include "TTree.h"
@ -28,9 +29,12 @@ private:
/* Static access method. */
MedtechAnalysis();
double x, y, e;
public:
~MedtechAnalysis();
MedtechAnalysis(const MedtechAnalysis&) = delete;
MedtechAnalysis& operator=(const MedtechAnalysis&) = delete;
void Fill(double, double, double);
void Close();

View File

@ -12,6 +12,7 @@
#include "G4UserSteppingAction.hh"
#include "MedtechEventAction.hh"
#include "G4Gamma.hh"
#include "MedtechAnalysis.hh"
class MedtechSteppingAction : public G4UserSteppingAction
{

View File

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

View File

@ -13,6 +13,10 @@ MedtechAnalysis::MedtechAnalysis()
file = new TFile("data.root","RECREATE");
instance = this;
MedtechAnalysisMutex = G4MUTEX_INITIALIZER;
tree -> Branch("x", &x, "x/D");
tree -> Branch("y", &y, "y/D");
tree -> Branch("e", &e, "e/D");
}
MedtechAnalysis::~MedtechAnalysis()
@ -24,18 +28,20 @@ MedtechAnalysis* MedtechAnalysis::getInstance()
{
if (instance == 0)
{
std::cout << "Created instance" << std::endl;
instance = new MedtechAnalysis();
}
return instance;
}
void MedtechAnalysis::Fill(double x, double y, double e)
void MedtechAnalysis::Fill(double x1, double y1, double e1)
{
G4AutoLock lock(&MedtechAnalysisMutex);
tree -> Branch("x", &x, "x/D");
tree -> Branch("y", &y, "y/D");
tree -> Branch("e", &e, "e/D");
x = x1;
y = y1;
e = e1;
tree -> Fill();

View File

@ -11,7 +11,7 @@ MedtechPrimaryGeneratorAction::MedtechPrimaryGeneratorAction()
{
Parameters *param = Parameters::getInstance();
G4int numberOfParticles = 100;
G4int numberOfParticles = 1000;
particleGun = new G4ParticleGun(numberOfParticles);
G4ParticleTable *particleTable = G4ParticleTable::GetParticleTable();
G4ParticleDefinition *particle = particleTable -> FindParticle("e-");

View File

@ -64,7 +64,7 @@ void MedtechSteppingAction::UserSteppingAction(const G4Step* step)
{
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);
}