Jpp test-rotations-old-533-g2bdbdb559
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 139 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 148 of file JPerth.cc.

151 :
152 input(data),
153 stop(false)
154 {
155 using namespace std;
156 using namespace JPP;
157
158 Q.reset();
159
160 for (size_t i = 0; i < ns; ++i) {
161
162 thread worker([this, storage, option]() {
163
164 JRegressor_t regressor(storage);
165
166 regressor.parameters.resize(5);
167
168 regressor.parameters[0] = JLine3Z::pX();
169 regressor.parameters[1] = JLine3Z::pY();
170 regressor.parameters[2] = JLine3Z::pT();
171 regressor.parameters[3] = JLine3Z::pDX();
172 regressor.parameters[4] = JLine3Z::pDY();
173
175 JLine3Z value;
176
177 for ( ; ; ) {
178
179 {
180 unique_lock<mutex> lock(in);
181
182 cv.wait(lock, [this]() { return stop || this->input.hasNext(); });
183
184 if (stop && !this->input.hasNext()) {
185 return;
186 }
187
188 const event_type* evt = this->input.next();
189
190 // re-organise data
191
192 data.clear();
193
194 // 2 => evaluation of the derivative of the chi2 to each fit parameter.
195
196 if (option != 2 || evt->status) {
197 for (map_type::const_iterator p = evt->data.begin(); p != evt->data.end(); ++p) {
198 copy(p->second.begin(), p->second.end(), back_inserter(data));
199 }
200 }
201
202 value = evt->value;
203 }
204
205 if (!data.empty()) {
206
207 const double chi2 = regressor(value, data.begin(), data.end());
208
209 {
210 unique_lock<mutex> lock(out);
211
212 Q.put(chi2);
213 }
214 }
215 }
216 });
217
218 workers.emplace_back(std::move(worker));
219 }
220 }
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:246
std::condition_variable cv
Definition JPerth.cc:250
static JMATH::JQuantile_t Q
Definition JPerth.cc:243

◆ ~JPerth()

JRECONSTRUCTION::JPerth::~JPerth ( )
inline

Destructor.

Definition at line 226 of file JPerth.cc.

227 {
228 using namespace std;
229
230 {
231 unique_lock<mutex> lock(in);
232
233 stop = true;
234 }
235
236 cv.notify_all();
237
238 for (auto& worker : workers) {
239 worker.join();
240 }
241 }

Member Data Documentation

◆ Q

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

Definition at line 243 of file JPerth.cc.

◆ workers

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

Definition at line 246 of file JPerth.cc.

◆ input

input_type JRECONSTRUCTION::JPerth::input
private

Definition at line 247 of file JPerth.cc.

◆ in

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

Definition at line 248 of file JPerth.cc.

◆ out

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

Definition at line 249 of file JPerth.cc.

◆ cv

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

Definition at line 250 of file JPerth.cc.

◆ stop

bool JRECONSTRUCTION::JPerth::stop
private

Definition at line 251 of file JPerth.cc.


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