Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:18:35

0001 //-------------------------------------------------
0002 //
0003 /**  \class HLTL1MuonNoL2Selector
0004  * 
0005  *   HLTL1MuonNoL2Selector:
0006  *   Simple selector to output a subset of L1 muon collection 
0007  *   with no L2 link.
0008  *   
0009  *   based on RecoMuon/L2MuonSeedGenerator
0010  *
0011  *
0012  *   \author  S. Folgueras
0013  */
0014 //
0015 //--------------------------------------------------
0016 
0017 // Class Header
0018 #include "HLTL1MuonNoL2Selector.h"
0019 
0020 // Framework
0021 #include "FWCore/Framework/interface/EventSetup.h"
0022 #include "FWCore/Framework/interface/Event.h"
0023 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0024 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0025 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0026 
0027 using namespace std;
0028 using namespace edm;
0029 using namespace l1t;
0030 
0031 // constructors
0032 HLTL1MuonNoL2Selector::HLTL1MuonNoL2Selector(const edm::ParameterSet& iConfig)
0033     : theL1Source_(iConfig.getParameter<InputTag>("InputObjects")),
0034       theL1MinPt_(iConfig.getParameter<double>("L1MinPt")),
0035       theL1MaxEta_(iConfig.getParameter<double>("L1MaxEta")),
0036       theL1MinQuality_(iConfig.getParameter<unsigned int>("L1MinQuality")),
0037       centralBxOnly_(iConfig.getParameter<bool>("CentralBxOnly")),
0038       theL2CandTag_(iConfig.getParameter<edm::InputTag>("L2CandTag")),
0039       theL2CandToken_(consumes<reco::RecoChargedCandidateCollection>(theL2CandTag_)),
0040       seedMapTag_(iConfig.getParameter<InputTag>("SeedMapTag")),
0041       seedMapToken_(consumes<SeedMap>(seedMapTag_)) {
0042   muCollToken_ = consumes<MuonBxCollection>(theL1Source_);
0043 
0044   produces<MuonBxCollection>();
0045 }
0046 
0047 // destructor
0048 HLTL1MuonNoL2Selector::~HLTL1MuonNoL2Selector() = default;
0049 
0050 void HLTL1MuonNoL2Selector::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0051   edm::ParameterSetDescription desc;
0052   desc.add<edm::InputTag>("InputObjects", edm::InputTag(""));
0053   desc.add<edm::InputTag>("L2CandTag", edm::InputTag("hltL2MuonCandidates"));
0054   desc.add<edm::InputTag>("SeedMapTag", edm::InputTag("hltL2Muons"));
0055   desc.add<double>("L1MinPt", -1.);
0056   desc.add<double>("L1MaxEta", 5.0);
0057   desc.add<unsigned int>("L1MinQuality", 0);
0058   // # OBSOLETE - these parameters are ignored, they are left only not to break old configurations
0059   // they will not be printed in the generated cfi.py file
0060   desc.addOptionalNode(edm::ParameterDescription<edm::InputTag>("L1CandTag", edm::InputTag(""), false), false)
0061       ->setComment("This parameter is obsolete and will be ignored.");
0062   desc.add<bool>("CentralBxOnly", true);
0063   descriptions.add("hltL1MuonNoL2Selector", desc);
0064 }
0065 
0066 void HLTL1MuonNoL2Selector::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
0067   using namespace std;
0068   using namespace reco;
0069   using namespace trigger;
0070 
0071   const std::string metname = "Muon|RecoMuon|HLTL1MuonNoL2Selector";
0072 
0073   unique_ptr<MuonBxCollection> output(new MuonBxCollection());
0074 
0075   // Get hold of L2 trks
0076   edm::Handle<RecoChargedCandidateCollection> L2cands;
0077   iEvent.getByToken(theL2CandToken_, L2cands);
0078 
0079   // Muon particles
0080   edm::Handle<MuonBxCollection> muColl;
0081   iEvent.getByToken(muCollToken_, muColl);
0082   LogTrace(metname) << "Number of muons " << muColl->size() << endl;
0083 
0084   edm::Handle<SeedMap> seedMapHandle;
0085   iEvent.getByToken(seedMapToken_, seedMapHandle);
0086 
0087   for (int ibx = muColl->getFirstBX(); ibx <= muColl->getLastBX(); ++ibx) {
0088     if (centralBxOnly_ && (ibx != 0))
0089       continue;
0090     for (auto it = muColl->begin(ibx); it != muColl->end(ibx); it++) {
0091       l1t::MuonRef l1muon(muColl, distance(muColl->begin(muColl->getFirstBX()), it));
0092 
0093       unsigned int quality = it->hwQual();
0094       float pt = it->pt();
0095       float eta = it->eta();
0096 
0097       if (pt < theL1MinPt_ || std::abs(eta) > theL1MaxEta_ || quality <= theL1MinQuality_)
0098         continue;
0099 
0100       // Loop over L2's to find whether the L1 fired this L2.
0101       bool isTriggeredByL1 = false;
0102       for (auto const& cand : *L2cands) {
0103         TrackRef l2muon = cand.get<TrackRef>();
0104         const edm::RefVector<L2MuonTrajectorySeedCollection>& seeds =
0105             (*seedMapHandle)[l2muon->seedRef().castTo<edm::Ref<L2MuonTrajectorySeedCollection> >()];
0106         for (auto const& seed : seeds) {
0107           // Check if the L2 was seeded by a triggered L1, in such case skip the loop.
0108           if (seed->l1tParticle() == l1muon) {
0109             isTriggeredByL1 = true;
0110             break;
0111           }
0112         }
0113         if (isTriggeredByL1)
0114           break;  // if I found a L2 I do not need to loop on the rest.
0115       }
0116       // Once we loop on all L2 decide:
0117       if (!isTriggeredByL1) {
0118         output->push_back(ibx, *it);
0119       }
0120     }
0121   }  // loop over L1
0122 
0123   iEvent.put(std::move(output));
0124 }
0125 
0126 // declare this class as a framework plugin
0127 #include "FWCore/Framework/interface/MakerMacros.h"
0128 DEFINE_FWK_MODULE(HLTL1MuonNoL2Selector);