File indexing completed on 2024-07-12 02:41:52
0001 #include "FWCore/Framework/interface/Event.h"
0002 #include "FWCore/Framework/interface/Frameworkfwd.h"
0003 #include "FWCore/Framework/interface/stream/EDProducer.h"
0004 #include "FWCore/Framework/interface/MakerMacros.h"
0005 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0007 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0008 #include "FWCore/Utilities/interface/EDGetToken.h"
0009 #include "FWCore/Utilities/interface/EDPutToken.h"
0010 #include "FWCore/Utilities/interface/Exception.h"
0011 #include "FWCore/Utilities/interface/InputTag.h"
0012 #include "FWCore/Utilities/interface/StreamID.h"
0013 #include "FWCore/Utilities/interface/Span.h"
0014
0015
0016 #include "DataFormats/L1Scouting/interface/L1ScoutingMuon.h"
0017 #include "DataFormats/L1Scouting/interface/OrbitCollection.h"
0018 #include "L1TriggerScouting/Utilities/interface/conversion.h"
0019
0020 #include <memory>
0021 #include <utility>
0022 #include <vector>
0023
0024 using namespace l1ScoutingRun3;
0025
0026 class MuBxSelector : public edm::stream::EDProducer<> {
0027 public:
0028 explicit MuBxSelector(const edm::ParameterSet&);
0029 ~MuBxSelector() {}
0030 static void fillDescriptions(edm::ConfigurationDescriptions&);
0031
0032 private:
0033 void produce(edm::Event&, const edm::EventSetup&) override;
0034
0035
0036 edm::EDGetTokenT<OrbitCollection<l1ScoutingRun3::Muon>> muonsTokenData_;
0037
0038
0039 int minNMu_;
0040 std::vector<double> minMuPt_;
0041 std::vector<double> maxMuEta_;
0042 std::vector<int> minMuTfIndex_;
0043 std::vector<int> maxMuTfIndex_;
0044 std::vector<int> minMuHwQual_;
0045 };
0046
0047 MuBxSelector::MuBxSelector(const edm::ParameterSet& iPSet)
0048 : muonsTokenData_(consumes(iPSet.getParameter<edm::InputTag>("muonsTag"))),
0049 minNMu_(iPSet.getParameter<int>("minNMu")),
0050 minMuPt_(iPSet.getParameter<std::vector<double>>("minMuPt")),
0051 maxMuEta_(iPSet.getParameter<std::vector<double>>("maxMuEta")),
0052 minMuTfIndex_(iPSet.getParameter<std::vector<int>>("minMuTfIndex")),
0053 maxMuTfIndex_(iPSet.getParameter<std::vector<int>>("maxMuTfIndex")),
0054 minMuHwQual_(iPSet.getParameter<std::vector<int>>("minMuHwQual"))
0055
0056 {
0057 if ((minMuPt_.size() != (size_t)(size_t)minNMu_) || (maxMuEta_.size() != (size_t)minNMu_) ||
0058 (minMuTfIndex_.size() != (size_t)minNMu_) || (maxMuTfIndex_.size() != (size_t)minNMu_) ||
0059 (minMuHwQual_.size() != (size_t)minNMu_))
0060 throw cms::Exception("MuBxSelector::MuBxSelector")
0061 << "size mismatch: size of minMuPt or maxMuEta or minMuTfIndex or maxMuTfIndex or minMuHwQual != minNMu.";
0062
0063 produces<std::vector<unsigned>>("SelBx").setBranchAlias("MuSelectedBx");
0064 }
0065
0066
0067 void MuBxSelector::produce(edm::Event& iEvent, const edm::EventSetup&) {
0068 edm::Handle<OrbitCollection<l1ScoutingRun3::Muon>> muonsCollection;
0069
0070 iEvent.getByToken(muonsTokenData_, muonsCollection);
0071
0072 std::unique_ptr<std::vector<unsigned>> muBx(new std::vector<unsigned>);
0073
0074
0075 for (const unsigned& bx : muonsCollection->getFilledBxs()) {
0076 const auto& muons = muonsCollection->bxIterator(bx);
0077
0078
0079 if (muons.size() < minNMu_)
0080 continue;
0081
0082
0083 bool muCond = false;
0084 int nAccMus = 0;
0085 for (const auto& muon : muons) {
0086 muCond = (std::abs(ugmt::fEta(muon.hwEta())) < maxMuEta_[nAccMus]) &&
0087 (muon.tfMuonIndex() <= maxMuTfIndex_[nAccMus]) && (muon.tfMuonIndex() >= minMuTfIndex_[nAccMus]) &&
0088 (ugmt::fPt(muon.hwPt()) >= minMuPt_[nAccMus]) && (muon.hwQual() >= minMuHwQual_[nAccMus]);
0089 if (muCond)
0090 nAccMus++;
0091 if (nAccMus == minNMu_)
0092 break;
0093 }
0094
0095 if (nAccMus < minNMu_)
0096 continue;
0097
0098 muBx->push_back(bx);
0099
0100 }
0101
0102 iEvent.put(std::move(muBx), "SelBx");
0103 }
0104
0105 void MuBxSelector::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0106 edm::ParameterSetDescription desc;
0107 desc.setUnknown();
0108 descriptions.addDefault(desc);
0109 }
0110
0111 DEFINE_FWK_MODULE(MuBxSelector);