16 #include "Riostream.h"
52 if (niter==0)
if (value<0.)
return 0.;
else return 1./(value+1.);
53 else if (modelvalue<=0.)
return 0.;
else return 1./modelvalue;
71 TObjArray comps, fixedcomps;
76 Bool_t assigned = kFALSE;
82 if (!assigned)
continue;
86 else fixedcomps.Add(fModel);
89 Int_t ncomp = comps.GetLast()+1;
90 if (ncomp<=0)
return kFALSE;
92 TMatrixD matr(ncomp,ncomp);
93 TVectorD vector(ncomp);
95 Double_t** DopData =
new Double_t* [fitter->
GetNumData()];
99 Double_t** Weights =
new Double_t* [fitter->
GetNumData()];
106 Bool_t changed = kFALSE;
112 for(Int_t ndata=0;ndata<fitter->
GetNumData();ndata++) {
121 Double_t* weight = Weights[ndata];
123 for (Int_t nbin=0;nbin<size;nbin++)
124 weight[nbin] =
PointWeight(niter,FFtype, ampl*values[nbin], result[nbin], ampl*ampl*devs[nbin]);
127 for(Int_t n1=0;n1<ncomp;n1++)
128 for(Int_t n2=n1;n2<ncomp;n2++) {
130 for(Int_t ndata=0;ndata<fitter->
GetNumData();ndata++) {
133 if ((bins1!=0) && (bins2!=0)) {
135 Double_t* weight = Weights[ndata];
136 for(Int_t nbin=0;nbin<size;nbin++)
137 fSum+=bins1[nbin]*bins2[nbin]*weight[nbin];
145 for(Int_t ndata=0;ndata<fitter->
GetNumData();ndata++) {
150 Double_t* bins = DopData[ndata];
152 for(Int_t nbin=0;nbin<size;nbin++)
153 bins[nbin] = dampl*values[nbin];
155 for(Int_t n=0;n<=fixedcomps.GetLast();n++) {
160 for(Int_t nbin=0;nbin<size;nbin++)
161 bins[nbin] -= mampl*mbins[nbin];
168 for(Int_t n=0;n<ncomp;n++) {
170 for(Int_t ndata=0;ndata<fitter->
GetNumData();ndata++) {
172 if (bins1==0)
continue;
174 Double_t* bins = DopData[ndata];
175 Double_t* weight = Weights[ndata];
176 for(Int_t nbin=0;nbin<size;nbin++)
177 fSum+=bins[nbin]*bins1[nbin]*weight[nbin];
183 if (matr.Determinant()==0.) {
184 std::cerr <<
" Amplitude estimation algorithm failed. " << std::endl;
185 std::cerr <<
" Determinant of matrix == 0.; This may be due to equivalent model components or zero model at all" << std::endl;
192 for(Int_t n=0;n<ncomp;n++) {
207 for(Int_t n=0;n<fitter->
GetNumData();n++)
delete[] Weights[n];
210 for(Int_t n=0;n<fitter->
GetNumData();n++)
delete[] DopData[n];
218 if (fitter==0)
return kFALSE;
221 TArrayI refindex(fitter->
GetNumModel()); refindex.Reset(-1);
222 TArrayI fixedindex(fitter->
GetNumModel()); fixedindex.Reset(-1);
227 for(Int_t n=0;n<nmodel;n++) {
229 Bool_t assigned = kFALSE;
235 if (!assigned)
continue;
239 else fixedindex[nfixed++] = n;
242 if (ncomp<=0)
return kFALSE;
244 TMatrixD matr(ncomp,ncomp);
245 TVectorD vector(ncomp);
247 TArrayC Usage(nmodel);
248 TArrayD ModelValues(nmodel);
249 TArrayD ModelAmpls(nmodel);
253 Bool_t changed = kFALSE;
256 matr = 0.; vector = 0.;
258 for(Int_t ndata=0;ndata<fitter->
GetNumData();ndata++) {
261 if (iter==0)
return kFALSE;
266 Usage.Reset(0); ModelAmpls.Reset(0.); ModelValues.Reset(0.);
267 for(Int_t n=0;n<nmodel;n++) {
277 Double_t result = 0.;
278 for (Int_t n=0; n<nmodel;n++)
281 result += ModelAmpls[n] * ModelValues[n];
284 if (weight<=0.)
continue;
286 for (Int_t i1=0;i1<ncomp;i1++)
287 for(Int_t i2=i1;i2<ncomp;i2++) {
288 Double_t zn = matr(i1,i2);
289 zn += ModelValues[refindex[i1]] * ModelValues[refindex[i2]] * weight;
291 if (i1!=i2) matr(i2,i1) = zn;
294 Double_t dvalue = dampl*iter->
Value();
295 for(Int_t nf=0;nf<nfixed;nf++)
296 dvalue -= ModelAmpls[fixedindex[nf]] * ModelValues[fixedindex[nf]];
298 for (Int_t i1=0;i1<ncomp;i1++) {
299 Double_t zn = vector(i1);
300 zn += ModelValues[refindex[i1]] * dvalue * weight;
304 }
while (iter->
Next());
306 for(Int_t n=0;n<nmodel;n++)
312 if (matr.Determinant()==0.) {
313 std::cerr <<
" Amplitude estimation algorithm failed. " << std::endl;
314 std::cerr <<
" Determinant of matrix == 0.; This may be due to equivalent model components or zero model at all" << std::endl;
321 for(Int_t n=0;n<ncomp;n++) {
342 std::cout <<
" number of iterations " <<
fiNumIters << std::endl;
virtual void DoAction(TGo4FitterAbstract *Fitter)
void RebuildAll(Bool_t ForceBuild=kFALSE)
Double_t PointWeight(Int_t niter, Int_t FFtype, Double_t value, Double_t modelvalue, Double_t standdev)
virtual TGo4FitDataIter * MakeIter()
Int_t GetDataBinsSize(TGo4FitData *data)
Double_t * GetDataBinsResult(TGo4FitData *data)
void SetAmplError(Double_t iError)
virtual void Print(Option_t *option) const
void SetAmplValue(Double_t iAmpl)
const char * AssignmentName(Int_t n)
Bool_t CalculateWithIterators(TGo4Fitter *fitter)
Double_t * GetDataBinsDevs(TGo4FitData *data)
virtual Bool_t Reset(Bool_t UseRanges=kTRUE)
virtual Double_t EvaluateAtPoint(TGo4FitData *data, Int_t nbin, Bool_t UseRanges=kTRUE)
void Print(Option_t *option) const
TGo4FitModel * GetModel(Int_t n)
virtual Bool_t Next(Bool_t UseRanges=kTRUE)
virtual Bool_t BeforeEval(Int_t ndim)
TGo4FitData * GetData(Int_t n)
Int_t NumAssigments() const
Int_t GetFitFunctionType()
Double_t * GetModelBinsValues(TGo4FitModel *model, const char *DataName)
Bool_t DataBuffersAllocated(TGo4FitData *data)
Bool_t CalculateWithBuffers(TGo4Fitter *fitter)
const char * GetDataName(Int_t n)
Int_t GetNumModel() const
Bool_t IsAssignTo(const char *DataName) const
Double_t * GetDataBinsValues(TGo4FitData *data)
TGo4FitData * FindData(const char *DataName)
Int_t IndexesSize() const
Double_t StandardDeviation() const
Double_t GetRatioValueFor(const char *DataName)
Bool_t ModelBuffersAllocated(TGo4FitModel *model)
TGo4FitParameter * GetAmplPar()
virtual ~TGo4FitAmplEstimation()