ProjectionX question

Hi,

I produced the file hsimple.root using $ROOTSYS/tutorials/hsimple.C and copied it into the local directory twice under the names hsimple1.root and hsimple.root and run the attached file. If I uncomment line 22 and comment line 21 the script runs like charm. If I comment line 22 and uncomment line 21 it crashes with the following message:

root [0] .x test.C
Error: Symbol hpxpy is not defined in current scope test.C:22:
Error: Failed to evaluate hpxpy->GetYaxis()
Error: Failed to evaluate hpxpy->GetYaxis()->FindBin(1.6)
*** Interpreter error recovered ***
root [1]

Why with the default arguments TH2::ProjectionX() works fine, and with custom ones crash on the second call on different object?! Or do I totally misunderstand something?

Cheers,
Ivan

P.S. root ver. 5.16.00 on Debian/i686/2.6.22.1
test.C (704 Bytes)

it seems to work if you do:

        int i = hpxpy->GetYaxis()->FindBin(1.6);
        hpxpy->ProjectionX("_px", 0, i);

Yes, it works… :confused: Not that I understand what is the principle difference between the initial code:

and your one:

int i = hpxpy->GetYaxis()->FindBin(1.6); hpxpy->ProjectionX("_px", 0, i);
Anyway, thanks for the solution

Cheers,
Ivan

As you may have noticed, the C++ ROOT interpreter is very flexible and allows you to use some variables without having declared them. hpxpy, in your macro, is exactly the case. That is not valid C++ but CINT is a nice guy and allows you to do it in some limits… and you reached the limits it seems. In that particular case CINT was lost.

I let the CINT experts give you more details.

Currently CINT looks up a ‘name’ only if it is on the ‘outside’ of the statement. So inhout->ProjectionX("_px", 0, hin->GetYaxis()->FindBin(1.6));CINT will look up “hout” but will not lookup “hin”.Another solution would have been{code]
h = hpxpy;
h->ProjectionX("_px", 0, h->GetYaxis()->FindBin(1.6));[/code]

Cheers,
Philippe