StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
PeakAnaPainter.cxx
1 #include "PeakAnaPainter.h"
2 #include "PeakAna.h"
3 
4 ClassImp(PeakAnaPainter)
5 
7 {
8  Init();
9 }
10 
12 {
13  mPA = 0;
14 
15  mTheBaseLine = 0;
16  mTheHitLine = 0;
17 
18  mPaveT_PA = 0;
19  mGraphOption = "";
20  mPeakOption = "";
21  mStatsOption = "";
22 }
23 
24 PeakAnaPainter::~PeakAnaPainter()
25 {
26  delete mTheBaseLine;
27  delete mTheHitLine; mTheHitLine=0;
28  delete mPaveT_PA; mPaveT_PA=0;
29 }
30 
32 {
33  if( ana==0 ){return;}
34  mPA = ana;
35 }
36 
38 {
39  if( mPaveT_PA!=0 ){ mPaveT_PA->Clear(); }
40 }
41 
42 Color_t PeakAnaPainter::GetBaseLineColor()
43 {if(mTheBaseLine==0){return 0;}else{return mTheBaseLine->GetLineColor();} }
44 Style_t PeakAnaPainter::GetBaseLineStyle()
45 {if(mTheBaseLine==0){return 0;}else{return mTheBaseLine->GetLineStyle();} }
46 Width_t PeakAnaPainter::GetBaseLineWidth()
47 {if(mTheBaseLine==0){return 0;}else{return mTheBaseLine->GetLineWidth();} }
48 
49 Color_t PeakAnaPainter::GetHitLineColor()
50 {if(mTheHitLine==0){return 0;}else{return mTheHitLine->GetLineColor();} }
51 Style_t PeakAnaPainter::GetHitLineStyle()
52 {if(mTheHitLine==0){return 0;}else{return mTheHitLine->GetLineStyle();} }
53 Width_t PeakAnaPainter::GetHitLineWidth()
54 {if(mTheHitLine==0){return 0;}else{return mTheHitLine->GetLineWidth();} }
55 
56 void PeakAnaPainter::SetBaseLineColor(Color_t color)
57 {if(mTheBaseLine==0){mTheBaseLine=new TLine();} mTheBaseLine->SetLineColor(color); }
58 void PeakAnaPainter::SetBaseLineColorAlpha(Color_t color,Float_t alpha)
59 {if(mTheBaseLine==0){mTheBaseLine=new TLine();} mTheBaseLine->SetLineColorAlpha(color,alpha); }
60 void PeakAnaPainter::SetBaseLineStyle(Style_t style)
61 {if(mTheBaseLine==0){mTheBaseLine=new TLine();} mTheBaseLine->SetLineStyle(style); }
62 void PeakAnaPainter::SetBaseLineWidth(Width_t width)
63 {if(mTheBaseLine==0){mTheBaseLine=new TLine();} mTheBaseLine->SetLineWidth(width); }
64 
65 void PeakAnaPainter::SetHitLineColor(Color_t color)
66 {if(mTheHitLine==0){mTheHitLine=new TLine();} mTheHitLine->SetLineColor(color); }
67 void PeakAnaPainter::SetHitLineColorAlpha(Color_t color,Float_t alpha)
68 {if(mTheHitLine==0){mTheHitLine=new TLine();} mTheHitLine->SetLineColorAlpha(color,alpha); }
69 void PeakAnaPainter::SetHitLineStyle(Style_t style)
70 {if(mTheHitLine==0){mTheHitLine=new TLine();} mTheHitLine->SetLineStyle(style); }
71 void PeakAnaPainter::SetHitLineWidth(Width_t width)
72 {if(mTheHitLine==0){mTheHitLine=new TLine();} mTheHitLine->SetLineWidth(width); }
73 
74 void PeakAnaPainter::Paint(Option_t* opt)
75 {
76  if( mPA==0 ){ return; }
77  std::string option(opt);
78 
79  CleanPainter();
80  bool drawgraph = true;
81  bool region = false;
82  bool drawbaselines = false;
83  bool drawfoundpeakrange = false;
84  bool drawallpeakranges = false;
85  bool drawfoundmarker = false;
86  bool drawallmarkers = false;
87 
88  std::size_t firstcolon = option.find(";");
89  if( firstcolon!=std::string::npos ){
90  mGraphOption = option.substr(0,firstcolon);
91  std::size_t secondcolon = option.find(";",firstcolon+1);
92  if( secondcolon!=std::string::npos ){
93  mPeakOption = option.substr(firstcolon+1,secondcolon-firstcolon-1);
94  mStatsOption = option.substr(secondcolon+1);
95  std::size_t thirdcolon = option.find(";",secondcolon+1);
96  if( thirdcolon!=std::string::npos ){ LOG_WARN << "PeakAnaPainter::Paint(): Too many semicolons in draw option" << endm; }
97  }
98  else{ mPeakOption = option.substr(firstcolon+1); }
99  }
100  else{ mGraphOption = option; }
101 
102  mPeakOption.ToLower();
103  if( mGraphOption.Length()==0 ){ drawgraph=false; }
104  if( mPeakOption.Contains("r") ){ region=true; }
105  if( mPeakOption.Contains("b") ){ drawbaselines=true; }
106  if( mPeakOption.Contains("f") ){ drawfoundpeakrange=true; }
107  if( mPeakOption.Contains("p") ){ drawfoundpeakrange=true; drawallpeakranges=true; }
108  if( mPeakOption.Contains("m") ){ drawfoundmarker=true; }
109  if( mPeakOption.Contains("w") ){ drawfoundmarker=true; drawallmarkers=true; }
110  if( mPeakOption.Contains("e") ){ drawfoundpeakrange=true; drawallpeakranges=true; drawfoundmarker=true; drawallmarkers=true; }
111  if( mPeakOption.Contains("a") ){ drawbaselines=true; drawfoundpeakrange=true; drawallpeakranges=true; drawfoundmarker=true; drawallmarkers=true; }
112 
113  if( drawgraph ) { this->PaintRawData(); }
114  if( region && drawgraph ) { this->PaintFoundPeak(); } //Doesn't make sense to restrict graph range if graph is not being drawn
115  if( drawbaselines ) { this->PaintBaselines(); }
116  if( drawfoundpeakrange ) { this->PaintFoundPeakRange(); }
117  if( drawallpeakranges ) { this->PaintPeakRanges(); }
118  if( drawfoundmarker ) { this->PaintFoundMarker(); }
119  if( drawallmarkers ) { this->PaintPeakMarkers(); }
120  if( mStatsOption.Length()!=0 ) { this->PaintStats(); }
121 }
122 
123 
124 TPaveText* PeakAnaPainter::MakePaveText(Double_t xmin, Double_t ymin, Double_t xmax, Double_t ymax)
125 {
126  if( mPaveT_PA==0 ){ mPaveT_PA = new TPaveText(xmin,ymin,xmax,ymax,"NB NDC"); }
127  else{
128  mPaveT_PA->Clear();
129  }
130  mPaveT_PA->SetFillColorAlpha(kWhite,1);//Fully opaque by default
131  //mPaveT_PA->SetFillStyle(4000);
132  return mPaveT_PA;
133 }
134 
136 {
137  if( mPA==0 || mPA->GetData()==0 || mPA->GetData()->GetN()==0 ){return false;}
138  else{ return true; }
139 }
140 
142 {
143  if( !ValidGraph() ){ return;}
144  mPA->GetData()->Paint(mGraphOption.Data());
145  return;
146 }
147 
149 {
150  if( !ValidGraph()){return;}
151  Double_t Xmin = mPA->PeakStart();
152  Double_t Xmax = mPA->PeakEnd();
153  if( !(Xmin>mPA->MaxX() || Xmax>mPA->MaxX()) ){mPA->GetData()->GetXaxis()->SetRangeUser(Xmin-5,Xmax+5);}
154 }
155 
157 {
158  Double_t base = mPA->Baseline();
159  Double_t hitline = base+mPA->BaselineSigmaScale()*mPA->BaselineSigma();
160  if( mTheBaseLine==0 ){mTheBaseLine = new TLine(mPA->MinX(),base,mPA->MaxX(),base);}
161  else{ mTheBaseLine->SetY1(base); mTheBaseLine->SetY2(base);}
162  if( mTheHitLine==0 ){mTheHitLine = new TLine(mPA->MinX(),hitline,mPA->MaxX(),hitline);}
163  else{ mTheHitLine->SetY1(hitline); mTheHitLine->SetY2(hitline);}
164  mTheBaseLine->SetLineColor(kBlack);
165  mTheHitLine->SetLineColor(kViolet);
166 
167  mTheBaseLine->Paint();
168  mTheHitLine->Paint();
169 }
170 
172 {
173  if( !ValidGraph() ){return;}
174  Int_t computedindex = mPA->FoundPeakIndex();
175  if( computedindex<0 ){computedindex = mPA->AnalyzeForPeak();}
176  if( computedindex == mPA->NPeaks() ){return;}//If no peak found then computed index is equal to number of peaks in peak vector
177 
178  TLine* sl = mPA->GetPeak(computedindex).GetStartLine(mPA->MinY(),mPA->MaxY());
179  sl->SetLineColor(kRed);
180  sl->Paint();
181  TLine* el = mPA->GetPeak(computedindex).GetEndLine(mPA->MinY(),mPA->MaxY());
182  el->SetLineColor(kOrange);
183  el->Paint();
184 }
185 
186 
188 {
189  if( !ValidGraph() ){return;}
190  Int_t computedindex = mPA->FoundPeakIndex();
191  if(computedindex<0 ){computedindex = mPA->AnalyzeForPeak();}
192 
193  if( mPA->GetDebug() > 1){
194  LOG_DEBUG<< "|SizePeaks:"<<mPA->NPeaks() << "|FoundPeak:"<<computedindex << "|Base:"<<mPA->Baseline() << "|Hit:"<<mPA->Baseline()+mPA->BaselineSigmaScale()*mPA->BaselineSigma();
195  if( mPA->NPeaks()!=0 && computedindex<mPA->NPeaks() ){(mPA->GetPeak(computedindex)).Print("debug");}
196  LOG_DEBUG << endm;
197  }
198 
199  for( UShort_t ipeak = 0; ipeak<mPA->NPeaks(); ++ipeak ){
200  if( ipeak==computedindex ){continue;}
201  mPA->GetPeak(ipeak).GetStartLine( mPA->MinY(), mPA->MaxY() )->Paint();
202  TMarker* mp = mPA->GetPeak(ipeak).GetPeakMarker();
203  mp->SetMarkerSize(mPA->GetMarkerSize()*2.0);
204  mp->Paint();
205  mPA->GetPeak(ipeak).GetEndLine( mPA->MinY(), mPA->MaxY() )->Paint();
206  }
207 
208  return;
209 }
210 
212 {
213  if( !ValidGraph() ){return;}
214  Int_t computedindex = mPA->FoundPeakIndex();
215  if( computedindex<0 ){computedindex = mPA->AnalyzeForPeak();}
216  if( computedindex == mPA->NPeaks() ){return;}//If no peak found then computed index is equal to number of peaks in peak vector
217 
218  TMarker* mp = mPA->GetPeak(computedindex).GetPeakMarker();
219  mp->SetMarkerColor(kViolet);
220  mp->SetMarkerSize(mPA->GetMarkerSize()*2.0);
221  mp->Paint();
222 }
223 
225 {
226  if( !ValidGraph() ){return;}
227  Int_t computedindex = mPA->FoundPeakIndex();
228  if(computedindex<0 ){computedindex = mPA->AnalyzeForPeak();}
229 
230  for( UShort_t ipeak = 0; ipeak<mPA->NPeaks(); ++ipeak ){
231  if( ipeak==computedindex ){continue;}
232  TMarker* mp = mPA->GetPeak(ipeak).GetPeakMarker();
233  mp->SetMarkerSize(mPA->GetMarkerSize()*2.0);
234  mp->Paint();
235  }
236 }
237 
239 {
240  //@[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)
241  this->MakePaveText()->SetTextSize(0.025);
243  //mPaveT_PA->Draw("same");
244  mPaveT_PA->Paint( mPaveT_PA->GetOption() );
245 
246 }
247 
virtual void CleanPainter()
Clean up internal objects.
TString mPeakOption
option for drawing the peaks
bool ValidGraph()
Check if PeakAna object loaded and has a non-zero TGraph.
UInt_t GetDebug() const
Definition: PeakAna.h:227
TLine * mTheHitLine
threshold for a peak PeakAna::mBaseline + PeakAna::mBaselineSigma*PeakAna::mBaselineSigmaScale ...
TString mGraphOption
option for drawing the TGraph
TLine * GetStartLine(Double_t ymin=0, Double_t ymax=0)
Create and return a TLine for the start of the peak window.
Definition: PeakWindow.cxx:317
virtual void SetPeakAna(PeakAna *ana)
Double_t MinY() const
Definition: PeakAna.h:182
const PeakWindow & GetPeak(UInt_t peakidx) const
Definition: PeakAna.h:228
Int_t FoundPeakIndex() const
Definition: PeakAna.h:233
virtual void PaintFoundPeakRange()
Just draw the found peak on the current pad.
virtual TGraph * GetData() const
Definition: PeakAna.h:226
TMarker * GetPeakMarker()
Create and return a TMarker to mark the location of the peak.
Definition: PeakWindow.cxx:349
Double_t PeakEnd()
Found Signal ending x-value.
Definition: PeakAna.h:250
virtual void PaintPeakRanges()
Draw all found peaks on the current pad except the found peak.
TLine * mTheBaseLine
line for the PeakAna::mBaseline
virtual void PaintRawData()
Raw data with no modifications.
Double_t MinX() const
Definition: PeakAna.h:181
virtual Int_t AnalyzeForPeak()
Main analysis method for finding peaks.
Definition: PeakAna.cxx:153
Double_t MaxX() const
Definition: PeakAna.h:183
Double_t PeakStart()
Found Signal starting x-value.
Definition: PeakAna.h:249
TString mStatsOption
option for what to put in stats box
virtual void AddPeakStats(TPaveText *pave, const char *opt="")
Add peak information to a &quot;statistics&quot; box.
Definition: PeakAna.cxx:1010
virtual void PaintFoundMarker()
Draw the marker indicating the found peak.
Double_t BaselineSigma() const
Definition: PeakAna.h:179
PeakAna * mPA
pointer to PeakAna for drawing (PA=PeakAna)
virtual void PaintBaselines()
Just draw the baseline and hitlines.
Double_t MaxY() const
Definition: PeakAna.h:184
virtual void PaintPeakMarkers()
Draw markers indicating all peaks except the found peak marker.
virtual void PaintStats()
Draw Stats box for peak finding.
Double_t Baseline() const
Definition: PeakAna.h:178
int NPeaks() const
Definition: PeakAna.h:246
TPaveText * mPaveT_PA
for custom stats box
virtual TPaveText * MakePaveText(Double_t xmin=0.7, Double_t ymin=0.5, Double_t xmax=1.0, Double_t ymax=1.0)
Makes the stats box to show peak infomation.
Double_t BaselineSigmaScale() const
Definition: PeakAna.h:180
virtual void PaintFoundPeak()
Raw data inside zoomed in on found signal region.
TLine * GetEndLine(Double_t ymin=0, Double_t ymax=0)
Create and return a TLine for the end of the peak window.
Definition: PeakWindow.cxx:373
void Init()
Initialize internal variables to null.