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"
Topic attachments
I Attachment History Action Size Date Who Comment
Texttxt SmallAnalysis.py.txt r1 manage 2.2 K 2012-11-22 - 09:55 FelixHoehle  
Texttxt littleHelpers_cff.py.txt r1 manage 1.8 K 2012-11-22 - 09:55 FelixHoehle  
Texttxt patSel_DiLepPF2PAT_cfg.py.txt r1 manage 6.2 K 2012-11-22 - 09:55 FelixHoehle  
Texttxt simpleCutBasedElectronID_cff.py.txt r1 manage 7.6 K 2012-11-22 - 09:55 FelixHoehle  
Edit | Attach | Watch | Print version | History: r1 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r1 - 2012-11-22 - FelixHoehle
 
    • Cern Search Icon Cern Search
    • TWiki Search Icon TWiki Search
    • Google Search Icon Google Search

    Sandbox All webs login

This site is powered by the TWiki collaboration platform Powered by PerlCopyright & 2008-2023 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
or Ideas, requests, problems regarding TWiki? use Discourse or Send feedback