GSI Object Oriented Online Offline (Go4)  GO4-6.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4FitModelFromData.cxx
Go to the documentation of this file.
1 // $Id: TGo4FitModelFromData.cxx 2749 2020-04-16 10:05:15Z linev $
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 
20 TGo4FitModelFromData::TGo4FitModelFromData() : TGo4FitModel(), fxData(this, TGo4FitData::Class()), fxIter(0) {
21 }
22 
23 TGo4FitModelFromData::TGo4FitModelFromData(const char* iName, TGo4FitData *iDataAsModel, Bool_t Amplitude) :
24  TGo4FitModel(iName,"data used as model",Amplitude),
25  fxData("forModel", "Data, used to represent model component",
26  this, TGo4FitData::Class(), kTRUE, iDataAsModel, kTRUE), fxIter(0) {
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",
32  this, TGo4FitData::Class(), kTRUE), fxIter(0) {
33  SetDataAsModel(new TGo4FitDataHistogram("Histogram",histo,iOwned), kTRUE);
34 }
35 
37 {
38  if (fxIter) delete fxIter;
39 }
40 
42 {
43  return dynamic_cast<TGo4FitData*> (fxData.GetObject());
44 }
45 
47  fxData.SetObject(iData,iOwned);
49 }
50 
51 Bool_t TGo4FitModelFromData::Initialize(Int_t UseBuffers) {
52  if (GetDataAsModel() == 0) return kFALSE;
53 
54  for(Int_t n=0;n<NumAssigments();n++)
55  if (GetAssignedConnection(n))
57  std::cout << "TGo4FitModelFromData: incompatible data used for model" << std::endl;
58  return kFALSE;
59  }
60 
61  return TGo4FitModel::Initialize(UseBuffers);
62 }
63 
65  if (fxIter!=0) { delete fxIter; fxIter = 0; }
66  if (GetDataAsModel()==0) return kFALSE;
68  if (fxIter==0) return kFALSE;
69  return fxIter->Reset(kFALSE);
70 }
71 
72 Double_t TGo4FitModelFromData::EvaluateAtPoint(TGo4FitData* data, Int_t nbin, Bool_t UseRanges) {
73  if (data==0) return 0.;
74  return FindDataPoint(GetDataIndexesSize(data), GetDataFullIndex(data,nbin));
75 }
76 
77 Double_t TGo4FitModelFromData::EvaluateAtPoint(TGo4FitDataIter* iter, Bool_t UseRanges) {
78  if (iter==0) return 0.;
79  return FindDataPoint(iter->IndexesSize(), iter->Indexes());
80 }
81 
83  if (fxIter!=0) { delete fxIter; fxIter = 0; }
84 }
85 
86 
87 void TGo4FitModelFromData::FillSlotList(TSeqCollection* list) {
89  list->Add(&fxData);
91 }
92 
93 void TGo4FitModelFromData::Print(Option_t* option) const {
94  TGo4FitModel::Print(option);
95  std::cout << "Model driven from data" << std::endl;
96  if (GetDataAsModel()) GetDataAsModel()->Print(option);
97 }
98 
99 Double_t TGo4FitModelFromData::FindDataPoint(Int_t NumIndexes, const Int_t* Indexes) {
100  if ((fxIter==0) || (fxIter->ReachEnd()) || (Indexes==0) || (NumIndexes!=fxIter->IndexesSize())) return 0.;
101  Int_t num = NumIndexes-1;
102  while (num>=0)
103  if (fxIter->Indexes()[num]==Indexes[num]) { num--; continue; } else
104  if (fxIter->Indexes()[num]>Indexes[num]) return 0.; else
105  if (!fxIter->Next(kFALSE)) return 0.;
106  return fxIter->Value();
107 }
void SetUpdateSlotList()
Int_t GetDataIndexesSize(TGo4FitData *data)
virtual void Print(Option_t *option) const
virtual TGo4FitDataIter * MakeIter()
Definition: TGo4FitData.h:165
TGo4FitDataIter * fxIter
virtual void Print(Option_t *option) const
virtual Bool_t Reset(Bool_t UseRanges=kTRUE)
Bool_t IsCompatibleData(TGo4FitData *data)
TGo4FitData * GetAssignedConnection(Int_t n)
virtual Bool_t Initialize(Int_t UseBuffers=-1)
Bool_t SetObject(TObject *iObject, Bool_t iOwned=kFALSE, Bool_t CheckClass=kTRUE)
void SetDataAsModel(TGo4FitData *iData, Bool_t iOwned)
virtual void Print(Option_t *option) const
virtual Bool_t Initialize(Int_t UseBuffers=-1)
virtual Bool_t Next(Bool_t UseRanges=kTRUE)
virtual void FillSlotList(TSeqCollection *lst)
virtual void FillSlotList(TSeqCollection *list)
virtual Double_t EvaluateAtPoint(TGo4FitData *data, Int_t nbin, Bool_t UseRanges=kTRUE)
Int_t NumAssigments() const
Definition: TGo4FitModel.h:124
virtual void FillSlotList(TSeqCollection *list)
Double_t FindDataPoint(Int_t NumIndexes, const Int_t *Indexes)
Double_t Value() const
Definition: TGo4FitData.h:514
const Int_t * Indexes() const
Definition: TGo4FitData.h:464
Bool_t ReachEnd() const
Definition: TGo4FitData.h:541
TObject * GetObject() const
TGo4FitData * GetDataAsModel() const
Int_t IndexesSize() const
Definition: TGo4FitData.h:459
virtual Bool_t BeforeEval(Int_t)
const Int_t * GetDataFullIndex(TGo4FitData *data, Int_t nbin)