I try to draw one histogram 2D with two TTree data.
Each rootfile(in the attachment) has two Tleaves that one is (TLeaf*)GAIN650 and the other is (TLeaf*)GAIN700, and each one has 48 bins. Why does the script draw only 96 bins ? Is this correct ? If so, why then is the statistics not correct ? The histogram shows only the statistics of the X axis of the (TLeaf*)GAIN650 and that of the Y axis of (TLeaf*)GAIN700 for the rootfile 2983_Ntuple.root as if there was no the statistics of 2987_NTuple.root file ?
The script to try to run as in the following ; it runs with rootfiles in the attachment…
PS : to run,please, try this one : root -l Chain.C
#include <iostream>
#include <fstream>
using namespace std;
int runno;
void Chain() {
gStyle->SetOptStat("menrMR");
TCanvas *c1 = new TCanvas("GAIN Correlation","GAIN Correlation",600,400);
TH2F *hGAIN = new TH2F("GAINCorr","GAINCorr",96,0,2700000,96,0,2700000);
ifstream myin;
myin.open("deneme.txt",ios::in);
if(!(myin.good())){ cout<<"There is no available deneme.txt"<<endl;}
while(myin>>runno) {
TChain *chain = new TChain("TreeofGAINsforHVs");
chain->AddFile(Form("/Users/Erkurt/Desktop/!!!THESIS!!!/BURNIN Thesis/%d_Ntuples.root",runno));
// chain->ls();
Int_t nentries = (Int_t)chain->GetEntries();
cout<<"entries "<<nentries<<endl;
TLeaf *GAIN650 = TreeofGAINsforHVs->GetLeaf("GAIN650");
TLeaf *GAIN700 = TreeofGAINsforHVs->GetLeaf("GAIN700");
for (int i=0; i<48; i++) {
GAIN650->GetBranch()->GetEntry(i);
GAIN700->GetBranch()->GetEntry(i);
hGAIN->Fill(GAIN650->GetValue(),GAIN700->GetValue());
hGAIN->SetMarkerStyle(8);
hGAIN->SetMarkerColor(kRed);
hGAIN->GetXaxis()->SetTitle("GAIN650");
hGAIN->GetYaxis()->SetTitle("GAIN700");
}
}
hGAIN->Draw();
}
So set up the entire chain before you start looping. At the moment you re-create a one-file chain over and over again and get almost by chance the proper looping.