@@ -216,7 +216,7 @@ float FastTracker::dist(float z, float r)
216216 int nSteps = 301 ;
217217 const int nSigma = 4 ;
218218 float dist = 0.0 ;
219- float dz0 = (nSigma * sigmaD - (-nSigma) * sigmaD / (nSteps - 1 ) );
219+ float dz0 = (nSigma * sigmaD - (-nSigma) * sigmaD) / (nSteps - 1 );
220220 float z0 = 0.0 ;
221221 for (int i = 0 ; i < nSteps; i++) {
222222 if (i == nSteps - 1 ) {
@@ -239,7 +239,7 @@ float FastTracker::oneEventHitDensity(float multiplicity, float radius)
239239 // see here:
240240 // https://github.com/AliceO2Group/DelphesO2/blob/master/src/DetectorK/DetectorK.cxx#L694
241241 float den = multiplicity / (o2::constants::math::TwoPI * radius * radius);
242- float tg = o2::math_utils::tan (2 . * o2::math_utils::atan (-avgRapidity));
242+ float tg = o2::math_utils::tan (2 . * o2::math_utils::atan (std::exp ( -avgRapidity))); // theta = 2 atan(exp(-eta))
243243 den = den / o2::math_utils::sqrt (1 + 1 / (tg * tg));
244244 return den;
245245}
@@ -249,7 +249,7 @@ float FastTracker::integratedHitDensity(float multiplicity, float radius)
249249 // porting of DetektorK::IntegratedHitDensity
250250 // see here:
251251 // https://github.com/AliceO2Group/DelphesO2/blob/master/src/DetectorK/DetectorK.cxx#L712
252- float zdcHz = luminosity * 1 .e24 * mCrossSectionMinB ;
252+ float zdcHz = luminosity * 1 .e - 24 * mCrossSectionMinB ; // cm^-2 s^-1 * barn (1 b = 1e-24 cm^2)
253253 float den = zdcHz * integrationTime / 1000 . * multiplicity * dist (0 ., radius) / (o2::constants::math::TwoPI * radius);
254254 if (den < oneEventHitDensity (multiplicity, radius)) {
255255 den = oneEventHitDensity (multiplicity, radius);
@@ -286,9 +286,9 @@ float FastTracker::hitDensity(float radius)
286286 // Look-up tables, UpcHitDensity(radius) always returns 0,
287287 // hence it is left commented out for now
288288 if (radius < maxRadiusSlowDet) {
289- arealDensity = oneEventHitDensity (dNdEtaCent, radius);
290- arealDensity += otherBackground * oneEventHitDensity (dNdEtaMinB, radius) + integratedHitDensity (dNdEtaMinB, radius);
289+ arealDensity = oneEventHitDensity (dNdEtaCent, radius) + integratedHitDensity (dNdEtaMinB, radius);
291290 // +UpcHitDensity(radius);
291+ arealDensity += otherBackground * integratedHitDensity (dNdEtaMinB, radius);
292292 }
293293 return arealDensity;
294294}
@@ -317,6 +317,8 @@ int FastTracker::fastTrack(o2::track::TrackParCov inputTrack, o2::track::TrackPa
317317 std::array<float , 3 > posIni{}; // provision for != PV
318318 inputTrack.getXYZGlo (posIni);
319319 const float initialRadius = std::hypot (posIni[0 ], posIni[1 ]);
320+ const float initialX = inputTrack.getX (); // local X of the input track, used for back-propagation
321+ const float initialAlpha = inputTrack.getAlpha (); // frame of the input track
320322 const float kTrackingMargin = 0.1 ;
321323
322324 int firstActiveLayer = -1 ; // first layer that is not inert
@@ -365,7 +367,9 @@ int FastTracker::fastTrack(o2::track::TrackParCov inputTrack, o2::track::TrackPa
365367
366368 // check if layer is reached
367369 float targetX = 1e+3 ;
368- inputTrack.getXatLabR (layers[il].getRadius (), targetX, magneticField);
370+ // propagate outward: for a track starting at the vertex both crossings of the cylinder are at about the same
371+ // distance and DirAuto may pick the one behind the vertex, i.e. propagate the track backwards
372+ inputTrack.getXatLabR (layers[il].getRadius (), targetX, magneticField, o2::track::DirOutward);
369373 if (targetX > InterceptFailed) {
370374 LOGF (debug, " Failed to find intercept for layer %d at radius %.2f cm" , il, layers[il].getRadius ());
371375 break ; // failed to find intercept
@@ -383,6 +387,14 @@ int FastTracker::fastTrack(o2::track::TrackParCov inputTrack, o2::track::TrackPa
383387 }
384388 }
385389 }
390+ // as in DetectorK::SolveTrack: in the frame of an active layer the track must have |sin(phi)| < mMaxSnp,
391+ // otherwise the layer is considered not reached (avoids grazing crossings)
392+ if (ok && !layers[il].isInert ()) {
393+ std::array<float , 3 > posLayer{};
394+ inputTrack.getXYZGlo (posLayer);
395+ o2::track::TrackParCov trackInLayerFrame (inputTrack);
396+ ok = trackInLayerFrame.rotate (std::atan2 (posLayer[1 ], posLayer[0 ])) && std::abs (trackInLayerFrame.getSnp ()) < mMaxSnp ;
397+ }
386398 LOGF (debug, " Propagation was %s up to layer %d" , ok ? " successful" : " unsuccessful" , il);
387399
388400 // was there a problem on this layer?
@@ -429,26 +441,39 @@ int FastTracker::fastTrack(o2::track::TrackParCov inputTrack, o2::track::TrackPa
429441 o2::track::TrackParCov inwardTrack (inputTrack);
430442
431443 // Enlarge covariance matrix
432- std::array<float , o2::track::kNParams > trPars = {0 .};
433- for (int ip = 0 ; ip < o2::track::kNParams ; ip++) {
434- trPars[ip] = outputTrack.getParam (ip);
435- }
436444 static constexpr float LargeErr2Coord = 5 * 5 ;
437445 static constexpr float LargeErr2Dir = 0.7 * 0.7 ;
438446 static constexpr float LargeErr2PtI = 30.5 * 30.5 ;
439- std::array<float , o2::track::kCovMatSize > largeCov = {0 .};
440- for (int ic = o2::track::kCovMatSize ; ic > 0 ; --ic) {
441- largeCov[ic] = 0 .;
442- }
443- largeCov[o2::track::CovLabels::kSigY2 ] = largeCov[o2::track::CovLabels::kSigZ2 ] = LargeErr2Coord;
444- largeCov[o2::track::CovLabels::kSigSnp2 ] = largeCov[o2::track::CovLabels::kSigTgl2 ] = LargeErr2Dir;
445- largeCov[o2::track::CovLabels::kSigQ2Pt2 ] = LargeErr2PtI * trPars[o2::track::ParLabels::kQ2Pt ] * trPars[o2::track::ParLabels::kQ2Pt ];
446-
447- inwardTrack.setCov (largeCov);
448- inwardTrack.checkCovariance ();
447+ auto resetToLargeCovariance = [](o2::track::TrackParCov& trk) {
448+ std::array<float , o2::track::kCovMatSize > largeCov{}; // zero-initialised
449+ largeCov[o2::track::CovLabels::kSigY2 ] = largeCov[o2::track::CovLabels::kSigZ2 ] = LargeErr2Coord;
450+ largeCov[o2::track::CovLabels::kSigSnp2 ] = largeCov[o2::track::CovLabels::kSigTgl2 ] = LargeErr2Dir;
451+ largeCov[o2::track::CovLabels::kSigQ2Pt2 ] = LargeErr2PtI * trk.getQ2Pt () * trk.getQ2Pt ();
452+ trk.setCov (largeCov);
453+ trk.checkCovariance ();
454+ };
455+ resetToLargeCovariance (inwardTrack);
456+
457+ // as in DetectorK, radius and search radii are scaled by 100 in the good-hit probability: the scaling
458+ // cancels in the probability, but it means that all layers are treated as fast detectors (r * 100 > maxRadiusSlowDet)
459+ static constexpr float DelphesScale = 100 .f ;
460+
461+ // bookkeeping of the layer crossings of the inward pass, re-used by the second outward pass
462+ struct LayerCrossing {
463+ bool crossed = false ; // the layer was crossed in the inward pass
464+ bool trackerHit = false ; // a tracker measurement was added on this layer
465+ bool tofHit = false ; // TOF layer crossed (probability computed, but no measurement)
466+ float phi = 0 .f; // azimuth of the crossing point (frame of the layer)
467+ float r = 0 .f; // radius of the crossing point
468+ float z = 0 .f; // z of the crossing point
469+ float sigY2Inw = 0 .f; // inward prediction before the update
470+ float sigZ2Inw = 0 .f;
471+ };
472+ std::vector<LayerCrossing> crossings (layers.size ());
449473
450474 // +-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+
451475 // Inward pass to calculate covariances
476+ // As in DetectorK::SolveTrack, the track is rotated to the frame of each layer (X axis normal to the layer)
452477 for (int il = lastLayerReached; il >= firstLayerReached; il--) {
453478
454479 float targetX = 1e+3 ;
@@ -469,19 +494,31 @@ int FastTracker::fastTrack(o2::track::TrackParCov inputTrack, o2::track::TrackPa
469494 std::array<float , 3 > spacePoint{};
470495 inputTrack.getXYZGlo (spacePoint);
471496 std::vector<float > thisHit = {spacePoint[0 ], spacePoint[1 ], spacePoint[2 ]};
497+ const float phiHit = std::atan2 (spacePoint[1 ], spacePoint[0 ]);
498+ const float rHit = std::hypot (spacePoint[0 ], spacePoint[1 ]);
472499
473- // towards adding cluster: move to track alpha
474- float alpha = inwardTrack.getAlpha ();
475- std::array<float , 3 > xyz1 = {std::cos (alpha) * spacePoint[0 ] + std::sin (alpha) * spacePoint[1 ],
476- -std::sin (alpha) * spacePoint[0 ] + std::cos (alpha) * spacePoint[1 ],
477- spacePoint[2 ]};
478-
479- if (!inwardTrack.propagateTo (xyz1[0 ], magneticField)) {
500+ // move to the frame of the layer at the crossing point, where the hit is at local (rHit, 0, z)
501+ if (!inwardTrack.rotate (phiHit) || !inwardTrack.propagateTo (rHit, magneticField)) {
480502 continue ;
481503 }
482504
483- if (!layers[il].isInert () && !layers[il].isTOF ()) { // only update covm for tracker hits
484- const o2::track::TrackParametrization<float >::dim2_t hitpoint = {xyz1[1 ], xyz1[2 ]};
505+ // dead phi regions produce no hit (as in the outward pass), but their material is still traversed
506+ const bool inDeadRegion = layers[il].isInDeadPhiRegion (inputTrack.getPhi ());
507+ const bool isTrackerHit = !layers[il].isInert () && !layers[il].isTOF () && !inDeadRegion;
508+
509+ LayerCrossing& crossing = crossings[il];
510+ crossing.crossed = true ;
511+ crossing.trackerHit = isTrackerHit;
512+ crossing.tofHit = layers[il].isTOF () && !inDeadRegion;
513+ crossing.phi = phiHit;
514+ crossing.r = rHit;
515+ crossing.z = spacePoint[2 ];
516+ // save the inward prediction before the update (DetectorK: saveParInward)
517+ crossing.sigY2Inw = inwardTrack.getSigmaY2 ();
518+ crossing.sigZ2Inw = inwardTrack.getSigmaZ2 ();
519+
520+ if (isTrackerHit) { // only update covm for tracker hits
521+ const o2::track::TrackParametrization<float >::dim2_t hitpoint = {0 .f , spacePoint[2 ]};
485522 const o2::track::TrackParametrization<float >::dim3_t hitpointcov = {layers[il].getResolutionRPhi () * layers[il].getResolutionRPhi (), 0 .f , layers[il].getResolutionZ () * layers[il].getResolutionZ ()};
486523
487524 inwardTrack.update (hitpoint, hitpointcov);
@@ -507,6 +544,10 @@ int FastTracker::fastTrack(o2::track::TrackParCov inputTrack, o2::track::TrackPa
507544 }
508545 }
509546
547+ if (inDeadRegion) {
548+ continue ; // no hit in dead region, material already accounted for
549+ }
550+
510551 if (layers[il].isSilicon ()) {
511552 nSiliconPoints++; // count silicon hits
512553 }
@@ -521,24 +562,69 @@ int FastTracker::fastTrack(o2::track::TrackParCov inputTrack, o2::track::TrackPa
521562 trackOU = trackIU;
522563 }
523564 }
565+ }
524566
525- if (!layers[il].isInert () && !layers[il].isTOF ()) { // good hit probability calculation
526- float sigYCmb = o2::math_utils::sqrt (inwardTrack.getSigmaY2 () + layers[il].getResolutionRPhi () * layers[il].getResolutionRPhi ());
527- float sigZCmb = o2::math_utils::sqrt (inwardTrack.getSigmaZ2 () + layers[il].getResolutionZ () * layers[il].getResolutionZ ());
528- goodHitProbability[il] = probGoodChiSqHit (layers[il].getRadius () * 100 , sigYCmb * 100 , sigZCmb * 100 );
529- goodHitProbability[0 ] *= goodHitProbability[il];
567+ // +-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+
568+ // Second outward pass for the good hit probabilities (DetectorK "backward tracking"):
569+ // the search window at each layer is the combination of the inward and outward predictions,
570+ // both taken before the update with the hit on that layer
571+ o2::track::TrackParCov outwardTrack (inwardTrack);
572+ resetToLargeCovariance (outwardTrack);
573+ for (int il = firstLayerReached; il <= lastLayerReached; il++) {
574+ const LayerCrossing& crossing = crossings[il];
575+ if (!crossing.crossed ) {
576+ continue ;
577+ }
578+ if (!outwardTrack.rotate (crossing.phi ) || !outwardTrack.propagateTo (crossing.r , magneticField)) {
579+ LOGF (debug, " Second outward pass: failed to reach layer %d" , il);
580+ break ; // the remaining layers keep goodHitProbability = -1 (not used)
581+ }
582+
583+ if (crossing.trackerHit || crossing.tofHit ) {
584+ const float sigY2Out = outwardTrack.getSigmaY2 ();
585+ const float sigZ2Out = outwardTrack.getSigmaZ2 ();
586+ const float sigY2Cmb = crossing.sigY2Inw * sigY2Out / (crossing.sigY2Inw + sigY2Out);
587+ const float sigZ2Cmb = crossing.sigZ2Inw * sigZ2Out / (crossing.sigZ2Inw + sigZ2Out);
588+ const float sigYCmb = o2::math_utils::sqrt (sigY2Cmb + layers[il].getResolutionRPhi () * layers[il].getResolutionRPhi ());
589+ const float sigZCmb = o2::math_utils::sqrt (sigZ2Cmb + layers[il].getResolutionZ () * layers[il].getResolutionZ ());
590+ const float layerGoodHitProbability = probGoodChiSqHit (layers[il].getRadius () * DelphesScale, sigYCmb * DelphesScale, sigZCmb * DelphesScale);
591+ if (il > 0 ) { // index 0 holds the accumulated product, do not overwrite it
592+ goodHitProbability[il] = layerGoodHitProbability;
593+ }
594+ if (crossing.trackerHit ) { // TOF layers are not part of the tracking efficiency
595+ goodHitProbability[0 ] *= layerGoodHitProbability;
596+ }
530597 }
531- }
532598
533- // backpropagate to original radius
534- float finalX = 1e+3 ;
535- bool inPropStatus = inwardTrack.getXatLabR (initialRadius, finalX, magneticField);
536- if (finalX > InterceptFailed) {
537- LOG (debug) << " Failed to find intercept for initial radius " << initialRadius << " cm, x = " << finalX << " and status " << inPropStatus << " and sn = " << inwardTrack.getSnp () << " r = " << inwardTrack.getY () * inwardTrack.getY ();
538- return -3 ; // failed to find intercept
599+ if (crossing.trackerHit ) {
600+ const o2::track::TrackParametrization<float >::dim2_t hitpoint = {0 .f , crossing.z };
601+ const o2::track::TrackParametrization<float >::dim3_t hitpointcov = {layers[il].getResolutionRPhi () * layers[il].getResolutionRPhi (), 0 .f , layers[il].getResolutionZ () * layers[il].getResolutionZ ()};
602+ outwardTrack.update (hitpoint, hitpointcov);
603+ outwardTrack.checkCovariance ();
604+ }
605+
606+ bool ok = true ;
607+ if (mApplyMSCorrection && layers[il].getRadiationLength () > 0 ) {
608+ ok = outwardTrack.correctForMaterial (layers[il].getRadiationLength (), 0 , applyAngularCorrection);
609+ }
610+ if (ok && mApplyElossCorrection && layers[il].getDensity () > 0 ) {
611+ for (int ise = xrhosteps; ise > 0 ; --ise) { // correct in small steps, energy loss going outward
612+ ok = outwardTrack.correctForMaterial (0 , -layers[il].getDensity () / xrhosteps, applyAngularCorrection);
613+ if (!ok) {
614+ break ;
615+ }
616+ }
617+ }
618+ if (!ok) {
619+ LOGF (debug, " Second outward pass: material correction failed at layer %d" , il);
620+ break ;
621+ }
539622 }
540623
541- if (!inwardTrack.propagateTo (finalX, magneticField)) {
624+ // backpropagate to the original position: rotate back to the frame of the input track and
625+ // propagate to its initial local X. Searching for an intercept at initialRadius fails when the
626+ // refitted track's DCA exceeds it (e.g. initialRadius ~ 0 for tracks at the PV)
627+ if (!inwardTrack.rotate (initialAlpha) || !inwardTrack.propagateTo (initialX, magneticField)) {
542628 return -4 ; // failed to propagate
543629 }
544630
@@ -548,16 +634,8 @@ int FastTracker::fastTrack(o2::track::TrackParCov inputTrack, o2::track::TrackPa
548634 return nIntercepts;
549635 }
550636
551- // generate efficiency
552- float eff = 1 .;
553- for (size_t i = 0 ; i < layers.size (); i++) {
554- float iGoodHit = goodHitProbability[i];
555- if (iGoodHit <= 0 ) {
556- continue ;
557- }
558-
559- eff *= iGoodHit;
560- }
637+ // generate efficiency: product of the good-hit probabilities, accumulated in index 0
638+ const float eff = goodHitProbability[0 ];
561639 if (mApplyEffCorrection ) {
562640 if (gRandom ->Uniform () > eff) {
563641 return -8 ;
0 commit comments