Berkeley Nuclear Data Software
SpectrumAnalysis.h
Go to the documentation of this file.
1 #ifndef _SPECTRUM_ANALYSIS_H_
2 #define _SPECTRUM_ANALYSIS_H_
6 #include "ConfigClasses.h"
7 #include "TH1.h"
8 #include "TFile.h"
9 #include "Math/Minimizer.h"
10 #include "Math/Factory.h"
11 #include "Math/Functor.h"
12 #include <vector>
13 #include <map>
14 #include <string>
15 #include <iostream>
16 using std::map;
17 using std::vector;
18 using std::string;
19 
20 class PeakInfo
21 {
22 public:
23  PeakInfo();
24  PeakInfo(TFitResultPtr& a_fitResult, double a_binWidth);
25  vector<double> m_amp;
26  vector<double> m_sig;
27  vector<double> m_bkg;
28  vector<double> m_mean;
29  double m_binWidth;
30  double m_chi2;
31  void printPeak();
32  vector<double> getArea();
33  friend std::ostream& operator<<(std::ostream& os, const PeakInfo& a_peakInfo);
34 
35  friend std::istream& operator>>(std::istream& a_istream, PeakInfo& a_peakInfo);
36 
37 };
38 
40 {
41 public:
43  using EffPeakSet = std::map<double, std::pair<double, double>>;
44 
47 
55  void loadHists(string a_fname, int a_modID, double a_countTime=0);
57  // void loadSimHists(string a_fname);
59  void loadBackgroundHists(string a_fname, int a_modID, double a_countTime);
61  void addHists(string a_fname, int a_modID, double a_countTime=0);
62  void addBackgroundHists(string a_fname, int a_modID, double a_countTime);
67  void setResolutionParameters(vector<double> a_params);
70  void fixResolution(bool a_fixRes);
71  void fixMean(bool a_fixMean);
72  void setVerbosity(int a_verbosity);
74  // void rebinSpectrum(int a_channel,
75  // int a_rebinFactor=2,
76  // bool a_fullClover = false);
77  void rebinSpectrum(DetType a_detType,
78  int a_detID,
79  int a_elemID,
80  int a_rebinFactor=2);
90  // vector<PeakInfo> FitPeaksMan(int a_channel,
91  // double a_lower,
92  // double a_higher,// int a_numPeaks,
93  // vector<double> a_peakMeans,
94  // bool a_fullClover=false,
95  // bool a_addBack=false,
96  // bool a_checkPeakRes=true);
97  vector<PeakInfo> FitPeaksMan(DetType a_detType,
98  int a_detID,
99  int a_elemID,
100  double a_lower,
101  double a_higher,
102  vector<double> a_peakMeans,
103  bool a_addBack=false,
104  bool a_bgoVeto = false,
105  bool a_checkPeakRes=true);
109  vector<PeakInfo> FitPeaksMan(TH1F* a_hist,
110  double a_lower,
111  double a_higher,
112  vector<double> a_peakMeans,
113  int a_polyDegree=0);
115  // vector<PeakInfo> FitPeaksManPol1(int a_channel,
116  // int a_lower,
117  // int a_higher,
118  // // int a_numPeaks,
119  // vector<double> a_peakMeans,
120  // bool a_checkPeakRes=true,
121  // bool a_fullClover=false,
122  // bool a_addBack=false);
123  vector<PeakInfo> FitPeaksManPol1(DetType a_detType,
124  int a_detID,
125  int a_elemID,
126  double a_lower,
127  double a_higher,
128  vector<double> a_peakMeans,
129  bool a_addBack=false,
130  bool a_bgoVeto = false,
131  bool a_checkPeakRes=true);
133  void printPeakFits();
136  // vector<PeakInfo> FitPeaksErf(int a_channel,
137  // double a_lower,
138  // double a_higher,
139  // double a_peakMean,
140  // bool a_fullClover=false,
141  // bool a_addBack=false);
142  vector<PeakInfo> FitPeaksErf(DetType a_detType,
143  int a_detID,
144  int a_elemID,
145  double a_lower,
146  double a_higher,
147  double a_peakMean,
148  bool a_addBack=false,
149  bool a_bgoVeto = false);
150  vector<PeakInfo> FitPeaksErf(TH1F* a_hist,
151  double a_lower,
152  double a_higher,
153  double a_peakMean);
154  // Specific function (but didn't want to muddy FitPeaksMan more) to fit the
155  // 6111 keV peak for Cl-35 efficiency for clover leafs that are double-peaking
156  vector<PeakInfo> FitPeaks6111Double(TH1F* a_hist);
163  // EffPeakSet Eu152Efficiency(int a_channel,
164  // double a_activity,
165  // double a_countTime,
166  // double a_simBrTot=.2101,
167  // bool a_res=false,
168  // bool a_fullClover=false,
169  // bool a_addBack=false,
170  // bool a_draw =false);
172  int a_detID,
173  int a_elemID,
174  double a_activity,
175  double a_countTime,
176  double a_simBrTot=.2101,
177  bool a_res=false,
178  bool a_bgoVeto=false,
179  bool a_addBack=false,
180  bool a_draw =false);
181  EffPeakSet Eu152Efficiency(TH1F* a_hist,
182  double a_activity,
183  double a_countTime,
184  double a_simBrTot=.2101,
185  bool a_res=false,
186  bool a_draw =false);
187 
188 
197  EffPeakSet Co56Efficiency(TH1F* a_hist,
198  double a_activity,
199  double a_countTime,
200  double a_simBrTot=.9993999,
201  bool a_res=false,
202  bool a_draw =false);
203 
211  // multi_peaking int is for using a double- or triple-Gaussian fit (FitPeaksMan with two
212  // or three peaks in the vector argument) for when a clover is double-peaking (or triple...)
213  EffPeakSet Ga66Efficiency(TH1F* a_hist,
214  double a_activity,
215  double a_countTime,
216  int multi_peaking=0,
217  double a_simBrTot=.37,
218  bool a_res=false,
219  bool a_draw =false);
220 
229  // double peak Boolean is for using a double-Gaussian fit (FitPeaksMan with two
230  // peaks in the vector argument) for when a clover is double-peaking
231  EffPeakSet Cl35Efficiency(TH1F* a_hist,
232  double a_activity,
233  double a_countTime,
234  bool double_peak=false,
235  double a_simBrTot=1.0,
236  bool a_res=false,
237  bool a_draw =false);
238 
239  // Creates an EffPeakSet object from a text file that can then be
240  // passed to other functions.
241  // The purpose is so that you can combine multiple isotope's efficiencies
242  // into one EffPeakSet object for doing things like calcEffCurve.
243  // The text file must be in a three-column, space-separated format of
244  // energy | efficiency | efficiency uncertainty
245  // Your multiple-isotope efficiencies should be scaled before you add them
246  // to this file, if applicable.
247  // Order doesn't matter, EffPeakSet sorts them in order by energy already.
248  EffPeakSet createEffPeakSet(string infilename);
249 
254  static Double_t totalFit(Double_t *x, Double_t *par);
255 
260  static Double_t fullGeFit(Double_t *x, Double_t *par);
261 
267  vector<double> calcEffCurve(EffPeakSet const& a_ps, string a_fitType) const;
268 
271  void calcAddBackFactor();
274  // EffPeakSet U235Efficiency(int a_channel,
275  // double a_activity,
276  // double a_activityErr,
277  // double a_countTime);
278 
280  map<int, TH1*> getHists();
281  map<int,vector<TH1*>> getCloverHists();
282  TH1* getHist(DetType a_detType,
283  int a_detID,
284  int a_elemID=0,
285  bool a_addBack=false,
286  bool a_bgoVeto=false);
287  map<int, map<double, PeakInfo>> getPeakFits();
288 
290  vector<double> ChannelResolution(DetType a_detType,
291  int a_detID,
292  int a_elemID=0);
293 
298  int autoEu152EnergyCalibration(int a_channel, int a_guess=5000);
299  int autoEu152EnergyCalibration(TH1* a_hist, int a_guess=5000);
300 
301  int autoEu152EnergyCalibration1408Guess(int a_channel, int a_guess);
302  int autoEu152EnergyCalibration1408Guess(TH1* a_hist, int a_guess);
304  void removePeakFit(DetType a_detType,
305  int a_detID,
306  int a_elemID,
307  double a_energy);
308 
309  void setUpMinimizer();
310 
311  double fitPeakConstrained(const double* a_params);
312 
313  std::vector<double> fitSTOFBandProjection(TH1F* a_histogram,
314  double a_minLight,
315  double a_maxLight,
316  vector<double> a_peakCentroid,
317  int a_polOrder
318  );
319 
320 /*
326  void findPeaks(int a_channel, double a_minHeight, int a_numPeaks);
327 
328  void FitPeakBasic(int a_channel, double a_peakCentroid, double a_low= 5 , double a_high=5);;
329  void FitDoublePeak(int a_channel, double a_peakCentroid, double a_peakSeparation,
330  double a_relativeHeight, double a_fitWindow);
331 
332  map<string, vector<vector<double>>> m_zeroCrossings;
334  void writeToConfig();
335 */
336 
337 map<DetType, map<int, map<int,TH1*>>> m_histsD;
338 private:
340  double m_countTime=0;
342  double m_bkgCountTime=0;
343 
345  map<int, TH1*> m_hists;
346  map<int, TH1*> m_bkgHists;
348  map<int, vector<TH1*>> m_cloverHists;
349  map<int, vector<TH1*>> m_bkgCloverHists;
358  // map<DetType, map<int, map<int,TH1*>>> m_histsD;
359  map<DetType, map<int, map<int,TH1*>>> m_histsBkgD;
361  map<int, map<double, PeakInfo>> m_peakFits;
362  map<DetType, map<int, map<int, map<double, PeakInfo>>>> m_peakFitsD;
363 
365  TH1F* m_currHist;
366  TF1* m_currFit;
367  double m_currSig;
368  int m_numParams;
369  vector<int> m_sigParamIndex;
370  ROOT::Math::Minimizer* m_minimum;
371  ROOT::Math::Functor m_chiSquareFunc;
373  vector<double> m_resParams;
374  bool m_fixRes;
375 
376  bool m_fixMean;
377  vector<int> m_meanParamIndex;
378  int m_verbosity;
379 };
380 #endif
DetType
Definition: ConfigClasses.h:20
Definition: SpectrumAnalysis.h:21
double m_binWidth
Definition: SpectrumAnalysis.h:29
friend std::ostream & operator<<(std::ostream &os, const PeakInfo &a_peakInfo)
Definition: SpectrumAnalysis.cpp:50
vector< double > m_mean
Definition: SpectrumAnalysis.h:28
vector< double > m_sig
Definition: SpectrumAnalysis.h:26
double m_chi2
Definition: SpectrumAnalysis.h:30
vector< double > m_amp
Definition: SpectrumAnalysis.h:25
void printPeak()
Definition: SpectrumAnalysis.cpp:68
vector< double > m_bkg
Definition: SpectrumAnalysis.h:27
PeakInfo()
Definition: SpectrumAnalysis.cpp:22
friend std::istream & operator>>(std::istream &a_istream, PeakInfo &a_peakInfo)
Definition: SpectrumAnalysis.cpp:59
vector< double > getArea()
Definition: SpectrumAnalysis.cpp:43
Definition: SpectrumAnalysis.h:40
void setVerbosity(int a_verbosity)
Definition: SpectrumAnalysis.cpp:3036
int autoEu152EnergyCalibration1408Guess(int a_channel, int a_guess)
Definition: SpectrumAnalysis.cpp:2794
std::vector< double > fitSTOFBandProjection(TH1F *a_histogram, double a_minLight, double a_maxLight, vector< double > a_peakCentroid, int a_polOrder)
Definition: SpectrumAnalysis.cpp:3041
map< int, vector< TH1 * > > getCloverHists()
Definition: SpectrumAnalysis.cpp:1416
map< int, map< double, PeakInfo > > getPeakFits()
Definition: SpectrumAnalysis.cpp:1453
vector< PeakInfo > FitPeaksMan(DetType a_detType, int a_detID, int a_elemID, double a_lower, double a_higher, vector< double > a_peakMeans, bool a_addBack=false, bool a_bgoVeto=false, bool a_checkPeakRes=true)
Definition: SpectrumAnalysis.cpp:818
void loadHists(string a_fname, int a_modID, double a_countTime=0)
Definition: SpectrumAnalysis.cpp:162
void printPeakFits()
prints information about fitted peaks (mean, area, resolution, chi2/ndf)
Definition: SpectrumAnalysis.cpp:1042
std::map< double, std::pair< double, double > > EffPeakSet
Container type for efficiency outputs.
Definition: SpectrumAnalysis.h:43
void rebinSpectrum(DetType a_detType, int a_detID, int a_elemID, int a_rebinFactor=2)
rebins spectra
Definition: SpectrumAnalysis.cpp:2915
map< DetType, map< int, map< int, TH1 * > > > m_histsD
Definition: SpectrumAnalysis.h:337
EffPeakSet Eu152Efficiency(DetType a_detType, int a_detID, int a_elemID, double a_activity, double a_countTime, double a_simBrTot=.2101, bool a_res=false, bool a_bgoVeto=false, bool a_addBack=false, bool a_draw=false)
Definition: SpectrumAnalysis.cpp:1574
void fixMean(bool a_fixMean)
Definition: SpectrumAnalysis.cpp:3032
static Double_t fullGeFit(Double_t *x, Double_t *par)
Definition: SpectrumAnalysis.cpp:2291
EffPeakSet Co56Efficiency(TH1F *a_hist, double a_activity, double a_countTime, double a_simBrTot=.9993999, bool a_res=false, bool a_draw=false)
Definition: SpectrumAnalysis.cpp:1794
static Double_t totalFit(Double_t *x, Double_t *par)
https://doi.org/10.1016/S0168-9002(98)00778-5
Definition: SpectrumAnalysis.cpp:2282
EffPeakSet Cl35Efficiency(TH1F *a_hist, double a_activity, double a_countTime, bool double_peak=false, double a_simBrTot=1.0, bool a_res=false, bool a_draw=false)
Definition: SpectrumAnalysis.cpp:2065
void addBackgroundHists(string a_fname, int a_modID, double a_countTime)
Definition: SpectrumAnalysis.cpp:547
void calcAddBackFactor()
Definition: SpectrumAnalysis.cpp:2522
vector< PeakInfo > FitPeaksErf(DetType a_detType, int a_detID, int a_elemID, double a_lower, double a_higher, double a_peakMean, bool a_addBack=false, bool a_bgoVeto=false)
Definition: SpectrumAnalysis.cpp:1100
vector< PeakInfo > FitPeaks6111Double(TH1F *a_hist)
Definition: SpectrumAnalysis.cpp:1245
EffPeakSet createEffPeakSet(string infilename)
Definition: SpectrumAnalysis.cpp:2260
void setResolutionParameters(vector< double > a_params)
Definition: SpectrumAnalysis.cpp:3023
void subtractBackgroundSpectra()
subtract background spectra from loaded spectra
Definition: SpectrumAnalysis.cpp:774
void setUpMinimizer()
Definition: SpectrumAnalysis.cpp:2977
void addHists(string a_fname, int a_modID, double a_countTime=0)
adds spectra to previously loaded spectra
Definition: SpectrumAnalysis.cpp:258
int autoEu152EnergyCalibration(int a_channel, int a_guess=5000)
Definition: SpectrumAnalysis.cpp:2655
double fitPeakConstrained(const double *a_params)
Definition: SpectrumAnalysis.cpp:2954
vector< PeakInfo > FitPeaksManPol1(DetType a_detType, int a_detID, int a_elemID, double a_lower, double a_higher, vector< double > a_peakMeans, bool a_addBack=false, bool a_bgoVeto=false, bool a_checkPeakRes=true)
same as FitPeaksMan but fit peaks with 1st degree polynomial background
Definition: SpectrumAnalysis.cpp:1051
vector< double > ChannelResolution(DetType a_detType, int a_detID, int a_elemID=0)
creates plot of resolution vs energy
Definition: SpectrumAnalysis.cpp:1458
vector< double > calcEffCurve(EffPeakSet const &a_ps, string a_fitType) const
Definition: SpectrumAnalysis.cpp:2301
void loadBackgroundHists(string a_fname, int a_modID, double a_countTime)
loads GEANT4 output processed with GenAnalysis.generateSpectrumVeto()
Definition: SpectrumAnalysis.cpp:452
EffPeakSet Ga66Efficiency(TH1F *a_hist, double a_activity, double a_countTime, int multi_peaking=0, double a_simBrTot=.37, bool a_res=false, bool a_draw=false)
Definition: SpectrumAnalysis.cpp:1906
void fixResolution(bool a_fixRes)
Definition: SpectrumAnalysis.cpp:3028
void removePeakFit(DetType a_detType, int a_detID, int a_elemID, double a_energy)
removes last peak in m_peakFits
Definition: SpectrumAnalysis.cpp:2945
map< int, TH1 * > getHists()
returns m_hists, useful for drawing
Definition: SpectrumAnalysis.cpp:1412
SpectrumAnalysis()
default constructor
Definition: SpectrumAnalysis.cpp:87
TH1 * getHist(DetType a_detType, int a_detID, int a_elemID=0, bool a_addBack=false, bool a_bgoVeto=false)
Definition: SpectrumAnalysis.cpp:1420