00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "TGo4FitModelFromData.h"
00017
00018 #include "Riostream.h"
00019
00020 #include "TH1.h"
00021 #include "TArrayI.h"
00022
00023 #include "TGo4FitData.h"
00024 #include "TGo4FitDataHistogram.h"
00025
00026 TGo4FitModelFromData::TGo4FitModelFromData() : TGo4FitModel(), fxData(this, TGo4FitData::Class()), fxIter(0) {
00027 }
00028
00029 TGo4FitModelFromData::TGo4FitModelFromData(const char* iName, TGo4FitData *iDataAsModel, Bool_t Amplitude) :
00030 TGo4FitModel(iName,"data used as model",Amplitude),
00031 fxData("forModel", "Data, used to represent model component",
00032 this, TGo4FitData::Class(), kTRUE, iDataAsModel, kTRUE), fxIter(0) {
00033 }
00034
00035 TGo4FitModelFromData::TGo4FitModelFromData(const char* iName, TH1* histo, Bool_t iOwned, Bool_t Amplitude) :
00036 TGo4FitModel(iName,"data used as model",Amplitude),
00037 fxData("forModel", "Data, used to represent model component",
00038 this, TGo4FitData::Class(), kTRUE), fxIter(0) {
00039 SetDataAsModel(new TGo4FitDataHistogram("Histogram",histo,iOwned), kTRUE);
00040 }
00041
00042 TGo4FitModelFromData::~TGo4FitModelFromData()
00043 {
00044 if (fxIter) delete fxIter;
00045 }
00046
00047 TGo4FitData* TGo4FitModelFromData::GetDataAsModel() const
00048 {
00049 return dynamic_cast<TGo4FitData*> (fxData.GetObject());
00050 }
00051
00052 void TGo4FitModelFromData::SetDataAsModel(TGo4FitData* iData, Bool_t iOwned) {
00053 fxData.SetObject(iData,iOwned);
00054 SetUpdateSlotList();
00055 }
00056
00057 Bool_t TGo4FitModelFromData::Initialize(Int_t UseBuffers) {
00058 if (GetDataAsModel() == 0) return kFALSE;
00059
00060 for(Int_t n=0;n<NumAssigments();n++)
00061 if (GetAssignedConnection(n))
00062 if (!GetAssignedConnection(n)->IsCompatibleData(GetDataAsModel())) {
00063 cout << "TGo4FitModelFromData: incompatible data used for model" << endl;
00064 return kFALSE;
00065 }
00066
00067 return TGo4FitModel::Initialize(UseBuffers);
00068 }
00069
00070 Bool_t TGo4FitModelFromData::BeforeEval(Int_t) {
00071 if (fxIter!=0) { delete fxIter; fxIter = 0; }
00072 if (GetDataAsModel()==0) return kFALSE;
00073 fxIter = GetDataAsModel()->MakeIter();
00074 if (fxIter==0) return kFALSE;
00075 return fxIter->Reset(kFALSE);
00076 }
00077
00078 Double_t TGo4FitModelFromData::EvaluateAtPoint(TGo4FitData* data, Int_t nbin, Bool_t UseRanges) {
00079 if (data==0) return 0.;
00080 return FindDataPoint(GetDataIndexesSize(data), GetDataFullIndex(data,nbin));
00081 }
00082
00083 Double_t TGo4FitModelFromData::EvaluateAtPoint(TGo4FitDataIter* iter, Bool_t UseRanges) {
00084 if (iter==0) return 0.;
00085 return FindDataPoint(iter->IndexesSize(), iter->Indexes());
00086 }
00087
00088 void TGo4FitModelFromData::AfterEval() {
00089 if (fxIter!=0) { delete fxIter; fxIter = 0; }
00090 }
00091
00092
00093 void TGo4FitModelFromData::FillSlotList(TSeqCollection* list) {
00094 TGo4FitModel::FillSlotList(list);
00095 list->Add(&fxData);
00096 if (GetDataAsModel()) GetDataAsModel()->FillSlotList(list);
00097 }
00098
00099 void TGo4FitModelFromData::Print(Option_t* option) const {
00100 TGo4FitModel::Print(option);
00101 cout << "Model driven from data" << endl;
00102 if (GetDataAsModel()) GetDataAsModel()->Print(option);
00103 }
00104
00105 Double_t TGo4FitModelFromData::FindDataPoint(Int_t NumIndexes, const Int_t* Indexes) {
00106 if ((fxIter==0) || (fxIter->ReachEnd()) || (Indexes==0) || (NumIndexes!=fxIter->IndexesSize())) return 0.;
00107 Int_t num = NumIndexes-1;
00108 while (num>=0)
00109 if (fxIter->Indexes()[num]==Indexes[num]) { num--; continue; } else
00110 if (fxIter->Indexes()[num]>Indexes[num]) return 0.; else
00111 if (!fxIter->Next(kFALSE)) return 0.;
00112 return fxIter->Value();
00113 }
00114
00115