Jpp 20.0.0-195-g190c9e876
the software that should make you happy
Loading...
Searching...
No Matches
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, const int option)
 Constructor.
 
 ~JPerth ()
 Destructor.
 

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 162 of file JPerth.cc.

Constructor & Destructor Documentation

◆ JPerth()

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

Constructor.

Parameters
storagestorage for PDFs
datadata
nsnumber of threads
optionoption

Definition at line 171 of file JPerth.cc.

174 :
175 input(data),
176 stop(false)
177 {
178 using namespace std;
179 using namespace JPP;
180
181 Q.reset();
182
183 for (size_t i = 0; i < ns; ++i) {
184
185 thread worker([this, storage, option]() {
186
187 JRegressor_t regressor(storage);
188
189 regressor.parameters.resize(5);
190
191 regressor.parameters[0] = JLine3Z::pX();
192 regressor.parameters[1] = JLine3Z::pY();
193 regressor.parameters[2] = JLine3Z::pT();
194 regressor.parameters[3] = JLine3Z::pDX();
195 regressor.parameters[4] = JLine3Z::pDY();
196
198 JLine3Z value;
199
200 for ( ; ; ) {
201
202 {
203 unique_lock<mutex> lock(in);
204
205 cv.wait(lock, [this]() { return stop || this->input.hasNext(); });
206
207 if (stop && !this->input.hasNext()) {
208 return;
209 }
210
211 const event_type* evt = this->input.next();
212
213 // re-organise data
214
215 data.clear();
216
217 // 2 => evaluation of the derivative of the chi2 to each fit parameter.
218
219 if (option != 2 || evt->status) {
220 for (map_type::const_iterator p = evt->data.begin(); p != evt->data.end(); ++p) {
221 copy(p->second.begin(), p->second.end(), back_inserter(data));
222 }
223 }
224
225 value = evt->value;
226 }
227
228 if (!data.empty()) {
229
230 const double chi2 = regressor(value, data.begin(), data.end());
231
232 {
233 unique_lock<mutex> lock(out);
234
235 Q.put(chi2);
236 }
237 }
238 }
239 });
240
241 workers.emplace_back(std::move(worker));
242 }
243 }
static parameter_type pY()
Definition JLine1Z.hh:181
static parameter_type pX()
Definition JLine1Z.hh:180
static parameter_type pT()
Definition JLine1Z.hh:182
Data structure for fit of straight line in positive z-direction.
Definition JLine3Z.hh:40
static parameter_type pDY()
Definition JLine3Z.hh:320
static parameter_type pDX()
Definition JLine3Z.hh:319
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
void copy(const JFIT::JEvt::const_iterator __begin, const JFIT::JEvt::const_iterator __end, Evt &out)
Copy tracks.
Template definition of a data regressor of given model.
Definition JRegressor.hh:70
virtual const pointer_type & next() override
Get next element.
virtual bool hasNext() override
Check availability of next element.
void put(const double x)
Put value.
void reset()
Reset.
std::vector< std::thread > workers
Definition JPerth.cc:269
std::condition_variable cv
Definition JPerth.cc:273
static JMATH::JQuantile_t Q
Definition JPerth.cc:266

◆ ~JPerth()

JRECONSTRUCTION::JPerth::~JPerth ( )
inline

Destructor.

Definition at line 249 of file JPerth.cc.

250 {
251 using namespace std;
252
253 {
254 unique_lock<mutex> lock(in);
255
256 stop = true;
257 }
258
259 cv.notify_all();
260
261 for (auto& worker : workers) {
262 worker.join();
263 }
264 }

Member Data Documentation

◆ Q

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

Definition at line 266 of file JPerth.cc.

◆ workers

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

Definition at line 269 of file JPerth.cc.

◆ input

input_type JRECONSTRUCTION::JPerth::input
private

Definition at line 270 of file JPerth.cc.

◆ in

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

Definition at line 271 of file JPerth.cc.

◆ out

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

Definition at line 272 of file JPerth.cc.

◆ cv

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

Definition at line 273 of file JPerth.cc.

◆ stop

bool JRECONSTRUCTION::JPerth::stop
private

Definition at line 274 of file JPerth.cc.


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