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