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