CMS 3D CMS Logo

RecoTauProducer.cc
Go to the documentation of this file.
1 /*
2  * RecoTauProducer
3  *
4  * Interface between the various tau algorithms and the edm::Event. The
5  * RecoTauProducer takes as data input is a collection (view) of reco::PFJets,
6  * and Jet-PiZero assoications that give the reco::RecoTauPiZeros for those
7  * jets. The actual building of taus is done by the list of builders - each of
8  * which constructs a PFTau for each PFJet. The output collection may have
9  * multiple taus for each PFJet - these overlaps are to be resolved by the
10  * RecoTauCleaner module.
11  *
12  * Additionally, there are "modifier" plugins, which can do things like add the
13  * lead track significance, or electron rejection variables.
14  *
15  * Authors: Evan K. Friis (UC Davis),
16  * Christian Veelken (LLR)
17  *
18  */
19 #include "boost/bind.hpp"
20 #include <boost/ptr_container/ptr_vector.hpp>
21 
22 #include <algorithm>
23 #include <functional>
24 
32 
35 
43 
45 
47 public:
50  typedef std::vector<std::unique_ptr<Builder>> BuilderList;
51  typedef std::vector<std::unique_ptr<Modifier>> ModifierList;
52 
53  explicit RecoTauProducer(const edm::ParameterSet& pset);
54  ~RecoTauProducer() override {}
55  void produce(edm::Event& evt, const edm::EventSetup& es) override;
56 
57  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
58 
59 private:
64 
65  double minJetPt_;
66  double maxJetAbsEta_;
67  //token definition
72 
73  BuilderList builders_;
74  ModifierList modifiers_;
75  // Optional selection on the output of the taus
76  std::unique_ptr<StringCutObjectSelector<reco::PFTau>> outputSelector_;
77  // Whether or not to add build a tau from a jet for which the builders
78  // return no taus. The tau will have no content, only the four vector of
79  // the orginal jet.
81 };
82 
84  jetSrc_ = pset.getParameter<edm::InputTag>("jetSrc");
85  jetRegionSrc_ = pset.getParameter<edm::InputTag>("jetRegionSrc");
86  chargedHadronSrc_ = pset.getParameter<edm::InputTag>("chargedHadronSrc");
87  piZeroSrc_ = pset.getParameter<edm::InputTag>("piZeroSrc");
88 
89  minJetPt_ = pset.getParameter<double>("minJetPt");
90  maxJetAbsEta_ = pset.getParameter<double>("maxJetAbsEta");
91  //consumes definition
92  jet_token = consumes<reco::JetView>(jetSrc_);
93  jetRegion_token = consumes<edm::AssociationMap<edm::OneToOne<reco::JetView, reco::JetView>>>(jetRegionSrc_);
94  chargedHadron_token = consumes<reco::PFJetChargedHadronAssociation>(chargedHadronSrc_);
95  piZero_token = consumes<reco::JetPiZeroAssociation>(piZeroSrc_);
96 
97  typedef std::vector<edm::ParameterSet> VPSet;
98  // Get each of our tau builders
99  const VPSet& builders = pset.getParameter<VPSet>("builders");
100  for (VPSet::const_iterator builderPSet = builders.begin(); builderPSet != builders.end(); ++builderPSet) {
101  // Get plugin name
102  const std::string& pluginType = builderPSet->getParameter<std::string>("plugin");
103  // Build the plugin
104  builders_.emplace_back(RecoTauBuilderPluginFactory::get()->create(pluginType, *builderPSet, consumesCollector()));
105  }
106 
107  const VPSet& modfiers = pset.getParameter<VPSet>("modifiers");
108  for (VPSet::const_iterator modfierPSet = modfiers.begin(); modfierPSet != modfiers.end(); ++modfierPSet) {
109  // Get plugin name
110  const std::string& pluginType = modfierPSet->getParameter<std::string>("plugin");
111  // Build the plugin
112  modifiers_.emplace_back(RecoTauModifierPluginFactory::get()->create(pluginType, *modfierPSet, consumesCollector()));
113  }
114 
115  // Check if we want to apply a final output selection
116  std::string selection = pset.getParameter<std::string>("outputSelection");
117  if (!selection.empty()) {
119  }
120  buildNullTaus_ = pset.getParameter<bool>("buildNullTaus");
121 
122  produces<reco::PFTauCollection>();
123 }
124 
126  // Get the jet input collection via a view of Candidates
128  evt.getByToken(jet_token, jetView);
129 
130  // Get the jet region producer
132  evt.getByToken(jetRegion_token, jetRegionHandle);
133 
134  // Get the charged hadron input collection
136  evt.getByToken(chargedHadron_token, chargedHadronAssoc);
137 
138  // Get the pizero input collection
140  evt.getByToken(piZero_token, piZeroAssoc);
141 
142  // Update all our builders and modifiers with the event info
143  for (auto& builder : builders_) {
144  builder->setup(evt, es);
145  }
146  for (auto& modifier : modifiers_) {
147  modifier->setup(evt, es);
148  }
149 
150  // Create output collection
151  auto output = std::make_unique<reco::PFTauCollection>();
152  output->reserve(jetView->size());
153 
154  // Loop over the jets and build the taus for each jet
155  for (size_t i_j = 0; i_j < jetView->size(); ++i_j) {
156  const auto& jetRef = jetView->refAt(i_j);
157  // Get the jet with extra constituents from an area around the jet
158  if (jetRef->pt() - minJetPt_ < 1e-5)
159  continue;
160  if (std::abs(jetRef->eta()) - maxJetAbsEta_ > -1e-5)
161  continue;
162  reco::JetBaseRef jetRegionRef = (*jetRegionHandle)[jetRef];
163  if (jetRegionRef.isNull()) {
164  throw cms::Exception("BadJetRegionRef") << "No jet region can be found for the current jet: " << jetRef.id();
165  }
166  // Remove all the jet constituents from the jet extras
167  std::vector<reco::CandidatePtr> jetCands = jetRef->daughterPtrVector();
168  std::vector<reco::CandidatePtr> allRegionalCands = jetRegionRef->daughterPtrVector();
169  // Sort both by ref key
170  std::sort(jetCands.begin(), jetCands.end());
171  std::sort(allRegionalCands.begin(), allRegionalCands.end());
172  // Get the regional junk candidates not in the jet.
173  std::vector<reco::CandidatePtr> uniqueRegionalCands;
174 
175  // This can actually be less than zero, if the jet has really crazy soft
176  // stuff really far away from the jet axis.
177  if (allRegionalCands.size() > jetCands.size()) {
178  uniqueRegionalCands.reserve(allRegionalCands.size() - jetCands.size());
179  }
180 
181  // Subtract the jet cands from the regional cands
182  std::set_difference(allRegionalCands.begin(),
183  allRegionalCands.end(),
184  jetCands.begin(),
185  jetCands.end(),
186  std::back_inserter(uniqueRegionalCands));
187 
188  // Get the charged hadrons associated with this jet
189  const std::vector<reco::PFRecoTauChargedHadron>& chargedHadrons = (*chargedHadronAssoc)[jetRef];
190 
191  // Get the pizeros associated with this jet
192  const std::vector<reco::RecoTauPiZero>& piZeros = (*piZeroAssoc)[jetRef];
193  // Loop over our builders and create the set of taus for this jet
194  unsigned int nTausBuilt = 0;
195  for (const auto& builder : builders_) {
196  // Get a ptr_vector of taus from the builder
198  (*builder)(jetRef, chargedHadrons, piZeros, uniqueRegionalCands));
199 
200  // Make sure all taus have their jetref set correctly
201  std::for_each(taus.begin(), taus.end(), boost::bind(&reco::PFTau::setjetRef, _1, reco::JetBaseRef(jetRef)));
202  // Copy without selection
203  if (!outputSelector_.get()) {
204  output->insert(output->end(), taus.begin(), taus.end());
205  nTausBuilt += taus.size();
206  } else {
207  // Copy only those that pass the selection.
208  for (auto const& tau : taus) {
209  if ((*outputSelector_)(tau)) {
210  nTausBuilt++;
211  output->push_back(tau);
212  }
213  }
214  }
215  }
216  // If we didn't build *any* taus for this jet, build a null tau if desired.
217  // The null PFTau has no content, but it's four vector is set to that of the
218  // jet.
219  if (!nTausBuilt && buildNullTaus_) {
220  reco::PFTau nullTau(std::numeric_limits<int>::quiet_NaN(), jetRef->p4());
221  nullTau.setjetRef(reco::JetBaseRef(jetRef));
222  output->push_back(nullTau);
223  }
224  }
225 
226  // Loop over the taus we have created and apply our modifiers to the taus
227  for (reco::PFTauCollection::iterator tau = output->begin(); tau != output->end(); ++tau) {
228  for (const auto& modifier : modifiers_) {
229  (*modifier)(*tau);
230  }
231  }
232 
233  for (auto& modifier : modifiers_) {
234  modifier->endEvent();
235  }
236 
237  evt.put(std::move(output));
238 }
239 
241  // combinatoricRecoTaus
243  desc.add<edm::InputTag>("piZeroSrc", edm::InputTag("ak4PFJetsRecoTauPiZeros"));
244 
245  edm::ParameterSetDescription pset_signalQualityCuts;
246  pset_signalQualityCuts.add<double>("maxDeltaZ", 0.4);
247  pset_signalQualityCuts.add<double>("minTrackPt", 0.5);
248  pset_signalQualityCuts.add<double>("minTrackVertexWeight", -1.0);
249  pset_signalQualityCuts.add<double>("maxTrackChi2", 100.0);
250  pset_signalQualityCuts.add<unsigned int>("minTrackPixelHits", 0);
251  pset_signalQualityCuts.add<double>("minGammaEt", 1.0);
252  pset_signalQualityCuts.add<unsigned int>("minTrackHits", 3);
253  pset_signalQualityCuts.add<double>("minNeutralHadronEt", 30.0);
254  pset_signalQualityCuts.add<double>("maxTransverseImpactParameter", 0.1);
255  pset_signalQualityCuts.addOptional<bool>("useTracksInsteadOfPFHadrons");
256 
257  edm::ParameterSetDescription pset_vxAssocQualityCuts;
258  pset_vxAssocQualityCuts.add<double>("minTrackPt", 0.5);
259  pset_vxAssocQualityCuts.add<double>("minTrackVertexWeight", -1.0);
260  pset_vxAssocQualityCuts.add<double>("maxTrackChi2", 100.0);
261  pset_vxAssocQualityCuts.add<unsigned int>("minTrackPixelHits", 0);
262  pset_vxAssocQualityCuts.add<double>("minGammaEt", 1.0);
263  pset_vxAssocQualityCuts.add<unsigned int>("minTrackHits", 3);
264  pset_vxAssocQualityCuts.add<double>("maxTransverseImpactParameter", 0.1);
265  pset_vxAssocQualityCuts.addOptional<bool>("useTracksInsteadOfPFHadrons");
266 
267  edm::ParameterSetDescription pset_isolationQualityCuts;
268  pset_isolationQualityCuts.add<double>("maxDeltaZ", 0.2);
269  pset_isolationQualityCuts.add<double>("minTrackPt", 1.0);
270  pset_isolationQualityCuts.add<double>("minTrackVertexWeight", -1.0);
271  pset_isolationQualityCuts.add<double>("maxTrackChi2", 100.0);
272  pset_isolationQualityCuts.add<unsigned int>("minTrackPixelHits", 0);
273  pset_isolationQualityCuts.add<double>("minGammaEt", 1.5);
274  pset_isolationQualityCuts.add<unsigned int>("minTrackHits", 8);
275  pset_isolationQualityCuts.add<double>("maxTransverseImpactParameter", 0.03);
276  pset_isolationQualityCuts.addOptional<bool>("useTracksInsteadOfPFHadrons");
277 
278  edm::ParameterSetDescription pset_qualityCuts;
279  pset_qualityCuts.add<edm::ParameterSetDescription>("signalQualityCuts", pset_signalQualityCuts);
280  pset_qualityCuts.add<edm::ParameterSetDescription>("vxAssocQualityCuts", pset_vxAssocQualityCuts);
281  pset_qualityCuts.add<edm::ParameterSetDescription>("isolationQualityCuts", pset_isolationQualityCuts);
282  pset_qualityCuts.add<std::string>("leadingTrkOrPFCandOption", "leadPFCand");
283  pset_qualityCuts.add<std::string>("pvFindingAlgo", "closestInDeltaZ");
284  pset_qualityCuts.add<edm::InputTag>("primaryVertexSrc", edm::InputTag("offlinePrimaryVertices"));
285  pset_qualityCuts.add<bool>("vertexTrackFiltering", false);
286  pset_qualityCuts.add<bool>("recoverLeadingTrk", false);
287 
288  {
289  edm::ParameterSetDescription vpsd_modifiers;
290  vpsd_modifiers.add<std::string>("name");
291  vpsd_modifiers.add<std::string>("plugin");
292  vpsd_modifiers.add<int>("verbosity", 0);
293 
294  vpsd_modifiers.add<edm::ParameterSetDescription>("qualityCuts", pset_qualityCuts);
295  vpsd_modifiers.addOptional<edm::InputTag>("ElectronPreIDProducer");
296  vpsd_modifiers.addOptional<std::string>("DataType");
297  vpsd_modifiers.addOptional<double>("maximumForElectrionPreIDOutput");
298  vpsd_modifiers.addOptional<double>("ElecPreIDLeadTkMatch_maxDR");
299  vpsd_modifiers.addOptional<double>("EcalStripSumE_minClusEnergy");
300  vpsd_modifiers.addOptional<double>("EcalStripSumE_deltaPhiOverQ_minValue");
301  vpsd_modifiers.addOptional<double>("EcalStripSumE_deltaPhiOverQ_maxValue");
302  vpsd_modifiers.addOptional<double>("EcalStripSumE_deltaEta");
303  vpsd_modifiers.addOptional<double>("dRaddNeutralHadron");
304  vpsd_modifiers.addOptional<double>("minGammaEt");
305  vpsd_modifiers.addOptional<double>("dRaddPhoton");
306  vpsd_modifiers.addOptional<double>("minNeutralHadronEt");
307  vpsd_modifiers.addOptional<edm::InputTag>("pfTauTagInfoSrc");
308 
309  desc.addVPSet("modifiers", vpsd_modifiers);
310  }
311 
312  desc.add<edm::InputTag>("jetRegionSrc", edm::InputTag("recoTauAK4PFJets08Region"));
313  desc.add<double>("maxJetAbsEta", 2.5);
314  desc.add<std::string>("outputSelection", "leadPFChargedHadrCand().isNonnull()");
315  desc.add<edm::InputTag>("chargedHadronSrc", edm::InputTag("ak4PFJetsRecoTauChargedHadrons"));
316  desc.add<double>("minJetPt", 14.0);
317  desc.add<edm::InputTag>("jetSrc", edm::InputTag("ak4PFJets"));
318 
319  {
320  edm::ParameterSetDescription desc_builders;
321  desc_builders.add<std::string>("name");
322  desc_builders.add<std::string>("plugin");
323  desc_builders.add<int>("verbosity", 0);
324 
325  desc_builders.add<edm::ParameterSetDescription>("qualityCuts", pset_qualityCuts);
326  {
327  edm::ParameterSetDescription desc_decayModes;
328  desc_decayModes.add<unsigned int>("nPiZeros", 0);
329  desc_decayModes.add<unsigned int>("maxPiZeros", 0);
330  desc_decayModes.add<unsigned int>("nCharged", 1);
331  desc_decayModes.add<unsigned int>("maxTracks", 6);
332  desc_builders.addVPSetOptional("decayModes", desc_decayModes);
333  }
334  desc_builders.add<double>("minAbsPhotonSumPt_insideSignalCone", 2.5);
335  desc_builders.add<double>("minRelPhotonSumPt_insideSignalCone", 0.1);
336  desc_builders.add<edm::InputTag>("pfCandSrc", edm::InputTag("particleFlow"));
337 
338  desc_builders.addOptional<std::string>("signalConeSize");
339  desc_builders.addOptional<double>("isolationConeSize");
340  desc_builders.addOptional<double>("minAbsPhotonSumPt_outsideSignalCone");
341  desc_builders.addOptional<double>("minRelPhotonSumPt_outsideSignalCone");
342  desc_builders.addOptional<std::string>("isoConeChargedHadrons");
343  desc_builders.addOptional<std::string>("isoConeNeutralHadrons");
344  desc_builders.addOptional<std::string>("isoConePiZeros");
345  desc_builders.addOptional<double>("leadObjectPt");
346  desc_builders.addOptional<std::string>("matchingCone");
347  desc_builders.addOptional<int>("maxSignalConeChargedHadrons");
348  desc_builders.addOptional<std::string>("signalConeChargedHadrons");
349  desc_builders.addOptional<std::string>("signalConeNeutralHadrons");
350  desc_builders.addOptional<std::string>("signalConePiZeros");
351  desc_builders.addOptional<bool>("usePFLeptons");
352 
353  std::vector<edm::ParameterSet> vpset_default;
354  {
355  edm::ParameterSet pset_default_builders;
356  pset_default_builders.addParameter<std::string>("name", "");
357  pset_default_builders.addParameter<std::string>("plugin", "");
358  pset_default_builders.addParameter<int>("verbosity", 0);
359  pset_default_builders.addParameter<double>("minAbsPhotonSumPt_insideSignalCone", 2.5);
360  pset_default_builders.addParameter<double>("minRelPhotonSumPt_insideSignalCone", 0.1);
361  pset_default_builders.addParameter<edm::InputTag>("pfCandSrc", edm::InputTag("particleFlow"));
362  vpset_default.push_back(pset_default_builders);
363  }
364  desc.addVPSet("builders", desc_builders, vpset_default);
365  }
366 
367  desc.add<bool>("buildNullTaus", false);
368  desc.add<int>("verbosity", 0);
369  descriptions.add("combinatoricRecoTaus", desc);
370 }
371 
T getParameter(std::string const &) const
edm::InputTag piZeroSrc_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
ParameterDescriptionBase * addVPSet(U const &iLabel, ParameterSetDescription const &validator, std::vector< ParameterSet > const &defaults)
~RecoTauProducer() override
def create(alignables, pedeDump, additionalData, outputFile, config)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
BuilderList builders_
ParameterDescriptionBase * addVPSetOptional(U const &iLabel, ParameterSetDescription const &validator, std::vector< ParameterSet > const &defaults)
edm::EDGetTokenT< reco::JetView > jet_token
selection
main part
Definition: corrVsCorr.py:100
size_type size() const
boost::ptr_vector< reco::PFTau > output_type
ModifierList modifiers_
std::vector< std::unique_ptr< Builder > > BuilderList
std::vector< std::unique_ptr< Modifier > > ModifierList
RefToBase< value_type > refAt(size_type i) const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
RecoTauProducer(const edm::ParameterSet &pset)
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:124
edm::EDGetTokenT< edm::AssociationMap< edm::OneToOne< reco::JetView, reco::JetView > > > jetRegion_token
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
edm::InputTag chargedHadronSrc_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
edm::InputTag jetSrc_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void produce(edm::Event &evt, const edm::EventSetup &es) override
bool isNull() const
Checks for null.
Definition: RefToBase.h:295
edm::EDGetTokenT< reco::JetPiZeroAssociation > piZero_token
reco::tau::RecoTauModifierPlugin Modifier
void add(std::string const &label, ParameterSetDescription const &psetDescription)
edm::EDGetTokenT< reco::PFJetChargedHadronAssociation > chargedHadron_token
void setjetRef(const JetBaseRef &)
Definition: PFTau.cc:56
reco::tau::RecoTauBuilderPlugin Builder
edm::InputTag jetRegionSrc_
def move(src, dest)
Definition: eostools.py:511
std::unique_ptr< StringCutObjectSelector< reco::PFTau > > outputSelector_