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