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

/Go4Fit/TGo4FitParsList.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 "TGo4FitParsList.h"
00017 
00018 #include <iostream.h>
00019 #include <iomanip.h>
00020 
00021 #include "TClass.h"
00022 
00023 #include "TGo4FitParameter.h"
00024 
00025 TGo4FitParsList::TGo4FitParsList() : TGo4FitNamed(), fxPars(), fbCanRollbackPars(kFALSE) {
00026 
00027 }
00028 
00029 TGo4FitParsList::TGo4FitParsList(Bool_t IsParsOwned) : TGo4FitNamed(), fxPars(), fbCanRollbackPars(kFALSE) {
00030   fxPars.SetOwner(IsParsOwned);
00031 }
00032 
00033 TGo4FitParsList::TGo4FitParsList(const char* Name, const char* Title, Bool_t IsParsOwned) : TGo4FitNamed(Name,Title), fxPars(), fbCanRollbackPars(kFALSE) {
00034   fxPars.SetOwner(IsParsOwned);
00035 }
00036 
00037 TGo4FitParsList::~TGo4FitParsList() {
00038 }
00039 
00040 Int_t TGo4FitParsList::GetParIndex(const TGo4FitParameter* par) {
00041    for(Int_t i=0;i<NumPars();i++)
00042      if(GetPar(i)==par) return i;
00043    return -1;
00044 }
00045 
00046 Double_t TGo4FitParsList::GetParValue(const char* ParName) {
00047    TGo4FitParameter* par = Find(ParName);
00048    if(par) return par->GetValue();
00049       else return 0.;
00050 }
00051 
00052 Bool_t TGo4FitParsList::SetParValue(const char* ParName, Double_t iValue) {
00053    TGo4FitParameter* par = Find(ParName);
00054    if(par) { par->SetValue(iValue); return kTRUE; }
00055       else return kFALSE;
00056 }
00057 
00058 void TGo4FitParsList::GetParsValues(Double_t* pars) {
00059    for(Int_t i=0;i<NumPars();i++)
00060      pars[i] = Get(i)->GetValue();
00061 }
00062 
00063 void TGo4FitParsList::SetParsValues(Double_t* pars) {
00064    if (pars)
00065      for(Int_t i=0;i<NumPars();i++)
00066         Get(i)->SetValue(pars[i]);
00067 }
00068 
00069 Double_t TGo4FitParsList::GetParError(const char* ParName) {
00070    TGo4FitParameter* par = Find(ParName);
00071    if(par) return par->GetError();
00072       else return 0.;
00073 }
00074 
00075 Bool_t TGo4FitParsList::SetParError(const char* ParName, Double_t iError) {
00076    TGo4FitParameter* par = Find(ParName);
00077    if(par) { par->SetError(iError); return kTRUE; }
00078       else return kFALSE;
00079 }
00080 
00081 Bool_t TGo4FitParsList::SetParFixed(const char* ParName, Bool_t iFixed) {
00082    TGo4FitParameter* par = Find(ParName);
00083    if(par) { par->SetFixed(iFixed); return kTRUE; }
00084       else return kFALSE;
00085 }
00086 
00087 Bool_t TGo4FitParsList::GetParFixed(const char* ParName) {
00088    TGo4FitParameter* par = Find(ParName);
00089    if(par) return par->GetFixed();
00090       else return kFALSE;
00091 }
00092 
00093 Int_t TGo4FitParsList::NumFixedPars() {
00094   Int_t res = 0;
00095   for (Int_t n=0; n<NumPars(); n++)
00096      if (Get(n)->GetFixed()) res++;
00097   return res;
00098 }
00099 
00100 Int_t TGo4FitParsList::NumFreePars() {
00101   return NumPars()-NumFixedPars();
00102 }
00103 
00104 
00105 Bool_t TGo4FitParsList::SetParRange(const char* ParName, Double_t RangeMin, Double_t RangeMax) {
00106    TGo4FitParameter* par = Find(ParName);
00107    if(par) { par->SetRange(RangeMin,RangeMax); return kTRUE; }
00108       else return kFALSE;
00109 }
00110 
00111 Bool_t TGo4FitParsList::GetParRange(const char* ParName, Double_t& RangeMin, Double_t& RangeMax) {
00112    TGo4FitParameter* par = Find(ParName);
00113    if(par) return par->GetRange(RangeMin,RangeMax);
00114       else return kFALSE;
00115 }
00116 
00117 Bool_t TGo4FitParsList::SetParEpsilon(const char* ParName, Double_t Epsilon) {
00118    TGo4FitParameter* par = Find(ParName);
00119    if(par) { par->SetEpsilon(Epsilon); return kTRUE; }
00120       else return kFALSE;
00121 }
00122 
00123 Bool_t TGo4FitParsList::GetParEpsilon(const char* ParName, Double_t& Epsilon) {
00124    TGo4FitParameter* par = Find(ParName);
00125    if(par) return par->GetEpsilon(Epsilon);
00126       else return kFALSE;
00127 }
00128 
00129 
00130 void TGo4FitParsList::SetParName(Int_t n, const char* name) {
00131    if(Get(n)) Get(n)->SetName(name);
00132 }
00133 
00134 const char* TGo4FitParsList::GetParName(Int_t n) {
00135    if(Get(n)) return Get(n)->GetName();
00136          else return 0;
00137 }
00138 
00139 const char* TGo4FitParsList::GetParFullName(Int_t n) {
00140    if(Get(n)) return Get(n)->GetFullName();
00141          else return 0;
00142 }
00143 
00144 void TGo4FitParsList::SetParsNames(const char* name0, const char* name1, const char* name2, const char* name3, const char* name4,
00145                                    const char* name5, const char* name6, const char* name7, const char* name8, const char* name9) {
00146   SetParName(0,name0);
00147   SetParName(1,name1);
00148   SetParName(2,name2);
00149   SetParName(3,name3);
00150   SetParName(4,name4);
00151   SetParName(5,name5);
00152   SetParName(6,name6);
00153   SetParName(7,name7);
00154   SetParName(8,name8);
00155   SetParName(9,name9);
00156 }
00157 
00158 void TGo4FitParsList::SetParsValues(Double_t par0, Double_t par1, Double_t par2, Double_t par3, Double_t par4,
00159                                     Double_t par5, Double_t par6, Double_t par7, Double_t par8, Double_t par9) {
00160   if(Get(0)) Get(0)->SetValue(par0);
00161   if(Get(1)) Get(1)->SetValue(par1);
00162   if(Get(2)) Get(2)->SetValue(par2);
00163   if(Get(3)) Get(3)->SetValue(par3);
00164   if(Get(4)) Get(4)->SetValue(par4);
00165   if(Get(5)) Get(5)->SetValue(par5);
00166   if(Get(6)) Get(6)->SetValue(par6);
00167   if(Get(7)) Get(7)->SetValue(par7);
00168   if(Get(8)) Get(8)->SetValue(par8);
00169   if(Get(9)) Get(9)->SetValue(par9);
00170 }
00171 
00172 void TGo4FitParsList::MemorizePars() {
00173    for(Int_t i=0;i<NumPars();i++)
00174      Get(i)->MemorizeValue();
00175    fbCanRollbackPars = kTRUE;  
00176 }
00177 
00178 void TGo4FitParsList::RememberPars() {
00179   for(Int_t i=0;i<NumPars();i++)
00180     Get(i)->RememberValue();
00181 }
00182 
00183 Bool_t TGo4FitParsList::IsAllParsFixed() {
00184   for(Int_t i=0;i<NumPars();i++)
00185     if (!Get(i)->GetFixed()) return kFALSE;
00186   return kTRUE;
00187 }
00188 
00189 void TGo4FitParsList::Print(Option_t* option) const {
00190    TGo4FitParsList* lst = (TGo4FitParsList*) this;
00191    if ((lst->NumPars()>0) && fxPars.IsOwner()) {
00192       cout << "  List of parameters:" << endl;
00193       for(Int_t n=0;n<lst->NumPars();n++)
00194         lst->GetPar(n)->Print(option);
00195    }
00196 }
00197 
00198 void TGo4FitParsList::PrintPars() const {
00199    cout << endl << "*** LIST OF PARAMETERS VALUE ***" << endl;
00200    TGo4FitParsList* l = (TGo4FitParsList*) this;
00201    int oldprec = cout.precision(6);
00202    for(Int_t n=0;n<l->NumPars();n++)
00203      cout << setw(15) << l->GetParFullName(n)
00204           << " " << setw(10) << l->GetPar(n)->GetValue()
00205           << " " << setw(10) << l->GetPar(n)->GetError() << endl;
00206    cout.precision(oldprec);
00207 }
00208 
00209 void TGo4FitParsList::SetParsOwner(TGo4FitNamed* iOwner) {
00210    for(Int_t i=0;i<NumPars();i++)
00211       Get(i)->SetOwner(iOwner);
00212 }
00213 
00214 TGo4FitParameter* TGo4FitParsList::CreatePar(const char* ParName, const char* Title, Double_t iValue) {
00215   if (Find(ParName)==0) return AddPar(new TGo4FitParameter(ParName,Title,iValue));
00216                    else return Find(ParName);
00217 }
00218 
00219 TGo4FitParameter* TGo4FitParsList::Find(const char* ParName) {
00220    for(Int_t i=0;i<NumPars();i++)
00221       if (strcmp(Get(i)->GetName(),ParName)==0) return Get(i);
00222 
00223    for(Int_t i=0;i<NumPars();i++)
00224       if (strcmp(Get(i)->GetFullName(),ParName)==0) return Get(i);
00225 
00226    return 0;
00227 }
00228 
00229 TGo4FitParameter* TGo4FitParsList::Find(const char* OwnerFullName, const char* ParName) {
00230    for(Int_t i=0;i<NumPars();i++) {
00231       TGo4FitParameter* par = Get(i);
00232       if (par->GetOwner()==0) continue;
00233       if ( (strcmp(par->GetOwnerFullName(),OwnerFullName)==0) &&
00234            (strcmp(par->GetName(),ParName)==0) ) return par;
00235    }
00236    return 0;
00237 }
00238 
00239 TGo4FitParameter* TGo4FitParsList::Find(TGo4FitParameter* par) {
00240    for(Int_t i=0;i<NumPars();i++)
00241      if (Get(i)==par) return par;
00242    return 0;
00243 }
00244 
00245 Bool_t TGo4FitParsList::RemoveParByIndex(Int_t indx) {
00246   if((indx>=0) && (indx<NumPars())) return RemovePar(Get(indx));
00247                                else return kFALSE;
00248 }
00249 
00250 Bool_t TGo4FitParsList::RemovePar(const char* name) {
00251    return RemovePar(FindPar(name));
00252 }
00253 
00254 Bool_t TGo4FitParsList::RemovePar(TGo4FitParameter* par) {
00255    if (fxPars.FindObject(par)) {
00256       fbCanRollbackPars = kFALSE; 
00257       fxPars.Remove(par);
00258       if (fxPars.IsOwner()) delete par;
00259       return kTRUE;
00260    } else return kFALSE;
00261 }
00262 
00263 void TGo4FitParsList::CollectParsTo(TGo4FitParsList & list) {
00264   for(Int_t i=0;i<NumPars();i++) {
00265     TGo4FitParameter* par = Get(i);
00266     if (list.GetParIndex(par)<0) list.AddPar(par);
00267   }
00268 }
00269 
00270 void TGo4FitParsList::ClearParsBlocking() {
00271    for(Int_t i=0;i<NumPars();i++)
00272      Get(i)->ClearBlocked();
00273 }
00274 
00275 void TGo4FitParsList::ClearPars() { 
00276    fxPars.Clear(); 
00277    fbCanRollbackPars = kFALSE; 
00278 }
00279 
00280 
00281 TGo4FitParameter* TGo4FitParsList::AddPar(TGo4FitParameter* par) {
00282   fxPars.AddLast(par);
00283   if ((par!=0) && fxPars.IsOwner()) par->SetOwner(this);
00284   fbCanRollbackPars = kFALSE;
00285   return par;
00286 }
00287 
00288 TGo4FitParameter* TGo4FitParsList::InsertPar(TGo4FitParameter* par, Int_t indx) {
00289   if (indx<0) fxPars.AddLast(par);
00290          else fxPars.AddAt(par,indx);
00291   if ((par!=0) && fxPars.IsOwner()) par->SetOwner(this);
00292   fbCanRollbackPars = kFALSE;
00293   return par;
00294 }
00295 
00296 void TGo4FitParsList::Streamer(TBuffer& b) {
00297    if (b.IsReading()) {
00298      TGo4FitParsList::Class()->ReadBuffer(b, this);
00299      Bool_t IsOwner;
00300      b >> IsOwner;
00301      if (IsOwner) {
00302        fxPars.Streamer(b);
00303        SetParsOwner(this);
00304      }
00305    } else {
00306      TGo4FitParsList::Class()->WriteBuffer(b, this);
00307      b << fxPars.IsOwner();
00308      if (fxPars.IsOwner())
00309        fxPars.Streamer(b);
00310    }
00311 }
00312 
00313 ClassImp(TGo4FitParsList)
00314 
00315 //----------------------------END OF GO4 SOURCE FILE ---------------------

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