CMS 3D CMS Logo

HLTDQMMuonSelector.cc
Go to the documentation of this file.
16 
17 
19 public:
21  void produce(edm::Event&, edm::EventSetup const&)override;
22  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
23 private:
24 
25  enum class MuonSelectionType {
27  };
28 
30  bool passMuonSel(const reco::Muon& muon,const reco::Vertex& vertex)const;
31 
32 
36 
38 
39 
40 };
41 
42 
44  muonToken_(consumes<reco::MuonCollection>(config.getParameter<edm::InputTag>("objs"))),
45  vtxToken_(consumes<reco::VertexCollection>(config.getParameter<edm::InputTag>("vertices"))),
46  selection_(config.getParameter<std::string>("selection")),
47  muonSelType_(convertToEnum(config.getParameter<std::string>("muonSelectionType")))
48 {
49  produces<edm::ValueMap<bool> >();
50 }
51 
53 {
55  desc.add<edm::InputTag>("objs", edm::InputTag("muons"));
56  desc.add<edm::InputTag>("vertices", edm::InputTag("offlinePrimaryVertices"));
57  desc.add<std::string>("selection","et > 5");
58  desc.add<std::string>("muonSelectionType","tight");
59  descriptions.add("hltDQMMuonSelector", desc);
60 }
61 
62 
64 {
66  event.getByToken(muonToken_,muonHandle);
67 
69  event.getByToken(vtxToken_,vtxHandle);
70 
71  if(!muonHandle.isValid()) return;
72 
73  std::vector<bool> selResults;
74  for(auto& muon : *muonHandle){
75  if(vtxHandle.isValid() && !vtxHandle->empty()){
76  selResults.push_back(passMuonSel(muon,vtxHandle->front()) && selection_(muon));
77  }else{
78  selResults.push_back(false);
79  }
80  }
81  auto valMap = std::make_unique<edm::ValueMap<bool> >();
83  filler.insert(muonHandle, selResults.begin(), selResults.end());
84  filler.fill();
85  event.put(std::move(valMap));
86 }
87 
89 {
90  const std::vector<std::pair<std::string,MuonSelectionType> > strsToEnums = {
91  {"tight",MuonSelectionType::Tight},
92  {"medium",MuonSelectionType::Medium},
93  {"loose",MuonSelectionType::Loose},
94  {"soft",MuonSelectionType::Soft},
95  {"highpt",MuonSelectionType::HighPt},
97  };
98  for(const auto& strEnumPair : strsToEnums){
99  if(val==strEnumPair.first) return strEnumPair.second;
100  }
101  std::ostringstream validEnums;
102  for(const auto& strEnumPair : strsToEnums) validEnums <<strEnumPair.first<<" ";
103  throw cms::Exception("InvalidConfig") << "invalid muonSelectionType "<<val<<", allowed values are "<<validEnums.str();
104 }
105 
107 {
108  switch(muonSelType_){
110  return muon::isTightMuon(muon,vertex);
112  return muon::isMediumMuon(muon);
114  return muon::isLooseMuon(muon);
116  return muon::isSoftMuon(muon,vertex);
118  return muon::isHighPtMuon(muon,vertex);
120  return true;
121  default:
122  edm::LogError("HLTDQMMuonSelector")<<" inconsistent code, an option has been added to MuonSelectionType without updating HLTDQMMuonSelector::passMuonSel";
123  return false;
124  }
125 
126 }
127 
static MuonSelectionType convertToEnum(const std::string &val)
bool isMediumMuon(const reco::Muon &, bool run2016_hip_mitigation=false)
MuonSelectionType muonSelType_
HLTDQMMuonSelector(const edm::ParameterSet &config)
StringCutObjectSelector< reco::Muon, true > selection_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void produce(edm::Event &, edm::EventSetup const &) override
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:1
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
Definition: config.py:1
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
bool isLooseMuon(const reco::Muon &)
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool isSoftMuon(const reco::Muon &, const reco::Vertex &, bool run2016_hip_mitigation=false)
bool isValid() const
Definition: HandleBase.h:74
bool isHighPtMuon(const reco::Muon &, const reco::Vertex &)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
edm::EDGetTokenT< reco::MuonCollection > muonToken_
bool passMuonSel(const reco::Muon &muon, const reco::Vertex &vertex) const
fixed size matrix
HLT enums.
bool isTightMuon(const reco::Muon &, const reco::Vertex &)
edm::EDGetTokenT< reco::VertexCollection > vtxToken_
def move(src, dest)
Definition: eostools.py:510
Definition: event.py:1