In both EventLoop and Athena if you want to do any sort of real
analysis you will access the xAOD objects through the event store. To
add some xAOD-related output to our job let’s retrieve the EventInfo
object and print out the run and event number for each event. We
chose this, because every xAOD you encounter will have an EventInfo
object (so you can run this on any file) and because knowing the run
and event number can actually be useful when you are debugging your
job and need to identify a specific event.
The run and event number are stored in the EventInfo
object, which
is defined in the xAODEventInfo
package, so let’s add that to our
MyAnalysis/CMakeLists.txt
LINK_LIBRARIES
field. It should now
look like this (we only added xAODEventInfo
to it, the rest of the
command is unchanged):
atlas_add_library (MyAnalysisLib
MyAnalysis/*.h Root/*.cxx
PUBLIC_HEADERS MyAnalysis
LINK_LIBRARIES AnaAlgorithmLib xAODEventInfo)
In the future when we tell you to add a library just add it to the end
of that command (we won’t be spelling this out again). The name of
the library is usually either the package name (e.g. PackageName
) or
the package name with the Lib
suffix (e.g. PackageNameLib
). Which
of the two it is depends on the package you use, there is no system to
it. You’ll have to check the documentation, look at the
CMakeLists.txt
file in that package, or just try both alternatives.
Next add the corresponding include at the top of
MyAnalysis/Root/MyxAODAnalysis.cxx
:
#include <xAODEventInfo/EventInfo.h>
Then in execute()
we need to retrieve the EventInfo
object and
print out the run and event number
StatusCode MyxAODAnalysis :: execute ()
{
// Here you do everything that needs to be done on every single
// events, e.g. read input variables, apply cuts, and fill
// histograms and trees. This is where most of your actual analysis
// code will go.
ANA_MSG_INFO ("in execute");
// retrieve the eventInfo object from the event store
const xAOD::EventInfo *eventInfo = nullptr;
ANA_CHECK (evtStore()->retrieve (eventInfo, "EventInfo"));
// print out run and event number from retrieved object
ANA_MSG_INFO ("in execute, runNumber = " << eventInfo->runNumber() << ", eventNumber = " << eventInfo->eventNumber());
return StatusCode::SUCCESS;
}
There is quite a bit of magic going on here. If everything seems clear to you: great! If not, don’t worry too much, we’ll be coming back to it and explaining the different parts in more detail (it’s a bit of a chicken and an egg problem).
Now let’s recompile:
cd ../build/
make
Note that when we called make
it calls cmake
for us, because it
realizes that we modified the CMakeLists.txt
file and need to call
cmake
.
If we go to the run directory and re-run our job we should now see it print out run and event numbers for every event.
If you are using EventLoop do:
cd ../run
ATestRun_eljob.py --submission-dir=submitDir
If you are using Athena do:
cd ../run
athena.py MyAnalysis/ATestRun_jobOptions.py
Browse the xAOD code in LXR and see if your can find how to print the Bunch Crossing ID, or another property of EventInfo.