Jpp  18.0.1-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Static Public Attributes | Private Attributes | List of all members
JACOUSTICS::JPlatypus Class Reference

Thread pool for global fits. More...

#include <JPlatypus_t.hh>

Public Member Functions

 JPlatypus (const JGeometry &geometry, const JEmitters &emitters, const JSoundVelocity &velocity, const JFitParameters &parameters, const size_t ns)
 Constructor. More...
 
 ~JPlatypus ()
 Destructor. More...
 
size_t backlog ()
 Get number of pending data. More...
 
void enqueue (const JSuperEvt &evt)
 Queue super event. More...
 

Static Public Attributes

static JTOOLS::JQuantile Q
 chi2/NDF More...
 

Private Attributes

std::vector< std::thread > workers
 
std::queue< JSuperEvtinput
 
std::mutex in
 
std::mutex out
 
std::condition_variable cv
 
bool stop
 

Detailed Description

Thread pool for global fits.

Definition at line 34 of file JPlatypus_t.hh.

Constructor & Destructor Documentation

JACOUSTICS::JPlatypus::JPlatypus ( const JGeometry geometry,
const JEmitters emitters,
const JSoundVelocity velocity,
const JFitParameters parameters,
const size_t  ns 
)
inline

Constructor.

Parameters
geometrydetector geometry
emittersemitters geometry
velocitysound velocity
parametersparameters
nsnumber of threads

Definition at line 45 of file JPlatypus_t.hh.

49  :
50  stop(false)
51  {
52  using namespace std;
53  using namespace JPP;
54 
55  Q.reset();
56 
57  for (size_t i = 0; i < ns; ++i) {
58 
59  thread worker([this, geometry, emitters, velocity, parameters]() {
60 
62 
63  for (JKatoomba<JGandalf> katoomba(geometry, velocity, parameters.option); ; ) {
64 
65  katoomba.estimator.reset(getMEstimator(parameters.mestimator));
66 
67  {
68  unique_lock<mutex> lock(in);
69 
70  cv.wait(lock, [this]() { return stop || !input.empty(); });
71 
72  if (stop && input.empty()) {
73  return;
74  }
75 
76  const JSuperEvt& evt = input.front();
77 
78  data.clear();
79 
80  for (JSuperEvt::rx_type::const_iterator hit = evt.rx.begin(); hit != evt.rx.end(); ++hit) {
81 
82  data.push_back(JHit(emitters[hit->id],
83  hit->counter,
84  JLocation(hit->string, hit->floor),
85  hit->toa,
86  parameters.sigma_s,
87  hit->weight));
88  }
89 
90  katoomba.value = getModel(evt);
91 
92  input.pop();
93  }
94 
95  const double chi2 = katoomba (data.begin(), data.end()) / katoomba.estimator->getRho(1.0);
96  const double ndf = getWeight(data.begin(), data.end()) - katoomba.value.getN();
97 
98  {
99  unique_lock<mutex> lock(out);
100 
101  Q.put(chi2 / ndf);
102  }
103  }
104  });
105 
106  workers.emplace_back(move(worker));
107  }
108  }
JModel getModel(const JEvt &evt)
Get model.
double getWeight(T __begin, T __end)
Get total weight of data points.
Definition: JKatoomba_t.hh:59
void reset()
Reset.
Definition: JQuantile.hh:87
std::vector< size_t > ns
Acoustics hit.
Template specialisation of fit function of acoustic model based on JGandalf minimiser.
Definition: JKatoomba_t.hh:629
Logical location of module.
Definition: JLocation.hh:37
void put(const double x, const double w=1.0)
Put value.
Definition: JQuantile.hh:133
static JTOOLS::JQuantile Q
chi2/NDF
Definition: JPlatypus_t.hh:171
std::queue< JSuperEvt > input
Definition: JPlatypus_t.hh:175
std::vector< std::thread > workers
Definition: JPlatypus_t.hh:174
Acoustic super event fit.
Definition: JSuperEvt.hh:36
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
std::condition_variable cv
Definition: JPlatypus_t.hh:178
JACOUSTICS::JPlatypus::~JPlatypus ( )
inline

Destructor.

Definition at line 114 of file JPlatypus_t.hh.

115  {
116  using namespace std;
117 
118  {
119  unique_lock<mutex> lock(in);
120 
121  stop = true;
122  }
123 
124  cv.notify_all();
125 
126  for (auto& worker : workers) {
127  worker.join();
128  }
129  }
std::vector< std::thread > workers
Definition: JPlatypus_t.hh:174
std::condition_variable cv
Definition: JPlatypus_t.hh:178

Member Function Documentation

size_t JACOUSTICS::JPlatypus::backlog ( )
inline

Get number of pending data.

Returns
number of pending data

Definition at line 137 of file JPlatypus_t.hh.

138  {
139  using namespace std;
140 
141  {
142  unique_lock<mutex> lock(in);
143 
144  return input.size();
145  }
146  }
std::queue< JSuperEvt > input
Definition: JPlatypus_t.hh:175
void JACOUSTICS::JPlatypus::enqueue ( const JSuperEvt evt)
inline

Queue super event.

Parameters
evtsuper event

Definition at line 154 of file JPlatypus_t.hh.

155  {
156  using namespace std;
157 
158  {
159  unique_lock<mutex> lock(in);
160 
161  if (stop) {
162  throw runtime_error("The thread pool has been stopped.");
163  }
164 
165  input.emplace(evt);
166  }
167 
168  cv.notify_one();
169  }
std::queue< JSuperEvt > input
Definition: JPlatypus_t.hh:175
std::condition_variable cv
Definition: JPlatypus_t.hh:178

Member Data Documentation

JTOOLS::JQuantile JACOUSTICS::JPlatypus::Q
static

chi2/NDF

Definition at line 171 of file JPlatypus_t.hh.

std::vector<std::thread> JACOUSTICS::JPlatypus::workers
private

Definition at line 174 of file JPlatypus_t.hh.

std::queue<JSuperEvt> JACOUSTICS::JPlatypus::input
private

Definition at line 175 of file JPlatypus_t.hh.

std::mutex JACOUSTICS::JPlatypus::in
private

Definition at line 176 of file JPlatypus_t.hh.

std::mutex JACOUSTICS::JPlatypus::out
private

Definition at line 177 of file JPlatypus_t.hh.

std::condition_variable JACOUSTICS::JPlatypus::cv
private

Definition at line 178 of file JPlatypus_t.hh.

bool JACOUSTICS::JPlatypus::stop
private

Definition at line 179 of file JPlatypus_t.hh.


The documentation for this class was generated from the following files: