GSI Object Oriented Online Offline (Go4)  GO4-6.3.0
TGo4FitModelFromData.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 "TGo4FitModelFromData.h"
15 
16 #include <iostream>
17 
18 #include "TGo4FitDataHistogram.h"
19 
21 
22 TGo4FitModelFromData::TGo4FitModelFromData(const char *iName, TGo4FitData *iDataAsModel, Bool_t Amplitude)
23  : TGo4FitModel(iName, "data used as model", Amplitude),
24  fxData("forModel", "Data, used to represent model component", this, TGo4FitData::Class(), kTRUE, iDataAsModel,
25  kTRUE)
26 {
27 }
28 
29 TGo4FitModelFromData::TGo4FitModelFromData(const char *iName, TH1 *histo, Bool_t iOwned, Bool_t Amplitude)
30  : TGo4FitModel(iName, "data used as model", Amplitude),
31  fxData("forModel", "Data, used to represent model component", this, TGo4FitData::Class(), kTRUE)
32 {
33  SetDataAsModel(new TGo4FitDataHistogram("Histogram", histo, iOwned), kTRUE);
34 }
35 
37 {
38 }
39 
41 {
42  return dynamic_cast<TGo4FitData *>(fxData.GetObject());
43 }
44 
46 {
47  fxData.SetObject(iData, iOwned);
49 }
50 
51 Bool_t TGo4FitModelFromData::Initialize(Int_t UseBuffers)
52 {
53  if (!GetDataAsModel())
54  return kFALSE;
55 
56  for (Int_t n = 0; n < NumAssigments(); n++)
57  if (GetAssignedConnection(n))
59  std::cout << "TGo4FitModelFromData: incompatible data used for model" << std::endl;
60  return kFALSE;
61  }
62 
63  return TGo4FitModel::Initialize(UseBuffers);
64 }
65 
67 {
68  fxIter.reset();
69 
70  if (!GetDataAsModel())
71  return kFALSE;
73  if (!fxIter)
74  return kFALSE;
75  return fxIter->Reset(kFALSE);
76 }
77 
78 Double_t TGo4FitModelFromData::EvaluateAtPoint(TGo4FitData *data, Int_t nbin, Bool_t UseRanges)
79 {
80  return data ? FindDataPoint(GetDataIndexesSize(data), GetDataFullIndex(data, nbin)) : 0.;
81 }
82 
83 Double_t TGo4FitModelFromData::EvaluateAtPoint(std::unique_ptr<TGo4FitDataIter> &iter, Bool_t UseRanges)
84 {
85  return iter ? FindDataPoint(iter->IndexesSize(), iter->Indexes()) : 0.;
86 }
87 
89 {
90  fxIter.reset();
91 }
92 
93 void TGo4FitModelFromData::FillSlotList(TSeqCollection *list)
94 {
96  list->Add(&fxData);
97  if (GetDataAsModel())
99 }
100 
101 void TGo4FitModelFromData::Print(Option_t *option) const
102 {
103  TGo4FitModel::Print(option);
104  std::cout << "Model driven from data" << std::endl;
105  if (GetDataAsModel())
106  GetDataAsModel()->Print(option);
107 }
108 
109 Double_t TGo4FitModelFromData::FindDataPoint(Int_t NumIndexes, const Int_t *Indexes)
110 {
111  if (!fxIter || fxIter->ReachEnd() || !Indexes || (NumIndexes != fxIter->IndexesSize()))
112  return 0.;
113  Int_t num = NumIndexes - 1;
114  while (num >= 0) {
115  if (fxIter->Indexes()[num] == Indexes[num]) {
116  num--;
117  continue;
118  } else if (fxIter->Indexes()[num] > Indexes[num])
119  return 0.;
120  else if (!fxIter->Next(kFALSE))
121  return 0.;
122  }
123  return fxIter->Value();
124 }
void SetUpdateSlotList()
std::unique_ptr< TGo4FitDataIter > fxIter
Int_t GetDataIndexesSize(TGo4FitData *data)
void Print(Option_t *option="") const override
Bool_t Initialize(Int_t UseBuffers=-1) override
void FillSlotList(TSeqCollection *list) override
void Print(Option_t *option="") const override
void Print(Option_t *option="") const override
Bool_t IsCompatibleData(TGo4FitData *data)
TGo4FitData * GetAssignedConnection(Int_t n)
Bool_t SetObject(TObject *iObject, Bool_t iOwned=kFALSE, Bool_t CheckClass=kTRUE)
void SetDataAsModel(TGo4FitData *iData, Bool_t iOwned)
virtual Bool_t Initialize(Int_t UseBuffers=-1)
void FillSlotList(TSeqCollection *list) override
virtual void FillSlotList(TSeqCollection *lst)
virtual std::unique_ptr< TGo4FitDataIter > MakeIter()
Definition: TGo4FitData.h:175
Int_t NumAssigments() const
Definition: TGo4FitModel.h:124
Int_t IndexesSize() const
Definition: TGo4FitData.h:454
Double_t FindDataPoint(Int_t NumIndexes, const Int_t *Indexes)
Bool_t BeforeEval(Int_t) override
const Int_t * Indexes() const
Definition: TGo4FitData.h:459
TGo4FitData * GetDataAsModel() const
Double_t EvaluateAtPoint(TGo4FitData *data, Int_t nbin, Bool_t UseRanges=kTRUE) override
TObject * GetObject() const
const Int_t * GetDataFullIndex(TGo4FitData *data, Int_t nbin)