13#include "TrkReco/TLine0.h"
14#include "TrkReco/TMDCUtil.h"
15#include "TrkReco/TMDCWire.h"
16#include "TrkReco/TMDCWireHit.h"
17#include "TrkReco/TMDCWireHitMC.h"
18#include "TrkReco/TTrackHEP.h"
21TLine0::_fitter =
TLineFitter(
"TLine0 Default Line Fitter");
28 _fittedUpdated(
false),
41 _fittedUpdated(
false),
53TLine0::dump(
const std::string & msg,
const std::string & pre)
const {
55 if (msg ==
"") def =
true;
57 if (def || msg.find(
"line") != std::string::npos || msg.find(
"detail") != std::string::npos) {
59 std::cout <<
"#links=" <<
_links.length();
60 std::cout <<
",a=" << _a;
61 std::cout <<
",b=" << _b;
62 std::cout <<
",det=" << _det;
63 std::cout << std::endl;
114#ifdef TRKRECO_DEBUG_DETAIL
115 if (!
_fitted) std::cout <<
"TLine0::chi2 !!! fit not performed" << std::endl;
118 if (_fittedUpdated)
return _chi2;
121 for (
unsigned i = 0; i <
n; i++) {
126 double c = y - _a *
x - _b;
129 _fittedUpdated =
true;
137 for (
unsigned i = 0; i <
n; i++) {
140 if (dist > maxSigma) bad.append(l);
143#ifdef TRKRECO_DEBUG_DETAIL
144 std::cout <<
" TLine0::refine ... rejected hits:max distance=" << maxSigma;
145 std::cout << std::endl;
147 for (
unsigned i = 0; i < bad.length(); i++) {
155 else std::cout <<
"0";
159 if (
distance(l) > maxSigma) std::cout <<
" X";
160 std::cout << std::endl;
168 _fittedUpdated =
false;
178 int nsl[11] = {64,80,96,128,144,160,176,208,240,256,288};
179 int npos = 0, nneg = 0;
180 for (
unsigned i = 0; i <
n -1 ; i++) {
182 for (
unsigned j = i+1; j <
n ; j++) {
186 if(i > 0 && (mask[i-1] == 1 && mask[j] == 1) ){
194 int jlocal =
s.hit()->wire()->localId();
195 if(ilocal > 0 && ilocal < ilast){
196 if(
abs(jlocal-ilocal) > 1 ) {
200 }
else if(ilocal == 0){
201 if(jlocal > 1 && jlocal < ilast){
205 }
else if(ilocal == ilast){
206 if(jlocal > 0 && jlocal < ilast-1){
215 if(l.
position().y() >= 0) npos += 1;
221 double sumX = 0., sumY = 0., sumX2 = 0., sumXY = 0., sumY2 = 0.;
224 for (
unsigned i = 0; i <
n; i++) {
226 if(mask[i] == 1)
continue;
232 if(
abs(npos-nneg) > 3){
233 if(npos > nneg && y < 0 )
continue;
234 if(npos < nneg && y > 0 )
continue;
247 if(nused < 2 || (nused == 2 && lyid[0]==lyid[1])) {
250 double sum = double(nused);
251 _det = sum * sumX2 - sumX * sumX;
255 _a = (sumXY * sum - sumX * sumY) / _det;
256 _b = (sumX2 * sumY - sumX * sumXY) / _det;
268 int npos = 0, nneg = 0;
269 for (
unsigned i = 0; i <
n -1 ; i++) {
271 for (
unsigned j = i+1; j <
n ; j++) {
280 if(l.
position().y() >= 0) npos += 1;
286 double sumX = 0., sumY = 0., sumX2 = 0., sumXY = 0., sumY2 = 0.;
289 for (
unsigned i = 0; i <
n; i++) {
291 if(mask[i] == 1)
continue;
297 if(npos > nneg && y < 0 )
continue;
298 if(npos < nneg && y > 0 )
continue;
311 double sum = double(nused);
312 _det = sum * sumX2 - sumX * sumX;
316 _a = (sumXY * sum - sumX * sumY) / _det;
317 _b = (sumX2 * sumY - sumX * sumXY) / _det;
330 double Crad = 180./3.141592;
331 for (
unsigned i = 0; i <
n -1 ; i++) {
333 for (
unsigned j = i+1; j <
n ; j++) {
358 phi_max = phi_ave/
n + 40;
359 phi_min = phi_ave/
n - 40;
363 double sumX = 0., sumY = 0., sumX2 = 0., sumXY = 0., sumY2 = 0.;
366 for (
unsigned i = 0; i <
n; i++) {
368 if(mask[i] == 1)
continue;
375 if(phi > phi_max && phi<phi_min )
continue;
388 double sum = double(nused);
389 _det = sum * sumX2 - sumX * sumX;
393 _a = (sumXY * sum - sumX * sumY) / _det;
394 _b = (sumX2 * sumY - sumX * sumXY) / _det;
406 int nsl[11] = {64,80,96,128,144,160,176,208,240,256,288};
409 double Crad = 180./3.141592;
410 for (
unsigned i = 0; i <
n -1 ; i++) {
412 for (
unsigned j = i+1; j <
n ; j++) {
416 if(i > 0 && (mask[i-1] == 1 && mask[j] == 1) ){
424 int jlocal =
s.hit()->wire()->localId();
425 if(ilocal > 0 && ilocal < ilast){
426 if(
abs(jlocal-ilocal) > 1 ) {
430 }
else if(ilocal == 0){
431 if(jlocal > 1 && jlocal < ilast){
435 }
else if(ilocal == ilast){
436 if(jlocal > 0 && jlocal < ilast-1){
462 phi_max = phi_ave/
n + 40;
463 phi_min = phi_ave/
n - 40;
467 double sumX = 0., sumY = 0., sumX2 = 0., sumXY = 0., sumY2 = 0.;
470 for (
unsigned i = 0; i <
n; i++) {
472 if(mask[i] == 1)
continue;
479 if(phi > phi_max && phi<phi_min )
continue;
492 if(nused < 2 || (nused == 2 && lyid[0]==lyid[1])) {
495 double sum = double(nused);
496 _det = sum * sumX2 - sumX * sumX;
500 _a = (sumXY * sum - sumX * sumY) / _det;
501 _b = (sumX2 * sumY - sumX * sumXY) / _det;
512 int nneg = 0, npos = 0;
513 for (
unsigned i = 0; i <
n -1 ; i++) {
525 for (
unsigned i = 0; i <
n; i++) {
535 if(
abs(nneg - npos) > 3) {
536 if(npos > nneg && l.
position().y() < 0 ) bad.append(l);
537 if(npos < nneg && l.
position().y() > 0 ) bad.append(l);
541 if (bad.length() > 0 && bad.length() <
n) {
547 _fittedUpdated =
false;
554 _fittedUpdated =
false;
561 _fittedUpdated =
false;
568 unsigned nb =
_links.length();
571 unsigned n = list.length();
572 for (
unsigned i = 0; i <
n; i++) {
576 if (dist < maxSigma) {
582 unsigned na =
_links.length();
586 for(
unsigned i = 0; i<na ;i++){
597 if(bad.length() > 0)
_links.remove(bad);
599 _fittedUpdated =
false;
605#ifdef TRKRECO_DEBUG_DETAIL
606 if (!
_fitted) std::cout <<
"TLine0::reducedChi2 !!! fit not performed" << std::endl;
609 if (_fittedUpdated)
return _reducedChi2;
613 for (
unsigned i = 0; i <
n; i++) {
618 double c = y - _a *
x - _b;
620 chi2 += c * c / err / err;
623 _reducedChi2 =
chi2/(
n-2);
624 _fittedUpdated =
true;
int SortByWireId(const void *a, const void *b)
Sorter.
void appendSLY(AList< TMLink > &list)
int fit2sp()
fits itself using single hits in a wire-layer. Error was happened if return value is not zero.
double chi2(void) const
returns chi2.
double distance(const TMLink &) const
returns distance to a position of TMLink itself. (not to a wire)
void appendByszdistance(AList< TMLink > &list, unsigned isl, float maxSigma)
double reducedChi2(void) const
returns reduced-chi2.
int fit2()
fits itself. Error was happened if return value is not zero.
virtual ~TLine0()
Destructor.
void removeChits()
remove extremly bad points.
void removeSLY(AList< TMLink > &list)
int fit2p()
fits itself using isolated hits. Error was happened if return value is not zero.
void refine(AList< TMLink > &list, float maxSigma)
remove bad points by chi2. Bad points are returned in a 'list'. fit() should be called before calling...
int fit2s()
fits itself using single hits in a wire-layer. Error was happened if return value is not zero.
void dump(const std::string &message=std::string(""), const std::string &prefix=std::string("")) const
dumps debug information.
A class to fit a TTrackBase object to a line.
const TTrackHEP *const hep(void) const
returns a pointer to a GEN_HEPEVT.
float dDrift(unsigned) const
returns drift distance error.
const TMDCWire *const wire(void) const
returns a pointer to a TMDCWire.
const TMDCWireHitMC *const mc(void) const
returns a pointer to TMDCWireHitMC.
unsigned localId(void) const
returns local id in a wire layer.
unsigned layerId(void) const
returns layer id.
unsigned superLayerId(void) const
returns super layer id.
A class to relate TMDCWireHit and TTrack objects.
const TMDCWireHit * hit(void) const
returns a pointer to a hit.
const HepPoint3D & position(void) const
returns position.
const TMDCWire *const wire(void) const
returns a pointer to a wire.
A virtual class for a track class in tracking.
virtual void dump(const std::string &message=std::string(""), const std::string &prefix=std::string("")) const
dumps debug information.
const TMFitter *const fitter(void) const
returns a pointer to a default fitter.
unsigned id(void) const
returns an id started from 0.