2D fitting with htemp -> compiled mode

Hi,

I got in troubles when doing:

nt->Draw(“vem_charge3:vem_charge1”);
TH2F prueba = (TH2F)gPad->GetPrimitive(“htemp”);
prueba->Fit(“pol1”);

always getting the same error message:

Error in : function pol1 dimension, 1, does not match histogram dimension, 2

The point is that I don’t want to declare the 2D histogram in my compiled program, since I don’t want to set the number of bins. So, I also tried:

TProfile *pvem_charge = new TProfile();
nt->Draw(“vem_charge3:vem_charge1>>pvem_charge”);
pvem_charge->Fit(“pol1”,"",“same”,0,4000); (if not “same”, it draws a new empty histo).

but I get the profile with a flat fit over zero (p0=0,p1=0).

So, in a desperated attempt, I tried:

TProfile *pvem_charge = new TProfile();
nt->Draw(“vem_charge3:vem_charge1>>pvem_charge”);
TH1F prueba = (TH1F)gPad->GetPrimitive(“pvem_charge”);
prueba->Fit(“pol1”,"",“same”,0,4000);

Ok, I have no idea what else to try. Could you please help me??

Thanks.

Fede.

Hi,

You could use:

nt->Draw("vem_charge3:vem_charge1","","prof"); TH2F *prueba = (TH2F*)gPad->GetPrimitive("htemp"); prueba->Fit("pol1"); or

TProfile *pvem_charge = new TProfile(); pvem_charge->SetName("pvem_charge"); nt->Draw("vem_charge3:vem_charge1>>pvem_charge"); pvem_charge->Fit("pol1","","same",0,4000); (if not "same", it draws a new empty histo).

Cheers,
Philippe

I already tried your second option and it gives the plot with a zero fit.

About the first option, it works, but it does not what I exactly want to do. When I write on CINT:

nt->Draw(“vem_charge1:vem_charge2”);

and then make the fit manually, I get the plot number1.

Then, if I run the macro with:
nt->Draw(“vem_charge1:vem_charge2”,"",“prof”);
TH2F prueba = (TH2F)gPad->GetPrimitive(“htemp”);
prueba->Fit(“pol1”);

I get the plot number2.

But two things happen that I don’t like. First, it gets some binning that I don’t want… but I can tolerate. Second, and the worst, the result of the fit is not the same and not a very good one, as you can see…