Jpp 20.0.0-27-g39925593c-D
the software that should make you happy
Loading...
Searching...
No Matches
JPlatypus_t.hh
Go to the documentation of this file.
1#ifndef __JACOUSTICS__JPLATYPUS_T__
2#define __JACOUSTICS__JPLATYPUS_T__
3
4#include <string>
5#include <type_traits>
6#include <functional>
7#include <future>
8#include <mutex>
9#include <thread>
10#include <vector>
11
13
14#include "JMath/JQuantile_t.hh"
15
16#include "JTools/JHashMap.hh"
17
18#include "JAcoustics/JHit.hh"
24
25
26namespace JACOUSTICS {}
27namespace JPP { using namespace JACOUSTICS; }
28
29namespace JACOUSTICS {
30
31 /**
32 * Thread pool for global fits using super events.
33 */
34 class JPlatypus {
35 public:
36
39
40 /**
41 * Constructor.
42 *
43 * \param geometry detector geometry
44 * \param emitters emitters geometry
45 * \param velocity sound velocity
46 * \param parameters parameters
47 * \param input input
48 * \param ns number of threads
49 */
50 JPlatypus(const JGeometry& geometry,
51 const JEmitters& emitters,
52 const JSoundVelocity& velocity,
53 const JFitParameters& parameters,
55 const size_t ns) :
56 input(input),
57 stop(false)
58 {
59 using namespace std;
60 using namespace JPP;
61
62 Q.reset();
63
64 for (size_t i = 0; i < ns; ++i) {
65
66 thread worker([this, geometry, emitters, velocity, parameters]() {
67
68 vector<JHit> data;
69
70 for (JKatoomba<JGandalf> katoomba(geometry, velocity, parameters.option); ; ) {
71
72 katoomba.estimator.reset(getMEstimator(parameters.mestimator));
73
74 {
76
77 cv.wait(lock, [this]() { return stop || this->input.hasNext(); });
78
79 if (stop && !this->input.hasNext()) {
80 return;
81 }
82
83 const JSuperEvt* evt = this->input.next();
84
85 data.clear();
86
87 for (JSuperEvt::rx_type::const_iterator hit = evt->rx.begin(); hit != evt->rx.end(); ++hit) {
88
89 data.push_back(JHit(emitters[hit->id],
90 hit->counter,
91 JLocation(hit->string, hit->floor),
92 hit->toa,
93 parameters.sigma_s,
94 hit->weight));
95 }
96
97 katoomba.value = getModel(*evt);
98 }
99
100 const double chi2 = katoomba (data.begin(), data.end()) / katoomba.estimator->getRho(1.0);
101 const double ndf = getWeight(data.begin(), data.end()) - katoomba.value.getN();
102
103 {
105
106 Q.put(chi2 / ndf);
107 }
108 }
109 });
110
111 workers.emplace_back(std::move(worker));
112 }
113 }
114
115
116 /**
117 * Destructor.
118 */
120 {
121 using namespace std;
122
123 {
125
126 stop = true;
127 }
128
129 cv.notify_all();
130
131 for (auto& worker : workers) {
132 worker.join();
133 }
134 }
135
136 static JMATH::JQuantile_t Q; //!< chi2/NDF
137
138 private:
141 std::mutex in;
142 std::mutex out;
143 std::condition_variable cv;
144 bool stop;
145 };
146}
147
148#endif
Acoustic hit.
Acoustic emitter.
Acoustic fit parameters.
General purpose class for hash map of unique elements.
Fit functions of acoustic model.
Acoustic super event fit toolkit.
Acoustic event fit.
Thread pool for global fits using super events.
JLANG::JObjectIterator< JSuperEvt > input_type
std::condition_variable cv
JTOOLS::JHashMap< int, JEmitter > JEmitters
static JMATH::JQuantile_t Q
chi2/NDF
~JPlatypus()
Destructor.
JPlatypus(const JGeometry &geometry, const JEmitters &emitters, const JSoundVelocity &velocity, const JFitParameters &parameters, input_type &input, const size_t ns)
Constructor.
std::vector< std::thread > workers
Logical location of module.
Definition JLocation.hh:40
Interface of object iteration for a single data type.
virtual bool hasNext()=0
Check availability of next element.
virtual const pointer_type & next()=0
Get next element.
Template definition of a multi-dimensional oscillation probability interpolation table.
Auxiliary classes and methods for acoustic position calibration.
JModel getModel(const JEvt &evt)
Get model.
JMEstimator * getMEstimator(const int type)
Get M-Estimator.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
JRECONSTRUCTION::JWeight getWeight
int option
fit option (see JACOUSTICS::JMODEL::JOption_t)
double sigma_s
time-of-arrival resolution [s]
int mestimator
M-estimator (see JFIT::JMEstimator_t)
Acoustics hit.
Implementation for depth dependend velocity of sound.
Acoustic super event fit.
Definition JSuperEvt.hh:38
Auxiliary data structure for average.
General purpose class for hash map of unique keys.
Definition JHashMap.hh:75