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 
20 #include <algorithm>
21 #include <functional>
22 #include <memory>
23 
30 
34 
42 
44 
46 public:
49  typedef std::vector<std::unique_ptr<Builder>> BuilderList;
50  typedef std::vector<std::unique_ptr<Modifier>> ModifierList;
51 
52  explicit RecoTauProducer(const edm::ParameterSet& pset);
53  ~RecoTauProducer() override {}
54  void produce(edm::Event& evt, const edm::EventSetup& es) override;
55 
56  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
57 
58 private:
63 
64  double minJetPt_;
65  double maxJetAbsEta_;
66  //token definition
71 
74  // Optional selection on the output of the taus
75  std::unique_ptr<StringCutObjectSelector<reco::PFTau>> outputSelector_;
76  // Whether or not to add build a tau from a jet for which the builders
77  // return no taus. The tau will have no content, only the four vector of
78  // the orginal jet.
80 };
81 
83  jetSrc_ = pset.getParameter<edm::InputTag>("jetSrc");
84  jetRegionSrc_ = pset.getParameter<edm::InputTag>("jetRegionSrc");
85  chargedHadronSrc_ = pset.getParameter<edm::InputTag>("chargedHadronSrc");
86  piZeroSrc_ = pset.getParameter<edm::InputTag>("piZeroSrc");
87 
88  minJetPt_ = pset.getParameter<double>("minJetPt");
89  maxJetAbsEta_ = pset.getParameter<double>("maxJetAbsEta");
90  //consumes definition
91  jet_token = consumes<reco::JetView>(jetSrc_);
92  jetRegion_token = consumes<edm::AssociationMap<edm::OneToOne<reco::JetView, reco::JetView>>>(jetRegionSrc_);
93  chargedHadron_token = consumes<reco::PFJetChargedHadronAssociation>(chargedHadronSrc_);
94  piZero_token = consumes<reco::JetPiZeroAssociation>(piZeroSrc_);
95 
96  typedef std::vector<edm::ParameterSet> VPSet;
97  // Get each of our tau builders
98  const VPSet& builders = pset.getParameter<VPSet>("builders");
99  for (VPSet::const_iterator builderPSet = builders.begin(); builderPSet != builders.end(); ++builderPSet) {
100  // Get plugin name
101  const std::string& pluginType = builderPSet->getParameter<std::string>("plugin");
102  // Build the plugin
103  builders_.emplace_back(RecoTauBuilderPluginFactory::get()->create(pluginType, *builderPSet, consumesCollector()));
104  }
105 
106  const VPSet& modfiers = pset.getParameter<VPSet>("modifiers");
107  for (VPSet::const_iterator modfierPSet = modfiers.begin(); modfierPSet != modfiers.end(); ++modfierPSet) {
108  // Get plugin name
109  const std::string& pluginType = modfierPSet->getParameter<std::string>("plugin");
110  // Build the plugin
111  modifiers_.emplace_back(RecoTauModifierPluginFactory::get()->create(pluginType, *modfierPSet, consumesCollector()));
112  }
113 
114  // Check if we want to apply a final output selection
115  std::string selection = pset.getParameter<std::string>("outputSelection");
116  if (!selection.empty()) {
117  outputSelector_ = std::make_unique<StringCutObjectSelector<reco::PFTau>>(selection);
118  }
119  buildNullTaus_ = pset.getParameter<bool>("buildNullTaus");
120 
121  produces<reco::PFTauCollection>();
122 }
123 
125  // Get the jet input collection via a view of Candidates
127  evt.getByToken(jet_token, jetView);
128 
129  // Get the jet region producer
131  evt.getByToken(jetRegion_token, jetRegionHandle);
132 
133  // Get the charged hadron input collection
135  evt.getByToken(chargedHadron_token, chargedHadronAssoc);
136 
137  // Get the pizero input collection
139  evt.getByToken(piZero_token, piZeroAssoc);
140 
141  // Update all our builders and modifiers with the event info
142  for (auto& builder : builders_) {
143  builder->setup(evt, es);
144  }
145  for (auto& modifier : modifiers_) {
146  modifier->setup(evt, es);
147  }
148 
149  // Create output collection
150  auto output = std::make_unique<reco::PFTauCollection>();
151  output->reserve(jetView->size());
152 
153  // Loop over the jets and build the taus for each jet
154  for (size_t i_j = 0; i_j < jetView->size(); ++i_j) {
155  const auto& jetRef = jetView->refAt(i_j);
156  // Get the jet with extra constituents from an area around the jet
157  if (jetRef->pt() - minJetPt_ < 1e-5)
158  continue;
159  if (std::abs(jetRef->eta()) - maxJetAbsEta_ > -1e-5)
160  continue;
161  reco::JetBaseRef jetRegionRef = (*jetRegionHandle)[jetRef];
162  if (jetRegionRef.isNull()) {
163  throw cms::Exception("BadJetRegionRef") << "No jet region can be found for the current jet: " << jetRef.id();
164  }
165  // Remove all the jet constituents from the jet extras
166  std::vector<reco::CandidatePtr> jetCands = jetRef->daughterPtrVector();
167  std::vector<reco::CandidatePtr> allRegionalCands = jetRegionRef->daughterPtrVector();
168  // Sort both by ref key
169  std::sort(jetCands.begin(), jetCands.end());
170  std::sort(allRegionalCands.begin(), allRegionalCands.end());
171  // Get the regional junk candidates not in the jet.
172  std::vector<reco::CandidatePtr> uniqueRegionalCands;
173 
174  // This can actually be less than zero, if the jet has really crazy soft
175  // stuff really far away from the jet axis.
176  if (allRegionalCands.size() > jetCands.size()) {
177  uniqueRegionalCands.reserve(allRegionalCands.size() - jetCands.size());
178  }
179 
180  // Subtract the jet cands from the regional cands
181  std::set_difference(allRegionalCands.begin(),
182  allRegionalCands.end(),
183  jetCands.begin(),
184  jetCands.end(),
185  std::back_inserter(uniqueRegionalCands));
186 
187  // Get the charged hadrons associated with this jet
188  const std::vector<reco::PFRecoTauChargedHadron>& chargedHadrons = (*chargedHadronAssoc)[jetRef];
189 
190  // Get the pizeros associated with this jet
191  const std::vector<reco::RecoTauPiZero>& piZeros = (*piZeroAssoc)[jetRef];
192  // Loop over our builders and create the set of taus for this jet
193  unsigned int nTausBuilt = 0;
194  for (const auto& builder : builders_) {
195  // Get a std::vector of std::unique_ptr to taus from the builder
197  (*builder)(jetRef, chargedHadrons, piZeros, uniqueRegionalCands));
198 
199  // Make sure all taus have their jetref set correctly
200  std::for_each(taus.begin(), taus.end(), [&](auto& arg) { arg->setjetRef(reco::JetBaseRef(jetRef)); });
201  // Copy without selection
202  if (!outputSelector_.get()) {
203  for (auto& tau : taus) {
204  output->push_back(*tau);
205  }
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 (auto& tau : *output) {
229  for (const auto& modifier : modifiers_) {
230  (*modifier)(tau);
231  }
232  }
233 
234  for (auto& modifier : modifiers_) {
235  modifier->endEvent();
236  }
237 
238  evt.put(std::move(output));
239 }
240 
242  // combinatoricRecoTaus
244  desc.add<edm::InputTag>("piZeroSrc", edm::InputTag("ak4PFJetsRecoTauPiZeros"));
245 
246  edm::ParameterSetDescription desc_qualityCuts;
248 
249  {
250  edm::ParameterSetDescription vpsd_modifiers;
251  vpsd_modifiers.add<std::string>("name");
252  vpsd_modifiers.add<std::string>("plugin");
253  vpsd_modifiers.add<int>("verbosity", 0);
254 
255  vpsd_modifiers.add<edm::ParameterSetDescription>("qualityCuts", desc_qualityCuts);
256  vpsd_modifiers.addOptional<edm::InputTag>("ElectronPreIDProducer");
257  vpsd_modifiers.addOptional<std::string>("DataType");
258  vpsd_modifiers.addOptional<double>("maximumForElectrionPreIDOutput");
259  vpsd_modifiers.addOptional<double>("ElecPreIDLeadTkMatch_maxDR");
260  vpsd_modifiers.addOptional<double>("EcalStripSumE_minClusEnergy");
261  vpsd_modifiers.addOptional<double>("EcalStripSumE_deltaPhiOverQ_minValue");
262  vpsd_modifiers.addOptional<double>("EcalStripSumE_deltaPhiOverQ_maxValue");
263  vpsd_modifiers.addOptional<double>("EcalStripSumE_deltaEta");
264  vpsd_modifiers.addOptional<double>("dRaddNeutralHadron");
265  vpsd_modifiers.addOptional<double>("minGammaEt");
266  vpsd_modifiers.addOptional<double>("dRaddPhoton");
267  vpsd_modifiers.addOptional<double>("minNeutralHadronEt");
268  vpsd_modifiers.addOptional<edm::InputTag>("pfTauTagInfoSrc");
269  vpsd_modifiers.addOptional<edm::InputTag>("trackSrc");
270 
271  desc.addVPSet("modifiers", vpsd_modifiers);
272  }
273 
274  desc.add<edm::InputTag>("jetRegionSrc", edm::InputTag("recoTauAK4PFJets08Region"));
275  desc.add<double>("maxJetAbsEta", 2.5);
276  desc.add<std::string>("outputSelection", "leadPFChargedHadrCand().isNonnull()");
277  desc.add<edm::InputTag>("chargedHadronSrc", edm::InputTag("ak4PFJetsRecoTauChargedHadrons"));
278  desc.add<double>("minJetPt", 14.0);
279  desc.add<edm::InputTag>("jetSrc", edm::InputTag("ak4PFJets"));
280 
281  {
282  edm::ParameterSetDescription desc_builders;
283  desc_builders.add<std::string>("name");
284  desc_builders.add<std::string>("plugin");
285  desc_builders.add<int>("verbosity", 0);
286 
287  desc_builders.add<edm::ParameterSetDescription>("qualityCuts", desc_qualityCuts);
288  {
289  edm::ParameterSetDescription desc_decayModes;
290  desc_decayModes.add<unsigned int>("nPiZeros", 0);
291  desc_decayModes.add<unsigned int>("maxPiZeros", 0);
292  desc_decayModes.add<unsigned int>("nCharged", 1);
293  desc_decayModes.add<unsigned int>("maxTracks", 6);
294  desc_builders.addVPSetOptional("decayModes", desc_decayModes);
295  }
296  desc_builders.add<double>("minAbsPhotonSumPt_insideSignalCone", 2.5);
297  desc_builders.add<double>("minRelPhotonSumPt_insideSignalCone", 0.1);
298  desc_builders.add<edm::InputTag>("pfCandSrc", edm::InputTag("particleFlow"));
299 
300  desc_builders.addOptional<std::string>("signalConeSize");
301  desc_builders.addOptional<double>("isolationConeSize");
302  desc_builders.addOptional<double>("minAbsPhotonSumPt_outsideSignalCone");
303  desc_builders.addOptional<double>("minRelPhotonSumPt_outsideSignalCone");
304  desc_builders.addOptional<std::string>("isoConeChargedHadrons");
305  desc_builders.addOptional<std::string>("isoConeNeutralHadrons");
306  desc_builders.addOptional<std::string>("isoConePiZeros");
307  desc_builders.addOptional<double>("leadObjectPt");
308  desc_builders.addOptional<std::string>("matchingCone");
309  desc_builders.addOptional<int>("maxSignalConeChargedHadrons");
310  desc_builders.addOptional<std::string>("signalConeChargedHadrons");
311  desc_builders.addOptional<std::string>("signalConeNeutralHadrons");
312  desc_builders.addOptional<std::string>("signalConePiZeros");
313  desc_builders.addOptional<bool>("usePFLeptons");
314 
315  std::vector<edm::ParameterSet> vpset_default;
316  {
317  edm::ParameterSet pset_default_builders;
318  pset_default_builders.addParameter<std::string>("name", "");
319  pset_default_builders.addParameter<std::string>("plugin", "");
320  pset_default_builders.addParameter<int>("verbosity", 0);
321  pset_default_builders.addParameter<double>("minAbsPhotonSumPt_insideSignalCone", 2.5);
322  pset_default_builders.addParameter<double>("minRelPhotonSumPt_insideSignalCone", 0.1);
323  pset_default_builders.addParameter<edm::InputTag>("pfCandSrc", edm::InputTag("particleFlow"));
324  vpset_default.push_back(pset_default_builders);
325  }
326  desc.addVPSet("builders", desc_builders, vpset_default);
327  }
328 
329  desc.add<bool>("buildNullTaus", false);
330  desc.add<int>("verbosity", 0);
331  descriptions.add("combinatoricRecoTaus", desc);
332 }
333 
edm::InputTag piZeroSrc_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
RefToBase< value_type > refAt(size_type i) const
std::vector< std::unique_ptr< reco::PFTau > > output_type
~RecoTauProducer() override
static void fillDescriptions(edm::ParameterSetDescription &descriptions)
Declare all parameters read from python config file.
def create(alignables, pedeDump, additionalData, outputFile, config)
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
ModifierList modifiers_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:540
std::vector< std::unique_ptr< Builder > > BuilderList
A arg
Definition: Factorize.h:31
std::vector< std::unique_ptr< Modifier > > ModifierList
size_type size() const
RecoTauProducer(const edm::ParameterSet &pset)
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:135
edm::EDGetTokenT< edm::AssociationMap< edm::OneToOne< reco::JetView, reco::JetView > > > jetRegion_token
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::InputTag chargedHadronSrc_
bool isNull() const
Checks for null.
Definition: RefToBase.h:297
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
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:57
reco::tau::RecoTauBuilderPlugin Builder
#define get
edm::InputTag jetRegionSrc_
std::vector< std::string > set_difference(std::vector< std::string > const &v1, std::vector< std::string > const &v2)
def move(src, dest)
Definition: eostools.py:511
std::unique_ptr< StringCutObjectSelector< reco::PFTau > > outputSelector_