Berkeley Nuclear Data Software
GammaProductionAna.h
Go to the documentation of this file.
1 #ifndef _GAMMA_PRODUCTION_ANALYSIS_H_
2 #define _GAMMA_PRODUCTION_ANALYSIS_H_
3 //ROOT includes
4 #include "TH1.h"
5 #include "SpectrumAnalysis.h"
6 #include "TH2.h"
7 #include "TMatrixD.h"
8 #include "TFitResult.h"
9 #include "TRandom3.h"
10 #include "TALYSUtils.h"
11 #include "FluxMatrixAna.h"
12 #include "NSDPhysicsEvents.h"
13 #include "TChain.h"
14 //c++includes
15 #include <cstdint>
16 #include <vector>
17 #include <utility>
18 #include <deque>
19 using std::vector;
20 #include <map>
21 using std::map;
22 using std::pair;
23 
24 // #include "../../BasicSupport/external/eigen/Eigen/Dense"
25 #include <Eigen/Dense>
28 
30 {
31 public:
32  DataValuePair();
33  double m_xVal;
34  double m_xUnc;
35  double m_xUncUp=0.;
36  double m_yVal;
37  double m_yUnc;
38  friend std::ostream& operator<<(std::ostream& os, const DataValuePair& a_dataPair);
39  friend std::istream& operator>>(std::istream& a_istream, DataValuePair& a_dataPair);
40 };
41 
43 {
44 public:
50  GammaProductionAna(int a_ZID, int a_AID, string a_talysPath);
51 // ------------------
53  void setupTALYSUtils(int a_ZID, int a_AID, string a_talysPath);
55  void setTalysPath(std::string a_path);
65  TH2F* buildFluxMatrix(std::string a_stofFluxFileName,
66  double a_minEnergy,
67  double a_maxEnergy,
68  double a_flightPath, // cm
69  double a_timeResolution, // ns [sigma]
70  double a_RFPeriod,
71  double a_timeBinWidth=-1);
72  void addFluxMatrix(FluxAna a_fluxAna);
80  void readGammaEffParams(std::string a_effParamFile,
81  std::string a_fitType="Debertin",
82  bool a_readEffCovMat = false);
87  void readEGammaLevels(std::string a_lvlFile);
91  void loadExpTOFvsEGamma(vector<std::string> a_expFiles);
92  void loadExpTOFvsEGamma(std::string a_expFile);
93  // loads tree without making histograms allowing you to load several
94  // files as a seperate step
95  void addTree(std::string a_expTree);
96  void addTreeBKG(std::string a_expTree);
97  // builds hists from the loaded trees
98  void buildHists(vector<int> a_cloverList,
99  bool a_saveFile,
100  string a_outFileName);
101  void buildHistsBKG(vector<int> a_cloverList,
102  bool a_saveFile,
103  string a_outFileName);
105  void loadExpBKGData(vector<std::string> a_expFile);
106  void loadExpBKGData(std::string a_expFile);
108  void setBackgroundScalar(double a_scalar);
115  void addEXFORCrossSection(std::string a_fileName,
116  double a_gammaEnergy,
117  bool a_draw=false,
118  std::string a_dataSetName = "");
119 // ------------------
124  void setVerbosity(int a_verbosity);
126  void setTotalCharge(double a_charge);
128  void setTargetRhoR(double a_rhoR);
130  void setTargetSolidAngle(double a_solidAngle);
131  void setDetSolidAngle(double a_solidAngle);
133  void setRFPeriod(double a_RFPeriod);
135  void setTimeResolution(double a_timeResolution);
137  void setFlightPath(double a_flightPath);
138 // ------------------
142  vector<double> calcGammaEff(int a_detID, int a_elementID, double a_energy);
144 
146  vector<Eigen::MatrixXf> getFluxMatrix(double a_minEnergy);
149  vector<Eigen::MatrixXf> getFluxMatrix(double a_gammaEnergy,
150  double a_thresholdAdder);
154  TH2F* getFluxHist();
155 // ------------------
161  PeakInfo getPeakArea(double a_tof, double a_tofWidth,
162  int a_detID, int a_elementID,
163  double a_energy,
164  bool a_draw=0,
165  bool a_fitBkg=1,
166  bool a_drawBkg=0,
167  bool a_saveFit=1);
169  void setNewPeakFit(double a_gammaEnergy,
170  int a_detID,
171  int a_elementID,
172  int a_tof,
173  PeakInfo a_peakInfo);
176  void writePeakFits(double a_gammaEnergy,
177  int a_detID,
178  int a_elementID);
179  void readPeakFits(double a_gammaEnergy,
180  int a_detID,
181  int a_elementID);
187  map<double, std::pair<double,double>> getTotExpYield(double a_gammaEnergy,
188  int a_detID, int a_elementID,
189  double a_tofWidth=-1,
190  bool a_draw=true,
191  int a_plotType=0);
192 
195  Eigen::VectorXf calculateYieldUnc(Eigen::MatrixXf a_fluxUncMat,
196  Eigen::VectorXf a_crossSection);
197  Eigen::VectorXf calculateYieldUnc(vector<Eigen::MatrixXf> a_fluxMats,
198  Eigen::VectorXf a_crossSectionUnc,
199  Eigen::VectorXf a_crossSection);
205  Eigen::VectorXf convolveXSec(double a_gammaEnergy,
206  int a_detID,
207  int a_elementID,
208  bool a_calcUnc=false,
209  bool a_useEXFOR=false,
210  double a_thresholdAdder=0.);
211 // ------------------
215  double plotComp(double a_gammaEnergy,
216  int a_detID,
217  int a_elementID,
218  bool a_useEXFOR=false,
219  double a_normalize=1,
220  bool a_drawEnAxis=true,
221  bool a_draw=true);
223  double plotRatio(double a_energy1,
224  double a_energy2,
225  int a_detID,
226  int a_elementID,
227  bool a_useEXFOR=false,
228  bool a_drawEnAxis=true,
229  bool a_draw=true);
232  void compDetectorElements(double a_gammaEnergy,
233  int a_detID1,
234  int a_elementID1,
235  int a_detID2,
236  int a_elementID2);
246  vector<DataValuePair> calcUnwrappedXSec(double a_gammaEnergy,
247  int a_detID,
248  int a_elementID,
249  double a_thresholdAdder=0.,
250  double a_normalize=0,
251  bool a_draw=true);
257  vector<DataValuePair> calcUnwrappedXSec(map<double, std::pair<double,double>> a_expYields,
258  double a_gammaEnergy,
259  double a_threshold,
260  bool a_normalize=0,
261  bool a_draw=true);
262  //overloaded method to input gamma data from radware
263  vector<DataValuePair> calcUnwrappedXSec(string a_expYields,
264  double a_gammaEnergy,
265  double a_threshold,
266  bool a_normalize=0,
267  bool a_draw=true);
268 
273  void testUnwrapping(double a_gammaEnergy,
274  int a_detID,
275  int a_elementID);
278  void noExpUnwrapTest(double a_gammaEnergy,
279  int a_detID=0,
280  int a_elementID=2,
281  double a_alpha=1.);
283  void plotSVD();
287  double testForwardModel(double a_gammaEnergy,
288  int a_detID,
289  int a_elementID,
290  double a_smoothness=1.e-2,
291  bool a_draw=true,
292  bool a_useEXFOR=false);
294  double forwardModelFit(const double* a_params);
297  void setupTALYSParams(std::string a_paramFile);
299  void talysForwardModel(vector<double> a_gammaEnergy,
300  int a_detID,
301  int a_elementID,
302  bool a_scale=false,
303  bool a_runECIS=true);
304  double talysModelFit(const double* a_params);
307  vector<std::pair<double,double>> scanTALYSParameter(int a_parameterNum,
308  vector<double> a_gammaEnergy,
309  bool a_runECIS=true,
310  int a_detID=1,
311  int a_elementID=2);
312  vector<std::pair<double,double>> scanTALYSParameter(std::string a_paramName,
313  vector<double> a_gammaEnergy,
314  bool a_runECIS=true,
315  int a_detID=1,
316  int a_elementID=2);
318  void setSaveTALYSFits(bool a_saveFits);
320  vector<double> getEnergySpecLowerBinEdges();
321  Eigen::VectorXf getEXFORCrossSection(double a_gammaEnergy,
322  bool a_calcUnc=false,
323  double a_thresholdAdder=0);
326  TH1F* m_lastHist;
327 
328  std::map<string, int> m_talysParams;
329  map<int,map<int,TH2F*>> m_tofEgamma;
330 
331  void writeNonWrappedXSec(double a_gammaE, int a_detID, int a_elemID);
332  map<int, PeakInfo> getPeakFits(double a_gammaE, int a_detID, int a_elemID);
333 private:
335  TH2F* m_fluxHist;
336  Eigen::MatrixXf m_fullFluxMat;
337  Eigen::MatrixXf m_fullFluxMatErr;
339  double m_bkgScalar;
341  vector<double> m_ener0BinEdges;
343  vector<double> m_enerBinWidths;
345  vector<double> m_enerBinCenters;
347  // map<int,map<int,TH2F*>> m_tofEgamma;
348  map<int,map<int,TH2F*>> m_tofEgamma0;
349  map<int,map<int,TH2F*>> m_tofEgammaBKG;
351  map<int,map<int,vector<double>>> m_effParams;
353  map<double,vector<std::pair<std::string,std::string>>> m_eGammaLevels;
354  map<double, vector<double>> m_eGammaThreshold;
356  std::string m_talysPath;
358  double m_rhoR = 5.283e21;
359  double m_solidAngle = 3.67e-5;
360  double m_solidAngleDet = 1;
362  double m_totalCharge;
364  double m_RFPeriod;
365  double m_timeResolution;
366  double m_flightPath;
368  map<double, map<int, map<int, map<int, PeakInfo>>>> m_peakFits;
370  map<int, map<int, Eigen::MatrixXf>> m_gammaEffCovMats;
372  map<double, std::pair<vector<double>, vector<double>>> m_exforData;
373  map<double, std::string> m_exforDataSetNames;
374  map<string, map<double, vector<DataValuePair>>> m_exforDataAll;
375  bool m_hasGammaEffUnc;
376  bool m_hasFluxUncMat;
377  bool m_useTALYSscaler;
378  bool m_runECIS;
379 
381  TALYSUtils m_talysUtil;
383  // vector<double> getEnergyPoints(double a_gammaEnergy);
384 
385  map<int, map<int,map<double, vector<DataValuePair>>>> m_unwrappedXSecs;
386  map<double, vector<DataValuePair>> m_currUnwrappedData;
387  map<double, vector<int>> m_currUnwrappedDataIndex;
388 
389  TRandom3* m_rand_gen;
390 
391  FluxAna m_fluxMatAna;
392 public:
393  vector<double> calcNonWrappedEners(vector<double> a_cumulativeCounts, vector<double> a_eners);
394 private:
395 int m_verbosity;
396 public:
397 vector<double> getEnergyPoints(double a_gammaEnergy, int a_coinGammaID=0);
399  bool m_ratio;
400  int setupTALYSMinimizer(vector<double> a_gammaEnergy,
401  int a_detID,
402  int a_elementID);
403  vector<Eigen::MatrixXf> m_currFluxMat;
404  vector<Eigen::MatrixXf> m_currFluxUncMat;
405  vector<Eigen::VectorXf> m_currData;
406  vector<Eigen::VectorXf> m_currDataUnc;
407  std::pair<int ,int> m_currDetElemID;
408  // std::map<string, std::pair<double,std::pair<double,double>>> m_talysParams;
409  vector<double> m_tempGammaEnergy;
410  ROOT::Math::Minimizer* m_minimum;
411 
412  double m_smoothness;
413  // Double_t fTOFWrapper(Double_t* x, Double_t* par);
414  //adding calibrated tree support
415  //storing loaded trees
416  TChain* m_trees;
417  std::vector<string> m_loadedTrees;
418  bool m_hasFile;
420 
421  TChain* m_treesBKG;
422  std::vector<string> m_loadedTreesBKG;
425 };
426 
427 #endif
Definition: GammaProductionAna.h:30
double m_xVal
Definition: GammaProductionAna.h:33
double m_yVal
Definition: GammaProductionAna.h:36
double m_xUnc
Definition: GammaProductionAna.h:34
DataValuePair()
Definition: GammaProductionAna.cpp:40
double m_xUncUp
Definition: GammaProductionAna.h:35
friend std::ostream & operator<<(std::ostream &os, const DataValuePair &a_dataPair)
Definition: GammaProductionAna.cpp:48
friend std::istream & operator>>(std::istream &a_istream, DataValuePair &a_dataPair)
Definition: GammaProductionAna.cpp:62
double m_yUnc
Definition: GammaProductionAna.h:37
Definition: FluxMatrixAna.h:35
Definition: GammaProductionAna.h:43
void setTargetSolidAngle(double a_solidAngle)
sr
Definition: GammaProductionAna.cpp:480
void addTree(std::string a_expTree)
Definition: GammaProductionAna.cpp:792
Eigen::VectorXf getEXFORCrossSection(double a_gammaEnergy, bool a_calcUnc=false, double a_thresholdAdder=0)
Definition: GammaProductionAna.cpp:1656
void readGammaEffParams(std::string a_effParamFile, std::string a_fitType="Debertin", bool a_readEffCovMat=false)
Definition: GammaProductionAna.cpp:1218
vector< Eigen::VectorXf > m_currDataUnc
Definition: GammaProductionAna.h:406
vector< std::pair< double, double > > scanTALYSParameter(int a_parameterNum, vector< double > a_gammaEnergy, bool a_runECIS=true, int a_detID=1, int a_elementID=2)
Definition: GammaProductionAna.cpp:3842
ROOT::Math::Minimizer * m_minimum
Definition: GammaProductionAna.h:410
void readPeakFits(double a_gammaEnergy, int a_detID, int a_elementID)
Definition: GammaProductionAna.cpp:2278
double m_smoothness
Definition: GammaProductionAna.h:412
TChain * m_trees
Definition: GammaProductionAna.h:416
void setTargetRhoR(double a_rhoR)
Definition: GammaProductionAna.cpp:476
double forwardModelFit(const double *a_params)
fit function for above
Definition: GammaProductionAna.cpp:3599
void addFluxMatrix(FluxAna a_fluxAna)
Definition: GammaProductionAna.cpp:415
void buildHistsBKG(vector< int > a_cloverList, bool a_saveFile, string a_outFileName)
Definition: GammaProductionAna.cpp:973
bool m_hasFileBKG
Definition: GammaProductionAna.h:423
bool m_saveFits
Definition: GammaProductionAna.h:398
vector< Eigen::MatrixXf > m_currFluxMat
Definition: GammaProductionAna.h:403
vector< Eigen::VectorXf > m_currData
Definition: GammaProductionAna.h:405
void setNewPeakFit(double a_gammaEnergy, int a_detID, int a_elementID, int a_tof, PeakInfo a_peakInfo)
replace a peak fit with a new one
Definition: GammaProductionAna.cpp:2236
void plotSVD()
plot the flux matrix reconstructed from its SVD
Definition: GammaProductionAna.cpp:3222
void writePeakFits(double a_gammaEnergy, int a_detID, int a_elementID)
Definition: GammaProductionAna.cpp:2245
void addEXFORCrossSection(std::string a_fileName, double a_gammaEnergy, bool a_draw=false, std::string a_dataSetName="")
Definition: GammaProductionAna.cpp:1032
vector< double > calcNonWrappedEners(vector< double > a_cumulativeCounts, vector< double > a_eners)
Definition: GammaProductionAna.cpp:4130
void loadExpTOFvsEGamma(std::string a_expFile)
Eigen::VectorXf calculateYieldUnc(Eigen::MatrixXf a_fluxUncMat, Eigen::VectorXf a_crossSection)
Definition: GammaProductionAna.cpp:1621
bool m_hasFile
Definition: GammaProductionAna.h:418
void setupTALYSParams(std::string a_paramFile)
Definition: GammaProductionAna.cpp:3636
void addTreeBKG(std::string a_expTree)
Definition: GammaProductionAna.cpp:853
void setVerbosity(int a_verbosity)
Definition: GammaProductionAna.cpp:467
vector< double > calcGammaEff(int a_detID, int a_elementID, double a_energy)
Definition: GammaProductionAna.cpp:1294
TALYSUtils * getTALYSUtils()
Definition: GammaProductionAna.cpp:1369
map< double, std::pair< double, double > > getTotExpYield(double a_gammaEnergy, int a_detID, int a_elementID, double a_tofWidth=-1, bool a_draw=true, int a_plotType=0)
Definition: GammaProductionAna.cpp:1465
vector< Eigen::MatrixXf > m_currFluxUncMat
Definition: GammaProductionAna.h:404
NSDPhysicsEvents::CloverEvent * m_currentEventBKG
Definition: GammaProductionAna.h:424
int setupTALYSMinimizer(vector< double > a_gammaEnergy, int a_detID, int a_elementID)
Definition: GammaProductionAna.cpp:3769
void loadExpTOFvsEGamma(vector< std::string > a_expFiles)
void compDetectorElements(double a_gammaEnergy, int a_detID1, int a_elementID1, int a_detID2, int a_elementID2)
Definition: GammaProductionAna.cpp:2135
std::pair< int,int > m_currDetElemID
Definition: GammaProductionAna.h:407
void setRFPeriod(double a_RFPeriod)
[ns]
Definition: GammaProductionAna.cpp:490
void setSaveTALYSFits(bool a_saveFits)
save plots of GENESIS data vs TALYS generated by minimizer
Definition: GammaProductionAna.cpp:3640
PeakInfo getPeakArea(double a_tof, double a_tofWidth, int a_detID, int a_elementID, double a_energy, bool a_draw=0, bool a_fitBkg=1, bool a_drawBkg=0, bool a_saveFit=1)
Definition: GammaProductionAna.cpp:1378
void setupTALYSUtils(int a_ZID, int a_AID, string a_talysPath)
if default constuctor was used, this sets up the TALYS interface
Definition: GammaProductionAna.cpp:107
void noExpUnwrapTest(double a_gammaEnergy, int a_detID=0, int a_elementID=2, double a_alpha=1.)
Definition: GammaProductionAna.cpp:3106
SpectrumAnalysis m_specAna
refit peaks from getPeakArea
Definition: GammaProductionAna.h:325
vector< double > m_tempGammaEnergy
Definition: GammaProductionAna.h:409
bool m_ratio
Definition: GammaProductionAna.h:399
NSDPhysicsEvents::CloverEvent * m_currentEvent
Definition: GammaProductionAna.h:419
void setBackgroundScalar(double a_scalar)
normalization for background subtraction
Definition: GammaProductionAna.cpp:1190
GammaProductionAna()
default constructor
Definition: GammaProductionAna.cpp:68
vector< Eigen::MatrixXf > getFluxMatrix(double a_minEnergy)
calculates gamma ray uncertainties
Definition: GammaProductionAna.cpp:434
vector< double > getEnergyPoints(double a_gammaEnergy, int a_coinGammaID=0)
Definition: GammaProductionAna.cpp:2947
TH2F * buildFluxMatrix(std::string a_stofFluxFileName, double a_minEnergy, double a_maxEnergy, double a_flightPath, double a_timeResolution, double a_RFPeriod, double a_timeBinWidth=-1)
Definition: GammaProductionAna.cpp:114
double plotComp(double a_gammaEnergy, int a_detID, int a_elementID, bool a_useEXFOR=false, double a_normalize=1, bool a_drawEnAxis=true, bool a_draw=true)
Definition: GammaProductionAna.cpp:1773
double testForwardModel(double a_gammaEnergy, int a_detID, int a_elementID, double a_smoothness=1.e-2, bool a_draw=true, bool a_useEXFOR=false)
Definition: GammaProductionAna.cpp:3272
vector< DataValuePair > calcUnwrappedXSec(double a_gammaEnergy, int a_detID, int a_elementID, double a_thresholdAdder=0., double a_normalize=0, bool a_draw=true)
Definition: GammaProductionAna.cpp:2298
void talysForwardModel(vector< double > a_gammaEnergy, int a_detID, int a_elementID, bool a_scale=false, bool a_runECIS=true)
Chi-2 minimization on a set of TALYS parameters.
Definition: GammaProductionAna.cpp:3644
void setTotalCharge(double a_charge)
total charge from BCM [uC]
Definition: GammaProductionAna.cpp:472
map< int, PeakInfo > getPeakFits(double a_gammaE, int a_detID, int a_elemID)
Definition: GammaProductionAna.cpp:4111
void setTalysPath(std::string a_path)
path to directory where talys will be run
Definition: GammaProductionAna.cpp:1213
map< int, map< int, TH2F * > > m_tofEgamma
Definition: GammaProductionAna.h:329
vector< DataValuePair > calcUnwrappedXSec(map< double, std::pair< double, double >> a_expYields, double a_gammaEnergy, double a_threshold, bool a_normalize=0, bool a_draw=true)
void loadExpBKGData(vector< std::string > a_expFile)
stored in m_tofEgammaBKG
Definition: GammaProductionAna.cpp:502
void setDetSolidAngle(double a_solidAngle)
Definition: GammaProductionAna.cpp:485
std::vector< string > m_loadedTreesBKG
Definition: GammaProductionAna.h:422
TChain * m_treesBKG
Definition: GammaProductionAna.h:421
void setTimeResolution(double a_timeResolution)
sigma [ns]
Definition: GammaProductionAna.cpp:494
double talysModelFit(const double *a_params)
Definition: GammaProductionAna.cpp:3957
double plotRatio(double a_energy1, double a_energy2, int a_detID, int a_elementID, bool a_useEXFOR=false, bool a_drawEnAxis=true, bool a_draw=true)
ratio of gamma 1 over gamma 2
Definition: GammaProductionAna.cpp:1978
std::vector< string > m_loadedTrees
Definition: GammaProductionAna.h:417
Eigen::VectorXf convolveXSec(double a_gammaEnergy, int a_detID, int a_elementID, bool a_calcUnc=false, bool a_useEXFOR=false, double a_thresholdAdder=0.)
Definition: GammaProductionAna.cpp:1684
TH2F * getFluxHist()
Definition: GammaProductionAna.cpp:1373
vector< double > getEnergySpecLowerBinEdges()
returns m_energ0BinEdges
Definition: GammaProductionAna.cpp:4062
void readEGammaLevels(std::string a_lvlFile)
Definition: GammaProductionAna.cpp:1195
void testUnwrapping(double a_gammaEnergy, int a_detID, int a_elementID)
Definition: GammaProductionAna.cpp:2962
void writeNonWrappedXSec(double a_gammaE, int a_detID, int a_elemID)
Definition: GammaProductionAna.cpp:4066
std::map< string, int > m_talysParams
Definition: GammaProductionAna.h:328
TH1F * m_lastHist
Definition: GammaProductionAna.h:326
void setFlightPath(double a_flightPath)
neutron beam flight path [m]
Definition: GammaProductionAna.cpp:498
void buildHists(vector< int > a_cloverList, bool a_saveFile, string a_outFileName)
Definition: GammaProductionAna.cpp:914
Definition: NSDPhysicsEvents.h:110
Definition: SpectrumAnalysis.h:21
Definition: SpectrumAnalysis.h:40
Definition: TALYSUtils.h:62