PandaRoot
PndHypGeSpectrumAnalyser.h
Go to the documentation of this file.
1 /*
2  * PndHypGeSpectrumAnalyser.h
3  *
4  * Copyright 2013 Marcell Steinen <steinen@kph.uni-mainz.de>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19  * MA 02110-1301, USA.
20  *
21  *
22  */
23 
24 // "IsA()" Error is given by ClassDef line. This line must be used for Go4 and PANDAroot.
25 
26 #ifndef PNDHYPGESPECTRUMANALYSER_H
27 #define PNDHYPGESPECTRUMANALYSER_H
28 
29 #include "TH1D.h"
30 #include "TSpectrum.h"
31 #include "TMath.h"
32 #include "TF1.h"
33 #include "TGraphErrors.h"
34 #include "TCanvas.h"
35 #include "TFile.h"
36 
37 #include <iostream>
38 #include <vector>
39 #include <map>
40 #include <fstream>
41 
42 using namespace std;
43 
45  public:
46  PndHypGeSpectrumAnalyser(TH1D *hEnergySpec_ext, Int_t nPeaks = 2, Int_t FuncWidthExt = 100);
47  PndHypGeSpectrumAnalyser(TH1D *hEnergySpec_ext, vector<double> *Energies_ext, Int_t FuncWidthExt = 100); // constructor with energies from external array
48  PndHypGeSpectrumAnalyser(TH1D *hEnergySpec_ext, TString Nuclei, Int_t FuncWidthExt = 100); // constructor with energies from internal database
49  virtual ~PndHypGeSpectrumAnalyser();
50 
51  TH1D *GetEnergySpectrum() { return fhEnergySpectrum; }
52  void SetEnergySpectrum(TH1D *hEnergySpec_ext);
53 
54  Int_t AnalyseSpectrum();
55  Int_t AnalyseSimulationSpectrum();
56  Int_t FindPeaks();
57  Int_t FitPeaks();
58 
59  Int_t DrawCalibratedSpectrum();
60  Int_t DrawSimulationSpectrum();
61  Int_t DoEnergyCalibration();
62  Int_t CalculateFWHM();
63  Int_t CalculateFWTM();
64  Double_t CalculateEfficiency();
65  Double_t GetFWHM511();
66  Double_t GetFWTM511();
67  Double_t GetFWHMCo1();
68  Double_t GetFWTMCo1();
69  Double_t GetFWHMCo();
70  Double_t GetFWTMCo();
71  Double_t GetFWHMAl();
72  Double_t GetFWTMAl();
73  Double_t GetEfficiency();
74  Double_t GetEfficiencyError();
75 
76  Double_t GetCountsCo(); // NIY
77 
78  Int_t CompareNuclei(TString NucleiName); // database comparison
79 
80  void SetTxtFileOutputName(TString TxtFilename_ext);
81  void SetRootFileOutputName(TString RootFilename_ext);
82  void SetOutputPath(TString OutputPath_ext);
83 
84  Int_t ExportToTextFile(TString TxtFilename_ext = "test.txt");
85  Int_t ExportToRootFile(TString RootFilename_ext = "test.root");
86 
87  void SetSearchRange(Double_t RangeMin, Double_t RangeMax);
88 
89  void SetGaussianFitting();
90  Bool_t IsGaussianFitting();
91 
92  void SetFreeSkewedFitting();
93  Bool_t IsFreeSkewedFitting();
94 
95  void SetSecondGausianFitting();
96  Bool_t IsSecondGausianFitting();
97 
98  void SetNewFunctionFitting();
99  Bool_t IsNewFunctionFitting();
100  void SetNoDrawingMode(Bool_t NoDrawingMode_ext = true); // NIY
101  Bool_t IsNoDrawingMode(); // NIY
102 
103  void SetInputHistogramResolution(Double_t InputHistogramResolution_ext);
104  void SetNumberOfSimEvents(Int_t NumberOfSimEvents_ext, Bool_t OnlyTwoPiSimulated = 1);
105 
106  private:
107  Double_t FindUpperSigmaFitLimit(Double_t threshold, Float_t StartingPoint);
108  void PeakSort();
109  Double_t Calibrate(Double_t Channel);
110 
111  Double_t CalculateLowerErrorLeft(Double_t threshold, TH1D *histo, Double_t StartingValue);
112  Double_t CalculateUpperErrorLeft(Double_t threshold, TH1D *histo, Double_t StartingValue);
113  Double_t CalculateLowerErrorRight(Double_t threshold, TH1D *histo, Double_t StartingValue);
114  Double_t CalculateUpperErrorRight(Double_t threshold, TH1D *histo, Double_t StartingValue);
115 
116  /* add your private declarations */
117  TCanvas *fEnergySpecCanvas;
118  TH1D *fhEnergySpectrum;
119 
120  TCanvas *fCalSpecCanvas;
121  TH1D *fhCalibratedSpectrum;
122 
123  TCanvas *fSubstractCanvas;
124  TH1D *fhSubstractSpectrum;
125  TSpectrum *fSpectrum;
126  Float_t *PeaksPosX;
127  Float_t *PeaksPosY;
128 
129  Int_t nPeaks;
130  Int_t nPeaksFound; // number of Peaks found by fSpectrum->Search("...")
131 
132  TF1 *FitFunc[50];
133  TF1 *FitFuncWithoutBg[50];
134  TF1 *CalibratedFunction[50];
135  TF1 *FuncGaus[50];
136  TF1 *FuncSmoothedStep[50];
137  TF1 *FuncLinear[50];
138  TF1 *FuncTail[50];
139 
140  Int_t FuncWidth;
141  vector<double> PeakFitX;
142  vector<double> PeakFitXError;
143  vector<double> PeakCounts;
144 
145  TGraphErrors *fgCalibration;
146  TCanvas *fCalCanvas;
147  TF1 *CalFunc;
148 
149  Double_t Amplitude[50];
150  Double_t FWHMHeight[50];
151  Double_t FWHMlow[50];
152  Double_t FWHMlowLeftBorder[50];
153  Double_t FWHMlowRightBorder[50];
154  Double_t FWHMlowLeftBorderEnergy[50];
155  Double_t FWHMlowRightBorderEnergy[50];
156  Double_t FWHMhigh[50];
157  Double_t FWHMhighLeftBorder[50];
158  Double_t FWHMhighRightBorder[50];
159  Double_t FWHMhighLeftBorderEnergy[50];
160  Double_t FWHMhighRightBorderEnergy[50];
161  Double_t FWHMlowEnergy[50];
162  Double_t FWHMhighEnergy[50];
163 
164  Double_t FWTMHeight[50];
165  Double_t FWTMlow[50];
166  Double_t FWTMhigh[50];
167  Double_t FWTMlowEnergy[50];
168  Double_t FWTMhighEnergy[50];
169 
170  TH1D *fhFitErrorhistogram[50];
171 
172  map<double, double> FWHM_ch;
173  map<double, double> FWHM_en;
174  map<double, double> FWTM_ch;
175  map<double, double> FWTM_en;
176 
177  vector<double> Energies; // vector of peak energies
178  vector<double> EnergyErrors; // vector of peak energy errors
179 
180  TString OutputPath;
181 
182  ofstream TxtFile;
183  TString TxtFilename;
184 
185  TFile *RootFile;
186  TString RootFilename;
187 
188  Bool_t BreakProgram;
189 
190  Int_t fFittingMethod;
191 
192  Bool_t NoDrawingMode;
193 
194  Double_t fFEPEfficiency;
195  Double_t fFEPEfficiencyError;
196  Double_t fInputHistogramResolution;
197  Int_t fNumberOfSimEvents;
198  Int_t fSolidAngleCorrectionFactor;
199 
200  ClassDef(PndHypGeSpectrumAnalyser, 1) // This line must be used for Go4 and PANDAroot !!!!!!!!!!! gives "IsA()" Error if compiled with g++
201 };
202 
203 #endif /* PNDHYPGESPECTRUMANALYSER_H */
STL namespace.