diff --git a/Event/xAOD/xAODEventInfoCnv/src/EventInfoRunNumberFixAlg.cxx b/Event/xAOD/xAODEventInfoCnv/src/EventInfoRunNumberFixAlg.cxx new file mode 100644 index 0000000000000000000000000000000000000000..4053a8e7438bd078ad690603d034bd9512264575 --- /dev/null +++ b/Event/xAOD/xAODEventInfoCnv/src/EventInfoRunNumberFixAlg.cxx @@ -0,0 +1,75 @@ +/* + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration +*/ + +// Gaudi/Athena include(s): +#include "AthenaKernel/errorcheck.h" + +// Local include(s): +#include "EventInfoRunNumberFixAlg.h" +#include "xAODEventInfo/EventAuxInfo.h" + +// Misc +#include "CxxUtils/make_unique.h" +#include <memory> + +namespace xAOD { + + EventInfoRunNumberFixAlg::EventInfoRunNumberFixAlg( const std::string& name, + ISvcLocator* svcLoc ) + : AthAlgorithm( name, svcLoc ) + { + + declareProperty( "McChannelNumber" , m_mcChannelNumber = 0 ); + declareProperty( "ContainerName" , m_containerName = "EventInfo" ); + } + + StatusCode EventInfoRunNumberFixAlg::initialize() { + // Return gracefully: + return StatusCode::SUCCESS; + + } + + StatusCode EventInfoRunNumberFixAlg::execute() { + + const xAOD::EventInfo* originalEventInfo = nullptr; + ATH_CHECK( evtStore()->retrieve (originalEventInfo, + m_containerName) ); + + // Only run if a difference is found + if( originalEventInfo->mcChannelNumber()==m_mcChannelNumber ){ + return StatusCode::SUCCESS; + } + + // + const SG::DataProxy* proxy = + evtStore()->proxy (ClassID_traits<xAOD::EventInfo>::ID(), + m_containerName ); + if (!proxy) { + ATH_MSG_WARNING( "No xAOD::EventInfo " + << "with key \"" << m_containerName << "\" found" ); + return StatusCode::SUCCESS; + } + + xAOD::EventInfo* eventInfo=nullptr; + if (proxy->isConst()) { + eventInfo = new xAOD::EventInfo(); + *eventInfo = *originalEventInfo; + auto store = CxxUtils::make_unique<xAOD::EventAuxInfo>(); + eventInfo->setStore (store.get()); + eventInfo->setMCChannelNumber(m_mcChannelNumber); + ATH_CHECK( evtStore()->overwrite (eventInfo, + m_containerName, + true, false) ); + ATH_CHECK( evtStore()->overwrite (std::move(store), + m_containerName + "Aux.", + true, false) ); + } else { + ATH_CHECK( evtStore()->retrieve (eventInfo, + m_containerName) ); + eventInfo->setMCChannelNumber(m_mcChannelNumber); + } + return StatusCode::SUCCESS; + } + +} // xAOD namespace diff --git a/Event/xAOD/xAODEventInfoCnv/src/EventInfoRunNumberFixAlg.h b/Event/xAOD/xAODEventInfoCnv/src/EventInfoRunNumberFixAlg.h new file mode 100644 index 0000000000000000000000000000000000000000..992ff3b373cc2244b9df9a0d06dd167bd56a6e29 --- /dev/null +++ b/Event/xAOD/xAODEventInfoCnv/src/EventInfoRunNumberFixAlg.h @@ -0,0 +1,46 @@ +// Dear emacs, this is -*- c++ -*- + +/* + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration +*/ +#ifndef XAODCREATORALGS_EVENTINFOAODFIXALG_H +#define XAODCREATORALGS_EVENTINFOAODFIXALG_H + +// System include(s): +#include <string> + +// Athena/Gaudi include(s): +#include "AthenaBaseComps/AthAlgorithm.h" + +// xAOD include +#include "xAODEventInfo/EventInfo.h" + +namespace xAOD { + + /** + * @short Algorithm to fix AOD EventInfo + */ + class EventInfoRunNumberFixAlg : public AthAlgorithm { + + public: + /// Regular algorithm constructor + EventInfoRunNumberFixAlg( const std::string& name, ISvcLocator* svcLoc ); + + /// Function initialising the algorithm + virtual StatusCode initialize() override; + /// Function executing the algorithm + virtual StatusCode execute() override; + + private: + + // Container name + std::string m_containerName; + + /// Correct number number to be used to update EventInfo + uint32_t m_mcChannelNumber; + + }; // class EventInfoRunNumberFixAlg + +} // namespace xAODMaker + +#endif diff --git a/Event/xAOD/xAODEventInfoCnv/src/components/xAODEventInfoCnv_entries.cxx b/Event/xAOD/xAODEventInfoCnv/src/components/xAODEventInfoCnv_entries.cxx index 6af48e19f67f8eff5ab0c70e1db36eec57427d1b..f508c23f595c5fb7ddf6930435f6d9a65511cc08 100644 --- a/Event/xAOD/xAODEventInfoCnv/src/components/xAODEventInfoCnv_entries.cxx +++ b/Event/xAOD/xAODEventInfoCnv/src/components/xAODEventInfoCnv_entries.cxx @@ -15,6 +15,9 @@ #include "../EventInfoModifierAlg.h" #include "../EventInfoMCWeightFixAlg.h" +#include "../EventInfoRunNumberFixAlg.h" + +using namespace xAOD; DECLARE_NAMESPACE_TOOL_FACTORY( xAODMaker, EventInfoCnvTool ) DECLARE_NAMESPACE_TOOL_FACTORY( xAODMaker, EventInfoSelectorTool ) @@ -25,6 +28,7 @@ DECLARE_NAMESPACE_ALGORITHM_FACTORY( xAODMaker, EventInfoNonConstCnvAlg ) DECLARE_NAMESPACE_ALGORITHM_FACTORY( xAODReader, EventInfoModifierAlg ) DECLARE_ALGORITHM_FACTORY( EventInfoMCWeightFixAlg ) +DECLARE_ALGORITHM_FACTORY( EventInfoRunNumberFixAlg ) DECLARE_FACTORY_ENTRIES( xAODEventInfoCnv ) { @@ -37,5 +41,6 @@ DECLARE_FACTORY_ENTRIES( xAODEventInfoCnv ) { DECLARE_NAMESPACE_ALGORITHM( xAODReader, EventInfoModifierAlg ) DECLARE_ALGORITHM( EventInfoMCWeightFixAlg ) + DECLARE_ALGORITHM( EventInfoRunNumberFixAlg ) } diff --git a/Reconstruction/AODFix/python/AODFix_r210.py b/Reconstruction/AODFix/python/AODFix_r210.py index 968e819c661c03883b1172ec2a4d59bf243506f0..57a5122426492daa9127e733187f97c7a9ffa52b 100644 --- a/Reconstruction/AODFix/python/AODFix_r210.py +++ b/Reconstruction/AODFix/python/AODFix_r210.py @@ -3,11 +3,16 @@ from AthenaCommon.Logging import logging from AthenaCommon import CfgMgr +from AthenaCommon.GlobalFlags import globalflags +import PyJobTransforms.trfJobOptions logAODFix_r210 = logging.getLogger( 'AODFix_r210' ) from AODFix_base import AODFix_base +from RecExConfig.InputFilePeeker import inputFileSummary +import os + class AODFix_r210(AODFix_base): ''' This class just performs AODFix on 21.0.X releases @@ -42,6 +47,11 @@ class AODFix_r210(AODFix_base): topSequence = AlgSequence() oldMetadataList = self.prevAODFix.split("-") + + if "evtRunNum" not in oldMetadataList: + self.evtRunNum_postSystemRec(topSequence) + pass + if "trklinks" not in oldMetadataList: self.trklinks_postSystemRec(topSequence) pass @@ -86,6 +96,89 @@ class AODFix_r210(AODFix_base): # Below are the individual AODfixes, split up and documented # Name must follow format: <fixID>_<whereCalled> + def evtRunNum_postSystemRec(self, topSequence): + + """ This fixes the wrong run number arising from buggy EVNT-to-EVNT transform workflows. + --- > JIRA: https://its.cern.ch/jira/browse/AGENE-1655 + """ + schedule_evtRunNum = False + if 'mc_channel_number' in inputFileSummary: + input_mcChanNb = inputFileSummary['mc_channel_number'][0] + """ + MC15.366000.Sherpa_221_NNPDF30NNLO_Znunu_PTV0_70.py + MC15.366001.Sherpa_221_NNPDF30NNLO_Znunu_PTV70_100.py + MC15.366002.Sherpa_221_NNPDF30NNLO_Znunu_PTV100_140_MJJ0_500.py + MC15.366003.Sherpa_221_NNPDF30NNLO_Znunu_PTV100_140_MJJ500_1000.py + MC15.366004.Sherpa_221_NNPDF30NNLO_Znunu_PTV100_140_MJJ1000_E_CMS.py + MC15.366005.Sherpa_221_NNPDF30NNLO_Znunu_PTV140_280_MJJ0_500.py + MC15.366006.Sherpa_221_NNPDF30NNLO_Znunu_PTV140_280_MJJ500_1000.py + MC15.366007.Sherpa_221_NNPDF30NNLO_Znunu_PTV140_280_MJJ1000_E_CMS.py + MC15.366008.Sherpa_221_NNPDF30NNLO_Znunu_PTV280_500.py + """ + if input_mcChanNb>= 366000 and input_mcChanNb<=366008: + schedule_evtRunNum = True + """ + MC15.304784.Pythia8EvtGen_A14NNPDF23LO_jetjet_Powerlaw.py + """ + if input_mcChanNb==304784: + schedule_evtRunNum = True + """ + mc15_13TeV.364310.Sherpa_222_NNPDF30NNLO_Wenu_MAXHTPTV70_140.evgen.EVNT.e6209 + mc15_13TeV.364311.Sherpa_222_NNPDF30NNLO_Wmunu_MAXHTPTV70_140.evgen.EVNT.e6209 + mc15_13TeV.364312.Sherpa_222_NNPDF30NNLO_Wtaunu_MAXHTPTV70_140.evgen.EVNT.e6209 + mc15_13TeV.364103.Sherpa_221_NNPDF30NNLO_Zmumu_MAXHTPTV70_140_CVetoBVeto.evgen.EVNT.e5271 + mc15_13TeV.364132.Sherpa_221_NNPDF30NNLO_Ztautau_MAXHTPTV70_140_CFilterBVeto.evgen.EVNT.e5307 + mc15_13TeV.364145.Sherpa_221_NNPDF30NNLO_Znunu_MAXHTPTV70_140_CVetoBVeto.evgen.EVNT.e5308 + mc15_13TeV.364146.Sherpa_221_NNPDF30NNLO_Znunu_MAXHTPTV70_140_CFilterBVeto.evgen.EVNT.e5308 + mc15_13TeV.364106.Sherpa_221_NNPDF30NNLO_Zmumu_MAXHTPTV140_280_CVetoBVeto.evgen.EVNT.e5271 + mc15_13TeV.364107.Sherpa_221_NNPDF30NNLO_Zmumu_MAXHTPTV140_280_CFilterBVeto.evgen.EVNT.e5271 + mc15_13TeV.364120.Sherpa_221_NNPDF30NNLO_Zee_MAXHTPTV140_280_CVetoBVeto.evgen.EVNT.e5299 + mc15_13TeV.364134.Sherpa_221_NNPDF30NNLO_Ztautau_MAXHTPTV140_280_CVetoBVeto.evgen.EVNT.e5307 + mc15_13TeV.364148.Sherpa_221_NNPDF30NNLO_Znunu_MAXHTPTV140_280_CVetoBVeto.evgen.EVNT.e5308 + mc15_13TeV.364162.Sherpa_221_NNPDF30NNLO_Wmunu_MAXHTPTV140_280_CVetoBVeto.evgen.EVNT.e5340 + mc15_13TeV.364163.Sherpa_221_NNPDF30NNLO_Wmunu_MAXHTPTV140_280_CFilterBVeto.evgen.EVNT.e5340 + mc15_13TeV.364176.Sherpa_221_NNPDF30NNLO_Wenu_MAXHTPTV140_280_CVetoBVeto.evgen.EVNT.e5340 + mc15_13TeV.364177.Sherpa_221_NNPDF30NNLO_Wenu_MAXHTPTV140_280_CFilterBVeto.evgen.EVNT.e5340 + mc15_13TeV.364190.Sherpa_221_NNPDF30NNLO_Wtaunu_MAXHTPTV140_280_CVetoBVeto.evgen.EVNT.e5340 + mc15_13TeV.364191.Sherpa_221_NNPDF30NNLO_Wtaunu_MAXHTPTV140_280_CFilterBVeto.evgen.EVNT.e5340 + """ + if input_mcChanNb>=364310 and input_mcChanNb<=364312: + schedule_evtRunNum = True + if input_mcChanNb==364132: + schedule_evtRunNum = True + if input_mcChanNb>=364145 and input_mcChanNb<=364146: + schedule_evtRunNum = True + if input_mcChanNb>=364106 and input_mcChanNb<=364107: + schedule_evtRunNum = True + if input_mcChanNb==364120: + schedule_evtRunNum = True + if input_mcChanNb==364134: + schedule_evtRunNum = True + if input_mcChanNb==364148: + schedule_evtRunNum = True + if input_mcChanNb>=364162 and input_mcChanNb<=364163: + schedule_evtRunNum = True + if input_mcChanNb>=364176 and input_mcChanNb<=364177: + schedule_evtRunNum = True + if input_mcChanNb>=364190 and input_mcChanNb<=364191: + schedule_evtRunNum = True + + if schedule_evtRunNum: + variables = {} + runNumber = None + if os.access('runargs.AODtoDAOD.py',os.R_OK): + execfile('runargs.AODtoDAOD.py',variables) + if 'runArgs' in variables and hasattr(variables['runArgs'],'runNumber'): + runNumber = variables['runArgs'].runNumber + + isSimulation = False + if (globalflags.DataSource() == 'geant4'): + isSimulation = True + + if isSimulation and runNumber and runNumber != input_mcChanNb: + from xAODEventInfoCnv.xAODEventInfoCnvConf import xAOD__EventInfoRunNumberFixAlg + EventInfoRunNumberFixAlg = xAOD__EventInfoRunNumberFixAlg( McChannelNumber = int(runNumber) ) + topSequence+=EventInfoRunNumberFixAlg def trklinks_postSystemRec(self, topSequence): """This fixes the links to tracks in muons and btagging