ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/JetFitAnalyzer/interface/HistoFitter.h
Revision: 1.9
Committed: Thu Mar 4 18:49:03 2010 UTC (15 years, 2 months ago) by dnisson
Content type: text/plain
Branch: MAIN
CVS Tags: V02-03-00
Changes since 1.8: +1 -1 lines
Log Message:
Changed sigma, eliminated bias

File Contents

# Content
1 // Original Author: David Nisson
2 // Fits a two-dimensional model in eta and phi consisting of summed
3 // Gaussians to a histogram, supplied in the function fit_histo.
4 // This histogram can be of mass, energy, or momentum.
5
6 #ifndef UserCode_JetFitAnalyzer_HistoFitter_h
7 #define UserCode_JetFitAnalyzer_HistoFitter_h
8
9 #include <TH2.h>
10 #include <vector>
11 #include <string>
12 #include <TString.h>
13 #include <TFormula.h>
14 #include <TMinuit.h>
15
16 class HistoFitter {
17 public:
18 // the objective function that gets minimized by TMinuit
19 static void fcn(int&, double *, double&, double *, int);
20 // the correction to Gaussians drifting outside of histogram
21 static double outsiderCorrection(double *, double XbinSize,
22 double YbinSize,
23 double cutoffRad = 0.2);
24
25 // place where fitting trouble happened
26 enum TroubleStage {
27 T_NULL = 0,
28 T_SIMPLEX,
29 T_MIGRAD,
30 T_MINOS
31 };
32
33 // the histogram class used internally by HistoFitter
34 struct VectorHisto {
35 std::vector< std::vector<double> > bins;
36 double Xlo, Xhi, Ylo, Yhi;
37 };
38
39 // information about fitting trouble
40 struct Trouble {
41 TroubleStage occ;
42 int istat;
43 };
44
45 // structure that stores the fit results
46 struct FitResults {
47 TH2 *rebinnedHisto;
48 std::vector< double > chisquare;
49 std::vector< std::vector<TString> > pars;
50 std::vector< std::vector<double> > pval;
51 std::vector< std::vector<double> > perr;
52 std::vector< std::vector<double> > plo;
53 std::vector< std::vector<double> > phi;
54 };
55
56 class ModelDefinition {
57 public:
58 int numberOfGaussians();
59 void setNumberOfGaussians(int);
60 int maxNumberOfGaussians() {
61 return theMaxNumberOfGaussians;
62 }
63 void setMaxNumberOfGaussians(int newNumberOfGaussians) {
64 theMaxNumberOfGaussians = newNumberOfGaussians;
65 }
66
67 double fitFunction(double, double, double *);
68
69 TFormula *indivFormula();
70 void setFormula(TFormula *);
71 void indivParameter(int, std::string&, double&, double&, double&, double&);
72 void setIndivParameter(int, std::string, double, double, double, double);
73 unsigned indivEnergy();
74 void setIndivEnergy(unsigned);
75 unsigned indivMeanX();
76 void setIndivMeanX(unsigned);
77 unsigned indivMeanY();
78 void setIndivMeanY(unsigned);
79 virtual double chisquareSigma(double, double) = 0;
80 double formulaIntegral(double, double, double, double,
81 double*, double, double);
82 std::vector< std::vector< double > > subtractCurrentFit(VectorHisto,
83 FitResults);
84 void initParsFromModelDef(std::vector<TString> &,
85 double *, double *, double *, double *,
86 int, FitResults);
87 void findInitialValues(std::vector<TString> &,
88 double *, double *, double *, double *,
89 int, FitResults, int);
90 double initNewN(FitResults, int);
91 double initNewMeanX(FitResults, int);
92 double initNewMeanY(FitResults, int);
93 void initParameters(TH2 *, TMinuit *, std::vector<TString> &,
94 double *, double *, double *, double *,
95 int, FitResults);
96
97
98 private:
99 TFormula *theIndivFormula; // formula for individual Gaussian
100 std::vector<std::string> indivParNames;
101 std::vector<double> indivParStarts;
102 std::vector<double> indivParStartingStepSizes;
103 std::vector<double> indivParLowerLimit;
104 std::vector<double> indivParUpperLimit;
105 unsigned theIndivEnergy;
106 unsigned theIndivMeanX;
107 unsigned theIndivMeanY;
108 int theNumberOfGaussians;
109 int theMaxNumberOfGaussians;
110 };
111
112 int getNumberOfDegreesOfFreedom(VectorHisto, int);
113
114 FitResults putParsInFitResults(std::vector<TString>,
115 double *, double *, double *, double *,
116 FitResults&);
117 static VectorHisto loadTH2IntoVectorHisto(TH2*);
118 Trouble minimize(TMinuit*, VectorHisto, int);
119
120 int findNnewGauss(TH2 *, VectorHisto, FitResults);
121 FitResults fit_histo(TH2 *hist,
122 std::vector<Trouble> &t,
123 int start_theNumberOfGaussians = 1,
124 double P_cutoff_val = 0.5);
125
126 ModelDefinition& curr_ModelDefinition();
127 void set_ModelDefinition(ModelDefinition *_mdef);
128
129 double fitFunction_TF2(double *, double *);
130 protected:
131 static ModelDefinition *static_mdef;
132 static VectorHisto energy;
133 };
134
135 #endif