TGo4FitModelFromData.cxx

Go to the documentation of this file.
00001 // $Id: TGo4FitModelFromData.cxx 478 2009-10-29 12:26:09Z linev $
00002 //-----------------------------------------------------------------------
00003 //       The GSI Online Offline Object Oriented (Go4) Project
00004 //         Experiment Data Processing at EE department, GSI
00005 //-----------------------------------------------------------------------
00006 // Copyright (C) 2000- GSI Helmholtzzentrum für Schwerionenforschung GmbH
00007 //                     Planckstr. 1, 64291 Darmstadt, Germany
00008 // Contact:            http://go4.gsi.de
00009 //-----------------------------------------------------------------------
00010 // This software can be used under the license agreements as stated
00011 // in Go4License.txt file which is part of the distribution.
00012 //-----------------------------------------------------------------------
00013 
00014 #include "TGo4FitModelFromData.h"
00015 
00016 #include "Riostream.h"
00017 
00018 #include "TH1.h"
00019 #include "TArrayI.h"
00020 
00021 #include "TGo4FitData.h"
00022 #include "TGo4FitDataHistogram.h"
00023 
00024 TGo4FitModelFromData::TGo4FitModelFromData() : TGo4FitModel(), fxData(this, TGo4FitData::Class()), fxIter(0) {
00025 }
00026 
00027 TGo4FitModelFromData::TGo4FitModelFromData(const char* iName, TGo4FitData *iDataAsModel, Bool_t Amplitude) :
00028   TGo4FitModel(iName,"data used as model",Amplitude),
00029   fxData("forModel", "Data, used to represent model component",
00030           this, TGo4FitData::Class(), kTRUE, iDataAsModel, kTRUE), fxIter(0) {
00031 }
00032 
00033 TGo4FitModelFromData::TGo4FitModelFromData(const char* iName, TH1* histo, Bool_t iOwned, Bool_t Amplitude) :
00034    TGo4FitModel(iName,"data used as model",Amplitude),
00035    fxData("forModel", "Data, used to represent model component",
00036            this, TGo4FitData::Class(), kTRUE), fxIter(0) {
00037       SetDataAsModel(new TGo4FitDataHistogram("Histogram",histo,iOwned), kTRUE);
00038 }
00039 
00040 TGo4FitModelFromData::~TGo4FitModelFromData()
00041 {
00042    if (fxIter) delete fxIter;
00043 }
00044 
00045 TGo4FitData* TGo4FitModelFromData::GetDataAsModel() const
00046 {
00047    return dynamic_cast<TGo4FitData*> (fxData.GetObject());
00048 }
00049 
00050 void TGo4FitModelFromData::SetDataAsModel(TGo4FitData* iData, Bool_t iOwned) {
00051   fxData.SetObject(iData,iOwned);
00052   SetUpdateSlotList();
00053 }
00054 
00055 Bool_t TGo4FitModelFromData::Initialize(Int_t UseBuffers) {
00056    if (GetDataAsModel() == 0) return kFALSE;
00057 
00058    for(Int_t n=0;n<NumAssigments();n++)
00059      if (GetAssignedConnection(n))
00060         if (!GetAssignedConnection(n)->IsCompatibleData(GetDataAsModel())) {
00061             cout << "TGo4FitModelFromData: incompatible data used for model" << endl;
00062             return kFALSE;
00063          }
00064 
00065    return TGo4FitModel::Initialize(UseBuffers);
00066 }
00067 
00068 Bool_t TGo4FitModelFromData::BeforeEval(Int_t) {
00069   if (fxIter!=0) { delete fxIter; fxIter = 0; }
00070   if (GetDataAsModel()==0) return kFALSE;
00071   fxIter = GetDataAsModel()->MakeIter();
00072   if (fxIter==0) return kFALSE;
00073   return fxIter->Reset(kFALSE);
00074 }
00075 
00076 Double_t TGo4FitModelFromData::EvaluateAtPoint(TGo4FitData* data, Int_t nbin, Bool_t UseRanges) {
00077   if (data==0) return 0.;
00078   return FindDataPoint(GetDataIndexesSize(data), GetDataFullIndex(data,nbin));
00079 }
00080 
00081 Double_t TGo4FitModelFromData::EvaluateAtPoint(TGo4FitDataIter* iter, Bool_t UseRanges) {
00082    if (iter==0) return 0.;
00083    return FindDataPoint(iter->IndexesSize(), iter->Indexes());
00084 }
00085 
00086 void TGo4FitModelFromData::AfterEval() {
00087   if (fxIter!=0) { delete fxIter; fxIter = 0; }
00088 }
00089 
00090 
00091 void TGo4FitModelFromData::FillSlotList(TSeqCollection* list) {
00092   TGo4FitModel::FillSlotList(list);
00093   list->Add(&fxData);
00094   if (GetDataAsModel()) GetDataAsModel()->FillSlotList(list);
00095 }
00096 
00097 void TGo4FitModelFromData::Print(Option_t* option) const {
00098    TGo4FitModel::Print(option);
00099    cout << "Model driven from data"  << endl;
00100    if (GetDataAsModel()) GetDataAsModel()->Print(option);
00101 }
00102 
00103 Double_t TGo4FitModelFromData::FindDataPoint(Int_t NumIndexes, const Int_t* Indexes) {
00104    if ((fxIter==0) || (fxIter->ReachEnd()) || (Indexes==0) || (NumIndexes!=fxIter->IndexesSize())) return 0.;
00105    Int_t num = NumIndexes-1;
00106    while (num>=0)
00107      if (fxIter->Indexes()[num]==Indexes[num]) { num--; continue; } else
00108        if (fxIter->Indexes()[num]>Indexes[num]) return 0.; else
00109          if (!fxIter->Next(kFALSE)) return 0.;
00110    return fxIter->Value();
00111 }

Generated on Thu Oct 28 15:54:12 2010 for Go4-Fitpackagev4.04-2 by  doxygen 1.5.1