16#include "TrkReco/TBuilderCurl.h"
17#include "TrkReco/TMLink.h"
18#include "TrkReco/TTrack.h"
19#include "TrackUtil/Lpav.h"
24#include "TrkReco/TMLine.h"
25#include "TrkReco/TRobustLineFitter.h"
29#define DEBUG_CURL_DUMP 0
30#define DEBUG_CURL_GNUPLOT 0
31#define DEBUG_CURL_MC 0
33#if (DEBUG_CURL_GNUPLOT+DEBUG_CURL_MC)
34#include "TrkReco/TMDCWireHitMC.h"
35#include "TrkReco/TTrackHEP.h"
37#include "MdcTables/MdcTables.h"
41#include "GaudiKernel/StatusCode.h"
42#include "GaudiKernel/IInterface.h"
43#include "GaudiKernel/Kernel.h"
44#include "GaudiKernel/Service.h"
45#include "GaudiKernel/ISvcLocator.h"
46#include "GaudiKernel/SvcFactory.h"
47#include "GaudiKernel/IDataProviderSvc.h"
48#include "GaudiKernel/Bootstrap.h"
49#include "GaudiKernel/MsgStream.h"
50#include "GaudiKernel/SmartDataPtr.h"
51#include "GaudiKernel/IMessageSvc.h"
53#if (DEBUG_CURL_DUMP+DEBUG_CURL_GNUPLOT+DEBUG_CURL_MC)
56static int debugMcFlag = 1;
61 _fitter(
"TBuilderCurl Fitter"){
64 StatusCode scmgn = Gaudi::svcLocator()->service(
"MagneticFieldSvc",m_pmgnIMF);
65 if(scmgn!=StatusCode::SUCCESS) {
66 std::cout<< __FILE__<<
"Unable to open Magnetic field service"<<std::endl;
124 fit->propagation(
false);
136 double &tanL)
const {
191#if (DEBUG_CURL_DUMP+DEBUG_CURL_GNUPLOT+DEBUG_CURL_MC)
192 Belle_event_Manager &evtMgr = Belle_event_Manager::get_manager();
194 if(evtMgr.count() != 0 &&
195 evtMgr[0].ExpMC() != 2)debugMcFlag = 0;
199 unsigned nList = list.length();
202 for(
unsigned i = 0, size = track.
links().length(); i < size; ++i){
203 unsigned superID = (track.
links())[i]->wire()->superLayerId();
204 if(superID == 0 || superID == 1 || superID == 5 ||
205 superID == 6 || superID == 7 || superID == 8 ){
207 for (
unsigned j = 0; j < nList; ++j) {
209 if(l->
hit()->
wire()->
id() == (track.
links())[i]->hit()->wire()->id()){
213 if(ok == 1)list.append(((track.
links())[i]));
216 (track.
links())[i]->leftRight(2);
218 for(
unsigned i = 0, size = list.length(); i < size; ++i){
219 track.
_links.remove(list[i]);
221 list[i]->leftRight(2);
224 if(list.length() < 2 ||
225 list.length()+track.
nLinks() < 5)
return NULL;
227 unsigned debug_stereo_counter1 = 0;
228 for(
unsigned i=0;i<track.
links().length();++i){
229 unsigned superID = (track.
links())[i]->hit()->wire()->superLayerId();
230 if(superID == 0 || superID == 1 ||
231 superID == 5 || superID == 6 ||
232 superID == 7 || superID == 8 )++debug_stereo_counter1;
234 std::cout <<
"(TBuilderCurl)Fitted Track:";
235 std::cout <<
", A# = " << track.
links().length()-debug_stereo_counter1;
236 std::cout <<
", S# = " << debug_stereo_counter1 <<
"(==0)";
237 std::cout <<
", A+S# = " << track.
links().length();
238 std::cout <<
", Cand Stereo Wires # = " << list.length() << std::endl;
239 double debugChg = -1.;
240 if(track.
charge() > 0.)debugChg = 1.;
241 if(debugChg > 0.)std::cout <<
"(TBuilderCurl) Positive Track" << std::endl;
242 else std::cout <<
"(TBuilderCurl) Negative Track" << std::endl;
250 bool err2D = fitWDD(xc2D,yc2D,r2D,tmpAxialList);
259 for(
unsigned i = 0, size = list.length(); i < size; ++i){
260 if(list[i]->arcZ(0).
x() == -999. && list[i]->arcZ(1).
x() == -999.)removeList.append(list[i]);
262 list.remove(removeList);
263 if(list.length() < 2 ||
264 list.length()+track.
nLinks() < 5){
266 std::cout <<
"(TBuilderCurl) Fail...few wires which can be set Arc-Z # = "
267 << list.length() << std::endl;
272 std::cout <<
"(TBuilderCurl) Cand Stereo Wires which can be set Arc-Z # = "
273 << list.length() << std::endl;
274 plotArcZ(list,0.,0.,0);
280 for(
unsigned i = 0, size = list.length(); i < size; ++i){
281 layer[list[i]->wire()->layer()->axialStereoLayerId()].append(*list[i]);
285 for(
int i=0;i<18;++i){
286 if(layer[i].length())
287 std::cout <<
"(TBuilderCurl) Cand Stereo Wires which can be set Arc-Z # = "
289 <<
" on " << i <<
" Layer." << std::endl;
297 double minChi2 = 9999.;
298 double goodA = 9999.;
299 double goodB = 9999.;
300 makeLine(track, list, allStereoList, goodL,
301 minChi2, goodA, goodB, goodP);
302 HepAListDeleteAll(goodP);
305 std::cout <<
"(TBuilderCurl) a = " << goodA <<
", b = " << goodB
306 <<
" (after makeLine-function)" << std::endl;
312 if(rfitter.
fit(newLine0) != 0){
314 std::cout <<
"(TBuilderCurl) Fail...linefitting...fail." << std::endl;
320 std::cout <<
"(TBuilderCurl) a = " << newLine0.
a() <<
", b = " << newLine0.
b()
321 <<
" (after robustline-fit)" << std::endl;
325 unsigned nGoodL = goodL.length();
329 if(fabs(newLine0.
b()) < 10.){
330 appendPoints(list, goodL2,
333 appendPoints(list, goodL2,
338 appendPoints(list, goodL2,
341 goodL.append(goodL2);
345 if(rfitter.
fit(newLine) != 0){
347 std::cout <<
"(TBuilderCurl) Fail...appending and re-fitting...fail." << std::endl;
353 std::cout <<
"(TBuilderCurl) a = " << newLine.
a() <<
", b = " << newLine.
b()
354 <<
" (after last-append + re-robustline-fit)" << std::endl;
358 track.TTrackBase::append(good);
361 std::cout <<
"(TBuilderCurl) Fail...checking wire numbers...fail." << std::endl;
370 double tmpQ = track.
charge() > 0. ? 1. : -1.;
371 tmpA[1] = fmod(atan2(tmpQ * yc2D,
377 tmpA[2] = tmpQ*(333.564095/(-1000*(m_pmgnIMF->
getReferField())))/r2D;
379 tmpA[0] = xc2D/
cos(tmpA[1]) - tmpQ*r2D;
397 if(fabs(a[3]) > 10. && fabs(goodB) < 10.){
403 if(fabs(a[3]) > 50. && fabs(goodB) < 50.){
406 track.TTrackBase::remove(goodL2);
413 std::cout <<
"(TBuilderCurl) Created Line: y = " << newLine.
a()
414 <<
" * x + " << newLine.
b()
415 <<
", size = " << good.length() << std::endl;
416 plotArcZ(
const_cast< AList<TMLink>&
>(good), newLine.
a(), newLine.
b(), 0);
437 int err = _fitter.
fit(track);
440 std::cout <<
"(TBuilderCurl) Fail fitting(0)...error code = " << err << std::endl;
443 }
else if ( fabs(track.
helix().
a()[3]) > fabs(a[3]) &&
444 (fabs(track.
helix().
a()[3]) > 50. ||
445 fabs(track.
helix().
a()[2]) > 100. ||
446 fabs(track.
helix().
a()[2]) < 0.1) ){
471 std::cout <<
"(TBuilderCurl) Fail checking(1)..." << std::endl;
475 err = _fitter.
fit(track);
478 std::cout <<
"(TBuilderCurl) Fail fitting(1)...error code = " << err << std::endl;
485 std::cout <<
"(TBuilderCurl) Fail checking(2)..." << std::endl;
489 err = _fitter.
fit(track);
492 std::cout <<
"(TBuilderCurl) Fail fitting(2)...error code = " << err << std::endl;
499 std::cout <<
"(TBuilderCurl) Fail checking(3)..." << std::endl;
503 err = _fitter.
fit(track);
506 std::cout <<
"(TBuilderCurl) Fail fitting(3)...error code = " << err << std::endl;
512 for(
int i=0;i<track.
links().length();++i){
513 if(track.
links()[i]->pull() > 36.){
514 std::cout << track.
links()[i]->wire()->id()
515 <<
" :+: " << track.
links()[i]->pull() << std::endl;
518 std::cout <<
"Not Valid For Fit!" << std::endl;
526 std::cout <<
"(TBuilderCurl) Fail checking(4)..." << std::endl;
530 err = _fitter.
fit(track);
533 std::cout <<
"(TBuilderCurl) Fail fitting(4)...error code = " << err << std::endl;
539 for(
int i=0;i<track.
links().length();++i){
540 if(track.
links()[i]->pull() > 36.){
541 std::cout << track.
links()[i]->wire()->id()
542 <<
" :*: " << track.
links()[i]->pull() << std::endl;
545 std::cout <<
"Not Valid For Fit!" << std::endl;
559 std::cout <<
"(TBuilderCurl) Success fitting, but pre-selection...fail." << std::endl;
564 track.
pt() < 0.005 ||
567 std::cout <<
"(TBuilderCurl) Success fitting, but selection...fail." << std::endl;
568 std::cout <<
"(TBuilderCurl) impact = " << track.
impact() << std::endl;
569 std::cout <<
"(TBuilderCurl) pt = " << track.
pt() << std::endl;
570 std::cout <<
"(TBuilderCurl) pz = " << track.
pz() << std::endl;
571 std::cout <<
"(TBuilderCurl) dz = " << track.
helix().
a()[3] << std::endl;
578 fabs(a[3]) < fabs(track.
helix().
a()[3])){
582 std::cout <<
"(TBuilderCurl) Success Build Stereo!!!" << std::endl;
600 for(
unsigned i=0,size=track.
nLinks();i<size;++i){
601 unsigned id = (track.
links())[i]->wire()->superLayerId();
602 if(
id == 2)alayer[0].append((track.
links())[i]);
603 else if(
id == 3)alayer[1].append((track.
links())[i]);
604 else if(
id == 4)alayer[2].append((track.
links())[i]);
605 else if(
id == 9)alayer[3].append((track.
links())[i]);
606 else if(
id == 10)alayer[4].append((track.
links())[i]);
609 for(
unsigned i=0,size=list.length();i<size;++i){
610 unsigned id = list[i]->wire()->superLayerId();
611 if(
id == 0)slayer[0].append(list[i]);
612 else if(
id == 1)slayer[1].append(list[i]);
613 else if(
id == 5)slayer[2].append(list[i]);
614 else if(
id == 6)slayer[3].append(list[i]);
615 else if(
id == 7)slayer[4].append(list[i]);
616 else if(
id == 8)slayer[5].append(list[i]);
619 std::cout <<
"Stereo = "
620 << slayer[0].length() <<
" "
621 << slayer[1].length() <<
" "
622 << slayer[2].length() <<
" "
623 << slayer[3].length() <<
" "
624 << slayer[4].length() << std::endl;
625 std::cout <<
"Axial = "
626 << alayer[0].length() <<
" "
627 << alayer[1].length() <<
" "
628 << alayer[2].length() <<
" "
629 << alayer[3].length() <<
" "
630 << alayer[4].length() <<
" "
631 << alayer[5].length() << std::endl;
634 if(slayer[0].length() >= 1){
635 if(alayer[0].length()+alayer[1].length() >= 4){
636 setArcZ(track,slayer[0],alayer[0],alayer[1],ip);
637 }
else if(alayer[0].length()+alayer[1].length()+
638 alayer[2].length() >= 4){
639 setArcZ(track,slayer[0],alayer[0],alayer[1],
641 }
else if(alayer[0].length()+alayer[1].length()+
642 alayer[2].length()+alayer[3].length() >= 4){
643 setArcZ(track,slayer[0],alayer[0],alayer[1],
644 alayer[2],alayer[3],ip);
645 }
else if(alayer[0].length()+alayer[1].length()+
646 alayer[2].length()+alayer[3].length()+
647 alayer[4].length() >= 4){
648 setArcZ(track,slayer[0],alayer[0],alayer[1],
649 alayer[2],alayer[3],alayer[4],ip);
652 if(slayer[1].length() >= 1){
653 if(alayer[0].length()+alayer[1].length() >= 4){
654 setArcZ(track,slayer[1],alayer[0],alayer[1],ip);
655 }
else if(alayer[0].length()+alayer[1].length()+
656 alayer[2].length() >= 4){
657 setArcZ(track,slayer[1],alayer[0],alayer[1],
659 }
else if(alayer[0].length()+alayer[1].length()+
660 alayer[2].length()+alayer[3].length() >= 4){
661 setArcZ(track,slayer[1],alayer[0],alayer[1],
662 alayer[2],alayer[3],ip);
663 }
else if(alayer[0].length()+alayer[1].length()+
664 alayer[2].length()+alayer[3].length()+
665 alayer[4].length() >= 4){
666 setArcZ(track,slayer[1],alayer[0],alayer[1],
667 alayer[2],alayer[3],alayer[4],ip);
670 if(slayer[2].length() >= 1){
671 if(alayer[1].length()+alayer[2].length() >= 4){
672 setArcZ(track,slayer[2],alayer[1],alayer[2],ip);
674 else if(alayer[0].length()+alayer[1].length()+
675 alayer[2].length() >= 4){
676 setArcZ(track,slayer[2],alayer[0],alayer[1],alayer[2],ip);
677 }
else if(alayer[0].length()+alayer[1].length()+
678 alayer[2].length()+alayer[3].length() >= 4){
679 setArcZ(track,slayer[2],alayer[0],alayer[1],
680 alayer[2],alayer[3],ip);
681 }
else if(alayer[0].length()+alayer[1].length()+
682 alayer[2].length()+alayer[3].length()+
683 alayer[4].length() >= 4){
684 setArcZ(track,slayer[2],alayer[0],alayer[1],
685 alayer[2],alayer[3],alayer[4],ip);
689 if(slayer[3].length() >= 1){
690 if(alayer[1].length()+alayer[2].length() >= 4){
691 setArcZ(track,slayer[3],alayer[1],alayer[2],ip);
692 }
else if(alayer[0].length()+alayer[1].length()+
693 alayer[2].length() >= 4){
694 setArcZ(track,slayer[3],alayer[0],alayer[1],
696 }
else if(alayer[0].length()+alayer[1].length()+
697 alayer[2].length()+alayer[3].length()
699 setArcZ(track,slayer[3],alayer[0],alayer[1],
700 alayer[2],alayer[3],ip);
701 }
else if(alayer[0].length()+alayer[1].length()+
702 alayer[2].length()+alayer[3].length()+
703 alayer[4].length() >= 4){
704 setArcZ(track,slayer[3],alayer[0],alayer[1],
705 alayer[2],alayer[3],alayer[4],ip);
709 if(slayer[4].length() >= 1){
710 if(alayer[1].length()+alayer[2].length()
712 setArcZ(track,slayer[4],alayer[1],alayer[2],
714 }
else if(alayer[0].length()+alayer[1].length()+
715 alayer[2].length() >= 4){
716 setArcZ(track,slayer[4],alayer[0],alayer[1],
718 }
else if(alayer[0].length()+alayer[1].length()+
719 alayer[2].length()+alayer[3].length()
721 setArcZ(track,slayer[4],alayer[0],alayer[1],
722 alayer[2],alayer[3],ip);
723 }
else if(alayer[0].length()+alayer[1].length()+
724 alayer[2].length()+alayer[3].length()+
725 alayer[4].length() >= 4){
726 setArcZ(track,slayer[4],alayer[0],alayer[1],
727 alayer[2],alayer[3],alayer[4],ip);
730 if(slayer[5].length() >= 1){
731 if(alayer[1].length()+alayer[2].length()
733 setArcZ(track,slayer[5],alayer[1],alayer[2],
735 }
else if(alayer[1].length()+alayer[2].length()+
736 alayer[3].length() >= 4){
737 setArcZ(track,slayer[5],alayer[1],alayer[2],
739 }
else if(alayer[0].length()+alayer[1].length()+
740 alayer[2].length()+alayer[3].length()
742 setArcZ(track,slayer[5],alayer[0],alayer[1],
743 alayer[2],alayer[3],ip);
744 }
else if(alayer[0].length()+alayer[1].length()+
745 alayer[2].length()+alayer[3].length()+
746 alayer[4].length() >= 4){
747 setArcZ(track,slayer[5],alayer[0],alayer[1],
748 alayer[2],alayer[3],alayer[4],ip);
758 double a,
double b,
TTrack &track,
double z_cut)
const {
759 unsigned size = list.length();
760 if(size == 0)
return 0;
762 for(
unsigned i=0;i<size;++i){
763 for(
unsigned j=0;j<4;++j){
764 if(j <= 1 && list[i]->arcZ(j).
x() == -999.)
continue;
765 else if(j > 1 && list[i]->arcZ(j).
x() == -999.)
break;
766 double y = a*list[i]->arcZ(j).x()+b;
767 if(fabs(y-list[i]->arcZ(j).y()) < z_cut){
768 list[i]->position(list[i]->arcZ(j));
769 line.append(list[i]);
784 double &m_a,
double &
m_b,
double &chi2,
double &nhits,
787 m_a =
m_b = nhits = 0.;
789 unsigned n = points.length();
790 double sum = double(
n);
791 double sumX = 0., sumY = 0., sumX2 = 0., sumXY = 0., sumY2 = 0.;
792 for (
unsigned i = 0; i <
n; i++) {
803 if(ipC != 0)sum += 1.0;
806 double m_det = sum * sumX2 - sumX * sumX;
807 if(m_det == 0. && sum != 2.){
809 }
else if(m_det == 0. && sum == 2.){
810 double x0 = points[0]->position().x();
811 double y0 = points[0]->position().y();
812 double x1 = points[1]->position().x();
813 double y1 = points[1]->position().y();
814 if(x0 == x1)
return -1;
815 m_a = (y0-y1)/(x0-x1);
821 m_a = (sumXY * sum - sumX * sumY) / m_det;
822 m_b = (sumX2 * sumY - sumX * sumXY) / m_det;
824 for(
unsigned i = 0; i <
n; i++) {
829 double d = y-(
x*m_a+
m_b);
837TBuilderCurl::fitLine(
AList<TMLink> &tmpLine,
double &min_chi2,
838 double &good_a,
double &good_b,
840 int &overCounter)
const {
843 unsigned size = tmpLine.length();
846 double chi2 = line.chi2()/(
static_cast<double>(size-2));
847 if(chi2 < min_chi2 && fabs(line.b()) < m_param.
Z_CUT){
852 HepAListDeleteAll(goodPosition);
853 for(
unsigned i=0;i<size;++i)
859 unsigned size = tmpLine.length();
861 if(!(
doLineFit(tmpLine,ta,tb,tc,tn,1)) && tn > 2.){
862 double chi2 = tc/(tn-2.);
863 if(chi2 < min_chi2 && fabs(tb) < m_param.
Z_CUT){
868 HepAListDeleteAll(goodPosition);
869 for(
unsigned i=0;i<size;++i)
882TBuilderCurl::check(
const TTrack &track)
const {
883 unsigned nAhits(0), nShits(0);
884 for(
unsigned i=0,size=track.
nLinks();i<size;++i){
886 if(track.
links()[i]->wire()->stereo())++nShits;
889 if(nAhits >= 3 && nShits >= 2)
return 1;
904 int size = list.length();
905 if(size <= 1)
return 0;
906 int layerId = list[0]->hit()->wire()->layerId();
908 if(layerId >= 15)maxLocalId = 127;
909 if(layerId >= 23)maxLocalId = 159;
910 if(layerId >= 32)maxLocalId = 207;
911 if(layerId >= 41)maxLocalId = 255;
912 int HId = (int)(0.8*(maxLocalId+1));
913 int LId = (int)(0.2*(maxLocalId+1));
916 for(
int i=0;i>size;++i){
917 if(list[i]->hit()->wire()->localId() < LId)low = 1;
918 else if(list[i]->hit()->wire()->localId() > HId)high = 1;
919 if(low == 1 && high == 1)
return 1;
933 int size = list.length();
934 if(size <= 1)
return 0;
935 int layerId = list[0]->hit()->wire()->layerId();
937 if(layerId >= 15)maxLocalId = 127;
938 if(layerId >= 23)maxLocalId = 159;
939 if(layerId >= 32)maxLocalId = 207;
940 if(layerId >= 41)maxLocalId = 255;
941 int HId = (int)(0.8*(maxLocalId+1));
942 int LId = (int)(0.2*(maxLocalId+1));
945 for(
int i=0;i>size;++i){
946 if(list[i]->hit()->wire()->localId() < LId)low = 1;
947 else if(list[i]->hit()->wire()->localId() > HId)high = 1;
948 if(low == 1 && high == 1)
return 1;
957 if(layerId >= 15)maxLocalId = 127;
958 if(layerId >= 23)maxLocalId = 159;
959 if(layerId >= 32)maxLocalId = 207;
960 if(layerId >= 41)maxLocalId = 255;
966 int n = layer.length();
968 for(
int i=0;i<
n;++i){
970 if(layer[i]->hit()->wire()->localId() >= border)list.append(layer[i]);
972 if(layer[i]->hit()->wire()->localId() <= border)list.append(layer[i]);
978 if(border*2 < offset)border += offset;
979 for(
int i=0;i<
n;++i){
980 int lId = layer[i]->hit()->wire()->localId();
981 if(lId*2 < offset)lId += offset;
983 if(lId >= border)list.append(layer[i]);
985 if(lId <= border)list.append(layer[i]);
993 int size = list.length();
994 if(size <= 1)
return 0;
995 int layerId = list[0]->hit()->wire()->layerId();
1004 if(layerId == 0)maxLocalId = 39;
1005 else if(layerId == 1)maxLocalId = 43;
1006 else if(layerId == 2)maxLocalId = 47;
1007 else if(layerId == 3)maxLocalId = 55;
1008 else if(layerId == 4)maxLocalId = 63;
1009 else if(layerId == 5)maxLocalId = 71;
1010 else if(layerId < 8)maxLocalId = 79;
1011 else if(layerId < 24)maxLocalId = 159;
1012 else if(layerId < 28)maxLocalId = 175;
1013 else if(layerId < 32)maxLocalId = 207;
1014 else if(layerId < 43)maxLocalId = 239;
1016 for(
int i=0;i<size;++i){
1017 if(list[i]->hit()->wire()->localId() == 0 ||
1018 list[i]->hit()->wire()->localId() == 1 ||
1019 list[i]->hit()->wire()->localId() == maxLocalId-1 ||
1020 list[i]->hit()->wire()->localId() == maxLocalId){
1025 if(
flag == 0)
return 0;
1026 int maxDif = (int)(0.5*(maxLocalId+1));
1029 for(
int i=0;i<size;++i){
1030 if(list[i]->hit()->wire()->localId() < maxDif)
1031 lList.append(list[i]);
1033 fList.append(list[i]);
1038 if(fList.length() >= 1 &&
1039 lList.length() >= 1)
return 1;
1056 for(
unsigned i = 0, size = list.length();
1058 HepPoint3D point((list[i]->hit()->mc()->datcdc()->m_xin+
1059 list[i]->hit()->mc()->datcdc()->m_xout)*0.5,
1060 (list[i]->hit()->mc()->datcdc()->m_yin+
1061 list[i]->hit()->mc()->datcdc()->m_yout)*0.5,
1063 double cosdPhi = - center.dot((point - center).
unit()) / center.mag();
1065 if(fabs(cosdPhi) < 1.0){
1066 dPhi = acos(cosdPhi);
1067 }
else if(cosdPhi >= 1.0){
1073 (list[i]->hit()->mc()->datcdc()->m_zin+
1074 list[i]->hit()->mc()->datcdc()->m_zout)*0.5,
1086 bool err2D = fitWDD(xc2D,yc2D,r2D,track.
links());
1089 if(newLine.
fit() != 0)
return NULL;
1097 double tmpQ = track.
charge() > 0. ? 1. : -1.;
1098 tmpA[1] = fmod(atan2(tmpQ * yc2D,
1104 tmpA[2] =tmpQ*(333.564095/(-1000*(m_pmgnIMF->
getReferField())))/r2D;
1105 tmpA[0] = xc2D/
cos(tmpA[1]) - tmpQ*r2D;
1112 std::cout << track.
helix().
a()[0] <<
" " << track.
helix().
a()[1] <<
" "
1113 << track.
helix().
a()[2] <<
" " << track.
helix().
a()[3] <<
" "
1114 << track.
helix().
a()[4] << std::endl;
1118 int err = _fitter.
fit(track);
1119 if (err < m_param.ERROR_FOR_HELIX_FIT)
return NULL;
1121 err = _fitter.
fit(track);
1122 if (err < m_param.ERROR_FOR_HELIX_FIT)
return NULL;
1124 err = _fitter.
fit(track);
1125 if (err < m_param.ERROR_FOR_HELIX_FIT)
return NULL;
1127 err = _fitter.
fit(track);
1128 if (err < m_param.ERROR_FOR_HELIX_FIT)
return NULL;
1130 std::cout << track.
helix().
a()[0] <<
" " << track.
helix().
a()[1] <<
" "
1131 << track.
helix().
a()[2] <<
" " << track.
helix().
a()[3] <<
" "
1132 << track.
helix().
a()[4] << std::endl;
1137 if (track.
nLinks() < m_param.SELECTOR_NLINKS)
return NULL;
1139 track.
pt() < m_param.SELECTOR_MIN_PT)
return NULL;
1152 double a,
double b,
const int flag)
const {
1153#if DEBUG_CURL_GNUPLOT
1155 if(a == 9999. || b == 9999.){
1160 double gmaxX = 0. ,gminX = 0.;
1161 double gmaxY = 0. ,gminY = 0.;
1162 FILE *gnuplot, *
data;
1163 if((
data = fopen(
"you_can_remove_this.dat",
"w")) != NULL){
1164 for(
int ii=0;ii<tmpLine.length();ii++){
1166 fprintf(
data,
"%lf, %lf\n",
1167 tmpLine[ii]->position().
x(),
1168 tmpLine[ii]->position().y());
1169 if(
flag)std::cout <<
" Wire ID = " << tmpLine[ii]->hit()->wire()->id()
1170 <<
" Arc = " << tmpLine[ii]->position().x()
1171 <<
" Z = " << tmpLine[ii]->position().y();
1178 if(gmaxX < tmpLine[ii]->position().
x())
1179 gmaxX = tmpLine[ii]->position().x();
1180 if(gminX > tmpLine[ii]->position().
x())
1181 gminX = tmpLine[ii]->position().x();
1182 if(gmaxY < tmpLine[ii]->position().y())
1183 gmaxY = tmpLine[ii]->position().y();
1184 if(gminY > tmpLine[ii]->position().y())
1185 gminY = tmpLine[ii]->position().y();
1189 if((
data = fopen(
"you_can_remove_this.dat2",
"w")) != NULL){
1192 for(
int ii=0;ii<tmpLine.length();ii++){
1193 double z = (tmpLine[ii]->hit()->mc()->datcdc()->m_zin+
1194 tmpLine[ii]->hit()->mc()->datcdc()->m_zout)*0.5;
1195 if(tmpLine[ii]->arcZ(0).x() != -999.){
1197 fprintf(
data,
"%lf, %lf\n",tmpLine[ii]->arcZ(0).
x(),z);
1198 if(gmaxX < tmpLine[ii]->arcZ(0).
x())
1199 gmaxX = tmpLine[ii]->arcZ(0).x();
1200 if(gminX > tmpLine[ii]->arcZ(0).
x())
1201 gminX = tmpLine[ii]->arcZ(0).x();
1212 if((
data = fopen(
"you_can_remove_this.dat3",
"w")) != NULL){
1213 for(
int ii=0;ii<tmpLine.length();ii++){
1214 for(
int jj=0;jj<4;++jj){
1215 if(tmpLine[ii]->arcZ(jj).
x() != -999.){
1217 fprintf(
data,
"%lf, %lf\n",
1218 tmpLine[ii]->arcZ(jj).
x(),
1219 tmpLine[ii]->arcZ(jj).y());
1220 if(gmaxX < tmpLine[ii]->arcZ(jj).
x())
1221 gmaxX = tmpLine[ii]->arcZ(jj).x();
1222 if(gminX > tmpLine[ii]->arcZ(jj).
x())
1223 gminX = tmpLine[ii]->arcZ(jj).x();
1224 if(gmaxY < tmpLine[ii]->arcZ(jj).y())
1225 gmaxY = tmpLine[ii]->arcZ(jj).y();
1226 if(gminY > tmpLine[ii]->arcZ(jj).y())
1227 gminY = tmpLine[ii]->arcZ(jj).y();
1235 if(gmaxX < 0.)gmaxX = 0.;
if(gminX > 0.)gminX = 0.;
1236 if(gmaxY < 0.)gmaxY = 0.;
if(gminY > 0.)gminY = 0.;
1237 if(nCounter && (gnuplot = popen(
"gnuplot",
"w")) != NULL){
1238 fprintf(gnuplot,
"set nokey \n");
1239 fprintf(gnuplot,
"set size 0.721,1.0 \n");
1240 fprintf(gnuplot,
"set xrange [%f:%f] \n",gminX,gmaxX);
1241 fprintf(gnuplot,
"set yrange [%f:%f] \n",gminY,gmaxY);
1242 if(a == 0. && b == 0.){
1243 fprintf(gnuplot,
"plot \"you_can_remove_this.dat3\", \"you_can_remove_this.dat\", \"you_can_remove_this.dat2\" \n");
1245 fprintf(gnuplot,
"plot \"you_can_remove_this.dat3\", \"you_can_remove_this.dat\", \"you_can_remove_this.dat2\", %lf*x+%lf \n", a, b);
1270 unsigned maxLocalId = 39;
1271 if(layerId == 1)maxLocalId = 43;
1272 else if(layerId == 2)maxLocalId = 47;
1273 else if(layerId == 3)maxLocalId = 55;
1274 else if(layerId == 4)maxLocalId = 63;
1275 else if(layerId == 5)maxLocalId = 71;
1276 else if(layerId == 6 || layerId == 7 )maxLocalId = 79;
1277 else if(layerId == 20 || layerId == 21 || layerId == 22 || layerId == 23)maxLocalId = 159;
1278 else if(layerId == 24 || layerId == 25 || layerId == 26 || layerId == 27)maxLocalId = 175;
1279 else if(layerId == 28 || layerId == 29 || layerId == 30 || layerId == 31)maxLocalId = 207;
1280 else if(layerId == 32 || layerId == 33 || layerId == 34 || layerId == 35)maxLocalId = 239;
1287 unsigned maxLocalId,
1293 findId = maxLocalId;
1294 if(localId != 0)findId = localId-1;
1297 if(localId != maxLocalId)findId = localId+1;
1301 unsigned isolate = 1;
1302 for(
int i=0;i<allStereoList.length();++i){
1303 if(allStereoList[i]->wire()->layerId() == layerId &&
1304 allStereoList[i]->wire()->localId() == findId){
1318 if(hitsOnLayer.length() == 0 ||
1319 hitsOnLayer.length() > 3)
return;
1320 twoOnLayer.removeAll();
1321 if(hitsOnLayer.length() == 1){
1322 if(hitsOnLayer[0]->wire()->superLayerId() == 0)
return;
1323 unsigned maxLocalId =
findMaxLocalId(hitsOnLayer[0]->wire()->layerId());
1324 unsigned R =
isIsolation(hitsOnLayer[0]->wire()->localId(),
1326 hitsOnLayer[0]->wire()->layerId(),1,allStereoList);
1327 unsigned L =
isIsolation(hitsOnLayer[0]->wire()->localId(),
1329 hitsOnLayer[0]->wire()->layerId(),-1,allStereoList);
1330 if(R == 1 && L == 0){
1331 unsigned nextLocalId = hitsOnLayer[0]->wire()->localIdForPlus()+1;
1334 hitsOnLayer[0]->wire()->layerId(),-1,allStereoList);
1336 hitsOnLayer[0]->leftRight(1);
1337 hitsOnLayer[0]->position(hitsOnLayer[0]->arcZ(1));
1338 twoOnLayer.append(hitsOnLayer[0]);
1340 }
else if(R == 0 && L == 1){
1341 unsigned nextLocalId = hitsOnLayer[0]->wire()->localIdForMinus()+1;
1344 hitsOnLayer[0]->wire()->layerId(),1,allStereoList);
1346 hitsOnLayer[0]->leftRight(0);
1347 hitsOnLayer[0]->position(hitsOnLayer[0]->arcZ(0));
1348 twoOnLayer.append(hitsOnLayer[0]);
1352 if(hitsOnLayer.length() == 2){
1353 if(hitsOnLayer[0]->wire()->localIdForPlus()+1 ==
1354 hitsOnLayer[1]->wire()->localId()){
1355 unsigned maxLocalId =
findMaxLocalId(hitsOnLayer[0]->wire()->layerId());
1356 unsigned R =
isIsolation(hitsOnLayer[0]->wire()->localId(),
1358 hitsOnLayer[0]->wire()->layerId(),1,allStereoList);
1359 unsigned L =
isIsolation(hitsOnLayer[1]->wire()->localId(),
1361 hitsOnLayer[1]->wire()->layerId(),-1,allStereoList);
1362 if(R == 1 && L == 1){
1363 hitsOnLayer[0]->leftRight(1);
1364 hitsOnLayer[0]->position(hitsOnLayer[0]->arcZ(1));
1365 hitsOnLayer[1]->leftRight(0);
1366 hitsOnLayer[1]->position(hitsOnLayer[1]->arcZ(0));
1367 twoOnLayer.append(hitsOnLayer[0]);
1368 twoOnLayer.append(hitsOnLayer[1]);
1372 if(hitsOnLayer.length() == 3){
1373 if(hitsOnLayer[0]->wire()->localIdForPlus()+1 ==
1374 hitsOnLayer[1]->wire()->localId() &&
1375 hitsOnLayer[1]->wire()->localIdForPlus()+1 !=
1376 hitsOnLayer[2]->wire()->localId()){
1377 unsigned maxLocalId =
findMaxLocalId(hitsOnLayer[0]->wire()->layerId());
1378 unsigned R =
isIsolation(hitsOnLayer[0]->wire()->localId(),
1380 hitsOnLayer[0]->wire()->layerId(),1,allStereoList);
1381 unsigned L =
isIsolation(hitsOnLayer[1]->wire()->localId(),
1383 hitsOnLayer[1]->wire()->layerId(),-1,allStereoList);
1384 if(R == 1 && L == 1){
1385 hitsOnLayer[0]->leftRight(1);
1386 hitsOnLayer[0]->position(hitsOnLayer[0]->arcZ(1));
1387 hitsOnLayer[1]->leftRight(0);
1388 hitsOnLayer[1]->position(hitsOnLayer[1]->arcZ(0));
1389 twoOnLayer.append(hitsOnLayer[0]);
1390 twoOnLayer.append(hitsOnLayer[1]);
1392 }
else if(hitsOnLayer[0]->wire()->localIdForPlus()+1 !=
1393 hitsOnLayer[1]->wire()->localId() &&
1394 hitsOnLayer[1]->wire()->localIdForPlus()+1 ==
1395 hitsOnLayer[2]->wire()->localId()){
1396 unsigned maxLocalId =
findMaxLocalId(hitsOnLayer[1]->wire()->layerId());
1397 unsigned R =
isIsolation(hitsOnLayer[1]->wire()->localId(),
1399 hitsOnLayer[1]->wire()->layerId(),1,allStereoList);
1400 unsigned L =
isIsolation(hitsOnLayer[2]->wire()->localId(),
1402 hitsOnLayer[2]->wire()->layerId(),-1,allStereoList);
1403 if(R == 1 && L == 1){
1404 hitsOnLayer[1]->leftRight(1);
1405 hitsOnLayer[1]->position(hitsOnLayer[1]->arcZ(1));
1406 hitsOnLayer[2]->leftRight(0);
1407 hitsOnLayer[2]->position(hitsOnLayer[2]->arcZ(0));
1408 twoOnLayer.append(hitsOnLayer[1]);
1409 twoOnLayer.append(hitsOnLayer[2]);
1422 for(
unsigned i=0;i<hitsOnLayer.length();++i){
1424 hitsOnLayer[i]->leftRight(0);
1425 hitsOnLayer[i]->position(hitsOnLayer[i]->arcZ(0));
1427 hitsOnLayer[i]->leftRight(1);
1428 hitsOnLayer[i]->position(hitsOnLayer[i]->arcZ(1));
1435 unsigned nHits = hitsOnLayer.length();
1436 if(nHits == 0)
return false;
1438 if(hitsOnLayer[nHits-1]->leftRight() == 1)
return false;
1439 for(
unsigned i=0;i<nHits;++i){
1440 if(hitsOnLayer[i]->leftRight() == 0){
1441 hitsOnLayer[i]->leftRight(1);
1442 hitsOnLayer[i]->position(hitsOnLayer[i]->arcZ(1));
1452 goodWires.removeAll();
1453 for(
int i=0;i<allWires.length();++i){
1454 if(allWires[i]->position().
x() != -999.){
1455 goodWires.append(allWires[i]);
1461TBuilderCurl::fitLine2(
const AList<TMLink> &tmpLine,
double &min_chi2,
1462 double &good_a,
double &good_b,
1464 int &overCounter)
const {
1467 if(goodWires.length() >= 3)
1468 fitLine(goodWires, min_chi2, good_a, good_b, goodLine, goodPosition, overCounter);
1474 if(
abs(LR) != 1)
return;
1475 double Q = track.
charge();
1477 if(Q > 0. && LR == 1)isOuter = -1;
1478 else if(Q < 0. && LR == -1)isOuter = -1;
1479 radius = fabs(track.
radius());
1486 (radius+((double)isOuter)*(hit.
hit()->
drift()))*(center-wire).
unit();
1494 hitsOnLayer.remove(hits);
1495 if(hitsOnLayer.length() == 0)
return;
1497 unsigned nHits = hits.length();
1498 if(nHits == 0)
return;
1504 if(hits[nHits-1]->leftRight() == 1){
1506 ref = *hits[nHits-1];
1508 for(
unsigned i=0;i<nHits;++i){
1509 if(hits[i]->leftRight() == 0){
1519 double Q = track.
charge();
1520 for(
int i=0;i<hitsOnLayer.length();++i){
1522 if((hitsOnLayer[i]->wire()->xyPosition()-center).mag()-radius < 0.)isOuter = -1;
1523 if(Q > 0. && isOuter == 1){
1524 hitsOnLayer[i]->position(hitsOnLayer[i]->arcZ(0));
1525 hitsOnLayer[i]->leftRight(0);
1526 }
else if(Q > 0. && isOuter == -1){
1527 hitsOnLayer[i]->position(hitsOnLayer[i]->arcZ(1));
1528 hitsOnLayer[i]->leftRight(1);
1529 }
else if(Q < 0. && isOuter == 1){
1530 hitsOnLayer[i]->position(hitsOnLayer[i]->arcZ(1));
1531 hitsOnLayer[i]->leftRight(1);
1532 }
else if(Q < 0. && isOuter == -1){
1533 hitsOnLayer[i]->position(hitsOnLayer[i]->arcZ(0));
1534 hitsOnLayer[i]->leftRight(0);
1540TBuilderCurl::makeLine(
TTrack &track,
1542 double &min_chi2,
double &good_a,
double &good_b,
1544 if(list.length() == 0)
return;
1548 for(
unsigned i = 0, size = list.length(); i < size; ++i){
1549 layer[list[i]->wire()->layer()->axialStereoLayerId()].append(*list[i]);
1550 layerOrg[list[i]->wire()->layer()->axialStereoLayerId()].append(*list[i]);
1556 for(
unsigned i=0;i<24;++i){
1557 if(layer[i].length()){
1559 sortByLocalId(layer[i]);
1563 layer[i].removeAll();
1564 allFixedWires.append(tmp);
1566 if(i<4)fixedWires[0].append(tmp);
1567 else if(i<8)fixedWires[1].append(tmp);
1568 else if(i<12)fixedWires[2].append(tmp);
1569 else if(i<16)fixedWires[3].append(tmp);
1570 else if(i<20)fixedWires[4].append(tmp);
1571 else fixedWires[5].append(tmp);
1573 if(i<4)nonFixedWires[0].append(layer[i]);
1574 else if(i<8)nonFixedWires[1].append(layer[i]);
1575 else if(i<12)nonFixedWires[2].append(layer[i]);
1576 else if(i<16)nonFixedWires[3].append(layer[i]);
1577 else if(i<20)nonFixedWires[4].append(layer[i]);
1578 else nonFixedWires[5].append(layer[i]);
1584 std::cout <<
"(TBuilderCurl) 1st fixed & non-fixed wires selection:" << std::endl;
1585 std::cout <<
"(TBuilderCurl) all fixed wires # = " << allFixedWires.length() << std::endl;
1586 std::cout <<
"(TBuilderCurl) fixed wires # = ("
1587 << fixedWires[0].length() <<
", "
1588 << fixedWires[1].length() <<
", "
1589 << fixedWires[2].length() <<
", "
1590 << fixedWires[3].length() <<
", "
1591 << fixedWires[4].length() <<
", "
1592 << fixedWires[5].length() <<
")" << std::endl;
1593 std::cout <<
"(TBuilderCurl) non fixed wires # = ("
1594 << nonFixedWires[0].length() <<
", "
1595 << nonFixedWires[1].length() <<
", "
1596 << nonFixedWires[2].length() <<
", "
1597 << nonFixedWires[3].length() <<
", "
1598 << nonFixedWires[4].length() <<
", "
1599 << nonFixedWires[5].length() <<
")" << std::endl;
1601 for(
unsigned i=0;i<allFixedWires.length();++i)
1602 std::cout << i <<
": LocalID/LayerID = " << allFixedWires[i]->wire()->localId()
1603 <<
"/" << allFixedWires[i]->wire()->layerId()
1604 <<
", LR = " << allFixedWires[i]->leftRight() << std::endl;
1608 int createdLine = 0;
1609 int overCounter = 0;
1612 if(allFixedWires.length() >= 5){
1614 if(goodWires.length() >= 5){
1615 fitLine(goodWires, min_chi2, good_a, good_b, goodLine, goodPosition, overCounter);
1616 if(fabs(good_b) < 10.)createdLine = 1;
1621 if(createdLine == 0){
1624 double Q = track.
charge();
1625 unsigned isIncreased = 0;
1626 for(
int sl=0;sl<6;++sl){
1627 if(fixedWires[sl].length() >= 1 &&
1628 nonFixedWires[sl].length() >= 1){
1630 unsigned bestNCorrectLR = 0;
1633 for(
int i=0;i<fixedWires[sl].length();++i){
1634 int LR = fixedWires[sl][i]->leftRight() == 0 ? -1 : 1;
1638 unsigned nCorrectLR = 0;
1639 for(
int j=0;j<fixedWires[sl].length();++j){
1642 if((fixedWires[sl][j]->wire()->xyPosition()-center).mag()-radius < 0.)tmpIsOuter = -1;
1643 if(Q > 0. && tmpIsOuter == 1 && fixedWires[sl][j]->leftRight() == 0)++nCorrectLR;
1644 else if(Q > 0. && tmpIsOuter == -1 && fixedWires[sl][j]->leftRight() == 1)++nCorrectLR;
1645 else if(Q < 0. && tmpIsOuter == 1 && fixedWires[sl][j]->leftRight() == 1)++nCorrectLR;
1646 else if(Q < 0. && tmpIsOuter == -1 && fixedWires[sl][j]->leftRight() == 0)++nCorrectLR;
1649 if(i == 0 || nCorrectLR > bestNCorrectLR){
1650 bestNCorrectLR = nCorrectLR;
1654 if(bestNCorrectLR == fixedWires[sl].length()-1)
break;
1656 for(
int i=0;i<nonFixedWires[sl].length();++i){
1658 if((nonFixedWires[sl][i]->wire()->xyPosition()-bestC).mag()-bestR < 0.)isOuter = -1;
1659 if(Q > 0. && isOuter == 1){
1660 nonFixedWires[sl][i]->position(nonFixedWires[sl][i]->arcZ(0));
1661 nonFixedWires[sl][i]->leftRight(0);
1662 }
else if(Q > 0. && isOuter == -1){
1663 nonFixedWires[sl][i]->position(nonFixedWires[sl][i]->arcZ(1));
1664 nonFixedWires[sl][i]->leftRight(1);
1665 }
else if(Q < 0. && isOuter == 1){
1666 nonFixedWires[sl][i]->position(nonFixedWires[sl][i]->arcZ(1));
1667 nonFixedWires[sl][i]->leftRight(1);
1668 }
else if(Q < 0. && isOuter == -1){
1669 nonFixedWires[sl][i]->position(nonFixedWires[sl][i]->arcZ(0));
1670 nonFixedWires[sl][i]->leftRight(0);
1673 allFixedWires.append(nonFixedWires[sl]);
1674 fixedWires[sl].append(nonFixedWires[sl]);
1675 nonFixedWires[sl].removeAll();
1680 std::cout <<
"(TBuilderCurl) 2nd fixed & non-fixed wires selection:" << std::endl;
1681 std::cout <<
"(TBuilderCurl) all fixed wires # = " << allFixedWires.length() << std::endl;
1682 std::cout <<
"(TBuilderCurl) fixed wires # = ("
1683 << fixedWires[0].length() <<
", "
1684 << fixedWires[1].length() <<
", "
1685 << fixedWires[2].length() <<
", "
1686 << fixedWires[3].length() <<
", "
1687 << fixedWires[4].length() <<
", "
1688 << fixedWires[5].length() <<
")" << std::endl;
1689 std::cout <<
"(TBuilderCurl) non fixed wires # = ("
1690 << nonFixedWires[0].length() <<
", "
1691 << nonFixedWires[1].length() <<
", "
1692 << nonFixedWires[2].length() <<
", "
1693 << nonFixedWires[3].length() <<
", "
1694 << nonFixedWires[4].length() <<
", "
1695 << nonFixedWires[5].length() <<
")" << std::endl;
1697 for(
unsigned i=0;i<allFixedWires.length();++i)
1698 std::cout << i <<
": LocalID/LayerID = " << allFixedWires[i]->wire()->localId()
1699 <<
"/" << allFixedWires[i]->wire()->layerId()
1700 <<
", LR = " << allFixedWires[i]->leftRight() << std::endl;
1704 if(isIncreased == 1 && allFixedWires.length() >= 5){
1706 if(goodWires.length() >= 5){
1707 fitLine(goodWires, min_chi2, good_a, good_b, goodLine, goodPosition, overCounter);
1708 if(fabs(good_b) < 10.)createdLine = 1;
1715 if(createdLine == 0){
1717 int maxNonFixedLayerIndex[6] = { -1, -1, -1, -1, -1, -1 };
1718 int maxLength[6] = { 0, 0, 0, 0, 0, 0 };
1719 for(
int l=0;l<24;++l){
1723 else if(l<12)sl = 2;
1724 else if(l<16)sl = 3;
1725 else if(l<20)sl = 4;
1726 layer[l].remove(fixedWires[sl]);
1728 if(layer[l].length() && layer[l].length() > maxLength[sl]){
1729 maxLength[sl] = layer[l].length();
1730 maxNonFixedLayerIndex[sl] = l;
1735 unsigned nonFixedSuperLayerIndex[6] = { 0,0,0,0,0,0 };
1736 unsigned isIncreased = 0;
1737 for(
unsigned i=0;i<6;++i){
1738 allFixedWires.append(nonFixedWires[i]);
1739 if(nonFixedWires[i].length()){
1741 nonFixedSuperLayerIndex[index] = i;
1748 moveLR(layer[maxNonFixedLayerIndex[nonFixedSuperLayerIndex[0]]],
1749 nonFixedWires[nonFixedSuperLayerIndex[0]],
1752 setLR(nonFixedWires[nonFixedSuperLayerIndex[1]]);
1754 moveLR(layer[maxNonFixedLayerIndex[nonFixedSuperLayerIndex[1]]],
1755 nonFixedWires[nonFixedSuperLayerIndex[1]],
1758 setLR(nonFixedWires[nonFixedSuperLayerIndex[2]]);
1760 moveLR(layer[maxNonFixedLayerIndex[nonFixedSuperLayerIndex[2]]],
1761 nonFixedWires[nonFixedSuperLayerIndex[2]],
1764 setLR(nonFixedWires[nonFixedSuperLayerIndex[3]]);
1766 moveLR(layer[maxNonFixedLayerIndex[nonFixedSuperLayerIndex[3]]],
1767 nonFixedWires[nonFixedSuperLayerIndex[3]],
1770 setLR(nonFixedWires[nonFixedSuperLayerIndex[4]]);
1772 moveLR(layer[maxNonFixedLayerIndex[nonFixedSuperLayerIndex[4]]],
1773 nonFixedWires[nonFixedSuperLayerIndex[4]],
1776 setLR(nonFixedWires[nonFixedSuperLayerIndex[5]]);
1778 moveLR(layer[maxNonFixedLayerIndex[nonFixedSuperLayerIndex[5]]],
1779 nonFixedWires[nonFixedSuperLayerIndex[5]],
1781 fitLine2(allFixedWires, min_chi2, good_a, good_b, goodLine, goodPosition, overCounter);
1782 if(overCounter>10000)
goto kokohe;
1783 }
while(
moveLR(layer[maxNonFixedLayerIndex[nonFixedSuperLayerIndex[5]]]));
1785 fitLine2(allFixedWires, min_chi2, good_a, good_b, goodLine, goodPosition, overCounter);
1786 if(overCounter>10000)
goto kokohe;
1788 }
while(
moveLR(layer[maxNonFixedLayerIndex[nonFixedSuperLayerIndex[4]]]));
1790 fitLine2(allFixedWires, min_chi2, good_a, good_b, goodLine, goodPosition, overCounter);
1791 if(overCounter>10000)
goto kokohe;
1793 }
while(
moveLR(layer[maxNonFixedLayerIndex[nonFixedSuperLayerIndex[3]]]));
1795 fitLine2(allFixedWires, min_chi2, good_a, good_b, goodLine, goodPosition, overCounter);
1796 if(overCounter>10000)
goto kokohe;
1798 }
while(
moveLR(layer[maxNonFixedLayerIndex[nonFixedSuperLayerIndex[2]]]));
1800 fitLine2(allFixedWires, min_chi2, good_a, good_b, goodLine, goodPosition, overCounter);
1801 if(overCounter>10000)
goto kokohe;
1803 }
while(
moveLR(layer[maxNonFixedLayerIndex[nonFixedSuperLayerIndex[1]]]));
1805 fitLine2(allFixedWires, min_chi2, good_a, good_b, goodLine, goodPosition, overCounter);
1806 if(overCounter>10000)
goto kokohe;
1808 }
while(
moveLR(layer[maxNonFixedLayerIndex[nonFixedSuperLayerIndex[0]]]));
1810 }
else if(allFixedWires.length() >= 3){
1811 fitLine2(allFixedWires, min_chi2, good_a, good_b, goodLine, goodPosition, overCounter);
1815 for(
unsigned i = 0, size = goodLine.length(); i < size; ++i){
1816 goodLine[i]->position(*(goodPosition[i]));
1819 std::cout <<
"(TBuilderCurl) make a line from All SuperLayers." << std::endl;
1820 plotArcZ(goodLine, good_a, good_b, 0);
1825TBuilderCurl::fitWDD(
double &xc,
double &yc,
double &r,
1827 if(list.length() <= 3)
return false;
1830 for(
int i=0;i<list.length();++i){
1831 circle.
add_point(list[i]->wire()->xyPosition().
x(),
1832 list[i]->wire()->xyPosition().y(),1.0);
1835 if (circle.
fit() < 0.0 || circle.
kappa() == 0.0)
return false;
1839 const int maxIte = 2;
1840 for(
int ite=0;ite<maxIte;++ite){
1844 for(
int i=0;i<list.length();++i){
1845 double R = sqrt((list[i]->wire()->xyPosition().
x()-xc)*(list[i]->wire()->xyPosition().
x()-xc)+
1846 (list[i]->wire()->xyPosition().y()-yc)*(list[i]->wire()->xyPosition().y()-yc));
1847 if(R == 0.)
continue;
1849 double dir =
R > r ? -1. : 1.;
1850 double X = xc+(list[i]->wire()->xyPosition().x()-xc)*U*(R+dir*list[i]->hit()->drift());
1851 double Y = yc+(list[i]->wire()->xyPosition().y()-yc)*U*(R+dir*list[i]->hit()->drift());
1855 if (circle2.
fit() < 0.0 || circle2.
kappa() == 0.0)
return false;
1856 xc = circle2.
center()[0];
1857 yc = circle2.
center()[1];
1865TBuilderCurl::stereoHit(
double &xc,
double &yc,
double &r,
double &
q,
1868 if(list.length() == 0)
return -1;
1872 for(
unsigned i = 0, size = list.length(); i < size; ++i){
1880 double vmag2 =
v.mag2();
1881 double vmag = sqrt(vmag2);
1883 for(
unsigned j = 0; j < 4; ++j)
1884 list[i]->arcZ(tmp,j);
1887 if (vmag == 0.)
continue;
1890 double R[2] = {r + drift, r - drift};
1891 double wv =
w.dot(
v);
1893 d2[0] = vmag2*
R[0]*
R[0] + (wv*wv - vmag2*
w.mag2());
1894 d2[1] = vmag2*
R[1]*
R[1] + (wv*wv - vmag2*
w.mag2());
1896 if (d2[0] < 0. && d2[1] < 0.)
continue;
1898 bool ok_inner(
true);
1899 bool ok_outer(
true);
1900 double d[2] = {-1., -1.};
1918 l[0][0] = (- wv + d[0]) / vmag2;
1919 l[1][0] = (- wv - d[0]) / vmag2;
1920 z[0][0] = X.z() + l[0][0]*V.z();
1921 z[1][0] = X.z() + l[1][0]*V.z();
1925 l[0][1] = (- wv + d[1]) / vmag2;
1926 l[1][1] = (- wv - d[1]) / vmag2;
1927 z[0][1] = X.z() + l[0][1]*V.z();
1928 z[1][1] = X.z() + l[1][1]*V.z();
1934 p[0][0] =
x + l[0][0] *
v;
1935 p[1][0] =
x + l[1][0] *
v;
1938 p[0][0] -= drift/pc0.mag()*pc0;
1939 tmp_pc = p[1][0] - center;
1941 p[1][0] -= drift/pc1.mag()*pc1;
1944 p[0][1] =
x + l[0][1] *
v;
1945 p[1][1] =
x + l[1][1] *
v;
1948 p[0][1] += drift/pc0.mag()*pc0;
1949 tmp_pc = p[1][1] - center;
1951 p[1][1] += drift/pc1.mag()*pc1;
1960 ok_xy[0][0] =
false;
1961 ok_xy[1][0] =
false;
1967 ok_xy[0][1] =
false;
1968 ok_xy[1][1] =
false;
1971 if (
q * (center.x() * p[0][0].y() - center.y() * p[0][0].x()) < 0.)
1972 ok_xy[0][0] =
false;
1973 if (
q * (center.x() * p[1][0].y() - center.y() * p[1][0].x()) < 0.)
1974 ok_xy[1][0] =
false;
1977 if (
q * (center.x() * p[0][1].y() - center.y() * p[0][1].x()) < 0.)
1978 ok_xy[0][1] =
false;
1979 if (
q * (center.x() * p[1][1].y() - center.y() * p[1][1].x()) < 0.)
1980 ok_xy[1][1] =
false;
1982 if(!ok_inner && ok_outer && (!ok_xy[0][0]) && (!ok_xy[1][0])){
1985 if(ok_inner && !ok_outer && (!ok_xy[0][1]) && (!ok_xy[1][1])){
2007 if ((!ok_xy[0][0]) && (!ok_xy[1][0]) &&
2008 (!ok_xy[0][1]) && (!ok_xy[1][1])){
2012 double cosdPhi, dPhi;
2014 unsigned indexL = 0;
2015 unsigned indexR = 0;
2021 cosdPhi = - center.dot((p[0][0] - center).
unit()) / center.mag();
2022 if(fabs(cosdPhi) < 1.0){
2023 dPhi = acos(cosdPhi);
2024 }
else if(cosdPhi >= 1.0){
2034 if(indexL == 0)list[i]->arcZ(
HepPoint3D(r*dPhi, z[0][0], 0.), 0);
2035 else list[i]->arcZ(
HepPoint3D(r*dPhi, z[0][0], 0.), 2);
2039 if(indexR == 0)list[i]->arcZ(
HepPoint3D(r*dPhi, z[0][0], 0.), 1);
2040 else list[i]->arcZ(
HepPoint3D(r*dPhi, z[0][0], 0.), 3);
2046 cosdPhi = - center.dot((p[1][0] - center).
unit()) / center.mag();
2047 if(fabs(cosdPhi) < 1.0){
2048 dPhi = acos(cosdPhi);
2049 }
else if(cosdPhi >= 1.0){
2059 if(indexL == 0)list[i]->arcZ(
HepPoint3D(r*dPhi, z[1][0], 0.), 0);
2060 else list[i]->arcZ(
HepPoint3D(r*dPhi, z[1][0], 0.), 2);
2064 if(indexR == 0)list[i]->arcZ(
HepPoint3D(r*dPhi, z[1][0], 0.), 1);
2065 else list[i]->arcZ(
HepPoint3D(r*dPhi, z[1][0], 0.), 3);
2071 cosdPhi = - center.dot((p[0][1] - center).
unit()) / center.mag();
2072 if(fabs(cosdPhi) < 1.0){
2073 dPhi = acos(cosdPhi);
2074 }
else if(cosdPhi >= 1.0){
2084 if(indexR == 0)list[i]->arcZ(
HepPoint3D(r*dPhi, z[0][1], 0.), 1);
2085 else list[i]->arcZ(
HepPoint3D(r*dPhi, z[0][1], 0.), 3);
2089 if(indexL == 0)list[i]->arcZ(
HepPoint3D(r*dPhi, z[0][1], 0.), 0);
2090 else list[i]->arcZ(
HepPoint3D(r*dPhi, z[0][1], 0.), 2);
2096 cosdPhi = - center.dot((p[1][1] - center).
unit()) / center.mag();
2097 if(fabs(cosdPhi) < 1.0){
2098 dPhi = acos(cosdPhi);
2099 }
else if(cosdPhi >= 1.0){
2109 if(indexR == 0)list[i]->arcZ(
HepPoint3D(r*dPhi, z[1][1], 0.), 1);
2110 else list[i]->arcZ(
HepPoint3D(r*dPhi, z[1][1], 0.), 3);
2114 if(indexL == 0)list[i]->arcZ(
HepPoint3D(r*dPhi, z[1][1], 0.), 0);
2115 else list[i]->arcZ(
HepPoint3D(r*dPhi, z[1][1], 0.), 2);
2126 unsigned ip)
const {
2128 tmp.append(alayer1);
2130 if(fitWDD(xc,yc,r,tmp)){
2132 stereoHit(xc,yc,r,
q,slayer);
2140 unsigned ip)
const {
2142 tmp.append(alayer1);
2143 tmp.append(alayer2);
2145 if(fitWDD(xc,yc,r,tmp)){
2147 stereoHit(xc,yc,r,
q,slayer);
2155 unsigned ip)
const {
2157 tmp.append(alayer1);
2158 tmp.append(alayer2);
2159 tmp.append(alayer3);
2161 if(fitWDD(xc,yc,r,tmp)){
2163 stereoHit(xc,yc,r,
q,slayer);
2172 unsigned ip)
const {
2174 tmp.append(alayer1);
2175 tmp.append(alayer2);
2176 tmp.append(alayer3);
2177 tmp.append(alayer4);
2179 if(fitWDD(xc,yc,r,tmp)){
2181 stereoHit(xc,yc,r,
q,slayer);
2204#undef DEBUG_CURL_DUMP
2205#undef DEBUG_CURL_GNUPLOT
HepGeom::Vector3D< double > HepVector3D
*******INTEGER m_nBinMax INTEGER m_NdiMax !No of bins in histogram for cell exploration division $ !Last vertex $ !Last active cell $ !Last cell in buffer $ !No of sampling when dividing cell $ !No of function total $ !Flag for random ceel for $ !Flag for type of for WtMax $ !Flag which decides whether vertices are included in the sampling $ entire domain is hyp !Maximum effective eevents per saves r n generator level $ !Flag for chat level in !Latex Output unit
*********DOUBLE PRECISION m_pi INTEGER m_lenwt !max no of aux weights INTEGER m_phmax !maximum photon multiplicity ISR FSR *DOUBLE COMPLEX m_Pauli4 DOUBLE COMPLEX m_AmpBorn DOUBLE COMPLEX m_AmpBoxy DOUBLE COMPLEX m_AmpBorn1 DOUBLE COMPLEX m_AmpBorn2 DOUBLE COMPLEX m_AmpExpo2p DOUBLE COMPLEX m_Rmat DOUBLE COMPLEX m_BoxGZut !DOUBLE COMPLEX m_F1finPair2 !DOUBLE PRECISION m_Vcut DOUBLE PRECISION m_Alfinv DOUBLE PRECISION m_Lorin1 DOUBLE PRECISION m_Lorin2 DOUBLE PRECISION m_b
double cos(const BesAngle a)
#define WireHitFittingValid
#define WireHitInvalidForFit
int SortByWireId(const void *a, const void *b)
Sorter.
****INTEGER imax DOUBLE PRECISION m_pi *DOUBLE PRECISION m_amfin DOUBLE PRECISION m_Chfin DOUBLE PRECISION m_Xenph DOUBLE PRECISION m_sinw2 DOUBLE PRECISION m_GFermi DOUBLE PRECISION m_MfinMin DOUBLE PRECISION m_ta2 INTEGER m_out INTEGER m_KeyFSR INTEGER m_KeyQCD *COMMON c_Semalib $ !copy of input $ !CMS energy $ !beam mass $ !final mass $ !beam charge $ !final charge $ !smallest final mass $ !Z mass $ !Z width $ !EW mixing angle $ !Gmu Fermi $ alphaQED at q
**********Class see also m_nmax DOUBLE PRECISION m_amel DOUBLE PRECISION m_x2 DOUBLE PRECISION m_alfinv DOUBLE PRECISION m_Xenph INTEGER m_KeyWtm INTEGER m_idyfs DOUBLE PRECISION m_zini DOUBLE PRECISION m_q2 DOUBLE PRECISION m_Wt_KF DOUBLE PRECISION m_WtCut INTEGER m_KFfin *COMMON c_KarLud $ !Input CMS energy[GeV] $ !CMS energy after beam spread beam strahlung[GeV] $ !Beam energy spread[GeV] $ !z boost due to beam spread $ !electron beam mass *ff pair spectrum $ !minimum v
HepGeom::Point3D< double > HepPoint3D
int checkBorder(AList< TMLink > &layer0, AList< TMLink > &layer1, AList< TMLink > &layer2)
void selectGoodWires(const AList< TMLink > &allWires, AList< TMLink > &goodWires)
void makeList(AList< TMLink > &layer, AList< TMLink > &list, double q, int border, int checkB, TMLink *layer0)
bool moveLR(AList< TMLink > &hitsOnLayer)
void calVirtualCircle(const TMLink &hit, const TTrack &track, const int LR, HepPoint3D ¢er, double &radius)
unsigned findMaxLocalId(unsigned layerId)
int doLineFit(AList< TMLink > &points, double &m_a, double &m_b, double &chi2, double &nhits, int ipC=1)
unsigned isIsolation(unsigned localId, unsigned maxLocalId, unsigned layerId, int lr, const AList< TMLink > &allStereoList)
void setLR(AList< TMLink > &hitsOnLayer, unsigned LR=0)
int offsetBorder(TMLink *l)
void findTwoHits(AList< TMLink > &twoOnLayer, const AList< TMLink > &hitsOnLayer, const AList< TMLink > &allStereoList)
const HepPoint3D & center(void) const
returns position of helix center(z = 0.);
const HepVector & a(void) const
returns helix parameters.
virtual double getReferField()=0
void add_point(double x, double y, double w=1)
A class to build a track.
virtual int fit(TTrackBase &) const
fits a track using a private fitter.
virtual ~TBuilderCurl()
Destructor.
TBuilderCurl(const std::string &name)
Constructor.
TTrack * buildStereo(TTrack &track, const AList< TMLink > &) const
appends stereo hits to a track.
TTrack * buildStereoMC(TTrack &track, const AList< TMLink > &) const
void setParam(const TCurlFinderParameter &)
double SELECTOR_STRANGE_PZ
double SELECTOR_MAX_IMPACT
unsigned SVD_RECONSTRUCTION
double Z_DIFF_FOR_LAST_ATTEND
double SELECTOR_REPLACE_DZ
double SELECTOR_MAX_SIGMA
A class to fit a TTrackBase object to a helix.
bool tof(void) const
sets/returns propagation-delay correction flag.
int fit(TTrackBase &) const
bool sag(void) const
sets/returns sag correction flag.
bool propagation(void) const
sets/returns propagation-delay correction flag.
A class to represent a track in tracking.
double b(void) const
returns coefficient b.
double a(void) const
returns coefficient a.
float drift(unsigned) const
returns drift distance.
const TMDCWire *const wire(void) const
returns a pointer to a TMDCWire.
unsigned id(void) const
returns id.
unsigned layerId(void) const
returns layer id.
const HepVector3D & direction(void) const
returns direction vector of the wire.
const HepPoint3D & xyPosition(void) const
returns middle position of a wire. z componet is 0.
const HepPoint3D & forwardPosition(void) const
returns position in forward endplate.
const HepPoint3D & backwardPosition(void) const
returns position in backward endplate.
A class to represent a track in tracking.
double a(void) const
returns coefficient a.
double b(void) const
returns coefficient b.
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 class to fit a TTrackBase object to a line.
virtual int fit(TTrackBase &) const
virtual int fit(void)
fits itself by a default fitter. Error was happened if return value is not zero.
virtual void refine(AList< TMLink > &list, double maxSigma)
removes bad points by pull. The bad points are removed from the track, and are returned in 'list'.
void append(TMLink &)
appends a TMLink.
const AList< TMLink > & links(unsigned mask=0) const
returns a list of masked TMLinks assigned to this track. 'mask' will be applied if mask is not 0.
unsigned nLinks(unsigned mask=0) const
returns # of masked TMLinks assigned to this track object.
A class to represent a track in tracking.
const Helix & helix(void) const
returns helix parameter.
int stereoHitForCurl(TMLink &link, AList< HepPoint3D > &arcZList) const
double radius(void) const
returns signed radius.
double impact(void) const
returns signed impact parameter to the origin.
double pt(void) const
returns Pt.
double pz(void) const
returns Pz.
double charge(void) const
returns charge.
complex_t R(double Q2, double M2, double G, double Mp2, double Mm2)