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 
17 
23 
26 
28 
29 TSGFromPropagation::TSGFromPropagation(const edm::ParameterSet & iConfig) :theTkLayerMeasurements (0), theTracker(0), theMeasTracker(0), theNavigation(0), theService(0), theEstimator(0), theTSTransformer(0), theSigmaZ(0), theConfig (iConfig)
30 {
31  theCategory = "Muon|RecoMuon|TSGFromPropagation";
32  theMeasTrackerName = iConfig.getParameter<std::string>("MeasurementTrackerName");
33 
34 }
35 
36 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)
37 {
38  theCategory = "Muon|RecoMuon|TSGFromPropagation";
39  theMeasTrackerName = iConfig.getParameter<std::string>("MeasurementTrackerName");
40 }
41 
43 {
44 
45  LogTrace(theCategory) << " TSGFromPropagation dtor called ";
46  if ( theNavigation ) delete theNavigation;
47  if ( theUpdator ) delete theUpdator;
48  if ( theEstimator ) delete theEstimator;
50  if ( theTSTransformer ) delete theTSTransformer;
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 
177 
178  theSigmaZ = theConfig.getParameter<double>("SigmaZ");
179 
181 
182  edm::ParameterSet errorMatrixPset = theConfig.getParameter<edm::ParameterSet>("errorMatrixPset");
183  if ( theResetMethod == "matrix" && !errorMatrixPset.empty()){
184  theAdjustAtIp = errorMatrixPset.getParameter<bool>("atIP");
185  theErrorMatrixAdjuster = new MuonErrorMatrix(errorMatrixPset);
186  } else {
187  theAdjustAtIp =false;
189  }
190 
191  theService->eventSetup().get<TrackerRecoGeometryRecord>().get(theTracker);
193 
194 }
195 
197 
198  bool measTrackerChanged = false;
199 
200  //edm::Handle<reco::BeamSpot> beamSpot;
202 
203  unsigned long long newCacheId_MT = theService->eventSetup().get<CkfComponentsRecord>().cacheIdentifier();
204 
205  if ( theUpdateStateFlag && newCacheId_MT != theCacheId_MT ) {
206  LogTrace(theCategory) << "Measurment Tracker Geometry changed!";
207  theCacheId_MT = newCacheId_MT;
209  measTrackerChanged = true;
210  }
211 
212  if ( theUpdateStateFlag ) theMeasTracker->update(iEvent);
213 
214  if ( measTrackerChanged && (&*theMeasTracker) ) {
217  }
218 
219  bool trackerGeomChanged = false;
220 
221  unsigned long long newCacheId_TG = theService->eventSetup().get<TrackerRecoGeometryRecord>().cacheIdentifier();
222 
223  if ( newCacheId_TG != theCacheId_TG ) {
224  LogTrace(theCategory) << "Tracker Reco Geometry changed!";
225  theCacheId_TG = newCacheId_TG;
227  trackerGeomChanged = true;
228  }
229 
230  if ( trackerGeomChanged && (&*theTracker) ) {
231  if ( theNavigation ) delete theNavigation;
233  }
234 }
235 
237 
238  TrajectoryStateOnSurface innerTS;
239 
240  if ( staMuon.first && staMuon.first->isValid() ) {
241  if (staMuon.first->direction() == alongMomentum) {
242  innerTS = staMuon.first->firstMeasurement().updatedState();
243  }
244  else if (staMuon.first->direction() == oppositeToMomentum) {
245  innerTS = staMuon.first->lastMeasurement().updatedState();
246  }
247  } else {
249  }
250  //rescale the error
251  adjust(innerTS);
252 
253  return innerTS;
254 
255 // return theTSTransformer->innerStateOnSurface(*(staMuon.second),*theService->trackingGeometry(), &*theService->magneticField());
256 }
257 
259 
261 
262  if ( theUseVertexStateFlag && staMuon.second->pt() > 1.0 ) {
264  //rescale the error at IP
265  adjust(iniState);
266 
267  StateOnTrackerBound fromInside(&*(theService->propagator("PropagatorWithMaterial")));
268  result = fromInside(iniState);
269  } else {
270  StateOnTrackerBound fromOutside(&*propagator());
271  result = fromOutside(innerState(staMuon));
272  }
273  return result;
274 }
275 
277 
279  return createSeed(tsos, container, id);
280 
281 }
282 
284 
285  PTrajectoryStateOnDet* seedTSOS = theTSTransformer->persistentState(tsos,id.rawId());
286  return TrajectorySeed(*seedTSOS,container,oppositeToMomentum);
287 
288 }
289 
290 
291 void TSGFromPropagation::validMeasurements(std::vector<TrajectoryMeasurement>& tms) const {
292 
293  std::vector<TrajectoryMeasurement>::iterator tmsend = std::remove_if(tms.begin(), tms.end(), isInvalid());
294  tms.erase(tmsend, tms.end());
295  return;
296 
297 }
298 
299 std::vector<TrajectoryMeasurement> TSGFromPropagation::findMeasurements_new(const DetLayer* nl, const TrajectoryStateOnSurface& staState) const {
300 
301  std::vector<TrajectoryMeasurement> result;
302 
303  std::vector<DetLayer::DetWithState> compatDets = nl->compatibleDets(staState, *propagator(), *estimator());
304  if ( compatDets.empty() ) return result;
305 
306  for (std::vector<DetLayer::DetWithState>::const_iterator idws = compatDets.begin(); idws != compatDets.end(); ++idws) {
307  if ( idws->second.isValid() && (idws->first) ) {
308  std::vector<TrajectoryMeasurement> tmptm =
309  theMeasTracker->idToDet(idws->first->geographicalId())->fastMeasurements(idws->second, idws->second, *propagator(), *estimator());
310  validMeasurements(tmptm);
311 // if ( tmptm.size() > 2 ) {
312 // std::stable_sort(tmptm.begin(),tmptm.end(),increasingEstimate());
313 // result.insert(result.end(),tmptm.begin(), tmptm.begin()+2);
314 // } else {
315  result.insert(result.end(),tmptm.begin(), tmptm.end());
316 // }
317  }
318  }
319 
320  return result;
321 
322 }
323 
324 std::vector<TrajectoryMeasurement> TSGFromPropagation::findMeasurements(const DetLayer* nl, const TrajectoryStateOnSurface& staState) const {
325 
326  std::vector<TrajectoryMeasurement> result = tkLayerMeasurements()->measurements((*nl), staState, *propagator(), *estimator());
327  validMeasurements(result);
328  return result;
329 }
330 
332  if ( !theSelectStateFlag ) return true;
333  else {
334  if ( beamSpot.isValid() ) {
335  return ( ( fabs(zDis(tsos) - beamSpot->z0() ) < theSigmaZ) );
336 
337  } else {
338  return ( ( fabs(zDis(tsos)) < theSigmaZ) );
339 // double theDxyCut = 100;
340 // return ( (zDis(tsos) < theSigmaZ) && (dxyDis(tsos) < theDxyCut) );
341  }
342  }
343 
344 }
345 
347  return fabs(( - tsos.globalPosition().x() * tsos.globalMomentum().y() + tsos.globalPosition().y() * tsos.globalMomentum().x() )/tsos.globalMomentum().perp());
348 }
349 
351  return tsos.globalPosition().z() - tsos.globalPosition().perp() * tsos.globalMomentum().z()/tsos.globalMomentum().perp();
352 }
353 
355  float pt = (staMuon.second)->pt();
356  if ( pt < 13.0 ) theFlexErrorRescaling = 3;
357  else if ( pt < 30.0 ) theFlexErrorRescaling = 5;
358  else theFlexErrorRescaling = 10;
359  return;
360 }
361 
362 
364 
365  //rescale the error
366  if ( theResetMethod == "discreate" ) {
368  return;
369  }
370 
371  //rescale the error
372  if ( theResetMethod == "fixed" || !theErrorMatrixAdjuster) {
374  return;
375  }
376 
378  CurvilinearTrajectoryError sfMat = theErrorMatrixAdjuster->get(state.momentum());//FIXME with position
379  MuonErrorMatrix::multiply(oMat, sfMat);
380 
381  state = FreeTrajectoryState(state.parameters(),
382  oMat);
383 }
384 
386 
387  //rescale the error
388  if ( theResetMethod == "discreate" ) {
390  return;
391  }
392 
393  if ( theResetMethod == "fixed" || !theErrorMatrixAdjuster) {
395  return;
396  }
397 
399  CurvilinearTrajectoryError sfMat = theErrorMatrixAdjuster->get(state.globalMomentum());//FIXME with position
400  MuonErrorMatrix::multiply(oMat, sfMat);
401 
403  oMat,
404  state.surface(),
405  state.surfaceSide(),
406  state.weight());
407 }
408 
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
TrajectoryStateTransform * theTSTransformer
T perp() const
Definition: PV3DBase.h:66
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
virtual TrajectoryStateOnSurface update(const TrajectoryStateOnSurface &, const TransientTrackingRecHit &) const =0
const CurvilinearTrajectoryError & curvilinearError() const
void init(const MuonServiceProxy *)
initialize
T y() const
Definition: PV3DBase.h:57
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:288
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:58
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
PTrajectoryStateOnDet * persistentState(const TrajectoryStateOnSurface &ts, unsigned int detid) 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:359
GlobalVector momentum() const
#define LogTrace(id)
std::string thePropagatorName
Definition: DetId.h:20
void rescaleError(double factor)
const GlobalTrajectoryParameters & globalParameters() const
edm::ESHandle< GeometricSearchTracker > theTracker
const T & get() const
Definition: EventSetup.h:55
const LayerMeasurements * tkLayerMeasurements() const
TrajectoryStateOnSurface innerStateOnSurface(const reco::Track &tk, const TrackingGeometry &geom, const MagneticField *field) 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:70
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:56
edm::Handle< reco::BeamSpot > beamSpot
edm::ESHandle< Propagator > propagator(std::string propagatorName) const
get the propagator
FreeTrajectoryState initialFreeState(const reco::Track &tk, const MagneticField *field) const