Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

TGo4FitParsList.cxx

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

Generated on Fri Nov 28 12:59:13 2008 for Go4-v3.04-1 by  doxygen 1.4.2