Fit function.
228 {
231
233
235
238
239 data.reserve(dataL0.size() +
240 dataL1.size());
241
243
245
246 for (
size_t index = 0; index !=
omega.size(); ++index) {
247
248 for (
const auto& dir :
omega[index]) {
249
251
252
253 buffer_type::iterator __end =
copy(dataL1.begin(), dataL1.end(),
data.begin());
254
255 for (buffer_type::iterator i =
data.begin(); i != __end; ++i) {
256 i->rotate(R);
257 }
258
259
260
262
263 buffer_type::iterator __p =
data.begin();
264
266
267 partial_sort(
data.begin(), __p, __end,
cmz);
268
269 __end = __p;
270 }
271
272
273
275
279
280 buffer_type::iterator p = __end;
281 buffer_type::iterator q =
copy(dataL0.begin(), dataL0.end(), p);
282
283 for (buffer_type::iterator i = p; i != q; ++i) {
284
286
287 i->rotate(R);
288
289 if (match1D.count(*i,
data.begin(), __end) != 0) {
290 *p = *i;
291 ++p;
292 }
293 }
294 }
295
297 }
298
299
300 if (
distance(
data.begin(), __end) <= NUMBER_OF_PARAMETERS) {
301 continue;
302 }
303
304
305
307 double chi2 = numeric_limits<double>::max();
308 int NDF =
distance(
data.begin(), __end) - NUMBER_OF_PARAMETERS;
310
311 try {
312
314
315 (*this)(
data.begin(), __end);
316
319
321
322 tz = *this;
324 }
325 catch(const exception& error) {
326 continue;
327 }
328
329
330
332
334
336
337 for (
int n = 1;
n <= number_of_outliers; ++
n) {
338
340
341 buffer_type::iterator __end1 = prev(__end,
n);
342
343 do {
344
345 try {
346
347 (*this)(
data.begin(), __end1);
348
351
353
355
357
358 WARNING(endl <<
"JMuonPrefit: invalid chi2 " << y << endl);
359
360 } else {
361
362 if (y < 0.0) {
364 }
365
366 if (y < ymin) {
368 tz = *this;
369 chi2 = ymin;
370 NDF =
distance(
data.begin(), __end1) - NUMBER_OF_PARAMETERS;
372 }
373 }
374 }
375 catch(const exception& error) {}
376
378
380 }
381
382 } else {
383
384 const int number_of_outliers = NDF - 1;
385
386 for (
int n = 1;
n <= number_of_outliers; ++
n) {
387
388 double ymax = 0.0;
389 int k = -1;
390
391 for (
size_t i = 0; i !=
Y.size(); ++i) {
392
394
395 if (y > ymax) {
397 k = i;
398 }
399 }
400
402 break;
403 }
404
405 try {
406
408
409 this->update(
data.begin(), __end,
V);
410
412
413 tz = *this;
415 NDF -= 1;
417 }
418 catch(const exception& error) {
419 break;
420 }
421 }
422 }
423
425
426 buffer[index].push_back(
getFit(event(), tz, dir,
getQuality(chi2, N, NDF), NDF));
427
428
429
432 }
433 }
434
435
437
439
440 struct element_type {
441
442 size_t index;
444
445 struct compare {
446
447 inline bool operator()(const element_type& first, const element_type& second) const
448 {
450 }
451 };
452 };
453
454 for (auto& i : buffer) {
455
456 auto ws = i.begin();
457
459
461 i.end(),
462 [](
const JFit& fit) { return fit.getQ(); },
463 [](
const JFit& first,
const JFit& second) { return getAngle(first, second); },
465 }
466
468 }
469
470 priority_queue<element_type, deque<element_type>, element_type::compare> queue;
471
472 auto move = [&buffer,&queue](size_t i) {
473
474 if (!buffer[i].empty()) {
475
476 queue.push({i, buffer[i].front()});
477
478 buffer[i].pop_front();
479 }
480 };
481
482 for (size_t i = 0; i != buffer.size(); ++i) {
483 move(i);
484 }
485
487
488 const element_type top = queue.top();
489
490 queue.pop();
491
492 out.push_back(top.fit);
493
494 move(top.index);
495 }
496
498
500
501 while (!queue.empty()) {
502
503 const element_type top = queue.top();
504
505 queue.pop();
506
507 out.push_back(top.fit);
508
509 flag.insert(top.index);
510 }
511
512 for (
size_t i = 0; i !=
omega.size(); ++i) {
513
514 if (flag.count(i) == 0) {
515
517
518 typedef deque<JFit>::iterator
iterator;
519
520 struct {
521 double dot;
522 size_t i;
524 } xs = { -1.0, 0, buffer[0].end() };
525
526 for (size_t i = 0; i != buffer.size(); ++i) {
527
528 for (
iterator p = buffer[i].begin(); p != buffer[i].end(); ++p) {
529
530 const double dot = pointing.getDot(*p);
531
532 if (dot > xs.dot) {
533 xs = { dot, i, p };
534 }
535 }
536 }
537
538 if (xs.p != buffer[xs.i].end()) {
539
540 out.push_back(*xs.p);
541
542 buffer[xs.i].erase(xs.p);
543 }
544 }
545 }
546 }
547
548 } else {
549
550 for (const auto& i : buffer) {
551 for (const auto& fit : i) {
552 out.push_back(fit);
553 }
554 }
555
557 }
558
559 return out;
560 }
Data structure for fit of straight line paralel to z-axis.
void set(const JVector3D &pos, T __begin, T __end, const double alpha, const double sigma)
Set co-variance matrix.
void set(const JLine1Z &track, T __begin, T __end)
Set time residual vector.
JPosition3D & rotate_back(const JRotation3D &R)
Rotate back.
Auxiliary class to compare fit results with respect to a reference direction (e.g....
int getModuleID() const
Get module identifier.
static const int JPP_COVERAGE_POSITION
coverage of dynamic position calibration of this event
static const int JPP_COVERAGE_ORIENTATION
coverage of dynamic orientation calibration of this event
double getChi2(const double P)
Get chi2 corresponding to given probability.
size_t getCount(const array_type< T > &buffer, const JCompare_t &compare)
Count number of unique values.
T watershed(T __begin, T __end, const JFunction_t &getValue, const JDistance_t &getDistance, double Y, int N=std::numeric_limits< int >::max())
Watershed algorithm.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
double getQuality(const double chi2, const int N, const int NDF)
Get quality of fit.
void copy(const JFIT::JEvt::const_iterator __begin, const JFIT::JEvt::const_iterator __end, Evt &out)
Copy tracks.
bool qualitySorter(const JFit &first, const JFit &second)
Comparison of fit results.
JFit getFit(const JHistory &history, const JTrack3D &track, const double Q, const int NDF, const double energy=0.0, const int status=SINGLE_STAGE)
Get fit.
counter_type advance(counter_type &counter, const counter_type value, const counter_type limit=std::numeric_limits< counter_type >::max())
Advance counter.
JHitIterator_t clusterize(JHitIterator_t __begin, JHitIterator_t __end, const JMatch_t &match, const int Nmin=1)
Partition data according given binary match operator.
void update(const size_t k, const double value)
Update inverted matrix at given diagonal element.
void invert()
Invert matrix according LDU decomposition.
size_t numberOfPrefits
number of prefits
int numberOfOutliers
maximum number of outliers
double Qwatershed
minimal quality step
int factoryLimit
factory limit for combinatorics
int NMaxHits
maximal number of hits
double sigma_ns
time resolution [ns]
static constexpr double STANDARD_DEVIATIONS
number of standard deviations for outlier removal [unit]
static const struct JRECONSTRUCTION::JMuonPrefit::cmz cmz