2 #include "PeakAnaPainter.h"
16 mInternalSignal=
false;
21 mG_Data =
new TGraph(size,xvals,yvals);
37 mInternalSignal =
true;
57 mChiralityPeakScale = 1;
59 mChiralityProbScale = 1;
60 mChiralityThreshold = -1;
73 if( graph!=0 ){
mG_Data = graph; }
77 if( graph!=0 ){mInternalSignal=
false;}
85 if(
this == &rhs ){
return *
this; }
89 mInternalSignal=
false;
121 else{ ((
PeakAna&)obj).mFilterWeights = 0; }
131 TGraph* cloneg = (TGraph*)
GetData()->Clone(newname);
134 ana->ForceInternal();
138 for( UInt_t i=0; i<
mPeaks.size(); ++i ){
148 if(mInternalSignal ){
delete mG_Data;}
160 if( mChiralityThreshold>=0 &&
mPeaks.size()>1 ){
161 std::vector<PeakWindow> mergedpeaks;
162 this->MergeByChirality(mergedpeaks);
163 mPeaks.swap( mergedpeaks );
180 Int_t PeakAna::AnalyzeForNoisyPeak()
189 for( Int_t inoisy=0; inoisy<noisyana.
NPeaks(); ++inoisy )
225 for(
int i=0; i<
mG_Data->GetN(); ++i ){
226 Double_t X; Double_t Y;
228 if( X<xmin || X>xmax ){
continue;}
232 LOG_WARN <<
"Unable to find a maximum adc\nSetting to impossible values" << endm;
261 std::cout <<
"|P::Graph:"<<
mG_Data;
264 std::cout <<
"|Flag::Internal:"<<mInternalSignal;
268 std::cout << std::endl;
270 std::cout << std::endl;
272 std::cout << std::endl;
273 std::cout <<
"|MaxX:"<<
mMaxX;
274 std::cout <<
"|MaxY:"<<
mMaxY;
275 std::cout << std::endl;
277 if( mFilterWeights!=0 ){
for(
int i=0; i<
mFilterScale*2+1; ++i ){ std::cout << mFilterWeights[i] <<
","; } }
278 std::cout << std::endl;
279 std::cout <<
" - Peaks:" << std::endl;
280 for( UInt_t i=0; i<
mPeaks.size(); ++i ){
281 std::cout <<
" + |i:"<<i;
283 std::cout << std::endl
304 if( graph==0 ){LOG_ERROR <<
"PeaAna::SetData - Graph cannot be 0!" << endm;
return;}
308 mInternalSignal =
false;
313 if( hist==0 ){LOG_ERROR <<
"PeakAna::SetData - Histogram cannot be 0" << endm;
return;}
315 if( mInternalSignal ){
delete mG_Data;}
317 mInternalSignal =
true;
324 if( scale<=0 ){
return; }
325 if( sigma==0 ){ sigma=scale/2.0; }
332 if( sigma<0){ LOG_WARN <<
"PeakAna::SetBaseline - Baseline sigma should not be less than zero\n" << endm; }
384 Int_t nbins = hist->GetNbinsX();
386 if( numavgs<1 || static_cast<Int_t>(numavgs)>nbins ){
return 0;}
387 TGraph* AvgGr =
new TGraph();
388 for( Int_t ibin=1; ibin<=nbins; ibin+=numavgs ){
391 for(Int_t i=ibin; i<ibin+static_cast<Int_t>(numavgs) && i<=nbins; ++i ){ sum += hist->GetBinContent(i); ++counter; }
392 Double_t avg = sum/
static_cast<Double_t
>(counter);
394 Double_t xlow = hist->GetBinLowEdge(ibin);
395 Double_t xhigh = hist->GetBinLowEdge(ibin+counter);
396 AvgGr->SetPoint(AvgGr->GetN(),(xlow+xhigh)/2.0,avg);
403 if( Peaks.size()==0 ){
return 0;}
404 TGraph* graph =
new TGraph();
405 for( UInt_t ipeak=0; ipeak<Peaks.size(); ++ipeak )
407 graph->SetPoint( ipeak,Peaks.at(ipeak).mPeakX,Peaks.at(ipeak).MidPoint() );
414 TGraph* graph =
new TGraph();
415 for( UInt_t ipeak=0; ipeak<
mPeaks.size(); ++ipeak )
417 graph->SetPoint( ipeak,
mPeaks.at(ipeak).mPeakX,
mPeaks.at(ipeak).MidPoint() );
426 TGraph* graph =
new TGraph();
427 for( Int_t ipeak=0; ipeak<Ana.
NPeaks(); ++ipeak ){
431 NewAna.ForceInternal();
437 if(
GetData()==0 ){
return this;}
438 const int npoints =
GetData()->GetN();
439 if( sizeavgs==0 || npoints<=1 ){
return this; }
440 if( sizeavgs<0 ){ sizeavgs = -sizeavgs; }
441 double ynew[npoints];
442 double* xdata =
GetData()->GetX();
443 double* ydata =
GetData()->GetY();
444 for(
int ipoint=0; ipoint<npoints; ++ipoint ){
445 double sumweights = 1;
447 double sumvalues = sumweights*ydata[ipoint];
448 int nextpoint_m = ipoint;
449 int nextpoint_p = ipoint;
450 double lastx_m = xdata[ipoint];
451 double lastx_p = xdata[ipoint];
452 for(
int sizecounter=0; sizecounter<sizeavgs; ++sizecounter ){
454 Double_t delxerr = 0.001*
mDeltaX;
455 if( (nextpoint_m-1)>=0 ){
456 if(
mDeltaX<=0 || ((
mDeltaX-delxerr)<=fabs(xdata[nextpoint_m-1]-lastx_m) && fabs(xdata[nextpoint_m-1]-lastx_m)<=(
mDeltaX+delxerr)) ){
459 lastx_m = xdata[nextpoint_m];
461 else{ sumvalues += ydata[nextpoint_m]; }
471 else{ sumweights += 1; }
473 if( (nextpoint_p+1)<npoints ){
474 if(
mDeltaX<=0 || ((
mDeltaX-delxerr)<=fabs(xdata[nextpoint_p+1]-lastx_p) && fabs(xdata[nextpoint_p+1]-lastx_p)<=(
mDeltaX+delxerr)) ){
476 lastx_p = xdata[nextpoint_p];
478 else{ sumvalues += ydata[nextpoint_p]; }
486 else{ sumweights += 1; }
489 ynew[ipoint] = sumvalues/sumweights;
490 if(
GetDebug()>2 ){ std::cout <<
" - |i:"<<ipoint<<
"|ynew:"<<ynew[ipoint] << std::endl; }
494 TGraph* filtered =
new TGraph(npoints,xdata,ynew);
496 ana->ForceInternal();
497 if(
GetDebug()>1 ){ std::cout <<
"PeakAna::MeanFilter:Copied PeakAna" << std::endl; }
500 if( mInternalSignal ){
502 std::copy( ynew, ynew+npoints, ydata);
506 if(
GetDebug()>1 ){ std::cout <<
"PeakAna::MeanFilter:Internal Graph Modified" << std::endl; }
509 TGraph* graph =
new TGraph(npoints,xdata,ynew );
512 if(
GetDebug()>1 ){ std::cout <<
"PeakAna::MeanFilter:Created New Internal Graph" << std::endl; }
520 if(
GetData()==0 ){
return this;}
521 const int npoints =
GetData()->GetN();
522 if( sizeavgs==0 || npoints<=1 ){
return this; }
523 if( sizeavgs<0 ){ sizeavgs = -sizeavgs; }
524 double ynew[npoints];
525 double* xdata =
GetData()->GetX();
526 double* ydata =
GetData()->GetY();
527 for(
int ipoint=0; ipoint<npoints; ++ipoint ){
528 double sumweights = 1;
530 double sumvalues = sumweights*ydata[ipoint];
531 int nextpoint_m = ipoint;
532 int nextpoint_p = ipoint;
533 double lastx_m = xdata[ipoint];
534 double lastx_p = xdata[ipoint];
535 for(
int sizecounter=0; sizecounter<sizeavgs; ++sizecounter ){
537 Double_t delxerr = 0.001*
mDeltaX;
538 if( (nextpoint_m-1)>=0 ){
539 if(
mDeltaX<=0 || ((
mDeltaX-delxerr)<=fabs(xdata[nextpoint_m-1]-lastx_m) && fabs(xdata[nextpoint_m-1]-lastx_m)<=(
mDeltaX+delxerr)) ){
542 lastx_m = xdata[nextpoint_m];
544 else{ sumvalues+=ydata[nextpoint_m]; }
557 else{ sumvalues += ydata[0]; }
559 if( (nextpoint_p+1)<npoints ){
560 if(
mDeltaX<=0 || ((
mDeltaX-delxerr)<=fabs(xdata[nextpoint_p+1]-lastx_p) && fabs(xdata[nextpoint_p+1]-lastx_p)<=(
mDeltaX+delxerr)) ){
562 lastx_p = xdata[nextpoint_p];
564 else{ sumvalues += ydata[nextpoint_p]; }
575 else{ sumvalues += ydata[npoints-1]; }
582 else{ sumweights += 2; }
584 ynew[ipoint] = sumvalues/sumweights;
585 if(
GetDebug()>2 ){ std::cout <<
" - |i:"<<ipoint<<
"|ynew:"<<ynew[ipoint] << std::endl; }
590 TGraph* filtered =
new TGraph(npoints,xdata,ynew);
592 ana->ForceInternal();
593 if(
GetDebug()>1 ){ std::cout <<
"PeakAna::MeanFilter:Copied PeakAna" << std::endl; }
596 if( mInternalSignal ){
598 std::copy( ynew, ynew+npoints, ydata);
602 if(
GetDebug()>1 ){ std::cout <<
"PeakAna::MeanFilter:Internal Graph Modified" << std::endl; }
605 TGraph* graph =
new TGraph(npoints,xdata,ynew );
608 if(
GetDebug()>1 ){ std::cout <<
"PeakAna::MeanFilter:Created New Internal Graph" << std::endl; }
624 LOG_DEBUG <<
"PeakAna::PeakTunnel - |prob:"<<prob <<
"|thr:"<<
mTunnelThreshold;
629 else{
return false; }
642 std::vector<PeakWindow> PossiblePeak;
643 if(
GetDebug()>1 ){LOG_DEBUG <<
"PeakAna - In GetPossiblePeaks" << endm; }
648 LOG_DEBUG <<
"|baseline:"<<baseline <<
"|slopecutoff:"<<slopecutoff << endm;
652 if(
GetDebug()>1 ){LOG_DEBUG <<
"Finding Peak for cutoff " << slopecutoff << endm;}
654 if(
GetDebug()>2 ){LOG_DEBUG <<
"PeakAna::GetPossiblePeaks:Start graph reading loop" << endm;}
655 Int_t npoints =
mG_Data->GetN();
656 for( Int_t ismp=0; ismp<npoints-1; ++ismp ){
657 Double_t LX; Double_t LY;
658 Double_t RX; Double_t RY;
660 mG_Data->GetPoint(ismp+1,RX,RY);
661 if(
GetDebug()>1 ){LOG_DEBUG <<
" - |P:"<<ismp <<
"|LX:"<<LX <<
"|LY:"<<LY<<
"|RX:"<<RX <<
"|RY:"<<RY << endm;}
664 if( LX <
mXRangeMin ){
if(
GetDebug()>2 ){LOG_DEBUG <<
"'LX' too small"<<endm;}
continue; }
665 if( LX >
mXRangeMax ){
if(
GetDebug()>2 ){LOG_DEBUG <<
"'LX' too large"<<endm;}
continue; }
666 if( LY < mYRangeMin || LY >
mYRangeMax){
if(
GetDebug()>2 ){LOG_DEBUG <<
"'LY' outside y range"<<endm;}
continue; }
667 if( RY < mYRangeMin || RY > mYRangeMax){
if(
GetDebug()>2 ){LOG_DEBUG <<
"'RY' outside y range"<<endm;}
continue; }
668 Double_t Slope = (RY-LY)/(RX-LX);
670 Double_t delxerr = 0.001*
mDeltaX;
671 if( !((
mDeltaX-delxerr)<=(RX-LX) && (RX-LX)<=(
mDeltaX+delxerr)) ){
672 if(
GetDebug()>2 ){ LOG_DEBUG <<
" - |DeltaX:"<<
mDeltaX <<
"|RX-LX:"<<RX-LX << endm;}
678 if(
GetDebug()>2 ){LOG_DEBUG <<
" - |Slope:"<<Slope << endm;}
680 if(
GetDebug()>2 ){LOG_DEBUG <<
" - peak|ismp:"<<ismp <<
"|start:"<<peak.
mStartX <<
"|end:"<<peak.
mEndX << endm;}
683 if(
GetDebug()>1 ){LOG_DEBUG <<
" + No StartTime" << endm;}
685 if( LY>baseline+slopecutoff || RY>baseline+slopecutoff ){
687 if(
GetDebug()>1 ){LOG_DEBUG <<
" + Passed Slope and baselineCutoff setting as start time" << endm;}
697 if(
GetDebug()>1 ){LOG_DEBUG <<
" + Found StartTime:"<< peak.
mStartX <<
"|LocalMax:"<<LocalMax<<endm;}
701 if(
GetDebug()>2){LOG_DEBUG<<
" + Slope>=0|"<<Slope<<endm;}
709 if(
GetDebug()>2){LOG_DEBUG<<
" + Slope<0"<<endm;}
711 if( LocalMax>peak.
mEndX || LY<baseline+slopecutoff || ismp==npoints-2 || RY<=
mYRangeMin ){
716 Int_t n = PossiblePeak.size();
717 if( n==0 ){ PossiblePeak.push_back(peak); }
722 PossiblePeak[n-1] = newpeak;
725 else{ PossiblePeak.push_back(peak); }
727 if(
GetDebug()>1){LOG_DEBUG <<
" * |Found:"; PossiblePeak.back().Print(
"debug"); LOG_DEBUG<<endm;}
729 if(
GetDebug()>2){LOG_DEBUG <<
" * |peakreset:"; peak.
Print(
"debug"); LOG_DEBUG<<endm;}
735 if(
GetDebug()>0 ){ LOG_DEBUG <<
"PeakAna::GetPossiblePeaks:End graph reading loop|SizePeaks:" <<PossiblePeak.size() << endm; }
737 mPeaks.swap(PossiblePeak);
743 if( PossiblePeaks.size()==0 ){
744 if(
GetDebug()>0 ){LOG_DEBUG <<
"PeakAna::SearchForPeak - Error:Unable to find a valid peak\nReturning impossible index" << endm; }
745 return PossiblePeaks.size();
749 LOG_DEBUG <<
"|Size of Possible peaks:"<<PossiblePeaks.size();
754 Short_t peakindex=-1;
755 for( UShort_t ipeak=0; ipeak<PossiblePeaks.size(); ++ipeak ){
758 LOG_DEBUG <<
"|Index:"<<ipeak;
759 PossiblePeaks.at(ipeak).Print(
"debug");
762 Double_t PeakLoc = PossiblePeaks.at(ipeak).mPeakX;
767 LOG_DEBUG <<
"|TrueIndex:"<<peakindex;
772 if( peakindex>=0 &&
mSearch.
mStartX>0 && PossiblePeaks.at(peakindex).mP_Peak>0 ){
773 if(
GetDebug()>1){PossiblePeaks.at(peakindex).Print(
"debug");LOG_DEBUG<<endm;}
776 else{
return PossiblePeaks.size();}
794 if( !newpeaks.empty() ){ newpeaks.clear(); }
795 for( UInt_t i=0; i<
mPeaks.size(); ++i){
797 if( newpeaks.empty() ){ newpeaks.push_back(
mPeaks.at(i));
continue; }
800 newpeaks.back().Combine(
mPeaks.at(i),thisprob<=nextprob?
true:
false);
802 else{ newpeaks.push_back(
mPeaks.at(i)); }
806 void PeakAna::MergeByChirality(std::vector<PeakWindow>& newpeaks)
const
811 std::vector<short> mergelist;
812 for( UInt_t i=0; i<
mPeaks.size(); ++i ){
817 mergelist.push_back( this->MergeLeftOrRight(i) );
822 std::vector< std::pair<int,int> > coupledindexs = this->MergeIndices(mergelist);
825 for( UInt_t i=0; i<
mPeaks.size(); ++i ){
826 bool combined =
false;
827 for( UInt_t j=0; j<coupledindexs.size(); ++j ){
828 if(static_cast<int>(i)==coupledindexs.at(j).first){
830 for(
int k=coupledindexs.at(j).first+1; k<=coupledindexs.at(j).second; ++k ){
833 combpeak.
Combine(
mPeaks.at(k),thisprob<=otherprob?
true:
false);
835 newpeaks.push_back(combpeak);
836 i=coupledindexs.at(j).second;
840 if( !combined ){ newpeaks.push_back(
mPeaks.at(i) ); }
845 short PeakAna::MergeLeftOrRight(UInt_t index)
const
847 if( index>=
mPeaks.size() ){
return 0;}
848 if(
mPeaks.size()==1 ){
return 0;}
851 Double_t leftchir = 0;
852 Double_t thischir =
mPeaks.at(index).PeakChirality(mChiralityPeakScale,mChiralityScale);
853 Double_t rightchir = 0;
854 if( thischir==0 || thischir==1 ){
return 0;}
857 rightchir =
mPeaks.at(index+1).PeakChirality(mChiralityPeakScale,mChiralityScale);
858 if(
mPeaks.at(index+1).PeakChiralityProb(mChiralityProbScale,rightchir) > mChiralityThreshold ){
861 else if( index+1==
mPeaks.size() ){
862 leftchir =
mPeaks.at(index-1).PeakChirality(mChiralityPeakScale,mChiralityScale);
863 if(
mPeaks.at(index-1).PeakChiralityProb(mChiralityProbScale,leftchir) > mChiralityThreshold ){
866 else if( 0<index && index<
mPeaks.size() ){
867 leftchir =
mPeaks.at(index-1).PeakChirality(mChiralityPeakScale,mChiralityScale);
868 rightchir =
mPeaks.at(index+1).PeakChirality(mChiralityPeakScale,mChiralityScale);
869 if(
mPeaks.at(index-1).PeakChiralityProb(mChiralityProbScale,leftchir) > mChiralityThreshold ){
872 if(
mPeaks.at(index+1).PeakChiralityProb(mChiralityProbScale,rightchir) > mChiralityThreshold ){
876 else{ std::cout <<
"PeakAna::MergeLeftOrRight - WARNING:Invalid index" << std::endl; }
879 if( leftchir==0 && rightchir==0 ){
return 0; }
880 else if( leftchir!=0 && rightchir==0 ){
881 if( thischir*leftchir<0 ){
return -1;}
885 leftchir==0 && rightchir!=0 ){
886 if( thischir*rightchir<0 ){
return 1;}
890 bool leftoppsign=
false;
891 if( (leftchir*rightchir)<0 ){leftoppsign=
true;}
892 bool rightoppsign=
false;
893 if( (rightchir*thischir)<0 ){rightoppsign=
true;}
895 Double_t leftchirprob =
mPeaks.at(index-1).PeakChiralityProb(mChiralityProbScale,leftchir);
896 Double_t rightchirprob =
mPeaks.at(index+1).PeakChiralityProb(mChiralityProbScale,rightchir);
902 if( leftchirprob<rightchirprob ){
return -1; }
else{
return 1; }
907 if( rightoppsign ){
return 1; }
911 if( thischir>0 ){
return 1;}
921 bool PeakAna::MergeLeft(Double_t leftchir, Double_t thischir, Double_t rightchir)
const
924 bool leftoppsign=
false;
925 if( (leftchir*rightchir)<0 ){leftoppsign=
true;}
926 bool rightoppsign=
false;
927 if( (rightchir*thischir)<0 ){rightoppsign=
true;}
932 if( leftchir<rightchir ){
return true; }
else{
return false; }
937 if( rightoppsign ){
return false; }
940 if( leftchir<=rightchir ){
return true; }
else{
return true;}
945 std::vector< std::pair<int,int> > PeakAna::MergeIndices(std::vector<short>& vec)
const
947 int firstpos_index = -1;
948 int lastneg_index = -1;
950 std::vector< std::pair<int,int> > mergeindexs;
951 for(
int i=0; i<static_cast<int>(vec.size()); ++i ){
954 if( firstpos_index<0 ){
if( vec.at(i)>0 ){firstpos_index = i;} }
956 if( lastneg_index>firstpos_index ){
958 std::pair<int,int> mergepair(firstpos_index,lastneg_index);
959 mergeindexs.push_back(mergepair);
961 if( vec.at(i)==0 ){firstpos_index = -1;}
962 else{ firstpos_index=i; }
969 if( zero_count < 1 ){ firstpos_index=-1; lastneg_index=-1; zero_count=0; }
975 if( firstpos_index>=0 ){
990 void PeakAna::Paint(Option_t* opt)
995 if (strlen(opt) > 0){
mPainter->Paint(opt); }
1012 if( pave==0 ){
return; }
1013 TString option(opt);
1014 bool statsalloption =
false;
1015 bool statsdetailoption =
false;
1018 if( option.Contains(
"a") ){ statsalloption =
true; }
1019 if( option.Contains(
"d") ){ statsdetailoption =
true; }
1021 pave->AddText(
"--Found Peaks--");
1027 if( !statsalloption ){
1028 TText* t = pave->AddText( Form(
"I:%u|S:[%2.2f,%2.2f]|E[%2.2f,%2.2f]|P(%d,%2.2f,%2.2f)",
1038 t->SetTextAlign(11);
1039 if( statsdetailoption ){
1040 TText* t2 = pave->AddText( Form(
" + |Prob:%1.4f|Chir:%3.1f|ChirProb:%1.4f",
1043 (
GetPeak(
mComputedIndex)).PeakChiralityProb(ChiralityProbScale(),ChiralityPeakScale(),ChiralityScale())
1045 t2->SetTextAlign(11);
1050 for( Int_t ipeak=0; ipeak<
NPeaks(); ++ipeak ){
1051 TText* t = pave->AddText( Form(
"|I:%u|S[%2.2f,%2.2f]|E[%2.2f,%2.2f]",
1058 t->SetTextAlign(11);
1060 if( statsdetailoption ){
1064 TText* t2 = pave->AddText( Form(
" + |P(%d,%2.2f,%2.2f)|Prob:%1.4f",
1070 t2->SetTextAlign(11);
1079 Color_t PeakAna::GetLineColor()
const
1081 Style_t PeakAna::GetLineStyle()
const
1083 Width_t PeakAna::GetLineWidth()
const
1086 Color_t PeakAna::GetFillColor()
const
1088 Style_t PeakAna::GetFillStyle()
const
1091 Color_t PeakAna::GetMarkerColor()
const
1093 Size_t PeakAna::GetMarkerSize()
const
1095 Style_t PeakAna::GetMarkerStyle()
const
1098 void PeakAna::SetLineColor(Color_t color)
1100 void PeakAna::SetLineColorAlpha(Color_t color, Float_t alpha)
1102 void PeakAna::SetLineStyle(Style_t style)
1104 void PeakAna::SetLineWidth(Width_t width)
1107 void PeakAna::SetFillColor(Color_t color)
1109 void PeakAna::SetFillColorAlpha(Color_t color, Float_t alpha)
1111 void PeakAna::SetFillStyle(Style_t style)
1114 void PeakAna::SetMarkerColor(Color_t color)
1116 void PeakAna::SetMarkerColorAlpha(Color_t color, Float_t alpha)
1118 void PeakAna::SetMarkerSize(Size_t size)
1120 void PeakAna::SetMarkerStyle(Style_t style)
1124 Color_t PeakAna::GetBaseLineColor()
const
1126 Style_t PeakAna::GetBaseLineStyle()
const
1128 Width_t PeakAna::GetBaseLineWidth()
const
1131 Color_t PeakAna::GetHitLineColor()
const
1133 Style_t PeakAna::GetHitLineStyle()
const
1135 Width_t PeakAna::GetHitLineWidth()
const
1138 void PeakAna::SetBaseLineColor(Color_t color)
1139 {GetPainter()->SetBaseLineColor(color);}
1140 void PeakAna::SetBaseLineColorAlpha(Color_t color,Float_t alpha)
1141 {GetPainter()->SetBaseLineColorAlpha(color,alpha);}
1142 void PeakAna::SetBaseLineStyle(Style_t style)
1143 {GetPainter()->SetBaseLineStyle(style);}
1144 void PeakAna::SetBaseLineWidth(Width_t width)
1145 {GetPainter()->SetBaseLineWidth(width);}
1147 void PeakAna::SetHitLineColor(Color_t color)
1148 {GetPainter()->SetHitLineColor(color);}
1149 void PeakAna::SetHitLineColorAlpha(Color_t color,Float_t alpha)
1150 {GetPainter()->SetHitLineColorAlpha(color,alpha);}
1151 void PeakAna::SetHitLineStyle(Style_t style)
1152 {GetPainter()->SetHitLineStyle(style);}
1153 void PeakAna::SetHitLineWidth(Width_t width)
1154 {GetPainter()->SetHitLineWidth(width);}
1156 Color_t PeakAna::GetPeakLineColorS(UInt_t peakidx)
const
1157 {
return GetPeak(peakidx).GetStartLineColor();}
1158 Color_t PeakAna::GetPeakLineColorE(UInt_t peakidx)
const
1159 {
return GetPeak(peakidx).GetEndLineColor();}
1160 Style_t PeakAna::GetPeakStyleS(UInt_t peakidx)
const
1161 {
return GetPeak(peakidx).GetStartLineStyle();}
1162 Style_t PeakAna::GetPeakStyleE(UInt_t peakidx)
const
1163 {
return GetPeak(peakidx).GetEndLineStyle();}
1164 Width_t PeakAna::GetPeakWidthS(UInt_t peakidx)
const
1165 {
return GetPeak(peakidx).GetStartLineWidth();}
1166 Width_t PeakAna::GetPeakWidthE(UInt_t peakidx)
const
1167 {
return GetPeak(peakidx).GetEndLineWidth();}
1169 Color_t PeakAna::GetFoundPeakLineColorS()
const
1171 Color_t PeakAna::GetFoundPeakLineColorE()
const
1173 Style_t PeakAna::GetFoundPeakStyleS()
const
1175 Style_t PeakAna::GetFoundPeakStyleE()
const
1177 Width_t PeakAna::GetFoundPeakWidthS()
const
1179 Width_t PeakAna::GetFoundPeakWidthE()
const
1182 void PeakAna::SetFoundPeakLineColorS(Color_t s_color)
1184 void PeakAna::SetFoundPeakLineColorE(Color_t e_color)
1186 void PeakAna::SetFoundPeakLineColor(Color_t s_color, Color_t e_color)
1188 void PeakAna::SetFoundPeakStyleS(Style_t s_style)
1190 void PeakAna::SetFoundPeakStyleE(Style_t e_style)
1192 void PeakAna::SetFoundPeakStyle(Style_t s_style,Style_t e_style)
1194 void PeakAna::SetFoundPeakWidthS(Width_t s_width)
1196 void PeakAna::SetFoundPeakWidthE(Width_t e_width)
1198 void PeakAna::SetFoundPeakWidth(Width_t s_width, Width_t e_width)
1201 void PeakAna::SetPeakLineColorS(UInt_t peakidx, Color_t s_color)
1202 {
GetPeak(peakidx).SetStartLineColor(s_color); }
1203 void PeakAna::SetPeakLineColorE(UInt_t peakidx, Color_t e_color)
1204 {
GetPeak(peakidx).SetStartLineColor(e_color); }
1205 void PeakAna::SetPeakLineColor(UInt_t peakidx, Color_t s_color, Color_t e_color)
1206 {
GetPeak(peakidx).SetStartLineColor(s_color);
GetPeak(peakidx).SetStartLineColor(e_color); }
1207 void PeakAna::SetPeakLineColorAlphaS(UInt_t peakidx, Color_t s_color,Float_t s_alpha)
1208 {
GetPeak(peakidx).SetStartLineColorAlpha( s_color, s_alpha); }
1209 void PeakAna::SetPeakLineColorAlphaE(UInt_t peakidx, Color_t e_color,Float_t e_alpha)
1210 {
GetPeak(peakidx).SetEndLineColorAlpha( e_color, e_alpha); }
1211 void PeakAna::SetPeakLineColorAlpha(UInt_t peakidx, Color_t s_color,Float_t s_alpha, Color_t e_color, Float_t e_alpha)
1212 {
GetPeak(peakidx).SetStartLineColorAlpha( s_color, s_alpha);
GetPeak(peakidx).SetEndLineColorAlpha( e_color, e_alpha); }
1213 void PeakAna::SetPeakLineStyleS(UInt_t peakidx, Style_t s_style)
1214 {
GetPeak(peakidx).SetStartLineStyle(s_style); }
1215 void PeakAna::SetPeakLineStyleE(UInt_t peakidx, Style_t e_style)
1216 {
GetPeak(peakidx).SetEndLineStyle(e_style); }
1217 void PeakAna::SetPeakLineStyle(UInt_t peakidx, Style_t s_style, Style_t e_style)
1218 {
GetPeak(peakidx).SetStartLineStyle(s_style);
GetPeak(peakidx).SetEndLineStyle(e_style); }
1219 void PeakAna::SetPeakLineWidthS(UInt_t peakidx, Width_t s_width)
1220 {
GetPeak(peakidx).SetStartLineWidth(s_width); }
1221 void PeakAna::SetPeakLineWidthE(UInt_t peakidx, Width_t e_width)
1222 {
GetPeak(peakidx).SetEndLineWidth(e_width); }
1223 void PeakAna::SetPeakLineWidth(UInt_t peakidx, Width_t s_width, Width_t e_width)
1224 {
GetPeak(peakidx).SetStartLineWidth(s_width);
GetPeak(peakidx).SetEndLineWidth(e_width); }
1226 void PeakAna::SetAllPeakLineColor(Color_t s_color, Color_t e_color)
1228 for( UInt_t ipeak=0; ipeak<
mPeaks.size(); ++ipeak ){
1229 mPeaks.at(ipeak).SetStartLineColor(s_color);
1230 mPeaks.at(ipeak).SetEndLineColor(e_color);
1233 void PeakAna::SetAllPeakLineStyle(Style_t s_style, Style_t e_style)
1235 for( UInt_t ipeak=0; ipeak<
mPeaks.size(); ++ipeak ){
1236 mPeaks.at(ipeak).SetStartLineStyle(s_style);
1237 mPeaks.at(ipeak).SetEndLineStyle(e_style);
1240 void PeakAna::SetAllPeakLineWidth(Width_t s_width, Width_t e_width)
1242 for( UInt_t ipeak=0; ipeak<
mPeaks.size(); ++ipeak ){
1243 mPeaks.at(ipeak).SetStartLineWidth(s_width);
1244 mPeaks.at(ipeak).SetEndLineWidth(e_width);
1250 if( rx<0 ){rx = -rx;}
1251 if( ry<0 ){ry = -ry;}
1252 if( sx==0 ){ sx =
static_cast<double>(rx)*0.5; }
1253 if( sy==0 ){ sy =
static_cast<double>(ry)*0.5; }
1254 const int nsizex = (2*rx+1);
1255 const int nsizey = (2*ry+1);
1259 double* GM_2D =
new double[nsizex*nsizey];
1260 for(
int ix=0; ix<nsizex; ++ix ){
1261 for(
int jy=0; jy<nsizey; ++jy ){
1264 double product = 1.0;
1265 if( sx!=0 ){ product *= exp( (-1.0*xi*xi)/(2.0*sx*sx) )/(sqrt(2.0*3.14159265358979323846)*sx); }
1266 if( sy!=0 ){ product *= exp( (-1.0*yi*yi)/(2.0*sy*sy) )/(sqrt(2.0*3.14159265358979323846)*sy); }
1267 GM_2D[ix*nsizey+jy] = product;
1273 double invsum = 1.0/GM_sum;
1274 for(
int i=0; i<nsizex; ++i ){
1275 for(
int j=0; j<nsizey; ++j ){
1276 GM_2D[i*nsizey+j] *= invsum;
virtual Int_t SearchForPeak(const std::vector< PeakWindow > &PossiblePeaks)
searches a vector of PeakWindow's for a specific peak based on input search criteria ...
void SetTunnelPars(Double_t scale, Double_t sigma)
Int_t mComputedIndex
Index in mPeaks where a peak was found.
void SetWindow(const Int_t start, const Int_t end)
Overwrite peak start and end values in mFoundPeak. WARNING doesn't set peak values nor overwrite mCom...
virtual ~PeakAna()
Destructor.
static PeakWindow Combine(const PeakWindow &leftpeak, const PeakWindow &rightpeak, bool keepleft=true)
combine two PeakWindow objects
static double * GaussianMatrix2D(int rx, double sx=0, int ry=0, double sy=0, bool kNorm=true)
Generates up to a 2D matrix of Gaussian weights.
Double_t SearchPeak() const
virtual void MergeByProbability(std::vector< PeakWindow > &newpeaks) const
Merges peaks in mPeaks using peak probability parameters.
virtual void SetPeakAna(PeakAna *ana)
virtual TObject * Clone(const char *newname) const
Clones internal graph as opposed to just copying the pointer.
Double_t mBaselineSigma
Error on PeakAna::mBaseline.
const PeakWindow & GetPeak(UInt_t peakidx) const
static TGraph * ConvertHistToGraph(TH1 *graph, UInt_t numavgs=1)
Converts a histogram to a graph.
Int_t FoundPeakIndex() const
void SetSearchWindow(Double_t peak, Double_t width)
Sets peak search parameters.
Double_t PeakY()
y-value of found signal peak
void SetTunnelThreshold(Double_t value)
void SetWindow(Double_t s, Double_t e)
virtual void SetData(TGraph *graph)
sets new data for PeakAna
TGraph * mG_Data
TGraph that stores the x,y data.
Double_t PeakX()
x-value of found signal peak
virtual TGraph * GetData() const
PeakAna * MeanFilter(Int_t sizeavgs=0, bool copy=true)
Apply a Mean filter to the data.
Double_t mXRangeMax
Absolute possible x-value maximum of data.
void PeakXY(Double_t &xval, Double_t &yval)
get peak x, and y value directly by reference
PeakAna ConvertPeaksToAna()
same as ConvertPeaksToAna() but returns new PeakAna with same settings without modifying current one ...
virtual void Draw(Option_t *opt="")
Draw method for PeakAna.
TString mOption
Drawing option.
virtual void GetPossiblePeaks()
Finds all possible Peaks in signal with some criteria.
PeakWindow mFoundPeak
Copy of found peak in mPeaks.
virtual void Copy(TObject &obj) const
Internal method use Clone instead.
virtual void GetXYMax(Double_t xmin, Double_t xmax)
Finds and sets mMaxX and mMaxY.
void SetBaseline(Double_t base, Double_t sigma)
Double_t mPeakX
x-value of peak position as determined by SetPeak()
void SetRange(Double_t xmin, Double_t ymin, Double_t xmax, Double_t ymax)
Sets the absolute range of the data.
Double_t mYRangeMin
Absolute possible y-value minimum of data.
Double_t mTunnelSigma
Sigma for Gaussian for determining tunneling probability (default is 1) see #PeakWindow::PeakTunelPro...
void ResetPeak()
Resets values associated with peak finding.
Int_t mP_Peak
Point Number of peak in a TGraph object (P for point), point is such that slope with previous point w...
virtual Int_t AnalyzeForPeak()
Main analysis method for finding peaks.
Double_t mMaxX
x-value where global maximum occurs
virtual void Print(Option_t *opt="") const
Prints information about PeakWindow.
void SetTunnelScale(Double_t value)
Double_t SearchWidth() const
void SetBaselineSigmaScale(Double_t scale)
virtual void AddPeakStats(TPaveText *pave, const char *opt="")
Add peak information to a "statistics" box.
PeakAnaPainter * mPainter
Painter for this class.
virtual void Print(Option_t *opt="") const
Print peak information.
Double_t BaselineSigma() const
virtual void Reset(Double_t start, Double_t end)
Reset PeakWindow to constructor state.
Double_t mStartY
y value associated with mStartX
PeakAna * GausFilter(Int_t sizeavgs=0, bool copy=true)
Apply a Gaussian filter to the data.
Double_t * mFilterWeights
Array of weights to use in filtering, size is 2*mFilterScale+1.
Double_t TunnelScale() const
Double_t MidPoint(TGraph *graph=0) const
Computes the the line formed by the points (mStartX,mStartY) and (mEndX,mEndY) and evaluates that lin...
Double_t mMaxY
y-value of global maximum
Double_t mBaselineSigmaScale
scale on PeakAna::mBaselineSigma to determine final threshold
PeakAna()
Default constructor that always creates a new TGraph.
void SetFilter(UInt_t filter, Int_t scale, Double_t sigma=0)
Set the filter to use when peak finding.
Double_t PeakProb(const PeakWindow &window, Double_t scale, Double_t sigma) const
compute a given PeakWindow probability using internal graph
std::vector< PeakWindow > mPeaks
vector that stores all the found peaks in the data
Double_t mStartX
x value for start of the peak window
bool PeakTunnel(const PeakWindow &window) const
test whether a given peak satisifies peak tunnel parameters
void SetPeak(TGraph *gdata)
sets mPeakX based on mP_Peak using line of slopes from points (mP_Peak-1,mP_Peak) and (mP_Peak...
Double_t Baseline() const
bool ValidPeakIdx() const
Double_t mTunnelScale
Scale on exponential for determining tunneling probability (default is 1) see #PeakWindow::PeakTunelP...
UInt_t mFilter
Filter to use in AnalyzeForPeak()
void Init()
Initialize internal varaibles.
Int_t mFilterScale
How many points to group together when applying filter.
Double_t mYRangeMax
Absolute possible y-value maximum of data.
Double_t mEndX
x value for end of the peak window
Double_t mBaseline
Minimum threshold to search for a peak.
Double_t BaselineSigmaScale() const
Double_t mTunnelThreshold
Cutoff probability for peak tunneling method. If threshold less than 0 (default) then skip peak tunne...
Double_t mDeltaX
graph known delta-x
PeakAna & operator=(const PeakAna &rhs)
Assignment operator doesn't clone graph.
Double_t mEndY
y value associated with mEndX
Double_t mPeakY
y-value at mP_Peak
void ConvertPeaksToGraph()
same as ConvertPeaksToGraph() but creates a new graph that replaces old one
Double_t TunnelSigma() const
virtual Double_t PeakTunnelProb(TGraph *graph, Double_t scale=1.0, Double_t sigma=1.0) const
Compute probablity that a given PeakWindow is a real peak.
Double_t mXRangeMin
Absolute possible x-value minimum of data.
PeakWindow mSearch
Variable that defines peak search parameters.
void SetTunnelSigma(Double_t value)
void SetPeak(const Int_t peakpoint, const Double_t peakx)
Overwrite peak location in #mFoundpeak. WARNING doesn't set start and end values nor overwrite mCompu...
bool GoodWindow()
Check if found peak is inside mXRangeMin, mYRangeMin, mXRangeMax, mYRangeMax and has logical values...