20
#include "src/common_cpp/API/PyWrapMapBase.hh"
22
#include "src/common_cpp/DataStructure/Data.hh"
23
#include "src/common_cpp/DataStructure/GlobalEvent.hh"
24
#include "src/common_cpp/DataStructure/ReconEvent.hh"
25
#include "src/common_cpp/DataStructure/Spill.hh"
27
#include "src/common_cpp/Globals/GlobalsManager.hh"
28
#include "src/common_cpp/Recon/Global/TrackMatching.hh"
29
#include "src/common_cpp/Utils/Globals.hh"
31
#include "src/legacy/Config/MiceModule.hh"
18
33
#include "src/map/MapCppGlobalTrackMatching/MapCppGlobalTrackMatching.hh"
20
#include "src/common_cpp/DataStructure/Data.hh"
21
#include "Interface/Squeak.hh"
22
#include "src/common_cpp/Converter/DataConverters/JsonCppSpillConverter.hh"
23
#include "src/common_cpp/Converter/DataConverters/CppJsonSpillConverter.hh"
24
#include "src/common_cpp/API/PyWrapMapBase.hh"
29
37
PyMODINIT_FUNC init_MapCppGlobalTrackMatching(void) {
30
PyWrapMapBase<MAUS::MapCppGlobalTrackMatching>::PyWrapMapBaseModInit
38
PyWrapMapBase<MapCppGlobalTrackMatching>::PyWrapMapBaseModInit
31
39
("MapCppGlobalTrackMatching", "", "", "", "");
38
46
void MapCppGlobalTrackMatching::_birth(const std::string& argJsonConfigDocument) {
47
if (!Globals::HasInstance()) {
48
GlobalsManager::InitialiseGlobals(argJsonConfigDocument);
39
50
// Check if the JSON document can be parsed, else return error only.
40
51
_configCheck = false;
41
52
bool parsingSuccessful = _reader.parse(argJsonConfigDocument, _configJSON);
42
53
if (!parsingSuccessful) {
43
throw MAUS::Exception(Exception::recoverable,
44
"Failed to parse configuration",
45
"MapCppGlobalTrackMatching::birth");
54
throw Exception(Exception::recoverable,
55
"Failed to parse configuration",
56
"MapCppGlobalTrackMatching::birth");
47
58
_configCheck = true;
48
_classname = "MapCppGlobalTrackMatching";
59
_mapper_name = "MapCppGlobalTrackMatching";
60
_pid_hypothesis_string = _configJSON["track_matching_pid_hypothesis"].asString();
61
Json::Value track_matching_tolerances = _configJSON["track_matching_tolerances"];
62
_matching_tolerances["TOF0"] = std::make_pair(
63
track_matching_tolerances["TOF0x"].asDouble(),
64
track_matching_tolerances["TOF0y"].asDouble());
65
_matching_tolerances["TOF1"] = std::make_pair(
66
track_matching_tolerances["TOF1x"].asDouble(),
67
track_matching_tolerances["TOF1y"].asDouble());
68
_matching_tolerances["TOF2"] = std::make_pair(
69
track_matching_tolerances["TOF2x"].asDouble(),
70
track_matching_tolerances["TOF2y"].asDouble());
71
_matching_tolerances["KL"] = std::make_pair(10000,
72
track_matching_tolerances["KLy"].asDouble());
73
_energy_loss = _configJSON["track_matching_energy_loss"].asBool();
74
std::string geo_filename = _configJSON["reconstruction_geometry_filename"].asString();
75
MiceModule* geo_module = new MiceModule(geo_filename);
76
std::vector<const MiceModule*> tofs =
77
geo_module->findModulesByPropertyString("Detector", "TOF");
78
double tof12_cdt = ((tofs.at(2)->globalPosition().z() -
79
tofs.at(1)->globalPosition().z())/299.791);
80
_matching_tolerances["TOF12dT"] = std::make_pair(
81
tof12_cdt/track_matching_tolerances["TOF12maxSpeed"].asDouble(),
82
tof12_cdt/track_matching_tolerances["TOF12minSpeed"].asDouble());
51
85
void MapCppGlobalTrackMatching::_death() {
54
void MapCppGlobalTrackMatching::_process(MAUS::Data* data_cpp) const {
88
void MapCppGlobalTrackMatching::_process(Data* data_cpp) const {
55
89
// Read string and convert to a Json object
57
throw MAUS::Exception(Exception::recoverable,
59
"MapCppGlobalTrackMatching::_process");
91
throw Exception(Exception::recoverable,
93
"MapCppGlobalTrackMatching::_process");
61
95
if (!_configCheck) {
62
throw MAUS::Exception(Exception::recoverable,
63
"Birth has not been successfully called",
64
"MapCppGlobalTrackMatching::_process");
96
throw Exception(Exception::recoverable,
97
"Birth has not been successfully called",
98
"MapCppGlobalTrackMatching::_process");
67
const MAUS::Spill* spill = data_cpp->GetSpill();
69
MAUS::ReconEventPArray* recon_events = spill->GetReconEvents();
100
const Spill* spill = data_cpp->GetSpill();
102
ReconEventPArray* recon_events = spill->GetReconEvents();
71
103
if (!recon_events) {
75
MAUS::ReconEventPArray::iterator recon_event_iter;
76
for (recon_event_iter = recon_events->begin();
77
recon_event_iter != recon_events->end();
107
for (auto recon_event_iter = recon_events->begin();
108
recon_event_iter != recon_events->end();
109
++recon_event_iter) {
79
110
// Load the ReconEvent, and import it into the GlobalEvent
80
MAUS::ReconEvent* recon_event = (*recon_event_iter);
81
MAUS::GlobalEvent* global_event = recon_event->GetGlobalEvent();
82
MAUS::recon::global::TrackMatching track_matching;
83
track_matching.FormTracks(global_event, _classname);
111
ReconEvent* recon_event = (*recon_event_iter);
112
GlobalEvent* global_event = recon_event->GetGlobalEvent();
115
recon::global::TrackMatching
116
track_matching(global_event, _mapper_name, _pid_hypothesis_string,
117
_matching_tolerances, 10.0, _energy_loss);
118
track_matching.USTrack();
119
track_matching.DSTrack();
120
track_matching.throughTrack();