Skip to content

Commit

Permalink
Merge pull request #532 from UCATLAS/upgrade/StartUsingAnaToolHandle
Browse files Browse the repository at this point in the history
Bump to 2.3.45, and start using AnaToolHandle
  • Loading branch information
mmilesi committed Mar 7, 2016
2 parents 897f033 + f0276d6 commit ff0bd18
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 79 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
env:
- ABV=2.3.44
- ABV=2.3.45

before_install:
- ls
Expand Down
74 changes: 30 additions & 44 deletions Root/BasicEventSelection.cxx
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
/********************************************************
*
* Basic event selection. Performs general simple cuts
* (GRL, Event Cleaning, Min nr. Tracks for PV candidate)
*
* G. Facini (gabriel.facini@cern.ch)
* M. Milesi (marco.milesi@cern.ch)
* J. Dandoy (jeff.dandoy@cern.ch)
* J. Alison (john.alison@cern.ch)
*
*******************************************************/

//#include "PATInterfaces/CorrectionCode.h"
//#include "AsgTools/StatusCode.h"

// EL include(s):
#include <EventLoop/Job.h>
#include <EventLoop/Worker.h>
Expand All @@ -31,6 +16,7 @@
#include "TrigConfxAOD/xAODConfigTool.h"
#include "TrigDecisionTool/TrigDecisionTool.h"
#include "PATInterfaces/CorrectionCode.h"
//#include "AsgTools/StatusCode.h"

// ROOT include(s):
#include "TFile.h"
Expand All @@ -46,7 +32,7 @@ BasicEventSelection :: BasicEventSelection (std::string className) :
Algorithm(className),
m_PU_default_channel(0),
m_grl(nullptr),
m_pileuptool(nullptr),
m_pileup_tool_handle("CP::PileupReweightingTool/PileupToolName"),
m_trigConfTool(nullptr),
m_trigDecTool(nullptr),
m_histEventCount(nullptr),
Expand Down Expand Up @@ -219,7 +205,7 @@ EL::StatusCode BasicEventSelection :: fileExecute ()
//
const xAOD::CutBookkeeperContainer* incompleteCBC(nullptr);
if ( !m_event->retrieveMetaInput(incompleteCBC, "IncompleteCutBookkeepers").isSuccess() ) {
Error("initializeEvent()","Failed to retrieve IncompleteCutBookkeepers from MetaData! Exiting.");
Error("fileExecute()","Failed to retrieve IncompleteCutBookkeepers from MetaData! Exiting.");
return EL::StatusCode::FAILURE;
}
bool allFromUnknownStream(true);
Expand All @@ -232,7 +218,7 @@ EL::StatusCode BasicEventSelection :: fileExecute ()
}
}
if ( !allFromUnknownStream ) {
Error("initializeEvent()","Found incomplete Bookkeepers! Check file for corruption.");
Error("fileExecute()","Found incomplete Bookkeepers! Check file for corruption.");
return EL::StatusCode::FAILURE;
}

Expand Down Expand Up @@ -283,13 +269,13 @@ EL::StatusCode BasicEventSelection :: fileExecute ()

// Write metadata event bookkeepers to histogram
//
Info("histInitialize()", "Meta data from this file:");
Info("histInitialize()", "Initial events = %u", static_cast<unsigned int>(m_MD_initialNevents) );
Info("histInitialize()", "Selected events = %u", static_cast<unsigned int>(m_MD_finalNevents) );
Info("histInitialize()", "Initial sum of weights = %f", m_MD_initialSumW);
Info("histInitialize()", "Selected sum of weights = %f", m_MD_finalSumW);
Info("histInitialize()", "Initial sum of weights squared = %f", m_MD_initialSumWSquared);
Info("histInitialize()", "Selected sum of weights squared = %f", m_MD_finalSumWSquared);
Info("fileExecute()", "Meta data from this file:");
Info("fileExecute()", "Initial events = %u", static_cast<unsigned int>(m_MD_initialNevents) );
Info("fileExecute()", "Selected events = %u", static_cast<unsigned int>(m_MD_finalNevents) );
Info("fileExecute()", "Initial sum of weights = %f", m_MD_initialSumW);
Info("fileExecute()", "Selected sum of weights = %f", m_MD_finalSumW);
Info("fileExecute()", "Initial sum of weights squared = %f", m_MD_initialSumWSquared);
Info("fileExecute()", "Selected sum of weights squared = %f", m_MD_finalSumWSquared);

m_histEventCount -> Fill(1, m_MD_initialNevents);
m_histEventCount -> Fill(2, m_MD_finalNevents);
Expand Down Expand Up @@ -329,12 +315,12 @@ EL::StatusCode BasicEventSelection :: initialize ()

// if truth level make sure parameters are set properly
if( m_truthLevelOnly ) {
Info("configure()", "Truth only! Turn off trigger stuff");
Info("initialize()", "Truth only! Turn off trigger stuff");
m_triggerSelection = "";
m_applyTriggerCut = m_storeTrigDecisions = m_storePassL1 = m_storePassHLT = m_storeTrigKeys = false;
Info("configure()", "Truth only! Turn off GRL");
Info("initialize()", "Truth only! Turn off GRL");
m_applyGRLCut = false;
Info("configure()", "Truth only! Turn off Pile-up Reweight");
Info("initialize()", "Truth only! Turn off Pile-up Reweight");
m_doPUreweighting = false;
}

Expand Down Expand Up @@ -450,9 +436,8 @@ EL::StatusCode BasicEventSelection :: initialize ()
//

if ( m_doPUreweighting ) {
m_pileuptool = new CP::PileupReweightingTool("Pileup");

//m_pileuptool->EnableDebugging(true);
RETURN_CHECK("BasicEventSelection::initialize()", m_pileup_tool_handle.make("CP::PileupReweightingTool/Pileup"), "Failed to create handle to CP::PileupReweightingTool");;

std::vector<std::string> PRWFiles;
std::vector<std::string> lumiCalcFiles;
Expand Down Expand Up @@ -493,15 +478,17 @@ EL::StatusCode BasicEventSelection :: initialize ()
printf( "\t %s \n", lumiCalcFiles.at(i).c_str() );
}

RETURN_CHECK("BasicEventSelection::initialize()", m_pileuptool->setProperty("ConfigFiles", PRWFiles), "");
RETURN_CHECK("BasicEventSelection::initialize()", m_pileuptool->setProperty("LumiCalcFiles", lumiCalcFiles), "");
RETURN_CHECK("BasicEventSelection::initialize()", m_pileup_tool_handle.setProperty("ConfigFiles", PRWFiles), "");
RETURN_CHECK("BasicEventSelection::initialize()", m_pileup_tool_handle.setProperty("LumiCalcFiles", lumiCalcFiles), "");
if ( m_PU_default_channel ) {
RETURN_CHECK("BasicEventSelection::initialize()", m_pileuptool->setProperty("DefaultChannel", m_PU_default_channel), "");
RETURN_CHECK("BasicEventSelection::initialize()", m_pileup_tool_handle.setProperty("DefaultChannel", m_PU_default_channel), "");
}
RETURN_CHECK("BasicEventSelection::initialize()", m_pileuptool->setProperty("DataScaleFactor", 1.0/1.16), "Failed to set pileup reweighting data scale factor");
RETURN_CHECK("BasicEventSelection::initialize()", m_pileuptool->setProperty("DataScaleFactorUP", 1.0), "Failed to set pileup reweighting data scale factor up");
RETURN_CHECK("BasicEventSelection::initialize()", m_pileuptool->setProperty("DataScaleFactorDOWN", 1.0/1.23), "Failed to set pileup reweighting data scale factor down");
RETURN_CHECK("BasicEventSelection::initialize()", m_pileuptool->initialize(), "Failed to properly initialize CP::PileupReweightingTool");
RETURN_CHECK("BasicEventSelection::initialize()", m_pileup_tool_handle.setProperty("DataScaleFactor", 1.0/1.16), "Failed to set pileup reweighting data scale factor");
RETURN_CHECK("BasicEventSelection::initialize()", m_pileup_tool_handle.setProperty("DataScaleFactorUP", 1.0), "Failed to set pileup reweighting data scale factor up");
RETURN_CHECK("BasicEventSelection::initialize()", m_pileup_tool_handle.setProperty("DataScaleFactorDOWN", 1.0/1.23), "Failed to set pileup reweighting data scale factor down");
RETURN_CHECK("BasicEventSelection::initialize()", m_pileup_tool_handle.initialize(), "Failed to properly initialize CP::PileupReweightingTool");
//m_pileup_tool_handle->EnableDebugging(true);

}

// 3.
Expand Down Expand Up @@ -597,12 +584,12 @@ EL::StatusCode BasicEventSelection :: execute ()
// Update Pile-Up Reweighting
//------------------------------------------------------------------------------------------
if ( m_isMC && m_doPUreweighting ) {
m_pileuptool->apply( *eventInfo ); // NB: this call automatically decorates eventInfo with:
// 1.) the PU weight ("PileupWeight")
// 2.) the corrected mu ("corrected_averageInteractionsPerCrossing")
// 3.) the random run number ("RandomRunNumber")
// 4.) the random lumiblock number ("RandomLumiBlockNumber")
}
m_pileup_tool_handle->apply( *eventInfo ); // NB: this call automatically decorates eventInfo with:
// 1.) the PU weight ("PileupWeight")
// 2.) the corrected mu ("corrected_averageInteractionsPerCrossing")
// 3.) the random run number ("RandomRunNumber")
// 4.) the random lumiblock number ("RandomLumiBlockNumber")
}

//------------------------------------------------------------------------------------------
// Declare an 'eventInfo' decorator with the *total* MC event weight
Expand Down Expand Up @@ -824,7 +811,6 @@ EL::StatusCode BasicEventSelection :: finalize ()
m_RunNr_VS_EvtNr.clear();

if ( m_grl ) { delete m_grl; m_grl = nullptr; }
if ( m_pileuptool ) { delete m_pileuptool; m_pileuptool = nullptr; }
if ( m_trigDecTool ) { delete m_trigDecTool; m_trigDecTool = nullptr; }
if ( m_trigConfTool ) { delete m_trigConfTool; m_trigConfTool = nullptr; }

Expand Down
79 changes: 50 additions & 29 deletions Root/MuonEfficiencyCorrector.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ MuonEfficiencyCorrector :: MuonEfficiencyCorrector (std::string className) :
m_asgMuonEffCorrTool_muSF_Iso(nullptr),
m_asgMuonEffCorrTool_muSF_Trig(nullptr),
m_asgMuonEffCorrTool_muSF_TTVA(nullptr),
m_pileuptool(nullptr)
m_pileup_tool_handle("CP::PileupReweightingTool/PileupToolName")
{
// Here you put any code for the base initialization of variables,
// e.g. initialize all pointers to 0. Note that you should only put
Expand Down Expand Up @@ -64,7 +64,9 @@ MuonEfficiencyCorrector :: MuonEfficiencyCorrector (std::string className) :

// Trigger efficiency SF
//
m_runNumber = 900000; // do NOT change this default value!
m_runNumber = 276329;
m_useRandomRunNumber = true;

m_WorkingPointRecoTrig = "Loose";
m_WorkingPointIsoTrig = "LooseTrackOnly";
m_SingleMuTrig = "HLT_mu20_iloose_L1MU15";
Expand Down Expand Up @@ -193,7 +195,7 @@ EL::StatusCode MuonEfficiencyCorrector :: initialize ()
RETURN_CHECK( "MuonEfficiencyCorrector::initialize()", m_asgMuonEffCorrTool_muSF_Reco->initialize(), "Failed to properly initialize MuonEfficiencyScaleFactors for reco efficiency SF");
m_toolAlreadyUsed[m_recoEffSF_tool_name] = false;
}

//
// Add the chosen WP to the string labelling the vector<SF> decoration
//
Expand Down Expand Up @@ -284,30 +286,29 @@ EL::StatusCode MuonEfficiencyCorrector :: initialize ()
m_trigEffSF_tool_name = "MuonTriggerScaleFactors_effSF_Trig_Reco" + m_WorkingPointRecoTrig + "_Iso" + m_WorkingPointIsoTrig;

if ( asg::ToolStore::contains<CP::MuonTriggerScaleFactors>(m_trigEffSF_tool_name) ) {

m_asgMuonEffCorrTool_muSF_Trig = asg::ToolStore::get<CP::MuonTriggerScaleFactors>(m_trigEffSF_tool_name);
m_toolAlreadyUsed[m_trigEffSF_tool_name] = true;

} else {
m_asgMuonEffCorrTool_muSF_Trig = new CP::MuonTriggerScaleFactors(m_trigEffSF_tool_name);
m_toolAlreadyUsed[m_trigEffSF_tool_name] = false;
int runNumber(m_runNumber);
if ( asg::ToolStore::contains<CP::PileupReweightingTool>("Pileup") ) {
m_pileuptool = asg::ToolStore::get<CP::PileupReweightingTool>("Pileup");
}
//

RETURN_CHECK("MuonEfficiencyCorrector::initialize()", m_pileup_tool_handle.make("CP::PileupReweightingTool/Pileup"), "Failed to create handle to CP::PileupReweightingTool");;
RETURN_CHECK("MuonEfficiencyCorrector::initialize()", m_pileup_tool_handle.initialize(), "Failed to properly initialize CP::PileupReweightingTool");

// If PileupReweightingTool exists, and a specific runNumber hasn't been set by the user yet,
// use the random runNumber weighted by integrated luminosity got from CP::PileupReweightingTool::getRandomRunNumber()
// Source: // https://twiki.cern.ch/twiki/bin/view/AtlasProtected/ExtendedPileupReweighting#Generating_PRW_config_files
//
if ( m_isMC && m_runNumber == 900000 && m_pileuptool ) {
runNumber = m_pileuptool->getRandomRunNumber( *eventInfo, false );
Info("initialize()","CP::MuonTriggerScaleFactors - setting runNumber %i read from CP::PileupReweightingTool::getRandomRunNumber()", runNumber);
} else {
Warning("initialize()","CP::MuonTriggerScaleFactors - setting runNumber %i read from user's configuration - NOT RECOMMENDED", runNumber );
}
if( m_asgMuonEffCorrTool_muSF_Trig->setRunNumber( runNumber ) == CP::CorrectionCode::Error ) {
Warning("initialize()","Cannot set RunNumber for MuonTriggerScaleFactors tool");

if ( m_isMC && !m_useRandomRunNumber ) {
Warning("initialize()","CP::MuonTriggerScaleFactors - setting runNumber %i read from user's configuration - NOT RECOMMENDED", m_runNumber );
if( m_asgMuonEffCorrTool_muSF_Trig->setRunNumber( m_runNumber ) == CP::CorrectionCode::Error ) {
Warning("initialize()","Cannot set RunNumber for MuonTriggerScaleFactors tool");
}
}

// Add an "Iso" prefix to the WP (required for tool configuration)
//
std::string iso_trig_WP = "Iso" + m_WorkingPointIsoTrig;
Expand Down Expand Up @@ -363,7 +364,7 @@ EL::StatusCode MuonEfficiencyCorrector :: initialize ()
RETURN_CHECK( "MuonEfficiencyCorrector::initialize()", m_asgMuonEffCorrTool_muSF_TTVA->setProperty("CalibrationRelease", m_calibRelease ),"Failed to set calibration release property of MuonEfficiencyScaleFactors for TTVA efficiency SF");
RETURN_CHECK( "MuonEfficiencyCorrector::initialize()", m_asgMuonEffCorrTool_muSF_TTVA->initialize(), "Failed to properly initialize MuonEfficiencyScaleFactors for TTVA efficiency SF");
}

//
// Add the chosen WP to the string labelling the vector<SF> decoration
//
Expand Down Expand Up @@ -443,7 +444,7 @@ EL::StatusCode MuonEfficiencyCorrector :: execute ()

// decorate muons w/ SF - there will be a decoration w/ different name for each syst!
//
this->executeSF( inputMuons, countInputCont );
this->executeSF( eventInfo, inputMuons, countInputCont );

} else {
// if m_inputAlgo = NOT EMPTY --> you are retrieving syst varied containers from an upstream algo. This is the case of calibrators: one different SC
Expand Down Expand Up @@ -472,7 +473,7 @@ EL::StatusCode MuonEfficiencyCorrector :: execute ()

// decorate muons w/ SF - there will be a decoration w/ different name for each syst!
//
this->executeSF( inputMuons, countInputCont );
this->executeSF( eventInfo, inputMuons, countInputCont );

// increment counter
//
Expand Down Expand Up @@ -522,7 +523,6 @@ EL::StatusCode MuonEfficiencyCorrector :: finalize ()
if ( m_asgMuonEffCorrTool_muSF_Iso ) { m_asgMuonEffCorrTool_muSF_Iso = nullptr; delete m_asgMuonEffCorrTool_muSF_Iso; }
if ( m_asgMuonEffCorrTool_muSF_Trig ) { m_asgMuonEffCorrTool_muSF_Trig = nullptr; delete m_asgMuonEffCorrTool_muSF_Trig; }
if ( m_asgMuonEffCorrTool_muSF_TTVA ) { m_asgMuonEffCorrTool_muSF_TTVA = nullptr; delete m_asgMuonEffCorrTool_muSF_TTVA; }
if ( m_pileuptool ) { m_pileuptool = nullptr; delete m_pileuptool; }

return EL::StatusCode::SUCCESS;
}
Expand All @@ -546,7 +546,7 @@ EL::StatusCode MuonEfficiencyCorrector :: histFinalize ()
return EL::StatusCode::SUCCESS;
}

EL::StatusCode MuonEfficiencyCorrector :: executeSF ( const xAOD::MuonContainer* inputMuons, unsigned int countSyst )
EL::StatusCode MuonEfficiencyCorrector :: executeSF ( const xAOD::EventInfo* eventInfo, const xAOD::MuonContainer* inputMuons, unsigned int countSyst )
{

//
Expand All @@ -570,11 +570,11 @@ EL::StatusCode MuonEfficiencyCorrector :: executeSF ( const xAOD::MuonContainer
// Firstly, loop over available systematics for this tool - remember: syst == EMPTY_STRING --> nominal
// Every systematic will correspond to a different SF!
//

// Do it only if a tool with *this* name hasn't already been used
//
if ( !( m_toolAlreadyUsed.find(m_recoEffSF_tool_name)->second ) ) {

for ( const auto& syst_it : m_systListReco ) {

// Create the name of the SF weight to be recorded
Expand Down Expand Up @@ -663,7 +663,7 @@ EL::StatusCode MuonEfficiencyCorrector :: executeSF ( const xAOD::MuonContainer
// e.g. the different SC containers w/ calibration systematics upstream.
//
// Use the counter defined in execute() to check this is done only once per event
//
//
if ( countSyst == 0 ) { RETURN_CHECK( "MuonEfficiencyCorrector::executeSF()", m_store->record( sysVariationNamesReco, m_outputSystNamesReco), "Failed to record vector of systematic names for muon reco efficiency SF" ); }

}
Expand Down Expand Up @@ -787,6 +787,27 @@ EL::StatusCode MuonEfficiencyCorrector :: executeSF ( const xAOD::MuonContainer
//
if ( !( m_toolAlreadyUsed.find(m_trigEffSF_tool_name)->second ) ) {

// Unless specifically switched off by the user,
// use the per-event random runNumber weighted by integrated luminosity got from CP::PileupReweightingTool::getRandomRunNumber()
// Source:
// https://twiki.cern.ch/twiki/bin/view/AtlasProtected/ExtendedPileupReweighting#Generating_PRW_config_files
// https://twiki.cern.ch/twiki/bin/view/AtlasProtected/MCPAnalysisGuidelinesMC15#Muon_trigger_efficiency_scale_fa
//
if ( m_isMC && m_useRandomRunNumber ) {

// Use mu-dependent randomization (recommended)
//
int randRunNumber = m_pileup_tool_handle->getRandomRunNumber( *eventInfo, true );

int runNumber = ( randRunNumber != 0 ) ? randRunNumber : m_runNumber;

if( m_asgMuonEffCorrTool_muSF_Trig->setRunNumber( runNumber ) == CP::CorrectionCode::Error ) {
Error("executeSF()", "Failed to set RunNumber for MuonTriggerScaleFactors tool");
return EL::StatusCode::FAILURE;
}

}

for ( const auto& syst_it : m_systListIso ) {

// Create the name of the SF weight to be recorded
Expand Down Expand Up @@ -882,18 +903,18 @@ EL::StatusCode MuonEfficiencyCorrector :: executeSF ( const xAOD::MuonContainer
// e.g. the different SC containers w/ calibration systematics upstream.
//
// Use the counter defined in execute() to check this is done only once per event
//
//
if ( countSyst == 0 ) { RETURN_CHECK( "MuonEfficiencyCorrector::executeSF()", m_store->record( sysVariationNamesTrig, m_outputSystNamesTrig), "Failed to record vector of systematic names for muon trigger efficiency SF" ); }

}

// 4.
// TTVA efficiency SFs - this is a per-MUON weight
//
// Firstly, loop over available systematics for this tool - remember: syst == EMPTY_STRING --> nominal
// Every systematic will correspond to a different SF!
//

// Do it only if a tool with *this* name hasn't already been used
//
if ( !( m_toolAlreadyUsed.find(m_TTVAEffSF_tool_name)->second ) ) {
Expand Down Expand Up @@ -987,6 +1008,6 @@ EL::StatusCode MuonEfficiencyCorrector :: executeSF ( const xAOD::MuonContainer
if ( countSyst == 0 ) { RETURN_CHECK( "MuonEfficiencyCorrector::executeSF()", m_store->record( sysVariationNamesTTVA, m_outputSystNamesTTVA), "Failed to record vector of systematic names for muon TTVA efficiency SF" ); }

}

return EL::StatusCode::SUCCESS;
}
Loading

0 comments on commit ff0bd18

Please sign in to comment.