forked from uboone/xsec_analyzer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestWeights.C
85 lines (72 loc) · 6.07 KB
/
TestWeights.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
#include <map>
#include <string>
void TestWeights()
{
const std::string rootPath = "/pnfs/uboone/persistent/users/jdetje/ubcc1piPelee/22Feb24/";
// List of files; tuple: file type, run, path, fileWeight
const std::vector<std::tuple<std::string, std::string, std::string, float>> files = {
// std::make_tuple("beam on", "1", rootPath + "bnb_beam_on_peleeTuple_uboone_v08_00_00_70_run1_C1_ubcc1pi.root", 1.f),
// std::make_tuple("beam on", "2", rootPath + "bnb_beam_on_peleeTuple_uboone_v08_00_00_70_run2_ubcc1pi.root", 1.f),
// std::make_tuple("beam on", "3", rootPath + "bnb_beam_on_peleeTuple_uboone_v08_00_00_70_run3_ubcc1pi.root", 1.f),
// std::make_tuple("beam on", "4bcd", rootPath + "bnb_beam_on_peleeTuple_uboone_run4bcd_ubcc1pi.root", 1.f),
// std::make_tuple("beam on", "5", rootPath + "bnb_beam_on_peleeTuple_uboone_v08_00_00_75_run5_ubcc1pi.root", 1.f),
// std::make_tuple("beam off", "1", rootPath + "bnb_beam_off_peleeTuple_uboone_v08_00_00_70_run1_ubcc1pi.root", 0.56421),
// std::make_tuple("beam off", "2", rootPath + "bnb_beam_off_peleeTuple_uboone_v08_00_00_70_run2_ubcc1pi.root", 0.40202),
// std::make_tuple("beam off", "3", rootPath + "bnb_beam_off_peleeTuple_uboone_v08_00_00_70_run3_ubcc1pi.root", 0.30657),
// std::make_tuple("beam off", "4bcd", rootPath + "bnb_beam_off_peleeTuple_uboone_run4bcd_ubcc1pi.root", 0.30175),
// std::make_tuple("beam off", "5", rootPath + "bnb_beam_off_peleeTuple_uboone_v08_00_00_72_run5_ubcc1pi.root", 0.32807),
// std::make_tuple("nu mc", "1", rootPath + "overlay_peleeTuple_uboone_v08_00_00_70_run1_nu_ubcc1pi.root", 0.13011),
// std::make_tuple("nu mc", "2", rootPath + "overlay_peleeTuple_uboone_v08_00_00_70_run2_nu_ubcc1pi.root", 0.25750),
// std::make_tuple("nu mc", "3", rootPath + "overlay_peleeTuple_uboone_v08_00_00_70_run3_nu_ubcc1pi.root", 0.20113),
// std::make_tuple("nu mc", "4bcd", rootPath + "overlay_peleeTuple_uboone_run4bcd_nu_ubcc1pi.root", 0.13074),
// std::make_tuple("nu mc", "5", rootPath + "overlay_nu_peleeTuple_uboone_v08_00_00_73_weightFix_run5_ubcc1pi.root", 0.15196),
std::make_tuple("nu mc", "1", "/exp/uboone/data/users/jdetje/ubcc1piPelee/27March24_pionMomThreshold/overlay_peleeTuple_uboone_v08_00_00_70_run1_nu_ubcc1pi_only_testing.root", 0.13011*2.0), // Times two because the scaling is for the full MC and this is only half
std::make_tuple("nu mc", "2", "/exp/uboone/data/users/jdetje/ubcc1piPelee/27March24_pionMomThreshold/overlay_peleeTuple_uboone_v08_00_00_70_run2_nu_ubcc1pi_only_testing.root", 0.25750*2.0),
// std::make_tuple("nu mc", "3", "/exp/uboone/data/users/jdetje/ubcc1piPelee/27March24_pionMomThreshold/overlay_peleeTuple_uboone_v08_00_00_70_run3_nu_ubcc1pi_only_testing.root", 0.20113*2.0),
// std::make_tuple("nu mc", "4bcd", "/exp/uboone/data/users/jdetje/ubcc1piPelee/27March24_pionMomThreshold/overlay_peleeTuple_uboone_run4bcd_nu_ubcc1pi_only_testing.root", 0.13074*2.0),
// std::make_tuple("nu mc", "5", "/exp/uboone/data/users/jdetje/ubcc1piPelee/27March24_pionMomThreshold/overlay_nu_peleeTuple_uboone_v08_00_00_73_weightFix_run5_ubcc1pi_only_testing.root", 0.15196*2.0),
std::make_tuple("dirt mc", "1", rootPath + "overlay_peleeTuple_uboone_v08_00_00_70_run1_dirt_ubcc1pi.root", 0.52806),
std::make_tuple("dirt mc", "2", rootPath + "overlay_peleeTuple_uboone_v08_00_00_70_run2_dirt_ubcc1pi.root", 0.27521),
// std::make_tuple("dirt mc", "3", rootPath + "overlay_peleeTuple_uboone_v08_00_00_70_run3_dirt_ubcc1pi.root", 0.80892),
// std::make_tuple("dirt mc", "4bcd", rootPath + "overlay_peleeTuple_uboone_run4bcd_dirt_ubcc1pi.root", 0.39701),
// std::make_tuple("dirt mc", "5", rootPath + "overlay_peleeTuple_uboone_v08_00_00_70_run5_dirt_ubcc1pi.root", 0.41280),
};
for (const auto &[fileType, run, path, fileWeight] : files)
{
std::cout << "Processing file " << path <<std::endl;
// const auto weight = weights.at(f);
// std::cout << "Processing file " << path << " with weight " << weight << std::endl;
// Open the file and get the tree
TFile* tFile = TFile::Open(path.c_str());
TTree* tree = (TTree*)tFile->Get("stv_tree");
const std::string eventType = (fileType == "beam on") ? "bnb" : "mc";
const std::string weightString = "(std::isfinite(spline_weight*tuned_cv_weight) && spline_weight*tuned_cv_weight >= 0 && spline_weight*tuned_cv_weight <= 30 ? spline_weight*tuned_cv_weight : 1)*" + std::to_string(fileWeight);
// Define variables to hold branch values
Float_t spline_weight, tuned_cv_weight;
Bool_t isTrueCC1pi, isTrueGoldenPion;
// Set branch addresses
tree->SetBranchAddress("spline_weight", &spline_weight);
tree->SetBranchAddress("tuned_cv_weight", &tuned_cv_weight);
tree->SetBranchAddress("true_cc1pi", &isTrueCC1pi);
// std::cout << "\033[1;31mWARNING - Only processing 20% of events!!!\033[0m" << std::endl;
const auto nEntries = tree->GetEntries();
double largestWeight = 0;
double largestWeightUnder30 = 0;
std::vector<int> weightHistogram(10, 0);
for (Long64_t i = 0; i < nEntries; i++)
{
tree->GetEntry(i);
double weight = std::isfinite(spline_weight*tuned_cv_weight) ? spline_weight*tuned_cv_weight : 1;
if (weight > largestWeight) largestWeight = weight;
if (weight > largestWeightUnder30 && weight < 30) largestWeightUnder30 = weight;
weightHistogram[std::min(int(weight/5), 9)] += 1;
} // End of loop over events
std::cout << "Largest weight: " << largestWeight << " and largest weight under 30: " << largestWeightUnder30 << std::endl;
for (size_t i = 0; i < weightHistogram.size(); i++)
{
std::cout << "Weight sum in range " << i*5 << " to " << (i+1)*5 << ": " << weightHistogram[i] << std::endl;
}
// Close the file
tFile->Close();
} // End of loop over files
} // End of function SelectionTable