00001
00002
00003
00004
00005
00007 #include "RecoRomanPot/RecoFP420/interface/TrackProducerFP420.h"
00008 #include <stdio.h>
00009 #include <gsl/gsl_fit.h>
00010 #include<vector>
00011 #include <iostream>
00012 using namespace std;
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 TrackProducerFP420::TrackProducerFP420(int asn0, int apn0, int arn0, int axytype, double az420, double azD2, double azD3, double apitchX, double apitchY, double apitchXW, double apitchYW, double aZGapLDet, double aZSiStep, double aZSiPlane, double aZSiDet, double azBlade, double agapBlade, bool aUseHalfPitchShiftInX, bool aUseHalfPitchShiftInY, bool aUseHalfPitchShiftInXW, bool aUseHalfPitchShiftInYW, double adXX, double adYY, float achiCutX, float achiCutY, double azinibeg, int verbosity, double aXsensorSize, double aYsensorSize) {
00024
00025
00026
00027 verbos=verbosity;
00028 sn0 = asn0;
00029 pn0 = apn0;
00030 rn0 = arn0;
00031 xytype = axytype;
00032 z420= az420;
00033 zD2 = azD2;
00034 zD3 = azD3;
00035
00036 pitchX = apitchX;
00037 pitchY = apitchY;
00038 pitchXW = apitchXW;
00039 pitchYW = apitchYW;
00040 ZGapLDet = aZGapLDet;
00041 ZSiStep = aZSiStep;
00042 ZSiPlane = aZSiPlane;
00043 ZSiDet = aZSiDet;
00044 zBlade = azBlade;
00045 gapBlade = agapBlade;
00046
00047 UseHalfPitchShiftInX = aUseHalfPitchShiftInX;
00048 UseHalfPitchShiftInY = aUseHalfPitchShiftInY;
00049 UseHalfPitchShiftInXW = aUseHalfPitchShiftInXW;
00050 UseHalfPitchShiftInYW = aUseHalfPitchShiftInYW;
00051 dXX = adXX;
00052 dYY = adYY;
00053 chiCutX = achiCutX;
00054 chiCutY = achiCutY;
00055 zinibeg = azinibeg;
00056 XsensorSize = aXsensorSize;
00057 YsensorSize = aYsensorSize;
00058
00059 if (verbos > 0) {
00060 std::cout << "TrackProducerFP420: call constructor" << std::endl;
00061 std::cout << " sn0= " << sn0 << " pn0= " << pn0 << " rn0= " << rn0 << " xytype= " << xytype << std::endl;
00062 std::cout << " zD2= " << zD2 << " zD3= " << zD3 << " zinibeg= " << zinibeg << std::endl;
00063
00064 std::cout << " pitchX= " << pitchX << " pitchY= " << pitchY << std::endl;
00065 std::cout << " ZGapLDet= " << ZGapLDet << std::endl;
00066 std::cout << " ZSiStep= " << ZSiStep << " ZSiPlane= " << ZSiPlane << std::endl;
00067 std::cout << " ZSiDet= " <<ZSiDet << std::endl;
00068 std::cout << " UseHalfPitchShiftInX= " << UseHalfPitchShiftInX << " UseHalfPitchShiftInY= " << UseHalfPitchShiftInY << std::endl;
00069 std::cout << "TrackProducerFP420:----------------------" << std::endl;
00070 std::cout << " dXX= " << dXX << " dYY= " << dYY << std::endl;
00071 std::cout << " chiCutX= " << chiCutX << " chiCutY= " << chiCutY << std::endl;
00072 }
00073
00074 theFP420NumberingScheme = new FP420NumberingScheme();
00075
00076
00077
00078 }
00080
00081
00082
00083
00084
00086 std::vector<TrackFP420> TrackProducerFP420::trackFinderSophisticated(edm::Handle<ClusterCollectionFP420> input, int det){
00088
00089 std::vector<TrackFP420> rhits;
00090 int restracks = 10;
00091 rhits.reserve(restracks);
00092 rhits.clear();
00093 double Ax[10]; double Bx[10]; double Cx[10]; int Mx[10];
00094 double Ay[10]; double By[10]; double Cy[10]; int My[10];
00095 double AxW[10]; double BxW[10]; double CxW[10]; int MxW[10];
00096 double AyW[10]; double ByW[10]; double CyW[10]; int MyW[10];
00097 if (verbos > 0) {
00098 std::cout << "===============================================================================" << std::endl;
00099 std::cout << "=================================================================" << std::endl;
00100 std::cout << "==========================================================" << std::endl;
00101 std::cout << "= =" << std::endl;
00102 std::cout << "TrackProducerFP420: Start trackFinderSophisticated " << std::endl;
00103 }
00106
00107 if( xytype < 1 || xytype > 2 ){
00108 std::cout << "TrackProducerFP420:ERROR in trackFinderSophisticated: check xytype = " << xytype << std::endl;
00109 return rhits;
00110 }
00111
00112
00113 if( sn0 != 3 ){
00114 std::cout << "TrackProducerFP420:ERROR in trackFinderSophisticated: check sn0 (configuration) = " << sn0 << std::endl;
00115 return rhits;
00116 }
00118 int zbeg = 1, zmax=3;
00120
00121 int reshits1 = 12;
00122 int reshits2 = 24;
00123
00124 int nX[20], nY[20];
00125 int uX[20], uY[20];
00126 double zX[24][20], xX[24][20], wX[24][20];
00127 double zY[24][20], yY[24][20], wY[24][20];
00128 double yXW[24][20], wXW[24][20];
00129 double xYW[24][20], wYW[24][20];
00130 bool qX[24][20], qY[24][20];
00131
00132 int txf = 0; int txs1 = 0; int txss = 0;
00133 int tyf = 0; int tys1 = 0; int tyss = 0;
00134
00135 double pitch=0.;
00136 double pitchW=0.;
00137 if(xytype==1){
00138 pitch=pitchY;
00139 pitchW=pitchYW;
00140 }
00141 else if(xytype==2){
00142 pitch=pitchX;
00143 pitchW=pitchXW;
00144 }
00145
00146
00147
00148 float Xshift = pitch/2.;
00149 float Yshift = pitchW/2.;
00150
00151
00152 int nmetcurx=0;
00153 int nmetcury=0;
00154 unsigned int ii0 = 999999;
00155 int allplacesforsensors=7;
00156 for (int sector=1; sector < sn0; sector++) {
00157 for (int zmodule=1; zmodule<pn0; zmodule++) {
00158 for (int zsideinorder=1; zsideinorder<allplacesforsensors; zsideinorder++) {
00159 int zside = theFP420NumberingScheme->FP420NumberingScheme::realzside(rn0, zsideinorder);
00160 if (verbos == -49) {
00161 std::cout << "TrackProducerFP420: sector= " << sector << " zmodule= " << zmodule << " zsideinorder= " << zsideinorder << " zside= " << zside << " det= " << det << std::endl;
00162 }
00163 if(zside != 0) {
00164 int justlayer = theFP420NumberingScheme->FP420NumberingScheme::unpackLayerIndex(rn0, zside);
00165 if(justlayer<1||justlayer>2) {
00166 std::cout << "TrackProducerFP420:WRONG justlayer= " << justlayer << std::endl;
00167 }
00168 int copyinlayer = theFP420NumberingScheme->FP420NumberingScheme::unpackCopyIndex(rn0, zside);
00169 if(copyinlayer<1||copyinlayer>3) {
00170 std::cout << "TrackProducerFP420:WRONG copyinlayer= " << copyinlayer << std::endl;
00171 }
00172 int orientation = theFP420NumberingScheme->FP420NumberingScheme::unpackOrientation(rn0, zside);
00173 if(orientation<1||orientation>2) {
00174 std::cout << "TrackProducerFP420:WRONG orientation= " << orientation << std::endl;
00175 }
00176
00177
00178 int detfixed=1;
00179 int nlayers=3;
00180 unsigned int ii = theFP420NumberingScheme->FP420NumberingScheme::packMYIndex(nlayers,pn0,sn0,detfixed,justlayer,sector,zmodule)-1;
00181
00183
00184 if (verbos == -49) {
00185 std::cout << "TrackProducerFP420: justlayer= " << justlayer << " copyinlayer= " << copyinlayer << " ii= " << ii << std::endl;
00186 }
00187
00188 double zdiststat = 0.;
00189 if(sn0<4) {
00190 if(sector==2) zdiststat = zD3;
00191 }
00192 else {
00193 if(sector==2) zdiststat = zD2;
00194 if(sector==3) zdiststat = zD3;
00195 }
00196 double kplane = -(pn0-1)/2 - 0.5 + (zmodule-1);
00197 double zcurrent = zinibeg + z420 + (ZSiStep-ZSiPlane)/2 + kplane*ZSiStep + zdiststat;
00198
00199
00200 if(justlayer==1){
00201 if(orientation==1) zcurrent += (ZGapLDet+ZSiDet/2);
00202 if(orientation==2) zcurrent += zBlade-(ZGapLDet+ZSiDet/2);
00203 }
00204 if(justlayer==2){
00205 if(orientation==1) zcurrent += (ZGapLDet+ZSiDet/2)+zBlade+gapBlade;
00206 if(orientation==2) zcurrent += 2*zBlade+gapBlade-(ZGapLDet+ZSiDet/2);
00207 }
00208
00209
00210 if(det == 2) zcurrent = -zcurrent;
00211
00212
00213
00214
00215
00216
00217 float dYYcur = dYY;
00218 float dYYWcur = dXX;
00219
00220 float dXXcur = dXX;
00221 float dXXWcur = dYY;
00222
00223 if(justlayer==2) {
00224
00225 if (UseHalfPitchShiftInX == true){
00226 dXXcur += Xshift;
00227 }
00228
00229 if (UseHalfPitchShiftInXW == true){
00230 dXXWcur -= Yshift;
00231 }
00232 }
00233
00234 double XXXDelta = 0.0;
00235 if(copyinlayer==2) { XXXDelta = XsensorSize;}
00236 if(copyinlayer==3) { XXXDelta = 2.*XsensorSize;}
00237 double YYYDelta = 0.0;
00238 if(copyinlayer==2) { YYYDelta = XsensorSize;}
00239 if(copyinlayer==3) { YYYDelta = 2.*XsensorSize;}
00240
00241
00242
00243 unsigned int iu=theFP420NumberingScheme->FP420NumberingScheme::packMYIndex(rn0,pn0,sn0,det,zside,sector,zmodule);
00244 if (verbos > 0 ) {
00245 std::cout << "TrackProducerFP420: check iu = " << iu << std::endl;
00246 std::cout << "TrackProducerFP420: sector= " << sector << " zmodule= " << zmodule << " zside= " << zside << " det= " << det << " rn0= " << rn0 << " pn0= " << pn0 << " sn0= " << sn0 << " copyinlayer= " << copyinlayer << std::endl;
00247 }
00248
00249 std::vector<ClusterFP420> currentclust;
00250 currentclust.clear();
00251 ClusterCollectionFP420::Range outputRange;
00252 outputRange = input->get(iu);
00253
00254 ClusterCollectionFP420::ContainerIterator sort_begin = outputRange.first;
00255 ClusterCollectionFP420::ContainerIterator sort_end = outputRange.second;
00256 for ( ;sort_begin != sort_end; ++sort_begin ) {
00257
00258 currentclust.push_back(*sort_begin);
00259 }
00260
00261 if (verbos > 0 ) {
00262 std::cout << "TrackProducerFP420: currentclust.size = " << currentclust.size() << std::endl;
00263 }
00264
00265
00266 std::vector<ClusterFP420>::const_iterator simHitIter = currentclust.begin();
00267 std::vector<ClusterFP420>::const_iterator simHitIterEnd = currentclust.end();
00268
00269 if(xytype ==1){
00270 if(ii != ii0) {
00271 ii0=ii;
00272 nY[ii] = 0;
00273 uY[ii] = 0;
00274 nmetcury=0;
00275 }
00276 }
00277 else if(xytype ==2){
00278 if(ii != ii0) {
00279 ii0=ii;
00280 nX[ii] = 0;
00281 uX[ii] = 0;
00282 nmetcurx=0;
00283 }
00284 }
00285
00286 for (;simHitIter != simHitIterEnd; ++simHitIter) {
00287 const ClusterFP420 icluster = *simHitIter;
00288
00289
00290
00291
00292
00293 if(xytype ==1){
00294 nY[ii]++;
00295 if(copyinlayer==1 && nY[ii]>reshits1){
00296 nY[ii]=reshits1;
00297 std::cout << "WARNING-ERROR:TrackproducerFP420: currentclust.size()= " << currentclust.size() <<" bigger reservated number of hits" << " zcurrent=" << zY[nY[ii]-1][ii] << " copyinlayer= " << copyinlayer << " ii= " << ii << std::endl;
00298 }
00299 if(copyinlayer !=1 && nY[ii]>reshits2){
00300 nY[ii]=reshits2;
00301 std::cout << "WARNING-ERROR:TrackproducerFP420: currentclust.size()= " << currentclust.size() <<" bigger reservated number of hits" << " zcurrent=" << zY[nY[ii]-1][ii] << " copyinlayer= " << copyinlayer << " ii= " << ii << std::endl;
00302 }
00303 zY[nY[ii]-1][ii] = zcurrent;
00304 yY[nY[ii]-1][ii] = icluster.barycenter()*pitch+0.5*pitch+YYYDelta;
00305 xYW[nY[ii]-1][ii] = icluster.barycenterW()*pitchW+0.5*pitchW;
00306
00307 yY[nY[ii]-1][ii] = yY[nY[ii]-1][ii] - dYYcur;
00308 wY[nY[ii]-1][ii] = 1./(icluster.barycerror()*pitch);
00309 wY[nY[ii]-1][ii] *= wY[nY[ii]-1][ii];
00310 if(det == 2) {
00311 xYW[nY[ii]-1][ii] =(xYW[nY[ii]-1][ii]+dYYWcur);
00312 }
00313 else {
00314 xYW[nY[ii]-1][ii] =-(xYW[nY[ii]-1][ii]+dYYWcur);
00315 }
00316 wYW[nY[ii]-1][ii] = 1./(icluster.barycerrorW()*pitchW);
00317 wYW[nY[ii]-1][ii] *= wYW[nY[ii]-1][ii];
00318 qY[nY[ii]-1][ii] = true;
00319 if(copyinlayer==1 && nY[ii]==reshits1) break;
00320 if(copyinlayer !=1 && nY[ii]==reshits2) break;
00321 }
00322
00323 else if(xytype ==2){
00324 nX[ii]++;
00325 if (verbos == -49) {
00326 std::cout << "TrackproducerFP420: nX[ii]= " << nX[ii] << " Ncl= " << currentclust.size() << " copyinlayer= " << copyinlayer << " ii= " << ii << " zcurrent = " << zcurrent << " xX= " << icluster.barycenter()*pitch+0.5*pitch+XXXDelta << " yXW= " << icluster.barycenterW()*pitchW+0.5*pitchW << " det= " << det << " cl.size= " << icluster.amplitudes().size() << " cl.ampl[0]= " << icluster.amplitudes()[0] << std::endl;
00327 }
00328 if(copyinlayer==1 && nX[ii]>reshits1){
00329 std::cout << "WARNING-ERROR:TrackproducerFP420: nX[ii]= " << nX[ii] <<" bigger reservated number of hits" << " currentclust.size()= " << currentclust.size() << " copyinlayer= " << copyinlayer << " ii= " << ii << std::endl;
00330 nX[ii]=reshits1;
00331 }
00332 if(copyinlayer !=1 && nX[ii]>reshits2){
00333 std::cout << "WARNING-ERROR:TrackproducerFP420: nX[ii]= " << nX[ii] <<" bigger reservated number of hits" << " currentclust.size()= " << currentclust.size() << " copyinlayer= " << copyinlayer << " ii= " << ii << std::endl;
00334 nX[ii]=reshits2;
00335 }
00336 zX[nX[ii]-1][ii] = zcurrent;
00337 xX[nX[ii]-1][ii] = icluster.barycenter()*pitch+0.5*pitch+XXXDelta;
00338 yXW[nX[ii]-1][ii] = icluster.barycenterW()*pitchW+0.5*pitchW;
00339
00340 xX[nX[ii]-1][ii] =-(xX[nX[ii]-1][ii]+dXXcur);
00341 wX[nX[ii]-1][ii] = 1./(icluster.barycerror()*pitch);
00342 wX[nX[ii]-1][ii] *= wX[nX[ii]-1][ii];
00343 if(det == 2) {
00344 yXW[nX[ii]-1][ii] = -(yXW[nX[ii]-1][ii] - dXXWcur);
00345 }
00346 else {
00347 yXW[nX[ii]-1][ii] = yXW[nX[ii]-1][ii] - dXXWcur;
00348 }
00349 wXW[nX[ii]-1][ii] = 1./(icluster.barycerrorW()*pitchW);
00350 wXW[nX[ii]-1][ii] *= wXW[nX[ii]-1][ii];
00351 qX[nX[ii]-1][ii] = true;
00352 if (verbos == -29) {
00353 std::cout << "trackFinderSophisticated: nX[ii]= " << nX[ii]<< " ii = " << ii << " zcurrent = " << zcurrent << " yXW[nX[ii]-1][ii] = " << yXW[nX[ii]-1][ii] << " xX[nX[ii]-1][ii] = " << xX[nX[ii]-1][ii] << std::endl;
00354 std::cout << " XXXDelta= " << XXXDelta << " dXXcur= " << dXXcur << " -dXXWcur= " << -dXXWcur << std::endl;
00355 std::cout << " icluster.barycerrorW()*pitchW= " << icluster.barycerrorW()*pitchW << " wXW[nX[ii]-1][ii]= " <<wXW[nX[ii]-1][ii] << std::endl;
00356 std::cout << " -icluster.barycenterW()*pitchW+0.5*pitchW = " << icluster.barycenterW()*pitchW+0.5*pitchW << std::endl;
00357 std::cout << "============================================================" << std::endl;
00358 }
00359 if (verbos > 0) {
00360 std::cout << "trackFinderSophisticated: nX[ii]= " << nX[ii]<< " ii = " << ii << " zcurrent = " << zcurrent << " xX[nX[ii]-1][ii] = " << xX[nX[ii]-1][ii] << std::endl;
00361 std::cout << " wX[nX[ii]-1][ii] = " << wX[nX[ii]-1][ii] << " wXW[nX[ii]-1][ii] = " << wXW[nX[ii]-1][ii] << std::endl;
00362 std::cout << " -icluster.barycenter()*pitch-0.5*pitch = " << -icluster.barycenter()*pitch-0.5*pitch << " -dXXcur = " << -dXXcur << " -XXXDelta = " << -XXXDelta << std::endl;
00363 std::cout << "============================================================" << std::endl;
00364 }
00365
00366 if(copyinlayer==1 && nX[ii]==reshits1) break;
00367 if(copyinlayer !=1 && nX[ii]==reshits2) break;
00368 }
00369
00370 }
00371
00372
00373 if(xytype ==1){
00374 if(nY[ii] > nmetcury) {
00375 nmetcury=nY[ii];
00376 ++tyf; if(sector==1) ++tys1; if(sector==(sn0-1)) ++tyss;
00377 }
00378 }
00379
00380 else if(xytype ==2){
00381 if(nX[ii] > nmetcurx) {
00382 nmetcurx=nX[ii];
00383 ++txf; if(sector==1) ++txs1; if(sector==(sn0-1)) ++txss;
00384 }
00385 }
00386
00387 }
00388 }
00389 }
00390 }
00391 if (verbos > 0) {
00392 std::cout << "trackFinderSophisticated: tyf= " << tyf<< " tys1 = " << tys1 << " tyss = " << tyss << std::endl;
00393 std::cout << "trackFinderSophisticated: txf= " << txf<< " txs1 = " << txs1 << " txss = " << txss << std::endl;
00394 std::cout << "============================================================" << std::endl;
00395 }
00396
00397
00398
00399
00400
00401
00402
00403
00404 int nitMax=10;
00405
00406
00407
00408
00409
00410
00411
00412
00413 int pys1Cut = 3, pyssCut = 1, pyallCut= 5;
00414
00415
00416
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00433
00434
00435 double sigman=0.18, ssigma = 2.5, sigmam=0.18;
00436 if( sn0 < 4 ){
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447 sigman=0.30, ssigma = 8.0, sigmam=1.0;
00448
00449 }
00450 if (verbos > 0) {
00451 std::cout << "trackFinderSophisticated: ssigma= " << ssigma << std::endl;
00452 }
00453
00455
00456
00457
00458
00459
00460
00461
00462
00463 int numberXtracks=0, numberYtracks=0, totpl = 2*(pn0-1)*(sn0-1); double sigma;
00464
00465 for (int xytypecurrent=xytype; xytypecurrent<xytype+1; ++xytypecurrent) {
00466 if (verbos > 0) {
00467 std::cout << "trackFinderSophisticated: xytypecurrent= " << xytypecurrent << std::endl;
00468 }
00469
00470
00471
00472 double tg0 = 0.;
00473 int qAcl[20], qAii[20], fip=0, niteration = 0;
00474 int ry = 0, rys1 = 0, ryss = 0;
00475 int tas1=tys1, tass=tyss, taf=tyf;
00476 bool SelectTracks = true;
00477
00479
00480
00481 double yA[24][20], zA[24][20], wA[24][20]; int nA[20], uA[20]; bool qA[24][20];
00482
00483
00484
00485 if(xytypecurrent ==1){
00486
00487 numberYtracks=0;
00488 tg0= 3*1./(800.+20.);
00489 tas1=tys1;
00490 tass=tyss;
00491 taf=tyf;
00492 for (int ii=0; ii < totpl; ++ii) {
00493 if (verbos > 0) {
00494 std::cout << "trackFinderSophisticated: ii= " << ii << " nY[ii]= " << nY[ii] << std::endl;
00495 std::cout << "trackFinderSophisticated: ii= " << ii << " uY[ii]= " << uY[ii] << std::endl;
00496 }
00497 nA[ii] = nY[ii];
00498 uA[ii] = uY[ii];
00499 for (int cl=0; cl<nA[ii]; ++cl) {
00500 if (verbos > 0) {
00501 std::cout << " cl= " << cl << " yY[cl][ii]= " << yY[cl][ii] << std::endl;
00502 std::cout << " zY[cl][ii]= " << zY[cl][ii] << " wY[cl][ii]= " << wY[cl][ii] << " qY[cl][ii]= " << qY[cl][ii] << std::endl;
00503 }
00504 yA[cl][ii] = yY[cl][ii];
00505 zA[cl][ii] = zY[cl][ii];
00506 wA[cl][ii] = wY[cl][ii];
00507 qA[cl][ii] = qY[cl][ii];
00508 }
00509 }
00510
00511 }
00512
00513
00514 else if(xytypecurrent ==2){
00515
00516 numberXtracks=0;
00517 tg0= 3*2./(800.+20.);
00518 tas1=txs1;
00519 tass=txss;
00520 taf=txf;
00521 for (int ii=0; ii < totpl; ++ii) {
00522 if (verbos > 0) {
00523 std::cout << "trackFinderSophisticated: ii= " << ii << " nX[ii]= " << nX[ii] << std::endl;
00524 std::cout << "trackFinderSophisticated: ii= " << ii << " uX[ii]= " << uX[ii] << std::endl;
00525 }
00526 nA[ii] = nX[ii];
00527 uA[ii] = uX[ii];
00528 for (int cl=0; cl<nA[ii]; ++cl) {
00529 if (verbos == -29) {
00530 std::cout << " cl= " << cl << " xX[cl][ii]= " << xX[cl][ii] << std::endl;
00531 std::cout << " zX[cl][ii]= " << zX[cl][ii] << " wX[cl][ii]= " << wX[cl][ii] << " qX[cl][ii]= " << qX[cl][ii] << std::endl;
00532 }
00533 yA[cl][ii] = xX[cl][ii];
00534 zA[cl][ii] = zX[cl][ii];
00535 wA[cl][ii] = wX[cl][ii];
00536 qA[cl][ii] = qX[cl][ii];
00537 }
00538 }
00539
00540 }
00541
00542
00543
00544
00545 if (verbos > 0) {
00546 std::cout << " start road finder " << std::endl;
00547 }
00548 do {
00549 double fyY[20], fzY[20], fwY[20];
00550 double fyYW[20], fwYW[20];
00551 int py = 0, pys1 = 0, pyss = 0;
00552 bool NewStation = false, py1first = false;
00553 for (int sector=1; sector < sn0; ++sector) {
00554 double tav=0., t1=0., t2=0., t=0., sm;
00555 int stattimes=0;
00556 if( sector != 1 ) {
00557 NewStation = true;
00558 }
00559 for (int zmodule=1; zmodule<pn0; ++zmodule) {
00560 for (int justlayer=zbeg; justlayer<zmax; justlayer++) {
00561
00562 int detfixed=1;
00563 int nlayers=3;
00564 unsigned int ii = theFP420NumberingScheme->FP420NumberingScheme::packMYIndex(nlayers,pn0,sn0,detfixed,justlayer,sector,zmodule)-1;
00565
00566
00567 if(nA[ii]!=0 && uA[ii]!= nA[ii]) {
00568
00569 ++py; if(sector==1) ++pys1; if(sector==(sn0-1)) ++pyss;
00570 if(py==2 && sector==1) {
00571
00572 double dymin=9999999., df2; int cl2=-1;
00573 for (int cl=0; cl<nA[ii]; ++cl) {
00574 if(qA[cl][ii]){
00575 df2 = std::abs(fyY[fip]-yA[cl][ii]);
00576 if(df2 < dymin) {
00577 dymin = df2;
00578 cl2=cl;
00579 }
00580 }
00581 }
00582
00583 if(cl2!=-1){
00584 t=(yA[cl2][ii]-fyY[fip])/(zA[cl2][ii]-fzY[fip]);
00585 t1 = t*wA[cl2][ii];
00586 t2 = wA[cl2][ii];
00587 if (verbos > 0) {
00588 std::cout << " t= " << t << " tg0= " << tg0 << std::endl;
00589 }
00590 if(std::abs(t)<tg0) {
00591 qA[cl2][ii] = false;
00592 fyY[py-1]=yA[cl2][ii];
00593 fzY[py-1]=zA[cl2][ii];
00594 fwY[py-1]=wA[cl2][ii];
00595 qAcl[py-1] = cl2;
00596 qAii[py-1] = ii;
00597 ++uA[ii];
00598 if (verbos > 0) {
00599 std::cout << " point is taken, mark it for not using again uA[ii]= " << uA[ii] << std::endl;
00600 }
00601 if(uA[ii]==nA[ii]){
00602 ++ry; if(sector==1) ++rys1; if(sector==(sn0-1)) ++ryss;
00603 }
00604 }
00605 else{
00606 py--; if(sector==1) pys1--; if(sector==(sn0-1)) pyss--;
00607 t1 -= t*wA[cl2][ii]; t2 -= wA[cl2][ii];
00608 }
00609 }
00610 else{
00611 py--; if(sector==1) pys1--; if(sector==(sn0-1)) pyss--;
00612 }
00613 }
00614 else {
00615
00616 bool clLoopTrue = true;
00617 int clcurr=-1;
00618 for (int clind=0; clind<nA[ii]; ++clind) {
00619 if(clLoopTrue) {
00620 int cl=clind;
00621 if(qA[cl][ii]){
00622 clcurr = cl;
00623 if(py<3 ){
00624 if(py==1) {
00625 py1first = true;
00626 fip=py-1;
00627 qA[cl][ii] = false;
00628 fyY[py-1]=yA[cl][ii];
00629 fzY[py-1]=zA[cl][ii];
00630 fwY[py-1]=wA[cl][ii];
00631 qAcl[py-1] = cl;
00632 qAii[py-1] = ii;
00633 ++uA[ii];
00634 if (verbos > 0) std::cout << " point is taken, mark it uA[ii]= " << uA[ii] << std::endl;
00635 }
00636 if(uA[ii]==nA[ii]){
00637 ++ry; if(sector==1) ++rys1; if(sector==(sn0-1)) ++ryss;
00638 }
00639 }
00640 else {
00641 if(NewStation){
00642 if( sn0 < 4 ) {
00643
00644 sigma = ssigma;
00645 }
00646 else {
00647 sigma = ssigma/(sn0-1-sector);
00648 }
00649
00650
00651 if(stattimes==1 || sector==3 ) sigma = sigmam;
00652
00653
00654 double cov00, cov01, cov11, c0Y, c1Y, chisqY;
00655 gsl_fit_wlinear (fzY, 1, fwY, 1, fyY, 1, py-1,
00656 &c0Y, &c1Y, &cov00, &cov01, &cov11,
00657 &chisqY);
00658
00659
00660 int cl2match=-1;
00661 double dymin=9999999., df2;
00662 for (int clmatch=0; clmatch<nA[ii]; ++clmatch) {
00663 if(qA[clmatch][ii]){
00664 double smmatch = c0Y+ c1Y*zA[clmatch][ii];
00665 df2 = std::abs(smmatch-yA[clmatch][ii]);
00666 if(df2 < dymin) {
00667 dymin = df2;
00668 cl2match=clmatch;
00669 }
00670 }
00671 }
00672
00673 if(cl2match != -1) {
00674 cl=cl2match;
00675 clLoopTrue = false;
00676 }
00677
00678 sm = c0Y+ c1Y*zA[cl][ii];
00679
00680 if (verbos > 0) {
00681 std::cout << " sector= " << sector << " sn0= " << sn0 << " sigma= " << sigma << std::endl;
00682 std::cout << " stattimes= " << stattimes << " ssigma= " << ssigma << " sigmam= " << sigmam << std::endl;
00683 std::cout << " sm= " << sm << " c0Y= " << c0Y << " c1Y= " << c1Y << " chisqY= " << chisqY << std::endl;
00684 std::cout << " zA[cl][ii]= " << zA[cl][ii] << " ii= " << ii << " cl= " << cl << std::endl;
00685 for (int ct=0; ct<py-1; ++ct) {
00686 std::cout << " py-1= " << py-1 << " fzY[ct]= " << fzY[ct] << std::endl;
00687 std::cout << " fyY[ct]= " << fyY[ct] << " fwY[ct]= " << fwY[ct] << std::endl;
00688 }
00689 }
00690
00691 }
00692 else{
00693 t=(yA[cl][ii]-fyY[fip])/(zA[cl][ii]-fzY[fip]);
00694 t1 += t*wA[cl][ii];
00695 t2 += wA[cl][ii];
00696 tav=t1/t2;
00697 sm = fyY[fip]+tav*(zA[cl][ii]-fzY[fip]);
00698
00699 sigma = sigman;
00700 }
00701
00702 double diffpo = yA[cl][ii]-sm;
00703 if (verbos > 0) {
00704 std::cout << " diffpo= " << diffpo << " yA[cl][ii]= " << yA[cl][ii] << " sm= " << sm << " sigma= " << sigma << std::endl;
00705 }
00706
00707 if(std::abs(diffpo) < sigma ) {
00708 if(NewStation){
00709 ++stattimes;
00710 if(stattimes==1) {
00711 fip=py-1;
00712 t1 = 0; t2 = 0;
00713 }
00714 else if(stattimes==2){
00715 NewStation = false;
00716 t=(yA[cl][ii]-fyY[fip])/(zA[cl][ii]-fzY[fip]);
00717
00718
00719 t1 = t*wA[cl][ii];
00720 t2 = wA[cl][ii];
00721 }
00722 }
00723 fyY[py-1]=yA[cl][ii];
00724 fzY[py-1]=zA[cl][ii];
00725 fwY[py-1]=wA[cl][ii];
00726 qA[cl][ii] = false;
00727 qAcl[py-1] = cl;
00728 qAii[py-1] = ii;
00729 ++uA[ii];
00730 if (verbos > 0) {
00731 std::cout << " 3333 point is taken, mark it uA[ii]= " << uA[ii] << std::endl;
00732 }
00733 if(uA[ii]==nA[ii]){
00734 ++ry; if(sector==1) ++rys1; if(sector==(sn0-1)) ++ryss;
00735 }
00736
00737 }
00738 else{
00739 t1 -= t*wA[cl][ii]; t2 -= wA[cl][ii];
00740 }
00741 }
00742
00743 if(!qA[cl][ii]) break;
00744 }
00745 }
00746 }
00747
00748 if( (py!=1 && clcurr != -1 && qA[clcurr][ii]) || (py==1 && !py1first)) {
00749
00750 py--; if(sector==1) pys1--; if(sector==(sn0-1)) pyss--;
00751 }
00752 }
00753 }
00754 }
00755 }
00756 }
00757
00759
00760 if (verbos > 0) {
00761 std::cout << "END: pys1= " << pys1 << " pyss = " << pyss << " py = " << py << std::endl;
00762 }
00763
00764
00765 if( pys1 < pys1Cut || pyss < pyssCut || py < pyallCut ){
00766
00767 }
00768
00769 else{
00771 double cov00, cov01, cov11;
00772 double c0Y, c1Y, chisqY;
00773 gsl_fit_wlinear (fzY, 1, fwY, 1, fyY, 1, py,
00774 &c0Y, &c1Y, &cov00, &cov01, &cov11,
00775 &chisqY);
00777
00778
00779
00780
00781
00782
00783
00784
00785
00787 float chindfx;
00788 if(py>2) {
00789 chindfx = chisqY/(py-2);
00790 }
00791 else{
00792
00793 chindfx = 9999;
00794 }
00795 if (verbos > 0) {
00796
00797 std::cout << " Do FIT XZ: chindfx= " << chindfx << " chisqY= " << chisqY << " py= " << py << std::endl;
00798 }
00799
00801 if (verbos > 0) {
00802 std::cout << " preparation for second order fit for Wide pixels= " << std::endl;
00803 }
00804 for (int ipy=0; ipy<py; ++ipy) {
00805 if(xytypecurrent ==1){
00806 fyYW[ipy]=xYW[qAcl[ipy]][qAii[ipy]];
00807 fwYW[ipy]=wYW[qAcl[ipy]][qAii[ipy]];
00808 if (verbos > 0) {
00809 std::cout << " ipy= " << ipy << std::endl;
00810 std::cout << " qAcl[ipy]= " << qAcl[ipy] << " qAii[ipy]= " << qAii[ipy] << std::endl;
00811 std::cout << " fyYW[ipy]= " << fyYW[ipy] << " fwYW[ipy]= " << fwYW[ipy] << std::endl;
00812 }
00813 }
00814 else if(xytypecurrent ==2){
00815 fyYW[ipy]=yXW[qAcl[ipy]][qAii[ipy]];
00816 fwYW[ipy]=wXW[qAcl[ipy]][qAii[ipy]];
00817 if (verbos ==-29) {
00818 std::cout << " ipy= " << ipy << std::endl;
00819 std::cout << " qAcl[ipy]= " << qAcl[ipy] << " qAii[ipy]= " << qAii[ipy] << std::endl;
00820 std::cout << " fyYW[ipy]= " << fyYW[ipy] << " fwYW[ipy]= " << fwYW[ipy] << std::endl;
00821 }
00822 }
00823 }
00824
00825
00826
00827 if (verbos > 0) {
00828 std::cout << " start second order fit for Wide pixels= " << std::endl;
00829 }
00830 double wov00, wov01, wov11;
00831 double w0Y, w1Y, whisqY;
00832 gsl_fit_wlinear (fzY, 1, fwYW, 1, fyYW, 1, py,
00833 &w0Y, &w1Y, &wov00, &wov01, &wov11,
00834 &whisqY);
00836
00837
00838
00839 float chindfy;
00840 if(py>2) {
00841 chindfy = whisqY/(py-2);
00842 }
00843 else{
00844
00845 chindfy = 9999;
00846 }
00847
00848 if (verbos > 0) {
00849 std::cout << " chindfy= " << chindfy << " chiCutY= " << chiCutY << std::endl;
00850 }
00851
00852
00853 if(xytypecurrent ==1){
00854 if(chindfx < chiCutX && chindfy < chiCutY) {
00855 ++numberYtracks;
00856 Ay[numberYtracks-1] = c0Y;
00857 By[numberYtracks-1] = c1Y;
00858 Cy[numberYtracks-1] = chisqY;
00859
00860 My[numberYtracks-1] = py;
00861 AyW[numberYtracks-1] = w0Y;
00862 ByW[numberYtracks-1] = w1Y;
00863 CyW[numberYtracks-1] = whisqY;
00864 MyW[numberYtracks-1] = py;
00865 if (verbos > 0) {
00866 if(py>20) {
00867 std::cout << " niteration = " << niteration << std::endl;
00868 std::cout << " chindfy= " << chindfy << " py= " << py << std::endl;
00869 std::cout << " c0Y= " << c0Y << " c1Y= " << c1Y << std::endl;
00870 std::cout << " pys1= " << pys1 << " pyss = " << pyss << std::endl;
00871 }
00872 }
00873 }
00874 }
00875 else if(xytypecurrent ==2){
00876 if(chindfx < chiCutX && chindfy < chiCutY) {
00877 ++numberXtracks;
00878 Ax[numberXtracks-1] = c0Y;
00879 Bx[numberXtracks-1] = c1Y;
00880 Cx[numberXtracks-1] = chisqY;
00881
00882 Mx[numberXtracks-1] = py;
00883 AxW[numberXtracks-1] = w0Y;
00884 BxW[numberXtracks-1] = w1Y;
00885 CxW[numberXtracks-1] = whisqY;
00886 MxW[numberXtracks-1] = py;
00887 if (verbos > 0) {
00888 std::cout << " niteration = " << niteration << std::endl;
00889 std::cout << " chindfx= " << chindfy << " px= " << py << std::endl;
00890 std::cout << " c0X= " << c0Y << " c1X= " << c1Y << std::endl;
00891 std::cout << " pxs1= " << pys1 << " pxss = " << pyss << std::endl;
00892 }
00893 }
00894 }
00895
00896
00897 }
00899
00900 if (verbos > 0) {
00901 std::cout << "Current iteration, niteration >= " << niteration << std::endl;
00902 std::cout << " numberYtracks= " << numberYtracks << std::endl;
00903 std::cout << " numberXtracks= " << numberXtracks << std::endl;
00904 std::cout << " pys1= " << pys1 << " pyss = " << pyss << " py = " << py << std::endl;
00905 std::cout << " tas1= " << tas1 << " tass = " << tass << " taf = " << taf << std::endl;
00906 std::cout << " rys1= " << rys1 << " ryss = " << ryss << " ry = " << ry << std::endl;
00907 std::cout << " tas1-rys1= " << tas1-rys1 << " tass-ryss = " << tass-ryss << " taf-ry = " << taf-ry << std::endl;
00908 std::cout << "---------------------------------------------------------- " << std::endl;
00909 }
00910
00911 if( tas1-rys1<pys1Cut || tass-ryss<pyssCut || taf-ry<pyallCut ){
00912 SelectTracks = false;
00913 }
00914 else{
00915 ++niteration;
00916 }
00917
00918 } while(SelectTracks && niteration < nitMax );
00919
00920
00921
00922
00923
00924
00925
00926 }
00927
00928
00929 if (verbos > 0) {
00930 std::cout << " numberXtracks= " << numberXtracks << " numberYtracks= " << numberYtracks << std::endl;
00931 }
00932
00933
00934
00935
00936
00937 if(xytype>2) {
00938
00939
00940
00941
00942
00943 if (verbos > 0) {
00944 std::cout << " numberXtracks= " << numberXtracks << " numberYtracks= " << numberYtracks << std::endl;
00945 }
00946 if(numberXtracks>0) {
00947 int newxnum[10], newynum[10];
00948 int nmathed=0;
00949 do {
00950 double dthmin= 999999.;
00951 int trminx=-1, trminy=-1;
00952 for (int trx=0; trx<numberXtracks; ++trx) {
00953 if (verbos > 0) {
00954 std::cout << "----------- trx= " << trx << " nmathed= " << nmathed << std::endl;
00955 }
00956 for (int tr=0; tr<numberYtracks; ++tr) {
00957 if (verbos > 0) {
00958 std::cout << "--- tr= " << tr << " nmathed= " << nmathed << std::endl;
00959 }
00960 bool YesY=false;
00961 for (int nmx=0; nmx<nmathed; ++nmx) {
00962 if(trx==newxnum[nmx]) YesY=true;
00963 if(YesY) break;
00964 for (int nm=0; nm<nmathed; ++nm) {
00965 if(tr==newynum[nm]) YesY=true;
00966 if(YesY) break;
00967 }
00968 }
00969 if(!YesY) {
00970
00971
00972
00973
00974
00975
00976
00977 double dthdif= std::abs(AxW[trx]-Ay[tr]) + std::abs(BxW[trx]-By[tr]);
00978
00979 if (verbos > 0) {
00980
00981 std::cout << " abs(AxW[trx]-Ay[tr]) = " << std::abs(AxW[trx]-Ay[tr]) << " abs(BxW[trx]-By[tr])= " << std::abs(BxW[trx]-By[tr]) << " dthdif= " << dthdif << std::endl;
00982 }
00983
00984 if( dthdif < dthmin ) {
00985 dthmin = dthdif;
00986 trminx = trx;
00987 trminy = tr;
00988 }
00989
00990 }
00991 }
00992 }
00993 ++nmathed;
00994 if(trminx != -1) {
00995 newxnum[nmathed-1] = trminx;
00996 }
00997 else{
00998 newxnum[nmathed-1] = nmathed-1;
00999 }
01000 if (verbos > 0) {
01001 std::cout << " trminx= " << trminx << std::endl;
01002 }
01003 if(nmathed>numberYtracks){
01004 newynum[nmathed-1] = -1;
01005 if (verbos > 0) {
01006 std::cout << "!!! nmathed= " << nmathed << " > numberYtracks= " << numberYtracks << std::endl;
01007 }
01008 }
01009 else {
01010 if (verbos > 0) {
01011 std::cout << " trminy= " << trminy << std::endl;
01012 }
01013 newynum[nmathed-1] = trminy;
01014 }
01015 } while(nmathed<numberXtracks && nmathed < restracks);
01016
01017
01018
01019
01020 for (int tr=0; tr<nmathed; ++tr) {
01021 int tx=newxnum[tr];
01022 int ty=newynum[tr];
01023 if(ty==-1){
01024 ty=tx;
01025 Ay[ty]=999.;
01026 By[ty]=999.;
01027 Cy[ty]=999.;
01028 My[ty]=-1;
01029 }
01030
01031
01032
01033 if (verbos > 0) {
01034 if(Mx[tx]>20) {
01035 std::cout << " for track tr= " << tr << " tx= " << tx << " ty= " << ty << std::endl;
01036 std::cout << " Ax= " << Ax[tx] << " Ay= " << Ay[ty] << std::endl;
01037 std::cout << " Bx= " << Bx[tx] << " By= " << By[ty] << std::endl;
01038 std::cout << " Cx= " << Cx[tx] << " Cy= " << Cy[ty] << std::endl;
01039 std::cout << " Mx= " << Mx[tx] << " My= " << My[ty] << std::endl;
01040 std::cout << " AxW= " << AxW[tx] << " AyW= " << AyW[ty] << std::endl;
01041 std::cout << " BxW= " << BxW[tx] << " ByW= " << ByW[ty] << std::endl;
01042 std::cout << " CxW= " << CxW[tx] << " CyW= " << CyW[ty] << std::endl;
01043 std::cout << " MxW= " << MxW[tx] << " MyW= " << MyW[ty] << std::endl;
01044 }
01045 }
01046
01047 rhits.push_back( TrackFP420(Ax[tx],Bx[tx],Cx[tx],Mx[tx],Ay[ty],By[ty],Cy[ty],My[ty]) );
01048 }
01049
01050 }
01051
01052
01053 }
01054
01055 else if(xytype==1) {
01056 for (int ty=0; ty<numberYtracks; ++ty) {
01057 if (verbos > 0) {
01058 std::cout << " for track ty= " << ty << std::endl;
01059 std::cout << " Ay= " << Ay[ty] << std::endl;
01060 std::cout << " By= " << By[ty] << std::endl;
01061 std::cout << " Cy= " << Cy[ty] << std::endl;
01062 std::cout << " My= " << My[ty] << std::endl;
01063 std::cout << " AyW= " << AyW[ty] << std::endl;
01064 std::cout << " ByW= " << ByW[ty] << std::endl;
01065 std::cout << " CyW= " << CyW[ty] << std::endl;
01066 std::cout << " MyW= " << MyW[ty] << std::endl;
01067 }
01068 rhits.push_back( TrackFP420(AyW[ty],ByW[ty],CyW[ty],MyW[ty],Ay[ty],By[ty],Cy[ty],My[ty]) );
01069 }
01070
01071 }
01072
01073 else if(xytype==2) {
01074 for (int tx=0; tx<numberXtracks; ++tx) {
01075 if (verbos > 0) {
01076 std::cout << " for track tx= " << tx << std::endl;
01077 std::cout << " Ax= " << Ax[tx] << std::endl;
01078 std::cout << " Bx= " << Bx[tx] << std::endl;
01079 std::cout << " Cx= " << Cx[tx] << std::endl;
01080 std::cout << " Mx= " << Mx[tx] << std::endl;
01081 std::cout << " AxW= " << AxW[tx] << std::endl;
01082 std::cout << " BxW= " << BxW[tx] << std::endl;
01083 std::cout << " CxW= " << CxW[tx] << std::endl;
01084 std::cout << " MxW= " << MxW[tx] << std::endl;
01085 }
01086 rhits.push_back( TrackFP420(Ax[tx],Bx[tx],Cx[tx],Mx[tx],AxW[tx],BxW[tx],CxW[tx],MxW[tx]) );
01087 }
01088
01089 }
01090
01091
01092
01093
01095
01096
01097
01098 return rhits;
01099
01100 }
01104
01105