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