424 if (re)
fReIn.Set(n);
425 if (im)
fImIn.Set(n);
427 for (Int_t i=0; i<n; i++)
429 if (re)
fReIn.SetAt(re[i],i);
430 if (im)
fImIn.SetAt(im[i],i);
462 if (re) nre=re->GetSize();
463 if (im) nim=im->GetSize();
467 if (nre && nim>nre) n=nre;
468 if (nim && nre>nim) n=nim;
473 if (nre)
fReIn.Set(n);
474 if (nim)
fImIn.Set(n);
478 for (Int_t i=0; i<n; i++)
483 fReIn.SetAt(valre,i);
488 fImIn.SetAt(valim,i);
519 cout <<
" *" << ClassName() <<
"::Load* No input sample specified." << endl;
527 if (n<1 || !store || dim<1 || i<1 || i>dim)
529 cout <<
" *" << ClassName() <<
"::Load* Inconsistent input for NcSample treatment." << endl;
530 cout <<
" Store Mode:" << store <<
" Entries:" << n <<
" Dimension:" << dim <<
" i:" << i <<
" f:" <<
fSample << endl;
538 for (Int_t idx=1; idx<=n; idx++)
541 fReIn.SetAt(val,idx-1);
571 cout <<
" *" << ClassName() <<
"::Load* No input sample specified." << endl;
581 if (n<1 || !store || dim<1 || !i)
583 cout <<
" *" << ClassName() <<
"::Load* Inconsistent input for NcSample treatment." << endl;
584 cout <<
" Store Mode:" << store <<
" Entries:" << n <<
" Dimension:" << dim <<
" name:" << name <<
" f:" <<
fSample << endl;
615 cout <<
" *" << ClassName() <<
"::Load* No input histogram specified." << endl;
619 Int_t nbins=h->GetNbinsX();
620 Double_t nentries=h->GetEntries();
622 if (!nbins || !nentries)
624 cout <<
" *" << ClassName() <<
"::Load* Inconsistent input for histogram treatment." << endl;
625 cout <<
" Nbins:" << nbins <<
" Nentries:" << nentries <<
" f:" <<
fSample << endl;
633 for (Int_t i=1; i<=nbins; i++)
635 val=h->GetBinContent(i);
636 fReIn.SetAt(val,i-1);
664 cout <<
" *" << ClassName() <<
"::Load* No input TGraph object specified." << endl;
672 cout <<
" *" << ClassName() <<
"::Load* Inconsistent input for TGraph treatment." << endl;
673 cout <<
" n:" << n <<
" f:" <<
fSample << endl;
684 for (Int_t i=0; i<n; i++)
744 cout <<
" *" << ClassName() <<
"::SetWaveform* No data array specified." << endl;
753 for (Int_t i=0; i<n; i++)
784 cout <<
" *" << ClassName() <<
"::SetWaveform* No data array specified." << endl;
789 if (h) n=h->GetSize();
797 for (Int_t i=0; i<n; i++)
832 cout <<
" *" << ClassName() <<
"::SetWaveform* No data sample specified." << endl;
840 if (n<1 || !store || dim<1 || i<1 || i>dim)
842 cout <<
" *" << ClassName() <<
"::SetWaveform* Inconsistent input for NcSample treatment." << endl;
843 cout <<
" Store Mode:" << store <<
" Entries:" << n <<
" Dimension:" << dim <<
" i:" << i <<
" f:" <<
fSample << endl;
851 for (Int_t idx=1; idx<=n; idx++)
886 cout <<
" *" << ClassName() <<
"::SetWaveform* No data sample specified." << endl;
896 if (n<1 || !store || dim<1 || !i)
898 cout <<
" *" << ClassName() <<
"::SetWaveform* Inconsistent input for NcSample treatment." << endl;
899 cout <<
" Store Mode:" << store <<
" Entries:" << n <<
" Dimension:" << dim <<
" name:" << name <<
" f:" <<
fSample << endl;
931 cout <<
" *" << ClassName() <<
"::SetWaveform* No input histogram specified." << endl;
935 Int_t nbins=h->GetNbinsX();
936 Double_t nentries=h->GetEntries();
938 if (!nbins || !nentries)
940 cout <<
" *" << ClassName() <<
"::SetWaveform* Inconsistent input for histogram treatment." << endl;
941 cout <<
" Nbins:" << nbins <<
" Nentries:" << nentries <<
" f:" <<
fSample << endl;
949 for (Int_t i=1; i<=nbins; i++)
951 val=h->GetBinContent(i);
981 cout <<
" *" << ClassName() <<
"::SetWaveform* No input TGraph object specified." << endl;
989 cout <<
" *" << ClassName() <<
"::SetWaveform* Inconsistent input for TGraph treatment." << endl;
990 cout <<
" n:" << n <<
" f:" <<
fSample << endl;
1001 for (Int_t i=0; i<n; i++)
1003 gr->GetPoint(i,x,y);
1023 if (mode==1) n=
fNwf;
1055 if (sel.Contains(
"RE") && sel.Contains(
"in"))
return fReIn;
1056 if (sel.Contains(
"IM") && sel.Contains(
"in"))
return fImIn;
1057 if (sel.Contains(
"RE") && sel.Contains(
"out"))
return fReOut;
1058 if (sel.Contains(
"IM") && sel.Contains(
"out"))
return fImOut;
1059 if (sel.Contains(
"Hist"))
return fHisto;
1060 if (sel.Contains(
"Wave"))
return fWaveform;
1063 Double_t pi=acos(-1.);
1068 for (Int_t i=0; i<
fN; i++)
1070 if (sel.Contains(
"in"))
1075 if (sel.Contains(
"out"))
1080 amp=sqrt(re*re+im*im);
1082 if (im || re) phi=atan2(im,re);
1084 if (sel.Contains(
"AMP")) data.SetAt(amp,i);
1085 if (sel.Contains(
"PHIR")) data.SetAt(phi,i);
1086 if (sel.Contains(
"PHID")) data.SetAt(phi*180./pi,i);
1156 if (mode==
"C2C") opt=
"C2CFORWARD";
1157 if (mode==
"C2CI") opt=
"C2CBACKWARD";
1167 fProc=TVirtualFFT::FFT(1,&
fN,opt);
1170 Int_t nReIn=
fReIn.GetSize();
1171 Int_t nImIn=
fImIn.GetSize();
1174 Double_t* data=
fReIn.GetArray();
1175 fProc->SetPoints(data);
1179 for (Int_t i=0; i<
fN; i++)
1182 if (nReIn && !nImIn)
fProc->SetPoint(i,
fReIn[i],0);
1183 if (!nReIn && nImIn)
fProc->SetPoint(i,0,
fImIn[i]);
1197 for (Int_t i=0; i<
fN; i++)
1199 fProc->GetPointComplex(i,re,im);
1207 if (mode==
"C2R" || mode==
"C2CI") imode=-1;
1209 name.Form(
"DFT (%-s)",mode.Data());
1210 if (imode<0) name.Form(
"Inverse DFT (%-s)",mode.Data());
1213 TString opts[8]={
"RE",
"IM",
"AMP",
"dB",
"PHIR",
"PHID",
"CPHI",
"SPHI"};
1215 for (Int_t i=0; i<8; i++)
1217 if (sel.Contains(opts[i]))
1226 if (sel.Contains(
"n") || sel.Contains(
"t"))
1228 if (mode==
"C2C" || mode==
"C2CI") sel+=
" RE";
1296 if (!mode ||
fN<1)
return;
1305 fProc=TVirtualFFT::FFT(1,&
fN,
"DHT ES K");
1308 Double_t* data=
fReIn.GetArray();
1309 fProc->SetPoints(data);
1320 for (Int_t i=0; i<
fN; i++)
1322 re=
fProc->GetPointReal(i,kFALSE);
1328 TString name=
"Discrete Hartley Transform (DHT)";
1329 if (mode<0) name=
"Inverse Discrete Hartley Transform (IDHT)";
1394 if (abs(type)<1 || abs(type)>4 ||
fN<1 || (abs(type)==1 &&
fN<2))
return;
1398 if (type==-1 || type==-4) type2=abs(type);
1399 if (type==-2) type2=3;
1400 if (type==-3) type2=2;
1412 fProc=TVirtualFFT::SineCosine(1,&
fN,&kind,
"ES");
1415 Double_t* data=
fReIn.GetArray();
1416 fProc->SetPoints(data);
1427 for (Int_t i=0; i<
fN; i++)
1429 re=
fProc->GetPointReal(i,kFALSE);
1432 re/=sqrt(2.*(rN-1.));
1441 TString name=
"Discrete Cosine Transform (DCT-";
1442 if (type<0) name=
"Inverse Discrete Cosine Transform (IDCT-";
1443 if (abs(type)==1) name+=
"I)";
1444 if (abs(type)==2) name+=
"II)";
1445 if (abs(type)==3) name+=
"III)";
1446 if (abs(type)==4) name+=
"IV)";
1510 if (abs(type)<1 || abs(type)>4 ||
fN<1 || (abs(type)==1 &&
fN<2))
return;
1514 if (type==-1 || type==-4) type2=abs(type);
1515 if (type==-2) type2=3;
1516 if (type==-3) type2=2;
1528 fProc=TVirtualFFT::SineCosine(1,&
fN,&kind,
"ES K");
1531 Double_t* data=
fReIn.GetArray();
1532 fProc->SetPoints(data);
1543 for (Int_t i=0; i<
fN; i++)
1545 re=
fProc->GetPointReal(i,kFALSE);
1548 re/=sqrt(2.*(rN+1.));
1557 TString name=
"Discrete Sine Transform (DST-";
1558 if (type<0) name=
"Inverse Discrete Sine Transform (IDST-";
1559 if (abs(type)==1) name+=
"I)";
1560 if (abs(type)==2) name+=
"II)";
1561 if (abs(type)==3) name+=
"III)";
1562 if (abs(type)==4) name+=
"IV)";
1673 if (!mode ||
fN<1)
return;
1686 for (Int_t k=0; k<
fN; k++)
1721 for (Int_t n=0; n<
fN; n++)
1731 TString opts[8]={
"X",
"HT",
"AMP",
"dB",
"PHIR",
"PHID",
"CPHI",
"OMEGA"};
1733 for (Int_t i=0; i<8; i++)
1735 if (sel.Contains(opts[i]))
1755 sel.ReplaceAll(
"X",
"RE");
1756 sel.ReplaceAll(
"HT",
"IM");
1759 TString name=
"Discrete Hilbert Transform (DHIT)";
1760 if (mode<0) name=
"Inverse Discrete Hilbert Transform (IDHIT)";
1808 if (!mode ||
fN<1 || !hist)
return;
1811 Float_t maxfrac=0.5;
1812 if (sel.Contains(
"n") || sel.Contains(
"t") || sel.Contains(
"2"))
1818 if ((sel.Contains(
"Hz") || sel.Contains(
"t") || sel.Contains(
"OMEGA")) &&
fSample<=0)
return;
1820 if (sel.Contains(
"OMEGA") && !(sel.Contains(
"n")) && !(sel.Contains(
"t")))
return;
1831 if (sel.Contains(
"k"))
1833 hist->SetBins(n,0,n-1);
1834 title+=
"index frequency domain";
1841 title2.Form(
" (DAQ: %-.3g samples/sec)",
fSample);
1845 if (sel.Contains(
"RE")) title+=
";Re(Q[k])";
1846 if (sel.Contains(
"IM")) title+=
";Im(Q[k])";
1847 if (sel.Contains(
"AMP")) title+=
";Amplitude |Q[k]|";
1848 if (sel.Contains(
"dB")) title+=
";Amplitude |Q[k]| in dB";
1849 if (sel.Contains(
"PHIR")) title+=
";Phase #varphi[k] (rad)";
1850 if (sel.Contains(
"PHID")) title+=
";Phase #varphi[k] (deg)";
1851 if (sel.Contains(
"CPHI")) title+=
";cos(#varphi[k])";
1852 if (sel.Contains(
"SPHI")) title+=
";sin(#varphi[k])";
1853 if (!(title.Contains(
"[k]")))
1856 title+=
";Value Q[k]";
1859 if (sel.Contains(
"f"))
1861 hist->SetBins(n,0,maxfrac);
1862 title+=
"fractional frequency domain";
1869 title2.Form(
" (DAQ: %-.3g samples/sec)",
fSample);
1872 title+=
";Fraction f of sampling rate";
1873 if (sel.Contains(
"RE")) title+=
";Re(Q[f])";
1874 if (sel.Contains(
"IM")) title+=
";Im(Q[f])";
1875 if (sel.Contains(
"AMP")) title+=
";Amplitude |Q[f]|";
1876 if (sel.Contains(
"dB")) title+=
";Amplitude |Q[f]| in dB";
1877 if (sel.Contains(
"PHIR")) title+=
";Phase #varphi[f] (rad)";
1878 if (sel.Contains(
"PHID")) title+=
";Phase #varphi[f] (deg)";
1879 if (sel.Contains(
"CPHI")) title+=
";cos(#varphi[f])";
1880 if (sel.Contains(
"SPHI")) title+=
";sin(#varphi[f])";
1881 if (!(title.Contains(
"[f]")))
1884 title+=
";Value Q[f]";
1887 if (sel.Contains(
"Hz"))
1889 hist->SetBins(n,0,maxfrac*
fSample);
1890 title+=
"actual frequency domain";
1897 title2.Form(
" (DAQ: %-.3g samples/sec)",
fSample);
1900 title+=
";Frequency #nu (Hz)";
1901 if (sel.Contains(
"RE")) title+=
";Re(Q[#nu])";
1902 if (sel.Contains(
"IM")) title+=
";Im(Q[#nu])";
1903 if (sel.Contains(
"AMP")) title+=
";Amplitude |Q[#nu]|";
1904 if (sel.Contains(
"dB")) title+=
";Amplitude |Q[#nu]| in dB";
1905 if (sel.Contains(
"PHIR")) title+=
";Phase #varphi[#nu] (rad)";
1906 if (sel.Contains(
"PHID")) title+=
";Phase #varphi[#nu] (deg)";
1907 if (sel.Contains(
"CPHI")) title+=
";cos(#varphi[#nu])";
1908 if (sel.Contains(
"SPHI")) title+=
";sin(#varphi[#nu])";
1909 if (!(title.Contains(
"[#nu]")))
1912 title+=
";Value Q[#nu]";
1916 if (sel.Contains(
"n"))
1918 hist->SetBins(
fN,0,
fN);
1919 title+=
"sampling time domain";
1920 if (mode>0 && !(name.Contains(
"Hilbert"))) title+=
" input";
1923 title+=
";Sample number n";
1924 if (name.Contains(
"Hilbert"))
1926 if (sel.Contains(
"RE")) title+=
";Value X[n]";
1927 if (sel.Contains(
"IM")) title+=
";Value HT[n]";
1928 if (sel.Contains(
"AMP")) title+=
";Amplitude |Z[n]|";
1929 if (sel.Contains(
"dB")) title+=
";Amplitude |Z[n]| in dB";
1933 if (sel.Contains(
"RE")) title+=
";Re(X[n])";
1934 if (sel.Contains(
"IM")) title+=
";Im(X[n])";
1935 if (sel.Contains(
"AMP")) title+=
";Amplitude |X[n]|";
1936 if (sel.Contains(
"dB")) title+=
";Amplitude |X[n]| in dB";
1938 if (sel.Contains(
"PHIR")) title+=
";Phase #varphi[n] (rad)";
1939 if (sel.Contains(
"PHID")) title+=
";Phase #varphi[n] (deg)";
1940 if (sel.Contains(
"CPHI")) title+=
";cos(#varphi[n])";
1941 if (sel.Contains(
"SPHI")) title+=
";sin(#varphi[n])";
1942 if (sel.Contains(
"OMEGA")) title+=
";#omega[n] (rad/s)";
1943 if (!(title.Contains(
"[n]")))
1946 title+=
";Value X[n]";
1949 if (sel.Contains(
"t"))
1952 title+=
"actual time domain";
1953 if (mode>0 && !(name.Contains(
"Hilbert"))) title+=
" input";
1956 title+=
";Time t (seconds)";
1957 if (name.Contains(
"Hilbert"))
1959 if (sel.Contains(
"RE")) title+=
";Value X[t]";
1960 if (sel.Contains(
"IM")) title+=
";Value HT[t]";
1961 if (sel.Contains(
"AMP")) title+=
";Amplitude |Z[t]|";
1962 if (sel.Contains(
"dB")) title+=
";Amplitude |Z[t]| in dB";
1966 if (sel.Contains(
"RE")) title+=
";Re(X[t])";
1967 if (sel.Contains(
"IM")) title+=
";Im(X[t])";
1968 if (sel.Contains(
"AMP")) title+=
";Amplitude |X[t]|";
1969 if (sel.Contains(
"dB")) title+=
";Amplitude |X[t]| in dB";
1971 if (sel.Contains(
"PHIR")) title+=
";Phase #varphi[t] (rad)";
1972 if (sel.Contains(
"PHID")) title+=
";Phase #varphi[t] (deg)";
1973 if (sel.Contains(
"CPHI")) title+=
";cos(#varphi[t])";
1974 if (sel.Contains(
"SPHI")) title+=
";sin(#varphi[t])";
1975 if (sel.Contains(
"OMEGA")) title+=
";#omega[t] (rad/s)";
1976 if (!(title.Contains(
"[t]")))
1979 title+=
";Value X[t]";
1983 hist->SetTitle(title);
1985 Int_t nReIn=
fReIn.GetSize();
1986 Int_t nImIn=
fImIn.GetSize();
1987 Int_t nReOut=
fReOut.GetSize();
1988 Int_t nImOut=
fImOut.GetSize();
1989 Double_t pi=acos(-1.);
2003 Double_t fstep=1./(2.*double(
fN));
2004 if (name.Contains(
"DCT-I") &&
fN>1) fstep=1./(2.*double(
fN-1));
2005 if (name.Contains(
"DST-I")) fstep=1./(2.*double(
fN+1));
2008 for (Int_t i=0; i<n; i++)
2010 if (name.Contains(
"DCT-"))
2013 if (mode==3 || mode==-2 || abs(mode)==4) x+=0.5;
2015 if (name.Contains(
"DST-"))
2018 if (mode==3 || mode==-2 || abs(mode)==4) x-=0.5;
2021 if (sel.Contains(
"Hz")) x*=
fSample;
2023 if (sel.Contains(
"n") || sel.Contains(
"t"))
2027 if (name.Contains(
"Hilbert"))
2032 if (i<n-1) re2=
fReOut[i+1];
2037 if (i<n-1) im2=
fImOut[i+1];
2042 if (nReIn) re=
fReIn[i];
2043 if (nImIn) im=
fImIn[i];
2048 if (nReOut) re=
fReOut[i];
2049 if (nImOut) im=
fImOut[i];
2050 if (name.Contains(
"Hilbert") && i<n-1)
2052 if (nReOut) re2=
fReOut[i+1];
2053 if (nImOut) im2=
fImOut[i+1];
2061 if (nReIn) re=
fReIn[i];
2062 if (nImIn) im=
fImIn[i];
2066 if (nReOut) re=
fReOut[i];
2067 if (nImOut) im=
fImOut[i];
2070 if (name.Contains(
"DCT-") || name.Contains(
"DST-"))
2072 if (sel.Contains(
"f") || sel.Contains(
"Hz"))
2078 hist->SetBinContent(i+1,re);
2083 amp=sqrt(re*re+im*im);
2085 if (im || re) phi=atan2(im,re);
2089 if (
fSample>0 && i<n-1 && (im2 || re2))
2091 phi2=atan2(im2,re2);
2092 if ((phi2*phi)>=0) omega=fabs(phi2-phi)*
fSample;
2094 if (sel.Contains(
"RE")) hist->SetBinContent(i+1,re);
2095 if (sel.Contains(
"IM")) hist->SetBinContent(i+1,im);
2096 if (sel.Contains(
"AMP")) hist->SetBinContent(i+1,amp);
2097 if (amp<=0) amp=hist->GetMinimum();
2098 if (sel.Contains(
"dB"))
2103 amp=hist->GetMinimum();
2104 hist->SetBinContent(i+1,amp);
2108 hist->SetBinContent(i+1,20.*log10(amp));
2111 if (sel.Contains(
"PHIR")) hist->SetBinContent(i+1,phi);
2112 if (sel.Contains(
"PHID")) hist->SetBinContent(i+1,phi*180./pi);
2113 if (sel.Contains(
"CPHI")) hist->SetBinContent(i+1,cphi);
2114 if (sel.Contains(
"SPHI")) hist->SetBinContent(i+1,sphi);
2115 if (sel.Contains(
"OMEGA")) hist->SetBinContent(i+1,omega);
2120 for (Int_t i=0; i<n; i++)
2122 fHisto[i]=hist->GetBinContent(i+1);
2192 if (hist) hist->Reset();
2196 Int_t nx=x.GetSize();
2197 Int_t nh=h.GetSize();
2201 printf(
" *%-s::Convolve* Input or Waveform data are missing. Ninput=%-i Nwaveform=%-i \n",ClassName(),nx,nh);
2205 if (shift<0 || shift>2)
2207 printf(
" *%-s::Convolve* Invalid input argument shift=%-i \n",ClassName(),shift);
2222 for (Int_t ix=0; ix<nx; ix++)
2224 for (Int_t ih=0; ih<nh; ih++)
2227 y[ix+ih]=y[ix+ih]+x[ix]*h[ih];
2229 if (
fNorm==
"NONE" ||
fNorm==
"GNCC")
continue;
2233 x2[ix+ih]+=pow(x[ix],2);
2235 h2[ix+ih]+=pow(h[ih],2);
2248 for (Int_t i=0; i<nx; i++)
2252 for (Int_t i=0; i<nh; i++)
2258 for (Int_t i=0; i<ny; i++)
2261 if (val>0) y[i]=y[i]/val;
2264 else if (
fNorm==
"NCC")
2266 for (Int_t i=0; i<ny; i++)
2268 val=sqrt(x2[i]*h2[i]);
2269 if (val>0) y[i]=y[i]/val;
2284 for (Int_t ix=0; ix<nx; ix++)
2286 for (Int_t ih=0; ih<nh; ih++)
2290 if (!ns[iy])
continue;
2297 sx=sqrt(x2mean-pow(x1mean,2));
2298 sh=sqrt(h2mean-pow(h1mean,2));
2301 if (sxsh>0) val=(x[ix]-x1mean)*(h[ih]-h1mean)/(rn*sxsh);
2316 for (Int_t i=0; i<nx; i++)
2318 temp[i]=y[i+ioffset];
2334 title.Form(
"NcDSP Convolution result (%-g samples/sec);Time in seconds;Value",
fSample);
2335 if (shift==0 || shift==2)
2337 hist->SetBins(ny,0,
double(ny)/
fSample);
2346 title.Form(
"NcDSP Convolution result;Sample number;Value");
2347 if (shift==0 || shift==2)
2349 hist->SetBins(ny,0,ny);
2353 hist->SetBins(ny,-nh+1,nx);
2357 hist->SetTitle(title);
2358 hist->SetMarkerStyle(20);
2359 for (Int_t ibin=1; ibin<=ny; ibin++)
2361 hist->SetBinContent(ibin,y[ibin-1]);
2364 Double_t ymin=hist->GetMinimum();
2365 Double_t ymax=hist->GetMaximum();
2369 if (i1) xlow=hist->GetBinLowEdge(ilow+1);
2372 xup=hist->GetBinLowEdge(iup+1);
2373 xup+=hist->GetBinWidth(1);
2381 vline1=
new TLine(xlow,ymin,xlow,ymax);
2382 vline1->SetLineStyle(2);
2383 vline1->SetLineWidth(2);
2384 vline1->SetLineColor(4);
2388 vline2=
new TLine(xup,ymin,xup,ymax);
2389 vline2->SetLineStyle(2);
2390 vline2->SetLineWidth(2);
2391 vline2->SetLineColor(4);
2394 TList* hlist=hist->GetListOfFunctions();
2395 if (vline1) hlist->Add(vline1);
2396 if (vline2) hlist->Add(vline2);
2473 if (hist) hist->Reset();
2474 Int_t nx=
fReIn.GetSize();
2479 printf(
" *%-s::Correlate* Input or Waveform data are missing. Ninput=%-i Nwaveform=%-i \n",ClassName(),nx,nh);
2484 if (norm!=
"NONE" && norm!=
"GNCC" && norm!=
"NCC" && norm!=
"ZNCC")
2486 printf(
" *%-s::Correlate* Unsupported normalization mode : norm=%-s \n",ClassName(),norm.Data());
2493 for (Int_t i=1; i<=nh; i++)
2506 Int_t ny=y.GetSize();
2508 for (Int_t i=1; i<ny; i++)
2518 Int_t idx=imax-nh+1;
2522 if (peak) *peak=xpeak;
2532 title.Form(
"%-s Normalized Cross-Correlation (NCC): max. at lag=%-g sec. (%-g samples/sec)",ClassName(),xpeak,
fSample);
2534 else if (norm==
"ZNCC")
2536 title.Form(
"%-s Zero-Normalized Cross-Correlation (ZNCC): max. at lag=%-g sec. (%-g samples/sec)",ClassName(),xpeak,
fSample);
2538 else if (norm==
"GNCC")
2540 title.Form(
"%-s Globally Normalized Cross-Correlation (GNCC): max. at lag=%-g sec. (%-g samples/sec)",ClassName(),xpeak,
fSample);
2544 title.Form(
"%-s Unnormalized Cross-Correlation: max. at lag=%-g sec. (%-g samples/sec)",ClassName(),xpeak,
fSample);
2546 title+=
";Time lag in seconds;Cross-Correlation value";
2552 title.Form(
"%-s Normalized Cross-Correlation (NCC): max. at lag=%-i samplings",ClassName(),idx);
2554 else if (norm==
"ZNCC")
2556 title.Form(
"%-s Zero-Normalized Cross-Correlation (ZNCC): max. at lag=%-i samplings",ClassName(),idx);
2558 else if (norm==
"GNCC")
2560 title.Form(
"%-s Gobally Normalized Cross-Correlation (GNCC): max. at lag=%-i samplings",ClassName(),idx);
2564 title.Form(
"%-s Unnormalized Cross-Correlation: max. at lag=%-i samplings",ClassName(),idx);
2566 title+=
";Lag in samplings;Cross-Correlation value";
2568 hist->SetTitle(title);
2577TArrayD
NcDSP::Digitize(Int_t nbits,Double_t vcal,Int_t mode,TH1* hist,Double_t* stp,Double_t* scale)
const
2643 if (hist) hist->Reset();
2645 if (mode<0 || mode>3)
2647 cout <<
" *" << ClassName() <<
"::Digitize* Inconsistent input mode=" << mode << endl;
2651 if (!nbits || nbits>60 || nbits<-60 || fabs(vcal)<=0)
2653 cout <<
" *" << ClassName() <<
"::Digitize* Inconsistent input nbits=" << nbits <<
" vcal=" << vcal << endl;
2657 if ((mode==1 || mode==3) && nbits==1)
2659 cout <<
" *" << ClassName() <<
"::Digitize* Inconsistent input nbits=" << nbits <<
" mode=" << mode << endl;
2663 Bool_t logmode=kFALSE;
2664 if (nbits<0) logmode=kTRUE;
2668 Long_t nlevels=pow(2,nbits);
2669 Double_t range=fabs(vcal);
2670 if (mode==1 || mode==3) range*=2.;
2671 Double_t step=fabs(vcal);
2672 if (mode==0) step=range/double(nlevels-1);
2673 if (mode==1) step=range/double(nlevels-2);
2675 if (step<=0)
return arrdig;
2678 Long_t nstepsmax=nlevels-1;
2679 if ((mode==0 || mode==2) && vcal<0)
2681 nstepsmin=-nlevels+1;
2684 if (mode==1 || mode==3)
2686 nstepsmin=-nlevels/2;
2687 nstepsmax=nlevels/2-1;
2690 Double_t digvalmin=double(nstepsmin)*step;
2691 Double_t digvalmax=double(nstepsmax)*step;
2693 cout <<
" *" << ClassName() <<
"::Digitize* Parameters of the " << nbits <<
"-bits";
2694 if (logmode) cout <<
" Log10";
2695 cout <<
" ADC digitization." << endl;
2697 if (logmode) s=
"Log10";
2698 if (mode==0 || mode==2)
2700 cout <<
" Digitized " << s <<
" full scale range : [" << digvalmin <<
"," << digvalmax <<
"] Step size : " << step << endl;
2702 if (mode==1 || mode==3)
2704 cout <<
" Digitized " << s <<
" full scale range : [" << (digvalmin+step) <<
"," << digvalmax <<
"] Step size : " << step;
2705 cout <<
" Actual range : [" << digvalmin <<
"," << digvalmax <<
"]" << endl;
2710 Double_t linvalmin=pow(10,digvalmin);
2711 Double_t linvalmax=pow(10,digvalmax);
2712 if (mode==0 || mode==2)
2714 cout <<
" Digitized linear full scale range : [" << linvalmin <<
"," << linvalmax <<
"]" << endl;
2716 if (mode==1 || mode==3)
2718 cout <<
" Digitized linear full scale range : [" << (linvalmin*pow(10,step)) <<
"," << linvalmax <<
"]";
2719 cout <<
" Actual range : [" << linvalmin <<
"," << linvalmax <<
"]" << endl;
2729 if (vcal<0) *scale=digvalmin;
2730 if (vcal>0) *scale=digvalmax;
2732 if (mode==3) *scale=digvalmax;
2737 printf(
" === No waveform data present: Only listing of ADC specs.===\n");
2749 title.Form(
"NcDSP Digitize result (%-g samples/sec);Time in seconds;Value",
fSample);
2753 title.Form(
"NcDSP Digitize result;Sample number;Value");
2756 hist->SetMarkerStyle(20);
2757 hist->SetTitle(title);
2763 for (Int_t j=0; j<
fNwf; j++)
2776 cout <<
" *" << ClassName() <<
"::Digitize* Error: Non-positive input value encountered for Log10 ADC." << endl;
2783 if (nsteps<nstepsmin) nsteps=nstepsmin;
2784 if (nsteps>nstepsmax) nsteps=nstepsmax;
2786 digval=double(nsteps)*step;
2788 if (logmode) digval=pow(10,digval);
2792 if (hist) hist->SetBinContent(j+1,digval);
2798TArrayL64
NcDSP::ADC(Int_t nbits,Double_t range,Double_t Vbias,TArray* Vsig,TH1* hist,Int_t B,Int_t C)
const
2885 TArrayL64 arradc(0);
2886 if (hist) hist->Reset();
2889 Int_t nVsig=Vsig->GetSize();
2891 if (nbits<=0 || nbits>60 || !range || fabs(Vbias)>fabs(range) || B<0 || (B && C<1))
2893 printf(
"\n *%-s::ADC* Inconsistent input nbits=%-i range=%-g Vbias=%-g B=%-i C=%-i \n",ClassName(),nbits,range,Vbias,B,C);
2899 Long64_t N=pow(2,nbits);
2901 Long64_t adcmax=N-1;
2909 if (B==1) rB=exp(1);
2911 Double_t radcmax=adcmax;
2930 if (range<0) Vfs=pow(rB,-rC)*pow(rB,radcmax*rC/rN)*Vref;
2931 if (range>0) Vref=pow(rB,rC)*pow(rB,-radcmax*rC/rN)*Vfs;
2932 LSB=Vref*pow(rB,-rC)*(pow(rB,rC/rN)-1.);
2935 if (frac>0) ped=Long64_t(rN*(math.
Log(rB,frac)+rC)/rC);
2938 if (LSB<=0 || Vfs<=0)
2940 printf(
"\n *%-s::ADC* Inconsistent parameters : LSB=%-g Vfs=%-g \n",ClassName(),LSB,Vfs);
2944 if (!B) ped=Vbias/LSB;
2946 Double_t DR=20.*log10(Vfs/LSB);
2948 TString mode=
"linear";
2949 if (B==1) mode=
"Log_e";
2958 printf(
" *%-s::ADC* No input data have been provided --> Only the value of adc(Vbias) is returned. \n",ClassName());
2961 printf(
" Parameters for a %-i-bits %-s ADC with adc=[%-lli,%-lli] : \n",nbits,mode.Data(),adcmin,adcmax);
2962 printf(
" Vref=%-g Vfs=%-g LSB=%-g DR=%-g (dB) Vbias=%-g adc(Vbias)=%-lli \n",Vref,Vfs,LSB,DR,Vbias,ped);
2966 printf(
" Parameters for a %-i-bits %-s ADC with adc=[%-lli,%-lli] and a code efficiency factor of %-i: \n",nbits,mode.Data(),adcmin,adcmax,C);
2967 printf(
" Vref=%-g Vfs=%-g LSB=%-g DR=%-g (dB) Vbias=%-g adc(Vbias)=%-lli \n",Vref,Vfs,LSB,DR,Vbias,ped);
2981 hist->SetBins(nVsig,0,
double(nVsig)/
fSample);
2982 title.Form(
"%-s %-i-bits %-s ADC with Vfs=%-g LSB=%-g (%-g samples/sec);Time in seconds;ADC counts",ClassName(),nbits,mode.Data(),Vfs,LSB,
fSample);
2986 title.Form(
"%-s %-i-bits %-s ADC with Vfs=%-g LSB=%-g;Sample number;ADC counts",ClassName(),nbits,mode.Data(),Vfs,LSB);
2987 hist->SetBins(nVsig,0,nVsig);
2989 hist->SetMarkerStyle(20);
2990 hist->SetTitle(title);
2996 for (Int_t j=0; j<nVsig; j++)
2998 val=Vbias+Vsig->GetAt(j);
3004 if (frac>0) radcval=(rN/rC)*(math.
Log(rB,frac)+rC);
3011 adcval=Long64_t(radcval);
3014 if (adcval<adcmin) adcval=adcmin;
3015 if (adcval>adcmax) adcval=adcmax;
3019 if (hist) hist->SetBinContent(j+1,adcval);
3025TArrayD
NcDSP::DAC(Int_t nbits,Double_t range,Double_t Vbias,TArray* adcs,TArray* peds,TH1* hist,Int_t B,Int_t C)
const
3116 if (hist) hist->Reset();
3119 Int_t nadcs=adcs->GetSize();
3122 if (peds) npeds=peds->GetSize();
3124 if (nbits<=0 || nbits>60 || !range || fabs(Vbias)>fabs(range) || (peds && npeds<nadcs) || B<0 || (B && C<1))
3126 printf(
"\n *%-s::DAC* Inconsistent input nbits=%-i range=%-g Vbias=%-g nadcs=%-i npeds=%-i B=%-i C=%-i \n",ClassName(),nbits,range,Vbias,nadcs,npeds,B,C);
3134 Long64_t N=pow(2,nbits);
3136 Long64_t adcmax=N-1;
3144 if (B==1) rB=exp(1);
3146 Double_t radcmax=adcmax;
3165 if (range<0) Vfs=pow(rB,-rC)*pow(rB,radcmax*rC/rN)*Vref;
3166 if (range>0) Vref=pow(rB,rC)*pow(rB,-radcmax*rC/rN)*Vfs;
3167 LSB=Vref*pow(rB,-rC)*(pow(rB,rC/rN)-1.);
3170 if (frac>0) ped=Long64_t(rN*(math.
Log(rB,frac)+rC)/rC);
3173 if (LSB<=0 || Vfs<=0)
3175 printf(
"\n *%-s::DAC* Inconsistent parameters : LSB=%-g Vfs=%-g \n",ClassName(),LSB,Vfs);
3179 if (!B) ped=Vbias/LSB;
3181 Double_t DR=20.*log10(Vfs/LSB);
3183 TString mode=
"linear";
3184 if (B==1) mode=
"Log_e";
3193 printf(
" *%-s::DAC* No input data have been provided --> Only the value of adc(Vbias) is returned. \n",ClassName());
3196 printf(
" Parameters for a %-i-bits %-s DAC with adc=[%-lli,%-lli] : \n",nbits,mode.Data(),adcmin,adcmax);
3197 printf(
" Vref=%-g Vfs=%-g LSB=%-g DR=%-g (dB) Vbias=%-g adc(Vbias)=%-lli \n",Vref,Vfs,LSB,DR,Vbias,ped);
3201 printf(
" Parameters for a %-i-bits %-s DAC with adc=[%-lli,%-lli] and a code efficiency factor of %-i: \n",nbits,mode.Data(),adcmin,adcmax,C);
3202 printf(
" Vref=%-g Vfs=%-g LSB=%-g DR=%-g (dB) Vbias=%-g adc(Vbias)=%-lli \n",Vref,Vfs,LSB,DR,Vbias,ped);
3216 hist->SetBins(nadcs,0,
double(nadcs)/
fSample);
3217 title.Form(
"%-s %-i-bits %-s DAC with Vfs=%-g LSB=%-g (%-g samples/sec);Time in seconds;Amplitude",ClassName(),nbits,mode.Data(),Vfs,LSB,
fSample);
3221 title.Form(
"%-s %-i-bits %-s DAC with Vfs=%-g LSB=%-g;Sample number;Amplitude",ClassName(),nbits,mode.Data(),Vfs,LSB);
3222 hist->SetBins(nadcs,0,nadcs);
3224 hist->SetMarkerStyle(20);
3225 hist->SetTitle(title);
3231 for (Int_t j=0; j<nadcs; j++)
3238 dacval=Vref*pow(rB,-rC)*pow(rB,radc*rC/rN);
3252 if (B || (!B && !peds))
3254 dacval=dacval-Vbias;
3259 if (hist) hist->SetBinContent(j+1,dacval);
3265TArrayD
NcDSP::Transmit(Int_t nbits,Double_t range,Double_t Vbias,TArray* Vsig,TArray* peds,TH1* hist,Int_t B,Int_t C)
const
3329 if (hist) hist->Reset();
3332 if (!Vsig &&
fNwf<1)
3334 printf(
" *%-s::Transmit* Specifications for the ADC-DAC transmission chain. \n",ClassName());
3335 adcarr=
ADC(nbits,range,Vbias,0,0,B,C);
3337 dacarr[0]=adcarr[0];
3342 adcarr=
ADC(nbits,range,Vbias,Vsig,hist,B,C);
3345 dacarr=
DAC(nbits,range,Vbias,&adcarr,peds,hist,B,C);
3349 TString title=hist->GetTitle();
3350 title.ReplaceAll(
"DAC",
"ADC-DAC (Transmit)");
3351 hist->SetTitle(title);
3380 if (hist) hist->Reset();
3382 if (step<=0 || vmax<=vmin)
3384 cout <<
" *" << ClassName() <<
"::SampleAndHold* Error : Invalid input step=" << step <<
" vmin=" << vmin <<
" vmax=" << vmax << endl;
3389 Int_t n=(vmax-vmin)/step;
3394 hist->SetBins(n,vmin,vmax);
3395 TString sloc=
"start";
3396 if (!loc) sloc=
"center";
3397 if (loc>0) sloc=
"end";
3399 title.Form(
"NcDSP SampleAndHold for Function %-s in steps of %-.3g;X value;F(x) at the %-s of each step",(f.GetExpFormula(
"p")).Data(),step,sloc.Data());
3400 hist->SetTitle(title);
3401 hist->SetMarkerStyle(20);
3413 if (loc<0) xval=xlow;
3414 if (!loc) xval=xlow+step/2.;
3415 if (loc>0) xval=xlow+step;
3416 if (xval>vmax) xval=vmax;
3421 if (hist) hist->SetBinContent(i+1,data[i]);
3457 if (hist) hist->Reset();
3461 cout <<
" *" << ClassName() <<
"::SampleAndHold* Error : No waveform present." << endl;
3471 if (n<=0 || jmin<0 || jmin>=
fNwf || jmax<0 || jmax>=
fNwf)
3473 cout <<
" *" << ClassName() <<
"::SampleAndHold* Invalid input n=" << n <<
" jmin=" << jmin <<
" jmax=" << jmax << endl;
3479 if (
fNwf%n) ndata++;
3481 for (Int_t i=0; i<ndata; i++)
3489 for (Int_t i=0; i<ndata; i++)
3497 if (k<jmin)
continue;
3508 TString sloc=
"start";
3509 if (!loc) sloc=
"center";
3510 if (loc>0) sloc=
"end";
3514 Double_t fnew=
fSample/double(n);
3515 title.Form(
"NcDSP SampleAndHold over %-i original samplings (New: %-g samples/sec);Time in seconds;Value at the %-s of each new sample",n,fnew,sloc.Data());
3520 title.Form(
"NcDSP SampleAndHold over %-i original samplings;New sample number;Value at the %-s of each new sample",n,sloc.Data());
3521 hist->SetBins(ndata,jmin,jmax);
3523 hist->SetTitle(title);
3524 hist->SetMarkerStyle(20);
3525 for (Int_t i=1; i<=ndata; i++)
3527 hist->SetBinContent(i,data[i-1]);
3555 if (hist) hist->Reset();
3557 if (step<=0 || vmax<=vmin)
3559 cout <<
" *" << ClassName() <<
"::SampleAndSum* Error : Invalid input step=" << step <<
" vmin=" << vmin <<
" vmax=" << vmax << endl;
3564 Int_t n=(vmax-vmin)/step;
3566 for (Int_t i=0; i<n; i++)
3573 hist->SetBins(n,vmin,vmax);
3575 title.Form(
"NcDSP SampleAndSum for Function %-s with sampling steps of %-.3g;X value;Integral over each step",(f.GetExpFormula(
"p")).Data(),step);
3576 hist->SetTitle(title);
3577 hist->SetMarkerStyle(20);
3590 if (xup>vmax) xup=vmax;
3592 yval=f.Integral(xlow,xup);
3595 if (hist) hist->SetBinContent(i+1,data[i]);
3629 if (hist) hist->Reset();
3633 cout <<
" *" << ClassName() <<
"::SampleAndSum* Error : No waveform present." << endl;
3643 if (n<=0 || jmin<0 || jmin>=
fNwf || jmax<0 || jmax>=
fNwf)
3645 cout <<
" *" << ClassName() <<
"::SampleAndSum* Invalid input n=" << n <<
" jmin=" << jmin <<
" jmax=" << jmax << endl;
3651 if (
fNwf%n) ndata++;
3653 for (Int_t i=0; i<ndata; i++)
3660 for (Int_t i=0; i<ndata; i++)
3663 for (Int_t k=0; k<n; k++)
3665 if (j<jmin)
continue;
3678 Double_t fnew=
fSample/double(n);
3679 title.Form(
"NcDSP SampleAndSum over %-i original samplings;Time in seconds;Summed value per %-.3g seconds",n,1./fnew);
3684 title.Form(
"NcDSP SampleAndSum over %-i original samplings;New sample number;Summed value in each new sample",n);
3685 hist->SetBins(ndata,jmin,jmax);
3687 hist->SetTitle(title);
3688 hist->SetMarkerStyle(20);
3689 for (Int_t i=1; i<=ndata; i++)
3691 hist->SetBinContent(i,data[i-1]);
3792 if (hist) hist->Reset();
3793 if (hisf) hisf->Reset();
3794 Int_t nx=
fReIn.GetSize();
3798 printf(
" *%-s::FilterMovingAverage* No loaded input data present. \n",ClassName());
3802 if (n<1 || n>nx || (mode!=
"rec" && mode!=
"conv"))
3804 printf(
" *%-s::FilterMovingAverage* Inconsistent input n=%-i for x[%-i] and mode=%-s \n",ClassName(),n,nx,mode.Data());
3809 TArrayD xsave=
fReIn;
3825 if (i1 || i2) ny=nx;
3834 for (Int_t i=0; i<n; i++)
3841 for (Int_t k=1; k<ny; k++)
3844 if ((k+n-1)<nx) add=x[k+n-1];
3845 y[k]=y[k-1]-x[k-1]+add;
3850 for (Int_t i=0; i<ny; i++)
3863 title.Form(
"%-s;Time in seconds;Value",ClassName());
3864 hist->SetBins(ny,0,
double(ny)/
fSample);
3868 title.Form(
"%-s;Sample number;Value",ClassName());
3869 hist->SetBins(ny,0,ny);
3873 hist->SetTitle(title);
3876 for (Int_t ibin=1; ibin<=ny; ibin++)
3878 hist->SetBinContent(ibin,y[ibin-1]);
3884 Double_t ymin=hist->GetMinimum();
3885 Double_t ymax=hist->GetMaximum();
3889 if (i1) xlow=hist->GetBinLowEdge(*i1+1);
3892 xup=hist->GetBinLowEdge(*i2+1);
3893 xup+=hist->GetBinWidth(1);
3901 vline1=
new TLine(xlow,ymin,xlow,ymax);
3902 vline1->SetLineStyle(2);
3903 vline1->SetLineWidth(2);
3904 vline1->SetLineColor(4);
3908 vline2=
new TLine(xup,ymin,xup,ymax);
3909 vline2->SetLineStyle(2);
3910 vline2->SetLineWidth(2);
3911 vline2->SetLineColor(4);
3914 TList* hlist=hist->GetListOfFunctions();
3915 if (vline1) hlist->Add(vline1);
3916 if (vline2) hlist->Add(vline2);
3921 title.Form(
"%-s Moving Average (%-s mode) Filter: Time domain result averaged over %-i samples",ClassName(),mode.Data(),n);
3922 hist->SetTitle(title);
3932 title.Form(
"%-s Moving Average (%-s mode) Filter: Frequency domain result (%-i sample averaging in time domain)",ClassName(),mode.Data(),n);
3933 hisf->SetTitle(title);
4014 if (hisf) hisf->Reset();
4015 if (hist) hist->Reset();
4016 Int_t nx=
fReIn.GetSize();
4020 printf(
" *%-s::FilterLowPass* No loaded input data present. \n",ClassName());
4024 if (n<1 || fcut<=0 || fcut>0.5)
4026 printf(
" *%-s::FilterLowPass* Invalid input fcut=%-g n=%-i \n",ClassName(),fcut,n);
4031 TArrayD xsave=
fReIn;
4036 if (!odd && adaptn) n++;
4052 title.Form(
"%-s Low Pass Filter: Time domain result with #nu-cut=%-.3g Hz (%-i-point kernel)",ClassName(),nucut,n);
4056 title.Form(
"%-s Low Pass Filter: Time domain result with #nu-cut/#nu-sample=%-.3g (%-i-point kernel)",ClassName(),fcut,n);
4058 hist->SetTitle(title);
4072 title.Form(
"%-s Low Pass Filter: Frequency domain result with #nu-cut=%-.3g Hz (%-i-point time domain kernel)",ClassName(),nucut,n);
4076 title.Form(
"%-s Low Pass Filter: Frequency domain result with #nu-cut/#nu-sample=%-.3g (%-i-point time domain kernel)",ClassName(),fcut,n);
4078 hisf->SetTitle(title);
4159 if (hisf) hisf->Reset();
4160 if (hist) hist->Reset();
4161 Int_t nx=
fReIn.GetSize();
4165 printf(
" *%-s::FilterHighPass* No loaded input data present. \n",ClassName());
4169 if (n<1 || fcut<=0 || fcut>0.5)
4171 printf(
" *%-s::FilterHighPass* Invalid input fcut=%-g n=%-i \n",ClassName(),fcut,n);
4176 TArrayD xsave=
fReIn;
4181 if (!odd && adaptn) n++;
4197 title.Form(
"NcDSP High Pass Filter: Time domain result with #nu-cut=%-.3g Hz (%-i-point kernel)",nucut,n);
4201 title.Form(
"NcDSP High Pass Filter: Time domain result with #nu-cut/#nu-sample=%-.3g (%-i-point kernel)",fcut,n);
4203 hist->SetTitle(title);
4217 title.Form(
"NcDSP High Pass Filter: Frequency domain result with #nu-cut=%-.3g Hz (%-i-point time domain kernel)",nucut,n);
4221 title.Form(
"NcDSP High Pass Filter: Frequency domain result with #nu-cut/#nu-sample=%-.3g (%-i-point time domain kernel)",fcut,n);
4223 hisf->SetTitle(title);
4236TArrayD
NcDSP::FilterBandPass(Double_t f1,Double_t f2,Int_t n,TH1* hisf,Bool_t dB,TH1* hist,Int_t* i1,Int_t* i2,Bool_t adaptn)
4306 if (hisf) hisf->Reset();
4307 if (hist) hist->Reset();
4308 Int_t nx=
fReIn.GetSize();
4312 printf(
" *%-s::FilterBandPass* No loaded input data present. \n",ClassName());
4316 if (n<1 || f1<=0 || f1>0.5 || f2<=0 || f2>0.5 || f2<=f1)
4318 printf(
" *%-s::FilterBandPass* Invalid input f1=%-g f2=%-g n=%-i \n",ClassName(),f1,f2,n);
4323 TArrayD xsave=
fReIn;
4328 if (!odd && adaptn) n++;
4345 title.Form(
"NcDSP Band Pass Filter: Time domain result for [%-.3g,%-.3g] Hz (%-i-point kernel)",nu1,nu2,n);
4349 title.Form(
"NcDSP Band Pass Filter: Time domain result for #nu/#nu-sample=[%-.3g,%-.3g] (%-i-point kernel)",f1,f2,n);
4351 hist->SetTitle(title);
4366 title.Form(
"NcDSP Band Pass Filter: Frequency domain result for [%-.3g,%-.3g] Hz (%-i-point time domain kernel)",nu1,nu2,n);
4370 title.Form(
"NcDSP Band Pass Filter: Frequency domain result for #nu/#nu-sample=[%-.3g,%-.3g] (%-i-point time domain kernel)",f1,f2,n);
4372 hisf->SetTitle(title);
4454 if (hisf) hisf->Reset();
4455 if (hist) hist->Reset();
4456 Int_t nx=
fReIn.GetSize();
4460 printf(
" *%-s::FilterBandReject* No loaded input data present. \n",ClassName());
4464 if (n<1 || f1<=0 || f1>0.5 || f2<=0 || f2>0.5 || f2<=f1)
4466 printf(
" *%-s::FilterBandReject* Invalid input f1=%-g f2=%-g n=%-i \n",ClassName(),f1,f2,n);
4471 TArrayD xsave=
fReIn;
4476 if (!odd && adaptn) n++;
4493 title.Form(
"NcDSP Band Reject Filter: Time domain result for [%-.3g,%-.3g] Hz (%-i-point kernel)",nu1,nu2,n);
4497 title.Form(
"NcDSP Band Reject Filter: Time domain result for #nu/#nu-sample=[%-.3g,%-.3g] (%-i-point kernel)",f1,f2,n);
4499 hist->SetTitle(title);
4514 title.Form(
"NcDSP Band Reject Filter: Frequency domain result for [%-.3g,%-.3g] Hz (%-i-point time domain kernel)",nu1,nu2,n);
4518 title.Form(
"NcDSP Band Reject Filter: Frequency domain result for #nu/#nu-sample=[%-.3g,%-.3g] (%-i-point time domain kernel)",f1,f2,n);
4520 hisf->SetTitle(title);
4606 if (hisf) hisf->Reset();
4607 if (hist) hist->Reset();
4608 Int_t nx=
fReIn.GetSize();
4612 printf(
" *%-s::FilterMultiBand* No loaded input data present. \n",ClassName());
4616 Int_t arrsize=freqs.GetSize();
4617 Int_t oddsize=arrsize%2;
4618 Int_t nbands=arrsize/2;
4619 if (nbands<1 || n<1 || oddsize)
4621 printf(
" *%-s::FilterMultiBand* Invalid input array size=%-i nbands=%-i n=%-i \n",ClassName(),arrsize,nbands,n);
4626 TArrayD xsave=
fReIn;
4631 if (!odd && adaptn) n++;
4647 for (Int_t jband=1; jband<=nbands; jband++)
4650 flow=freqs.GetAt(index);
4651 fup=freqs.GetAt(index+1);
4654 if (!flow || !fup)
continue;
4663 title.Form(
"%-s MultiBand Filter: Time domain result for %-i bands (%-i-point kernel each)",ClassName(),neff,n);
4664 hist->SetTitle(title);
4674 title.Form(
"%-s MultiBand Filter: Frequency domain result for %-i bands (%-i-point time domain kernel each)",ClassName(),neff,n);
4675 hisf->SetTitle(title);
4731 if (hisf) hisf->Reset();
4732 if (hist) hist->Reset();
4736 printf(
" *%-s::GetMovingAverageKernel* Invalid input n=%-i \n",ClassName(),n);
4741 TArrayD xsave=
fReIn;
4745 for (Int_t i=0; i<n; i++)
4756 title.Form(
"NcDSP Moving Average Filter: Frequency domain kernel (%-i-point time domain kernel)",n);
4757 hisf->SetTitle(title);
4762 title.Form(
"NcDSP Moving Average Filter: Time domain kernel (%-i-point zero padded)",n);
4763 hist->SetTitle(title);
4827 if (hisf) hisf->Reset();
4829 if (n<1 || fcut<=0 || fcut>0.5)
4831 printf(
" *%-s::GetLowPassKernel* Invalid input fcut=%-g n=%-i \n",ClassName(),fcut,n);
4836 TArrayD xsave=
fReIn;
4841 if (!odd && adaptn) n++;
4843 Double_t twopi=2.*acos(-1.);
4849 for (Int_t i=0; i<=m; i++)
4858 h[i]=sin(twopi*fcut*
double(i-m/2))*(0.42-0.5*cos(twopi*ri/rm)+0.08*cos(2.*twopi*ri/rm))/
double(i-m/2);
4864 for (Int_t i=0; i<n; i++)
4878 title.Form(
"NcDSP Low Pass Filter: Frequency domain kernel with #nu-cut=%-.3g Hz (%-i-point time domain kernel)",nucut,n);
4882 title.Form(
"NcDSP Low Pass Filter: Frequency domain kernel with #nu-cut/#nu-sample=%-.3g (%-i-point time domain kenel)",fcut,n);
4884 hisf->SetTitle(title);
4892 title.Form(
"NcDSP Low Pass Filter: Time domain kernel (%-i-point zero padded) with #nu-cut=%-.3g Hz",n,nucut);
4896 title.Form(
"NcDSP Low Pass Filter: Time domain kernel (%-i-point zero padded) with #nu-cut/#nu-sample=%-.3g",n,fcut);
4898 hist->SetTitle(title);
4962 if (hisf) hisf->Reset();
4964 if (n<1 || fcut<=0 || fcut>0.5)
4966 printf(
" *%-s::GetHighPassKernel* Invalid input fcut=%-g n=%-i \n",ClassName(),fcut,n);
4971 TArrayD xsave=
fReIn;
4976 if (!odd && adaptn) n++;
4982 for (Int_t i=0; i<n; i++)
4997 title.Form(
"NcDSP High Pass Filter: Frequency domain kernel with #nu-cut=%-.3g Hz (%-i-point time domain kernel)",nucut,n);
5001 title.Form(
"NcDSP High Pass Filter: Frequency domain kernel with #nu-cut/#nu-sample=%-.3g (%-i-point time domain kernel)",fcut,n);
5003 hisf->SetTitle(title);
5011 title.Form(
"NcDSP High Pass Filter: Time domain kernel (%-i-point zero padded) with #nu-cut=%-.3g Hz",n,nucut);
5015 title.Form(
"NcDSP High Pass Filter: Time domain kernel (%-i-point zero padded) with #nu-cut/#nu-sample=%-.3g",n,fcut);
5017 hist->SetTitle(title);
5083 if (hisf) hisf->Reset();
5085 if (n<1 || f1<=0 || f1>0.5 || f2<=0 || f2>0.5 || f2<=f1)
5087 printf(
" *%-s::GetBandPassKernel* Invalid input f1=%-g f2=%-g n=%-i \n",ClassName(),f1,f2,n);
5092 TArrayD xsave=
fReIn;
5097 if (!odd && adaptn) n++;
5103 for (Int_t i=0; i<n; i++)
5119 title.Form(
"NcDSP Band Pass Filter: Frequency domain kernel for [%-.3g,%-.3g] Hz (%-i-point time domain kernel)",nu1,nu2,n);
5123 title.Form(
"NcDSP Band Pass Filter: Frequency domain kernel for #nu/#nu-sample=[%-.3g,%-.3g] (%-i-point time domain kernel)",f1,f2,n);
5125 hisf->SetTitle(title);
5134 title.Form(
"NcDSP Band Pass Filter: Time domain kernel (%-i-point zero padded) for [%-.3g,%-.3g] Hz",n,nu1,nu2);
5138 title.Form(
"NcDSP Band Pass Filter: Time domain kernel (%-i-point zero padded) for #nu/#nu-sample=[%-.3g,%-.3g]",n,f1,f2);
5140 hist->SetTitle(title);
5205 if (hisf) hisf->Reset();
5207 if (n<1 || f1<=0 || f1>0.5 || f2<=0 || f2>0.5 || f2<=f1)
5209 printf(
" *%-s::GetBandRejectKernel* Invalid input f1=%-g f2=%-g n=%-i \n",ClassName(),f1,f2,n);
5214 TArrayD xsave=
fReIn;
5219 if (!odd && adaptn) n++;
5229 for (Int_t i=0; i<n; i++)
5231 h[i]=hlow[i]+hhigh[i];
5244 title.Form(
"NcDSP Band Reject Filter: Frequency domain kernel for [%-.3g,%-.3g] Hz (%-i-point time domain kernel)",nu1,nu2,n);
5248 title.Form(
"NcDSP Band Reject Filter: Frequency domain kernel for #nu/#nu-sample=[%-.3g,%-.3g] (%-i-point time domain kernel)",f1,f2,n);
5250 hisf->SetTitle(title);
5259 title.Form(
"NcDSP Band Reject Filter: Time domain kernel (%-i-point zero padded) for [%-.3g,%-.3g] Hz",n,nu1,nu2);
5263 title.Form(
"NcDSP Band Reject Filter: Time domain kernel (%-i-point zero padded) for #nu/#nu-sample=[%-.3g,%-.3g]",n,f1,f2);
5265 hist->SetTitle(title);
5335 if (hisf) hisf->Reset();
5337 Int_t arrsize=freqs.GetSize();
5338 Int_t oddsize=arrsize%2;
5339 Int_t nbands=arrsize/2;
5340 if (nbands<1 || n<1 || oddsize)
5342 printf(
" *%-s::GetMultiBandKernel* Invalid input array size=%-i nbands=%-i n=%-i \n",ClassName(),arrsize,nbands,n);
5347 TArrayD xsave=
fReIn;
5352 if (!odd && adaptn) n++;
5361 for (Int_t jband=1; jband<=nbands; jband++)
5364 flow=freqs.GetAt(index);
5365 fup=freqs.GetAt(index+1);
5368 if (!flow || !fup)
continue;
5400 title.Form(
"%-s MultiBand Filter: Frequency domain kernel for %-i bands (%-i-point time domain kernel each)",ClassName(),neff,n);
5401 hisf->SetTitle(title);
5406 title.Form(
"%-s MultiBand Filter: Time domain kernel (zero padded) for %-i bands (%-i-point kernel each)",ClassName(),neff,n);
5407 hist->SetTitle(title);
5434 if (hisf) hisf->Reset(
"M");
5435 if (hist) hist->Reset(
"M");
5439 Int_t nh=h->GetSize();
5459 for (Int_t i=0; i<nh; i++)
5461 arr[nfront+i]=h->GetAt(i);
5466 hist->SetTitle(
"NcDSP HistogramFilterFFT time domain kernel (zero padded);Time in seconds;Value");
5467 hist->SetBins(narr,0,
double(narr)/
fSample);
5471 hist->SetTitle(
"NcDSP HistogramFilterFFT time domain kernel (zero padded);Sample number;Value");
5472 hist->SetBins(narr,0,narr);
5474 for (Int_t i=1; i<=narr; i++)
5476 hist->SetBinContent(i,arr[i-1]);
5478 hist->SetLineWidth(2);
5479 hist->SetLineColor(kBlue);
5488 Int_t k=log(nh)/log(2);
5497 for (Int_t i=0; i<nh; i++)
5499 arr[nfront+i]=h->GetAt(i);
5533 if (!kernel)
return;
5536 Double_t max=hisf->GetMaximum();
5539 if (max) hisf->Scale(1./fabs(max));
5543 for (Int_t i=1; i<=hisf->GetNbinsX(); i++)
5545 hisf->AddBinContent(i,-max);
5548 hisf->SetLineWidth(2);
5549 hisf->SetLineColor(kBlue);
5615 if (results) results->
Reset();
5619 if (tu!=
"ps" && tu!=
"ns" && tu!=
"sec" && tu!=
"hour" && tu!=
"day")
5621 printf(
"*%-s::Periodogram* Unsupported time unit : %-s \n",ClassName(),tu.Data());
5625 if (Tmin<=0 || (Tmax>Tmin && Tmax<=0) || n<1)
5627 printf(
"*%-s::Periodogram* Inconsistent input : Tmin=%-g Tmax=%-g n=%-i \n",ClassName(),Tmin,Tmax,n);
5632 Int_t nt=t.GetSize();
5633 Int_t ny=y.GetSize();
5635 if (dy) ndy=dy->GetSize();
5637 if ((nt+ny+ndy)!=3*nt)
5641 printf(
"*%-s::Periodogram* Incompatible input array sizes : nt=%-i ny=%-i ndy=%-i \n",ClassName(),nt,ny,ndy);
5645 printf(
"*%-s::Periodogram* Incompatible input array sizes : nt=%-i ny=%-i \n",ClassName(),nt,ny);
5651 Float_t fmax=1./Tmin;
5653 if (Tmax>Tmin) fmin=1./Tmax;
5654 Float_t fstep=(fmax-fmin)/
float(n);
5658 Double_t ti,yi,dyi2,wi,zi;
5665 for (Int_t i=0; i<nt; i++)
5673 dyi2=pow(dy->GetAt(i),2);
5674 if (!dyi2)
continue;
5677 if (Z) zi=Z->Eval(ti);
5690 Double_t W=warr.GetSum();
5694 printf(
"*%-s::Periodogram* No valid data available. \n",ClassName());
5702 Double_t twopi=2.*acos(-1.);
5738 for (Int_t i=0; i<na; i++)
5744 zcosi=zi*cos(omega*ti);
5745 zsini=zi*sin(omega*ti);
5749 C2+=wi*pow(zcosi,2);
5750 S2+=wi*pow(zsini,2);
5765 if (Y2*D) P=(S2*pow(YC,2)+C2*pow(YS,2)-2.*CS*YC*YS)/(Y2*D);
5788 gr.SetPoint(ip,f,P);
5795 if (tu==
"ps") unit=
"THz";
5796 if (tu==
"ns") unit=
"GHz";
5797 if (tu==
"hour") unit=
"1/hour";
5798 if (tu==
"day") unit=
"1/day";
5800 title.Form(
"%-s Periodogram;Frequency in %-s;Normalized Power",ClassName(),unit.Data());
5801 gr.SetNameTitle(
"Periodogram",title);
5802 gr.SetMarkerStyle(8);
5803 gr.SetMarkerSize(0.5);
5804 gr.SetMarkerColor(kBlue);
5877 printf(
"*%-s::Periodogram* Error: NcSample storage mode is not activated. \n",ClassName());
5884 if (ns<1 || it<1 || it>ndim || iy<1 || iy>ndim || idy<0 || idy>ndim)
5886 printf(
"*%-s::Periodogram* Inconsistent NcSample input: it=%-i iy=%-i idy=%-i #entries=%-i \n",ClassName(),it,iy,idy,ns);
5894 for (Int_t i=1; i<=ns; i++)
5898 if (idy) dy[i-1]=s.
GetEntry(i,idy);
5984 if (!idy && namedy!=
"-") idy=-1;
5988 if (ns<1 || it<1 || iy<1 || idy<0)
5990 printf(
"*%-s::Periodogram* Inconsistent NcSample input: namet=%-s namey=%-s namedy=%-s #entries=%-i \n",ClassName(),namet.Data(),namey.Data(),namedy.Data(),ns);
5994 gr=
Periodogram(tu,Tmin,Tmax,n,s,it,iy,idy,Z,results);
6060 Int_t nbins=h.GetNbinsX();
6061 Int_t nen=h.GetEntries();
6063 if (nbins<1 || nen<1)
6065 printf(
"*%-s::Periodogram* Inconsistent histogram input: nbins=%-i #entries=%-i \n",ClassName(),nbins,nen);
6073 for (Int_t i=1; i<=nbins; i++)
6075 t[i-1]=h.GetBinCenter(i);
6076 y[i-1]=h.GetBinContent(i);
6077 if (err) dy[i-1]=h.GetBinError(i);
6154 if (err && !(g.InheritsFrom(
"TGraphErrors")))
6156 printf(
"*%-s::Periodogram* Error: For weighted fitting the input graph has to be a TGraphErrors object. \n",ClassName());
6164 printf(
"*%-s::Periodogram* Error: Input graph is empty. \n",ClassName());
6174 for (Int_t i=0; i<np; i++)
6176 g.GetPoint(i,gx,gy);
6179 if (err) dy[i]=g.GetErrorY(i);
6209 if (strlen(name)) q->SetName(name);
void AddNamedSlot(TString s)
Various Digital Signal Processing (DSP) operations for (sequential) data samples.
Int_t GetN(Int_t mode=0) const
TArrayD FilterMultiBand(TArray &freqs, Int_t n, TH1 *hisf=0, Bool_t dB=kTRUE, TH1 *hist=0, Int_t *i1=0, Int_t *i2=0, Bool_t adaptn=kTRUE)
void SetSamplingFrequency(Float_t f)
TArrayD FilterLowPass(Double_t fcut, Int_t n, TH1 *hisf=0, Bool_t dB=kTRUE, TH1 *hist=0, Int_t *i1=0, Int_t *i2=0, Bool_t adaptn=kTRUE)
TArrayD Convolve(TH1 *hist=0, Int_t *i1=0, Int_t *i2=0, Int_t shift=0)
TGraph Periodogram(TString tu, Double_t Tmin, Double_t Tmax, Int_t n, TArray &t, TArray &y, TArray *dy=0, TF1 *Z=0, NcDevice *results=0) const
TArrayD GetMultiBandKernel(TArray &freqs, Int_t n, TH1 *hisf=0, Bool_t dB=kTRUE, TH1 *hist=0, Bool_t adaptn=kTRUE)
void HistogramTrafoResult(TString name, Int_t mode, TH1 *hist, TString sel)
void Hilbert(Int_t mode, TH1 *hist=0, TString sel="none")
void Fourier(TString mode, TH1 *hist=0, TString sel="none")
void SetWaveform(Int_t n, Double_t *h, Float_t f=-1)
TArrayD FilterHighPass(Double_t fcut, Int_t n, TH1 *hisf=0, Bool_t dB=kTRUE, TH1 *hist=0, Int_t *i1=0, Int_t *i2=0, Bool_t adaptn=kTRUE)
TArrayD GetBandRejectKernel(Double_t f1, Double_t f2, Int_t n, TH1 *hisf=0, Bool_t dB=kTRUE, TH1 *hist=0, Bool_t adaptn=kTRUE)
NcDSP(const char *name="", const char *title="")
void Cosine(Int_t type, TH1 *hist=0, TString sel="none")
TArrayL64 ADC(Int_t nbits, Double_t range, Double_t Vbias=0, TArray *Vsig=0, TH1 *hist=0, Int_t B=0, Int_t C=3) const
TArrayD GetHighPassKernel(Double_t fcut, Int_t n, TH1 *hisf=0, Bool_t dB=kTRUE, TH1 *hist=0, Bool_t adaptn=kTRUE)
TArrayD FilterMovingAverage(Int_t n, TString mode, TH1 *hist=0, Int_t *i1=0, Int_t *i2=0, TH1 *hisf=0, Bool_t dB=kTRUE)
void Hartley(Int_t mode, TH1 *hist=0, TString sel="none")
TArrayD GetData(TString mode) const
TArrayD Digitize(Int_t nbits, Double_t vcal, Int_t mode, TH1 *hist=0, Double_t *stp=0, Double_t *scale=0) const
TArrayD FilterBandReject(Double_t f1, Double_t f2, Int_t n, TH1 *hisf=0, Bool_t dB=kTRUE, TH1 *hist=0, Int_t *i1=0, Int_t *i2=0, Bool_t adaptn=kTRUE)
void HistogramFilterFFT(TArray *h, TH1 *hisf, Bool_t dB, Bool_t kernel, TH1 *hist=0)
TArrayD DAC(Int_t nbits, Double_t range, Double_t Vbias=0, TArray *adcs=0, TArray *peds=0, TH1 *hist=0, Int_t B=0, Int_t C=3) const
TArrayD GetLowPassKernel(Double_t fcut, Int_t n, TH1 *hisf=0, Bool_t dB=kTRUE, TH1 *hist=0, Bool_t adaptn=kTRUE)
TArrayD GetMovingAverageKernel(Int_t n, TH1 *hisf=0, Bool_t dB=kTRUE, TH1 *hist=0)
TArrayD SampleAndHold(TF1 f, Double_t step, Double_t vmin, Double_t vmax, TH1 *hist=0, Int_t loc=-1) const
virtual TObject * Clone(const char *name="") const
Float_t GetSamplingFrequency() const
TArrayD Correlate(TH1 *hist=0, Int_t *i1=0, Int_t *i2=0, Double_t *peak=0, TString norm="NONE")
TArrayD SampleAndSum(TF1 f, Double_t step, Double_t vmin, Double_t vmax, TH1 *hist=0) const
void Sine(Int_t type, TH1 *hist=0, TString sel="none")
void Load(Int_t n, Double_t *re, Double_t *im=0, Float_t f=-1)
TArrayD FilterBandPass(Double_t f1, Double_t f2, Int_t n, TH1 *hisf=0, Bool_t dB=kTRUE, TH1 *hist=0, Int_t *i1=0, Int_t *i2=0, Bool_t adaptn=kTRUE)
TArrayD GetBandPassKernel(Double_t f1, Double_t f2, Int_t n, TH1 *hisf=0, Bool_t dB=kTRUE, TH1 *hist=0, Bool_t adaptn=kTRUE)
TArrayD Transmit(Int_t nbits, Double_t range, Double_t Vbias=0, TArray *Vsig=0, TArray *peds=0, TH1 *hist=0, Int_t B=0, Int_t C=3) const
Signal (Hit) handling of a generic device.
virtual void Reset(Int_t mode=0)
Various mathematical tools for scientific analysis.
Double_t Log(Double_t B, Double_t x) const
Sampling and statistics tools for various multi-dimensional data samples.
Int_t GetStoreMode() const
Int_t GetIndex(TString name) const
Int_t GetDimension() const
Double_t GetEntry(Int_t i, Int_t j, Int_t mode=0, Int_t k=0)
Generic handling of (extrapolated) detector signals.
virtual void SetSignal(Double_t sig, Int_t j=1)