Project

General

Profile

SoftwareHints » History » Version 16

Dobbs, Adam, 27 June 2014 12:18

1 1 Dobbs, Adam
h1. Software Hints and Tips
2
3 16 Dobbs, Adam
A presentation giving a tracker software "How To", covering general code design, where things are found, how to run a simulation, and access and analyse output data, is available at:
4
5
document#90
6
7 1 Dobbs, Adam
h2. Running a tracker simulation
8
9
There is a dedicated directory holding top level scripts for producing tracker data within MAUS at:
10
11
<pre>
12
bin/user/scifi
13
</pre>
14
15 7 Dobbs, Adam
For example to run a MAUS simulation of the tracker in the presence of a magnetic field (helical tracks) do the following from the MAUS root directory:
16 1 Dobbs, Adam
17
<pre>
18
source env.sh
19
cd bin/user/scifi
20
./simulate_scifi.py --configuration_file datacard_mc_helical
21
</pre> 
22
23
The equivalent command for no magnetic field (straight tracks) is:
24
25
<pre>
26
./simulate_scifi.py --configuration_file datacard_mc_straight
27
</pre>
28
29
h2. Datacard variables
30
31
Datacard variables control the various parameters passed to MAUS. The variables assume the default values set in src/common_py/ConfigurationDefaults.py unless overridden in a datacard or elsewhere.  Here are a few common variables: 
32
33
* Number of spills. The number of spills to simulate can be set by editing the relevant datacard file and changing the variable 'spill_generator_number_of_spills'.
34
* The number of particles per spill is controlled by the beam variable. This has a number of sub-variables, two of which can be set to alter the number of particles per spill:
35
** 'binomial_n' is the number of attempts at generating a track
36 2 Dobbs, Adam
** 'binomial_p' is the probability an attempt succeeds
37
* Helical pattern recognition can be turned on or off by setting 'SciFiHelicalPROn' to 1 or 0 respectively
38
* Straight pattern recognition can be turned on or off by setting 'SciFiStraightPROn' to 1 or 0 respectively
39 1 Dobbs, Adam
40
h2. Accessing the output data
41
42 15 Dobbs, Adam
Example ROOT and PyROOT scripts for accessing the data are available "here":http://micewww.pp.rl.ac.uk/documents/89
43 11 Dobbs, Adam
44
In order for ROOT to understand the classes we have written, a ROOT dictionary, built automatically by MAUS, must first be loaded. In an interactive ROOT session this done with following command:
45 1 Dobbs, Adam
46
<pre>
47
.L $MAUS_ROOT_DIR/build/libMausCpp.so
48
</pre>
49
50
The equivalent command if using "PyROOT":http://root.cern.ch/drupal/content/pyroot is 
51
52
<pre>
53
import libMausCpp
54
</pre>
55
56
An example ROOT session to open a data file would be:
57
58
<pre>
59
> .L $MAUS_ROOT_DIR/build/libMausCpp.so
60
> TFile f1("maus_output.root")
61
> TBrowser b
62
</pre>
63
64
The equivalent PyROOT session would be:
65
66
<pre>
67 5 Dobbs, Adam
>>> from ROOT import *
68
>>> import libMausCpp
69
>>> f1 = TFile("maus_output.root")
70
>>> b = TBrowser()
71 1 Dobbs, Adam
</pre>
72
73 5 Dobbs, Adam
74 2 Dobbs, Adam
The tracker MC data can then be found by browsing to:
75
<pre>
76
Spill:data:_spill:_mc:_sci_fi_hits
77
</pre>
78 1 Dobbs, Adam
79
The reconstructed data is stored under:
80
<pre>
81
Spill:data:_spill:recon:_scifi_event
82 5 Dobbs, Adam
</pre>
83
84
An example PyROOT session to access some data:
85
86
<pre>
87
>>> from ROOT import *
88
>>> import libMausCpp
89
>>> f1 = TFile("maus_output.root")
90
>>> t1 = f1.Get("Spill")
91
>>> t1
92
<ROOT.TTree object ("Spill") at 0x8bfa970>
93 13 Dobbs, Adam
>>> t1.Draw("_spill._recon._scifi_event._scifitracks._f_chi2")
94 5 Dobbs, Adam
>>> data = MAUS.Data()
95
>>> t1.SetBranchAddress("data", data)
96
>>> t1.GetEntry(1)
97
51435
98
>>> spill = data.GetSpill()
99
>>> spill
100
<ROOT.MAUS::Spill object at 0x92f4a40>
101
>>> spill.GetReconEvents().size()
102
1L
103
>>> revt = spill.GetReconEvents()[0]
104
>>> sfevt = revt.GetSciFiEvent()
105
>>> htrks = sfevt.helicalprtracks()
106
>>> htrks.size()
107
2L
108 12 Dobbs, Adam
>>> spoints = htrks[0].get_spacepoints_pointers()
109
>>> spoints.size()
110 5 Dobbs, Adam
5L
111 12 Dobbs, Adam
>>> sp = spoints[0]
112 5 Dobbs, Adam
>>> sp.get_position().x()
113 1 Dobbs, Adam
8.468833333333333
114
</pre>
115 8 Dobbs, Adam
116
h2. Running the tests
117
118
All branches should pass the testing framework before being pushed up to launchpad.  The full set of tests can be run with:
119
120
<pre>
121
./tests/run_tests.bash
122
</pre>
123
124
This can take quite a while to run however.  Running smaller sections of the tests first will generally save you time.  Two common places where test errors creep in are in cpp style and python style checks.  The cpp style test can be run on its own with:
125
126
<pre>
127
python tests/style/test_cpp_style.py
128
</pre>
129
130
The python style test can be run with:
131
132
<pre>
133
python tests/style/test_python_style.py
134
</pre>
135
136
The unit tests (which include the cpp style check but not the python style check) can be run with:
137
138
<pre>
139
./tests/unit_tests.bash
140
</pre>
141
142 9 Dobbs, Adam
An individual cpp unit test module can also be run. For example, to run just the Pattern Recognition unit tests:
143
144
<pre>
145
build/test_cpp_unit --gtest_filter=PatternRecogntionTest.*
146
</pre>
147
148 8 Dobbs, Adam
Once these all pass, make sure you run full test suite before pushing to launchpad if you have made any significant code changes.
149 10 Dobbs, Adam
150
The MAUS documentation for unit tests can be found on the [[maus::Unit tests|MAUS wiki]].