KaliVeda
Toolkit for HIC analysis
Loading...
Searching...
No Matches
KVTGIDFitter.cpp
1/*
2$Id: KVTGIDFitter.cpp,v 1.2 2009/03/03 14:27:15 franklan Exp $
3$Revision: 1.2 $
4$Date: 2009/03/03 14:27:15 $
5*/
6
7//Created by KVClassFactory on Mon Apr 21 09:26:24 2008
8//Author: franklan
9
10#include "KVTGIDFitter.h"
11#include "fit_ede.h"
12#include "KVIDZAGrid.h"
13#include "KVIDGridManager.h"
14#include "KVTGIDGrid.h"
15
16using namespace std;
17
19
20
21
22
24
26{
27 // Default constructor
28 fLight = fType = fZorA = 0;
29 fPar = zd = ad = xd = yd = 0;
30 istate = 0;
31 fTGID = 0;
32 fGrid = 0;
33 fXmin = fXmax = 0.0;
34}
35
36
38
39
42
44{
45 // Destructor
46 if (fPar) delete [] fPar;
47 if (istate) delete [] istate;
48 if (zd) delete [] zd;
49 if (ad) delete [] ad;
50 if (xd) delete [] xd;
51 if (yd) delete [] yd;
52}
53
54
56
57
62
64{
65 // Fit the grid using the functional chosen with SetType and SetLight.
66 // Status of fit after this call can be retrieved with GetFitStatus().
67
68 // must inherit from KVIDZAGrid!
69 if (!theGrid->InheritsFrom(KVIDZAGrid::Class())) {
70 Error("Fit(KVIDGraph*)",
71 "Can only fit graphs inheriting from KVIDZAGrid");
72 fGrid = 0;
73 return;
74 }
75 fGrid = theGrid;
76 fZorA = (Int_t)(!theGrid->HasMassIDCapability());
77 // prepare new parameter array and status array
78 if (fPar) delete [] fPar;
80 fPar = new Float_t[npar];
81 if (istate) delete [] istate;
82 istate = new Int_t[npar];
83
84 //initialise grid - this should sort lines in order of Z & A
85 theGrid->Initialize();
86
87 //limit points according to abscissa ?
88 Bool_t with_xlimits = (fXmax > fXmin);
89
90 // calculate total number of points to fit
91 Int_t npts = 0;
92 TIter next_id(theGrid->GetIdentifiers());
94 while ((id = (KVIDentifier*)next_id())) {
95 if (!with_xlimits) {
96 npts += id->GetN(); // count all points
97 }
98 else {
99 Double_t x, y;
100 for (int i = 0; i < id->GetN(); i++) {
101 id->GetPoint(i, x, y);
102 if (x >= fXmin && x <= fXmax) ++npts; // only points between [fXmin,fXmax]
103 }
104 }
105 }
106 cout << "Points to fit = " << npts << endl;
107 if (npts < 2) {
108 Error("Fit(KVIDGraph*)",
109 "Too few points for fit");
110 irc = -2;
111 return;
112 }
113
114 // prepare and fill arrays with Z, A, X & Y
115 if (zd) delete [] zd;
116 if (ad) delete [] ad;
117 if (xd) delete [] xd;
118 if (yd) delete [] yd;
119 zd = new Float_t[npts];
120 ad = new Float_t[npts];
121 xd = new Float_t[npts];
122 yd = new Float_t[npts];
123 next_id.Reset();
124 npts = 0;
125 Double_t x, y;
126 while ((id = (KVIDentifier*)next_id())) {
127 for (int i = 0; i < id->GetN(); i++) {
128 id->GetPoint(i, x, y);
129 if ((!with_xlimits) || (x >= fXmin && x <= fXmax)) {
130 xd[npts] = (Float_t)x;
131 yd[npts] = (Float_t)y;
132 zd[npts] = id->GetZ();
133 ad[npts] = id->GetA();
134 ++npts;
135 }
136 }
137 }
138
139 /*** FIT FONCTIONNELLE ***/
140 irc = globede_c(npts, zd, ad, xd, yd, fType, fLight, fPar, istate);
141
142 //generate TGID corresponding to fit
143 MakeTGID();
144}
145
146
148
149
158
160{
161 // Return status code of last fit.
162 // 0 -> convergence reached
163 // 1 -> convergence reached, but not well marked minimum
164 // 2 -> too many iterations, convergence not reached
165 // -1 -> no identification line with at least 2 points
166 // -2 -> too few data points
167 // -3 -> addressing problem between Fortran and C
168 return irc;
169}
170
171
172
175
177{
178 // String with meaning of fit status codes (see GetFitStatus)
179
180 static TString message[] = {
181 "addressing problem between Fortran and C",
182 "too few data points",
183 "no identification line with at least 2 points",
184 "convergence reached",
185 "convergence reached, but not well marked minimum",
186 "too many iterations, convergence not reached"
187 };
188 return message[irc + 3].Data();
189}
190
191
193
194
201
203{
204 // Returns array containing status of each parameter:
205 // =0 -> free parameter
206 // =1 -> parameter constrained by the lower limit
207 // =2 -> parameter constrained by the upper limit
208 // =3 -> constant parameter (bl(i)=bu(i)=par(i))
209 return istate;
210}
211
212
214
215
218
220{
221 // Make a KVTGID out of fit result, if fit converged (irc<2)
222
223 if (irc < 0 || irc > 1) return;
224 if (!fGrid) return;
225
235}
236
237
239
240
249
250void KVTGIDFitter::FitPanel(Int_t functional_type, Bool_t with_csi_light_energy,
251 Int_t first_Z, Int_t last_Z, Double_t xmin, Double_t xmax)
252{
253 // GUI method used to fit grid previously set with SetGrid(KVIDGraph*).
254 // functional_type = 0 (standard) or 1 (extended functional)
255 // with_csi_light_energy = kTRUE (with) or kFALSE (without CsI light-energy relation for 'X')
256 // first_Z, last_Z: set minimum & maximum Z for which fit is valid in KVTGID object
257 // resulting from fit. (default: -1, take first and last Z of grid)
258 // xmin, xmax: only fit points with abscissa between limits [xmin,xmax]
259 // (default: use all points regardless of abscissa)
260
261 if (!fGrid) {
262 Error("FitPanel", "Set grid to fit with SetGrid(KVIDGraph*)");
263 return;
264 }
265 SetFunctionalType(functional_type);
266 SetLight((Int_t)with_csi_light_energy);
267 fXmin = xmin;
268 fXmax = xmax;
269 Fit(fGrid);
270 if (irc > 1 || irc < 0) {
271 Warning("FitPanel", "Fit failed. Status of fit = %d", irc);
272 return;
273 }
274 if (!fTGID) {
275 Error("FitPanel", "Fit failed : %s", GetFitStatusString());
276 return;
277 }
278
279 if (first_Z != -1) fTGID->SetIDmin(first_Z);
280 if (last_Z != -1) fTGID->SetIDmax(last_Z);
281
283 // generate grid representing fit
284 KVTGIDGrid* fitgr = new KVTGIDGrid(fTGID, (KVIDZAGrid*)fGrid);
285 // make fitted grid 'onlyzid' if parent grid was
288 fitgr->Generate(fGrid->GetXmax(), fGrid->GetXmin());
289 gIDGridManager->Modified();
290
291 if (fPad) {
292 // draw fitted grid in same pad as original
293 fPad->cd();
294 fitgr->Draw();
295 fPad->Modified();
296 fPad->Update();
297 }
298}
299
300
int Int_t
bool Bool_t
char Char_t
float Float_t
double Double_t
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize id
float xmin
float xmax
char * Form(const char *fmt,...)
Base class for particle identification in a 2D map.
Definition KVIDGraph.h:32
const TList * GetIDTelescopes() const
Definition KVIDGraph.h:245
Axis_t GetXmax() const
Definition KVIDGraph.h:393
void Draw(Option_t *opt="")
Int_t GetMassFormula() const
Definition KVIDGraph.h:438
virtual Bool_t HasMassIDCapability() const
Definition KVIDGraph.h:169
const KVNumberList & GetRuns() const
Definition KVIDGraph.h:261
void FindAxisLimits()
Calculate X/Y min/max of all objects in graph.
const KVList * GetIdentifiers() const
Definition KVIDGraph.h:298
void SetMassFormula(Int_t)
const Char_t * GetName() const
Axis_t GetXmin() const
Definition KVIDGraph.h:385
virtual void Initialize()=0
virtual void SetOnlyZId(Bool_t yes=kTRUE)
Identification grid with lines corresponding to different nuclear isotopes (KVIDZALine)
Definition KVIDZAGrid.h:66
Base class for graphical cuts used in particle identification.
virtual TObject * Last() const
virtual TObject * First() const
Fit of E-DE functional.
Float_t * fPar
array of fit parameters
Float_t * zd
array of Z's
Int_t GetFitStatus() const
Float_t * yd
array of Y coordinates
Float_t * xd
array of X coordinates
virtual void Fit(KVIDGraph *)
virtual ~KVTGIDFitter()
Destructor.
Int_t * GetStatusOfParameters() const
Int_t fZorA
is grid for Z&A or only Z identification ?
void FitPanel(Int_t functional_type=1, Bool_t with_csi_light_energy=kTRUE, Int_t first_Z=-1, Int_t last_Z=-1, Double_t xmin=0.0, Double_t xmax=0.0)
void MakeTGID()
Make a KVTGID out of fit result, if fit converged (irc<2)
Float_t * ad
array of A's
Int_t * istate
status of parameters
Double_t fXmin
limit for fit
Int_t irc
status code
Double_t fXmax
limit for fit
Int_t fType
type of functional
const Char_t * GetFitStatusString() const
String with meaning of fit status codes (see GetFitStatus)
KVTGID * fTGID
KVTGID object representing fit result.
Int_t fLight
handles CsI total light-energy conversion
void SetFunctionalType(Int_t t)
void SetLight(Int_t ih)
Grid representing result of fit.
Definition KVTGIDGrid.h:24
virtual void Generate(Double_t xmax, Double_t xmin, Int_t ID_min=0, Int_t ID_max=0, Int_t npoints=50, Bool_t logscale=kTRUE)
void SetIDTelescopes(const TCollection *)
Definition KVTGID.cpp:743
void SetIDmax(Double_t x)
Definition KVTGID.h:117
void SetVarX(const Char_t *x)
Definition KVTGID.h:263
static KVTGID * MakeTGID(const Char_t *name, Int_t type, Int_t light, Int_t ZorA, Int_t mass)
Definition KVTGID.cpp:429
void SetValidRuns(const KVNumberList &r)
Definition KVTGID.h:249
void SetIDmin(Double_t x)
Definition KVTGID.h:125
void SetVarY(const Char_t *x)
Definition KVTGID.h:271
void SetLTGParameters(Double_t *par)
Definition KVTGID.cpp:527
static Int_t GetNumberOfLTGParameters(Int_t type, Int_t light)
Definition KVTGID.cpp:700
TVirtualPad * fPad
the pad in which grid is drawn (=0 if not drawn)
KVIDGraph * fGrid
the grid to fit
static TClass * Class()
const char * GetVarX() const
const char * GetVarY() const
void Reset()
virtual void Warning(const char *method, const char *msgfmt,...) const
virtual Bool_t InheritsFrom(const char *classname) const
virtual void Error(const char *method, const char *msgfmt,...) const
const char * Data() const
virtual void Modified(Bool_t flag=1)=0
virtual TVirtualPad * cd(Int_t subpadnumber=0)=0
virtual void Update()=0
Double_t y[n]
Double_t x[n]
ClassImp(TPyArg)