Integrating submodules
Overview
Teaching: 10 min
Exercises: 30 minQuestions
How can I integrate my submodules into the analysis code?
What changes to cmake will I need to do to add the new libraries?
Objectives
Retrieve additional objects from the ATLAS EDM
Review how to make changes to cmake
Retrieving new objects in AnalysisPayload
We added two submodules to help with the electron and muon selections. Now we need to properly add them to our code so we can retrieve those objects and use them in our analysis.
Updating libraries
We need to add the electron and muon libaries from the ATLAS EDM. We want to retrieve electron and muon containers from the event store, just like we did for jets.
In the block, ATLAS EDM functionality
, you should add
#include "xAODEgamma/ElectronContainer.h"
#include "xAODMuon/MuonContainer.h"
To make use of the helper functions we added in the submodules, we also need to our new HelperSelection
libaries under #include "JetSelectionHelper/JetSelectionHelper.h"
#include "ElectronSelectionHelper/ElectronSelectionHelper.h"
#include "MuonSelectionHelper/MuonSelectionHelper.h"
Retrieving new objects
Just like we retrieved the jet container from the event store, we need to do the same for the electrons and the muons.
Electrons are retrieved from the ElectronContainer
as follows
const xAOD::ElectronContainer *electrons = nullptr;
event.retrieve(electrons, "Electrons" ) ;
The muons are retrieved from the MuonContainer
as follows
const xAOD::MuonContainer *muons = nullptr;
event.retrieve(muons, "Muons") ;
Normally, we would want to calibrate the electrons and the muons, just as we did for the jets; however, we will not do this today.
If you are interested in how to retrieve additional objects and their calibrations, you can refer to this xAOD analysis tutorial twikli.
Selecting electrons
Now that we have retrieved the electrons and muons, we want to save the electron and muon vectors that are present in our dataset as well as those that pass the pt and eta requirements defined in the ElectronSelectionHelper
and MuonSelectionHelper
.
Let us first declare the ElectronSelectionHelper
tool, similar to what was done for jets.
ElectronSelectionHelper electron_selector;
We will create a vector for the electrons that pass the requirements in ElectronSelectionHelper
called electrons_kin
(to follow the terminology we used for jets).
std::vector<xAOD::Electron> electrons_kin;
We can loop over our electron container and fill electrons into the vectors, similar to what is done for the jets.
for(const xAOD::Electron* electron : *electrons) {
if( electron_selector.isElectronGood(electron) ){
electrons_kin.push_back(*electron);
}
}
In the above for loop
, we can add a printout of electron kinematics that we will use later on.
std::cout << "Electron : " << electron->pt() << "\t" << electron->eta() << "\t" << electron->phi() << "\t" << electron->m() << "\t" << electron->charge() << std::endl;
The only variable that is new in this printout for electrons, as opposed to jets, is the charge
.
Adding muons
Modify the
AnalysisPayload
program to retrieve loop over themuons
collection and store the muons into a vector for the muons that pass theisMuonGood
selection fromMuonSelectionHelper
calledmuons_kin
.
Solution
The lines of code you will need to add are shown below; however, their location is not specified.
MuonSelectionHelper muon_selector; std::vector<xAOD::Muon> muons_kin; for(const xAOD::Muon* muon : *muons) { if( muon_selector.isMuonGood(muon) ){ muons_kin.push_back(*muon); } }
Updating the CMakeLists
In the CMake module, you saw that when you added the jet calibration
libraries, you needed to update the CMakeLists.txt
in the AnalysisPayload
folder, otherwise you would get a build error.
Since we have added 2 submodules and included them in AnalysisPayload
, we also need to add them to the CMakeLists.txt
.
After you have updated the CMakeLists.txt
, outside of source
, compile and build your code.
Solution
The libraries we need to link are
xAODEgamma
,xAODMuon
,ElectronSelectionHelperLib
, andMuonSelectionHelperLib
. YourAnalysisPayload/CMakeLists.txt
should now contain the following.ATLAS_ADD_EXECUTABLE ( AnalysisPayload utils/AnalysisPayload.cxx INCLUDE_DIRS ${ROOT_INCLUDE_DIRS} LINK_LIBRARIES ${ROOT_LIBRARIES} xAODEventInfo xAODRootAccess xAODJet xAODEgamma xAODMuon AsgTools JetCalibToolsLib JetSelectionHelperLib ElectronSelectionHelperLib MuonSelectionHelperLib)
Key Points
When we add a new submodule, we need to update cmake.
Running over xAODs/DAODs is not that scary