I have a piece of code that was previously working on ROOT5, but now I’m encountering some issues when trying to run it on ROOT6. I’m hoping to get some help in making this code compatible with ROOT6.
My current status:
| Built for macosxarm64 on Jul 28 2022, 18:08:51
| From tags/v6-26-06@v6-26-06
| With Apple clang version 14.0.0 (clang-1400.0.29.202)
marcos@mbp new % root get_flux.C
Processing get_flux.C…
/angleResponse/new/./get_flux.C:38:5: error: use of undeclared identifier ‘scale’
scale(hb, ct1/ct2*0.85);
^
/angleResponse/new/./get_flux.C:40:5: error: use of undeclared identifier ‘substract’
substract(htemp, hb);
^
/angleResponse/new/./get_flux.C:41:16: error: use of undeclared identifier ‘hist_c2e’
TH1D *he = hist_c2e(htemp);
^
/angleResponse/new/./get_flux.C:42:5: error: use of undeclared identifier ‘calibrate’
calibrate(he, inc);
^
/angleResponse/new/./get_flux.C:45:28: error: use of undeclared identifier ‘get_h_ct’
tg->SetPoint(np, inc, get_h_ct(he, 96, 1000)); np++;
Here is the code that I’m having issues with (get_flux.C):
{
double deg = 1.0;
TFile *fn = new TFile(Form(“%.1fdeg/flux.root”, deg), “recreate”);for(int i=725; i<760; i++){
TGraph *g = get_flux_by_orbit(i, deg);
fn->cd();
g->Write();
delete g;
}fn->Close();
}TGraph* get_flux_by_orbit(int obs, double deg) {
TFile *fb = new TFile(“fb.root”);
TFile *f = new TFile(“f.root”);
int n_spectra_in_orbit = 119-1;TGraph *tg = new TGraph();
tg->SetName(Form(“g_%d”, obs));
int np = 0;
double inc, inc2;for(int k=0; k<n_spectra_in_orbit-1; k++){
TH1D htemp = (TH1D)f->Get(Form(“%d/h_%d_%d”, obs, obs, k));
TH1D htemp2 = (TH1D)f->Get(Form(“%d/h_%d_%d”, obs, obs, k+1));if(htemp && htemp2){ inc = atof(htemp->GetTitle()); inc2 = atof(htemp2->GetTitle()); if(inc<=60 && inc2<=60){ TH1D *hb = (TH1D*)fb->Get("hbg"); double ct1 = htemp->Integral(htemp->FindBin(50), htemp->FindBin(59)); double ct2 = hb->Integral(hb->FindBin(50), hb->FindBin(59)); scale(hb, ct1/ct2*0.85); substract(htemp, hb); TH1D *he = hist_c2e(htemp); calibrate(he, inc); if(inc<=inc2){ tg->SetPoint(np, inc, get_h_ct(he, 96, 1000)); np++; } delete he; delete hb; } } delete htemp; delete htemp2;
}
fb->Close();
f->Close();
delete f;
delete fb;
return tg;
}double get_h_ct(TH1D *h, int bin1, int bin2) {
double sum = 0;
for(int i=bin1; i<=bin2; i++){
double s=h->GetBinContent(i);
if(s>0) sum += s;
}
return sum;
}void calibrate(TH1D h, double jd) {
double theta = jd/1803.1415926;
double cf1 = cos(theta);
TFile fef(“efficiency_factor_new.root”);
TGraph tef = (TGraph) fef.Get(Form(“g%d”, (int)(jd*100)));
for(int i=0; iGetNbinsX(); i++){
double eg = h->GetBinCenter(i+1);
if(eg>=600){
double cf2 = tef->Eval(eg, 0, “S”);
double err = h->GetBinError(i+1);
h->SetBinContent(i+1, h->GetBinContent(i+1)/cf1/cf2);
h->SetBinError(i+1, err/cf1/cf2);
}
}
fef.Close();
}TH1D* hist_c2e(TH1D h) {
double bw = 10.536;
double low = 110.536-40.424;
double up = 1001*10.536-40.424;
int bins = (int)((up-low)/bw);
TH1D *he = new TH1D(Form(“e%s”, h->GetName()), “spectra”, bins, low, up);
for(int i=0; iGetNbinsX(); i++) he->SetBinContent(i+1, h->GetBinContent(i+1));
return he;
}void scale(TH1D *h, double factor) {
int n = h->GetNbinsX();
double *xe = new double[n];
for(int i=0; i<n; i++){
xe[i] = h->GetBinError(i+1);
h->SetBinContent(i+1, h->GetBinContent(i+1)*factor);
h->SetBinError(i+1, xe[i]*factor);
}
delete [] xe;
}void substract(TH1D *h1, TH1D *h2) {
int n = h1->GetNbinsX();
if(n==h2->GetNbinsX()) {
double *xe = new double[n];
for(int i=0; i<n; i++){
xe[i] = h1->GetBinError(i+1);
}
for(int i=0; i<n; i++){
h1->SetBinContent(i+1, h1->GetBinContent(i+1)-h2->GetBinContent(i+1));
h1->SetBinError(i+1, sqrt(xe[i]*xe[i]+h2->GetBinError(i+1)*h2->GetBinError(i+1)));
}
delete [] xe;
} else {
cout<<“substract error …bins”<<endl;
}
}
I would greatly appreciate any suggestions on how to resolve these issues and make this code compatible with ROOT6.
Thank you in advance for your help!
Marcos