File indexing completed on 2024-09-07 04:37:14
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #include "FWCore/Framework/interface/Frameworkfwd.h"
0019
0020 #include "DataFormats/Math/interface/deltaR.h"
0021
0022 #include "DataFormats/Common/interface/ValueMap.h"
0023 #include "DataFormats/Common/interface/View.h"
0024 #include "DataFormats/Common/interface/Ptr.h"
0025
0026 #include "DataFormats/L1Trigger/interface/L1MuonParticleFwd.h"
0027 #include "DataFormats/L1Trigger/interface/L1MuonParticle.h"
0028
0029 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
0030 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0031 #include "DataFormats/TrackReco/interface/Track.h"
0032 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidate.h"
0033 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidateFwd.h"
0034 #include "DataFormats/MuonReco/interface/MuonFwd.h"
0035 #include "DataFormats/MuonReco/interface/Muon.h"
0036 #include "DataFormats/TrajectorySeed/interface/TrajectorySeed.h"
0037
0038
0039 #include "DataFormats/L1Trigger/interface/L1MuonParticleFwd.h"
0040 #include "DataFormats/TrackReco/interface/Track.h"
0041 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0042 #include "DataFormats/Common/interface/AssociationMap.h"
0043 #include "DataFormats/Common/interface/OneToMany.h"
0044 #include "DataFormats/Common/interface/Handle.h"
0045 #include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h"
0046
0047 #include "DataFormats/MuonSeed/interface/L2MuonTrajectorySeed.h"
0048 #include "DataFormats/MuonSeed/interface/L2MuonTrajectorySeedCollection.h"
0049 #include "DataFormats/MuonSeed/interface/L3MuonTrajectorySeed.h"
0050 #include "DataFormats/MuonSeed/interface/L3MuonTrajectorySeedCollection.h"
0051
0052 #include "FWCore/Framework/interface/stream/EDProducer.h"
0053 #include "FWCore/Framework/interface/ESHandle.h"
0054 #include "FWCore/Framework/interface/Event.h"
0055 #include "FWCore/Framework/interface/MakerMacros.h"
0056 #include "FWCore/Common/interface/TriggerNames.h"
0057 #include "FWCore/Utilities/interface/InputTag.h"
0058 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0059
0060 #include "CommonTools/Utils/interface/StringCutObjectSelector.h"
0061 #include "MuonAnalysis/MuonAssociators/interface/PropagateToMuonSetup.h"
0062 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
0063
0064 class TriggerMatcherToHLTDebug : public edm::stream::EDProducer<> {
0065 public:
0066
0067 explicit TriggerMatcherToHLTDebug(const edm::ParameterSet &pset);
0068
0069
0070 ~TriggerMatcherToHLTDebug() override;
0071
0072
0073 void produce(edm::Event &event, const edm::EventSetup &eventSetup) override;
0074
0075 private:
0076 typedef edm::AssociationMap<edm::OneToMany<std::vector<L2MuonTrajectorySeed>, std::vector<L2MuonTrajectorySeed> > >
0077 SeedMap;
0078
0079 edm::EDGetTokenT<edm::View<reco::Muon> > tagToken_;
0080 edm::EDGetTokenT<l1extra::L1MuonParticleCollection> l1Token_;
0081 PropagateToMuonSetup const l1matcherSetup_;
0082
0083 std::string metname;
0084
0085
0086 double deltaR_;
0087
0088
0089 int minL1Quality_;
0090
0091
0092 edm::EDGetTokenT<reco::BeamSpot> beamspotToken_;
0093 int min_N_L2;
0094 double max_Eta_L2;
0095 int min_Nhits_L2;
0096 double max_Dr_L2;
0097 double max_Dz_L2;
0098 double min_Pt_L2;
0099 double nsigma_Pt_L2;
0100
0101
0102 int min_N_L3;
0103 double max_Eta_L3;
0104 int min_Nhits_L3;
0105 double max_Dr_L3;
0106 double max_Dz_L3;
0107 double min_Pt_L3;
0108 double nsigma_Pt_L3;
0109
0110 edm::EDGetTokenT<L2MuonTrajectorySeedCollection> theL2SeedsToken_;
0111 edm::EDGetTokenT<reco::RecoChargedCandidateCollection> theL2MuonsToken_;
0112 edm::EDGetTokenT<L3MuonTrajectorySeedCollection> theL3SeedsToken_;
0113 edm::EDGetTokenT<reco::TrackCollection> theL3TkTracksToken_;
0114 edm::EDGetTokenT<reco::RecoChargedCandidateCollection> theL3MuonsToken_;
0115 edm::EDGetTokenT<SeedMap> seedMapToken_;
0116
0117
0118 template <typename T>
0119 void storeValueMap(edm::Event &iEvent,
0120 const edm::Handle<edm::View<reco::Muon> > &handle,
0121 const std::vector<T> &values,
0122 const std::string &label) const;
0123 };
0124
0125 using namespace std;
0126 using namespace edm;
0127 using namespace l1extra;
0128 using namespace reco;
0129
0130
0131 TriggerMatcherToHLTDebug::TriggerMatcherToHLTDebug(const edm::ParameterSet &pset)
0132 : tagToken_(consumes<View<reco::Muon> >(pset.getParameter<edm::InputTag>("tags"))),
0133 l1Token_(consumes<L1MuonParticleCollection>(pset.getParameter<edm::InputTag>("l1s"))),
0134 l1matcherSetup_(pset.getParameter<edm::ParameterSet>("l1matcherConfig"), consumesCollector()),
0135 deltaR_(pset.getParameter<double>("deltaR")),
0136 minL1Quality_(pset.getParameter<int32_t>("MinL1Quality")),
0137 beamspotToken_(consumes<BeamSpot>(pset.getParameter<edm::InputTag>("BeamSpotTag"))),
0138 min_N_L2(pset.getParameter<int>("MinN_L2")),
0139 max_Eta_L2(pset.getParameter<double>("MaxEta_L2")),
0140 min_Nhits_L2(pset.getParameter<int>("MinNhits_L2")),
0141 max_Dr_L2(pset.getParameter<double>("MaxDr_L2")),
0142 max_Dz_L2(pset.getParameter<double>("MaxDz_L2")),
0143 min_Pt_L2(pset.getParameter<double>("MinPt_L2")),
0144 nsigma_Pt_L2(pset.getParameter<double>("NSigmaPt_L2")),
0145 min_N_L3(pset.getParameter<int>("MinN_L3")),
0146 max_Eta_L3(pset.getParameter<double>("MaxEta_L3")),
0147 min_Nhits_L3(pset.getParameter<int>("MinNhits_L3")),
0148 max_Dr_L3(pset.getParameter<double>("MaxDr_L3")),
0149 max_Dz_L3(pset.getParameter<double>("MaxDz_L3")),
0150 min_Pt_L3(pset.getParameter<double>("MinPt_L3")),
0151 nsigma_Pt_L3(pset.getParameter<double>("NSigmaPt_L3")),
0152 seedMapToken_(consumes<SeedMap>(pset.getParameter<edm::InputTag>("SeedMapTag"))) {
0153 theL2SeedsToken_ = consumes<L2MuonTrajectorySeedCollection>(pset.getParameter<InputTag>("L2Seeds_Collection"));
0154 theL2MuonsToken_ = consumes<RecoChargedCandidateCollection>(pset.getParameter<InputTag>("L2Muons_Collection"));
0155 theL3SeedsToken_ = consumes<L3MuonTrajectorySeedCollection>(pset.getParameter<InputTag>("L3Seeds_Collection"));
0156 theL3TkTracksToken_ = consumes<TrackCollection>(pset.getParameter<InputTag>("L3TkTracks_Collection"));
0157 theL3MuonsToken_ = consumes<RecoChargedCandidateCollection>(pset.getParameter<InputTag>("L3Muons_Collection"));
0158
0159 metname = "TriggerMatcherToHLTDebug";
0160
0161 produces<edm::ValueMap<int> >("propagatesToM2");
0162 produces<edm::ValueMap<int> >("hasL1Particle");
0163 produces<edm::ValueMap<int> >("hasL1Filtered");
0164 produces<edm::ValueMap<int> >("hasL2Seed");
0165 produces<edm::ValueMap<int> >("hasL2Muon");
0166 produces<edm::ValueMap<int> >("hasL2MuonFiltered");
0167 produces<edm::ValueMap<int> >("hasL3Seed");
0168 produces<edm::ValueMap<int> >("hasL3Track");
0169 produces<edm::ValueMap<int> >("hasL3Muon");
0170 produces<edm::ValueMap<int> >("hasL3MuonFiltered");
0171
0172 produces<edm::ValueMap<reco::CandidatePtr> >("l1Candidate");
0173 produces<edm::ValueMap<reco::CandidatePtr> >("l2Candidate");
0174 produces<edm::ValueMap<reco::CandidatePtr> >("l3Candidate");
0175 }
0176
0177
0178 TriggerMatcherToHLTDebug::~TriggerMatcherToHLTDebug() {}
0179
0180
0181 void TriggerMatcherToHLTDebug::produce(Event &event, const EventSetup &eventSetup) {
0182 auto const l1matcher = l1matcherSetup_.init(eventSetup);
0183
0184 Handle<View<reco::Muon> > muons;
0185 event.getByToken(tagToken_, muons);
0186
0187 Handle<l1extra::L1MuonParticleCollection> L1Muons;
0188 event.getByToken(l1Token_, L1Muons);
0189
0190 Handle<L2MuonTrajectorySeedCollection> L2Seeds;
0191 event.getByToken(theL2SeedsToken_, L2Seeds);
0192
0193 Handle<RecoChargedCandidateCollection> L2Muons;
0194 event.getByToken(theL2MuonsToken_, L2Muons);
0195
0196 Handle<L3MuonTrajectorySeedCollection> L3Seeds;
0197 event.getByToken(theL3SeedsToken_, L3Seeds);
0198
0199 Handle<reco::TrackCollection> L3TkTracks;
0200 event.getByToken(theL3TkTracksToken_, L3TkTracks);
0201
0202 Handle<RecoChargedCandidateCollection> L3Muons;
0203 event.getByToken(theL3MuonsToken_, L3Muons);
0204
0205
0206 BeamSpot beamSpot;
0207 Handle<BeamSpot> recoBeamSpotHandle;
0208 event.getByToken(beamspotToken_, recoBeamSpotHandle);
0209 beamSpot = *recoBeamSpotHandle;
0210
0211
0212 edm::Handle<SeedMap> seedMapHandle;
0213 event.getByToken(seedMapToken_, seedMapHandle);
0214
0215 size_t nmu = muons->size();
0216 std::vector<int> propagatesToM2(nmu), hasL1Particle(nmu), hasL1Filtered(nmu);
0217 std::vector<int> hasL2Seed(nmu), hasL2Muon(nmu), hasL2MuonFiltered(nmu);
0218 std::vector<int> hasL3Seed(nmu), hasL3Track(nmu), hasL3TrackFiltered(nmu), hasL3Muon(nmu), hasL3MuonFiltered(nmu);
0219 std::vector<reco::CandidatePtr> l1ptr(nmu), l2ptr(nmu), l3ptr(nmu);
0220
0221 for (size_t i = 0; i < nmu; ++i) {
0222 const reco::Muon &mu = (*muons)[i];
0223
0224
0225 TrajectoryStateOnSurface stateAtMB2 = l1matcher.extrapolate(mu);
0226 if (!stateAtMB2.isValid())
0227 continue;
0228 propagatesToM2[i] = 1;
0229
0230 double etaTk = stateAtMB2.globalPosition().eta();
0231 double phiTk = stateAtMB2.globalPosition().phi();
0232 l1extra::L1MuonParticleCollection::const_iterator it;
0233 L2MuonTrajectorySeedCollection::const_iterator iSeed;
0234 L3MuonTrajectorySeedCollection::const_iterator iSeedL3;
0235 RecoChargedCandidateCollection::const_iterator iL2Muon;
0236 reco::TrackCollection::const_iterator tktrackL3;
0237 RecoChargedCandidateCollection::const_iterator iL3Muon;
0238
0239 reco::CandidatePtr thisL1, thisL2, thisL3;
0240 for (it = L1Muons->begin(); it != L1Muons->end(); ++it) {
0241 const L1MuGMTExtendedCand muonCand = (*it).gmtMuonCand();
0242 unsigned int quality = muonCand.quality();
0243
0244 double L1phi = (*it).phi();
0245 double L1eta = (*it).eta();
0246 double L1pt = (*it).pt();
0247 double dR = deltaR(etaTk, phiTk, L1eta, L1phi);
0248
0249
0250 if (dR >= deltaR_)
0251 continue;
0252 thisL1 = reco::CandidatePtr(L1Muons, it - L1Muons->begin());
0253 if (!hasL1Particle[i])
0254 l1ptr[i] = thisL1;
0255 hasL1Particle[i]++;
0256
0257 if ((quality <= 3) || (L1pt < 7))
0258 continue;
0259 if (!hasL1Filtered[i])
0260 l1ptr[i] = thisL1;
0261 hasL1Filtered[i]++;
0262
0263 if (!L2Seeds.isValid())
0264 continue;
0265
0266 for (iSeed = L2Seeds->begin(); iSeed != L2Seeds->end(); ++iSeed) {
0267 l1extra::L1MuonParticleRef l1FromSeed = iSeed->l1Particle();
0268 if (l1FromSeed.id() != L1Muons.id())
0269 throw cms::Exception("CorruptData")
0270 << "You're using a different L1 collection than the one used by L2 seeds.\n";
0271 if (l1FromSeed.key() != thisL1.key())
0272 continue;
0273 if (!hasL2Seed[i])
0274 l1ptr[i] = thisL1;
0275 hasL2Seed[i]++;
0276
0277 if (!L2Muons.isValid())
0278 continue;
0279
0280 for (iL2Muon = L2Muons->begin(); iL2Muon != L2Muons->end(); ++iL2Muon) {
0281
0282
0283
0284
0285
0286
0287
0288
0289
0290 const edm::RefVector<L2MuonTrajectorySeedCollection> &seeds =
0291 (*seedMapHandle)[iL2Muon->track()->seedRef().castTo<edm::Ref<L2MuonTrajectorySeedCollection> >()];
0292
0293 for (size_t jjj = 0; jjj < seeds.size(); jjj++) {
0294 if (seeds[jjj]->l1Particle() != l1FromSeed)
0295 continue;
0296 }
0297
0298 thisL2 = reco::CandidatePtr(L2Muons, iL2Muon - L2Muons->begin());
0299 if (!hasL2Muon[i]) {
0300 l1ptr[i] = thisL1;
0301 l2ptr[i] = thisL2;
0302 }
0303 hasL2Muon[i]++;
0304
0305 LogTrace(metname) << "L2MUON TROVATO!" << endl;
0306 const reco::Track &L2Track = *iL2Muon->track();
0307 double Eta_L2 = L2Track.eta();
0308 double Pt_L2 = L2Track.pt();
0309 int nValidHits_L2 = L2Track.numberOfValidHits();
0310 double BSPos_L2 = L2Track.dxy(beamSpot.position());
0311 double dz_L2 = L2Track.dz();
0312 double err0_L2 = L2Track.error(0);
0313 double abspar0_L2 = fabs(L2Track.parameter(0));
0314 double ptLx_L2 = Pt_L2;
0315 if (abspar0_L2 > 0)
0316 ptLx_L2 += nsigma_Pt_L2 * err0_L2 / abspar0_L2 * Pt_L2;
0317
0318
0319 bool passFilter = (((fabs(Eta_L2)) <= max_Eta_L2) && (nValidHits_L2 >= min_Nhits_L2) &&
0320 ((fabs(BSPos_L2)) <= max_Dr_L2) && ((fabs(dz_L2)) <= max_Dz_L2) && (ptLx_L2 >= min_Pt_L2));
0321 if (!passFilter)
0322 continue;
0323 if (!hasL2MuonFiltered[i]) {
0324 l1ptr[i] = thisL1;
0325 l2ptr[i] = thisL2;
0326 }
0327 hasL2MuonFiltered[i]++;
0328
0329 const reco::TrackRef L2FilteredRef = iL2Muon->track();
0330
0331
0332 if (!L3Seeds.isValid())
0333 continue;
0334 for (iSeedL3 = L3Seeds->begin(); iSeedL3 != L3Seeds->end(); ++iSeedL3) {
0335 TrackRef staTrack = iSeedL3->l2Track();
0336 if (staTrack != L2FilteredRef)
0337 continue;
0338 if (!hasL3Seed[i]) {
0339 l1ptr[i] = thisL1;
0340 l2ptr[i] = thisL2;
0341 }
0342 hasL3Seed[i]++;
0343
0344 if (!L3TkTracks.isValid())
0345 continue;
0346 for (tktrackL3 = L3TkTracks->begin(); tktrackL3 != L3TkTracks->end(); ++tktrackL3) {
0347 edm::Ref<L3MuonTrajectorySeedCollection> l3seedRef =
0348 tktrackL3->seedRef().castTo<edm::Ref<L3MuonTrajectorySeedCollection> >();
0349 TrackRef staTrack2 = l3seedRef->l2Track();
0350
0351 if (staTrack2 != L2FilteredRef)
0352 continue;
0353 if (!hasL3Track[i]) {
0354 l1ptr[i] = thisL1;
0355 l2ptr[i] = thisL2;
0356 }
0357 hasL3Track[i]++;
0358
0359 if (!L3Muons.isValid())
0360 continue;
0361 for (iL3Muon = L3Muons->begin(); iL3Muon != L3Muons->end(); ++iL3Muon) {
0362 edm::Ref<L3MuonTrajectorySeedCollection> l3seedRef2 =
0363 iL3Muon->track()->seedRef().castTo<edm::Ref<L3MuonTrajectorySeedCollection> >();
0364 TrackRef staTrack3 = l3seedRef2->l2Track();
0365
0366 if (staTrack3 != L2FilteredRef)
0367 continue;
0368 thisL3 = reco::CandidatePtr(L3Muons, iL3Muon - L3Muons->begin());
0369
0370 if (!hasL3Muon[i]) {
0371 l1ptr[i] = thisL1;
0372 l2ptr[i] = thisL2;
0373 l3ptr[i] = thisL3;
0374 }
0375 hasL3Muon[i]++;
0376
0377 const reco::Track &L3Track = *iL3Muon->track();
0378 double Eta_L3 = L3Track.eta();
0379 double Pt_L3 = L3Track.pt();
0380 int nValidHits_L3 = L3Track.numberOfValidHits();
0381 double BSPos_L3 = L3Track.dxy(beamSpot.position());
0382 double dz_L3 = L3Track.dz();
0383 double err0_L3 = L3Track.error(0);
0384 double abspar0_L3 = fabs(L3Track.parameter(0));
0385 double ptLx_L3 = Pt_L3;
0386
0387 if (abspar0_L3 > 0)
0388 ptLx_L3 += nsigma_Pt_L3 * err0_L3 / abspar0_L3 * Pt_L3;
0389
0390 if (((fabs(Eta_L3)) <= max_Eta_L3) && (nValidHits_L3 >= min_Nhits_L3) &&
0391 ((fabs(BSPos_L3)) <= max_Dr_L3) && ((fabs(dz_L3)) <= max_Dz_L3) && (ptLx_L3 >= min_Pt_L3)) {
0392 if (!hasL3MuonFiltered[i]) {
0393 l1ptr[i] = thisL1;
0394 l2ptr[i] = thisL2;
0395 l3ptr[i] = thisL3;
0396 }
0397 hasL3MuonFiltered[i]++;
0398
0399 }
0400 }
0401 }
0402 }
0403 }
0404 }
0405 }
0406 }
0407 storeValueMap<int>(event, muons, propagatesToM2, "propagatesToM2");
0408 storeValueMap<int>(event, muons, hasL1Particle, "hasL1Particle");
0409 storeValueMap<int>(event, muons, hasL1Filtered, "hasL1Filtered");
0410 storeValueMap<int>(event, muons, hasL2Seed, "hasL2Seed");
0411 storeValueMap<int>(event, muons, hasL2Muon, "hasL2Muon");
0412 storeValueMap<int>(event, muons, hasL2MuonFiltered, "hasL2MuonFiltered");
0413 storeValueMap<int>(event, muons, hasL3Seed, "hasL3Seed");
0414 storeValueMap<int>(event, muons, hasL3Track, "hasL3Track");
0415 storeValueMap<int>(event, muons, hasL3Muon, "hasL3Muon");
0416 storeValueMap<int>(event, muons, hasL3MuonFiltered, "hasL3MuonFiltered");
0417 storeValueMap<reco::CandidatePtr>(event, muons, l1ptr, "l1Candidate");
0418 storeValueMap<reco::CandidatePtr>(event, muons, l2ptr, "l2Candidate");
0419 storeValueMap<reco::CandidatePtr>(event, muons, l3ptr, "l3Candidate");
0420 }
0421
0422 template <typename T>
0423 void TriggerMatcherToHLTDebug::storeValueMap(edm::Event &iEvent,
0424 const edm::Handle<edm::View<reco::Muon> > &handle,
0425 const std::vector<T> &values,
0426 const std::string &label) const {
0427 using namespace edm;
0428 using namespace std;
0429 unique_ptr<ValueMap<T> > valMap(new ValueMap<T>());
0430 typename edm::ValueMap<T>::Filler filler(*valMap);
0431 filler.insert(handle, values.begin(), values.end());
0432 filler.fill();
0433 iEvent.put(std::move(valMap), label);
0434 }
0435
0436 DEFINE_FWK_MODULE(TriggerMatcherToHLTDebug);