CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
GlobalTrackQualityProducer Class Reference

#include <GlobalTrackQualityProducer.h>

Inheritance diagram for GlobalTrackQualityProducer:
edm::EDProducer edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 GlobalTrackQualityProducer (const edm::ParameterSet &iConfig)
 
virtual ~GlobalTrackQualityProducer ()
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
virtual ~EDProducer ()
 
- Public Member Functions inherited from edm::ProducerBase
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription
const &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 
- Public Member Functions inherited from edm::EDConsumerBase
 EDConsumerBase ()
 
ProductHolderIndex indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndex > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndex > &) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Private Member Functions

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

Private Attributes

edm::InputTag inputCollection_
 
edm::InputTag inputLinksCollection_
 
MeasurementEstimatortheEstimator
 
GlobalMuonTrackMatchertheGlbMatcher
 
GlobalMuonRefittertheGlbRefitter
 
MuonServiceProxytheService
 

Additional Inherited Members

- Public Types inherited from edm::EDProducer
typedef EDProducer ModuleType
 
typedef WorkerT< EDProducerWorkerType
 
- Public Types inherited from edm::ProducerBase
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 
- Static Public Member Functions inherited from edm::EDProducer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDProducer
CurrentProcessingContext const * currentContext () const
 
- Protected Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Definition at line 26 of file GlobalTrackQualityProducer.h.

Constructor & Destructor Documentation

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

Definition at line 32 of file GlobalTrackQualityProducer.cc.

References Chi2MeasurementEstimatorESProducer_cfi::Chi2MeasurementEstimator, edm::ParameterSet::getParameter(), GlobalMuonRefitter_cff::GlobalMuonRefitter, GlobalMuonTrackMatcher_cff::GlobalMuonTrackMatcher, MuonServiceProxy_cff::MuonServiceProxy, theEstimator, theGlbMatcher, theGlbRefitter, and theService.

32  :
33  inputCollection_(iConfig.getParameter<edm::InputTag>("InputCollection")),inputLinksCollection_(iConfig.getParameter<edm::InputTag>("InputLinksCollection")),theService(0),theGlbRefitter(0),theGlbMatcher(0)
34 {
35  // service parameters
36  edm::ParameterSet serviceParameters = iConfig.getParameter<edm::ParameterSet>("ServiceParameters");
37  theService = new MuonServiceProxy(serviceParameters);
38 
39  // TrackRefitter parameters
40  edm::ParameterSet refitterParameters = iConfig.getParameter<edm::ParameterSet>("RefitterParameters");
41  theGlbRefitter = new GlobalMuonRefitter(refitterParameters, theService);
42 
43  edm::ParameterSet trackMatcherPSet = iConfig.getParameter<edm::ParameterSet>("GlobalMuonTrackMatcher");
44  theGlbMatcher = new GlobalMuonTrackMatcher(trackMatcherPSet,theService);
45 
46  double maxChi2 = iConfig.getParameter<double>("MaxChi2");
47  double nSigma = iConfig.getParameter<double>("nSigma");
48  theEstimator = new Chi2MeasurementEstimator(maxChi2,nSigma);
49 
50  produces<edm::ValueMap<reco::MuonQuality> >();
51 }
T getParameter(std::string const &) const
GlobalMuonTrackMatcher * theGlbMatcher
GlobalTrackQualityProducer::~GlobalTrackQualityProducer ( )
virtual

Definition at line 53 of file GlobalTrackQualityProducer.cc.

References theEstimator, theGlbMatcher, theGlbRefitter, and theService.

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

Member Function Documentation

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

Definition at line 176 of file GlobalTrackQualityProducer.cc.

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

Referenced by produce().

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

Definition at line 245 of file GlobalTrackQualityProducer.cc.

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

Referenced by produce().

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

Implements edm::EDProducer.

Definition at line 61 of file GlobalTrackQualityProducer.cc.

References reco::MuonQuality::chi2LocalMomentum, reco::MuonQuality::chi2LocalPosition, MuonServiceProxy::eventSetup(), edm::helper::Filler< Map >::fill(), edm::EventSetup::get(), edm::Event::getByLabel(), edm::Event::getProvenance(), reco::MuonQuality::glbKink, reco::MuonQuality::glbTrackProbability, reco::MuonQuality::globalDeltaEtaPhi, edm::Ref< C, T, F >::id(), inputCollection_, inputLinksCollection_, edm::helper::Filler< Map >::insert(), edm::Ref< C, T, F >::isNull(), edm::HandleBase::isValid(), kink(), electronStore::links, reco::MuonQuality::localDistance, LogTrace, GlobalMuonTrackMatcher::match(), GlobalMuonTrackMatcher::matchTight(), max(), newChi2(), edm::ESHandle< class >::product(), edm::Event::put(), GlobalMuonRefitter::refit(), GlobalMuonRefitter::setEvent(), GlobalMuonRefitter::setServices(), reco::MuonQuality::staRelChi2, AlCaHLTBitMon_QueryRunRegistry::string, theGlbMatcher, theGlbRefitter, theService, reco::MuonQuality::tightMatch, trackProbability(), reco::MuonQuality::trkKink, reco::MuonQuality::trkRelChi2, MuonServiceProxy::update(), and reco::MuonQuality::updatedSta.

62 {
63  const std::string theCategory = "Muon|RecoMuon|GlobalTrackQualityProducer";
64 
65  theService->update(iSetup);
66 
67  theGlbRefitter->setEvent(iEvent);
68 
69  theGlbRefitter->setServices(theService->eventSetup());
70 
71  // Take the GLB muon container(s)
73  iEvent.getByLabel(inputCollection_,glbMuons);
74 
76  iEvent.getByLabel(inputLinksCollection_, linkCollectionHandle);
77 
78  //Retrieve tracker topology from geometry
80  iSetup.get<IdealGeometryRecord>().get(tTopoHand);
81  const TrackerTopology *tTopo=tTopoHand.product();
82 
83 
84  // reserve some space
85  std::vector<reco::MuonQuality> valuesQual;
86  valuesQual.reserve(glbMuons->size());
87 
88  int trackIndex = 0;
89  for (reco::TrackCollection::const_iterator track = glbMuons->begin(); track!=glbMuons->end(); ++track , ++trackIndex) {
90  reco::TrackRef glbRef(glbMuons,trackIndex);
91  reco::TrackRef staTrack = reco::TrackRef();
92 
93  std::vector<Trajectory> refitted=theGlbRefitter->refit(*track,1,tTopo);
94 
95  LogTrace(theCategory)<<"GLBQual N refitted " << refitted.size();
96 
97  std::pair<double,double> thisKink;
98  double relative_muon_chi2 = 0.0;
99  double relative_tracker_chi2 = 0.0;
100  double glbTrackProbability = 0.0;
101  if(refitted.size()>0) {
102  thisKink = kink(refitted.front()) ;
103  std::pair<double,double> chi = newChi2(refitted.front());
104  relative_muon_chi2 = chi.second; //normalized inside to /sum(muHits.dimension)
105  relative_tracker_chi2 = chi.first; //normalized inside to /sum(tkHits.dimension)
106  glbTrackProbability = trackProbability(refitted.front());
107  }
108 
109  LogTrace(theCategory)<<"GLBQual: Kink " << thisKink.first << " " << thisKink.second;
110  LogTrace(theCategory)<<"GLBQual: Rel Chi2 " << relative_tracker_chi2 << " " << relative_muon_chi2;
111  LogTrace(theCategory)<<"GLBQual: trackProbability " << glbTrackProbability;
112 
113  // Fill the STA-TK match information
114  float chi2, d, dist, Rpos;
115  chi2 = d = dist = Rpos = -1.0;
116  bool passTight = false;
117  typedef MuonTrajectoryBuilder::TrackCand TrackCand;
118  if ( linkCollectionHandle.isValid() ) {
119  for ( reco::MuonTrackLinksCollection::const_iterator links = linkCollectionHandle->begin();
120  links != linkCollectionHandle->end(); ++links )
121  {
122  if ( links->trackerTrack().isNull() ||
123  links->standAloneTrack().isNull() ||
124  links->globalTrack().isNull() )
125  {
126  edm::LogWarning(theCategory) << "Global muon links to constituent tracks are invalid. There should be no such object. Muon is skipped.";
127  continue;
128  }
129  if (links->globalTrack() == glbRef) {
130  staTrack = !links->standAloneTrack().isNull() ? links->standAloneTrack() : reco::TrackRef();
131  TrackCand staCand = TrackCand((Trajectory*)(0),links->standAloneTrack());
132  TrackCand tkCand = TrackCand((Trajectory*)(0),links->trackerTrack());
133  chi2 = theGlbMatcher->match(staCand,tkCand,0,0);
134  d = theGlbMatcher->match(staCand,tkCand,1,0);
135  Rpos = theGlbMatcher->match(staCand,tkCand,2,0);
136  dist = theGlbMatcher->match(staCand,tkCand,3,0);
137  passTight = theGlbMatcher->matchTight(staCand,tkCand);
138  }
139  }
140  }
141 
142  if(!staTrack.isNull()) LogTrace(theCategory)<<"GLBQual: Used UpdatedAtVtx : " << (iEvent.getProvenance(staTrack.id()).productInstanceName() == std::string("UpdatedAtVtx"));
143 
144  float maxFloat01 = std::numeric_limits<float>::max()*0.1; // a better solution would be to use float above .. m/be not
145  reco::MuonQuality muQual;
146  if(!staTrack.isNull()) muQual.updatedSta = iEvent.getProvenance(staTrack.id()).productInstanceName() == std::string("UpdatedAtVtx");
147  muQual.trkKink = thisKink.first > maxFloat01 ? maxFloat01 : thisKink.first;
148  muQual.glbKink = thisKink.second > maxFloat01 ? maxFloat01 : thisKink.second;
149  muQual.trkRelChi2 = relative_tracker_chi2 > maxFloat01 ? maxFloat01 : relative_tracker_chi2;
150  muQual.staRelChi2 = relative_muon_chi2 > maxFloat01 ? maxFloat01 : relative_muon_chi2;
151  muQual.tightMatch = passTight;
152  muQual.chi2LocalPosition = dist;
153  muQual.chi2LocalMomentum = chi2;
154  muQual.localDistance = d;
155  muQual.globalDeltaEtaPhi = Rpos;
156  muQual.glbTrackProbability = glbTrackProbability;
157  valuesQual.push_back(muQual);
158  }
159 
160  /*
161  for(int i = 0; i < valuesTkRelChi2.size(); i++) {
162  LogTrace(theCategory)<<"value " << valuesTkRelChi2[i] ;
163  }
164  */
165 
166  // create and fill value maps
167  std::auto_ptr<edm::ValueMap<reco::MuonQuality> > outQual(new edm::ValueMap<reco::MuonQuality>());
168  edm::ValueMap<reco::MuonQuality>::Filler fillerQual(*outQual);
169  fillerQual.insert(glbMuons, valuesQual.begin(), valuesQual.end());
170  fillerQual.fill();
171 
172  // put value map into event
173  iEvent.put(outQual);
174 }
float chi2LocalPosition
chi2 value for the STA-TK matching of local position
Definition: MuonQuality.h:19
float chi2LocalMomentum
chi2 value for the STA-TK matching of local momentum
Definition: MuonQuality.h:21
std::pair< const Trajectory *, reco::TrackRef > TrackCand
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
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
virtual double trackProbability(Trajectory &track) const
virtual std::pair< double, double > kink(Trajectory &muon) const
bool isNull() const
Checks for null.
Definition: Ref.h:247
bool tightMatch
if the STA-TK matching passed the tighter matching criteria
Definition: MuonQuality.h:27
const T & max(const T &a, const T &b)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:94
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:76
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
#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:55
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:14
T const * product() const
Definition: ESHandle.h:62
float localDistance
local distance seperation for STA-TK TSOS matching on same surface
Definition: MuonQuality.h:23
GlobalMuonTrackMatcher * theGlbMatcher
ProductID id() const
Accessor for product ID.
Definition: Ref.h:256
Provenance getProvenance(BranchID const &theID) const
Definition: Event.cc:68
std::vector< Trajectory > refit(const reco::Track &globalTrack, const int theMuonHitsOption, const TrackerTopology *tTopo) const
build combined trajectory from sta Track and tracker RecHits
double GlobalTrackQualityProducer::trackProbability ( Trajectory track) const
privatevirtual

Definition at line 301 of file GlobalTrackQualityProducer.cc.

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

Referenced by produce().

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

Member Data Documentation

edm::InputTag GlobalTrackQualityProducer::inputCollection_
private

Definition at line 38 of file GlobalTrackQualityProducer.h.

Referenced by produce().

edm::InputTag GlobalTrackQualityProducer::inputLinksCollection_
private

Definition at line 39 of file GlobalTrackQualityProducer.h.

Referenced by produce().

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