GSI Object Oriented Online Offline (Go4) GO4-6.4.5
Loading...
Searching...
No Matches
TGo4FitComponent.cxx
Go to the documentation of this file.
1// $Id$
2//-----------------------------------------------------------------------
3// The GSI Online Offline Object Oriented (Go4) Project
4// Experiment Data Processing at EE department, GSI
5//-----------------------------------------------------------------------
6// Copyright (C) 2000- GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
7// Planckstr. 1, 64291 Darmstadt, Germany
8// Contact: http://go4.gsi.de
9//-----------------------------------------------------------------------
10// This software can be used under the license agreements as stated
11// in Go4License.txt file which is part of the distribution.
12//-----------------------------------------------------------------------
13
14#include "TGo4FitComponent.h"
15
16#include <iostream>
17
18#include "TCutG.h"
19#include "TMath.h"
20
21#include "TGo4FitParameter.h"
22
23const UInt_t kExcludeCut = 0x00100000;
24
30
31TGo4FitComponent::TGo4FitComponent(const char *iName, const char *iTitle)
32 : TGo4FitParsList(iName, iTitle, kTRUE), TGo4FitSlotList(), fxRangeAxis(), fxRangeValue(), fxCuts(), fiAmplIndex(-1),
33 fbUseBuffers(kFALSE)
34{
35 fxCuts.SetOwner(kTRUE);
36}
37
39
41TGo4FitComponent::NewParameter(const char *Name, const char *Title, Double_t iValue, Bool_t Fixed, Int_t AtIndx)
42{
43 TGo4FitParameter *par = new TGo4FitParameter(Name, Title, iValue);
44 if (AtIndx < 0)
45 AddPar(par);
46 else
47 InsertPar(par, AtIndx);
48 if (Fixed)
49 par->SetFixed(kTRUE);
50 return par;
51}
52
53TGo4FitParameter *TGo4FitComponent::NewAmplitude(const char *Name, Double_t iValue, Bool_t IsFixed, Int_t AtIndx)
54{
55 TGo4FitParameter *par = new TGo4FitParameter(Name ? Name : "Ampl", "Amplitude", iValue);
56 if (AtIndx < 0) {
57 AddPar(par);
58 AtIndx = NumPars() - 1;
59 } else {
60 InsertPar(par, AtIndx);
61 }
62 SetAmplIndex(AtIndx);
63 if (IsFixed)
64 par->SetFixed(kTRUE);
65 return par;
66}
67
72
74{
75 return GetAmplPar() ? GetAmplPar()->GetName() : nullptr;
76}
77
79{
80 return GetAmplPar() ? GetAmplPar()->GetFullName() : nullptr;
81}
83{
84 return GetAmplPar() ? GetAmplPar()->GetValue() : 1.0;
85}
86
88{
89 if (GetAmplPar())
90 Get(fiAmplIndex)->SetValue(iAmpl);
91}
92
94{
95 return GetAmplPar() ? GetAmplPar()->GetError() : 0.0;
96}
97
98void TGo4FitComponent::SetAmplError(Double_t iError)
99{
100 if (GetAmplPar())
101 Get(fiAmplIndex)->SetError(iError);
102}
103
104Bool_t TGo4FitComponent::MakeAmpl(Bool_t isFixed)
105{
106 if (GetAmplPar())
107 return kFALSE;
108 NewAmplitude();
109 if (isFixed)
110 GetAmplPar()->SetFixed(kTRUE);
111 return kTRUE;
112}
113
115{
116 if (!GetAmplPar())
117 return kFALSE;
119 SetAmplIndex(-1);
120 return kTRUE;
121}
122
123void TGo4FitComponent::GetRangeCondition(Int_t n, Int_t &typ, Int_t &naxis, Double_t &left, Double_t &right) const
124{
125 if ((n >= 0) && (n < GetNumRangeCondition())) {
126 Int_t naxis1 = fxRangeAxis[n * 2];
127 Int_t naxis2 = fxRangeAxis[n * 2 + 1];
128 Double_t value1 = fxRangeValue[n * 2];
129 Double_t value2 = fxRangeValue[n * 2 + 1];
130
131 if ((naxis1 < 0) && (naxis2 > 0)) {
132 typ = 0;
133 naxis = -naxis1 - 1;
134 left = value1;
135 right = value2;
136 } else if ((naxis1 > 0) && (naxis2 < 0)) {
137 typ = 1;
138 naxis = naxis1 - 1;
139 left = value1;
140 right = value2;
141 } else if (naxis1 < 0) {
142 typ = 2;
143 naxis = -naxis1 - 1;
144 left = value1;
145 right = 0.;
146 } else if (naxis1 > 0) {
147 typ = 3;
148 naxis = naxis1 - 1;
149 left = 0.;
150 right = value1;
151 }
152 }
153}
154
155void TGo4FitComponent::SetRangeCondition(Int_t n, Int_t typ, Int_t naxis, Double_t left, Double_t right)
156{
157 if ((n >= 0) && (n < GetNumRangeCondition())) {
158 Int_t naxis1, naxis2;
159 Double_t value1, value2;
160
161 switch (typ) {
162 case 0:
163 naxis1 = -(naxis + 1);
164 value1 = left;
165 naxis2 = +(naxis + 1);
166 value2 = right;
167 break;
168 case 1:
169 naxis1 = +(naxis + 1);
170 value1 = left;
171 naxis2 = -(naxis + 1);
172 value2 = right;
173 break;
174 case 2:
175 naxis1 = -(naxis + 1);
176 value1 = left;
177 naxis2 = 0;
178 value2 = 0.;
179 break;
180 case 3:
181 naxis1 = +(naxis + 1);
182 value1 = right;
183 naxis2 = 0;
184 value2 = 0.;
185 break;
186 default: return;
187 }
188
189 fxRangeAxis[n * 2] = naxis1;
190 fxRangeAxis[n * 2 + 1] = naxis2;
191 fxRangeValue[n * 2] = value1;
192 fxRangeValue[n * 2 + 1] = value2;
193 }
194}
195
196void TGo4FitComponent::AddRangeCondition(Int_t typ, Int_t naxis, Double_t left, Double_t right)
197{
198 Int_t sz = fxRangeValue.GetSize() + 2;
199 fxRangeAxis.Set(sz);
200 fxRangeValue.Set(sz);
201 SetRangeCondition(sz / 2 - 1, typ, naxis, left, right);
202}
203
205{
206 if ((n < 0) || (n >= GetNumRangeCondition()))
207 return;
208
209 Int_t indx = n * 2;
210 while (indx < fxRangeAxis.GetSize() - 2) {
211 fxRangeAxis[indx] = fxRangeAxis[indx + 2];
212 fxRangeValue[indx] = fxRangeValue[indx + 2];
213 indx += 1;
214 }
215 fxRangeAxis.Set(indx);
216 fxRangeValue.Set(indx);
217}
218
219void TGo4FitComponent::SetRange(Int_t naxis, Double_t min, Double_t max)
220{
221 AddRangeCondition(0, naxis, min, max);
222}
223
224void TGo4FitComponent::ExcludeRange(Int_t naxis, Double_t min, Double_t max)
225{
226 AddRangeCondition(1, naxis, min, max);
227}
228
229void TGo4FitComponent::SetRangeMin(Int_t naxis, Double_t value)
230{
231 AddRangeCondition(2, naxis, value, 0.);
232}
233
234void TGo4FitComponent::SetRangeMax(Int_t naxis, Double_t value)
235{
236 AddRangeCondition(3, naxis, 0., value);
237}
238
240{
241 if (naxis < 0) {
242 fxRangeAxis.Set(0);
243 fxRangeValue.Set(0);
244 fxCuts.Delete();
245 } else {
246 Int_t indx = 0, dindx = 0;
247 while (indx < fxRangeAxis.GetSize()) {
248 if (TMath::Abs(fxRangeAxis[indx]) != (naxis + 1)) {
249 fxRangeAxis[dindx] = fxRangeAxis[indx];
250 fxRangeAxis[dindx + 1] = fxRangeAxis[indx + 1];
251 fxRangeValue[dindx] = fxRangeValue[indx];
252 fxRangeValue[dindx + 1] = fxRangeValue[indx + 1];
253 dindx += 2;
254 }
255 indx += 2;
256 }
257 fxRangeAxis.Set(dindx);
258 fxRangeValue.Set(dindx);
259 if ((naxis == 0) || (naxis == 1))
260 fxCuts.Delete();
261 }
262}
263
265{
266 return (GetNumRangeCondition() > 0) || (GetNumRangeCut() > 0);
267}
268
269void TGo4FitComponent::AddRangeCut(TCutG *cut, Bool_t exclude)
270{
271 cut->SetBit(kExcludeCut, exclude);
272 fxCuts.Add(cut);
273}
274
276{
277 return fxCuts.GetLast() + 1;
278}
279
280TCutG *TGo4FitComponent::GetRangeCut(Int_t n) const
281{
282 return (n >= 0) && (n <= fxCuts.GetLast()) ? dynamic_cast<TCutG *>(fxCuts.At(n)) : nullptr;
283}
284
286{
287 TCutG *cut = GetRangeCut(n);
288 return !cut ? kFALSE : cut->TestBit(kExcludeCut);
289}
290
291void TGo4FitComponent::SetRangeCutExcluding(Int_t n, Bool_t exclude)
292{
293 TCutG *cut = GetRangeCut(n);
294 if (cut)
295 cut->SetBit(kExcludeCut, exclude);
296}
297
299{
300 TCutG *cut = GetRangeCut(n);
301 if (cut) {
302 fxCuts.Remove(cut);
303 delete cut;
304 fxCuts.Compress();
305 }
306}
307
308Bool_t TGo4FitComponent::GetRangeMin(Int_t naxis, Double_t &value) const
309{
310 Bool_t isany = kFALSE;
311 for (Int_t indx = 0; indx < fxRangeAxis.GetSize(); indx += 2)
312 if (fxRangeAxis[indx] == -(naxis + 1)) {
313 Double_t zn = fxRangeValue[indx];
314 if ((!isany) || (zn < value))
315 value = zn;
316 isany = kTRUE;
317 }
318 if (naxis < 2)
319 for (Int_t ncut = 0; ncut < GetNumRangeCut(); ncut++) {
320 TCutG *cut = GetRangeCut(ncut);
321 if (cut->TestBit(kExcludeCut))
322 continue;
323 Double_t *arr = (naxis == 0) ? cut->GetX() : cut->GetY();
324 Double_t zn = arr[0];
325 for (Int_t i = 1; i < cut->GetN(); i++)
326 if (arr[i] < zn)
327 zn = arr[i];
328 if ((!isany) || (zn < value))
329 value = zn;
330 isany = kTRUE;
331 }
332
333 return isany;
334}
335
336Bool_t TGo4FitComponent::GetRangeMax(Int_t naxis, Double_t &value) const
337{
338 Bool_t isany = kFALSE;
339 Double_t zn;
340 for (Int_t indx = 0; indx < fxRangeAxis.GetSize(); indx += 2) {
341 if ((fxRangeAxis[indx] == -(naxis + 1)) && (fxRangeAxis[indx + 1] == +(naxis + 1)))
342 zn = fxRangeValue[indx + 1];
343 else if ((fxRangeAxis[indx] == +(naxis + 1)) && (fxRangeAxis[indx + 1] == 0))
344 zn = fxRangeValue[indx];
345 else
346 continue;
347 if ((!isany) || (zn > value))
348 value = zn;
349 isany = kTRUE;
350 }
351 if (naxis < 2)
352 for (Int_t ncut = 0; ncut < GetNumRangeCut(); ncut++) {
353 TCutG *cut = GetRangeCut(ncut);
354 if (cut->TestBit(kExcludeCut))
355 continue;
356 Double_t *arr = naxis == 0 ? cut->GetX() : cut->GetY();
357 zn = arr[0];
358 for (Int_t i = 1; i < cut->GetN(); i++)
359 if (arr[i] > zn)
360 zn = arr[i];
361 if ((!isany) || (zn > value))
362 value = zn;
363 isany = kTRUE;
364 }
365
366 return isany;
367}
368
369Bool_t TGo4FitComponent::CheckRangeConditions(const Double_t *values, Int_t numaxis)
370{
371 Int_t condsize = GetNumRangeCondition();
372
373 if ((condsize == 0) && (GetNumRangeCut() == 0))
374 return kTRUE;
375
376 Bool_t res1 = kTRUE, res2 = kTRUE;
377
378 Bool_t isanycond = kFALSE;
379
380 for (Int_t naxis = 0; naxis < numaxis; naxis++) {
381 Char_t resaxis1 = kTRUE, resaxis2 = kFALSE;
382 Bool_t isany = kFALSE;
383 for (Int_t ncond = 0; ncond < condsize; ncond++) {
384
385 Int_t typ, axisnumber;
386 Double_t left, right;
387 GetRangeCondition(ncond, typ, axisnumber, left, right);
388
389 if (axisnumber != naxis)
390 continue;
391
392 switch (typ) {
393 case 0:
394 isany = kTRUE; // include range
395 if ((values[naxis] >= left) && (values[naxis] <= right))
396 resaxis2 = kTRUE;
397 break;
398 case 1: // exclude range
399 if ((values[naxis] >= left) && (values[naxis] <= right))
400 resaxis1 = kFALSE;
401 break;
402 case 2:
403 if (values[naxis] < left)
404 resaxis1 = kFALSE;
405 break; // set left bound
406 case 3:
407 if (values[naxis] > right)
408 resaxis1 = kFALSE;
409 break; // set right bound
410 }
411 }
412
413 res1 = res1 && resaxis1;
414 if (!isany)
415 resaxis2 = kTRUE;
416 res2 = res2 && resaxis2;
417 isanycond = isanycond || isany;
418 if (!res1)
419 break;
420 }
421
422 if (res1 && !(isanycond && res2) && (numaxis > 1) && (GetNumRangeCut() > 0)) {
423 res2 = kFALSE;
424 for (Int_t n = 0; n < GetNumRangeCut(); n++) {
425 TCutG *cut = GetRangeCut(n);
426 if (cut->IsInside(values[0], values[1])) {
427 if (cut->TestBit(kExcludeCut)) {
428 res1 = kFALSE;
429 break;
430 } else {
431 res2 = kTRUE;
432 break;
433 }
434 }
435 }
436 }
437
438 return res1 && res2;
439}
440
442{
444 for (Int_t n = 0; n < NumSlots(); n++) {
445 TGo4FitSlot *slot = GetSlot(n);
446 if (slot && slot->GetOwned()) {
447 TGo4FitParsList *pars = dynamic_cast<TGo4FitParsList *>(slot->GetObject());
448 if (pars)
449 pars->CollectParsTo(list);
450 }
451 }
452}
453
454void TGo4FitComponent::Print(Option_t *option) const
455{
456 std::cout << "***************************************************************************" << std::endl;
457 TGo4FitNamed::Print(option);
459 std::cout << " Amplitude index: " << fiAmplIndex << std::endl;
460
461 for (Int_t ncond = 0; ncond < GetNumRangeCondition(); ncond++) {
462 if (ncond == 0)
463 std::cout << " Range selection: " << std::endl;
464 Int_t typ, naxis;
465 Double_t left, right;
466 GetRangeCondition(ncond, typ, naxis, left, right);
467
468 std::cout << " axis " << naxis << " ";
469
470 switch (typ) {
471 case 0: std::cout << " select range from " << left << " to " << right; break;
472 case 1: std::cout << " exclude range from " << left << " to " << right; break;
473 case 2: std::cout << " set left bound to " << left; break;
474 case 3: std::cout << " set right bound to " << right; break;
475 }
476
477 std::cout << std::endl;
478 }
479
480 for (Int_t n = 0; n < GetNumRangeCut(); n++) {
481 TCutG *cut = GetRangeCut(n);
482 if (cut->TestBit(kExcludeCut))
483 std::cout << " Exclude";
484 else
485 std::cout << " Include";
486 std::cout << " axes ranges, using TCutG object " << std::endl;
487 cut->Print(option);
488 }
489}
const UInt_t kExcludeCut
TCutG * GetRangeCut(Int_t n) const
Returns specified range cut.
void SetRangeCondition(Int_t n, Int_t typ, Int_t naxis, Double_t left, Double_t right)
Change specified range condition.
TGo4FitParameter * GetAmplPar()
Return amplitude parameter object.
Bool_t GetRangeMax(Int_t naxis, Double_t &value) const
Defines maximum allowed value for given range.
void SetAmplIndex(Int_t iAmplIndex=-1)
Set index of amplitude parameter.
Int_t GetNumRangeCondition() const
Returns number of range condition (exclude range cuts).
void SetRange(Int_t naxis, Double_t min, Double_t max)
Includes axis range in consideration.
Bool_t fbUseBuffers
Specify usage of buffers after initialization.
Bool_t CheckRangeConditions(const Double_t *values, Int_t numaxis)
Check all range conditions for specified point.
TObjArray fxCuts
Array of TCutG objects, used for range selection.
void GetRangeCondition(Int_t n, Int_t &typ, Int_t &naxis, Double_t &left, Double_t &right) const
Return value for specified range condition.
void ClearRanges(Int_t naxis=-1)
Clear all range conditions for given axis.
Double_t GetAmplError()
Return error of amplitude parameter.
const char * GetAmplFullName()
Returns full name of amplitude parameter.
void SetRangeMin(Int_t naxis, Double_t value)
Set minimum axis value, taken into consideration.
void CollectParsTo(TGo4FitParsList &list) override
Collect all parameters to provided parameters list object.
Bool_t MakeAmpl(Bool_t isFixed=kFALSE)
Create amplitude parameter and adds it to parameters list.
Bool_t IsRangeCutExcluding(Int_t n) const
Return kTRUE if cut exclude range.
void SetAmplError(Double_t iError)
Set error of amplitude parameter.
Int_t GetNumRangeCut() const
Returns number of range cuts, assigned to object.
Int_t GetAmplIndex() const
Returns index of amplitude parameter.
void ExcludeRange(Int_t naxis, Double_t min, Double_t max)
Exclude axis range from consideration.
Int_t fiAmplIndex
Index of amplitude parameter (-1 if none).
TArrayD fxRangeValue
Array for range values storage.
TGo4FitParameter * NewAmplitude(const char *Name=nullptr, Double_t iValue=0., Bool_t IsFixed=kFALSE, Int_t AtIndx=0)
Create amplitude parameter with specified properties.
TGo4FitComponent()
Default constructor.
Bool_t IsAnyRangeLimits() const
Return kTRUE, if any range conditions were introduced.
const char * GetAmplName()
Returns name of amplitude parameter.
void SetRangeCutExcluding(Int_t n, Bool_t exclude=kTRUE)
Set type of range cut (excluding or including).
Bool_t GetRangeMin(Int_t naxis, Double_t &value) const
Defines minimum allowed value for given range.
void RemoveRangeCondition(Int_t n)
Removes specified range condition.
void AddRangeCondition(Int_t typ, Int_t naxis, Double_t left, Double_t right)
Add new range condition.
void SetRangeMax(Int_t naxis, Double_t value)
Set maximum axis value, taken into consideration.
void RemoveRangeCut(Int_t n)
Delete range cut with specified index.
Double_t GetAmplValue()
Return value of amplitude parameter.
TGo4FitParameter * NewParameter(const char *Name, const char *Title, Double_t iValue=0., Bool_t Fixed=kFALSE, Int_t AtIndx=-1)
Create new parameter with provided properties and add to parameters list.
void SetAmplValue(Double_t iAmpl)
Set value of amplitude parameter.
void Print(Option_t *option="") const override
Print info about object on standard output.
void AddRangeCut(TCutG *cut, Bool_t exclude=kFALSE)
Add TCutG object as range condition for two-dimensional case.
Bool_t RemoveAmpl()
Remove amplitude parameter from parameters list.
virtual ~TGo4FitComponent()
Destroys TGo4FitComponent object.
TArrayI fxRangeAxis
Array for range conditions storage (axis indexes).
void Print(Option_t *option="") const override
const char * GetFullName()
Returns full name of object.
Model and data objects parameter.
Double_t GetValue() const
Return parameter value.
Double_t GetError() const
Get value of parameter error.
void SetError(Double_t iError)
Set value of parameter error.
void SetValue(Double_t iValue)
Set parameter value.
void SetFixed(Bool_t iFixed)
Set status of parameter fixed or not.
Bool_t RemoveParByIndex(Int_t indx)
virtual void CollectParsTo(TGo4FitParsList &list)
Add all parameters to provided TGo4FitParsList object.
virtual TGo4FitParameter * Get(Int_t n)
void Print(Option_t *option="") const override
Default print method.
TGo4FitParsList()
Default constructor.
TGo4FitParameter * GetPar(Int_t n)
Return parameter according given index.
virtual Int_t NumPars()
Return number of parameters in list.
TGo4FitParameter * InsertPar(TGo4FitParameter *par, Int_t indx)
TGo4FitParameter * AddPar(TGo4FitParameter *par)
Int_t NumSlots()
Returns number of slots in list.
TGo4FitSlot * GetSlot(Int_t nslot)
Returns slots from list with specified index.
Managing pointers on specific objects.
Definition TGo4FitSlot.h:28
Bool_t GetOwned() const
Return ownership flag.
TObject * GetObject() const
Return pointer on assigned object.