# Error: use of undeclared identifier (ROOT6)

**URL:** <https://root-forum.cern.ch/t/error-use-of-undeclared-identifier-root6/54120>\
**Category:** Newbie\
**Created:** [March 19, 2023, 6:44pm UTC](https://root-forum.cern.ch/t/error-use-of-undeclared-identifier-root6/54120 "2023-03-19T18:44:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marcos\_Ng](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/marcos_ng/32/32848_2.png) [@Marcos\_Ng](https://root-forum.cern.ch/u/Marcos_Ng)\
**Post date:** [March 19, 2023, 6:44pm UTC](https://root-forum.cern.ch/t/error-use-of-undeclared-identifier-root6/54120/1 "2023-03-19T18:44:15Z")

</div>

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/180_3.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 = 1_10.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

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [March 19, 2023, 6:50pm UTC](https://root-forum.cern.ch/t/error-use-of-undeclared-identifier-root6/54120/2 "2023-03-19T18:50:36Z")

</div>

You need to rearrange your “`get_flux.C`” file so that the '`scale`", “`substract`”, and other functions are defined before they are used.

---

<div class="post-metadata">

**Author:** ![Marcos\_Ng](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/marcos_ng/32/32848_2.png) [@Marcos\_Ng](https://root-forum.cern.ch/u/Marcos_Ng)\
**Post date:** [March 19, 2023, 6:58pm UTC](https://root-forum.cern.ch/t/error-use-of-undeclared-identifier-root6/54120/3 "2023-03-19T18:58:57Z")

</div>

Thanks! It seems work after your insights.

The program is arranged as:

double get\_h\_ct(TH1D \*h, int bin1, int bin2) {…}  
void calibrate(TH1D _h, double jd) {…}  
TH1D_ hist\_c2e(TH1D \*h) {…}  
void scale(TH1D \*h, double factor) {…}  
void substract(TH1D \*h1, TH1D _h2) {…}  
TGraph_ get\_flux\_by\_orbit(int obs, double deg) {…}

and added: void get\_flux() {…}
