append.C
Go to the documentation of this file.
1 // Append 20% uncertainty to fitting rootfile on
2 // final states with no data (fDcex & fProd)
3 
4 #include "TROOT.h"
5 //#include "TStyle.h"
6 
7 #include "TObject.h"
8 //#include "TCanvas.h"
9 #include "TH2.h"
10 #include "TH1.h"
11 #include "TMatrix.h"
12 #include "TMatrixD.h"
13 //#include "TLegend.h"
14 //#include "TGraph.h"
15 #include "TFile.h"
16 //#include "TTree.h"
17 
18 #include <iostream>
19 #include <algorithm>
20 //#include <vector>
21 #include <string>
22 
23 
24 void append()
25 {
26 
27  // file where xsec is scaled up
28  std::string inName =
29  "<MY_INPUTS>/C_PiMinus_fit.root";
30 
31  TFile *inFile = new TFile(inName.c_str(), "UPDATE");
32 
33 
34  TMatrixT<double> *FitCovariance = (TMatrixT<double>*)inFile->Get("FitCovariance");
35 
36  FitCovariance->ResizeTo(6,6);
37 
38  // Set diagonal entry to (sigma)**2, all the others stay as zero
39  double cov_value = 0.2*0.2;
40 
41  (*FitCovariance)(4,4) = cov_value;
42  (*FitCovariance)(5,5) = cov_value;
43 
44  FitCovariance->Write("FitCovariance", TObject::kOverwrite);
45 
46 
47  std::vector existing_ints{"fAbs", "fCex", "fInel", "fReac"};
48  TH1D* parsHist = (TH1D*)inFile->Get("parsHist");
49  TH1D new_parsHist("new_parsHist", "", 6, 0, 6);
50 
51  TH2D* FitCovHist = (TH2D*)inFile->Get("FitCovHist");
52  TH2D new_FitCovHist("new_FitCovHist", "", 6, 0, 6, 6, 0, 6);
53 
54 
55  for(uint i=0; i<existing_ints.size(); ++i){
56  double val = parsHist->GetBinContent(i+1);
57  double err = parsHist->GetBinError(i+1);
58  //std::cout << i+1 << " = " << val << " +/- " << err << std::endl;
59  new_parsHist.SetBinContent(i+1, val);
60  new_parsHist.GetXaxis()->SetBinLabel( i+1, existing_ints.at(i));
61  new_parsHist.SetBinError(i+1, err);
62 
63  new_FitCovHist.GetXaxis()->SetBinLabel( i+1, existing_ints.at(i));
64  new_FitCovHist.GetYaxis()->SetBinLabel( i+1, existing_ints.at(i));
65 
66  for(uint j=0; j<existing_ints.size(); ++j){
67  double cov_val = FitCovHist->GetBinContent(i+1, j+1);
68  new_FitCovHist.SetBinContent(i+1, j+1, cov_val);
69  }
70 
71  }
72 
73  new_parsHist.SetBinContent(5, 1.);
74  new_parsHist.GetXaxis()->SetBinLabel( 5, "fDcex");
75  new_parsHist.SetBinError(5, 0.2);
76 
77  new_parsHist.SetBinContent(6, 1.);
78  new_parsHist.GetXaxis()->SetBinLabel( 6, "fProd");
79  new_parsHist.SetBinError(6, 0.2);
80 
81  new_parsHist.Write("parsHist", TObject::kOverwrite);
82 
83 
84  new_FitCovHist.SetBinContent(5, 5, cov_value);
85  new_FitCovHist.GetXaxis()->SetBinLabel(5, "fDcex");
86  new_FitCovHist.GetYaxis()->SetBinLabel(5, "fDcex");
87 
88  new_FitCovHist.SetBinContent(6, 6, cov_value);
89  new_FitCovHist.GetXaxis()->SetBinLabel(6, "fProd");
90  new_FitCovHist.GetYaxis()->SetBinLabel(6, "fProd");
91 
92  new_FitCovHist.Write("FitCovHist", TObject::kOverwrite);
93 
94 
95  inFile->Close();
96 
97 }
98 
void append()
Definition: append.C:24
ifstream inFile
Definition: AnaPlotMaker.h:34
const double j
Definition: BetheBloch.cxx:29
enum BeamMode string
unsigned int uint