hi guys,
I need some help again
I will be using the function below for several times like more than 50 times as I keep changing these 3 parameters:
fpf[i]->SetParameter(4,61.0);
fpf[i]->SetParameter(6,gRandom->Gaus(0.9346,0.0045));
fpf[i]->SetParameter(7,gRandom->Gaus(3.2880,0.2134));
For this case, my code would be getting longer and longer as I add more and more parameters.
Sample parameters:
fpf[i]->SetParameter(4,61.0); fpf[i]->SetParameter(6,gRandom->Gaus(0.9346,0.0045)); fpf[i]->SetParameter(7,gRandom->Gaus(3.2880,0.2134));
fpf[i]->SetParameter(4,55.0); fpf[i]->SetParameter(6,gRandom->Gaus(0.9122,0.0023)); fpf[i]->SetParameter(7,gRandom->Gaus(3.1280,0.0134));
fpf[i]->SetParameter(4,118.0); fpf[i]->SetParameter(6,gRandom->Gaus(0.8921,0.0003)); fpf[i]->SetParameter(7,gRandom->Gaus(2.8990,0.0014));
fpf[i]->SetParameter(4,71.0); fpf[i]->SetParameter(6,gRandom->Gaus(0.9021,0.0035)); fpf[i]->SetParameter(7,gRandom->Gaus(2.9590,0.0019));
Can you help me write a sample code for me to reduce my lengthy program?
for (Int_t i=0; i<nof; i++)
{
fna = "f"; fna += i;
//choice: transfer momentum square; electron(finite)proton
fpf[i] = new TF1("fna","(((2.0*[0]*[0]*[1]*[1]*[2]*[2]*[3]*[3])/(x*x*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)+2.0*[3]*[3]*x*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)+(x*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)*sqrt(x*x*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)+4.0*[3]*[3]*x*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)))))*((2.0*[3]*[3])/(2.0*[3]*[3]+x*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)+sqrt(x*x*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)+4.0*[3]*[3]*x*sin([4]*[5]/360.0)*sin([4]*[5]/360.0))))*((4.0*[3]*[3])/(4.0*[3]*[3]+x))*([6]*[6]*cos([4]*[5]/360.0)*cos([4]*[5]/360.0)+[7]*[7]*(2.0*[3]*[3]*x*cos([4]*[5]/360.0)*cos([4]*[5]/360.0)+4.0*[3]*[3]*x*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)+x*x*sin([4]*[5]/360.0)*sin([4]*[5]/360.0))/(8.0*[3]*[3]*[3]*[3])))", 0.0025, 1.0);
fpf[i]->SetParameter(0,1.0);
fpf[i]->SetParameter(1,1.0);
fpf[i]->SetParameter(2,1.0/137.0);
fpf[i]->SetParameter(3,gRandom->Gaus(0.938272081,0.000000006));
fpf[i]->SetParameter(4,61.0);
fpf[i]->SetParameter(5,TMath::Pi());
fpf[i]->SetParameter(6,gRandom->Gaus(0.9346,0.0045));
fpf[i]->SetParameter(7,gRandom->Gaus(3.2880,0.2134));
}
//=== getting the average of the function===//
TGraph *av1 = new TGraph();
for (Int_t j=0; j < nop; j++)
{
xpt = del*j + 0.0025*del;
av1->SetPoint(j, xpt, 0.0);
}
for (Int_t i=0; i<nof; i++)
{
for (Int_t j=0; j < nop; j++)
{
av1->GetPoint(j, xpt, ypt);
av1->SetPoint(j, xpt, ypt + fpf[i]->Eval(xpt)/(Double_t)nof);
}
}
best regards,
jaybee