KaliVeda
Toolkit for HIC analysis
KVGaus2D.cpp
1 //Created by KVClassFactory on Tue Feb 7 16:49:15 2012
2 //Author: bonnet
3 
4 #include "KVGaus2D.h"
5 #include "TH2.h"
6 #include "Riostream.h"
7 #include "TMath.h"
8 #include "TMarker.h"
9 
11 
12 //________________________________________________________________
13 
14 
18 {
19  // Default constructor
20  SetName("Gaus2D");
21  is2D = kTRUE;
22 
23 }
24 
25 
26 
27 
34 
36 {
37  // Copy constructor
38  // This ctor is used to make a copy of an existing object (for example
39  // when a method returns an object), and it is always a good idea to
40  // implement it.
41  // If your class allocates memory in its constructor(s) then it is ESSENTIAL :-)
42 
43 }
44 
45 
46 
48 
49 Bool_t KVGaus2D::NewFunction_2D()
50 {
51 
52  Int_t nf = lfunc->GetEntries();
53 
54  f2Dfit = new TF2(Form("func_%d", ++nf),
55  this,
56  &KVGaus2D::f2D,
57  Xmin,
58  Xmax,
59  Ymin,
60  Ymax,
61  6,
62  GetName(),
63  "f2D"
64  );
65 
66  lfunc->Add(f2Dfit);
67 
68  hclone->GetXaxis()->SetRangeUser(Xmin, Xmax);
69  hclone->GetYaxis()->SetRangeUser(Ymin, Ymax);
70 
71  f2Dfit->SetParameters(
72  hclone->GetMean(1),
73  hclone->GetRMS(1),
74  hclone->GetMean(2),
75  hclone->GetRMS(2),
76  ((TH2*)hclone)->GetCorrelationFactor(),
77  hclone->Integral()
78  );
79 
80  return kTRUE;
81 }
82 
83 
84 
86 
87 TF1* KVGaus2D::ReloadFunction_2D(const Char_t* nom, Int_t npar)
88 {
89 
90  TF2* f2 = new TF2(nom,
91  this,
92  &KVGaus2D::f2D,
93  0, 1, 0, 1,
94  npar,
95  GetName(),
96  "f2D"
97  );
98 
99  return f2;
100 }
101 
102 
103 
108 
109 Double_t KVGaus2D::f2D(Double_t* xx, Double_t* para)
110 {
111 
112 //Function gaussienne 2D
113 //
114 // E1 vs E2
115 
116  userdefined = kTRUE;
117 
118  Double_t e2 = xx[0];
119  Double_t e1 = xx[1];
120 
121  Double_t E2 = para[0];
122  Double_t sigE2 = para[1];
123  Double_t E1 = para[2];
124  Double_t sigE1 = para[3];
125  Double_t rho = para[4];
126  Double_t norm = para[5];
127 
128  Double_t dE1 = E1 - e1;
129  Double_t dE2 = E2 - e2;
130 
131  Double_t A = -0.5 / ((1. - TMath::Power(rho, 2.)) * TMath::Power(sigE1 * sigE2, 2.)) * (TMath::Power(dE1 * sigE2, 2.) + TMath::Power(dE2 * sigE1, 2.) - 2.*rho * dE1 * dE2 * sigE1 * sigE2);
132  Double_t det = (1. - TMath::Power(rho, 2.)) * TMath::Power(sigE1 * sigE2, 2.);
133  Double_t P = norm * 1. / det * exp(A);
134 
135  return P;
136 
137 }
138 
139 
140 
142 
144 {
145  TMarker* m1 = new TMarker(f2Dfit->GetParameter(0), f2Dfit->GetParameter(2), 8);
146  m1->SetMarkerSize(0.7);
147 
148  m1->Draw();
149 }
150 
151 
int Int_t
bool Bool_t
char Char_t
double Double_t
constexpr Bool_t kTRUE
char * Form(const char *fmt,...)
Manage SemiAutomatic Fits.
Definition: KVAutoFit.h:26
Handle semi-automatic fit to 2D Gaussian distributions.
Definition: KVGaus2D.h:17
void ExtraDrawing() override
Definition: KVGaus2D.cpp:143
KVGaus2D(Bool_t batch=kFALSE)
Default constructor.
Definition: KVGaus2D.cpp:17
virtual void SetMarkerSize(Size_t msize=1)
virtual Double_t Integral(Int_t binx1, Int_t binx2, Int_t biny1, Int_t biny2, Option_t *option="") const
void Draw(Option_t *option="") override
const char * GetName() const override
RVec< PromoteType< T > > exp(const RVec< T > &v)
gr SetName("gr")
Double_t Power(Double_t x, Double_t y)
ClassImp(TPyArg)