Medtech/src/MedtechAnalysis.cc

78 lines
1.7 KiB
C++

//
// MedtechAnalysis.cc
// medtech
//
// Created by Baranyai David on 2018. 04. 03..
//
#include "MedtechAnalysis.hh"
MedtechAnalysis::MedtechAnalysis()
{
char filename[20];
Parameters *parameter = Parameters::getInstance();
snprintf(filename, 30, "data_c%dt%d.root", (int)parameter -> GetConeSize(), (int)parameter -> GetTubeSize());
tree = new TTree("tree", "tree");
electrontree = new TTree("electrontree","electrontree");
file = new TFile(filename,"RECREATE");
instance = this;
MedtechAnalysisMutex = G4MUTEX_INITIALIZER;
tree -> Branch("x", &x, "x/D");
tree -> Branch("y", &y, "y/D");
tree -> Branch("z", &z, "z/D");
tree -> Branch("e", &e, "e/D");
electrontree -> Branch("x", &x, "x/D");
electrontree -> Branch("y", &y, "y/D");
electrontree -> Branch("e", &e, "e/D");
electrontree -> Branch("z", &z, "z/D");
}
MedtechAnalysis::~MedtechAnalysis()
{
}
MedtechAnalysis* MedtechAnalysis::getInstance()
{
if (instance == 0)
{
std::cout << "Created instance" << std::endl;
instance = new MedtechAnalysis();
}
return instance;
}
void MedtechAnalysis::Fill(int num, double x1, double y1, double z1, double e1)
{
G4AutoLock lock(&MedtechAnalysisMutex);
x = x1;
y = y1;
z = z1;
e = e1;
if(num == 1)
{
tree -> Fill();
}
if(num == 2)
{
electrontree -> Fill();
}
lock.unlock();
}
void MedtechAnalysis::Close()
{
tree -> Write();
electrontree -> Write();
file -> Close();
}
/* Null, because instance will be initialized on demand. */
MedtechAnalysis* MedtechAnalysis::instance = 0;