Skip to content
Snippets Groups Projects
Commit 6c70a9ae authored by Tadej Novak's avatar Tadej Novak
Browse files

Revert "Merge branch 'bugfix_objectcutflow' into 'main'"

Revert "Merge branch 'bugfix_objectcutflow' into 'main'"

This reverts merge request !68554
parent f140781f
No related branches found
No related tags found
No related merge requests found
/*
Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
*/
/// @author Nils Krumnack
/// @author Baptiste Ravina
#ifndef ASG_ANALYSIS_ALGORITHMS__OBJECT_CUT_FLOW_HIST_ALG_H
......@@ -12,6 +11,7 @@
#include <AnaAlgorithm/AnaAlgorithm.h>
#include <AsgTools/PropertyWrapper.h>
#include <SelectionHelpers/ISelectionNameSvc.h>
#include <SelectionHelpers/ISelectionReadAccessor.h>
#include <SelectionHelpers/SysReadSelectionHandle.h>
#include <SystematicsHandles/SysReadHandle.h>
#include <SystematicsHandles/SysListHandle.h>
......@@ -19,14 +19,19 @@
namespace CP
{
/// \brief an algorithm for dumping the object-level cutflow
/// \brief an algorithm for dumping the kinematics of an IParticle
/// container into histograms
///
/// This is mostly meant as a temporary helper algorithm to debug
/// the common CP algorithms as they get developed.
class ObjectCutFlowHistAlg final : public EL::AnaAlgorithm
{
/// \brief the standard constructor
public:
ObjectCutFlowHistAlg (const std::string& name,
ISvcLocator* pSvcLocator);
ISvcLocator* pSvcLocator);
public:
StatusCode initialize () override;
......@@ -39,10 +44,10 @@ namespace CP
private:
SysListHandle m_systematicsList {this};
/// \brief the particle collection we run on
/// \brief the jet collection we run on
private:
SysReadHandle<xAOD::IParticleContainer> m_inputHandle {
this, "input", "", "the input particle container to run on"};
this, "input", "", "the input collection to run on"};
/// \brief the preselection we apply to our input
private:
......@@ -61,10 +66,13 @@ namespace CP
private:
Gaudi::Property<std::string> m_histTitle {this, "histTitle", "object cut flow", "title for the created histograms"};
/// \brief the input object selections for which to create a cutflow
private:
std::vector<std::string> m_selection;
/// the list of accessors and cut ignore list
private:
SysReadSelectionHandleArray m_selections {
this, "selections", {}, "the inputs to the object cutflow"};
std::vector<std::pair<std::unique_ptr<ISelectionReadAccessor>,unsigned> > m_accessors;
/// \brief the total number of cuts configured (needed to
/// configure histograms)
......
/*
Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
*/
/// @author Nils Krumnack
/// @author Baptiste Ravina
//
......@@ -12,6 +11,7 @@
#include <AsgAnalysisAlgorithms/ObjectCutFlowHistAlg.h>
#include <PATCore/AcceptInfo.h>
#include <RootCoreUtils/StringUtil.h>
#include <TH1.h>
......@@ -23,10 +23,12 @@ namespace CP
{
ObjectCutFlowHistAlg ::
ObjectCutFlowHistAlg (const std::string& name,
ISvcLocator* pSvcLocator)
ISvcLocator* pSvcLocator)
: AnaAlgorithm (name, pSvcLocator)
{
declareProperty ("histPattern", m_histPattern, "the pattern for histogram names");
declareProperty ("selection", m_selection, "the list of selection decorations");
}
......@@ -36,28 +38,49 @@ namespace CP
{
ANA_CHECK (m_inputHandle.initialize (m_systematicsList));
ANA_CHECK (m_preselection.initialize (m_systematicsList, m_inputHandle, SG::AllowEmpty));
ANA_CHECK (m_selections.initialize (m_systematicsList, m_inputHandle));
ANA_CHECK (m_systematicsList.initialize());
ANA_CHECK (m_selectionNameSvc.retrieve());
// Total label
m_labels.push_back ("total");
// Individual labels
for (size_t i{}; i < m_selections.size(); i++) {
std::string label = m_selections.at(i).getSelectionName();
// Check if the string ends with "_%SYS%"
if (label.size() >= 6 && label.substr(label.size() - 6) == "_%SYS%") {
// Remove "_%SYS%" from the end of the string
label.erase(label.size() - 6);
for (std::size_t iter = 0, end = m_selection.size(); iter != end; ++ iter)
{
unsigned ncuts = 0u;
std::unique_ptr<ISelectionReadAccessor> accessor;
ANA_CHECK (makeSelectionReadAccessor (m_selection[iter], accessor));
if (accessor->isBool())
{
ANA_MSG_DEBUG ("selection " << m_selection[iter] << " is a bool, using 1 cut");
ncuts = 1;
m_labels.push_back (accessor->label());
} else if (const asg::AcceptInfo *acceptInfo = m_selectionNameSvc->getAcceptInfo (m_inputHandle.getNamePattern(), accessor->label());
acceptInfo != nullptr)
{
ANA_MSG_DEBUG ("found accept info for " << m_inputHandle.getNamePattern() << " " << accessor->label());
ncuts = acceptInfo->getNCuts();
for (unsigned i = 0; i != ncuts; i++)
{
ANA_MSG_DEBUG ("using cut name from accept info: " << acceptInfo->getCutName (i));
m_labels.push_back (acceptInfo->getCutName (i));
}
} else
{
ANA_MSG_ERROR ("could not find accept info for " << m_inputHandle.getNamePattern() << " " << accessor->label());
return StatusCode::FAILURE;
}
m_labels.push_back (label);
m_allCutsNum ++;
m_accessors.push_back (std::make_pair (std::move (accessor), ncuts));
m_allCutsNum += ncuts;
assert (m_allCutsNum+1 == m_labels.size());
}
assert (m_allCutsNum+1 == m_labels.size());
return StatusCode::SUCCESS;
}
StatusCode ObjectCutFlowHistAlg ::
execute ()
{
......@@ -87,20 +110,35 @@ namespace CP
}
}
for (const xAOD::IParticle *particle : *input) {
if (m_preselection.getBool (*particle, sys)) {
unsigned cutIndex = 1;
histIter->second->Fill (0);
for (size_t i{}; i < m_selections.size(); i++) {
if (m_selections.at(i).getBool (*particle, sys) > 0) {
histIter->second->Fill (cutIndex);
}
cutIndex++;
}
}
for (const xAOD::IParticle *particle : *input)
{
if (m_preselection.getBool (*particle, sys))
{
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)
{
if (selection & (1 << index))
{
histIter->second->Fill (cutIndex);
} else
{
keep = false;
break;
}
}
if (!keep)
break;
}
}
}
}
return StatusCode::SUCCESS;
}
}
......@@ -271,7 +271,7 @@ class ObjectCutFlowBlock (ConfigBlock):
alg = config.createAlgorithm( 'CP::ObjectCutFlowHistAlg', 'CutFlowDumperAlg_' + self.containerName + '_' + self.selectionName + postfix )
alg.histPattern = 'cflow_' + self.containerName + "_" + self.selectionName + postfix + '_%SYS%'
alg.selections = config.getSelectionCutFlow (self.containerName, self.selectionName)
alg.selection = config.getSelectionCutFlow (self.containerName, self.selectionName)
alg.input = config.readName (self.containerName)
alg.histTitle = "Object Cutflow: " + self.containerName + "." + self.selectionName
......
......@@ -292,10 +292,10 @@ def makeOverlapAnalysisSequence( dataType,
'OverlapRemovalCutFlowDumperAlg_%s' % container[ 0 ] + postfix )
alg.histPattern = container[ 0 ] + postfix + '_OR_cflow_%SYS%'
if inputLabel:
alg.selections = [ '%s,as_char' % inputLabel,
alg.selection = [ '%s,as_char' % inputLabel,
'%s,as_char' % outputLabel ]
else:
alg.selections = [ '%s,as_char' % outputLabel ]
alg.selection = [ '%s,as_char' % outputLabel ]
seq.append( alg, inputPropName = { container[ 0 ] : 'input' } )
# Set up a view container for the type.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment