13#include "TrkReco/TMLine.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"
21TMLine::_fitter =
TLineFitter(
"TMLine Default Line Fitter");
28 _fittedUpdated(
false),
41 _fittedUpdated(
false),
53TMLine::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;
116 std::cout <<
"TMLine::chi2 !!! fit not performed" << std::endl;
119 if (_fittedUpdated)
return _chi2;
122 for (
unsigned i = 0; i <
n; i++) {
127 double c =
y - _a *
x - _b;
130 _fittedUpdated =
true;
138 for (
unsigned i = 0; i <
n; i++) {
141 if (dist > maxSigma) bad.append(l);
144#ifdef TRKRECO_DEBUG_DETAIL
145 std::cout <<
" TMLine::refine ... rejected hits:max distance=" << maxSigma;
146 std::cout << std::endl;
148 for (
unsigned i = 0; i < bad.length(); i++) {
156 else std::cout <<
"0";
160 if (
distance(l) > maxSigma) std::cout <<
" X";
161 std::cout << std::endl;
169 _fittedUpdated =
false;
175 std::cout<<
" "<<__FILE__<<
" "<<__LINE__<<
" ERROR : nsl"<<std::endl;
180 int nsl[11] = {64,80,96,128,144,160,192,208,240,256,288};
181 int npos = 0, nneg = 0;
182 for (
unsigned i = 0; i <
n -1 ; i++) {
184 for (
unsigned j = i+1; j <
n ; j++) {
188 if(i > 0 && (mask[i-1] == 1 && mask[j] == 1) ){
196 int jlocal =
s.hit()->wire()->localId();
197 if(ilocal > 0 && ilocal < ilast){
198 if(
abs(jlocal-ilocal) > 1 ) {
202 }
else if(ilocal == 0){
203 if(jlocal > 1 && jlocal < ilast){
207 }
else if(ilocal == ilast){
208 if(jlocal > 0 && jlocal < ilast-1){
217 if(l.
position().y() >= 0) npos += 1;
223 double sumX = 0., sumY = 0., sumX2 = 0., sumXY = 0., sumY2 = 0.;
226 for (
unsigned i = 0; i <
n; i++) {
228 if(mask[i] == 1)
continue;
234 if(
abs(npos-nneg) > 3){
235 if(npos > nneg &&
y < 0 )
continue;
236 if(npos < nneg && y > 0 )
continue;
249 if(nused < 2 || (nused == 2 && lyid[0]==lyid[1])) {
252 double sum = double(nused);
253 _det = sum * sumX2 - sumX * sumX;
257 _a = (sumXY * sum - sumX * sumY) / _det;
258 _b = (sumX2 * sumY - sumX * sumXY) / _det;
270 int npos = 0, nneg = 0;
271 for (
unsigned i = 0; i <
n -1 ; i++) {
273 for (
unsigned j = i+1; j <
n ; j++) {
282 if(l.
position().y() >= 0) npos += 1;
288 double sumX = 0., sumY = 0., sumX2 = 0., sumXY = 0., sumY2 = 0.;
291 for (
unsigned i = 0; i <
n; i++) {
293 if(mask[i] == 1)
continue;
299 if(npos > nneg &&
y < 0 )
continue;
300 if(npos < nneg && y > 0 )
continue;
313 double sum = double(nused);
314 _det = sum * sumX2 - sumX * sumX;
318 _a = (sumXY * sum - sumX * sumY) / _det;
319 _b = (sumX2 * sumY - sumX * sumXY) / _det;
332 double Crad = 180./3.141592;
333 for (
unsigned i = 0; i <
n -1 ; i++) {
335 for (
unsigned j = i+1; j <
n ; j++) {
360 phi_max = phi_ave/
n + 40;
361 phi_min = phi_ave/
n - 40;
365 double sumX = 0., sumY = 0., sumX2 = 0., sumXY = 0., sumY2 = 0.;
368 for (
unsigned i = 0; i <
n; i++) {
370 if(mask[i] == 1)
continue;
377 if(phi > phi_max && phi<phi_min )
continue;
390 double sum = double(nused);
391 _det = sum * sumX2 - sumX * sumX;
395 _a = (sumXY * sum - sumX * sumY) / _det;
396 _b = (sumX2 * sumY - sumX * sumXY) / _det;
406 std::cout<<
" "<<__FILE__<<
" "<<__LINE__<<
" ERROR : nsl"<<std::endl;
409 int nsl[11] = {64,80,96,128,144,160,192,208,240,256,288};
412 double Crad = 180./3.141592;
413 for (
unsigned i = 0; i <
n -1 ; i++) {
415 for (
unsigned j = i+1; j <
n ; j++) {
419 if(i > 0 && (mask[i-1] == 1 && mask[j] == 1) ){
427 int jlocal =
s.hit()->wire()->localId();
428 if(ilocal > 0 && ilocal < ilast){
429 if(
abs(jlocal-ilocal) > 1 ) {
433 }
else if(ilocal == 0){
434 if(jlocal > 1 && jlocal < ilast){
438 }
else if(ilocal == ilast){
439 if(jlocal > 0 && jlocal < ilast-1){
465 phi_max = phi_ave/
n + 40;
466 phi_min = phi_ave/
n - 40;
470 double sumX = 0., sumY = 0., sumX2 = 0., sumXY = 0., sumY2 = 0.;
473 for (
unsigned i = 0; i <
n; i++) {
475 if(mask[i] == 1)
continue;
482 if(phi > phi_max && phi<phi_min )
continue;
495 if(nused < 2 || (nused == 2 && lyid[0]==lyid[1])) {
498 double sum = double(nused);
499 _det = sum * sumX2 - sumX * sumX;
503 _a = (sumXY * sum - sumX * sumY) / _det;
504 _b = (sumX2 * sumY - sumX * sumXY) / _det;
515 int nneg = 0, npos = 0;
516 for (
unsigned i = 0; i <
n -1 ; i++) {
528 for (
unsigned i = 0; i <
n; i++) {
538 if(
abs(nneg - npos) > 3) {
539 if(npos > nneg && l.
position().y() < 0 ) bad.append(l);
540 if(npos < nneg && l.
position().y() > 0 ) bad.append(l);
544 if (bad.length() > 0 && bad.length() <
n) {
550 _fittedUpdated =
false;
557 _fittedUpdated =
false;
564 _fittedUpdated =
false;
571 unsigned nb =
_links.length();
574 unsigned n = list.length();
575 for (
unsigned i = 0; i <
n; i++) {
579 if (dist < maxSigma) {
589 for(
unsigned i = 0; i<
na ;i++){
600 if(bad.length() > 0)
_links.remove(bad);
602 _fittedUpdated =
false;
610 std::cout <<
"TMLine::reducedChi2 !!! fit not performed" << std::endl;
613 if (_fittedUpdated)
return _reducedChi2;
617 for (
unsigned i = 0; i <
n; i++) {
622 double c =
y - _a *
x - _b;
625 chi2 += c * c / err / err;
628 _reducedChi2 =
chi2/(
n-2);
629 _fittedUpdated =
true;
637 if (fabs((* a)->b()) > fabs((* b)->b()))
639 else if (fabs((* a)->b()) == fabs((* b)->b()))
651 if (fabs((* a)->b()) > fabs((* b)->b()))
653 else if (fabs((* a)->b()) == fabs((* b)->b()))
int SortByWireId(const void *a, const void *b)
Sorter.
int SortByB(const void *av, const void *bv)
Sorter.
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 represent a track in tracking.
double chi2(void) const
returns chi2.
void removeChits()
remove extremly bad points.
void removeSLY(AList< TMLink > &list)
int fit2()
fits itself. 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.
virtual ~TMLine()
Destructor.
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)
int fit2p()
fits itself using isolated hits. Error was happened if return value is not zero.
int fit2sp()
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.
void appendSLY(AList< TMLink > &list)
double reducedChi2(void) const
returns reduced-chi2.
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.