1 |
hegner |
1.1 |
/*!
|
2 |
|
|
|
3 |
llista |
1.2 |
\page PhysicsTools_PythonAnalysis Package PhysicsTools/PythonAnalysis
|
4 |
hegner |
1.1 |
<center>
|
5 |
|
|
<small>
|
6 |
llista |
1.2 |
<a href=http://cmsdoc.cern.ch/swdev/viewcvs/viewcvs.cgi/CMSSW/PhysicsTools/PythonAnalysis/?cvsroot=CMSSW>CVS head for this package</a> -
|
7 |
|
|
<a href=http://cmsdoc.cern.ch/swdev/viewcvs/viewcvs.cgi/CMSSW/PhysicsTools/PythonAnalysis/developers?rev=HEAD&cvsroot=CMSSW&content-type=text/vnd.viewcvs-markup>Administrative privileges</a>
|
8 |
hegner |
1.1 |
</small>
|
9 |
|
|
</center>
|
10 |
|
|
|
11 |
|
|
\section desc Description
|
12 |
|
|
<!-- Short description of what this package is supposed to provide -->
|
13 |
hegner |
1.3 |
Examples of using CMSSW in Python.
|
14 |
|
|
Some helper routines for startup, tab completion and shorter syntax.
|
15 |
|
|
|
16 |
hegner |
1.1 |
|
17 |
|
|
\subsection interface Public interface
|
18 |
hegner |
1.4 |
- <b>cmstools</>: public interface to all modules.
|
19 |
|
|
|
20 |
hegner |
1.1 |
\subsection modules Modules
|
21 |
hegner |
1.3 |
- <b>cmstools.py</b>: prepares environment and defines some commands
|
22 |
|
|
- <b>cmscompleter.py</b>: class for tab completion
|
23 |
|
|
- <b>namespaceDict.py</b>: builds the FWLite namespace (without loading libs)
|
24 |
hegner |
1.1 |
|
25 |
|
|
\subsection tests Unit tests and examples
|
26 |
hegner |
1.4 |
- <b>interactive use</b>: all libraries are loaded automatically when needed. To start set the environment variable <tt>PYTHONPATH</tt>:
|
27 |
|
|
\htmlonly
|
28 |
|
|
<pre>
|
29 |
|
|
export PYTHONPATH=$CMSSW_BASE/src/PhysicsTools/PythonAnalysis/python:$PYTHONPATH (bash)
|
30 |
|
|
setenv PYTHONPATH $CMSSW_BASE/src/PhysicsTools/PythonAnalysis/python:$PYTHONPATH (csh)
|
31 |
|
|
\endhtmlonly
|
32 |
|
|
fire up the python interpreter
|
33 |
|
|
\htmlonly
|
34 |
|
|
<pre>
|
35 |
|
|
python
|
36 |
|
|
\endhtmlonly
|
37 |
|
|
and import cmstools and ROOT:
|
38 |
|
|
\htmlonly
|
39 |
|
|
<pre>
|
40 |
|
|
from cmstools import *
|
41 |
|
|
from ROOT import *
|
42 |
|
|
</pre>
|
43 |
|
|
\endhtmlonly
|
44 |
|
|
That's it.
|
45 |
|
|
|
46 |
llista |
1.2 |
- <b>trackerHits.py</b>: Reads sim event information and creates the files <tt>histo.root</tt>
|
47 |
|
|
and <tt>tofhits.jpg</tt>.
|
48 |
hegner |
1.4 |
\htmlonly
|
49 |
|
|
<ol>
|
50 |
|
|
<li>Prepare the environment and load the cms module:
|
51 |
|
|
<pre>
|
52 |
|
|
from cmstools import *
|
53 |
|
|
from ROOT import *
|
54 |
|
|
</pre>
|
55 |
|
|
<li>Open ROOT file and access branch:
|
56 |
|
|
<pre>
|
57 |
|
|
file = TFile('simevent.root')
|
58 |
|
|
events = file.Get('Events')
|
59 |
|
|
branch = events.GetBranch('PSimHit_r_TrackerHitsTIBLowTof.obj')
|
60 |
|
|
|
61 |
|
|
simHit = std.vector(PSimHit)()
|
62 |
|
|
branch.SetAddress(simHit)
|
63 |
|
|
</pre>
|
64 |
|
|
<li>Prepare histogram and loop over all events to fill it
|
65 |
|
|
<pre>
|
66 |
|
|
histo = TH1F('tofhits', 'Tof of hits', 100, -0.5, 50)
|
67 |
|
|
|
68 |
|
|
for ev in all(events):
|
69 |
|
|
branch.GetEntry(ev)
|
70 |
|
|
for hit in all(simHit):
|
71 |
|
|
histo.Fill(hit.timeOfFlight())
|
72 |
|
|
</pre>
|
73 |
|
|
<li>Save histogram in a file:
|
74 |
|
|
<pre>
|
75 |
|
|
hFile = TFile('histo.root', 'RECREATE')
|
76 |
|
|
histo.Write()
|
77 |
|
|
</pre>
|
78 |
|
|
<li>Plot histogram as a jpg-file:
|
79 |
|
|
<pre>
|
80 |
|
|
gROOT.SetBatch()
|
81 |
|
|
gROOT.SetStyle('Plain')
|
82 |
|
|
|
83 |
|
|
c = TCanvas()
|
84 |
|
|
histo.Draw()
|
85 |
|
|
c.SaveAs('tofhits.jpg')
|
86 |
|
|
</pre>
|
87 |
|
|
</ol>
|
88 |
|
|
\endhtmlonly
|
89 |
|
|
|
90 |
llista |
1.2 |
- <b>howto.txt</b>: short explanation
|
91 |
hegner |
1.1 |
|
92 |
|
|
\section status Status and planned development
|
93 |
|
|
<!-- e.g. completed, stable, missing features -->
|
94 |
|
|
Prototype.
|
95 |
|
|
|
96 |
|
|
<hr>
|
97 |
hegner |
1.4 |
Last updated: 23-MAR-2006 B. Hegner
|
98 |
hegner |
1.1 |
*/
|
99 |
|
|
|