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 
27 
29 
30 TSGFromPropagation::TSGFromPropagation(const edm::ParameterSet & iConfig) :theTkLayerMeasurements (0), theTracker(0), theMeasTracker(0), theNavigation(0), theService(0), theEstimator(0), theTSTransformer(0), theSigmaZ(0), theConfig (iConfig)
31 {
32  theCategory = "Muon|RecoMuon|TSGFromPropagation";
33  theMeasTrackerName = iConfig.getParameter<std::string>("MeasurementTrackerName");
34 
35 }
36 
37 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)
38 {
39  theCategory = "Muon|RecoMuon|TSGFromPropagation";
40  theMeasTrackerName = iConfig.getParameter<std::string>("MeasurementTrackerName");
41 }
42 
44 {
45 
46  LogTrace(theCategory) << " TSGFromPropagation dtor called ";
47  if ( theNavigation ) delete theNavigation;
48  if ( theUpdator ) delete theUpdator;
49  if ( theEstimator ) delete theEstimator;
52 
53 }
54 
55 void TSGFromPropagation::trackerSeeds(const TrackCand& staMuon, const TrackingRegion& region, std::vector<TrajectorySeed> & result) {
56 
57  if ( theResetMethod == "discrete" ) getRescalingFactor(staMuon);
58 
59  TrajectoryStateOnSurface staState = outerTkState(staMuon);
60 
61  if ( !staState.isValid() ) {
62  LogTrace(theCategory) << "Error: initial state from L2 muon is invalid.";
63  return;
64  }
65 
66  LogTrace(theCategory) << "begin of trackerSeed:\n staState pos: "<<staState.globalPosition()
67  << " mom: "<<staState.globalMomentum()
68  <<"pos eta: "<<staState.globalPosition().eta()
69  <<"mom eta: "<<staState.globalMomentum().eta();
70 
71  std::vector<const DetLayer*> nls = theNavigation->compatibleLayers(*(staState.freeState()), oppositeToMomentum);
72 
73  LogTrace(theCategory) << " compatible layers: "<<nls.size();
74 
75  if ( nls.empty() ) return;
76 
77  int ndesLayer = 0;
78 
79  bool usePredictedState = false;
80 
81  if ( theUpdateStateFlag ) { //use updated states
82  std::vector<TrajectoryMeasurement> alltm;
83 
84  for (std::vector<const DetLayer*>::const_iterator inl = nls.begin();
85  inl != nls.end(); inl++, ndesLayer++ ) {
86  if ( (*inl == 0) ) break;
87 // if ( (inl != nls.end()-1 ) && ( (*inl)->subDetector() == GeomDetEnumerators::TEC ) && ( (*(inl+1))->subDetector() == GeomDetEnumerators::TOB ) ) continue;
88  alltm = findMeasurements_new(*inl, staState);
89  if ( (!alltm.empty()) ) {
90  LogTrace(theCategory) << "final compatible layer: "<<ndesLayer;
91  break;
92  }
93  }
94 
95  if ( alltm.empty() ) {
96  LogTrace(theCategory) << " NO Measurements Found: eta: "<<staState.globalPosition().eta() <<"pt "<<staState.globalMomentum().perp();
97  usePredictedState = true;
98  } else {
99  LogTrace(theCategory) << " Measurements for seeds: "<<alltm.size();
100  std::stable_sort(alltm.begin(),alltm.end(),increasingEstimate());
101  if ( alltm.size() > 5 ) alltm.erase(alltm.begin() + 5, alltm.end());
102 
103  int i = 0;
104  for (std::vector<TrajectoryMeasurement>::const_iterator itm = alltm.begin();
105  itm != alltm.end(); itm++, i++) {
106  TrajectoryStateOnSurface updatedTSOS = updator()->update(itm->predictedState(), *(itm->recHit()));
107  if ( updatedTSOS.isValid() && passSelection(updatedTSOS) ) {
109  container.push_back(itm->recHit()->hit()->clone());
110  TrajectorySeed ts = createSeed(updatedTSOS, container, itm->recHit()->geographicalId());
111  result.push_back(ts);
112  }
113  }
114  LogTrace(theCategory) << "result: "<<result.size();
115  return;
116  }
117  }
118 
119  if ( !theUpdateStateFlag || usePredictedState ) { //use predicted states
120  LogTrace(theCategory) << "use predicted state: ";
121  for (std::vector<const DetLayer*>::const_iterator inl = nls.begin();
122  inl != nls.end(); inl++ ) {
123 
124  if ( !result.empty() || *inl == 0 ) {
125  break;
126  }
127  std::vector<DetLayer::DetWithState> compatDets = (*inl)->compatibleDets(staState, *propagator(), *estimator());
128  LogTrace(theCategory) << " compatDets "<<compatDets.size();
129  if ( compatDets.empty() ) continue;
130  TrajectorySeed ts = createSeed(compatDets.front().second, compatDets.front().first->geographicalId());
131  result.push_back(ts);
132 
133  }
134  LogTrace(theCategory) << "result: "<<result.size();
135  return;
136  }
137  return;
138 }
139 
141 
142  theMaxChi2 = theConfig.getParameter<double>("MaxChi2");
143 
144  theFixedErrorRescaling = theConfig.getParameter<double>("ErrorRescaling");
145 
146  theFlexErrorRescaling = 1.0;
147 
148  theResetMethod = theConfig.getParameter<std::string>("ResetMethod");
149 
150  if (theResetMethod != "discrete" && theResetMethod != "fixed" && theResetMethod != "matrix" ) {
151  edm::LogError("TSGFromPropagation")
152  <<"Wrong error rescaling method: "<<theResetMethod <<"\n"
153  <<"Possible choices are: discrete, fixed, matrix.\n"
154  <<"Use discrete method" <<std::endl;
155  theResetMethod = "discrete";
156  }
157 
159 
160  theCacheId_MT = 0;
161 
162  theCacheId_TG = 0;
163 
164  thePropagatorName = theConfig.getParameter<std::string>("Propagator");
165 
166  theService = service;
167 
168  theUseVertexStateFlag = theConfig.getParameter<bool>("UseVertexState");
169 
170  theUpdateStateFlag = theConfig.getParameter<bool>("UpdateState");
171 
172  theSelectStateFlag = theConfig.getParameter<bool>("SelectState");
173 
174  theUpdator = new KFUpdator();
175 
176  theSigmaZ = theConfig.getParameter<double>("SigmaZ");
177 
179 
180  edm::ParameterSet errorMatrixPset = theConfig.getParameter<edm::ParameterSet>("errorMatrixPset");
181  if ( theResetMethod == "matrix" && !errorMatrixPset.empty()){
182  theAdjustAtIp = errorMatrixPset.getParameter<bool>("atIP");
183  theErrorMatrixAdjuster = new MuonErrorMatrix(errorMatrixPset);
184  } else {
185  theAdjustAtIp =false;
187  }
188 
189  theService->eventSetup().get<TrackerRecoGeometryRecord>().get(theTracker);
191 
192 }
193 
195 
196  bool measTrackerChanged = false;
197 
198  //edm::Handle<reco::BeamSpot> beamSpot;
200 
201  unsigned long long newCacheId_MT = theService->eventSetup().get<CkfComponentsRecord>().cacheIdentifier();
202 
203  if ( theUpdateStateFlag && newCacheId_MT != theCacheId_MT ) {
204  LogTrace(theCategory) << "Measurment Tracker Geometry changed!";
205  theCacheId_MT = newCacheId_MT;
207  measTrackerChanged = true;
208  }
209 
210  if ( theUpdateStateFlag ) theMeasTracker->update(iEvent);
211 
212  if ( measTrackerChanged && (&*theMeasTracker) ) {
215  }
216 
217  bool trackerGeomChanged = false;
218 
219  unsigned long long newCacheId_TG = theService->eventSetup().get<TrackerRecoGeometryRecord>().cacheIdentifier();
220 
221  if ( newCacheId_TG != theCacheId_TG ) {
222  LogTrace(theCategory) << "Tracker Reco Geometry changed!";
223  theCacheId_TG = newCacheId_TG;
225  trackerGeomChanged = true;
226  }
227 
228  if ( trackerGeomChanged && (&*theTracker) ) {
229  if ( theNavigation ) delete theNavigation;
231  }
232 }
233 
235 
236  TrajectoryStateOnSurface innerTS;
237 
238  if ( staMuon.first && staMuon.first->isValid() ) {
239  if (staMuon.first->direction() == alongMomentum) {
240  innerTS = staMuon.first->firstMeasurement().updatedState();
241  }
242  else if (staMuon.first->direction() == oppositeToMomentum) {
243  innerTS = staMuon.first->lastMeasurement().updatedState();
244  }
245  } else {
247  }
248  //rescale the error
249  adjust(innerTS);
250 
251  return innerTS;
252 
253 // return trajectoryStateTransform::innerStateOnSurface(*(staMuon.second),*theService->trackingGeometry(), &*theService->magneticField());
254 }
255 
257 
259 
260  if ( theUseVertexStateFlag && staMuon.second->pt() > 1.0 ) {
262  //rescale the error at IP
263  adjust(iniState);
264 
265  StateOnTrackerBound fromInside(&*(theService->propagator("PropagatorWithMaterial")));
266  result = fromInside(iniState);
267  } else {
268  StateOnTrackerBound fromOutside(&*propagator());
269  result = fromOutside(innerState(staMuon));
270  }
271  return result;
272 }
273 
275 
277  return createSeed(tsos, container, id);
278 
279 }
280 
282 
283  PTrajectoryStateOnDet const & seedTSOS = trajectoryStateTransform::persistentState(tsos,id.rawId());
284  return TrajectorySeed(seedTSOS,container,oppositeToMomentum);
285 
286 }
287 
288 
289 void TSGFromPropagation::validMeasurements(std::vector<TrajectoryMeasurement>& tms) const {
290 
291  std::vector<TrajectoryMeasurement>::iterator tmsend = std::remove_if(tms.begin(), tms.end(), isInvalid());
292  tms.erase(tmsend, tms.end());
293  return;
294 
295 }
296 
297 std::vector<TrajectoryMeasurement> TSGFromPropagation::findMeasurements_new(const DetLayer* nl, const TrajectoryStateOnSurface& staState) const {
298 
299  std::vector<TrajectoryMeasurement> result;
300 
301  std::vector<DetLayer::DetWithState> compatDets = nl->compatibleDets(staState, *propagator(), *estimator());
302  if ( compatDets.empty() ) return result;
303 
304  for (std::vector<DetLayer::DetWithState>::const_iterator idws = compatDets.begin(); idws != compatDets.end(); ++idws) {
305  if ( idws->second.isValid() && (idws->first) ) {
306  std::vector<TrajectoryMeasurement> tmptm =
307  theMeasTracker->idToDet(idws->first->geographicalId())->fastMeasurements(idws->second, idws->second, *propagator(), *estimator());
308  validMeasurements(tmptm);
309 // if ( tmptm.size() > 2 ) {
310 // std::stable_sort(tmptm.begin(),tmptm.end(),increasingEstimate());
311 // result.insert(result.end(),tmptm.begin(), tmptm.begin()+2);
312 // } else {
313  result.insert(result.end(),tmptm.begin(), tmptm.end());
314 // }
315  }
316  }
317 
318  return result;
319 
320 }
321 
322 std::vector<TrajectoryMeasurement> TSGFromPropagation::findMeasurements(const DetLayer* nl, const TrajectoryStateOnSurface& staState) const {
323 
324  std::vector<TrajectoryMeasurement> result = tkLayerMeasurements()->measurements((*nl), staState, *propagator(), *estimator());
325  validMeasurements(result);
326  return result;
327 }
328 
330  if ( !theSelectStateFlag ) return true;
331  else {
332  if ( beamSpot.isValid() ) {
333  return ( ( fabs(zDis(tsos) - beamSpot->z0() ) < theSigmaZ) );
334 
335  } else {
336  return ( ( fabs(zDis(tsos)) < theSigmaZ) );
337 // double theDxyCut = 100;
338 // return ( (zDis(tsos) < theSigmaZ) && (dxyDis(tsos) < theDxyCut) );
339  }
340  }
341 
342 }
343 
345  return fabs(( - tsos.globalPosition().x() * tsos.globalMomentum().y() + tsos.globalPosition().y() * tsos.globalMomentum().x() )/tsos.globalMomentum().perp());
346 }
347 
349  return tsos.globalPosition().z() - tsos.globalPosition().perp() * tsos.globalMomentum().z()/tsos.globalMomentum().perp();
350 }
351 
353  float pt = (staMuon.second)->pt();
354  if ( pt < 13.0 ) theFlexErrorRescaling = 3;
355  else if ( pt < 30.0 ) theFlexErrorRescaling = 5;
356  else theFlexErrorRescaling = 10;
357  return;
358 }
359 
360 
362 
363  //rescale the error
364  if ( theResetMethod == "discreate" ) {
366  return;
367  }
368 
369  //rescale the error
370  if ( theResetMethod == "fixed" || !theErrorMatrixAdjuster) {
372  return;
373  }
374 
376  CurvilinearTrajectoryError sfMat = theErrorMatrixAdjuster->get(state.momentum());//FIXME with position
377  MuonErrorMatrix::multiply(oMat, sfMat);
378 
379  state = FreeTrajectoryState(state.parameters(),
380  oMat);
381 }
382 
384 
385  //rescale the error
386  if ( theResetMethod == "discreate" ) {
388  return;
389  }
390 
391  if ( theResetMethod == "fixed" || !theErrorMatrixAdjuster) {
393  return;
394  }
395 
397  CurvilinearTrajectoryError sfMat = theErrorMatrixAdjuster->get(state.globalMomentum());//FIXME with position
398  MuonErrorMatrix::multiply(oMat, sfMat);
399 
401  oMat,
402  state.surface(),
403  state.surfaceSide(),
404  state.weight());
405 }
406 
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:71
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:62
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
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:63
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:356
GlobalVector momentum() const
#define LogTrace(id)
std::string thePropagatorName
Definition: DetId.h:20
void rescaleError(double factor)
const GlobalTrajectoryParameters & globalParameters() const
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:75
std::string theMeasTrackerName
GlobalVector globalMomentum() const
const Surface & surface() 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 trackerSeeds(const TrackCand &, const TrackingRegion &, std::vector< TrajectorySeed > &)
generate seed(s) for a track
void adjust(FreeTrajectoryState &) const
adjust the error matrix of the FTS
const Chi2MeasurementEstimator * theEstimator
T x() const
Definition: PV3DBase.h:61
edm::Handle< reco::BeamSpot > beamSpot
edm::ESHandle< Propagator > propagator(std::string propagatorName) const
get the propagator