30int main(
int argc,
char **argv)
34 namespace fs = std::filesystem;
38 fs::path outputFilepath;
39 fs::path candidateNllrListFilepath;
40 size_t duplicatesPerCandidate;
48 zap[
'o'] =
make_field(outputFilepath,
"output file with histograms");
49 zap[
'i'] =
make_field(candidateNllrListFilepath,
"file with list of H2D NLLR files to use, each one an output from JPseudoExperimentCondNLLR");
50 zap[
'n'] =
make_field(duplicatesPerCandidate,
"number of times to duplicate candidates") = 1;
51 zap[
'x'] =
make_field(X,
"x-axis of -log(p) histogram") = histogram_type(80, 0., +8);
56 catch(
const exception& error) {
57 FATAL(error.what() << endl);
63 ifstream file( candidateNllrListFilepath );
67 while (getline(file, line)) {
68 if ( fs::is_regular_file(line) ) {
69 candidateNllrFilepath_vec.push_back(line);
71 cout <<
" Skipping file '" << line <<
"' : it does not exist" << endl;
77 cerr <<
"Unable to open file: " << candidateNllrListFilepath << endl;
79 size_t numberOfCandidates = candidateNllrFilepath_vec.size();
80 size_t numberOfCandidates_eff = numberOfCandidates * duplicatesPerCandidate;
83 size_t nbins_pT = X.getNumberOfBins();
84 size_t min_pT = X.getLowerLimit();
85 size_t max_pT = X.getUpperLimit();
86 TFile outfile(outputFilepath.c_str(),
"recreate");
87 TH1D h1d_pT_rcdf_bestof(
"h1d_pT_rcdf_bestofcandidate",
"Distribution of p_{local} over complete dataset (best 1st period candidate); -log_{10}(p_{local}); Reverse CDF",
88 nbins_pT, min_pT, max_pT);
89 TH1D h1d_pT_rcdf_constr(
"h1d_pT_rcdf_constrcandidate",
"Distribution of p_{local} over complete dataset (best filtered candidate); -log_{10}(p_{local}); Reverse CDF",
90 nbins_pT, min_pT, max_pT);
91 TH1D h1d_pT_trialfactor_bestof(
"h1d_pT_trialfactor_bestofcandidate",
"Trial factor for p_{local} over complete dataset (best 1st period candidate); -log_{10}(p_{local}); Trial factor",
92 nbins_pT, min_pT, max_pT);
93 TH1D h1d_pT_trialfactor_constr(
"h1d_pT_trialfactor_constrcandidate",
"Trial factor for p_{local} over complete dataset (best filtered candidate); -log_{10}(p_{local}); Trial factor",
94 nbins_pT, min_pT, max_pT);
96 for (
size_t pT_bin = 1; pT_bin != nbins_pT+1; ++pT_bin) {
97 h1d_pT_rcdf_bestof.SetBinContent(pT_bin, 0.);
98 h1d_pT_rcdf_constr.SetBinContent(pT_bin, 1.);
103 double numberOfCandidates_constr_eff = 0;
104 cout <<
"Looping over " << numberOfCandidates <<
" candidates, duplicated " << duplicatesPerCandidate <<
" times" << endl;
105 for (
size_t i_cand = 0; i_cand != numberOfCandidates; ++i_cand) {
107 TFile infile( ( candidateNllrFilepath_vec[i_cand] ).c_str(),
"read");
108 TH2D* h2d_nllr = infile.Get<TH2D>(
"h2d_nllr");
109 TH2D* h2d_nllr_constr = infile.Get<TH2D>(
"h2d_nllr_constr");
111 size_t nbins_L1 = h2d_nllr->GetNbinsX();
112 size_t nbins_LT = h2d_nllr->GetNbinsY();
113 TH1D* h1d_LT = h2d_nllr->ProjectionY();
114 h1d_LT->GetXaxis()->SetRange(0,nbins_LT+1);
115 TH1D* h1d_LT_rcdf = (TH1D*) h1d_LT->GetCumulative(
false);
123 TH1D* h1d_L1 = h2d_nllr->ProjectionX();
124 h1d_L1->GetXaxis()->SetRange(0,nbins_L1+1);
125 TH1D* h1d_L1_cdf = (TH1D*) h1d_L1->GetCumulative();
130 for (
size_t L1_bin = 0; L1_bin != nbins_L1+1; ++L1_bin) {
131 TH1D* h1d_LT_L1slice = h2d_nllr->ProjectionY( (
"_py_" + to_string(L1_bin)).c_str(), L1_bin, L1_bin ) ;
132 h1d_LT_cdf_perL1_vec.push_back( (TH1D*) h1d_LT_L1slice->GetCumulative() );
133 h1d_LT_L1slice->Delete();
134 if (h1d_LT_cdf_perL1_vec.back()->GetBinContent(nbins_LT)>0) {
135 h1d_LT_cdf_perL1_vec.back()->Scale(1./h1d_LT_cdf_perL1_vec.back()->GetBinContent(nbins_LT));
140 TGraph gpT_rcdf_bestof_sumcontr;
141 for (
size_t LT_bin = 1; LT_bin != nbins_LT+1; ++LT_bin) {
142 double rcdf_sumcontr = 1./numberOfCandidates - TMath::Power( h1d_L1_cdf->GetBinContent(0),
int(numberOfCandidates_eff) )/numberOfCandidates * h1d_LT_cdf_perL1_vec[0]->GetBinContent(LT_bin-1);
143 for (
size_t L1_bin = 1; L1_bin != nbins_L1+1; ++L1_bin) {
144 rcdf_sumcontr -= ( TMath::Power( h1d_L1_cdf->GetBinContent(L1_bin),
int(numberOfCandidates_eff) ) - TMath::Power( h1d_L1_cdf->GetBinContent(L1_bin-1),
int(numberOfCandidates_eff)) )/numberOfCandidates * h1d_LT_cdf_perL1_vec[L1_bin]->GetBinContent(LT_bin-1) ;
146 double pT = h1d_LT_rcdf->GetBinContent(LT_bin);
147 double neglog10pT = ( pT > 0 ? -TMath::Log10(pT) : 100);
148 gpT_rcdf_bestof_sumcontr.AddPoint( neglog10pT, rcdf_sumcontr );
153 for (
size_t pT_bin = 1; pT_bin != nbins_pT+1; ++pT_bin) {
154 double rcdf_sumcontr = 0;
155 double neglog10pT = h1d_pT_rcdf_bestof.GetBinLowEdge(pT_bin);
157 rcdf_sumcontr = 1./numberOfCandidates;
158 }
else if ( neglog10pT <= gpT_rcdf_bestof_sumcontr.GetPointX(nbins_LT-1) ) {
159 rcdf_sumcontr = gpT_rcdf_bestof_sumcontr.Eval( neglog10pT );
161 h1d_pT_rcdf_bestof.AddBinContent(pT_bin, rcdf_sumcontr);
165 h1d_L1_cdf->Delete();
166 for (
size_t L1_bin = 0; L1_bin != nbins_L1+1; ++L1_bin) {
167 h1d_LT_cdf_perL1_vec[L1_bin]->Delete();
175 TH1D* h1d_LT_constr = h2d_nllr_constr->ProjectionY();
176 h1d_LT_constr->GetXaxis()->SetRange(0,nbins_LT+1);
177 double P_passfilter = h1d_LT_constr->Integral(0, nbins_LT+1);
178 TH1D* h1d_LT_cdf_constr = (TH1D*) h1d_LT_constr->GetCumulative();
179 h1d_LT_cdf_constr->Scale( 1./P_passfilter );
180 h1d_LT_constr->Delete();
181 numberOfCandidates_constr_eff += P_passfilter * duplicatesPerCandidate;
184 TGraph gpT_cdf_constr_prodcontr;
185 for (
size_t LT_bin = 1; LT_bin != nbins_LT+1; ++LT_bin) {
186 double cdf_prodcontr = TMath::Power( (1.-P_passfilter) + P_passfilter * h1d_LT_cdf_constr->GetBinContent(LT_bin-1),
int(duplicatesPerCandidate)) ;
187 double pT = h1d_LT_rcdf->GetBinContent(LT_bin);
188 double neglog10pT = ( pT > 0 ? -TMath::Log10(pT) : 100);
189 gpT_cdf_constr_prodcontr.AddPoint( neglog10pT, cdf_prodcontr );
194 for (
size_t pT_bin = 1; pT_bin != nbins_pT+1; ++pT_bin) {
195 double cdf_prodcontr = 1.;
196 double neglog10pT = h1d_pT_rcdf_constr.GetBinLowEdge(pT_bin);
199 }
else if ( neglog10pT <= gpT_cdf_constr_prodcontr.GetPointX(nbins_LT-1) ) {
200 cdf_prodcontr = gpT_cdf_constr_prodcontr.Eval( neglog10pT );
202 h1d_pT_rcdf_constr.SetBinContent(pT_bin,
203 h1d_pT_rcdf_constr.GetBinContent(pT_bin) * cdf_prodcontr);
207 h1d_LT_cdf_constr->Delete();
210 h2d_nllr_constr->Delete();
217 for (
size_t pT_bin = 1; pT_bin != nbins_pT+1; ++pT_bin) {
218 h1d_pT_rcdf_bestof.SetBinError(pT_bin,0);
219 h1d_pT_rcdf_constr.SetBinContent(pT_bin, 1- h1d_pT_rcdf_constr.GetBinContent(pT_bin) );
220 h1d_pT_rcdf_constr.SetBinError(pT_bin,0);
222 h1d_pT_trialfactor_bestof.SetBinContent(pT_bin, h1d_pT_rcdf_bestof.GetBinContent(pT_bin) / TMath::Power(10, - h1d_pT_rcdf_bestof.GetBinLowEdge(pT_bin) ) );
223 h1d_pT_trialfactor_bestof.SetBinError(pT_bin,0);
224 h1d_pT_trialfactor_constr.SetBinContent(pT_bin, h1d_pT_rcdf_constr.GetBinContent(pT_bin) / TMath::Power(10, - h1d_pT_rcdf_constr.GetBinLowEdge(pT_bin) ) );
225 h1d_pT_trialfactor_constr.SetBinError(pT_bin,0);
227 h1d_pT_rcdf_bestof.SetStats(0);
228 h1d_pT_rcdf_constr.SetStats(0);
229 h1d_pT_trialfactor_bestof.SetStats(0);
230 h1d_pT_trialfactor_constr.SetStats(0);
233 TF1 f1_pT_trialfactor_all(
"f1_pT_trialfactor_allcandidates", (
"(1 - TMath::Power(1-TMath::Power(10,-x), " + to_string(numberOfCandidates_eff) +
" ) ) / TMath::Power(10,-x)" ).c_str(), min_pT, max_pT);
234 TF1 f1_pT_trialfactor_constr(
"f1_pT_trialfactor_constrcandidates", (
"(1 - TMath::Power(1-TMath::Power(10,-x), " + to_string(numberOfCandidates_constr_eff) +
" ) ) / TMath::Power(10,-x)" ).c_str(), min_pT, max_pT);
235 f1_pT_trialfactor_all.SetLineWidth(1);
236 f1_pT_trialfactor_all.SetLineColor(1);
237 f1_pT_trialfactor_constr.SetLineWidth(1);
238 f1_pT_trialfactor_constr.SetLineColor(1);
242 h1d_pT_rcdf_bestof.Write();
243 h1d_pT_rcdf_constr.Write();
244 h1d_pT_trialfactor_bestof.Write();
245 h1d_pT_trialfactor_constr.Write();
246 f1_pT_trialfactor_all.Write();
247 f1_pT_trialfactor_constr.Write();