CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TSGFromPropagation.cc
Go to the documentation of this file.
2 
15 
19 
24 
28 
30 
31 TSGFromPropagation::TSGFromPropagation(const edm::ParameterSet & iConfig) :theTkLayerMeasurements (0), theTracker(0), theMeasTracker(0), theNavigation(0), theService(0), theEstimator(0), theTSTransformer(0), theSigmaZ(0), theConfig (iConfig)
32 {
33  theCategory = "Muon|RecoMuon|TSGFromPropagation";
34  theMeasTrackerName = iConfig.getParameter<std::string>("MeasurementTrackerName");
35 
36 }
37 
38 TSGFromPropagation::TSGFromPropagation(const edm::ParameterSet & iConfig, const MuonServiceProxy* service) : theTkLayerMeasurements (0), theTracker(0), theMeasTracker(0), theNavigation(0), theService(service),theUpdator(0), theEstimator(0), theTSTransformer(0), theSigmaZ(0), theConfig (iConfig)
39 {
40  theCategory = "Muon|RecoMuon|TSGFromPropagation";
41  theMeasTrackerName = iConfig.getParameter<std::string>("MeasurementTrackerName");
42 }
43 
45 {
46 
47  LogTrace(theCategory) << " TSGFromPropagation dtor called ";
48  if ( theNavigation ) delete theNavigation;
49  if ( theUpdator ) delete theUpdator;
50  if ( theEstimator ) delete theEstimator;
53 
54 }
55 
56 void TSGFromPropagation::trackerSeeds(const TrackCand& staMuon, const TrackingRegion& region, const TrackerTopology *tTopo, std::vector<TrajectorySeed> & result) {
57 
58  if ( theResetMethod == "discrete" ) getRescalingFactor(staMuon);
59 
60  TrajectoryStateOnSurface staState = outerTkState(staMuon);
61 
62  if ( !staState.isValid() ) {
63  LogTrace(theCategory) << "Error: initial state from L2 muon is invalid.";
64  return;
65  }
66 
67  LogTrace(theCategory) << "begin of trackerSeed:\n staState pos: "<<staState.globalPosition()
68  << " mom: "<<staState.globalMomentum()
69  <<"pos eta: "<<staState.globalPosition().eta()
70  <<"mom eta: "<<staState.globalMomentum().eta();
71 
72  std::vector<const DetLayer*> nls = theNavigation->compatibleLayers(*(staState.freeState()), oppositeToMomentum);
73 
74  LogTrace(theCategory) << " compatible layers: "<<nls.size();
75 
76  if ( nls.empty() ) return;
77 
78  int ndesLayer = 0;
79 
80  bool usePredictedState = false;
81 
82  if ( theUpdateStateFlag ) { //use updated states
83  std::vector<TrajectoryMeasurement> alltm;
84 
85  for (std::vector<const DetLayer*>::const_iterator inl = nls.begin();
86  inl != nls.end(); inl++, ndesLayer++ ) {
87  if ( (*inl == 0) ) break;
88 // if ( (inl != nls.end()-1 ) && ( (*inl)->subDetector() == GeomDetEnumerators::TEC ) && ( (*(inl+1))->subDetector() == GeomDetEnumerators::TOB ) ) continue;
89  alltm = findMeasurements_new(*inl, staState);
90  if ( (!alltm.empty()) ) {
91  LogTrace(theCategory) << "final compatible layer: "<<ndesLayer;
92  break;
93  }
94  }
95 
96  if ( alltm.empty() ) {
97  LogTrace(theCategory) << " NO Measurements Found: eta: "<<staState.globalPosition().eta() <<"pt "<<staState.globalMomentum().perp();
98  usePredictedState = true;
99  } else {
100  LogTrace(theCategory) << " Measurements for seeds: "<<alltm.size();
101  std::stable_sort(alltm.begin(),alltm.end(),increasingEstimate());
102  if ( alltm.size() > 5 ) alltm.erase(alltm.begin() + 5, alltm.end());
103 
104  int i = 0;
105  for (std::vector<TrajectoryMeasurement>::const_iterator itm = alltm.begin();
106  itm != alltm.end(); itm++, i++) {
107  TrajectoryStateOnSurface updatedTSOS = updator()->update(itm->predictedState(), *(itm->recHit()));
108  if ( updatedTSOS.isValid() && passSelection(updatedTSOS) ) {
110  container.push_back(itm->recHit()->hit()->clone());
111  TrajectorySeed ts = createSeed(updatedTSOS, container, itm->recHit()->geographicalId());
112  result.push_back(ts);
113  }
114  }
115  LogTrace(theCategory) << "result: "<<result.size();
116  return;
117  }
118  }
119 
120  if ( !theUpdateStateFlag || usePredictedState ) { //use predicted states
121  LogTrace(theCategory) << "use predicted state: ";
122  for (std::vector<const DetLayer*>::const_iterator inl = nls.begin();
123  inl != nls.end(); inl++ ) {
124 
125  if ( !result.empty() || *inl == 0 ) {
126  break;
127  }
128  std::vector<DetLayer::DetWithState> compatDets = (*inl)->compatibleDets(staState, *propagator(), *estimator());
129  LogTrace(theCategory) << " compatDets "<<compatDets.size();
130  if ( compatDets.empty() ) continue;
131  TrajectorySeed ts = createSeed(compatDets.front().second, compatDets.front().first->geographicalId());
132  result.push_back(ts);
133 
134  }
135  LogTrace(theCategory) << "result: "<<result.size();
136  return;
137  }
138  return;
139 }
140 
142 
143  theMaxChi2 = theConfig.getParameter<double>("MaxChi2");
144 
145  theFixedErrorRescaling = theConfig.getParameter<double>("ErrorRescaling");
146 
147  theFlexErrorRescaling = 1.0;
148 
150 
151  if (theResetMethod != "discrete" && theResetMethod != "fixed" && theResetMethod != "matrix" ) {
152  edm::LogError("TSGFromPropagation")
153  <<"Wrong error rescaling method: "<<theResetMethod <<"\n"
154  <<"Possible choices are: discrete, fixed, matrix.\n"
155  <<"Use discrete method" <<std::endl;
156  theResetMethod = "discrete";
157  }
158 
160 
161  theCacheId_MT = 0;
162 
163  theCacheId_TG = 0;
164 
166 
167  theService = service;
168 
169  theUseVertexStateFlag = theConfig.getParameter<bool>("UseVertexState");
170 
171  theUpdateStateFlag = theConfig.getParameter<bool>("UpdateState");
172 
173  theSelectStateFlag = theConfig.getParameter<bool>("SelectState");
174 
175  theUpdator = new KFUpdator();
176 
177  theSigmaZ = theConfig.getParameter<double>("SigmaZ");
178 
180 
181  edm::ParameterSet errorMatrixPset = theConfig.getParameter<edm::ParameterSet>("errorMatrixPset");
182  if ( theResetMethod == "matrix" && !errorMatrixPset.empty()){
183  theAdjustAtIp = errorMatrixPset.getParameter<bool>("atIP");
184  theErrorMatrixAdjuster = new MuonErrorMatrix(errorMatrixPset);
185  } else {
186  theAdjustAtIp =false;
188  }
189 
190  theService->eventSetup().get<TrackerRecoGeometryRecord>().get(theTracker);
192 
193 }
194 
196 
197  bool measTrackerChanged = false;
198 
199  //edm::Handle<reco::BeamSpot> beamSpot;
201 
202  unsigned long long newCacheId_MT = theService->eventSetup().get<CkfComponentsRecord>().cacheIdentifier();
203 
204  if ( theUpdateStateFlag && newCacheId_MT != theCacheId_MT ) {
205  LogTrace(theCategory) << "Measurment Tracker Geometry changed!";
206  theCacheId_MT = newCacheId_MT;
208  measTrackerChanged = true;
209  }
210 
211  if ( theUpdateStateFlag ) theMeasTracker->update(iEvent);
212 
213  if ( measTrackerChanged && (&*theMeasTracker) ) {
216  }
217 
218  bool trackerGeomChanged = false;
219 
220  unsigned long long newCacheId_TG = theService->eventSetup().get<TrackerRecoGeometryRecord>().cacheIdentifier();
221 
222  if ( newCacheId_TG != theCacheId_TG ) {
223  LogTrace(theCategory) << "Tracker Reco Geometry changed!";
224  theCacheId_TG = newCacheId_TG;
226  trackerGeomChanged = true;
227  }
228 
229  if ( trackerGeomChanged && (&*theTracker) ) {
230  if ( theNavigation ) delete theNavigation;
232  }
233 }
234 
236 
237  TrajectoryStateOnSurface innerTS;
238 
239  if ( staMuon.first && staMuon.first->isValid() ) {
240  if (staMuon.first->direction() == alongMomentum) {
241  innerTS = staMuon.first->firstMeasurement().updatedState();
242  }
243  else if (staMuon.first->direction() == oppositeToMomentum) {
244  innerTS = staMuon.first->lastMeasurement().updatedState();
245  }
246  } else {
248  }
249  //rescale the error
250  adjust(innerTS);
251 
252  return innerTS;
253 
254 // return trajectoryStateTransform::innerStateOnSurface(*(staMuon.second),*theService->trackingGeometry(), &*theService->magneticField());
255 }
256 
258 
260 
261  if ( theUseVertexStateFlag && staMuon.second->pt() > 1.0 ) {
263  //rescale the error at IP
264  adjust(iniState);
265 
266  StateOnTrackerBound fromInside(&*(theService->propagator("PropagatorWithMaterial")));
267  result = fromInside(iniState);
268  } else {
269  StateOnTrackerBound fromOutside(&*propagator());
270  result = fromOutside(innerState(staMuon));
271  }
272  return result;
273 }
274 
276 
278  return createSeed(tsos, container, id);
279 
280 }
281 
283 
284  PTrajectoryStateOnDet const & seedTSOS = trajectoryStateTransform::persistentState(tsos,id.rawId());
285  return TrajectorySeed(seedTSOS,container,oppositeToMomentum);
286 
287 }
288 
289 
290 void TSGFromPropagation::validMeasurements(std::vector<TrajectoryMeasurement>& tms) const {
291 
292  std::vector<TrajectoryMeasurement>::iterator tmsend = std::remove_if(tms.begin(), tms.end(), isInvalid());
293  tms.erase(tmsend, tms.end());
294  return;
295 
296 }
297 
298 std::vector<TrajectoryMeasurement> TSGFromPropagation::findMeasurements_new(const DetLayer* nl, const TrajectoryStateOnSurface& staState) const {
299 
300  std::vector<TrajectoryMeasurement> result;
301 
302  std::vector<DetLayer::DetWithState> compatDets = nl->compatibleDets(staState, *propagator(), *estimator());
303  if ( compatDets.empty() ) return result;
304 
305  for (std::vector<DetLayer::DetWithState>::const_iterator idws = compatDets.begin(); idws != compatDets.end(); ++idws) {
306  if ( idws->second.isValid() && (idws->first) ) {
307  std::vector<TrajectoryMeasurement> tmptm =
308  theMeasTracker->idToDet(idws->first->geographicalId())->fastMeasurements(idws->second, idws->second, *propagator(), *estimator());
309  validMeasurements(tmptm);
310 // if ( tmptm.size() > 2 ) {
311 // std::stable_sort(tmptm.begin(),tmptm.end(),increasingEstimate());
312 // result.insert(result.end(),tmptm.begin(), tmptm.begin()+2);
313 // } else {
314  result.insert(result.end(),tmptm.begin(), tmptm.end());
315 // }
316  }
317  }
318 
319  return result;
320 
321 }
322 
323 std::vector<TrajectoryMeasurement> TSGFromPropagation::findMeasurements(const DetLayer* nl, const TrajectoryStateOnSurface& staState) const {
324 
325  std::vector<TrajectoryMeasurement> result = tkLayerMeasurements()->measurements((*nl), staState, *propagator(), *estimator());
326  validMeasurements(result);
327  return result;
328 }
329 
331  if ( !theSelectStateFlag ) return true;
332  else {
333  if ( beamSpot.isValid() ) {
334  return ( ( fabs(zDis(tsos) - beamSpot->z0() ) < theSigmaZ) );
335 
336  } else {
337  return ( ( fabs(zDis(tsos)) < theSigmaZ) );
338 // double theDxyCut = 100;
339 // return ( (zDis(tsos) < theSigmaZ) && (dxyDis(tsos) < theDxyCut) );
340  }
341  }
342 
343 }
344 
346  return fabs(( - tsos.globalPosition().x() * tsos.globalMomentum().y() + tsos.globalPosition().y() * tsos.globalMomentum().x() )/tsos.globalMomentum().perp());
347 }
348 
350  return tsos.globalPosition().z() - tsos.globalPosition().perp() * tsos.globalMomentum().z()/tsos.globalMomentum().perp();
351 }
352 
354  float pt = (staMuon.second)->pt();
355  if ( pt < 13.0 ) theFlexErrorRescaling = 3;
356  else if ( pt < 30.0 ) theFlexErrorRescaling = 5;
357  else theFlexErrorRescaling = 10;
358  return;
359 }
360 
361 
363 
364  //rescale the error
365  if ( theResetMethod == "discreate" ) {
367  return;
368  }
369 
370  //rescale the error
371  if ( theResetMethod == "fixed" || !theErrorMatrixAdjuster) {
373  return;
374  }
375 
377  CurvilinearTrajectoryError sfMat = theErrorMatrixAdjuster->get(state.momentum());//FIXME with position
378  MuonErrorMatrix::multiply(oMat, sfMat);
379 
380  state = FreeTrajectoryState(state.parameters(),
381  oMat);
382 }
383 
385 
386  //rescale the error
387  if ( theResetMethod == "discreate" ) {
389  return;
390  }
391 
392  if ( theResetMethod == "fixed" || !theErrorMatrixAdjuster) {
394  return;
395  }
396 
398  CurvilinearTrajectoryError sfMat = theErrorMatrixAdjuster->get(state.globalMomentum());//FIXME with position
399  MuonErrorMatrix::multiply(oMat, sfMat);
400 
402  oMat,
403  state.surface(),
404  state.surfaceSide(),
405  state.weight());
406 }
407 
T getParameter(std::string const &) const
std::vector< TrajectoryMeasurement > measurements(const DetLayer &layer, const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est) const
int i
Definition: DBlmapReader.cc:9
TSGFromPropagation(const edm::ParameterSet &pset)
constructor
const edm::EventSetup & eventSetup() const
get the whole EventSetup
const MuonServiceProxy * theService
T perp() const
Definition: PV3DBase.h:72
TrajectoryStateOnSurface outerTkState(const TrackCand &) const
std::pair< const Trajectory *, reco::TrackRef > TrackCand
TrajectoryStateOnSurface innerStateOnSurface(const reco::Track &tk, const TrackingGeometry &geom, const MagneticField *field)
double zDis(const TrajectoryStateOnSurface &tsos) const
unsigned long long theCacheId_TG
const GlobalTrajectoryParameters & parameters() const
virtual TrajectoryStateOnSurface update(const TrajectoryStateOnSurface &, const TransientTrackingRecHit &) const =0
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...
edm::ParameterSet theConfig
edm::ESHandle< MagneticField > magneticField() const
get the magnetic field
const CurvilinearTrajectoryError & curvilinearError() const
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:273
edm::ESHandle< MeasurementTracker > theMeasTracker
int iEvent
Definition: GenABIO.cc:243
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)
FreeTrajectoryState * freeState(bool withErrors=true) const
SurfaceSide surfaceSide() const
Position relative to material, defined relative to momentum vector.
T z() const
Definition: PV3DBase.h:64
bool passSelection(const TrajectoryStateOnSurface &) const
check some quantity and beam-spot compatibility and decide to continue
tuple result
Definition: query.py:137
void validMeasurements(std::vector< TrajectoryMeasurement > &) const
select valid measurements
double dxyDis(const TrajectoryStateOnSurface &tsos) const
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:76
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
GlobalVector momentum() const
#define LogTrace(id)
std::string thePropagatorName
Definition: DetId.h:20
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
FreeTrajectoryState initialFreeState(const reco::Track &tk, const MagneticField *field)
edm::ESHandle< GeometricSearchTracker > theTracker
const T & get() const
Definition: EventSetup.h:55
const LayerMeasurements * tkLayerMeasurements() const
char state
Definition: procUtils.cc:75
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)
const LayerMeasurements * theTkLayerMeasurements
MuonErrorMatrix * theErrorMatrixAdjuster
edm::ESHandle< Propagator > propagator() const
void adjust(FreeTrajectoryState &) const
adjust the error matrix of the FTS
const Chi2MeasurementEstimator * theEstimator
T x() const
Definition: PV3DBase.h:62
edm::Handle< reco::BeamSpot > beamSpot
edm::ESHandle< Propagator > propagator(std::string propagatorName) const
get the propagator