Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

/Go4Fit/TGo4FitModelFromData.cxx

Go to the documentation of this file.
00001 //---------------------------------------------------------------
00002 //        Go4 Release Package v2.10-5 (build 21005) 
00003 //                      03-Nov-2005
00004 //---------------------------------------------------------------
00005 //       The GSI Online Offline Object Oriented (Go4) Project
00006 //       Experiment Data Processing at DVEE department, GSI
00007 //---------------------------------------------------------------
00008 //
00009 //Copyright (C) 2000- Gesellschaft f. Schwerionenforschung, GSI
00010 //                    Planckstr. 1, 64291 Darmstadt, Germany
00011 //Contact:            http://go4.gsi.de
00012 //----------------------------------------------------------------
00013 //This software can be used under the license agreements as stated
00014 //in Go4License.txt file which is part of the distribution.
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 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Tue Nov 8 10:55:56 2005 for Go4-v2.10-5 by doxygen1.2.15