Accessing collections within PythonFWLite
The basic usage and examples are given here
WorkBookFWLitePython. The structure is very similar to "normal" FWLite written in C++. Each collection of an input file is accessible via an Handle object. This Handle has to be intialised with the datatype of the desired collection and loaded with event.getByLabel. This small snippet shows the procedure:
...
events = Events ('yourInputFile.root')
handle = Handle ('std::vector<pat::Muon>')
label = ("selectedPatMuons")
### the event loop
for event in events:
event.getByLabel (label, handle)
muons = handle.product()
##looping muons
for moun in mouns:
print muon.pt()
...
Each member function of the objects is available and with
PyROOT is possible to create plots directly from root files.
If you are developing a selection it is also possible to ask for the filter decisions within
PythonFWLite. Therefore it is neccessary to have an path for each filter step you apply. The framework saves for each event the decisions of all Paths within the
TriggerResults collection.
myTrigResultslabel=("TriggerResults")
myTrigResultshandle=Handle("edm::TriggerResults")
### the event loop
for event in events:
## if you want to access a collection created by an previous process e.g. HLT for triggers
event.getByLabel((myTrigResultslabel,"","HLT"),myTrigResultshandle)
myTrigResults=myTrigResultshandle.product()
### all Triggers/paths are available by calling myTrigResults[i] with the according i of your desired trigger
### to get the mapping of a certain trigger name to the according index you have to call
TriggerNames=event.object().triggerNames(myTrigResults)
## trigger decisions can be tested with this
if trigResultsHLT[TriggerNamesHLT.triggerIndex("HLT_DoubleMu7_v8")].accept()
print "HLT_DoubleMu7_v8 was accepted"