CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MuonIdProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: MuonIdentification
4 // Class: MuonIdProducer
5 //
6 //
7 // Original Author: Dmytro Kovalskyi
8 // $Id: MuonIdProducer.cc,v 1.59 2010/07/04 16:48:41 slava77 Exp $
9 //
10 //
11 
12 
13 // system include files
14 #include <memory>
15 
16 // user include files
19 
22 
24 
34 
37 
38 #include <boost/regex.hpp>
43 
46 
47 #include <algorithm>
48 
53 
55 
57 muIsoExtractorCalo_(0),muIsoExtractorTrack_(0),muIsoExtractorJet_(0)
58 {
59  produces<reco::MuonCollection>();
60  produces<reco::CaloMuonCollection>();
61  produces<reco::MuonTimeExtraMap>("combined");
62  produces<reco::MuonTimeExtraMap>("dt");
63  produces<reco::MuonTimeExtraMap>("csc");
64 
65  minPt_ = iConfig.getParameter<double>("minPt");
66  minP_ = iConfig.getParameter<double>("minP");
67  minPCaloMuon_ = iConfig.getParameter<double>("minPCaloMuon");
68  minNumberOfMatches_ = iConfig.getParameter<int>("minNumberOfMatches");
69  addExtraSoftMuons_ = iConfig.getParameter<bool>("addExtraSoftMuons");
70  maxAbsEta_ = iConfig.getParameter<double>("maxAbsEta");
71  maxAbsDx_ = iConfig.getParameter<double>("maxAbsDx");
72  maxAbsPullX_ = iConfig.getParameter<double>("maxAbsPullX");
73  maxAbsDy_ = iConfig.getParameter<double>("maxAbsDy");
74  maxAbsPullY_ = iConfig.getParameter<double>("maxAbsPullY");
75  fillCaloCompatibility_ = iConfig.getParameter<bool>("fillCaloCompatibility");
76  fillEnergy_ = iConfig.getParameter<bool>("fillEnergy");
77  fillMatching_ = iConfig.getParameter<bool>("fillMatching");
78  fillIsolation_ = iConfig.getParameter<bool>("fillIsolation");
79  writeIsoDeposits_ = iConfig.getParameter<bool>("writeIsoDeposits");
80  fillGlobalTrackQuality_ = iConfig.getParameter<bool>("fillGlobalTrackQuality");
81  ptThresholdToFillCandidateP4WithGlobalFit_ = iConfig.getParameter<double>("ptThresholdToFillCandidateP4WithGlobalFit");
82  sigmaThresholdToFillCandidateP4WithGlobalFit_ = iConfig.getParameter<double>("sigmaThresholdToFillCandidateP4WithGlobalFit");
83  caloCut_ = iConfig.getParameter<double>("minCaloCompatibility"); //CaloMuons
84  arbClean_ = iConfig.getParameter<bool>("runArbitrationCleaner"); // muon mesh
85 
86  // Load TrackDetectorAssociator parameters
87  edm::ParameterSet parameters = iConfig.getParameter<edm::ParameterSet>("TrackAssociatorParameters");
88  parameters_.loadParameters( parameters );
89 
90  // Load parameters for the TimingFiller
91  edm::ParameterSet timingParameters = iConfig.getParameter<edm::ParameterSet>("TimingFillerParameters");
92  theTimingFiller_ = new MuonTimingFiller(timingParameters);
93 
94  if (fillCaloCompatibility_){
95  // Load MuonCaloCompatibility parameters
96  parameters = iConfig.getParameter<edm::ParameterSet>("MuonCaloCompatibility");
97  muonCaloCompatibility_.configure( parameters );
98  }
99 
100  if (fillIsolation_){
101  // Load MuIsoExtractor parameters
102  edm::ParameterSet caloExtractorPSet = iConfig.getParameter<edm::ParameterSet>("CaloExtractorPSet");
103  std::string caloExtractorName = caloExtractorPSet.getParameter<std::string>("ComponentName");
104  muIsoExtractorCalo_ = IsoDepositExtractorFactory::get()->create( caloExtractorName, caloExtractorPSet);
105 
106  edm::ParameterSet trackExtractorPSet = iConfig.getParameter<edm::ParameterSet>("TrackExtractorPSet");
107  std::string trackExtractorName = trackExtractorPSet.getParameter<std::string>("ComponentName");
108  muIsoExtractorTrack_ = IsoDepositExtractorFactory::get()->create( trackExtractorName, trackExtractorPSet);
109 
110  edm::ParameterSet jetExtractorPSet = iConfig.getParameter<edm::ParameterSet>("JetExtractorPSet");
111  std::string jetExtractorName = jetExtractorPSet.getParameter<std::string>("ComponentName");
112  muIsoExtractorJet_ = IsoDepositExtractorFactory::get()->create( jetExtractorName, jetExtractorPSet);
113  }
114  if (fillIsolation_ && writeIsoDeposits_){
115  trackDepositName_ = iConfig.getParameter<std::string>("trackDepositName");
116  produces<reco::IsoDepositMap>(trackDepositName_);
117  ecalDepositName_ = iConfig.getParameter<std::string>("ecalDepositName");
118  produces<reco::IsoDepositMap>(ecalDepositName_);
119  hcalDepositName_ = iConfig.getParameter<std::string>("hcalDepositName");
120  produces<reco::IsoDepositMap>(hcalDepositName_);
121  hoDepositName_ = iConfig.getParameter<std::string>("hoDepositName");
122  produces<reco::IsoDepositMap>(hoDepositName_);
123  jetDepositName_ = iConfig.getParameter<std::string>("jetDepositName");
124  produces<reco::IsoDepositMap>(jetDepositName_);
125  }
126 
127  inputCollectionLabels_ = iConfig.getParameter<std::vector<edm::InputTag> >("inputCollectionLabels");
128  inputCollectionTypes_ = iConfig.getParameter<std::vector<std::string> >("inputCollectionTypes");
129  if (inputCollectionLabels_.size() != inputCollectionTypes_.size())
130  throw cms::Exception("ConfigurationError") << "Number of input collection labels is different from number of types. " <<
131  "For each collection label there should be exactly one collection type specified.";
132  if (inputCollectionLabels_.size()>4 ||inputCollectionLabels_.empty())
133  throw cms::Exception("ConfigurationError") << "Number of input collections should be from 1 to 4.";
134 
135  debugWithTruthMatching_ = iConfig.getParameter<bool>("debugWithTruthMatching");
136  if (debugWithTruthMatching_) edm::LogWarning("MuonIdentification")
137  << "========================================================================\n"
138  << "Debugging mode with truth matching is turned on!!! Make sure you understand what you are doing!\n"
139  << "========================================================================\n";
140  if (fillGlobalTrackQuality_){
141  globalTrackQualityInputTag_ = iConfig.getParameter<edm::InputTag>("globalTrackQualityInputTag");
142  }
143 
144  //create mesh holder
145  meshAlgo_ = new MuonMesh(iConfig.getParameter<edm::ParameterSet>("arbitrationCleanerOptions"));
146 }
147 
148 
150 {
155  if (meshAlgo_) delete meshAlgo_;
156  // TimingReport::current()->dump(std::cout);
157 }
158 
160 {
161  // TimerStack timers;
162  // timers.push("MuonIdProducer::produce::init");
163 
168 
169  // timers.push("MuonIdProducer::produce::init::getPropagator");
171  iSetup.get<TrackingComponentsRecord>().get("SteppingHelixPropagatorAny", propagator);
172  trackAssociator_.setPropagator(propagator.product());
173 
174  // timers.pop_and_push("MuonIdProducer::produce::init::getInputCollections");
175  for ( unsigned int i = 0; i < inputCollectionLabels_.size(); ++i ) {
176  if ( inputCollectionTypes_[i] == "inner tracks" ) {
179  throw cms::Exception("FatalError") << "Failed to get input track collection with label: " << inputCollectionLabels_[i];
180  LogTrace("MuonIdentification") << "Number of input inner tracks: " << innerTrackCollectionHandle_->size();
181  continue;
182  }
183  if ( inputCollectionTypes_[i] == "outer tracks" ) {
186  throw cms::Exception("FatalError") << "Failed to get input track collection with label: " << inputCollectionLabels_[i];
187  LogTrace("MuonIdentification") << "Number of input outer tracks: " << outerTrackCollectionHandle_->size();
188  continue;
189  }
190  if ( inputCollectionTypes_[i] == "links" ) {
193  throw cms::Exception("FatalError") << "Failed to get input link collection with label: " << inputCollectionLabels_[i];
194  LogTrace("MuonIdentification") << "Number of input links: " << linkCollectionHandle_->size();
195  continue;
196  }
197  if ( inputCollectionTypes_[i] == "muons" ) {
200  throw cms::Exception("FatalError") << "Failed to get input muon collection with label: " << inputCollectionLabels_[i];
201  LogTrace("MuonIdentification") << "Number of input muons: " << muonCollectionHandle_->size();
202  continue;
203  }
204  throw cms::Exception("FatalError") << "Unknown input collection type: " << inputCollectionTypes_[i];
205  }
206 }
207 
210 {
211  LogTrace("MuonIdentification") << "Creating a muon from a track " << track.get()->pt() <<
212  " Pt (GeV), eta: " << track.get()->eta();
213  reco::Muon aMuon( makeMuon( *(track.get()) ) );
214  switch (type) {
215  case InnerTrack:
216  aMuon.setInnerTrack( track );
217  break;
218  case OuterTrack:
219  aMuon.setOuterTrack( track );
220  break;
221  case CombinedTrack:
222  aMuon.setGlobalTrack( track );
223  break;
224  }
225  return aMuon;
226 }
227 
228 
230 {
231  reco::CaloMuon aMuon;
232  aMuon.setInnerTrack( muon.innerTrack() );
233 
234  if (muon.isEnergyValid()) aMuon.setCalEnergy( muon.calEnergy() );
235  // get calo compatibility
237  return aMuon;
238 }
239 
240 
242 {
243  LogTrace("MuonIdentification") << "Creating a muon from a link to tracks object";
244  reco::Muon aMuon;
247  ( fabs(links.trackerTrack()->qoverp()-links.globalTrack()->qoverp()) <
249  aMuon = makeMuon( *(links.globalTrack()) );
250  else
251  aMuon = makeMuon( *(links.trackerTrack()) );
252 
253  aMuon.setInnerTrack( links.trackerTrack() );
254  aMuon.setOuterTrack( links.standAloneTrack() );
255  aMuon.setGlobalTrack( links.globalTrack() );
256  return aMuon;
257 }
258 
260 {
261  // Pt and absolute momentum requirement
262  if (track.pt() < minPt_ || (track.p() < minP_ && track.p() < minPCaloMuon_)){
263  LogTrace("MuonIdentification") << "Skipped low momentum track (Pt,P): " << track.pt() <<
264  ", " << track.p() << " GeV";
265  return false;
266  }
267 
268  // Eta requirement
269  if ( fabs(track.eta()) > maxAbsEta_ ){
270  LogTrace("MuonIdentification") << "Skipped track with large pseudo rapidity (Eta: " << track.eta() << " )";
271  return false;
272  }
273  return true;
274 }
275 
276 unsigned int MuonIdProducer::chamberId( const DetId& id )
277 {
278  switch ( id.det() ) {
279  case DetId::Muon:
280  switch ( id.subdetId() ) {
281  case MuonSubdetId::DT:
282  {
283  DTChamberId detId(id.rawId());
284  return detId.rawId();
285  }
286  break;
287  case MuonSubdetId::CSC:
288  {
289  CSCDetId detId(id.rawId());
290  return detId.chamberId().rawId();
291  }
292  break;
293  default:
294  return 0;
295  }
296  default:
297  return 0;
298  }
299  return 0;
300 }
301 
302 
304 {
305  int numberOfCommonDetIds = 0;
306  if ( ! muon.isMatchesValid() ||
307  track.extra().isNull() ||
308  track.extra()->recHits().isNull() ) return numberOfCommonDetIds;
309  const std::vector<reco::MuonChamberMatch>& matches( muon.matches() );
310  for ( std::vector<reco::MuonChamberMatch>::const_iterator match = matches.begin();
311  match != matches.end(); ++match )
312  {
313  if ( match->segmentMatches.empty() ) continue;
314  bool foundCommonDetId = false;
315 
316  for ( TrackingRecHitRefVector::const_iterator hit = track.extra()->recHitsBegin();
317  hit != track.extra()->recHitsEnd(); ++hit )
318  {
319  // LogTrace("MuonIdentification") << "hit DetId: " << std::hex << hit->get()->geographicalId().rawId() <<
320  // "\t hit chamber DetId: " << getChamberId(hit->get()->geographicalId()) <<
321  // "\t segment DetId: " << match->id.rawId() << std::dec;
322 
323  if ( chamberId(hit->get()->geographicalId()) == match->id.rawId() ) {
324  foundCommonDetId = true;
325  break;
326  }
327  }
328  if ( foundCommonDetId ) {
329  numberOfCommonDetIds++;
330  break;
331  }
332  }
333  return numberOfCommonDetIds;
334 }
335 
337 {
338  edm::ESHandle<CSCGeometry> geomHandle;
339  iSetup.get<MuonGeometryRecord>().get(geomHandle);
340 
341  meshAlgo_->setCSCGeometry(geomHandle.product());
342 
343 }
344 
346  const reco::MuonTrackLinks& badMuon )
347 {
348  if ( std::min(goodMuon.globalTrack()->hitPattern().numberOfValidMuonHits(),
349  badMuon.globalTrack()->hitPattern().numberOfValidMuonHits()) > 10 ){
350  if ( goodMuon.globalTrack()->normalizedChi2() >
351  badMuon.globalTrack()->normalizedChi2() )
352  return false;
353  else
354  return true;
355  }
356  if ( goodMuon.globalTrack()->hitPattern().numberOfValidMuonHits() <
357  badMuon.globalTrack()->hitPattern().numberOfValidMuonHits() ) return false;
358  return true;
359 }
360 
362 {
363  // TimerStack timers;
364  // timers.push("MuonIdProducer::produce");
365 
366  std::auto_ptr<reco::MuonCollection> outputMuons(new reco::MuonCollection);
367  std::auto_ptr<reco::CaloMuonCollection> caloMuons( new reco::CaloMuonCollection );
368 
369  init(iEvent, iSetup);
370 
371  std::auto_ptr<reco::MuonTimeExtraMap> muonTimeMap(new reco::MuonTimeExtraMap());
372  reco::MuonTimeExtraMap::Filler filler(*muonTimeMap);
373  std::auto_ptr<reco::MuonTimeExtraMap> muonTimeMapDT(new reco::MuonTimeExtraMap());
374  reco::MuonTimeExtraMap::Filler fillerDT(*muonTimeMapDT);
375  std::auto_ptr<reco::MuonTimeExtraMap> muonTimeMapCSC(new reco::MuonTimeExtraMap());
376  reco::MuonTimeExtraMap::Filler fillerCSC(*muonTimeMapCSC);
377 
378  std::auto_ptr<reco::IsoDepositMap> trackDepMap(new reco::IsoDepositMap());
379  reco::IsoDepositMap::Filler trackDepFiller(*trackDepMap);
380  std::auto_ptr<reco::IsoDepositMap> ecalDepMap(new reco::IsoDepositMap());
381  reco::IsoDepositMap::Filler ecalDepFiller(*ecalDepMap);
382  std::auto_ptr<reco::IsoDepositMap> hcalDepMap(new reco::IsoDepositMap());
383  reco::IsoDepositMap::Filler hcalDepFiller(*hcalDepMap);
384  std::auto_ptr<reco::IsoDepositMap> hoDepMap(new reco::IsoDepositMap());
385  reco::IsoDepositMap::Filler hoDepFiller(*hoDepMap);
386  std::auto_ptr<reco::IsoDepositMap> jetDepMap(new reco::IsoDepositMap());
387  reco::IsoDepositMap::Filler jetDepFiller(*jetDepMap);
388 
389  // loop over input collections
390 
391  // muons first - no cleaning, take as is.
393  for ( reco::MuonCollection::const_iterator muon = muonCollectionHandle_->begin();
394  muon != muonCollectionHandle_->end(); ++muon )
395  outputMuons->push_back(*muon);
396 
397  // links second ( assume global muon type )
399  std::vector<bool> goodmuons(linkCollectionHandle_->size(),true);
400  if ( goodmuons.size()>1 ){
401  // check for shared tracker tracks
402  for ( unsigned int i=0; i<linkCollectionHandle_->size()-1; ++i ){
403  if (!checkLinks(&linkCollectionHandle_->at(i))) continue;
404  for ( unsigned int j=i+1; j<linkCollectionHandle_->size(); ++j ){
405  if (!checkLinks(&linkCollectionHandle_->at(j))) continue;
406  if ( linkCollectionHandle_->at(i).trackerTrack().isNonnull() &&
407  linkCollectionHandle_->at(i).trackerTrack() ==
408  linkCollectionHandle_->at(j).trackerTrack() )
409  {
410  // Tracker track is the essential part that dominates muon resolution
411  // so taking either muon is fine. All that is important is to preserve
412  // the muon identification information. If number of hits is small,
413  // keep the one with large number of hits, otherwise take the smalest chi2/ndof
415  goodmuons[j] = false;
416  else
417  goodmuons[i] = false;
418  }
419  }
420  }
421  // check for shared stand-alone muons.
422  for ( unsigned int i=0; i<linkCollectionHandle_->size()-1; ++i ){
423  if ( !goodmuons[i] ) continue;
424  if (!checkLinks(&linkCollectionHandle_->at(i))) continue;
425  for ( unsigned int j=i+1; j<linkCollectionHandle_->size(); ++j ){
426  if ( !goodmuons[j] ) continue;
427  if (!checkLinks(&linkCollectionHandle_->at(j))) continue;
428  if ( linkCollectionHandle_->at(i).standAloneTrack().isNonnull() &&
429  linkCollectionHandle_->at(i).standAloneTrack() ==
430  linkCollectionHandle_->at(j).standAloneTrack() )
431  {
433  goodmuons[j] = false;
434  else
435  goodmuons[i] = false;
436  }
437  }
438  }
439  }
440 
441  for ( unsigned int i=0; i<linkCollectionHandle_->size(); ++i ){
442  if ( !goodmuons[i] ) continue;
443  const reco::MuonTrackLinks* links = &linkCollectionHandle_->at(i);
444  if ( ! checkLinks(links)) continue;
445  // check if this muon is already in the list
446  bool newMuon = true;
447  for ( reco::MuonCollection::const_iterator muon = outputMuons->begin();
448  muon != outputMuons->end(); ++muon )
449  if ( muon->track() == links->trackerTrack() &&
450  muon->standAloneMuon() == links->standAloneTrack() &&
451  muon->combinedMuon() == links->globalTrack() )
452  newMuon = false;
453  if ( newMuon ) {
454  outputMuons->push_back( makeMuon( *links ) );
455  outputMuons->back().setType(reco::Muon::GlobalMuon | reco::Muon::StandAloneMuon);
456  }
457  }
458  }
459 
460  // tracker and calo muons are next
462  LogTrace("MuonIdentification") << "Creating tracker muons";
463  for ( unsigned int i = 0; i < innerTrackCollectionHandle_->size(); ++i )
464  {
466  if ( ! isGoodTrack( track ) ) continue;
467  bool splitTrack = false;
468  if ( track.extra().isAvailable() &&
469  TrackDetectorAssociator::crossedIP( track ) ) splitTrack = true;
470  std::vector<TrackDetectorAssociator::Direction> directions;
471  if ( splitTrack ) {
472  directions.push_back(TrackDetectorAssociator::InsideOut);
473  directions.push_back(TrackDetectorAssociator::OutsideIn);
474  } else {
475  directions.push_back(TrackDetectorAssociator::Any);
476  }
477  for ( std::vector<TrackDetectorAssociator::Direction>::const_iterator direction = directions.begin();
478  direction != directions.end(); ++direction )
479  {
480  // make muon
481  // timers.push("MuonIdProducer::produce::fillMuonId");
483  trackerMuon.setType( reco::Muon::TrackerMuon );
484  fillMuonId(iEvent, iSetup, trackerMuon, *direction);
485  // timers.pop();
486 
487  if ( debugWithTruthMatching_ ) {
488  // add MC hits to a list of matched segments.
489  // Since it's debugging mode - code is slow
490  MuonIdTruthInfo::truthMatchMuon(iEvent, iSetup, trackerMuon);
491  }
492 
493  // check if this muon is already in the list
494  // have to check where muon hits are really located
495  // to match properly
496  bool newMuon = true;
497  bool goodTrackerMuon = isGoodTrackerMuon( trackerMuon );
498  for ( reco::MuonCollection::iterator muon = outputMuons->begin();
499  muon != outputMuons->end(); ++muon )
500  {
501  if ( muon->innerTrack().get() == trackerMuon.innerTrack().get() &&
503  phiOfMuonIneteractionRegion(trackerMuon)) > 0 )
504  {
505  newMuon = false;
506  muon->setMatches( trackerMuon.matches() );
507  if (trackerMuon.isTimeValid()) muon->setTime( trackerMuon.time() );
508  if (trackerMuon.isEnergyValid()) muon->setCalEnergy( trackerMuon.calEnergy() );
509  if (goodTrackerMuon) muon->setType( muon->type() | reco::Muon::TrackerMuon );
510  LogTrace("MuonIdentification") << "Found a corresponding global muon. Set energy, matches and move on";
511  break;
512  }
513  }
514  if ( newMuon ) {
515  if ( goodTrackerMuon ){
516  outputMuons->push_back( trackerMuon );
517  } else {
518  LogTrace("MuonIdentification") << "track failed minimal number of muon matches requirement";
519  const reco::CaloMuon& caloMuon = makeCaloMuon(trackerMuon);
520  if ( ! caloMuon.isCaloCompatibilityValid() || caloMuon.caloCompatibility() < caloCut_ || caloMuon.p() < minPCaloMuon_) continue;
521  caloMuons->push_back( caloMuon );
522  }
523  }
524  }
525  }
526  }
527 
528  // and at last the stand alone muons
530  LogTrace("MuonIdentification") << "Looking for new muons among stand alone muon tracks";
531  for ( unsigned int i = 0; i < outerTrackCollectionHandle_->size(); ++i )
532  {
533  // check if this muon is already in the list of global muons
534  bool newMuon = true;
535  for ( reco::MuonCollection::iterator muon = outputMuons->begin();
536  muon != outputMuons->end(); ++muon )
537  {
538  if ( ! muon->standAloneMuon().isNull() ) {
539  // global muon
540  if ( muon->standAloneMuon().get() == &(outerTrackCollectionHandle_->at(i)) ) {
541  newMuon = false;
542  break;
543  }
544  } else {
545  // tracker muon - no direct links to the standalone muon
546  // since we have only a few real muons in an event, matching
547  // the stand alone muon to the tracker muon by DetIds should
548  // be good enough for association. At the end it's up to a
549  // user to redefine the association and what it means. Here
550  // we would like to avoid obvious double counting and we
551  // tolerate a potential miss association
552  if ( overlap(*muon,outerTrackCollectionHandle_->at(i))>0 ) {
553  LogTrace("MuonIdentification") << "Found associated tracker muon. Set a reference and move on";
554  newMuon = false;
555  muon->setOuterTrack( reco::TrackRef( outerTrackCollectionHandle_, i ) );
556  muon->setType( muon->type() | reco::Muon::StandAloneMuon );
557  break;
558  }
559  }
560  }
561  if ( newMuon ) {
562  LogTrace("MuonIdentification") << "No associated stand alone track is found. Making a muon";
563  outputMuons->push_back( makeMuon(iEvent, iSetup,
565  outputMuons->back().setType( reco::Muon::StandAloneMuon );
566  }
567  }
568  }
569 
570  LogTrace("MuonIdentification") << "Dress up muons if it's necessary";
571 
572  int nMuons=outputMuons->size();
573 
574  std::vector<reco::MuonTimeExtra> dtTimeColl(nMuons);
575  std::vector<reco::MuonTimeExtra> cscTimeColl(nMuons);
576  std::vector<reco::MuonTimeExtra> combinedTimeColl(nMuons);
577  std::vector<reco::IsoDeposit> trackDepColl(nMuons);
578  std::vector<reco::IsoDeposit> ecalDepColl(nMuons);
579  std::vector<reco::IsoDeposit> hcalDepColl(nMuons);
580  std::vector<reco::IsoDeposit> hoDepColl(nMuons);
581  std::vector<reco::IsoDeposit> jetDepColl(nMuons);
582 
583  // Fill various information
584  unsigned int i=0;
585  for ( reco::MuonCollection::iterator muon = outputMuons->begin(); muon != outputMuons->end(); ++muon )
586  {
587  // Fill muonID
588  // timers.push("MuonIdProducer::produce::fillMuonId");
589  if ( ( fillMatching_ && ! muon->isMatchesValid() ) ||
590  ( fillEnergy_ && !muon->isEnergyValid() ) )
591  {
592  // predict direction based on the muon interaction region location
593  // if it's available
594  if ( muon->isStandAloneMuon() ) {
595  if ( cos(phiOfMuonIneteractionRegion(*muon) - muon->phi()) > 0 )
597  else
599  } else {
600  LogTrace("MuonIdentification") << "THIS SHOULD NEVER HAPPEN";
601  fillMuonId(iEvent, iSetup, *muon);
602  }
603  }
604 
606  // Fill global quality information
607  fillGlbQuality(iEvent, iSetup, *muon);
608  }
609  LogDebug("MuonIdentification");
610 
611  // timers.push("MuonIdProducer::produce::fillCaloCompatibility");
612  if ( fillCaloCompatibility_ ) muon->setCaloCompatibility( muonCaloCompatibility_.evaluate(*muon) );
613  // timers.pop();
614 
615  // timers.push("MuonIdProducer::produce::fillIsolation");
616  if ( fillIsolation_ ) fillMuonIsolation(iEvent, iSetup, *muon,
617  trackDepColl[i], ecalDepColl[i], hcalDepColl[i], hoDepColl[i], jetDepColl[i]);
618  // timers.pop();
619 
620  // fill timing information
621  reco::MuonTime muonTime;
622  reco::MuonTimeExtra dtTime;
623  reco::MuonTimeExtra cscTime;
624  reco::MuonTimeExtra combinedTime;
625 
626  theTimingFiller_->fillTiming(*muon, dtTime, cscTime, combinedTime, iEvent, iSetup);
627 
628  muonTime.nDof=combinedTime.nDof();
629  muonTime.timeAtIpInOut=combinedTime.timeAtIpInOut();
630  muonTime.timeAtIpInOutErr=combinedTime.timeAtIpInOutErr();
631  muonTime.timeAtIpOutIn=combinedTime.timeAtIpOutIn();
632  muonTime.timeAtIpOutInErr=combinedTime.timeAtIpOutInErr();
633 
634  muon->setTime( muonTime);
635  dtTimeColl[i] = dtTime;
636  cscTimeColl[i] = cscTime;
637  combinedTimeColl[i] = combinedTime;
638 
639  i++;
640 
641  }
642 
643  LogTrace("MuonIdentification") << "number of muons produced: " << outputMuons->size();
644  // timers.push("MuonIdProducer::produce::fillArbitration");
645  if ( fillMatching_ ) fillArbitrationInfo( outputMuons.get() );
646  // timers.pop();
647  edm::OrphanHandle<reco::MuonCollection> muonHandle = iEvent.put(outputMuons);
648 
649  filler.insert(muonHandle, combinedTimeColl.begin(), combinedTimeColl.end());
650  filler.fill();
651  fillerDT.insert(muonHandle, dtTimeColl.begin(), dtTimeColl.end());
652  fillerDT.fill();
653  fillerCSC.insert(muonHandle, cscTimeColl.begin(), cscTimeColl.end());
654  fillerCSC.fill();
655 
656  iEvent.put(muonTimeMap,"combined");
657  iEvent.put(muonTimeMapDT,"dt");
658  iEvent.put(muonTimeMapCSC,"csc");
659 
661  trackDepFiller.insert(muonHandle, trackDepColl.begin(), trackDepColl.end());
662  trackDepFiller.fill();
663  iEvent.put(trackDepMap, trackDepositName_);
664  ecalDepFiller.insert(muonHandle, ecalDepColl.begin(), ecalDepColl.end());
665  ecalDepFiller.fill();
666  iEvent.put(ecalDepMap, ecalDepositName_);
667  hcalDepFiller.insert(muonHandle, hcalDepColl.begin(), hcalDepColl.end());
668  hcalDepFiller.fill();
669  iEvent.put(hcalDepMap, hcalDepositName_);
670  hoDepFiller.insert(muonHandle, hoDepColl.begin(), hoDepColl.end());
671  hoDepFiller.fill();
672  iEvent.put(hoDepMap, hoDepositName_);
673  jetDepFiller.insert(muonHandle, jetDepColl.begin(), jetDepColl.end());
674  jetDepFiller.fill();
675  iEvent.put(jetDepMap, jetDepositName_);
676  }
677 
678  iEvent.put(caloMuons);
679 }
680 
681 
683 {
684  if(muon.track()->pt() < minPt_ || muon.track()->p() < minP_) return false;
685  if ( addExtraSoftMuons_ &&
686  muon.pt()<5 && fabs(muon.eta())<1.5 &&
687  muon.numberOfMatches( reco::Muon::NoArbitration ) >= 1 ) return true;
689 }
690 
692  reco::Muon& aMuon,
694 {
695  // perform track - detector association
696  const reco::Track* track = 0;
697  if ( ! aMuon.track().isNull() )
698  track = aMuon.track().get();
699  else
700  {
701  if ( ! aMuon.standAloneMuon().isNull() )
702  track = aMuon.standAloneMuon().get();
703  else
704  throw cms::Exception("FatalError") << "Failed to fill muon id information for a muon with undefined references to tracks";
705  }
706 
707  TrackDetMatchInfo info = trackAssociator_.associate(iEvent, iSetup, *track, parameters_, direction);
708 
709  if ( fillEnergy_ ) {
710  reco::MuonEnergy muonEnergy;
713  muonEnergy.ho = info.crossedEnergy(TrackDetMatchInfo::HORecHits);
715  muonEnergy.emS9 = info.nXnEnergy(TrackDetMatchInfo::EcalRecHits,1); // 3x3 energy
716  muonEnergy.emS25 = info.nXnEnergy(TrackDetMatchInfo::EcalRecHits,2); // 5x5 energy
717  muonEnergy.hadS9 = info.nXnEnergy(TrackDetMatchInfo::HcalRecHits,1); // 3x3 energy
718  muonEnergy.hoS9 = info.nXnEnergy(TrackDetMatchInfo::HORecHits,1); // 3x3 energy
719  muonEnergy.towerS9 = info.nXnEnergy(TrackDetMatchInfo::TowerTotal,1); // 3x3 energy
720  muonEnergy.ecal_position = info.trkGlobPosAtEcal;
721  muonEnergy.hcal_position = info.trkGlobPosAtHcal;
722  if (! info.crossedEcalIds.empty() ) muonEnergy.ecal_id = info.crossedEcalIds.front();
723  if (! info.crossedHcalIds.empty() ) muonEnergy.hcal_id = info.crossedHcalIds.front();
724  // find maximal energy depositions and their time
725  DetId emMaxId = info.findMaxDeposition(TrackDetMatchInfo::EcalRecHits,2); // max energy deposit in 5x5 shape
726  for(std::vector<const EcalRecHit*>::const_iterator hit=info.ecalRecHits.begin();
727  hit!=info.ecalRecHits.end(); ++hit) {
728  if ((*hit)->id() != emMaxId) continue;
729  muonEnergy.emMax = (*hit)->energy();
730  muonEnergy.ecal_time = (*hit)->time();
731  }
732  DetId hadMaxId = info.findMaxDeposition(TrackDetMatchInfo::HcalRecHits,1); // max energy deposit in 3x3 shape
733  for(std::vector<const HBHERecHit*>::const_iterator hit=info.hcalRecHits.begin();
734  hit!=info.hcalRecHits.end(); ++hit) {
735  if ((*hit)->id() != hadMaxId) continue;
736  muonEnergy.hadMax = (*hit)->energy();
737  muonEnergy.hcal_time = (*hit)->time();
738  }
739  aMuon.setCalEnergy( muonEnergy );
740  }
741  if ( ! fillMatching_ && ! aMuon.isTrackerMuon() ) return;
742 
743  // fill muon match info
744  std::vector<reco::MuonChamberMatch> muonChamberMatches;
745  unsigned int nubmerOfMatchesAccordingToTrackAssociator = 0;
746  for( std::vector<TAMuonChamberMatch>::const_iterator chamber=info.chambers.begin();
747  chamber!=info.chambers.end(); chamber++ )
748  {
749  reco::MuonChamberMatch matchedChamber;
750 
751  LocalError localError = chamber->tState.localError().positionError();
752  matchedChamber.x = chamber->tState.localPosition().x();
753  matchedChamber.y = chamber->tState.localPosition().y();
754  matchedChamber.xErr = sqrt( localError.xx() );
755  matchedChamber.yErr = sqrt( localError.yy() );
756 
757  matchedChamber.dXdZ = chamber->tState.localDirection().z()!=0?chamber->tState.localDirection().x()/chamber->tState.localDirection().z():9999;
758  matchedChamber.dYdZ = chamber->tState.localDirection().z()!=0?chamber->tState.localDirection().y()/chamber->tState.localDirection().z():9999;
759  // DANGEROUS - compiler cannot guaranty parameters ordering
760  AlgebraicSymMatrix55 trajectoryCovMatrix = chamber->tState.localError().matrix();
761  matchedChamber.dXdZErr = trajectoryCovMatrix(1,1)>0?sqrt(trajectoryCovMatrix(1,1)):0;
762  matchedChamber.dYdZErr = trajectoryCovMatrix(2,2)>0?sqrt(trajectoryCovMatrix(2,2)):0;
763 
764  matchedChamber.edgeX = chamber->localDistanceX;
765  matchedChamber.edgeY = chamber->localDistanceY;
766 
767  matchedChamber.id = chamber->id;
768  if ( ! chamber->segments.empty() ) ++nubmerOfMatchesAccordingToTrackAssociator;
769 
770  // fill segments
771  for( std::vector<TAMuonSegmentMatch>::const_iterator segment = chamber->segments.begin();
772  segment != chamber->segments.end(); segment++ )
773  {
774  reco::MuonSegmentMatch matchedSegment;
775  matchedSegment.x = segment->segmentLocalPosition.x();
776  matchedSegment.y = segment->segmentLocalPosition.y();
777  matchedSegment.dXdZ = segment->segmentLocalDirection.z()?segment->segmentLocalDirection.x()/segment->segmentLocalDirection.z():0;
778  matchedSegment.dYdZ = segment->segmentLocalDirection.z()?segment->segmentLocalDirection.y()/segment->segmentLocalDirection.z():0;
779  matchedSegment.xErr = segment->segmentLocalErrorXX>0?sqrt(segment->segmentLocalErrorXX):0;
780  matchedSegment.yErr = segment->segmentLocalErrorYY>0?sqrt(segment->segmentLocalErrorYY):0;
781  matchedSegment.dXdZErr = segment->segmentLocalErrorDxDz>0?sqrt(segment->segmentLocalErrorDxDz):0;
782  matchedSegment.dYdZErr = segment->segmentLocalErrorDyDz>0?sqrt(segment->segmentLocalErrorDyDz):0;
783  matchedSegment.t0 = segment->t0;
784  matchedSegment.mask = 0;
785  matchedSegment.dtSegmentRef = segment->dtSegmentRef;
786  matchedSegment.cscSegmentRef = segment->cscSegmentRef;
787  matchedSegment.hasZed_ = segment->hasZed;
788  matchedSegment.hasPhi_ = segment->hasPhi;
789  // test segment
790  bool matchedX = false;
791  bool matchedY = false;
792  LogTrace("MuonIdentification") << " matching local x, segment x: " << matchedSegment.x <<
793  ", chamber x: " << matchedChamber.x << ", max: " << maxAbsDx_;
794  LogTrace("MuonIdentification") << " matching local y, segment y: " << matchedSegment.y <<
795  ", chamber y: " << matchedChamber.y << ", max: " << maxAbsDy_;
796  if (matchedSegment.xErr>0 && matchedChamber.xErr>0 )
797  LogTrace("MuonIdentification") << " xpull: " <<
798  fabs(matchedSegment.x - matchedChamber.x)/sqrt(pow(matchedSegment.xErr,2) + pow(matchedChamber.xErr,2));
799  if (matchedSegment.yErr>0 && matchedChamber.yErr>0 )
800  LogTrace("MuonIdentification") << " ypull: " <<
801  fabs(matchedSegment.y - matchedChamber.y)/sqrt(pow(matchedSegment.yErr,2) + pow(matchedChamber.yErr,2));
802 
803  if (fabs(matchedSegment.x - matchedChamber.x) < maxAbsDx_) matchedX = true;
804  if (fabs(matchedSegment.y - matchedChamber.y) < maxAbsDy_) matchedY = true;
805  if (matchedSegment.xErr>0 && matchedChamber.xErr>0 &&
806  fabs(matchedSegment.x - matchedChamber.x)/sqrt(pow(matchedSegment.xErr,2) + pow(matchedChamber.xErr,2)) < maxAbsPullX_) matchedX = true;
807  if (matchedSegment.yErr>0 && matchedChamber.yErr>0 &&
808  fabs(matchedSegment.y - matchedChamber.y)/sqrt(pow(matchedSegment.yErr,2) + pow(matchedChamber.yErr,2)) < maxAbsPullY_) matchedY = true;
809  if (matchedX && matchedY) matchedChamber.segmentMatches.push_back(matchedSegment);
810  }
811  muonChamberMatches.push_back(matchedChamber);
812  }
813  aMuon.setMatches(muonChamberMatches);
814 
815  LogTrace("MuonIdentification") << "number of muon chambers: " << aMuon.matches().size() << "\n"
816  << "number of chambers with segments according to the associator requirements: " <<
817  nubmerOfMatchesAccordingToTrackAssociator;
818  LogTrace("MuonIdentification") << "number of segment matches with the producer requirements: " <<
820 
821  // fillTime( iEvent, iSetup, aMuon );
822 }
823 
825 {
826  //
827  // apply segment flags
828  //
829  std::vector<std::pair<reco::MuonChamberMatch*,reco::MuonSegmentMatch*> > chamberPairs; // for chamber segment sorting
830  std::vector<std::pair<reco::MuonChamberMatch*,reco::MuonSegmentMatch*> > stationPairs; // for station segment sorting
831  std::vector<std::pair<reco::MuonChamberMatch*,reco::MuonSegmentMatch*> > arbitrationPairs; // for muon segment arbitration
832 
833  // muonIndex1
834  for( unsigned int muonIndex1 = 0; muonIndex1 < pOutputMuons->size(); ++muonIndex1 )
835  {
836  // chamberIter1
837  for( std::vector<reco::MuonChamberMatch>::iterator chamberIter1 = pOutputMuons->at(muonIndex1).matches().begin();
838  chamberIter1 != pOutputMuons->at(muonIndex1).matches().end(); ++chamberIter1 )
839  {
840  if(chamberIter1->segmentMatches.empty()) continue;
841  chamberPairs.clear();
842 
843  // segmentIter1
844  for( std::vector<reco::MuonSegmentMatch>::iterator segmentIter1 = chamberIter1->segmentMatches.begin();
845  segmentIter1 != chamberIter1->segmentMatches.end(); ++segmentIter1 )
846  {
847  chamberPairs.push_back(std::make_pair(&(*chamberIter1), &(*segmentIter1)));
848  if(!segmentIter1->isMask()) // has not yet been arbitrated
849  {
850  arbitrationPairs.clear();
851  arbitrationPairs.push_back(std::make_pair(&(*chamberIter1), &(*segmentIter1)));
852 
853 
854 
855  // find identical segments with which to arbitrate
856  // tracker muons only
857  if (pOutputMuons->at(muonIndex1).isTrackerMuon()) {
858  // muonIndex2
859  for( unsigned int muonIndex2 = muonIndex1+1; muonIndex2 < pOutputMuons->size(); ++muonIndex2 )
860  {
861  // tracker muons only
862  if (! pOutputMuons->at(muonIndex2).isTrackerMuon()) continue;
863  // chamberIter2
864  for( std::vector<reco::MuonChamberMatch>::iterator chamberIter2 = pOutputMuons->at(muonIndex2).matches().begin();
865  chamberIter2 != pOutputMuons->at(muonIndex2).matches().end(); ++chamberIter2 )
866  {
867  // segmentIter2
868  for( std::vector<reco::MuonSegmentMatch>::iterator segmentIter2 = chamberIter2->segmentMatches.begin();
869  segmentIter2 != chamberIter2->segmentMatches.end(); ++segmentIter2 )
870  {
871  if(segmentIter2->isMask()) continue; // has already been arbitrated
872  if(fabs(segmentIter2->x - segmentIter1->x ) < 1E-3 &&
873  fabs(segmentIter2->y - segmentIter1->y ) < 1E-3 &&
874  fabs(segmentIter2->dXdZ - segmentIter1->dXdZ ) < 1E-3 &&
875  fabs(segmentIter2->dYdZ - segmentIter1->dYdZ ) < 1E-3 &&
876  fabs(segmentIter2->xErr - segmentIter1->xErr ) < 1E-3 &&
877  fabs(segmentIter2->yErr - segmentIter1->yErr ) < 1E-3 &&
878  fabs(segmentIter2->dXdZErr - segmentIter1->dXdZErr) < 1E-3 &&
879  fabs(segmentIter2->dYdZErr - segmentIter1->dYdZErr) < 1E-3)
880  arbitrationPairs.push_back(std::make_pair(&(*chamberIter2), &(*segmentIter2)));
881  } // segmentIter2
882  } // chamberIter2
883  } // muonIndex2
884  }
885 
886  // arbitration segment sort
887  if(arbitrationPairs.empty()) continue; // this should never happen
888  if(arbitrationPairs.size()==1) {
889  arbitrationPairs.front().second->setMask(reco::MuonSegmentMatch::BelongsToTrackByDRSlope);
890  arbitrationPairs.front().second->setMask(reco::MuonSegmentMatch::BelongsToTrackByDXSlope);
891  arbitrationPairs.front().second->setMask(reco::MuonSegmentMatch::BelongsToTrackByDR);
892  arbitrationPairs.front().second->setMask(reco::MuonSegmentMatch::BelongsToTrackByDX);
893  arbitrationPairs.front().second->setMask(reco::MuonSegmentMatch::Arbitrated);
894  } else {
895  sort(arbitrationPairs.begin(), arbitrationPairs.end(), SortMuonSegmentMatches(reco::MuonSegmentMatch::BelongsToTrackByDRSlope));
896  arbitrationPairs.front().second->setMask(reco::MuonSegmentMatch::BelongsToTrackByDRSlope);
897  sort(arbitrationPairs.begin(), arbitrationPairs.end(), SortMuonSegmentMatches(reco::MuonSegmentMatch::BelongsToTrackByDXSlope));
898  arbitrationPairs.front().second->setMask(reco::MuonSegmentMatch::BelongsToTrackByDXSlope);
899  sort(arbitrationPairs.begin(), arbitrationPairs.end(), SortMuonSegmentMatches(reco::MuonSegmentMatch::BelongsToTrackByDR));
900  arbitrationPairs.front().second->setMask(reco::MuonSegmentMatch::BelongsToTrackByDR);
901  sort(arbitrationPairs.begin(), arbitrationPairs.end(), SortMuonSegmentMatches(reco::MuonSegmentMatch::BelongsToTrackByDX));
902  arbitrationPairs.front().second->setMask(reco::MuonSegmentMatch::BelongsToTrackByDX);
903  for( unsigned int it = 0; it < arbitrationPairs.size(); ++it )
904  arbitrationPairs.at(it).second->setMask(reco::MuonSegmentMatch::Arbitrated);
905  }
906  }
907 
908  // setup me1a cleaning for later
909  if( chamberIter1->id.subdetId() == MuonSubdetId::CSC && arbClean_ ) {
910  CSCDetId cscid(chamberIter1->id);
911  if(cscid.ring() == 4)
912  for( std::vector<reco::MuonSegmentMatch>::iterator segmentIter2 = chamberIter1->segmentMatches.begin();
913  segmentIter2 != chamberIter1->segmentMatches.end(); ++segmentIter2 ) {
914  if( segmentIter1->cscSegmentRef.isNonnull() && segmentIter2->cscSegmentRef.isNonnull() )
915  if( meshAlgo_->isDuplicateOf(segmentIter1->cscSegmentRef,segmentIter2->cscSegmentRef) &&
916  (segmentIter2->mask & 0x1e0000) &&
917  (segmentIter1->mask & 0x1e0000) )
919  //if the track has lost the segment already through normal arbitration no need to do it again.
920  }
921  }// mark all ME1/a duplicates that this track owns
922 
923  } // segmentIter1
924 
925  // chamber segment sort
926  if(chamberPairs.empty()) continue; // this should never happen
927  if(chamberPairs.size()==1) {
928  chamberPairs.front().second->setMask(reco::MuonSegmentMatch::BestInChamberByDRSlope);
929  chamberPairs.front().second->setMask(reco::MuonSegmentMatch::BestInChamberByDXSlope);
930  chamberPairs.front().second->setMask(reco::MuonSegmentMatch::BestInChamberByDR);
931  chamberPairs.front().second->setMask(reco::MuonSegmentMatch::BestInChamberByDX);
932  } else {
933  sort(chamberPairs.begin(), chamberPairs.end(), SortMuonSegmentMatches(reco::MuonSegmentMatch::BestInChamberByDRSlope));
934  chamberPairs.front().second->setMask(reco::MuonSegmentMatch::BestInChamberByDRSlope);
935  sort(chamberPairs.begin(), chamberPairs.end(), SortMuonSegmentMatches(reco::MuonSegmentMatch::BestInChamberByDXSlope));
936  chamberPairs.front().second->setMask(reco::MuonSegmentMatch::BestInChamberByDXSlope);
937  sort(chamberPairs.begin(), chamberPairs.end(), SortMuonSegmentMatches(reco::MuonSegmentMatch::BestInChamberByDR));
938  chamberPairs.front().second->setMask(reco::MuonSegmentMatch::BestInChamberByDR);
939  sort(chamberPairs.begin(), chamberPairs.end(), SortMuonSegmentMatches(reco::MuonSegmentMatch::BestInChamberByDX));
940  chamberPairs.front().second->setMask(reco::MuonSegmentMatch::BestInChamberByDX);
941  }
942  } // chamberIter1
943 
944  // station segment sort
945  for( int stationIndex = 1; stationIndex < 5; ++stationIndex )
946  for( int detectorIndex = 1; detectorIndex < 4; ++detectorIndex )
947  {
948  stationPairs.clear();
949 
950  // chamberIter
951  for( std::vector<reco::MuonChamberMatch>::iterator chamberIter = pOutputMuons->at(muonIndex1).matches().begin();
952  chamberIter != pOutputMuons->at(muonIndex1).matches().end(); ++chamberIter )
953  {
954  if(!(chamberIter->station()==stationIndex && chamberIter->detector()==detectorIndex)) continue;
955  if(chamberIter->segmentMatches.empty()) continue;
956 
957  for( std::vector<reco::MuonSegmentMatch>::iterator segmentIter = chamberIter->segmentMatches.begin();
958  segmentIter != chamberIter->segmentMatches.end(); ++segmentIter )
959  stationPairs.push_back(std::make_pair(&(*chamberIter), &(*segmentIter)));
960  } // chamberIter
961 
962  if(stationPairs.empty()) continue; // this may very well happen
963  if(stationPairs.size()==1) {
964  stationPairs.front().second->setMask(reco::MuonSegmentMatch::BestInStationByDRSlope);
965  stationPairs.front().second->setMask(reco::MuonSegmentMatch::BestInStationByDXSlope);
966  stationPairs.front().second->setMask(reco::MuonSegmentMatch::BestInStationByDR);
967  stationPairs.front().second->setMask(reco::MuonSegmentMatch::BestInStationByDX);
968  } else {
969  sort(stationPairs.begin(), stationPairs.end(), SortMuonSegmentMatches(reco::MuonSegmentMatch::BestInStationByDRSlope));
970  stationPairs.front().second->setMask(reco::MuonSegmentMatch::BestInStationByDRSlope);
971  sort(stationPairs.begin(), stationPairs.end(), SortMuonSegmentMatches(reco::MuonSegmentMatch::BestInStationByDXSlope));
972  stationPairs.front().second->setMask(reco::MuonSegmentMatch::BestInStationByDXSlope);
973  sort(stationPairs.begin(), stationPairs.end(), SortMuonSegmentMatches(reco::MuonSegmentMatch::BestInStationByDR));
974  stationPairs.front().second->setMask(reco::MuonSegmentMatch::BestInStationByDR);
975  sort(stationPairs.begin(), stationPairs.end(), SortMuonSegmentMatches(reco::MuonSegmentMatch::BestInStationByDX));
976  stationPairs.front().second->setMask(reco::MuonSegmentMatch::BestInStationByDX);
977  }
978  }
979 
980  } // muonIndex1
981 
982  if(arbClean_) {
983  // clear old mesh, create and prune new mesh!
984  meshAlgo_->clearMesh();
985  meshAlgo_->runMesh(pOutputMuons);
986  }
987 }
988 
990  reco::IsoDeposit& trackDep, reco::IsoDeposit& ecalDep, reco::IsoDeposit& hcalDep, reco::IsoDeposit& hoDep,
991  reco::IsoDeposit& jetDep)
992 {
993  reco::MuonIsolation isoR03, isoR05;
994  const reco::Track* track = 0;
995  if ( ! aMuon.track().isNull() )
996  track = aMuon.track().get();
997  else
998  {
999  if ( ! aMuon.standAloneMuon().isNull() )
1000  track = aMuon.standAloneMuon().get();
1001  else
1002  throw cms::Exception("FatalError") << "Failed to compute muon isolation information for a muon with undefined references to tracks";
1003  }
1004 
1005  // get deposits
1006  reco::IsoDeposit depTrk = muIsoExtractorTrack_->deposit(iEvent, iSetup, *track );
1007  std::vector<reco::IsoDeposit> caloDeps = muIsoExtractorCalo_->deposits(iEvent, iSetup, *track);
1008  reco::IsoDeposit depJet = muIsoExtractorJet_->deposit(iEvent, iSetup, *track );
1009 
1010  if(caloDeps.size()!=3) {
1011  LogTrace("MuonIdentification") << "Failed to fill vector of calorimeter isolation deposits!";
1012  return;
1013  }
1014 
1015  reco::IsoDeposit depEcal = caloDeps.at(0);
1016  reco::IsoDeposit depHcal = caloDeps.at(1);
1017  reco::IsoDeposit depHo = caloDeps.at(2);
1018 
1019  trackDep = depTrk;
1020  ecalDep = depEcal;
1021  hcalDep = depHcal;
1022  hoDep = depHo;
1023  jetDep = depJet;
1024 
1025  isoR03.sumPt = depTrk.depositWithin(0.3);
1026  isoR03.emEt = depEcal.depositWithin(0.3);
1027  isoR03.hadEt = depHcal.depositWithin(0.3);
1028  isoR03.hoEt = depHo.depositWithin(0.3);
1029  isoR03.nTracks = depTrk.depositAndCountWithin(0.3).second;
1030  isoR03.nJets = depJet.depositAndCountWithin(0.3).second;
1031  isoR03.trackerVetoPt = depTrk.candEnergy();
1032  isoR03.emVetoEt = depEcal.candEnergy();
1033  isoR03.hadVetoEt = depHcal.candEnergy();
1034  isoR03.hoVetoEt = depHo.candEnergy();
1035 
1036  isoR05.sumPt = depTrk.depositWithin(0.5);
1037  isoR05.emEt = depEcal.depositWithin(0.5);
1038  isoR05.hadEt = depHcal.depositWithin(0.5);
1039  isoR05.hoEt = depHo.depositWithin(0.5);
1040  isoR05.nTracks = depTrk.depositAndCountWithin(0.5).second;
1041  isoR05.nJets = depJet.depositAndCountWithin(0.5).second;
1042  isoR05.trackerVetoPt = depTrk.candEnergy();
1043  isoR05.emVetoEt = depEcal.candEnergy();
1044  isoR05.hadVetoEt = depHcal.candEnergy();
1045  isoR05.hoVetoEt = depHo.candEnergy();
1046 
1047 
1048  aMuon.setIsolation(isoR03, isoR05);
1049 
1050 }
1051 
1053 {
1054  //FIXME: E = sqrt(p^2 + m^2), where m == 0.105658369(9)GeV
1055  double energy = sqrt(track.p() * track.p() + 0.011163691);
1056  math::XYZTLorentzVector p4(track.px(),
1057  track.py(),
1058  track.pz(),
1059  energy);
1060  return reco::Muon( track.charge(), p4, track.vertex() );
1061 }
1062 
1064 {
1065  double phi = 0;
1066  if( id.subdetId() == MuonSubdetId::DT ) { // DT
1067  DTChamberId muonId(id.rawId());
1068  if ( muonId.sector() <= 12 )
1069  phi = (muonId.sector()-1)/6.*M_PI;
1070  if ( muonId.sector() == 13 ) phi = 3/6.*M_PI;
1071  if ( muonId.sector() == 14 ) phi = 9/6.*M_PI;
1072  }
1073  if( id.subdetId() == MuonSubdetId::CSC ) { // CSC
1074  CSCDetId muonId(id.rawId());
1075  phi = M_PI/4+(muonId.triggerSector()-1)/3.*M_PI;
1076  }
1077  if ( phi > M_PI ) phi -= 2*M_PI;
1078  return phi;
1079 }
1080 
1082 {
1083  if ( muon.isStandAloneMuon() ) return muon.standAloneMuon()->innerPosition().phi();
1084  // the rest is tracker muon only
1085  if ( muon.matches().empty() ){
1086  if ( muon.innerTrack().isAvailable() &&
1087  muon.innerTrack()->extra().isAvailable() )
1088  return muon.innerTrack()->outerPosition().phi();
1089  else
1090  return muon.phi(); // makes little sense, but what else can I use
1091  }
1092  return sectorPhi(muon.matches().at(0).id);
1093 }
1094 
1096 {
1098  iEvent.getByLabel(globalTrackQualityInputTag_, glbQualH);
1099 
1100  if(aMuon.isGlobalMuon() && !glbQualH.failedToGet()) {
1101  aMuon.setCombinedQuality((*glbQualH)[aMuon.combinedMuon()]);
1102  }
1103 
1104  LogDebug("MuonIdentification") << "tkChiVal " << aMuon.combinedQuality().trkRelChi2;
1105 
1106 }
1107 
1108 
1110  bool trackBAD = links->trackerTrack().isNull();
1111  bool staBAD = links->standAloneTrack().isNull();
1112  bool glbBAD = links->globalTrack().isNull();
1113  if (trackBAD || staBAD || glbBAD )
1114  {
1115  edm::LogWarning("muonIDbadLinks") << "Global muon links to constituent tracks are invalid: trkBad "
1116  <<trackBAD <<" standaloneBad "<<staBAD<<" globalBad "<<glbBAD
1117  <<". There should be no such object. Muon is skipped.";
1118  return false;
1119  }
1120  return true;
1121 }
#define LogDebug(id)
std::string hoDepositName_
double p() const
momentum vector magnitude
Definition: TrackBase.h:128
type
Definition: HCALResponse.h:22
float hadEt
hcal sum-Et
Definition: MuonIsolation.h:9
T getParameter(std::string const &) const
static const unsigned int BelongsToTrackByME1aClean
std::string jetDepositName_
double candEnergy() const
Get energy or pT attached to cand trajectory.
Definition: IsoDeposit.h:131
int i
Definition: DBlmapReader.cc:9
float xx() const
Definition: LocalError.h:19
reco::Muon makeMuon(edm::Event &iEvent, const edm::EventSetup &iSetup, const reco::TrackRef &track, TrackType type)
static const unsigned int GlobalMuon
Definition: Muon.h:140
void fillMuonIsolation(edm::Event &, const edm::EventSetup &, reco::Muon &aMuon, reco::IsoDeposit &trackDep, reco::IsoDeposit &ecalDep, reco::IsoDeposit &hcalDep, reco::IsoDeposit &hoDep, reco::IsoDeposit &jetDep)
static void truthMatchMuon(const edm::Event &iEvent, const edm::EventSetup &iSetup, reco::Muon &aMuon)
DTRecSegment4DRef dtSegmentRef
void runMesh(std::vector< reco::Muon > *p)
Definition: MuonMesh.h:39
static bool crossedIP(const reco::Track &track)
float sumPt
sum-pt of tracks
Definition: MuonIsolation.h:7
virtual void setOuterTrack(const TrackRef &t)
set reference to Track
Definition: Muon.cc:719
void setType(unsigned int type)
Definition: Muon.h:144
TrackDetectorAssociator trackAssociator_
CSCSegmentRef cscSegmentRef
const TrackExtraRef & extra() const
reference to &quot;extra&quot; object
Definition: Track.h:97
static const unsigned int Arbitrated
segment mask flags
void fillMuonId(edm::Event &, const edm::EventSetup &, reco::Muon &, TrackDetectorAssociator::Direction direction=TrackDetectorAssociator::InsideOut)
reco::isodeposit::IsoDepositExtractor * muIsoExtractorCalo_
virtual TrackRef innerTrack() const
Definition: Muon.h:38
edm::Handle< reco::MuonTrackLinksCollection > linkCollectionHandle_
bool isTrackerMuon() const
Definition: Muon.h:149
int overlap(const reco::Muon &muon, const reco::Track &track)
bool fillCaloCompatibility_
std::vector< const EcalRecHit * > ecalRecHits
hits in the cone
virtual void setInnerTrack(const TrackRef &t)
set reference to Track
Definition: Muon.cc:720
std::vector< DetId > crossedEcalIds
std::string trackDepositName_
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:52
double phiOfMuonIneteractionRegion(const reco::Muon &muon) const
std::vector< CaloMuon > CaloMuonCollection
collection of Muon objects
Definition: MuonFwd.h:27
DetId findMaxDeposition(EnergyType)
Find detector elements with highest energy deposition.
float hadVetoEt
hcal sum-et in the veto region in r-phi
Definition: MuonIsolation.h:15
virtual TrackRef track() const
reference to a Track
Definition: Muon.h:39
bool isGlobalMuon() const
Definition: Muon.h:148
float emS9
energy deposited in 3x3 ECAL crystal shape around central crystal
Definition: MuonEnergy.h:18
std::vector< std::string > inputCollectionTypes_
double evaluate(const reco::Muon &)
MuonCaloCompatibility muonCaloCompatibility_
static const unsigned int BestInStationByDRSlope
float timeAtIpOutInErr() const
Definition: MuonTimeExtra.h:50
bool isMatchesValid() const
Definition: Muon.h:89
#define min(a, b)
Definition: mlp_lapack.h:161
void setIsolation(const MuonIsolation &isoR03, const MuonIsolation &isoR05)
Definition: Muon.cc:712
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
double px() const
x coordinate of momentum vector
Definition: TrackBase.h:132
bool isAvailable() const
Definition: Ref.h:278
static const unsigned int BelongsToTrackByDXSlope
bool isStandAloneMuon() const
Definition: Muon.h:150
void setCalEnergy(const MuonEnergy &calEnergy)
set energy deposition information
Definition: Muon.h:64
void fillGlbQuality(edm::Event &, const edm::EventSetup &, reco::Muon &aMuon)
int nDof() const
number of measurements used in timing calculation
Definition: MuonTimeExtra.h:23
float timeAtIpOutInErr
Definition: MuonTime.h:18
std::vector< DetId > crossedHcalIds
float trkRelChi2
chi2 value for the inner track stub with respect to the global track
Definition: MuonQuality.h:15
double nXnEnergy(const DetId &, EnergyType, int gridSize=1)
get energy of the NxN shape (N = 2*gridSize + 1) around given detector element
float towerS9
total energy in 3x3 tower shape
Definition: MuonEnergy.h:12
static const unsigned int BestInStationByDR
virtual double eta() const
momentum pseudorapidity
MuonTime time() const
get timing information
Definition: Muon.h:82
virtual void beginRun(edm::Run &, const edm::EventSetup &)
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
math::XYZPoint trkGlobPosAtHcal
void clearMesh()
Definition: MuonMesh.h:41
float ecal_time
Calorimeter timing.
Definition: MuonEnergy.h:37
float ho
energy deposited in crossed HO towers
Definition: MuonEnergy.h:32
MuonMesh * meshAlgo_
double depositWithin(double coneSize, const Vetos &vetos=Vetos(), bool skipDepositVeto=false) const
Get deposit.
Definition: IsoDeposit.cc:34
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
void setCSCGeometry(const CSCGeometry *pg)
Definition: MuonMesh.h:43
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:30
void init(edm::Event &, const edm::EventSetup &)
DetId hcal_id
DetId of the central HCAL tower with smallest depth.
Definition: MuonEnergy.h:50
int iEvent
Definition: GenABIO.cc:243
static const int CSC
Definition: MuonSubdetId.h:15
bool isNull() const
Checks for null.
Definition: Ref.h:244
double ptThresholdToFillCandidateP4WithGlobalFit_
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:140
TrackAssociatorParameters parameters_
bool isCaloCompatibilityValid() const
Definition: CaloMuon.h:45
void fillArbitrationInfo(reco::MuonCollection *)
void setPropagator(const Propagator *)
use a user configured propagator
float yy() const
Definition: LocalError.h:21
float emS25
energy deposited in 5x5 ECAL crystal shape around central crystal
Definition: MuonEnergy.h:20
double p() const
momentum vector magnitude
Definition: CaloMuon.h:52
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:84
T sqrt(T t)
Definition: SSEVec.h:28
double p4[4]
Definition: TauolaWrapper.h:92
bool isGoodTrackerMuon(const reco::Muon &muon)
double pt() const
track transverse momentum
Definition: TrackBase.h:130
float emEt
ecal sum-Et
Definition: MuonIsolation.h:8
bool checkLinks(const reco::MuonTrackLinks *) const
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
float timeAtIpInOutErr
Definition: MuonTime.h:15
std::vector< TAMuonChamberMatch > chambers
int nJets
number of jets in the cone
Definition: MuonIsolation.h:12
std::vector< const HBHERecHit * > hcalRecHits
static const unsigned int BestInChamberByDX
std::string ecalDepositName_
MuonQuality combinedQuality() const
get energy deposition information
Definition: Muon.h:72
float timeAtIpOutIn
b) particle is moving from outside in
Definition: MuonTime.h:17
int nDof
number of muon stations used
Definition: MuonTime.h:10
float timeAtIpInOutErr() const
Definition: MuonTimeExtra.h:45
int j
Definition: DBlmapReader.cc:9
CSCDetId chamberId() const
Definition: CSCDetId.h:55
float hoEt
ho sum-Et
Definition: MuonIsolation.h:10
float hoS9
energy deposited in 3x3 HO tower shape around central tower
Definition: MuonEnergy.h:34
static const unsigned int BestInChamberByDR
math::XYZPoint ecal_position
Trajectory position at the calorimeter.
Definition: MuonEnergy.h:43
bool isValid() const
Definition: HandleBase.h:76
edm::Handle< reco::TrackCollection > outerTrackCollectionHandle_
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:359
double crossedEnergy(EnergyType)
energy in detector elements crossed by the track by types
#define LogTrace(id)
static const unsigned int BestInStationByDXSlope
static double sectorPhi(const DetId &id)
bool isEnergyValid() const
Definition: Muon.h:60
float hoVetoEt
ho sum-et in the veto region in r-phi
Definition: MuonIsolation.h:16
int numberOfMatches(ArbitrationType type=SegmentAndTrackArbitration) const
get number of chambers with matched segments
Definition: Muon.cc:40
double pz() const
z coordinate of momentum vector
Definition: TrackBase.h:136
MuonEnergy calEnergy() const
get energy deposition information
Definition: Muon.h:62
reco::CaloMuon makeCaloMuon(const reco::Muon &)
virtual ~MuonIdProducer()
int nTracks
number of tracks in the cone (excluding veto region)
Definition: MuonIsolation.h:11
static const unsigned int BestInChamberByDXSlope
float emMax
maximal energy of ECAL crystal in the 5x5 shape
Definition: MuonEnergy.h:22
reco::isodeposit::IsoDepositExtractor * muIsoExtractorTrack_
const Point & vertex() const
reference point on the track. This method is DEPRECATED, please use referencePoint() instead ...
Definition: TrackBase.h:155
int ring() const
Definition: CSCDetId.h:77
bool failedToGet() const
Definition: HandleBase.h:80
void setCaloCompatibility(float input)
Definition: CaloMuon.h:44
Definition: DetId.h:20
#define M_PI
Definition: BFit3D.cc:3
bool isTimeValid() const
Definition: Muon.h:80
virtual TrackRef combinedMuon() const
reference to a stand-alone muon Track
Definition: Muon.h:45
static const unsigned int TrackerMuon
Definition: Muon.h:141
float emVetoEt
ecal sum-et in the veto region in r-phi
Definition: MuonIsolation.h:14
void configure(const edm::ParameterSet &)
reco::isodeposit::IsoDepositExtractor * muIsoExtractorJet_
bool isDuplicateOf(const CSCSegmentRef &lhs, const CSCSegmentRef &rhs) const
Definition: MuonMesh.cc:342
MuonTimingFiller * theTimingFiller_
float timeAtIpInOut() const
Definition: MuonTimeExtra.h:44
float hadMax
maximal energy of HCAL tower in the 3x3 shape
Definition: MuonEnergy.h:30
virtual double pt() const
transverse momentum
virtual std::vector< reco::IsoDeposit > deposits(const edm::Event &ev, const edm::EventSetup &evSetup, const reco::Track &track) const
static const unsigned int BelongsToTrackByDRSlope
virtual void setInnerTrack(const TrackRef &t)
set reference to Track
Definition: CaloMuon.h:31
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
void setCombinedQuality(const MuonQuality &combinedQuality)
set energy deposition information
Definition: Muon.h:74
std::vector< edm::InputTag > inputCollectionLabels_
std::vector< MuonChamberMatch > & matches()
get muon matching information
Definition: Muon.h:91
void setCalEnergy(const MuonEnergy &calEnergy)
set energy deposition information
Definition: CaloMuon.h:38
int triggerSector() const
Definition: CSCDetId.cc:47
MuonIdProducer(const edm::ParameterSet &)
std::vector< reco::MuonSegmentMatch > segmentMatches
bool fillGlobalTrackQuality_
DetId ecal_id
DetId of the central ECAL crystal.
Definition: MuonEnergy.h:47
static const unsigned int BelongsToTrackByDR
std::string hcalDepositName_
unsigned int chamberId(const DetId &)
static const unsigned int BelongsToTrackByDX
functor predicate for standard library sort algorithm
int sector() const
Definition: DTChamberId.h:63
std::pair< double, int > depositAndCountWithin(double coneSize, const Vetos &vetos=Vetos(), double threshold=-1e+36, bool skipDepositVeto=false) const
Get deposit.
Definition: IsoDeposit.cc:44
math::XYZPoint hcal_position
Definition: MuonEnergy.h:44
def stationIndex
Definition: plotscripts.py:386
static const unsigned int BestInStationByDX
TrackDetMatchInfo associate(const edm::Event &, const edm::EventSetup &, const FreeTrajectoryState &, const AssociatorParameters &)
edm::Handle< reco::TrackCollection > innerTrackCollectionHandle_
math::XYZPoint trkGlobPosAtEcal
Track position at different parts of the calorimeter.
int charge() const
track electric charge
Definition: TrackBase.h:112
static const int DT
Definition: MuonSubdetId.h:14
bool isGoodTrack(const reco::Track &track)
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:6
double sigmaThresholdToFillCandidateP4WithGlobalFit_
static const unsigned int StandAloneMuon
Definition: Muon.h:142
virtual reco::IsoDeposit deposit(const edm::Event &ev, const edm::EventSetup &evSetup, const reco::Track &track) const =0
float timeAtIpOutIn() const
b) particle is moving from outside in
Definition: MuonTimeExtra.h:49
void setMatches(const std::vector< MuonChamberMatch > &matches)
set muon matching information
Definition: Muon.h:94
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:239
virtual void setGlobalTrack(const TrackRef &t)
set reference to Track
Definition: Muon.cc:723
void fillTiming(const reco::Muon &muon, reco::MuonTimeExtra &dtTime, reco::MuonTimeExtra &cscTime, reco::MuonTimeExtra &combinedTime, edm::Event &iEvent, const edm::EventSetup &iSetup)
virtual void produce(edm::Event &, const edm::EventSetup &)
virtual double phi() const
momentum azimuthal angle
static const unsigned int BestInChamberByDRSlope
float caloCompatibility() const
Definition: CaloMuon.h:43
bool validateGlobalMuonPair(const reco::MuonTrackLinks &goodMuon, const reco::MuonTrackLinks &badMuon)
bool debugWithTruthMatching_
float timeAtIpInOut
Definition: MuonTime.h:14
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
float trackerVetoPt
(sum-)pt inside the veto region in r-phi
Definition: MuonIsolation.h:13
float hadS9
energy deposited in 3x3 HCAL tower shape around central tower
Definition: MuonEnergy.h:28
T get(const Candidate &c)
Definition: component.h:56
edm::InputTag globalTrackQualityInputTag_
edm::Handle< reco::MuonCollection > muonCollectionHandle_
void loadParameters(const edm::ParameterSet &)
double py() const
y coordinate of momentum vector
Definition: TrackBase.h:134
Definition: Run.h:31
Definition: DDAxes.h:10
virtual TrackRef standAloneMuon() const
reference to a stand-alone muon Track
Definition: Muon.h:42