Jpp  18.3.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
12 #include "JLang/JObjectIterator.hh"
13 
14 #include "JTools/JHashMap.hh"
15 
16 #include "JAcoustics/JHit.hh"
17 #include "JAcoustics/JEmitter.hh"
20 #include "JAcoustics/JSuperEvt.hh"
22 
23 
24 namespace JACOUSTICS {}
25 namespace JPP { using namespace JACOUSTICS; }
26 
27 namespace JACOUSTICS {
28 
29  /**
30  * Thread pool for global fits using super events.
31  */
32  class JPlatypus {
33  public:
34 
37 
38  /**
39  * Constructor.
40  *
41  * \param geometry detector geometry
42  * \param emitters emitters geometry
43  * \param velocity sound velocity
44  * \param parameters parameters
45  * \param input input
46  * \param ns number of threads
47  */
48  JPlatypus(const JGeometry& geometry,
49  const JEmitters& emitters,
50  const JSoundVelocity& velocity,
53  const size_t ns) :
54  input(input),
55  stop(false)
56  {
57  using namespace std;
58  using namespace JPP;
59 
60  Q.reset();
61 
62  for (size_t i = 0; i < ns; ++i) {
63 
64  thread worker([this, geometry, emitters, velocity, parameters]() {
65 
67 
68  for (JKatoomba<JGandalf> katoomba(geometry, velocity, parameters.option); ; ) {
69 
70  katoomba.estimator.reset(getMEstimator(parameters.mestimator));
71 
72  {
73  unique_lock<mutex> lock(in);
74 
75  cv.wait(lock, [this]() { return stop || this->input.hasNext(); });
76 
77  if (stop && !this->input.hasNext()) {
78  return;
79  }
80 
81  const JSuperEvt* evt = this->input.next();
82 
83  data.clear();
84 
85  for (JSuperEvt::rx_type::const_iterator hit = evt->rx.begin(); hit != evt->rx.end(); ++hit) {
86 
87  data.push_back(JHit(emitters[hit->id],
88  hit->counter,
89  JLocation(hit->string, hit->floor),
90  hit->toa,
91  parameters.sigma_s,
92  hit->weight));
93  }
94 
95  katoomba.value = getModel(*evt);
96  }
97 
98  const double chi2 = katoomba (data.begin(), data.end()) / katoomba.estimator->getRho(1.0);
99  const double ndf = getWeight(data.begin(), data.end()) - katoomba.value.getN();
100 
101  {
102  unique_lock<mutex> lock(out);
103 
104  Q.put(chi2 / ndf);
105  }
106  }
107  });
108 
109  workers.emplace_back(std::move(worker));
110  }
111  }
112 
113 
114  /**
115  * Destructor.
116  */
118  {
119  using namespace std;
120 
121  {
122  unique_lock<mutex> lock(in);
123 
124  stop = true;
125  }
126 
127  cv.notify_all();
128 
129  for (auto& worker : workers) {
130  worker.join();
131  }
132  }
133 
134  static JQuantile Q; //!< chi2/NDF
135 
136  private:
139  std::mutex in;
140  std::mutex out;
141  std::condition_variable cv;
142  bool stop;
143  };
144 }
145 
146 #endif
JModel getModel(const JEvt &evt)
Get model.
Acoustic hit.
void reset()
Reset.
Definition: JKatoomba_t.hh:89
double getWeight(T __begin, T __end)
Get total weight of data points.
Definition: JKatoomba_t.hh:61
General purpose class for hash map of unique keys.
Definition: JHashMap.hh:72
General purpose class for hash map of unique elements.
std::vector< size_t > ns
*fatal Wrong number of arguments esac JCookie sh typeset Z DETECTOR typeset Z SOURCE_RUN typeset Z TARGET_RUN set_variable PARAMETERS_FILE $WORKDIR parameters
Definition: diff-Tuna.sh:38
Interface of object iteration for a single data type.
Acoustic emitter.
JPlatypus(const JGeometry &geometry, const JEmitters &emitters, const JSoundVelocity &velocity, const JFitParameters &parameters, input_type &input, const size_t ns)
Constructor.
Definition: JPlatypus_t.hh:48
Acoustics hit.
Acoustic super event fit toolkit.
Acoustic fit parameters.
Template specialisation of fit function of acoustic model based on JGandalf minimiser.
Definition: JKatoomba_t.hh:733
virtual const pointer_type & next()=0
Get next element.
Logical location of module.
Definition: JLocation.hh:37
Acoustic event fit.
JTOOLS::JHashMap< int, JEmitter > JEmitters
Definition: JPlatypus_t.hh:35
static JQuantile Q
chi2/NDF
Definition: JPlatypus_t.hh:134
virtual bool hasNext()=0
Check availability of next element.
std::vector< std::thread > workers
Definition: JPlatypus_t.hh:137
Implementation for depth dependend velocity of sound.
Acoustic super event fit.
Definition: JSuperEvt.hh:36
~JPlatypus()
Destructor.
Definition: JPlatypus_t.hh:117
Thread pool for global fits using super events.
Definition: JPlatypus_t.hh:32
Auxiliary data structure for average.
Definition: JKatoomba_t.hh:76
Fit functions of acoustic model.
void put(const double x)
Put value.
Definition: JKatoomba_t.hh:101
then if[[!-f $DETECTOR]] then JDetector sh $DETECTOR fi cat $WORKDIR trigger_parameters txt<< EOFtrigger3DMuon.enabled=1;trigger3DMuon.numberOfHits=5;trigger3DMuon.gridAngle_deg=1;ctMin=0.0;TMaxLocal_ns=15.0;EOF set_variable TRIGGEREFFICIENCY_TRIGGERED_EVENTS_ONLY INPUT_FILES=() for((i=1;$i<=$NUMBER_OF_RUNS;++i));do JSirene.sh $DETECTOR $JPP_DATA/genhen.km3net_wpd_V2_0.evt.gz $WORKDIR/sirene_ ${i}.root JTriggerEfficiency.sh $DETECTOR $DETECTOR $WORKDIR/sirene_ ${i}.root $WORKDIR/trigger_efficiency_ ${i}.root $WORKDIR/trigger_parameters.txt $JPP_DATA/PMT_parameters.txt INPUT_FILES+=($WORKDIR/trigger_efficiency_ ${i}.root) done for ANGLE_DEG in $ANGLES_DEG[*];do set_variable SIGMA_NS 3.0 set_variable OUTLIERS 3 set_variable OUTPUT_FILE $WORKDIR/matrix\[${ANGLE_DEG}\deg\].root $JPP_DIR/examples/JReconstruction-f"$INPUT_FILES[*]"-o $OUTPUT_FILE-S ${SIGMA_NS}-A ${ANGLE_DEG}-O ${OUTLIERS}-d ${DEBUG}--!fiif[[$OPTION=="plot"]];then if((0));then for H1 in h0 h1;do JPlot1D-f"$WORKDIR/matrix["${^ANGLES_DEG}" deg].root:${H1}"-y"1 2e3"-Y-L TR-T""-\^"number of events [a.u.]"-> o chi2
Definition: JMatrixNZ.sh:106
double sigma_s
time-of-arrival resolution [s]
int mestimator
M-estimator.
JMEstimator * getMEstimator(const int type)
Get M-Estimator.
Definition: JMEstimator.hh:203
JLANG::JObjectIterator< JSuperEvt > input_type
Definition: JPlatypus_t.hh:36
std::condition_variable cv
Definition: JPlatypus_t.hh:141