All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ROC.cc
Go to the documentation of this file.
1 #include "ROC.h"
2 
3 #include "TGraph.h"
4 
6  crt_track_angle.Initialize("crt_track_angle", 0, 6, 60);
8  crt_hit_distance.Initialize("crt_hit_distance", 0, 100, 100);
10 }
11 
13  for (const NormalizedPrimitive *prim: fAllPrimitives) {
14  prim->Write();
15  }
16 }
17 
18 void ana::SBNOsc::ROC::Normalize(float neutrino_scale, float cosmic_scale) {
19  for (NormalizedPrimitive *prim: fAllPrimitives) {
20  prim->Normalize(neutrino_scale, cosmic_scale);
21  }
22 }
23 
25  for (const NormalizedPrimitive *prim: fAllPrimitives) {
26  std::cout << "Cut (" << prim->name << ") value: " << prim->BestCut() << std::endl;
27  }
28 }
29 
30 void ana::SBNOsc::ROC::Fill(const ana::SBNOsc::Cuts &cuts, const numu::RecoEvent &event, bool file_is_neutrino) {
31  for (unsigned i = 0; i < event.reco.size(); i++) {
32  const numu::RecoInteraction &reco = event.reco[i];
33  bool is_signal = reco.match.mode == numu::mCC;
34  bool is_bkg = reco.match.mode == numu::mCosmic || reco.match.mode == numu::mIntimeCosmic;
35  if (!is_signal && !is_bkg) continue; // ignore NC stuff for now
36 
37  const numu::RecoTrack &track = event.tracks.at(reco.slice.primary_track_index);
38 
39  std::array<bool, ana::SBNOsc::Cuts::nCuts> results = cuts.ProcessRecoCuts(event, i, true);
40 
41  // only apply to events that already pass flash matching
42  if (results[5] /* flashmatch */) {
43  // CRT stuff
44  if (track.crt_match.track.present) {
45  if (file_is_neutrino) crt_track_angle.FillNeutrino(is_signal, track.crt_match.track.angle);
46  else crt_track_angle.FillCosmic(is_signal, track.crt_match.track.angle);
47  }
48  else {
49  if (file_is_neutrino) crt_track_angle.FillNeverNeutrino(is_signal);
50  else crt_track_angle.FillNeverCosmic(is_signal);
51  }
52  if (track.crt_match.hit_match.present && !cuts.TimeInSpill(track.crt_match.hit_match.time)) {
53  if (file_is_neutrino) crt_hit_distance.FillNeutrino(is_signal, track.crt_match.hit_match.distance);
54  else crt_hit_distance.FillCosmic(is_signal, track.crt_match.hit_match.distance);
55  }
56  else {
57  if (file_is_neutrino) crt_hit_distance.FillNeverNeutrino(is_signal);
58  else crt_hit_distance.FillNeverCosmic(is_signal);
59  }
60  }
61  }
62 
63 }
64 
65 void ana::SBNOsc::ROC::NormalizedPrimitive::Initialize(const std::string &this_name, float cut_low, float cut_high, unsigned n_bin) {
66  fNeutrino.Initialize(this_name + "neutrino_", cut_low, cut_high, n_bin);
67  fCosmic.Initialize(this_name + "cosmic_", cut_low, cut_high, n_bin);
68  name = this_name;
69 }
70 
71 void ana::SBNOsc::ROC::Primitive::Initialize(const std::string &this_name, float cut_low, float cut_high, unsigned n_bin) {
72  signal = new TH1D((this_name + "signal").c_str(), this_name.c_str(), n_bin, cut_low, cut_high);
73  background = new TH1D((this_name + "background").c_str(), this_name.c_str(), n_bin, cut_low, cut_high);
74  n_signal = 0;
75  n_background = 0;
76  name = this_name;
77 }
78 
79 void ana::SBNOsc::ROC::Primitive::Fill(bool is_signal, float value) {
80  TH1D *hist = is_signal ? signal : background;
81  unsigned bin = 1;
82  while (bin <= hist->GetNbinsX() && value > hist->GetXaxis()->GetBinCenter(bin)) {
83  hist->Fill(hist->GetXaxis()->GetBinCenter(bin));
84  bin += 1;
85  }
86  n_signal += is_signal;
87  n_background += !is_signal;
88 }
89 
91  TH1D *hist = is_signal ? signal : background;
92  unsigned bin = 1;
93  for (unsigned bin = 1; bin <= hist->GetNbinsX(); bin++) {
94  hist->Fill(hist->GetXaxis()->GetBinCenter(bin));
95  }
96  n_signal += is_signal;
97  n_background += !is_signal;
98 }
99 
101  n_signal += is_signal;
102  n_background += !is_signal;
103 }
104 
106  signal->Scale(scale);
107  background->Scale(scale);
108  n_signal *= scale;
109  n_background *= scale;
110 }
111 
112 void ana::SBNOsc::ROC::NormalizedPrimitive::Normalize(float scale_neutrino, float scale_cosmic) {
113  fNeutrino.Scale(scale_neutrino);
114  fCosmic.Scale(scale_cosmic);
115 }
116 
118  return fNeutrino.signal->GetBinContent(bin) + fCosmic.signal->GetBinContent(bin);
119 }
120 
122  return fNeutrino.background->GetBinContent(bin) + fCosmic.background->GetBinContent(bin);
123 }
124 
126  return fNeutrino.signal->GetNbinsX();
127 }
128 
130  return fNeutrino.signal->GetBinCenter(bin);
131 }
132 
134  return fNeutrino.n_signal + fCosmic.n_signal;
135 }
136 
138  return fNeutrino.n_background + fCosmic.n_background;
139 }
140 
142  float max_significance = 0.;
143  float best_cut = 0.;
144  for (unsigned bin = 1; bin <= NCutVals(); bin++) {
145  float sig = Signal(bin);
146  float bkg = Background(bin);
147  float this_significance = 0.;
148  if (sig + bkg > 1.e-4) {
149  this_significance = sig / sqrt(sig + bkg);
150  }
151  if (this_significance > max_significance) {
152  max_significance = this_significance;
153  best_cut = GetCutVal(bin);
154  }
155  }
156  return best_cut;
157 }
158 
160  std::vector<float> eff;
161  std::vector<float> rejection;
162  for (unsigned bin = 1; bin <= NCutVals(); bin++) {
163  float this_eff = Signal(bin) / NSignal();
164  float this_rej = 1 - Background(bin) / NBackground();
165  eff.push_back(this_eff);
166  rejection.push_back(this_rej);
167  }
168  TGraph *ROC = new TGraph(NCutVals(), &eff[0], &rejection[0]);
169  ROC->SetTitle(name.c_str());
170  ROC->SetName(name.c_str());
171  ROC->Write();
172 
173  delete ROC;
174 }
175 
177  delete signal;
178  delete background;
179 }
180 
181 
bool TimeInSpill(float time) const
Definition: Cuts.cc:217
InteractionMode mode
Mode of the interaction.
Track track
CRT Track match.
Definition: CRTMatch.h:30
NormalizedPrimitive crt_hit_distance
Definition: ROC.h:78
void Initialize(const std::string &name, float cut_low, float cut_high, unsigned n_bin)
Definition: ROC.cc:71
float distance
//!&lt; Distance from projected track to CRT Hit. Nonsense if present is false.
Definition: CRTMatch.h:26
CRTMatch crt_match
CRTMatch.
Definition: RecoTrack.h:59
bool present
Whether this CRTMatch has a matching track.
Definition: CRTMatch.h:16
void Fill(bool is_signal, float value)
Definition: ROC.cc:79
TruthMatch match
Info for mathing to truth.
Definition: RecoEvent.h:42
void FillNever(bool is_signal)
Definition: ROC.cc:90
float Signal(unsigned bin) const
Definition: ROC.cc:117
int primary_track_index
Index of the primary track.
Definition: RecoEvent.h:27
std::array< bool, nCuts > ProcessRecoCuts(const numu::RecoEvent &event, unsigned reco_vertex_index, bool fSequentialCuts=true) const
Definition: Cuts.cc:125
process_name use argoneut_mc_hitfinder track
void Write() const
Definition: ROC.cc:12
float Background(unsigned bin) const
Definition: ROC.cc:121
constexpr details::BinObj< T > bin(T value)
Returns a wrapper to print the specified data in binary format.
Definition: Mode.h:9
process_name standard_reco_uboone reco
void Fill(const Cuts &cuts, const numu::RecoEvent &event, bool file_is_neutrino)
Definition: ROC.cc:30
bool present
Whether this CRTMatch has a matching hit.
Definition: CRTMatch.h:25
void Normalize(float neutrino_scale, float cosmic_scale)
Definition: ROC.cc:18
float GetCutVal(unsigned bin) const
Definition: ROC.cc:129
void Normalize(float scale_neutrino, float scale_cosmic)
Definition: ROC.cc:112
RecoSlice slice
Particle content of the interaction.
Definition: RecoEvent.h:39
do i e
float angle
Angle between TPC track and CRT track.
Definition: CRTMatch.h:18
then echo fcl name
unsigned NCutVals() const
Definition: ROC.cc:125
temporary value
void FillAlways(bool is_signal)
Definition: ROC.cc:100
void BestCuts() const
Definition: ROC.cc:24
NormalizedPrimitive crt_track_angle
Definition: ROC.h:77
void Scale(float scale)
Definition: ROC.cc:105
void Initialize(const std::string &name, float cut_low, float cut_high, unsigned n_bin)
Definition: ROC.cc:65
std::vector< NormalizedPrimitive * > fAllPrimitives
Definition: ROC.h:79
HitMatch hit_match
CRT Hit match.
Definition: CRTMatch.h:31
BEGIN_PROLOG could also be cout
void Initialize()
Definition: ROC.cc:5