Adding flexibility to submission macros
[u/mrichter/AliRoot.git] / PWG0 / AliUnfolding.h
1 /* $Id$ */
2
3 #ifndef ALIUNFOLDING_H
4 #define ALIUNFOLDING_H
5
6 //
7 // class that implements several unfolding methods
8 // I.e. chi2 minimization and bayesian unfolding
9 // The whole class is static and not thread-safe (due to the fact that MINUIT unfolding is not thread-safe)
10 //
11
12 // TMatrixD, TVectorD defined here, because it does not seem possible to predeclare these (or i do not know how)
13 // -->
14 // $ROOTSYS/include/TVectorDfwd.h:21: conflicting types for `typedef struct TVectorT<Double_t> TVectorD'
15 // PWG0/AliUnfolding.h:21: previous declaration as `struct TVectorD'
16
17 #include "TObject.h"
18 #include <TMatrixD.h>
19 #include <TVectorD.h>
20
21 class TH1;
22 class TH2;
23 class TF1;
24
25 class AliUnfolding : public TObject
26 {
27   public:
28     enum RegularizationType { kNone = 0, kPol0, kPol1, kLog, kEntropy, kCurvature, kRatio };
29     enum MethodType { kInvalid = -1, kChi2Minimization = 0, kBayesian = 1, kFunction = 2};
30
31     virtual ~AliUnfolding() {};
32
33     static void SetUnfoldingMethod(MethodType methodType);
34     static void SetCreateOverflowBin(Float_t overflowBinLimit);
35     static void SetSkipBinsBegin(Int_t nBins);
36     static void SetNbins(Int_t nMeasured, Int_t nUnfolded);
37     static void SetChi2Regularization(RegularizationType type, Float_t weight);
38     static void SetMinuitStepSize(Float_t stepSize) { fgMinuitStepSize = stepSize; }
39     static void SetMinimumInitialValue(Bool_t flag, Float_t value = -1) { fgMinimumInitialValue = flag; fgMinimumInitialValueFix = value; }
40     static void SetNormalizeInput(Bool_t flag) { fgNormalizeInput = flag; }
41     static void SetNotFoundEvents(Float_t notFoundEvents) { fgNotFoundEvents = notFoundEvents; }
42     static void SetSkip0BinInChi2(Bool_t flag) { fgSkipBin0InChi2 = flag; }
43     static void SetBayesianParameters(Float_t smoothing, Int_t nIterations);
44     static void SetFunction(TF1* function);
45     static void SetDebug(Bool_t flag) { fgDebug = flag; }
46
47     static Int_t Unfold(TH2* correlation, TH1* efficiency, TH1* measured, TH1* initialConditions, TH1* result, Bool_t check = kFALSE);
48     static Int_t UnfoldGetBias(TH2* correlation, TH1* efficiency, TH1* measured, TH1* initialConditions, TH1* result);
49
50     static TH1* GetPenaltyPlot(Double_t* params);
51     static TH1* GetPenaltyPlot(TH1* corrected);
52   
53   protected:
54     AliUnfolding() {};
55
56     static Int_t UnfoldWithMinuit(TH2* correlation, TH1* efficiency, TH1* measured, TH1* initialConditions, TH1* result, Bool_t check);
57     static Int_t UnfoldWithBayesian(TH2* correlation, TH1* aEfficiency, TH1* measured, TH1* initialConditions, TH1* aResult);
58     static Int_t UnfoldWithFunction(TH2* correlation, TH1* efficiency, TH1* measured, TH1* /* initialConditions */, TH1* aResult);
59
60     static void DrawGuess(Double_t *params);
61     static void CreateOverflowBin(TH2* correlation, TH1* measured); 
62     static void SetStaticVariables(TH2* correlation, TH1* measured, TH1* efficiency);
63
64     static Double_t RegularizationPol0(TVectorD& params);
65     static Double_t RegularizationPol1(TVectorD& params);
66     static Double_t RegularizationTotalCurvature(TVectorD& params);
67     static Double_t RegularizationEntropy(TVectorD& params);
68     static Double_t RegularizationLog(TVectorD& params);
69     static Double_t RegularizationRatio(TVectorD& params);
70
71     static void Chi2Function(Int_t&, Double_t*, Double_t& chi2, Double_t *params, Int_t);
72     static void TF1Function(Int_t& unused1, Double_t* unused2, Double_t& chi2, Double_t *params, Int_t unused3);
73
74     // static variable to be accessed by MINUIT
75     static TMatrixD* fgCorrelationMatrix;            // contains fCurrentCorrelation in matrix form
76     static TMatrixD* fgCorrelationMatrixSquared;     // contains squared fCurrentCorrelation in matrix form
77     static TMatrixD* fgCorrelationCovarianceMatrix;  // contains the errors of fCurrentESD
78     static TVectorD* fgCurrentESDVector;             // contains fCurrentESD
79     static TVectorD* fgEntropyAPriori;               // a-priori distribution for entropy regularization
80     static TVectorD* fgEfficiency;                   // efficiency
81     static TVectorD* fgBinWidths;                    // bin widths to be taken into account in regularization
82
83     static TF1* fgFitFunction;                       // fit function
84
85     // --- configuration params follow ---
86     static MethodType fgMethodType;                  // unfolding method to be used
87     static Int_t fgMaxParams;                        // bins in unfolded histogram = number of fit params
88     static Int_t fgMaxInput;                         // bins in measured histogram
89     static Float_t fgOverflowBinLimit;               // to fix fluctuations at high multiplicities, all entries above the limit are summarized in one bin
90
91     static RegularizationType fgRegularizationType;  // regularization that is used during Chi2 method
92     static Float_t fgRegularizationWeight;           // factor for regularization term
93     static Int_t fgSkipBinsBegin;                    // (optional) skip the given number of bins in the regularization
94     static Float_t fgMinuitStepSize;                 // (usually not needed to be changed) step size in minimization
95     static Bool_t fgMinimumInitialValue;             // set all initial values at least to the smallest value among the initial values
96     static Float_t fgMinimumInitialValueFix;         // use this as the minimum initial value instead of determining it automatically
97     static Bool_t fgNormalizeInput;                  // normalize input spectrum
98     static Float_t fgNotFoundEvents;                 // constraint on the total number of not found events sum(guess * (1/eff -1))
99     static Bool_t fgSkipBin0InChi2;                  // skip bin 0 (= 0 measured) in chi2 function
100
101     static Float_t fgBayesianSmoothing;              // smoothing parameter (0 = no smoothing)
102     static Int_t   fgBayesianIterations;             // number of iterations in Bayesian method
103
104     static Bool_t fgDebug;                           // debug flag
105     // --- end of configuration ---
106     
107     static Int_t fgCallCount;                        // call count to chi2 function
108
109 private:
110     AliUnfolding(const AliUnfolding&);
111     AliUnfolding& operator=(const AliUnfolding&);
112
113   ClassDef(AliUnfolding, 0);
114 };
115
116 #endif
117