CMS 3D CMS Logo

HLTDQMMuonSelector.cc
Go to the documentation of this file.
16 
18 public:
20  void produce(edm::Event&, edm::EventSetup const&) override;
21  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
22 
23 private:
25 
27  bool passMuonSel(const reco::Muon& muon, const reco::Vertex& vertex) const;
28 
32 
34 };
35 
37  : muonToken_(consumes<reco::MuonCollection>(config.getParameter<edm::InputTag>("objs"))),
38  vtxToken_(consumes<reco::VertexCollection>(config.getParameter<edm::InputTag>("vertices"))),
39  selection_(config.getParameter<std::string>("selection")),
40  muonSelType_(convertToEnum(config.getParameter<std::string>("muonSelectionType"))) {
41  produces<edm::ValueMap<bool> >();
42 }
43 
46  desc.add<edm::InputTag>("objs", edm::InputTag("muons"));
47  desc.add<edm::InputTag>("vertices", edm::InputTag("offlinePrimaryVertices"));
48  desc.add<std::string>("selection", "et > 5");
49  desc.add<std::string>("muonSelectionType", "tight");
50  descriptions.add("hltDQMMuonSelector", desc);
51 }
52 
55  event.getByToken(muonToken_, muonHandle);
56 
58  event.getByToken(vtxToken_, vtxHandle);
59 
60  if (!muonHandle.isValid())
61  return;
62 
63  std::vector<bool> selResults;
64  for (auto& muon : *muonHandle) {
65  if (vtxHandle.isValid() && !vtxHandle->empty()) {
66  selResults.push_back(passMuonSel(muon, vtxHandle->front()) && selection_(muon));
67  } else {
68  selResults.push_back(false);
69  }
70  }
71  auto valMap = std::make_unique<edm::ValueMap<bool> >();
73  filler.insert(muonHandle, selResults.begin(), selResults.end());
74  filler.fill();
75  event.put(std::move(valMap));
76 }
77 
79  const std::vector<std::pair<std::string, MuonSelectionType> > strsToEnums = {{"tight", MuonSelectionType::Tight},
80  {"medium", MuonSelectionType::Medium},
81  {"loose", MuonSelectionType::Loose},
82  {"soft", MuonSelectionType::Soft},
83  {"highpt", MuonSelectionType::HighPt},
84  {"none", MuonSelectionType::None}};
85  for (const auto& strEnumPair : strsToEnums) {
86  if (val == strEnumPair.first)
87  return strEnumPair.second;
88  }
89  std::ostringstream validEnums;
90  for (const auto& strEnumPair : strsToEnums)
91  validEnums << strEnumPair.first << " ";
92  throw cms::Exception("InvalidConfig") << "invalid muonSelectionType " << val << ", allowed values are "
93  << validEnums.str();
94 }
95 
97  switch (muonSelType_) {
99  return muon::isTightMuon(muon, vertex);
101  return muon::isMediumMuon(muon);
103  return muon::isLooseMuon(muon);
105  return muon::isSoftMuon(muon, vertex);
107  return muon::isHighPtMuon(muon, vertex);
109  return true;
110  default:
111  edm::LogError("HLTDQMMuonSelector") << " inconsistent code, an option has been added to MuonSelectionType "
112  "without updating HLTDQMMuonSelector::passMuonSel";
113  return false;
114  }
115 }
116 
static MuonSelectionType convertToEnum(const std::string &val)
bool isMediumMuon(const reco::Muon &, bool run2016_hip_mitigation=false)
MuonSelectionType muonSelType_
HLTDQMMuonSelector(const edm::ParameterSet &config)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void produce(edm::Event &, edm::EventSetup const &) override
Definition: config.py:1
Log< level::Error, false > LogError
std::vector< Vertex > VertexCollection
Definition: Vertex.h:31
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
bool isLooseMuon(const reco::Muon &)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
bool isSoftMuon(const reco::Muon &, const reco::Vertex &, bool run2016_hip_mitigation=false)
bool isHighPtMuon(const reco::Muon &, const reco::Vertex &)
StringCutObjectSelector< reco::Muon, true > selection_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
edm::EDGetTokenT< reco::MuonCollection > muonToken_
bool isValid() const
Definition: HandleBase.h:70
fixed size matrix
HLT enums.
bool passMuonSel(const reco::Muon &muon, const reco::Vertex &vertex) const
bool isTightMuon(const reco::Muon &, const reco::Vertex &)
edm::EDGetTokenT< reco::VertexCollection > vtxToken_
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1