1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
16 /* $Id: AliUnfolding.cxx 31168 2009-02-23 15:18:45Z jgrosseo $ */
18 // This class allows 1-dimensional unfolding.
19 // Methods that are implemented are chi2 minimization and bayesian unfolding.
21 // Author: Jan.Fiete.Grosse-Oetringhaus@cern.ch
23 #include "AliUnfolding.h"
26 #include <TVirtualFitter.h>
31 #include "Riostream.h"
34 using namespace std; //required for resolving the 'cout' symbol
36 TMatrixD* AliUnfolding::fgCorrelationMatrix = 0;
37 TMatrixD* AliUnfolding::fgCorrelationMatrixSquared = 0;
38 TMatrixD* AliUnfolding::fgCorrelationCovarianceMatrix = 0;
39 TVectorD* AliUnfolding::fgCurrentESDVector = 0;
40 TVectorD* AliUnfolding::fgEntropyAPriori = 0;
41 TVectorD* AliUnfolding::fgEfficiency = 0;
43 TAxis* AliUnfolding::fgUnfoldedAxis = 0;
44 TAxis* AliUnfolding::fgMeasuredAxis = 0;
46 TF1* AliUnfolding::fgFitFunction = 0;
48 AliUnfolding::MethodType AliUnfolding::fgMethodType = AliUnfolding::kInvalid;
49 Int_t AliUnfolding::fgMaxInput = -1; // bins in measured histogram
50 Int_t AliUnfolding::fgMaxParams = -1; // bins in unfolded histogram = number of fit params
51 Float_t AliUnfolding::fgOverflowBinLimit = -1;
53 AliUnfolding::RegularizationType AliUnfolding::fgRegularizationType = AliUnfolding::kPol1;
54 Float_t AliUnfolding::fgRegularizationWeight = 10000;
55 Int_t AliUnfolding::fgSkipBinsBegin = 0;
56 Float_t AliUnfolding::fgMinuitStepSize = 0.1; // (usually not needed to be changed) step size in minimization
57 Float_t AliUnfolding::fgMinuitPrecision = 1e-6; // minuit precision
58 Int_t AliUnfolding::fgMinuitMaxIterations = 1e6; // minuit maximum number of iterations
59 Bool_t AliUnfolding::fgMinimumInitialValue = kFALSE; // set all initial values at least to the smallest value among the initial values
60 Float_t AliUnfolding::fgMinimumInitialValueFix = -1;
61 Bool_t AliUnfolding::fgNormalizeInput = kFALSE; // normalize input spectrum
62 Float_t AliUnfolding::fgNotFoundEvents = 0;
63 Bool_t AliUnfolding::fgSkipBin0InChi2 = kFALSE;
65 Float_t AliUnfolding::fgBayesianSmoothing = 1; // smoothing parameter (0 = no smoothing)
66 Int_t AliUnfolding::fgBayesianIterations = 10; // number of iterations in Bayesian method
68 Bool_t AliUnfolding::fgDebug = kFALSE;
70 Int_t AliUnfolding::fgCallCount = 0;
72 Int_t AliUnfolding::fgPowern = 5;
74 Double_t AliUnfolding::fChi2FromFit = 0.;
75 Double_t AliUnfolding::fPenaltyVal = 0.;
76 Double_t AliUnfolding::fAvgResidual = 0.;
78 Int_t AliUnfolding::fgPrintChi2Details = 0;
80 TCanvas *AliUnfolding::fgCanvas = 0;
81 TH1 *AliUnfolding::fghUnfolded = 0;
82 TH2 *AliUnfolding::fghCorrelation = 0;
83 TH1 *AliUnfolding::fghEfficiency = 0;
84 TH1 *AliUnfolding::fghMeasured = 0;
86 ClassImp(AliUnfolding)
88 //____________________________________________________________________
89 void AliUnfolding::SetUnfoldingMethod(MethodType methodType)
91 // set unfolding method
92 fgMethodType = methodType;
97 case kInvalid: name = "INVALID"; break;
98 case kChi2Minimization: name = "Chi2 Minimization"; break;
99 case kBayesian: name = "Bayesian unfolding"; break;
100 case kFunction: name = "Functional fit"; break;
102 Printf("AliUnfolding::SetUnfoldingMethod: %s enabled.", name);
105 //____________________________________________________________________
106 void AliUnfolding::SetCreateOverflowBin(Float_t overflowBinLimit)
108 // enable the creation of a overflow bin that includes all statistics below the given limit
110 fgOverflowBinLimit = overflowBinLimit;
112 Printf("AliUnfolding::SetCreateOverflowBin: overflow bin limit set to %f", overflowBinLimit);
115 //____________________________________________________________________
116 void AliUnfolding::SetSkipBinsBegin(Int_t nBins)
118 // set number of skipped bins in regularization
120 fgSkipBinsBegin = nBins;
122 Printf("AliUnfolding::SetSkipBinsBegin: skipping %d bins at the beginning of the spectrum in the regularization.", fgSkipBinsBegin);
125 //____________________________________________________________________
126 void AliUnfolding::SetNbins(Int_t nMeasured, Int_t nUnfolded)
128 // set number of bins in the input (measured) distribution and in the unfolded distribution
129 fgMaxInput = nMeasured;
130 fgMaxParams = nUnfolded;
132 if (fgCorrelationMatrix)
134 delete fgCorrelationMatrix;
135 fgCorrelationMatrix = 0;
137 if (fgCorrelationMatrixSquared)
139 fgCorrelationMatrixSquared = 0;
140 delete fgCorrelationMatrixSquared;
142 if (fgCorrelationCovarianceMatrix)
144 delete fgCorrelationCovarianceMatrix;
145 fgCorrelationCovarianceMatrix = 0;
147 if (fgCurrentESDVector)
149 delete fgCurrentESDVector;
150 fgCurrentESDVector = 0;
152 if (fgEntropyAPriori)
154 delete fgEntropyAPriori;
155 fgEntropyAPriori = 0;
164 delete fgUnfoldedAxis;
169 delete fgMeasuredAxis;
173 Printf("AliUnfolding::SetNbins: Set %d measured bins and %d unfolded bins", nMeasured, nUnfolded);
176 //____________________________________________________________________
177 void AliUnfolding::SetChi2Regularization(RegularizationType type, Float_t weight)
180 // sets the parameters for chi2 minimization
183 fgRegularizationType = type;
184 fgRegularizationWeight = weight;
186 Printf("AliUnfolding::SetChi2Regularization --> Regularization set to %d with weight %f", (Int_t) type, weight);
189 //____________________________________________________________________
190 void AliUnfolding::SetBayesianParameters(Float_t smoothing, Int_t nIterations)
193 // sets the parameters for Bayesian unfolding
196 fgBayesianSmoothing = smoothing;
197 fgBayesianIterations = nIterations;
199 Printf("AliUnfolding::SetBayesianParameters --> Paramaters set to %d iterations with smoothing %f", fgBayesianIterations, fgBayesianSmoothing);
202 //____________________________________________________________________
203 void AliUnfolding::SetFunction(TF1* function)
205 // set function for unfolding with a fit function
207 fgFitFunction = function;
209 Printf("AliUnfolding::SetFunction: Set fit function with %d parameters.", function->GetNpar());
212 //____________________________________________________________________
213 Int_t AliUnfolding::Unfold(TH2* correlation, TH1* efficiency, TH1* measured, TH1* initialConditions, TH1* result, Bool_t check)
215 // unfolds with unfolding method fgMethodType
218 // correlation: response matrix as measured vs. generated
219 // efficiency: (optional) efficiency that is applied on the unfolded spectrum, i.e. it has to be in unfolded variables. If 0 no efficiency is applied.
220 // measured: the measured spectrum
221 // initialConditions: (optional) initial conditions for the unfolding. if 0 the measured spectrum is used as initial conditions.
222 // result: target for the unfolded result
223 // check: depends on the unfolding method, see comments in specific functions
225 // return code: see UnfoldWithMinuit/UnfoldWithBayesian/UnfoldWithFunction
227 if (fgMaxInput == -1)
229 Printf("AliUnfolding::Unfold: WARNING. Number of measured bins not set with SetNbins. Using number of bins in measured distribution");
230 fgMaxInput = measured->GetNbinsX();
232 if (fgMaxParams == -1)
234 Printf("AliUnfolding::Unfold: WARNING. Number of unfolded bins not set with SetNbins. Using number of bins in measured distribution");
235 fgMaxParams = measured->GetNbinsX();
238 if (fgOverflowBinLimit > 0)
239 CreateOverflowBin(correlation, measured);
241 switch (fgMethodType)
245 Printf("AliUnfolding::Unfold: ERROR: Unfolding method not set. Use SetUnfoldingMethod. Exiting...");
248 case kChi2Minimization:
249 return UnfoldWithMinuit(correlation, efficiency, measured, initialConditions, result, check);
251 return UnfoldWithBayesian(correlation, efficiency, measured, initialConditions, result);
253 return UnfoldWithFunction(correlation, efficiency, measured, initialConditions, result);
261 //____________________________________________________________________
262 void AliUnfolding::SetStaticVariables(TH2* correlation, TH1* measured, TH1* efficiency)
264 // fill static variables needed for minuit fit
266 if (!fgCorrelationMatrix)
267 fgCorrelationMatrix = new TMatrixD(fgMaxInput, fgMaxParams);
268 if (!fgCorrelationMatrixSquared)
269 fgCorrelationMatrixSquared = new TMatrixD(fgMaxInput, fgMaxParams);
270 if (!fgCorrelationCovarianceMatrix)
271 fgCorrelationCovarianceMatrix = new TMatrixD(fgMaxInput, fgMaxInput);
272 if (!fgCurrentESDVector)
273 fgCurrentESDVector = new TVectorD(fgMaxInput);
274 if (!fgEntropyAPriori)
275 fgEntropyAPriori = new TVectorD(fgMaxParams);
277 fgEfficiency = new TVectorD(fgMaxParams);
279 delete fgUnfoldedAxis;
280 fgUnfoldedAxis = new TAxis(*(correlation->GetXaxis()));
282 delete fgMeasuredAxis;
283 fgMeasuredAxis = new TAxis(*(correlation->GetYaxis()));
285 fgCorrelationMatrix->Zero();
286 fgCorrelationCovarianceMatrix->Zero();
287 fgCurrentESDVector->Zero();
288 fgEntropyAPriori->Zero();
290 // normalize correction for given nPart
291 for (Int_t i=1; i<=correlation->GetNbinsX(); ++i)
293 Double_t sum = correlation->Integral(i, i, 1, correlation->GetNbinsY());
296 Float_t maxValue = 0;
298 for (Int_t j=1; j<=correlation->GetNbinsY(); ++j)
300 // find most probably value
301 if (maxValue < correlation->GetBinContent(i, j))
303 maxValue = correlation->GetBinContent(i, j);
308 correlation->SetBinContent(i, j, correlation->GetBinContent(i, j) / sum);// * correlation->GetXaxis()->GetBinWidth(i));
309 correlation->SetBinError(i, j, correlation->GetBinError(i, j) / sum);
311 if (i <= fgMaxParams && j <= fgMaxInput)
313 (*fgCorrelationMatrix)(j-1, i-1) = correlation->GetBinContent(i, j);
314 (*fgCorrelationMatrixSquared)(j-1, i-1) = correlation->GetBinContent(i, j) * correlation->GetBinContent(i, j);
318 //printf("MPV for Ntrue = %f is %f\n", fCurrentCorrelation->GetXaxis()->GetBinCenter(i), fCurrentCorrelation->GetYaxis()->GetBinCenter(maxBin));
322 Float_t smallestError = 1;
323 if (fgNormalizeInput)
325 Float_t sumMeasured = measured->Integral();
326 measured->Scale(1.0 / sumMeasured);
327 smallestError /= sumMeasured;
330 for (Int_t i=0; i<fgMaxInput; ++i)
332 (*fgCurrentESDVector)[i] = measured->GetBinContent(i+1);
333 if (measured->GetBinError(i+1) > 0)
335 (*fgCorrelationCovarianceMatrix)(i, i) = (Double_t) 1e-6 / measured->GetBinError(i+1) / measured->GetBinError(i+1);
337 else // in this case put error of 1, otherwise 0 bins are not added to the chi2...
338 (*fgCorrelationCovarianceMatrix)(i, i) = (Double_t) 1e-6 / smallestError / smallestError;
340 if ((*fgCorrelationCovarianceMatrix)(i, i) > 1e7)
341 (*fgCorrelationCovarianceMatrix)(i, i) = 0;
342 //Printf("%d, %e", i, (*fgCorrelationCovarianceMatrix)(i, i));
345 // efficiency is expected to match bin width of result
346 for (Int_t i=0; i<fgMaxParams; ++i)
348 (*fgEfficiency)(i) = efficiency->GetBinContent(i+1);
351 if (correlation->GetNbinsX() != fgMaxParams || correlation->GetNbinsY() != fgMaxInput)
352 cout << "Response histo has incorrect dimensions; expect (" << fgMaxParams << ", " << fgMaxInput << "), got (" << correlation->GetNbinsX() << ", " << correlation->GetNbinsY() << ")" << endl;
356 //____________________________________________________________________
357 Int_t AliUnfolding::UnfoldWithMinuit(TH2* correlation, TH1* efficiency, TH1* measured, TH1* initialConditions, TH1* result, Bool_t check)
360 // implementation of unfolding (internal function)
362 // unfolds <measured> using response from <correlation> and effiency <efficiency>
363 // output is in <result>
364 // <initialConditions> set the initial values for the minimization, if 0 <measured> is used
365 // negative values in initialConditions mean that the given parameter is fixed to the absolute of the value
366 // if <check> is true no unfolding is made, instead only the chi2 without unfolding is printed
368 // returns minuit status (0 = success), (-1 when check was set)
371 SetStaticVariables(correlation, measured, efficiency);
373 // Initialize TMinuit via generic fitter interface
374 Int_t params = fgMaxParams;
375 if (fgNotFoundEvents > 0)
378 TVirtualFitter *minuit = TVirtualFitter::Fitter(0, params);
379 Double_t arglist[100];
380 // minuit->SetDefaultFitter("Minuit2");
382 // disable any output (-1), unfortuantly we do not see warnings anymore then. Have to find another way...
384 minuit->ExecuteCommand("SET PRINT", arglist, 1);
386 // however, enable warnings
387 //minuit->ExecuteCommand("SET WAR", arglist, 0);
389 // set minimization function
390 minuit->SetFCN(Chi2Function);
393 minuit->SetPrecision(fgMinuitPrecision);
395 minuit->SetMaxIterations(fgMinuitMaxIterations);
397 for (Int_t i=0; i<fgMaxParams; i++)
398 (*fgEntropyAPriori)[i] = 1;
400 // set initial conditions as a-priori distribution for MRX regularization
402 for (Int_t i=0; i<fgMaxParams; i++)
403 if (initialConditions && initialConditions->GetBinContent(i+1) > 0)
404 (*fgEntropyAPriori)[i] = initialConditions->GetBinContent(i+1);
407 if (!initialConditions) {
408 initialConditions = measured;
410 Printf("AliUnfolding::UnfoldWithMinuit: Using different initial conditions...");
411 //new TCanvas; initialConditions->DrawCopy();
412 if (fgNormalizeInput)
413 initialConditions->Scale(1.0 / initialConditions->Integral());
416 // extract minimum value from initial conditions (if we set a value to 0 it will stay 0)
417 Float_t minValue = 1e35;
418 if (fgMinimumInitialValueFix < 0)
420 for (Int_t i=0; i<fgMaxParams; ++i)
422 Int_t bin = initialConditions->GetXaxis()->FindBin(result->GetXaxis()->GetBinCenter(i+1));
423 if (initialConditions->GetBinContent(bin) > 0)
424 minValue = TMath::Min(minValue, (Float_t) initialConditions->GetBinContent(bin));
428 minValue = fgMinimumInitialValueFix;
430 Double_t* results = new Double_t[fgMaxParams+1];
431 for (Int_t i=0; i<fgMaxParams; ++i)
433 Int_t bin = initialConditions->GetXaxis()->FindBin(result->GetXaxis()->GetBinCenter(i+1));
434 results[i] = initialConditions->GetBinContent(bin);
440 results[i] = -results[i];
443 if (!fix && fgMinimumInitialValue && results[i] < minValue)
444 results[i] = minValue;
446 // minuit sees squared values to prevent it from going negative...
447 results[i] = TMath::Sqrt(results[i]);
449 minuit->SetParameter(i, Form("param%d", i), results[i], (fix) ? 0 : fgMinuitStepSize, 0, 0);
451 if (fgNotFoundEvents > 0)
453 results[fgMaxParams] = efficiency->GetBinContent(1);
454 minuit->SetParameter(fgMaxParams, "vtx0", results[fgMaxParams], fgMinuitStepSize / 100, 0.01, 0.80);
459 Chi2Function(dummy, 0, chi2, results, 0);
460 printf("AliUnfolding::UnfoldWithMinuit: Chi2 of initial parameters is = %f\n", chi2);
469 // first param is number of iterations, second is precision....
470 arglist[0] = (float)fgMinuitMaxIterations;
471 // arglist[1] = 1e-5;
472 // minuit->ExecuteCommand("SET PRINT", arglist, 3);
473 // minuit->ExecuteCommand("SCAN", arglist, 0);
474 Int_t status = minuit->ExecuteCommand("MIGRAD", arglist, 1);
475 Printf("AliUnfolding::UnfoldWithMinuit: MINUIT status is %d", status);
476 //printf("!!!!!!!!!!!!!! MIGRAD finished: Starting MINOS !!!!!!!!!!!!!!");
477 //minuit->ExecuteCommand("MINOS", arglist, 0);
479 if (fgNotFoundEvents > 0)
481 results[fgMaxParams] = minuit->GetParameter(fgMaxParams);
482 Printf("Efficiency for bin 0 changed from %f to %f", efficiency->GetBinContent(1), results[fgMaxParams]);
483 efficiency->SetBinContent(1, results[fgMaxParams]);
486 for (Int_t i=0; i<fgMaxParams; ++i)
488 results[i] = minuit->GetParameter(i);
489 Double_t value = results[i] * results[i];
490 // error is : 2 * (relError on results[i]) * (value) = 2 * (minuit->GetParError(i) / minuit->GetParameter(i)) * (minuit->GetParameter(i) * minuit->GetParameter(i))
492 if (TMath::IsNaN(minuit->GetParError(i)))
493 Printf("WARNING: Parameter %d error is nan", i);
495 error = 2 * minuit->GetParError(i) * results[i];
499 //printf("value before efficiency correction: %f\n",value);
500 if (efficiency->GetBinContent(i+1) > 0)
502 value /= efficiency->GetBinContent(i+1);
503 error /= efficiency->GetBinContent(i+1);
511 //printf("value after efficiency correction: %f +/- %f\n",value,error);
512 result->SetBinContent(i+1, value);
513 result->SetBinError(i+1, error);
516 Int_t tmpCallCount = fgCallCount;
517 fgCallCount = 0; // needs to be 0 so that the Chi2Function prints its output
518 Chi2Function(dummy, 0, chi2, results, 0);
520 Printf("AliUnfolding::UnfoldWithMinuit: iterations %d. Chi2 of final parameters is = %f", tmpCallCount, chi2);
527 //____________________________________________________________________
528 Int_t AliUnfolding::UnfoldWithBayesian(TH2* correlation, TH1* aEfficiency, TH1* measured, TH1* initialConditions, TH1* aResult)
531 // unfolds a spectrum using the Bayesian method
534 if (measured->Integral() <= 0)
536 Printf("AliUnfolding::UnfoldWithBayesian: ERROR: The measured spectrum is empty");
540 const Int_t kStartBin = 0;
542 Int_t kMaxM = fgMaxInput; //<= fCurrentCorrelation->GetNbinsY(); // max measured axis
543 Int_t kMaxT = fgMaxParams; //<= fCurrentCorrelation->GetNbinsX(); // max true axis
545 // convergence limit: kMaxT * 0.001^2 = kMaxT * 1e-6 (e.g. 250 bins --> 2.5 e-4)
546 const Double_t kConvergenceLimit = kMaxT * 1e-6;
548 // store information in arrays, to increase processing speed (~ factor 5)
549 Double_t* measuredCopy = new Double_t[kMaxM];
550 Double_t* measuredError = new Double_t[kMaxM];
551 Double_t* prior = new Double_t[kMaxT];
552 Double_t* result = new Double_t[kMaxT];
553 Double_t* efficiency = new Double_t[kMaxT];
554 Double_t* binWidths = new Double_t[kMaxT];
556 Double_t** response = new Double_t*[kMaxT];
557 Double_t** inverseResponse = new Double_t*[kMaxT];
558 for (Int_t i=0; i<kMaxT; i++)
560 response[i] = new Double_t[kMaxM];
561 inverseResponse[i] = new Double_t[kMaxM];
565 Float_t measuredIntegral = measured->Integral();
566 for (Int_t m=0; m<kMaxM; m++)
568 measuredCopy[m] = measured->GetBinContent(m+1) / measuredIntegral;
569 measuredError[m] = measured->GetBinError(m+1) / measuredIntegral;
571 for (Int_t t=0; t<kMaxT; t++)
573 response[t][m] = correlation->GetBinContent(t+1, m+1);
574 inverseResponse[t][m] = 0;
578 for (Int_t t=0; t<kMaxT; t++)
582 efficiency[t] = aEfficiency->GetBinContent(t+1);
587 prior[t] = measuredCopy[t];
589 binWidths[t] = aResult->GetXaxis()->GetBinWidth(t+1);
592 // pick prior distribution
593 if (initialConditions)
595 printf("Using different starting conditions...\n");
597 Float_t inputDistIntegral = initialConditions->Integral();
598 for (Int_t i=0; i<kMaxT; i++)
599 prior[i] = initialConditions->GetBinContent(i+1) / inputDistIntegral;
602 //TH1F* convergence = new TH1F("convergence", "convergence", 200, 0.5, 200.5);
606 for (Int_t i=0; i<fgBayesianIterations || fgBayesianIterations < 0; i++)
609 Printf("AliUnfolding::UnfoldWithBayesian: iteration %i", i);
611 // calculate IR from Bayes theorem
612 // IR_ji = R_ij * prior_i / sum_k(R_kj * prior_k)
614 Double_t chi2Measured = 0;
615 for (Int_t m=0; m<kMaxM; m++)
618 for (Int_t t = kStartBin; t<kMaxT; t++)
619 norm += response[t][m] * prior[t];
621 // calc. chi2: (measured - response * prior) / error
622 if (measuredError[m] > 0)
624 Double_t value = (measuredCopy[m] - norm) / measuredError[m];
625 chi2Measured += value * value;
630 for (Int_t t = kStartBin; t<kMaxT; t++)
631 inverseResponse[t][m] = response[t][m] * prior[t] / norm;
635 for (Int_t t = kStartBin; t<kMaxT; t++)
636 inverseResponse[t][m] = 0;
639 //Printf("chi2Measured of the last prior is %e", chi2Measured);
641 for (Int_t t = kStartBin; t<kMaxT; t++)
644 for (Int_t m=0; m<kMaxM; m++)
645 value += inverseResponse[t][m] * measuredCopy[m];
647 if (efficiency[t] > 0)
648 result[t] = value / efficiency[t];
654 // draw intermediate result
655 for (Int_t t=0; t<kMaxT; t++)
657 aResult->SetBinContent(t+1, result[t]);
659 aResult->SetMarkerStyle(24+i);
660 aResult->SetMarkerColor(2);
661 aResult->DrawCopy((i == 0) ? "P" : "PSAME");
664 Double_t chi2LastIter = 0;
665 // regularization (simple smoothing)
666 for (Int_t t=kStartBin; t<kMaxT; t++)
668 Float_t newValue = 0;
670 // 0 bin excluded from smoothing
671 if (t > kStartBin+2 && t<kMaxT-1)
673 Float_t average = (result[t-1] / binWidths[t-1] + result[t] / binWidths[t] + result[t+1] / binWidths[t+1]) / 3 * binWidths[t];
675 // weight the average with the regularization parameter
676 newValue = (1 - fgBayesianSmoothing) * result[t] + fgBayesianSmoothing * average;
679 newValue = result[t];
681 // calculate chi2 (change from last iteration)
684 Double_t diff = (prior[t] - newValue) / prior[t];
685 chi2LastIter += diff * diff;
690 //printf("Chi2 of %d iteration = %e\n", i, chi2LastIter);
691 //convergence->Fill(i+1, chi2LastIter);
693 if (fgBayesianIterations < 0 && chi2LastIter < kConvergenceLimit)
695 Printf("AliUnfolding::UnfoldWithBayesian: Stopped Bayesian unfolding after %d iterations at chi2(change since last iteration) of %e; chi2Measured of the last prior is %e", i, chi2LastIter, chi2Measured);
698 } // end of iterations
700 //new TCanvas; convergence->DrawCopy(); gPad->SetLogy();
701 //delete convergence;
704 if (!fgNormalizeInput)
705 factor = measuredIntegral;
706 for (Int_t t=0; t<kMaxT; t++)
707 aResult->SetBinContent(t+1, result[t] * factor);
709 delete[] measuredCopy;
710 delete[] measuredError;
716 for (Int_t i=0; i<kMaxT; i++)
718 delete[] response[i];
719 delete[] inverseResponse[i];
722 delete[] inverseResponse;
727 // Calculate the covariance matrix, all arguments are taken from NIM,A362,487-498,1995
729 /*printf("Calculating covariance matrix. This may take some time...\n");
731 // check if this is the right one...
732 TH1* sumHist = GetMultiplicityMC(inputRange, eventType)->ProjectionY("sumHist", 1, GetMultiplicityMC(inputRange, eventType)->GetNbinsX());
734 Int_t xBins = hInverseResponseBayes->GetNbinsX();
735 Int_t yBins = hInverseResponseBayes->GetNbinsY();
737 // calculate "unfolding matrix" Mij
738 Float_t matrixM[251][251];
739 for (Int_t i=1; i<=xBins; i++)
741 for (Int_t j=1; j<=yBins; j++)
743 if (fCurrentEfficiency->GetBinContent(i) > 0)
744 matrixM[i-1][j-1] = hInverseResponseBayes->GetBinContent(i, j) / fCurrentEfficiency->GetBinContent(i);
746 matrixM[i-1][j-1] = 0;
750 Float_t* vectorn = new Float_t[yBins];
751 for (Int_t j=1; j<=yBins; j++)
752 vectorn[j-1] = fCurrentESD->GetBinContent(j);
754 // first part of covariance matrix, depends on input distribution n(E)
755 Float_t cov1[251][251];
757 Float_t nEvents = fCurrentESD->Integral(); // N
762 for (Int_t k=0; k<xBins; k++)
764 printf("In Cov1: %d\n", k);
765 for (Int_t l=0; l<yBins; l++)
769 // sum_j Mkj Mlj n(Ej) * (1 - n(Ej) / N)
770 for (Int_t j=0; j<yBins; j++)
771 cov1[k][l] += matrixM[k][j] * matrixM[l][j] * vectorn[j]
772 * (1.0 - vectorn[j] / nEvents);
774 // - sum_i,j (i != j) Mki Mlj n(Ei) n(Ej) / N
775 for (Int_t i=0; i<yBins; i++)
776 for (Int_t j=0; j<yBins; j++)
780 cov1[k][l] -= matrixM[k][i] * matrixM[l][j] * vectorn[i]
781 * vectorn[j] / nEvents;
786 printf("Cov1 finished\n");
788 TH2F* cov = (TH2F*) hInverseResponseBayes->Clone("cov");
791 for (Int_t i=1; i<=xBins; i++)
792 for (Int_t j=1; j<=yBins; j++)
793 cov->SetBinContent(i, j, cov1[i-1][j-1]);
798 // second part of covariance matrix, depends on response matrix
799 Float_t cov2[251][251];
801 // Cov[P(Er|Cu), P(Es|Cu)] term
802 Float_t covTerm[100][100][100];
803 for (Int_t r=0; r<yBins; r++)
804 for (Int_t u=0; u<xBins; u++)
805 for (Int_t s=0; s<yBins; s++)
808 covTerm[r][u][s] = 1.0 / sumHist->GetBinContent(u+1) * hResponse->GetBinContent(u+1, r+1)
809 * (1.0 - hResponse->GetBinContent(u+1, r+1));
811 covTerm[r][u][s] = - 1.0 / sumHist->GetBinContent(u+1) * hResponse->GetBinContent(u+1, r+1)
812 * hResponse->GetBinContent(u+1, s+1);
815 for (Int_t k=0; k<xBins; k++)
816 for (Int_t l=0; l<yBins; l++)
819 printf("In Cov2: %d %d\n", k, l);
820 for (Int_t i=0; i<yBins; i++)
821 for (Int_t j=0; j<yBins; j++)
823 //printf("In Cov2: %d %d %d %d\n", k, l, i, j);
824 // calculate Cov(Mki, Mlj) = sum{ru},{su} ...
826 for (Int_t r=0; r<yBins; r++)
827 for (Int_t u=0; u<xBins; u++)
828 for (Int_t s=0; s<yBins; s++)
830 if (hResponse->GetBinContent(u+1, r+1) == 0 || hResponse->GetBinContent(u+1, s+1) == 0
831 || hResponse->GetBinContent(u+1, i+1) == 0)
834 tmpCov += BayesCovarianceDerivate(matrixM, hResponse, fCurrentEfficiency, k, i, r, u)
835 * BayesCovarianceDerivate(matrixM, hResponse, fCurrentEfficiency, l, j, s, u)
839 cov2[k][l] += fCurrentESD->GetBinContent(i+1) * fCurrentESD->GetBinContent(j+1) * tmpCov;
843 printf("Cov2 finished\n");
845 for (Int_t i=1; i<=xBins; i++)
846 for (Int_t j=1; j<=yBins; j++)
847 cov->SetBinContent(i, j, cov1[i-1][j-1] + cov2[i-1][j-1]);
853 //____________________________________________________________________
854 Double_t AliUnfolding::RegularizationPol0(TVectorD& params)
856 // homogenity term for minuit fitting
857 // pure function of the parameters
858 // prefers constant function (pol0)
860 // Does not take into account efficiency
863 for (Int_t i=1+fgSkipBinsBegin; i<fgMaxParams; ++i)
865 Double_t right = params[i] / fgUnfoldedAxis->GetBinWidth(i+1);
866 Double_t left = params[i-1] / fgUnfoldedAxis->GetBinWidth(i);
870 Double_t diff = (right - left);
871 chi2 += diff * diff / left / ((fgUnfoldedAxis->GetBinWidth(i+1) + fgUnfoldedAxis->GetBinWidth(i)) / 2);
878 //____________________________________________________________________
879 Double_t AliUnfolding::RegularizationPol1(TVectorD& params)
881 // homogenity term for minuit fitting
882 // pure function of the parameters
883 // prefers linear function (pol1)
885 // Does not take into account efficiency
888 for (Int_t i=2+fgSkipBinsBegin; i<fgMaxParams; ++i)
890 if (params[i-1] == 0)
893 Double_t right = params[i] / fgUnfoldedAxis->GetBinWidth(i+1);
894 Double_t middle = params[i-1] / fgUnfoldedAxis->GetBinWidth(i);
895 Double_t left = params[i-2] / fgUnfoldedAxis->GetBinWidth(i-1);
897 Double_t der1 = (right - middle) / ((fgUnfoldedAxis->GetBinWidth(i+1) + fgUnfoldedAxis->GetBinWidth(i)) / 2);
898 Double_t der2 = (middle - left) / ((fgUnfoldedAxis->GetBinWidth(i) + fgUnfoldedAxis->GetBinWidth(i-1)) / 2);
900 //Double_t diff = (der1 - der2) / middle;
901 //chi2 += diff * diff;
902 chi2 += (der1 - der2) * (der1 - der2) / middle * fgUnfoldedAxis->GetBinWidth(i);
908 //____________________________________________________________________
909 Double_t AliUnfolding::RegularizationLog(TVectorD& params)
911 // homogenity term for minuit fitting
912 // pure function of the parameters
913 // prefers logarithmic function (log)
915 // Does not take into account efficiency
919 for (Int_t i=2+fgSkipBinsBegin; i<fgMaxParams; ++i)
921 if (params[i-1] == 0 || params[i] == 0 || params[i-2] == 0)
924 Double_t right = log(params[i] / fgUnfoldedAxis->GetBinWidth(i+1));
925 Double_t middle = log(params[i-1] / fgUnfoldedAxis->GetBinWidth(i));
926 Double_t left = log(params[i-2] / fgUnfoldedAxis->GetBinWidth(i-1));
928 Double_t der1 = (right - middle) / ((fgUnfoldedAxis->GetBinWidth(i+1) + fgUnfoldedAxis->GetBinWidth(i)) / 2);
929 Double_t der2 = (middle - left) / ((fgUnfoldedAxis->GetBinWidth(i) + fgUnfoldedAxis->GetBinWidth(i-1)) / 2);
931 //Double_t error = 1. / params[i] + 4. / params[i-1] + 1. / params[i-2];
933 //if (fgCallCount == 0)
934 // Printf("%d %f %f", i, (der1 - der2) * (der1 - der2), error);
935 chi2 += (der1 - der2) * (der1 - der2);// / error;
941 //____________________________________________________________________
942 Double_t AliUnfolding::RegularizationTotalCurvature(TVectorD& params)
944 // homogenity term for minuit fitting
945 // pure function of the parameters
946 // minimizes the total curvature (from Unfolding Methods In High-Energy Physics Experiments,
947 // V. Blobel (Hamburg U.) . DESY 84/118, Dec 1984. 40pp.
949 // Does not take into account efficiency
953 for (Int_t i=2+fgSkipBinsBegin; i<fgMaxParams; ++i)
955 Double_t right = params[i];
956 Double_t middle = params[i-1];
957 Double_t left = params[i-2];
959 Double_t der1 = (right - middle);
960 Double_t der2 = (middle - left);
962 Double_t diff = (der1 - der2);
970 //____________________________________________________________________
971 Double_t AliUnfolding::RegularizationEntropy(TVectorD& params)
973 // homogenity term for minuit fitting
974 // pure function of the parameters
975 // calculates entropy, from
976 // The method of reduced cross-entropy (M. Schmelling 1993)
978 // Does not take into account efficiency
980 Double_t paramSum = 0;
982 for (Int_t i=fgSkipBinsBegin; i<fgMaxParams; ++i)
983 paramSum += params[i];
986 for (Int_t i=fgSkipBinsBegin; i<fgMaxParams; ++i)
988 Double_t tmp = params[i] / paramSum;
989 //Double_t tmp = params[i];
990 if (tmp > 0 && (*fgEntropyAPriori)[i] > 0)
992 chi2 += tmp * TMath::Log(tmp / (*fgEntropyAPriori)[i]);
1001 //____________________________________________________________________
1002 Double_t AliUnfolding::RegularizationRatio(TVectorD& params)
1004 // homogenity term for minuit fitting
1005 // pure function of the parameters
1007 // Does not take into account efficiency
1011 for (Int_t i=5+fgSkipBinsBegin; i<fgMaxParams; ++i)
1013 if (params[i-1] == 0 || params[i] == 0)
1016 Double_t right = params[i] / fgUnfoldedAxis->GetBinWidth(i+1);
1017 Double_t middle = params[i-1] / fgUnfoldedAxis->GetBinWidth(i);
1018 Double_t left = params[i-2] / fgUnfoldedAxis->GetBinWidth(i-1);
1019 Double_t left2 = params[i-3] / fgUnfoldedAxis->GetBinWidth(i-2);
1020 Double_t left3 = params[i-4] / fgUnfoldedAxis->GetBinWidth(i-3);
1021 Double_t left4 = params[i-5] / fgUnfoldedAxis->GetBinWidth(i-4);
1023 //Double_t diff = left / middle - middle / right;
1024 //Double_t diff = 2 * left / middle - middle / right - left2 / left;
1025 Double_t diff = 4 * left2 / left - middle / right - left / middle - left3 / left2 - left4 / left3;
1027 chi2 += diff * diff;// / middle;
1033 //____________________________________________________________________
1034 Double_t AliUnfolding::RegularizationPowerLaw(TVectorD& params)
1036 // homogenity term for minuit fitting
1037 // pure function of the parameters
1038 // prefers power law with n = -5
1040 // Does not take into account efficiency
1044 Double_t right = 0.;
1045 Double_t middle = 0.;
1048 for (Int_t i=2+fgSkipBinsBegin; i<fgMaxParams; ++i)
1050 if (params[i] < 1e-8 || params[i-1] < 1e-8 || params[i-2] < 1e-8)
1053 if (fgUnfoldedAxis->GetBinWidth(i+1) < 1e-8 || fgUnfoldedAxis->GetBinWidth(i) < 1e-8 || fgUnfoldedAxis->GetBinWidth(i-1) < 1e-8)
1056 middle = TMath::Power(params[i-1] / fgUnfoldedAxis->GetBinWidth(i),fgPowern);
1059 right = TMath::Power(params[i] / fgUnfoldedAxis->GetBinWidth(i),fgPowern)/middle;
1061 left = TMath::Power(params[i-2] / fgUnfoldedAxis->GetBinWidth(i-1),fgPowern)/middle;
1065 Double_t der1 = (right - middle) / ((fgUnfoldedAxis->GetBinWidth(i+1) + fgUnfoldedAxis->GetBinWidth(i)) / 2);
1066 Double_t der2 = (middle - left) / ((fgUnfoldedAxis->GetBinWidth(i-1) + fgUnfoldedAxis->GetBinWidth(i-2)) / 2);
1068 chi2 += (der1 - der2) * (der1 - der2)/ ( fgUnfoldedAxis->GetBinWidth(i)/2. + fgUnfoldedAxis->GetBinWidth(i-1) + fgUnfoldedAxis->GetBinWidth(i-2)/2.)/( fgUnfoldedAxis->GetBinWidth(i)/2. + fgUnfoldedAxis->GetBinWidth(i-1) + fgUnfoldedAxis->GetBinWidth(i-2)/2.);// / error;
1069 // printf("i: %d chi2 = %f\n",i,chi2);
1077 //____________________________________________________________________
1078 Double_t AliUnfolding::RegularizationLogLog(TVectorD& params)
1080 // homogenity term for minuit fitting
1081 // pure function of the parameters
1082 // prefers a powerlaw (linear on a log-log scale)
1084 // The calculation takes into account the efficiencies
1088 for (Int_t i=2+fgSkipBinsBegin; i<fgMaxParams; ++i)
1090 if (params[i-1] == 0 || params[i] == 0 || params[i-2] == 0)
1092 if ((*fgEfficiency)(i-1) == 0 || (*fgEfficiency)(i) == 0 || (*fgEfficiency)(i-2) == 0)
1096 Double_t right = log(params[i] / (*fgEfficiency)(i) / fgUnfoldedAxis->GetBinWidth(i));
1097 Double_t middle = log(params[i-1] / (*fgEfficiency)(i-1) / fgUnfoldedAxis->GetBinWidth(i-1));
1098 Double_t left = log(params[i-2] / (*fgEfficiency)(i-2) / fgUnfoldedAxis->GetBinWidth(i-2));
1100 Double_t der1 = (right - middle) / ( log(fgUnfoldedAxis->GetBinCenter(i+1)) - log(fgUnfoldedAxis->GetBinCenter(i)) );
1101 Double_t der2 = (middle - left) /( log(fgUnfoldedAxis->GetBinCenter(i)) - log(fgUnfoldedAxis->GetBinCenter(i-1)) );
1103 double tmp = (log(fgUnfoldedAxis->GetBinCenter(i+1)) - log(fgUnfoldedAxis->GetBinCenter(i-1)))/2.;
1104 Double_t dder = (der1-der2) / tmp;
1106 chi2 += dder * dder;
1114 //____________________________________________________________________
1115 void AliUnfolding::Chi2Function(Int_t&, Double_t*, Double_t& chi2, Double_t *params, Int_t)
1118 // fit function for minuit
1119 // does: (m - Ad)W(m - Ad) where m = measured, A correlation matrix, d = guess, W = covariance matrix
1122 // TODO use static members for the variables here to speed up processing (no construction/deconstruction)
1125 TVectorD paramsVector(fgMaxParams);
1126 for (Int_t i=0; i<fgMaxParams; ++i)
1127 paramsVector[i] = params[i] * params[i];
1129 // calculate penalty factor
1130 Double_t penaltyVal = 0;
1132 switch (fgRegularizationType)
1135 case kPol0: penaltyVal = RegularizationPol0(paramsVector); break;
1136 case kPol1: penaltyVal = RegularizationPol1(paramsVector); break;
1137 case kCurvature: penaltyVal = RegularizationTotalCurvature(paramsVector); break;
1138 case kEntropy: penaltyVal = RegularizationEntropy(paramsVector); break;
1139 case kLog: penaltyVal = RegularizationLog(paramsVector); break;
1140 case kRatio: penaltyVal = RegularizationRatio(paramsVector); break;
1141 case kPowerLaw: penaltyVal = RegularizationPowerLaw(paramsVector); break;
1142 case kLogLog: penaltyVal = RegularizationLogLog(paramsVector); break;
1145 penaltyVal *= fgRegularizationWeight; //beta*PU
1148 TVectorD measGuessVector(fgMaxInput);
1149 measGuessVector = (*fgCorrelationMatrix) * paramsVector;
1152 measGuessVector -= (*fgCurrentESDVector);
1155 // new error calcuation using error on the guess
1158 TVectorD errorGuessVector(fgMaxInput);
1159 //errorGuessVector = (*fgCorrelationMatrixSquared) * paramsVector;
1160 errorGuessVector = (*fgCorrelationMatrix) * paramsVector;
1162 Double_t chi2FromFit = 0;
1163 for (Int_t i=0; i<fgMaxInput; ++i)
1166 if (errorGuessVector(i) > 0)
1167 error = errorGuessVector(i);
1168 chi2FromFit += measGuessVector(i) * measGuessVector(i) / error;
1172 // old error calcuation using the error on the measured
1173 TVectorD copy(measGuessVector);
1176 // this step can be optimized because currently only the diagonal elements of fgCorrelationCovarianceMatrix are used
1177 // normal way is like this:
1178 // measGuessVector *= (*fgCorrelationCovarianceMatrix);
1179 // optimized way like this:
1180 for (Int_t i=0; i<fgMaxInput; ++i)
1181 measGuessVector[i] *= (*fgCorrelationCovarianceMatrix)(i, i);
1184 if (fgSkipBin0InChi2)
1185 measGuessVector[0] = 0;
1187 // (Ad - m) W (Ad - m)
1188 // the factor 1e6 prevents that a very small number (measGuessVector[i]) is multiplied with a very
1189 // big number ((*fgCorrelationCovarianceMatrix)(i, i)) (see UnfoldWithMinuit)
1190 Double_t chi2FromFit = measGuessVector * copy * 1e6;
1193 Double_t notFoundEventsConstraint = 0;
1194 Double_t currentNotFoundEvents = 0;
1195 Double_t errorNotFoundEvents = 0;
1197 if (fgNotFoundEvents > 0)
1199 for (Int_t i=0; i<fgMaxParams; ++i)
1201 Double_t eff = (1.0 / (*fgEfficiency)(i) - 1);
1203 eff = (1.0 / params[fgMaxParams] - 1);
1204 currentNotFoundEvents += eff * paramsVector(i);
1205 errorNotFoundEvents += eff * eff * paramsVector(i); // error due to guess (paramsVector)
1207 errorNotFoundEvents += (eff * 0.03) * (eff * 0.03) * paramsVector(i) * paramsVector(i); // error on eff
1208 // if ((fgCallCount % 10000) == 0)
1209 //Printf("%d %f %f %f", i, (*fgEfficiency)(i), paramsVector(i), currentNotFoundEvents);
1211 errorNotFoundEvents += fgNotFoundEvents;
1212 // TODO add error on background, background estimate
1214 notFoundEventsConstraint = (currentNotFoundEvents - fgNotFoundEvents) * (currentNotFoundEvents - fgNotFoundEvents) / errorNotFoundEvents;
1219 Float_t currentMult = 0;
1220 // try to match dn/deta
1221 for (Int_t i=0; i<fgMaxParams; ++i)
1223 avg += paramsVector(i) * currentMult;
1224 sum += paramsVector(i);
1225 currentMult += fgUnfoldedAxis->GetBinWidth(i);
1228 Float_t chi2Avg = 0; //(avg - 3.73) * (avg - 3.73) * 100;
1230 chi2 = chi2FromFit + penaltyVal + notFoundEventsConstraint + chi2Avg;
1232 if ((fgCallCount++ % 1000) == 0)
1235 Printf("AliUnfolding::Chi2Function: Iteration %d (ev %d %d +- %f) (%f) (%f): %f %f %f %f --> %f", fgCallCount-1, (Int_t) fgNotFoundEvents, (Int_t) currentNotFoundEvents, TMath::Sqrt(errorNotFoundEvents), params[fgMaxParams-1], avg, chi2FromFit, penaltyVal, notFoundEventsConstraint, chi2Avg, chi2);
1237 //for (Int_t i=0; i<fgMaxInput; ++i)
1238 // Printf("%d: %f", i, measGuessVector(i) * copy(i) * 1e6);
1241 fChi2FromFit = chi2FromFit;
1242 fPenaltyVal = penaltyVal;
1245 //____________________________________________________________________
1246 void AliUnfolding::MakePads() {
1247 TPad *presult = new TPad("presult","result",0,0.4,1,1);
1248 presult->SetNumber(1);
1251 TPad *pres = new TPad("pres","residuals",0,0.2,1,0.4);
1254 TPad *ppen = new TPad("ppen","penalty",0,0.0,1,0.2);
1259 //____________________________________________________________________
1260 void AliUnfolding::DrawResults(TH2* correlation, TH1* efficiency, TH1* measured, TH1* initialConditions, TCanvas *canv, Int_t reuseHists,TH1 *unfolded)
1262 // Draw histograms of
1263 // - Result folded with response
1264 // - Penalty factors
1265 // - Chisquare contributions
1266 // (Useful for debugging/sanity checks and the interactive unfolder)
1268 // If a canvas pointer is given (canv != 0), it will be used for all
1269 // plots; 3 pads are made if needed.
1272 Int_t blankCanvas = 0;
1273 TVirtualPad *presult = 0;
1274 TVirtualPad *pres = 0;
1275 TVirtualPad *ppen = 0;
1279 presult = canv->GetPad(1);
1280 pres = canv->GetPad(2);
1281 ppen = canv->GetPad(3);
1282 if (presult == 0 || pres == 0 || ppen == 0) {
1286 presult = canv->GetPad(1);
1287 pres = canv->GetPad(2);
1288 ppen = canv->GetPad(3);
1292 presult = new TCanvas;
1298 if (fgMaxInput == -1)
1300 Printf("AliUnfolding::Unfold: WARNING. Number of measured bins not set with SetNbins. Using number of bins in measured distribution");
1301 fgMaxInput = measured->GetNbinsX();
1303 if (fgMaxParams == -1)
1305 Printf("AliUnfolding::Unfold: WARNING. Number of unfolded bins not set with SetNbins. Using number of bins in measured distribution");
1306 fgMaxParams = initialConditions->GetNbinsX();
1309 if (fgOverflowBinLimit > 0)
1310 CreateOverflowBin(correlation, measured);
1312 // Uses Minuit methods
1314 SetStaticVariables(correlation, measured, efficiency);
1316 Double_t* params = new Double_t[fgMaxParams+1];
1317 for (Int_t i=0; i<fgMaxParams; ++i)
1319 params[i] = initialConditions->GetBinContent(i+1) * efficiency->GetBinContent(i+1);
1321 Bool_t fix = kFALSE;
1325 params[i] = -params[i];
1327 params[i]=TMath::Sqrt(params[i]);
1329 //cout << "params[" << i << "] " << params[i] << endl;
1336 //fgPrintChi2Details = kTRUE;
1337 fgCallCount = 0; // To make sure that Chi2Function prints the components
1338 Chi2Function(dummy, 0, chi2, params, 0);
1341 TH1 *meas2 = (TH1*)measured->Clone("meas2");
1342 meas2->SetTitle("meas2");
1343 meas2->SetName("meas2");
1344 meas2->SetLineColor(1);
1345 meas2->SetLineWidth(2);
1346 meas2->SetMarkerColor(meas2->GetLineColor());
1347 meas2->SetMarkerStyle(20);
1348 Float_t scale = unfolded->GetXaxis()->GetBinWidth(1)/meas2->GetXaxis()->GetBinWidth(1);
1349 meas2->Scale(scale);
1353 meas2->DrawCopy("same");
1354 //meas2->GetXaxis()->SetLimits(0,fgMaxInput);
1355 meas2->SetBit(kCannotPick);
1356 DrawGuess(params, presult, pres, ppen, reuseHists,unfolded);
1359 //____________________________________________________________________
1360 void AliUnfolding::RedrawInteractive() {
1362 // Helper function for interactive unfolding
1364 DrawResults(fghCorrelation,fghEfficiency,fghMeasured,fghUnfolded,fgCanvas,1,fghUnfolded);
1366 //____________________________________________________________________
1367 void AliUnfolding::InteractiveUnfold(TH2* correlation, TH1* efficiency, TH1* measured, TH1* initialConditions)
1370 // Function to do interactive unfolding
1371 // A canvas is drawn with the unfolding result
1372 // Change the histogram with your mouse and all histograms
1373 // will be updated automatically
1375 fgCanvas = new TCanvas("UnfoldingCanvas","Interactive unfolding",500,800);
1381 delete fghUnfolded; fghUnfolded = 0;
1384 gROOT->SetEditHistograms(kTRUE);
1386 fghUnfolded = new TH1F("AliUnfoldingfghUnfolded","Unfolded result (Interactive unfolder",efficiency->GetNbinsX(),efficiency->GetXaxis()->GetXmin(),efficiency->GetXaxis()->GetXmax());
1388 fghCorrelation = correlation;
1389 fghEfficiency = efficiency;
1390 fghMeasured = measured;
1392 if(fgMinuitMaxIterations>0)
1393 UnfoldWithMinuit(correlation,efficiency,measured,initialConditions,fghUnfolded,kFALSE);
1395 fghUnfolded = initialConditions;
1397 fghUnfolded->SetLineColor(2);
1398 fghUnfolded->SetMarkerColor(2);
1399 fghUnfolded->SetLineWidth(2);
1403 fghUnfolded->Draw();
1404 DrawResults(correlation,efficiency,measured,fghUnfolded,fgCanvas,kFALSE,fghUnfolded);
1406 TExec *execRedraw = new TExec("redraw","AliUnfolding::RedrawInteractive()");
1407 fghUnfolded->GetListOfFunctions()->Add(execRedraw);
1409 //____________________________________________________________________
1410 void AliUnfolding::DrawGuess(Double_t *params, TVirtualPad *pfolded, TVirtualPad *pres, TVirtualPad *ppen, Int_t reuseHists,TH1* unfolded)
1413 // draws residuals of solution suggested by params and effect of regularization
1417 pfolded = new TCanvas;
1424 TVectorD paramsVector(fgMaxParams);
1425 for (Int_t i=0; i<fgMaxParams; ++i)
1426 paramsVector[i] = params[i] * params[i];
1429 TVectorD measGuessVector(fgMaxInput);
1430 measGuessVector = (*fgCorrelationMatrix) * paramsVector;
1434 folded = dynamic_cast<TH1*>(gROOT->FindObject("__hfolded"));
1435 if (!reuseHists || folded == 0) {
1436 if (fgMeasuredAxis->GetXbins()->GetArray()) // variable bins
1437 folded = new TH1F("__hfolded","Folded histo from AliUnfolding",fgMeasuredAxis->GetNbins(),fgMeasuredAxis->GetXbins()->GetArray());
1439 folded = new TH1F("__hfolded","Folded histo from AliUnfolding",fgMeasuredAxis->GetNbins(),fgMeasuredAxis->GetXmin(),fgMeasuredAxis->GetXmax());
1442 folded->SetBit(kCannotPick);
1443 folded->SetLineColor(4);
1444 folded->SetLineWidth(2);
1446 for (Int_t ibin =0; ibin < fgMaxInput; ibin++)
1447 folded->SetBinContent(ibin+1, measGuessVector[ibin]);
1449 Float_t scale = unfolded->GetXaxis()->GetBinWidth(1)/folded->GetXaxis()->GetBinWidth(1);
1450 folded->Scale(scale);
1454 folded->Draw("same");
1457 measGuessVector -= (*fgCurrentESDVector);
1459 TVectorD copy(measGuessVector);
1462 // this step can be optimized because currently only the diagonal elements of fgCorrelationCovarianceMatrix are used
1463 // normal way is like this:
1464 // measGuessVector *= (*fgCorrelationCovarianceMatrix);
1465 // optimized way like this:
1466 for (Int_t i=0; i<fgMaxInput; ++i)
1467 measGuessVector[i] *= (*fgCorrelationCovarianceMatrix)(i, i);
1469 // (Ad - m) W (Ad - m)
1470 // the factor 1e6 prevents that a very small number (measGuessVector[i]) is multiplied with a very
1471 // big number ((*fgCorrelationCovarianceMatrix)(i, i)) (see ApplyMinuitFit)
1472 //Double_t chi2FromFit = measGuessVector * copy * 1e6;
1475 // Double_t pTarray[fgMaxParams+1];
1476 // for(int i=0; i<fgMaxParams; i++) {
1477 // pTarray[i] = fgUnfoldedAxis->GetBinCenter(i)-0.5*fgUnfoldedAxis->GetBinWidth(i);
1479 // pTarray[fgMaxParams] = fgUnfoldedAxis->GetBinCenter(fgMaxParams-1)+0.5*fgUnfoldedAxis->GetBinWidth(fgMaxParams-1);
1480 // TH1* residuals = new TH1F("residuals", "residuals", fgMaxParams,pTarray);
1481 // TH1* residuals = new TH1F("residuals", "residuals", fgMaxInput, -0.5, fgMaxInput - 0.5);
1482 // for (Int_t i=0; i<fgMaxInput; ++i)
1483 // residuals->SetBinContent(i+1, measGuessVector(i) * copy(i) * 1e6);7
1484 TH1* residuals = GetResidualsPlot(params);
1485 residuals->GetXaxis()->SetTitleSize(0.06);
1486 residuals->GetXaxis()->SetTitleOffset(0.7);
1487 residuals->GetXaxis()->SetLabelSize(0.07);
1488 residuals->GetYaxis()->SetTitleSize(0.08);
1489 residuals->GetYaxis()->SetTitleOffset(0.5);
1490 residuals->GetYaxis()->SetLabelSize(0.06);
1491 pres->cd(); residuals->DrawCopy(); gPad->SetLogy();
1495 TH1* penalty = GetPenaltyPlot(params);
1496 penalty->GetXaxis()->SetTitleSize(0.06);
1497 penalty->GetXaxis()->SetTitleOffset(0.7);
1498 penalty->GetXaxis()->SetLabelSize(0.07);
1499 penalty->GetYaxis()->SetTitleSize(0.08);
1500 penalty->GetYaxis()->SetTitleOffset(0.5);
1501 penalty->GetYaxis()->SetLabelSize(0.06);
1502 ppen->cd(); penalty->DrawCopy(); gPad->SetLogy();
1505 //____________________________________________________________________
1506 TH1* AliUnfolding::GetResidualsPlot(TH1* corrected)
1509 // MvL: THIS MUST BE INCORRECT.
1510 // Need heff to calculate params from TH1 'corrected'
1514 // fill residuals histogram of solution suggested by params and effect of regularization
1517 Double_t* params = new Double_t[fgMaxParams];
1518 for (Int_t i=0; i<fgMaxParams; i++)
1521 for (Int_t i=0; i<TMath::Min(fgMaxParams, corrected->GetNbinsX()); i++)
1522 params[i] = TMath::Sqrt(TMath::Abs(corrected->GetBinContent(i+1)*(*fgEfficiency)(i)));
1524 TH1 * plot = GetResidualsPlot(params);
1529 //____________________________________________________________________
1530 TH1* AliUnfolding::GetResidualsPlot(Double_t* params)
1533 // fill residuals histogram of solution suggested by params and effect of regularization
1537 TVectorD paramsVector(fgMaxParams);
1538 for (Int_t i=0; i<fgMaxParams; ++i)
1539 paramsVector[i] = params[i] * params[i];
1542 TVectorD measGuessVector(fgMaxInput);
1543 measGuessVector = (*fgCorrelationMatrix) * paramsVector;
1546 measGuessVector -= (*fgCurrentESDVector);
1548 TVectorD copy(measGuessVector);
1551 // this step can be optimized because currently only the diagonal elements of fgCorrelationCovarianceMatrix are used
1552 // normal way is like this:
1553 // measGuessVector *= (*fgCorrelationCovarianceMatrix);
1554 // optimized way like this:
1555 for (Int_t i=0; i<fgMaxInput; ++i)
1556 measGuessVector[i] *= (*fgCorrelationCovarianceMatrix)(i, i);
1558 // (Ad - m) W (Ad - m)
1559 // the factor 1e6 prevents that a very small number (measGuessVector[i]) is multiplied with a very
1560 // big number ((*fgCorrelationCovarianceMatrix)(i, i)) (see ApplyMinuitFit)
1561 //Double_t chi2FromFit = measGuessVector * copy * 1e6;
1565 if (fgMeasuredAxis->GetXbins()->GetArray()) // variable bins
1566 residuals = new TH1F("residuals", "residuals;unfolded pos;residual",fgMeasuredAxis->GetNbins(),fgMeasuredAxis->GetXbins()->GetArray());
1568 residuals = new TH1F("residuals", "residuals;unfolded pos;residual",fgMeasuredAxis->GetNbins(),fgMeasuredAxis->GetXmin(), fgMeasuredAxis->GetXmax());
1569 // TH1* residuals = new TH1F("residuals", "residuals", fgMaxInput, -0.5, fgMaxInput - 0.5);
1571 Double_t sumResiduals = 0.;
1572 for (Int_t i=0; i<fgMaxInput; ++i) {
1573 residuals->SetBinContent(i+1, measGuessVector(i) * copy(i) * 1e6);
1574 sumResiduals += measGuessVector(i) * copy(i) * 1e6;
1576 fAvgResidual = sumResiduals/(double)fgMaxInput;
1581 //____________________________________________________________________
1582 TH1* AliUnfolding::GetPenaltyPlot(TH1* corrected)
1584 // draws the penalty factors as function of multiplicity of the current selected regularization
1586 Double_t* params = new Double_t[fgMaxParams];
1587 for (Int_t i=0; i<fgMaxParams; i++)
1590 for (Int_t i=0; i<TMath::Min(fgMaxParams, corrected->GetNbinsX()); i++)
1591 params[i] = (*fgEfficiency)(i)*corrected->GetBinContent(i+1);
1593 TH1* penalty = GetPenaltyPlot(params);
1600 //____________________________________________________________________
1601 TH1* AliUnfolding::GetPenaltyPlot(Double_t* params)
1603 // draws the penalty factors as function of multiplicity of the current selected regularization
1605 //TH1* penalty = new TH1F("penalty", ";unfolded multiplicity;penalty factor", fgMaxParams, -0.5, fgMaxParams - 0.5);
1606 // TH1* penalty = new TH1F("penalty", ";unfolded pos;penalty factor", fgMaxParams, fgUnfoldedAxis->GetBinCenter(0)-0.5*fgUnfoldedAxis->GetBinWidth(0),fgUnfoldedAxis->GetBinCenter(fgMaxParams)+0.5*fgUnfoldedAxis->GetBinWidth(fgMaxParams) );
1609 if (fgUnfoldedAxis->GetXbins()->GetArray())
1610 penalty = new TH1F("penalty", ";unfolded pos;penalty factor", fgUnfoldedAxis->GetNbins(),fgUnfoldedAxis->GetXbins()->GetArray());
1612 penalty = new TH1F("penalty", ";unfolded pos;penalty factor", fgUnfoldedAxis->GetNbins(),fgUnfoldedAxis->GetXmin(),fgUnfoldedAxis->GetXmax());
1614 for (Int_t i=1+fgSkipBinsBegin; i<fgMaxParams; ++i)
1617 if (fgRegularizationType == kPol0)
1619 Double_t right = params[i] / fgUnfoldedAxis->GetBinWidth(i+1);
1620 Double_t left = params[i-1] / fgUnfoldedAxis->GetBinWidth(i);
1624 Double_t diffTmp = (right - left);
1625 diff = diffTmp * diffTmp / left / ((fgUnfoldedAxis->GetBinWidth(i+1) + fgUnfoldedAxis->GetBinWidth(i)) / 2) / 100;
1628 if (fgRegularizationType == kPol1 && i > 1+fgSkipBinsBegin)
1630 if (params[i-1] == 0)
1633 Double_t right = params[i] / fgUnfoldedAxis->GetBinWidth(i+1);
1634 Double_t middle = params[i-1] / fgUnfoldedAxis->GetBinWidth(i);
1635 Double_t left = params[i-2] / fgUnfoldedAxis->GetBinWidth(i-1);
1637 Double_t der1 = (right - middle) / ((fgUnfoldedAxis->GetBinWidth(i+1) + fgUnfoldedAxis->GetBinWidth(i)) / 2);
1638 Double_t der2 = (middle - left) / ((fgUnfoldedAxis->GetBinWidth(i) + fgUnfoldedAxis->GetBinWidth(i-1)) / 2);
1640 diff = (der1 - der2) * (der1 - der2) / middle;
1643 if (fgRegularizationType == kLog && i > 1+fgSkipBinsBegin)
1645 if (params[i-1] == 0)
1648 Double_t right = log(params[i]);
1649 Double_t middle = log(params[i-1]);
1650 Double_t left = log(params[i-2]);
1652 Double_t der1 = (right - middle);
1653 Double_t der2 = (middle - left);
1655 //Double_t error = 1. / params[i] + 4. / params[i-1] + 1. / params[i-2];
1656 //Printf("%d %f %f", i, (der1 - der2) * (der1 - der2), error);
1658 diff = (der1 - der2) * (der1 - der2);// / error;
1660 if (fgRegularizationType == kCurvature && i > 1+fgSkipBinsBegin)
1662 Double_t right = params[i]; // params are sqrt
1663 Double_t middle = params[i-1];
1664 Double_t left = params[i-2];
1666 Double_t der1 = (right - middle)/0.5/(fgUnfoldedAxis->GetBinWidth(i-1) + fgUnfoldedAxis->GetBinWidth(i));
1667 Double_t der2 = (middle - left)/0.5/(fgUnfoldedAxis->GetBinWidth(i) + fgUnfoldedAxis->GetBinWidth(i+1));
1669 diff = (der1 - der2)/(fgUnfoldedAxis->GetBinWidth(i-1) + fgUnfoldedAxis->GetBinWidth(i) + fgUnfoldedAxis->GetBinWidth(i-1))*3.0;
1670 diff = 1e4*diff*diff;
1672 if (fgRegularizationType == kPowerLaw && i > 1+fgSkipBinsBegin)
1675 if (params[i] < 1e-8 || params[i-1] < 1e-8 || params[i-2] < 1e-8)
1678 if (fgUnfoldedAxis->GetBinWidth(i+1) < 1e-8 || fgUnfoldedAxis->GetBinWidth(i) < 1e-8 || fgUnfoldedAxis->GetBinWidth(i) < 1e-8)
1681 double middle = TMath::Power(params[i-1] / fgUnfoldedAxis->GetBinWidth(i),fgPowern);
1684 double right = TMath::Power(params[i] / fgUnfoldedAxis->GetBinWidth(i+1),fgPowern)/middle;
1686 double left = TMath::Power(params[i-2] / fgUnfoldedAxis->GetBinWidth(i-1),fgPowern)/middle;
1690 Double_t der1 = (right - middle) / ((fgUnfoldedAxis->GetBinWidth(i+1) + fgUnfoldedAxis->GetBinWidth(i)) / 2);
1691 Double_t der2 = (middle - left) / ((fgUnfoldedAxis->GetBinWidth(i) + fgUnfoldedAxis->GetBinWidth(i-1)) / 2);
1693 diff = (der1 - der2) * (der1 - der2);// / error;
1697 if (fgRegularizationType == kLogLog && i > 1+fgSkipBinsBegin)
1700 if (params[i] < 1e-8 || params[i-1] < 1e-8 || params[i-2] < 1e-8)
1703 Double_t right = log(params[i] / (*fgEfficiency)(i) / fgUnfoldedAxis->GetBinWidth(i+1));
1704 Double_t middle = log(params[i-1] / (*fgEfficiency)(i-1) / fgUnfoldedAxis->GetBinWidth(i));
1705 Double_t left = log(params[i-2] / (*fgEfficiency)(i-2) / fgUnfoldedAxis->GetBinWidth(i-1));
1707 Double_t der1 = (right - middle) / ( log(fgUnfoldedAxis->GetBinCenter(i+1)) - log(fgUnfoldedAxis->GetBinCenter(i)) );
1708 Double_t der2 = (middle - left) /( log(fgUnfoldedAxis->GetBinCenter(i)) - log(fgUnfoldedAxis->GetBinCenter(i-1)) );
1710 double tmp = (log(fgUnfoldedAxis->GetBinCenter(i+1)) - log(fgUnfoldedAxis->GetBinCenter(i-1)))/2.;
1711 Double_t dder = (der1-der2) / tmp;
1716 penalty->SetBinContent(i, diff*fgRegularizationWeight);
1718 //Printf("%d %f %f %f %f", i-1, left, middle, right, diff);
1724 //____________________________________________________________________
1725 void AliUnfolding::TF1Function(Int_t& unused1, Double_t* unused2, Double_t& chi2, Double_t *params, Int_t unused3)
1728 // fit function for minuit
1729 // uses the TF1 stored in fgFitFunction
1732 for (Int_t i=0; i<fgFitFunction->GetNpar(); i++)
1733 fgFitFunction->SetParameter(i, params[i]);
1735 Double_t* params2 = new Double_t[fgMaxParams];
1737 for (Int_t i=0; i<fgMaxParams; ++i)
1738 params2[i] = fgFitFunction->Eval(i);
1740 Chi2Function(unused1, unused2, chi2, params2, unused3);
1748 //____________________________________________________________________
1749 Int_t AliUnfolding::UnfoldWithFunction(TH2* correlation, TH1* efficiency, TH1* measured, TH1* /* initialConditions */, TH1* aResult)
1752 // correct spectrum using minuit chi2 method applying a functional fit
1757 Printf("AliUnfolding::UnfoldWithFunction: ERROR fit function not set. Exiting.");
1761 SetChi2Regularization(kNone, 0);
1763 SetStaticVariables(correlation, measured, efficiency);
1765 // Initialize TMinuit via generic fitter interface
1766 TVirtualFitter *minuit = TVirtualFitter::Fitter(0, fgFitFunction->GetNpar());
1768 minuit->SetFCN(TF1Function);
1769 for (Int_t i=0; i<fgFitFunction->GetNpar(); i++)
1771 Double_t lower, upper;
1772 fgFitFunction->GetParLimits(i, lower, upper);
1773 minuit->SetParameter(i, Form("param%d",i), fgFitFunction->GetParameter(i), fgMinuitStepSize, lower, upper);
1776 Double_t arglist[100];
1778 minuit->ExecuteCommand("SET PRINT", arglist, 1);
1779 minuit->ExecuteCommand("SCAN", arglist, 0);
1780 minuit->ExecuteCommand("MIGRAD", arglist, 0);
1781 //minuit->ExecuteCommand("MINOS", arglist, 0);
1783 for (Int_t i=0; i<fgFitFunction->GetNpar(); i++)
1784 fgFitFunction->SetParameter(i, minuit->GetParameter(i));
1786 for (Int_t i=0; i<fgMaxParams; ++i)
1788 Double_t value = fgFitFunction->Eval(i);
1790 Printf("%d : %f", i, value);
1794 if (efficiency->GetBinContent(i+1) > 0)
1796 value /= efficiency->GetBinContent(i+1);
1801 aResult->SetBinContent(i+1, value);
1802 aResult->SetBinError(i+1, 0);
1808 //____________________________________________________________________
1809 void AliUnfolding::CreateOverflowBin(TH2* correlation, TH1* measured)
1811 // Finds the first bin where the content is below fgStatLimit and combines all values for this bin and larger bins
1812 // The same limit is applied to the correlation
1815 for (Int_t i=1; i<=measured->GetNbinsX(); ++i)
1817 if (measured->GetBinContent(i) <= fgOverflowBinLimit)
1826 Printf("AliUnfolding::CreateOverflowBin: WARNING: First bin is already below limit of %f", fgOverflowBinLimit);
1830 Printf("AliUnfolding::CreateOverflowBin: Bin limit in measured spectrum determined to be %d", lastBin);
1832 TCanvas* canvas = 0;
1836 canvas = new TCanvas("StatSolution", "StatSolution", 1000, 800);
1837 canvas->Divide(2, 2);
1840 measured->SetStats(kFALSE);
1841 measured->DrawCopy();
1845 correlation->SetStats(kFALSE);
1846 correlation->DrawCopy("COLZ");
1849 measured->SetBinContent(lastBin, measured->Integral(lastBin, measured->GetNbinsX()));
1850 for (Int_t i=lastBin+1; i<=measured->GetNbinsX(); ++i)
1852 measured->SetBinContent(i, 0);
1853 measured->SetBinError(i, 0);
1855 // the error is set to sqrt(N), better solution possible?, sum of relative errors of all contributions???
1856 measured->SetBinError(lastBin, TMath::Sqrt(measured->GetBinContent(lastBin)));
1858 Printf("AliUnfolding::CreateOverflowBin: This bin has now %f +- %f entries", measured->GetBinContent(lastBin), measured->GetBinError(lastBin));
1860 for (Int_t i=1; i<=correlation->GetNbinsX(); ++i)
1862 correlation->SetBinContent(i, lastBin, correlation->Integral(i, i, lastBin, correlation->GetNbinsY()));
1863 // the error is set to sqrt(N), better solution possible?, sum of relative errors of all contributions???
1864 correlation->SetBinError(i, lastBin, TMath::Sqrt(correlation->GetBinContent(i, lastBin)));
1866 for (Int_t j=lastBin+1; j<=correlation->GetNbinsY(); ++j)
1868 correlation->SetBinContent(i, j, 0);
1869 correlation->SetBinError(i, j, 0);
1873 Printf("AliUnfolding::CreateOverflowBin: Adjusted correlation matrix!");
1878 measured->DrawCopy();
1882 correlation->DrawCopy("COLZ");
1886 Int_t AliUnfolding::UnfoldGetBias(TH2* correlation, TH1* efficiency, TH1* measured, TH1* initialConditions, TH1* result)
1888 // unfolds and assigns bias as errors with Eq. 19 of Cowan, "a survey of unfolding methods for particle physics"
1889 // b_i = sum_j dmu_i/dn_j (nu_j - n_j) with nu_j as folded guess, n_j as data
1890 // dmu_i/dn_j is found numerically by changing the bin content and re-unfolding
1892 // return code: 0 (success) -1 (error: from Unfold(...) )
1894 if (Unfold(correlation, efficiency, measured, initialConditions, result) != 0)
1897 TMatrixD matrix(fgMaxInput, fgMaxParams);
1900 for (Int_t loop=0; loop<4; loop++)
1901 newResult[loop] = (TH1*) result->Clone(Form("newresult_%d", loop));
1903 // change bin-by-bin and built matrix of effects
1904 for (Int_t m=0; m<fgMaxInput; m++)
1906 if (measured->GetBinContent(m+1) < 1)
1909 for (Int_t loop=0; loop<4; loop++)
1911 //Printf("%d %d", i, loop);
1915 case 0: factor = 0.5; break;
1916 case 1: factor = -0.5; break;
1917 case 2: factor = 1; break;
1918 case 3: factor = -1; break;
1922 TH1* measuredClone = (TH1*) measured->Clone("measuredClone");
1924 measuredClone->SetBinContent(m+1, measured->GetBinContent(m+1) + factor * TMath::Sqrt(measured->GetBinContent(m+1)));
1925 //new TCanvas; measuredClone->Draw("COLZ");
1927 newResult[loop]->Reset();
1928 Unfold(correlation, efficiency, measuredClone, measuredClone, newResult[loop]);
1929 // WARNING if we leave here, then nothing is calculated
1932 delete measuredClone;
1935 for (Int_t t=0; t<fgMaxParams; t++)
1938 //matrix(i, j) = (result->GetBinContent(j+1) - newResult->GetBinContent(j+1)) / TMath::Sqrt(changedHist->GetBinContent(1, i+1));
1940 // four values from the derivate (procedure taken from ROOT -- suggestion by Ruben)
1941 // = 1/2D * [ 8 (f(D/2) - f(-D/2)) - (f(D)-f(-D)) ]/3
1945 measured->SetBinContent(1, m+1, 100);
1946 newResult[0]->SetBinContent(t+1, 5 * 0.5 + 10);
1947 newResult[1]->SetBinContent(t+1, 5 * -0.5 + 10);
1948 newResult[2]->SetBinContent(t+1, 5 * 1 + 10);
1949 newResult[3]->SetBinContent(t+1, 5 * -1 + 10);
1952 matrix(m, t) = 0.5 / TMath::Sqrt(measured->GetBinContent(m+1)) *
1953 ( 8. * (newResult[0]->GetBinContent(t+1) - newResult[1]->GetBinContent(t+1)) -
1954 (newResult[2]->GetBinContent(t+1) - newResult[3]->GetBinContent(t+1))
1959 for (Int_t loop=0; loop<4; loop++)
1960 delete newResult[loop];
1962 // ...calculate folded guess
1963 TH1* convoluted = (TH1*) measured->Clone("convoluted");
1964 convoluted->Reset();
1965 for (Int_t m=0; m<fgMaxInput; m++)
1968 for (Int_t t = 0; t<fgMaxParams; t++)
1970 Float_t tmp = correlation->GetBinContent(t+1, m+1) * result->GetBinContent(t+1);
1972 tmp *= efficiency->GetBinContent(t+1);
1975 convoluted->SetBinContent(m+1, value);
1979 convoluted->Scale(measured->Integral() / convoluted->Integral());
1981 //new TCanvas; convoluted->Draw(); measured->Draw("SAME"); measured->SetLineColor(2);
1985 convoluted->Add(measured, -1);
1988 for (Int_t t = 0; t<fgMaxParams; t++)
1991 for (Int_t m=0; m<fgMaxInput; m++)
1992 error += matrix(m, t) * convoluted->GetBinContent(m+1);
1993 result->SetBinError(t+1, error);
1996 //new TCanvas; result->Draw(); gPad->SetLogy();