makeInitialDecorrelatedErrorPlot.C
Go to the documentation of this file.
1 // script to make a comparison of initial and decorrelated error
2 //
3 // this is compiled with CMake when novasoft is built and can be run with
4 // ./runMakeInitialDecorrelatedErrorPlot.sh </path/to/directory/>
5 // where the path contains all of the covariance matrix files
6 //
7 // author: Adam Lister
8 // date : 2020-02-15
9 
10 // cpp
11 #include <string>
12 #include <string_view>
13 #include <iostream>
14 
15 // root
16 #include "TFile.h"
17 #include "TCanvas.h"
18 #include "TLine.h"
19 #include "TH1D.h"
20 #include "TLegend.h"
21 
22 #include "../utilities/CovarianceBinUtility.h"
23 
24 void usage(){
25 
26  std::cout
27  << "usage:"
28  << "\n -- makeInitialDecorrelatedErrorPlot </path/to/file>"
29  << std::endl;
30 
31 }
32 
34 
35  for (int i = 1; i < h->GetNbinsX()+1; i++){
36  h->SetBinContent(i, 0-h->GetBinContent(i));
37  }
38 
39 }
40 
42  bool isfhc,
43  bool isrhc,
44  bool isnd,
45  bool isfd,
46  bool isnuelow,
47  bool isnuehigh,
48  bool isnueperi,
49  bool isnumuq1,
50  bool isnumuq2,
51  bool isnumuq3,
52  bool isnumuq4,
53  bool isnc){
54 
56  int offset = 0;
57  long key = 0;
58 
59  // seperate components of covmat
60  std::set<cmf::BeamType_t> beamTypes;
61  std::set<cmf::DetType_t> detectors;
62  std::set<cmf::SelectionType_t> selectionTypes;
63  std::vector<int> offsets;
64 
65  if (isfhc) beamTypes .insert(cmf::kFHC);
66  if (isrhc) beamTypes .insert(cmf::kRHC);
67  if (isnd) detectors .insert(cmf::kNEARDET);
68  if (isfd) detectors .insert(cmf::kFARDET);
69  if (isnuelow) selectionTypes.insert(cmf::kNuESelectionLowPID);
70  if (isnuehigh) selectionTypes.insert(cmf::kNuESelectionHighPID);
71  if (isnueperi) selectionTypes.insert(cmf::kNuESelectionPeripheral);
72  if (isnumuq1) selectionTypes.insert(cmf::kNuMuSelectionQ1);
73  if (isnumuq2) selectionTypes.insert(cmf::kNuMuSelectionQ2);
74  if (isnumuq3) selectionTypes.insert(cmf::kNuMuSelectionQ3);
75  if (isnumuq4) selectionTypes.insert(cmf::kNuMuSelectionQ4);
76  if (isnc) selectionTypes.insert(cmf::kNCSelection);
77 
78  for(auto const& bt : beamTypes){
79  md.period = (bt == cmf::kFHC) ? 1 : 4;
80 
81  // have to have the same bins in the ND and FD
82  for(auto const& det : detectors){
83  md.detector = det;
84 
85  // loop over the selection types in each detector
86  for(auto const& sel : selectionTypes){
87 
88  // no peripheral nue selection in the ND
89  if(det == cmf::kNEARDET &&
90  sel == cmf::kNuESelectionPeripheral) continue;
91 
92  md.selectionType = sel;
93  key = md.DetectorBeamSelectionKey();
94 
96  offsets.push_back(offset);
97 
98  }
99  }
100  }
101 
102  TFile* _file0 = new TFile(fileName.c_str(), "read");
103 
104  TH1D* hInitial = (TH1D*)_file0->Get("decorrelator/initialError");
105  TH1D* hDecorrelated = (TH1D*)_file0->Get("decorrelator/decorrelatedError");
106 
107  TH1D* hInitialLower = (TH1D*)hInitial->Clone("hInitialLower");
108  TH1D* hDecorrelatedLower = (TH1D*)hDecorrelated->Clone("hDecorrelatedLower");
109 
110  makeBinContentNegative(hInitialLower);
111  makeBinContentNegative(hDecorrelatedLower);
112 
113  hDecorrelated->SetLineColor(kAzure+1);
114  hDecorrelated->SetFillColor(kAzure+1);
115  hDecorrelatedLower->SetLineColor(kAzure+1);
116  hDecorrelatedLower->SetFillColor(kAzure+1);
117  hInitialLower->SetLineColor(kAzure+6);
118  hInitialLower->SetFillColor(kAzure+6);
119  hInitial->SetLineColor(kAzure+6);
120  hInitial->SetFillColor(kAzure+6);
121 
122 
123  TCanvas *c1 = new TCanvas("c1", "c1", 2000, 400);
124  c1->SetLeftMargin(0.06);
125  c1->SetBottomMargin(0.18);
126  c1->SetRightMargin(0.03);
127 
128  hInitial->SetTitle(";Logical Bin Number;Fractional Error");
129  hInitial->GetYaxis()->SetTitleOffset(0.35);
130  hInitial->GetXaxis()->SetTitleOffset(0.8);
131  hInitial->GetYaxis()->CenterTitle();
132  hInitial->GetXaxis()->CenterTitle();
133  hInitial->GetYaxis()->SetNdivisions(505);
134  hInitial->GetYaxis()->SetTickLength(0.005);
135  hInitial->Draw("hInitial");
136  hInitial->SetLineWidth(2);
137 
138  hInitial->GetXaxis()->SetTitleFont(43);
139  hInitial->GetYaxis()->SetTitleFont(43);
140  hInitial->GetXaxis()->SetTitleSize(30);
141  hInitial->GetYaxis()->SetTitleSize(30);
142  hInitial->GetXaxis()->SetLabelFont(43);
143  hInitial->GetYaxis()->SetLabelFont(43);
144  hInitial->GetXaxis()->SetLabelSize(30);
145  hInitial->GetYaxis()->SetLabelSize(30);
146 
147  float yaxissize =hInitial->GetMaximum()*1.25;
148 
149  hInitial->Draw();
150  //hInitial->GetYaxis()->SetRangeUser(hInitial->GetMaximum()*-1.4, hInitial->GetMaximum()*1.4);
151  hInitial->GetYaxis()->SetRangeUser(-yaxissize, yaxissize);
152  hInitialLower->Draw("same");
153  hDecorrelated->Draw("same");
154  hDecorrelatedLower->Draw("same");
155  gPad->Modified();
156  gPad->Update();
157  gPad->RedrawAxis();
158 
159  TLine* lin = new TLine(0,0,0,0);
160  lin->SetLineColor(kBlack);
161  lin->SetLineStyle(2);
162  for (size_t i = 0; i < offsets.size(); i++){
163  lin->SetX1(offsets.at(i));
164  lin->SetX2(offsets.at(i));
165  lin->SetY1(-yaxissize);
166  lin->SetY2(yaxissize);
167  lin->DrawClone("same");
168  }
169 
170  TLegend *leg = new TLegend(0.1, 0.75, 0.3, 0.90);
171  leg->AddEntry(hInitial , "Initial Error");
172  leg->AddEntry(hDecorrelated, "Decorrelated Error");
173  leg->SetLineWidth(0);
174  leg->SetFillStyle(0);
175  leg->SetTextFont(43);
176  leg->SetTextSize(30);
177  leg->Draw("same");
178 
179 
180  c1->SaveAs("corrDecorr.png");
181  c1->SaveAs("corrDecorr.pdf");
182 
183 }
184 
185 int main(int argc, char *argv[]){
186 
187  if (argc == 0)
188  usage();
189 
190  std::string fileName = argv[1];
191  bool isfhc = argv[2];
192  bool isrhc = argv[3];
193  bool isnd = argv[4];
194  bool isfd = argv[5];
195  bool isnuelow = argv[6];
196  bool isnuehigh = argv[7];
197  bool isnueperi = argv[8];
198  bool isnumuq1 = argv[9];
199  bool isnumuq2 = argv[10];
200  bool isnumuq3 = argv[11];
201  bool isnumuq4 = argv[12];
202  bool isnc = argv[13];
203 
205  isfhc,
206  isrhc,
207  isnd,
208  isfd,
209  isnuelow,
210  isnuehigh,
211  isnueperi,
212  isnumuq1,
213  isnumuq2,
214  isnumuq3,
215  isnumuq4,
216  isnc);
217 
218  return 0;
219 
220 }
fileName
Definition: plotROC.py:78
int KeyToOffset(long const &key, bool allSels=false)
cmf::DetType_t detector
Definition: Structs.h:114
bool isfd
Definition: geo.cxx:18
long DetectorBeamSelectionKey() const
Definition: Structs.cxx:194
cmf::SelectionType_t selectionType
Definition: Structs.h:116
void makeBinContentNegative(TH1D *h)
OStream cout
Definition: OStream.cxx:6
c1
Definition: demo5.py:24
long period
Definition: Structs.h:118
int main(int argc, char *argv[])
void makeInitialDecorrelatedErrorPlot(std::string fileName, bool isfhc, bool isrhc, bool isnd, bool isfd, bool isnuelow, bool isnuehigh, bool isnueperi, bool isnumuq1, bool isnumuq2, bool isnumuq3, bool isnumuq4, bool isnc)
static CovarianceBinUtility * Instance()
enum BeamMode string