Jpp  18.6.0-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
JRECONSTRUCTION::JPerth Struct Reference

Thread pool for fits to data. More...

Public Member Functions

 JPerth (const JRegressorStorage_t &storage, const data_type &data, const size_t ns)
 Constructor. More...
 
 ~JPerth ()
 Destructor. More...
 

Static Public Attributes

static JMATH::JQuantile_t Q
 

Private Attributes

std::vector< std::thread > workers
 
input_type input
 
std::mutex in
 
std::mutex out
 
std::condition_variable cv
 
bool stop
 

Detailed Description

Thread pool for fits to data.

Definition at line 138 of file JPerth.cc.

Constructor & Destructor Documentation

JRECONSTRUCTION::JPerth::JPerth ( const JRegressorStorage_t storage,
const data_type data,
const size_t  ns 
)
inline

Constructor.

Parameters
storagestorage for PDFs
datadata
nsnumber of threads

Definition at line 146 of file JPerth.cc.

148  :
149  input(data),
150  stop(false)
151  {
152  using namespace std;
153  using namespace JPP;
154 
155  Q.reset();
156 
157  for (size_t i = 0; i < ns; ++i) {
158 
159  thread worker([this, storage]() {
160 
161  JRegressor_t regressor(storage);
162 
163  regressor.parameters.resize(5);
164 
165  regressor.parameters[0] = JLine3Z::pX();
166  regressor.parameters[1] = JLine3Z::pY();
167  regressor.parameters[2] = JLine3Z::pT();
168  regressor.parameters[3] = JLine3Z::pDX();
169  regressor.parameters[4] = JLine3Z::pDY();
170 
172  JLine3Z value;
173 
174  for ( ; ; ) {
175 
176  {
177  unique_lock<mutex> lock(in);
178 
179  cv.wait(lock, [this]() { return stop || this->input.hasNext(); });
180 
181  if (stop && !this->input.hasNext()) {
182  return;
183  }
184 
185  const event_type* evt = this->input.next();
186 
187  // re-organise data
188 
189  data.clear();
190 
191  for (map_type::const_iterator p = evt->data.begin(); p != evt->data.end(); ++p) {
192  copy(p->second.begin(), p->second.end(), back_inserter(data));
193  }
194 
195  value = evt->value;
196  }
197 
198  const double chi2 = regressor(value, data.begin(), data.end());
199 
200  {
201  unique_lock<mutex> lock(out);
202 
203  Q.put(chi2);
204  }
205  }
206  });
207 
208  workers.emplace_back(std::move(worker));
209  }
210  }
Template definition of a data regressor of given model.
Definition: JRegressor.hh:70
static JMATH::JQuantile_t Q
Definition: JPerth.cc:233
std::vector< size_t > ns
void put(const double x)
Put value.
Definition: JQuantile_t.hh:46
Data structure for fit of straight line in positive z-direction.
Definition: JLine3Z.hh:36
static parameter_type pT()
Definition: JLine1Z.hh:182
std::condition_variable cv
Definition: JPerth.cc:240
Auxiliary data structure to store data and fit in memory.
Definition: JPerth.cc:76
static parameter_type pDX()
Definition: JLine3Z.hh:319
virtual const pointer_type & next()=0
Get next element.
virtual bool hasNext()=0
Check availability of next element.
std::vector< std::thread > workers
Definition: JPerth.cc:236
static parameter_type pY()
Definition: JLine1Z.hh:181
static parameter_type pDY()
Definition: JLine3Z.hh:320
static parameter_type pX()
Definition: JLine1Z.hh:180
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
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:162
void reset()
Reset.
Definition: JQuantile_t.hh:34
JRECONSTRUCTION::JPerth::~JPerth ( )
inline

Destructor.

Definition at line 216 of file JPerth.cc.

217  {
218  using namespace std;
219 
220  {
221  unique_lock<mutex> lock(in);
222 
223  stop = true;
224  }
225 
226  cv.notify_all();
227 
228  for (auto& worker : workers) {
229  worker.join();
230  }
231  }
std::condition_variable cv
Definition: JPerth.cc:240
std::vector< std::thread > workers
Definition: JPerth.cc:236

Member Data Documentation

JMATH::JQuantile_t JRECONSTRUCTION::JPerth::Q
static

Definition at line 233 of file JPerth.cc.

std::vector<std::thread> JRECONSTRUCTION::JPerth::workers
private

Definition at line 236 of file JPerth.cc.

input_type JRECONSTRUCTION::JPerth::input
private

Definition at line 237 of file JPerth.cc.

std::mutex JRECONSTRUCTION::JPerth::in
private

Definition at line 238 of file JPerth.cc.

std::mutex JRECONSTRUCTION::JPerth::out
private

Definition at line 239 of file JPerth.cc.

std::condition_variable JRECONSTRUCTION::JPerth::cv
private

Definition at line 240 of file JPerth.cc.

bool JRECONSTRUCTION::JPerth::stop
private

Definition at line 241 of file JPerth.cc.


The documentation for this struct was generated from the following file: