Hi all,
I was trying to make a TH3 histogram by filling data from a set of TTrees. The TTrees are being read from 295 different root files.
At the end of reading all 295 files, I am getting this error; for 10 files, it seems to run fine.
I suggest it’s a memory issue, but not sure how to manage it. Can someone please offer their insight/suggestions as to how to deal with this?
Thanks a lot!
root.exe: malloc.c:2617: sysmalloc: Assertion `(old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)' failed.
#include "TFile.h"
#include "TH1F.h"
#include "TH2F.h"
#include "TTreeReader.h"
#include "TTreeReaderValue.h"
//File I/O
#include <iostream>
#include <fstream>
const int nDet = 8;
const double dt = 2;
void make_E_correl(){
//time offsets
std::ifstream inputFile("Time_Shift.txt"); // Open the text file for reading
if (!inputFile.is_open()) std::cerr << "Error opening file!" << std::endl;
double offsets[nDet+1][nDet+1]; //array to store the offsets
double shift; int m, n;
while (inputFile >> m >> n >> shift) {
offsets[m][n] = shift;
}
//----------------------------------------------------------------------------
//Making Histos
TH1* h_Fat_E = new TH1F("h_Fat_E", "Fatima Energy All Crystals", 1200, 0, 1200);
h_Fat_E->SetXTitle("Ch No.");
h_Fat_E->SetYTitle("Counts/keV");
TH1* E_Shift_add = new TH1F("h_Fat_Eshift", "Fatima Energy Shifted All Crystals", 1200, 0, 1200);
E_Shift_add->SetXTitle("Ch No.");
E_Shift_add->SetYTitle("Counts/keV");
TH1* E_Raw[9], *E_Shift[9];
for (int i = 1; i < 9; i ++){
TString name = Form("E_Raw_Det_%d", i);
TString name2 = Form("E_Shift_Det_%d", i);
E_Raw[i] = new TH1F(name, name, 1200, 0, 1200);
E_Shift[i] = new TH1F(name2, name2, 1200, 0, 1200);
}
TH2* gg_mat = new TH2F("gg_mat", "#gamma-#gamma LaBr3" , 1200, 0, 1200, 1200, 0, 1200);
gg_mat->SetOption("colz");
TH2* gg_mat_Ge = new TH2F("labr_labr_Ge", "LaBr_{3}-LaBr_{3}-Ge_Gate" , 1200, 0, 1200, 1200, 0, 1200);
TH3 *gg_dt_cube = new TH3F("labr_labr_dt", "LaBr_{3}-LaBr_{3}-dt", 1200, 0, 1200, 1200, 0, 1200, 400, -5, 5); //gamma - gamma -dt cube
//File Loop
for (int file_num = 1; file_num <= 295; file_num++) {
TFile* dataFile;
dataFile = TFile::Open(Form("Trees/f6_%04d.root", file_num) , "READ");
if (!dataFile || dataFile->IsZombie()) {
cout << "File is Zombie" << endl;
return;
}
//Storing branch data in variables
TTreeReader Reader("AnalysisxTree", dataFile);
TTreeReaderArray<Double_t> Fat_E(Reader,"AnlEvent.QDC_E[9]");
TTreeReaderValue<Int_t> Fat_mult(Reader,"AnlEvent.mult");
TTreeReaderArray<Long64_t> Fat_T(Reader,"AnlEvent.TDC_T[9]");
TTreeReaderArray<Int_t> Fat_E_ID(Reader,"AnlEvent.QDC_ID[9]");
TTreeReaderArray<Int_t> Fat_T_ID(Reader,"AnlEvent.TDC_ID[9]");
TTreeReaderArray<Double_t> Ge_E(Reader,"AnlEvent.E[2][7]");
int evt_num = 0;
while (Reader.Next()) {
for (int crys = 0; crys < 14; crys++) {
if ( Ge_E[crys] > 125.9 && Ge_E[crys] < 131.9) { //EB range crys = 7 - 13
for(int i=0; i<*Fat_mult; i++) {
for (int j = i+1; j<*Fat_mult; j++){
double t_ij = (Fat_T[i] - Fat_T[j])*0.025;
double c_ij = offsets[ Fat_E_ID[i] ][ Fat_E_ID[j] ];
double t_ij_align = t_ij - c_ij;
if (TMath::Abs(t_ij_align) < dt)
gg_mat_Ge->Fill(Fat_E[i], Fat_E[j]);
gg_mat_Ge->Fill(Fat_E[j], Fat_E[i]);
gg_dt_cube->Fill(Fat_E[i], Fat_E[j], t_ij_align);
}
}
}
}
evt_num++;
}
cout << "Processed: " << evt_num << " events." << endl;
}
//Output File
TFile *f = new TFile ("ggdt_cube.root", "RECREATE");
f->mkdir("Energy");
f->cd("Energy");
h_Fat_E->Write();
gg_mat->Write();
gg_mat_Ge->Write();
gg_dt_cube->Write();
f->Close();
}