Jpp  18.4.0
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 JTOOLS::JQuantile 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 135 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 143 of file JPerth.cc.

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

Destructor.

Definition at line 213 of file JPerth.cc.

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

Member Data Documentation

JTOOLS::JQuantile JRECONSTRUCTION::JPerth::Q
static

Definition at line 230 of file JPerth.cc.

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

Definition at line 233 of file JPerth.cc.

input_type JRECONSTRUCTION::JPerth::input
private

Definition at line 234 of file JPerth.cc.

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

Definition at line 235 of file JPerth.cc.

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

Definition at line 236 of file JPerth.cc.

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

Definition at line 237 of file JPerth.cc.

bool JRECONSTRUCTION::JPerth::stop
private

Definition at line 238 of file JPerth.cc.


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