File: 01-basic.py

package info (click to toggle)
fastjet 3.4.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 9,552 kB
  • sloc: cpp: 78,628; python: 6,112; sh: 1,038; fortran: 673; makefile: 636; ansic: 161
file content (60 lines) | stat: -rwxr-xr-x 1,840 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python
"""Simple example to try out fastjet from python, with funcionality similar to
../01-basic.cc

For this script to work, make sure that the installation location for
the fastjet python module (cf. fastjet-config --pythonpath) is
included in your PYTHONPATH environment variable.

"""
from __future__ import print_function

import fastjet as fj
#import gzip

def main():


    # set up our jet definition and a jet selector
    jet_def = fj.JetDefinition(fj.antikt_algorithm, 0.6)
    selector = fj.SelectorPtMin(5.0) & fj.SelectorAbsRapMax(4.5)

    filename = '../data/single-event.dat'
    
    # get the event
    event = read_event(filename)
    # cluster it
    jets = selector(jet_def(event))

    # print out some information about the event and clustering
    print("Event has {0} particles".format(len(event)))
    print("jet definition is:",jet_def)
    print("jet selector is:", selector,"\n")
    
    # print the jets
    print_jets(jets)
    
    # get internal information about one of the jets
    if (len(jets) > 0):
        print("Number of constituents of jets[0] is {0}".format(len(jets[0].constituents())))

#----------------------------------------------------------------------
def print_jets(jets):
    print("{0:>5s} {1:>10s} {2:>10s} {3:>10s}".format("jet #", "pt", "rap", "phi"))
    for ijet in range(len(jets)):
        print("{0:5d} {1:10.3f} {2:10.4f} {3:10.4f}".format(
            ijet, jets[ijet].pt(), jets[ijet].rap(), jets[ijet].phi()))
    
        
#----------------------------------------------------------------------
def read_event(filename):
    f = open(filename, 'r')
    event = []
    for line in f:
        p = line.split()
        event.append(fj.PseudoJet(float(p[0]),float(p[1]),float(p[2]),float(p[3])));

    return event
    
if __name__ == '__main__':
    main()