KaliVeda  1.13/01
Heavy-Ion Analysis Toolkit
KVTGIDFitter.cpp
Go to the documentation of this file.
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 
16 using namespace std;
17 
19 
20 
21 
22 
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;
79  Int_t npar = KVTGID::GetNumberOfLTGParameters(fType, fLight);
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());
93  KVIDentifier* id;
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 
226  fTGID = KVTGID::MakeTGID(Form("%s_fit", fGrid->GetName()), fType, fLight, fZorA,
227  fGrid->GetMassFormula());
228  fTGID->SetLTGParameters(fPar);
229  fTGID->SetIDmin(((KVIDentifier*)fGrid->GetIdentifiers()->First())->GetZ());
230  fTGID->SetIDmax(((KVIDentifier*)fGrid->GetIdentifiers()->Last())->GetZ());
231  fTGID->SetValidRuns(fGrid->GetRuns());
232  fTGID->SetVarX(fGrid->GetVarX());
233  fTGID->SetVarY(fGrid->GetVarY());
234  fTGID->SetIDTelescopes(fGrid->GetIDTelescopes());
235 }
236 
237 
239 
240 
249 
250 void 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 
282  if (fGrid->GetXmin() == fGrid->GetXmax()) fGrid->FindAxisLimits();
283  // generate grid representing fit
284  KVTGIDGrid* fitgr = new KVTGIDGrid(fTGID, (KVIDZAGrid*)fGrid);
285  // make fitted grid 'onlyzid' if parent grid was
286  fitgr->SetOnlyZId(!fGrid->HasMassIDCapability());
287  if (!fGrid->HasMassIDCapability()) fitgr->SetMassFormula(fGrid->GetMassFormula());
288  fitgr->Generate(fGrid->GetXmax(), fGrid->GetXmin());
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
KVIDGridManager * gIDGridManager
ClassImp(KVPartitionList) void KVPartitionList
Initialisation.
char Char_t
bool Bool_t
double Double_t
float Float_t
float xmin
float xmax
char * Form(const char *fmt,...)
Base class for particle identification in a 2D map.
Definition: KVIDGraph.h:31
Axis_t GetXmax() const
Definition: KVIDGraph.h:392
void Draw(Option_t *opt="")
Definition: KVIDGraph.cpp:888
Int_t GetMassFormula() const
Definition: KVIDGraph.h:437
virtual Bool_t HasMassIDCapability() const
Definition: KVIDGraph.h:168
void SetMassFormula(Int_t)
Definition: KVIDGraph.cpp:1473
Axis_t GetXmin() const
Definition: KVIDGraph.h:384
virtual void Initialize()=0
virtual void SetOnlyZId(Bool_t yes=kTRUE)
Definition: KVIDGraph.cpp:1496
const KVList * GetIdentifiers() const
Definition: KVIDGraph.h:297
Identification grid with lines corresponding to different nuclear isotopes (KVIDZALine)
Definition: KVIDZAGrid.h:65
Base class for graphical cuts used in particle identification.
Definition: KVIDentifier.h:27
Fit of E-DE functional.
Definition: KVTGIDFitter.h:79
Int_t GetFitStatus() const
virtual void Fit(KVIDGraph *)
virtual ~KVTGIDFitter()
Destructor.
Int_t * GetStatusOfParameters() const
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)
const Char_t * GetFitStatusString() const
String with meaning of fit status codes (see GetFitStatus)
Grid representing result of fit.
Definition: KVTGIDGrid.h:23
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)
Definition: KVTGIDGrid.cpp:131
static KVTGID * MakeTGID(const Char_t *name, Int_t type, Int_t light, Int_t ZorA, Int_t mass)
Definition: KVTGID.cpp:429
static Int_t GetNumberOfLTGParameters(Int_t type, Int_t light)
Definition: KVTGID.cpp:700
Int_t GetN() const
void Reset()
virtual Bool_t InheritsFrom(const char *classname) const
const char * Data() const
Double_t y[n]
Double_t x[n]
TFitResultPtr Fit(FitObject *h1, TF1 *f1, Foption_t &option, const ROOT::Math::MinimizerOptions &moption, const char *goption, ROOT::Fit::DataRange &range)
void Error(const char *location, const char *va_(fmt),...)
void Warning(const char *location, const char *va_(fmt),...)