CMS 3D CMS Logo

PFRecoTauDiscriminationAgainstMuon2Container.cc
Go to the documentation of this file.
1 
11 
13 
16 
26 
29 
30 #include <vector>
31 #include <string>
32 #include <iostream>
33 #include <atomic>
34 
35 namespace {
36 
37  class PFRecoTauDiscriminationAgainstMuon2Container final : public PFTauDiscriminationContainerProducerBase {
38  public:
39  explicit PFRecoTauDiscriminationAgainstMuon2Container(const edm::ParameterSet& cfg)
40  : PFTauDiscriminationContainerProducerBase(cfg), moduleLabel_(cfg.getParameter<std::string>("@module_label")) {
41  auto const wpDefs = cfg.getParameter<std::vector<edm::ParameterSet>>("IDWPdefinitions");
42  // check content of discriminatorOption and add as enum to avoid string comparison per event
43  for (auto& wpDefsEntry : wpDefs) {
44  std::string discriminatorOption_string = wpDefsEntry.getParameter<std::string>("discriminatorOption");
45  int discOption;
46  if (discriminatorOption_string == "loose")
48  else if (discriminatorOption_string == "medium")
50  else if (discriminatorOption_string == "tight")
52  else if (discriminatorOption_string == "custom")
54  else
56  << " Invalid Configuration parameter 'discriminatorOption' = " << discriminatorOption_string << " !!\n";
57  wpDefs_.push_back(
59  wpDefsEntry.getParameter<double>("HoPMin"),
60  wpDefsEntry.getParameter<int>("maxNumberOfMatches"),
61  wpDefsEntry.getParameter<bool>("doCaloMuonVeto"),
62  wpDefsEntry.getParameter<int>("maxNumberOfHitsLast2Stations")));
63  }
64  srcMuons_ = cfg.getParameter<edm::InputTag>("srcMuons");
65  muons_token = consumes<reco::MuonCollection>(srcMuons_);
66  dRmuonMatch_ = cfg.getParameter<double>("dRmuonMatch");
67  dRmuonMatchLimitedToJetArea_ = cfg.getParameter<bool>("dRmuonMatchLimitedToJetArea");
68  minPtMatchedMuon_ = cfg.getParameter<double>("minPtMatchedMuon");
69  typedef std::vector<int> vint;
70  maskMatchesDT_ = cfg.getParameter<vint>("maskMatchesDT");
71  maskMatchesCSC_ = cfg.getParameter<vint>("maskMatchesCSC");
72  maskMatchesRPC_ = cfg.getParameter<vint>("maskMatchesRPC");
73  maskHitsDT_ = cfg.getParameter<vint>("maskHitsDT");
74  maskHitsCSC_ = cfg.getParameter<vint>("maskHitsCSC");
75  maskHitsRPC_ = cfg.getParameter<vint>("maskHitsRPC");
76  verbosity_ = cfg.getParameter<int>("verbosity");
77  }
78  ~PFRecoTauDiscriminationAgainstMuon2Container() override {}
79 
80  void beginEvent(const edm::Event&, const edm::EventSetup&) override;
81 
83 
84  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
85 
86  private:
88  std::vector<PFRecoTauDiscriminationAgainstMuonConfigSet> wpDefs_;
89  edm::InputTag srcMuons_;
92  double dRmuonMatch_;
93  bool dRmuonMatchLimitedToJetArea_;
94  double minPtMatchedMuon_;
95  std::vector<int> maskMatchesDT_;
96  std::vector<int> maskMatchesCSC_;
97  std::vector<int> maskMatchesRPC_;
98  std::vector<int> maskHitsDT_;
99  std::vector<int> maskHitsCSC_;
100  std::vector<int> maskHitsRPC_;
101  static std::atomic<unsigned int> numWarnings_;
102  static constexpr unsigned int maxWarnings_ = 3;
103  int verbosity_;
104  };
105 
106  std::atomic<unsigned int> PFRecoTauDiscriminationAgainstMuon2Container::numWarnings_{0};
107 
109  if (!srcMuons_.label().empty()) {
110  evt.getByToken(muons_token, muons_);
111  }
112  }
113 
115  const reco::PFTauRef& pfTau) const {
116  const reco::PFCandidatePtr& pfCand = pfTau->leadPFChargedHadrCand();
118  moduleLabel_,
119  srcMuons_.label().empty(),
120  minPtMatchedMuon_,
121  dRmuonMatch_,
122  dRmuonMatchLimitedToJetArea_,
123  numWarnings_,
124  maxWarnings_,
125  maskMatchesDT_,
126  maskMatchesCSC_,
127  maskMatchesRPC_,
128  maskHitsDT_,
129  maskHitsCSC_,
130  maskHitsRPC_,
131  muons_,
132  pfTau,
133  pfCand);
134 
136  for (auto const& wpDefsEntry : wpDefs_) {
137  result.workingPoints.push_back(helper.eval(wpDefsEntry, pfTau));
138  if (verbosity_)
139  edm::LogPrint("PFTauAgainstMuon2") << "--> returning discriminatorValue = " << result.workingPoints.back();
140  }
141  return result;
142  }
143 
144 } // namespace
145 
147  // pfRecoTauDiscriminationAgainstMuon2Container
149  desc.add<std::vector<int>>("maskHitsRPC",
150  {
151  0,
152  0,
153  0,
154  0,
155  });
156  desc.add<std::vector<int>>("maskMatchesRPC",
157  {
158  0,
159  0,
160  0,
161  0,
162  });
163  desc.add<std::vector<int>>("maskMatchesCSC",
164  {
165  1,
166  0,
167  0,
168  0,
169  })
170  ->setComment(
171  "flags to mask/unmask DT, CSC and RPC chambers in individual muon stations. Segments and hits that are "
172  "present in that muon station are ignored in case the 'mask' is set to 1. Per default only the innermost CSC "
173  "chamber is ignored, as it is affected by spurious hits in high pile-up events.");
174  desc.add<std::vector<int>>("maskHitsCSC",
175  {
176  0,
177  0,
178  0,
179  0,
180  });
181  desc.add<edm::InputTag>("PFTauProducer", edm::InputTag("pfRecoTauProducer"));
182  desc.add<int>("verbosity", 0);
183  desc.add<std::vector<int>>("maskMatchesDT",
184  {
185  0,
186  0,
187  0,
188  0,
189  });
190  desc.add<double>("minPtMatchedMuon", 5.0);
191  desc.add<bool>("dRmuonMatchLimitedToJetArea", false);
192  {
194  psd0.add<std::string>("BooleanOperator", "and");
195  {
197  psd1.add<double>("cut", 0.5);
198  psd1.add<edm::InputTag>("Producer", edm::InputTag("pfRecoTauDiscriminationByLeadingTrackFinding"));
199  psd0.addOptional<edm::ParameterSetDescription>("leadTrack", psd1); // optional with default?
200  }
201  // Prediscriminants can be
202  // Prediscriminants = noPrediscriminants,
203  // as in RecoTauTag/Configuration/python/HPSPFTaus_cff.py
204  //
205  // and the definition is:
206  // RecoTauTag/RecoTau/python/TauDiscriminatorTools.py
207  // # Require no prediscriminants
208  // noPrediscriminants = cms.PSet(
209  // BooleanOperator = cms.string("and"),
210  // )
211  // -- so this is the minimum required definition
212  // otherwise it inserts the leadTrack with Producer = InpuTag(...) and does not find the corresponding output during the run
213  desc.add<edm::ParameterSetDescription>("Prediscriminants", psd0);
214  }
215  desc.add<std::vector<int>>("maskHitsDT",
216  {
217  0,
218  0,
219  0,
220  0,
221  });
222  desc.add<double>("dRmuonMatch", 0.3);
223  desc.add<edm::InputTag>("srcMuons", edm::InputTag("muons"))
224  ->setComment("optional collection of muons to check for overlap with taus");
225 
227  desc_wp.add<std::string>("IDname");
228  desc_wp.add<std::string>("discriminatorOption")
229  ->setComment("available options are: 'loose', 'medium', 'tight' and 'custom'");
230  desc_wp.add<double>("HoPMin");
231  desc_wp.add<int>("maxNumberOfMatches")
232  ->setComment("negative value would turn off this cut in case of 'custom' discriminator");
233  desc_wp.add<bool>("doCaloMuonVeto");
234  desc_wp.add<int>("maxNumberOfHitsLast2Stations")
235  ->setComment("negative value would turn off this cut in case of 'custom' discriminator");
236  edm::ParameterSet pset_wp;
237  pset_wp.addParameter<std::string>("IDname", "pfRecoTauDiscriminationAgainstMuon2Container");
238  pset_wp.addParameter<std::string>("discriminatorOption", "loose");
239  pset_wp.addParameter<double>("HoPMin", 0.2);
240  pset_wp.addParameter<int>("maxNumberOfMatches", 0);
241  pset_wp.addParameter<bool>("doCaloMuonVeto", false);
242  pset_wp.addParameter<int>("maxNumberOfHitsLast2Stations", 0);
243  std::vector<edm::ParameterSet> vpsd_wp;
244  vpsd_wp.push_back(pset_wp);
245  desc.addVPSet("IDWPdefinitions", desc_wp, vpsd_wp);
246  //add empty raw value config to simplify subsequent provenance searches
247  desc.addVPSet("IDdefinitions", edm::ParameterSetDescription(), {});
248 
249  descriptions.add("pfRecoTauDiscriminationAgainstMuon2Container", desc);
250 }
251 
252 DEFINE_FWK_MODULE(PFRecoTauDiscriminationAgainstMuon2Container);
ConfigurationDescriptions.h
Handle.h
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
Muon.h
TauDiscriminationProducerBase.h
vint
double vint[400]
Definition: JetMatchingHook.cc:18
edm::EDGetTokenT< reco::MuonCollection >
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
RecoTauMuonTools.h
PFRecoTauDiscriminationAgainstMuon2Helper.h
edm::Handle< reco::MuonCollection >
edm::ParameterSetDescription::addOptional
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:105
PFRecoTauDiscriminationAgainstMuonConfigSet
Definition: PFRecoTauDiscriminationAgainstMuon2Helper.h:7
edm::Ref< PFTauCollection >
PFRecoTauDiscriminationAgainstMuonConfigSet::kTight
Definition: PFRecoTauDiscriminationAgainstMuon2Helper.h:8
deltaR.h
Track.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
MuonSelectors.h
MuonFwd.h
fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
TauDiscriminationProducerBase::discriminate
virtual TauDiscriminatorDataType discriminate(const TauRef &tau) const =0
PFRecoTauDiscriminationAgainstMuonConfigSet::kMedium
Definition: PFRecoTauDiscriminationAgainstMuon2Helper.h:8
TauDiscriminationProducerBase
Definition: TauDiscriminationProducerBase.h:55
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:528
ParameterSetDescription.h
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
edm::ParameterSet
Definition: ParameterSet.h:36
TauDiscriminationProducerBase::moduleLabel_
std::string moduleLabel_
Definition: TauDiscriminationProducerBase.h:106
PFRecoTauDiscriminationAgainstMuon2Helper
Definition: PFRecoTauDiscriminationAgainstMuon2Helper.h:24
helper
Definition: helper.py:1
edm::ParameterSet::addParameter
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:124
GsfTrack.h
edm::LogPrint
Definition: MessageLogger.h:342
edm::EventSetup
Definition: EventSetup.h:57
PFRecoTauDiscriminationAgainstMuonConfigSet::kCustom
Definition: PFRecoTauDiscriminationAgainstMuon2Helper.h:8
HitPattern.h
TauDiscriminationProducerBase::beginEvent
virtual void beginEvent(const edm::Event &, const edm::EventSetup &)
Definition: TauDiscriminationProducerBase.h:74
edm::Ptr< PFCandidate >
looper.cfg
cfg
Definition: looper.py:297
std
Definition: JetResolutionObject.h:76
Exception
Definition: hltDiff.cc:246
PFRecoTauDiscriminationAgainstMuonConfigSet::kLoose
Definition: PFRecoTauDiscriminationAgainstMuon2Helper.h:8
Exception.h
mps_fire.result
result
Definition: mps_fire.py:303
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15
edm::errors::UnimplementedFeature
Definition: EDMException.h:38
MuonChamberMatch.h
reco::SingleTauDiscriminatorContainer
Definition: TauDiscriminatorContainer.h:9