Merge lp:~christopher-hunt08/maus/maus_primary_adjuster into lp:maus/merge

Proposed by Christopher Hunt
Status: Merged
Merged at revision: 753
Proposed branch: lp:~christopher-hunt08/maus/maus_primary_adjuster
Merge into: lp:maus/merge
Diff against target: 210 lines (+184/-0)
4 files modified
src/common_py/ConfigurationDefaults.py (+3/-0)
src/map/MapCppPrimaryCorrection/MapCppPrimaryCorrection.cc (+86/-0)
src/map/MapCppPrimaryCorrection/MapCppPrimaryCorrection.hh (+82/-0)
src/map/MapCppPrimaryCorrection/sconscript (+13/-0)
To merge this branch: bzr merge lp:~christopher-hunt08/maus/maus_primary_adjuster
Reviewer Review Type Date Requested Status
MAUS Maintainers Pending
Review via email: mp+352811@code.launchpad.net

Commit message

Adds a mapper than can be used to shift/scale the momenta of primary particles before simulation.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/common_py/ConfigurationDefaults.py'
2--- src/common_py/ConfigurationDefaults.py 2018-06-21 04:06:03 +0000
3+++ src/common_py/ConfigurationDefaults.py 2018-08-09 11:00:11 +0000
4@@ -44,6 +44,9 @@
5 "good_pval":0.02,
6 }
7
8+
9+primary_correction = { 'scale' : 1.0, 'shift' : -10.0 }
10+
11 type_of_dataflow = 'pipeline_single_thread'
12
13 input_json_file_name = "maus_input.json"
14
15=== added directory 'src/map/MapCppPrimaryCorrection'
16=== added file 'src/map/MapCppPrimaryCorrection/MapCppPrimaryCorrection.cc'
17--- src/map/MapCppPrimaryCorrection/MapCppPrimaryCorrection.cc 1970-01-01 00:00:00 +0000
18+++ src/map/MapCppPrimaryCorrection/MapCppPrimaryCorrection.cc 2018-08-09 11:00:11 +0000
19@@ -0,0 +1,86 @@
20+/* This file is part of MAUS: http://micewww.pp.rl.ac.uk:8080/projects/maus
21+ *
22+ * MAUS is free software: you can redistribute it and/or modify
23+ * it under the terms of the GNU General Public License as published by
24+ * the Free Software Foundation, either version 3 of the License, or
25+ * (at your option) any later version.
26+ *
27+ * MAUS is distributed in the hope that it will be useful,
28+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
29+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30+ * GNU General Public License for more details.
31+ *
32+ * You should have received a copy of the GNU General Public License
33+ * along with MAUS. If not, see <http://www.gnu.org/licenses/>.
34+ *
35+ */
36+
37+#include <Python.h>
38+
39+#include <string>
40+#include <vector>
41+
42+#include "src/common_cpp/Utils/Globals.hh"
43+#include "src/common_cpp/Globals/GlobalsManager.hh"
44+#include "src/common_cpp/API/PyWrapMapBase.hh"
45+#include "src/common_cpp/DataStructure/Primary.hh"
46+#include "Geant4/G4ParticleTable.hh"
47+
48+#include "src/map/MapCppPrimaryCorrection/MapCppPrimaryCorrection.hh"
49+
50+namespace MAUS {
51+
52+PyMODINIT_FUNC init_MapCppPrimaryCorrection(void) {
53+ PyWrapMapBase<MAUS::MapCppPrimaryCorrection>::PyWrapMapBaseModInit
54+ ("MapCppPrimaryCorrection",
55+ "",
56+ "",
57+ "",
58+ "");
59+}
60+
61+void MapCppPrimaryCorrection::_birth(const std::string& argJsonConfigDocument) {
62+ if (!Globals::HasInstance()) {
63+ GlobalsManager::InitialiseGlobals(argJsonConfigDocument);
64+ }
65+ Json::Value* json = Globals::GetConfigurationCards();
66+ _momentum_shift = (*json)["primary_correction"]["shift"].asDouble();
67+ _momentum_scale = (*json)["primary_correction"]["scale"].asDouble();
68+}
69+
70+void MapCppPrimaryCorrection::_process(MAUS::Data* data) const {
71+ Spill* spill = data->GetSpill();
72+ std::vector<MCEvent*>* mc = spill->GetMCEvents();
73+
74+ for (std::vector<MCEvent*>::iterator it = mc->begin(); it != mc->end(); ++it) {
75+ Primary* primary = (*it)->GetPrimary();
76+
77+ double p = primary->GetMomentum().Mag();
78+
79+ double new_p = (_momentum_scale*p)+_momentum_shift;
80+
81+ if (new_p < 1.0e-15) {
82+ new_p = 1.0; // 1MeV to stop errors. Really we should skip these events!
83+ }
84+
85+// std::cerr << "Correction p = " << p << " -> " << new_p << std::endl;
86+
87+ ThreeVector vec = primary->GetMomentum();
88+
89+ double scale = new_p / p;
90+
91+ vec.setX(vec.x()*scale);
92+ vec.setY(vec.y()*scale);
93+ vec.setZ(vec.z()*scale);
94+
95+ primary->SetMomentum(vec);
96+
97+ G4ParticleDefinition* particle = G4ParticleTable::GetParticleTable()
98+ ->FindParticle(primary->GetParticleId());
99+ double mass = particle->GetPDGMass();
100+ double energy = sqrt(mass*mass + vec.Mag2());
101+
102+ primary->SetEnergy(energy);
103+ }
104+}
105+}
106
107=== added file 'src/map/MapCppPrimaryCorrection/MapCppPrimaryCorrection.hh'
108--- src/map/MapCppPrimaryCorrection/MapCppPrimaryCorrection.hh 1970-01-01 00:00:00 +0000
109+++ src/map/MapCppPrimaryCorrection/MapCppPrimaryCorrection.hh 2018-08-09 11:00:11 +0000
110@@ -0,0 +1,82 @@
111+/* This file is part of MAUS: http://micewww.pp.rl.ac.uk/projects/maus
112+ *
113+ * MAUS is free software: you can redistribute it and/or modify
114+ * it under the terms of the GNU General Public License as published by
115+ * the Free Software Foundation, either version 3 of the License, or
116+ * (at your option) any later version.
117+ *
118+ * MAUS is distributed in the hope that it will be useful,
119+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
120+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
121+ * GNU General Public License for more details.
122+ *
123+ * You should have received a copy of the GNU General Public License
124+ * along with MAUS. If not, see <http://www.gnu.org/licenses/>.
125+ *
126+ */
127+
128+/** @class MapCppPrimaryCorrection
129+ * Simulate the JSON input and return JSON input
130+ *
131+ */
132+
133+// TODO(Rogers): Error is that we use wrong geant4 devices for this stuff.
134+// Really we should use EventAction to control per spill stuff and
135+// stick multiple tracks from the spill into the same primary
136+
137+
138+#ifndef _SRC_MAP_MAPCPPPRIMARYCORRECTION_HH_
139+#define _SRC_MAP_MAPCPPPRIMARYCORRECTION_HH_
140+
141+// C headers
142+#include <stdlib.h>
143+
144+// C++ headers
145+#include <string>
146+
147+// external libraries
148+#include "json/json.h"
149+
150+// MAUS code
151+#include "src/common_cpp/API/MapBase.hh"
152+
153+namespace MAUS {
154+
155+class MapCppPrimaryCorrection : public MapBase<MAUS::Data> {
156+ public:
157+ /** @brief Sets up the worker
158+ */
159+ MapCppPrimaryCorrection()
160+ : MapBase<MAUS::Data>("MapCppPrimaryCorrection") {
161+ }
162+
163+ ~MapCppPrimaryCorrection() {}
164+
165+ private:
166+ /** @brief Begin the startup procedure for Simulation
167+ *
168+ * @param config a JSON document with the configuration.
169+ */
170+ void _birth(const std::string& argJsonConfigDocument);
171+
172+ /** @brief NULL op - nothing to death
173+ *
174+ * This takes no arguments
175+ */
176+ void _death() {}
177+
178+ /** @brief Track JSON input and return new document
179+ *
180+ * This function will simulate a single spill defined
181+ * in JSON format.
182+ *
183+ * @param document a JSON document for a spill
184+ */
185+ void _process(MAUS::Data* data) const;
186+
187+ double _momentum_shift;
188+ double _momentum_scale;
189+}; // Don't forget this trailing colon!!!!
190+}
191+
192+#endif // _SRC_MAP_MAPCPPPRIMARYCORRECTION_HH_
193
194=== added file 'src/map/MapCppPrimaryCorrection/sconscript'
195--- src/map/MapCppPrimaryCorrection/sconscript 1970-01-01 00:00:00 +0000
196+++ src/map/MapCppPrimaryCorrection/sconscript 2018-08-09 11:00:11 +0000
197@@ -0,0 +1,13 @@
198+import glob, os
199+
200+require_root = True
201+require_g4 = True
202+
203+#get environment and project
204+Import('env', 'project')
205+localenv = env.Clone()
206+
207+dir = 'Interface'
208+srclst = map(lambda x: os.path.join(dir, x), glob.glob(os.path.join(project,dir, '*.cpp')))
209+
210+env.jDev.build_project(localenv, project)

Subscribers

People subscribed via source and target branches