1 | #very simple EventSelection class aimed at demonstrating the
|
---|
2 | #typical implementation of an EventSelection class
|
---|
3 |
|
---|
4 | #On purpose, the categories are not in any "logical" order, and there is some redundant check when testing the category.
|
---|
5 | #This is mostly for illustration.
|
---|
6 |
|
---|
7 | # requirements:
|
---|
8 | # event.muons
|
---|
9 | # event.electrons
|
---|
10 | # event.jets
|
---|
11 |
|
---|
12 | # the list of category names
|
---|
13 | categoryNames = [ "MuonChannel/SingleMuon", "ElectronChannel/SingleElectron", "ElectronChannel/Jet", "MuonChannel/DoubleMuon", "ElectronChannel/DoubleElectron" ]
|
---|
14 |
|
---|
15 | def eventCategory(event):
|
---|
16 | """Check analysis requirements for various steps
|
---|
17 | and return a tuple of data used to decide
|
---|
18 | to what category an event belong """
|
---|
19 | categoryData = [ ]
|
---|
20 | # 0: number of muons
|
---|
21 | categoryData.append(event.muons.GetEntries())
|
---|
22 | # 1: number of electrons
|
---|
23 | categoryData.append(event.electrons.GetEntries())
|
---|
24 | # 2: number of jets
|
---|
25 | categoryData.append(event.jets.GetEntries())
|
---|
26 | # 3: Pt of the leading muon > 2GeV
|
---|
27 | if event.muons.GetEntries():
|
---|
28 | categoryData.append(event.muons[0].PT>1.)
|
---|
29 | else:
|
---|
30 | categoryData.append(False)
|
---|
31 | # 4: Pt of the leading electron > 2 GeV
|
---|
32 | if event.electrons.GetEntries():
|
---|
33 | categoryData.append(event.electrons[0].PT>1.)
|
---|
34 | else:
|
---|
35 | categoryData.append(False)
|
---|
36 | # DONE
|
---|
37 | return categoryData
|
---|
38 |
|
---|
39 | def isInCategory(category, categoryData):
|
---|
40 | """Check if the event enters category X, given the tuple computed by eventCategory."""
|
---|
41 | if category==0:
|
---|
42 | return categoryData[0]>0
|
---|
43 | elif category==1:
|
---|
44 | return categoryData[1]>0
|
---|
45 | elif category==2:
|
---|
46 | return categoryData[2]>0
|
---|
47 | elif category==3:
|
---|
48 | return isInCategory(0,categoryData) and categoryData[3]==True
|
---|
49 | elif category==4:
|
---|
50 | return isInCategory(1,categoryData) and categoryData[4]==True
|
---|
51 | else:
|
---|
52 | return False
|
---|
53 |
|
---|