CMS 3D CMS Logo

TSGFromPropagation.cc
Go to the documentation of this file.
2 
13 
17 
22 
26 
28 
30 
32 {
33  theCategory = "Muon|RecoMuon|TSGFromPropagation";
34  theMeasTrackerName = iConfig.getParameter<std::string>("MeasurementTrackerName");
35  theMeasurementTrackerEventTag = iConfig.getParameter<edm::InputTag>("MeasurementTrackerEvent");
39 }
40 
42 {
43 
44  LogTrace(theCategory) << " TSGFromPropagation dtor called ";
45  if ( theNavigation ) delete theNavigation;
46  if ( theUpdator ) delete theUpdator;
47  if ( theEstimator ) delete theEstimator;
49 }
50 
51 void TSGFromPropagation::trackerSeeds(const TrackCand& staMuon, const TrackingRegion& region, const TrackerTopology *tTopo, std::vector<TrajectorySeed> & result) {
52 
53  if ( theResetMethod == "discrete" ) getRescalingFactor(staMuon);
54 
55  TrajectoryStateOnSurface staState = outerTkState(staMuon);
56 
57  if ( !staState.isValid() ) {
58  LogTrace(theCategory) << "Error: initial state from L2 muon is invalid.";
59  return;
60  }
61 
62  LogTrace(theCategory) << "begin of trackerSeed:\n staState pos: "<<staState.globalPosition()
63  << " mom: "<<staState.globalMomentum()
64  <<"pos eta: "<<staState.globalPosition().eta()
65  <<"mom eta: "<<staState.globalMomentum().eta();
66 
67  std::vector<const DetLayer*> nls = theNavigation->compatibleLayers(*(staState.freeState()), oppositeToMomentum);
68 
69  LogTrace(theCategory) << " compatible layers: "<<nls.size();
70 
71  if ( nls.empty() ) return;
72 
73  int ndesLayer = 0;
74 
75  bool usePredictedState = false;
76 
77  if ( theUpdateStateFlag ) { //use updated states
78  std::vector<TrajectoryMeasurement> alltm;
79 
80  for (std::vector<const DetLayer*>::const_iterator inl = nls.begin();
81  inl != nls.end(); inl++, ndesLayer++ ) {
82  if ( (*inl == 0) ) break;
83 // if ( (inl != nls.end()-1 ) && ( (*inl)->subDetector() == GeomDetEnumerators::TEC ) && ( (*(inl+1))->subDetector() == GeomDetEnumerators::TOB ) ) continue;
84  alltm = findMeasurements_new(*inl, staState);
85  if ( (!alltm.empty()) ) {
86  LogTrace(theCategory) << "final compatible layer: "<<ndesLayer;
87  break;
88  }
89  }
90 
91  if ( alltm.empty() ) {
92  LogTrace(theCategory) << " NO Measurements Found: eta: "<<staState.globalPosition().eta() <<"pt "<<staState.globalMomentum().perp();
93  usePredictedState = true;
94  } else {
95  LogTrace(theCategory) << " Measurements for seeds: "<<alltm.size();
96  std::stable_sort(alltm.begin(),alltm.end(),increasingEstimate());
97  if ( alltm.size() > 5 ) alltm.erase(alltm.begin() + 5, alltm.end());
98 
99  int i = 0;
100  for (std::vector<TrajectoryMeasurement>::const_iterator itm = alltm.begin();
101  itm != alltm.end(); itm++, i++) {
102  TrajectoryStateOnSurface updatedTSOS = updator()->update(itm->predictedState(), *(itm->recHit()));
103  if ( updatedTSOS.isValid() && passSelection(updatedTSOS) ) {
105  container.push_back(itm->recHit()->hit()->clone());
106  TrajectorySeed ts = createSeed(updatedTSOS, container, itm->recHit()->geographicalId());
107  result.push_back(ts);
108  }
109  }
110  LogTrace(theCategory) << "result: "<<result.size();
111  return;
112  }
113  }
114 
115  if ( !theUpdateStateFlag || usePredictedState ) { //use predicted states
116  LogTrace(theCategory) << "use predicted state: ";
117  for (std::vector<const DetLayer*>::const_iterator inl = nls.begin();
118  inl != nls.end(); inl++ ) {
119 
120  if ( !result.empty() || *inl == 0 ) {
121  break;
122  }
123  std::vector<DetLayer::DetWithState> compatDets = (*inl)->compatibleDets(staState, *propagator(), *estimator());
124  LogTrace(theCategory) << " compatDets "<<compatDets.size();
125  if ( compatDets.empty() ) continue;
126  TrajectorySeed ts = createSeed(compatDets.front().second, compatDets.front().first->geographicalId());
127  result.push_back(ts);
128 
129  }
130  LogTrace(theCategory) << "result: "<<result.size();
131  return;
132  }
133  return;
134 }
135 
137 
138  theMaxChi2 = theConfig.getParameter<double>("MaxChi2");
139 
140  theFixedErrorRescaling = theConfig.getParameter<double>("ErrorRescaling");
141 
142  theFlexErrorRescaling = 1.0;
143 
145 
146  if (theResetMethod != "discrete" && theResetMethod != "fixed" && theResetMethod != "matrix" ) {
147  edm::LogError("TSGFromPropagation")
148  <<"Wrong error rescaling method: "<<theResetMethod <<"\n"
149  <<"Possible choices are: discrete, fixed, matrix.\n"
150  <<"Use discrete method" <<std::endl;
151  theResetMethod = "discrete";
152  }
153 
155 
156  theCacheId_MT = 0;
157 
158  theCacheId_TG = 0;
159 
161 
162  theService = service;
163 
164  theUseVertexStateFlag = theConfig.getParameter<bool>("UseVertexState");
165 
166  theUpdateStateFlag = theConfig.getParameter<bool>("UpdateState");
167 
168  theSelectStateFlag = theConfig.getParameter<bool>("SelectState");
169 
170  theUpdator = new KFUpdator();
171 
172  theSigmaZ = theConfig.getParameter<double>("SigmaZ");
173 
174  //theBeamSpotInputTag = theConfig.getParameter<edm::InputTag>("beamSpot");
175 
177  if ( theResetMethod == "matrix" && !errorMatrixPset.empty()){
178  theAdjustAtIp = errorMatrixPset.getParameter<bool>("atIP");
179  theErrorMatrixAdjuster = new MuonErrorMatrix(errorMatrixPset);
180  } else {
181  theAdjustAtIp =false;
183  }
184 
185  theService->eventSetup().get<TrackerRecoGeometryRecord>().get(theTracker);
187 
188 }
189 
192 
193  unsigned long long newCacheId_MT = theService->eventSetup().get<CkfComponentsRecord>().cacheIdentifier();
194 
195  if ( theUpdateStateFlag && newCacheId_MT != theCacheId_MT ) {
196  LogTrace(theCategory) << "Measurment Tracker Geometry changed!";
197  theCacheId_MT = newCacheId_MT;
199  }
200 
201  if ( theUpdateStateFlag ) {
204  }
205 
206  bool trackerGeomChanged = false;
207 
208  unsigned long long newCacheId_TG = theService->eventSetup().get<TrackerRecoGeometryRecord>().cacheIdentifier();
209 
210  if ( newCacheId_TG != theCacheId_TG ) {
211  LogTrace(theCategory) << "Tracker Reco Geometry changed!";
212  theCacheId_TG = newCacheId_TG;
214  trackerGeomChanged = true;
215  }
216 
217  if ( trackerGeomChanged && (&*theTracker) ) {
218  if ( theNavigation ) delete theNavigation;
220  }
221 }
222 
224 
225  TrajectoryStateOnSurface innerTS;
226 
227  if ( staMuon.first && staMuon.first->isValid() ) {
228  if (staMuon.first->direction() == alongMomentum) {
229  innerTS = staMuon.first->firstMeasurement().updatedState();
230  }
231  else if (staMuon.first->direction() == oppositeToMomentum) {
232  innerTS = staMuon.first->lastMeasurement().updatedState();
233  }
234  } else {
236  }
237  //rescale the error
238  adjust(innerTS);
239 
240  return innerTS;
241 
242 // return trajectoryStateTransform::innerStateOnSurface(*(staMuon.second),*theService->trackingGeometry(), &*theService->magneticField());
243 }
244 
246 
248 
249  if ( theUseVertexStateFlag && staMuon.second->pt() > 1.0 ) {
251  //rescale the error at IP
252  adjust(iniState);
253 
254  StateOnTrackerBound fromInside(&*(theService->propagator("PropagatorWithMaterial")));
255  result = fromInside(iniState);
256  } else {
257  StateOnTrackerBound fromOutside(&*propagator());
258  result = fromOutside(innerState(staMuon));
259  }
260  return result;
261 }
262 
264 
266  return createSeed(tsos, container, id);
267 
268 }
269 
271 
272  PTrajectoryStateOnDet const & seedTSOS = trajectoryStateTransform::persistentState(tsos,id.rawId());
273  return TrajectorySeed(seedTSOS,container,oppositeToMomentum);
274 
275 }
276 
277 
278 void TSGFromPropagation::validMeasurements(std::vector<TrajectoryMeasurement>& tms) const {
279 
280  std::vector<TrajectoryMeasurement>::iterator tmsend = std::remove_if(tms.begin(), tms.end(), isInvalid());
281  tms.erase(tmsend, tms.end());
282  return;
283 
284 }
285 
286 std::vector<TrajectoryMeasurement> TSGFromPropagation::findMeasurements_new(const DetLayer* nl, const TrajectoryStateOnSurface& staState) const {
287 
288  std::vector<TrajectoryMeasurement> result;
289 
290  std::vector<DetLayer::DetWithState> compatDets = nl->compatibleDets(staState, *propagator(), *estimator());
291  if ( compatDets.empty() ) return result;
292 
293  for (std::vector<DetLayer::DetWithState>::const_iterator idws = compatDets.begin(); idws != compatDets.end(); ++idws) {
294  if ( idws->second.isValid() && (idws->first) ) {
295  std::vector<TrajectoryMeasurement> tmptm =
296  theMeasTrackerEvent->idToDet(idws->first->geographicalId()).fastMeasurements(idws->second, idws->second, *propagator(), *estimator());
297  validMeasurements(tmptm);
298 // if ( tmptm.size() > 2 ) {
299 // std::stable_sort(tmptm.begin(),tmptm.end(),increasingEstimate());
300 // result.insert(result.end(),tmptm.begin(), tmptm.begin()+2);
301 // } else {
302  result.insert(result.end(),tmptm.begin(), tmptm.end());
303 // }
304  }
305  }
306 
307  return result;
308 
309 }
310 
311 std::vector<TrajectoryMeasurement> TSGFromPropagation::findMeasurements(const DetLayer* nl, const TrajectoryStateOnSurface& staState) const {
312 
313  std::vector<TrajectoryMeasurement> result = tkLayerMeasurements()->measurements((*nl), staState, *propagator(), *estimator());
314  validMeasurements(result);
315  return result;
316 }
317 
319  if ( !theSelectStateFlag ) return true;
320  else {
321  if ( beamSpot.isValid() ) {
322  return ( ( fabs(zDis(tsos) - beamSpot->z0() ) < theSigmaZ) );
323 
324  } else {
325  return ( ( fabs(zDis(tsos)) < theSigmaZ) );
326 // double theDxyCut = 100;
327 // return ( (zDis(tsos) < theSigmaZ) && (dxyDis(tsos) < theDxyCut) );
328  }
329  }
330 
331 }
332 
334  return fabs(( - tsos.globalPosition().x() * tsos.globalMomentum().y() + tsos.globalPosition().y() * tsos.globalMomentum().x() )/tsos.globalMomentum().perp());
335 }
336 
338  return tsos.globalPosition().z() - tsos.globalPosition().perp() * tsos.globalMomentum().z()/tsos.globalMomentum().perp();
339 }
340 
342  float pt = (staMuon.second)->pt();
343  if ( pt < 13.0 ) theFlexErrorRescaling = 3;
344  else if ( pt < 30.0 ) theFlexErrorRescaling = 5;
345  else theFlexErrorRescaling = 10;
346  return;
347 }
348 
349 
351 
352  //rescale the error
353  if ( theResetMethod == "discreate" ) {
355  return;
356  }
357 
358  //rescale the error
359  if ( theResetMethod == "fixed" || !theErrorMatrixAdjuster) {
361  return;
362  }
363 
365  CurvilinearTrajectoryError sfMat = theErrorMatrixAdjuster->get(state.momentum());//FIXME with position
366  MuonErrorMatrix::multiply(oMat, sfMat);
367 
368  state = FreeTrajectoryState(state.parameters(),
369  oMat);
370 }
371 
373 
374  //rescale the error
375  if ( theResetMethod == "discreate" ) {
377  return;
378  }
379 
380  if ( theResetMethod == "fixed" || !theErrorMatrixAdjuster) {
382  return;
383  }
384 
386  CurvilinearTrajectoryError sfMat = theErrorMatrixAdjuster->get(state.globalMomentum());//FIXME with position
387  MuonErrorMatrix::multiply(oMat, sfMat);
388 
389  state = TrajectoryStateOnSurface(state.weight(),
390  state.globalParameters(),
391  oMat,
392  state.surface(),
393  state.surfaceSide());
394 }
395 
edm::Handle< MeasurementTrackerEvent > theMeasTrackerEvent
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
MeasurementDetWithData idToDet(const DetId &id) const
Previous MeasurementDetSystem interface.
double z0() const
z coordinate
Definition: BeamSpot.h:68
std::vector< TrajectoryMeasurement > measurements(const DetLayer &layer, const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est) const
const edm::EventSetup & eventSetup() const
get the whole EventSetup
const MuonServiceProxy * theService
TrajectoryStateTransform * theTSTransformer
T perp() const
Definition: PV3DBase.h:72
TrajectoryStateOnSurface outerTkState(const TrackCand &) const
std::pair< const Trajectory *, reco::TrackRef > TrackCand
double zDis(const TrajectoryStateOnSurface &tsos) const
unsigned long long theCacheId_TG
const GlobalTrajectoryParameters & parameters() const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
LayerMeasurements theTkLayerMeasurements
const CurvilinearTrajectoryError & curvilinearError() const
void init(const MuonServiceProxy *)
initialize
PTrajectoryStateOnDet persistentState(const TrajectoryStateOnSurface &ts, unsigned int detid)
T y() const
Definition: PV3DBase.h:63
GlobalPoint globalPosition() const
CurvilinearTrajectoryError get(GlobalVector momentum, bool convolute=true)
main method to be used. Retrieve a 5x5 symetrical matrix according to parametrization of error or sca...
TSGFromPropagation(const edm::ParameterSet &pset, edm::ConsumesCollector &iC)
constructor
#define nullptr
edm::ParameterSet theConfig
edm::ESHandle< MagneticField > magneticField() const
get the magnetic field
const CurvilinearTrajectoryError & curvilinearError() const
virtual TrajectoryStateOnSurface update(const TrajectoryStateOnSurface &, const TrackingRecHit &) const =0
virtual std::vector< DetWithState > compatibleDets(const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est) const
const TrajectoryStateUpdator * theUpdator
virtual ~TSGFromPropagation()
destructor
TrajectoryStateOnSurface innerState(const TrackCand &) const
void push_back(D *&d)
Definition: OwnVector.h:290
edm::ESHandle< MeasurementTracker > theMeasTracker
int iEvent
Definition: GenABIO.cc:230
const SurfaceType & surface() const
std::vector< TrajectoryMeasurement > findMeasurements(const DetLayer *, const TrajectoryStateOnSurface &) const
look for measurements on the first compatible layer
void getRescalingFactor(const TrackCand &staMuon)
SurfaceSide surfaceSide() const
Position relative to material, defined relative to momentum vector.
FreeTrajectoryState const * freeState(bool withErrors=true) const
T z() const
Definition: PV3DBase.h:64
bool passSelection(const TrajectoryStateOnSurface &) const
check some quantity and beam-spot compatibility and decide to continue
void validMeasurements(std::vector< TrajectoryMeasurement > &) const
select valid measurements
double dxyDis(const TrajectoryStateOnSurface &tsos) const
edm::EDGetTokenT< MeasurementTrackerEvent > theMeasurementTrackerEventToken
static void multiply(CurvilinearTrajectoryError &initial_error, const CurvilinearTrajectoryError &scale_error)
multiply term by term the two matrix
const TrajectoryStateUpdator * updator() const
bool isValid() const
Definition: HandleBase.h:74
GlobalVector momentum() const
#define LogTrace(id)
edm::InputTag theMeasurementTrackerEventTag
std::string thePropagatorName
Definition: DetId.h:18
void rescaleError(double factor)
const GlobalTrajectoryParameters & globalParameters() const
void trackerSeeds(const TrackCand &, const TrackingRegion &, const TrackerTopology *, std::vector< TrajectorySeed > &)
generate seed(s) for a track
edm::ESHandle< GeometricSearchTracker > theTracker
const T & get() const
Definition: EventSetup.h:56
const LayerMeasurements * tkLayerMeasurements() const
TrajectorySeed createSeed(const TrajectoryStateOnSurface &, const DetId &) const
create a hitless seed from a trajectory state
const DirectTrackerNavigation * theNavigation
edm::ESHandle< GlobalTrackingGeometry > trackingGeometry() const
get the tracking geometry
T eta() const
Definition: PV3DBase.h:76
std::string theMeasTrackerName
GlobalVector globalMomentum() const
void setEvent(const edm::Event &)
set an event
std::vector< const DetLayer * > compatibleLayers(const FreeTrajectoryState &fts, PropagationDirection timeDirection) const
find compatible layers for a given trajectory state
unsigned long long theCacheId_MT
edm::InputTag theBeamSpotInputTag
const Chi2MeasurementEstimator * estimator() const
std::vector< TrajectoryMeasurement > findMeasurements_new(const DetLayer *, const TrajectoryStateOnSurface &) const
look for measurements on the first compatible layer (faster way)
MuonErrorMatrix * theErrorMatrixAdjuster
edm::ESHandle< Propagator > propagator() const
edm::EDGetTokenT< reco::BeamSpot > theBeamSpotToken
void adjust(FreeTrajectoryState &) const
adjust the error matrix of the FTS
const Chi2MeasurementEstimator * theEstimator
T x() const
Definition: PV3DBase.h:62
FreeTrajectoryState initialFreeState(const reco::Track &tk, const MagneticField *field, bool withErr=true)
edm::Handle< reco::BeamSpot > beamSpot
edm::ESHandle< Propagator > propagator(std::string propagatorName) const
get the propagator
TrajectoryStateOnSurface innerStateOnSurface(const reco::Track &tk, const TrackingGeometry &geom, const MagneticField *field, bool withErr=true)