CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Types | Public Member Functions | Private Member Functions | Private Attributes
KalmanAlignmentTrackRefitter Class Reference

#include <KalmanAlignmentTrackRefitter.h>

Inheritance diagram for KalmanAlignmentTrackRefitter:
TrackProducerBase< reco::Track >

Public Types

typedef std::vector
< KalmanAlignmentSetup * > 
AlignmentSetupCollection
 
typedef
AlignmentAlgorithmBase::ConstTrajTrackPair 
ConstTrajTrackPair
 
typedef
AlignmentAlgorithmBase::ConstTrajTrackPairCollection 
ConstTrajTrackPairCollection
 
typedef edm::OwnVector
< TrackingRecHit
RecHitContainer
 
typedef
KalmanAlignmentSetup::SortingDirection 
SortingDirection
 
typedef std::vector< TrackletPtrTrackletCollection
 
typedef
KalmanAlignmentTracklet::TrackletPtr 
TrackletPtr
 
typedef
KalmanAlignmentTracklet::TrajTrackPairCollection 
TrajTrackPairCollection
 
- Public Types inherited from TrackProducerBase< reco::Track >
typedef std::pair< Trajectory
*, std::pair< reco::Track
*, PropagationDirection > > 
AlgoProduct
 
typedef std::vector< AlgoProductAlgoProductCollection
 
typedef std::vector< reco::TrackTrackCollection
 

Public Member Functions

 KalmanAlignmentTrackRefitter (const edm::ParameterSet &config, AlignableNavigator *navigator)
 Constructor. More...
 
virtual void produce (edm::Event &, const edm::EventSetup &)
 Dummy implementation, due to inheritance from TrackProducerBase. More...
 
TrackletCollection refitTracks (const edm::EventSetup &eventSetup, const AlignmentSetupCollection &algoSetups, const ConstTrajTrackPairCollection &tracks, const reco::BeamSpot *beamSpot)
 
 ~KalmanAlignmentTrackRefitter (void)
 Destructor. More...
 
- Public Member Functions inherited from TrackProducerBase< reco::Track >
const edm::ParameterSetgetConf () const
 
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. More...
 
virtual void getFromEvt (edm::Event &, edm::Handle< TrackCandidateCollection > &, reco::BeamSpot &)
 Get TrackCandidateCollection from the Event (needed by TrackProducer) More...
 
virtual void getFromEvt (edm::Event &, edm::Handle< TrackCollection > &, reco::BeamSpot &)
 Get TrackCollection from the Event (needed by TrackRefitter) More...
 
void setAlias (std::string alias)
 set the aliases of produced collections More...
 
void setClusterRemovalInfo (const edm::InputTag &clusterRemovalInfo)
 Sets the information on cluster removal, and turns it on. More...
 
void setConf (const edm::ParameterSet &conf)
 Set parameter set. More...
 
void setSecondHitPattern (Trajectory *traj, reco::Track &track, const Propagator *prop, const MeasurementTrackerEvent *measTk)
 
void setSrc (const edm::EDGetToken &src, const edm::EDGetTokenT< reco::BeamSpot > &bsSrc, const edm::EDGetTokenT< MeasurementTrackerEvent > &mteSrc)
 set label of source collection More...
 
 TrackProducerBase (bool trajectoryInEvent=false)
 Constructor. More...
 
virtual ~TrackProducerBase ()
 Destructor. More...
 

Private Member Functions

void debugTrackData (const std::string identifier, const Trajectory *traj, const reco::Track *track, const reco::BeamSpot *bs)
 
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_"))
 
bool rejectTrack (const reco::Track *track) const
 
void sortRecHits (RecHitContainer &hits, const TransientTrackingRecHitBuilder *builder, const SortingDirection &sortingDir) const
 

Private Attributes

bool theDebugFlag
 
AlignableNavigatortheNavigator
 
TrackProducerAlgorithm
< reco::Track
theRefitterAlgo
 

Additional Inherited Members

- Protected Attributes inherited from TrackProducerBase< reco::Track >
std::string alias_
 
edm::EDGetTokenT< reco::BeamSpotbsSrc_
 
edm::InputTag clusterRemovalInfo_
 
edm::EDGetTokenT
< MeasurementTrackerEvent
mteSrc_
 
bool rekeyClusterRefs_
 
edm::OrphanHandle
< TrackCollection
rTracks_
 
edm::ESHandle< NavigationSchooltheSchool
 
bool trajectoryInEvent_
 

Detailed Description

This class serves the very specific needs of the KalmanAlignmentAlgorithm. Tracks are partially refitted to 'tracklets' using the current estimate on the alignment (see class CurrentAlignmentKFUpdator. These tracklets are either used to compute an exteranal estimate for other tracklets or are handed to the alignment algorithm for further processing. If a tracklet is used as an external prediction or for further processing is defined via the configuration file. NOTE: The trajectory measurements of the tracklets are always ordered along the direction of the momentum!

Definition at line 31 of file KalmanAlignmentTrackRefitter.h.

Member Typedef Documentation

Definition at line 37 of file KalmanAlignmentTrackRefitter.h.

Definition at line 46 of file KalmanAlignmentTrackRefitter.h.

Definition at line 47 of file KalmanAlignmentTrackRefitter.h.

Definition at line 40 of file KalmanAlignmentTrackRefitter.h.

Definition at line 38 of file KalmanAlignmentTrackRefitter.h.

Definition at line 44 of file KalmanAlignmentTrackRefitter.h.

Definition at line 43 of file KalmanAlignmentTrackRefitter.h.

Definition at line 42 of file KalmanAlignmentTrackRefitter.h.

Constructor & Destructor Documentation

KalmanAlignmentTrackRefitter::KalmanAlignmentTrackRefitter ( const edm::ParameterSet config,
AlignableNavigator navigator 
)

Constructor.

Definition at line 27 of file KalmanAlignmentTrackRefitter.cc.

References TrackProducerBase< T >::setConf().

27  :
28  theRefitterAlgo( config ),
29  theNavigator( navigator ),
30  theDebugFlag( config.getUntrackedParameter<bool>( "debug", true ) )
31 {
33  // --- GPetrucc: I can't understand where anything is read from the event, and who's the consumer.
34  // If there is one anywhere, it should do the consumes<T> calls and pass that to the setSrc
35  //TrackProducerBase< reco::Track >::setSrc( consumes<TrackCandidateCollection>(iConfig.getParameter<edm::InputTag>( "src" )),
36  // consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>( "beamSpot" )));
37 }
T getUntrackedParameter(std::string const &, T const &) const
void setConf(const edm::ParameterSet &conf)
Set parameter set.
TrackProducerAlgorithm< reco::Track > theRefitterAlgo
KalmanAlignmentTrackRefitter::~KalmanAlignmentTrackRefitter ( void  )

Destructor.

Definition at line 40 of file KalmanAlignmentTrackRefitter.cc.

40 {}

Member Function Documentation

void KalmanAlignmentTrackRefitter::debugTrackData ( const std::string  identifier,
const Trajectory traj,
const reco::Track track,
const reco::BeamSpot bs 
)
private

Definition at line 362 of file KalmanAlignmentTrackRefitter.cc.

References reco::TrackBase::chi2(), reco::TrackBase::dxy(), reco::TrackBase::dz(), alignCSCRings::e, reco::TrackBase::eta(), KalmanAlignmentDataCollector::fillHistogram(), Trajectory::foundHits(), reco::TrackBase::ndof(), reco::TrackBase::normalizedChi2(), reco::TrackBase::phi(), reco::BeamSpot::position(), reco::TrackBase::pt(), and reco::btau::trackChi2.

Referenced by refitTracks().

366 {
367  unsigned int ndof = static_cast<unsigned int>( track->ndof() );
368  double trackChi2 = track->chi2();
369  if ( ( trackChi2 > 0. ) && ( ndof > 0 ) )
370  {
371  GENFUNCTION cumulativeChi2 = Genfun::CumulativeChiSquare( ndof );
372  KalmanAlignmentDataCollector::fillHistogram( identifier + string("_CumChi2"), 1. - cumulativeChi2( trackChi2 ) );
373  } else if ( ndof == 0 ) {
374  KalmanAlignmentDataCollector::fillHistogram( identifier + string("_CumChi2"), -1. );
375  } else {
376  KalmanAlignmentDataCollector::fillHistogram( identifier + string("_CumChi2"), -2. );
377  }
378 
379  KalmanAlignmentDataCollector::fillHistogram( identifier + string("_NHits"), traj->foundHits() );
380  KalmanAlignmentDataCollector::fillHistogram( identifier + string("_Pt"), 1e-2*track->pt() );
381  KalmanAlignmentDataCollector::fillHistogram( identifier + string("_Eta"), track->eta() );
382  KalmanAlignmentDataCollector::fillHistogram( identifier + string("_Phi"), track->phi() );
383  KalmanAlignmentDataCollector::fillHistogram( identifier + string("_NormChi2"), track->normalizedChi2() );
384  KalmanAlignmentDataCollector::fillHistogram( identifier + string("_DZ"), track->dz() );
385 
386  KalmanAlignmentDataCollector::fillHistogram( identifier + string("_DXY_BS"), fabs( track->dxy( bs->position() ) ) );
387  KalmanAlignmentDataCollector::fillHistogram( identifier + string("_DXY"), fabs( track->dxy() ) );
388  //KalmanAlignmentDataCollector::fillHistogram( identifier + string("_D0"), fabs( track->d0() ) );
389 }
int foundHits() const
Definition: Trajectory.h:234
static void fillHistogram(std::string histo_name, float data)
double normalizedChi2() const
chi-squared divided by n.d.o.f. (or chi-squared * 1e6 if n.d.o.f. is zero)
Definition: TrackBase.h:609
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:693
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:699
double chi2() const
chi-squared of the fit
Definition: TrackBase.h:597
double ndof() const
number of degrees of freedom of the fit
Definition: TrackBase.h:603
double pt() const
track transverse momentum
Definition: TrackBase.h:669
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...
Definition: TrackBase.h:657
const Point & position() const
position
Definition: BeamSpot.h:62
double dxy() const
dxy parameter. (This is the transverse impact parameter w.r.t. to (0,0,0) ONLY if refPoint is close t...
Definition: TrackBase.h:639
virtual void KalmanAlignmentTrackRefitter::produce ( edm::Event ,
const edm::EventSetup  
)
inlinevirtual

Dummy implementation, due to inheritance from TrackProducerBase.

Implements TrackProducerBase< reco::Track >.

Definition at line 61 of file KalmanAlignmentTrackRefitter.h.

Referenced by JSONExport.JsonExport::export(), HTMLExport.HTMLExport::export(), and HTMLExport.HTMLExportStatic::export().

61 {}
KalmanAlignmentTrackRefitter::TrajTrackPairCollection KalmanAlignmentTrackRefitter::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_") 
)
private

Definition at line 204 of file KalmanAlignmentTrackRefitter.cc.

References AnalyticalPropagator_cfi::AnalyticalPropagator, anyDirection, edm::OwnVector< T, P >::begin(), TransientTrackingRecHitBuilder::build(), TRecHit1DMomConstraint::build(), TrackProducerAlgorithm< T >::buildTrack(), alignCSCRings::e, edm::OwnVector< T, P >::end(), KalmanAlignmentDataCollector::fillHistogram(), TrajectoryStateOnSurface::globalParameters(), i, reco::TransientTrack::impactPointState(), TrajectoryStateOnSurface::isValid(), TrajectoryStateOnSurface::localError(), TrajectoryStateOnSurface::localParameters(), PV3DBase< T, PVType, FrameType >::mag(), GlobalTrajectoryParameters::momentum(), LocalTrajectoryParameters::momentum(), PV3DBase< T, PVType, FrameType >::perp(), trajectoryStateTransform::persistentState(), Propagator::propagationDirection(), TrajectoryStateOnSurface::rescaleError(), query::result, fileCollector::seed, edm::OwnVector< T, P >::size(), sortRecHits(), TrajectoryStateOnSurface::surface(), and theRefitterAlgo.

Referenced by refitTracks().

216 {
217 
219 
220  if ( recHits.size() < 2 ) return result;
221 
222  sortRecHits( recHits, recHitBuilder, sortingDir );
223 
225  RecHitContainer::iterator itRecHit;
226  for ( itRecHit = recHits.begin(); itRecHit != recHits.end(); ++itRecHit )
227  hits.push_back( recHitBuilder->build( &(*itRecHit) ) );
228 
229  TransientTrackingRecHit::ConstRecHitPointer firstHit = hits.front();
230 
231  AnalyticalPropagator firstStatePropagator( magneticField, anyDirection );
232  TrajectoryStateOnSurface firstState = firstStatePropagator.propagate( fullTrack.impactPointState(), firstHit->det()->surface() );
233 
234  KalmanAlignmentDataCollector::fillHistogram( identifier + string("_IPPt"),
235  1e-2*fullTrack.impactPointState().globalParameters().momentum().perp() );
236 
237  if ( !firstState.isValid() ) return result;
238 
239 // LocalTrajectoryError startError;
240 
241 // const double startErrorValue = 100;
242 // const unsigned int nTrajParam = 5;
243 
244 // if ( useExternalEstimate ) {
245 // startError = firstState.localError();
246 // } else {
247 // if ( reuseMomentumEstimate )
248 // {
249 // AlgebraicSymMatrix firstStateError( asHepMatrix( firstState.localError().matrix() ) );
250 // AlgebraicSymMatrix startErrorMatrix( nTrajParam, 0 );
251 // startErrorMatrix[0][0] = 1e-10;
252 // //startErrorMatrix[0][0] = firstStateError[0][0];
253 // startErrorMatrix[1][1] = startErrorValue;//firstStateError[1][1];
254 // startErrorMatrix[2][2] = startErrorValue;//firstStateError[2][2];
255 // startErrorMatrix[3][3] = startErrorValue;
256 // startErrorMatrix[4][4] = startErrorValue;
257 // startError = LocalTrajectoryError( startErrorMatrix );
258 // } else {
259 // AlgebraicSymMatrix startErrorMatrix( startErrorValue*AlgebraicSymMatrix( nTrajParam, 1 ) );
260 // startError = LocalTrajectoryError( startErrorMatrix );
261 // }
262 
263 // }
264 
265 // // MOMENTUM ESTIMATE FOR COSMICS. P = 1.5 GeV
266 // LocalTrajectoryParameters firstStateParameters = firstState.localParameters();
267 // AlgebraicVector firstStateParamVec = asHepVector( firstStateParameters.mixedFormatVector() );
268 // firstStateParamVec[0] = 1./1.5;
269 // LocalTrajectoryParameters cosmicsStateParameters( firstStateParamVec, firstStateParameters.pzSign(), true );
270 // TrajectoryStateOnSurface tsos( cosmicsStateParameters, startError, firstState.surface(), magneticField );
271 
272  KalmanAlignmentDataCollector::fillHistogram( identifier + string("_FSPt"),
273  1e-2*firstState.globalParameters().momentum().perp() );
274 
275  firstState.rescaleError( 100 );
276  TrajectoryStateOnSurface tsos( firstState.localParameters(), firstState.localError(),
277  firstState.surface(), magneticField );
278 
279  // Generate a trajectory seed.
280  TrajectorySeed seed( PTrajectoryStateOnDet(), recHits, propagator->propagationDirection() );
281 
282  // Generate track candidate.
283 
284  PTrajectoryStateOnDet state = trajectoryStateTransform::persistentState( tsos, firstHit->det()->geographicalId().rawId() );
285  TrackCandidate candidate( recHits, seed, state );
286 
287  AlgoProductCollection algoResult;
288 
289  int charge = static_cast<int>( tsos.charge() );
290  double momentum = firstState.localParameters().momentum().mag();
292  TRecHit1DMomConstraint::build( charge, momentum, 1e-10, &tsos.surface() );
293 
294  //no insert in OwnVector...
296  tmpHits.push_back(testhit);
297  for (TransientTrackingRecHit::RecHitContainer::const_iterator i=hits.begin(); i!=hits.end(); i++){
298  tmpHits.push_back(*i);
299  }
300  hits.swap(tmpHits);
301 
302  theRefitterAlgo.buildTrack( fitter, propagator, algoResult, hits, tsos, seed, 0, *beamSpot, candidate.seedRef());
303 
304  for ( AlgoProductCollection::iterator it = algoResult.begin(); it != algoResult.end(); ++it )
305  result.push_back( make_pair( (*it).first, (*it).second.first ) );
306 
307  return result;
308 }
int i
Definition: DBlmapReader.cc:9
T perp() const
Definition: PV3DBase.h:72
static void fillHistogram(std::string histo_name, float data)
virtual PropagationDirection propagationDirection() const
Definition: Propagator.h:155
const LocalTrajectoryParameters & localParameters() const
PTrajectoryStateOnDet persistentState(const TrajectoryStateOnSurface &ts, unsigned int detid)
std::vector< ConstRecHitPointer > RecHitContainer
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
T mag() const
Definition: PV3DBase.h:67
std::shared_ptr< TrackingRecHit const > ConstRecHitPointer
virtual RecHitPointer build(const TrackingRecHit *p) const =0
build a tracking rechit from an existing rechit
tuple result
Definition: query.py:137
LocalVector momentum() const
Momentum vector in the local frame.
const LocalTrajectoryError & localError() const
std::vector< AlgoProduct > AlgoProductCollection
std::shared_ptr< TrackingRecHit const > RecHitPointer
void sortRecHits(RecHitContainer &hits, const TransientTrackingRecHitBuilder *builder, const SortingDirection &sortingDir) const
const GlobalTrajectoryParameters & globalParameters() const
static RecHitPointer build(const int charge, const double mom, const double err, const Surface *surface)
TrackProducerAlgorithm< reco::Track > theRefitterAlgo
KalmanAlignmentTrackRefitter::TrackletCollection KalmanAlignmentTrackRefitter::refitTracks ( const edm::EventSetup eventSetup,
const AlignmentSetupCollection algoSetups,
const ConstTrajTrackPairCollection tracks,
const reco::BeamSpot beamSpot 
)

Definition at line 44 of file KalmanAlignmentTrackRefitter.cc.

References AlignableNavigator::alignableFromDetId(), AnalyticalPropagator_cfi::AnalyticalPropagator, anyDirection, SiPixelRawToDigiRegional_cfi::beamSpot, debugTrackData(), edm::OwnVector< T, P >::empty(), TrackProducerBase< reco::Track >::getFromES(), edm::ESHandle< class >::product(), edm::OwnVector< T, P >::push_back(), refitSingleTracklet(), rejectTrack(), query::result, edm::OwnVector< T, P >::size(), theDebugFlag, theNavigator, and funct::true.

Referenced by KalmanAlignmentAlgorithm::run().

48 {
49  // Retrieve what we need from the EventSetup
51  edm::ESHandle< MagneticField > aMagneticField;
52  edm::ESHandle< TrajectoryFitter > aTrajectoryFitter;
53  edm::ESHandle< Propagator > aPropagator;
56 
58  aGeometry,
59  aMagneticField,
60  aTrajectoryFitter,
61  aPropagator,
62  theMeasTk,
63  aRecHitBuilder );
64 
66  TrackCollection fullTracks;
67 
68  ConstTrajTrackPairCollection refittedFullTracks;
69  ConstTrajTrackPairCollection::const_iterator itTrack;
70 
71  for( itTrack = tracks.begin(); itTrack != tracks.end(); ++itTrack )
72  {
73  TransientTrack fullTrack( *(*itTrack).second, aMagneticField.product() );
74 
75  AlignmentSetupCollection::const_iterator itSetup;
76  for ( itSetup = algoSetups.begin(); itSetup != algoSetups.end(); ++itSetup )
77  {
78  RecHitContainer trackingRecHits;
79  RecHitContainer externalTrackingRecHits;
80 
82  RecHitContainer zPlusRecHits;
83  RecHitContainer zMinusRecHits;
84 
85  // Extract collection with TrackingRecHits
86  Trajectory::ConstRecHitContainer hits = (*itTrack).first->recHits();
87  Trajectory::ConstRecHitContainer::iterator itHits;
88 
89  for ( itHits = hits.begin(); itHits != hits.end(); ++itHits )
90  {
91  if ( !(*itHits)->isValid() ) continue;
92 
93  try
94  {
95  //if ( !theNavigator->alignableFromDetId( (*itHits)->geographicalId() )->alignmentParameters() ) continue;
96  theNavigator->alignableFromDetId( (*itHits)->geographicalId() );
97  } catch(...) { continue; }
98 
99  if ( (*itSetup)->useForTracking( *itHits ) )
100  {
101  trackingRecHits.push_back( (*itHits)->hit()->clone() );
102 
103  ( (*itHits)->det()->position().z() > 0. ) ?
104  zPlusRecHits.push_back( (*itHits)->hit()->clone() ) :
105  zMinusRecHits.push_back( (*itHits)->hit()->clone() );
106 
109  }
110  else if ( (*itSetup)->useForExternalTracking( *itHits ) )
111  {
112  externalTrackingRecHits.push_back( (*itHits)->hit()->clone() );
113  }
114  }
115 
116  //edm::LogInfo( "KalmanAlignmentTrackRefitter" ) << "Hits for tracking/external: " << trackingRecHits.size() << "/" << externalTrackingRecHits.size();
117 
118  //if ( !zPlusRecHits.size() || !zMinusRecHits.size() ) continue;
120 
121  if ( trackingRecHits.empty() ) continue;
122 
123  if ( externalTrackingRecHits.empty() )
124  {
125  if ( ( (*itSetup)->getExternalTrackingSubDetIds().size() == 0 ) && // O.K., no external hits expected,
126  ( trackingRecHits.size() >= (*itSetup)->minTrackingHits() ) )
127  {
128  TrajTrackPairCollection refitted = refitSingleTracklet( aGeometry.product(), aMagneticField.product(),
129  (*itSetup)->fitter(), (*itSetup)->propagator(),
130  aRecHitBuilder.product(), fullTrack,
131  trackingRecHits, beamSpot,
132  (*itSetup)->sortingDirection(), false, true );
133 
134  // The refitting did not work ... Try next!
135  if ( refitted.empty() ) continue;
136  if ( rejectTrack( refitted.front().second ) ) continue;
137 
138  if ( theDebugFlag )
139  {
140  debugTrackData( (*itSetup)->id(), refitted.front().first, refitted.front().second, beamSpot );
141  debugTrackData( "OrigFullTrack", (*itTrack).first, (*itTrack).second, beamSpot );
142  }
143 
144 
145  TrackletPtr trackletPtr( new KalmanAlignmentTracklet( refitted.front(), *itSetup ) );
146  result.push_back( trackletPtr );
147  }
148  else { continue; } // Expected external hits but found none or not enough hits.
149  }
150  else if ( ( trackingRecHits.size() >= (*itSetup)->minTrackingHits() ) &&
151  ( externalTrackingRecHits.size() >= (*itSetup)->minExternalHits() ) )
152  {
153  // Create an instance of KalmanAlignmentTracklet with an external prediction.
154 
155  TrajTrackPairCollection external = refitSingleTracklet( aGeometry.product(), aMagneticField.product(),
156  (*itSetup)->externalFitter(), (*itSetup)->externalPropagator(),
157  aRecHitBuilder.product(), fullTrack,
158  externalTrackingRecHits, beamSpot,
159  (*itSetup)->externalSortingDirection(),
160  false, true );
161  //if ( external.empty() || rejectTrack( external.front().second ) ) { continue; }
162  if ( external.empty() ) { continue; }
163 
164  TransientTrack externalTrack( *external.front().second, aMagneticField.product() );
165 
166  TrajTrackPairCollection refitted = refitSingleTracklet( aGeometry.product(), aMagneticField.product(),
167  (*itSetup)->fitter(), (*itSetup)->propagator(),
168  aRecHitBuilder.product(), externalTrack,
169  trackingRecHits, beamSpot,
170  (*itSetup)->sortingDirection(),
171  false, true, (*itSetup)->id() );
172 
173  if ( refitted.empty() ) { continue; }
174  if ( rejectTrack( refitted.front().second ) ) continue;
175 
176  //const Surface& surface = refitted.front().first->firstMeasurement().updatedState().surface();
177  const Surface& surface = refitted.front().first->lastMeasurement().updatedState().surface();
178  TrajectoryStateOnSurface externalTsos = externalTrack.impactPointState();
179  AnalyticalPropagator externalPredictionPropagator( aMagneticField.product(), anyDirection );
180  TrajectoryStateOnSurface externalPrediction = externalPredictionPropagator.propagate( externalTsos, surface );
181  if ( !externalPrediction.isValid() ) continue;
182 
183  if ( theDebugFlag )
184  {
185  debugTrackData( string("External") + (*itSetup)->id(), external.front().first, external.front().second, beamSpot );
186  debugTrackData( (*itSetup)->id(), refitted.front().first, refitted.front().second, beamSpot );
187  debugTrackData( "OrigFullTrack", (*itTrack).first, (*itTrack).second, beamSpot );
188  }
189 
190  TrackletPtr trackletPtr( new KalmanAlignmentTracklet( refitted.front(), externalPrediction, *itSetup ) );
191  result.push_back( trackletPtr );
192 
193  delete external.front().first;
194  delete external.front().second;
195  }
196  }
197  }
198 
199  return result;
200 }
edm::OwnVector< TrackingRecHit > RecHitContainer
bool rejectTrack(const reco::Track *track) const
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:13
KalmanAlignmentTracklet::TrackletPtr TrackletPtr
KalmanAlignmentTracklet::TrajTrackPairCollection TrajTrackPairCollection
tuple result
Definition: query.py:137
TrackingRecHit::ConstRecHitContainer ConstRecHitContainer
Definition: Trajectory.h:47
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_"))
void debugTrackData(const std::string identifier, const Trajectory *traj, const reco::Track *track, const reco::BeamSpot *bs)
tuple tracks
Definition: testEve_cfg.py:39
AlignmentAlgorithmBase::ConstTrajTrackPairCollection ConstTrajTrackPairCollection
T const * product() const
Definition: ESHandle.h:86
std::vector< TrackletPtr > TrackletCollection
AlignableDetOrUnitPtr alignableFromDetId(const DetId &detid)
Returns AlignableDetOrUnitPtr corresponding to given DetId.
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
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.
bool KalmanAlignmentTrackRefitter::rejectTrack ( const reco::Track track) const
private

Definition at line 346 of file KalmanAlignmentTrackRefitter.cc.

References reco::TrackBase::chi2(), reco::TrackBase::ndof(), and reco::btau::trackChi2.

Referenced by refitTracks().

347 {
348  double trackChi2 = track->chi2();
349  unsigned int ndof = static_cast<unsigned int>( track->ndof() );
350  if ( trackChi2 <= 0. || ndof <= 0 ) return false;
351 
352  //FIXME: should be configurable (via KalmanAlignmentSetup)
353  double minChi2Prob = 0;//1e-6;
354  double maxChi2Prob = 1.0;
355 
356  GENFUNCTION cumulativeChi2 = Genfun::CumulativeChiSquare( ndof );
357  double chi2Prob = 1. - cumulativeChi2( trackChi2 );
358  return ( chi2Prob < minChi2Prob ) || ( chi2Prob > maxChi2Prob );
359 }
double chi2() const
chi-squared of the fit
Definition: TrackBase.h:597
double ndof() const
number of degrees of freedom of the fit
Definition: TrackBase.h:603
void KalmanAlignmentTrackRefitter::sortRecHits ( RecHitContainer hits,
const TransientTrackingRecHitBuilder builder,
const SortingDirection sortingDir 
) const
private

Definition at line 311 of file KalmanAlignmentTrackRefitter.cc.

References edm::OwnVector< T, P >::back(), edm::OwnVector< T, P >::begin(), TransientTrackingRecHitBuilder::build(), edm::OwnVector< T, P >::end(), edm::OwnVector< T, P >::front(), insideOut, mag(), edm::OwnVector< T, P >::push_back(), edm::OwnVector< T, P >::size(), KalmanAlignmentSetup::sortDownsideUp, KalmanAlignmentSetup::sortInsideOut, KalmanAlignmentSetup::sortOutsideIn, KalmanAlignmentSetup::sortUpsideDown, edm::OwnVector< T, P >::swap(), tmp, and detailsBasic3DVector::y.

Referenced by refitSingleTracklet().

314 {
315  // Don't start sorting if there is only 1 or even 0 elements.
316  if ( hits.size() < 2 ) return;
317 
318  TransientTrackingRecHit::RecHitPointer firstHit = builder->build( &hits.front() );
319  double firstRadius = firstHit->det()->surface().toGlobal( firstHit->localPosition() ).mag();
320  double firstY = firstHit->det()->surface().toGlobal( firstHit->localPosition() ).y();
321 
322  TransientTrackingRecHit::RecHitPointer lastHit = builder->build( &hits.back() );
323  double lastRadius = lastHit->det()->surface().toGlobal( lastHit->localPosition() ).mag();
324  double lastY = lastHit->det()->surface().toGlobal( lastHit->localPosition() ).y();
325 
326  bool insideOut = firstRadius < lastRadius;
327  bool upsideDown = lastY < firstY;
328 
329  if ( ( insideOut && ( sortingDir == KalmanAlignmentSetup::sortInsideOut ) ) ||
330  ( !insideOut && ( sortingDir == KalmanAlignmentSetup::sortOutsideIn ) ) ||
331  ( upsideDown && ( sortingDir == KalmanAlignmentSetup::sortUpsideDown ) ) ||
332  ( !upsideDown && ( sortingDir == KalmanAlignmentSetup::sortDownsideUp ) ) ) return;
333 
334  // Fill temporary container with reversed hits.
336  RecHitContainer::iterator itHit = hits.end();
337  do { --itHit; tmp.push_back( ( *itHit ).clone() ); } while ( itHit != hits.begin() );
338 
339  // Swap the content of the temporary and the input container.
340  hits.swap( tmp );
341 
342  return;
343 }
edm::OwnVector< TrackingRecHit > RecHitContainer
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
virtual RecHitPointer build(const TrackingRecHit *p) const =0
build a tracking rechit from an existing rechit
std::shared_ptr< TrackingRecHit const > RecHitPointer
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100

Member Data Documentation

bool KalmanAlignmentTrackRefitter::theDebugFlag
private

Definition at line 94 of file KalmanAlignmentTrackRefitter.h.

Referenced by refitTracks().

AlignableNavigator* KalmanAlignmentTrackRefitter::theNavigator
private

Definition at line 93 of file KalmanAlignmentTrackRefitter.h.

Referenced by refitTracks().

TrackProducerAlgorithm<reco::Track> KalmanAlignmentTrackRefitter::theRefitterAlgo
private

Definition at line 91 of file KalmanAlignmentTrackRefitter.h.

Referenced by refitSingleTracklet().