~christopher-hunt08/maus/maus_integrated_kalman

« back to all changes in this revision

Viewing changes to src/map/MapCppGlobalTrackMatching/MapCppGlobalTrackMatching.cc

merging in changes in merge branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 *
16
16
 */
17
17
 
 
18
#include <vector>
 
19
 
 
20
#include "src/common_cpp/API/PyWrapMapBase.hh"
 
21
 
 
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"
 
26
 
 
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"
 
30
 
 
31
#include "src/legacy/Config/MiceModule.hh"
 
32
 
18
33
#include "src/map/MapCppGlobalTrackMatching/MapCppGlobalTrackMatching.hh"
19
34
 
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"
25
 
 
26
 
 
27
35
namespace MAUS {
28
36
 
29
37
  PyMODINIT_FUNC init_MapCppGlobalTrackMatching(void) {
30
 
    PyWrapMapBase<MAUS::MapCppGlobalTrackMatching>::PyWrapMapBaseModInit
 
38
    PyWrapMapBase<MapCppGlobalTrackMatching>::PyWrapMapBaseModInit
31
39
                                    ("MapCppGlobalTrackMatching", "", "", "", "");
32
40
  }
33
41
 
36
44
  }
37
45
 
38
46
  void MapCppGlobalTrackMatching::_birth(const std::string& argJsonConfigDocument) {
 
47
    if (!Globals::HasInstance()) {
 
48
      GlobalsManager::InitialiseGlobals(argJsonConfigDocument);
 
49
    }
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");
46
57
    }
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());
49
83
  }
50
84
 
51
85
  void MapCppGlobalTrackMatching::_death() {
52
86
  }
53
87
 
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
56
90
    if (!data_cpp) {
57
 
        throw MAUS::Exception(Exception::recoverable,
58
 
                              "data_cpp was NULL",
59
 
                              "MapCppGlobalTrackMatching::_process");
 
91
        throw Exception(Exception::recoverable,
 
92
                        "data_cpp was NULL",
 
93
                        "MapCppGlobalTrackMatching::_process");
60
94
    }
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");
65
99
    }
66
 
 
67
 
    const MAUS::Spill* spill = data_cpp->GetSpill();
68
 
 
69
 
    MAUS::ReconEventPArray* recon_events = spill->GetReconEvents();
70
 
 
 
100
    const Spill* spill = data_cpp->GetSpill();
 
101
 
 
102
    ReconEventPArray* recon_events = spill->GetReconEvents();
71
103
    if (!recon_events) {
72
104
      return;
73
105
    }
74
106
 
75
 
    MAUS::ReconEventPArray::iterator recon_event_iter;
76
 
    for (recon_event_iter = recon_events->begin();
77
 
         recon_event_iter != recon_events->end();
78
 
         ++recon_event_iter) {
 
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();
 
113
 
 
114
      if (global_event) {
 
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();
 
121
      }
84
122
    }
85
123
  }
86
124
} // ~MAUS