~christopher-hunt08/maus/maus_integrated_kalman

« back to all changes in this revision

Viewing changes to tests/integration/test_scifi/test_scifi_recon_straight/test_scifi_recon_straight.py

  • Committer: Durga Rajaram
  • Date: 2014-07-16 15:13:05 UTC
  • mfrom: (659.1.92 cand)
  • Revision ID: durga@fnal.gov-20140716151305-q27rv1y9p03v9lks
Tags: MAUS-v0.9, MAUS-v0.9.0
MAUS-v0.9.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
#  This file is part of MAUS: http://micewww.pp.rl.ac.uk:8080/projects/maus
 
4
#
 
5
#  MAUS is free software: you can redistribute it and/or modify
 
6
#  it under the terms of the GNU General Public License as published by
 
7
#  the Free Software Foundation, either version 3 of the License, or
 
8
#  (at your option) any later version.
 
9
#
 
10
#  MAUS is distributed in the hope that it will be useful,
 
11
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
#  GNU General Public License for more details.
 
14
#
 
15
#  You should have received a copy of the GNU General Public License
 
16
#  along with MAUS.  If not, see <http://www.gnu.org/licenses/>.
 
17
 
 
18
""" Run the examples and check they return 0 """
 
19
 
 
20
#pylint: disable = E1101
 
21
#pylint: disable = C0103
 
22
 
 
23
import os
 
24
import subprocess as sub
 
25
import unittest
 
26
import ROOT
 
27
import libMausCpp #pylint: disable = W0611
 
28
 
 
29
mrd = os.environ["MAUS_ROOT_DIR"]
 
30
wrk_dir = os.path.join(mrd,
 
31
          "tests/integration/test_scifi/test_scifi_recon_straight/")
 
32
straight_datacard_name = os.path.join(wrk_dir, "datacard_mc_straight")
 
33
straight_root_file_name = os.path.join(wrk_dir, "maus_output_straight.root")
 
34
simulation = os.path.join(wrk_dir, "simulate_scifi.py")
 
35
 
 
36
def run_straight_simulation():
 
37
    """ Run the stright tracks simulation """
 
38
 
 
39
    print "Using " + simulation
 
40
 
 
41
    call_options = [simulation,
 
42
                    "-configuration_file", straight_datacard_name,
 
43
                    "-output_root_file_name", straight_root_file_name,
 
44
                    "-verbose_level", "0"]
 
45
 
 
46
    log_file_name = os.path.join(mrd, "tmp/test_scifi_straight_recon.log")
 
47
    log_file = open(log_file_name, 'w')
 
48
    print 'Running simulate_scifi, logging in', log_file_name
 
49
    proc = sub.Popen(call_options, stdout=log_file, stderr=sub.STDOUT)
 
50
    proc.wait()
 
51
    return proc, log_file_name
 
52
 
 
53
class TestSciFiReconStraight(unittest.TestCase): # pylint: disable=R0904
 
54
    """ Run the scifi straight recon and check output """
 
55
 
 
56
    def test_straight_recon(self):
 
57
        """ TestSciFiRecon: Run the straight simulation and check the output """
 
58
 
 
59
        # Run the simulation and check it completes with return code 0
 
60
        proc, log_file_name = run_straight_simulation()
 
61
        self.assertEqual(proc.returncode, 0, msg="Check log "+log_file_name)
 
62
 
 
63
        # Check the ROOT output is as expected
 
64
        root_file = ROOT.TFile(straight_root_file_name, "READ")
 
65
        data = ROOT.MAUS.Data() # pylint: disable = E1101
 
66
        tree = ROOT.TTree()
 
67
        tree = root_file.Get("Spill")
 
68
        tree.SetBranchAddress("data", data)
 
69
 
 
70
        # Check chi^2 average is reasonably low for straight pat rec tracks
 
71
        tree.Draw(
 
72
          "_spill._recon._scifi_event._scifistraightprtracks._x_chisq>>h1",
 
73
          "_spill._recon._scifi_event._scifistraightprtracks._tracker==0")
 
74
        h1 = ROOT.gDirectory.Get('h1')
 
75
        self.assertLess(h1.GetMean(), 15)
 
76
        self.assertLess(h1.GetRMS(), 15)
 
77
        self.assertGreater(h1.GetEntries(), 190)
 
78
 
 
79
        tree.Draw(
 
80
          "_spill._recon._scifi_event._scifistraightprtracks._y_chisq>>h2",
 
81
          "_spill._recon._scifi_event._scifistraightprtracks._tracker==0")
 
82
        h2 = ROOT.gDirectory.Get('h2')
 
83
        self.assertLess(h2.GetMean(), 15)
 
84
        self.assertLess(h2.GetRMS(), 15)
 
85
        self.assertGreater(h2.GetEntries(), 190)
 
86
 
 
87
        tree.Draw(
 
88
          "_spill._recon._scifi_event._scifistraightprtracks._x_chisq>>h3",
 
89
          "_spill._recon._scifi_event._scifistraightprtracks._tracker==1")
 
90
        h3 = ROOT.gDirectory.Get('h3')
 
91
        self.assertLess(h3.GetMean(), 15)
 
92
        self.assertLess(h3.GetRMS(), 15)
 
93
        self.assertGreater(h3.GetEntries(), 30)
 
94
 
 
95
        tree.Draw(
 
96
          "_spill._recon._scifi_event._scifistraightprtracks._y_chisq>>h4",
 
97
          "_spill._recon._scifi_event._scifistraightprtracks._tracker==1")
 
98
        h4 = ROOT.gDirectory.Get('h4')
 
99
        self.assertLess(h4.GetMean(), 15)
 
100
        self.assertLess(h4.GetRMS(), 15)
 
101
        self.assertGreater(h4.GetEntries(), 30)
 
102
 
 
103
        # Check chi^2 average is reasonably low for straight final tracks
 
104
        tree.Draw("_spill._recon._scifi_event._scifitracks._f_chi2>>h5",
 
105
                  "_spill._recon._scifi_event._scifitracks._tracker==0")
 
106
        h5 = ROOT.gDirectory.Get('h5')
 
107
        self.assertLess(h5.GetMean(), 7)
 
108
        self.assertLess(h5.GetRMS(), 5)
 
109
        self.assertGreater(h5.GetEntries(), 190)
 
110
 
 
111
        tree.Draw("_spill._recon._scifi_event._scifitracks._s_chi2>>h6",
 
112
                  "_spill._recon._scifi_event._scifitracks._tracker==0")
 
113
        h6 = ROOT.gDirectory.Get('h6')
 
114
        self.assertLess(h6.GetMean(), 15)
 
115
        self.assertLess(h6.GetRMS(), 10)
 
116
        self.assertGreater(h6.GetEntries(), 190)
 
117
 
 
118
        tree.Draw("_spill._recon._scifi_event._scifitracks._f_chi2>>h7",
 
119
                  "_spill._recon._scifi_event._scifitracks._tracker==1")
 
120
        h7 = ROOT.gDirectory.Get('h7')
 
121
        self.assertLess(h7.GetMean(), 15)
 
122
        self.assertLess(h7.GetRMS(), 10)
 
123
        self.assertGreater(h7.GetEntries(), 30)
 
124
 
 
125
        tree.Draw("_spill._recon._scifi_event._scifitracks._s_chi2>>h8",
 
126
                  "_spill._recon._scifi_event._scifitracks._tracker==1")
 
127
        h8 = ROOT.gDirectory.Get('h8')
 
128
        self.assertLess(h8.GetMean(), 35)
 
129
        self.assertLess(h8.GetRMS(), 60)
 
130
        self.assertGreater(h8.GetEntries(), 30)
 
131
 
 
132
if __name__ == "__main__":
 
133
    unittest.main()
 
 
b'\\ No newline at end of file'