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