Good Evening,
i’ve got a little problem while simulating a number of pions (100 GeV) colliding to a simulated calorimeter through GEANT4. Basically I have a lot of entries and the Output fills two trees in my code. Unfortunately I noticed that the memory usage increase a lot while the data fills the tree itself, making my computer completely crash. This is the code where I fill and write my trees and write them into a file.
My pc has 12 GB of ram.
void
CALAnalysisManager::BeginOfRun()
{
G4String m_pDataFile = "events.root";
m_pOutputFile = new TFile(m_pDataFile, "RECREATE");
//namefile.open("names.txt");
m_pTree = new TTree("events","Tree that contains info");
m_pTree1 = new TTree("Total Energy deposited","Tree that contains info about energy");
m_pTree1->Branch("E_{TOT}", &m_pEventData->eTot); //energia depositata totale nei gap
m_pTree->Branch("E_{DEP}", &m_pEventData->eDep); //Energia depositata per step per singolo hit
m_pTree->Branch("LayerID", &m_pEventData->layerId);
m_pTree->Branch("Position", &m_pEventData->position);
m_pTree->Branch("EventID", &m_pEventData->eventId);
m_pTree->Branch("ParticleID", &idparticle); //nome particella}
void
Preformatted textCALAnalysisManager::EndOfRun()
{
m_pOutputFile->cd();
m_pOutputFile->Write();
m_pOutputFile->Close();
//namefile.close();
}
void
CALAnalysisManager::BeginOfEvent(const G4Event* pEvent)
{
G4cout << "\n============================================================\n"
<< "Begin of event: "<< pEvent->GetEventID() << G4endl
<< "-------------------------------------------------------------\n";
if (absCollID == -1)
{
G4SDManager * pSDManager = G4SDManager::GetSDMpointer();
absCollID = pSDManager->GetCollectionID("AbsorberHitsCollectionName");
}
}
void
CALAnalysisManager::EndOfEvent(const G4Event *pEvent)
{
G4cout<<"ENDOFEVENT\n";
G4HCofThisEvent * pHCofThisEvent = pEvent->GetHCofThisEvent();
G4cout<<"GOT THE HC\n";
CALCalorHitsCollection * absHitsCollection = (CALCalorHitsCollection*) (pHCofThisEvent->GetHC(absCollID));
G4cout<<"GOT THE abs HC\n";
G4int totEntries = absHitsCollection->entries();
G4cout<<"GOT totEntries:"<<totEntries<<G4endl;
G4double eTmp = 0;
CALCalorHit * absoHit;
G4cout<<"INIZIO LA LETTURA DELLE ENERGIE\n";
for (int i=0; i<totEntries; i++)
{
absoHit = (*absHitsCollection)[i];
eTmp += absoHit->getTotalEnergyDeposited();
m_pEventData->eDep = absoHit->getTotalEnergyDeposited();
m_pEventData->layerId = absoHit->getLayerId();
m_pEventData->particleId = absoHit->getParticleId();
names = m_pEventData->particleId;
if(names == "pi-")
idparticle = 0;
else if(names == "pi+")
idparticle = 1;
else if(names == "neutron")
idparticle = 2;
else if(names == "proton")
idparticle = 3;
else if(names == "gamma")
idparticle = 4;
else if(names == "e-")
idparticle = 5;
else if(names == "e+")
idparticle = 6;
else if(names == "mu+")
idparticle = 7;
else if(names == "mu-")
idparticle = 8;
else
idparticle = -1;
m_pEventData->position = {absoHit->getHitPos()[0],absoHit->getHitPos()[1],absoHit->getHitPos()[2]};
m_pEventData->eventId = pEvent->GetEventID();
//namefile << names << '\n';
m_pTree->Fill();
}
G4cout<<"LETTE\n";
m_pEventData->eTot = eTmp;
m_pTree1->Fill();
m_pEventData->Clear();
}
Could you help me solving this problem please?
_ROOT Version:6.06/8
_Platform:Ubuntu 16.04
_Compiler5.5.0 20171010171010