00001
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef TDSPVECTOR_H
00019 #define TDSPVECTOR_H
00020
00021 #include <Riostream.h>
00022 #include <TRandom.h>
00023 #include <TObject.h>
00024 #include <TGraph.h>
00025 #include <TError.h>
00026 #include <TH1.h>
00027 #include <TH2.h>
00028 #include <TFile.h>
00029 #include "TComplex.h"
00030
00031 #ifdef WIN32
00032 # include "../../config.h"
00033 #else
00034 # ifdef __MAKECINT__
00035 # include "../../config.h"
00036 # else
00037 # include "config.h"
00038 # endif
00039 #endif
00040
00041
00048 #ifdef HAVE_MATLAB
00049 class TmxArray;
00050 #endif
00051
00052 extern TComplexBase _twopi;
00053 extern TComplexBase _sqrt2;
00054 extern TComplexBase _inv_sqrt2;
00055
00056 #define kTDSPVector_Conv_MatchA 0x1
00057 #define kTDSPVector_Conv_MatchB 0x2
00058 #define kTDSPVector_Conv_Conj 0x4
00059 #define kTDSPVector_Conv_UseBlockLen 0x8
00060
00061 #define kTDSPVector_Conv_Defaults 0
00062
00063 #define kStrictNone 0
00064 #define kStrictWarning 1
00065 #define kStrictError 2
00066
00067 enum eXCorr_Options { kXCorrNone, kXCorrCoeff, kXCorrBiased, kXCorrUnBiased };
00068
00069 class TDSPVector : public TNamed {
00070
00071 static UInt_t fPerLine;
00072 static TH1 *fHistogram;
00073
00075
00076 Int_t fMinAlloc;
00077 Double_t fAllocHighScale;
00078 Double_t fAllocLowScale;
00079
00080
00081 protected:
00082
00083 static UInt_t fStrict;
00084 static Bool_t fATLAS;
00085 char* fXTitle;
00086 char* fYTitle;
00087 TComplex *fVec;
00088 Int_t Num;
00089 Int_t fPos;
00090
00091 TComplex *fAllocedVec;
00092 Int_t fAllocedNum;
00093 Double_t fSamplingRate;
00094 Int_t fZero;
00095
00096
00097 public:
00098
00099
00100
00101 static Bool_t LoadATLAS(char *name=NULL);
00102 static void EnableATLAS() { fATLAS=kTRUE;}
00103 static void DisableATLAS() { fATLAS=kFALSE;};
00104 static Bool_t UsingATLAS() { return fATLAS;};
00105
00106 Int_t Lo() const { return 0;};
00107 Int_t Hi() const { return Num-1;};
00108 void Swap(Int_t, Int_t);
00109 TComplex& Element(Int_t i) { return fVec[i];};
00110 TComplex *GetVec() { return fVec; };
00111 TComplex *MoveVec(Int_t n) { return fVec+=n;};
00112 Int_t GetLen() const { return Num; };
00113 Double_t GetTime() { return Num/fSamplingRate;};
00114 void Free();
00115 Int_t GetZero() { return fZero; };
00116 void SetZero(Int_t z) { fZero=z; };
00117 void SetVec(TComplex *s, Int_t num=-1);
00118 void ResetSignal() { fVec = fAllocedVec;};
00119 virtual void SetLen(Int_t num, Bool_t savedata=kFALSE);
00120 void SetMinLen(Int_t num);
00121 void Set(const TComplex&);
00122 void Set(Double_t);
00123 void Set(Int_t i, TDSPVector*,Int_t p=0,Int_t len=-1);
00124 void SetReal(Double_t);
00125 void SetImag(Double_t);
00126 void Zeros() { Set(0.0); };
00127 void Ones() { Set(1.0);};
00128 void Delta(Int_t pos=0) { Zeros(); (*this)(pos)=1; };
00129 void Step(TComplex& start, TComplex& step);
00130 void Step(TComplex& start);
00131 void Step(Double_t start, Double_t step=1.0);
00132 void Step();
00133 void ConjugateMe();
00134 void AdjointMe();
00135 TDSPVector* Adjoint(TDSPVector *out=NULL);
00136 void Append(TDSPVector*);
00137 Double_t Dist(TDSPVector*);
00138 Double_t Dist(TDSPVector&);
00139 Double_t Dist2(TDSPVector*);
00140 Double_t Dist2(TDSPVector&);
00141 TComplex Dot(TDSPVector*, Bool_t conj=kTRUE);
00142 TComplex Dot(TDSPVector&, Bool_t conj=kTRUE);
00143 Double_t Dot2(TDSPVector*);
00144 Double_t Dot2(TDSPVector&);
00145 void RandN(Double_t mean=0, Double_t sigma=1);
00146 void RandNreal(Double_t mean=0, Double_t sigma=1);
00147 void RandNimag(Double_t mean=0, Double_t sigma=1);
00148 void RandNC(Double_t sigma=1);
00149 void RandNC(TComplex&, Double_t sigma=1);
00150 void RandNC(TComplex *, Double_t sigma=1);
00151 void RandNC(TComplex *, TComplex *sigmas);
00152
00153 void RandNC(TDSPVector*, Double_t sigma=1);
00154 void RandNC(TDSPVector&, Double_t sigma=1);
00155 void RandNC(TDSPVector*, TDSPVector*sigmas);
00156 void RandPhase();
00157 void MultRandPhase(TDSPVector*in=NULL);
00158 void RandNPhase(Double_t variance=1,Double_t rate=1);
00159 void MultRandNPhase(Double_t variance=1,Double_t rate=1);
00160 void MultRandNPhase(Double_t variance,Double_t rate,TDSPVector*);
00161 void Reverse();
00162 void RandRayleigh(Double_t sigma=1,Double_t phase=0);
00163 void ModulateMe(TComplex, Double_t burstlen=0,Double_t burstoff=0,
00164 Double_t phase=0);
00165 TDSPVector* Modulate(TComplex, Double_t burstlen=0, Double_t burstoff=0,
00166 Double_t phase=0,
00167 TDSPVector* = NULL);
00168
00169 TDSPVector* DownSampling(UInt_t M, TDSPVector *pulse=NULL, TDSPVector *output=NULL);
00170
00171 TDSPVector* UpSampling( UInt_t K, TDSPVector *pulse=NULL, TDSPVector *output=NULL,
00172 UInt_t iStep=1, UInt_t iOff=0);
00173
00174 TDSPVector *Alias(TDSPVector *a=NULL, Int_t NewLen=0);
00175
00176 TComplex Sum(TDSPVector *weights=NULL) ;
00177 Double_t Sum2(TDSPVector *weights=NULL);
00178 TComplex Prod();
00179 Double_t ProdReal();
00180 Double_t ProdImag();
00181
00182
00183 Double_t Norm(TDSPVector *weights=NULL,Int_t p=2);
00184 Double_t Norm2(TDSPVector *weights=NULL) { return Sum2(weights);};
00185
00186 Double_t Energy() { return Norm2()/fSamplingRate;};
00187 Double_t Power() { return Num ? Norm2()/Num : 0;};
00188
00189 TComplex Mean(TDSPVector *weights=NULL);
00190 Double_t Mean2(TDSPVector *weights=NULL);
00191 Double_t Variance(TDSPVector *weights=NULL);
00192 Double_t Moment1(TDSPVector *x = NULL);
00193 Double_t Moment2(TDSPVector *x = NULL);
00194 Double_t CMoment2(TDSPVector *x = NULL);
00195 Double_t Max() { return MaxReal();};
00196 Double_t Min() { return MinReal();};
00197
00198 Double_t MaxReal();
00199 Double_t MinReal();
00200 Double_t MaxImag();
00201 Double_t MinImag();
00202
00203 Double_t MaxAbs2();
00204 Double_t MinAbs2();
00205
00206 Double_t MaxAbs() { return TMath::Sqrt(MaxAbs2());};
00207 Double_t MinAbs() { return TMath::Sqrt(MinAbs2());};
00208
00209 TDSPVector* GetPhase(TDSPVector*resul=NULL);
00210 void Phase();
00211 void Sqr();
00212 void Abs2() { Sqr();};
00213 void Abs();
00214 void Sqrt();
00215 void SqrtReal();
00216 void SqrtImag();
00217 void Exp();
00218 void Cos();
00219 void Sin();
00220 void Log();
00221 void Log10();
00222 void Log2();
00223 void Normalize(Double_t norm=1.0);
00224 TDSPVector *Dup() { return Copy(NULL);};
00225 TDSPVector *Copy(TDSPVector* n);
00226 void Apply(TComplex (*fcn)(TComplex&));
00227 void SetSamplingRate(Double_t s) { fSamplingRate = s;};
00228 Double_t GetSamplingRate() { return fSamplingRate; };
00229 void SamplingRate(Double_t s) { fSamplingRate *= s;};
00230 void Configure(TDSPVector*);
00231 void SetXTitle(char *name);
00232 void SetYTitle(char *name);
00233
00234 Int_t OnCodeInc(TDSPVector *Alphabet);
00235 Int_t OnCodeInc(TComplex *Alphabet,
00236 Int_t NumAlphabet);
00237 Int_t OnCodeSet(Int_t value,
00238 TDSPVector* al);
00239 Int_t OnCodeSet(Int_t value,
00240 TComplex* al,Int_t num_al);
00241 Int_t OnCodeGet(Int_t* value,
00242 TDSPVector* al);
00243 Int_t OnCodeGet(Int_t* value,
00244 TComplex* al,Int_t num_al);
00245
00246
00248
00249 TDSPVector* DivBy(TDSPVector *a, TDSPVector *result=NULL);
00250 TDSPVector* MultBy(TDSPVector *a, TDSPVector *result=NULL);
00251 TDSPVector* AddBy(TDSPVector *a, TDSPVector *result=NULL);
00252 TDSPVector* SubBy(TDSPVector *a, TDSPVector *result=NULL);
00253
00255
00256 TDSPVector* DivBy(TComplex a, TDSPVector *result=NULL);
00257 TDSPVector* MultBy(TComplex a, TDSPVector *result=NULL);
00258 TDSPVector* AddBy(TComplex a, TDSPVector *result=NULL);
00259 TDSPVector* SubBy(TComplex a, TDSPVector *result=NULL);
00260
00261 TDSPVector* Conv(TDSPVector* input,
00262 TDSPVector* output = NULL,
00263 Int_t opt = kTDSPVector_Conv_Defaults,
00264 Int_t b = 0);
00265
00266 void DumpParams(ostream *os = NULL);
00267
00268
00269 void FFTShiftMe();
00270 void IFFTShiftMe();
00271
00272 TDSPVector* XCorr(Int_t max_lags = 0,
00273 eXCorr_Options o = kXCorrNone) { return XCorr(this, NULL , max_lags, o);};
00274
00275 TDSPVector* XCorr(TDSPVector *i2,
00276 Int_t max_lags = 0,
00277 eXCorr_Options o = kXCorrNone) { return XCorr(i2, NULL , max_lags, o); };
00278
00279 TDSPVector* XCorr(TDSPVector *i2,
00280 TDSPVector *result,
00281 Int_t max_lags = 0,
00282 eXCorr_Options o = kXCorrNone);
00283
00284 TGraph* Graph(Option_t* = "complex", TGraph *in=NULL, Double_t dx=1.0, Double_t xoff=0.0);
00285 virtual void Draw(Option_t* = "ac", Double_t dx=1.0, Double_t xoff=0.0);
00286 TH1* FillAbs(TH1 *h = NULL);
00287 TH1* FillAbs2(TH1 *h = NULL);
00288 TH1* FillPhase(TH1 *h = NULL);
00289 TH1* FillReal(TH1 *h = NULL);
00290 TH1* FillImag(TH1 *h = NULL);
00291 TH2* Fill(TH2 *h = NULL);
00292 virtual void Print(Option_t*option="");
00293 void Input();
00294
00296
00298
00299
00300
00301 #ifdef HAVE_MATLAB
00302 TDSPVector &operator=(TmxArray &m);
00303 #endif
00304
00305 TDSPVector &operator=(const Double_t x) { Set(x); return *this;};
00306 TDSPVector &operator=(TDSPVector& x) { x.Copy(this);return *this;};
00307 TDSPVector &operator=(const TComplex& c) { Set(c); return *this;};
00308 TDSPVector &operator&=(const Double_t&);
00309
00310 TDSPVector &operator/=(const TComplex& d);
00311 TDSPVector &operator/=(const Double_t& d);
00312 TDSPVector &operator/=(const Int_t& d);
00313 TDSPVector &operator*=(const TComplex& d);
00314 TDSPVector &operator*=(const Double_t& d);
00315 TDSPVector &operator*=(const Int_t& d);
00316 TDSPVector &operator+=(const TComplex& d);
00317 TDSPVector &operator+=(const Double_t& d);
00318 TDSPVector &operator+=(const Int_t& d);
00319 TDSPVector &operator-=(const TComplex& d);
00320 TDSPVector &operator-=(const Double_t& d);
00321 TDSPVector &operator-=(const Int_t& d);
00322
00323 TDSPVector &operator+=(const TDSPVector&s);
00324 TDSPVector &operator-=(const TDSPVector&s);
00325 TDSPVector &operator*=(const TDSPVector&s);
00326 TComplex &operator()(Int_t index);
00327 TComplex &operator[](Int_t index);
00328
00329 static TDSPVector* Load(TFile* f, char *key);
00330 static TDSPVector* Load(char *fname, char *key);
00331
00332 void Save(TFile* f, char *key);
00333 void Save(char *fname , char *key, char *opt="RECREATE");
00334
00335
00336 TDSPVector(Int_t len=0);
00337 virtual ~TDSPVector();
00338
00339 static void ValuesPerLine(UInt_t p) { fPerLine = p;};
00340
00341 friend Bool_t operator==(TDSPVector &, TDSPVector &);
00342 friend istream &operator>>(istream&,TDSPVector&);
00343 friend ostream &operator<<(ostream&,TDSPVector&);
00344 friend istream &operator>>(istream&,TDSPVector*);
00345 friend ostream &operator<<(ostream&,TDSPVector*);
00346
00347 friend Double_t filternorm(TDSPVector *fir,
00348 TDSPVector *iir = NULL,
00349 UInt_t p = 2);
00350
00351 friend TDSPVector* filter(TDSPVector *in,
00352 TDSPVector *out,
00353 TDSPVector *fir,
00354 TDSPVector *iir=NULL);
00355
00356 friend void mult(TDSPVector *a,TDSPVector *b,
00357 TDSPVector *c);
00358
00359
00360 friend void econv(TDSPVector *a,
00361 TDSPVector *b,
00362 TDSPVector *c,
00363 Int_t offset = 0,
00364 Int_t step = 1,
00365 Int_t opt =kTDSPVector_Conv_Defaults );
00366
00367 ClassDef(TDSPVector,1)
00368
00369 };
00370
00371
00372 inline TDSPVector& TDSPVector::operator&=(const Double_t& d) {
00373 fVec[fPos++] = d;
00374 return *this;
00375 }
00376
00377 inline TDSPVector& TDSPVector::operator/=(const Double_t& d) {
00378 for(register Int_t i=0;i<Num;++i)
00379 fVec[i]/=d;
00380 return *this;
00381 }
00382
00383 inline TDSPVector& TDSPVector::operator/=(const Int_t& d) {
00384 for(register Int_t i=0;i<Num;++i)
00385 fVec[i]/=d;
00386 return *this;
00387
00388 }
00389
00390 inline TDSPVector& TDSPVector::operator/=(const TComplex& d) {
00391 for(register Int_t i=0;i<Num;++i)
00392 fVec[i]/=d;
00393 return *this;
00394 }
00395 inline TDSPVector& TDSPVector::operator*=(const Double_t& d) {
00396 for(register Int_t i=0;i<Num;++i)
00397 fVec[i]*=d;
00398 return *this;
00399 }
00400
00401 inline TDSPVector& TDSPVector::operator*=(const Int_t& d) {
00402 for(register Int_t i=0;i<Num;++i)
00403 fVec[i]*=d;
00404 return *this;
00405
00406 }
00407
00408 inline TDSPVector& TDSPVector::operator*=(const TComplex& d) {
00409 for(register Int_t i=0;i<Num;++i)
00410 fVec[i]*=d;
00411
00412 return *this;
00413 }
00414
00415 inline TDSPVector& TDSPVector::operator+=(const Double_t& d) {
00416 for(register Int_t i=0;i<Num;++i)
00417 fVec[i]+=d;
00418 return *this;
00419 }
00420
00421 inline TDSPVector& TDSPVector::operator+=(const Int_t& d) {
00422 for(register Int_t i=0;i<Num;++i)
00423 fVec[i]+=d;
00424 return *this;
00425
00426 }
00427
00428 inline TDSPVector& TDSPVector::operator+=(const TComplex& d) {
00429 for(register Int_t i=0;i<Num;++i)
00430 fVec[i]+=d;
00431 return *this;
00432 }
00433
00434
00435 inline TDSPVector& TDSPVector::operator-=(const Double_t& d) {
00436 for(register Int_t i=0;i<Num;++i)
00437 fVec[i]-=d;
00438 return *this;
00439 }
00440
00441 inline TDSPVector& TDSPVector::operator-=(const Int_t& d) {
00442 for(register Int_t i=0;i<Num;++i)
00443 fVec[i]-=d;
00444 return *this;
00445
00446 }
00447
00448 inline TDSPVector& TDSPVector::operator-=(const TComplex& d) {
00449 for(register Int_t i=0;i<Num;++i)
00450 fVec[i]-=d;
00451
00452 return *this;
00453 }
00454
00455
00456
00457
00458 inline void TDSPVector::SetVec(TComplex *s,Int_t l ) {
00459 if (l!=-1) Num = l;
00460 fVec = s;
00461 }
00462
00463 inline void TDSPVector::Set(const TComplex& c) {
00464 for(register Int_t i=0;i<Num;++i) fVec[i] = c;
00465 }
00466
00467 inline void TDSPVector::Set(Double_t d) {
00468 for(register Int_t i=0;i<Num;++i) { fVec[i].fRe = d; fVec[i].fIm = 0; };
00469 }
00470
00471 inline void TDSPVector::SetReal(Double_t d) {
00472 for(register Int_t i=0;i<Num;++i) fVec[i].fRe = d;
00473 }
00474
00475 inline void TDSPVector::SetImag(Double_t d) {
00476 for(register Int_t i=0;i<Num;++i) fVec[i].fIm = d;
00477 }
00478
00479 inline void TDSPVector::AdjointMe() {
00480 for(register Int_t i=0;i<Num;++i) fVec[i].fIm *= -1.0;
00481 }
00482
00483 inline TDSPVector* TDSPVector::Adjoint(TDSPVector *out) {
00484 if (!out) out = new TDSPVector();
00485 out->SetLen(Num);
00486 for(register Int_t i=0;i<Num;++i) {
00487 out->fVec[i].fRe=fVec[i].fRe;
00488 out->fVec[i].fIm=fVec[i].fIm * -1.0;
00489 }
00490 out->Configure(this);
00491 return out;
00492 }
00493
00494 inline void TDSPVector::Reverse() {
00495 Int_t n=Num/2;
00496 Int_t n1=Num-1;
00497 TComplex tmp;
00498 for(register Int_t i=0;i<n;++i) {
00499 tmp=fVec[n1-i];
00500 fVec[n1-i] = fVec[i];
00501 fVec[i]=tmp;
00502 }
00503 }
00504
00505 inline void TDSPVector::RandNreal(Double_t mean, Double_t sigma) {
00506 for(register Int_t i=0;i<Num;++i)
00507 fVec[i].fRe = gRandom->Gaus(mean,sigma);
00508 }
00509
00510 inline void TDSPVector::RandNimag(Double_t mean, Double_t sigma) {
00511 for(register Int_t i=0;i<Num;++i)
00512 fVec[i].fIm = gRandom->Gaus(mean,sigma);
00513 }
00514
00515 inline void TDSPVector::RandN(Double_t mean, Double_t sigma) {
00516 for(register Int_t i=0;i<Num;++i) {
00517 fVec[i].fRe = gRandom->Gaus(mean,sigma);
00518 fVec[i].fIm = 0;
00519 }
00520 }
00521
00522
00523 inline void TDSPVector::RandNC(TDSPVector& means, Double_t sigma) {
00524 RandNC(&means, sigma);
00525 }
00526
00527
00528
00529 inline void TDSPVector::Step(TComplex& start, TComplex& step) {
00530 TComplex s = start;
00531 for(register Int_t i=0;i<Num;++i) {
00532 fVec[i] = s;
00533 s+=step;
00534 }
00535 }
00536
00537 inline void TDSPVector::Step(TComplex& start) {
00538 TComplex s = start;
00539 for(register Int_t i=0;i<Num;++i) {
00540 fVec[i] = s;
00541 s+=1;
00542 }
00543 }
00544
00545 inline void TDSPVector::Step(Double_t start, Double_t step) {
00546 for(register Int_t i=0;i<Num;++i) {
00547 fVec[i] = start;
00548 start+=step;
00549 }
00550 }
00551
00552 inline void TDSPVector::Step() {
00553 for(register Int_t i=0;i<Num;++i)
00554 fVec[i] = i;
00555 }
00556
00557 inline void TDSPVector::RandRayleigh(Double_t sigma, Double_t phase) {
00558 TComplexBase tmp1,tmp2;
00559 for(register Int_t i=0;i<Num;++i) {
00560 tmp1=gRandom->Gaus(0,sigma);
00561 tmp2=gRandom->Gaus(0,sigma);
00562 tmp1=TMath::Sqrt(tmp1*tmp1+tmp2*tmp2);
00563
00564 fVec[i].fRe = TMath::Cos(phase)*tmp1;
00565 fVec[i].fIm = TMath::Sin(phase)*tmp1;
00566 }
00567 }
00568
00569 inline void TDSPVector::Sqr() {
00570 for(register Int_t i=0;i<Num;++i)
00571 fVec[i]= fVec[i].fRe*fVec[i].fRe + fVec[i].fIm*fVec[i].fIm;
00572 }
00573
00574
00575 inline void TDSPVector::Abs() {
00576 for(register Int_t i=0;i<Num;++i)
00577 fVec[i]= ::Abs(fVec[i]);
00578 }
00579
00580 inline void TDSPVector::Sqrt() {
00581 for(register Int_t i=0;i<Num;++i)
00582 fVec[i]= ::Sqrt(fVec[i]);
00583 }
00584
00585 inline void TDSPVector::Exp() {
00586 for(register Int_t i=0;i<Num;++i)
00587 fVec[i]= ::Exp(fVec[i]);
00588 }
00589 inline void TDSPVector::Log() {
00590 for(register Int_t i=0;i<Num;++i)
00591 fVec[i]= ::Log(fVec[i]);
00592 }
00593 inline void TDSPVector::Log10() {
00594 for(register Int_t i=0;i<Num;++i)
00595 fVec[i]= ::Log10(fVec[i]);
00596 }
00597 inline void TDSPVector::Log2() {
00598 for(register Int_t i=0;i<Num;++i)
00599 fVec[i]= ::Log2(fVec[i]);
00600 }
00601 inline void TDSPVector::Cos() {
00602 for(register Int_t i=0;i<Num;++i)
00603 fVec[i]= ::Cos(fVec[i]);
00604 }
00605 inline void TDSPVector::Phase() {
00606 for(register Int_t i=0;i<Num;++i)
00607 fVec[i]= fVec[i].Phase();
00608 }
00609 inline void TDSPVector::Sin() {
00610 for(register Int_t i=0;i<Num;++i)
00611 fVec[i]= ::Sin(fVec[i]);
00612 }
00613
00614 inline void TDSPVector::SqrtReal() {
00615 for(register Int_t i=0;i<Num;++i)
00616 fVec[i].fRe = TMath::Sqrt(fVec[i].fRe);
00617 }
00618
00619 inline void TDSPVector::SqrtImag() {
00620 for(register Int_t i=0;i<Num;++i)
00621 fVec[i].fIm = TMath::Sqrt(fVec[i].fIm);
00622 }
00623
00624 inline void TDSPVector::Normalize(Double_t norm) {
00625 Double_t f = norm/Norm();
00626 (*this)*=f;
00627 }
00628
00629
00630 inline Double_t TDSPVector::Dot2(TDSPVector *s) {
00631 Double_t dot2=0;
00632 if (s->GetSamplingRate()!=GetSamplingRate())
00633 Warning("Dot2","Sampling rates differ (%f != %f) !",GetSamplingRate(),s->GetSamplingRate());
00634 for(register Int_t i=0;i<Num;++i) {
00635 dot2 += fVec[i].fRe*s->fVec[i].fRe + fVec[i].fIm*s->fVec[i].fIm;
00636 }
00637
00638 return dot2;
00639 }
00640 inline Double_t TDSPVector::Dist2(TDSPVector& s) {
00641 return Dist2(&s);
00642 }
00643 inline Double_t TDSPVector::Dist(TDSPVector* s) {
00644 return TMath::Sqrt(Dist2(s));
00645 }
00646 inline Double_t TDSPVector::Dist(TDSPVector& s) {
00647 return Dist(&s);
00648 }
00649
00650 inline Double_t TDSPVector::Dot2(TDSPVector& s) {
00651 return Dot2(&s);
00652 }
00653 inline TComplex TDSPVector::Dot(TDSPVector* s, Bool_t conj) {
00654 if (s->GetSamplingRate()!=GetSamplingRate())
00655 Warning("Dot","Sampling rates differ (%f != %f) !",GetSamplingRate(),s->GetSamplingRate());
00656
00657 TComplex dot=0;
00658 if (conj)
00659 for(register Int_t i=0;i<Num;++i)
00660 dot += fVec[i] % s->fVec[i];
00661 else
00662 for(register Int_t i=0;i<Num;++i)
00663 dot += fVec[i] * s->fVec[i];
00664 return dot;
00665 }
00666 inline TComplex TDSPVector::Dot(TDSPVector& s, Bool_t conj) {
00667 return Dot(&s,conj);
00668 }
00669
00670 inline TComplex& TDSPVector::operator()(Int_t index) {
00671 if (fVec) {
00672 if ((index<Num)&&(index>=0))
00673 return fVec[index];
00674 else
00675 Error("operator()","index %d out of bounds (%d..%d)",index,0,Num-1);
00676 } else
00677 Error("operator()","vector not allocated (this->fVec=0x0)!");
00678 return ComplexZero;
00679 }
00680
00681 inline TComplex& TDSPVector::operator[](Int_t index) {
00682 return fVec[index];
00683 }
00684
00685 inline Bool_t operator ==(TDSPVector &z1, TDSPVector &z2) {
00686 if (z1.GetSamplingRate()!=z2.GetSamplingRate()) {
00687 Warning("Dot2","Sampling rates differ (%f != %f) - vectors are NOT equal !",z1.GetSamplingRate(),z2.GetSamplingRate());
00688 return kFALSE;
00689 }
00690 Int_t len1 = z1.GetLen();
00691 Int_t len2 = z2.GetLen();
00692
00693 TComplex *vec1 = z1.GetVec();
00694 TComplex *vec2 = z2.GetVec();
00695
00696 if (len2<len1) {
00697 register Int_t tmp = len1;
00698 len1=len2;
00699 len2=tmp;
00700 vec1 = z2.GetVec();
00701 vec2 = z1.GetVec();
00702 } else {
00703 vec1 = z1.GetVec();
00704 vec2 = z2.GetVec();
00705
00706 }
00707
00708 register Int_t i;
00709 for(i=0;i<len1;++i)
00710 if (vec1[i]!=vec2[i]) return kFALSE;
00711
00714
00715 for(;i<len2;++i)
00716 if (vec2[i].fRe || vec2[i].fIm) return kFALSE;
00717
00718 return kTRUE;
00719 }
00720
00721 inline void TDSPVector::Apply(TComplex (*fcn)(TComplex&)){
00722
00723 for(register Int_t i=0;i<Num;++i)
00724 fVec[i] = (*fcn)(fVec[i]);
00725
00726 }
00727
00728 inline TDSPVector* TDSPVector::Copy(TDSPVector *output){
00729
00730 if (!output) output = new TDSPVector();
00731
00732 output->SetLen(Num);
00733 TComplex *ovec = output->GetVec();
00734
00735 for(register Int_t i=0;i<Num;++i)
00736 ovec[i] = fVec[i];
00737
00738 output->Configure(this);
00739
00740 return output;
00741
00742 }
00743
00744 inline TDSPVector* TDSPVector::Alias(TDSPVector *a, Int_t NewNum) {
00745 if (!a) a = new TDSPVector();
00746 a->Free();
00747 a->Configure(this);
00748 if (!NewNum) NewNum=Num;
00749 a->SetVec(fVec,NewNum);
00750 return a;
00751 }
00752
00753 inline void TDSPVector::Configure(TDSPVector *s) {
00754 SetSamplingRate(s->GetSamplingRate());
00755 }
00756
00757
00758 inline Double_t TDSPVector::MaxReal() {
00759 Double_t max = fVec->fRe;
00760 Double_t m = 0;
00761 for(register Int_t i=1;i<Num;++i) if ((m=fVec[i].fRe)>max) max=m;
00762 return max;
00763 }
00764
00765 inline Double_t TDSPVector::MinReal() {
00766 Double_t min = fVec->fRe;
00767 Double_t m = 0;
00768 for(register Int_t i=1;i<Num;++i) if ((m=fVec[i].fRe)<min) min=m;
00769 return min;
00770 }
00771 inline Double_t TDSPVector::MaxImag() {
00772 Double_t max = fVec->fIm;
00773 Double_t m = 0;
00774 for(register Int_t i=1;i<Num;++i) if ((m=fVec[i].fIm)>max) max=m;
00775 return max;
00776 }
00777
00778 inline Double_t TDSPVector::MinImag() {
00779 Double_t min = fVec->fIm;
00780 Double_t m = 0;
00781 for(register Int_t i=1;i<Num;++i) if ((m=fVec[i].fIm)<min) min=m;
00782 return min;
00783 }
00784 inline Double_t TDSPVector::MaxAbs2() {
00785 Double_t max = fVec->fIm*fVec->fIm+fVec->fRe*fVec->fRe;
00786 Double_t m = 0;
00787 for(register Int_t i=1;i<Num;++i)
00788 if ((m=fVec[i].fIm*fVec[i].fIm+fVec[i].fRe*fVec[i].fRe)>max) max=m;
00789 return max;
00790 }
00791
00792 inline Double_t TDSPVector::MinAbs2() {
00793 Double_t min = fVec->fIm*fVec->fIm+fVec->fRe*fVec->fRe;
00794 Double_t m = 0;
00795 for(register Int_t i=1;i<Num;++i)
00796 if ((m=fVec[i].fIm*fVec[i].fIm+fVec[i].fRe*fVec[i].fRe)<min) min=m;
00797 return min;
00798 }
00799
00800 inline void TDSPVector::Swap(Int_t i, Int_t j) {
00801 TComplex tmp=fVec[i];
00802 fVec[i] = fVec[j];
00803 fVec[j] = tmp;
00804 }
00805
00806 inline TComplex TDSPVector::Mean(TDSPVector *weights) {
00807 if (weights) return Sum(weights)/weights->Norm2();
00808 return Sum(weights)/Num;
00809 }
00810 inline Double_t TDSPVector::Mean2(TDSPVector *weights) {
00811 if (weights) return Sum2(weights)/weights->Norm2();
00812 return Sum2(weights)/Num;
00813 }
00814
00815 #include <VectorRoutines.h>
00816
00817 #endif