Dear all,
I would like to generate a root file with a tree and a TH2D from 2 different input root files. Here is the code:
#include <TROOT.h>
#include <Riostream.h>
#include <TChain.h>
#include <TString.h>
#include <TFile.h>
#include <fstream>
#include <TLorentzVector.h>
#include <iostream>
#include <TSystem.h>
#include <TMath.h>
#include <TLeaf.h>
#include <TBranch.h>
#include "TH2D.h"
void addVarToTree()
{
// Opening first root file and getting the tree
TFile *myfile1 = new TFile("file1.root","READ");
TTree *data_weighted1 = (TTree*)myfile1->Get("data_Weighted");
// Opening second root file and getting two 2D histograms
TFile *myfile2 = new TFile("file2.root","READ");
TH2D *HaccHistoMinus = (TH2D*)myfile2->Get("Hacc_kpipi_Minus_DAsyCorr");
TH2D *HaccHistoPlus = (TH2D*)myfile2->Get("Hacc_kpipi_Plus_DAsyCorr");
// Creating a new root file with the tree and histograms above
TFile *newfile = new TFile("outputfile.root","recreate");
TTree *newtree = data_weighted1->CloneTree();
HaccHistoMinus->Write();
HaccHistoPlus->Write();
newfile->Write();
}
I want to write on “outputfile” the tree “data_Weighted” and the 2D histograms “Hacc_kpipi_Minus_DAsyCorr” and “Hacc_kpipi_Plus_DAsyCorr”. However, after running the script above, I have two trees “data_Weighted”, one correctly cloned, plus a second one which seems being a random sub-sample of the true one. I would like to understand what is happening (why a second “data_Weighted” is showing up in my outputfile).
Many thanks,
Diego
Link to the files:
https://drive.google.com/drive/folders/1-maDWN_KdbSN9AcxQDWAx6U8fi0VSsID?usp=sharing