GSI Object Oriented Online Offline (Go4)  GO4-5.3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4FitModelFromData.cxx
Go to the documentation of this file.
1 // $Id: TGo4FitModelFromData.cxx 933 2013-01-29 15:27:58Z 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 für 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 "Riostream.h"
17 #include "TH1.h"
18 #include "TArrayI.h"
19 
20 #include "TGo4FitData.h"
21 #include "TGo4FitDataHistogram.h"
22 
23 TGo4FitModelFromData::TGo4FitModelFromData() : TGo4FitModel(), fxData(this, TGo4FitData::Class()), fxIter(0) {
24 }
25 
26 TGo4FitModelFromData::TGo4FitModelFromData(const char* iName, TGo4FitData *iDataAsModel, Bool_t Amplitude) :
27  TGo4FitModel(iName,"data used as model",Amplitude),
28  fxData("forModel", "Data, used to represent model component",
29  this, TGo4FitData::Class(), kTRUE, iDataAsModel, kTRUE), fxIter(0) {
30 }
31 
32 TGo4FitModelFromData::TGo4FitModelFromData(const char* iName, TH1* histo, Bool_t iOwned, Bool_t Amplitude) :
33  TGo4FitModel(iName,"data used as model",Amplitude),
34  fxData("forModel", "Data, used to represent model component",
35  this, TGo4FitData::Class(), kTRUE), fxIter(0) {
36  SetDataAsModel(new TGo4FitDataHistogram("Histogram",histo,iOwned), kTRUE);
37 }
38 
40 {
41  if (fxIter) delete fxIter;
42 }
43 
45 {
46  return dynamic_cast<TGo4FitData*> (fxData.GetObject());
47 }
48 
50  fxData.SetObject(iData,iOwned);
52 }
53 
54 Bool_t TGo4FitModelFromData::Initialize(Int_t UseBuffers) {
55  if (GetDataAsModel() == 0) return kFALSE;
56 
57  for(Int_t n=0;n<NumAssigments();n++)
58  if (GetAssignedConnection(n))
60  std::cout << "TGo4FitModelFromData: incompatible data used for model" << std::endl;
61  return kFALSE;
62  }
63 
64  return TGo4FitModel::Initialize(UseBuffers);
65 }
66 
68  if (fxIter!=0) { delete fxIter; fxIter = 0; }
69  if (GetDataAsModel()==0) return kFALSE;
71  if (fxIter==0) return kFALSE;
72  return fxIter->Reset(kFALSE);
73 }
74 
75 Double_t TGo4FitModelFromData::EvaluateAtPoint(TGo4FitData* data, Int_t nbin, Bool_t UseRanges) {
76  if (data==0) return 0.;
77  return FindDataPoint(GetDataIndexesSize(data), GetDataFullIndex(data,nbin));
78 }
79 
80 Double_t TGo4FitModelFromData::EvaluateAtPoint(TGo4FitDataIter* iter, Bool_t UseRanges) {
81  if (iter==0) return 0.;
82  return FindDataPoint(iter->IndexesSize(), iter->Indexes());
83 }
84 
86  if (fxIter!=0) { delete fxIter; fxIter = 0; }
87 }
88 
89 
90 void TGo4FitModelFromData::FillSlotList(TSeqCollection* list) {
92  list->Add(&fxData);
94 }
95 
96 void TGo4FitModelFromData::Print(Option_t* option) const {
97  TGo4FitModel::Print(option);
98  std::cout << "Model driven from data" << std::endl;
99  if (GetDataAsModel()) GetDataAsModel()->Print(option);
100 }
101 
102 Double_t TGo4FitModelFromData::FindDataPoint(Int_t NumIndexes, const Int_t* Indexes) {
103  if ((fxIter==0) || (fxIter->ReachEnd()) || (Indexes==0) || (NumIndexes!=fxIter->IndexesSize())) return 0.;
104  Int_t num = NumIndexes-1;
105  while (num>=0)
106  if (fxIter->Indexes()[num]==Indexes[num]) { num--; continue; } else
107  if (fxIter->Indexes()[num]>Indexes[num]) return 0.; else
108  if (!fxIter->Next(kFALSE)) return 0.;
109  return fxIter->Value();
110 }
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)