Memory leak fix
This commit is contained in:
		
							parent
							
								
									789d8bf0eb
								
							
						
					
					
						commit
						07feee174a
					
				| 
						 | 
					@ -9,6 +9,7 @@
 | 
				
			||||||
#define MedtechAnalysis_hh
 | 
					#define MedtechAnalysis_hh
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <stdio.h>
 | 
					#include <stdio.h>
 | 
				
			||||||
 | 
					#include <iostream>
 | 
				
			||||||
#include "G4Threading.hh"
 | 
					#include "G4Threading.hh"
 | 
				
			||||||
#include "G4AutoLock.hh"
 | 
					#include "G4AutoLock.hh"
 | 
				
			||||||
#include "TTree.h"
 | 
					#include "TTree.h"
 | 
				
			||||||
| 
						 | 
					@ -28,9 +29,12 @@ private:
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    /* Static access method. */
 | 
					    /* Static access method. */
 | 
				
			||||||
    MedtechAnalysis();
 | 
					    MedtechAnalysis();
 | 
				
			||||||
 | 
					    double x, y, e;
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
    ~MedtechAnalysis();
 | 
					    ~MedtechAnalysis();
 | 
				
			||||||
 | 
					    MedtechAnalysis(const MedtechAnalysis&) = delete;
 | 
				
			||||||
 | 
					    MedtechAnalysis& operator=(const MedtechAnalysis&) = delete;
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    void Fill(double, double, double);
 | 
					    void Fill(double, double, double);
 | 
				
			||||||
    void Close();
 | 
					    void Close();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -12,6 +12,7 @@
 | 
				
			||||||
#include "G4UserSteppingAction.hh"
 | 
					#include "G4UserSteppingAction.hh"
 | 
				
			||||||
#include "MedtechEventAction.hh"
 | 
					#include "MedtechEventAction.hh"
 | 
				
			||||||
#include "G4Gamma.hh"
 | 
					#include "G4Gamma.hh"
 | 
				
			||||||
 | 
					#include "MedtechAnalysis.hh"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class MedtechSteppingAction : public G4UserSteppingAction
 | 
					class MedtechSteppingAction : public G4UserSteppingAction
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -19,7 +19,6 @@
 | 
				
			||||||
#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)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -13,6 +13,10 @@ MedtechAnalysis::MedtechAnalysis()
 | 
				
			||||||
    file = new TFile("data.root","RECREATE");
 | 
					    file = new TFile("data.root","RECREATE");
 | 
				
			||||||
    instance = this;
 | 
					    instance = this;
 | 
				
			||||||
    MedtechAnalysisMutex = G4MUTEX_INITIALIZER;
 | 
					    MedtechAnalysisMutex = G4MUTEX_INITIALIZER;
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    tree -> Branch("x", &x, "x/D");
 | 
				
			||||||
 | 
					    tree -> Branch("y", &y, "y/D");
 | 
				
			||||||
 | 
					    tree -> Branch("e", &e, "e/D");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
MedtechAnalysis::~MedtechAnalysis()
 | 
					MedtechAnalysis::~MedtechAnalysis()
 | 
				
			||||||
| 
						 | 
					@ -24,18 +28,20 @@ MedtechAnalysis* MedtechAnalysis::getInstance()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    if (instance == 0)
 | 
					    if (instance == 0)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
					        std::cout << "Created instance" << std::endl;
 | 
				
			||||||
        instance = new MedtechAnalysis();
 | 
					        instance = new MedtechAnalysis();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    return instance;
 | 
					    return instance;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void MedtechAnalysis::Fill(double x, double y, double e)
 | 
					void MedtechAnalysis::Fill(double x1, double y1, double e1)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    G4AutoLock lock(&MedtechAnalysisMutex);
 | 
					    G4AutoLock lock(&MedtechAnalysisMutex);
 | 
				
			||||||
    tree -> Branch("x", &x, "x/D");
 | 
					    
 | 
				
			||||||
    tree -> Branch("y", &y, "y/D");
 | 
					    x = x1;
 | 
				
			||||||
    tree -> Branch("e", &e, "e/D");
 | 
					    y = y1;
 | 
				
			||||||
 | 
					    e = e1;
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    tree -> Fill();
 | 
					    tree -> Fill();
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -11,7 +11,7 @@ MedtechPrimaryGeneratorAction::MedtechPrimaryGeneratorAction()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    Parameters *param = Parameters::getInstance();
 | 
					    Parameters *param = Parameters::getInstance();
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    G4int numberOfParticles = 100;
 | 
					    G4int numberOfParticles = 1000;
 | 
				
			||||||
    particleGun = new G4ParticleGun(numberOfParticles);
 | 
					    particleGun = new G4ParticleGun(numberOfParticles);
 | 
				
			||||||
    G4ParticleTable *particleTable = G4ParticleTable::GetParticleTable();
 | 
					    G4ParticleTable *particleTable = G4ParticleTable::GetParticleTable();
 | 
				
			||||||
    G4ParticleDefinition *particle = particleTable -> FindParticle("e-");
 | 
					    G4ParticleDefinition *particle = particleTable -> FindParticle("e-");
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -64,7 +64,7 @@ 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();
 | 
					        MedtechAnalysis *man = MedtechAnalysis::getInstance();
 | 
				
			||||||
        man -> Fill(postX, postY, postkinE);
 | 
					        man -> Fill(postX, postY, postkinE);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue