ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/JetFitAnalyzer/interface/HistoFitter.h
Revision: 1.7
Committed: Fri Jan 22 23:53:09 2010 UTC (15 years, 3 months ago) by dnisson
Content type: text/plain
Branch: MAIN
Changes since 1.6: +7 -2 lines
Log Message:
Latest version of my code which I am working on--prints out true W vertex

File Contents

# User Rev Content
1 dnisson 1.1 // Original Author: David Nisson
2 dnisson 1.7 // 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 dnisson 1.1
6     #ifndef UserCode_JetFitAnalyzer_HistoFitter_h
7     #define UserCode_JetFitAnalyzer_HistoFitter_h
8    
9 dnisson 1.3 #include <TH2.h>
10     #include <vector>
11     #include <string>
12     #include <TString.h>
13     #include <TFormula.h>
14     #include <TMinuit.h>
15    
16 dnisson 1.1 class HistoFitter {
17     public:
18 dnisson 1.4 // the objective function that gets minimized by TMinuit
19 dnisson 1.3 static void fcn(int&, double *, double&, double *, int);
20 dnisson 1.4 // the correction to Gaussians drifting outside of histogram
21     static double outsiderCorrection(double *, double XbinSize,
22     double YbinSize,
23     double cutoffRad = 0.2);
24 dnisson 1.2
25 dnisson 1.7 // place where fitting trouble happened
26 dnisson 1.1 enum TroubleStage {
27     T_NULL = 0,
28     T_SIMPLEX,
29     T_MIGRAD,
30     T_MINOS
31     };
32    
33 dnisson 1.7 // the histogram class used internally by HistoFitter
34 dnisson 1.1 struct VectorHisto {
35 dnisson 1.2 std::vector< std::vector<double> > bins;
36 dnisson 1.1 double Xlo, Xhi, Ylo, Yhi;
37 dnisson 1.3 };
38 dnisson 1.1
39 dnisson 1.7 // information about fitting trouble
40 dnisson 1.1 struct Trouble {
41     TroubleStage occ;
42     int istat;
43     };
44    
45 dnisson 1.7 // structure that stores the fit results
46 dnisson 1.1 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 dnisson 1.3 TFormula *indivFormula();
70 dnisson 1.1 void setFormula(TFormula *);
71     void indivParameter(int, std::string&, double&, double&, double&, double&);
72     void setIndivParameter(int, std::string, double, double, double, double);
73 dnisson 1.2 unsigned indivEnergy();
74     void setIndivEnergy(unsigned);
75     unsigned indivMeanX();
76     void setIndivMeanX(unsigned);
77     unsigned indivMeanY();
78     void setIndivMeanY(unsigned);
79 dnisson 1.1 virtual double chisquareSigma(double) = 0;
80     double formulaIntegral(double, double, double, double,
81 dnisson 1.4 double*, double, double);
82 dnisson 1.3 std::vector< std::vector< double > > subtractCurrentFit(VectorHisto,
83     FitResults);
84 dnisson 1.1 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 dnisson 1.6 int, FitResults, int);
90     double initNewN(FitResults, int);
91     double initNewMeanX(FitResults, int);
92     double initNewMeanY(FitResults, int);
93 dnisson 1.1 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 dnisson 1.3 std::vector<double> indivParStartingStepSizes;
103 dnisson 1.1 std::vector<double> indivParLowerLimit;
104     std::vector<double> indivParUpperLimit;
105 dnisson 1.2 unsigned theIndivEnergy;
106     unsigned theIndivMeanX;
107     unsigned theIndivMeanY;
108 dnisson 1.1 int theNumberOfGaussians;
109     int theMaxNumberOfGaussians;
110     };
111    
112 dnisson 1.2 int getNumberOfDegreesOfFreedom(VectorHisto, int);
113    
114 dnisson 1.3 FitResults putParsInFitResults(std::vector<TString>,
115     double *, double *, double *, double *);
116     static VectorHisto loadTH2IntoVectorHisto(TH2*);
117     Trouble minimize(TMinuit*, VectorHisto, int);
118    
119 dnisson 1.6 int findNnewGauss(TH2 *, VectorHisto, FitResults);
120 dnisson 1.2 FitResults fit_histo(TH2 *hist,
121     std::vector<Trouble> &t,
122     int start_theNumberOfGaussians = 1,
123 dnisson 1.1 double P_cutoff_val = 0.5);
124    
125     ModelDefinition& curr_ModelDefinition();
126     void set_ModelDefinition(ModelDefinition *_mdef);
127    
128 dnisson 1.2 double fitFunction_TF2(double *, double *);
129     protected:
130     static ModelDefinition *static_mdef;
131 dnisson 1.3 static VectorHisto energy;
132 dnisson 1.2 };
133 dnisson 1.1
134     #endif