MiniballSort
Loading...
Searching...
No Matches
MiniballAngleFitter.hh
Go to the documentation of this file.
1#ifndef __MINIBALLANGLEFITTER_HH
2#define __MINIBALLANGLEFITTER_HH
3
4// C++ includes
5#include <fstream>
6#include <iostream>
7#include <string>
8#include <sstream>
9#include <vector>
10
11// ROOT includes
12#include "TFile.h"
13#include "TMath.h"
14#include "TCanvas.h"
15#include "TGraph.h"
16#include "TMultiGraph.h"
17#include "TGraphErrors.h"
18#include "TF1.h"
19#include "TH1.h"
20#include "TH2.h"
21#include "TLegend.h"
22#include "Math/Functor.h"
23#include "Math/Factory.h"
24#include "Math/Minimizer.h"
25#include "Math/MinimizerOptions.h"
26
27// Settings header
28#ifndef __SETTINGS_HH
29# include "Settings.hh"
30#endif
31
32// Reaction header
33#ifndef __REACTION_HH
34# include "Reaction.hh"
35#endif
36
37
39
40public:
41
42 // ctors and dtors
45 MiniballAngleFunction( std::shared_ptr<MiniballSettings> _myset, std::shared_ptr<MiniballReaction> _myreact );
46
47 // Initial setup, called from constructors
48 void Initialise();
49
50 // Fit the segment spectra to get the energies
51 bool FitPeak( TH1D *h, double &en, double &er );
52 void FitSegmentEnergies( TFile *infile );
53
54 // Load/save energies
55 void LoadExpEnergies( std::string energy_file );
56 void SaveExpEnergies( std::string energy_file );
57
58 // Check if segment is present and has a phi constraint
59 inline bool IsPresent( unsigned int clu ){
60 return cluster[clu];
61 };
62 inline bool IsPresent( unsigned int clu, unsigned int cry, unsigned int seg ){
63 return present[clu][cry][seg];
64 };
65 inline bool HasPhiConstraint( unsigned int clu, unsigned int cry, unsigned int seg ){
66 return phiconst[clu][cry][seg];
67 };
68
69 // Setter and getter for reference energy
70 inline void SetReferenceEnergy( double e ){ eref = e; };
71 inline double GetReferenceEnergy(){ return eref; };
72
73 // Getters for the experimental energies
74 inline double GetExpEnergy( unsigned int clu, unsigned int cry, unsigned int seg ){
75 return energy[clu][cry][seg];
76 };
77 inline double GetExpError( unsigned int clu, unsigned int cry, unsigned int seg ){
78 return err[clu][cry][seg];
79 };
80
81 // Getters for the phi angles
82 inline double GetExpPhi( unsigned int clu, unsigned int cry, unsigned int seg ){
83 return phic[clu][cry][seg];
84 };
85 inline double GetExpPhiError( unsigned int clu, unsigned int cry, unsigned int seg ){
86 return phie[clu][cry][seg];
87 };
88
89 // operator for the fit function
90 double operator() ( const double *p );
91
92private:
93
94 // Vectors for data, etc
95 std::vector<std::vector<std::vector<bool>>> present;
96 std::vector<std::vector<std::vector<bool>>> phiconst;
97 std::vector<std::vector<std::vector<double>>> energy;
98 std::vector<std::vector<std::vector<double>>> err;
99 std::vector<std::vector<std::vector<double>>> phic; // phi constraint
100 std::vector<std::vector<std::vector<double>>> phie; // phi error
101 std::vector<bool> cluster;
102
103 // Settings files, etc
104 std::shared_ptr<MiniballSettings> myset;
105 std::shared_ptr<MiniballReaction> myreact;
106
107 double user_z = 0;
108 double eref = 439.986; // Lund = 439.986; NNDC = 440.2
109
110};
111
113
114public:
115
116 // ctors and dtors
119 MiniballAngleFitter( std::string settings_file, std::string reaction_file );
120 MiniballAngleFitter( std::shared_ptr<MiniballSettings> _myset, std::shared_ptr<MiniballReaction> _myreact );
121
122 // Initialise at the start, called from ctors
123 void Initialise();
124
125 // Call the actual fitting
126 void DoFit();
127
128 // Write the results to a reaction file
129 void SaveReactionFile( std::string fname );
130
131 // Save experimental energies
132 inline void SaveExpEnergies( std::string energy_file ){
133 ff.SaveExpEnergies( energy_file );
134 };
135
136 // Set the input ROOT file
137 bool SetInputROOTFile( std::string fname );
138 inline void CloseROOTFile(){
139 if( input_root_file != nullptr ) input_root_file->Close();
140 };
141
142 // Set the input data file with energies
143 bool SetInputEnergiesFile( std::string fname );
144
145 // Set the output directory
146 inline void SetOutputDirectory( std::string dir ){
147 datadir = dir;
148 };
149
150private:
151
152 // Settings files, etc
153 std::shared_ptr<MiniballSettings> myset;
154 std::shared_ptr<MiniballReaction> myreact;
155
156 // Input ROOT file
157 TFile *input_root_file = nullptr;
158
159 // Input data file
161
162 // This is the main fit function
164
165 // Output directory
166 std::string datadir;
167
168 // Some colours and marker styles
169 std::vector<int> mystyles, mycolors;
170
171 // Flag if we need to fit the peaks ourselves, or they are given
172 bool flag_fit_peaks = false;
173
174 // Paramaters and limits
175 unsigned npars = 1;
176 std::vector<double> pars;
177 std::vector<std::string> names;
178 std::vector<double> LL;
179 std::vector<double> UL;
180
181};
182
183
184#endif
185
std::vector< double > UL
std::vector< int > mystyles
void SetOutputDirectory(std::string dir)
std::vector< double > LL
void SaveExpEnergies(std::string energy_file)
std::vector< double > pars
std::vector< std::string > names
std::vector< int > mycolors
std::shared_ptr< MiniballSettings > myset
bool SetInputEnergiesFile(std::string fname)
bool SetInputROOTFile(std::string fname)
std::shared_ptr< MiniballReaction > myreact
void SaveReactionFile(std::string fname)
MiniballAngleFunction ff
void SaveExpEnergies(std::string energy_file)
void LoadExpEnergies(std::string energy_file)
std::vector< bool > cluster
bool IsPresent(unsigned int clu)
std::vector< std::vector< std::vector< double > > > energy
std::shared_ptr< MiniballSettings > myset
bool HasPhiConstraint(unsigned int clu, unsigned int cry, unsigned int seg)
void SetReferenceEnergy(double e)
bool IsPresent(unsigned int clu, unsigned int cry, unsigned int seg)
std::vector< std::vector< std::vector< double > > > phic
std::vector< std::vector< std::vector< bool > > > phiconst
double GetExpError(unsigned int clu, unsigned int cry, unsigned int seg)
std::vector< std::vector< std::vector< bool > > > present
bool FitPeak(TH1D *h, double &en, double &er)
void FitSegmentEnergies(TFile *infile)
double GetExpPhi(unsigned int clu, unsigned int cry, unsigned int seg)
std::shared_ptr< MiniballReaction > myreact
std::vector< std::vector< std::vector< double > > > phie
double GetExpEnergy(unsigned int clu, unsigned int cry, unsigned int seg)
std::vector< std::vector< std::vector< double > > > err
double operator()(const double *p)
double GetExpPhiError(unsigned int clu, unsigned int cry, unsigned int seg)