Crombie Tools
Plot2D.h
Go to the documentation of this file.
1 //--------------------------------------------------------------------------------------------------
2 // Plot2D
3 //
4 // Authors: D.Abercrombie
5 //--------------------------------------------------------------------------------------------------
6 #ifndef CROMBIETOOLS_PLOTTOOLS_PLOT2D_H
7 #define CROMBIETOOLS_PLOTTOOLS_PLOT2D_H
8 
9 #include "TMatrixDSym.h"
10 #include "TGraphErrors.h"
11 #include "TF2.h"
12 #include "TF1.h"
13 
14 #include "FileConfigReader.h"
15 
16 class Plot2D : public FileConfigReader
17 {
18  public:
19  Plot2D();
20  virtual ~Plot2D();
21 
22  void SetExprX ( TString expr ) { fInExprX = expr; }
23  void AddExprX ( TString expr ) { fInExprXs.push_back(expr); }
24  void ResetInitialGuess () { fGuessParams.resize(0);
25  fGuesses.resize(0); }
26  void SetInitialGuess ( Int_t param, Double_t guess ) { fGuessParams.push_back(param);
27  fGuesses.push_back(guess); }
28 
29  void SetLooseGuess ( Int_t param, Double_t guess ) { fLooseGuessParams.push_back(param);
30  fLooseGuesses.push_back(guess); }
31  void ResetParameterLimits ();
32  void SetParameterLimits ( Int_t param, Double_t low, Double_t high );
33  void SetFunction ( TString function ) { fFunctionString = function; }
34  void SetLooseFit ( TString function ) { fLooseFunction = function; }
35  void SetLooseLimits ( Int_t param, Double_t low, Double_t high );
36  void AddMapping ( Int_t from, Int_t to, Double_t fact = 1.0 );
37 
38  virtual std::vector<TGraphErrors*> MakeGraphs ( TString ParameterExpr );
39 
40  void DoFits ( Int_t NumXBins, Double_t *XBins,
41  Int_t NumYBins, Double_t MinY, Double_t MaxY );
42 
43  void DoFits ( Int_t NumXBins, Double_t MinX, Double_t MaxX,
44  Int_t NumYBins, Double_t MinY, Double_t MaxY );
45 
46  void MakeCanvas ( TString FileBase, std::vector<TGraphErrors*> theGraphs,
47  TString XLabel, TString YLabel, Double_t YMin, Double_t YMax,
48  Bool_t logY = false );
49 
50  void MakeCanvas ( TString FileBase, TString ParameterExpr, TString XLabel, TString YLabel,
51  Double_t YMin, Double_t YMax, Bool_t logY = false );
52 
53  void MakeCanvas ( TString FileBase, Int_t ParameterNum, TString XLabel, TString YLabel,
54  Double_t YMin, Double_t YMax, Bool_t logY = false );
55 
56  void SetDumpingFits ( Bool_t dump ) { fDumpingFits = dump; }
57  void SetNumPoints ( Int_t num ) { fNumPoints = num; }
58  void SetFitOptions ( TString opts ) { fFitOptions = opts; }
59 
60  protected:
61 
62  std::vector<TF1*> MakeFuncs ( TString ParameterExpr, Double_t MinX, Double_t MaxX );
63 
64  void MapTo ( TF1* fitFunc, TF1* looseFunc );
65  virtual void DoFit ( TF1* fitFunc, TF1* looseFunc, TH2D* histToFit,
66  TF1**& fitHolder, TMatrixDSym**& covHolder );
67 
68  virtual TF1* MakeFunction ( TString function, Double_t MinX, Double_t MaxX,
69  Double_t MinY, Double_t MaxY )
70  { return new TF2("func", function, MinX, MaxX, MinY, MaxY); }
71 
72  virtual void ClearFits ();
73 
74  std::vector<TF1**> fFits;
75  std::vector<TMatrixDSym**> fCovs;
76 
77  std::vector<Int_t> fGuessParams;
78  std::vector<Double_t> fGuesses;
79  std::vector<Int_t> fLooseGuessParams;
80  std::vector<Double_t> fLooseGuesses;
81 
82  std::vector<Int_t> fParams; // This is vector used for setting parameter limits for fits
83  std::vector<Double_t> fParamLows; // Low values of these parameters
84  std::vector<Double_t> fParamHighs; // High values of these parameters
85  std::vector<Int_t> fLooseParams; // This is vector used for setting parameter limits for loose fits
86  std::vector<Double_t> fLooseParamLows; // Low values of these parameters
87  std::vector<Double_t> fLooseParamHighs; // High values of these parameters
88 
89  TString fInExprX; // X Expression should be constant
90  std::vector<TString> fInExprXs;
91  TString fFunctionString;
92 
93  TString fLooseFunction;
94  std::vector<Int_t> fParamFrom;
95  std::vector<Int_t> fParamTo;
96  std::vector<Double_t> fParamFactor;
97 
98  Bool_t fDumpingFits; // Bool used to dump .png files if you want to check fits
99  Int_t fNumFitDumps; // int to keep track of different number of fits
100  TString fFitOptions;
101 
102  private:
103 
104  Int_t fNumPoints;
105 
106  ClassDef(Plot2D, 1)
107 };
108 
109 #endif