21 #include "CLHEP/GenericFunctions/CumulativeChiSquare.hh"
35 declareInterface<ITrackSelectorTool>(
this);
44 evt->beamPosSigmaX(),
evt->beamPosSigmaY(),
evt->beamPosSigmaZ(),
45 evt->beamTiltXZ(),
evt->beamTiltYZ(),
evt->beamPosSigmaXY());
48 ATH_MSG_WARNING(
" Cannot get beamSpot center from xAOD::EventInfo. Using (0,0,0)... " );
53 if (beamSpotHandle.isValid()) {
56 ATH_MSG_WARNING(
" Cannot get beamSpot center from BeamSpotData. Using (0,0,0)... " );
70 ATH_MSG_DEBUG(
"No TrackSummaryTool set. OK if running on AOD.");
76 ATH_MSG_DEBUG(
"No TrackParticleCreatorTool set but shared hit selection used. OK if running on AOD.");
86 ATH_MSG_ERROR(
" Eta dependent cut on number of TRT hits requested but TrtDCCutTool not specified. ");
87 return StatusCode::FAILURE;
90 return StatusCode::FAILURE;
94 ATH_MSG_DEBUG(
"Using eta dependent cut on number of TRT hits.");
97 ATH_MSG_DEBUG(
"Using eta dependent cut on number of TRT hits + outliers.");
110 ATH_MSG_ERROR(
"Number of cuts DOES NOT match the number of intervals to apply. Please check jobOptions. ");
111 return StatusCode::FAILURE;
113 ATH_MSG_ERROR(
"Zero vectors for number of cuts and pt intervals. Please check jobOptions. ");
114 return StatusCode::FAILURE;
117 return StatusCode::SUCCESS;
124 return StatusCode::SUCCESS;
135 if (!preselectionDecision) {
136 ATH_MSG_DEBUG(
"Track rejected because of preselection decision!");
140 ATH_MSG_DEBUG(
" Preselection was requested but cannot be made since no Perigee in Track is available. This is not an error." );
144 if (myVertex==
nullptr) {
145 myVertex =
getBeamSpot(Gaudi::Hive::currentContext());
149 for (
const auto *
i : *
track.trackParameters()){
158 firstmeaspar=
track.perigeeParameters();
160 ATH_MSG_WARNING(
" First measurment on track is missing. Using perigee Parameters, but they are missing: 0 pointer! Track selection failed " );
174 track.info().particleHypothesis() ).release();
175 const Trk::Perigee* extrapolatedPerigee = extrapolatedParameters ?
dynamic_cast<const Trk::Perigee*
>(extrapolatedParameters) :
nullptr;
176 if (!extrapolatedPerigee || !extrapolatedPerigee->covariance() ) {
178 if (extrapolatedParameters) {
179 ATH_MSG_WARNING(
"The return object of the extrapolator was not a perigee even if a perigeeSurface was used!" );
180 delete extrapolatedParameters;
181 extrapolatedParameters=
nullptr;
187 bool dec =
decision(extrapolatedPerigee, recVertex ? &recVertex->covariancePosition() :
nullptr );
192 bool isInTrtAcceptance=
true;
193 if (!extrapolatedPerigee || std::fabs(extrapolatedPerigee->momentum().eta())>
m_TrtMaxEtaAcceptance) {
194 isInTrtAcceptance=
false;
196 if (extrapolatedPerigee!=
track.perigeeParameters()) {
197 delete extrapolatedPerigee;
198 extrapolatedPerigee=
nullptr;
201 ATH_MSG_DEBUG(
"Track rejected because of perigee parameters!");
206 if (TrkQuality==
nullptr) {
207 ATH_MSG_WARNING(
"Requested cut on track quality was not possible. Track has no FitQuality object attached. Selection failed." );
217 std::unique_ptr<Trk::TrackSummary> summaryUniquePtr;
221 summary = summaryUniquePtr.get();
224 ATH_MSG_FATAL(
"Track preselection: cannot create a track summary (but useTrackSummary is true). Selection failed." );
231 ATH_MSG_FATAL(
"Track preselection: cannot create a track particle (but useSharedHitInfo is true). Selection failed." );
247 nHitTrtPlusOutliers =
m_trtDCTool->minNumberDCs( (*
track.trackParameters())[0] );
256 nHitTrt, nHitTrtPlusOutliers)) {
272 if (!preselectionDecision) {
273 ATH_MSG_DEBUG(
"Track rejected because of preselection decision!");
277 ATH_MSG_WARNING(
" Preselection was requested but cannot be made since the Perigee is not the defining Parameter of the TrackParticle. This is not an error." );
279 bool isInTrtAcceptance=
true;
280 if (!perigeeBeforeExtrapolation || std::fabs(perigeeBeforeExtrapolation->momentum().eta())>
m_TrtMaxEtaAcceptance) {
281 isInTrtAcceptance=
false;
285 if (TrkQuality==
nullptr) {
286 ATH_MSG_WARNING(
"Requested cut on track quality was not possible. TrackParticleBase has no FitQuality object attached. Selection failed." );
297 ATH_MSG_WARNING(
"Track preselection: cannot create a track summary (but useTrackSummary is true). Selection failed." );
303 ATH_MSG_ERROR(
"Use of InDetDetailedTrackSelectorTool with Trk::TrackParticleBase and useSharedHitInfo is not supported");
318 nHitTrtPlusOutliers =
m_trtDCTool->minNumberDCs( (
track.trackParameters())[0] );
326 if ((!perigeeBeforeExtrapolation) or
328 nHitTrt, nHitTrtPlusOutliers))) {
335 myVertex =
getBeamSpot(Gaudi::Hive::currentContext());
339 for (
const auto *
i :
track.trackParameters()) {
340 if (
i->covariance() &&
347 if (!extrapolatedPerigee || !extrapolatedPerigee->covariance() ) {
348 ATH_MSG_DEBUG(
" Track Paraemters at first measurement not found. Perigee not found. Cannot do TrackSelection..." );
356 firstmeaspar=&(
track.definingParameters());
368 extrapolatedPerigee = extrapolatedParameters ?
dynamic_cast<const Trk::Perigee*
>(extrapolatedParameters) :
nullptr;
369 if (extrapolatedPerigee==
nullptr || !extrapolatedPerigee->covariance()) {
371 if (extrapolatedParameters) {
372 ATH_MSG_WARNING(
"The return object of the extrapolator was not a perigee even if a perigeeSurface was used!" );
373 delete extrapolatedParameters;
374 extrapolatedParameters =
nullptr;
377 if (extrapolatedParameters)
ATH_MSG_VERBOSE (
"Result: " << *extrapolatedParameters);
379 bool dec =
decision(extrapolatedPerigee, recVertex ? &recVertex->covariancePosition() :
nullptr );
384 if (extrapolatedPerigee!=&(
track.definingParameters())) {
385 delete extrapolatedPerigee;
386 extrapolatedPerigee=
nullptr;
389 ATH_MSG_DEBUG(
"Track rejected because of perigee parameters!");
402 evt->beamPosSigmaX(),
evt->beamPosSigmaY(),
evt->beamPosSigmaZ(),
403 evt->beamTiltXZ(),
evt->beamTiltYZ(),
evt->beamPosSigmaXY());
406 ATH_MSG_WARNING(
" Cannot get beamSpot center from xAOD::EventInfo. Using (0,0,0)... " );
411 if (beamSpotHandle.isValid()) {
412 return beamSpotHandle->beamVtx().position();
414 ATH_MSG_WARNING(
" Cannot get beamSpot center from BeamSpotData. Using (0,0,0)... " );
429 ATH_MSG_DEBUG(
"Track rejected because of preselection decision!");
450 nHitTrtPlusOutliers =
m_trtDCTool->minNumberDCs( &perigee );
472 ATH_MSG_DEBUG(
"Track rejected because of Pt-Dependent SCT Hit cut (CAREFUL! Excludes dead modules)") ;
479 ATH_MSG_DEBUG(
"Track rejected because of Pt-Dependent SCT Hit cut (CAREFUL! Excludes dead modules)") ;
491 ATH_MSG_DEBUG(
"and track rejected because at least one hit is expected in the innermost pixel layer") ;
493 }
else ATH_MSG_DEBUG(
"recovered track as no b-layer expected") ;
546 ATH_MSG_DEBUG(
"Track rejected because of nHitTrt "<<nh<<
" < "<<nHitTrt);
551 if (nhh<nHitTrtPlusOutliers) {
552 ATH_MSG_DEBUG(
"Track rejected because of nHitTrtPlusOutliers "<<nhh<<
" < "<<nHitTrtPlusOutliers);
581 if (nheh>1.) nheh=1.;
618 Gaudi::Hive::currentContext(),
619 perigee,perigeeSurface,
621 const Trk::Perigee* extrapolatedPerigee = extrapolatedParameters ?
dynamic_cast<const Trk::Perigee*
>(extrapolatedParameters) :
nullptr;
622 if (extrapolatedPerigee==
nullptr) {
623 ATH_MSG_WARNING(
"Extrapolation to the vertex failed: " << perigeeSurface << std::endl << perigee );
624 if (extrapolatedParameters!=
nullptr) {
625 ATH_MSG_WARNING(
"The return object of the extrapolator was not a perigee even if a perigeeSurface was used!" );
626 delete extrapolatedParameters;
627 extrapolatedParameters=
nullptr;
635 dec =
decision(extrapolatedPerigee,&vertexError);
637 dec =
decision(extrapolatedPerigee,
nullptr);
640 delete extrapolatedPerigee;
643 ATH_MSG_DEBUG(
"Track rejected because of perigee parameters!");
656 ATH_MSG_WARNING(
"Decision on measured perigee: Zero pointer to measured perigee passed. Selection failed." );
663 const EventContext& ctx = Gaudi::Hive::currentContext();
666 if (fieldCondObj ==
nullptr) {
671 fieldCondObj->getInitializedCache (fieldCache);
719 double d0wrtPriVtx = perigeeParms[
Trk::d0];
721 double z0wrtPriVtx =
deltaZ*sinTheta;
729 double DD0 = testtrackSigD0*testtrackSigD0;
731 if (covariancePosition) {
732 double DXX = dIPdx*dIPdx* (*covariancePosition)(0,0);
733 double DYY = dIPdy*dIPdy* (*covariancePosition)(1,1);
734 double DXY = 2.*dIPdx*dIPdy* (*covariancePosition)(0,1);
735 newD0Err = DD0 + DXX + DYY + DXY;
740 double d0ErrwrtPriVtx = (newD0Err>0 ? sqrt(newD0Err) : -10
e-9);
742 if (d0ErrwrtPriVtx<0) {
743 ATH_MSG_WARNING(
" error on d0 is negative: numeric error... (not expected. please report!)" );
756 double dZIPdTheta =
deltaZ*cosTheta;
757 double dZIPdz0 = sinTheta;
758 double dZIPdzV = -sinTheta;
759 double DTheta2 = dZIPdTheta*dZIPdTheta*testtrackSigTh*testtrackSigTh;
760 double DZ02 = dZIPdz0*dZIPdz0*testtrackSigZ0*testtrackSigZ0;
763 if (covariancePosition) {
764 double DZV2 = dZIPdzV*dZIPdzV* (*covariancePosition)(2,2);
765 newZ0Err = DTheta2 + DZ02 + DZV2 + DThetaZ0;
767 newZ0Err = DTheta2 + DZ02 + DThetaZ0;
770 double z0ErrwrtPriVtx = (newZ0Err>0 ? sqrt(newZ0Err) : -10
e-9);
772 if (z0ErrwrtPriVtx<0) {
773 ATH_MSG_WARNING(
" error on z0 is negative: numeric error... (not expected. please report!)" );
795 if(
nullptr == trkQuality) {
796 ATH_MSG_WARNING(
"Null FitQuality pointer passed. No track Quality cut possible. Selection failed." );
807 Genfun::CumulativeChiSquare myCumulativeChiSquare(
ndf);
808 proba = 1.-myCumulativeChiSquare(
chi2);
836 bool useSharedHitInfo,
840 const int nHitTrtPlusOutliers)
const
843 ATH_MSG_WARNING(
"Null TrackSummary pointer passed. Selection failed." );
861 if (nhp < 0) nhp = 0;
864 if (nhs < 0) nhs = 0;
867 if (ndhs < 0) ndhs = 0;
882 ATH_MSG_DEBUG(
"Track rejected because of Pt-Dependent SCT Hit cut (CAREFUL! Excludes dead modules)") ;
889 ATH_MSG_DEBUG(
"Track rejected because of Pt-Dependent SCT Hit cut (CAREFUL! Excludes dead modules)") ;
902 ATH_MSG_DEBUG(
"and no blayer tool configured, so will not try to recover track");
905 ATH_MSG_DEBUG(
"and track rejected because at least one hit is expected in the innermost pixel layer") ;
907 }
else ATH_MSG_DEBUG(
"recovered track as no b-layer expected") ;
973 ATH_MSG_DEBUG(
"Track rejected because of nHitTrt "<<nh<<
" < "<<nHitTrt);
979 if (nhh<nHitTrtPlusOutliers) {
980 ATH_MSG_DEBUG(
"Track rejected because of nHitTrtPlusOutliers "<<nhh<<
" < "<<nHitTrtPlusOutliers);
985 if (nhthits<0) nhthits=0;
992 if (nhthitsWithOutliers<0) nhthitsWithOutliers=0;
1010 if(nheh<0.) nheh=0.;
1011 if (nheh>1.) nheh=1.;
1019 if (useSharedHitInfo) {
1021 ATH_MSG_DEBUG(
"Track rejected because xAOD::TrackParticle not available");
1026 if(nbs < 0) nbs = 0;
1034 if(nps < 0) nps = 0;
1041 if(nss < 0) nss = 0;
1047 int nst = nps + nss;
1061 const AmgVector(5)& perigeeParms = myPerigee.parameters();
1064 const EventContext& ctx = Gaudi::Hive::currentContext();
1067 if (fieldCondObj ==
nullptr) {
1072 fieldCondObj->getInitializedCache (fieldCache);
1076 ATH_MSG_DEBUG(
"Track rejected because of perigee qOverP == 0.");