Hi ROOTers
i have a problem on TF2.i have some histogram and i want to calculate the following equation and summation.
my equations are N11 = Nsm + 0.01alpha + 0.01beta, N21 = Nsm + 0.02alpha + 0.01beta that i can obtain alpha and beta here .alpha=(N21-N11)/0.01, beta=(2*N11-N21-Nsm)/0.01;
so i want to calculate this summation = ((N11-Nsm)/Nsm)^2 that from i=0 to i=20 and i defined the Nsm,N11,N21 by this form:
int Nsm=hz->GetBinContent(is);
int N11=hz11->GetBinContent(is);
int N21=hz21->GetBinContent(is);
the part of my code is:
for(int is = 0 ; is < 20; is++)
{
how and where are x, y, and ki2 defined? Do you have a complete and running script that does everything but the summation of ki2 and the drawing? That might make it easier to understand what you are trying to do.
i searched and find some way for this problem and correct past code but i have another problem.
code is :
for(int is = 0 ; is < 20; is++)
{
int Nsm=hz->GetBinContent(is);
int N11=hz11->GetBinContent(is);
int N21=hz21->GetBinContent(is);
// N11=Nsm+0.01alpha+0.01beta;
// N21=Nsm+0.02alpha+0.01beta;
int alpha=(N21-N11)/0.01;
int beta=(2*N11-N21-Nsm)/0.01;
[color=red]now here i want to sum .i want to calculate coefficients but i can’t.i think i can not writing a loop or script to calculate for this summation.if i can calculate a,b,c my workis finish.
are these below lines true?
? int a=a+(alpha^2/Nsm);
?int b=b+(beta^2/Nsm);
?int c=c+((alpha*beta)/Nsm);[/color]
}
TF2 *ki2 = new TF2(“ki2”,"[0]*x^2+[1]*y^2+[2]xy",-1,1,-1,1);
ki2->SetParameters(0,a);
ki2->SetParameters(1,b);
ki2->SetParameters(2,c);
ki2->Draw();
thanks for your attention,i apology you beacuse i was bother you.
you don’t bother me at all You should (re-) read the part on scopes in your C++ book; a, b and c need to be declared outside the loop. And instead of a = a + whatever you can simply write a+= whatever. Really - if you don’t know the basics of C++ you will not be able to use ROOT, so please make sure you have read an introduction to C++.