Skip to content

Commit

Permalink
More additions and fixes to StFcsWaveformFitMaker and related classes (
Browse files Browse the repository at this point in the history
…star-bnl#579)

Added and changed some options for PeakAnaPainter; made corresponding
fixes of draw options in other parts of the code. Fixed an issue in the
GetPossiblePeaks algorithm of PeakAna. Fix for StFcsWaveformFitMaker to
prevent double calls to AnaPed() for pedestal determination. Added
pedestal subtraction to sum methods.
  • Loading branch information
dkapukchyan authored Sep 27, 2023
1 parent 7eaf967 commit 1d76e83
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 81 deletions.
22 changes: 16 additions & 6 deletions StRoot/StFcsWaveformFitMaker/PeakAna.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -487,12 +487,14 @@ PeakAna* PeakAna::MeanFilter( Int_t sizeavgs, bool copy )
}
}
ynew[ipoint] = sumvalues/sumweights;
if( GetDebug()>2 ){ std::cout << " - |i:"<<ipoint<<"|ynew:"<<ynew[ipoint] << std::endl; }
}

if( copy ){
TGraph* filtered = new TGraph(npoints,xdata,ynew);
PeakAna* ana = new PeakAna(*this,filtered);
ana->ForceInternal();
if( GetDebug()>1 ){ std::cout << "PeakAna::MeanFilter:Copied PeakAna" << std::endl; }
return ana;
}
if( mInternalSignal ){
Expand All @@ -501,11 +503,13 @@ PeakAna* PeakAna::MeanFilter( Int_t sizeavgs, bool copy )
//[July 3, 2022]>Taken from TGraph CtorAllocate(). Setting minimum and maximum to -1111 effectivley resets the minimum and maximum.
GetData()->SetMinimum(-1111);
GetData()->SetMaximum(-1111);
if( GetDebug()>1 ){ std::cout << "PeakAna::MeanFilter:Internal Graph Modified" << std::endl; }
}
else{
TGraph* graph = new TGraph(npoints,xdata,ynew );
SetData(graph);
ForceInternal();
if( GetDebug()>1 ){ std::cout << "PeakAna::MeanFilter:Created New Internal Graph" << std::endl; }
}
ResetPeak();
return this;
Expand Down Expand Up @@ -578,13 +582,15 @@ PeakAna* PeakAna::GausFilter( Int_t sizeavgs, bool copy )
else{ sumweights += 2; }
}
ynew[ipoint] = sumvalues/sumweights;
if( GetDebug()>2 ){ std::cout << " - |i:"<<ipoint<<"|ynew:"<<ynew[ipoint] << std::endl; }
}


if( copy ){
TGraph* filtered = new TGraph(npoints,xdata,ynew);
PeakAna* ana = new PeakAna(*this,filtered);
ana->ForceInternal();
if( GetDebug()>1 ){ std::cout << "PeakAna::MeanFilter:Copied PeakAna" << std::endl; }
return ana;
}
if( mInternalSignal ){
Expand All @@ -593,11 +599,13 @@ PeakAna* PeakAna::GausFilter( Int_t sizeavgs, bool copy )
//[July 3, 2022]>Taken from TGraph CtorAllocate(). Setting minimum and maximum to -1111 effectivley resets the minimum and maximum.
GetData()->SetMinimum(-1111);
GetData()->SetMaximum(-1111);
if( GetDebug()>1 ){ std::cout << "PeakAna::MeanFilter:Internal Graph Modified" << std::endl; }
}
else{
TGraph* graph = new TGraph(npoints,xdata,ynew );
SetData(graph);
ForceInternal();
if( GetDebug()>1 ){ std::cout << "PeakAna::MeanFilter:Created New Internal Graph" << std::endl; }
}
ResetPeak();
return this;
Expand Down Expand Up @@ -673,12 +681,14 @@ void PeakAna::GetPossiblePeaks()
//Check above will skip bad values
if( peak.mStartX<mXRangeMin ){//No start time yet
if( GetDebug()>1 ){LOG_DEBUG << " + No StartTime" << endm;}
if( LY>baseline+slopecutoff && Slope>0 ){
//Needs to be checked sequentially since we need to reject any points below the baseline+cutoff that may have a large slope
if( GetDebug()>1 ){LOG_DEBUG << " + Passed Slope and baselineCutoff setting as start time" << endm;}
peak.mStartX=LX;//Set start x-value
peak.mStartY=LY;//Set start y-value
LocalMax=LX;//Start checking local maximums
if( Slope>0){
if( LY>baseline+slopecutoff || RY>baseline+slopecutoff ){
//Needs to be checked sequentially since we need to reject any points below the baseline+cutoff that may have a large slope
if( GetDebug()>1 ){LOG_DEBUG << " + Passed Slope and baselineCutoff setting as start time" << endm;}
peak.mStartX=LX;//Set start x-value
peak.mStartY=LY;//Set start y-value
LocalMax=LX;//Start checking local maximums
}
}
//If didn't pass thresholds for start time then continue to next point
}
Expand Down
17 changes: 11 additions & 6 deletions StRoot/StFcsWaveformFitMaker/PeakAna.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/*
Author: David Kapukchyan
@[October 20, 2022]
> Added doxygen style comments
@[September 29, 2022]
> Got rid of the virtual painter as it is no longer needed
Expand Down Expand Up @@ -86,7 +89,6 @@ There is a helper data class #PeakWindow which holds the found peak data.

//Custom Headers
#include "PeakWindow.h"
//#include "PeakAnaVirtualPainter.h"
class PeakAnaPainter;

class PeakAna : public TObject
Expand Down Expand Up @@ -192,13 +194,16 @@ class PeakAna : public TObject
peak qa drawing options(case insensitive):\n
- "R" for range\n
- "B" for baselines\n
- "F" found peak qa\n
- "P" for full peak qa\n
- "A" for all, which combines "P" and "B"\n
stats drawing options(case insensitive):\n
- "F" found peak window\n
- "P" for all peak windows\n
- "M" for found peak marker\n
- "W" for all peak markers (upside down M)\n
- "E" combines "P" and "W"\n
- "A" for all, which combines "B", "P", and "W"\n
stats drawing options(case insensitive):\n
- "S" is to show just the found peak\n
- "A" is to show for all peaks\n
- "D" is whether to show detailed printout or not (works with option "S" or "A")
- "D" is whether to show detailed printout or not (works with option "S" or "A")\n
Example1: "APL;FB;S" means draw graph using option "APL", draw only found peak qa and baselines, and create a stats box showing only basic information about the found peak.
Example2: ";A;AD" means don't draw graph but draw all peaks and put detailed information of all peaks in a stats box
Expand Down
86 changes: 45 additions & 41 deletions StRoot/StFcsWaveformFitMaker/PeakAnaPainter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ void PeakAnaPainter::Paint(Option_t* opt)
bool drawgraph = true;
bool region = false;
bool drawbaselines = false;
bool drawfoundpeakqa = false;
bool drawfullpeakqa = false;
bool drawfoundpeakrange = false;
bool drawallpeakranges = false;
bool drawfoundmarker = false;
bool drawallmarkers = false;

std::size_t firstcolon = option.find(";");
if( firstcolon!=std::string::npos ){
Expand All @@ -99,19 +101,22 @@ void PeakAnaPainter::Paint(Option_t* opt)

mPeakOption.ToLower();
if( mGraphOption.Length()==0 ){ drawgraph=false; }
//if( peakopts.Contains("e") ){ drawgraph=false; }
if( mPeakOption.Contains("r") ){ region=true; }
if( mPeakOption.Contains("b") ){ drawbaselines=true; }
if( mPeakOption.Contains("f") ){ drawfoundpeakqa=true; }
if( mPeakOption.Contains("p") ){ drawfullpeakqa=true; }
if( mPeakOption.Contains("a") ){ drawbaselines=true; drawfullpeakqa=true; }
if( mPeakOption.Contains("f") ){ drawfoundpeakrange=true; }
if( mPeakOption.Contains("p") ){ drawfoundpeakrange=true; drawallpeakranges=true; }
if( mPeakOption.Contains("m") ){ drawfoundmarker=true; }
if( mPeakOption.Contains("w") ){ drawfoundmarker=true; drawallmarkers=true; }
if( mPeakOption.Contains("e") ){ drawfoundpeakrange=true; drawallpeakranges=true; drawfoundmarker=true; drawallmarkers=true; }
if( mPeakOption.Contains("a") ){ drawbaselines=true; drawfoundpeakrange=true; drawallpeakranges=true; drawfoundmarker=true; drawallmarkers=true; }

if( drawfoundpeakqa && drawfullpeakqa ){ drawfoundpeakqa=false; }//Redundant to do both found and all peaks
if( drawgraph ) { this->PaintRawData(); }
if( region && drawgraph ) { this->PaintFoundPeak(); } //Doesn't make sense to restrict graph range if graph is not being drawn
if( drawbaselines ) { this->PaintBaselines(); }
if( drawfoundpeakqa ) { this->PaintFoundPeakQa(); }
if( drawfullpeakqa ) { this->PaintPeakRanges(); }
if( drawfoundpeakrange ) { this->PaintFoundPeakRange(); }
if( drawallpeakranges ) { this->PaintPeakRanges(); }
if( drawfoundmarker ) { this->PaintFoundMarker(); }
if( drawallmarkers ) { this->PaintPeakMarkers(); }
if( mStatsOption.Length()!=0 ) { this->PaintStats(); }
}

Expand Down Expand Up @@ -143,37 +148,11 @@ void PeakAnaPainter::PaintRawData( )
void PeakAnaPainter::PaintFoundPeak( )
{
if( !ValidGraph()){return;}

Double_t Xmin = mPA->PeakStart();
Double_t Xmax = mPA->PeakEnd();
if( !(Xmin>mPA->MaxX() || Xmax>mPA->MaxX()) ){mPA->GetData()->GetXaxis()->SetRangeUser(Xmin-5,Xmax+5);}
}

void PeakAnaPainter::PaintFoundPeakQa()
{
if( !ValidGraph() ){return;}

Int_t computedindex = mPA->FoundPeakIndex();
if( computedindex<0 ){ computedindex = mPA->AnalyzeForPeak(); }
this->PaintBaselines();
this->PaintFoundRange();

return;
}

void PeakAnaPainter::PaintPeakQa( )
{
if( !ValidGraph() ){return;}

Int_t computedindex = mPA->FoundPeakIndex();
if( computedindex<0 ){computedindex = mPA->AnalyzeForPeak();}

this->PaintBaselines();
this->PaintPeakRanges();

return;
}

void PeakAnaPainter::PaintBaselines()
{
Double_t base = mPA->Baseline();
Expand All @@ -189,26 +168,25 @@ void PeakAnaPainter::PaintBaselines()
mTheHitLine->Paint();
}

void PeakAnaPainter::PaintFoundRange()
void PeakAnaPainter::PaintFoundPeakRange()
{
if( !ValidGraph() ){return;}
Int_t computedindex = mPA->FoundPeakIndex();
if( computedindex<0 ){computedindex = mPA->AnalyzeForPeak();}
if( computedindex == mPA->NPeaks() ){return;}//If no peak found then computed index is equal to number of peaks in peak vector

TLine* sl = mPA->GetPeak(computedindex).GetStartLine(mPA->MinY(),mPA->MaxY());
sl->SetLineColor(kRed);
sl->Paint();
TMarker* mp = mPA->GetPeak(computedindex).GetPeakMarker();
mp->SetMarkerColor(kViolet);
mp->SetMarkerSize(mPA->GetMarkerSize()*2.0);
mp->Paint();
TLine* el = mPA->GetPeak(computedindex).GetEndLine(mPA->MinY(),mPA->MaxY());
el->SetLineColor(kOrange);
el->Paint();
}


void PeakAnaPainter::PaintPeakRanges( )
{
if( !ValidGraph() ){return;}
Int_t computedindex = mPA->FoundPeakIndex();
if(computedindex<0 ){computedindex = mPA->AnalyzeForPeak();}

Expand All @@ -226,11 +204,37 @@ void PeakAnaPainter::PaintPeakRanges( )
mp->Paint();
mPA->GetPeak(ipeak).GetEndLine( mPA->MinY(), mPA->MaxY() )->Paint();
}
this->PaintFoundRange();

return;
}

void PeakAnaPainter::PaintFoundMarker()
{
if( !ValidGraph() ){return;}
Int_t computedindex = mPA->FoundPeakIndex();
if( computedindex<0 ){computedindex = mPA->AnalyzeForPeak();}
if( computedindex == mPA->NPeaks() ){return;}//If no peak found then computed index is equal to number of peaks in peak vector

TMarker* mp = mPA->GetPeak(computedindex).GetPeakMarker();
mp->SetMarkerColor(kViolet);
mp->SetMarkerSize(mPA->GetMarkerSize()*2.0);
mp->Paint();
}

void PeakAnaPainter::PaintPeakMarkers()
{
if( !ValidGraph() ){return;}
Int_t computedindex = mPA->FoundPeakIndex();
if(computedindex<0 ){computedindex = mPA->AnalyzeForPeak();}

for( UShort_t ipeak = 0; ipeak<mPA->NPeaks(); ++ipeak ){
if( ipeak==computedindex ){continue;}
TMarker* mp = mPA->GetPeak(ipeak).GetPeakMarker();
mp->SetMarkerSize(mPA->GetMarkerSize()*2.0);
mp->Paint();
}
}

void PeakAnaPainter::PaintStats()
{
//@[April 8, 2022]>Need a way to determine size of pavetext from number of peaks as well as information to be added for each peak (this could be as simple as counting the number of lines and scaling the size accordingly)
Expand Down
19 changes: 11 additions & 8 deletions StRoot/StFcsWaveformFitMaker/PeakAnaPainter.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/*
Author: David Kapukchyan
@[July 5, 2023]
> Modified paint functions to only paint certain things and added options to select what to paint
@[October 20, 2022]
> Added doxygen style comments
Expand Down Expand Up @@ -53,14 +56,14 @@ class PeakAnaPainter : public TObject
virtual ~PeakAnaPainter();

virtual void Paint(Option_t *opt="");
virtual void PaintRawData(); //!< Raw data with no modifications
virtual void PaintFoundPeak(); //!< Raw data inside zoomed in on found signal region
virtual void PaintFoundPeakQa(); //!< Draw signal and found signal window
virtual void PaintPeakQa(); //!< Show all found signal windows and signal
virtual void PaintBaselines(); //!< Just draw the baseline and hitlines
virtual void PaintFoundRange(); //!< Just draw the found peak on the current pad
virtual void PaintPeakRanges(); //!< Draw all found peaks on the current pad
virtual void PaintStats(); //!< Draw Stats box for peak finding
virtual void PaintRawData(); //!< Raw data with no modifications
virtual void PaintFoundPeak(); //!< Raw data inside zoomed in on found signal region
virtual void PaintBaselines(); //!< Just draw the baseline and hitlines
virtual void PaintFoundPeakRange(); //!< Just draw the found peak on the current pad
virtual void PaintPeakRanges(); //!< Draw all found peaks on the current pad except the found peak
virtual void PaintFoundMarker(); //!< Draw the marker indicating the found peak
virtual void PaintPeakMarkers(); //!< Draw markers indicating all peaks except the found peak marker
virtual void PaintStats(); //!< Draw Stats box for peak finding

virtual void CleanPainter(); //!< Clean up internal objects

Expand Down
Loading

0 comments on commit 1d76e83

Please sign in to comment.