Manual

User Manual:

Open the PDF directly: View PDF PDF.
Page Count: 14

DownloadManual
Open PDF In BrowserView PDF
SKFlatAnalyzer User Guide
Jae Sung Kim
Seoul National University
jae.sung.kim@cern.ch
January 30, 2019

Contents
1 Introduction
1.1 SKFlat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.2 SKFlatAnalyzer . . . . . . . . . . . . . . . . . . . . . . . . . .

2
2
2

2 Directories
2.1 DataFormats/ .
2.2 Analyzers/ . . .
2.3 include/ . . . .
2.4 src/ . . . . . .
2.5 data/$SKFlatV
2.6 python/ . . . .
2.7 script/ . . . . .
2.8 lib/ . . . . . . .

.
.
.
.
.
.
.
.

4
4
4
4
4
4
4
4
4

3 Structure
3.1 Analyzer inheritance . . . . . . . . . . . . . . . . . . . . . . .
3.2 Physics object inheritance . . . . . . . . . . . . . . . . . . . .

5
5
6

4 Analyzer class and submission command
4.1 SKFlatNtuple . . . . . . . . . . . . . . .
4.2 AnalyzerCore . . . . . . . . . . . . . . .
4.3 MyAnalyzer . . . . . . . . . . . . . . . .
4.4 Job macro . . . . . . . . . . . . . . . . .
4.5 SKFlat.py . . . . . . . . . . . . . . . . .
4.6 Simple way for debugging . . . . . . . .

7
7
7
8
8
9
9

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

5 Macro run order
10
5.1 Example of a macro with comments inline . . . . . . . . . . . 10
6 Migration from CATAnalyzer

11

7 Rules for developers
7.1 File/Function/Variable names are important
7.2 Equality operator between float or double .
7.3 std::map is good, but be careful . . . . . . .
7.4 When using random variables.. . . . . . . .

12
12
12
12
13

1

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

1

Introduction

1.1

SKFlat

• A flat ntuple
• Use MiniAOD as an input
• GihHub link : https://github.com/CMSSNU/SKFlatMaker

•

1.2

SKFlatAnalyzer

• ROOT6 based analyzer
• SNU (tamsa1), KISTI and KNU batch are supported by same submission commands (2019.01.22)
• Use SKFlat as an input
• Run over each event, and do the analysis!!
• Construct physics objects using branch elements:

2

Muon mu;
double r c = m u o n r o c h s f −>a t ( i ) ;
double r c e r r = m u o n r o c h s f u p −>a t ( i ) ;
mu. SetMiniAODPt ( muon pt−>a t ( i ) ) ;
mu. SetPtEtaPhiM ( muon pt−>a t ( i ) ∗ rc , muon eta−>a t ( i ) , muon phi
−>a t ( i ) , muon mass−>a t ( i ) ) ;

• GitHub link : https://github.com/CMSSNU/SKFlatAnalyzer

3

2
2.1

Directories
DataFormats/

Physics objects

2.2

Analyzers/

Ntuple handler (SKFlatNtuple) and Analyzers

2.3

include/

Header files

2.4

src/

Source files (define class, functions, ...)

2.5

data/$SKFlatV

Various data files including .root, .txt (e.g., fake rates, scale factors, ...).
Defined as an environment variable, $DATA DIR.

2.6

python/

Python scripts for job submission

2.7

script/

Any useful scripts

2.8

lib/

Compiled shared-libraries moved here

4

3
3.1

Structure
Analyzer inheritance

Figure 1: Diagram of analyzer inheritance.

5

3.2

Physics object inheritance

Figure 2: Diagram of physics object inheritance.

6

4

Analyzer class and submission command
Every analyzer inherits AnalyzerCore
AnalyzerCore inherits SKFlatNtuple

4.1

SKFlatNtuple

• Almost same as the output from TTree::MakeClass()
• SKFlatNtuple::Loop() loops over each event

4.2

AnalyzerCore

• Inherits SKFlatNtuple
• Includes header files of physics objects classes
• Physics analysis functions
s t d : : v e c t o r  AnalyzerCore : : GetAllMuons ( ) ; // r e t u r n a l l
muons
s t d : : v e c t o r  AnalyzerCore : : GetMuons ( T S t r i n g id , double
ptmin , double fetamax ) ; // r e t u r n muons p a s s i n g ID
selection
s t d : : v e c t o r  AnalyzerCore : : SelectMuons ( s t d : : v e c t o r  muons , T S t r i n g id , double ptmin , double fetamax ) ; //
S e l e c t muons p a s s i n g i d out o f pre−c o l l e c t e d muon
collections

• Histogram related functions
F i l l H i s t ( T S t r i n g histname , double val ue , double weight , int
n bi n , double x min , double x max ) ; // h i s t o g r a m i s
saved i n t h e d e f a u l t d i r e c t o r y o f t h e output r o o t f i l e
J S F i l l H i s t ( T S t r i n g s u f f i x , T S t r i n g histname , double val ue ,
double weight , int n bi n , double x min , double x max ) ;
// h i s t o g r a m i s saved i n t h e d i r e c t o r y named ” s u f f i x ” o f
t h e output r o o t f i l e

• (Example)
v e c t o r  e l e c t r o n s = G e t E l e c t r o n s ( param .
Electron Tight ID , 10. , 2.5) ;
f o r ( unsigned int i =0; i :
Replacing existing TH1: RelIso (Potential memory leak).”
• So I recommend you to add directory name as a prefix/suffix of the
histogram name :
Instead of “RelIso” alone, use “RelIso ”+

4.3

MyAnalyzer

• Inherits AnalyzeCore
• Run by the job macro

4.4

Job macro

• Macro will be created automatically by SKFlat.py command
• MyAnalyzer object is declared
• Input sample information ([DATA] DataStream / [MC] Sample name,
input files, xsec, sumW) is set
• Output file path is set
• SKFlatNtuple::Init() is run : Initializing branch element variables
• AnalyzerCore::initializeAnalyzer() is run
– This function is virtual, and can be redefined in ExampleRun
8

– Anything you want to do before the event loop can be done here
– Userflag is supported by python/SKFlat.py, by the option
“−−userflags flag1,flag2,flag3”
– The existence of a flag can be checked by using
AnalyzerCore::HasFlag(TString flag)
• SKFlatNtuple::Loop() is run : loop over events
• AnalyzerCore::WriteHist() is run : write histograms in the output

4.5

SKFlat.py

Script for batch job submission

4.6

Simple way for debugging

When debugging, it is better use the master node rather than using batch
system. Here is a quick intstruction to create a debugging macro script.
Let’s say you want to debug ‘MyAnalzyer’. Then, run (-n 10 can be any
number) :
SKFlayt.py -a MyAnalzyer -n 10 -i  -y  −−no exec
Go to the job directory. It should be :
$SKFlatRunlogDir/ Year  
If in KISTI, you will have run XYZ.C’s. If in SNU or KNU, you will have
job XYZ/run.C’s. Copy one of them (let’s call it as “run.C”) to $SKFlat WD. If SNU or KNU, edit the path for libDataFormats.so and libAnalyzers.so as follows;
R LOAD LIBRARY ( . / l i b / libDataFormats . s o )
R LOAD LIBRARY ( . / l i b / l i b A n a l y z e r s . s o )

Now, “run.C” uses the libraries in $SKFlat WD/lib, which is updated when
you run “make”. So, edit your codes, compile, and then do “root -l -b -q
run.C” in $SKFlat WD.
Here are some useful lines you can add in “run.C” :
• “m.MaxEvent = 1000;” : run 1000 events only
• “m.NSkipEvent = 10;” : skip first 10 events, and then run “m.MaxEvent”
events. If “m.MaxEvent” is not set, run to the end.
• “m.LogEvery = 2” : print current event number for every 2 events.

9

5

Macro run order

5.1
R
R
R
R
R

Example of a macro with comments inline

LOAD
LOAD
LOAD
LOAD
LOAD

LIBRARY( l i b P h y s i c s . s o )
LIBRARY( l i b T r e e . s o )
LIBRARY( l i b H i s t . s o )
LIBRARY ( . / l i b / libDataFormats . s o )
LIBRARY ( . / l i b / l i b A n a l y z e r s . s o )

void run ( ) {
//==== D e c l a r i n g an a n a l y z e r c l a s s i m m e d i a t e l y r u n s f o l l o w i n g s
in orders ;
//==== 1 ) C o n s t r u c t o r o f SKFlatNtuple i s c a l l e d
//==== 2 ) C o n s t r u c t o r o f AnalyzerCore i s c a l l e d
//==== 3 ) C o n s t r u c t o r o f ExampleRun i s c a l l e d
ExampleRun m;
//==== SKFlat n t u p l e d i r e c t o r y s t r u c t u r e . .
m. SetTreeName ( ” r e c o T r e e / SKFlat ” ) ;
//==== DATA o r MC?
m. IsDATA = true ;
//==== I f DATA, PD name
m. DataStream = ” SingleMuon ” ;
//==== DATA y e a r
m. DataYear = 2 0 1 6 ;
//==== F i l e s t o be ran with t h i s macro
m. AddFile ( ” SKFlatNtuple 2016 DATA 100 . r o o t ” ) ;
//==== output r o o t f i l e path
m. S e t O u t f i l e P a t h ( ” h i s t s . r o o t ” ) ;
//==== SKFlatNtuple : : I n i t ( ) , which d o e s SetBranchAddress ( )
m. I n i t ( ) ;
//==== AnalyzerCore : : i n i t i a l i z e A n a l y z e r T o o l s Read h i s t o g r a m s
o r i n i t i a l i z e MCCorrection h e l p e r s o r data−d r i v e n e s t i m a t o r s
m. i n i t i a l i z e A n a l y z e r T o o l s ( ) ;
//==== Any i n i t i a l i z a t i o n j u s t b e f o r e r u n n i n g e v e n t l o o p . This
i s o n l y ran once w i t h i n a macro . For example , you s h o u l d run
AnalyzerCore : : HasFlag ( ) h e r e . More example can be found HERE
m. i n i t i a l i z e A n a l y z e r ( ) ;
//==== F i n a l l y , run e v e n t l o o p s
m. Loop ( ) ;
//==== A l l e v e n t s a r e ran . Now w r i t e h i s t o g r a m s t o t h e output
rootfile
m. W r i t e H i s t ( ) ;
}

10

6

Migration from CATAnalyzer

Direct copy from CATAnalyzer codes to SKFlatAnalyzer won’t work, but
here are some tips.
• FillHist(histname, variable, weight, x min, x max, n bin)
→ FillHist(histname, variable, weight, n bin, x min, x max)
: follow the order of arguments of TH1 in ROOT

11

7

Rules for developers

Some rules you should follow, if you want to make a pull request to the
master branch.

7.1

File/Function/Variable names are important

Let’s spend enough time for naming our new file/function/variable... Good
naming makes programming efficient.

7.2

Equality operator between float or double

Guess what you would get from “root -l -b -q test.C” with below.
f l o a t GetFatJetSF ( f l o a t t a u 2 1 c u t ) {
i f ( t a u 2 1 c u t == 0 . 4 5 ) {
return 0 . 4 5 ;
}
i f ( t a u 2 1 c u t == 0 . 6 ) {
return 0 . 6 ;
}
else {
return 1 . ;
}
}
void t e s t ( ) {
c o u t << ” Value : ” << GetFatJetSF ( 0 . 4 5 ) << e n d l ;
}

Result is Value : 1. It works properly if you change float GetFatJetSF(float tau21cut) to float GetFatJetSF(double tau21cut). However, it is NOT recommended to apply equality operator between floats. If
you really need it, you can do |A − B| < e with a very small e (e.g., 0.001).

7.3

std::map is good, but be careful

We use a lot of std::map in the analyzer; rootfile for MCCorrection are saved
as “std::map histmap”, and histogram can be accessed by
“histmap[key]”. But if you store so many histograms into the map, it spends
so much time to obtain “histmap[mykey]”, because it checks “mykey==key”
12

for each keys. If you have saved thousands of fake-rate histograms into a map
and run a fake estimation, it will take years... If you are applying muon scale
factors, “map hist Muon[YOUR ID]” is ran for each event and each muons.
If you wrote too many IDs in ID/Muon/histmap.txt, you will waste your
time looping over unnecessary keys. To save your time, you can add a “#”
at the beginning of each lines in “ID/Muon/histmap.txt” (i.e., deactivating
it) :
ID SF NUM MediumID DEN genTracks RunAveraged SF ID.root NUM MediumID DEN genTracks eta pt
↓
#ID SF NUM MediumID DEN genTracks RunAveraged SF ID.root NUM MediumID DEN genTracks eta pt
Then histogram for Medium ID will not be saved in the histmap.

7.4

When using random variables..

Some functions use random variables (e.g., smearing from a distribution).
If you use default random seed, your results can be changed everytime you
run the analyzer. Easiest way to avoid this issue is using a combination
of RunNumber and EventNumber as a seed. E.g., seed = RunNumber ×
1000000000 + EventNumber.

13



Source Exif Data:
File Type                       : PDF
File Type Extension             : pdf
MIME Type                       : application/pdf
PDF Version                     : 1.5
Linearized                      : No
Page Count                      : 14
Page Mode                       : UseOutlines
Author                          : 
Title                           : 
Subject                         : 
Creator                         : LaTeX with hyperref package
Producer                        : pdfTeX-1.40.16
Create Date                     : 2019:01:30 10:59:20+01:00
Modify Date                     : 2019:01:30 10:59:20+01:00
Trapped                         : False
PTEX Fullbanner                 : This is pdfTeX, Version 3.14159265-2.6-1.40.16 (TeX Live 2015) kpathsea version 6.2.1
EXIF Metadata provided by EXIF.tools

Navigation menu