00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "TGo4FitComponent.h"
00017
00018 #include <iostream.h>
00019
00020 #include "TGo4FitSlot.h"
00021
00022 const UInt_t kExcludeCut = 0x00100000;
00023
00024 TGo4FitComponent::TGo4FitComponent() : TGo4FitParsList(), TGo4FitSlotList(),
00025 fxRangeAxis(), fxRangeValue(), fxCuts(), fiAmplIndex(-1), fbUseBuffers(kFALSE) {
00026 }
00027
00028 TGo4FitComponent::TGo4FitComponent(const char* iName, const char* iTitle) :
00029 TGo4FitParsList(iName,iTitle,kTRUE), TGo4FitSlotList(),
00030 fxRangeAxis(), fxRangeValue(), fxCuts(), fiAmplIndex(-1), fbUseBuffers(kFALSE) {
00031 fxCuts.SetOwner(kTRUE);
00032 }
00033
00034 TGo4FitComponent::~TGo4FitComponent() {
00035 }
00036
00037 TGo4FitParameter* TGo4FitComponent::NewParameter(const char* Name, const char* Title, Double_t iValue, Bool_t Fixed, Int_t AtIndx) {
00038 TGo4FitParameter* par = new TGo4FitParameter(Name, Title, iValue);
00039 if (AtIndx<0) AddPar(par);
00040 else InsertPar(par,AtIndx);
00041 if(Fixed) par->SetFixed(kTRUE);
00042 return par;
00043 }
00044
00045 TGo4FitParameter* TGo4FitComponent::NewAmplitude(const char* Name, Double_t iValue, Bool_t IsFixed, Int_t AtIndx) {
00046 TGo4FitParameter* par = 0;
00047 if (Name==0) par = new TGo4FitParameter("Ampl", "Amplitude", iValue);
00048 else par = new TGo4FitParameter(Name, "Amplitude", iValue);
00049 if (AtIndx<0) { AddPar(par); AtIndx = NumPars()-1; }
00050 else InsertPar(par,AtIndx);
00051 SetAmplIndex(AtIndx);
00052 if(IsFixed) par->SetFixed(kTRUE);
00053 return par;
00054 }
00055
00056 Bool_t TGo4FitComponent::MakeAmpl(Bool_t isFixed) {
00057 if (GetAmplPar()!=0) return kFALSE;
00058 NewAmplitude();
00059 if (isFixed) GetAmplPar()->SetFixed(kTRUE);
00060 return kTRUE;
00061 }
00062
00063 Bool_t TGo4FitComponent::RemoveAmpl() {
00064 if (GetAmplPar()==0) return kFALSE;
00065 RemoveParByIndex(GetAmplIndex());
00066 SetAmplIndex(-1);
00067 return kTRUE;
00068 }
00069
00070 void TGo4FitComponent::GetRangeCondition(Int_t n, Int_t& typ, Int_t& naxis, Double_t& left, Double_t& right) const {
00071 if ((n>=0) && (n<GetNumRangeCondition())) {
00072 Int_t naxis1 = fxRangeAxis[n*2];
00073 Int_t naxis2 = fxRangeAxis[n*2+1];
00074 Double_t value1 = fxRangeValue[n*2];
00075 Double_t value2 = fxRangeValue[n*2+1];
00076
00077 if ((naxis1<0) && (naxis2>0)) {
00078 typ = 0;
00079 naxis = -naxis1 - 1;
00080 left = value1;
00081 right = value2;
00082 } else
00083 if ((naxis1>0) && (naxis2<0)) {
00084 typ = 1;
00085 naxis = naxis1 - 1;
00086 left = value1;
00087 right = value2;
00088 } else
00089 if (naxis1<0) {
00090 typ = 2;
00091 naxis = -naxis1 - 1;
00092 left = value1;
00093 right = 0.;
00094 } else
00095 if (naxis1>0) {
00096 typ = 3;
00097 naxis = naxis1 - 1;
00098 left = 0.;
00099 right = value1;
00100 }
00101 }
00102 }
00103
00104 void TGo4FitComponent::SetRangeCondition(Int_t n, Int_t typ, Int_t naxis, Double_t left, Double_t right) {
00105 if ((n>=0) && (n<GetNumRangeCondition())) {
00106 Int_t naxis1, naxis2;
00107 Double_t value1, value2;
00108
00109 switch (typ) {
00110 case 0: naxis1 = -(naxis+1); value1 = left;
00111 naxis2 = +(naxis+1); value2 = right;
00112 break;
00113 case 1: naxis1 = +(naxis+1); value1 = left;
00114 naxis2 = -(naxis+1); value2 = right;
00115 break;
00116 case 2: naxis1 = -(naxis+1); value1 = left;
00117 naxis2 = 0; value2 = 0.;
00118 break;
00119 case 3: naxis1 = +(naxis+1); value1 = right;
00120 naxis2 = 0; value2 = 0.;
00121 break;
00122 default: return;
00123 }
00124
00125 fxRangeAxis[n*2] = naxis1;
00126 fxRangeAxis[n*2+1] = naxis2;
00127 fxRangeValue[n*2] = value1;
00128 fxRangeValue[n*2+1] = value2;
00129 }
00130 }
00131
00132 void TGo4FitComponent::AddRangeCondition(Int_t typ, Int_t naxis, Double_t left, Double_t right) {
00133 Int_t sz = fxRangeValue.GetSize()+2;
00134 fxRangeAxis.Set(sz); fxRangeValue.Set(sz);
00135 SetRangeCondition(sz/2-1,typ,naxis,left,right);
00136 }
00137
00138 void TGo4FitComponent::RemoveRangeCondition(Int_t n) {
00139 if ((n<0) || (n>=GetNumRangeCondition())) return;
00140
00141 Int_t indx = n*2;
00142 while (indx<fxRangeAxis.GetSize()-2) {
00143 fxRangeAxis[indx]=fxRangeAxis[indx+2];
00144 fxRangeValue[indx]=fxRangeValue[indx+2];
00145 indx+=1;
00146 }
00147 fxRangeAxis.Set(indx);
00148 fxRangeValue.Set(indx);
00149 }
00150
00151 void TGo4FitComponent::SetRange(Int_t naxis, Double_t min, Double_t max) {
00152 AddRangeCondition(0,naxis,min,max);
00153 }
00154
00155 void TGo4FitComponent::ExcludeRange(Int_t naxis, Double_t min, Double_t max) {
00156 AddRangeCondition(1,naxis,min,max);
00157 }
00158
00159 void TGo4FitComponent::SetRangeMin(Int_t naxis, Double_t value) {
00160 AddRangeCondition(2,naxis,value,0.);
00161 }
00162
00163 void TGo4FitComponent::SetRangeMax(Int_t naxis, Double_t value) {
00164 AddRangeCondition(3,naxis,0.,value);
00165 }
00166
00167 void TGo4FitComponent::ClearRanges(Int_t naxis) {
00168 if (naxis<0) { fxRangeAxis.Set(0); fxRangeValue.Set(0); fxCuts.Delete(); } else {
00169 Int_t indx = 0, dindx = 0;
00170 while (indx<fxRangeAxis.GetSize()) {
00171 if ( TMath::Abs(fxRangeAxis[indx]) != (naxis+1) ) {
00172 fxRangeAxis[dindx]=fxRangeAxis[indx];
00173 fxRangeAxis[dindx+1]=fxRangeAxis[indx+1];
00174 fxRangeValue[dindx]=fxRangeValue[indx];
00175 fxRangeValue[dindx+1]=fxRangeValue[indx+1];
00176 dindx+=2;
00177 }
00178 indx+=2;
00179 }
00180 fxRangeAxis.Set(dindx);
00181 fxRangeValue.Set(dindx);
00182 if ((naxis==0) || (naxis==1)) fxCuts.Delete();
00183 }
00184 }
00185
00186 Bool_t TGo4FitComponent::IsAnyRangeLimits() {
00187 return (GetNumRangeCondition()>0) || (GetNumRangeCut()>0);
00188 }
00189
00190 void TGo4FitComponent::AddRangeCut(TCutG* cut, Bool_t exclude) {
00191 cut->SetBit(kExcludeCut, exclude);
00192 fxCuts.Add(cut);
00193 }
00194
00195 Int_t TGo4FitComponent::GetNumRangeCut() const {
00196 return fxCuts.GetLast()+1;
00197 }
00198
00199 TCutG* TGo4FitComponent::GetRangeCut(Int_t n) const {
00200 return (n>=0) && (n<=fxCuts.GetLast()) ? dynamic_cast<TCutG*> (fxCuts.At(n)) : 0;
00201 }
00202
00203 Bool_t TGo4FitComponent::IsRangeCutExcluding(Int_t n) {
00204 TCutG* cut = GetRangeCut(n);
00205 return cut==0 ? kFALSE : cut->TestBit(kExcludeCut);
00206 }
00207
00208 void TGo4FitComponent::SetRangeCutExcluding(Int_t n, Bool_t exclude) {
00209 TCutG* cut = GetRangeCut(n);
00210 if (cut) cut->SetBit(kExcludeCut, exclude);
00211 }
00212
00213 void TGo4FitComponent::RemoveRangeCut(Int_t n) {
00214 TCutG* cut = GetRangeCut(n);
00215 if (cut) {
00216 fxCuts.Remove(cut);
00217 delete cut;
00218 fxCuts.Compress();
00219 }
00220 }
00221
00222 Bool_t TGo4FitComponent::GetRangeMin(Int_t naxis, Double_t& value) {
00223 Bool_t isany = kFALSE;
00224 for(Int_t indx=0;indx<fxRangeAxis.GetSize();indx+=2)
00225 if ( fxRangeAxis[indx] == -(naxis+1) ) {
00226 Double_t zn = fxRangeValue[indx];
00227 if( (!isany) || (zn<value) ) value = zn;
00228 isany = kTRUE;
00229 }
00230 if(naxis<2)
00231 for(Int_t ncut=0;ncut<GetNumRangeCut();ncut++) {
00232 TCutG* cut = GetRangeCut(ncut);
00233 if(cut->TestBit(kExcludeCut)) continue;
00234 Double_t* arr = naxis == 0 ? cut->GetX() : cut->GetY();
00235 Double_t zn = arr[0];
00236 for(Int_t i=1;i<cut->GetN();i++)
00237 if(arr[i]<zn) zn = arr[i];
00238 if( (!isany) || (zn<value) ) value = zn;
00239 isany = kTRUE;
00240 }
00241
00242 return isany;
00243 }
00244
00245 Bool_t TGo4FitComponent::GetRangeMax(Int_t naxis, Double_t& value) {
00246 Bool_t isany = kFALSE;
00247 Double_t zn;
00248 for(Int_t indx=0;indx<fxRangeAxis.GetSize();indx+=2) {
00249 if ( (fxRangeAxis[indx] == -(naxis+1)) && (fxRangeAxis[indx+1] == +(naxis+1))) zn = fxRangeValue[indx+1]; else
00250 if ( (fxRangeAxis[indx] == +(naxis+1)) && (fxRangeAxis[indx+1] == 0)) zn = fxRangeValue[indx]; else continue;
00251 if( (!isany) || (zn>value) ) value = zn;
00252 isany = kTRUE;
00253 }
00254 if(naxis<2)
00255 for(Int_t ncut=0;ncut<GetNumRangeCut();ncut++) {
00256 TCutG* cut = GetRangeCut(ncut);
00257 if(cut->TestBit(kExcludeCut)) continue;
00258 Double_t* arr = naxis == 0 ? cut->GetX() : cut->GetY();
00259 zn = arr[0];
00260 for(Int_t i=1;i<cut->GetN();i++)
00261 if(arr[i]>zn) zn = arr[i];
00262 if( (!isany) || (zn>value) ) value = zn;
00263 isany = kTRUE;
00264 }
00265
00266 return isany;
00267 }
00268
00269 Bool_t TGo4FitComponent::CheckRangeConditions(const Double_t* values, Int_t numaxis) {
00270 Int_t condsize = GetNumRangeCondition();
00271
00272 if ((condsize==0) && (GetNumRangeCut()==0)) return kTRUE;
00273
00274 Bool_t res1 = kTRUE, res2 = kTRUE;
00275
00276 Bool_t isanycond = kFALSE;
00277
00278 for(Int_t naxis=0;naxis<numaxis;naxis++) {
00279 Char_t resaxis1 = kTRUE, resaxis2 = kFALSE;
00280 Bool_t isany = kFALSE;
00281 for(Int_t ncond=0;ncond<condsize;ncond++) {
00282
00283 Int_t typ, axisnumber;
00284 Double_t left, right;
00285 GetRangeCondition(ncond, typ, axisnumber, left, right);
00286
00287 if (axisnumber != naxis) continue;
00288
00289 switch(typ) {
00290 case 0:
00291 isany = kTRUE;
00292 if((values[naxis]>=left) && (values[naxis]<=right)) resaxis2 = kTRUE;
00293 break;
00294 case 1:
00295 if((values[naxis]>=left) && (values[naxis]<=right)) resaxis1 = kFALSE;
00296 break;
00297 case 2: if(values[naxis]<left) resaxis1 = kFALSE; break;
00298 case 3: if(values[naxis]>right) resaxis1 = kFALSE; break;
00299 }
00300 }
00301
00302 res1 = res1 && resaxis1;
00303 if (!isany) resaxis2 = kTRUE;
00304 res2 = res2 && resaxis2;
00305 isanycond = isanycond || isany;
00306 if (!res1) break;
00307 }
00308
00309 if ( res1 && !(isanycond && res2) && (numaxis>1) && (GetNumRangeCut()>0)) {
00310 res2 = kFALSE;
00311 for (Int_t n=0;n<GetNumRangeCut();n++) {
00312 TCutG* cut = GetRangeCut(n);
00313 if (cut->IsInside(values[0],values[1]))
00314 if (cut->TestBit(kExcludeCut)) { res1 = kFALSE; break; }
00315 else { res2 = kTRUE; break; }
00316 }
00317 }
00318
00319 return res1 && res2;
00320 }
00321
00322 void TGo4FitComponent::CollectParsTo(TGo4FitParsList& list) {
00323 TGo4FitParsList::CollectParsTo(list);
00324 for(Int_t n=0;n<NumSlots();n++) {
00325 TGo4FitSlot* slot = GetSlot(n);
00326 if (slot && slot->GetOwned()) {
00327 TGo4FitParsList* pars = dynamic_cast<TGo4FitParsList*> (slot->GetObject());
00328 if (pars) pars->CollectParsTo(list);
00329 }
00330 }
00331 }
00332
00333 void TGo4FitComponent::Print(Option_t* option) const {
00334 cout << "***************************************************************************" << endl;
00335 TGo4FitNamed::Print(option);
00336 TGo4FitParsList::Print(option);
00337 cout << " Amplitude index: " << fiAmplIndex << endl;
00338
00339 for (Int_t ncond=0; ncond<GetNumRangeCondition(); ncond++) {
00340 if (ncond==0) cout << " Range selection: " << endl;
00341 Int_t typ, naxis;
00342 Double_t left, right;
00343 GetRangeCondition(ncond, typ, naxis, left, right);
00344
00345 cout << " axis " << naxis << " ";
00346
00347 switch(typ) {
00348 case 0:cout << " select range from " << left << " to " << right; break;
00349 case 1: cout << " exclude range from " << left << " to " << right; break;
00350 case 2: cout << " set left bound to " << left; break;
00351 case 3: cout << " set right bound to " << right; break;
00352 }
00353
00354 cout << endl;
00355 }
00356
00357 for (Int_t n=0;n<GetNumRangeCut();n++) {
00358 TCutG* cut = GetRangeCut(n);
00359 if (cut->TestBit(kExcludeCut)) cout << " Exclude"; else cout << " Include";
00360 cout << " axises ranges, using TCutG object " << endl;
00361 cut->Print(option);
00362 }
00363 }
00364
00365 ClassImp(TGo4FitComponent)
00366
00367