Saving arrays of objects of my class on a Tfile

Hi,

I have this class named Q where i can save the value and the error of a Q object.
I am analyzing a lot of data so i thought to separate in two macros the analysis so that in the first one i simply evaluate some arrays of Q objects from the data (that is going to take a while) and in the second one i will evaluate what i need for the analysis from the arrays of the Q objects.
So in the first macro i had calculated the arrays

Q N_peak[Nfs][Netabin+1][Nptbin+1][NmTcut][Ndistpeak][Ndistbkg];
Q N_bkg_lower[Nfs][Netabin+1][Nptbin+1][NmTcut][Ndistpeak][Ndistbkg];
Q N_bkg_upper[Nfs][Netabin+1][Nptbin+1][NmTcut][Ndistpeak][Ndistbkg];
Q N_bkg_both[Nfs][Netabin+1][Nptbin+1][NmTcut][Ndistpeak][Ndistbkg];

but now i don’t know how to pass them to the second macro because i tried to use a TTree and save it in a TFile but it didn’t work, maybe i made some mistakes.

here what i wrote:
in the first macro

    TFile* fout = new TFile("prepare_fey_output.root" , "recreate");
    TTree *tree = new TTree("Tree_prepare_fey", "Tree_prepare_fey");
   
    tree->Branch("N_peak", N_peak, "N_peak/D");
    tree->Branch("N_bkg_lower", N_bkg_lower, "N_bkg_lower/D");
    tree->Branch("N_bkg_upper", N_bkg_upper, "N_bkg_upper/D");
    tree->Branch("N_bkg_both", N_bkg_both, "N_bkg_both/D");
    tree->Fill();
    fout->Write();

in the second macro

    TFile *file = new TFile("prepare_fey_output.root", "READ");

    // Ottieni il TTree dal file
    TTree *tree = dynamic_cast<TTree*>(file->Get("Tree_prepare_fey"));

    // Collega i rami del TTree agli array
    tree->SetBranchAddress("N_peak", N_peak);
    tree->SetBranchAddress("N_bkg_lower", N_bkg_lower);
    tree->SetBranchAddress("N_bkg_upper", N_bkg_upper);
    tree->SetBranchAddress("N_bkg_both", N_bkg_both);

    // Leggi il TTree
    tree->GetEntry(0);
    // Chiudi il file
    file->Close();

I am confused. The first macro is explicit storing only a total of 4 doubles (no array) and their correctly retrieve in the second macro. How is it failling for you? What is the relationship between Q and those doubles?

The first macro stores 4 multidimensional arrays of Q objects and the question is how to pass them to another macro; i tried to use a TTree but i probably used it all wrong, i have read a few things about TTrees but in my mind they still are a little foggy.

What is the relation ship between the 2 macros? Are they run in the same process or not? in the same machine/node or not? on the same day or not? Are they always run back to back or something else?

1 Like

With the first one i want to evaluate the mentioned arrays and this is an operation that takes some time and then i want to pass them to the second macro that i will use to calculate the results, display some graph, etc. So the first macro will be executed just one time to get the arrays while the second one will probably change a lot during my work (add some graphs, change the way i compute errors,…)