# Th1 scaling axis

**URL:** <https://root-forum.cern.ch/t/th1-scaling-axis/55237>\
**Category:** ROOT\
**Created:** [June 8, 2023, 12:22pm UTC](https://root-forum.cern.ch/t/th1-scaling-axis/55237 "2023-06-08T12:22:52Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![faca87](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/f/b19c9b/32.png) [@faca87](https://root-forum.cern.ch/u/faca87)\
**Post date:** [June 8, 2023, 12:22pm UTC](https://root-forum.cern.ch/t/th1-scaling-axis/55237/1 "2023-06-08T12:22:52Z")

</div>

Hello, following an old topic [Can we shift histogram for several channels? - #2 by Pepe\_Le\_Pew](https://root-forum.cern.ch/t/can-we-shift-histogram-for-several-channels/12050/2) I wrote this macro to scale x-axis.

[scaleaxis.cpp](https://root-forum.cern.ch/uploads/short-url/9nZ1UoWYMqfVwy5GEM5VjW7Wlxt.cpp) (1.6 KB)

Now I need to get a,b,c parameters from terminal when running the macro.  
I know I can get them replacing

`void scaleaxis()`  
by  
`void scaleaxis(double a, double b, double c)`

and running as

`.x scaleaxis.cpp(0,10,0)`

[scaleaxis.cpp](https://root-forum.cern.ch/uploads/short-url/yfQMMXmnP06k0LS8FwNZJM4GeQf.cpp) (1.6 KB)

but I’m having problem to pass a,b,c to the ScaleX function, so that it can evaluate

` v = a + b*x + c*x*x;`

without defining a,b,c in it.

How to do that?

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [June 8, 2023, 1:38pm UTC](https://root-forum.cern.ch/t/th1-scaling-axis/55237/2 "2023-06-08T13:38:17Z")

</div>

> **[Passing a Function as a Parameter in C++ - GeeksforGeeks](https://www.geeksforgeeks.org/passing-a-function-as-a-parameter-in-cpp/)**
>
> A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.

---

<div class="post-metadata">

**Author:** ![faca87](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/f/b19c9b/32.png) [@faca87](https://root-forum.cern.ch/u/faca87)\
**Post date:** [June 8, 2023, 4:08pm UTC](https://root-forum.cern.ch/t/th1-scaling-axis/55237/3 "2023-06-08T16:08:23Z")

</div>

```auto
root [2] .x scaleaxis.cpp(0,10,0)
In file included from input_line_10:1:
scaleaxis.cpp:40:10: error: use of undeclared identifier 'a'
  invoke(a,b,c, &scaleaxis);
         ^
scaleaxis.cpp:40:12: error: use of undeclared identifier 'b'
  invoke(a,b,c, &scaleaxis);
           ^
scaleaxis.cpp:40:14: error: use of undeclared identifier 'c'
  invoke(a,b,c, &scaleaxis);
             ^
scaleaxis.cpp:40:18: error: use of undeclared identifier 'scaleaxis'
  invoke(a,b,c, &scaleaxis);
                 ^
scaleaxis.cpp:41:19: error: use of undeclared identifier 'a'
  cout << "a=" << a << "b=" << b << "c=" << c << endl;
                  ^
scaleaxis.cpp:41:32: error: use of undeclared identifier 'b'
  cout << "a=" << a << "b=" << b << "c=" << c << endl;
                               ^
scaleaxis.cpp:41:45: error: use of undeclared identifier 'c'
  cout << "a=" << a << "b=" << b << "c=" << c << endl;
                                            ^
scaleaxis.cpp:42:7: error: use of undeclared identifier 'a'
  v = a + b*x + c*x*x;
      ^
scaleaxis.cpp:42:11: error: use of undeclared identifier 'b'
  v = a + b*x + c*x*x;
          ^
scaleaxis.cpp:42:17: error: use of undeclared identifier 'c'
  v = a + b*x + c*x*x;

```

[scaleaxis.cpp](https://root-forum.cern.ch/uploads/short-url/67jGf4868gYdVAv83YDwKHStE9u.cpp) (1.7 KB)

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [June 9, 2023, 8:39am UTC](https://root-forum.cern.ch/t/th1-scaling-axis/55237/4 "2023-06-09T08:39:06Z")

</div>

Yes, the error message is correct. See your code:

```auto
Double_t ScaleX(Double_t x)
{
  Double_t v;
  invoke(a,b,c, &scaleaxis);
  cout << "a=" << a << "b=" << b << "c=" << c << endl;
  v = a + b*x + c*x*x;
  return v;
}

```

---

<div class="post-metadata">

**Author:** ![faca87](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/f/b19c9b/32.png) [@faca87](https://root-forum.cern.ch/u/faca87)\
**Post date:** [June 9, 2023, 12:07pm UTC](https://root-forum.cern.ch/t/th1-scaling-axis/55237/5 "2023-06-09T12:07:12Z")

</div>

Hi @couet,

I replaced

```auto
Double_t ScaleX(Double_t x)

```

by

`Double_t ScaleX(Double_t x, double a, double b, double c, void scaleaxis(double a, double b, double c))`

but I got this error

```auto
root [0]
Processing scaleaxis.cpp...
In file included from input_line_8:1:
scaleaxis.cpp:40:3: error: no matching function for call to 'invoke'
  invoke(a,b,c, &scaleaxis);
  ^ ~~~~~
scaleaxis.cpp:32:6: note: candidate function not viable: no known conversion from 'void (**)(double, double, double)' to 'void (*)(double, double, double)' for 4th argument; remove &
void invoke(double a, double b, double c, void (*func)(double, double, double))
     ^
software/gcc/10.2.0/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../include/c++/10.2.0/functional:85:5: note: candidate template ignored: substitution failure [with _Callable = double &, _Args = <double &, double &, void (**)(double, double, double)>]: no type named 'type' in 'std::invoke_result<double &, double &, double &, void (**)(double, double, double)>'
    invoke(_Callable&& __fn, _Args&&...__ args)
    ^
In file included from input_line_8:1:
SimulazioniFatte/21Nepgamma/Risonanza_6998/scaleaxis.cpp:76:2: error: no matching function for call to 'ScaleXaxis'
        ScaleXaxis(h,ScaleX);
        ^ ~~~~~~~~~
SimulazioniFatte/21Nepgamma/Risonanza_6998/scaleaxis.cpp:65:6: note: candidate function not viable: no known conversion from 'Double_t (Double_t, double, double, double, void (*)(double, double, double))' (aka 'double (double, double, double, double, void (*)(double, double, double))') to 'Double_t (*)(Double_t)' (aka 'double (*)(double)') for 2nd argument
void ScaleXaxis(TH1 *h, Double_t (*Scale)(Double_t))

```

then I also removed the & (As written in the error) but now I get

```auto
Processing scaleaxis.cpp...
In file included from input_line_8:1:
scaleaxis.cpp:76:2: error: no matching function for call to 'ScaleXaxis'
        ScaleXaxis(h,ScaleX);
        ^ ~~~~~~~~~
scaleaxis.cpp:65:6: note: candidate function not viable: no known conversion from 'Double_t (Double_t, double, double, double, void (*)(double, double, double))' (aka 'double (double, double, double, double, void (*)(double, double, double))') to 'Double_t (*)(Double_t)' (aka 'double (*)(double)') for 2nd argument
void ScaleXaxis(TH1 *h, Double_t (*Scale)(Double_t))

```

[scaleaxis.cpp](https://root-forum.cern.ch/uploads/short-url/7JWKfMBOPo8NFJ6Vcrj3rzEOleK.cpp) (1.8 KB)

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [June 9, 2023, 12:11pm UTC](https://root-forum.cern.ch/t/th1-scaling-axis/55237/6 "2023-06-09T12:11:40Z")

</div>

you call:

```auto
	ScaleXaxis(h,ScaleX);

```

But you do not have a such function (matching this signature).

---

<div class="post-metadata">

**Author:** ![faca87](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/f/b19c9b/32.png) [@faca87](https://root-forum.cern.ch/u/faca87)\
**Post date:** [June 9, 2023, 12:23pm UTC](https://root-forum.cern.ch/t/th1-scaling-axis/55237/7 "2023-06-09T12:23:00Z")

</div>

Then, I replaced

```auto
void ScaleAxis(TAxis *a, Double_t (*Scale)(Double_t))

```

by

```auto
void ScaleAxis(TAxis *a, Double_t (*Scale)(Double_t, double, double, double, void(double, double, double)))

```

but I got

```auto
root [0]
Processing scaleaxis.cpp...
In file included from input_line_8:1:
scaleaxis.cpp:53:63: error: too few arguments to function call, expected 5, have 1
      for(Int_t i = 0; i < X.GetSize(); i++) X[i] = Scale(X[i]);
                                                    ~~~~~ ^
scaleaxis.cpp:59:33: error: too few arguments to function call, expected 5, have 1
              Scale(a->GetXmin()),
              ~~~~~ ^
scaleaxis.cpp:60:33: error: too few arguments to function call, expected 5, have 1
              Scale(a->GetXmax()));
              ~~~~~ ^
scaleaxis.cpp:68:3: error: no matching function for call to 'ScaleAxis'
  ScaleAxis(h->GetXaxis(), Scale);
  ^ ~~~~~~~~
scaleaxis.cpp:47:6: note: candidate function not viable: no known conversion from 'Double_t (*)(Double_t)' (aka 'double (*)(double)') to 'Double_t (*)(Double_t, double, double, double, void (*)(double, double, double))' (aka 'double (*)(double, double, double, double, void (*)(double, double, double))') for 2nd argument
void ScaleAxis(TAxis *a, Double_t (*Scale)(Double_t, double, double, double, void(double, double, double)))
     ^
scaleaxis.cpp:76:2: error: no matching function for call to 'ScaleXaxis'
        ScaleXaxis(h,ScaleX);
        ^ ~~~~~~~~~
scaleaxis.cpp:65:6: note: candidate function not viable: no known conversion from 'Double_t (Double_t, double, double, double, void (*)(double, double, double))' (aka 'double (double, double, double, double, void (*)(double, double, double))') to 'Double_t (*)(Double_t)' (aka 'double (*)(double)') for 2nd argument
void ScaleXaxis(TH1 *h, Double_t (*Scale)(Double_t))
     ^
root [1]

```

and I’m not sure that I’m going to the right way, because in your link, the function was called as

`cout << invoke(20, 10, &multiply) << ` `'\n'` `;`

i.e. using the `&,` on the contrary, in my case the compiler asked to remove the `&`…then I’m not sure that I’m not making other mistakes

[scaleaxis.cpp](https://root-forum.cern.ch/uploads/short-url/2hVk3SGl6RnweBsb4vuKbDYicIt.cpp) (1.8 KB)

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [June 9, 2023, 12:32pm UTC](https://root-forum.cern.ch/t/th1-scaling-axis/55237/8 "2023-06-09T12:32:34Z")

</div>

That’s really elementary C++

your function’s signature is:

```auto
Double_t ScaleX(Double_t x, double a, double b, double c, void scaleaxis(double a, double b, double c))

```

And you call it with:

```auto
Scale(X[i]);

```

That’s why you get this error… read C++ doc …

---

<div class="post-metadata">

**Author:** ![faca87](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/f/b19c9b/32.png) [@faca87](https://root-forum.cern.ch/u/faca87)\
**Post date:** [June 9, 2023, 12:43pm UTC](https://root-forum.cern.ch/t/th1-scaling-axis/55237/9 "2023-06-09T12:43:21Z")

</div>

I replaced

`for(Int_t i = 0; i < X.GetSize(); i++) X[i] = Scale(X[i],a,b,c,scalexaxis);`

by

`for(Int_t i = 0; i < X.GetSize(); i++) X[i] = Scale(X[i],a,b,c,scalexaxis);`

but I got

```auto
root [0]
Processing scaleaxis.cpp...
In file included from input_line_8:1:
scaleaxis.cpp:53:66: error: use of undeclared identifier 'b'
      for(Int_t i = 0; i < X.GetSize(); i++) X[i] = Scale(X[i],a,b,c,scalexaxis);
                                                                 ^
scaleaxis.cpp:53:68: error: use of undeclared identifier 'c'
      for(Int_t i = 0; i < X.GetSize(); i++) X[i] = Scale(X[i],a,b,c,scalexaxis);
                                                                   ^
scaleaxis.cpp:53:70: error: use of undeclared identifier 'scalexaxis'
      for(Int_t i = 0; i < X.GetSize(); i++) X[i] = Scale(X[i],a,b,c,scalexaxis);
                                                                     ^
scaleaxis.cpp:59:33: error: too few arguments to function call, expected 5, have 1
              Scale(a->GetXmin()),
              ~~~~~ ^
scaleaxis.cpp:60:33: error: too few arguments to function call, expected 5, have 1
              Scale(a->GetXmax()));
              ~~~~~ ^
scaleaxis.cpp:68:3: error: no matching function for call to 'ScaleAxis'
  ScaleAxis(h->GetXaxis(), Scale);
  ^ ~~~~~~~~
scaleaxis.cpp:47:6: note: candidate function not viable: no known conversion from 'Double_t (*)(Double_t)' (aka 'double (*)(double)') to 'Double_t (*)(Double_t, double, double, double, void (*)(double, double, double))' (aka 'double (*)(double, double, double, double, void (*)(double, double, double))') for 2nd argument
void ScaleAxis(TAxis *a, Double_t (*Scale)(Double_t, double, double, double, void(double, double, double)))
     ^
scaleaxis.cpp:76:2: error: no matching function for call to 'ScaleXaxis'
        ScaleXaxis(h,ScaleX);
        ^ ~~~~~~~~~
scaleaxis.cpp:65:6: note: candidate function not viable: no known conversion from 'Double_t (Double_t, double, double, double, void (*)(double, double, double))' (aka 'double (double, double, double, double, void (*)(double, double, double))') to 'Double_t (*)(Double_t)' (aka 'double (*)(double)') for 2nd argument
void ScaleXaxis(TH1 *h, Double_t (*Scale)(Double_t))
     ^
root [1]

```

then I also replaced

`void ScaleAxis(TAxis *a, Double_t (*Scale)(Double_t))`

by

`void ScaleAxis(TAxis *a, Double_t (*Scale)(Double_t, double, double, double, void(double, double, double)))`  
and added the invoke function in this function too, but still doesn’t work

```auto
Processing scaleaxis.cpp...
In file included from input_line_8:1:
scaleaxis.cpp:50:12: error: use of undeclared identifier 'b'
  invoke(a,b,c, scaleaxis);
           ^
scaleaxis.cpp:50:14: error: use of undeclared identifier 'c'
  invoke(a,b,c, scaleaxis);
             ^
scaleaxis.cpp:50:17: error: use of undeclared identifier 'scaleaxis'
  invoke(a,b,c, scaleaxis);
                ^
scaleaxis.cpp:54:66: error: use of undeclared identifier 'b'
      for(Int_t i = 0; i < X.GetSize(); i++) X[i] = Scale(X[i],a,b,c,scalexaxis);
                                                                 ^
scaleaxis.cpp:54:68: error: use of undeclared identifier 'c'
      for(Int_t i = 0; i < X.GetSize(); i++) X[i] = Scale(X[i],a,b,c,scalexaxis);
                                                                   ^
/nfs/luna02/casaburf/SimulazioniFatte/21Nepgamma/Risonanza_6998/scaleaxis.cpp:54:70: error: use of undeclared identifier 'scalexaxis'
      for(Int_t i = 0; i < X.GetSize(); i++) X[i] = Scale(X[i],a,b,c,scalexaxis);
                                                                     ^
scaleaxis.cpp:60:33: error: too few arguments to function call, expected 5, have 1
              Scale(a->GetXmin()),
              ~~~~~ ^
scaleaxis.cpp:61:33: error: too few arguments to function call, expected 5, have 1
              Scale(a->GetXmax()));
              ~~~~~ ^
scaleaxis.cpp:69:3: error: no matching function for call to 'ScaleAxis'
  ScaleAxis(h->GetXaxis(), Scale);
  ^ ~~~~~~~~
scaleaxis.cpp:47:6: note: candidate function not viable: no known conversion from 'Double_t (*)(Double_t)' (aka 'double (*)(double)') to 'Double_t (*)(Double_t, double, double, double, void (*)(double, double, double))' (aka 'double (*)(double, double, double, double, void (*)(double, double, double))') for 2nd argument
void ScaleAxis(TAxis *a, Double_t (*Scale)(Double_t, double, double, double, void scaleaxis(double a, double b, double c)))
     ^
scaleaxis.cpp:77:2: error: no matching function for call to 'ScaleXaxis'
        ScaleXaxis(h,ScaleX);
        ^ ~~~~~~~~~
scaleaxis.cpp:66:6: note: candidate function not viable: no known conversion from 'Double_t (Double_t, double, double, double, void (*)(double, double, double))' (aka 'double (double, double, double, double, void (*)(double, double, double))') to 'Double_t (*)(Double_t)' (aka 'double (*)(double)') for 2nd argument
void ScaleXaxis(TH1 *h, Double_t (*Scale)(Double_t))
     ^
root [1]

```

[scaleaxis.cpp](https://root-forum.cern.ch/uploads/short-url/36N8WsfGqbDDorb4ev9m9T5SQpF.cpp) (1.9 KB)

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [June 9, 2023, 12:58pm UTC](https://root-forum.cern.ch/t/th1-scaling-axis/55237/10 "2023-06-09T12:58:50Z")

</div>

Same as before, the compiler tells you exactly what’s wrong:

```auto
use of undeclared identifier 'b'

```

Means exactly that: you are using a variable which is not declared. Again basic: In C++ all variable MUST be declared. So: declare them …

---

<div class="post-metadata">

**Author:** ![faca87](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/f/b19c9b/32.png) [@faca87](https://root-forum.cern.ch/u/faca87)\
**Post date:** [June 9, 2023, 6:25pm UTC](https://root-forum.cern.ch/t/th1-scaling-axis/55237/11 "2023-06-09T18:25:44Z")

</div>

I made some changes based on the errors I got step by step.  
Then I got this error

```auto
root [0]
Processing scaleaxis.cpp...
In file included from input_line_8:1:
scaleaxis.cpp:70:52: error: too few arguments to function call, expected 5, have 4
  ScaleAxis(h->GetXaxis(), Scale(c0,c1,c2,scaleaxis));
                           ~~~~~ ^
scaleaxis.cpp:78:15: error: no matching function for call to 'ScaleX'
        ScaleXaxis(h,ScaleX(c0,c1,c2,scaleaxis));
                     ^ ~~~~~
scaleaxis.cpp:37:10: note: candidate function not viable: requires 5 arguments, but 4 were provided
Double_t ScaleX(Double_t x, double c0, double c1, double c2, void scaleaxis(double c0, double c1, double c2))
         ^
root [1]

```

using this macro

[scaleaxis.cpp](https://root-forum.cern.ch/uploads/short-url/Aclcxo8FLWG5WXzLgwVkNZBp1iX.cpp) (2.2 KB)

then I replaced

`ScaleAxis(h->GetXaxis(), Scale(c0,c1,c2,scaleaxis));`

by

`ScaleAxis(h->GetXaxis(), Scale(Double_t x, c0,c1,c2,scaleaxis));`

and  
`ScaleXaxis(h,ScaleX(c0,c1,c2,scaleaxis));`

by

`ScaleXaxis(h,ScaleX(Double_t x,c0,c1,c2,scaleaxis));`

but now I get

```auto
root [0]
Processing scaleaxis.cpp...
In file included from input_line_8:1:
scaleaxis.cpp:70:34: error: unexpected type name 'Double_t': expected expression
  ScaleAxis(h->GetXaxis(), Scale(Double_t x,c0,c1,c2,scaleaxis));
                                 ^
scaleaxis.cpp:78:22: error: unexpected type name 'Double_t': expected expression
        ScaleXaxis(h,ScaleX(Double_t x,c0,c1,c2,scaleaxis));
                            ^
root [1]

```

[scaleaxis.cpp](https://root-forum.cern.ch/uploads/short-url/7Z1WRsqvKvpCLJLg5Wou2zSkHWX.cpp) (2.3 KB)

---

<div class="post-metadata">

**Author:** ![faca87](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/f/b19c9b/32.png) [@faca87](https://root-forum.cern.ch/u/faca87)\
**Post date:** [June 15, 2023, 7:32am UTC](https://root-forum.cern.ch/t/th1-scaling-axis/55237/12 "2023-06-15T07:32:57Z")

</div>

Hi @couet, do you know how to solve it?

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [June 15, 2023, 7:44am UTC](https://root-forum.cern.ch/t/th1-scaling-axis/55237/13 "2023-06-15T07:44:57Z")

</div>

This is simple C++ . Check your code the error message is clear.  
And please fix this kind of thing:

```auto
void invoke(double c0, double c1, double c2, void (*func)(double, double, double))
{
    return c0,c1,c2;
}

```

How tdo you ecpect this to work ? invoke is `void` … and even if it was `double` how do you expect the return with 3 values to work ?

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [June 15, 2023, 8:12am UTC](https://root-forum.cern.ch/t/th1-scaling-axis/55237/14 "2023-06-15T08:12:13Z")

</div>

Here is a working code. Start from that and adjuste it as you need:

```auto
double ScaleX(double x, double c0, double c1, double c2)
{
   double v;
   v = c0 + c1*x + c2*x*x;
   return v;
}

double invoke(double x, double c0, double c1, double c2, double (*func)(double, double, double, double))
{
   return func(x, c0, c1, c2);
}

void scaleaxis()
{
   double x = 3;
   double c0 = 0;
   double c1 = 1;
   double c2 = 2;
   cout << invoke(x, c0, c1, c2, &ScaleX) << '\n';
}

```

```auto
root [0] 
Processing scaleaxis.C...
21
root [1] 

```

---

<div class="post-metadata">

**Author:** ![faca87](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/f/b19c9b/32.png) [@faca87](https://root-forum.cern.ch/u/faca87)\
**Post date:** [June 15, 2023, 9:02am UTC](https://root-forum.cern.ch/t/th1-scaling-axis/55237/15 "2023-06-15T09:02:38Z")

</div>

Thank you @couet, I tried this code

[scaleaxis.cpp](https://root-forum.cern.ch/uploads/short-url/qh4de0oX6nl9LjBXCYRtOiog5yR.cpp) (1.8 KB)

but always getting error

```auto
root [0]
Processing scaleaxis.cpp...
In file included from input_line_8:1:
/nfs/luna02/casaburf/SimulazioniFatte/21Nepgamma/Risonanza_6998/scaleaxis.cpp:81:2: error: no matching function for call to 'ScaleXaxis'
        ScaleXaxis(h, c0, c1, c2, ScaleX);
        ^ ~~~~~~~~~
/nfs/luna02/casaburf/SimulazioniFatte/21Nepgamma/Risonanza_6998/scaleaxis.cpp:65:6: note: candidate function not viable: no known conversion from 'Double_t (Double_t, double, double, double)' (aka 'double (double, double, double, double)') to 'Double_t (*)(Double_t)' (aka 'double (*)(double)') for 5th argument
void ScaleXaxis(TH1 *h, double c0, double c1, double c2, Double_t (*Scale)(Double_t))
     ^

```

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [June 15, 2023, 9:06am UTC](https://root-forum.cern.ch/t/th1-scaling-axis/55237/16 "2023-06-15T09:06:23Z")

</div>

send me `filein.hist`

---

<div class="post-metadata">

**Author:** ![faca87](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/f/b19c9b/32.png) [@faca87](https://root-forum.cern.ch/u/faca87)\
**Post date:** [June 15, 2023, 10:27am UTC](https://root-forum.cern.ch/t/th1-scaling-axis/55237/17 "2023-06-15T10:27:27Z")

</div>

Here.

> **[filein.hist](https://wetransfer.com/downloads/de590c21ff7cda5d020ce7e4a6b3222820230615102703/55de11)**
>
> 1 file sent via WeTransfer, the simplest way to send your files around the world

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [June 15, 2023, 11:23am UTC](https://root-forum.cern.ch/t/th1-scaling-axis/55237/18 "2023-06-15T11:23:26Z")

</div>

The following code is correct C++ wise. You can run it with:

```auto
root [0] .x scaleaxis.cpp(1,2,3)
a = 1, b = 2, c = 3
Info in <TCanvas::MakeDefCanvas>: created default TCanvas with name c1
root [1] 

```

```auto
double ScaleX(double x, double a, double b, double c)
{
  double v;
  v = a + b*x + c*x*x;
  return v;
}

void ScaleAxis(TAxis *axis, double a, double b, double c, double (*Scale)(double, double, double, double))
{
   if (!axis) return;
   if (axis->GetXbins()->GetSize()) {
      TArrayD X(*(axis->GetXbins()));
      for(Int_t i = 0; i < X.GetSize(); i++) X[i] = Scale(X[i], a, b, c);
      axis->Set((X.GetSize() - 1), X.GetArray());
   } else {
      axis->Set(axis->GetNbins(),
              Scale(axis->GetXmin(), a, b, c),
              Scale(axis->GetXmax(), a, b, c));
   }
   return;
}

void scaleaxis(double a, double b, double c) {
   cout << "a = " << a << ", b = " << b << ", c = " << c << endl;

   TFile *RootIn = TFile::Open("filein.hist","READ");
   TFile *RootOut = new TFile("fileout.hist","RECREATE");
   TH1F *h = (TH1F*)RootIn->Get("zint");
   if (!h) return;

   TAxis *XAxis = h->GetXaxis();
   ScaleAxis(XAxis, a, b, c, &ScaleX);

   h->ResetStats();
   h->Draw();
   h->Write();
   RootOut->Write();
   RootIn->Close();
   RootOut->Close();
}

```

Now I let you fisnish it and check if does what you need. That’s your job.

---

<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:** [June 15, 2023, 11:58am UTC](https://root-forum.cern.ch/t/th1-scaling-axis/55237/19 "2023-06-15T11:58:32Z")

</div>

Read the comments in the source code of the original [`ScaleAxis`](https://root-forum.cern.ch/t/can-we-shift-histogram-for-several-channels/12050/2) function.

---

<div class="post-metadata">

**Author:** ![faca87](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/f/b19c9b/32.png) [@faca87](https://root-forum.cern.ch/u/faca87)\
**Post date:** [June 15, 2023, 1:06pm UTC](https://root-forum.cern.ch/t/th1-scaling-axis/55237/20 "2023-06-15T13:06:03Z")

</div>

Thank you @couet, your code works!

I also modiefied to try to use the `ScaleXaxis` function.

[scaleaxis.cpp](https://root-forum.cern.ch/uploads/short-url/3ZjYVChVfbaLJTFo1VQaE4w48Yd.cpp) (1.7 KB)

and looks like to work too!

@Wile_E_Coyote what comment are you referring?

[Next page](https://root-forum.cern.ch/t/th1-scaling-axis/55237.md?page=2)
