31 using namespace TopAnalysis;
34 EventSelection::EventSelection(
const std::string&
name,
const std::vector<std::string>& cutNames, TFile*
outputFile,
35 const std::vector<std::unique_ptr<top::ToolLoaderBase> >& toolLoaders,
38 m_cutflow_Loose(nullptr),
39 m_cutflowMCWeights(nullptr),
40 m_cutflowMCWeights_Loose(nullptr),
41 m_cutflowPUWeights(nullptr),
42 m_cutflowPUWeights_Loose(nullptr),
43 m_cutflowMCPUWeights(nullptr),
44 m_cutflowMCPUWeights_Loose(nullptr),
45 m_cutflowScaleFactors(nullptr),
46 m_cutflowScaleFactors_Loose(nullptr),
47 m_cutflowParticleLevel(nullptr),
48 m_cutflowParticleLevelMCWeights(nullptr),
51 m_sfRetriever(nullptr),
52 m_nominalHashValue(0),
53 m_containsInitial(false),
55 m_containsGoodCalo(false),
56 m_containsPrimaryVertex(false),
59 m_positionGoodCalo(0),
60 m_positionPrimaryVertex(0),
77 if (
config->doTightEvents()) {
78 m_cutflow =
new TH1D(
"cutflow", (
name +
" cutflow").c_str(), cutNames.size(), -0.5, cutNames.size() - 0.5);
80 cutNames.size(), -0.5, cutNames.size() - 0.5);
82 cutNames.size(), -0.5, cutNames.size() - 0.5);
84 cutNames.size(), -0.5, cutNames.size() - 0.5);
86 cutNames.size(), -0.5, cutNames.size() - 0.5);
88 if (
config->doLooseEvents()) {
90 cutNames.size(), -0.5, cutNames.size() - 0.5);
92 (
name +
" cutflow_Loose MC weights").c_str(),
93 cutNames.size(), -0.5, cutNames.size() - 0.5);
95 (
name +
" cutflow_Loose PU weights").c_str(),
96 cutNames.size(), -0.5, cutNames.size() - 0.5);
98 (
name +
" cutflow_Loose MC*PU weights").c_str(),
99 cutNames.size(), -0.5, cutNames.size() - 0.5);
101 (
name +
" cutflow_Loose ScaleFactors").c_str(),
102 cutNames.size(), -0.5, cutNames.size() - 0.5);
105 if (
config->doTopParticleLevel()) {
107 (
name +
" cutflow_particle_level").c_str(),
108 cutNames.size(), -0.5, cutNames.size() - 0.5);
110 (
name +
" cutflow_particle_level_mc").c_str(),
111 cutNames.size(), -0.5, cutNames.size() - 0.5);
115 for (
const auto& currentCutName : cutNames) {
118 for (
const auto& libraryPtr : toolLoaders) {
123 if (
tool !=
nullptr) {
126 throw std::runtime_error(
"Could not find " + currentCutName);
130 if (currentCutName ==
"INITIAL") {
135 if (currentCutName ==
"GRL") {
140 if (currentCutName ==
"GOODCALO") {
145 if (currentCutName ==
"PRIVTX") {
151 if (
config->doTightEvents()) {
158 if (
config->doLooseEvents()) {
174 if (currentCutName ==
"SAVE") {
188 m_allCuts(std::move(
other.m_allCuts)),
189 m_cutflow(std::move(
other.m_cutflow)),
190 m_cutflow_Loose(std::move(
other.m_cutflow_Loose)),
191 m_cutflowMCWeights(std::move(
other.m_cutflowMCWeights)),
192 m_cutflowMCWeights_Loose(std::move(
other.m_cutflowMCWeights_Loose)),
193 m_cutflowPUWeights(std::move(
other.m_cutflowPUWeights)),
194 m_cutflowPUWeights_Loose(std::move(
other.m_cutflowPUWeights_Loose)),
195 m_cutflowMCPUWeights(std::move(
other.m_cutflowMCPUWeights)),
196 m_cutflowMCPUWeights_Loose(std::move(
other.m_cutflowMCPUWeights_Loose)),
197 m_cutflowScaleFactors(std::move(
other.m_cutflowScaleFactors)),
198 m_cutflowScaleFactors_Loose(std::move(
other.m_cutflowScaleFactors_Loose)),
199 m_cutflowParticleLevel(std::move(
other.m_cutflowParticleLevel)),
200 m_cutflowParticleLevelMCWeights(std::move(
other.m_cutflowParticleLevelMCWeights)),
201 m_name(std::move(
other.m_name)),
202 m_isMC(std::move(
other.m_isMC)),
203 m_config(std::move(
other.m_config)),
204 m_sfRetriever(nullptr),
205 m_nominalHashValue(std::move(
other.m_nominalHashValue)),
206 m_containsInitial(std::move(
other.m_containsInitial)),
207 m_containsGRL(std::move(
other.m_containsGRL)),
208 m_containsGoodCalo(std::move(
other.m_containsGoodCalo)),
209 m_containsPrimaryVertex(std::move(
other.m_containsPrimaryVertex)),
210 m_positionInitial(std::move(
other.m_positionInitial)),
211 m_positionGRL(std::move(
other.m_positionGRL)),
212 m_positionGoodCalo(std::move(
other.m_positionGoodCalo)),
213 m_positionPrimaryVertex(std::move(
other.m_positionPrimaryVertex)),
214 m_toBeSaved(std::move(
other.m_toBeSaved)) {
223 if (asg::ToolStore::contains<ScaleFactorRetriever>(
"top::ScaleFactorRetriever")) {
224 m_sfRetriever = asg::ToolStore::get<ScaleFactorRetriever>(
"top::ScaleFactorRetriever");
227 top::check(asg::setProperty(topSFR,
"config",
config),
"Failed to set config");
303 bool passEvent(
false);
305 for (
const auto& currentCut :
m_allCuts) {
310 double mcweight = 1.;
311 double puweight = 1.;
312 double leptonSF = 1.;
315 mcweight =
event.m_info->auxdataConst<
float>(
"AnalysisTop_eventWeight");
326 bool countThisCut(
true);
328 countThisCut =
false;
331 countThisCut =
false;
334 countThisCut =
false;
337 countThisCut =
false;
357 passEvent |= (currentCut->name() ==
"SAVE");
380 bool passEvent(
false);
382 for (
const auto& currentCut :
m_allCuts) {
383 const bool passed = currentCut->applyParticleLevel(plEvent);
392 passEvent |= (currentCut->name() ==
"SAVE");
405 msgInfo << std::right;
406 if (
m_isMC) msgInfo << std::fixed << std::setprecision(2);
410 msgInfo <<
" - " <<
m_name <<
" cutflow:\n";
413 msgInfo << std::setw(7) <<
"" <<
414 std::setw(30) <<
"cut" <<
415 std::setw(15) <<
"events";
418 msgInfo << std::setw(15) <<
"mc weights" <<
419 std::setw(15) <<
"mc*pu weights" <<
420 std::setw(15) <<
"lepton SF" <<
421 std::setw(15) <<
"b-tag SF";
424 msgInfo << std::setw(15) <<
"particle level";
428 msgInfo << std::setw(15) <<
"particle level mc";
435 msgInfo <<
" " << std::setw(3) <<
i
436 << std::setw(30) <<
m_cutflow->GetXaxis()->GetBinLabel(
i)
437 << std::setw(15) <<
m_cutflow->GetBinContent(
i);
457 msgInfo <<
" - " <<
m_name <<
" cutflow (Loose):\n";
460 msgInfo << std::setw(7) <<
"" <<
461 std::setw(30) <<
"cut" <<
462 std::setw(15) <<
"events";
465 msgInfo << std::setw(15) <<
"mc weights" <<
466 std::setw(15) <<
"mc*pu weights" <<
467 std::setw(15) <<
"lepton SF" <<
468 std::setw(15) <<
"b-tag SF";
471 msgInfo << std::setw(15) <<
"particle level";
475 msgInfo << std::setw(15) <<
"particle level mc";
482 msgInfo <<
" " << std::setw(3) <<
i
511 std::vector<std::string> configs;
512 for (
const auto& currentCutName :
m_allCuts) {
513 if (currentCutName->name() !=
"FAKESMMCONFIGS")
continue;
516 for (
const std::string&
s :
conf->configurations())
517 configs.push_back(
s);
525 msgInfo <<
"\n - " <<
m_name <<
":\n";
528 msgInfo <<
" " << std::setw(3) <<
i
529 << std::setw(30) <<
m_cutflow->GetXaxis()->GetBinLabel(
i)
532 }
else if (
m_config->doLooseEvents()) {
534 msgInfo <<
" " << std::setw(3) <<
i
539 msgInfo << std::endl;