00086 {
00087 int debug = MdcxParameters::debug;
00088
00089 listoasses.removeAll();
00090 if ((whichtrack >= ntracks) || (whichtrack < 0)) {
00091 cout << "asked for associates of track " << whichtrack
00092 << " while there are only " << ntracks << " tracks in list " << endl;
00093 return listoasses;
00094 }
00095
00096 double m_2pi = 2.0*M_PI;
00097 MdcxHel* temphel = tttt[whichtrack];
00098
00099 if(5 == debug) temphel->print();
00100
00101 double lmax = temphel->Lmax();
00102
00103
00104 double gvin = MdcxParameters::firstMdcAxialRadius;
00105 double gvout = MdcxParameters::maxMdcRadius;
00106 double phiex = 0.38;
00107 double phim = -M_PI;
00108 double phip = M_PI;
00109 double rmin = fabs(temphel->D0());
00110 double rmax, pc, rc, rhel;
00111 if (temphel->Ominfl()) {
00112 rmax = fabs(temphel->D0() + 2.0/temphel->Omega());
00113 double xc = temphel->Xc();
00114 double yc = temphel->Yc();
00115 pc = atan2(yc,xc);
00116 rc = fabs(temphel->D0() + 1.0/temphel->Omega());
00117 rhel = fabs(1.0/temphel->Omega());
00118 } else {
00119 rmax = 1000.;
00120 pc = temphel->Phi0();
00121 rc = 1000.;
00122 rhel = 1000.;
00123 }
00124 if(5 == debug) {
00125 std::cout<<__FILE__<<" " << " rmin >?"<<rmin << " gvin "<<gvin
00126 << " rmax >?"<<rmax << " gvout "<<gvout << std::endl;
00127 }
00128
00129 if ((rmin<gvin) && (rmax>gvout)) {
00130
00131 if(5 == debug) std::cout<<__FILE__<<" case A (exiter) "<<std::endl;
00132
00133 double len = 0;
00134 double lstep = m_2pi*rhel/16.;
00135 if (lstep>10.) lstep = 10.;
00136 double xl = temphel->Xh(len);
00137 double yl = temphel->Yh(len);
00138 double phil = atan2(yl, xl);
00139 double rl = sqrt(xl*xl + yl*yl);
00140 int nstep = 0;
00141 double philast = phil;
00142 int isin = 0;
00143 int notout = 1;
00144 while ((notout) && (nstep<20)) {
00145 len += lstep;
00146 nstep++;
00147 xl = temphel->Xh(len);
00148 yl = temphel->Yh(len);
00149 phil = atan2(yl, xl);
00150 rl = sqrt(xl*xl + yl*yl);
00151 if ((rl<gvin) && (!isin)) {
00152 philast = phil;
00153 } else if ((rl>gvin) && (!isin)) {
00154 isin = 1; phim = philast; phip = philast;
00155 }
00156 if (isin) {
00157 double deltap = phil - philast;
00158 if (deltap > M_PI) phil -= m_2pi;
00159 if (deltap < -M_PI) phil += m_2pi;
00160 philast = phil;
00161 if (rl > gvout) notout = 0;
00162 if (phil < phim) phim = phil;
00163 if (phil > phip) phip = phil;
00164 }
00165 }
00166 } else if ((rmin>gvin) && (rmax>gvout)) {
00167 if(5 == debug) std::cout<<__FILE__<<" case B (albedo) "<<std::endl;
00168
00169 double len=0; double lstep=m_2pi*rhel/16.; if (lstep>10.)lstep=10.;
00170 double xl=temphel->Xh(len); double yl=temphel->Yh(len);
00171 double phil=atan2(yl,xl); double rl=sqrt(xl*xl+yl*yl);
00172 phim=phil; phip=phil; double phis=phil; double deltap,dp1,dp2;
00173 int nstep=0; double philast=phil;
00174 while ((rl<gvout)&&(nstep<20)){
00175 len+=lstep; nstep++; xl=temphel->Xh(len); yl=temphel->Yh(len);
00176 phil=atan2(yl,xl); rl=sqrt(xl*xl+yl*yl);
00177 deltap=phil-philast; if (deltap>M_PI)phil-=m_2pi;
00178 if (deltap<-M_PI)phil+=m_2pi; philast=phil;
00179 if (phil<phim)phim=phil; if (phil>phip)phip=phil;
00180 }
00181 dp1=fabs(phis-phim); dp2=fabs(phip-phis); deltap=dp1;
00182 if(dp2>dp1)deltap=dp2; phim=phis-deltap; phip=phis+deltap;
00183 } else if ((rmin<gvin) && (rmax<gvout)) {
00184
00185 if(5 == debug) std::cout<<__FILE__<<" case C (looper) "<<std::endl;
00186 if (rc>rhel){
00187 double alp=asin(rhel/rc); phim=pc-alp; phip=pc+alp;
00188 }else{
00189
00190 double len=0; double lstep=m_2pi*rhel/16.; if (lstep>10.)lstep=10.;
00191 double xl=temphel->Xh(len); double yl=temphel->Yh(len);
00192 double phil=atan2(yl,xl); double rl=sqrt(xl*xl+yl*yl);
00193 int nstep=0; double philast=phil; int isin=0; int notout=1;
00194 while ((notout)&&(nstep<33)){
00195 len+=lstep; nstep++; xl=temphel->Xh(len); yl=temphel->Yh(len);
00196 phil=atan2(yl,xl); rl=sqrt(xl*xl+yl*yl);
00197 if ((rl<gvin)&&(!isin)){
00198 philast=phil;
00199 }else if((rl>gvin)&&(!isin)){
00200 isin=1; phim=philast; phip=philast;
00201 }
00202 if (isin){
00203 double deltap=phil-philast; if (deltap>M_PI)phil-=m_2pi;
00204 if (deltap<-M_PI)phil+=m_2pi; philast=phil; if (rl<gvin)notout=0;
00205 if (phil<phim)phim=phil; if (phil>phip)phip=phil;
00206 }
00207 }
00208 }
00209 } else if ((rmin>gvin) && (rmax<gvout)) {
00210
00211 if (rc > rhel) {
00212 double alp = asin(rhel/rc);
00213 phim = pc - alp;
00214 phip = pc + alp;
00215 }
00216
00217 }
00218 phim -= phiex;
00219 phip += phiex;
00220
00221 if(5 == debug) {
00222 std::cout<<__FILE__<<" phim "<<phim <<" phip "<<phip<< std::endl;
00223 }
00224
00225
00226 kkl = 0;
00227 while(hhhh[kkl]) {
00228 MdcxHit* temphit = hhhh[kkl++];
00229 double factor=1.;
00230 if ((0 != temphit->type()) && (temphit->Layer()>7)) factor = MdcxParameters::addHitFactor;
00231 if (5 == debug){
00232 std::cout<<__FILE__<<" "<<__LINE__<< " try to add hit:"<< std::endl;
00233 temphit->print(std::cout);
00234 std::cout<<__FILE__
00235 <<" used "<<temphit->GetUsedOnHel()
00236 <<" pull " << fabs(temphit->pull(*temphel))
00237 <<" <? nSig " << MdcxParameters::nSigAddHitTrk
00238 << std::endl;
00239 }
00240
00241 if( (!temphit->GetUsedOnHel())
00242 && (fabs(temphit->pull(*temphel))< factor * MdcxParameters::nSigAddHitTrk) ) {
00243
00244 double pw = temphit->pw();
00245 if((phip-pw) > m_2pi) pw += m_2pi;
00246 if((phim-pw) < -m_2pi) pw -= m_2pi;
00247 if ( (pw>phim) && (pw<phip) ) {
00248 temphit->SetConstErr(0);
00249 double pull = temphit->pull( *temphel );
00250 ncalc++;
00251 sumpull += fabs(pull);
00252
00253 if(g_addHitCut) g_addHitCut->fill(fabs(pull));
00254 int layer = temphit->Layer();
00255 if(g_addHitCut2d) g_addHitCut2d->fill(layer,fabs(pull));
00256 if(5 == debug)
00257 std::cout<<__FILE__<<" "
00258 << " pull "<<pull
00259 << " addcut "<< MdcxParameters::nSigAddHitTrk
00260 << " len "<< temphel->Doca_Len()
00261 << " >? lmax "<< lmax
00262 << " >? maxTkLen "<< MdcxParameters::maxTrkLength
00263 << std::endl;
00264
00265 if(fabs(pull) < factor * MdcxParameters::nSigAddHitTrk) {
00266
00267 double len = temphel->Doca_Len();
00268
00269
00270
00271
00272 if (((len>0.0)&&(len<lmax))||((len<0.0)&&(len>-MdcxParameters::maxTrkLength))) {
00273
00274 listoasses.append(temphit);
00275 temphit->SetUsedOnHel(1);
00276 nadded++;
00277 if(5 == debug) std::cout<<"Added "<< std::endl;
00278 }
00279 }
00280 temphit->SetConstErr(1);
00281 }
00282 }
00283 }
00284
00285 return listoasses;
00286 }