EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CharmJetClassifier_Scan.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file CharmJetClassifier_Scan.C
1 #include "TROOT.h"
2 #include "TTree.h"
3 #include "TFile.h"
4 #include "TTreeFormula.h"
5 #include <iostream>
6 #include "TMath.h"
7 #include "TH1.h"
8 #include "TCut.h"
9 #include <map>
10 
11 void CharmJetClassifier_Scan(TString inputfile = "CharmJetClassification_Results.root",
12  TString foldername = "dataset",
13  TString taggername = "MLP",
14  Float_t bkg_eff = 0.004) {
15  TFile *_file0 = TFile::Open(inputfile.Data());
16  TTree *TestTree = static_cast < TTree * > (_file0->Get(Form("%s/TestTree", foldername.Data())));
17  TTree *TrainTree = static_cast < TTree * > (_file0->Get(Form("%s/TrainTree", foldername.Data())));
18 
19  Float_t nlight = TestTree->GetEntries("jet_flavor<4 || jet_flavor==22");
20  Float_t ncharm = TestTree->GetEntries("jet_flavor==4");
21 
22 
23  Float_t opt_cut = 0.000;
24  Float_t min_dist = 1000.0;
25 
26  for (Float_t mva_cut = 0.000; mva_cut < 1.000; mva_cut += 0.001) {
27  Float_t nlight_pass = TestTree->GetEntries(Form("jet_pt>5.0 && TMath::Abs(jet_eta) < 3.0 && met_et > 10.0 && (jet_flavor<4 || jet_flavor==22) && %s>%f", taggername.Data(), mva_cut));
28  Float_t ncharm_pass = TestTree->GetEntries(Form("jet_pt>5.0 && TMath::Abs(jet_eta) < 3.0 && met_et > 10.0 && (jet_flavor==4) && %s>%f", taggername.Data(), mva_cut));
29 
30  Float_t light_eff = nlight_pass / nlight;
31 
32  if (TMath::Abs(light_eff - bkg_eff) < min_dist) {
33  min_dist = TMath::Abs(light_eff - bkg_eff);
34  opt_cut = mva_cut;
35  }
36  }
37 
38  // Print the final selection information
39  Float_t nlight_pass = TestTree->GetEntries(Form("jet_pt>5.0 && TMath::Abs(jet_eta) < 3.0 && met_et > 10.0 && (jet_flavor<4 || jet_flavor==22) && %s>%f", taggername.Data(), opt_cut));
40  Float_t ncharm_pass = TestTree->GetEntries(Form("jet_pt>5.0 && TMath::Abs(jet_eta) < 3.0 && met_et > 10.0 && (jet_flavor==4) && %s>%f", taggername.Data(), opt_cut));
41 
42  std::cout << Form("MLP cut %.3f", opt_cut) << " yields Eff_c = "
43  << Form("%.3f", ncharm_pass / ncharm) << " and Eff_light = "
44  << Form("%.3e", nlight_pass / nlight) << std::endl;
45 
46 
48  // Background.
49  std::cout << "Over-Training Study" << std::endl;
50  std::cout << "=============================================" << std::endl;
51  std::map < TString, TCut > samples;
52  samples["Signal"] = TCut("jet_flavor==4");
53  samples["Background"] = TCut("(jet_flavor<4 || jet_flavor==22)");
54 
55  for (auto sample : samples) {
56  TH1F *h_train = new TH1F("h_train",
57  "",
58  100,
59  0,
60  1);
61  h_train->Sumw2();
62  auto h_test = static_cast < TH1F * > (h_train->Clone("h_test"));
63 
64  TrainTree->Project(h_train->GetName(), Form("%s",taggername.Data()), sample.second);
65  TestTree->Project(h_test->GetName(), Form("%s",taggername.Data()), sample.second);
66  Float_t KS_Test = h_test->KolmogorovTest(h_train);
67  std::cout << sample.first << ": K-S Test p-value = " << KS_Test << std::endl;
68 
69  if (h_test) delete h_test;
70 
71  if (h_train) delete h_train;
72  }
73 }