24 #include "RecoTracker/RoadSearchHelixMaker/interface/Dcxmatinv.hh"
25 #include "RecoTracker/RoadSearchHelixMaker/interface/DcxFittedHel.hh"
26 #include "RecoTracker/RoadSearchHelixMaker/interface/DcxHit.hh"
27 #include "RecoTracker/RoadSearchHelixMaker/interface/Dcxprobab.hh"
35 void DcxFittedHel::basics()
36 {nhits=0; itofit=0; fittime=0.0;
37 prob=0.0; chisq=1000000.0;
fail=1300; quality=0; origin=-1; usedonhel=0;
38 bailout=1; chidofbail=1000.0; niter=10;
42 void DcxFittedHel::basics(
const std::vector<DcxHit*> &
e) {
46 origin=OriginIncluded();
50 DcxFittedHel::DcxFittedHel(){basics();}
54 DcxFittedHel::DcxFittedHel(std::vector<DcxHit*> &ListOHits, DcxHel& hel,
double Sfac)
66 DcxFittedHel::~DcxFittedHel( ){ }
80 fittime=rhs.Fittime();
83 quality=rhs.Quality();
85 listohits=rhs.ListOHits();
87 usedonhel=rhs.GetUsedOnHel();
88 bailout=1; chidofbail=1000.0; niter=10;
93 DcxFittedHel& DcxFittedHel::Grow(
const DcxFittedHel& rhs, std::vector<DcxHit*> &ListOAdds){
102 quality=rhs.Quality();
104 listohits=rhs.ListOHits();
106 usedonhel=rhs.GetUsedOnHel();
107 bailout=1; chidofbail=1000.0; niter=10;
108 int kkk=0;
while (ListOAdds[kkk]){ListOAdds[kkk]->SetUsedOnHel(0); kkk++;}
109 kkk=0;
while (listohits[kkk]){listohits[kkk]->SetUsedOnHel(1); kkk++;}
110 double spull; DcxHel
temp=rhs;
111 kkk=0;
while (ListOAdds[kkk]){
112 if (ListOAdds[kkk]->GetUsedOnHel() == 0){
113 spull=ListOAdds[kkk]->pull(temp)/sfac; chisq+=spull*spull;
115 listohits.push_back(ListOAdds[kkk]); nhits++;
119 int ndof=nhits-nfree;
126 float DcxFittedHel::Residual(
int i){
127 float pull=listohits[
i]->pull(*
this);
128 float E=listohits[
i]->e();
132 float DcxFittedHel::Pull(
int i){
133 float pull=listohits[
i]->pull(*
this);
139 if(prob<Probmin) {
return 1303;}
146 void DcxFittedHel::VaryRes() {
147 int kbl=0;
while (listohits[kbl]){listohits[kbl]->SetConstErr(0); kbl++;}
150 int DcxFittedHel::ReFit(){
155 int DcxFittedHel::IterateFit(){
157 if(nfree>=nhits) {
return ftemp;}
161 for (
int i=0; i< niter; i++) {
169 if(ftemp!=0) {
break;}
170 if(fabs(chisq-prevchisq)<0.01*chisq) {
break;}
177 while(fabs(chisq-prevchisq)>0.01) {
182 if(iter>=1000)
break;
185 int ndof=nhits-nfree;
191 int DcxFittedHel::DoFit(){
194 if(nfree>=nhits) {
return ftemp;}
195 double m_2pi=2.0*
M_PI;
199 double A[10][10],
B[10],
D[10], det;
int ii,
jj;
200 for (ii=0; ii<norder; ii++){
201 D[ii]=0.0; B[ii]=0.0;
for (jj=0; jj<norder; jj++){A[ii][
jj]=0.0;}
204 for (
int i=0; i< nhits; i++){
205 std::vector<float> derivs=listohits[
i]->derivatives(*
this);
206 std::ostringstream
output;
209 for(
unsigned int ipar=0; ipar<derivs.size(); ipar++) {derivs[ipar]/=sfac;
210 output <<
" " << derivs[ipar];
214 chisq+=derivs[0]*derivs[0];
216 for(
int ipar=0; ipar<norder; ipar++){
217 D[ipar]+=derivs[0]*derivs[ipar+1];
219 for(
int jpar=0; jpar<norder; jpar++){
220 A[ipar][jpar]+=derivs[ipar+1]*derivs[jpar+1];
225 for (ii=0; ii<norder; ii++){
226 std::ostringstream
output;
227 output << D[ii] <<
" ";
for (jj=0;jj<norder;jj++){output << A[ii][
jj] <<
" ";}
234 int ndof=nhits-nfree;
236 float chiperdof=chisq/ndof;
237 if(chiperdof>chidofbail) {
return ftemp;}
245 for(ii=0;ii<norder;ii++){
for(jj=0;jj<norder;jj++){B[ii]+=A[ii][
jj]*D[
jj];}}
246 for (ii=0; ii<norder; ii++){
247 std::ostringstream
output;
248 output << B[ii] <<
" ";
for(jj=0;jj<norder;jj++){output << A[ii][
jj] <<
" ";}
252 if(qd0) {bump++; d0-=B[bump];}
253 if(qphi0) {bump++; phi0-=B[bump];
254 if (phi0 >
M_PI){phi0-=m_2pi;}
255 if (phi0 < -
M_PI){phi0+=m_2pi;}
256 cphi0=
cos(phi0); sphi0=
sin(phi0);
258 if(qomega) {bump++; omega-=B[bump];
259 ominfl=1;
if(fabs(omega)<omin){ominfl=0;}
261 if(qz0) {bump++; z0-=B[bump];}
262 if(qtanl) {bump++; tanl-=B[bump];}
263 if(qt0) {bump++; t0-=B[bump];}
264 x0=
X0(); y0=
Y0(); xc=Xc(); yc=Yc();
265 if ( fabs(d0) > 80.0 )ftemp=1305;
266 if ( fabs(omega) > 1.0 )ftemp=1306;
275 int DcxFittedHel::OriginIncluded() {
276 for(
int i=0; listohits[
i]; i++) {
277 int type=listohits[
i]->type();
287 int DcxFittedHel::FitPrint(){
289 <<
" iterations to fit= " << itofit
290 <<
" nhits= " << nhits
292 <<
" chisq= " << chisq
295 <<
" fittime= " << fittime ;
299 int DcxFittedHel::FitPrint(DcxHel &hel){
301 double m_2pi=2.0*
M_PI;
302 double difphi0=phi0-hel.Phi0();
303 if (difphi0>
M_PI)difphi0-=m_2pi;
if (difphi0<-
M_PI)difphi0+=m_2pi;
305 <<
" difphi0= " << difphi0
306 <<
" difomega= " << omega-hel.Omega()
307 <<
" difz0= " << z0-hel.Z0()
308 <<
" diftanl= " << tanl-hel.Tanl() ;
313 int DcxFittedHel::Layer(
int hitno)
const {
314 if(hitno>=nhits) {
return 0;}
316 const std::vector<DcxHit*> &temp=(std::vector<DcxHit*>&)listohits;
317 int layer=temp[hitno]->Layer();
322 int DcxFittedHel::SuperLayer(
int hitno)
const {
323 if(hitno>=nhits) {
return 0;}
324 if(hitno<0) {
return 0;}
326 const std::vector<DcxHit*> &temp=(std::vector<DcxHit*>&)listohits;
327 return temp[hitno]->SuperLayer();
nocap nocap const skelname & operator=(const skelname &)
float Dcxprobab(int &ndof, float &chisq)
Sin< T >::type sin(const T &t)
int Dcxmatinv(double *array, int *norder, double *det)
Cos< T >::type cos(const T &t)
DecomposeProduct< arg, typename Div::arg > D