CMS 3D CMS Logo

Package PhysicsTools/PythonAnalysis
CVS head for this package - Administrative privileges

Description

Examples of using CMSSW in Python. Some helper routines for startup, tab completion and shorter syntax.

Public interface

  • cmstools: public interface to all modules.

Modules

Unit tests and examples

  • interactive use: all libraries are loaded automatically when needed. fire up the python interpreter
    python
    
    and import cmstools and ROOT:
    from PhysicsTools.PythonAnalysis import *
    from ROOT import *
    
    That's it.
  • MCTruth.py: Reads gen event information and prints event number (root version)
  • MCTruth2.py: Reads gen event information and prints event number (using cmstools)
  • trackerHits.py: Reads sim event information and creates the files histo.root and tofhits.jpg.
    1. Prepare the environment and load the cms module:
      from PhysicsTools.PythonAnalysis.cmstools import *
      from ROOT import *
      
    2. Open ROOT file and access branch:
      events = EventTree.('simevents.root')
      
    3. Prepare histogram and loop over all events to fill it
      histo = TH1F('tofhits', 'Tof of hits', 100, -0.5, 50)
      
      for event in events:
          simHits = event.getProduct('PSimHit_r_TrackerHitsTIBLowTof.obj')
          for hit in simHits:
              histo.Fill(hit.timeOfFlight())
      
    4. Save histogram in a file:
      hFile = TFile('histo.root', 'RECREATE')
      histo.Write()
      
    5. Plot histogram as a jpg-file:
      gROOT.SetBatch()
      gROOT.SetStyle('Plain')
      
      c = TCanvas()
      histo.Draw()
      c.SaveAs('tofhits.jpg')
      
  • howto.txt: short explanation

Status and planned development

Prototype.

For more details, refer to the Analysis Tools TWiki on the Software Guide.


Last updated: 03-MAR-2007 B. Hegner