forked from uboone/xsec_analyzer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCutPlots.C
861 lines (709 loc) · 39.5 KB
/
CutPlots.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
// Standard library includes
#include <iomanip>
#include <map>
#include <memory>
#include <string>
// ROOT includes
#include "TCanvas.h"
#include "TChain.h"
#include "TFile.h"
#include "TH1D.h"
#include "THStack.h"
#include "TLegend.h"
#include "TLine.h"
#include "TParameter.h"
#include "TStyle.h"
#include "TPad.h"
// STV analysis includes
#include "EventCategory.hh"
#include "FiducialVolume.hh"
#include "FilePropertiesManager.hh"
#include "HistUtils.hh"
#include "PlotUtils.hh"
// Abbreviation to make using the enum class easier
using NFT = NtupleFileType;
#define FILE_PROPERTIES "file_properties_testingOnly_lowPiMomThreshold.txt"
void make_plots( const std::string& out_name,
const std::string& branchexpr, const std::string& selection,
const std::set<int>& runs, std::vector<double> bin_low_edges,
const std::string& x_axis_label = "",
const std::string& y_axis_label = "", const std::string& title = "",
const std::set<float> &vertical_lines = std::set<float>{},
const bool xAxisLog = false,
const bool yAxisLog = false,
const bool noData = false,
const std::string& mc_event_weight = DEFAULT_MC_EVENT_WEIGHT )
{
// Get the number of bins to use in histograms
int Nbins = bin_low_edges.size() - 1;
// Make a counter that iterates each time this function is called. We'll use
// it to avoid duplicate histogram names (which can confuse ROOT).
static long plot_counter = -1;
++plot_counter;
// Get access to the singleton utility classes that we'll need
const EventCategoryInterpreter& eci = EventCategoryInterpreter::Instance();
FilePropertiesManager& fpm = FilePropertiesManager::Instance();
#ifdef FILE_PROPERTIES
fpm.load_file_properties( FILE_PROPERTIES );
#endif
// Consider samples for data taken with the beam on, data taken with the beam
// off, and CV MC samples for numus, intrinsic nues, and dirt events
constexpr std::array< NFT, 4 > file_types = { NFT::kOnBNB, NFT::kExtBNB,
NFT::kNumuMC, NFT::kDirtMC }; // NFT::kIntrinsicNueMC
// Similar array that includes only the CV MC samples
constexpr std::array< NFT, 2 > mc_file_types = { NFT::kNumuMC,
NFT::kDirtMC }; // NFT::kIntrinsicNueMC
// Prepare TChains needed to loop over the event ntuples to be analyzed. Also
// prepare maps to keep track of the corresponding POT normalizations and
// total number of triggers (the latter of these is actually used only for
// data samples).
std::map< NFT, std::unique_ptr<TChain> > tchain_map;
std::map< NFT, double > pot_map;
std::map< NFT, long > trigger_map;
for ( const auto& type : file_types ) {
tchain_map.emplace( std::make_pair(type, new TChain("stv_tree")) );
pot_map[ type ] = 0.;
trigger_map[ type ] = 0;
}
// Add files for each of the selected runs to the appropriate TChain. Also
// update the corresponding POT normalizations. Use the FilePropertiesManager
// to find the right ntuple files for each run.
const auto& ntuple_map = fpm.ntuple_file_map();
const auto& data_norm_map = fpm.data_norm_map();
for ( const int& run : runs ) {
// Get the map storing the ntuple file names for the current run
const auto& run_map = ntuple_map.at( run );
for ( const auto& type : file_types ) {
// Get the set of ntuple files for the current run and sample type
const auto& ntuple_files = run_map.at( type );
// Get access to the corresponding TChain, total POT value, and total
// number of triggers that we want to use to handle these files
auto* tchain = tchain_map.at( type ).get();
double& total_pot = pot_map.at( type );
long& total_triggers = trigger_map.at( type );
for ( const auto& file_name : ntuple_files ) {
// Add the current file to the appropriate TChain
tchain->Add( file_name.c_str() );
// For data samples, get normalization information from the
// FilePropertiesManager and add it to the total (it's not stored in
// the files themselves)
if ( type == NFT::kOnBNB || type == NFT::kExtBNB ) {
const auto& norm_info = data_norm_map.at( file_name );
total_triggers += norm_info.trigger_count_;
// This will just be zero for beam-off data. We will calculate an
// effective value using the trigger counts below.
total_pot += norm_info.pot_;
}
// For MC samples, extract the POT normalization from the TParameter
// stored in the file
else if ( type == NFT::kNumuMC || type == NFT::kIntrinsicNueMC
|| type == NFT::kDirtMC )
{
TFile temp_file( file_name.c_str(), "read" );
TParameter<float>* temp_pot = nullptr;
temp_file.GetObject( "summed_pot", temp_pot );
double pot = temp_pot->GetVal();
total_pot += pot;
}
} // file names
} // ntuple types
} // runs
// Prepare strings used by multiple histograms below
std::string hist_name_prefix = "hist_plot" + std::to_string( plot_counter );
std::string plot_title = title + "; " + x_axis_label + "; " + y_axis_label;
// Fill the beam-off data histogram using the matching TChain
std::string off_data_hist_name = hist_name_prefix + "_ext";
TH1D* off_data_hist = new TH1D( off_data_hist_name.c_str(),
plot_title.c_str(), Nbins, bin_low_edges.data() );
TChain* off_chain = tchain_map.at( NFT::kExtBNB ).get();
off_chain->Draw( (branchexpr + " >> " + off_data_hist_name).c_str(),
selection.c_str(), "goff" );
//off_data_hist->SetDirectory( nullptr );
// We need to scale the beam-off data to an effective POT based on the ratio
// of the total trigger counts for beam-off and beam-on data. Do that here.
double pot_on = pot_map.at( NFT::kOnBNB );
double trigs_on = trigger_map.at( NFT::kOnBNB );
double trigs_off = trigger_map.at( NFT::kExtBNB );
// Compute the effective POT and store it in the map
double ext_effective_pot = trigs_off * pot_on / trigs_on;
pot_map[ NFT::kExtBNB ] = ext_effective_pot;
// Scale the beam-off data based on the effective POT
off_data_hist->Scale( pot_on / ext_effective_pot );
eci.set_ext_histogram_style( off_data_hist );
// Fill the beam-on data histogram using the matching TChain
std::string on_data_hist_name = hist_name_prefix + "_on";
TH1D* on_data_hist = new TH1D( on_data_hist_name.c_str(),
plot_title.c_str(), Nbins, bin_low_edges.data() );
TChain* on_chain = tchain_map.at( NFT::kOnBNB ).get();
on_chain->Draw( (branchexpr + " >> " + on_data_hist_name).c_str(),
selection.c_str(), "goff" );
//on_data_hist->SetDirectory( nullptr );
on_data_hist->Scale( 1. );
eci.set_bnb_data_histogram_style( on_data_hist );
// Initialize empty stacked histograms organized by MC event category
std::map< EventCategory, TH1D* > mc_hists;
// Loop over all MC event categories
for ( const auto& pair : eci.label_map() ) {
EventCategory cat = pair.first;
std::string cat_label = pair.second;
std::string temp_mc_hist_name = hist_name_prefix + "_mc"
+ std::to_string( cat );
TH1D* temp_mc_hist = new TH1D( temp_mc_hist_name.c_str(),
plot_title.c_str(), Nbins, bin_low_edges.data() );
mc_hists[ cat ] = temp_mc_hist;
//temp_mc_hist->SetDirectory( nullptr );
eci.set_mc_histogram_style( cat, temp_mc_hist );
// // Change the temp_mc_hist histgram fill color to grey and remove the outline
// temp_mc_hist->SetFillColor( kBlue );
// temp_mc_hist->SetLineColor( kBlue );
// temp_mc_hist->SetLineWidth( 0 );
}
// Loop over the different MC samples and collect their contributions. We
// have to handle them separately in order to get the POT normalization
// correct.
// Counter that avoids duplicate temporary MC histogram names. This is used
// to avoid annoying ROOT warnings.
static int dummy_counter = 0;
for ( const auto& type : mc_file_types ) {
// std::cout<<"DEBUG plot.C Point 16"<<std::endl;
TChain* mc_ch = tchain_map.at( type ).get();
double on_pot = pot_map.at( NFT::kOnBNB );
double mc_pot = pot_map.at( type );
// std::cout<<"DEBUG plot.C Point 17"<<std::endl;
// Add this sample's contribution to the stacked histograms by MC event
// category
for ( const auto& pair : eci.label_map() ) {
EventCategory ec = pair.first;
// std::cout<<"DEBUG plot.C Point 17.1"<<std::endl;
std::string temp_mc_hist_name = hist_name_prefix + "_temp_mc"
+ std::to_string( ec ) + "_number" + std::to_string( dummy_counter );
++dummy_counter;
// std::cout<<"DEBUG plot.C Point 17.2"<<std::endl;
TH1D* temp_mc_hist = new TH1D( temp_mc_hist_name.c_str(),
plot_title.c_str(), Nbins, bin_low_edges.data() );
mc_ch->Draw( (branchexpr + " >> " + temp_mc_hist_name).c_str(),
(mc_event_weight + "*(" + selection + " && category == "
+ std::to_string(ec) + ')').c_str(), "goff" );
// std::cout<<"DEBUG plot.C Point 17.3"<<std::endl;
// Scale to the same exposure as the beam-on data
temp_mc_hist->Scale( on_pot / mc_pot );
// Add this histogram's contribution (now properly scaled) to the total
// std::cout<<"DEBUG plot.C Point 18"<<std::endl;
mc_hists.at( ec )->Add( temp_mc_hist );
// std::cout<<"DEBUG plot.C Point 19"<<std::endl;
// We don't need the temporary histogram anymore, so just get rid of it
delete temp_mc_hist;
} // event categories
} // MC samples
// All the input histograms are now ready. Prepare the plot.
auto* c1 = new TCanvas("c1", "c1", 1200, 800); // Width is 1200 pixels, height is 800 pixels
//c1->SetLeftMargin( 0.12 );
//c1->SetBottomMargin( 1.49 );
TPad* pad1 = new TPad( "pad1", "", 0.0, noData ? 0.0 : 0.23, 0.75, 1.0 );
pad1->SetBottomMargin( 0.01 );
pad1->SetRightMargin( 0.03 );
pad1->SetLeftMargin( 0.13 );
pad1->SetGridx();
// Add bottom padding to the pad
pad1->SetBottomMargin( noData ? 0.15 : 0.05 );
pad1->Draw();
pad1->cd();
pad1->SetLogx(xAxisLog);
pad1->SetLogy(yAxisLog);
if (yAxisLog) on_data_hist->SetMinimum(1);
if(!noData) on_data_hist->Draw( "E1" );
// Stack of categorized MC predictions plus extBNB contribution
THStack* stacked_hist = new THStack( "mc", "" );
// Sum all contributions into this TH1D so that we can get the overall
// statistical uncertainty easily
TH1D* stat_err_hist = new TH1D(
("stat_err_hist_" + hist_name_prefix).c_str(), "",
Nbins, bin_low_edges.data()
);
stacked_hist->Add( off_data_hist );
stat_err_hist->Add( off_data_hist );
for ( auto citer = mc_hists.crbegin(); citer != mc_hists.crend();
++citer )
{
TH1D* hist = citer->second;
stacked_hist->Add( hist );
stat_err_hist->Add( hist );
}
if (yAxisLog) stacked_hist->SetMinimum(1);
if(noData) stacked_hist->Draw( "hist" );
else stacked_hist->Draw( "hist same" );
if(!noData) on_data_hist->Draw( "E1 same" );
eci.set_stat_err_histogram_style( stat_err_hist );
if (yAxisLog) stat_err_hist->SetMinimum(1);
stat_err_hist->Draw( "E2 same" );
// Adjust y-axis range for stacked plot. Check both the data and the
// stacked histograms (via the combined stat_err_hist)
double ymax = stat_err_hist->GetBinContent( stat_err_hist->GetMaximumBin() );
double ymax2 = on_data_hist->GetBinContent( on_data_hist->GetMaximumBin() );
if ( ymax < ymax2 ) ymax = ymax2;
// Redraw the histograms with the updated y-axis range
on_data_hist->GetYaxis()->SetRangeUser( 1, 1.2*ymax );
if(!noData) on_data_hist->Draw( "E1 same" );
for (const auto& x : vertical_lines) {
TLine* line = new TLine( x, 0, x, noData ? ymax : 1.2*ymax );
line->SetLineColor( kBlack );
line->SetLineStyle( 9 ); // dashed
line->SetLineWidth( 2 );
line->Draw();
}
// Prepare the plot legend
c1->cd(); // Go back from pad1 to main canvas c1
TLegend* lg = new TLegend(0.75, 0.1, 1, 0.95); // Position the legend to the right of the pads
std::string legend_title = get_legend_title( pot_on );
lg->SetHeader( legend_title.c_str(), "C" );
if(!noData) lg->AddEntry( on_data_hist, "Data (beam on)", "lp" );
lg->AddEntry( stat_err_hist, "Statistical uncertainty", "f" );
double total_events = stat_err_hist->Integral();
for ( const auto& pair : eci.label_map() ) {
EventCategory ec = pair.first;
std::string label = pair.second;
// Skip categories with no events
if ( mc_hists.at( ec )->Integral() == 0 ) continue;
// std::cout<<"DEBUG plot.C Point 20"<<std::endl;
TH1* category_hist = mc_hists.at( ec );
// std::cout<<"DEBUG plot.C Point 21"<<std::endl;
// Use TH1::Integral() to account for CV reweighting correctly
double events_in_category = category_hist->Integral();
double category_percentage = events_in_category * 100. / total_events;
std::string cat_pct_label = Form( "%.2f%#%", category_percentage );
lg->AddEntry( category_hist, (label + ", " + cat_pct_label).c_str(), "f" );
}
double beam_off_events = off_data_hist->Integral();
double beam_off_percentage = beam_off_events * 100. / total_events;
std::string off_pct_label = Form( "%.2f%#%", beam_off_percentage );
lg->AddEntry( off_data_hist, ("Data (beam off), "
+ off_pct_label).c_str(), "f" );
lg->SetBorderSize( 0 );
// Increase the font size for the legend header
// (see https://root-forum.cern.ch/t/tlegend-headers-font-size/14434)
TLegendEntry* lg_header = dynamic_cast< TLegendEntry* >(
lg->GetListOfPrimitives()->First() );
lg_header->SetTextSize( 0.03 );
lg->Draw( "same" );
// Ratio plot
TPad* pad2 = new TPad( "pad2", "", 0, 0.01, 0.75, 0.23 );
if(!noData)
{
pad2->SetFrameFillStyle( 4000 );
pad2->SetBottomMargin( 0.38 );
pad2->SetTopMargin( 0.01 );
pad2->SetRightMargin( 0.03 );
pad2->SetLeftMargin( 0.13 );
pad2->SetGridx();
pad2->Draw();
pad2->cd(); // change current pad to pad2
pad2->SetLogx(xAxisLog);
// Ratio plot
TH1D* h_ratio = dynamic_cast<TH1D*>( on_data_hist->Clone("h_ratio") );
h_ratio->SetStats( false );
h_ratio->Divide( stat_err_hist );
h_ratio->SetLineWidth( 2 );
h_ratio->SetLineColor( kBlack );
h_ratio->SetMarkerStyle( kFullCircle );
h_ratio->SetMarkerSize( 0.8 );
h_ratio->SetTitle( "" );
// x-axis
h_ratio->GetXaxis()->SetTitle( on_data_hist->GetXaxis()->GetTitle() );
h_ratio->GetXaxis()->CenterTitle( true );
h_ratio->GetXaxis()->SetLabelSize( 0.12 );
h_ratio->GetXaxis()->SetTitleSize( 0.18 );
h_ratio->GetXaxis()->SetTickLength( 0.05 );
h_ratio->GetXaxis()->SetTitleOffset( 0.9 );
// y-axis
h_ratio->GetYaxis()->SetTitle( "Ratio" ); //"#frac{Beam ON}{Beam OFF + MC}" );
h_ratio->GetYaxis()->CenterTitle( true );
h_ratio->GetYaxis()->SetLabelSize( 0.08);
h_ratio->GetYaxis()->SetTitleSize( 0.15 );
h_ratio->GetYaxis()->SetTitleOffset( 0.35 );
h_ratio->Draw( "E1" );
gStyle->SetGridColor( 17 );
// Adjust y-axis
double ratio_max = -std::numeric_limits<double>::max();
double ratio_min = std::numeric_limits<double>::max();
int nBins = h_ratio->GetNbinsX();
for (int i = 1; i <= nBins; ++i) {
double binContent = h_ratio->GetBinContent(i);
if (binContent > 0) {
if (binContent > ratio_max) {
ratio_max = binContent;
}
if (binContent < ratio_min) {
ratio_min = binContent;
}
}
}
h_ratio->SetMaximum( ratio_max + ratio_max*0.15 );
h_ratio->SetMinimum( ratio_min - ratio_min*0.2 );
gPad->Update();
// Draw a horizontal dashed line at ratio == 1
TLine* line = new TLine( h_ratio->GetXaxis()->GetXmin(), 1.0,
h_ratio->GetXaxis()->GetXmax(), 1.0 );
line->SetLineColor( kBlack );
line->SetLineStyle( 9 ); // dashed
line->Draw();
}
// Set the axis labels and title when not using pads
if(noData)
{
stacked_hist->GetXaxis()->SetTitle( x_axis_label.c_str() );
stacked_hist->GetYaxis()->SetTitle( y_axis_label.c_str() );
stacked_hist->SetTitle( title.c_str() );
}
c1->Update();
// Save the plot to a file named after selection and the runs included
std::string runNames = "";
for ( const auto& run : runs ) {
runNames += std::to_string( run );
}
std::string plot_name = "plots/" + out_name + "_runs" + runNames + "_testingOnly_lowPiMomThreshold";
c1->SaveAs( (plot_name + ".pdf").c_str() );
c1->SaveAs( (plot_name + ".png").c_str() );
c1->SaveAs( (plot_name + ".C").c_str() );
}
// // Overloaded version with constant-width binning
// void make_plots( const std::string& branchexpr, const std::string& selection,
// const std::set<int>& runs, double xmin, double xmax, int Nbins,
// const std::string& x_axis_label = "", const std::string& y_axis_label = "",
// const std::string& title = "",
// const std::string& mc_event_weight = DEFAULT_MC_EVENT_WEIGHT )
// {
// // Generates a vector of bin low edges equivalent to the approach used by the
// // TH1 constructor that takes xmin and xmax in addition to the number of bins
// auto bin_low_edges = get_bin_low_edges( xmin, xmax, Nbins );
// make_plots( branchexpr, selection, runs, bin_low_edges, x_axis_label,
// y_axis_label, title, mc_event_weight );
// }
std::vector<double> get_log_bin_edges( double xMin, double xMax, int nBins )
{
std::vector<double> binEdges(nBins + 1);
double logMin = TMath::Log10(xMin);
double logMax = TMath::Log10(xMax);
double binWidth = (logMax - logMin) / nBins;
for (int i = 0; i <= nBins; i++) {
binEdges[i] = TMath::Power(10, logMin + i * binWidth);
}
return binEdges;
}
void CutPlots() {
const std::vector<std::set<int>> runSets = {
std::set<int>{1},
std::set<int>{2},
std::set<int>{3},
std::set<int>{4},
std::set<int>{5},
std::set<int>{1,2,3,4,5},
};
const std::map<std::string, std::vector<double>> binEdges{
{"nTracks", {1, 2, 3, 4, 5, 6, 7}},
{"nUncontained", {0, 1, 2, 3, 4}},
{"nNonProtons", {1, 2, 3, 4, 5, 6}},
{"pionTruncatedMeandEdx", get_bin_low_edges( 0, 5, 30 )},
{"pionPhi", get_bin_low_edges( -3.15, 3.15, 30 )},
{"muonPhi", get_bin_low_edges( -3.15, 3.15, 30 )},
// {"pionPhi", {0.f, 1.f, 2.f}},
// {"muonPhi", {0.f, 1.f, 2.f}},
{"topologicalScore", get_bin_low_edges( 0, 1, 30 )},
{"maxVertexDist", get_log_bin_edges( 0.1, 1000, 30 )},
{"goldenPionBDTScore", get_bin_low_edges(-0.8, 0.6, 30 )},
{"openingAngle", get_bin_low_edges( 0, 3.15, 25 )},
{"openingAngle2", get_bin_low_edges( 2.35, 3.15, 8)},
{"muonMomentum", get_bin_low_edges( 0, 1.5, 30 )},
{"muonMomentum2", get_bin_low_edges( 0.0, 0.3, 8 )},
{"pionMomentum", get_bin_low_edges( 0, 1.0, 30 )},
{"pionMomentum2", get_bin_low_edges( 0, 0.2, 4 )},
};
for (const auto& runSet : runSets)
{
// make_plots( /* out_name = */ "cut1",
// /* branchexpr = */ "event_cutValue_nTracks",
// /* selection = */ "passed_topologicalScoreCC",
// /* runs = */ runSet,
// /* bin_low_edges = */ binEdges.at("nTracks"),
// /* x_axis_label = */ "Number of fitted tracks",
// /* y_axis_label = */ "# Events",
// /* title = */ "Generic Cut #1: At least two tracks",
// /* vertical_lines = */ std::set<float>{2.f} );
// make_plots( /* out_name = */ "cut2",
// /* branchexpr = */ "event_cutValue_nUncontained",
// /* selection = */ "passed_min2Tracks",
// /* runs = */ runSet,
// /* bin_low_edges = */ binEdges.at("nUncontained"),
// /* x_axis_label = */ "Number of reconstructed uncontained particles",
// /* y_axis_label = */ "# Events",
// /* title = */ "Generic Cut #2: At most one uncontained",
// /* vertical_lines = */ std::set<float>{2.f} );
// make_plots( /* out_name = */ "cut3",
// /* branchexpr = */ "event_cutValue_nNonProtons",
// /* selection = */ "passed_max1Uncontained",
// /* runs = */ runSet,
// /* bin_low_edges = */ binEdges.at("nNonProtons"),
// /* x_axis_label = */ "Number reconstructed of non-protons",
// /* y_axis_label = */ "# Events",
// /* title = */ "Generic Cut #3: Two non-protons",
// /* vertical_lines = */ std::set<float>{2.f, 3.f} );
// make_plots( /* out_name = */ "cut4",
// /* branchexpr = */ "event_cutValue_pionTruncatedMeandEdx",
// /* selection = */ "passed_2NonProtons",
// /* runs = */ runSet,
// /* bin_low_edges = */ binEdges.at("pionTruncatedMeandEdx"),
// /* x_axis_label = */ "Reconstructed track energy loss, dE/dx / MeV / cm",
// /* y_axis_label = */ "# Events",
// /* title = */ "Generic Cut #4: Pion candidate dE/dx is valid",
// /* vertical_lines = */ std::set<float>{1.0f} );
// make_plots( /* out_name = */ "cut5a",
// /* branchexpr = */ "event_cutValue_pionPhi",
// /* selection = */ "passed_pionHasValiddEdx",
// /* runs = */ runSet,
// /* bin_low_edges = */ binEdges.at("pionPhi"),
// /* x_axis_label = */ "Reconstructed pion azimuthal angle, #phi_{#pi} / rad",
// /* y_axis_label = */ "# Events",
// /* title = */ "Before Generic Cut #5: With pion-candidates in gaps");
// make_plots( /* out_name = */ "cut5b",
// /* branchexpr = */ "event_cutValue_pionPhi",
// /* selection = */ "passed_pionNotInGap",
// /* runs = */ runSet,
// /* bin_low_edges = */ binEdges.at("pionPhi"),
// /* x_axis_label = */ "Reconstructed pion azimuthal angle, #phi_{#pi} / rad",
// /* y_axis_label = */ "# Events",
// /* title = */ "After Generic Cut #5: Without pion-candidates in gaps");
// make_plots( /* out_name = */ "cut6a",
// /* branchexpr = */ "event_cutValue_muonPhi",
// /* selection = */ "passed_pionNotInGap",
// /* runs = */ runSet,
// /* bin_low_edges = */ binEdges.at("muonPhi"),
// /* x_axis_label = */ "Reconstructed muon azimuthal angle, #phi_{#mu} / rad",
// /* y_axis_label = */ "# Events",
// /* title = */ "Before Generic Cut #6: With muon-candidates in gaps");
// make_plots( /* out_name = */ "cut6b",
// /* branchexpr = */ "event_cutValue_muonPhi",
// /* selection = */ "passed_muonNotInGap",
// /* runs = */ runSet,
// /* bin_low_edges = */ binEdges.at("muonPhi"),
// /* x_axis_label = */ "Reconstructed muon azimuthal angle, #phi_{#mu} / rad",
// /* y_axis_label = */ "# Events",
// /* title = */ "After Generic Cut #6: Without muon-candidates in gaps");
// make_plots( /* out_name = */ "cut7",
// /* branchexpr = */ "event_cutValue_topologicalScore",
// /* selection = */ "passed_muonNotInGap",
// /* runs = */ runSet,
// /* bin_low_edges = */ binEdges.at("topologicalScore"),
// /* x_axis_label = */ "Neutrino-vs-cosmic topological score",
// /* y_axis_label = */ "# Events",
// /* title = */ "Generic Cut #7: Topological score",
// /* vertical_lines = */ std::set<float>{0.67f},
// /* xAxisLog = */ false,
// /* yAxisLog = */ true );
// make_plots( /* out_name = */ "cut8",
// /* branchexpr = */ "TMath::Sqrt(event_cutValue_maxVertexDist)",
// /* selection = */ "passed_topologicalScore",
// /* runs = */ runSet,
// /* bin_low_edges = */ binEdges.at("maxVertexDist"),
// /* x_axis_label = */ "Furthest track-start to vertex distance / cm",
// /* y_axis_label = */ "# Events",
// /* title = */ "Generic Cut #8: All tracks start close to neutrino vertex",
// /* vertical_lines = */ std::set<float>{9.5f},
// /* xAxisLog = */ true );
// make_plots( /* out_name = */ "cut9",
// /* branchexpr = */ "event_cutValue_openingAngle",
// /* selection = */ "passed_startNearVertex",
// /* runs = */ runSet,
// /* bin_low_edges = */ binEdges.at("openingAngle"),
// /* x_axis_label = */ "Reconstructed muon-pion opening angle, #theta_{#mu#pi} / rad",
// /* y_axis_label = */ "# Events",
// /* title = */ "Phase Space Cut #1: Cut on opening angle",
// /* vertical_lines = */ std::set<float>{2.65f},
// /* const bool xAxisLog = */ false,
// /* const bool yAxisLog = */ false,
// /* const bool noData = */ true );
// make_plots( /* out_name = */ "cut10",
// /* branchexpr = */ "cc1pi_reco_muonMomentum",
// /* selection = */ "passed_openingAngle",
// /* runs = */ runSet,
// /* bin_low_edges = */ binEdges.at("muonMomentum"),
// /* x_axis_label = */ "Reconstructed muon momentum, p_{#mu} / (GeV / c)",
// /* y_axis_label = */ "# Events",
// /* title = */ "Phase Space Cut #2: Cut on muon momentum",
// /* vertical_lines = */ std::set<float>{0.15f},
// /* xAxisLog = */ false,
// /* yAxisLog = */ false,
// /* noData = */ true );
// make_plots( /* out_name = */ "cut11",
// /* branchexpr = */ "cc1pi_reco_pionMomentum",
// /* selection = */ "passed_openingAngle && cc1pi_reco_muonMomentum > 0.15",
// /* runs = */ runSet,
// /* bin_low_edges = */ binEdges.at("pionMomentum"),
// /* x_axis_label = */ "Reconstructed pion momentum, p_{#pi} / (GeV / c)",
// /* y_axis_label = */ "# Events",
// /* title = */ "Phase Space Cut #3: Cut on pion momentum",
// /* vertical_lines = */ std::set<float>{0.1f},
// /* xAxisLog = */ false,
// /* yAxisLog = */ false,
// /* noData = */ true );
// // make_plots( /* out_name = */ "cut12a",
// // /* branchexpr = */ "cc1pi_reco_muonMomentum",
// // /* selection = */ "passed_openingAngle && cc1pi_reco_muonMomentum > 0.15 && cc1pi_reco_pionMomentum > 0.1",
// // /* runs = */ runSet,
// // /* bin_low_edges = */ binEdges.at("muonMomentum2"),
// // /* x_axis_label = */ "Reconstructed muon momentum, p_{#mu} / (GeV / c)",
// // /* y_axis_label = */ "# Events",
// // /* title = */ "Before Muon Momentum Subset Cut: Contained Muons");
// // make_plots( /* out_name = */ "cut12b",
// // /* branchexpr = */ "cc1pi_reco_muonMomentum",
// // /* selection = */ "passed_openingAngle && cc1pi_reco_muonMomentum > 0.15 && cc1pi_reco_pionMomentum > 0.1 && cc1pi_recoMuon_IsContained",
// // /* runs = */ runSet,
// // /* bin_low_edges = */ binEdges.at("muonMomentum2"),
// // /* x_axis_label = */ "Reconstructed muon momentum, p_{#mu} / (GeV / c)",
// // /* y_axis_label = */ "# Events",
// // /* title = */ "After Muon Momentum Subset Cut: Contained Muons");
make_plots( /* out_name = */ "cut12",
/* branchexpr = */ "event_cutValue_goldenPionBDT",
/* selection = */ "passed_openingAngle && cc1pi_reco_muonMomentum > 0.15 && cc1pi_reco_pionMomentum > 0.1",
/* runs = */ runSet,
/* bin_low_edges = */ binEdges.at("goldenPionBDTScore"),
/* x_axis_label = */ "Golden pion BDT response",
/* y_axis_label = */ "# Events",
/* title = */ "Pion Momentum Subset Cut: Golden-pion BDT",
/* vertical_lines = */ std::set<float>{-0.03f} );
// **************************************************************
// *************** Phase space restriction plots ****************
// make_plots( /* out_name = */ "genericSelection_restrictedPhaseSpace1",
// /* branchexpr = */ "event_cutValue_openingAngle",
// /* selection = */ "passed_startNearVertex",
// /* runs = */ runSet,
// /* bin_low_edges = */ binEdges.at("openingAngle2"),
// /* x_axis_label = */ "Reconstructed #theta_{#mu#pi} / rad",
// /* y_axis_label = */ "# Events",
// /* title = */ "Generic phase space restriction 1: Muon pion opening angle",
// /* vertical_lines = */ std::set<float>{2.65f} );
// make_plots( /* out_name = */ "genericSelection_restrictedPhaseSpace2",
// /* branchexpr = */ "cc1pi_reco_muonMomentum",
// /* selection = */ "passed_startNearVertex && event_cutValue_openingAngle < 2.65",
// /* runs = */ runSet,
// /* bin_low_edges = */ binEdges.at("muonMomentum2"),
// /* x_axis_label = */ "Muon momentum / (GeV / c)",
// /* y_axis_label = */ "# Events",
// /* title = */ "Generic phase space restriction 2: Muon momentum",
// /* vertical_lines = */ std::set<float>{0.15f} );
// make_plots( /* out_name = */ "genericSelection_restrictedPhaseSpace3",
// /* branchexpr = */ "cc1pi_reco_pionMomentum",
// /* selection = */ "passed_startNearVertex && event_cutValue_openingAngle < 2.65 && cc1pi_reco_muonMomentum > 0.15",
// /* runs = */ runSet,
// /* bin_low_edges = */ binEdges.at("pionMomentum2"),
// /* x_axis_label = */ "Pion momentum / GeV (GeV / c)",
// /* y_axis_label = */ "# Events",
// /* title = */ "Generic phase space restriction 3: Pion momentum",
// /* vertical_lines = */ std::set<float>{0.1f} );
// make_plots( /* out_name = */ "goldenSelection_restrictedPhaseSpace1",
// /* branchexpr = */ "event_cutValue_openingAngle",
// /* selection = */ "passed_startNearVertex && event_cutValue_goldenPionBDT > -0.03",
// /* runs = */ runSet,
// /* bin_low_edges = */ binEdges.at("openingAngle"),
// /* x_axis_label = */ "Reconstructed #theta_{#mu#pi} / rad",
// /* y_axis_label = */ "# Events",
// /* title = */ "Golden phase space restriction 1: Muon pion opening angle",
// /* vertical_lines = */ std::set<float>{2.65f} );
// make_plots( /* out_name = */ "goldenSelection_restrictedPhaseSpace2",
// /* branchexpr = */ "cc1pi_reco_muonMomentum",
// /* selection = */ "passed_startNearVertex && event_cutValue_goldenPionBDT > -0.03 && event_cutValue_openingAngle < 2.65",
// /* runs = */ runSet,
// /* bin_low_edges = */ binEdges.at("muonMomentum"),
// /* x_axis_label = */ "Muon momentum / (GeV / c)",
// /* y_axis_label = */ "# Events",
// /* title = */ "Golden phase space restriction 2: Muon momentum",
// /* vertical_lines = */ std::set<float>{0.15f} );
// make_plots( /* out_name = */ "goldenSelection_restrictedPhaseSpace3",
// /* branchexpr = */ "cc1pi_reco_pionMomentum",
// /* selection = */ "passed_startNearVertex && event_cutValue_goldenPionBDT > -0.03 && event_cutValue_openingAngle < 2.65 && cc1pi_reco_muonMomentum > 0.15",
// /* runs = */ runSet,
// /* bin_low_edges = */ binEdges.at("pionMomentum"),
// /* x_axis_label = */ "Pion momentum / GeV (GeV / c)",
// /* y_axis_label = */ "# Events",
// /* title = */ "Golden phase space restriction 3: Pion momentum",
// /* vertical_lines = */ std::set<float>{0.1f} );
// // **************************************************************
// // *************** Modified phase space restriction plots ****************
// make_plots( /* out_name = */ "genericSelection_restrictedPhaseSpace2_containedMuon",
// /* branchexpr = */ "cc1pi_reco_muonMomentum",
// /* selection = */ "passed_startNearVertex && event_cutValue_openingAngle < 2.65 && cc1pi_recoMuon_IsContained",
// /* runs = */ runSet,
// /* bin_low_edges = */ binEdges.at("muonMomentum"),
// /* x_axis_label = */ "Muon momentum / (GeV / c)",
// /* y_axis_label = */ "# Events",
// /* title = */ "Generic phase space restriction 2: Muon momentum",
// /* vertical_lines = */ std::set<float>{0.15f} );
// make_plots( /* out_name = */ "genericSelection_restrictedPhaseSpace2_uncontainedMuon",
// /* branchexpr = */ "cc1pi_reco_muonMomentum",
// /* selection = */ "passed_startNearVertex && event_cutValue_openingAngle < 2.65 && !cc1pi_recoMuon_IsContained",
// /* runs = */ runSet,
// /* bin_low_edges = */ binEdges.at("muonMomentum"),
// /* x_axis_label = */ "Muon momentum / (GeV / c)",
// /* y_axis_label = */ "# Events",
// /* title = */ "Generic phase space restriction 2: Muon momentum",
// /* vertical_lines = */ std::set<float>{0.15f} );
// make_plots( /* out_name = */ "cut11_noData",
// /* branchexpr = */ "cc1pi_reco_pionMomentum",
// /* selection = */ "passed_openingAngle && cc1pi_reco_muonMomentum > 0.15",
// /* runs = */ runSet,
// /* bin_low_edges = */ binEdges.at("pionMomentum"),
// /* x_axis_label = */ "Reconstructed pion momentum, p_{#pi} / (GeV / c)",
// /* y_axis_label = */ "# Events",
// /* title = */ "Phase Space Cut #3: Cut on pion momentum",
// /* vertical_lines = */ std::set<float>{0.1f},
// /* xAxisLog = */ false,
// /* yAxisLog = */ false,
// /* noData = */ true);
// make_plots( /* out_name = */ "cut11_noData_signal_truth",
// /* branchexpr = */ "cc1pi_truth_pionMomentum",
// /* selection = */ "passed_openingAngle && cc1pi_reco_muonMomentum > 0.15",
// /* runs = */ runSet,
// /* bin_low_edges = */ binEdges.at("pionMomentum"),
// /* x_axis_label = */ "True pion momentum, p_{#pi} / (GeV / c)",
// /* y_axis_label = */ "# Events",
// /* title = */ "Phase Space Cut #3: Cut on pion momentum",
// /* vertical_lines = */ std::set<float>{0.1f},
// /* xAxisLog = */ false,
// /* yAxisLog = */ false,
// /* noData = */ true);
// make_plots( /* out_name = */ "cut11_noData_signal_reco",
// /* branchexpr = */ "cc1pi_reco_pionMomentum",
// /* selection = */ "true_cc1pi && passed_openingAngle && cc1pi_reco_muonMomentum > 0.15",
// /* runs = */ runSet,
// /* bin_low_edges = */ binEdges.at("pionMomentum"),
// /* x_axis_label = */ "Reconstructed pion momentum, p_{#pi} / (GeV / c)",
// /* y_axis_label = */ "# Events",
// /* title = */ "Phase Space Cut #3: Cut on pion momentum",
// /* vertical_lines = */ std::set<float>{0.1f},
// /* xAxisLog = */ false,
// /* yAxisLog = */ false,
// /* noData = */ true);
// make_plots( /* out_name = */ "cut00_noData_signal_truth",
// /* branchexpr = */ "cc1pi_truth_pionMomentum",
// /* selection = */ "1",
// /* runs = */ runSet,
// /* bin_low_edges = */ binEdges.at("pionMomentum"),
// /* x_axis_label = */ "True pion momentum, p_{#pi} / (GeV / c)",
// /* y_axis_label = */ "# Events",
// /* title = */ "",
// /* vertical_lines = */ std::set<float>{0.1f},
// /* xAxisLog = */ false,
// /* yAxisLog = */ false,
// /* noData = */ true);
// make_plots( /* out_name = */ "cut11_noData_signal_truth_below100MeVReco",
// /* branchexpr = */ "cc1pi_truth_pionMomentum",
// /* selection = */ "passed_openingAngle && cc1pi_reco_muonMomentum > 0.15 && cc1pi_reco_pionMomentum < 0.1",
// /* runs = */ runSet,
// /* bin_low_edges = */ binEdges.at("pionMomentum"),
// /* x_axis_label = */ "True pion momentum, p_{#pi} / (GeV / c)",
// /* y_axis_label = */ "# Events",
// /* title = */ "Phase Space Cut #3: Cut on pion momentum",
// /* vertical_lines = */ std::set<float>{0.1f},
// /* xAxisLog = */ false,
// /* yAxisLog = */ false,
// /* noData = */ true);
}
}