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