CMS 3D CMS Logo

TSGFromPropagation.cc
Go to the documentation of this file.
2 
13 
17 
22 
26 
28 
30  : TSGFromPropagation(iConfig, iC, nullptr) {}
31 
35  : theCategory("Muon|RecoMuon|TSGFromPropagation"),
36  theService(service),
37  theMaxChi2(iConfig.getParameter<double>("MaxChi2")),
38  theFixedErrorRescaling(iConfig.getParameter<double>("ErrorRescaling")),
39  theUseVertexStateFlag(iConfig.getParameter<bool>("UseVertexState")),
40  theUpdateStateFlag(iConfig.getParameter<bool>("UpdateState")),
41  theResetMethod([](const edm::ParameterSet& iConfig) {
42  auto resetMethod = iConfig.getParameter<std::string>("ResetMethod");
43  if (resetMethod != "discrete" && resetMethod != "fixed" && resetMethod != "matrix") {
44  edm::LogError("TSGFromPropagation") << "Wrong error rescaling method: " << resetMethod << "\n"
45  << "Possible choices are: discrete, fixed, matrix.\n"
46  << "Use discrete method" << std::endl;
47  resetMethod = "discrete";
48  }
49  if ("fixed" == resetMethod) {
50  return ResetMethod::fixed;
51  }
52  if ("matrix" == resetMethod) {
53  return ResetMethod::matrix;
54  }
55  return ResetMethod::discrete;
56  }(iConfig)),
57  theSelectStateFlag(iConfig.getParameter<bool>("SelectState")),
58  thePropagatorName(iConfig.getParameter<std::string>("Propagator")),
59  theSigmaZ(iConfig.getParameter<double>("SigmaZ")),
60  theErrorMatrixPset(iConfig.getParameter<edm::ParameterSet>("errorMatrixPset")),
61  theBeamSpotToken(iC.consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("beamSpot"))),
62  theMeasurementTrackerEventToken(
63  iC.consumes<MeasurementTrackerEvent>(iConfig.getParameter<edm::InputTag>("MeasurementTrackerEvent"))),
64  theTrackerToken(iC.esConsumes()) {}
65 
66 TSGFromPropagation::~TSGFromPropagation() { LogTrace(theCategory) << " TSGFromPropagation dtor called "; }
67 
69  const TrackingRegion& region,
70  const TrackerTopology* tTopo,
71  std::vector<TrajectorySeed>& result) {
73  getRescalingFactor(staMuon);
74 
75  TrajectoryStateOnSurface staState = outerTkState(staMuon);
76 
77  if (!staState.isValid()) {
78  LogTrace(theCategory) << "Error: initial state from L2 muon is invalid.";
79  return;
80  }
81 
82  LogTrace(theCategory) << "begin of trackerSeed:\n staState pos: " << staState.globalPosition()
83  << " mom: " << staState.globalMomentum() << "pos eta: " << staState.globalPosition().eta()
84  << "mom eta: " << staState.globalMomentum().eta();
85 
86  std::vector<const DetLayer*> nls = theNavigation->compatibleLayers(*(staState.freeState()), oppositeToMomentum);
87 
88  LogTrace(theCategory) << " compatible layers: " << nls.size();
89 
90  if (nls.empty())
91  return;
92 
93  int ndesLayer = 0;
94 
95  bool usePredictedState = false;
96 
97  if (theUpdateStateFlag) { //use updated states
98  std::vector<TrajectoryMeasurement> alltm;
99 
100  for (std::vector<const DetLayer*>::const_iterator inl = nls.begin(); inl != nls.end(); inl++, ndesLayer++) {
101  if ((*inl == nullptr))
102  break;
103  // if ( (inl != nls.end()-1 ) && ( (*inl)->subDetector() == GeomDetEnumerators::TEC ) && ( (*(inl+1))->subDetector() == GeomDetEnumerators::TOB ) ) continue;
104  alltm = findMeasurements(*inl, staState);
105  if ((!alltm.empty())) {
106  LogTrace(theCategory) << "final compatible layer: " << ndesLayer;
107  break;
108  }
109  }
110 
111  if (alltm.empty()) {
112  LogTrace(theCategory) << " NO Measurements Found: eta: " << staState.globalPosition().eta() << "pt "
113  << staState.globalMomentum().perp();
114  usePredictedState = true;
115  } else {
116  LogTrace(theCategory) << " Measurements for seeds: " << alltm.size();
117  std::stable_sort(alltm.begin(), alltm.end(), increasingEstimate());
118  if (alltm.size() > 5)
119  alltm.erase(alltm.begin() + 5, alltm.end());
120 
121  int i = 0;
122  for (std::vector<TrajectoryMeasurement>::const_iterator itm = alltm.begin(); itm != alltm.end(); itm++, i++) {
123  TrajectoryStateOnSurface updatedTSOS = updator()->update(itm->predictedState(), *(itm->recHit()));
124  if (updatedTSOS.isValid() && passSelection(updatedTSOS)) {
126  container.push_back(itm->recHit()->hit()->clone());
127  TrajectorySeed ts = createSeed(updatedTSOS, container, itm->recHit()->geographicalId());
128  result.push_back(ts);
129  }
130  }
131  LogTrace(theCategory) << "result: " << result.size();
132  return;
133  }
134  }
135 
136  if (!theUpdateStateFlag || usePredictedState) { //use predicted states
137  LogTrace(theCategory) << "use predicted state: ";
138  for (std::vector<const DetLayer*>::const_iterator inl = nls.begin(); inl != nls.end(); inl++) {
139  if (!result.empty() || *inl == nullptr) {
140  break;
141  }
142  std::vector<DetLayer::DetWithState> compatDets = (*inl)->compatibleDets(staState, *propagator(), *estimator());
143  LogTrace(theCategory) << " compatDets " << compatDets.size();
144  if (compatDets.empty())
145  continue;
146  TrajectorySeed ts = createSeed(compatDets.front().second, compatDets.front().first->geographicalId());
147  result.push_back(ts);
148  }
149  LogTrace(theCategory) << "result: " << result.size();
150  return;
151  }
152  return;
153 }
154 
156  theFlexErrorRescaling = 1.0;
157 
158  theEstimator = std::make_unique<Chi2MeasurementEstimator>(theMaxChi2);
159 
160  theCacheId_TG = 0;
161 
163 
164  theUpdator = std::make_unique<KFUpdator>();
165 
167  theErrorMatrixAdjuster = std::make_unique<MuonErrorMatrix>(theErrorMatrixPset);
168  }
169 }
170 
172  iEvent.getByToken(theBeamSpotToken, beamSpot);
173 
174  if (theUpdateStateFlag) {
176  }
177 
178  unsigned long long newCacheId_TG = theService->eventSetup().get<TrackerRecoGeometryRecord>().cacheIdentifier();
179 
180  if (newCacheId_TG != theCacheId_TG) {
181  LogTrace(theCategory) << "Tracker Reco Geometry changed!";
182  theCacheId_TG = newCacheId_TG;
184  theNavigation = std::make_unique<DirectTrackerNavigation>(theTracker);
185  }
186 }
187 
189  TrajectoryStateOnSurface innerTS;
190 
191  if (staMuon.first && staMuon.first->isValid()) {
192  if (staMuon.first->direction() == alongMomentum) {
193  innerTS = staMuon.first->firstMeasurement().updatedState();
194  } else if (staMuon.first->direction() == oppositeToMomentum) {
195  innerTS = staMuon.first->lastMeasurement().updatedState();
196  }
197  } else {
199  *(staMuon.second), *theService->trackingGeometry(), &*theService->magneticField());
200  }
201  //rescale the error
202  adjust(innerTS);
203 
204  return innerTS;
205 
206  // return trajectoryStateTransform::innerStateOnSurface(*(staMuon.second),*theService->trackingGeometry(), &*theService->magneticField());
207 }
208 
211 
212  if (theUseVertexStateFlag && staMuon.second->pt() > 1.0) {
213  FreeTrajectoryState iniState =
215  //rescale the error at IP
216  adjust(iniState);
217 
218  StateOnTrackerBound fromInside(&*(theService->propagator("PropagatorWithMaterial")));
219  result = fromInside(iniState);
220  } else {
221  StateOnTrackerBound fromOutside(&*propagator());
222  result = fromOutside(innerState(staMuon));
223  }
224  return result;
225 }
226 
229  return createSeed(tsos, container, id);
230 }
231 
233  const edm::OwnVector<TrackingRecHit>& container,
234  const DetId& id) const {
235  PTrajectoryStateOnDet const& seedTSOS = trajectoryStateTransform::persistentState(tsos, id.rawId());
236  return TrajectorySeed(seedTSOS, container, oppositeToMomentum);
237 }
238 
239 void TSGFromPropagation::validMeasurements(std::vector<TrajectoryMeasurement>& tms) const {
240  std::vector<TrajectoryMeasurement>::iterator tmsend = std::remove_if(tms.begin(), tms.end(), isInvalid());
241  tms.erase(tmsend, tms.end());
242  return;
243 }
244 
245 std::vector<TrajectoryMeasurement> TSGFromPropagation::findMeasurements(
246  const DetLayer* nl, const TrajectoryStateOnSurface& staState) const {
247  std::vector<TrajectoryMeasurement> result;
248 
249  std::vector<DetLayer::DetWithState> compatDets = nl->compatibleDets(staState, *propagator(), *estimator());
250  if (compatDets.empty())
251  return result;
252 
253  for (std::vector<DetLayer::DetWithState>::const_iterator idws = compatDets.begin(); idws != compatDets.end();
254  ++idws) {
255  if (idws->second.isValid() && (idws->first)) {
256  std::vector<TrajectoryMeasurement> tmptm =
257  theMeasTrackerEvent->idToDet(idws->first->geographicalId())
258  .fastMeasurements(idws->second, idws->second, *propagator(), *estimator());
259  validMeasurements(tmptm);
260  // if ( tmptm.size() > 2 ) {
261  // std::stable_sort(tmptm.begin(),tmptm.end(),increasingEstimate());
262  // result.insert(result.end(),tmptm.begin(), tmptm.begin()+2);
263  // } else {
264  result.insert(result.end(), tmptm.begin(), tmptm.end());
265  // }
266  }
267  }
268 
269  return result;
270 }
271 
273  if (!theSelectStateFlag)
274  return true;
275  else {
276  if (beamSpot.isValid()) {
277  return ((fabs(zDis(tsos) - beamSpot->z0()) < theSigmaZ));
278 
279  } else {
280  return ((fabs(zDis(tsos)) < theSigmaZ));
281  // double theDxyCut = 100;
282  // return ( (zDis(tsos) < theSigmaZ) && (dxyDis(tsos) < theDxyCut) );
283  }
284  }
285 }
286 
288  return fabs(
289  (-tsos.globalPosition().x() * tsos.globalMomentum().y() + tsos.globalPosition().y() * tsos.globalMomentum().x()) /
290  tsos.globalMomentum().perp());
291 }
292 
294  return tsos.globalPosition().z() -
295  tsos.globalPosition().perp() * tsos.globalMomentum().z() / tsos.globalMomentum().perp();
296 }
297 
299  float pt = (staMuon.second)->pt();
300  if (pt < 13.0)
302  else if (pt < 30.0)
304  else
306  return;
307 }
308 
310  //rescale the error
312  state.rescaleError(theFlexErrorRescaling);
313  return;
314  }
315 
316  //rescale the error
318  state.rescaleError(theFixedErrorRescaling);
319  return;
320  }
321 
322  CurvilinearTrajectoryError oMat = state.curvilinearError();
323  CurvilinearTrajectoryError sfMat = theErrorMatrixAdjuster->get(state.momentum()); //FIXME with position
324  MuonErrorMatrix::multiply(oMat, sfMat);
325 
326  state = FreeTrajectoryState(state.parameters(), oMat);
327 }
328 
330  //rescale the error
332  state.rescaleError(theFlexErrorRescaling);
333  return;
334  }
335 
337  state.rescaleError(theFixedErrorRescaling);
338  return;
339  }
340 
341  CurvilinearTrajectoryError oMat = state.curvilinearError();
342  CurvilinearTrajectoryError sfMat = theErrorMatrixAdjuster->get(state.globalMomentum()); //FIXME with position
343  MuonErrorMatrix::multiply(oMat, sfMat);
344 
345  state =
346  TrajectoryStateOnSurface(state.weight(), state.globalParameters(), oMat, state.surface(), state.surfaceSide());
347 }
edm::Handle< MeasurementTrackerEvent > theMeasTrackerEvent
TrajectorySeed createSeed(const TrajectoryStateOnSurface &, const DetId &) const
create a hitless seed from a trajectory state
void trackerSeeds(const TrackCand &, const TrackingRegion &, const TrackerTopology *, std::vector< TrajectorySeed > &) override
generate seed(s) for a track
std::unique_ptr< const Chi2MeasurementEstimator > theEstimator
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
const MuonServiceProxy * theService
edm::ESHandle< GlobalTrackingGeometry > trackingGeometry() const
get the tracking geometry
T perp() const
Definition: PV3DBase.h:69
virtual std::vector< DetWithState > compatibleDets(const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est) const
const edm::EDGetTokenT< MeasurementTrackerEvent > theMeasurementTrackerEventToken
edm::ESHandle< Propagator > propagator() const
edm::ESHandle< MagneticField > magneticField() const
get the magnetic field
const TrajectoryStateUpdator * updator() const
void init(const MuonServiceProxy *) override
initialize
unsigned long long theCacheId_TG
T z() const
Definition: PV3DBase.h:61
T eta() const
Definition: PV3DBase.h:73
std::unique_ptr< MuonErrorMatrix > theErrorMatrixAdjuster
PTrajectoryStateOnDet persistentState(const TrajectoryStateOnSurface &ts, unsigned int detid)
MeasurementDetWithData idToDet(const DetId &id) const
Previous MeasurementDetSystem interface.
TrajectoryStateOnSurface innerState(const TrackCand &) const
std::vector< TrajectoryMeasurement > findMeasurements(const DetLayer *, const TrajectoryStateOnSurface &) const
look for measurements on the first compatible layer
TSGFromPropagation(const edm::ParameterSet &pset, edm::ConsumesCollector &iC)
constructor
bool passSelection(const TrajectoryStateOnSurface &) const
check some quantity and beam-spot compatibility and decide to continue
std::unique_ptr< const TrajectoryStateUpdator > theUpdator
Log< level::Error, false > LogError
std::pair< const Trajectory *, reco::TrackRef > TrackCand
const ResetMethod theResetMethod
void validMeasurements(std::vector< TrajectoryMeasurement > &) const
select valid measurements
const Chi2MeasurementEstimator * estimator() const
void setEvent(const edm::Event &) override
set an event
#define LogTrace(id)
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
void push_back(D *&d)
Definition: OwnVector.h:326
virtual TrajectoryStateOnSurface update(const TrajectoryStateOnSurface &, const TrackingRecHit &) const =0
int iEvent
Definition: GenABIO.cc:224
std::unique_ptr< const DirectTrackerNavigation > theNavigation
GlobalPoint globalPosition() const
void getRescalingFactor(const TrackCand &staMuon)
const double theFixedErrorRescaling
const edm::EDGetTokenT< reco::BeamSpot > theBeamSpotToken
bool empty() const
Definition: ParameterSet.h:201
const std::string theCategory
T get() const
Definition: EventSetup.h:82
static void multiply(CurvilinearTrajectoryError &initial_error, const CurvilinearTrajectoryError &scale_error)
multiply term by term the two matrix
const edm::ESGetToken< GeometricSearchTracker, TrackerRecoGeometryRecord > theTrackerToken
void adjust(FreeTrajectoryState &) const
adjust the error matrix of the FTS
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:151
const bool theUseVertexStateFlag
Definition: DetId.h:17
GlobalVector globalMomentum() const
bool isValid() const
Definition: HandleBase.h:70
TrajectoryStateOnSurface outerTkState(const TrackCand &) const
double z0() const
z coordinate
Definition: BeamSpot.h:65
HLT enums.
FreeTrajectoryState const * freeState(bool withErrors=true) const
edm::ESHandle< Propagator > propagator(std::string propagatorName) const
get the propagator
const edm::EventSetup & eventSetup() const
const edm::ParameterSet theErrorMatrixPset
double dxyDis(const TrajectoryStateOnSurface &tsos) const
FreeTrajectoryState initialFreeState(const reco::Track &tk, const MagneticField *field, bool withErr=true)
double zDis(const TrajectoryStateOnSurface &tsos) const
edm::Handle< reco::BeamSpot > beamSpot
~TSGFromPropagation() override
destructor
TrajectoryStateOnSurface innerStateOnSurface(const reco::Track &tk, const TrackingGeometry &geom, const MagneticField *field, bool withErr=true)