Fork me on GitHub

source: git/python/DelphesAnalysis/EventSelection.py@ 88a9b72

ImprovedOutputFile Timing dual_readout llp
Last change on this file since 88a9b72 was ae1d49f, checked in by pavel <pavel@…>, 12 years ago

add DelphesAnalysis

  • Property mode set to 100644
File size: 2.1 KB
Line 
1from CPconfig import configuration
2from importlib import import_module
3
4# A proper implementation of the event selection will at least
5# define the following:
6# - categoryNames (list of names of categories)
7# - eventCategory (category data producer)
8# - isInCategory (category definition, from category data)
9
10# the list of category names
11categoryNames = [ ]
12
13def eventCategory(event):
14 """Check analysis requirements for various steps
15 and return a tuple of data used to decide
16 to what category an event belong """
17 raise NotImplementedError
18 return []
19
20def isInCategory(category, categoryData):
21 """Check if the event enters category X, given the tuple computed by eventCategory."""
22 raise NotImplementedError
23 return True
24
25# specific implementation of the "virtual methods" above
26EventSelectionImplementation = __import__(configuration.eventSelection)
27categoryNames = EventSelectionImplementation.categoryNames
28eventCategory = EventSelectionImplementation.eventCategory
29isInCategory = EventSelectionImplementation.isInCategory
30
31# Functions below should not be touched in any implementation.
32
33def eventCategories():
34 """Return the number of catefories """
35 return len(categoryNames)
36
37def categoryName(category):
38 """Return the name of category x"""
39 if category<eventCategories() and category>=0: return categoryNames[category]
40 else: return "None"
41
42def categoriesHierarchy():
43 """Return a hierarchically organized list of categories"""
44 dct = {}
45 for i,item in enumerate(categoryNames):
46 p = dct
47 splitted = item.split('/')
48 for x in splitted[:-1]:
49 p = p.setdefault(x,{})
50 p[splitted[-1]] = i
51 return dct
52
53def prepareAnalysisEvent(event):
54 """Define collections and producers"""
55 for coll in configuration.eventCollections:
56 event.addCollection(coll.label,coll.collection)
57 for prod in configuration.eventProducers:
58 event.addProducer(prod.label,getattr(import_module(prod.module),prod.function),**prod.kwargs)
59 for weight in configuration.eventWeights:
60 events.addWeight(weight.label,getattr(import_module(weight.module),weight.classname)(**weight.kwargs))
61
Note: See TracBrowser for help on using the repository browser.