00001
00002
00003
00004
00005
00013
00014
00015
00016
00017
00018
00019
00020 #include "FWCore/Framework/interface/Frameworkfwd.h"
00021
00022 #include "DataFormats/Math/interface/deltaR.h"
00023
00024 #include "DataFormats/Common/interface/ValueMap.h"
00025 #include "DataFormats/Common/interface/View.h"
00026 #include "DataFormats/Common/interface/Ptr.h"
00027
00028 #include "DataFormats/L1Trigger/interface/L1MuonParticleFwd.h"
00029 #include "DataFormats/L1Trigger/interface/L1MuonParticle.h"
00030
00031 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00032 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00033 #include "DataFormats/TrackReco/interface/Track.h"
00034 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidate.h"
00035 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidateFwd.h"
00036 #include "DataFormats/MuonReco/interface/MuonFwd.h"
00037 #include "DataFormats/MuonReco/interface/Muon.h"
00038 #include "DataFormats/TrajectorySeed/interface/TrajectorySeed.h"
00039
00040
00041 #include "DataFormats/L1Trigger/interface/L1MuonParticleFwd.h"
00042 #include "DataFormats/TrackReco/interface/Track.h"
00043 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00044 #include "DataFormats/MuonSeed/interface/L2MuonTrajectorySeedCollection.h"
00045 #include "DataFormats/Common/interface/AssociationMap.h"
00046 #include "DataFormats/Common/interface/OneToMany.h"
00047 #include "DataFormats/Common/interface/Handle.h"
00048 #include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h"
00049
00050
00051 #include "DataFormats/MuonSeed/interface/L2MuonTrajectorySeed.h"
00052 #include "DataFormats/MuonSeed/interface/L2MuonTrajectorySeedCollection.h"
00053 #include "DataFormats/MuonSeed/interface/L3MuonTrajectorySeed.h"
00054 #include "DataFormats/MuonSeed/interface/L3MuonTrajectorySeedCollection.h"
00055
00056 #include "FWCore/Framework/interface/EDProducer.h"
00057 #include "FWCore/Framework/interface/ESHandle.h"
00058 #include "FWCore/Framework/interface/Event.h"
00059 #include "FWCore/Framework/interface/MakerMacros.h"
00060 #include "FWCore/Common/interface/TriggerNames.h"
00061 #include "FWCore/MessageService/interface/MessageLogger.h"
00062 #include "FWCore/Utilities/interface/InputTag.h"
00063 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00064
00065 #include "CommonTools/Utils/interface/StringCutObjectSelector.h"
00066 #include "MuonAnalysis/MuonAssociators/interface/PropagateToMuon.h"
00067 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
00068
00069
00070
00071
00072
00073
00074 class TriggerMatcherToHLTDebug: public edm::EDProducer {
00075
00076 public:
00077
00078 explicit TriggerMatcherToHLTDebug(const edm::ParameterSet &pset);
00079
00081 virtual ~TriggerMatcherToHLTDebug();
00082
00083
00084 void produce(edm::Event & event, const edm::EventSetup& eventSetup) override;
00085 void beginRun(const edm::Run &run, const edm::EventSetup &eventSetup) override;
00086
00087 private:
00088 edm::InputTag tagTag_, l1Tag_;
00089 PropagateToMuon l1matcher_;
00090
00091 std::string metname;
00092
00093
00094 double deltaR_;
00095
00096
00097 int minL1Quality_;
00098
00099
00100 edm::InputTag beamspotTag_ ;
00101 int min_N_L2;
00102 double max_Eta_L2;
00103 int min_Nhits_L2;
00104 double max_Dr_L2;
00105 double max_Dz_L2;
00106 double min_Pt_L2;
00107 double nsigma_Pt_L2;
00108
00109
00110 int min_N_L3;
00111 double max_Eta_L3;
00112 int min_Nhits_L3;
00113 double max_Dr_L3;
00114 double max_Dz_L3;
00115 double min_Pt_L3;
00116 double nsigma_Pt_L3;
00117
00118 edm::InputTag theL2SeedsLabel;
00119 edm::InputTag theL2MuonsLabel;
00120 edm::InputTag theL3SeedsLabel;
00121 edm::InputTag theL3TkTracksLabel;
00122 edm::InputTag theL3MuonsLabel;
00123 edm::InputTag seedMapTag_;
00124
00125
00126 typedef edm::AssociationMap<edm::OneToMany<std::vector<L2MuonTrajectorySeed>, std::vector<L2MuonTrajectorySeed> > > SeedMap;
00127
00128
00130 template<typename T>
00131 void storeValueMap(edm::Event &iEvent,
00132 const edm::Handle<edm::View<reco::Muon> > & handle,
00133 const std::vector<T> & values,
00134 const std::string & label) const ;
00135
00136 };
00137
00138 using namespace std;
00139 using namespace edm;
00140 using namespace l1extra;
00141 using namespace reco;
00142
00143
00144 TriggerMatcherToHLTDebug::TriggerMatcherToHLTDebug(const edm::ParameterSet &pset):
00145 tagTag_(pset.getParameter<edm::InputTag>("tags")),
00146 l1Tag_(pset.getParameter<edm::InputTag>("l1s")),
00147 l1matcher_(pset.getParameter<edm::ParameterSet>("l1matcherConfig")),
00148 deltaR_(pset.getParameter<double>("deltaR")),
00149 minL1Quality_(pset.getParameter<int32_t>("MinL1Quality")),
00150 beamspotTag_(pset.getParameter<edm::InputTag>("BeamSpotTag")),
00151 min_N_L2(pset.getParameter<int> ("MinN_L2")),
00152 max_Eta_L2(pset.getParameter<double> ("MaxEta_L2")),
00153 min_Nhits_L2(pset.getParameter<int> ("MinNhits_L2")),
00154 max_Dr_L2(pset.getParameter<double> ("MaxDr_L2")),
00155 max_Dz_L2(pset.getParameter<double> ("MaxDz_L2")),
00156 min_Pt_L2(pset.getParameter<double> ("MinPt_L2")),
00157 nsigma_Pt_L2(pset.getParameter<double> ("NSigmaPt_L2")),
00158 min_N_L3(pset.getParameter<int> ("MinN_L3")),
00159 max_Eta_L3(pset.getParameter<double> ("MaxEta_L3")),
00160 min_Nhits_L3(pset.getParameter<int> ("MinNhits_L3")),
00161 max_Dr_L3(pset.getParameter<double> ("MaxDr_L3")),
00162 max_Dz_L3(pset.getParameter<double> ("MaxDz_L3")),
00163 min_Pt_L3(pset.getParameter<double> ("MinPt_L3")),
00164 nsigma_Pt_L3(pset.getParameter<double> ("NSigmaPt_L3")),
00165 seedMapTag_(pset.getParameter<edm::InputTag >("SeedMapTag"))
00166 {
00167
00168
00169 theL2SeedsLabel = pset.getParameter<InputTag>("L2Seeds_Collection");
00170 theL2MuonsLabel = pset.getParameter<InputTag>("L2Muons_Collection");
00171 theL3SeedsLabel = pset.getParameter<InputTag>("L3Seeds_Collection");
00172 theL3TkTracksLabel = pset.getParameter<InputTag>("L3TkTracks_Collection");
00173 theL3MuonsLabel = pset.getParameter<InputTag>("L3Muons_Collection");
00174
00175
00176 metname = "TriggerMatcherToHLTDebug";
00177
00178 produces<edm::ValueMap<int> > ("propagatesToM2");
00179 produces<edm::ValueMap<int> > ("hasL1Particle");
00180 produces<edm::ValueMap<int> > ("hasL1Filtered");
00181 produces<edm::ValueMap<int> > ("hasL2Seed");
00182 produces<edm::ValueMap<int> > ("hasL2Muon");
00183 produces<edm::ValueMap<int> > ("hasL2MuonFiltered");
00184 produces<edm::ValueMap<int> > ("hasL3Seed");
00185 produces<edm::ValueMap<int> > ("hasL3Track");
00186 produces<edm::ValueMap<int> > ("hasL3Muon");
00187 produces<edm::ValueMap<int> > ("hasL3MuonFiltered");
00188
00189 produces<edm::ValueMap<reco::CandidatePtr> > ("l1Candidate");
00190 produces<edm::ValueMap<reco::CandidatePtr> > ("l2Candidate");
00191 produces<edm::ValueMap<reco::CandidatePtr> > ("l3Candidate");
00192 }
00193
00194
00195
00196
00197 TriggerMatcherToHLTDebug::~TriggerMatcherToHLTDebug() {}
00198
00199
00200 void TriggerMatcherToHLTDebug::produce(Event &event, const EventSetup &eventSetup) {
00201
00202 Handle<View<reco::Muon> > muons;
00203 event.getByLabel(tagTag_,muons);
00204
00205 Handle<l1extra::L1MuonParticleCollection> L1Muons;
00206 event.getByLabel(l1Tag_,L1Muons);
00207
00208 Handle<L2MuonTrajectorySeedCollection> L2Seeds;
00209 event.getByLabel(theL2SeedsLabel,L2Seeds);
00210
00211 Handle<RecoChargedCandidateCollection> L2Muons;
00212 event.getByLabel(theL2MuonsLabel,L2Muons);
00213
00214 Handle<L3MuonTrajectorySeedCollection> L3Seeds;
00215 event.getByLabel(theL3SeedsLabel,L3Seeds);
00216
00217 Handle<reco::TrackCollection> L3TkTracks;
00218 event.getByLabel(theL3TkTracksLabel,L3TkTracks);
00219
00220 Handle<RecoChargedCandidateCollection> L3Muons;
00221 event.getByLabel(theL3MuonsLabel,L3Muons);
00222
00223
00224 BeamSpot beamSpot;
00225 Handle<BeamSpot> recoBeamSpotHandle;
00226 event.getByLabel(beamspotTag_,recoBeamSpotHandle);
00227 beamSpot = *recoBeamSpotHandle;
00228
00229
00230 edm::Handle<SeedMap> seedMapHandle;
00231 event.getByLabel(seedMapTag_, seedMapHandle);
00232
00233
00234 size_t nmu = muons->size();
00235 std::vector<int> propagatesToM2(nmu), hasL1Particle(nmu), hasL1Filtered(nmu);
00236 std::vector<int> hasL2Seed(nmu), hasL2Muon(nmu), hasL2MuonFiltered(nmu);
00237 std::vector<int> hasL3Seed(nmu), hasL3Track(nmu), hasL3TrackFiltered(nmu), hasL3Muon(nmu), hasL3MuonFiltered(nmu);
00238 std::vector<reco::CandidatePtr> l1ptr(nmu), l2ptr(nmu), l3ptr(nmu);
00239
00240 for (size_t i = 0; i < nmu; ++i) {
00241 const reco::Muon &mu = (*muons)[i];
00242
00243
00244 TrajectoryStateOnSurface stateAtMB2 = l1matcher_.extrapolate(mu);
00245 if (!stateAtMB2.isValid()) continue;
00246 propagatesToM2[i] = 1;
00247
00248 double etaTk = stateAtMB2.globalPosition().eta();
00249 double phiTk = stateAtMB2.globalPosition().phi();
00250 l1extra::L1MuonParticleCollection::const_iterator it;
00251 vector<l1extra::L1MuonParticleRef>::const_iterator itMu3;
00252 L2MuonTrajectorySeedCollection::const_iterator iSeed;
00253 L3MuonTrajectorySeedCollection::const_iterator iSeedL3;
00254 RecoChargedCandidateCollection::const_iterator iL2Muon;
00255 reco::TrackCollection::const_iterator tktrackL3;
00256 RecoChargedCandidateCollection::const_iterator iL3Muon;
00257
00258 reco::CandidatePtr thisL1, thisL2, thisL3;
00259 for(it = L1Muons->begin(); it != L1Muons->end(); ++it) {
00260
00261 const L1MuGMTExtendedCand muonCand = (*it).gmtMuonCand();
00262 unsigned int quality = muonCand.quality();
00263
00264 double L1phi =(*it).phi();
00265 double L1eta =(*it).eta();
00266 double L1pt =(*it).pt();
00267 double dR=deltaR(etaTk,phiTk,L1eta,L1phi);
00268
00269
00270 if (dR >= deltaR_) continue;
00271 thisL1 = reco::CandidatePtr(L1Muons, it - L1Muons->begin());
00272 if (!hasL1Particle[i]) l1ptr[i] = thisL1;
00273 hasL1Particle[i]++;
00274
00275 if ((quality <= 3) || (L1pt<7)) continue;
00276 if (!hasL1Filtered[i]) l1ptr[i] = thisL1;
00277 hasL1Filtered[i]++;
00278
00279 if(!L2Seeds.isValid()) continue;
00280
00281 for( iSeed = L2Seeds->begin(); iSeed != L2Seeds->end(); ++iSeed) {
00282
00283 l1extra::L1MuonParticleRef l1FromSeed = iSeed->l1Particle();
00284 if (l1FromSeed.id() != L1Muons.id()) throw cms::Exception("CorruptData") << "You're using a different L1 collection than the one used by L2 seeds.\n";
00285 if (l1FromSeed.key() != thisL1.key()) continue;
00286 if (!hasL2Seed[i]) l1ptr[i] = thisL1;
00287 hasL2Seed[i]++;
00288
00289 if(!L2Muons.isValid()) continue;
00290
00291 for( iL2Muon = L2Muons->begin(); iL2Muon != L2Muons->end(); ++iL2Muon) {
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303 const edm::RefVector<L2MuonTrajectorySeedCollection>& seeds = (*seedMapHandle)[iL2Muon->track()->seedRef().castTo<edm::Ref<L2MuonTrajectorySeedCollection> >()];
00304
00305 for(size_t jjj=0; jjj<seeds.size(); jjj++){
00306
00307 if(seeds[jjj]->l1Particle()!= l1FromSeed) continue;
00308
00309 }
00310
00311
00312 thisL2 = reco::CandidatePtr(L2Muons, iL2Muon - L2Muons->begin()) ;
00313 if (!hasL2Muon[i]) { l1ptr[i] = thisL1; l2ptr[i] = thisL2; }
00314 hasL2Muon[i]++;
00315
00316 LogTrace(metname) <<"L2MUON TROVATO!"<<endl;
00317 const reco::Track & L2Track = *iL2Muon->track();
00318 double Eta_L2= L2Track.eta();
00319 double Pt_L2= L2Track.pt();
00320 int nValidHits_L2= L2Track.numberOfValidHits();
00321 double BSPos_L2 = L2Track.dxy(beamSpot.position());
00322 double dz_L2 =L2Track.dz();
00323 double err0_L2 = L2Track.error(0);
00324 double abspar0_L2 = fabs(L2Track.parameter(0));
00325 double ptLx_L2 = Pt_L2;
00326 if (abspar0_L2>0) ptLx_L2 += nsigma_Pt_L2*err0_L2/abspar0_L2*Pt_L2;
00327
00328
00329 bool passFilter = (((fabs(Eta_L2))<=max_Eta_L2)&&(nValidHits_L2>=min_Nhits_L2)&&((fabs(BSPos_L2))<=max_Dr_L2)&&((fabs(dz_L2))<=max_Dz_L2)&&(ptLx_L2>=min_Pt_L2));
00330 if (!passFilter) continue;
00331 if (!hasL2MuonFiltered[i]) { l1ptr[i] = thisL1; l2ptr[i] = thisL2; }
00332 hasL2MuonFiltered[i]++;
00333
00334 const reco::TrackRef L2FilteredRef = iL2Muon->track();
00335
00336
00337 if (!L3Seeds.isValid()) continue;
00338 for (iSeedL3 = L3Seeds->begin(); iSeedL3!= L3Seeds->end(); ++iSeedL3){
00339
00340 TrackRef staTrack = iSeedL3->l2Track();
00341 if (staTrack!=L2FilteredRef) continue;
00342 if (!hasL3Seed[i]) { l1ptr[i] = thisL1; l2ptr[i] = thisL2; }
00343 hasL3Seed[i]++;
00344
00345 if (!L3TkTracks.isValid()) continue;
00346 for (tktrackL3 = L3TkTracks->begin(); tktrackL3!= L3TkTracks->end(); ++tktrackL3){
00347
00348 edm::Ref<L3MuonTrajectorySeedCollection> l3seedRef = tktrackL3->seedRef().castTo<edm::Ref<L3MuonTrajectorySeedCollection> >();
00349 TrackRef staTrack2 = l3seedRef->l2Track();
00350
00351 if (staTrack2!=L2FilteredRef) continue;
00352 if (!hasL3Track[i]) { l1ptr[i] = thisL1; l2ptr[i] = thisL2; }
00353 hasL3Track[i]++;
00354
00355 if (!L3Muons.isValid()) continue;
00356 for (iL3Muon = L3Muons->begin(); iL3Muon != L3Muons->end(); ++iL3Muon) {
00357
00358 edm::Ref<L3MuonTrajectorySeedCollection> l3seedRef2 = iL3Muon->track()->seedRef().castTo<edm::Ref<L3MuonTrajectorySeedCollection> >();
00359 TrackRef staTrack3 = l3seedRef2->l2Track();
00360
00361 if (staTrack3!=L2FilteredRef) continue;
00362 thisL3 = reco::CandidatePtr(L3Muons, iL3Muon - L3Muons->begin());
00363
00364 if (!hasL3Muon[i]) { l1ptr[i] = thisL1; l2ptr[i] = thisL2; l3ptr[i] = thisL3; }
00365 hasL3Muon[i]++;
00366
00367 const reco::Track &L3Track = *iL3Muon->track();
00368 double Eta_L3= L3Track.eta();
00369 double Pt_L3= L3Track.pt();
00370 int nValidHits_L3= L3Track.numberOfValidHits();
00371 double BSPos_L3 = L3Track.dxy(beamSpot.position());
00372 double dz_L3 =L3Track.dz();
00373 double err0_L3 = L3Track.error(0);
00374 double abspar0_L3 = fabs(L3Track.parameter(0));
00375 double ptLx_L3 = Pt_L3;
00376
00377 if (abspar0_L3>0) ptLx_L3 += nsigma_Pt_L3*err0_L3/abspar0_L3*Pt_L3;
00378
00379 if(((fabs(Eta_L3))<=max_Eta_L3)&&(nValidHits_L3>=min_Nhits_L3)&&((fabs(BSPos_L3))<=max_Dr_L3)&&((fabs(dz_L3))<=max_Dz_L3)&&(ptLx_L3>=min_Pt_L3)){
00380
00381 if (!hasL3MuonFiltered[i]) { l1ptr[i] = thisL1; l2ptr[i] = thisL2; l3ptr[i] = thisL3; }
00382 hasL3MuonFiltered[i]++;
00383
00384 }
00385 }
00386 }
00387 }
00388 }
00389 }
00390 }
00391 }
00392 storeValueMap<int>(event, muons, propagatesToM2, "propagatesToM2");
00393 storeValueMap<int>(event, muons, hasL1Particle, "hasL1Particle");
00394 storeValueMap<int>(event, muons, hasL1Filtered, "hasL1Filtered");
00395 storeValueMap<int>(event, muons, hasL2Seed, "hasL2Seed");
00396 storeValueMap<int>(event, muons, hasL2Muon, "hasL2Muon");
00397 storeValueMap<int>(event, muons, hasL2MuonFiltered, "hasL2MuonFiltered");
00398 storeValueMap<int>(event, muons, hasL3Seed, "hasL3Seed");
00399 storeValueMap<int>(event, muons, hasL3Track, "hasL3Track");
00400 storeValueMap<int>(event, muons, hasL3Muon, "hasL3Muon");
00401 storeValueMap<int>(event, muons, hasL3MuonFiltered, "hasL3MuonFiltered");
00402 storeValueMap<reco::CandidatePtr>(event, muons, l1ptr, "l1Candidate");
00403 storeValueMap<reco::CandidatePtr>(event, muons, l2ptr, "l2Candidate");
00404 storeValueMap<reco::CandidatePtr>(event, muons, l3ptr, "l3Candidate");
00405 }
00406
00407 void
00408 TriggerMatcherToHLTDebug::beginRun(const edm::Run &iRun, const edm::EventSetup &iSetup) {
00409 l1matcher_.init(iSetup);
00410 }
00411
00412 template<typename T>
00413 void
00414 TriggerMatcherToHLTDebug::storeValueMap(edm::Event &iEvent,
00415 const edm::Handle<edm::View<reco::Muon> > & handle,
00416 const std::vector<T> & values,
00417 const std::string & label) const {
00418 using namespace edm; using namespace std;
00419 auto_ptr<ValueMap<T> > valMap(new ValueMap<T>());
00420 typename edm::ValueMap<T>::Filler filler(*valMap);
00421 filler.insert(handle, values.begin(), values.end());
00422 filler.fill();
00423 iEvent.put(valMap, label);
00424 }
00425
00426
00427
00428
00429 DEFINE_FWK_MODULE(TriggerMatcherToHLTDebug);