Merge lp:~jan.greis/maus/global-recon-rk into lp:maus/merge

Proposed by Jan Greis
Status: Merged
Merged at revision: 1151
Proposed branch: lp:~jan.greis/maus/global-recon-rk
Merge into: lp:maus/merge
Diff against target: 194 lines (+100/-30)
5 files modified
src/common_cpp/Recon/Global/ImportKLRecon.cc (+76/-25)
src/common_cpp/Recon/Global/ImportKLRecon.hh (+16/-4)
src/common_py/ConfigurationDefaults.py (+4/-0)
src/map/MapCppGlobalReconImport/MapCppGlobalReconImport.cc (+2/-1)
src/map/MapCppGlobalReconImport/MapCppGlobalReconImport.hh (+2/-0)
To merge this branch: bzr merge lp:~jan.greis/maus/global-recon-rk
Reviewer Review Type Date Requested Status
Adam Dobbs Pending
Review via email: mp+308807@code.launchpad.net
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_cpp/Recon/Global/ImportKLRecon.cc'
2--- src/common_cpp/Recon/Global/ImportKLRecon.cc 2016-08-31 11:59:03 +0000
3+++ src/common_cpp/Recon/Global/ImportKLRecon.cc 2016-10-19 13:41:35 +0000
4@@ -25,33 +25,84 @@
5 namespace recon {
6 namespace global {
7
8- void ImportKLRecon::process(const MAUS::KLEvent &kl_event,
9- MAUS::GlobalEvent* global_event,
10- std::string mapper_name) {
11-
12- KLEventCellHit KLEventCellHit = kl_event.GetKLEventCellHit();
13-
14- for (size_t i = 0; i < KLEventCellHit.GetKLCellHitArraySize(); ++i) {
15- KLCellHit KLCellHit = KLEventCellHit.GetKLCellHitArrayElement(i);
16- MAUS::DataStructure::Global::SpacePoint* GlobalKLSpacePoint =
17- new MAUS::DataStructure::Global::SpacePoint();
18- GlobalKLSpacePoint->set_ADC_charge(KLCellHit.GetCharge());
19- GlobalKLSpacePoint->set_ADC_charge_product(KLCellHit.GetChargeProduct());
20- GlobalKLSpacePoint->set_detector(MAUS::DataStructure::Global::kCalorimeter);
21- double x = KLCellHit.GetGlobalPosX();
22- double x_err = KLCellHit.GetErrorX();
23- double y = KLCellHit.GetGlobalPosY();
24- double y_err = KLCellHit.GetErrorY();
25- double z = KLCellHit.GetGlobalPosZ();
26- double z_err = KLCellHit.GetErrorZ();
27- double t = -1000000;
28- double t_err = 1000000;
29+ void ImportKLRecon::process(const MAUS::KLEvent &kl_event, MAUS::GlobalEvent* global_event,
30+ std::string mapper_name, bool merge_cell_hits) {
31+
32+ KLEventCellHit kl_event_cell_hit = kl_event.GetKLEventCellHit();
33+ std::vector<KLCellHit> kl_cell_hits = kl_event_cell_hit.GetKLCellHitArray();
34+ if (kl_cell_hits.size() < 1) {
35+ return;
36+ }
37+ std::sort(kl_cell_hits.begin(), kl_cell_hits.end(), KLCellHitSort);
38+ std::vector<std::vector<size_t> > cell_groupings = AdjacentCellGroupings(kl_cell_hits,
39+ merge_cell_hits);
40+
41+ for (size_t i = 0; i < cell_groupings.size(); i++) {
42+ double chargesum = 0.0, chargeproductsum = 0.0;
43+ double x = 0.0, x_err = 0.0, y = 0.0, y_err = 0.0, z = 0.0, z_err = 0.0;
44+ double weighted_y2 = 0.0;
45+ double t = -1000000, t_err = 1000000;
46+ for (size_t j = 0; j < cell_groupings.at(i).size(); j++) {
47+ KLCellHit kl_cell_hit = kl_cell_hits.at(cell_groupings.at(i).at(j));
48+ double charge = kl_cell_hit.GetCharge();
49+ double chargeproduct = kl_cell_hit.GetChargeProduct();
50+ chargesum += charge;
51+ chargeproductsum += chargeproduct;
52+ x += kl_cell_hit.GetGlobalPosX()*charge;
53+ y += kl_cell_hit.GetGlobalPosY()*charge;
54+ z += kl_cell_hit.GetGlobalPosZ()*charge;
55+ weighted_y2 += kl_cell_hit.GetGlobalPosY()*kl_cell_hit.GetGlobalPosY()*charge;
56+ // Are the same for all, so this way we can easily just pick out the last one
57+ x_err = kl_cell_hit.GetErrorX();
58+ z_err = kl_cell_hit.GetErrorZ();
59+ if (cell_groupings.at(i).size() == 1) {
60+ y_err = kl_cell_hit.GetErrorY();
61+ }
62+ }
63+ x /= chargesum;
64+ y /= chargesum;
65+ z /= chargesum;
66+ if (cell_groupings.at(i).size() != 1) {
67+ weighted_y2 /= chargesum;
68+ y_err = std::sqrt(weighted_y2 - y*y);
69+ }
70 TLorentzVector pos(x, y, z, t);
71 TLorentzVector pos_err(x_err, y_err, z_err, t_err);
72- GlobalKLSpacePoint->set_position(pos);
73- GlobalKLSpacePoint->set_position_error(pos_err);
74- global_event->add_space_point(GlobalKLSpacePoint);
75- }
76+ DataStructure::Global::SpacePoint* global_space_point =
77+ new DataStructure::Global::SpacePoint();
78+ global_space_point->set_ADC_charge(chargesum);
79+ global_space_point->set_ADC_charge_product(chargeproductsum);
80+ global_space_point->set_detector(MAUS::DataStructure::Global::kCalorimeter);
81+ global_space_point->set_position(pos);
82+ global_space_point->set_position_error(pos_err);
83+ global_event->add_space_point(global_space_point);
84+ }
85+ }
86+
87+ std::vector<std::vector<size_t> > ImportKLRecon::AdjacentCellGroupings(
88+ std::vector<KLCellHit> kl_cell_hits, bool merge_cell_hits) {
89+ std::vector<std::vector<size_t> > cell_groupings;
90+ std::vector<size_t> cell_hit_ids;
91+ if (kl_cell_hits.size() == 1) {
92+ cell_hit_ids.push_back(0);
93+ cell_groupings.push_back(cell_hit_ids);
94+ } else {
95+ for (size_t i = 0; i < kl_cell_hits.size() - 1; i++) {
96+ cell_hit_ids.push_back(i);
97+ if (kl_cell_hits.at(i+1).GetCell() != kl_cell_hits.at(i).GetCell() + 1
98+ or !merge_cell_hits) { // If configuration is set not to merge, one std::vector for each
99+ cell_groupings.push_back(cell_hit_ids);
100+ cell_hit_ids.clear();
101+ }
102+ }
103+ cell_hit_ids.push_back(kl_cell_hits.size() - 1);
104+ cell_groupings.push_back(cell_hit_ids);
105+ }
106+ return cell_groupings;
107+ }
108+
109+ bool ImportKLRecon::KLCellHitSort(KLCellHit hit1, KLCellHit hit2) {
110+ return (hit1.GetCell() < hit2.GetCell());
111 }
112
113 } // ~namespace global
114
115=== modified file 'src/common_cpp/Recon/Global/ImportKLRecon.hh'
116--- src/common_cpp/Recon/Global/ImportKLRecon.hh 2014-06-20 10:51:38 +0000
117+++ src/common_cpp/Recon/Global/ImportKLRecon.hh 2016-10-19 13:41:35 +0000
118@@ -47,14 +47,26 @@
119 /// Destructor
120 ~ImportKLRecon() {}
121
122- /** Main process, accepting the MAUS::KLEvent and importing
123+ /** @brief Main process, accepting the MAUS::KLEvent and importing
124 * space points into an existing MAUS::GlobalEvent
125 * @param kl_event The reconstructed KL Event
126 * @param global_event The Global Event, which will be changed
127 */
128- void process(const MAUS::KLEvent &kl_event,
129- MAUS::GlobalEvent* global_event,
130- std::string mapper_name);
131+ void process(const MAUS::KLEvent &kl_event, MAUS::GlobalEvent* global_event,
132+ std::string mapper_name, bool merge_cell_hits);
133+
134+ /** @brief Determine whether groupings of adjacent cells exist in the KLCellHits.
135+ * Returns a vector of vectors of cell numbers appropriately grouped, e.g. [[4],[7,8]]
136+ * If merge_cell_hits is false, all are separated, e.g. [[4],[7],[8]]
137+ */
138+ std::vector<std::vector<size_t> > AdjacentCellGroupings(std::vector<KLCellHit> kl_cell_hits,
139+ bool merge_cell_hits);
140+
141+ /**
142+ * @brief Returns whether the first KLCellHit has a lower cell number than the
143+ * second one. Used to perform an std::sort on a vector of KLCellHits.
144+ */
145+ static bool KLCellHitSort(KLCellHit hit1, KLCellHit hit2);
146
147 private:
148 /// Disallow copy constructor as unnecessary
149
150=== modified file 'src/common_py/ConfigurationDefaults.py'
151--- src/common_py/ConfigurationDefaults.py 2016-09-13 09:30:18 +0000
152+++ src/common_py/ConfigurationDefaults.py 2016-10-19 13:41:35 +0000
153@@ -826,3 +826,7 @@
154 "TOF2":0.0,
155 "KL":0.0
156 }
157+
158+# Whether multiple adjacent cell hits in the KL should be merged into single spacepoints on import
159+# into the global datastructure
160+global_merge_kl_cell_hits = True
161
162=== modified file 'src/map/MapCppGlobalReconImport/MapCppGlobalReconImport.cc'
163--- src/map/MapCppGlobalReconImport/MapCppGlobalReconImport.cc 2016-08-31 11:59:03 +0000
164+++ src/map/MapCppGlobalReconImport/MapCppGlobalReconImport.cc 2016-10-19 13:41:35 +0000
165@@ -55,6 +55,7 @@
166 "MapCppGlobalReconImport::_birth");
167 }
168
169+ _merge_cell_hits = _configJSON["global_merge_kl_cell_hits"].asBool();
170 _configCheck = true;
171 _classname = "MapCppGlobalReconImport";
172 }
173@@ -113,7 +114,7 @@
174 if (recon_event->GetKLEvent()) {
175 MAUS::KLEvent* kl_event = recon_event->GetKLEvent();
176 MAUS::recon::global::ImportKLRecon klrecon_importer;
177- klrecon_importer.process((*kl_event), global_event, _classname);
178+ klrecon_importer.process((*kl_event), global_event, _classname, _merge_cell_hits);
179 }
180 // Import EMR tracks into global event
181 if (recon_event->GetEMREvent()) {
182
183=== modified file 'src/map/MapCppGlobalReconImport/MapCppGlobalReconImport.hh'
184--- src/map/MapCppGlobalReconImport/MapCppGlobalReconImport.hh 2016-08-31 11:59:03 +0000
185+++ src/map/MapCppGlobalReconImport/MapCppGlobalReconImport.hh 2016-10-19 13:41:35 +0000
186@@ -95,6 +95,8 @@
187 Json::Value _configJSON;
188 /// JsonCpp setup
189 Json::Reader _reader;
190+ /// Whether adjacent cell hits should be merged into single spacepoints
191+ bool _merge_cell_hits;
192 /// Mapper name, useful for tracking results...
193 std::string _classname;
194 // Geometry file name

Subscribers

People subscribed via source and target branches