# Minuit in a loop

Hi,

I am trying to fit with minuit different histogram within a loop.
The problem is that I get the same values for the parameters all the times
for each different histogram (and it’s wrong) while if I fit an histogram one at the time I get different values;

here it is my pseudo-code

``````
for (int ex=0; ex<1000; ex++){

TH1F *data = getHisto(ex);

fillVectorFromHisto(data);

// ...
// ...

TVirtualFitter::SetDefaultFitter("Minuit");
TVirtualFitter* minuit = TVirtualFitter::Fitter(0,21);

char pname[6];

minuit->SetParameter(0,"Lumi" ,L, 0.0001,0,0);

for (int i = 1; i < 21; ++i) {

sprintf(pname,"par%d",i);
minuit->SetParameter(i, pname,0,0.01, 0,0);

}

minuit->SetFCN(fcn);

// minimize

// here I got values of the parameter each time the same

}
``````

I am sure that I am fitting different histograms
I tryed to define TVirtualFitter* minuit = TVirtualFitter::Fitter(0,21);
outside the loop but it doesn’t work

thank you
Francesco

sorry, solved… my fault
I haven’t correctly initialized a vector