FOMCalc.C
Go to the documentation of this file.
1 //Create a histogram out of the .root file generated on the grid.
2 #ifdef __CINT__
3 void FOMCalc()
4 {
5  std::cout << "Sorry, you must run in compiled mode" << std::endl;
6 }
7 #else
8 
9 #include "CAFAna/Cuts/Cuts.h"
10 #include "CAFAna/Core/Spectrum.h"
12 
13 
14 #include "TCanvas.h"
15 #include "TH2.h"
16 #include "TStyle.h"
17 #include "TArrow.h"
18 #include "TH1.h"
19 #include "TH3.h"
20 #include "TFile.h"
21 #include "TLegend.h"
22 #include "TGraph.h"
23 #include <cmath>
24 #include <cassert>
25 #include <memory>
26 #include "TProfile.h"
27 #include <fstream>
28 #include <sstream>
29 #include <iostream>
30 #include <iomanip>
31 #include <stdarg.h>
32 #include <stdlib.h>
33 #include <stdio.h>
34 #include <string.h>
35 
36 
37 using namespace ana;
38 
39 void FOMCalc()
40 {
41 
42  //Make a new file that reads in my generated .root file.
43  TFile *fpid = new TFile ("/nova/app/users/rbowles/tag_releaseS17-05-31/NDAna/ncpi0/PID/out2.root","READ");
44 
45 
46  //Check that the file exists.
47  if( !(fpid) || (fpid->IsZombie()))
48  {
49  std::cout << " <<<<<<<<<<< Intensity.root >>>>>>>> file doesn't exist OR Zombie!!" << std::endl;
50  }
51 
52 
53 
54  double s = 0;
55  double b=0;
56  double fom=0;
57  double maxfom=0;
58  double maxrem=0;
59  double den;
60 
61 
62  //Fill the Spectrums with the information from the .root file
63  auto sig = *Spectrum::LoadFrom(fpid->GetDirectory("sig"));
64  auto bkg = *Spectrum::LoadFrom(fpid->GetDirectory("bkg"));
65 
66  //Scale the histogram.
67  const double pot = 8.09e20;
68 
69  //Make histogram objects.
70  TH1* totbkgh = bkg.ToTH1(pot);
71 
72  TH1* sigh = sig.ToTH1(pot);
73 
74  int nbins = sigh->GetNbinsX();
75 
76  TH1D *hFom=new TH1D("FoM","FoM",nbins,0,1);
77  for(int i=0;i<nbins;i++)
78  {
79  s=sigh->Integral(0,i);
80  b=totbkgh->Integral(0,i);
81 
82  den=sqrt(s+b);
83 
84  fom = s/den;
85 
86  hFom->SetBinContent(i,fom);
87 
88  if(maxfom<fom)
89  {
90  maxfom=fom;
91 
92  maxrem=sigh->GetBinCenter(i);
93  }
94  }
95 
96  std::cout<<"Max FOM BDT: "<<maxfom<<" at: "<<maxrem<<std::endl;
97 
98 
99 
100  /*
101  for (Int_t bin = 0; bin < 81; ++bin)
102  {
103  Double_t sigbin = sigh->GetBinContent(bin);
104  Double_t bkgbin = totbkgh->GetBinContent(bin);
105 
106  std::cout<<"Signal entries in bin "<<bin<<": "<<sigbin<<std::endl;
107  std::cout<<"Background entries in bin "<<bin<<": "<<bkgbin<<std::endl;
108 
109  Double_t fom = sigbin/sqrt(sigbin+bkgbin);
110 
111  std::cout<<"Figure of Merit for bin "<<bin<<": "<<fom<<"\n"<<std::endl;
112  }
113  */
114 
115 }
116 
117 
118 #endif
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
Float_t den
Definition: plot.C:36
T sqrt(T number)
Definition: d0nt_math.hpp:156
void FOMCalc()
Definition: FOMCalc.C:39
const XML_Char * s
Definition: expat.h:262
const int nbins
Definition: cellShifts.C:15
static std::unique_ptr< Spectrum > LoadFrom(TDirectory *dir, const std::string &name)
Definition: Spectrum.cxx:546
#define pot
OStream cout
Definition: OStream.cxx:6
const hit & b
Definition: hits.cxx:21