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