diff --git a/Reconstruction/Jet/JetInterface/JetInterface/IJetEventSelector.h b/Reconstruction/Jet/JetInterface/JetInterface/IJetEventSelector.h new file mode 100644 index 0000000000000000000000000000000000000000..7a630808ad06117e7a1aac2d6a30cc2e15c4edf9 --- /dev/null +++ b/Reconstruction/Jet/JetInterface/JetInterface/IJetEventSelector.h @@ -0,0 +1,30 @@ +/* + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration +*/ + +// IJetEventSelector.h + +#ifndef IJetEventSelector_H +#define IJetEventSelector_H + +/// IJetEventSelector is a dual-use tool interface for a tool that selects +/// a jet based on EventInfo selections (e.g. mu, nPV) + +#include "AsgTools/IAsgTool.h" +#include "xAODEventInfo/EventInfo.h" + +class IJetEventSelector : virtual public asg::IAsgTool { +ASG_TOOL_INTERFACE(IJetEventSelector) + +public: + + /// Destructor. + virtual ~IJetEventSelector() { }; + + /// Method to select. + /// Returns true if eventinfo condition is passed. + virtual int keep(const xAOD::EventInfo &e) const =0; + +}; + +#endif diff --git a/Reconstruction/Jet/JetMonitoring/JetMonitoring/EventHistoVarTool.h b/Reconstruction/Jet/JetMonitoring/JetMonitoring/EventHistoVarTool.h new file mode 100644 index 0000000000000000000000000000000000000000..5013ebdab2301a1b92e8416dc82617040250c442 --- /dev/null +++ b/Reconstruction/Jet/JetMonitoring/JetMonitoring/EventHistoVarTool.h @@ -0,0 +1,58 @@ +/* this file is -*- C++ -*- + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef JETMONITORING_EventVARTOOL_H +#define JETMONITORING_EventVARTOOL_H + +#include "xAODEventInfo/EventInfo.h" + +#include "GaudiKernel/IAlgTool.h" +#include "AthenaBaseComps/AthAlgTool.h" + + +static const InterfaceID IID_IEventHistoVarTool("IEventHistoVarTool", 1 , 0); + +/////////////////////////////////////////////////////////// +/// \class EventHistoVarTool +/// +/// This class is a simple tool to access EventInfo +/// variables within the JetMonitoring environment +/// + +class IEventHistoVarTool : virtual public IAlgTool +{ +public: + + // Retrieve interface ID + static const InterfaceID& interfaceID() { return IID_IEventHistoVarTool; } + + virtual ~IEventHistoVarTool(){} + + /// the value of the variable for a given Event + virtual float value(const xAOD::EventInfo &) const = 0; + /// a compact description of the variable. + virtual std::string describe() const =0; +}; + + +class EventHistoVarTool : public AthAlgTool, virtual public IEventHistoVarTool { +public: + EventHistoVarTool(const std::string & type, const std::string & name, const IInterface* parent); + virtual ~EventHistoVarTool(){} + + virtual StatusCode initialize() ; + + virtual float value(const xAOD::EventInfo &) const; + virtual std::string describe() const {return m_varName;} + + +private: + + Gaudi::Property<std::string> m_varName {this,"Variable", ""}; + Gaudi::Property<float> m_defaultValue = {this,"Default", -1.}; + +}; + + +#endif diff --git a/Reconstruction/Jet/JetMonitoring/JetMonitoring/JetEventSelector.h b/Reconstruction/Jet/JetMonitoring/JetMonitoring/JetEventSelector.h new file mode 100644 index 0000000000000000000000000000000000000000..f35ce02283e44a7aa69c72f8ebb3f6849830181e --- /dev/null +++ b/Reconstruction/Jet/JetMonitoring/JetMonitoring/JetEventSelector.h @@ -0,0 +1,39 @@ +// -*- c++ -*- + +/* + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef JETMONITORING_JetEventSelector_H +#define JETMONITORING_JetEventSelector_H +#include "AsgTools/AsgTool.h" + +#include "JetInterface/IJetEventSelector.h" +#include "JetMonitoring/EventHistoVarTool.h" + + +class JetEventSelector : public asg::AsgTool , virtual public IJetEventSelector + { + ASG_TOOL_CLASS(JetEventSelector,IJetEventSelector) + public: + + JetEventSelector(const std::string &t); + virtual ~JetEventSelector(); + + virtual StatusCode initialize() ; + + int keep(const xAOD::EventInfo& e) const; + + protected: + + float m_min; + float m_max; + + ToolHandle<IEventHistoVarTool> m_var; + +}; + + + + +#endif diff --git a/Reconstruction/Jet/JetMonitoring/JetMonitoring/JetHistoSelectSort.h b/Reconstruction/Jet/JetMonitoring/JetMonitoring/JetHistoSelectSort.h index 80da49ee4287f034c70b5709003268703d6c751b..241e8e9fc1c5f82948974dd299c724891c92dd37 100644 --- a/Reconstruction/Jet/JetMonitoring/JetMonitoring/JetHistoSelectSort.h +++ b/Reconstruction/Jet/JetMonitoring/JetMonitoring/JetHistoSelectSort.h @@ -10,6 +10,7 @@ #include "AthenaBaseComps/AthAlgTool.h" #include "JetInterface/IJetSelector.h" +#include "JetInterface/IJetEventSelector.h" #include "JetMonitoring/IJetHistoFiller.h" #include "JetMonitoring/JetHistoVarTool.h" @@ -31,6 +32,7 @@ private: ToolHandleArray<IJetHistoFiller> m_jetFillerTools; ToolHandle<IJetSelector> m_selectTool; + ToolHandle<IJetEventSelector> m_eventSelTool; Gaudi::Property<int> m_selIndex {this,"SelectedIndex", -1}; ToolHandle<IJetHistoVarTool> m_sortVar; diff --git a/Reconstruction/Jet/JetMonitoring/JetMonitoring/JetVariable.h b/Reconstruction/Jet/JetMonitoring/JetMonitoring/JetVariable.h index 356b646d08ac682f9bd15a5b64379d7150b833a2..1666553d75ceeef18894b0b751f9228275c25e2e 100644 --- a/Reconstruction/Jet/JetMonitoring/JetMonitoring/JetVariable.h +++ b/Reconstruction/Jet/JetMonitoring/JetMonitoring/JetVariable.h @@ -176,11 +176,11 @@ namespace JetVar { xAOD::JetFourMom_t fourVec; bool status = false; - status = j.getAttribute<xAOD::JetFourMom_t>( "JetConstitScaleMomentum", fourVec ); + status = j.getAttribute<xAOD::JetFourMom_t>( "JetConstitScaleMomentum", fourVec ); // Jet four-momentum at constituent scale if( status ) constitScaleEnergy = fourVec.E() * m_scale ; else return 0.; - status = j.getAttribute<std::vector<float> >("EnergyPerSampling", samplingFrac ); - if( status ) return (samplingFrac[3]+samplingFrac[7])/constitScaleEnergy; + status = j.getAttribute<std::vector<float> >("EnergyPerSampling", samplingFrac ); //EnergyPerSampling is a vector of size 24; element i refers to the energy deposited in calo sampling i, see https://twiki.cern.ch/twiki/bin/viewauth/AtlasProtected/Run2JetMoments#Sampling_layers + if( status ) return (samplingFrac[3]+samplingFrac[7])/constitScaleEnergy; //3 is 'EMB3' in the LAr barrel, 7 is 'EME3' in the LAr EM endcap else return 0.; } }; @@ -193,11 +193,11 @@ namespace JetVar { xAOD::JetFourMom_t fourVec; bool status = false; - status = j.getAttribute<xAOD::JetFourMom_t>( "JetConstitScaleMomentum", fourVec ); + status = j.getAttribute<xAOD::JetFourMom_t>( "JetConstitScaleMomentum", fourVec ); // Jet four-momentum at constituent scale if( status ) constitScaleEnergy = fourVec.E() * m_scale ; else return 0.; - status = j.getAttribute<std::vector<float> >("EnergyPerSampling", samplingFrac ); - if( status ) return (samplingFrac[12]+samplingFrac[18])/constitScaleEnergy; + status = j.getAttribute<std::vector<float> >("EnergyPerSampling", samplingFrac ); // refer to EM3FracVar above + if( status ) return (samplingFrac[12]+samplingFrac[18])/constitScaleEnergy; //12 is 'TileBar0' in the Tile barrel, 18 is 'TileExt0' in the Tile extended barrel else return 0.; } }; diff --git a/Reconstruction/Jet/JetMonitoring/Root/JetEventSelector.cxx b/Reconstruction/Jet/JetMonitoring/Root/JetEventSelector.cxx new file mode 100644 index 0000000000000000000000000000000000000000..6aeadb562f634201e86e5c112c661ac054f87ea9 --- /dev/null +++ b/Reconstruction/Jet/JetMonitoring/Root/JetEventSelector.cxx @@ -0,0 +1,35 @@ +/* + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration +*/ + +#include "JetMonitoring/JetEventSelector.h" +#include <limits> + + +JetEventSelector::JetEventSelector(const std::string &t) + : asg::AsgTool(t) + , m_min(-std::numeric_limits<float>::max()) + , m_max( std::numeric_limits<float>::max()) + , m_var(this) +{ + + declareProperty("CutMin", m_min ); + declareProperty("CutMax", m_max ); + declareProperty("Var", m_var); +} + +JetEventSelector:: ~JetEventSelector(){ +} + +StatusCode JetEventSelector::initialize() { + + ATH_CHECK(m_var.retrieve() ); + ATH_MSG_INFO( "Selecting on var ("<< m_var->describe() << ") in ["<< m_min << " , "<< m_max<< "]"); + + return StatusCode::SUCCESS; +} + +int JetEventSelector::keep(const xAOD::EventInfo& e) const { + float v = m_var->value(e); + return (m_min < v ) && (v<m_max); +} diff --git a/Reconstruction/Jet/JetMonitoring/python/JetMonitoringConfig.py b/Reconstruction/Jet/JetMonitoring/python/JetMonitoringConfig.py index af41a7cb530e8b46cb3519722614197df06b3bc3..8ae162453e5aa66e445ccd170a5de9bde0a73f8c 100644 --- a/Reconstruction/Jet/JetMonitoring/python/JetMonitoringConfig.py +++ b/Reconstruction/Jet/JetMonitoring/python/JetMonitoringConfig.py @@ -390,12 +390,15 @@ class SelectSpec(ToolSpec): if '<' in selexpr: # interpret it as min<v<max cmin, v , cmax = interpretSelStr(selexpr) - selSpec = ToolSpec('JetSelectorAttribute', v+'sel', - Var = retrieveVarToolConf(v), - ) + if args.setdefault('isEventVariable', False) : + selProp = 'EventSelector' + selSpec = ToolSpec('JetEventSelector', v+'sel', Var = retrieveEventVarToolConf(v), ) + else: + selProp = 'Selector' + selSpec = ToolSpec('JetSelectorAttribute', v+'sel', Var = retrieveVarToolConf(v), ) if cmin is not None: selSpec['CutMin'] = cmin if cmax is not None: selSpec['CutMax'] = cmax - args['Selector'] = selSpec + args[selProp] = selSpec elif selexpr != '': from JetMonitoring.JetStandardHistoSpecs import knownSelector # assume it's a known pre-defined jet selector @@ -533,6 +536,21 @@ def retrieveVarToolConf(alias): return conf +def retrieveEventVarToolConf(alias): + """Return a ToolSpec from alias : (now with EventInfo variables) + * if alias is a string build a ToolSpec, assuming alias is an attribute of type float. + * if alias is a ToolSpec, returns it directly + """ + from JetMonitoring.JetStandardHistoSpecs import knownEventVar + if isinstance(alias, str): + conf = knownEventVar.get(alias,None) + if conf is None: + conf = ToolSpec('EventHistoVarTool', name=alias, Variable=alias) + else: # assume it's a config dict + conf = alias + return conf + + def retrieveHistoToolConf(alias): """Return a HistoSpec from alias : * if alias is a string look up in JetStandardHistoSpecs.knownHistos diff --git a/Reconstruction/Jet/JetMonitoring/python/JetStandardHistoSpecs.py b/Reconstruction/Jet/JetMonitoring/python/JetStandardHistoSpecs.py index fb50c6effd000c17b99e9902835065658bfe9d5d..587b5c67221fcdd386fe9d20936f90179c603420 100644 --- a/Reconstruction/Jet/JetMonitoring/python/JetStandardHistoSpecs.py +++ b/Reconstruction/Jet/JetMonitoring/python/JetStandardHistoSpecs.py @@ -22,7 +22,11 @@ knownVar = dict( ) - +knownEventVar = dict( + # These always are of type 'float' + avgMu = ToolSpec('EventHistoVarTool', 'avgMu', Variable='averageInteractionsPerCrossing'), + actMu = ToolSpec('EventHistoVarTool', 'actMu', Variable='actualInteractionsPerCrossing'), +) # *************************************** # The list of standard jet histograms. @@ -79,8 +83,8 @@ _knownHistos = [ HistoSpec('Jvt', (70, -0.2, 1.2), title='Jet JVT;JVT;', ), HistoSpec('JVFCorr', (120, -1.2, 1.2), title='Jet JVT; JVFCorr;', ), HistoSpec('JvtRpt', (75, 0, 1.5), title='Jet JVT Rpt; JVTRpt;', ), - HistoSpec('EM3Frac', (50,-0.1,0.5), title="EM3 fraction;EM3 fraction;Entries"), - HistoSpec('Tile0Frac', (50,-0.1,0.5), title="Tile0 fraction;Tile0 fraction;Entries"), + HistoSpec('EM3Frac', (50,-0.1,1.0), title="EM3 fraction;EM3 fraction;Entries"), + HistoSpec('Tile0Frac', (50,-0.1,1.0), title="Tile0 fraction;Tile0 fraction;Entries"), HistoSpec('GhostMuonSegmentCount', (60, 0, 60), title='Number of associated muon segments;Number;', xvar=VarSpec('GhostMuonSegmentCount','int')), @@ -94,8 +98,10 @@ _knownHistos = [ HistoSpec('NumTrkPt500[0]', (100, 0, 100), title='Number of tracks from PV0 above 0.5 GeV:N_{tracks}(p_{T}>0.5 GeV);', ), HistoSpec('NumTrkPt1000[0]', (100, 0, 100), title='Number of all tracks above 1 GeV:N_{tracks}(p_{T}>1 GeV);', ), - HistoSpec('SumPtTrkPt500:GeV', (100, 0, 200), title='Sum Pt of all tracks above 0.5 GeV:SumPt(p_{T}>0.5 GeV);', ), - HistoSpec('SumPtTrkPt500[0]:GeV', (100, 0, 200), title='Sum Pt of all tracks above 0.5 GeV[0]:SumPt(p_{T}>0.5 GeV)[0];', ), + HistoSpec('SumPtTrkPt500:GeV', (100, 0, 200), title='Sum Pt of all tracks above 0.5 GeV:SumPtTrk(p_{T}>0.5 GeV);', ), + HistoSpec('SumPtTrkPt500[0]:GeV', (100, 0, 200), title='Sum Pt of all tracks above 0.5 GeV[0]:SumPtTrk(p_{T}>0.5 GeV)[0];', ), + HistoSpec('SumPtChargedPFOPt500:GeV', (100, 0, 200), title='Sum Pt of all charged PFO above 0.5 GeV:SumPtChargedPFO(p_{T}>0.5 GeV);', ), + HistoSpec('SumPtChargedPFOPt500[0]:GeV', (100, 0, 200), title='Sum Pt of all charged PFO above 0.5 GeV[0]:SumPtChargedPFO(p_{T}>0.5 GeV)[0];', ), HistoSpec('FoxWolfram4', (100, -1, 1), title='FoxWolfram0;FoxWolfram4;', ), HistoSpec('FoxWolfram0', (100, -1, 1), title='FoxWolfram0;FoxWolfram0;', ), diff --git a/Reconstruction/Jet/JetMonitoring/src/EventHistoVarTool.cxx b/Reconstruction/Jet/JetMonitoring/src/EventHistoVarTool.cxx new file mode 100644 index 0000000000000000000000000000000000000000..9db068ccc9ca6473dd8abd39c672bdcb8da606cc --- /dev/null +++ b/Reconstruction/Jet/JetMonitoring/src/EventHistoVarTool.cxx @@ -0,0 +1,32 @@ +/* + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration +*/ + +#include "JetMonitoring/EventHistoVarTool.h" + + +EventHistoVarTool::EventHistoVarTool(const std::string & type, const std::string & name ,const IInterface* parent): + AthAlgTool( type, name, parent ) + +{ + declareInterface<IEventHistoVarTool>(this); +} + +StatusCode EventHistoVarTool::initialize() { + + if(m_varName=="") m_varName = name(); + + return StatusCode::SUCCESS; + +} + +float EventHistoVarTool::value(const xAOD::EventInfo & e) const { + + if (! e.isAvailable<float>(m_varName) ) { + ATH_MSG_WARNING("Could not access EventInfo variable "<< m_varName << ", returning default value " << m_defaultValue ); + return m_defaultValue; + } + + return e.auxdata<float>(m_varName); + +} diff --git a/Reconstruction/Jet/JetMonitoring/src/JetHistoSelectSort.cxx b/Reconstruction/Jet/JetMonitoring/src/JetHistoSelectSort.cxx index c360098d4cc876c9ea4c0db583f98e74c210823f..93e04da248ef9e3125be9f1ccf6a0ba27cb8d14b 100644 --- a/Reconstruction/Jet/JetMonitoring/src/JetHistoSelectSort.cxx +++ b/Reconstruction/Jet/JetMonitoring/src/JetHistoSelectSort.cxx @@ -1,7 +1,7 @@ #include <list> #include "AthContainers/ConstDataVector.h" #include "JetMonitoring/JetHistoSelectSort.h" - +#include "JetMonitoring/JetMonitoringAlg.h" JetHistoSelectSort::JetHistoSelectSort( const std::string& type, const std::string & name ,const IInterface* parent): @@ -16,6 +16,7 @@ JetHistoSelectSort::JetHistoSelectSort( const std::string& type, const std::str declareProperty("FillerTools",m_jetFillerTools); declareProperty("Selector",m_selectTool); + declareProperty("EventSelector",m_eventSelTool); declareProperty("SortVariable",m_sortVar); } @@ -36,6 +37,11 @@ StatusCode JetHistoSelectSort::initialize() { ATH_CHECK(m_selectTool.retrieve()); ATH_MSG_INFO( " Selecting with "<< m_selectTool->name() ); } + + if(m_eventSelTool.isEnabled()){ + ATH_CHECK(m_eventSelTool.retrieve()); + ATH_MSG_INFO( " Selecting with "<< m_eventSelTool->name() ); + } if( m_sortVar.isEnabled() ){ ATH_CHECK(m_sortVar.retrieve()); @@ -70,6 +76,10 @@ StatusCode JetHistoSelectSort::processJetContainer(const JetMonitoringAlg& paren tmpList.remove_if( sel ); } + if(m_eventSelTool.isEnabled()){ + auto eventInfo = parentAlg.GetEventInfo(ctx); + if ( ! m_eventSelTool->keep(*eventInfo) ) tmpList.clear(); + } ConstDataVector< xAOD::JetContainer > tmpCont(SG::VIEW_ELEMENTS); diff --git a/Reconstruction/Jet/JetMonitoring/src/components/JetMonitoring_entries.cxx b/Reconstruction/Jet/JetMonitoring/src/components/JetMonitoring_entries.cxx index fa5c644f972ce9f7e5ce8cd40204c56ef8da4427..cf1c2e33da6b7ce00d57e7afa8c32d67e697c284 100644 --- a/Reconstruction/Jet/JetMonitoring/src/components/JetMonitoring_entries.cxx +++ b/Reconstruction/Jet/JetMonitoring/src/components/JetMonitoring_entries.cxx @@ -8,6 +8,7 @@ #include "JetMonitoring/HIEfficiencyResponseHistos.h" #include "JetMonitoring/JetContainerHistoFiller.h" #include "JetMonitoring/JetSelectorAttribute.h" +#include "JetMonitoring/JetEventSelector.h" #include "JetMonitoring/HIJetUEMonitoring.h" #include "JetMonitoring/JetMonitoringAlg.h" @@ -15,6 +16,7 @@ #include "JetMonitoring/JetHistoAttributeFiller.h" #include "JetMonitoring/JetHistoTriggEfficiency.h" #include "JetMonitoring/JetHistoVarTool.h" +#include "JetMonitoring/EventHistoVarTool.h" #include "JetMonitoring/JetHistoSelectSort.h" #include "JetMonitoring/JetHistoResponseAndEff.h" @@ -32,6 +34,7 @@ DECLARE_COMPONENT( EfficiencyResponseHistos ) DECLARE_COMPONENT( HIEfficiencyResponseHistos ) DECLARE_COMPONENT( JetContainerHistoFiller ) DECLARE_COMPONENT( JetSelectorAttribute ) +DECLARE_COMPONENT( JetEventSelector ) DECLARE_COMPONENT( HIJetUEMonitoring ) DECLARE_COMPONENT( JetMonitoringAlg ) @@ -40,6 +43,7 @@ DECLARE_COMPONENT( JetHistoTriggEfficiency) DECLARE_COMPONENT( JetHistoAttributeFiller) DECLARE_COMPONENT( JetHistoSelectSort) DECLARE_COMPONENT( JetHistoVarTool) +DECLARE_COMPONENT( EventHistoVarTool) DECLARE_COMPONENT( JetHistoResponseAndEff) DECLARE_COMPONENT( JetAttributeHisto )