18
#include "src/common_cpp/API/PyWrapMapBase.hh"
18
19
#include "src/map/MapCppTrackerRecon/MapCppTrackerRecon.hh"
22
PyMODINIT_FUNC init_MapCppTrackerRecon(void) {
23
PyWrapMapBase<MapCppTrackerRecon>::PyWrapMapBaseModInit
24
("MapCppTrackerRecon", "", "", "", "");
22
MapCppTrackerRecon::MapCppTrackerRecon()
23
: _spill_json(NULL), _spill_cpp(NULL) {
27
MapCppTrackerRecon::MapCppTrackerRecon() : MapBase<Data>("MapCppTrackerRecon") {
26
30
MapCppTrackerRecon::~MapCppTrackerRecon() {
27
if (_spill_json != NULL) {
30
if (_spill_cpp != NULL) {
35
bool MapCppTrackerRecon::birth(std::string argJsonConfigDocument) {
36
_classname = "MapCppTrackerRecon";
39
if (!Globals::HasInstance()) {
40
GlobalsManager::InitialiseGlobals(argJsonConfigDocument);
42
Json::Value *json = Globals::GetConfigurationCards();
43
_helical_pr_on = (*json)["SciFiPRHelicalOn"].asBool();
44
_straight_pr_on = (*json)["SciFiPRStraightOn"].asBool();
45
_kalman_on = (*json)["SciFiKalmanOn"].asBool();
46
_size_exception = (*json)["SciFiClustExcept"].asInt();
47
_min_npe = (*json)["SciFiNPECut"].asDouble();
49
MiceModule* module = Globals::GetReconstructionMiceModules();
50
std::vector<const MiceModule*> modules =
51
module->findModulesByPropertyString("SensitiveDetector", "SciFi");
52
_geometry_helper = SciFiGeometryHelper(modules);
53
_geometry_helper.Build();
55
} catch (Exception& exception) {
56
MAUS::CppErrorHandler::getInstance()->HandleExceptionNoJson(exception, _classname);
57
} catch (std::exception& exc) {
58
MAUS::CppErrorHandler::getInstance()->HandleStdExcNoJson(exc, _classname);
63
bool MapCppTrackerRecon::death() {
67
std::string MapCppTrackerRecon::process(std::string document) {
68
Json::FastWriter writer;
71
read_in_json(document);
72
Spill& spill = *_spill_cpp;
74
try { // ================= Reconstruction =========================
75
if ( spill.GetReconEvents() ) {
76
for ( unsigned int k = 0; k < spill.GetReconEvents()->size(); k++ ) {
77
SciFiEvent *event = spill.GetReconEvents()->at(k)->GetSciFiEvent();
79
if ( event->digits().size() ) {
80
cluster_recon(*event);
83
if ( event->clusters().size() ) {
84
spacepoint_recon(*event);
86
// Pattern Recognition.
87
if ( event->spacepoints().size() ) {
88
pattern_recognition(_helical_pr_on, _straight_pr_on, *event);
92
if ( event->straightprtracks().size() || event->helicalprtracks().size() ) {
96
// print_event_info(*event);
99
std::cout << "No recon events found\n";
102
} catch (Exception& exception) {
106
std::stringstream ss;
107
ss << _classname << " says:" << reader.getFormatedErrorMessages();
108
errors["recon_failed"] = ss.str();
109
(*_spill_json)["errors"] = errors;
110
return writer.write(_spill_json);
112
return writer.write(*_spill_json);
115
void MapCppTrackerRecon::read_in_json(std::string json_data) {
117
Json::Value json_root;
118
Json::FastWriter writer;
120
if (_spill_cpp != NULL) {
126
json_root = JsonWrapper::StringToJson(json_data);
127
SpillProcessor spill_proc;
128
_spill_cpp = spill_proc.JsonToCpp(json_root);
130
std::cerr << "Bad json document" << std::endl;
131
_spill_cpp = new Spill();
132
MAUS::ErrorsMap errors = _spill_cpp->GetErrors();
133
std::stringstream ss;
134
ss << _classname << " says:" << reader.getFormatedErrorMessages();
135
errors["bad_json_document"] = ss.str();
136
_spill_cpp->GetErrors();
140
void MapCppTrackerRecon::save_to_json(Spill &spill) {
141
SpillProcessor spill_proc;
142
if (_spill_json != NULL) {
146
_spill_json = spill_proc.CppToJson(spill, "");
149
void MapCppTrackerRecon::cluster_recon(SciFiEvent &evt) {
33
void MapCppTrackerRecon::_birth(const std::string& argJsonConfigDocument) {
34
if (!Globals::HasInstance()) {
35
GlobalsManager::InitialiseGlobals(argJsonConfigDocument);
37
Json::Value *json = Globals::GetConfigurationCards();
38
_helical_pr_on = (*json)["SciFiPRHelicalOn"].asBool();
39
_straight_pr_on = (*json)["SciFiPRStraightOn"].asBool();
40
_kalman_on = (*json)["SciFiKalmanOn"].asBool();
41
_size_exception = (*json)["SciFiClustExcept"].asInt();
42
_min_npe = (*json)["SciFiNPECut"].asDouble();
44
MiceModule* module = Globals::GetReconstructionMiceModules();
45
std::vector<const MiceModule*> modules =
46
module->findModulesByPropertyString("SensitiveDetector", "SciFi");
47
_geometry_helper = SciFiGeometryHelper(modules);
48
_geometry_helper.Build();
51
void MapCppTrackerRecon::_death() {
54
void MapCppTrackerRecon::_process(Data* data) const {
55
Spill& spill = *(data->GetSpill());
57
if ( spill.GetReconEvents() ) {
58
for ( unsigned int k = 0; k < spill.GetReconEvents()->size(); k++ ) {
59
SciFiEvent *event = spill.GetReconEvents()->at(k)->GetSciFiEvent();
62
if ( event->digits().size() ) {
63
cluster_recon(*event);
66
if ( event->clusters().size() ) {
67
spacepoint_recon(*event);
69
// Pattern Recognition.
70
if ( event->spacepoints().size() ) {
71
pattern_recognition(*event);
75
if ( event->straightprtracks().size() || event->helicalprtracks().size() ) {
79
// print_event_info(*event);
82
std::cout << "No recon events found\n";
86
void MapCppTrackerRecon::cluster_recon(SciFiEvent &evt) const {
150
87
SciFiClusterRec clustering(_size_exception, _min_npe, _geometry_helper.GeometryMap());
151
88
clustering.process(evt);
154
void MapCppTrackerRecon::spacepoint_recon(SciFiEvent &evt) {
91
void MapCppTrackerRecon::spacepoint_recon(SciFiEvent &evt) const {
155
92
SciFiSpacePointRec spacepoints;
156
93
spacepoints.process(evt);
159
void MapCppTrackerRecon::pattern_recognition(const bool helical_pr_on, const bool straight_pr_on,
161
PatternRecognition pr1;
162
pr1.set_verbosity(0);
163
pr1.process(helical_pr_on, straight_pr_on, evt);
96
void MapCppTrackerRecon::pattern_recognition(SciFiEvent &evt) const {
97
PatternRecognition pr1; // Pat rec constructor calls Globals again
98
// We let the Map's helical and straight flags overide the interal pat rec variables for these,
99
// (pulled by pat rec from Globals) as this way we can customise which type runs for
101
pr1.set_helical_pr_on(_helical_pr_on);
102
pr1.set_straight_pr_on(_straight_pr_on);
166
void MapCppTrackerRecon::track_fit(SciFiEvent &evt) {
106
void MapCppTrackerRecon::track_fit(SciFiEvent &evt) const {
167
107
std::vector<KalmanSeed*> seeds;
168
108
size_t number_helical_tracks = evt.helicalprtracks().size();
169
109
size_t number_straight_tracks = evt.straightprtracks().size();
186
126
if ( seeds.size() ) {
187
127
KalmanTrackFit fit;
128
fit.SaveGeometry(_geometry_helper.RefPos(), _geometry_helper.Rot());
188
129
fit.Process(seeds, evt);
192
void MapCppTrackerRecon::print_event_info(SciFiEvent &event) {
193
Squeak::mout(Squeak::info) << event.digits().size() << " "
194
<< event.clusters().size() << " "
195
<< event.spacepoints().size() << "; "
196
<< event.straightprtracks().size() << " "
197
<< event.helicalprtracks().size() << "; ";
198
for ( size_t track_i = 0; track_i < event.scifitracks().size(); track_i++ ) {
199
Squeak::mout(Squeak::info) << " Chi2: " << event.scifitracks()[track_i]->f_chi2() << "; "
200
<< " P-Value: " << event.scifitracks()[track_i]->P_value() << "; ";
202
Squeak::mout(Squeak::info) << std::endl;
133
// void MapCppTrackerRecon::print_event_info(SciFiEvent &event) {
134
// std::cerr << event.digits().size() << " "
135
// << event.clusters().size() << " "
136
// << event.spacepoints().size() << "; "
137
// << event.straightprtracks().size() << " "
138
// << event.helicalprtracks().size() << "; ";
139
// for ( size_t track_i = 0; track_i < event.scifitracks().size(); track_i++ ) {
140
// std::cerr << " Chi2: " << event.scifitracks()[track_i]->f_chi2() << "; "
141
// << " Chi2: " << event.scifitracks()[track_i]->s_chi2() << "; "
142
// << " P-Value: " << event.scifitracks()[track_i]->P_value() << "; ";
144
// std::cerr << std::endl;
146
// Squeak::mout(Squeak::info) << event.digits().size() << " "
147
// << event.clusters().size() << " "
148
// << event.spacepoints().size() << "; "
149
// << event.straightprtracks().size() << " "
150
// << event.helicalprtracks().size() << "; ";
151
// for ( size_t track_i = 0; track_i < event.scifitracks().size(); track_i++ ) {
152
// Squeak::mout(Squeak::info) << " Chi2: " << event.scifitracks()[track_i]->f_chi2() << "; "
153
// << " Chi2: " << event.scifitracks()[track_i]->s_chi2() << "; "
154
// << " P-Value: " << event.scifitracks()[track_i]->P_value() << "; ";
156
// Squeak::mout(Squeak::info) << std::endl;
205
160
} // ~namespace MAUS