Release Setup †https://atlassoftwaredocs.web.cern.ch/ABtutorial/release_setup/ $ ssh -Y username@lxplus.cern.ch Replace "username" by your username. You can check your shell by $ echo $SHELL If this command gives /bin/bash you use bash. If you use bash, you need to add the following two lines to ~/.bashrc using emacs or vi or other editors. export ATLAS_LOCAL_ROOT_BASE=/cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase alias setupATLAS='source ${ATLAS_LOCAL_ROOT_BASE}/user/atlasLocalSetup.sh' If you use other login script or use other shell, you need to modify the corresponding script. Then, you need to exit and log in lxplus.cern.ch again to activate the alias. $ exit $ ssh -Y username@lxplus.cern.ch Now, you can run the setupATLAS command. $ setupATLAS You need to create some directories for this tutorial. You may choose the directory locations. But here, I assume that you create directories under your home directory. $ cd ~ # go to your home directory. $ mkdir ROOTAnalysisTutorial $ cd ROOTAnalysisTutorial $ mkdir source $ mkdir build $ mkdir run You are now at the ~/ROOTAnalysisTutorial/ directory. Then, you need to create the ~/ROOTAnalysisTutorial/source/CMakeLists.txt using an editor. $ emacs -nw source/CMakeLists.txt # # Project configuration for UserAnalysis. # # Set the minimum required CMake version: cmake_minimum_required( VERSION 3.4 FATAL_ERROR ) # Try to figure out what project is our parent. Just using a hard-coded list # of possible project names. Basically the names of all the other # sub-directories inside the Projects/ directory in the repository. set( _parentProjectNames Athena AthenaP1 AnalysisBase AthAnalysis AthSimulation AthDerivation AnalysisTop ) set( _defaultParentProject AnalysisBase ) foreach( _pp ${_parentProjectNames} ) if( NOT "$ENV{${_pp}_DIR}" STREQUAL "" ) set( _defaultParentProject ${_pp} ) break() endif() endforeach() # Set the parent project name based on the previous findings: set( ATLAS_PROJECT ${_defaultParentProject} CACHE STRING "The name of the parent project to build against" ) # Clean up: unset( _parentProjectNames ) unset( _defaultParentProject ) # Find the AnalysisBase project. This is what, amongst other things, pulls # in the definition of all of the "atlas_" prefixed functions/macros. find_package( ${ATLAS_PROJECT} REQUIRED ) # Set up CTest. This makes sure that per-package build log files can be # created if the user so chooses. atlas_ctest_setup() # Set up the GitAnalysisTutorial project. With this CMake will look for "packages" # in the current repository and all of its submodules, respecting the # "package_filters.txt" file, and set up the build of those packages. atlas_project( UserAnalysis 1.0.0 USE ${ATLAS_PROJECT} ${${ATLAS_PROJECT}_VERSION} ) # Set up the runtime environment setup script. This makes sure that the # project's "setup.sh" script can set up a fully functional runtime environment, # including all the externals that the project uses. lcg_generate_env( SH_FILE ${CMAKE_BINARY_DIR}/${ATLAS_PLATFORM}/env_setup.sh ) install( FILES ${CMAKE_BINARY_DIR}/${ATLAS_PLATFORM}/env_setup.sh DESTINATION . ) # Set up CPack. This call makes sure that an RPM or TGZ file can be created # from the built project. Used by Panda to send the project to the grid worker # nodes. atlas_cpack_setup() Compile the file with AnalysisBase 21.2.75 at the build directory. $ cd build/ $ asetup 21.2.75,AnalysisBase $ cmake ../source/ $ make $ source x86_64-*/setup.sh # This is necessary if you run some jobs. On Every Login †https://atlassoftwaredocs.web.cern.ch/ABtutorial/on_every_login/ The next time you start a new session to start working, you’ll have to do the following. $ ssh -Y username@lxplus.cern.ch $ setupATLAS $ cd ~/ROOTAnalysisTutorial $ cd ./build $ asetup --restore $ source x86_64-*/setup.sh xAOD Samples †https://atlassoftwaredocs.web.cern.ch/ABtutorial/xaod_samples/ https://twiki.cern.ch/twiki/bin/viewauth/AtlasComputing/SoftwareTutorialSoftwareBasics#Define_ALRB_TutorialData $ export ALRB_TutorialData=/afs/cern.ch/atlas/project/PAT/tutorial/cern-jan2018/ Create Your Package †https://atlassoftwaredocs.web.cern.ch/ABtutorial/create_package/ You are now at the ~/ROOTAnalysisTutorial/build/ directory. Let's create a new package. $ cd ../source/ $ mkdir MyAnalysis $ mkdir MyAnalysis/MyAnalysis $ mkdir MyAnalysis/Root $ mkdir MyAnalysis/src $ mkdir MyAnalysis/src/components $ mkdir MyAnalysis/share You are now at the ~/ROOTAnalysisTutorial/source/ directory. Create a new file, ~/ROOTAnalysisTutorial/source/MyAnalysis/CMakeLists.txt. $ emacs -nw MyAnalysis/CMakeLists.txt # The name of the package: atlas_subdir (MyAnalysis) Compile the new package. $ cd ../build/ $ cmake ../source/ $ make You need to run the following commands as well. $ cd ../build/ $ source x86_64-*/setup.sh You are now at the ~/ROOTAnalysisTutorial/build/ directory. Create Algorithm †https://atlassoftwaredocs.web.cern.ch/ABtutorial/alg_basic_algorithm/ You need to move to the source directory. $ cd ~/ROOTAnalysisTutorial/source/ You need to create a new file, MyAnalysis/MyAnalysis/MyxAODAnalysis.h. $ emacs -nw MyAnalysis/MyAnalysis/MyxAODAnalysis.h #ifndef MyAnalysis_MyxAODAnalysis_H #define MyAnalysis_MyxAODAnalysis_H #include <AnaAlgorithm/AnaAlgorithm.h> class MyxAODAnalysis : public EL::AnaAlgorithm { public: // this is a standard algorithm constructor MyxAODAnalysis (const std::string& name, ISvcLocator* pSvcLocator); // these are the functions inherited from Algorithm virtual StatusCode initialize () override; virtual StatusCode execute () override; virtual StatusCode finalize () override; private: // Configuration, and any other types of variables go here. //float m_cutValue; //TTree *m_myTree; //TH1 *m_myHist; }; #endif Create another file, MyAnalysis/Root/MyxAODAnalysis.cxx. $ emacs -nw MyAnalysis/Root/MyxAODAnalysis.cxx #include <AsgTools/MessageCheck.h> #include <MyAnalysis/MyxAODAnalysis.h> MyxAODAnalysis :: MyxAODAnalysis (const std::string& name, ISvcLocator *pSvcLocator) : EL::AnaAlgorithm (name, pSvcLocator) { // Here you put any code for the base initialization of variables, // e.g. initialize all pointers to 0. This is also where you // declare all properties for your algorithm. Note that things like // resetting statistics variables or booking histograms should // rather go into the initialize() function. } StatusCode MyxAODAnalysis :: initialize () { // Here you do everything that needs to be done at the very // beginning on each worker node, e.g. create histograms and output // trees. This method gets called before any input files are // connected. return StatusCode::SUCCESS; } 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. return StatusCode::SUCCESS; } StatusCode MyxAODAnalysis :: finalize () { // This method is the mirror image of initialize(), meaning it gets // called after the last event has been processed on the worker node // and allows you to finish up any objects you created in // initialize() before they are written to disk. This is actually // fairly rare, since this happens separately for each worker node. // Most of the time you want to do your post-processing on the // submission node after all your histogram outputs have been // merged. return StatusCode::SUCCESS; } Create the MyAnalysis/MyAnalysis/MyAnalysisDict.h $ emacs -nw MyAnalysis/MyAnalysis/MyAnalysisDict.h #ifndef MYANALYSIS_MYANALYSIS_DICT_H #define MYANALYSIS_MYANALYSIS_DICT_H // This file includes all the header files that you need to create // dictionaries for. #include <MyAnalysis/MyxAODAnalysis.h> #endif Create the MyAnalysis/MyAnalysis/selection.xml file $ emacs -nw MyAnalysis/MyAnalysis/selection.xml <lcgdict> <!-- This file contains a list of all classes for which a dictionary should be created. --> <class name="MyxAODAnalysis" /> </lcgdict> You need to update the CMakeLists.txt file for the package. $ emacs -nw MyAnalysis/CMakeLists.txt # The name of the package: atlas_subdir (MyAnalysis) # Add the shared library: atlas_add_library (MyAnalysisLib MyAnalysis/*.h Root/*.cxx PUBLIC_HEADERS MyAnalysis LINK_LIBRARIES AnaAlgorithmLib) if (XAOD_STANDALONE) # Add the dictionary (for AnalysisBase only): atlas_add_dictionary (MyAnalysisDict MyAnalysis/MyAnalysisDict.h MyAnalysis/selection.xml LINK_LIBRARIES MyAnalysisLib) endif () if (NOT XAOD_STANDALONE) # Add a component library for AthAnalysis only: atlas_add_component (MyAnalysis src/components/*.cxx LINK_LIBRARIES MyAnalysisLib) endif () # Install files from the package: atlas_install_joboptions( share/*_jobOptions.py ) atlas_install_scripts( share/*_eljob.py ) Compile the updated package $ cd ../build/ $ cmake ../source/ $ make You are now at the ~/ROOTAnalysisTutorial/build/ directory. Configuration (EventLoop) †https://atlassoftwaredocs.web.cern.ch/ABtutorial/alg_basic_macro/ Create a Python macro. $ cd ../ $ emacs -nw source/MyAnalysis/share/ATestRun_eljob.py #!/usr/bin/env python # Read the submission directory as a command line argument. You can # extend the list of arguments with your private ones later on. import optparse parser = optparse.OptionParser() parser.add_option( '-s', '--submission-dir', dest = 'submission_dir', action = 'store', type = 'string', default = 'submitDir', help = 'Submission directory for EventLoop' ) ( options, args ) = parser.parse_args() # Set up (Py)ROOT. import ROOT ROOT.xAOD.Init().ignore() # Set up the sample handler object. See comments from the C++ macro # for the details about these lines. import os sh = ROOT.SH.SampleHandler() sh.setMetaString( 'nc_tree', 'CollectionTree' ) inputFilePath = os.getenv( 'ALRB_TutorialData' ) + '/r9315/' ROOT.SH.ScanDir().filePattern( 'AOD.11182705._000001.pool.root.1' ).scan( sh, inputFilePath ) sh.printContent() # Create an EventLoop job. job = ROOT.EL.Job() job.sampleHandler( sh ) job.options().setDouble( ROOT.EL.Job.optMaxEvents, 500 ) # Create the algorithm's configuration. from AnaAlgorithm.DualUseConfig import createAlgorithm alg = createAlgorithm ( 'MyxAODAnalysis', 'AnalysisAlg' ) # later on we'll add some configuration options for our algorithm that go here # Add our algorithm to the job job.algsAdd( alg ) # Run the job using the direct driver. driver = ROOT.EL.DirectDriver() driver.submit( job, options.submission_dir ) Make it executable. $ chmod +x source/MyAnalysis/share/ATestRun_eljob.py Compile the package again. $ cd ./build/ $ cmake ../source/ $ make Run the macron in the run directory. $ cd ../run/ $ ATestRun_eljob.py --submission-dir=submitDir Add some printouts †https://atlassoftwaredocs.web.cern.ch/ABtutorial/alg_basic_printout/ Move to the source directory. $ cd ../source/ Update the MyxAODAnalysis.cxx file. $ emacs -nw MyAnalysis/Root/MyxAODAnalysis.cxx Add the following line in the execute method. ANA_MSG_INFO ("in execute"); Add the following line in the initialize method. ANA_MSG_INFO ("in initialize"); Compile the package again. $ cd ../build/ $ make Run the macro. $ cd ../run $ rm -rf submitDir $ ATestRun_eljob.py --submission-dir=submitDir xAOD access †https://atlassoftwaredocs.web.cern.ch/ABtutorial/alg_basic_xaod/ $ cd ../source/ Update MyAnalysis/CMakeLists.txt to be able to use xAODEventInfo class. $ emacs -nw MyAnalysis/CMakeLists.txt Change # Add the shared library: atlas_add_library (MyAnalysisLib MyAnalysis/*.h Root/*.cxx PUBLIC_HEADERS MyAnalysis LINK_LIBRARIES AnaAlgorithmLib) to atlas_add_library (MyAnalysisLib MyAnalysis/*.h Root/*.cxx PUBLIC_HEADERS MyAnalysis LINK_LIBRARIES AnaAlgorithmLib xAODEventInfo) Update MyAnalysis/Root/MyxAODAnalysis.cxx. $ emacs -nw MyAnalysis/Root/MyxAODAnalysis.cxx Add the following line to the beginning of the file. #include <xAODEventInfo/EventInfo.h> Change the execute method as follows. 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; } Compile the package. $ cd ../build/ $ make Run the macro. $ cd ../run $ rm -rf submitDir $ ATestRun_eljob.py --submission-dir=submitDir |