FairRoot/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 {
46  public:
47  PndHypGeSpectrumAnalyser(TH1D* hEnergySpec_ext,Int_t nPeaks =2,Int_t FuncWidthExt = 100);
48  PndHypGeSpectrumAnalyser(TH1D* hEnergySpec_ext, vector<double> *Energies_ext,Int_t FuncWidthExt = 100); // constructor with energies from external array
49  PndHypGeSpectrumAnalyser(TH1D* hEnergySpec_ext,TString Nuclei,Int_t FuncWidthExt = 100); // constructor with energies from internal database
50  virtual ~PndHypGeSpectrumAnalyser();
51 
52  TH1D* GetEnergySpectrum() {return fhEnergySpectrum;}
53  void SetEnergySpectrum(TH1D* hEnergySpec_ext);
54 
55  Int_t AnalyseSpectrum();
56  Int_t AnalyseSimulationSpectrum();
57  Int_t FindPeaks();
58  Int_t FitPeaks();
59 
60  Int_t DrawCalibratedSpectrum();
61  Int_t DrawSimulationSpectrum();
62  Int_t DoEnergyCalibration();
63  Int_t CalculateFWHM();
64  Int_t CalculateFWTM();
65  Double_t CalculateEfficiency();
66  Double_t GetFWHM511();
67  Double_t GetFWTM511();
68  Double_t GetFWHMCo1();
69  Double_t GetFWTMCo1();
70  Double_t GetFWHMCo();
71  Double_t GetFWTMCo();
72  Double_t GetFWHMAl();
73  Double_t GetFWTMAl();
74  Double_t GetEfficiency();
75  Double_t GetEfficiencyError();
76 
77  Double_t GetCountsCo(); //NIY
78 
79  Int_t CompareNuclei(TString NucleiName); // database comparison
80 
81  void SetTxtFileOutputName(TString TxtFilename_ext);
82  void SetRootFileOutputName(TString RootFilename_ext);
83  void SetOutputPath(TString OutputPath_ext);
84 
85  Int_t ExportToTextFile(TString TxtFilename_ext = "test.txt");
86  Int_t ExportToRootFile(TString RootFilename_ext = "test.root");
87 
88  void SetSearchRange(Double_t RangeMin,Double_t RangeMax);
89 
90  void SetGaussianFitting();
91  Bool_t IsGaussianFitting();
92 
93  void SetFreeSkewedFitting();
94  Bool_t IsFreeSkewedFitting();
95 
96  void SetSecondGausianFitting();
97  Bool_t IsSecondGausianFitting();
98 
99  void SetNewFunctionFitting();
100  Bool_t IsNewFunctionFitting();
101  void SetNoDrawingMode(Bool_t NoDrawingMode_ext = true); //NIY
102  Bool_t IsNoDrawingMode(); //NIY
103 
104  void SetInputHistogramResolution(Double_t InputHistogramResolution_ext);
105  void SetNumberOfSimEvents(Int_t NumberOfSimEvents_ext, Bool_t OnlyTwoPiSimulated = 1);
106 
107  private:
108 
109  Double_t FindUpperSigmaFitLimit(Double_t threshold, Float_t StartingPoint);
110  void PeakSort();
111  Double_t Calibrate(Double_t Channel);
112 
113  Double_t CalculateLowerErrorLeft(Double_t threshold, TH1D* histo, Double_t StartingValue);
114  Double_t CalculateUpperErrorLeft(Double_t threshold, TH1D* histo, Double_t StartingValue);
115  Double_t CalculateLowerErrorRight(Double_t threshold, TH1D* histo, Double_t StartingValue);
116  Double_t CalculateUpperErrorRight(Double_t threshold, TH1D* histo, Double_t StartingValue);
117 
118 
119  /* add your private declarations */
122 
123  TCanvas *fCalSpecCanvas;
125 
128  TSpectrum *fSpectrum;
129  Float_t *PeaksPosX;
130  Float_t *PeaksPosY;
131 
132  Int_t nPeaks;
133  Int_t nPeaksFound; //number of Peaks found by fSpectrum->Search("...")
134 
135  TF1 *FitFunc[50];
136  TF1 *FitFuncWithoutBg[50];
137  TF1 *CalibratedFunction[50];
138  TF1 *FuncGaus[50];
139  TF1 *FuncSmoothedStep[50];
140  TF1 *FuncLinear[50];
141  TF1 *FuncTail[50];
142 
143 
144 
145  Int_t FuncWidth;
146  vector<double> PeakFitX;
147  vector<double> PeakFitXError;
148  vector<double> PeakCounts;
149 
150  TGraphErrors *fgCalibration;
151  TCanvas *fCalCanvas;
152  TF1 *CalFunc;
153 
154  Double_t Amplitude[50];
155  Double_t FWHMHeight[50];
156  Double_t FWHMlow[50];
157  Double_t FWHMlowLeftBorder[50];
158  Double_t FWHMlowRightBorder[50];
159  Double_t FWHMlowLeftBorderEnergy[50];
160  Double_t FWHMlowRightBorderEnergy[50];
161  Double_t FWHMhigh[50];
162  Double_t FWHMhighLeftBorder[50];
163  Double_t FWHMhighRightBorder[50];
164  Double_t FWHMhighLeftBorderEnergy[50];
165  Double_t FWHMhighRightBorderEnergy[50];
166  Double_t FWHMlowEnergy[50];
167  Double_t FWHMhighEnergy[50];
168 
169  Double_t FWTMHeight[50];
170  Double_t FWTMlow[50];
171  Double_t FWTMhigh[50];
172  Double_t FWTMlowEnergy[50];
173  Double_t FWTMhighEnergy[50];
174 
175  TH1D *fhFitErrorhistogram[50];
176 
177  map<double,double> FWHM_ch;
178  map<double,double> FWHM_en;
179  map<double,double> FWTM_ch;
180  map<double,double> FWTM_en;
181 
182  vector<double> Energies; //vector of peak energies
183  vector<double> EnergyErrors; //vector of peak energy errors
184 
186 
187  ofstream TxtFile;
189 
190  TFile *RootFile;
192 
194 
196 
198 
204 
205  ClassDef(PndHypGeSpectrumAnalyser,1) // This line must be used for Go4 and PANDAroot !!!!!!!!!!! gives "IsA()" Error if compiled with g++
206 };
207 
208 #endif /* PNDHYPGESPECTRUMANALYSER_H */
Double_t
double threshold