18 #include "CLHEP/GenericFunctions/CumulativeChiSquare.hh"
24 using namespace Genfun;
28 theRefitterAlgo( config ),
29 theNavigator( navigator ),
30 theDebugFlag( config.getUntrackedParameter<bool>(
"debug",
true ) )
55 getFromES( setup, aGeometry, aMagneticField, aTrajectoryFitter, aPropagator, theMeasTk, aRecHitBuilder );
61 ConstTrajTrackPairCollection::const_iterator itTrack;
63 for( itTrack = tracks.begin(); itTrack != tracks.end(); ++itTrack )
67 AlignmentSetupCollection::const_iterator itSetup;
68 for ( itSetup = algoSetups.begin(); itSetup != algoSetups.end(); ++itSetup )
79 Trajectory::ConstRecHitContainer::iterator itHits;
81 for ( itHits = hits.begin(); itHits != hits.end(); ++itHits )
83 if ( !(*itHits)->isValid() )
continue;
89 }
catch(...) {
continue; }
91 if ( (*itSetup)->useForTracking( *itHits ) )
93 trackingRecHits.
push_back( (*itHits)->hit()->clone() );
95 ( (*itHits)->det()->position().z() > 0. ) ?
96 zPlusRecHits.
push_back( (*itHits)->hit()->clone() ) :
97 zMinusRecHits.
push_back( (*itHits)->hit()->clone() );
102 else if ( (*itSetup)->useForExternalTracking( *itHits ) )
104 externalTrackingRecHits.
push_back( (*itHits)->hit()->clone() );
113 if ( trackingRecHits.
empty() )
continue;
115 if ( externalTrackingRecHits.
empty() )
117 if ( ( (*itSetup)->getExternalTrackingSubDetIds().size() == 0 ) &&
118 ( trackingRecHits.
size() >= (*itSetup)->minTrackingHits() ) )
121 (*itSetup)->fitter(), (*itSetup)->propagator(),
122 aRecHitBuilder.
product(), fullTrack,
124 (*itSetup)->sortingDirection(),
false,
true );
127 if ( refitted.empty() )
continue;
128 if (
rejectTrack( refitted.front().second ) )
continue;
133 debugTrackData(
"OrigFullTrack", (*itTrack).first, (*itTrack).second, beamSpot );
138 result.push_back( trackletPtr );
142 else if ( ( trackingRecHits.
size() >= (*itSetup)->minTrackingHits() ) &&
143 ( externalTrackingRecHits.
size() >= (*itSetup)->minExternalHits() ) )
148 (*itSetup)->externalFitter(), (*itSetup)->externalPropagator(),
149 aRecHitBuilder.
product(), fullTrack,
151 (*itSetup)->externalSortingDirection(),
154 if ( external.empty() ) {
continue; }
159 (*itSetup)->fitter(), (*itSetup)->propagator(),
160 aRecHitBuilder.
product(), externalTrack,
162 (*itSetup)->sortingDirection(),
163 false,
true, (*itSetup)->id() );
165 if ( refitted.empty() ) {
continue; }
166 if (
rejectTrack( refitted.front().second ) )
continue;
169 const Surface& surface = refitted.front().first->lastMeasurement().updatedState().surface();
173 if ( !externalPrediction.isValid() )
continue;
177 debugTrackData(
string(
"External") + (*itSetup)->id(), external.front().first, external.front().second,
beamSpot );
179 debugTrackData(
"OrigFullTrack", (*itTrack).first, (*itTrack).second, beamSpot );
183 result.push_back( trackletPtr );
185 delete external.front().first;
186 delete external.front().second;
205 bool useExternalEstimate,
206 bool reuseMomentumEstimate,
207 const string identifier )
212 if ( recHits.
size() < 2 )
return result;
217 RecHitContainer::iterator itRecHit;
218 for ( itRecHit = recHits.
begin(); itRecHit != recHits.
end(); ++itRecHit )
219 hits.push_back( recHitBuilder->
build( &(*itRecHit) ) );
229 if ( !firstState.
isValid() )
return result;
269 firstState.
surface(), magneticField );
281 int charge =
static_cast<int>( tsos.charge() );
288 tmpHits.push_back(testhit);
289 for (TransientTrackingRecHit::RecHitContainer::const_iterator
i=hits.begin();
i!=hits.end();
i++){
290 tmpHits.push_back(*
i);
296 for ( AlgoProductCollection::iterator it = algoResult.begin(); it != algoResult.end(); ++it )
297 result.push_back( make_pair( (*it).first, (*it).second.first ) );
308 if ( hits.
size() < 2 )
return;
311 double firstRadius = firstHit->det()->surface().toGlobal( firstHit->localPosition() ).
mag();
312 double firstY = firstHit->det()->surface().toGlobal( firstHit->localPosition() ).
y();
315 double lastRadius = lastHit->det()->surface().toGlobal( lastHit->localPosition() ).
mag();
316 double lastY = lastHit->det()->surface().toGlobal( lastHit->localPosition() ).
y();
318 bool insideOut = firstRadius < lastRadius;
319 bool upsideDown = lastY < firstY;
328 RecHitContainer::iterator itHit = hits.
end();
329 do { --itHit; tmp.
push_back( ( *itHit ).clone() ); }
while ( itHit != hits.
begin() );
341 unsigned int ndof =
static_cast<unsigned int>( track->
ndof() );
342 if ( trackChi2 <= 0. || ndof <= 0 )
return false;
345 double minChi2Prob = 0;
346 double maxChi2Prob = 1.0;
348 GENFUNCTION cumulativeChi2 = Genfun::CumulativeChiSquare( ndof );
349 double chi2Prob = 1. - cumulativeChi2( trackChi2 );
350 return ( chi2Prob < minChi2Prob ) || ( chi2Prob > maxChi2Prob );
359 unsigned int ndof =
static_cast<unsigned int>( track->
ndof() );
361 if ( ( trackChi2 > 0. ) && ( ndof > 0 ) )
363 GENFUNCTION cumulativeChi2 = Genfun::CumulativeChiSquare( ndof );
365 }
else if ( ndof == 0 ) {
void rescaleError(double factor)
T getParameter(std::string const &) const
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)
virtual PropagationDirection propagationDirection() const
TrajectoryStateOnSurface propagate(const FreeTrajectoryState &fts, const Plane &plane) const
propagation to plane
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
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
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
void setConf(edm::ParameterSet conf)
Set parameter set.
LocalVector momentum() const
Momentum vector in the local frame.
const LocalTrajectoryError & localError() const
std::vector< AlgoProduct > AlgoProductCollection
void setSrc(edm::InputTag src, edm::InputTag bsSrc)
set label of source collection
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 Surface & surface() const
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="")
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.