Memory leak fix
This commit is contained in:
		
							parent
							
								
									789d8bf0eb
								
							
						
					
					
						commit
						07feee174a
					
				| 
						 | 
				
			
			@ -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();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -12,6 +12,7 @@
 | 
			
		|||
#include "G4UserSteppingAction.hh"
 | 
			
		||||
#include "MedtechEventAction.hh"
 | 
			
		||||
#include "G4Gamma.hh"
 | 
			
		||||
#include "MedtechAnalysis.hh"
 | 
			
		||||
 | 
			
		||||
class MedtechSteppingAction : public G4UserSteppingAction
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -19,7 +19,6 @@
 | 
			
		|||
#include "MedtechActionInitialization.hh"
 | 
			
		||||
#include "Parameters.hh"
 | 
			
		||||
#include "G4SteppingManager.hh"
 | 
			
		||||
#include "MedtechAnalysis.hh"
 | 
			
		||||
 | 
			
		||||
int main(int argc,char** argv)
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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();
 | 
			
		||||
    
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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-");
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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);
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue