CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L3TkMuonProducer.cc
Go to the documentation of this file.
1 
9 // Framework
16 
19 
20 #include <string>
21 
22 using namespace edm;
23 using namespace std;
24 using namespace reco;
25 
28  LogTrace("Muon|RecoMuon|L3TkMuonProducer")<<" constructor called";
29 
30  // StandAlone Collection Label
31  theL3CollectionLabel = parameterSet.getParameter<InputTag>("InputObjects");
32  trackToken_ = consumes<reco::TrackCollection>(theL3CollectionLabel);
33  produces<TrackCollection>();
34  produces<TrackExtraCollection>();
35  produces<TrackingRecHitCollection>();
36 
37 
38 
39  callWhenNewProductsRegistered( [this](const edm::BranchDescription& iBD) {
41  if(iBD.unwrappedTypeID() == id) {
42  this->mayConsume<L3MuonTrajectorySeedCollection>(edm::InputTag{iBD.moduleLabel(), iBD.productInstanceName(),iBD.processName()} );
43  }
44  });
45 
46 
47 
48 }
49 
52  LogTrace("Muon|RecoMuon|L3TkMuonProducer")<<" L3TkMuonProducer destructor called";
53 }
54 
56  //quit right away on nH=0
57  if (s1.nHits()==0 || s2.nHits()==0) return false;
58  //quit right away if not the same number of hits
59  if (s1.nHits()!=s2.nHits()) return false;
63  TrajectorySeed::const_iterator & i1_e=r1.second,&i2_e=r2.second;
64  TrajectorySeed::const_iterator & i1_b=r1.first,&i2_b=r2.first;
65  //quit right away if first detId does not match. front exist because of ==0 ->quit test
66  if(i1_b->geographicalId() != i2_b->geographicalId()) return false;
67  //then check hit by hit if they are the same
68  for (i1=i1_b,i2=i2_b;i1!=i1_e,i2!=i2_e;++i1,++i2){
69  if (!i1->sharesInput(&(*i2),TrackingRecHit::all)) return false;
70  }
71  return true;
72 }
73 
74 string printvector(const vector<TrackRef> & v){
75  std::stringstream ss;
76  for (unsigned int i=0;i!=v.size();++i) {
77  if (i!=0) ss<<"\n";
78  ss<<"track with ref: "<<v[i].id().id()<<":"<<v[i].key()
79  <<" and pT: "<<v[i]->pt()
80  <<" with seedRef: "<<v[i]->seedRef().id().id()<<":"<<v[i]->seedRef().key();
81  }
82  return ss.str();
83 }
84 
85 string printvector(const vector<L3TkMuonProducer::SeedRef> & v){
86  std::stringstream ss;
87  for (unsigned int i=0;i!=v.size();++i){
88  if (i!=0) 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()<<":"<<v[i]->l1Particle().key();
92  else
93  ss<<" and pT: "<<v[i]->l2Track()->pt()<<" of L2: "<<v[i]->l2Track().id().id()<<":"<<v[i]->l2Track().key();
94  }
95  return ss.str();
96 }
97 
99  std::stringstream ss;
100  ss<<" seed ref: "<<s.id().id()<<":"<<s.key()<<" has "<< s->nHits()<<"rechits";
101  TrajectorySeed::range r=s->recHits();
103  for (;it!=r.second;++it)
104  ss<<"\n detId: "<<it->geographicalId()<<" position: "<<it->localPosition()<<" and error: "<<it->localPositionError();
105  return ss.str();
106 }
107 
110  const string metname = "Muon|RecoMuon|L3TkMuonProducer";
111 
112  // Take the L3 container
113  LogDebug(metname)<<" Taking the L3/GLB muons: "<<theL3CollectionLabel.label();
115  event.getByToken(trackToken_,tracks);
116 
117  //make the LX->L3s pools
118  LXtoL3sMap LXtoL3s;
119 
120  unsigned int maxI = tracks->size();
121  bool gotL3seeds=false;
123 
124  //make a list of reference to tracker tracks
125  vector<TrackRef> orderedTrackTracks(maxI);
126  for (unsigned int i=0;i!=maxI;i++) 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()<<" for this tracker track: "<<tk.id().id()<<":"<<tk.key();
140 
141  //add the relations due to shared seeds
142  //check whether there is a "shared" seed in addition
143  if (!gotL3seeds){
144  //need to fetch the handle from the ref
145  const edm::Provenance & seedsProv=event.getProvenance(l3seedRef.id());
146  edm::InputTag l3seedsTag(seedsProv.moduleLabel(), seedsProv.productInstanceName(), seedsProv.processName());
147  event.getByLabel(l3seedsTag, l3seeds);
148  gotL3seeds=true;
149  LogDebug(metname)<<"got seeds handle from: "<<l3seedsTag;
150  }
151  //loop the other seeds in the collection
152  for (unsigned int iS=0;iS!=l3seeds->size();++iS){
153  const L3MuonTrajectorySeed & seed = (*l3seeds)[iS];
154  const L3MuonTrajectorySeed & thisSeed = *l3seedRef;
155  if (l3seedRef.key()==iS) continue; //not care about this one
156  //compare this seed with the seed in the collection
157  if (sharedSeed(seed,thisSeed)){
158  SeedRef thisSharedSeedRef(l3seeds,iS);
159  LogDebug(metname)<<"shared seeds: \n"<<printseed(l3seedRef)<<" and: \n"<<printseed(thisSharedSeedRef)
160  <<"\nadding ANOTHER seed ref: "<<thisSharedSeedRef.id().id()<<":"<<thisSharedSeedRef.key()<<" for this tracker track: "<<tk.id().id()<<":"<<tk.key();
161  // edm::LogError(metname)<<" we have a shared seed right there.";
162  allPossibleOrderedLx.push_back(thisSharedSeedRef);
163  }//seed is shared
164  }//loop all other existing seed for overlaps
165 
166  //now you have the full list of Lx objects that have seed this tracker track.
167  // order the list in pT of Lx objects
168  LogDebug(metname)<<"list of possible Lx objects for tracker track: "<<tk.id().id()<<":"<<tk.key()<<" before ordering\n"<<printvector(allPossibleOrderedLx);
169  sort(allPossibleOrderedLx.begin(),allPossibleOrderedLx.end(),seedRefBypT);
170  LogDebug(metname)<<"list of possible Lx objects for tracker track: "<<tk.id().id()<<":"<<tk.key()<<" after ordering\n"<<printvector(allPossibleOrderedLx);
171  // assign this tracker track to the highest pT Lx.
172  for (unsigned int iL=0;iL!=allPossibleOrderedLx.size();++iL){
173  SeedRef thisRef=allPossibleOrderedLx[iL];
174  pseudoRef ref = makePseudoRef(*thisRef);
175  LogDebug(metname)<<"seed ref: "<<thisRef.id().id()<<":"<<thisRef.key()<<" transcribe to pseudoref: "<<ref.first<<":"<<ref.second;
176  LXtoL3sMap::iterator f=LXtoL3s.find(ref);
177  if (f!=LXtoL3s.end()){
178  //there's already an entry. because of the prior ordering in pT of the tracker track refs
179  // the track ref already there *has* a higher pT: this one cannot compete and should be assigned to the next Lx;
180  LogDebug(metname)<<"this tracker track: "<<tk.id().id()<<":"<<tk.key()<<" ("<< tk->pt()<<")"
181  <<"\n cannot compete in pT with track: "<<f->second.first.id().id()<<":"<<f->second.first.key()<<" ("<<f->second.first->pt()<<")"
182  <<"\n already assigned to pseudo ref: "<<ref.first<<":"<<ref.second<<" which corresponds to seedRef: "<<f->second.second.id().id()<<":"<<f->second.second.key();
183  continue;
184  }else{
185  //there was no entry yet. make the assignement
186  LogDebug(metname)<<"this tracker track: "<<tk.id().id()<<":"<<tk.key()
187  <<" is assigned to pseudo ref: "<<ref.first<<":"<<ref.second<<" which corresponds to seedRef: "<<thisRef.id().id()<<":"<<thisRef.key();
188  LXtoL3s[ref] = std::make_pair(tk,thisRef);
189  //once assigned. break
190  break;
191  }
192  }//loop possible Lx for possible assignement
193  }//loop over ordered list of tracker track refs
194 
195 
196  //prepare the output
197  std::auto_ptr<TrackCollection> outTracks( new TrackCollection(LXtoL3s.size()));
198  std::auto_ptr<TrackExtraCollection> outTrackExtras( new TrackExtraCollection(LXtoL3s.size()));
199  reco::TrackExtraRefProd rTrackExtras = event.getRefBeforePut<TrackExtraCollection>();
200  std::auto_ptr<TrackingRecHitCollection> outRecHits( new TrackingRecHitCollection());
201  TrackingRecHitRefProd rHits = event.getRefBeforePut<TrackingRecHitCollection>();
202 
203  LogDebug(metname)<<"reading the map to make "<< LXtoL3s.size()<<"products.";
204  //fill the collection from the map
205  LXtoL3sMap::iterator f=LXtoL3s.begin();
206  unsigned int i=0;
207  for (;f!=LXtoL3s.end();++f,++i){
208 
209  LogDebug(metname)<<"copy the track over, and make ref to extra";
210  const Track & trk = *(f->second.first);
211  (*outTracks)[i] = Track(trk);
212  (*outTracks)[i].setExtra( TrackExtraRef(rTrackExtras,i));
213 
214  LogDebug(metname)<<"copy the trackExtra too, and change the seedref";
215  edm::RefToBase<TrajectorySeed> seedRef(f->second.second);
216  //do not use the copy constructor, otherwise the hit Ref are still the same
217  (*outTrackExtras)[i] = TrackExtra(
218  trk.outerPosition(), trk.outerMomentum(), trk.outerOk(),
219  trk.innerPosition(), trk.innerMomentum(), trk.innerOk(),
220  trk.outerStateCovariance(), trk.outerDetId(),
221  trk.innerStateCovariance(), trk.innerDetId(),
222  seedRef->direction(),seedRef
223  );
224 
225  LogDebug(metname)<<"copy the hits too";
226  unsigned int iRH=0;
227  for( trackingRecHit_iterator hit = trk.recHitsBegin(); hit != trk.recHitsEnd(); ++ hit,++iRH ) {
228  outRecHits->push_back((*hit)->clone());
229  (*outTrackExtras)[i].add( TrackingRecHitRef( rHits, iRH));
230  }
231  }
232 
233  LogDebug(metname)<<"made: "<<outTracks->size()<<" tracks, "<<outTrackExtras->size()<<" extras and "<<outRecHits->size()<<" rechits.";
234 
235  //put the collection in the event
236  LogDebug(metname)<<"loading...";
237  event.put(outTracks);
238  event.put(outTrackExtras);
239  event.put(outRecHits);
240  LogDebug(metname)<<" Event loaded"
241  <<"================================";
242 }
#define LogDebug(id)
PropagationDirection direction() const
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
std::pair< unsigned int, unsigned int > pseudoRef
string printseed(const L3TkMuonProducer::SeedRef &s)
const std::string metname
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:10
bool innerOk() const
return true if the innermost hit is valid
Definition: Track.h:39
edm::Ref< TrackExtraCollection > TrackExtraRef
persistent reference to a TrackExtra
Definition: TrackExtraFwd.h:13
std::string const & processName() const
std::string const & processName() const
Definition: Provenance.h:61
const math::XYZPoint & outerPosition() const
position of the outermost hit
Definition: Track.h:46
tuple s2
Definition: indexGen.py:106
bool sharedSeed(const L3MuonTrajectorySeed &s1, const L3MuonTrajectorySeed &s2)
const math::XYZPoint & innerPosition() const
position of the innermost hit
Definition: Track.h:41
std::string const & moduleLabel() const
std::string const & productInstanceName() const
recHitContainer::const_iterator const_iterator
edm::Ref< TrackingRecHitCollection > TrackingRecHitRef
persistent reference to a TrackingRecHit
CovarianceMatrix outerStateCovariance() const
outermost trajectory state curvilinear errors
Definition: Track.h:50
TypeID unwrappedTypeID() const
unsigned int outerDetId() const
DetId of the detector on which surface the outermost state is located.
Definition: Track.h:58
L3TkMuonProducer(const edm::ParameterSet &)
constructor with config
virtual void produce(edm::Event &, const edm::EventSetup &)
produce candidates
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:62
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
#define LogTrace(id)
std::map< pseudoRef, std::pair< reco::TrackRef, SeedRef > > LXtoL3sMap
std::vector< TrackExtra > TrackExtraCollection
collection of TrackExtra objects
Definition: TrackExtraFwd.h:9
edm::OwnVector< TrackingRecHit > TrackingRecHitCollection
collection of TrackingRecHits
const math::XYZVector & outerMomentum() const
momentum vector at the outermost hit position
Definition: Track.h:48
bool outerOk() const
return true if the outermost hit is valid
Definition: Track.h:37
tuple tracks
Definition: testEve_cfg.py:39
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:14
CovarianceMatrix innerStateCovariance() const
innermost trajectory state curvilinear errors
Definition: Track.h:52
key_type key() const
Accessor for product key.
Definition: Ref.h:266
range recHits() const
std::string const & moduleLabel() const
Definition: Provenance.h:60
virtual ~L3TkMuonProducer()
destructor
unsigned int nHits() const
const math::XYZVector & innerMomentum() const
momentum vector at the innermost hit position
Definition: Track.h:44
ProductID id() const
Accessor for product ID.
Definition: Ref.h:256
ProductIndex id() const
Definition: ProductID.h:38
std::string const & productInstanceName() const
Definition: Provenance.h:62
unsigned int innerDetId() const
DetId of the detector on which surface the innermost state is located.
Definition: Track.h:60
string printvector(const vector< TrackRef > &v)
ParameterSet const & parameterSet(Provenance const &provenance)
Definition: Provenance.cc:11
trackingRecHit_iterator recHitsEnd() const
Iterator to last hit on the track.
Definition: Track.h:64