33
HEP data analysis using ROOT week 3 ROOT Maths and Physics Libraries ROOT Geometries Mark Hodgkinson 1

HEP data analysis using ROOT...• Task 4: Remake the tau visible mass histogram, only for 3-prong taus (Hint: you need only change 1-2 lines of code for this) Then read in the tau

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: HEP data analysis using ROOT...• Task 4: Remake the tau visible mass histogram, only for 3-prong taus (Hint: you need only change 1-2 lines of code for this) Then read in the tau

HEP data analysis using ROOT

week 3 ▪ ROOT Maths and Physics Libraries

▪ ROOT Geometries

Mark Hodgkinson

1

Page 2: HEP data analysis using ROOT...• Task 4: Remake the tau visible mass histogram, only for 3-prong taus (Hint: you need only change 1-2 lines of code for this) Then read in the tau

Week 3

• ROOT maths and physics libraries – vectors and their operations – data modelling with RooFit

• ROOT geometries – internal TGeo classes – interfaces to other platforms

2

Page 3: HEP data analysis using ROOT...• Task 4: Remake the tau visible mass histogram, only for 3-prong taus (Hint: you need only change 1-2 lines of code for this) Then read in the tau

Update on ROOT setup• I noticed the version of ROOT 6.06-04 we have

installed has some libraries missing. • HEP cluster admins recommended I use ROOT

directly from cvmfs (or use your experiment specific setup, if available)

Page 4: HEP data analysis using ROOT...• Task 4: Remake the tau visible mass histogram, only for 3-prong taus (Hint: you need only change 1-2 lines of code for this) Then read in the tau

• Every version available :)

Update on ROOT setup

Page 5: HEP data analysis using ROOT...• Task 4: Remake the tau visible mass histogram, only for 3-prong taus (Hint: you need only change 1-2 lines of code for this) Then read in the tau

ROOT vectors• TLorentzVector – probably the most useful for HEP data

analysis

– initialised to (0,0,0,0)

• Other 2D and 3D vectors available

5

Page 6: HEP data analysis using ROOT...• Task 4: Remake the tau visible mass histogram, only for 3-prong taus (Hint: you need only change 1-2 lines of code for this) Then read in the tau

TLorentzVector

• Assumes beam along z-axis – transverse variables derived accordingly

• e.g. – DeltaPhi: angle between two 4 momenta in transverse plane – Et: transverse energy

• Watch out for issues like phi wraparounds in detector geometries - e.g. in ATLAS phi runs from -Pi to +Pi. 3.14 - -3.13 = 6.27, even though vectors are next to each other in the detector phi coordinate…

• Standard functions like deltaPhi calculations may (or may not) account for such things - TlorentzVector does seem to account for this, whilst your own calculation may not unless you are careful to catch such edge cases.

6

Page 7: HEP data analysis using ROOT...• Task 4: Remake the tau visible mass histogram, only for 3-prong taus (Hint: you need only change 1-2 lines of code for this) Then read in the tau

Extended ROOT vectors

• Extended vector libs now available

–many useful operations • e.g. vector projections

7

Page 8: HEP data analysis using ROOT...• Task 4: Remake the tau visible mass histogram, only for 3-prong taus (Hint: you need only change 1-2 lines of code for this) Then read in the tau

GenVector example• Find mathcoreVectorCollection.C in

$ROOTSYS – copy to your working directory and run

(compiled)

8

Page 9: HEP data analysis using ROOT...• Task 4: Remake the tau visible mass histogram, only for 3-prong taus (Hint: you need only change 1-2 lines of code for this) Then read in the tau

Gen

Vect

or e

xam

ple

9

Page 10: HEP data analysis using ROOT...• Task 4: Remake the tau visible mass histogram, only for 3-prong taus (Hint: you need only change 1-2 lines of code for this) Then read in the tau

GenVector example• Look at the macro – writes an STL vector of LorentzVectors (NOT

TLorentzVector) to a TTree

• Don’t use magic numbers to define fundamental constants!

10

Page 11: HEP data analysis using ROOT...• Task 4: Remake the tau visible mass histogram, only for 3-prong taus (Hint: you need only change 1-2 lines of code for this) Then read in the tau

Task 1• Here you will practice using a TTree to fill some histograms - in this case we need to

make a plot of the visible tau mass. • ROOT files with trees from MC simulation of Z->tautau are available. • Run the example and look at the printed visible tau pt - it is always zero! • In TauTruthClassifiers_MC12.cxx you need to fill in the setVisibleVectors function - use

the getNProng function as an example of what to do. Notice it has a loop on the “daughter” particles of the true tau particle and that similar loops are needed in setVisibleVectors.

• Then create and fill a histogram of the true visible mass in main.cxx (i.e. don’t include invisible particles - remember each tau always decays into a W boson and a neutrino, followed by the W decay to leptons or hadrons), and write it out to a file.

• Need Monte Carlo particle numbering scheme here. • Will use your knowledge of TLorentzVector, c++ vectors, ROOT histograms and file I/O.

Also notice it uses a std::map, but this is setup for you. • Map is c++ way of storing data with a key - it maps a key to a variable. In this case the

key is an integer and the data retrieved is a TLorentzVector. Can find many webpages explaining maps and other c++ data structures (pair, set etc) you might find useful with google search.

• Copy the folder from /home/hodgkinson/ROOTTutorial_Week3 to your own area.

11

Page 12: HEP data analysis using ROOT...• Task 4: Remake the tau visible mass histogram, only for 3-prong taus (Hint: you need only change 1-2 lines of code for this) Then read in the tau

Task

• First run “source /cvmfs/atlas.cern.ch/repo/sw/atlas-gcc/493/x86_64/setup.sh” to get an up to date compiler

• You can build an libraries and an executable by typing “make”.

• Then run the ROOTTutorial executable and specify the range of events to process - in the above we process all events between 0 and 1000.

• Input files have 45500 events in total. • What is actually being run starts from the code inside main.cxx, which in turn calls functions in

the other source code files. • We have instructions to submit jobs to our linux box cluster here - so you might also think about

running jobs in parallel to speed up things, and then hadding the output files. • If you get errors when you add your code in, typical things to do are:

• use google - often lots of hits from stackoverflow website about the exact errors you get • ask someone more experienced for help (people in your office etc)

12

Page 13: HEP data analysis using ROOT...• Task 4: Remake the tau visible mass histogram, only for 3-prong taus (Hint: you need only change 1-2 lines of code for this) Then read in the tau

Compilation• When working on this task you may notice C++ compiler errors

can be rather cryptic… • …perhaps drawback of compiling C++ code. Steeper learning

curve than learning e.g. python. • Bear in mind compiled C++ is significantly faster than

interpreted code (e.g. python) and that compilers find mistakes in your code - so it hopefully won’t crash out whilst processing data.

• If using python heavily prefiltering data with c++ can help (e.g. some of the Sheffield ATLAS people have such a scheme).

• Other options include finding out which algorithms in your code are slow and writing only those in C++ to get past the bottleneck - its possible to use C++ libraries in python.

13

Page 14: HEP data analysis using ROOT...• Task 4: Remake the tau visible mass histogram, only for 3-prong taus (Hint: you need only change 1-2 lines of code for this) Then read in the tau

RooFit

• Introduction from main author W. Wekerke (Nikhef) here.

• As with all software tools, you need to judge if you need this or if native ROOT fitting is enough - it is if all you want to do is fit a simple Gaussian for example.

e.g. for one of my projects, we are just using TH1F->Fit() functionality

14

Page 15: HEP data analysis using ROOT...• Task 4: Remake the tau visible mass histogram, only for 3-prong taus (Hint: you need only change 1-2 lines of code for this) Then read in the tau

• Taken from link on previous slide • Short answer - sufficiently complex fit might be better done in Roofit. • Rootfit is an extension of ROOT, and nowadays comes by default when

you install15

Page 16: HEP data analysis using ROOT...• Task 4: Remake the tau visible mass histogram, only for 3-prong taus (Hint: you need only change 1-2 lines of code for this) Then read in the tau

• Very often hear people talking about ‘Toy MC’ – use parameterisations of input PDFs for speed

• often useful to reweight PDFs to study propagation of errors

• RooFit provides such functionality – worked example

• from https://root.cern.ch/roofit-20-minutes

Simulating data with RooFit

16

Page 17: HEP data analysis using ROOT...• Task 4: Remake the tau visible mass histogram, only for 3-prong taus (Hint: you need only change 1-2 lines of code for this) Then read in the tau

RooFit example

• PDF functions in RooFit – Landau: parameterisation of dE/dx – Argus: empirical function describing n-body

decay – Breit-Wigner: (∗Gaussian) describes a

resonance – Crystal-Ball: radiative energy loss – Decay: can be symmetric and convoluted

17

Page 18: HEP data analysis using ROOT...• Task 4: Remake the tau visible mass histogram, only for 3-prong taus (Hint: you need only change 1-2 lines of code for this) Then read in the tau

RooFit Example• RooRealVar has a name, a title and a range. Optionally can specify a unit as well.

• RooRealVar by default initialises the value at mid-range. • But can also specify both initial value and range.

• Finally can create Gaussian PDF of the mass observable, mes, with a mean and width.

18

Page 19: HEP data analysis using ROOT...• Task 4: Remake the tau visible mass histogram, only for 3-prong taus (Hint: you need only change 1-2 lines of code for this) Then read in the tau

RooFit Example

• We can put the gaussian pdf in a RooPlot, and then draw the RooPlot.

Task 2: Setup a Landau PDF and draw that.19

Page 20: HEP data analysis using ROOT...• Task 4: Remake the tau visible mass histogram, only for 3-prong taus (Hint: you need only change 1-2 lines of code for this) Then read in the tau

RooFit example

• Argus background component

• Signal + Background PDF

// --- Build Argus background PDF --- RooRealVar argpar("argpar","argus shape parameter",-20.0,-100.,-1.) ; RooConstVar argconst("argconst","argus constant",5.291); RooArgusBG argus("argus","Argus PDF",mes,argconst,argpar) ;

// --- Construct signal+background PDF --- RooRealVar nsig("nsig","#signal events",200,0.,10000) ; RooRealVar nbkg("nbkg","#background events",800,0.,10000) ; RooAddPdf sum("sum","g+a",RooArgList(gauss,argus),RooArgList(nsig,nbkg)) ;

20

Page 21: HEP data analysis using ROOT...• Task 4: Remake the tau visible mass histogram, only for 3-prong taus (Hint: you need only change 1-2 lines of code for this) Then read in the tau

RooFit example

• Generate unbinned toy data – and perform Max Likelihood fit// --- Generate a toyMC sample from composite PDF ---RooDataSet *data = sum.generate(mes,2000);

// --- Perform extended ML fit of composite PDF to toy data ---sum.fitTo(*data);

// --- Plot toy data and composite PDF overlaid --- RooPlot* mesframe = mes.frame();data->plotOn(mesframe);sum.plotOn(mesframe); sum.plotOn(mesframe,RooFit::Components(argus),RooFit::LineStyle(kDashed)); mesframe->Draw();

21

Page 22: HEP data analysis using ROOT...• Task 4: Remake the tau visible mass histogram, only for 3-prong taus (Hint: you need only change 1-2 lines of code for this) Then read in the tau

RooFit example

22

Page 23: HEP data analysis using ROOT...• Task 4: Remake the tau visible mass histogram, only for 3-prong taus (Hint: you need only change 1-2 lines of code for this) Then read in the tau

Task• Lets re-use tree2.root, that we generated

in previous lecture tasks.

• We can import the destep variable into a RootDataSet and then use a RootPlot to draw it.

• Task 3: Set up an appropriate PDF and use it to fit this data. Compare this to using native ROOT fit functionality with appropriate shape. 23

Page 24: HEP data analysis using ROOT...• Task 4: Remake the tau visible mass histogram, only for 3-prong taus (Hint: you need only change 1-2 lines of code for this) Then read in the tau

Fitting

• Have only scratched the surface - enough to get you going, but much more you can learn.

• Other tools exist, e.g. HistFitter developed by ATLAS extends Roofit to make it fits of multiple data regions more convenient (e.g. typical ATLAS search for supersymmetry has histograms from 10 signal regions, each of which may have say 6 control and validation regions to constrain the PDFs)

• Task 4: Remake the tau visible mass histogram, only for 3-prong taus (Hint: you need only change 1-2 lines of code for this) Then read in the tau visible mass histogram, choose a shape and do a fit to the mass (use either RooFit or standard Fitting, as you prefer)

• Hint: You will need to run on all 45k events eventually, most of these 3 prong taus decay via the a1 resonance - a Breit-Wigner shape might be a good bet according to the PDG book.

• ROOT tutorials (in tutorials folder underneath $ROOTSYS) there are many Rootfit examples.

24

Page 25: HEP data analysis using ROOT...• Task 4: Remake the tau visible mass histogram, only for 3-prong taus (Hint: you need only change 1-2 lines of code for this) Then read in the tau

ROOT Geometries

• Many HEP experiments use ROOT compatible geometry definitions

• Some cross-platform interfaces – VMC, GEANT, XML, GDML

25

Page 26: HEP data analysis using ROOT...• Task 4: Remake the tau visible mass histogram, only for 3-prong taus (Hint: you need only change 1-2 lines of code for this) Then read in the tau

T2K Near Detector (ND280)

26

Page 27: HEP data analysis using ROOT...• Task 4: Remake the tau visible mass histogram, only for 3-prong taus (Hint: you need only change 1-2 lines of code for this) Then read in the tau

T2K Near Detector (ND280)

27

Page 28: HEP data analysis using ROOT...• Task 4: Remake the tau visible mass histogram, only for 3-prong taus (Hint: you need only change 1-2 lines of code for this) Then read in the tau

ACoRNE

28

Page 29: HEP data analysis using ROOT...• Task 4: Remake the tau visible mass histogram, only for 3-prong taus (Hint: you need only change 1-2 lines of code for this) Then read in the tau

ROOT TGeo

• examples in tutorials/geom – e.g. rootgeom.C

• run it – invoke the OpenGL

viewer

• try some of the others

29

Page 30: HEP data analysis using ROOT...• Task 4: Remake the tau visible mass histogram, only for 3-prong taus (Hint: you need only change 1-2 lines of code for this) Then read in the tau

Interfaces to other platforms

30

Page 31: HEP data analysis using ROOT...• Task 4: Remake the tau visible mass histogram, only for 3-prong taus (Hint: you need only change 1-2 lines of code for this) Then read in the tau

geant4 Virtual MC

• Extension to ROOT – built against Geant4 (or Geant3)

• Permits use of different transport codes without changing user code and geometry – a little beyond the scope of this course

31

Page 32: HEP data analysis using ROOT...• Task 4: Remake the tau visible mass histogram, only for 3-prong taus (Hint: you need only change 1-2 lines of code for this) Then read in the tau

Closing remarks

• Many physics objects and mathematical operations supported – only skimmed surface today

• Don’t rewrite/reinvent unnecessarily – shouldn’t be coding e.g. coordinate

transformations and vector products

• Magic numbers are bad – saw some today

32

Page 33: HEP data analysis using ROOT...• Task 4: Remake the tau visible mass histogram, only for 3-prong taus (Hint: you need only change 1-2 lines of code for this) Then read in the tau

Closing remarks

• Introduced compilation – lots more on this next week

• Next time: –more on compilation – ROOT as a dependency – bindings to other languages

• Any questions?

33