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 
108 void L3TkMuonProducer::produce(Event& event, const EventSetup& eventSetup) {
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 }
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 >
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
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:428
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::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
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
edm::StableProvenance::productInstanceName
std::string const & productInstanceName() const
Definition: StableProvenance.h:46
edm::parameterSet
ParameterSet const & parameterSet(StableProvenance const &provenance, ProcessHistory const &history)
Definition: Provenance.cc:11
fileCollector.seed
seed
Definition: fileCollector.py:127
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:70
edm::BranchDescription::processName
std::string const & processName() const
Definition: BranchDescription.h:73
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:98
edm::StableProvenance::processName
std::string const & processName() const
Definition: StableProvenance.h:45
edm::OwnVector::const_iterator
Definition: OwnVector.h:41
reco::TrackRef
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:20
edm::StableProvenance::moduleLabel
std::string const & moduleLabel() const
Definition: StableProvenance.h:43
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
edm::ParameterSet
Definition: ParameterSet.h:47
TrajectorySeed::direction
PropagationDirection direction() const
Definition: TrajectorySeed.h:54
TrackingRecHit::all
Definition: TrackingRecHit.h:59
Event.h
tracks
const uint32_t *__restrict__ const HitContainer *__restrict__ TkSoA *__restrict__ tracks
Definition: CAHitNtupletGeneratorKernelsImpl.h:159
edm::StableProvenance
Definition: StableProvenance.h:30
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
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:108
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:58
TrajectorySeed::recHits
RecHitRange recHits() const
Definition: TrajectorySeed.h:52
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:29
EventSetup.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
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:97
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:234
ParameterSet.h
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
hit
Definition: SiStripHitEffFromCalibTree.cc:88
edm::OwnVector< TrackingRecHit >
metname
const std::string metname
Definition: MuonSeedOrcaPatternRecognition.cc:40
edm::ProductID::id
ProductIndex id() const
Definition: ProductID.h:35