CMS 3D CMS Logo

L3TkMuonProducer.cc
Go to the documentation of this file.
1 
9 // Framework
15 
18 
19 #include <string>
20 
21 using namespace edm;
22 using namespace std;
23 using namespace reco;
24 
27  LogTrace("Muon|RecoMuon|L3TkMuonProducer") << " constructor called";
28 
29  // StandAlone Collection Label
30  theL3CollectionLabel = parameterSet.getParameter<InputTag>("InputObjects");
31  trackToken_ = consumes<reco::TrackCollection>(theL3CollectionLabel);
32  produces<TrackCollection>();
33  produces<TrackExtraCollection>();
34  produces<TrackingRecHitCollection>();
35 
36  callWhenNewProductsRegistered([this](const edm::BranchDescription& iBD) {
38  if (iBD.unwrappedTypeID() == id) {
39  this->mayConsume<L3MuonTrajectorySeedCollection>(
41  }
42  });
43 }
44 
47  LogTrace("Muon|RecoMuon|L3TkMuonProducer") << " L3TkMuonProducer destructor called";
48 }
49 
51  //quit right away on nH=0
52  if (s1.nHits() == 0 || s2.nHits() == 0)
53  return false;
54  //quit right away if not the same number of hits
55  if (s1.nHits() != s2.nHits())
56  return false;
58  TrajectorySeed::range r2 = s2.recHits();
60  TrajectorySeed::const_iterator &i1_e = r1.second, &i2_e = r2.second;
61  TrajectorySeed::const_iterator &i1_b = r1.first, &i2_b = r2.first;
62  //quit right away if first detId does not match. front exist because of ==0 ->quit test
63  if (i1_b->geographicalId() != i2_b->geographicalId())
64  return false;
65  //then check hit by hit if they are the same
66  for (i1 = i1_b, i2 = i2_b; i1 != i1_e && i2 != i2_e; ++i1, ++i2) {
67  if (!i1->sharesInput(&(*i2), TrackingRecHit::all))
68  return false;
69  }
70  return true;
71 }
72 
73 string printvector(const vector<TrackRef>& v) {
74  std::stringstream ss;
75  for (unsigned int i = 0; i != v.size(); ++i) {
76  if (i != 0)
77  ss << "\n";
78  ss << "track with ref: " << v[i].id().id() << ":" << v[i].key() << " and pT: " << v[i]->pt()
79  << " with seedRef: " << v[i]->seedRef().id().id() << ":" << v[i]->seedRef().key();
80  }
81  return ss.str();
82 }
83 
84 string printvector(const vector<L3TkMuonProducer::SeedRef>& v) {
85  std::stringstream ss;
86  for (unsigned int i = 0; i != v.size(); ++i) {
87  if (i != 0)
88  ss << "\n";
89  ss << "seed ref: " << v[i].id().id() << ":" << v[i].key();
90  if (v[i]->l2Track().isNull())
91  ss << " and pT: " << v[i]->l1Particle()->pt() << " of L1: " << v[i]->l1Particle().id().id() << ":"
92  << v[i]->l1Particle().key();
93  else
94  ss << " and pT: " << v[i]->l2Track()->pt() << " of L2: " << v[i]->l2Track().id().id() << ":"
95  << v[i]->l2Track().key();
96  }
97  return ss.str();
98 }
99 
101  std::stringstream ss;
102  ss << " seed ref: " << s.id().id() << ":" << s.key() << " has " << s->nHits() << "rechits";
103  TrajectorySeed::range r = s->recHits();
105  for (; it != r.second; ++it)
106  ss << "\n detId: " << std::hex << it->geographicalId().rawId() << std::dec << " position: " << it->localPosition()
107  << " and error: " << it->localPositionError();
108  return ss.str();
109 }
110 
113  const string metname = "Muon|RecoMuon|L3TkMuonProducer";
114 
115  // Take the L3 container
116  LogDebug(metname) << " Taking the L3/GLB muons: " << theL3CollectionLabel.label();
118  event.getByToken(trackToken_, tracks);
119 
120  //make the LX->L3s pools
121  LXtoL3sMap LXtoL3s;
122 
123  unsigned int maxI = tracks->size();
124  bool gotL3seeds = false;
126 
127  //make a list of reference to tracker tracks
128  vector<TrackRef> orderedTrackTracks(maxI);
129  for (unsigned int i = 0; i != maxI; i++)
130  orderedTrackTracks[i] = TrackRef(tracks, i);
131  LogDebug(metname) << "vector of L3 tracks before ordering:\n" << printvector(orderedTrackTracks);
132  //order them in pT
133  sort(orderedTrackTracks.begin(), orderedTrackTracks.end(), trackRefBypT);
134  LogDebug(metname) << "vector of L3 tracks after ordering:\n" << printvector(orderedTrackTracks);
135  //loop over then
136  for (unsigned int i = 0; i != maxI; i++) {
137  TrackRef& tk = orderedTrackTracks[i];
138  SeedRef l3seedRef = tk->seedRef().castTo<SeedRef>();
139 
140  vector<SeedRef> allPossibleOrderedLx; // with identical hit-set
141  //add the direct relation
142  allPossibleOrderedLx.push_back(l3seedRef);
143  LogDebug(metname) << "adding the seed ref: " << l3seedRef.id().id() << ":" << l3seedRef.key()
144  << " for this tracker track: " << tk.id().id() << ":" << tk.key();
145 
146  //add the relations due to shared seeds
147  //check whether there is a "shared" seed in addition
148  if (!gotL3seeds) {
149  //need to fetch the handle from the ref
150  const edm::Provenance& seedsProv = event.getProvenance(l3seedRef.id());
151  edm::InputTag l3seedsTag(seedsProv.moduleLabel(), seedsProv.productInstanceName(), seedsProv.processName());
152  event.getByLabel(l3seedsTag, l3seeds);
153  gotL3seeds = true;
154  LogDebug(metname) << "got seeds handle from: " << l3seedsTag;
155  }
156  //loop the other seeds in the collection
157  for (unsigned int iS = 0; iS != l3seeds->size(); ++iS) {
158  const L3MuonTrajectorySeed& seed = (*l3seeds)[iS];
159  const L3MuonTrajectorySeed& thisSeed = *l3seedRef;
160  if (l3seedRef.key() == iS)
161  continue; //not care about this one
162  //compare this seed with the seed in the collection
163  if (sharedSeed(seed, thisSeed)) {
164  SeedRef thisSharedSeedRef(l3seeds, iS);
165  LogDebug(metname) << "shared seeds: \n"
166  << printseed(l3seedRef) << " and: \n"
167  << printseed(thisSharedSeedRef)
168  << "\nadding ANOTHER seed ref: " << thisSharedSeedRef.id().id() << ":"
169  << thisSharedSeedRef.key() << " for this tracker track: " << tk.id().id() << ":" << tk.key();
170  // edm::LogError(metname)<<" we have a shared seed right there.";
171  allPossibleOrderedLx.push_back(thisSharedSeedRef);
172  } //seed is shared
173  } //loop all other existing seed for overlaps
174 
175  //now you have the full list of Lx objects that have seed this tracker track.
176  // order the list in pT of Lx objects
177  LogDebug(metname) << "list of possible Lx objects for tracker track: " << tk.id().id() << ":" << tk.key()
178  << " before ordering\n"
179  << printvector(allPossibleOrderedLx);
180  sort(allPossibleOrderedLx.begin(), allPossibleOrderedLx.end(), seedRefBypT);
181  LogDebug(metname) << "list of possible Lx objects for tracker track: " << tk.id().id() << ":" << tk.key()
182  << " after ordering\n"
183  << printvector(allPossibleOrderedLx);
184  // assign this tracker track to the highest pT Lx.
185  for (unsigned int iL = 0; iL != allPossibleOrderedLx.size(); ++iL) {
186  SeedRef thisRef = allPossibleOrderedLx[iL];
187  pseudoRef ref = makePseudoRef(*thisRef);
188  LogDebug(metname) << "seed ref: " << thisRef.id().id() << ":" << thisRef.key()
189  << " transcribe to pseudoref: " << ref.first << ":" << ref.second;
190  LXtoL3sMap::iterator f = LXtoL3s.find(ref);
191  if (f != LXtoL3s.end()) {
192  //there's already an entry. because of the prior ordering in pT of the tracker track refs
193  // the track ref already there *has* a higher pT: this one cannot compete and should be assigned to the next Lx;
194  LogDebug(metname) << "this tracker track: " << tk.id().id() << ":" << tk.key() << " (" << tk->pt() << ")"
195  << "\n cannot compete in pT with track: " << f->second.first.id().id() << ":"
196  << f->second.first.key() << " (" << f->second.first->pt() << ")"
197  << "\n already assigned to pseudo ref: " << ref.first << ":" << ref.second
198  << " which corresponds to seedRef: " << f->second.second.id().id() << ":"
199  << f->second.second.key();
200  continue;
201  } else {
202  //there was no entry yet. make the assignement
203  LogDebug(metname) << "this tracker track: " << tk.id().id() << ":" << tk.key()
204  << " is assigned to pseudo ref: " << ref.first << ":" << ref.second
205  << " which corresponds to seedRef: " << thisRef.id().id() << ":" << thisRef.key();
206  LXtoL3s[ref] = std::make_pair(tk, thisRef);
207  //once assigned. break
208  break;
209  }
210  } //loop possible Lx for possible assignement
211  } //loop over ordered list of tracker track refs
212 
213  //prepare the output
214  auto outTracks = std::make_unique<TrackCollection>(LXtoL3s.size());
215  auto outTrackExtras = std::make_unique<TrackExtraCollection>(LXtoL3s.size());
216  reco::TrackExtraRefProd rTrackExtras = event.getRefBeforePut<TrackExtraCollection>();
217  auto outRecHits = std::make_unique<TrackingRecHitCollection>();
218  TrackingRecHitRefProd rHits = event.getRefBeforePut<TrackingRecHitCollection>();
219 
220  LogDebug(metname) << "reading the map to make " << LXtoL3s.size() << "products.";
221  //fill the collection from the map
222  LXtoL3sMap::iterator f = LXtoL3s.begin();
223  unsigned int i = 0;
224  for (; f != LXtoL3s.end(); ++f, ++i) {
225  LogDebug(metname) << "copy the track over, and make ref to extra";
226  const Track& trk = *(f->second.first);
227  (*outTracks)[i] = Track(trk);
228  (*outTracks)[i].setExtra(TrackExtraRef(rTrackExtras, i));
229 
230  LogDebug(metname) << "copy the trackExtra too, and change the seedref";
231  edm::RefToBase<TrajectorySeed> seedRef(f->second.second);
232  //do not use the copy constructor, otherwise the hit Ref are still the same
233  (*outTrackExtras)[i] = TrackExtra(trk.outerPosition(),
234  trk.outerMomentum(),
235  trk.outerOk(),
236  trk.innerPosition(),
237  trk.innerMomentum(),
238  trk.innerOk(),
239  trk.outerStateCovariance(),
240  trk.outerDetId(),
241  trk.innerStateCovariance(),
242  trk.innerDetId(),
243  seedRef->direction(),
244  seedRef);
245 
246  LogDebug(metname) << "copy the hits too";
247  unsigned int iRH = 0;
248  for (trackingRecHit_iterator hit = trk.recHitsBegin(); hit != trk.recHitsEnd(); ++hit, ++iRH) {
249  outRecHits->push_back((*hit)->clone());
250  }
251  (*outTrackExtras)[i].setHits(rHits, 0, iRH);
252  }
253 
254  LogDebug(metname) << "made: " << outTracks->size() << " tracks, " << outTrackExtras->size() << " extras and "
255  << outRecHits->size() << " rechits.";
256 
257  //put the collection in the event
258  LogDebug(metname) << "loading...";
259  event.put(std::move(outTracks));
260  event.put(std::move(outTrackExtras));
261  event.put(std::move(outRecHits));
262  LogDebug(metname) << " Event loaded"
263  << "================================";
264 }
reco::Track::outerPosition
const math::XYZPoint & outerPosition() const
position of the outermost hit
Definition: Track.h:62
reco::Track::outerMomentum
const math::XYZVector & outerMomentum() const
momentum vector at the outermost hit position
Definition: Track.h:65
edm::RefProd< TrackExtraCollection >
edm::Provenance::moduleLabel
std::string const & moduleLabel() const
Definition: Provenance.h:55
L3TkMuonProducer::sharedSeed
bool sharedSeed(const L3MuonTrajectorySeed &s1, const L3MuonTrajectorySeed &s2)
Definition: L3TkMuonProducer.cc:50
L3TkMuonProducer::pseudoRef
std::pair< unsigned int, unsigned int > pseudoRef
Definition: L3TkMuonProducer.h:46
reco::Track::outerStateCovariance
CovarianceMatrix outerStateCovariance() const
outermost trajectory state curvilinear errors
Definition: Track.h:68
testProducerWithPsetDescEmpty_cfi.i2
i2
Definition: testProducerWithPsetDescEmpty_cfi.py:46
Handle.h
PDWG_EXOHSCP_cff.tracks
tracks
Definition: PDWG_EXOHSCP_cff.py:28
reco::Track::outerDetId
unsigned int outerDetId() const
DetId of the detector on which surface the outermost state is located.
Definition: Track.h:79
edm::BranchDescription::productInstanceName
std::string const & productInstanceName() const
Definition: BranchDescription.h:81
mps_fire.i
i
Definition: mps_fire.py:355
MessageLogger.h
reco::Track::recHitsBegin
trackingRecHit_iterator recHitsBegin() const
Iterator to first hit on the track.
Definition: Track.h:88
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
L3TkMuonProducer::L3TkMuonProducer
L3TkMuonProducer(const edm::ParameterSet &)
constructor with config
Definition: L3TkMuonProducer.cc:26
TrajectorySeed::range
std::pair< const_iterator, const_iterator > range
Definition: TrajectorySeed.h:21
TrajectorySeed::nHits
unsigned int nHits() const
Definition: TrajectorySeed.h:53
edm
HLT enums.
Definition: AlignableModifier.h:19
testProducerWithPsetDescEmpty_cfi.i1
i1
Definition: testProducerWithPsetDescEmpty_cfi.py:45
TrajectorySeed::const_iterator
recHitContainer::const_iterator const_iterator
Definition: TrajectorySeed.h:20
findQualityFiles.maxI
int maxI
Definition: findQualityFiles.py:182
indexGen.s2
s2
Definition: indexGen.py:107
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
findQualityFiles.v
v
Definition: findQualityFiles.py:179
reco::Track::outerOk
bool outerOk() const
return true if the outermost hit is valid
Definition: Track.h:50
edm::Handle
Definition: AssociativeIterator.h:50
edm::Ref
Definition: AssociativeIterator.h:58
reco::Track::innerStateCovariance
CovarianceMatrix innerStateCovariance() const
innermost trajectory state curvilinear errors
Definition: Track.h:71
reco::Track::innerOk
bool innerOk() const
return true if the innermost hit is valid
Definition: Track.h:53
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
reco::TrackExtra
Definition: TrackExtra.h:26
alignCSCRings.s
s
Definition: alignCSCRings.py:92
reco::Track::innerMomentum
const math::XYZVector & innerMomentum() const
momentum vector at the innermost hit position
Definition: Track.h:59
printvector
string printvector(const vector< TrackRef > &v)
Definition: L3TkMuonProducer.cc:73
edm::BranchDescription::processName
std::string const & processName() const
Definition: BranchDescription.h:73
edm::Provenance::processName
std::string const & processName() const
Definition: Provenance.h:57
reco::Track::recHitsEnd
trackingRecHit_iterator recHitsEnd() const
Iterator to last hit on the track.
Definition: Track.h:91
reco::Track
Definition: Track.h:27
reco::TrackExtraCollection
std::vector< TrackExtra > TrackExtraCollection
collection of TrackExtra objects
Definition: TrackExtraFwd.h:10
edm::BranchDescription::unwrappedTypeID
TypeID unwrappedTypeID() const
Definition: BranchDescription.h:97
edm::OwnVector::const_iterator
Definition: OwnVector.h:41
reco::TrackRef
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:20
edm::Provenance::productInstanceName
std::string const & productInstanceName() const
Definition: Provenance.h:58
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
edm::ParameterSet
Definition: ParameterSet.h:36
TrajectorySeed::direction
PropagationDirection direction() const
Definition: TrajectorySeed.h:54
TrackingRecHit::all
Definition: TrackingRecHit.h:59
Event.h
diffTwoXMLs.r2
r2
Definition: diffTwoXMLs.py:73
reco::TrackExtraRef
edm::Ref< TrackExtraCollection > TrackExtraRef
persistent reference to a TrackExtra
Definition: TrackExtraFwd.h:16
L3TkMuonProducer.h
reco::Track::innerPosition
const math::XYZPoint & innerPosition() const
position of the innermost hit
Definition: Track.h:56
L3TkMuonProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
produce candidates
Definition: L3TkMuonProducer.cc:112
reco::Track::innerDetId
unsigned int innerDetId() const
DetId of the detector on which surface the innermost state is located.
Definition: Track.h:82
edm::EventSetup
Definition: EventSetup.h:57
alignCSCRings.r
r
Definition: alignCSCRings.py:93
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
L3TkMuonProducer::~L3TkMuonProducer
~L3TkMuonProducer() override
destructor
Definition: L3TkMuonProducer.cc:46
edm::Ref::id
ProductID id() const
Accessor for product ID.
Definition: Ref.h:244
L3TkMuonProducer::LXtoL3sMap
std::map< pseudoRef, std::pair< reco::TrackRef, SeedRef > > LXtoL3sMap
Definition: L3TkMuonProducer.h:47
edm::TypeID
Definition: TypeID.h:22
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
L3MuonTrajectorySeedCollection
diffTwoXMLs.r1
r1
Definition: diffTwoXMLs.py:53
edm::BranchDescription::moduleLabel
std::string const & moduleLabel() const
Definition: BranchDescription.h:72
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:31
edm::parameterSet
ParameterSet const & parameterSet(Provenance const &provenance, ProcessHistory const &history)
Definition: Provenance.cc:11
options_cfi.eventSetup
eventSetup
Definition: options_cfi.py:12
TrajectorySeed::recHits
range recHits() const
Definition: TrajectorySeed.h:52
EventSetup.h
edm::RefToBase< TrajectorySeed >
edm::BranchDescription
Definition: BranchDescription.h:32
edm::Ref::key
key_type key() const
Accessor for product key.
Definition: Ref.h:250
printseed
string printseed(const L3TkMuonProducer::SeedRef &s)
Definition: L3TkMuonProducer.cc:100
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:671
ParameterSet.h
edm::Provenance
Definition: Provenance.h:34
event
Definition: event.py:1
edm::Event
Definition: Event.h:73
RecoChargedCandidateFwd.h
TauDecayModes.dec
dec
Definition: TauDecayModes.py:143
L3MuonTrajectorySeed
Definition: L3MuonTrajectorySeed.h:16
edm::InputTag
Definition: InputTag.h:15
SurveyInfoScenario_cff.seed
seed
Definition: SurveyInfoScenario_cff.py:295
hit
Definition: SiStripHitEffFromCalibTree.cc:88
edm::OwnVector< TrackingRecHit >
metname
const std::string metname
Definition: MuonSeedOrcaPatternRecognition.cc:43
edm::ProductID::id
ProductIndex id() const
Definition: ProductID.h:35