Atlas Software Framework Martin Zeman Institute of Physics, Academy of Sciences of the Czech Republic Institut de recherche sur les lois fondamentales de l’Univers, Service de Physique des Particules, Commissariat à l’Energie Atomique Saclay
Jak píšete software pro analýzu?
2
Jak píšete software pro analýzu? •
Několik způsobů jak psát analýzu: 1. Athena … “Sbohem a díky za všechny ryby.” 2. ROOT / RooFit makra v CINT: .C jednoduchý kód, nejčastěji operace na úrovni histogramů: Draw() etc. 3. ROOT / RooFit makra kompilovaná: .cxx, .h libovolný C++ kód, ruční integrace balíčků, ruční implementace 4. MakeClass: .cxx, .h, .C řeší implementaci vyčítání z libovolného ntuple Ttree automaScky vygeneruje kód, který načte všechny proměnné ve stromě 5. MakeSelector: .cxx, .h, .C podobný jako MakeClass + implementace PROOF (parallel ROOT processing) 6. SFrame: .cxx, .h, .py, .xml konzistentní framework, se kterým pracují velké skupiny C++ kód s python interface a XML konfiguračními skripty 3 7. SFrame with D3PDMakerReader = SFrame + Athena … muhahahah
ROOT CINT • The ROOT command line = C interpreter: “Start with simple C expressions, defining simple type variables, making addiSons, mulSplicaSons, up to more complex operaSons.” root [] 35 + 89.3 const double)1.24299999999999997e+02 root [] float x = 45.6 root [] float y = 56.2 + sqrt(x); … •
Případně lze implementovat jako makro: {
… nějakej kód …
}
4
Jedno vylepšení: ROOT_MSG •
Typický problém, když se dostaneme přes 1000 řádek: debugging & output handling
enum outputlevels { kALWAYS, kFATAL, kERROR, kWARNING, kINFO, kDEBUG, kVERBOSE }; // output levels to be used by ROOT_MSG methods int outputLevel = kINFO; // a variation of the ATH_MSG macro for ROOT #define ROOT_MSG_VERBOSE ROOT_MSG(kVERBOSE) #define ROOT_MSG_DEBUG ROOT_MSG(kDEBUG) << (TString) "DEBUG: " #define ROOT_MSG_INFO ROOT_MSG(kINFO) << (TString) "INFO: " #define ROOT_MSG_WARNING ROOT_MSG(kWARNING) << (TString) "WARNING: " #define ROOT_MSG_ERROR ROOT_MSG(kERROR) << (TString) "ERROR: " #define ROOT_MSG_FATAL ROOT_MSG(kFATAL) << (TString) "FATAL: " #define ROOT_MSG_ALWAYS ROOT_MSG(kALWAYS) #define ROOT_MSG(level) if (level <= outputLevel) std::cout
• Použic: 1. Nastavit nejvyšší úroveň výstupu, kterou chceme vidět: int outputLevel = kINFO; 2. Voláme jako cout: ROOT_MSG_INFO << “Tohle je INFO” << endl; ROOT_MSG_DEBUG << “Tohle je DEBUG” << endl; ROOT_MSG_ERROR << “Tohle je ERROR” << endl;
5
MakeClass • •
MakeClass vytvoří zdroják a hlavičku C++ třídy pro daný ntuple. Jediný způsob jak nezešílet při vyčítání proměnných z velkých stromů (TTree): > TFile *theFile = new TFile("filename.root"); > TTree *tree = (TTree*)theFile->Get(”CollectionTree"); > tree->MakeClass(); // In a ROOT session, you can do: // Root > .L CollecSonTree.C // Root > CollecSonTree t // Root > t.GetEntry(12); // Fill t data members with entry number 12 // Root > t.Show(); // Show values of entry 12 // Root > t.Show(16); // Read and show values of entry 16 // Root > t.Loop(); // Loop on all entries
6
MakeClass: CollectionTree.C •
Zdroják v podstatě obsahuje jen for cyklus přes entries stromu: void CollectionTree::Loop() { if (fChain == 0) return; Long64_t nentries = fChain->GetEntriesFast(); Long64_t nbytes = 0, nb = 0; for (Long64_t jentry=0; jentry < nentries; jentry++) { Long64_t ientry = LoadTree(jentry); if (ientry < 0) break; nb = fChain->GetEntry(jentry); nbytes += nb; … nějakej kód … if (Cut(ientry) < 0) continue; }
} 7
MakeClass: CollectionTree.h •
Hlavička definuje cesty k proměnným v TTree
// Fixed size dimensions of array or collections stored in the TTree if any. const Int_t kMaxm_genEvents = 1; const Int_t kMaxm_genVertices = 1193; const Int_t kMaxm_genParticles = 2241;
!!!!!!!!!!!!!!!!!!!!!!!!
class CollectionTree { public : TTree *fChain; //!pointer to the analyzed TTree or TChain Int_t fCurrent; //!current Tree number in a TChain // Declaration of leaf types //EventInfo_p3 *EventInfo_p3_McEventInfo; vector
m_AllTheData; //McEventCollection_p4 *McEventCollection_p4_GEN_EVENT; Int_t m_genEvents_; Int_t m_genEvents_m_signalProcessId[kMaxm_genEvents];
//[m_genEvents_]
… // List of branches TBranch *b_EventInfo_p3_McEventInfo_m_AllTheData; //! TBranch *b_McEventCollection_p4_GEN_EVENT_m_genEvents_; TBranch *b_m_genEvents_m_signalProcessId; //! …
//!
} void CollectionTree::Init(TTree *tree){ … fChain->SetBranchAddress("m_genEvents.m_signalProcessId", m_genEvents_m_signalProcessId, 8 &b_m_genEvents_m_signalProcessId); …
MakeSelector •
The class definiSon in NTUP_EVNT.h has been generated automaScally by the ROOT uSlity TTree::MakeSelector(). This class is derived from the ROOT class TSelector. For more informaSon on the Tselector framework see $ROOTSYS/README/README.SELECTOR or the ROOT User Manual.
• The following methods are defined in this file: Begin(): called every Sme a loop on the tree starts, a convenient place to create your histograms. SlaveBegin(): called azer Begin(), when on PROOF called only on the slave servers Process(): called for each event, in this funcSon you decide what to read and fill your histograms. SlaveTerminate(): called at the end of the loop on the tree, when on PROOF called only on the slave servers. Terminate(): called at the end of the loop on the tree, a convenient place to draw/fit your histograms. •
To use this file, try the following session on your Tree T: Root > T-‐>Process("NTUP_EVNT.C") Root > T-‐>Process("NTUP_EVNT.C","some opSons") Root > T-‐>Process("NTUP_EVNT.C+")
9
MakeSelector: NTUP_EVNT.h
class NTUP_EVNT : public Tselector { public : TTree *fChain; //!pointer to the analyzed TTree or TChain // DeclaraSon of leaf types //EventInfo_p3 *EventInfo_p3_McEventInfo; vector m_AllTheData; //McEventCollecSon_p4 *McEventCollecSon_p4_GEN_EVENT; Int_t m_genEvents_; Int_t m_genEvents_m_signalProcessId[kMaxm_genEvents]; //[m_genEvents_] // List of branches TBranch *b_EventInfo_p3_McEventInfo_m_AllTheData; //! TBranch *b_McEventCollecSon_p4_GEN_EVENT_m_genEvents_; //! TBranch *b_m_genEvents_m_signalProcessId; //! // ******************* DECLARE VARIABLES ******************* Int_t m_events_n; Int_t m_events_WW_n; Int_t m_events_dilep_n; Int_t m_events_piGamma_n; // ******************** DECLARE HISTOGRAMS ******************** TH1D * h1_stable_n; TH1D * h1_stable_pdgId; #ifdef NTUP_EVNT_cxx void NTUP_EVNT::Init(TTree *tree) { // Set branch addresses and branch pointers if (!tree) return; fChain = tree; fChain-‐>SetMakeClass(1); fChain-‐>SetBranchAddress("m_AllTheData", &m_AllTheData, &b_EventInfo_p3_McEventInfo_m_AllTheData); fChain-‐>SetBranchAddress("m_genEvents", &m_genEvents_, &b_McEventCollecSon_p4_GEN_EVENT_m_genEvents_); fChain-‐>SetBranchAddress("m_genEvents.m_signalProcessId", m_genEvents_m_signalProcessId, &b_m_genEvents_m_signalProcessId);
TSelector pro GenEvent NTUPLE
10
ProofAnalysis: PROOF + Cmake •
MakeClass will create a source and header file for your class based on the ntuple. This is definitely the way to go for more complicated data analysis ProofAnalysis.addFile(”path/to/file"); ProofAnalysis.addSelector(”TreeName", ”SelectorName"); ProofAnalysis.makeSelectors();
PROOF nelze použít na Gridu! Pouze na site s PoD (Proof on Demand: LXBATCH)
11
ATLA(SFrame)work •
general HEP analysis package based on ROOT trees:
svn co https://sframe.svn.sourceforge.net/svnroot/sframe/SFrame/trunk source setup.[c]sh make Pro instalaci na Mac je potřeba modifikovat LXPLUS funguje out-‐of-‐the-‐box •
Enviroment on LXPLUS:
export export export export export
ROOTSYS=/afs/cern.ch/sw/lcg/app/releases/ROOT/5.26.00b/x86_64-slc5-gcc43-opt/root PYTHONDIR=/afs/cern.ch/sw/lcg/external/Python/2.5/x86_64-slc5-gcc43-opt LD_LIBRARY_PATH=$ROOTSYS/lib:$PYTHONDIR/lib:$LD_LIBRARY_PATH PATH=$ROOTSYS/bin:$PYTHONDIR/bin:$PATH PYTHONPATH=$ROOTSYS/lib:$PYTHONDIR/lib:$PYTHONPATH
SFrameCore: Built from the sources under SFrame/core. It holds the main classes of the framework for controlling the execuSon of an analysis cycle. SFramePlugIns: Built from the sources under SFrame/plug-‐ins. It holds classes that can be useful in physics analyses. SFrameUser: Built from the sources under SFrame/user. This library is a skeleton for physics analysis code built on top of SFrame. 12 TWiki: h‡p://sourceforge.net/apps/mediawiki/sframe/index.php?Stle=Main_Page
SFrame •
Struktura: analýza v cyklech (e.g.: ntuple loop -> fitting -> postprocessing)
sframe_main FirstCycle_config.xml sframe_main SecondCycle_config.xml
Spuštění
13
14
15
16
17
18
19
20
AtlasFramework = SFrame + RootCore + D3PD •
Obecný balíček založený na ElectroweakBosons, který obsahuje: Sframe RootCore RootCoreBoost GoodRunsLists D3PDMakerReader
Instalační a setup skripty pro LXPLUS, farmu v Praze a Mac:
> d3pdReaderMaker.exe -n MuonD3PDObject -f d3pd.root -t d3pd -v "^mu_muid_.*" -p "mu_muid_" -c h‡ps://twiki.cern.ch/twiki/bin/viewauth/Atlas/RootCore 21 h‡ps://twiki.cern.ch/twiki/bin/viewauth/AtlasProtected/D3PDMakerReader
PyROOT interface: Show() # FILE DIRECTORIES directories = [ #"HerwigppTtbar_Lep10", …
# HISTOGRAMS (in directories) histograms = [ #"h1_stable_n", …
for histogram in histograms : for directory in directories : MakePlots.cd(directory) MakePlots.select(histogram + "_" + directory) MakePlots.cd("..") # Call comparison plot MakePlots.stackplotselected(i)
Typical PyROOT problems: Python 2.7.2 (default, Jan 20 2012, 12:12:51) >>> import ROOT Traceback (most recent call last): File "<stdin>", line 1, in <module> File site-‐packages/ROOT.py", line 85, in <module> import libPyROOT as _root ImportError: No module named libPyROOT
cd /Ports # zsh . /Ports/bin/thisroot.sh cd -‐
22
ShowGui
svn checkout h‡ps://svn.cern.ch/reps/PragueJPsi/Root/ShowGui
ROOT Python 2.7 PyROOT Qt4 PyQt4 root 5.32.01_0 python27 2.7.2_4 pyqt 4 4.9_0 qt4 4.7.4_1
Testováno na: Linux Mac ? Windows ?
Co vylepšit na GUI?
23
SVN •
Současný stav našeho pracního SVN: PragueJPsi svn+ssh://svn.cern.ch/reps/PragueJPsi
• •
Udělat pro obecný framework nový repozitář? Jak ho pojmenovat? Má vůbec někdo zájem s AtlasFramework pracovat či se na tom podílet?
24
TODO list •
ProofAnalysis přes TSelector: zahodit nebo rozšířit?
• • • • •
AtlasFramework: Naimplementovat AnalysisExample pomocí D3PDMakerReader pro GenEvent NTUPLE -> GenEvent D3PD AtlasFramework: Udělat tutorial? AtlasFramework: Namísto makefilů naimplementovat CMAKE AtlasFramework: Rozchodit na Gridu (SFramePanda, SFrameGanga) AtlasFramework: Athena ROOT Access? Používá to někdo?
•
ShowGui: Dodělat do Show.py základní kreslící algoritmy: – – – –
•
stack compare s nastavitelnými barvami normalizace podle tabulky Yaml interface pro deklaraci histogramů?
ShowGui: Další features do ShowGui?
25