18 #include "CLHEP/GenericFunctions/CumulativeChiSquare.hh"
24 using namespace Genfun;
28 theRefitterAlgo( config ),
29 theNavigator( navigator ),
30 theDebugFlag( config.getUntrackedParameter<bool>(
"debug",
true ) )
69 ConstTrajTrackPairCollection::const_iterator itTrack;
71 for( itTrack = tracks.begin(); itTrack != tracks.end(); ++itTrack )
75 AlignmentSetupCollection::const_iterator itSetup;
76 for ( itSetup = algoSetups.begin(); itSetup != algoSetups.end(); ++itSetup )
87 Trajectory::ConstRecHitContainer::iterator itHits;
89 for ( itHits = hits.begin(); itHits != hits.end(); ++itHits )
91 if ( !(*itHits)->isValid() )
continue;
97 }
catch(...) {
continue; }
99 if ( (*itSetup)->useForTracking( *itHits ) )
101 trackingRecHits.
push_back( (*itHits)->hit()->clone() );
103 ( (*itHits)->det()->position().z() > 0. ) ?
104 zPlusRecHits.
push_back( (*itHits)->hit()->clone() ) :
105 zMinusRecHits.
push_back( (*itHits)->hit()->clone() );
110 else if ( (*itSetup)->useForExternalTracking( *itHits ) )
112 externalTrackingRecHits.
push_back( (*itHits)->hit()->clone() );
121 if ( trackingRecHits.
empty() )
continue;
123 if ( externalTrackingRecHits.
empty() )
125 if ( ( (*itSetup)->getExternalTrackingSubDetIds().size() == 0 ) &&
126 ( trackingRecHits.
size() >= (*itSetup)->minTrackingHits() ) )
129 (*itSetup)->fitter(), (*itSetup)->propagator(),
130 aRecHitBuilder.
product(), fullTrack,
132 (*itSetup)->sortingDirection(),
false,
true );
135 if ( refitted.empty() )
continue;
136 if (
rejectTrack( refitted.front().second ) )
continue;
141 debugTrackData(
"OrigFullTrack", (*itTrack).first, (*itTrack).second, beamSpot );
146 result.push_back( trackletPtr );
150 else if ( ( trackingRecHits.
size() >= (*itSetup)->minTrackingHits() ) &&
151 ( externalTrackingRecHits.
size() >= (*itSetup)->minExternalHits() ) )
156 (*itSetup)->externalFitter(), (*itSetup)->externalPropagator(),
157 aRecHitBuilder.
product(), fullTrack,
159 (*itSetup)->externalSortingDirection(),
162 if ( external.empty() ) {
continue; }
167 (*itSetup)->fitter(), (*itSetup)->propagator(),
168 aRecHitBuilder.
product(), externalTrack,
170 (*itSetup)->sortingDirection(),
171 false,
true, (*itSetup)->id() );
173 if ( refitted.empty() ) {
continue; }
174 if (
rejectTrack( refitted.front().second ) )
continue;
177 const Surface& surface = refitted.front().first->lastMeasurement().updatedState().surface();
181 if ( !externalPrediction.isValid() )
continue;
185 debugTrackData(
string(
"External") + (*itSetup)->id(), external.front().first, external.front().second,
beamSpot );
187 debugTrackData(
"OrigFullTrack", (*itTrack).first, (*itTrack).second, beamSpot );
191 result.push_back( trackletPtr );
193 delete external.front().first;
194 delete external.front().second;
213 bool useExternalEstimate,
214 bool reuseMomentumEstimate,
215 const string identifier )
220 if ( recHits.
size() < 2 )
return result;
225 RecHitContainer::iterator itRecHit;
226 for ( itRecHit = recHits.
begin(); itRecHit != recHits.
end(); ++itRecHit )
227 hits.push_back( recHitBuilder->
build( &(*itRecHit) ) );
237 if ( !firstState.
isValid() )
return result;
277 firstState.
surface(), magneticField );
289 int charge =
static_cast<int>( tsos.charge() );
296 tmpHits.push_back(testhit);
297 for (TransientTrackingRecHit::RecHitContainer::const_iterator
i=hits.begin();
i!=hits.end();
i++){
298 tmpHits.push_back(*
i);
304 for ( AlgoProductCollection::iterator it = algoResult.begin(); it != algoResult.end(); ++it )
305 result.push_back( make_pair( (*it).first, (*it).second.first ) );
316 if ( hits.
size() < 2 )
return;
319 double firstRadius = firstHit->det()->surface().toGlobal( firstHit->localPosition() ).
mag();
320 double firstY = firstHit->det()->surface().toGlobal( firstHit->localPosition() ).
y();
323 double lastRadius = lastHit->det()->surface().toGlobal( lastHit->localPosition() ).
mag();
324 double lastY = lastHit->det()->surface().toGlobal( lastHit->localPosition() ).
y();
326 bool insideOut = firstRadius < lastRadius;
327 bool upsideDown = lastY < firstY;
336 RecHitContainer::iterator itHit = hits.
end();
337 do { --itHit; tmp.
push_back( ( *itHit ).clone() ); }
while ( itHit != hits.
begin() );
349 unsigned int ndof =
static_cast<unsigned int>( track->
ndof() );
350 if ( trackChi2 <= 0. || ndof <= 0 )
return false;
353 double minChi2Prob = 0;
354 double maxChi2Prob = 1.0;
356 GENFUNCTION cumulativeChi2 = Genfun::CumulativeChiSquare( ndof );
357 double chi2Prob = 1. - cumulativeChi2( trackChi2 );
358 return ( chi2Prob < minChi2Prob ) || ( chi2Prob > maxChi2Prob );
367 unsigned int ndof =
static_cast<unsigned int>( track->
ndof() );
369 if ( ( trackChi2 > 0. ) && ( ndof > 0 ) )
371 GENFUNCTION cumulativeChi2 = Genfun::CumulativeChiSquare( ndof );
373 }
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)
virtual PropagationDirection propagationDirection() const
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())
std::vector< ConstRecHitPointer > RecHitContainer
double phi() const
azimuthal angle of momentum vector
~KalmanAlignmentTrackRefitter(void)
Destructor.
std::vector< KalmanAlignmentSetup * > AlignmentSetupCollection
void setConf(const edm::ParameterSet &conf)
Set parameter set.
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.
KalmanAlignmentTracklet::TrajTrackPairCollection TrajTrackPairCollection
const SurfaceType & surface() const
double eta() const
pseudorapidity of momentum vector
double chi2() const
chi-squared of the fit
std::shared_ptr< TrackingRecHit const > ConstRecHitPointer
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
TrackingRecHit::ConstRecHitContainer ConstRecHitContainer
std::shared_ptr< TrackingRecHit const > RecHitPointer
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
static RecHitPointer build(const int charge, const double mom, const double err, const Surface *surface)
double dxy() const
dxy parameter. (This is the transverse impact parameter w.r.t. to (0,0,0) ONLY if refPoint is close t...
void swap(OwnVector< T, P > &other)
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.