CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
GlobalTrackQualityProducer Class Reference

#include <GlobalTrackQualityProducer.h>

Inheritance diagram for GlobalTrackQualityProducer:
edm::stream::EDProducer<>

Public Member Functions

 GlobalTrackQualityProducer (const edm::ParameterSet &iConfig)
 
 ~GlobalTrackQualityProducer () override
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
bool hasAbilityToProduceInLumis () const final
 
bool hasAbilityToProduceInRuns () const final
 

Private Member Functions

virtual std::pair< double, double > kink (Trajectory &muon) const
 
virtual std::pair< double, double > newChi2 (Trajectory &muon) const
 
void produce (edm::Event &, const edm::EventSetup &) override
 
virtual double trackProbability (Trajectory &track) const
 

Private Attributes

edm::EDGetTokenT< reco::TrackCollectionglbMuonsToken
 
edm::InputTag inputCollection_
 
edm::InputTag inputLinksCollection_
 
edm::EDGetTokenT< reco::MuonTrackLinksCollectionlinkCollectionToken
 
MeasurementEstimatortheEstimator
 
GlobalMuonTrackMatchertheGlbMatcher
 
GlobalMuonRefittertheGlbRefitter
 
MuonServiceProxytheService
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
typedef CacheContexts< T... > CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T... > HasAbility
 
typedef CacheTypes::LuminosityBlockCache LuminosityBlockCache
 
typedef LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCacheLuminosityBlockContext
 
typedef CacheTypes::LuminosityBlockSummaryCache LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache, GlobalCacheRunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 

Detailed Description

Definition at line 27 of file GlobalTrackQualityProducer.h.

Constructor & Destructor Documentation

GlobalTrackQualityProducer::GlobalTrackQualityProducer ( const edm::ParameterSet iConfig)
explicit

Definition at line 27 of file GlobalTrackQualityProducer.cc.

References Chi2MeasurementEstimator_cfi::Chi2MeasurementEstimator, edm::ParameterSet::getParameter(), glbMuonsToken, GlobalMuonRefitter_cff::GlobalMuonRefitter, globalMuons_cfi::GlobalMuonTrackMatcher, inputCollection_, inputLinksCollection_, linkCollectionToken, btvTracks_cfi::maxChi2, MuonServiceProxy_cff::MuonServiceProxy, gsfElectronCkfTrackCandidateMaker_cff::nSigma, theEstimator, theGlbMatcher, theGlbRefitter, and theService.

27  :
28  inputCollection_(iConfig.getParameter<edm::InputTag>("InputCollection")),inputLinksCollection_(iConfig.getParameter<edm::InputTag>("InputLinksCollection")),theService(nullptr),theGlbRefitter(nullptr),theGlbMatcher(nullptr)
29 {
30  // service parameters
31  edm::ParameterSet serviceParameters = iConfig.getParameter<edm::ParameterSet>("ServiceParameters");
32  theService = new MuonServiceProxy(serviceParameters);
33 
34  // TrackRefitter parameters
35  edm::ConsumesCollector iC = consumesCollector();
36  edm::ParameterSet refitterParameters = iConfig.getParameter<edm::ParameterSet>("RefitterParameters");
37  theGlbRefitter = new GlobalMuonRefitter(refitterParameters, theService, iC);
38 
39  edm::ParameterSet trackMatcherPSet = iConfig.getParameter<edm::ParameterSet>("GlobalMuonTrackMatcher");
40  theGlbMatcher = new GlobalMuonTrackMatcher(trackMatcherPSet,theService);
41 
42  double maxChi2 = iConfig.getParameter<double>("MaxChi2");
43  double nSigma = iConfig.getParameter<double>("nSigma");
44  theEstimator = new Chi2MeasurementEstimator(maxChi2,nSigma);
45 
46  glbMuonsToken=consumes<reco::TrackCollection>(inputCollection_);
47  linkCollectionToken=consumes<reco::MuonTrackLinksCollection>(inputLinksCollection_);
48 
49  produces<edm::ValueMap<reco::MuonQuality> >();
50 }
T getParameter(std::string const &) const
edm::EDGetTokenT< reco::TrackCollection > glbMuonsToken
edm::EDGetTokenT< reco::MuonTrackLinksCollection > linkCollectionToken
GlobalMuonTrackMatcher * theGlbMatcher
GlobalTrackQualityProducer::~GlobalTrackQualityProducer ( )
override

Definition at line 52 of file GlobalTrackQualityProducer.cc.

References theEstimator, theGlbMatcher, theGlbRefitter, and theService.

52  {
53  if (theService) delete theService;
54  if (theGlbRefitter) delete theGlbRefitter;
55  if (theGlbMatcher) delete theGlbMatcher;
56  if (theEstimator) delete theEstimator;
57 }
GlobalMuonTrackMatcher * theGlbMatcher

Member Function Documentation

std::pair< double, double > GlobalTrackQualityProducer::kink ( Trajectory muon) const
privatevirtual

Definition at line 175 of file GlobalTrackQualityProducer.cc.

References diffTreeTool::diff, relativeConstraints::error, TrajectoryStateOnSurface::globalPosition(), edm::isNotFinite(), TrajectoryStateOnSurface::isValid(), funct::m, M_PI, Trajectory::measurements(), convertSQLiteXML::ok, PV3DBase< T, PVType, FrameType >::phi(), GlobalErrorBase< T, ErrorWeightType >::phierr(), mps_fire::result, alignCSCRings::s, AlCaHLTBitMon_QueryRunRegistry::string, and DetId::Tracker.

Referenced by produce().

175  {
176 
177  const std::string theCategory = "Muon|RecoMuon|GlobalTrackQualityProducer";
178 
179  using namespace std;
180  using namespace edm;
181  using namespace reco;
182 
183  double result = 0.0;
184  double resultGlb = 0.0;
185 
186 
188  typedef ConstRecHitPointer RecHit;
189  typedef std::vector<TrajectoryMeasurement>::const_iterator TMI;
190 
191 
192  vector<TrajectoryMeasurement> meas = muon.measurements();
193 
194  for ( TMI m = meas.begin(); m != meas.end(); m++ ) {
196 
197  //not used double estimate = 0.0;
198 
199  RecHit rhit = (*m).recHit();
200  bool ok = false;
201  if ( rhit->isValid() ) {
202  if(DetId::Tracker == rhit->geographicalId().det()) ok = true;
203  }
204 
205  //if ( !ok ) continue;
206 
207  const TrajectoryStateOnSurface& tsos = (*m).predictedState();
208 
209 
210  if ( tsos.isValid() && rhit->isValid() && rhit->hit()->isValid()
211  && !edm::isNotFinite(rhit->localPositionError().xx()) //this is paranoia induced by reported case
212  && !edm::isNotFinite(rhit->localPositionError().xy()) //it's better to track down the origin of bad numbers
213  && !edm::isNotFinite(rhit->localPositionError().yy())
214  ) {
215 
216  double phi1 = tsos.globalPosition().phi();
217  if ( phi1 < 0 ) phi1 = 2*M_PI + phi1;
218 
219  double phi2 = rhit->globalPosition().phi();
220  if ( phi2 < 0 ) phi2 = 2*M_PI + phi2;
221 
222  double diff = fabs(phi1 - phi2);
223  if ( diff > M_PI ) diff = 2*M_PI - diff;
224 
225  GlobalPoint hitPos = rhit->globalPosition();
226 
227  GlobalError hitErr = rhit->globalPositionError();
228  //LogDebug(theCategory)<<"hitPos " << hitPos;
229  double error = hitErr.phierr(hitPos); // error squared
230 
231  double s = ( error > 0.0 ) ? (diff*diff)/error : (diff*diff);
232 
233  if(ok) result += s;
234  resultGlb += s;
235  }
236 
237  }
238 
239 
240  return std::pair<double,double>(result,resultGlb);
241 
242 }
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
GlobalPoint globalPosition() const
T phierr(const GlobalPoint &aPoint) const
TransientTrackingRecHit::ConstRecHitPointer ConstRecHitPointer
DataContainer const & measurements() const
Definition: Trajectory.h:196
bool isNotFinite(T x)
Definition: isFinite.h:10
std::shared_ptr< TrackingRecHit const > ConstRecHitPointer
#define M_PI
fixed size matrix
HLT enums.
std::pair< double, double > GlobalTrackQualityProducer::newChi2 ( Trajectory muon) const
privatevirtual

Definition at line 244 of file GlobalTrackQualityProducer.cc.

References MeasurementEstimator::estimate(), TrajectoryStateOnSurface::isValid(), funct::m, Trajectory::measurements(), DetId::Muon, AlCaHLTBitMon_QueryRunRegistry::string, theEstimator, and DetId::Tracker.

Referenced by produce().

244  {
245  const std::string theCategory = "Muon|RecoMuon|GlobalTrackQualityProducer";
246 
247  using namespace std;
248  using namespace edm;
249  using namespace reco;
250 
251  double muChi2 = 0.0;
252  double tkChi2 = 0.0;
253  unsigned int muNdof = 0;
254  unsigned int tkNdof = 0;
255 
257  typedef ConstRecHitPointer RecHit;
258  typedef vector<TrajectoryMeasurement>::const_iterator TMI;
259 
260  vector<TrajectoryMeasurement> meas = muon.measurements();
261 
262  for ( TMI m = meas.begin(); m != meas.end(); m++ ) {
264  const TrajectoryStateOnSurface& uptsos = (*m).updatedState();
265  // FIXME FIXME CLONE!!!
266  // TrackingRecHit::RecHitPointer preciseHit = hit->clone(uptsos);
267  const auto& preciseHit = hit;
268  double estimate = 0.0;
269  if (preciseHit->isValid() && uptsos.isValid()) {
270  estimate = theEstimator->estimate(uptsos, *preciseHit ).second;
271  }
272 
273  //LogTrace(theCategory) << "estimate " << estimate << " TM.est " << m->estimate();
274  //UNUSED: double tkDiff = 0.0;
275  //UNUSED: double staDiff = 0.0;
276  if ( hit->isValid() && (hit->geographicalId().det()) == DetId::Tracker ) {
277  tkChi2 += estimate;
278  //UNUSED: tkDiff = estimate - m->estimate();
279  tkNdof += hit->dimension();
280  }
281  if ( hit->isValid() && (hit->geographicalId().det()) == DetId::Muon ) {
282  muChi2 += estimate;
283  //UNUSED staDiff = estimate - m->estimate();
284  muNdof += hit->dimension();
285  }
286  }
287 
288  if (tkNdof < 6 ) tkChi2 = tkChi2; // or should I set it to a large number ?
289  else tkChi2 /= (tkNdof-5.);
290 
291  if (muNdof < 6 ) muChi2 = muChi2; // or should I set it to a large number ?
292  else muChi2 /= (muNdof-5.);
293 
294  return std::pair<double,double>(tkChi2,muChi2);
295 
296 }
TransientTrackingRecHit::ConstRecHitPointer ConstRecHitPointer
DataContainer const & measurements() const
Definition: Trajectory.h:196
std::shared_ptr< TrackingRecHit const > ConstRecHitPointer
fixed size matrix
HLT enums.
virtual HitReturnType estimate(const TrajectoryStateOnSurface &ts, const TrackingRecHit &hit) const =0
void GlobalTrackQualityProducer::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivate

Definition at line 60 of file GlobalTrackQualityProducer.cc.

References vertices_cff::chi2, reco::MuonQuality::chi2LocalMomentum, reco::MuonQuality::chi2LocalPosition, edmIntegrityCheck::d, MuonServiceProxy::eventSetup(), edm::EventSetup::get(), edm::Event::getByToken(), edm::Event::getProvenance(), reco::MuonQuality::glbKink, glbMuonsToken, reco::MuonQuality::glbTrackProbability, reco::MuonQuality::globalDeltaEtaPhi, edm::Ref< C, T, F >::id(), edm::Ref< C, T, F >::isNull(), edm::HandleBase::isValid(), kink(), linkCollectionToken, reco::MuonQuality::localDistance, LogTrace, GlobalMuonTrackMatcher::match(), GlobalMuonTrackMatcher::matchTight(), SiStripPI::max, eostools::move(), newChi2(), edm::ESHandle< T >::product(), edm::Event::put(), GlobalMuonRefitter::refit(), GlobalMuonRefitter::setEvent(), GlobalMuonRefitter::setServices(), reco::MuonQuality::staRelChi2, AlCaHLTBitMon_QueryRunRegistry::string, theGlbMatcher, theGlbRefitter, theService, reco::MuonQuality::tightMatch, HiIsolationCommonParameters_cff::track, trackProbability(), reco::MuonQuality::trkKink, reco::MuonQuality::trkRelChi2, MuonServiceProxy::update(), and reco::MuonQuality::updatedSta.

61 {
62  const std::string theCategory = "Muon|RecoMuon|GlobalTrackQualityProducer";
63 
64  theService->update(iSetup);
65 
66  theGlbRefitter->setEvent(iEvent);
67 
68  theGlbRefitter->setServices(theService->eventSetup());
69 
70  // Take the GLB muon container(s)
72  iEvent.getByToken(glbMuonsToken,glbMuons);
73 
75  iEvent.getByToken(linkCollectionToken,linkCollectionHandle);
76 
77  //Retrieve tracker topology from geometry
79  iSetup.get<TrackerTopologyRcd>().get(tTopoHand);
80  const TrackerTopology *tTopo=tTopoHand.product();
81 
82 
83  // reserve some space
84  std::vector<reco::MuonQuality> valuesQual;
85  valuesQual.reserve(glbMuons->size());
86 
87  int trackIndex = 0;
88  for (reco::TrackCollection::const_iterator track = glbMuons->begin(); track!=glbMuons->end(); ++track , ++trackIndex) {
89  reco::TrackRef glbRef(glbMuons,trackIndex);
90  reco::TrackRef staTrack = reco::TrackRef();
91 
92  std::vector<Trajectory> refitted=theGlbRefitter->refit(*track,1,tTopo);
93 
94  LogTrace(theCategory)<<"GLBQual N refitted " << refitted.size();
95 
96  std::pair<double,double> thisKink;
97  double relative_muon_chi2 = 0.0;
98  double relative_tracker_chi2 = 0.0;
99  double glbTrackProbability = 0.0;
100  if(!refitted.empty()) {
101  thisKink = kink(refitted.front()) ;
102  std::pair<double,double> chi = newChi2(refitted.front());
103  relative_muon_chi2 = chi.second; //normalized inside to /sum(muHits.dimension)
104  relative_tracker_chi2 = chi.first; //normalized inside to /sum(tkHits.dimension)
105  glbTrackProbability = trackProbability(refitted.front());
106  }
107 
108  LogTrace(theCategory)<<"GLBQual: Kink " << thisKink.first << " " << thisKink.second;
109  LogTrace(theCategory)<<"GLBQual: Rel Chi2 " << relative_tracker_chi2 << " " << relative_muon_chi2;
110  LogTrace(theCategory)<<"GLBQual: trackProbability " << glbTrackProbability;
111 
112  // Fill the STA-TK match information
113  float chi2, d, dist, Rpos;
114  chi2 = d = dist = Rpos = -1.0;
115  bool passTight = false;
116  typedef MuonTrajectoryBuilder::TrackCand TrackCand;
117  if ( linkCollectionHandle.isValid() ) {
118  for ( reco::MuonTrackLinksCollection::const_iterator links = linkCollectionHandle->begin();
119  links != linkCollectionHandle->end(); ++links )
120  {
121  if ( links->trackerTrack().isNull() ||
122  links->standAloneTrack().isNull() ||
123  links->globalTrack().isNull() )
124  {
125  edm::LogWarning(theCategory) << "Global muon links to constituent tracks are invalid. There should be no such object. Muon is skipped.";
126  continue;
127  }
128  if (links->globalTrack() == glbRef) {
129  staTrack = !links->standAloneTrack().isNull() ? links->standAloneTrack() : reco::TrackRef();
130  TrackCand staCand = TrackCand((Trajectory*)nullptr,links->standAloneTrack());
131  TrackCand tkCand = TrackCand((Trajectory*)nullptr,links->trackerTrack());
132  chi2 = theGlbMatcher->match(staCand,tkCand,0,0);
133  d = theGlbMatcher->match(staCand,tkCand,1,0);
134  Rpos = theGlbMatcher->match(staCand,tkCand,2,0);
135  dist = theGlbMatcher->match(staCand,tkCand,3,0);
136  passTight = theGlbMatcher->matchTight(staCand,tkCand);
137  }
138  }
139  }
140 
141  if(!staTrack.isNull()) LogTrace(theCategory)<<"GLBQual: Used UpdatedAtVtx : " << (iEvent.getProvenance(staTrack.id()).productInstanceName() == std::string("UpdatedAtVtx"));
142 
143  float maxFloat01 = std::numeric_limits<float>::max()*0.1; // a better solution would be to use float above .. m/be not
144  reco::MuonQuality muQual;
145  if(!staTrack.isNull()) muQual.updatedSta = iEvent.getProvenance(staTrack.id()).productInstanceName() == std::string("UpdatedAtVtx");
146  muQual.trkKink = thisKink.first > maxFloat01 ? maxFloat01 : thisKink.first;
147  muQual.glbKink = thisKink.second > maxFloat01 ? maxFloat01 : thisKink.second;
148  muQual.trkRelChi2 = relative_tracker_chi2 > maxFloat01 ? maxFloat01 : relative_tracker_chi2;
149  muQual.staRelChi2 = relative_muon_chi2 > maxFloat01 ? maxFloat01 : relative_muon_chi2;
150  muQual.tightMatch = passTight;
151  muQual.chi2LocalPosition = dist;
152  muQual.chi2LocalMomentum = chi2;
153  muQual.localDistance = d;
154  muQual.globalDeltaEtaPhi = Rpos;
155  muQual.glbTrackProbability = glbTrackProbability;
156  valuesQual.push_back(muQual);
157  }
158 
159  /*
160  for(int i = 0; i < valuesTkRelChi2.size(); i++) {
161  LogTrace(theCategory)<<"value " << valuesTkRelChi2[i] ;
162  }
163  */
164 
165  // create and fill value maps
166  auto outQual = std::make_unique<edm::ValueMap<reco::MuonQuality>>();
167  edm::ValueMap<reco::MuonQuality>::Filler fillerQual(*outQual);
168  fillerQual.insert(glbMuons, valuesQual.begin(), valuesQual.end());
169  fillerQual.fill();
170 
171  // put value map into event
172  iEvent.put(std::move(outQual));
173 }
float chi2LocalPosition
chi2 value for the STA-TK matching of local position
Definition: MuonQuality.h:19
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:136
float chi2LocalMomentum
chi2 value for the STA-TK matching of local momentum
Definition: MuonQuality.h:21
std::pair< const Trajectory *, reco::TrackRef > TrackCand
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
bool updatedSta
bool returns true if standAloneMuon_updatedAtVtx was used in the fit
Definition: MuonQuality.h:9
float glbKink
value of the kink algorithm applied to the global track
Definition: MuonQuality.h:13
edm::EDGetTokenT< reco::TrackCollection > glbMuonsToken
bool matchTight(const TrackCand &sta, const TrackCand &track) const
check if two tracks are compatible (less than Chi2Cut, DeltaDCut, DeltaRCut)
float glbTrackProbability
the tail probability (-ln(P)) of the global fit
Definition: MuonQuality.h:29
void setServices(const edm::EventSetup &)
set the services needed by the TrackTransformer
float trkKink
value of the kink algorithm applied to the inner track stub
Definition: MuonQuality.h:11
float trkRelChi2
chi2 value for the inner track stub with respect to the global track
Definition: MuonQuality.h:15
virtual std::pair< double, double > newChi2(Trajectory &muon) const
ProductID id() const
Accessor for product ID.
Definition: Ref.h:259
virtual double trackProbability(Trajectory &track) const
virtual std::pair< double, double > kink(Trajectory &muon) const
bool tightMatch
if the STA-TK matching passed the tighter matching criteria
Definition: MuonQuality.h:27
float globalDeltaEtaPhi
global delta-Eta-Phi of STA-TK matching
Definition: MuonQuality.h:25
double match(const TrackCand &sta, const TrackCand &track, int matchOption=0, int surfaceOption=1) const
bool isValid() const
Definition: HandleBase.h:74
bool isNull() const
Checks for null.
Definition: Ref.h:250
#define LogTrace(id)
virtual void setEvent(const edm::Event &)
pass the Event to the algo at each event
float staRelChi2
chi2 value for the outer track stub with respect to the global track
Definition: MuonQuality.h:17
const T & get() const
Definition: EventSetup.h:59
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:20
edm::EDGetTokenT< reco::MuonTrackLinksCollection > linkCollectionToken
float localDistance
local distance seperation for STA-TK TSOS matching on same surface
Definition: MuonQuality.h:23
GlobalMuonTrackMatcher * theGlbMatcher
Provenance getProvenance(BranchID const &theID) const
Definition: Event.cc:129
T const * product() const
Definition: ESHandle.h:86
std::vector< Trajectory > refit(const reco::Track &globalTrack, const int theMuonHitsOption, const TrackerTopology *tTopo) const
build combined trajectory from sta Track and tracker RecHits
def move(src, dest)
Definition: eostools.py:510
double GlobalTrackQualityProducer::trackProbability ( Trajectory track) const
privatevirtual

Definition at line 302 of file GlobalTrackQualityProducer.cc.

References Trajectory::chiSquared(), LnChiSquaredProbability(), and Trajectory::ndof().

Referenced by produce().

302  {
303 
304  if ( track.ndof() > 0 && track.chiSquared() > 0 ) {
305  return -LnChiSquaredProbability(track.chiSquared(), track.ndof());
306  } else {
307  return 0.0;
308  }
309 
310 }
float LnChiSquaredProbability(double chiSquared, double nrDOF)
int ndof(bool bon=true) const
Definition: Trajectory.cc:102
float chiSquared() const
Definition: Trajectory.h:262

Member Data Documentation

edm::EDGetTokenT<reco::TrackCollection> GlobalTrackQualityProducer::glbMuonsToken
private

Definition at line 41 of file GlobalTrackQualityProducer.h.

Referenced by GlobalTrackQualityProducer(), and produce().

edm::InputTag GlobalTrackQualityProducer::inputCollection_
private

Definition at line 39 of file GlobalTrackQualityProducer.h.

Referenced by GlobalTrackQualityProducer().

edm::InputTag GlobalTrackQualityProducer::inputLinksCollection_
private

Definition at line 40 of file GlobalTrackQualityProducer.h.

Referenced by GlobalTrackQualityProducer().

edm::EDGetTokenT<reco::MuonTrackLinksCollection> GlobalTrackQualityProducer::linkCollectionToken
private

Definition at line 42 of file GlobalTrackQualityProducer.h.

Referenced by GlobalTrackQualityProducer(), and produce().

MeasurementEstimator* GlobalTrackQualityProducer::theEstimator
private
GlobalMuonTrackMatcher* GlobalTrackQualityProducer::theGlbMatcher
private
GlobalMuonRefitter* GlobalTrackQualityProducer::theGlbRefitter
private
MuonServiceProxy* GlobalTrackQualityProducer::theService
private