77 StatusCode writeROOT(
const string&
name,
int type,
float realeff_mean,
float fakeeff_mean,
float eff_spread,
float eff_delta_with_pt);
86 std::map<CP::SystematicVariation, float> &syst_map,
87 std::map<CP::SystematicVariation, float> &syst_err_map,
95 std::map<CP::SystematicVariation, float> &syst_map,
96 std::map<CP::SystematicVariation, float> &syst_poserr_map,
97 std::map<CP::SystematicVariation, float> &syst_negerr_map,
102 StatusCode doMerge
ATLAS_NOT_THREAD_SAFE(
const std::vector<std::string> &
input,
const std::string &
name,
fbtTestToyMC_config &
config,
TH1F* h_lep_pt,
float &lep_pt,
TH1F* h_lep_eta,
float &lep_eta,
TH2F* h_lep_pt_eta,
float &fakes,
float &poserr,
float &negerr,
int icase);
106 double comboProb(
const vector<FakeBkgTools::ParticleData> & leptons_data,
const std::bitset<64> & tights,
const std::bitset<64> &reals) ;
140 config.realeff_mean = 0.90;
141 config.fakeeff_mean = 0.20;
143 config.eff_delta_with_pt = 0.;
147 config.saveFileNameBase =
"saveProgress";
148 config.mergeFileNameBase =
"saveProgress";
149 config.test_merge =
false;
150 config.test_histo =
false;
151 config.test_systematics =
false;
152 config.poisson_fluctuations =
false;
154 config.selection =
">=1T";
155 config.process =
">=1F[T]";
157 if (
config.verbose) cout <<
"maxnbaseline = " <<
config.maxnbaseline << endl;
167 if (
config.verbose) cout <<
"maxnbaseline = " <<
config.maxnbaseline << endl;
171 int nevents_thiscase;
174 TTree *ntuple =
new TTree(
"FakeBkg",
"Variables from toy MC");
175 ntuple->Branch(
"nevents", &nevents_thiscase,
"nevents/I");
177 ntuple->Branch(
"nevents_sel", &nevents_sel,
"nevents_sel/I");
178 Float_t fake_lep_frac;
179 ntuple->Branch(
"fake_lep_frac", &fake_lep_frac,
"fake_lep_frac/F");
181 ntuple->Branch(
"true_fakes", &true_fakes,
"true_fakes/F");
183 ntuple->Branch(
"asm_fakes", &asm_fakes,
"asm_fakes/F");
185 ntuple->Branch(
"asm_err", &asm_err,
"asm_err/F");
187 ntuple->Branch(
"fkf_fakes", &fkf_fakes,
"fkf_fakes/F");
189 ntuple->Branch(
"fkf_err", &fkf_err,
"fkf_err/F");
190 Float_t lhoodMM_fakes;
191 ntuple->Branch(
"lhoodMM_fakes", &lhoodMM_fakes,
"lhoodMM_fakes/F");
192 Float_t lhoodMM_poserr;
193 ntuple->Branch(
"lhoodMM_poserr", &lhoodMM_poserr,
"lhoodMM_poserr/F");
194 Float_t lhoodMM_negerr;
195 ntuple->Branch(
"lhoodMM_negerr", &lhoodMM_negerr,
"lhoodMM_negerr/F");
196 Float_t lhoodFF_fakes;
197 ntuple->Branch(
"lhoodFF_fakes", &lhoodFF_fakes,
"lhoodFF_fakes/F");
198 Float_t lhoodFF_poserr;
199 ntuple->Branch(
"lhoodFF_poserr", &lhoodFF_poserr,
"lhoodFF_poserr/F");
200 Float_t lhoodFF_negerr;
201 ntuple->Branch(
"lhoodFF_negerr", &lhoodFF_negerr,
"lhoodFF_negerr/F");
204 map<CP::SystematicVariation,float> lhoodMM_weight_map, lhoodMM_poserr_map, lhoodMM_negerr_map;
205 map<CP::SystematicVariation,float> lhoodFF_weight_map, lhoodFF_poserr_map, lhoodFF_negerr_map;
206 map<CP::SystematicVariation,float> asm_weight_map, asm_err_map;
207 map<CP::SystematicVariation,float> fkf_weight_map, fkf_err_map;
209 TRandom3
rand(242868252);
211 Double_t realeff_spread =
config.eff_spread;
212 Double_t fakeeff_spread =
config.eff_spread;
214 std::vector<bool> isTight;
215 std::vector<std::string>
input = {
config.outputdirname+
"efficiencies_full" };
225 input.back().append(
".root");
232 for (
unsigned icase(0); icase <
config.ncases; icase++) {
235 TH1F* h_lep_pt_lhoodMM = 0;
236 TH1F* h_lep_eta_lhoodMM = 0;
237 TH2F* h_lep_pt_eta_lhoodMM = 0;
238 TH1F* h_lep_pt_lhoodFF = 0;
239 TH1F* h_lep_eta_lhoodFF = 0;
240 TH2F* h_lep_pt_eta_lhoodFF = 0;
241 TH1F* h_lep_pt_asm = 0;
242 TH1F* h_lep_eta_asm = 0;
243 TH2F* h_lep_pt_eta_asm = 0;
244 TH1F* h_lep_pt_fkf = 0;
245 TH1F* h_lep_eta_fkf = 0;
246 TH2F* h_lep_pt_eta_fkf = 0;
250 h_lep_pt_lhoodMM =
new TH1F(
hname.c_str(),
hname.c_str(), 10, 0, 100);
252 h_lep_eta_lhoodMM =
new TH1F(
hname.c_str(),
hname.c_str(), 10, -5, 5);
254 h_lep_pt_eta_lhoodMM =
new TH2F(
hname.c_str(),
hname.c_str(), 10, 0, 100, 10, -5, 5);
256 h_lep_pt_lhoodFF =
new TH1F(
hname.c_str(),
hname.c_str(), 10, 0, 100);
258 h_lep_eta_lhoodFF =
new TH1F(
hname.c_str(),
hname.c_str(), 10, -5, 5);
260 h_lep_pt_eta_lhoodFF =
new TH2F(
hname.c_str(),
hname.c_str(), 10, 0, 100, 10, -5, 5);
262 h_lep_pt_asm =
new TH1F(
hname.c_str(),
hname.c_str(), 10, 0, 100);
264 h_lep_eta_asm =
new TH1F(
hname.c_str(),
hname.c_str(), 10, -5, 5);
266 h_lep_pt_eta_asm =
new TH2F(
hname.c_str(),
hname.c_str(), 10, 0, 100, 10, -5, 5);
268 h_lep_pt_fkf =
new TH1F(
hname.c_str(),
hname.c_str(), 10, 0, 100);
270 h_lep_eta_fkf =
new TH1F(
hname.c_str(),
hname.c_str(), 10, -5, 5);
272 h_lep_pt_eta_fkf =
new TH2F(
hname.c_str(),
hname.c_str(), 10, 0, 100, 10, -5, 5);
275 float lep_pt, lep_eta;
279 cout <<
"Starting case " << icase << endl;
282 std::vector<CP::LhoodMM_tools*> lhmTool_sav;
284 std::vector<CP::LhoodMM_tools*> lhmTool_FF_sav;
286 std::vector<CP::AsymptMatrixTool*> asmTool_sav;
288 std::vector<CP::ApplyFakeFactor*> fkfTool_sav;
312 ANA_CHECK( lhmTool_FF.setProperty(
"DoFakeFactorFit",
true) );
317 for (
int iSave = 0; iSave <=
nSave; iSave++) {
320 lhmTool_sav.push_back(lhmTool_is);
329 lhmTool_FF_sav.push_back(lhmTool_FF_is);
331 ANA_CHECK( lhmTool_FF_sav[iSave]->setProperty(
"DoFakeFactorFit",
true) );
344 asmTool_sav.push_back(asmTool_is);
349 fkfTool_sav.push_back(fkfTool_is);
360 Double_t realeff_mean_thiscase =
rand.Gaus(
config.realeff_mean, realeff_spread);
361 if (realeff_mean_thiscase > 0.99) realeff_mean_thiscase = 0.99;
362 Double_t fakeeff_mean_thiscase =
rand.Gaus(
config.fakeeff_mean, fakeeff_spread);
363 if (fakeeff_mean_thiscase < 0.01) fakeeff_mean_thiscase = 0.01;
364 if (fakeeff_mean_thiscase > realeff_mean_thiscase) fakeeff_mean_thiscase = realeff_mean_thiscase-0.01;
366 fake_lep_frac =
rand.Uniform();
374 std::vector<LhoodMMEvent> mmevts;
378 std::vector<double> realeff, fakeeff;
380 vector<FinalState*>
fs;
382 for (
unsigned ilep(0); ilep <=
config.maxnbaseline; ilep++) {
385 fs.push_back(this_fs);
388 if (
config.poisson_fluctuations) {
389 nevents_thiscase =
rand.Poisson(
config.nevents);
391 nevents_thiscase =
config.nevents;
398 for (
int pass(0); pass<2; pass++) {
402 int nEventsMultFactor = 1;
403 if (pass > 0) nEventsMultFactor = 10;
404 for (Long64_t ievt(0); ievt<nevents_thiscase*nEventsMultFactor; ievt++) {
406 float nlep_frac = 1./(
config.maxnbaseline-
config.minnbaseline+1);
407 Int_t nlep_select =
config.minnbaseline+
rand.Uniform()/nlep_frac;
409 float extraweight(1.0);
415 vector<FakeBkgTools::ParticleData> leptons_data;
417 vector<bool> lep_real;
420 vector<float> lep_pts;
421 for (
int ilep(0); ilep < nlep_select; ilep++) {
422 lep_pts.push_back(100*
rand.Uniform());
425 sort(lep_pts.begin(), lep_pts.end(), std::greater<float>());
427 for (
int ilep(0); ilep < nlep_select; ilep++) {
431 if (
rand.Uniform() > fake_lep_frac) {
437 lep_real.push_back(isReal);
441 lep_pt = lep_pts[ilep];
442 lep_eta = -5. + 10*
rand.Uniform();
443 lepton->
setP4( 1000*lep_pt, lep_eta, 0, 0.511);
446 ANA_CHECK( lookupEfficiencies(*lepton, lepton_data) );
450 TightAcc(*lepton) =
true;
452 TightAcc(*lepton) =
false;
456 TightAcc(*lepton) =
true;
458 TightAcc(*lepton) =
false;
463 leptons_data.push_back(lepton_data);
472 ANA_CHECK( lhmTool_sav[savIndex]->addEvent(leptons, extraweight) );
473 ANA_CHECK( lhmTool_FF_sav[savIndex]->addEvent(leptons, extraweight) );
474 ANA_CHECK( asmTool_sav[savIndex]->addEvent(leptons, extraweight) );
475 ANA_CHECK( fkfTool_sav[savIndex]->addEvent(leptons, extraweight) );
482 for (
int ilep(0); ilep < nlep_select; ilep++) {
483 if (!lep_real[ilep]) {
490 if (pass == 1 && all_real) {
497 ANA_CHECK( fkfTool_sav[savIndex]->addEvent(leptons, -extraweight/nEventsMultFactor) );
498 ANA_CHECK( lhmTool_FF_sav[savIndex]->addEvent(leptons, -extraweight/nEventsMultFactor) );
504 vector<int> lep_indices;
505 std::bitset<64> tights, reals, charges;
506 for (
int ilep(0); ilep < nlep_select; ilep++) {
507 lep_indices.push_back(ilep);
508 if (lep_real[ilep]) reals.set(ilep);
512 for (
long comb(0); comb < (1<<nlep_select); ++comb) {
513 tights = std::bitset<64>(comb);
514 if (
fs[nlep_select]->accept_selection(tights, charges)) {
515 if (
fs[nlep_select]->accept_process(nlep_select, reals, tights)) {
516 true_fakes += extraweight*
comboProb(leptons_data, tights, reals);
522 for (
int ilep = 0; ilep < nlep_select; ilep++) {
523 if (TightAcc(*leptons[ilep])) tights.set(ilep);
525 if (
fs[nlep_select]->accept_selection(tights,charges) ) {
526 nevents_sel += extraweight;
542 fkfYield -= wgt/nEventsMultFactor;
543 fkfErr += wgt*wgt/(nEventsMultFactor);
549 if (ievt > 0 && (((
nSave*ievt)%nevents_thiscase ==0) || ievt == nevents_thiscase -1) ) {
552 std::unique_ptr<TFile> saveFile(TFile::Open(
saveFileName.c_str(),
"RECREATE"));
553 ANA_CHECK( lhmTool_sav[savIndex]->saveProgress(saveFile->mkdir(
"fakes")) );
557 saveFile = std::make_unique<TFile>(
saveFileName.c_str(),
"RECREATE");
558 ANA_CHECK( asmTool_sav[savIndex]->saveProgress(saveFile.get()) );
564 if (ievt > 0 && (((
nSave*ievt)%(nevents_thiscase*nEventsMultFactor) ==0) || ievt == nevents_thiscase*nEventsMultFactor -1) ) {
568 std::unique_ptr<TFile> saveFile(TFile::Open(
saveFileName.c_str(),
"RECREATE"));
569 ANA_CHECK( lhmTool_FF_sav[savIndex]->saveProgress(saveFile->mkdir(
"fakes")) );
573 saveFile = std::make_unique<TFile>(
saveFileName.c_str(),
"RECREATE");
574 ANA_CHECK( fkfTool_sav[savIndex]->saveProgress(saveFile.get()) );
578 float nfakes_tmp(0), err_tmp(0);
585 if (*
it !=
nullptr)
delete *
it;
590 asm_err = sqrt(asmErr);
591 asm_fakes = asmYield;
601 fkf_fakes = fkfYield;
603 if (
config.test_systematics) {
605 std::string systBrName, systBrNameF;
607 for(
auto& sysvar : sysvars){
610 float asm_syst_weight, asm_syst_err;
611 float fkf_syst_weight, fkf_syst_err;
612 float lhoodMM_syst_weight, lhoodMM_syst_poserr, lhoodMM_syst_negerr;
613 float lhoodFF_syst_weight, lhoodFF_syst_poserr, lhoodFF_syst_negerr;
618 ANA_CHECK(
setupSystBranchesAsym(
"lhoodMM", sysvar, lhoodMM_syst_weight, lhoodMM_syst_poserr, lhoodMM_syst_negerr, lhoodMM_weight_map, lhoodMM_poserr_map, lhoodMM_negerr_map, ntuple) );
619 ANA_CHECK(
setupSystBranchesAsym(
"lhoodFF", sysvar, lhoodFF_syst_weight, lhoodFF_syst_poserr, lhoodFF_syst_negerr, lhoodFF_weight_map, lhoodFF_poserr_map, lhoodFF_negerr_map, ntuple) );
623 asm_err_map.find(sysvar)->second,
624 asm_err_map.find(sysvar)->second));
628 fkf_err_map.find(sysvar)->second,
629 fkf_err_map.find(sysvar)->second) );
632 lhoodMM_poserr_map.find(sysvar)->second,
633 lhoodMM_negerr_map.find(sysvar)->second) );
636 lhoodFF_poserr_map.find(sysvar)->second,
637 lhoodFF_negerr_map.find(sysvar)->second) );
642 cout <<
"OUTPUT true_fakes = " << true_fakes << endl;
643 cout <<
"OUTPUT nfakes for lhoodMM = " << lhoodMM_fakes <<
" +" << lhoodMM_poserr <<
" -" << lhoodMM_negerr << endl;
644 cout <<
"OUTPUT nfakes for lhoodFF = " << lhoodFF_fakes <<
" +" << lhoodFF_poserr <<
" -" << lhoodFF_negerr << endl;
645 cout <<
"OUTPUT nfakes for asm = " << asm_fakes <<
" +- " << asm_err << endl;
646 cout <<
"OUTPUT nfakes for fkf = " << fkf_fakes <<
" +- " << fkf_err << endl;
647 cout <<
"OUTPUT true_fakes = " << true_fakes << endl;
650 ANA_CHECK( doMerge(
input,
"lhm",
config, h_lep_pt_lhoodMM, lep_pt, h_lep_eta_lhoodMM, lep_eta, h_lep_pt_eta_lhoodMM, lhoodMM_fakes, lhoodMM_poserr, lhoodMM_negerr, icase) );
651 ANA_CHECK( doMerge(
input,
"lhf",
config, h_lep_pt_lhoodFF, lep_pt, h_lep_eta_lhoodFF, lep_eta, h_lep_pt_eta_lhoodFF, lhoodFF_fakes, lhoodFF_poserr, lhoodFF_negerr, icase) );
652 ANA_CHECK( doMerge(
input,
"asm",
config, h_lep_pt_asm, lep_pt, h_lep_eta_asm, lep_eta, h_lep_pt_eta_asm, asm_fakes, asm_err, asm_err, icase) );
653 ANA_CHECK( doMerge(
input,
"fkf",
config, h_lep_pt_fkf, lep_pt, h_lep_eta_fkf, lep_eta, h_lep_pt_eta_fkf, fkf_fakes, fkf_err, fkf_err, icase) );
660 h_lep_pt_lhoodMM->Write();
661 h_lep_eta_lhoodMM->Write();
662 h_lep_pt_eta_lhoodMM->Write();
663 h_lep_pt_lhoodFF->Write();
664 h_lep_eta_lhoodFF->Write();
665 h_lep_pt_eta_lhoodFF->Write();
666 h_lep_pt_asm->Write();
667 h_lep_eta_asm->Write();
668 h_lep_pt_eta_asm->Write();
669 h_lep_pt_fkf->Write();
670 h_lep_eta_fkf->Write();
671 h_lep_pt_eta_fkf->Write();
673 delete h_lep_pt_lhoodMM;
674 delete h_lep_eta_lhoodMM;
675 delete h_lep_pt_eta_lhoodMM;
676 delete h_lep_pt_lhoodFF;
677 delete h_lep_eta_lhoodFF;
678 delete h_lep_pt_eta_lhoodFF;
680 delete h_lep_eta_asm;
681 delete h_lep_pt_eta_asm;
683 delete h_lep_eta_fkf;
684 delete h_lep_pt_eta_fkf;
693 return StatusCode::SUCCESS;
697 TRandom3 rnd(235789);
701 std::unique_ptr<TFile>
file(TFile::Open(
name.c_str(),
"RECREATE"));
705 TH1D hElFake(
"FakeEfficiency_el_pt",
"FakeEfficiency_el_pt", nbin, 0., 1.*nbin);
706 TH1D hMuFake(
"FakeEfficiency_mu_pt",
"FakeEfficiency_mu_pt", nbin, 0., 1.*nbin);
707 TH1D hElReal(
"RealEfficiency_el_pt",
"RealEfficiency_el_pt", nbin, 0., 1.*nbin);
708 TH1D hMuReal(
"RealEfficiency_mu_pt",
"RealEfficiency_mu_pt", nbin, 0., 1.*nbin);
710 TH1D hElFake_bigSyst(
"FakeEfficiency_el_pt__bigSyst",
"FakeEfficiency_el_pt__bigSyst", nbin, 0., 1.*nbin);
711 TH1D hElFake_smallSyst(
"FakeEfficiency_el_pt__smallSyst",
"FakeEfficiency_el_pt__smallSyst", nbin, 0., 1.*nbin);
712 TH1D hMuFake_bigSyst(
"FakeEfficiency_mu_pt__bigSyst",
"FakeEfficiency_mu_pt__bigSyst", nbin, 0., 1.*nbin);
713 TH1D hMuFake_smallSyst(
"FakeEfficiency_mu_pt__smallSyst",
"FakeEfficiency_mu_pt__smallSyst", nbin, 0., 1.*nbin);
714 TH1D hElReal_bigSyst(
"RealEfficiency_el_pt__bigSyst",
"RealEfficiency_el_pt__bigSyst", nbin, 0., 1.*nbin);
715 TH1D hMuReal_bigSyst(
"RealEfficiency_mu_pt__bigSyst",
"RealEfficiency_mu_pt__bigSyst", nbin, 0., 1.*nbin);
717 for (
int ibin = 1; ibin <= nbin; ibin++) {
718 Double_t realeff = TMath::Min(rnd.Gaus(realeff_mean, eff_spread)+eff_delta_with_pt*(ibin-nbin/2), 0.99);
719 Double_t fakeeff = TMath::Max(rnd.Gaus(fakeeff_mean, eff_spread)-eff_delta_with_pt*(ibin-nbin/2), 0.01);
721 float minrfdiff = 0.10;
722 if (realeff - fakeeff < minrfdiff) {
723 if (realeff > minrfdiff) {
724 fakeeff = realeff - minrfdiff;
726 realeff = realeff + 0.10;
731 if (realeff < 0 || realeff > 1.) cout <<
"ERROR: Bad real efficiency value: " << realeff << endl;
732 if (fakeeff < 0 || fakeeff > 1.) cout <<
"ERROR: Bad fake efficiency value: " << fakeeff << endl;
733 if ((realeff - fakeeff) < minrfdiff) cout <<
"ERROR: Too small difference between real and fake efficiencies: " << realeff <<
" " << fakeeff << endl;
735 hElFake.SetBinContent(ibin, fakeeff);
736 hElFake.SetBinError(ibin, eff_spread);
738 hMuFake.SetBinContent(ibin, fakeeff);
739 hMuFake.SetBinError(ibin, eff_spread);
741 hElReal.SetBinContent(ibin, realeff);
742 hElReal.SetBinError(ibin, eff_spread);
744 hMuReal.SetBinContent(ibin, realeff);
745 hMuReal.SetBinError(ibin, eff_spread);
748 hElFake_bigSyst.SetBinContent(ibin, 0.20*hElFake.GetBinContent(ibin));
749 hElFake_smallSyst.SetBinContent(ibin, 0.02*hElFake.GetBinContent(ibin));
750 hMuFake_bigSyst.SetBinContent(ibin, 0.20*hMuFake.GetBinContent(ibin));
751 hMuFake_smallSyst.SetBinContent(ibin, 0.02*hMuFake.GetBinContent(ibin));
752 hElReal_bigSyst.SetBinContent(ibin, 0.20*hElReal.GetBinContent(ibin));
753 hMuReal_bigSyst.SetBinContent(ibin, 0.20*hMuReal.GetBinContent(ibin));
762 hElFake_bigSyst.Write();
763 hElReal_bigSyst.Write();
764 hElFake_smallSyst.Write();
765 hMuFake_bigSyst.Write();
766 hMuFake_smallSyst.Write();
767 hMuReal_bigSyst.Write();
770 return StatusCode::SUCCESS;
776 {
"ncases", required_argument, 0,
'c'},
777 {
"nevents", required_argument, 0,
'e'},
778 {
"minnb", required_argument, 0,
'm'},
779 {
"maxnb", required_argument, 0,
'n'},
780 {
"rmean", required_argument, 0,
'r'},
781 {
"fmean", required_argument, 0,
'f'},
782 {
"effsigma", required_argument, 0,
's'},
783 {
"effdeltawithpt", required_argument, 0,
'd'},
784 {
"sel", required_argument, 0,
'l'},
785 {
"proc", required_argument, 0,
'p'},
786 {
"test_save", no_argument, 0,
'S'},
787 {
"test_merge", required_argument, 0,
'M'},
788 {
"test_histo", required_argument, 0,
'H'},
789 {
"test_systematics", no_argument, 0,
'E'},
790 {
"verbose", no_argument, 0,
'v'},
791 {
"poisson", no_argument, 0,
'P'},
792 {
"help", no_argument, 0,
'h'},
800 while ((
c = getopt_long(
argc,
argv,
"c:e:m:n:r:f:s:d:l:p:S:M:HEPvh",
long_options, &longindex)) != -1) {
821 config.selection = optarg;
834 config.saveFileNameBase = optarg;
838 config.mergeFileNameBase = optarg;
844 config.test_systematics =
true;
850 config.poisson_fluctuations =
true;
867 while (
pos != string::npos) {
872 while (
pos != string::npos) {
876 return StatusCode::SUCCESS;
880 string outputdirname;
882 outputdirname =
"FakeBkgTools_toy_MC_nevents_";
884 outputdirname +=
"_ncases_";
886 outputdirname +=
"_minnbaseline_";
888 outputdirname +=
"_maxnbaseline_";
890 outputdirname +=
"_realeff_";
892 outputdirname +=
"_fakeeff_";
894 outputdirname +=
"_effspread_";
896 outputdirname +=
"_selection_";
897 outputdirname +=
config.selection;
898 outputdirname +=
"_process_";
899 outputdirname +=
config.process;
900 if (
config.poisson_fluctuations) {
901 outputdirname +=
"_poisson_";
907 pos = outputdirname.find(
">=");
908 while (
pos != string::npos) {
909 outputdirname.replace(
pos, 2,
"ge");
910 pos = outputdirname.find(
">=");
912 pos = outputdirname.find(
"<=");
913 while (
pos != string::npos) {
914 outputdirname.replace(
pos, 2,
"le");
915 pos = outputdirname.find(
"<=");
917 pos = outputdirname.find(
">");
918 while (
pos != string::npos) {
919 outputdirname.replace(
pos, 1,
"gt");
920 pos = outputdirname.find(
">");
922 pos = outputdirname.find(
"<");
923 while (
pos != string::npos) {
924 outputdirname.replace(
pos, 1,
"lt");
925 pos = outputdirname.find(
"<");
927 pos = outputdirname.find(
"=");
928 while (
pos != string::npos) {
929 outputdirname.replace(
pos, 1,
"eq");
930 pos = outputdirname.find(
"=");
932 pos = outputdirname.find(
",");
933 while (
pos != string::npos) {
934 outputdirname.replace(
pos, 1,
"");
935 pos = outputdirname.find(
",");
937 pos = outputdirname.find(
"[");
938 while (
pos != string::npos) {
939 outputdirname.replace(
pos, 1,
"");
940 pos = outputdirname.find(
"[");
942 pos = outputdirname.find(
"]");
943 while (
pos != string::npos) {
944 outputdirname.replace(
pos, 1,
"");
945 pos = outputdirname.find(
"]");
947 pos = outputdirname.find(
"\"");
948 while (
pos != string::npos) {
949 outputdirname.replace(
pos, 1,
"");
950 pos = outputdirname.find(
"\"");
952 pos = outputdirname.find(
"\\");
953 while (
pos != string::npos) {
954 outputdirname.replace(
pos, 1,
"");
955 pos = outputdirname.find(
"\\");
958 gSystem->mkdir(outputdirname.c_str());
959 rootfilename = outputdirname+
"/output.root";
961 config.outputdirname = outputdirname;
963 std::unique_ptr<TFile> f_out(TFile::Open(rootfilename.c_str(),
"RECREATE"));
982 return StatusCode::SUCCESS;
988 cout <<
"Um, no ROOT file!" << endl;
989 return StatusCode::FAILURE;
1002 if (
h_realeff_e == 0) cout <<
"No real e" << endl;
1003 if (
h_fakeeff_e == 0) cout <<
"No fake e" << endl;
1009 return StatusCode::SUCCESS;
1014 if (
h_realeff_e == 0) cout <<
"No real e" << endl;
1015 if (
h_fakeeff_e == 0) cout <<
"No fake e" << endl;
1025 return StatusCode::SUCCESS;
1028 double comboProb(
const vector<FakeBkgTools::ParticleData> & leptons_data,
const std::bitset<64> & tights,
const std::bitset<64> &reals) {
1031 for (
unsigned ilep = 0; ilep < leptons_data.size(); ilep++) {
1034 prob *= leptons_data[ilep].real_efficiency.nominal;
1036 prob *= leptons_data[ilep].fake_efficiency.nominal;
1040 prob *= (1.-leptons_data[ilep].real_efficiency.nominal);
1042 prob *= (1.-leptons_data[ilep].fake_efficiency.nominal);
1050 double comboProb_FF(
const vector<FakeBkgTools::ParticleData> & leptons_data,
const std::bitset<64> &tights,
const std::bitset<64> & reals) {
1054 for (
unsigned ilep = 0; ilep < leptons_data.size(); ilep++) {
1058 prob *= leptons_data[ilep].fake_efficiency.nominal;
1064 prob *= (1.-leptons_data[ilep].fake_efficiency.nominal);
1068 for (
unsigned ilep = 0; ilep < leptons_data.size(); ilep++) {
1070 float F = leptons_data[ilep].fake_efficiency.nominal/(1-leptons_data[ilep].fake_efficiency.nominal);
1081 std::map<CP::SystematicVariation, float> &syst_map,
1082 std::map<CP::SystematicVariation, float> &syst_err_map,
1084 syst_map.emplace(std::make_pair(sysvar,
weight));
1085 std::string systBrName = baseName;
1086 systBrName = systBrName+
"_fakes_"+sysvar.
name();
1087 std::string systBrNameF = systBrName+
"/F";
1088 ntuple->Branch(systBrName.c_str(), &(syst_map.find(sysvar)->second), systBrNameF.c_str());
1089 syst_err_map.emplace(std::make_pair(sysvar, weight_err));
1090 systBrName = baseName;
1091 systBrName = systBrName+
"_err_"+sysvar.
name();
1092 systBrNameF = systBrName+
"/F";
1093 ntuple->Branch(systBrName.c_str(), &(syst_err_map.find(sysvar)->second), systBrNameF.c_str());
1095 return StatusCode::SUCCESS;
1101 float &weight_poserr,
1102 float &weight_negerr,
1103 std::map<CP::SystematicVariation, float> &syst_map,
1104 std::map<CP::SystematicVariation, float> &syst_poserr_map,
1105 std::map<CP::SystematicVariation, float> &syst_negerr_map,
1107 syst_map.emplace(std::make_pair(sysvar,
weight));
1108 std::string systBrName = baseName;
1109 systBrName = systBrName+
"_fakes_"+sysvar.
name();
1110 std::string systBrNameF = systBrName+
"/F";
1111 ntuple->Branch(systBrName.c_str(), &(syst_map.find(sysvar)->second), systBrNameF.c_str());
1112 syst_poserr_map.emplace(std::make_pair(sysvar, weight_poserr));
1113 systBrName = baseName;
1114 systBrName = systBrName+
"_poserr_"+sysvar.
name();
1115 systBrNameF = systBrName+
"/F";
1116 ntuple->Branch(systBrName.c_str(), &(syst_poserr_map.find(sysvar)->second), systBrNameF.c_str());
1117 syst_negerr_map.emplace(std::make_pair(sysvar, weight_negerr));
1118 systBrName = baseName;
1119 systBrName = systBrName+
"_negerr_"+sysvar.
name();
1120 systBrNameF = systBrName+
"/F";
1121 ntuple->Branch(systBrName.c_str(), &(syst_negerr_map.find(sysvar)->second), systBrNameF.c_str());
1123 return StatusCode::SUCCESS;
1126 StatusCode doMerge
ATLAS_NOT_THREAD_SAFE(
const std::vector<std::string> &
input,
const std::string &
name,
fbtTestToyMC_config &
config,
TH1F* h_lep_pt,
float &lep_pt,
TH1F* h_lep_eta,
float &lep_eta,
TH2F* h_lep_pt_eta,
float &fakes,
float &poserr,
float &negerr,
int icase) {
1129 system(haddcmd.c_str());
1131 std::unique_ptr<CP::BaseFakeBkgTool>
tool;
1133 if (
name ==
"lhm" ||
name ==
"lhf") {
1134 std::string toolName =
"Lhood";
1135 if (
name ==
"lhm") {
1140 toolName +=
to_string(icase)+
"_tools_merge";
1141 tool = std::make_unique<CP::LhoodMM_tools>(toolName);
1142 if (
name ==
"lhf") {
1145 ANA_CHECK(
tool->setProperty(
"ProgressFileDirectory",
"fakes") );
1146 }
else if (
name ==
"asm") {
1147 tool = std::make_unique<CP::AsymptMatrixTool>(
"asm_tool_merge");
1148 }
else if (
name ==
"fkf") {
1149 tool = std::make_unique<CP::ApplyFakeFactor>(
"fkf_tool_merge");
1152 std::string mergeFileName =
config.mergeFileNameBase+
"_"+
name+
"_"+
to_string(icase)+
".root";
1153 std::cout << mergeFileName << std::endl;
1154 ANA_CHECK(
tool->setProperty(
"ProgressFileName", mergeFileName) );
1158 ANA_CHECK(
tool->register1DHistogram(h_lep_eta, &lep_eta) );
1159 ANA_CHECK(
tool->register2DHistogram(h_lep_pt_eta, &lep_pt, &lep_eta) );
1164 return StatusCode::SUCCESS;
1168 std::cout << std::endl <<
"fbtTestToyMC provides a toy MC model of a set of pseudoexperiments. It is intended to explore the statistical properties of the fake lepton background estimate for a given set of experiemental conditions (number of events, number of leptons required, typical values of the real and fake efficiencies, etc.)" << std::endl << std::endl;
1169 std::cout <<
"Options: " << std::endl;
1170 std::cout <<
" --ncases, -c: number of pseudoexperiments to run (default: 100)" << std::endl;
1171 std::cout <<
" --nevents, -e: number of events in each pseudoexperiment (default: 100)" << std::endl;
1172 std::cout <<
" --poisson, -P: use Poisson-distributed number of events in each pseudoexperiment, rather than a fixed number (default: false)" << std::endl;
1173 std::cout <<
" --minnb, -m: minimum number of baseline leptons per event (default: 1)" << std::endl;
1174 std::cout <<
" --maxnb, -m: maximum number of baseline leptons per event (default: 4)" << std::endl;
1175 std::cout <<
" --rmean, -r: average real lepton efficiency (default: 0.9)" << std::endl;
1176 std::cout <<
" --fmean, -f: average fake lepton efficiency (default: 0.2)" << std::endl;
1177 std::cout <<
" --effsigma, -s: standard deviation for lepton-to-lepton variation in real and fake efficiencies (default: 0.10)" << std::endl;
1178 std::cout <<
" --effdeltawithpt, -d: rate at which the real (fake) efficiency increases (decreases) with simulated pt. Note that the simulated pt range is 0 to 100" << std::endl;
1179 std::cout <<
" --sel, -l: selection string to be used by the tools (default \" >= 1T\") " << std::endl;
1180 std::cout <<
" --proc, -p: process string to be used by the tools (default \" >= 1F[T]\") " << std::endl;
1181 std::cout <<
" --test_save, -S: save output from subjobs in each pseudoexperiement. If set, requires an argument to specify the base name of the root files where the output will be saved. (default: false) " << std::endl;
1182 std::cout <<
" --test_merge, -M: merge output from subjobs in each pseudoexperiement. If set, requires an argument to specify the base name of the root files to be merged. This should match the base name used in a previous run with the --test_save option (default: false) " << std::endl;
1183 std::cout <<
" --test_histo, -H: test the filling of 1- and 2-dimensional histograms (default: false) " << std::endl;
1184 std::cout <<
" --test_systematics, -E: test the handling of systematic unceratinties (default: false) " << std::endl;
1185 std::cout <<
" --verbose, -v: enable verbose output (default: false) " << std::endl;
1186 std::cout <<
" --help, -h: print this help message" << std::endl;
1187 return StatusCode::SUCCESS;;