18 #include "CLHEP/GenericFunctions/CumulativeChiSquare.hh"
24 using namespace Genfun;
28 theRefitterAlgo( config ),
29 theNavigator( navigator ),
30 theDebugFlag( config.getUntrackedParameter<bool>(
"debug",
true ) )
57 getFromES( setup, aGeometry, aMagneticField, aTrajectoryFitter, aPropagator, theMeasTk, aRecHitBuilder );
63 ConstTrajTrackPairCollection::const_iterator itTrack;
65 for( itTrack = tracks.begin(); itTrack != tracks.end(); ++itTrack )
69 AlignmentSetupCollection::const_iterator itSetup;
70 for ( itSetup = algoSetups.begin(); itSetup != algoSetups.end(); ++itSetup )
81 Trajectory::ConstRecHitContainer::iterator itHits;
83 for ( itHits = hits.begin(); itHits != hits.end(); ++itHits )
85 if ( !(*itHits)->isValid() )
continue;
91 }
catch(...) {
continue; }
93 if ( (*itSetup)->useForTracking( *itHits ) )
95 trackingRecHits.
push_back( (*itHits)->hit()->clone() );
97 ( (*itHits)->det()->position().z() > 0. ) ?
98 zPlusRecHits.
push_back( (*itHits)->hit()->clone() ) :
99 zMinusRecHits.
push_back( (*itHits)->hit()->clone() );
104 else if ( (*itSetup)->useForExternalTracking( *itHits ) )
106 externalTrackingRecHits.
push_back( (*itHits)->hit()->clone() );
115 if ( trackingRecHits.
empty() )
continue;
117 if ( externalTrackingRecHits.
empty() )
119 if ( ( (*itSetup)->getExternalTrackingSubDetIds().size() == 0 ) &&
120 ( trackingRecHits.
size() >= (*itSetup)->minTrackingHits() ) )
123 (*itSetup)->fitter(), (*itSetup)->propagator(),
124 aRecHitBuilder.
product(), fullTrack,
126 (*itSetup)->sortingDirection(),
false,
true );
129 if ( refitted.empty() )
continue;
130 if (
rejectTrack( refitted.front().second ) )
continue;
135 debugTrackData(
"OrigFullTrack", (*itTrack).first, (*itTrack).second, beamSpot );
140 result.push_back( trackletPtr );
144 else if ( ( trackingRecHits.
size() >= (*itSetup)->minTrackingHits() ) &&
145 ( externalTrackingRecHits.
size() >= (*itSetup)->minExternalHits() ) )
150 (*itSetup)->externalFitter(), (*itSetup)->externalPropagator(),
151 aRecHitBuilder.
product(), fullTrack,
153 (*itSetup)->externalSortingDirection(),
156 if ( external.empty() ) {
continue; }
161 (*itSetup)->fitter(), (*itSetup)->propagator(),
162 aRecHitBuilder.
product(), externalTrack,
164 (*itSetup)->sortingDirection(),
165 false,
true, (*itSetup)->id() );
167 if ( refitted.empty() ) {
continue; }
168 if (
rejectTrack( refitted.front().second ) )
continue;
171 const Surface& surface = refitted.front().first->lastMeasurement().updatedState().surface();
175 if ( !externalPrediction.isValid() )
continue;
179 debugTrackData(
string(
"External") + (*itSetup)->id(), external.front().first, external.front().second,
beamSpot );
181 debugTrackData(
"OrigFullTrack", (*itTrack).first, (*itTrack).second, beamSpot );
185 result.push_back( trackletPtr );
187 delete external.front().first;
188 delete external.front().second;
207 bool useExternalEstimate,
208 bool reuseMomentumEstimate,
209 const string identifier )
214 if ( recHits.
size() < 2 )
return result;
219 RecHitContainer::iterator itRecHit;
220 for ( itRecHit = recHits.
begin(); itRecHit != recHits.
end(); ++itRecHit )
221 hits.push_back( recHitBuilder->
build( &(*itRecHit) ) );
231 if ( !firstState.
isValid() )
return result;
271 firstState.
surface(), magneticField );
283 int charge =
static_cast<int>( tsos.charge() );
290 tmpHits.push_back(testhit);
291 for (TransientTrackingRecHit::RecHitContainer::const_iterator
i=hits.begin();
i!=hits.end();
i++){
292 tmpHits.push_back(*
i);
298 for ( AlgoProductCollection::iterator it = algoResult.begin(); it != algoResult.end(); ++it )
299 result.push_back( make_pair( (*it).first, (*it).second.first ) );
310 if ( hits.
size() < 2 )
return;
313 double firstRadius = firstHit->det()->surface().toGlobal( firstHit->localPosition() ).
mag();
314 double firstY = firstHit->det()->surface().toGlobal( firstHit->localPosition() ).
y();
317 double lastRadius = lastHit->det()->surface().toGlobal( lastHit->localPosition() ).
mag();
318 double lastY = lastHit->det()->surface().toGlobal( lastHit->localPosition() ).
y();
320 bool insideOut = firstRadius < lastRadius;
321 bool upsideDown = lastY < firstY;
330 RecHitContainer::iterator itHit = hits.
end();
331 do { --itHit; tmp.
push_back( ( *itHit ).clone() ); }
while ( itHit != hits.
begin() );
343 unsigned int ndof =
static_cast<unsigned int>( track->
ndof() );
344 if ( trackChi2 <= 0. || ndof <= 0 )
return false;
347 double minChi2Prob = 0;
348 double maxChi2Prob = 1.0;
350 GENFUNCTION cumulativeChi2 = Genfun::CumulativeChiSquare( ndof );
351 double chi2Prob = 1. - cumulativeChi2( trackChi2 );
352 return ( chi2Prob < minChi2Prob ) || ( chi2Prob > maxChi2Prob );
361 unsigned int ndof =
static_cast<unsigned int>( track->
ndof() );
363 if ( ( trackChi2 > 0. ) && ( ndof > 0 ) )
365 GENFUNCTION cumulativeChi2 = Genfun::CumulativeChiSquare( ndof );
367 }
else if ( ndof == 0 ) {
void rescaleError(double factor)
TrackletCollection refitTracks(const edm::EventSetup &eventSetup, const AlignmentSetupCollection &algoSetups, const ConstTrajTrackPairCollection &tracks, const reco::BeamSpot *beamSpot)
static void fillHistogram(std::string histo_name, float data)
bool rejectTrack(const reco::Track *track) const
AlignableNavigator * theNavigator
const LocalTrajectoryParameters & localParameters() const
double normalizedChi2() const
chi-squared divided by n.d.o.f. (or chi-squared * 1e6 if n.d.o.f. is zero)
std::vector< reco::Track > TrackCollection
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
double phi() const
azimuthal angle of momentum vector
~KalmanAlignmentTrackRefitter(void)
Destructor.
void swap(OwnVector< T, P > &other) noexcept
std::vector< ConstRecHitPointer > RecHitContainer
std::vector< KalmanAlignmentSetup * > AlignmentSetupCollection
void setConf(const edm::ParameterSet &conf)
Set parameter set.
virtual PropagationDirection propagationDirection() const GCC11_FINAL
bool buildTrack(const TrajectoryFitter *, const Propagator *, AlgoProductCollection &, TransientTrackingRecHit::RecHitContainer &, TrajectoryStateOnSurface &, const TrajectorySeed &, float, const reco::BeamSpot &, SeedRef seedRef=SeedRef(), int qualityMask=0, signed char nLoops=0)
Construct Tracks to be put in the event.
TransientTrackingRecHit::ConstRecHitContainer ConstRecHitContainer
KalmanAlignmentTracklet::TrajTrackPairCollection TrajTrackPairCollection
const SurfaceType & surface() const
double eta() const
pseudorapidity of momentum vector
double chi2() const
chi-squared of the fit
double ndof() const
number of degrees of freedom of the fit
virtual RecHitPointer build(const TrackingRecHit *p) const =0
build a tracking rechit from an existing rechit
double pt() const
track transverse momentum
GlobalVector momentum() const
LocalVector momentum() const
Momentum vector in the local frame.
const LocalTrajectoryError & localError() const
std::vector< AlgoProduct > AlgoProductCollection
void sortRecHits(RecHitContainer &hits, const TransientTrackingRecHitBuilder *builder, const SortingDirection &sortingDir) const
TrajTrackPairCollection refitSingleTracklet(const TrackingGeometry *geometry, const MagneticField *magneticField, const TrajectoryFitter *fitter, const Propagator *propagator, const TransientTrackingRecHitBuilder *recHitBuilder, const reco::TransientTrack &originalTrack, RecHitContainer &recHits, const reco::BeamSpot *beamSpot, const SortingDirection &sortingDir, bool useExternalEstimate, bool reuseMomentumEstimate, const std::string identifier=std::string("RefitSingle_"))
double dz() const
dz parameter (= dsz/cos(lambda)). This is the track z0 w.r.t (0,0,0) only if the refPoint is close to...
void debugTrackData(const std::string identifier, const Trajectory *traj, const reco::Track *track, const reco::BeamSpot *bs)
const GlobalTrajectoryParameters & globalParameters() const
AlignmentAlgorithmBase::ConstTrajTrackPairCollection ConstTrajTrackPairCollection
T const * product() const
std::vector< TrackletPtr > TrackletCollection
std::vector< std::vector< double > > tmp
ESHandle< TrackerGeometry > geometry
const Point & position() const
position
TrajectoryStateOnSurface impactPointState() const
double dxy() const
dxy parameter. (This is the transverse impact parameter w.r.t. to (0,0,0) ONLY if refPoint is close t...
AlignableDetOrUnitPtr alignableFromDetId(const DetId &detid)
Returns AlignableDetOrUnitPtr corresponding to given DetId.
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
tuple AnalyticalPropagator
KalmanAlignmentTrackRefitter(const edm::ParameterSet &config, AlignableNavigator *navigator)
Constructor.
TrackProducerAlgorithm< reco::Track > theRefitterAlgo
virtual void getFromES(const edm::EventSetup &, edm::ESHandle< TrackerGeometry > &, edm::ESHandle< MagneticField > &, edm::ESHandle< TrajectoryFitter > &, edm::ESHandle< Propagator > &, edm::ESHandle< MeasurementTracker > &, edm::ESHandle< TransientTrackingRecHitBuilder > &)
Get needed services from the Event Setup.