@couet, @dastudillo Here is my code that I did:
#include "TFile.h"
#include "TTree.h"
#include "TRandom.h"
#include "TROOT.h"
#include "TBranch.h"
#include "TH1.h"
#include "Rtypes.h"
void enAgX100_1()
{
gROOT->cd();
THStack *hs =
new THStack("energy",
"Energies 0.02720 a 0.13509MeV with Ti 0.05mm with seed Agx100 of Theragnics; ELost/EKin;Counts");
TH1F *h = new TH1F("h", "h", 100, 0.2, 1.8);
if (h->GetSumw2N() == 0) h->Sumw2(kTRUE);
const char *files[] = { "EnSAgX100_27keV.root",
"EnSAgX100_30keV.root",
"EnSAgX100_31_7keV.root",
"EnSAgX100_35keV.root",
"EnSAgX100_35_5keV.root",
"EnSAgX100_36keV.root",
"EnSAgX100_37keV.root",
"EnSAgX100_40keV.root",
"EnSAgX100_45keV.root",
"EnSAgX100_55keV.root",
"EnSAgX100_85keV.root",
"EnSAgX100_135keV.root" };
const int n = sizeof(files) / sizeof(char*);
int color = 0;
int mycolor[i] = 0;
for (int i = 0; i < n; i++) {
TFile *f = TFile::Open(files[i]);
if ((!f) || f->IsZombie()) { delete f; continue; } // just a precaution
TTree *t; f->GetObject("GmDataTTree", t);
if (!t) { delete f; continue; } // just a precaution
gROOT->cd();
t->Project("h", // each file re-fills it from scratch
"(Event_AccumulatedEnergyLost / Event_InitialKineticEnergy)");
/*color += 1; // "next" color color = mycolor[j];
h->SetLineColor(color); h->SetMarkerColor(color); // do not "SetFillColor"*/
for (int i = 0; i < n; i++) {
color = mycolor[i];
h->SetLineColor(color); h->SetMarkerColor(color);
}
h->SetTitle(files[i]);
hs->Add((TH1F*)(h->Clone(TString::Format("h_%d", i))));
delete f; // automatically deletes "t", too
}
delete h; // no longer needed
TLegend *l = new TLegend(0.75, 0.9, 0.9, 0.25);
for (int i = 0; i < hs->GetNhists(); i++)
{ l->AddEntry(hs->GetHists()->At(i), "", "l"); }
hs->Draw("NOSTACK HIST");
l->Draw();
}
What am I do wrong? In attaching the image of the error message.
Thanks!
error|690x347