cflow

package
v0.0.0-...-46257ac Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 26, 2021 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

cflow package exposes types allowing to perform a cut flow on a single file.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Analysis

type Analysis struct {

	// EventMoel implements the Event interface.
	// It requires two functions, namely Event.Vars()
	// and Event.Weight(), to be defined.
	EventModel *Evt

	// Selection applied before applying individual cuts
	// of the cut sequence.
	Preselection func(e Evt) bool

	// Slice of cuts defining each stage of the cut flow.
	// The cuts are cumulated: if an event passes n-th cut,
	// it means it passes cut[0] && cut[1] && ... && cut[n].
	Cuts []Cut

	// List of the name of files to be analyzed.
	FilesName []string

	// Name of the TTree to be analyzed.
	TreeName string
}

Analysis type groups together all needed information to perform a cutflow analysis on a single sample.

Example (BasicCutFlow)
package main

import (
	"github.com/rmadar/tree-gonalyzer/cflow"
)

// User defined event model
type usrEvt struct {
	pt  float32
	eta float32
	phi float32
	pid int32
}

// How to connect the event variables to the original tree
func (e *usrEvt) Vars() []cflow.Var {
	return []cflow.Var{
		{Name: "l_pt", Value: &e.pt},
		{Name: "l_eta", Value: &e.eta},
		{Name: "l_phi", Value: &e.phi},
		{Name: "l_pid", Value: &e.pid},
	}
}

// Definition of the event weight
func (e *usrEvt) Weight() float64 {
	return float64(e.pt / 10.)
}

// Definition of the Cuts
var (
	presel = func(e cflow.Evt) bool {
		return e.(*usrEvt).pid == 11
	}
	cut0 = func(e cflow.Evt) bool {
		return e.(*usrEvt).eta > 0.5
	}
	cut1 = func(e cflow.Evt) bool {
		return e.(*usrEvt).pt > 10
	}
	cut2 = func(e cflow.Evt) bool {
		return e.(*usrEvt).phi < 2.0
	}
)

func main() {

	// List of input files
	files := []string{
		"../testdata/file1.root",
		"../testdata/file2.root",
	}

	// User-defined event model, based on cflow.Evt interface.
	var e cflow.Evt
	e = &usrEvt{}

	// Cut sequence - they are cumulated.
	cutSeq := []cflow.Cut{
		{Name: "Electron channel", Sel: cut0},
		{Name: "pT > 10 GeV", Sel: cut1},
		{Name: "Phi < 2.0 rad", Sel: cut2},
	}

	// Define the cutflow analyzer
	ana := cflow.Analysis{
		EventModel:   &e,
		Preselection: presel,
		Cuts:         cutSeq,
		FilesName:    files,
		TreeName:     "truth",
	}

	// Run the cutflow
	ana.Run()

}
Output:

| Cut name                 | Raw Yields                    | Weighted Yields               |
|                          |                    Abs    Rel |                    Abs    Rel |
|--------------------------|-------------------------------|-------------------------------|
| Electron channel         |            5526   100%   100% |        28230.59   100%   100% |
| pT > 10 GeV              |            5281    96%    96% |        28065.97    99%    99% |
| Phi < 2.0 rad            |            4312    78%    82% |        22874.73    81%    82% |

func (*Analysis) Run

func (ana *Analysis) Run()

Run executes the event loop in order to count raw and weighted yields. The final cutflow is printed in this function, after the event loop. The typical output of this function is:

| Cut name              | Raw Yields                 | Weighted Yields            |
|                       |                 Abs    Rel |                 Abs    Rel |
|-----------------------|----------------------------|----------------------------|
| Electron channel      |         5526   100%   100% |     28230.59   100%   100% |
| pT > 10 GeV           |         5281    96%    96% |     28065.97    99%    99% |
| Phi < 2.0 rad         |         4312    78%    82% |     22874.73    81%    82% |

type Cut

type Cut struct {
	Name string           // Name of the cut.
	Sel  func(e Evt) bool // Function defining the cut.
}

Cut contains the needed information

type Evt

type Evt interface {
	Vars() []Var     // Return the list of needed variables.
	Weight() float64 // Define the weight (from available variables).
}

Event model interface

type Var

type Var struct {
	Name  string      // Name of the branch
	Value interface{} // Pointer of the same type of the stored branch.
}

TreeVar groups the branch name and a value of the proper type, as needed by rtree.ReadVar.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL