Go to the documentation of this file.00001
00009
00010 #include "FWCore/Framework/interface/EDProducer.h"
00011 #include "FWCore/Framework/interface/Event.h"
00012 #include "FWCore/Framework/interface/EventSetup.h"
00013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00014 #include "DataFormats/Common/interface/Handle.h"
00015 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00016
00017 #include "RecoMuon/L3MuonProducer/src/L3TkMuonProducer.h"
00018 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidateFwd.h"
00019
00020 #include <string>
00021
00022 using namespace edm;
00023 using namespace std;
00024 using namespace reco;
00025
00027 L3TkMuonProducer::L3TkMuonProducer(const ParameterSet& parameterSet){
00028 LogTrace("Muon|RecoMuon|L3TkMuonProducer")<<" constructor called";
00029
00030
00031 theL3CollectionLabel = parameterSet.getParameter<InputTag>("InputObjects");
00032 produces<TrackCollection>();
00033 produces<TrackExtraCollection>();
00034 produces<TrackingRecHitCollection>();
00035 }
00036
00038 L3TkMuonProducer::~L3TkMuonProducer(){
00039 LogTrace("Muon|RecoMuon|L3TkMuonProducer")<<" L3TkMuonProducer destructor called";
00040 }
00041
00042 bool L3TkMuonProducer::sharedSeed(const L3MuonTrajectorySeed& s1,const L3MuonTrajectorySeed& s2){
00043
00044 if (s1.nHits()==0 || s2.nHits()==0) return false;
00045
00046 if (s1.nHits()!=s2.nHits()) return false;
00047 TrajectorySeed::range r1=s1.recHits();
00048 TrajectorySeed::range r2=s2.recHits();
00049 TrajectorySeed::const_iterator i1,i2;
00050 TrajectorySeed::const_iterator & i1_e=r1.second,&i2_e=r2.second;
00051 TrajectorySeed::const_iterator & i1_b=r1.first,&i2_b=r2.first;
00052
00053 if(i1_b->geographicalId() != i2_b->geographicalId()) return false;
00054
00055 for (i1=i1_b,i2=i2_b;i1!=i1_e,i2!=i2_e;++i1,++i2){
00056 if (!i1->sharesInput(&(*i2),TrackingRecHit::all)) return false;
00057 }
00058 return true;
00059 }
00060
00061 string printvector(const vector<TrackRef> & v){
00062 std::stringstream ss;
00063 for (unsigned int i=0;i!=v.size();++i) {
00064 if (i!=0) ss<<"\n";
00065 ss<<"track with ref: "<<v[i].id().id()<<":"<<v[i].key()
00066 <<" and pT: "<<v[i]->pt()
00067 <<" with seedRef: "<<v[i]->seedRef().id().id()<<":"<<v[i]->seedRef().key();
00068 }
00069 return ss.str();
00070 }
00071
00072 string printvector(const vector<L3TkMuonProducer::SeedRef> & v){
00073 std::stringstream ss;
00074 for (unsigned int i=0;i!=v.size();++i){
00075 if (i!=0) ss<<"\n";
00076 ss<<"seed ref: "<<v[i].id().id()<<":"<<v[i].key();
00077 if (v[i]->l2Track().isNull())
00078 ss<<" and pT: "<<v[i]->l1Particle()->pt()<<" of L1: "<<v[i]->l1Particle().id().id()<<":"<<v[i]->l1Particle().key();
00079 else
00080 ss<<" and pT: "<<v[i]->l2Track()->pt()<<" of L2: "<<v[i]->l2Track().id().id()<<":"<<v[i]->l2Track().key();
00081 }
00082 return ss.str();
00083 }
00084
00085 string printseed(const L3TkMuonProducer::SeedRef & s){
00086 std::stringstream ss;
00087 ss<<" seed ref: "<<s.id().id()<<":"<<s.key()<<" has "<< s->nHits()<<"rechits";
00088 TrajectorySeed::range r=s->recHits();
00089 TrajectorySeed::const_iterator it=r.first;
00090 for (;it!=r.second;++it)
00091 ss<<"\n detId: "<<it->geographicalId()<<" position: "<<it->localPosition()<<" and error: "<<it->localPositionError();
00092 return ss.str();
00093 }
00094
00096 void L3TkMuonProducer::produce(Event& event, const EventSetup& eventSetup){
00097 const string metname = "Muon|RecoMuon|L3TkMuonProducer";
00098
00099
00100 LogDebug(metname)<<" Taking the L3/GLB muons: "<<theL3CollectionLabel.label();
00101 Handle<TrackCollection> tracks;
00102 event.getByLabel(theL3CollectionLabel,tracks);
00103
00104
00105 LXtoL3sMap LXtoL3s;
00106
00107 unsigned int maxI = tracks->size();
00108 bool gotL3seeds=false;
00109 edm::Handle<L3MuonTrajectorySeedCollection> l3seeds;
00110
00111
00112 vector<TrackRef> orderedTrackTracks(maxI);
00113 for (unsigned int i=0;i!=maxI;i++) orderedTrackTracks[i]=TrackRef(tracks,i);
00114 LogDebug(metname)<<"vector of L3 tracks before ordering:\n"<<printvector(orderedTrackTracks);
00115
00116 sort(orderedTrackTracks.begin(),orderedTrackTracks.end(),trackRefBypT);
00117 LogDebug(metname)<<"vector of L3 tracks after ordering:\n"<<printvector(orderedTrackTracks);
00118
00119 for (unsigned int i=0;i!=maxI;i++) {
00120 TrackRef & tk=orderedTrackTracks[i];
00121 SeedRef l3seedRef = tk->seedRef().castTo<SeedRef>();
00122
00123 vector<SeedRef> allPossibleOrderedLx;
00124
00125 allPossibleOrderedLx.push_back(l3seedRef);
00126 LogDebug(metname)<<"adding the seed ref: "<<l3seedRef.id().id()<<":"<<l3seedRef.key()<<" for this tracker track: "<<tk.id().id()<<":"<<tk.key();
00127
00128
00129
00130 if (!gotL3seeds){
00131
00132 const edm::Provenance & seedsProv=event.getProvenance(l3seedRef.id());
00133 edm::InputTag l3seedsTag(seedsProv.moduleLabel(), seedsProv.productInstanceName(), seedsProv.processName());
00134 event.getByLabel(l3seedsTag, l3seeds);
00135 gotL3seeds=true;
00136 LogDebug(metname)<<"got seeds handle from: "<<l3seedsTag;
00137 }
00138
00139 for (unsigned int iS=0;iS!=l3seeds->size();++iS){
00140 const L3MuonTrajectorySeed & seed = (*l3seeds)[iS];
00141 const L3MuonTrajectorySeed & thisSeed = *l3seedRef;
00142 if (l3seedRef.key()==iS) continue;
00143
00144 if (sharedSeed(seed,thisSeed)){
00145 SeedRef thisSharedSeedRef(l3seeds,iS);
00146 LogDebug(metname)<<"shared seeds: \n"<<printseed(l3seedRef)<<" and: \n"<<printseed(thisSharedSeedRef)
00147 <<"\nadding ANOTHER seed ref: "<<thisSharedSeedRef.id().id()<<":"<<thisSharedSeedRef.key()<<" for this tracker track: "<<tk.id().id()<<":"<<tk.key();
00148
00149 allPossibleOrderedLx.push_back(thisSharedSeedRef);
00150 }
00151 }
00152
00153
00154
00155 LogDebug(metname)<<"list of possible Lx objects for tracker track: "<<tk.id().id()<<":"<<tk.key()<<" before ordering\n"<<printvector(allPossibleOrderedLx);
00156 sort(allPossibleOrderedLx.begin(),allPossibleOrderedLx.end(),seedRefBypT);
00157 LogDebug(metname)<<"list of possible Lx objects for tracker track: "<<tk.id().id()<<":"<<tk.key()<<" after ordering\n"<<printvector(allPossibleOrderedLx);
00158
00159 for (unsigned int iL=0;iL!=allPossibleOrderedLx.size();++iL){
00160 SeedRef thisRef=allPossibleOrderedLx[iL];
00161 pseudoRef ref = makePseudoRef(*thisRef);
00162 LogDebug(metname)<<"seed ref: "<<thisRef.id().id()<<":"<<thisRef.key()<<" transcribe to pseudoref: "<<ref.first<<":"<<ref.second;
00163 LXtoL3sMap::iterator f=LXtoL3s.find(ref);
00164 if (f!=LXtoL3s.end()){
00165
00166
00167 LogDebug(metname)<<"this tracker track: "<<tk.id().id()<<":"<<tk.key()<<" ("<< tk->pt()<<")"
00168 <<"\n cannot compete in pT with track: "<<f->second.first.id().id()<<":"<<f->second.first.key()<<" ("<<f->second.first->pt()<<")"
00169 <<"\n already assigned to pseudo ref: "<<ref.first<<":"<<ref.second<<" which corresponds to seedRef: "<<f->second.second.id().id()<<":"<<f->second.second.key();
00170 continue;
00171 }else{
00172
00173 LogDebug(metname)<<"this tracker track: "<<tk.id().id()<<":"<<tk.key()
00174 <<" is assigned to pseudo ref: "<<ref.first<<":"<<ref.second<<" which corresponds to seedRef: "<<thisRef.id().id()<<":"<<thisRef.key();
00175 LXtoL3s[ref] = std::make_pair(tk,thisRef);
00176
00177 break;
00178 }
00179 }
00180 }
00181
00182
00183
00184 std::auto_ptr<TrackCollection> outTracks( new TrackCollection(LXtoL3s.size()));
00185 std::auto_ptr<TrackExtraCollection> outTrackExtras( new TrackExtraCollection(LXtoL3s.size()));
00186 reco::TrackExtraRefProd rTrackExtras = event.getRefBeforePut<TrackExtraCollection>();
00187 std::auto_ptr<TrackingRecHitCollection> outRecHits( new TrackingRecHitCollection());
00188 TrackingRecHitRefProd rHits = event.getRefBeforePut<TrackingRecHitCollection>();
00189
00190 LogDebug(metname)<<"reading the map to make "<< LXtoL3s.size()<<"products.";
00191
00192 LXtoL3sMap::iterator f=LXtoL3s.begin();
00193 unsigned int i=0;
00194 for (;f!=LXtoL3s.end();++f,++i){
00195
00196 LogDebug(metname)<<"copy the track over, and make ref to extra";
00197 const Track & trk = *(f->second.first);
00198 (*outTracks)[i] = Track(trk);
00199 (*outTracks)[i].setExtra( TrackExtraRef(rTrackExtras,i));
00200
00201 LogDebug(metname)<<"copy the trackExtra too, and change the seedref";
00202 edm::RefToBase<TrajectorySeed> seedRef(f->second.second);
00203
00204 (*outTrackExtras)[i] = TrackExtra(
00205 trk.outerPosition(), trk.outerMomentum(), trk.outerOk(),
00206 trk.innerPosition(), trk.innerMomentum(), trk.innerOk(),
00207 trk.outerStateCovariance(), trk.outerDetId(),
00208 trk.innerStateCovariance(), trk.innerDetId(),
00209 seedRef->direction(),seedRef
00210 );
00211
00212 LogDebug(metname)<<"copy the hits too";
00213 unsigned int iRH=0;
00214 for( trackingRecHit_iterator hit = trk.recHitsBegin(); hit != trk.recHitsEnd(); ++ hit,++iRH ) {
00215 outRecHits->push_back((*hit)->clone());
00216 (*outTrackExtras)[i].add( TrackingRecHitRef( rHits, iRH));
00217 }
00218 }
00219
00220 LogDebug(metname)<<"made: "<<outTracks->size()<<" tracks, "<<outTrackExtras->size()<<" extras and "<<outRecHits->size()<<" rechits.";
00221
00222
00223 LogDebug(metname)<<"loading...";
00224 event.put(outTracks);
00225 event.put(outTrackExtras);
00226 event.put(outRecHits);
00227 LogDebug(metname)<<" Event loaded"
00228 <<"================================";
00229 }