confusionMatrix.C
Go to the documentation of this file.
1 #include <iostream.h>
2 #include <algorithm>
3 #include <math.h>
4 
5 int maxID(double arrayInput[]){
6  int max=0;
7  double maxVal=0.;
8 
9  for(int i=0;i<5;i++){
10  if(arrayInput[i]>maxVal){
11  max=i;
12  maxVal=arrayInput[i];
13  }
14 
15  }
16 
17  return max;
18 }
19 
20 void confusionMatrix(string input) {
21  gROOT->ForceStyle();
22 
23  TChain *ch=new TChain("t");
24  ch->SetMakeClass(1); //<===== important
25  ch->Add(input.c_str());
26 
27  int truelabel=0;
28  double numu=0;
29  double nue=0;
30  double nutau=0;
31  double nc=0;
32  double cosmic=0;
33  int chosenlabel=0;
34 
35  double idOut[5]={0.,0.,0.,0.,0.};
36 
37  ch->SetBranchAddress("truelabel",&truelabel);
38  ch->SetBranchAddress("numu",&numu);
39  ch->SetBranchAddress("nue",&nue);
40  ch->SetBranchAddress("nutau",&nutau);
41  ch->SetBranchAddress("nc",&nc);
42  ch->SetBranchAddress("cosmic",&cosmic);
43 
44  TH2D *heatmap= new TH2D( "heatmap", "", 5,0,5,5,0,5);
45 
46  char *interaction[5] =
47  {"#nu_{#mu}", "#nu_{e}","#nu_{#tau}","NC","Cosmic"};
48 
49  //heatmap->SetBit(TH1::kCanRebin);
50  Int_t nevent =ch.GetEntries();
51  for(Int_t i=0;i<nevent;i++){
52  ch->GetEntry(i);
53  idOut[0]=numu;
54  idOut[1]=nue;
55  idOut[2]=nutau;
56  idOut[3]=nc;
57  idOut[4]=cosmic;
58  chosenlabel=maxID(idOut);
59 
60  heatmap->Fill(double(truelabel),double(chosenlabel));
61 
62  }
63 
64  for (int i=1;i<6;i++){
65  double scale=0;
66  for (int j=1;j<6;j++){
67  scale=scale+heatmap->GetBinContent(i,j);
68  }
69 
70  std::cout<<"how many events do I see? "<<scale<<std::endl;
71 
72  for (int j=1;j<6;j++){
73  if(heatmap->GetBinContent(i,j)/scale>0.0001)
74  {
75  heatmap->SetBinContent(i,j,(heatmap->GetBinContent(i,j))/scale);
76  }
77  else{
78  heatmap->SetBinContent(i,j,.0001);
79  }
80  }
81  }
82 
83 
84 
85  string title="heatmap";
86 
87  TCanvas c3("c3",title.c_str(),900,900);
88 
89  heatmap->SetTitle("");
90  heatmap->SetXTitle("True");
91  heatmap->SetYTitle("Selected");
92  for(int i=1;i<6;i++){
93  heatmap->GetYaxis()->SetBinLabel(i, interaction[i-1]);
94  heatmap->GetXaxis()->SetBinLabel(i, interaction[i-1]);
95  }
96  heatmap->GetXaxis()->SetTickLength(0);
97  heatmap->GetYaxis()->SetTickLength(0);
98  heatmap->GetYaxis()->SetTitleSize(0.06);
99  heatmap->GetXaxis()->SetTitleSize(0.06);
100  heatmap->GetYaxis()->SetTitleOffset(1);
101  heatmap->GetXaxis()->SetTitleOffset(1);
102  heatmap->GetYaxis()->SetLabelSize(0.025);
103  heatmap->GetXaxis()->SetLabelSize(0.025);
104  heatmap->GetZaxis()->SetLabelSize(0.03);
105 
106  heatmap->GetXaxis()->CenterTitle();
107  heatmap->GetYaxis()->CenterTitle();
108 
109  gStyle->SetPalette(53);
110  heatmap->SetMaximum(1.0);
111  heatmap->Draw("colz");
112 
113  string output = "plots/"+title+".gif";
114  c3.Print(output.c_str());
115  string output = "plots/"+title+".C";
116  c3.Print(output.c_str());
117  string output = "plots/"+title+".eps";
118  c3.Print(output.c_str());
119 
120 
121 
122 
123  return;
124 }
125 
ofstream output
void confusionMatrix(string input)
int maxID(double arrayInput[])
Double_t scale
Definition: plot.C:25
Sum up livetimes from individual cosmic triggers.
const double j
Definition: BetheBloch.cxx:29
OStream cout
Definition: OStream.cxx:6
Int_t nevent
Definition: macro.C:10
T max(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:68