Commit 79002160 authored by Nils Krumnack's avatar Nils Krumnack
Browse files

switch to using SysListHandle::systematicsVector() instead of for-each

On request of @jburr to make this easier to understand and teach for
beginners.  Note that this involved a fair amount of whitespace
changes to make the for-body indentation consistent with the rest of
each file.
parent 0d09afed
......@@ -43,7 +43,7 @@ StatusCode AsgClassificationDecorationAlg::initialize()
StatusCode AsgClassificationDecorationAlg::execute()
{
return m_systematicsList.foreach ([&](const CP::SystematicSet &sys) -> StatusCode
for (const auto& sys : m_systematicsList.systematicsVector())
{
xAOD::IParticleContainer *particles{};
ANA_CHECK(m_particlesHandle.getCopy(particles, sys));
......@@ -53,9 +53,8 @@ StatusCode AsgClassificationDecorationAlg::execute()
ANA_CHECK(m_tool->classify(*particle, classification));
(*m_classificationAccessor)(*particle) = classification;
}
return StatusCode::SUCCESS;
});
}
return StatusCode::SUCCESS;
}
} // namespace CP
......@@ -52,7 +52,8 @@ namespace CP
StatusCode AsgEventScaleFactorAlg ::
execute ()
{
return m_systematicsList.foreach ([&] (const CP::SystematicSet& sys) -> StatusCode {
for (const auto& sys : m_systematicsList.systematicsVector())
{
const xAOD::EventInfo *eventInfo = nullptr;
ANA_CHECK (m_eventInfoHandle.retrieve (eventInfo, sys));
......@@ -69,8 +70,8 @@ namespace CP
}
m_scaleFactorOutputDecoration.set (*eventInfo, scaleFactor, sys);
}
return StatusCode::SUCCESS;
});
return StatusCode::SUCCESS;
}
}
......@@ -114,81 +114,83 @@ namespace CP
}
}
return m_systematicsList.foreach ([&] (const CP::SystematicSet& sys) -> StatusCode {
xAOD::IParticleContainer *particles = nullptr;
ANA_CHECK (m_particlesHandle.getCopy (particles, sys));
for (xAOD::IParticle *particle : *particles)
for (const auto& sys : m_systematicsList.systematicsVector())
{
xAOD::IParticleContainer *particles = nullptr;
ANA_CHECK (m_particlesHandle.getCopy (particles, sys));
for (xAOD::IParticle *particle : *particles)
{
asg::AcceptData acceptData (&m_accept);
if (m_preselection.getBool (*particle))
{
asg::AcceptData acceptData (&m_accept);
std::size_t cutIndex {0};
const xAOD::TrackParticle *track {nullptr};
if (const xAOD::Muon *muon = dynamic_cast<xAOD::Muon*>(particle))
track = muon->primaryTrackParticle();
else if (const xAOD::Electron *electron = dynamic_cast<xAOD::Electron*>(particle))
track = electron->trackParticle();
else
{
ANA_MSG_ERROR ("failed to cast input to electron or muon");
return StatusCode::FAILURE;
}
if (m_preselection.getBool (*particle))
acceptData.setCutResult (cutIndex ++, track != nullptr);
if (track != nullptr)
{
std::size_t cutIndex {0};
const xAOD::TrackParticle *track {nullptr};
if (const xAOD::Muon *muon = dynamic_cast<xAOD::Muon*>(particle))
track = muon->primaryTrackParticle();
else if (const xAOD::Electron *electron = dynamic_cast<xAOD::Electron*>(particle))
track = electron->trackParticle();
else
if (m_maxD0Significance > 0)
{
ANA_MSG_ERROR ("failed to cast input to electron or muon");
return StatusCode::FAILURE;
try
{
const float d0sig = xAOD::TrackingHelpers::d0significance
(track, eventInfo->beamPosSigmaX(), eventInfo->beamPosSigmaY(),
eventInfo->beamPosSigmaXY());
acceptData.setCutResult (cutIndex ++, fabs( d0sig ) < m_maxD0Significance);
} catch (const std::runtime_error &) {
acceptData.setCutResult (cutIndex ++, false);
}
}
acceptData.setCutResult (cutIndex ++, track != nullptr);
if (track != nullptr)
if (m_maxDeltaZ0SinTheta > 0)
{
if (m_maxD0Significance > 0)
{
try
{
const float d0sig = xAOD::TrackingHelpers::d0significance
(track, eventInfo->beamPosSigmaX(), eventInfo->beamPosSigmaY(),
eventInfo->beamPosSigmaXY());
acceptData.setCutResult (cutIndex ++, fabs( d0sig ) < m_maxD0Significance);
} catch (const std::runtime_error &) {
acceptData.setCutResult (cutIndex ++, false);
}
const double vertex_z = primaryVertex ? primaryVertex->z() : 0;
const float deltaZ0SinTheta
= (track->z0() + track->vz() - vertex_z) * sin (particle->p4().Theta());
acceptData.setCutResult (cutIndex ++, fabs (deltaZ0SinTheta) < m_maxDeltaZ0SinTheta);
}
if (m_nMinPixelHits != -1 || m_nMaxPixelHits != -1) {
uint8_t nPixelHits;
track->summaryValue(nPixelHits, xAOD::numberOfPixelHits);
bool accept = true;
if(m_nMinPixelHits != -1) {
accept &= nPixelHits >= m_nMinPixelHits;
}
if (m_maxDeltaZ0SinTheta > 0)
{
const double vertex_z = primaryVertex ? primaryVertex->z() : 0;
const float deltaZ0SinTheta
= (track->z0() + track->vz() - vertex_z) * sin (particle->p4().Theta());
acceptData.setCutResult (cutIndex ++, fabs (deltaZ0SinTheta) < m_maxDeltaZ0SinTheta);
if(m_nMaxPixelHits != -1) {
accept &= nPixelHits <= m_nMaxPixelHits;
}
if (m_nMinPixelHits != -1 || m_nMaxPixelHits != -1) {
uint8_t nPixelHits;
track->summaryValue(nPixelHits, xAOD::numberOfPixelHits);
bool accept = true;
if(m_nMinPixelHits != -1) {
accept &= nPixelHits >= m_nMinPixelHits;
}
if(m_nMaxPixelHits != -1) {
accept &= nPixelHits <= m_nMaxPixelHits;
}
acceptData.setCutResult (cutIndex++, accept);
acceptData.setCutResult (cutIndex++, accept);
}
if (m_nMinSCTHits != -1 || m_nMaxSCTHits != -1) {
uint8_t nSCTHits;
track->summaryValue(nSCTHits, xAOD::numberOfSCTHits);
bool accept = true;
if(m_nMinSCTHits != -1) {
accept &= nSCTHits >= m_nMinSCTHits;
}
if (m_nMinSCTHits != -1 || m_nMaxSCTHits != -1) {
uint8_t nSCTHits;
track->summaryValue(nSCTHits, xAOD::numberOfSCTHits);
bool accept = true;
if(m_nMinSCTHits != -1) {
accept &= nSCTHits >= m_nMinSCTHits;
}
if(m_nMaxSCTHits != -1) {
accept &= nSCTHits <= m_nMaxSCTHits;
}
acceptData.setCutResult (cutIndex++, accept);
if(m_nMaxSCTHits != -1) {
accept &= nSCTHits <= m_nMaxSCTHits;
}
acceptData.setCutResult (cutIndex++, accept);
}
}
m_selectionAccessor->setBits
(*particle, selectionFromAccept (acceptData));
}
return StatusCode::SUCCESS;
});
m_selectionAccessor->setBits
(*particle, selectionFromAccept (acceptData));
}
}
return StatusCode::SUCCESS;
}
}
......@@ -46,7 +46,8 @@ namespace CP
StatusCode AsgOriginalObjectLinkAlg ::
execute ()
{
return m_systematicsList.foreach ([&] (const CP::SystematicSet& sys) -> StatusCode {
for (const auto& sys : m_systematicsList.systematicsVector())
{
xAOD::IParticleContainer *particles = nullptr;
ANA_CHECK (m_particleHandle.getCopy (particles, sys));
......@@ -58,8 +59,8 @@ namespace CP
ATH_MSG_ERROR ("Cannot set original object links for container named " << m_baseContainerName);
return StatusCode::FAILURE;
}
}
return StatusCode::SUCCESS;
});
return StatusCode::SUCCESS;
}
}
......@@ -65,25 +65,27 @@ namespace CP
StatusCode AsgSelectionAlg ::
execute ()
{
return m_systematicsList.foreach ([&] (const CP::SystematicSet& sys) -> StatusCode {
if (m_systematicsTool)
ANA_CHECK (m_systematicsTool->applySystematicVariation (sys));
xAOD::IParticleContainer *particles = nullptr;
ANA_CHECK (m_particlesHandle.getCopy (particles, sys));
for (xAOD::IParticle *particle : *particles)
for (const auto& sys : m_systematicsList.systematicsVector())
{
if (m_systematicsTool)
ANA_CHECK (m_systematicsTool->applySystematicVariation (sys));
xAOD::IParticleContainer *particles = nullptr;
ANA_CHECK (m_particlesHandle.getCopy (particles, sys));
for (xAOD::IParticle *particle : *particles)
{
if (m_preselection.getBool (*particle))
{
m_selectionAccessor->setBits
(*particle, selectionFromAccept (m_selectionTool->accept (particle)));
}
else
{
if (m_preselection.getBool (*particle))
{
m_selectionAccessor->setBits
(*particle, selectionFromAccept (m_selectionTool->accept (particle)));
}
else
{
m_selectionAccessor->setBits(*particle, m_setOnFail);
}
m_selectionAccessor->setBits(*particle, m_setOnFail);
}
return StatusCode::SUCCESS;
});
}
}
return StatusCode::SUCCESS;
}
}
......@@ -223,7 +223,10 @@ namespace CP
StatusCode AsgViewFromSelectionAlg ::
execute ()
{
return m_systematicsList.foreach ([&] (const CP::SystematicSet& sys) -> StatusCode {
return (this->*m_function) (sys);});
for (const auto& sys : m_systematicsList.systematicsVector())
{
ANA_CHECK ((this->*m_function) (sys));
}
return StatusCode::SUCCESS;
}
}
......@@ -38,7 +38,8 @@ StatusCode EventSelectionByObjectFlagAlg ::execute() {
SysFilterReporterCombiner filterCombiner (m_filterParams, true);
// loop over systematics
return m_systematicsList.foreach ([&](const CP::SystematicSet &sys) -> StatusCode {
for (const auto& sys : m_systematicsList.systematicsVector())
{
SysFilterReporter filter (filterCombiner, sys);
// particle container
......@@ -55,9 +56,9 @@ StatusCode EventSelectionByObjectFlagAlg ::execute() {
}
}
}
}
return StatusCode::SUCCESS;
});
return StatusCode::SUCCESS;
}
StatusCode EventSelectionByObjectFlagAlg ::finalize() {
......
......@@ -45,22 +45,23 @@ namespace CP
StatusCode IsolationCloseByCorrectionAlg ::
execute ()
{
return m_systematicsList.foreach ([&] (const CP::SystematicSet& sys) -> StatusCode {
xAOD::ElectronContainer *electrons {nullptr};
if (m_electronsHandle)
ANA_CHECK (m_electronsHandle.getCopy (electrons, sys));
xAOD::MuonContainer *muons {nullptr};
if (m_muonsHandle)
ANA_CHECK (m_muonsHandle.getCopy (muons, sys));
xAOD::PhotonContainer *photons {nullptr};
if (m_photonsHandle)
ANA_CHECK (m_photonsHandle.getCopy (photons, sys));
for (const auto& sys : m_systematicsList.systematicsVector())
{
xAOD::ElectronContainer *electrons {nullptr};
if (m_electronsHandle)
ANA_CHECK (m_electronsHandle.getCopy (electrons, sys));
xAOD::MuonContainer *muons {nullptr};
if (m_muonsHandle)
ANA_CHECK (m_muonsHandle.getCopy (muons, sys));
xAOD::PhotonContainer *photons {nullptr};
if (m_photonsHandle)
ANA_CHECK (m_photonsHandle.getCopy (photons, sys));
ANA_CHECK_CORRECTION_EVENT
(m_outOfValidity, m_isolationCorrectionTool->getCloseByIsoCorrection
(electrons, muons, photons, m_topoEtConeModel));
ANA_CHECK_CORRECTION_EVENT
(m_outOfValidity, m_isolationCorrectionTool->getCloseByIsoCorrection
(electrons, muons, photons, m_topoEtConeModel));
}
return StatusCode::SUCCESS;
});
return StatusCode::SUCCESS;
}
}
......@@ -44,67 +44,67 @@ namespace CP
StatusCode KinematicHistAlg ::
execute ()
{
return m_systematicsList.foreach ([&] (const CP::SystematicSet& sys) -> StatusCode {
const xAOD::IParticleContainer *input = nullptr;
ANA_CHECK (m_inputHandle.retrieve (input, sys));
auto histIter = m_hist.find (sys);
if (histIter == m_hist.end())
for (const auto& sys : m_systematicsList.systematicsVector())
{
const xAOD::IParticleContainer *input = nullptr;
ANA_CHECK (m_inputHandle.retrieve (input, sys));
auto histIter = m_hist.find (sys);
if (histIter == m_hist.end())
{
std::string name;
HistGroup group;
name = RCU::substitute (m_histPattern, "%VAR%", "multiplicity");
ANA_CHECK (m_systematicsList.service().makeSystematicsName (name, name, sys));
ANA_CHECK (book (TH1F (name.c_str(), "multiplicity", 20, 0, 20)));
group.multiplicity = hist (name);
m_hist.insert (std::make_pair (sys, group));
histIter = m_hist.find (sys);
assert (histIter != m_hist.end());
}
std::size_t count = 0;
for (std::size_t iter = 0; iter != input->size(); ++ iter)
{
const xAOD::IParticle *particle = (*input)[iter];
if (m_preselection.getBool (*particle))
{
std::string name;
HistGroup group;
while (histIter->second.perObject.size() <= count)
{
std::string name;
HistSubgroup group;
name = RCU::substitute (m_histPattern, "%VAR%", "multiplicity");
ANA_CHECK (m_systematicsList.service().makeSystematicsName (name, name, sys));
ANA_CHECK (book (TH1F (name.c_str(), "multiplicity", 20, 0, 20)));
group.multiplicity = hist (name);
name = RCU::substitute (m_histPattern, "%VAR%", "pt" + std::to_string(histIter->second.perObject.size()));
ANA_CHECK (m_systematicsList.service().makeSystematicsName (name, name, sys));
ANA_CHECK (book (TH1F (name.c_str(), "pt", 20, 0, 200e3)));
group.pt = hist (name);
m_hist.insert (std::make_pair (sys, group));
histIter = m_hist.find (sys);
assert (histIter != m_hist.end());
}
name = RCU::substitute (m_histPattern, "%VAR%", "eta" + std::to_string(histIter->second.perObject.size()));
ANA_CHECK (m_systematicsList.service().makeSystematicsName (name, name, sys));
ANA_CHECK (book (TH1F (name.c_str(), "eta", 20, -5, 5)));
group.eta = hist (name);
std::size_t count = 0;
for (std::size_t iter = 0; iter != input->size(); ++ iter)
{
const xAOD::IParticle *particle = (*input)[iter];
if (m_preselection.getBool (*particle))
{
while (histIter->second.perObject.size() <= count)
{
std::string name;
HistSubgroup group;
name = RCU::substitute (m_histPattern, "%VAR%", "pt" + std::to_string(histIter->second.perObject.size()));
ANA_CHECK (m_systematicsList.service().makeSystematicsName (name, name, sys));
ANA_CHECK (book (TH1F (name.c_str(), "pt", 20, 0, 200e3)));
group.pt = hist (name);
name = RCU::substitute (m_histPattern, "%VAR%", "eta" + std::to_string(histIter->second.perObject.size()));
ANA_CHECK (m_systematicsList.service().makeSystematicsName (name, name, sys));
ANA_CHECK (book (TH1F (name.c_str(), "eta", 20, -5, 5)));
group.eta = hist (name);
name = RCU::substitute (m_histPattern, "%VAR%", "phi" + std::to_string(histIter->second.perObject.size()));
ANA_CHECK (m_systematicsList.service().makeSystematicsName (name, name, sys));
ANA_CHECK (book (TH1F (name.c_str(), "phi", 20, -M_PI, M_PI)));
group.phi = hist (name);
histIter->second.perObject.push_back (group);
}
HistSubgroup& group = histIter->second.perObject[count];
group.pt->Fill (particle->pt());
group.eta->Fill (particle->eta());
group.phi->Fill (particle->phi());
count += 1;
name = RCU::substitute (m_histPattern, "%VAR%", "phi" + std::to_string(histIter->second.perObject.size()));
ANA_CHECK (m_systematicsList.service().makeSystematicsName (name, name, sys));
ANA_CHECK (book (TH1F (name.c_str(), "phi", 20, -M_PI, M_PI)));
group.phi = hist (name);
histIter->second.perObject.push_back (group);
}
}
histIter->second.multiplicity->Fill (count);
HistSubgroup& group = histIter->second.perObject[count];
return StatusCode::SUCCESS;
});
group.pt->Fill (particle->pt());
group.eta->Fill (particle->eta());
group.phi->Fill (particle->phi());
count += 1;
}
}
histIter->second.multiplicity->Fill (count);
}
return StatusCode::SUCCESS;
}
}
......@@ -80,57 +80,58 @@ namespace CP
StatusCode ObjectCutFlowHistAlg ::
execute ()
{
return m_systematicsList.foreach ([&] (const CP::SystematicSet& sys) -> StatusCode {
const xAOD::IParticleContainer *input = nullptr;
ANA_CHECK (m_inputHandle.retrieve (input, sys));
for (const auto& sys : m_systematicsList.systematicsVector())
{
const xAOD::IParticleContainer *input = nullptr;
ANA_CHECK (m_inputHandle.retrieve (input, sys));
auto histIter = m_hist.find (sys);
if (histIter == m_hist.end())
{
std::string name;
ANA_CHECK (m_systematicsList.service().makeSystematicsName (name, m_histPattern, sys));
auto histIter = m_hist.find (sys);
if (histIter == m_hist.end())
{
std::string name;
ANA_CHECK (m_systematicsList.service().makeSystematicsName (name, m_histPattern, sys));
ANA_CHECK (book (TH1F (name.c_str(), "object cut flow", m_allCutsNum+1, 0, m_allCutsNum+1)));
ANA_CHECK (book (TH1F (name.c_str(), "object cut flow", m_allCutsNum+1, 0, m_allCutsNum+1)));
m_hist.insert (std::make_pair (sys, hist (name)));
histIter = m_hist.find (sys);
assert (histIter != m_hist.end());
m_hist.insert (std::make_pair (sys, hist (name)));
histIter = m_hist.find (sys);
assert (histIter != m_hist.end());
for (unsigned i = 0; i < m_allCutsNum+1; i++)
{
histIter->second->GetXaxis()->SetBinLabel(i + 1, m_labels[i].c_str());
}
for (unsigned i = 0; i < m_allCutsNum+1; i++)
{
histIter->second->GetXaxis()->SetBinLabel(i + 1, m_labels[i].c_str());
}
}
for (const xAOD::IParticle *particle : *input)
for (const xAOD::IParticle *particle : *input)
{
if (m_preselection.getBool (*particle))
{
if (m_preselection.getBool (*particle))
bool keep = true;
unsigned cutIndex = 1;
histIter->second->Fill (0);
for (const auto& accessor : m_accessors)
{
bool keep = true;
unsigned cutIndex = 1;
histIter->second->Fill (0);
for (const auto& accessor : m_accessors)
const auto selection = accessor.first->getBits (*particle);
for (unsigned index = 0, end = accessor.second;
index != end; ++ index, ++ cutIndex)
{
const auto selection = accessor.first->getBits (*particle);
for (unsigned index = 0, end = accessor.second;
index != end; ++ index, ++ cutIndex)
if (selection & (1 << index))
{
if (selection & (1 << index))
{
histIter->second->Fill (cutIndex);
} else
{
keep = false;
break;
}
}
if (!keep)
histIter->second->Fill (cutIndex);
} else
{
keep = false;
break;
}
}
if (!keep)
break;
}