{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", " \n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "

An introductional notebook to HEP analysis in C++


\n", "
\n", "\n", "

In this notebook you can find an easy set of commands that show some basic computing techniques commonly used in High Energy Physics (HEP) analyzes.

\n", "\n", "

It also shows how to create an histogram, fill it and draw it. Moreover it is an introduction to ROOT too. The final output is a plot with the number of leptons.

\n", "\n", "

Check the description of the varibles inside the dataset at the end of this notebook

\n", "\n", "

All done with less that 20 lines of code!

" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

An introduction to the ATLAS public datasets

\n", "

This is a notebook using the ROOT Prompt kernel that using c++ language, is intended to show the internal content and the way to call and interact with the datasets released by the ATLAS experiment with focus in Education and Training activities:

\n", "\n", "
\n", "\n", "

We use data recorded (simulated) by the ATLAS detector (experiment)

\n", "\n", "

where physics objects can be represented as below

\n", "\"ATLAS" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Cell #1

\n", "

At first we have to include several helpers that will support our analysis:

" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "#include \n", "#include \n", "#include " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Cell #2

\n", "

In order to activate the interactive visualisation of the histogram that is later created we can use the JSROOT magic:

" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "%jsroot on" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Cell #3

\n", "

Next we have to open the data that we want to analyze. It is stored in a _*.root_ file that consists of a tree having branches and leaves.

\n", "

As you can see, we are reading the data directly from the source! but you can read the file locally too.

" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "TFile *file = TFile::Open(\"http://opendata.atlas.cern/release/samples/MC/mc_147770.Zee.root\");" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Cell #4

\n", "

The next step is to define a tree named (we called _tree_) to get the data out of the _*.root_ file, that is into a tree called _mini_:

" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "TTree *tree = (TTree*) file->Get(\"mini\");" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Cell #5

\n", "

Now we extract the varibles we want from the dataset. As mentioned before, we will plot the number of leptons:

\n", "

(Note to know more about the content of the ATLAS Open Data datasets, please go to our documentation)

" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "UInt_t lepton_n = -1;\n", "tree->SetBranchAddress(\"lep_n\", &lepton_n);" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Cell #6

\n", "

After the data is opened we create a canvas on which we can draw a histogram. If we do not have a canvas we cannot see our histogram at the end. Its name is _Canvas_ and its header is _a first way to plot a variable_. The two following arguments define the width and the height of the canvas:

" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "TCanvas *canvas = new TCanvas(\"Canvas\",\"a first way to plot a variable\",800,600);" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Cell #7

\n", "

Now we define a histogram that will later be placed on this canvas. Its name is _variable_ and the header of the histogram is _Example plot: Number of leptons_. The three following arguments indicate that this histogram contains 4 so called bins which have a range from 0 to 4.

" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "TH1F *hist = new TH1F(\"variable\",\"Example plot: Number of leptons\",4,0,4);" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Cell #8

\n", "

The following lines are a loop that goes over the data that is stored in the tree and fills the histogram _h_ that we already defined. In this first notebook we don't do any cuts to keep it simple. Accordingly the loop fills the histogram for each event stored in the tree. After the program has looped over all the data it prints the word

\n", "__Done!__." ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Done!\n" ] } ], "source": [ "int nentries, nbytes, i;\n", "nentries = (Int_t)tree->GetEntries();\n", "\n", "for (i = 0; i < nentries; i++)\n", "{\n", " nbytes = tree->GetEntry(i);\n", " hist->Fill(lepton_n);\n", "}\n", "\n", "std::cout << \"Done!\" << std::endl;" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Cell #9

\n", "

After filling the histogram we want to see the results of the analysis. First we draw the histogram on the canvas and then the canvas on which the histogram lies:

" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "hist->Draw();\n", "canvas->Draw();" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "

Cell #10

\n", "

Description of the Variables inside the _mini_ tree in the ATLAS Open Data samples

\n", "\n", "| # variable | branchname | type | description |\n", "| :-----: | ------------- | :-------------: | :-----: |\n", "| 01 | runNumber | int | runNumber |\n", "| 02 | eventNumber | int | eventNumber |\n", "| 03 | channelNumber | int | channelNumber |\n", "| 04 | lbNumber | int | lbNumber |\n", "| 05 | rndRunNumber | int | randomized run number mimicking run number distribution in data |\n", "| 06 | mu | float | average interactions per bunch crossing |\n", "| 07 | mcWeight | float | weight of an MC event |\n", "| 08 | pvxp_n | int | number of primary vertices |\n", "| 09 | isGoodEvent | int | summary of diverse quality flags like hfor |\n", "| 10 | scaleFactor | float | overall scale factor for the preselected event |\n", "| 11 | trigE | bool | boolean whether a standard trigger has fired in the egamma stream |\n", "| 12 | trigM | bool | boolean whether a standard trigger has fired in the muon stream |\n", "| 13 | passGRL | bool | signifies whether event passes the GRL may be put in isGoodEvent |\n", "| 14 | hasGoodVertex | bool | signifies whether the event has at least one good vertex |\n", "| 15 | lep_n | int | number of preselected leptons |\n", "| 16 | lep_truthMatched | vector | boolean indicating whether the lepton is matched to a truth lepton |\n", "| 17 | lep_trigMatched | vector | boolean signifying whether the lepton is the one triggering the event |\n", "| 18 | lep_pt | vector | transverse momentum of the lepton |\n", "| 19 | lep_eta | vector | pseudo-rapidity of the lepton |\n", "| 20 | lep_phi | vector | azimuthal angle of the lepton |\n", "| 21 | lep_E | vector | energy of the lepton |\n", "| 22 | lep_z0 | vector | z-coordinate of the track associated to the lepton wrt. the primary vertex |\n", "| 23 | lep_charge | vector | charge of the lepton |\n", "| 24 | lep_isTight | vector | boolean indicating whether the lepton is of tight quality |\n", "| 25 | lep_flag | vector | bitmask implementing object cuts of the top group |\n", "| 26 | lep_type | vector | number signifying the lepton type (e, mu, tau) of the lepton |\n", "| 27 | lep_ptcone30 | vector | ptcone30 isolation for the lepton |\n", "| 28 | lep_etcone20 | vector | etcone20 isolation for the lepton |\n", "| 28 | lep_trackd0pvunbiased | vector | d0 of the track associated to the lepton at the point of closest approach (p.o.a.) |\n", "| 29 | lep_tracksigd0pvunbiased | vector | d0 signifcance of the track associated to the lepton at the p.o.a. |\n", "| 30 | met_et | float | Transverse energy of the missing momentum vector |\n", "| 31 | met_phi | float | Azimuthal angle of the missing momentum vector |\n", "| 32 | jet_n | int | number of selected jets |\n", "| 33 | jet_pt | vector | transverse momentum of the jet |\n", "| 34 | jet_eta | vector | pseudorapidity of the jet |\n", "| 35 | jet_phi | vector | azimuthal angle of the jet |\n", "| 36 | jet_E | vector | energy of the jet |\n", "| 37 | jet_m | vector | invariant mass of the jet |\n", "| 38 | jet_jvf | vector | JetVertexFraction of the jet |\n", "| 39 | jet_flag | vector | bitmask implementing object cuts of the top group |\n", "| 40 | jet_trueflav | vector | true flavor of the jet |\n", "| 41 | jet_truthMatched | vector | information whether the jet matches a jet on truth level |\n", "| 42 | jet_SV0 | vector | SV0 weight of the jet |\n", "| 43 | jet_MV1 | vector | MV1 weight of the jet |\n", "| 44 | scaleFactor_BTAG | float | scalefactor for btagging |\n", "| 45 | scaleFactor_ELE | float | scalefactor for electron efficiency |\n", "| 46 | scaleFactor_JVFSF | float | scalefactor for jet vertex fraction |\n", "| 47 | scaleFactor_MUON | float | scalefactor for muon efficiency |\n", "| 48 | scaleFactor_PILEUP | float | scalefactor for pileup reweighting |\n", "| 49 | scaleFactor_TRIGGER | float | scalefactor for trigger |\n", "| 50 | scaleFactor_ZVERTEX | float | scalefactor for z-vertex reweighting |" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
" ] } ], "metadata": { "kernelspec": { "display_name": "ROOT C++", "language": "c++", "name": "root" }, "language_info": { "codemirror_mode": "text/x-c++src", "file_extension": ".C", "mimetype": " text/x-c++src", "name": "c++" } }, "nbformat": 4, "nbformat_minor": 2 }