GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Peak1D.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2004 by Olivier Stezowski, B. Rosse & Christian Finck *
3  * stezow(AT)ipnl.in2p3.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
20 
23 #ifndef Gw_Peak1D
24 #define Gw_Peak1D
25 
26 #include "GwLogMessage.h"
27 #include "BasePeak.h"
28 
29 #include "Rtypes.h"
30 #include "TPolyLine.h"
31 #include "TVector2.h"
32 #include "TList.h"
33 #include "TGraph.h"
34 #include "NDB.h"
35 
36 class TF1;
37 class TH1;
38 class TMarker;
39 
40 namespace Gw {
41 
79 class Peak1D : public BasePeak {
80 
81 public:
82  enum EDrawAs { kPeak, kGate };
83 
84 public:
86  static Color_t GetDefaultMarkerColor()
87  { return fgMarkerColor; }
89  static Color_t GetDefaultFuncColor()
90  { return fgFuncColor; }
92  static void SetDefaultMarkerColor(Color_t c)
93  { fgMarkerColor = c; }
95  static void SetDefaultFuncColor(Color_t c)
96  { fgFuncColor = c; }
97 
98 public:
99  Peak1D();
100  Peak1D(const char* name, const char* title);
101  Peak1D(TPolyLine* polyline);
102  Peak1D(const Peak1D& p);
103  virtual ~Peak1D();
104 
106  // Peak1D& operator=(const Peak1D& p);
107  // Root copy, copy this to o
108  virtual void Copy(TObject &o) const;
109 
110 // Actions : Area, Fit
112  virtual void Fit(TH1 *histo, Option_t* optFit = "RN", Option_t* optBkg = "pol1");
113 
115  virtual void FitCombined(TH1 *histo, TList* peakList, Option_t* optFit = "RN", Option_t* optBkg = "pol1");
116 
118  void FitMenu(const char* nameFunc = "gaus", Option_t* optFit = "RN", Option_t* optBkg = "pol1"); //*MENU*
119 
121  virtual void Print(Option_t* opt ="f") const; //*MENU*
122 
124 
131  virtual void Area(Option_t *opt = "h"); //*MENU*
132 
133 // Set/Get methods
135  void SetPeak(Double_t pos, Double_t height, Double_t fwhm, Double_t intensity=0); //*MENU={Hierarchy="SetPeak/All"}*
137  void SetPeakFromFit();
139  void SetHeight(const Double_t height); // *MENU={Hierarchy="SetPeak/Height"}* *GETTER=GetHeight
141  void SetIntensity(const Double_t intensity);
143  virtual void SetPosition(const Double_t position, Option_t* axis = "X"); // *MENU={Hierarchy="SetPeak/Position"}* *GETTER=GetPosition
145  virtual void SetFWHM(const Double_t FWHM, Option_t* axis = "X"); // *MENU={Hierarchy="SetPeak/FWHM"}* *GETTER=GetFWHM
147  void SetBackground(Double_t bgLeft1, Double_t bgLeft2, Double_t bgRight1,Double_t bgRight2,
148  Double_t bgLevelLeft1, Double_t bgLevelLeft2, Double_t bgLevelRight1,Double_t bgLevelRight2);
150  // void SetBackground( Double_t bgLeft1, Double_t bgLeft2, Double_t bgRight1, Double_t bgRight2, const TVirtualPad *pad = 0x0);
151  void SetBackground( Double_t bgLeft1, Double_t bgLeft2, Double_t bgRight1, Double_t bgRight2, const TH1* );
153  void SetMarkerColor(Int_t color);
154 
156  virtual Double_t GetPosition(Option_t* axis = "X") const;
158  virtual Double_t GetFWHM(Option_t* axis = "X") const;
160  virtual TF1 *SetSignalFunction(const char* nameFunc = "gaus", TH1 *h=0x0);
162  virtual TF1 *SetSignalFunction(const TF1* func);
164  virtual TF1 *SignalFunction()
165  { return fSigFunc; }
167  virtual TF1 *PeakFunction()
168  { return fPeakFunc; }
170  virtual TF1 *SetBkgFunction(const char* nameFunc = "-");
172  virtual TF1 *SetBkgFunction(const TF1* func);
174  virtual TF1 *BkgFunction()
175  { return fBkgFunc; }
177  virtual TF1 *SignalAndBkgFunction();
178 
180  double Landau(double*xx,double*pp);
182  double Gaus(double*xx,double*pp);
184  double DoubleSidedCrystalBallFct(double*xx,double*pp);
186  double DoubleTailedGaussian(double*xx,double*pp);
188  double DoubleTailedStepedGaussian(double*xx,double*pp);
189 
190  TF1 *ExtractBkgFromDTGStep(TString Name);
191 
193  void WithBkg(Bool_t with_bg = true); //*TOGGLE* *GETTER=IsWithBkg
194 
196  Bool_t IsWithBkg() const
197  { return fBkgFlag; }
198 
200  virtual void SetBinWidth(Double_t width) {fBinWidth = width;}
201  virtual Double_t GetBinWidth() {return fBinWidth;}
202 
204  virtual void SetFillColorPeak(Color_t color);
205  virtual void SetFillStylePeak(Style_t style);
206  virtual void SetLineColorPeak(Color_t color);
207  virtual void SetLineWidthPeak(Width_t width);
208 
210  virtual void SetFillColorBkg(Color_t color);
211  virtual void SetFillStyleBkg(Style_t style);
212  virtual void SetLineColorBkg(Color_t color);
213  virtual void SetLineWidthBkg(Width_t width);
214 
216  virtual Color_t GetLineColorPeak();
217 
219  virtual TMarker* GetMarker(Int_t markerId);
220 
222  virtual TF1* GetSigFunction()
223  {return fSigFunc;}
224 
226  virtual void SetDrawAs(EDrawAs d);
228  virtual EDrawAs GetDrawAs() const
229  { return fDrawAs; }
230  virtual void SetDrawOption(Option_t* option = ""); //*MENU*
231 
233  virtual Bool_t IsSortable() const
234  {return kTRUE;}
235  virtual Int_t Compare(const TObject *obj) const;
236 
238  Double_t GetBase() const
239  { return fPolyLinePeak.GetY()[0]; }
240 
242  const TVector2 GetBkgLeft() const
243  { return TVector2(fBkgLeft1, fBkgLeft2); }
244  const TVector2 GetBkgRight() const
245  { return TVector2(fBkgRight1, fBkgRight2); }
246 
248  Short_t IsPointInBkg(Double_t x, Double_t /*y*/ = 0)
249  {
250  if ( x < fBkgLeft1 || x > fBkgRight2 )
251  return 2;
252  if ( x <= fBkgLeft2 || x >= fBkgRight1 )
253  return 1;
254  return 0;
255  }
256 
258  Double_t GetBkgIntegral() const { return fBkgIntegral;}
259 
261  Double_t GetPeakIntegral() const { return fPeakIntegral;}
262  Double_t GetPeakIntegralError() const { return fPeakIntegralError;}
263  void SetPeakIntegralError(Double_t IntErr) { fPeakIntegralError = IntErr;}
264 
266  Double_t GetSubPeakIntegral() const { return fSubPeakIntegral;}
267 
268 // Draw/Paint methods
270 
278  virtual void Paint(Option_t* opt ="");
279  virtual void Draw(Option_t* opt = "");
280  virtual void Browse(TBrowser * /*b*/)
281  {
282  Peak1D::Draw();
283  }
285  virtual void PaintFor(Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax);
286 
288  virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py);
289 
291  virtual Int_t DistancetoPrimitive(Int_t px, Int_t py);
292 
294  Double_t SignalAndBkg(Double_t* x, Double_t* par);
295  Double_t Bkg(Double_t* x, Double_t* par);
296 
297 private:
299  void SetPeakPoints();
300 
302  void SetPeakPoints(TPolyLine* polyline);
303 
305  void SetBkgPoints();
306 
308  void UpdatePeak();
309 
311  void UpdateBkg();
312 
314  void SetModified(TPolyLine &p, Bool_t modif = true);
316  Bool_t IsModified(TPolyLine &p);
317 
319  void InitPeakMarkers();
321  void ShiftPolyline(TPolyLine &, Double_t, Double_t);
323  void SetAllPointsinPolyline(TPolyLine &, Double_t x = 0.0, Double_t y = 0.0);
324 
326  void FitIsWithBkg(TH1* h, Option_t* optFit);
327 
328 private:
329  // peak's definition
330  Double_t fPosition; // Position of the Peak in energy
331  Double_t fFWHM; // FWHM of the Peak
332 
333  Double_t fBkgLeft1; // lower limit for left side background
334  Double_t fBkgLeft2; // upper limit for left side background
335  Double_t fBkgRight1; // lower limit for right side background
336  Double_t fBkgRight2; // upper limit for right side background
337  Double_t fBkgLevelLeft1; // level lower limit for left side background
338  Double_t fBkgLevelLeft2; // level upper limit for left side background
339  Double_t fBkgLevelRight1; // level lower limit for right side background
340  Double_t fBkgLevelRight2; // level upper limit for right side background
341  Double_t fBkgIntegral; // Total counts in background
342  Double_t fPeakIntegral; // Total counts in peak (bg substracted)
343  Double_t fPeakIntegralError;
344  Double_t fSubPeakIntegral; // Integral of background under peak
345 
346  Bool_t fBkgFlag; // flag w/o background
347 
348 protected:
349 
350  Double_t fBinWidth;
351 
352  // peak's display
353  TPolyLine fPolyLinePeak; // pointer to polyline peak
354  TPolyLine fPolyLineBkgL; // pointer to polyline left background
355  TPolyLine fPolyLineBkgR; // pointer to polyline right background
356 
357  TPolyLine* fCPolyline;
358  TPolyLine fCopyPolyline;
359 
360  TList fMarkerList; // list of different markers
361  EDrawAs fDrawAs; // flag for drawing polyline as gate ot peak
362 
363 public:
364 
366  bool IsDrawAs(EDrawAs mode){if(fDrawAs == mode) return true; else return false;}
367 
368  // peak's fit
369  TF1* fSigFunc; // pointer to signal function
370  TF1* fBkgFunc; // pointer to bkg function
371  TF1* fPeakFunc;
373 
374 protected:
375  static const Int_t fgkPointsPeak; // nb of polyline points for the peak
376  static const Int_t fgkPointsBkg; // nb of polyline points for background
377  static const Int_t fgkPeakIdx; // index of the peak central point
378 
379  static Color_t fgLineColorPeak[]; // default line color for peak
380  static Style_t fgFillStylePeak; // default fill style for peak
381  static Color_t fgLineColorBkg; // default line color for background
382  static Style_t fgFillStyleBkg; // default fill style for background
383  static Color_t fgMarkerColor; // default marker color
384  static Color_t fgFuncColor; // default function color
385 
386 
387 protected:
390 
391 public:
395 
396 protected:
397  mutable LogMessage fLog;
398 
399 private:
400  TGraph *fEfficiencyGraph;
401  TF1 *fEfficiencyFunc;
402  Float_t fRefArea;
403  Float_t fRefAreaError;
404  Float_t fEffRelError; //Relative error on afficiency curves
405 public:
406  void SetEfficiencyGraph(TGraph *gr, Float_t EffRelError = 0.1){fEfficiencyGraph = gr; fRefArea = 1; fRefAreaError = 0.;fEffRelError = EffRelError;}
407  void SetEfficiencyFunc(TF1 *f, Float_t EffRelError = 0.1){fEfficiencyFunc = f; fRefArea = 1; fRefAreaError = 0.;fEffRelError = EffRelError;}
408  void SetRefArea(Float_t a, Float_t ea){fRefArea = a; fRefAreaError = ea;}
409 
410 public:
411  ClassDef(Peak1D,5) // A 1D Peak
412 };
413 
414 }
415 #endif
TF1 * fPeakFunc
Definition: Peak1D.h:371
static Color_t fgLineColorPeak[]
Definition: Peak1D.h:379
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Handle event in pad.
Definition: Peak1D.cpp:1825
virtual void PaintFor(Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax)
set attribute to paint this gate on the given histogram
Definition: Peak1D.cpp:1999
void FitMenu(const char *nameFunc="gaus", Option_t *optFit="RN", Option_t *optBkg="pol1")
Fit with given function and background.
Definition: Peak1D.cpp:981
virtual void SetLineColorPeak(Color_t color)
Definition: Peak1D.cpp:1651
LogMessage fLog
Definition: Peak1D.h:397
virtual EDrawAs GetDrawAs() const
to know the current display mode
Definition: Peak1D.h:228
void SetEfficiencyGraph(TGraph *gr, Float_t EffRelError=0.1)
Definition: Peak1D.h:406
bool fIsAGammaSourceRay
Definition: Peak1D.h:388
static void SetDefaultMarkerColor(Color_t c)
Set default marker color.
Definition: Peak1D.h:92
void SetPeak(Double_t pos, Double_t height, Double_t fwhm, Double_t intensity=0)
Set peak members.
Definition: Peak1D.cpp:519
double Landau(double *xx, double *pp)
Landau Fonction.
Definition: Peak1D.cpp:2279
static void SetDefaultFuncColor(Color_t c)
Set default function color.
Definition: Peak1D.h:95
virtual TF1 * SignalAndBkgFunction()
Access to signal+Bkg function. Signa + Bkg must be set first, parameter are copied ! ...
Definition: Peak1D.cpp:483
void WithBkg(Bool_t with_bg=true)
toggle background (fit and display)
Definition: Peak1D.cpp:513
TPolyLine fCopyPolyline
current polyline
Definition: Peak1D.h:358
virtual void SetPosition(const Double_t position, Option_t *axis="X")
Set Position of peak.
Definition: Peak1D.cpp:546
GammaSourceRay * GetGammaSourceRay()
Definition: Peak1D.h:393
virtual void SetFWHM(const Double_t FWHM, Option_t *axis="X")
Set FWHM of peak.
Definition: Peak1D.cpp:555
static Color_t fgMarkerColor
Definition: Peak1D.h:383
double Gaus(double *xx, double *pp)
Gaus Fonction.
Definition: Peak1D.cpp:2252
void SetRefArea(Float_t a, Float_t ea)
Definition: Peak1D.h:408
TF1 * ExtractBkgFromDTGStep(TString Name)
Definition: Peak1D.cpp:2430
Bool_t IsWithBkg() const
Test if peak defined with background.
Definition: Peak1D.h:196
void SetEfficiencyFunc(TF1 *f, Float_t EffRelError=0.1)
Definition: Peak1D.h:407
virtual void SetFillColorBkg(Color_t color)
Set line attribute for bkg.
Definition: Peak1D.cpp:1702
bool IsDrawAs(EDrawAs mode)
To test the draw mod ex: IsDrawAs(kGate)
Definition: Peak1D.h:366
Base class for a Log message.
Definition: GwLogMessage.h:94
static Style_t fgFillStylePeak
Definition: Peak1D.h:380
TPolyLine fPolyLinePeak
Definition: Peak1D.h:353
TH1F * histo[MaxValue]
Definition: ReadDaqAlone.C:31
virtual void SetFillStylePeak(Style_t style)
Definition: Peak1D.cpp:1678
static const Int_t fgkPointsPeak
pointer to signal+ bkg function
Definition: Peak1D.h:375
Double_t GetPeakIntegral() const
Get integral of peak after calling area method.
Definition: Peak1D.h:261
virtual ~Peak1D()
Definition: Peak1D.cpp:442
Double_t SignalAndBkg(Double_t *x, Double_t *par)
functions used to really fit
Definition: Peak1D.cpp:472
header file for GwLogMessage.cpp
static Color_t GetDefaultFuncColor()
Get default function color.
Definition: Peak1D.h:89
EDrawAs fDrawAs
Definition: Peak1D.h:361
TPolyLine fPolyLineBkgL
Definition: Peak1D.h:354
virtual TF1 * PeakFunction()
Access to peak function ... don't delete it !
Definition: Peak1D.h:167
GammaSourceRay * fGammaSourceRay
Definition: Peak1D.h:389
Double_t Bkg(Double_t *x, Double_t *par)
Definition: Peak1D.cpp:455
virtual void Browse(TBrowser *)
Definition: Peak1D.h:280
void SetPeakIntegralError(Double_t IntErr)
Definition: Peak1D.h:263
virtual Color_t GetLineColorPeak()
Get line peak color.
Definition: Peak1D.cpp:1658
virtual void Fit(TH1 *histo, Option_t *optFit="RN", Option_t *optBkg="pol1")
Fit peak with background.
Definition: Peak1D.cpp:1406
Double_t GetSubPeakIntegral() const
Get integral of background under peak after calling area method.
Definition: Peak1D.h:266
static Color_t GetDefaultMarkerColor()
Get default marker color.
Definition: Peak1D.h:86
static const Int_t fgkPointsBkg
Definition: Peak1D.h:376
virtual Double_t GetFWHM(Option_t *axis="X") const
Get FWHM of peak.
Definition: Peak1D.cpp:962
const TVector2 GetBkgRight() const
Definition: Peak1D.h:244
TList fMarkerList
current polyline before modification
Definition: Peak1D.h:360
virtual void Paint(Option_t *opt="")
Paint method.
Definition: Peak1D.cpp:1729
virtual TF1 * SignalFunction()
Access to signal function ... don't delete it !
Definition: Peak1D.h:164
virtual Double_t GetPosition(Option_t *axis="X") const
Get position of peak.
Definition: Peak1D.cpp:955
Double_t fBinWidth
Definition: Peak1D.h:350
virtual TMarker * GetMarker(Int_t markerId)
Get marker for a given Id.
Definition: Peak1D.cpp:969
virtual void Print(Option_t *opt="f") const
Print current peak.
Definition: Peak1D.cpp:1594
virtual TF1 * BkgFunction()
Access to signal function ... don't delete it !
Definition: Peak1D.h:174
void SetHeight(const Double_t height)
Set height of peak.
Definition: Peak1D.cpp:567
void SetPeakFromFit()
Set peak members + polyline.
Definition: Peak1D.cpp:530
virtual void SetLineWidthPeak(Width_t width)
Definition: Peak1D.cpp:1664
static Color_t fgFuncColor
Definition: Peak1D.h:384
TPolyLine fPolyLineBkgR
Definition: Peak1D.h:355
virtual Double_t GetBinWidth()
Definition: Peak1D.h:201
Double_t GetBkgIntegral() const
Get integral of background after calling area method.
Definition: Peak1D.h:258
double DoubleTailedGaussian(double *xx, double *pp)
Double tailed gaussian (Dino like)
Definition: Peak1D.cpp:2351
static const Int_t fgkPeakIdx
Definition: Peak1D.h:377
void SetMarkerColor(Int_t color)
Set marker color of the peak polyline.
Definition: Peak1D.cpp:640
double DoubleSidedCrystalBallFct(double *xx, double *pp)
Double Sided Crystal Ball Fonction.
Definition: Peak1D.cpp:2306
TF1 * fSigFunc
Definition: Peak1D.h:369
virtual void SetBinWidth(Double_t width)
BinWidth of the fitted histogram for area correction.
Definition: Peak1D.h:200
Double_t GetBase() const
Get base of peakM.
Definition: Peak1D.h:238
virtual void Area(Option_t *opt="h")
to get the Area (+bkg) of this peak
Definition: Peak1D.cpp:1031
virtual void SetFillStyleBkg(Style_t style)
Definition: Peak1D.cpp:1710
A BasePeak is defined by a height, intensity and a dimension of the peak.
Definition: BasePeak.h:19
Double_t GetPeakIntegralError() const
Definition: Peak1D.h:262
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
Compute distance to object.
Definition: Peak1D.cpp:1813
virtual void SetLineColorBkg(Color_t color)
Definition: Peak1D.cpp:1686
ClassDef(BasePeak, 1)
bool IsAGammaSourceRay()
Definition: Peak1D.h:392
virtual Int_t Compare(const TObject *obj) const
Definition: Peak1D.cpp:2015
static Color_t fgLineColorBkg
Definition: Peak1D.h:381
A graphical interface for placing schematic peak onto a 1D histogram with a given position...
Definition: Peak1D.h:79
void SetIntensity(const Double_t intensity)
Set Intensity of peak.
Definition: Peak1D.cpp:579
virtual void FitCombined(TH1 *histo, TList *peakList, Option_t *optFit="RN", Option_t *optBkg="pol1")
Fit multi-defined peak with a common background.
Definition: Peak1D.cpp:1164
virtual void SetDrawAs(EDrawAs d)
Set drawing flag.
Definition: Peak1D.cpp:1718
TF1 * fBkgFunc
Definition: Peak1D.h:370
const TVector2 GetBkgLeft() const
Get background limits.
Definition: Peak1D.h:242
TPolyLine * fCPolyline
Definition: Peak1D.h:357
virtual void SetLineWidthBkg(Width_t width)
Definition: Peak1D.cpp:1694
Short_t IsPointInBkg(Double_t x, Double_t=0)
to determine if a point is in bg. 0 likely in peak, 1 in bg, 2 outside bg
Definition: Peak1D.h:248
virtual TF1 * SetSignalFunction(const char *nameFunc="gaus", TH1 *h=0x0)
Set pre-defined function to fit the signal.
Definition: Peak1D.cpp:716
double DoubleTailedStepedGaussian(double *xx, double *pp)
Double tailed gaussian with step (Dino like)
Definition: Peak1D.cpp:2391
TF1 * fFitCombined
pointer to signal+ bkg function
Definition: Peak1D.h:372
virtual void Copy(TObject &o) const
Assignment operator.
Definition: Peak1D.cpp:353
virtual TF1 * SetBkgFunction(const char *nameFunc="-")
Set pre-defined function for background during fit.
Definition: Peak1D.cpp:895
virtual Bool_t IsSortable() const
Sort.
Definition: Peak1D.h:233
void SetGammaSourceRay(GammaSourceRay *gsr)
Definition: Peak1D.h:394
virtual void Draw(Option_t *opt="")
Definition: Peak1D.cpp:1777
virtual void SetFillColorPeak(Color_t color)
Set line attribute for peak.
Definition: Peak1D.cpp:1671
static Style_t fgFillStyleBkg
Definition: Peak1D.h:382
virtual TF1 * GetSigFunction()
Get signal function.
Definition: Peak1D.h:222
virtual void SetDrawOption(Option_t *option="")
Definition: Peak1D.cpp:1796
void SetBackground(Double_t bgLeft1, Double_t bgLeft2, Double_t bgRight1, Double_t bgRight2, Double_t bgLevelLeft1, Double_t bgLevelLeft2, Double_t bgLevelRight1, Double_t bgLevelRight2)
Set background limits.
Definition: Peak1D.cpp:591