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 
31 
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 
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()) {
118  outputSelector_ = std::make_unique<StringCutObjectSelector<reco::PFTau>>(selection);
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(), [&](auto& arg) { arg.setjetRef(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 desc_qualityCuts;
247 
248  {
249  edm::ParameterSetDescription vpsd_modifiers;
250  vpsd_modifiers.add<std::string>("name");
251  vpsd_modifiers.add<std::string>("plugin");
252  vpsd_modifiers.add<int>("verbosity", 0);
253 
254  vpsd_modifiers.add<edm::ParameterSetDescription>("qualityCuts", desc_qualityCuts);
255  vpsd_modifiers.addOptional<edm::InputTag>("ElectronPreIDProducer");
256  vpsd_modifiers.addOptional<std::string>("DataType");
257  vpsd_modifiers.addOptional<double>("maximumForElectrionPreIDOutput");
258  vpsd_modifiers.addOptional<double>("ElecPreIDLeadTkMatch_maxDR");
259  vpsd_modifiers.addOptional<double>("EcalStripSumE_minClusEnergy");
260  vpsd_modifiers.addOptional<double>("EcalStripSumE_deltaPhiOverQ_minValue");
261  vpsd_modifiers.addOptional<double>("EcalStripSumE_deltaPhiOverQ_maxValue");
262  vpsd_modifiers.addOptional<double>("EcalStripSumE_deltaEta");
263  vpsd_modifiers.addOptional<double>("dRaddNeutralHadron");
264  vpsd_modifiers.addOptional<double>("minGammaEt");
265  vpsd_modifiers.addOptional<double>("dRaddPhoton");
266  vpsd_modifiers.addOptional<double>("minNeutralHadronEt");
267  vpsd_modifiers.addOptional<edm::InputTag>("pfTauTagInfoSrc");
268 
269  desc.addVPSet("modifiers", vpsd_modifiers);
270  }
271 
272  desc.add<edm::InputTag>("jetRegionSrc", edm::InputTag("recoTauAK4PFJets08Region"));
273  desc.add<double>("maxJetAbsEta", 2.5);
274  desc.add<std::string>("outputSelection", "leadPFChargedHadrCand().isNonnull()");
275  desc.add<edm::InputTag>("chargedHadronSrc", edm::InputTag("ak4PFJetsRecoTauChargedHadrons"));
276  desc.add<double>("minJetPt", 14.0);
277  desc.add<edm::InputTag>("jetSrc", edm::InputTag("ak4PFJets"));
278 
279  {
280  edm::ParameterSetDescription desc_builders;
281  desc_builders.add<std::string>("name");
282  desc_builders.add<std::string>("plugin");
283  desc_builders.add<int>("verbosity", 0);
284 
285  desc_builders.add<edm::ParameterSetDescription>("qualityCuts", desc_qualityCuts);
286  {
287  edm::ParameterSetDescription desc_decayModes;
288  desc_decayModes.add<unsigned int>("nPiZeros", 0);
289  desc_decayModes.add<unsigned int>("maxPiZeros", 0);
290  desc_decayModes.add<unsigned int>("nCharged", 1);
291  desc_decayModes.add<unsigned int>("maxTracks", 6);
292  desc_builders.addVPSetOptional("decayModes", desc_decayModes);
293  }
294  desc_builders.add<double>("minAbsPhotonSumPt_insideSignalCone", 2.5);
295  desc_builders.add<double>("minRelPhotonSumPt_insideSignalCone", 0.1);
296  desc_builders.add<edm::InputTag>("pfCandSrc", edm::InputTag("particleFlow"));
297 
298  desc_builders.addOptional<std::string>("signalConeSize");
299  desc_builders.addOptional<double>("isolationConeSize");
300  desc_builders.addOptional<double>("minAbsPhotonSumPt_outsideSignalCone");
301  desc_builders.addOptional<double>("minRelPhotonSumPt_outsideSignalCone");
302  desc_builders.addOptional<std::string>("isoConeChargedHadrons");
303  desc_builders.addOptional<std::string>("isoConeNeutralHadrons");
304  desc_builders.addOptional<std::string>("isoConePiZeros");
305  desc_builders.addOptional<double>("leadObjectPt");
306  desc_builders.addOptional<std::string>("matchingCone");
307  desc_builders.addOptional<int>("maxSignalConeChargedHadrons");
308  desc_builders.addOptional<std::string>("signalConeChargedHadrons");
309  desc_builders.addOptional<std::string>("signalConeNeutralHadrons");
310  desc_builders.addOptional<std::string>("signalConePiZeros");
311  desc_builders.addOptional<bool>("usePFLeptons");
312 
313  std::vector<edm::ParameterSet> vpset_default;
314  {
315  edm::ParameterSet pset_default_builders;
316  pset_default_builders.addParameter<std::string>("name", "");
317  pset_default_builders.addParameter<std::string>("plugin", "");
318  pset_default_builders.addParameter<int>("verbosity", 0);
319  pset_default_builders.addParameter<double>("minAbsPhotonSumPt_insideSignalCone", 2.5);
320  pset_default_builders.addParameter<double>("minRelPhotonSumPt_insideSignalCone", 0.1);
321  pset_default_builders.addParameter<edm::InputTag>("pfCandSrc", edm::InputTag("particleFlow"));
322  vpset_default.push_back(pset_default_builders);
323  }
324  desc.addVPSet("builders", desc_builders, vpset_default);
325  }
326 
327  desc.add<bool>("buildNullTaus", false);
328  desc.add<int>("verbosity", 0);
329  descriptions.add("combinatoricRecoTaus", desc);
330 }
331 
ConfigurationDescriptions.h
edm::RefToBase::isNull
bool isNull() const
Checks for null.
Definition: RefToBase.h:295
RecoTauProducer::chargedHadron_token
edm::EDGetTokenT< reco::PFJetChargedHadronAssociation > chargedHadron_token
Definition: RecoTauProducer.cc:70
RecoTauProducer::jetSrc_
edm::InputTag jetSrc_
Definition: RecoTauProducer.cc:60
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
RecoTauProducer::jetRegionSrc_
edm::InputTag jetRegionSrc_
Definition: RecoTauProducer.cc:61
RecoTauProducer::chargedHadronSrc_
edm::InputTag chargedHadronSrc_
Definition: RecoTauProducer.cc:62
ESHandle.h
RecoTauProducer::minJetPt_
double minJetPt_
Definition: RecoTauProducer.cc:65
RecoTauProducer::jetRegion_token
edm::EDGetTokenT< edm::AssociationMap< edm::OneToOne< reco::JetView, reco::JetView > > > jetRegion_token
Definition: RecoTauProducer.cc:69
metsig::tau
Definition: SignAlgoResolutions.h:49
RecoTauProducer::maxJetAbsEta_
double maxJetAbsEta_
Definition: RecoTauProducer.cc:66
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:72
edm::View::refAt
RefToBase< value_type > refAt(size_type i) const
edm::EDGetTokenT
Definition: EDGetToken.h:33
Tau3MuMonitor_cff.taus
taus
Definition: Tau3MuMonitor_cff.py:7
RecoTauProducer::produce
void produce(edm::Event &evt, const edm::EventSetup &es) override
Definition: RecoTauProducer.cc:125
RecoTauProducer::~RecoTauProducer
~RecoTauProducer() override
Definition: RecoTauProducer.cc:54
RecoTauProducer::RecoTauProducer
RecoTauProducer(const edm::ParameterSet &pset)
Definition: RecoTauProducer.cc:83
PFJetChargedHadronAssociation.h
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89285
PFJetCollection.h
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
JetPiZeroAssociation.h
HLT_FULL_cff.builders
builders
Definition: HLT_FULL_cff.py:32608
EDProducer.h
reco::tau::RecoTauBuilderPlugin
Definition: RecoTauBuilderPlugins.h:56
reco::PFTau
Definition: PFTau.h:36
RecoTauProducer::builders_
BuilderList builders_
Definition: RecoTauProducer.cc:73
beamerCreator.create
def create(alignables, pedeDump, additionalData, outputFile, config)
Definition: beamerCreator.py:44
Association.h
edm::Handle
Definition: AssociativeIterator.h:50
edm::ParameterSetDescription::addOptional
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:105
RecoTauProducer
Definition: RecoTauProducer.cc:46
MakerMacros.h
RecoTauProducer::outputSelector_
std::unique_ptr< StringCutObjectSelector< reco::PFTau > > outputSelector_
Definition: RecoTauProducer.cc:76
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
RecoTauProducer::modifiers_
ModifierList modifiers_
Definition: RecoTauProducer.cc:74
reco::tau::RecoTauBuilderPlugin::output_type
boost::ptr_vector< reco::PFTau > output_type
Definition: RecoTauBuilderPlugins.h:58
corrVsCorr.selection
selection
main part
Definition: corrVsCorr.py:100
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:535
RecoTauCommonUtilities.h
JetCollection.h
ParameterSetDescription.h
RecoTauProducer::BuilderList
std::vector< std::unique_ptr< Builder > > BuilderList
Definition: RecoTauProducer.cc:50
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::View::size
size_type size() const
RecoTauQualityCuts.h
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
edm::ParameterSet::addParameter
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:135
reco::tau::RecoTauQualityCuts::fillDescriptions
static void fillDescriptions(edm::ParameterSetDescription &descriptions)
Declare all parameters read from python config file.
Definition: RecoTauQualityCuts.cc:346
edm::Event::put
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
edm::stream::EDProducer
Definition: EDProducer.h:38
edm::EventSetup
Definition: EventSetup.h:58
get
#define get
RecoTauProducer::Modifier
reco::tau::RecoTauModifierPlugin Modifier
Definition: RecoTauProducer.cc:49
RecoTauBuilderPlugins.h
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
HistogramManager_cfi.VPSet
def VPSet(*args)
Definition: HistogramManager_cfi.py:404
eostools.move
def move(src, dest)
Definition: eostools.py:511
StringCutObjectSelector.h
reco::tau::RecoTauModifierPlugin
Definition: RecoTauBuilderPlugins.h:104
reco::PFTau::setjetRef
void setjetRef(const JetBaseRef &)
Definition: PFTau.cc:57
Exception
Definition: hltDiff.cc:245
PFTau.h
EventSetup.h
edm::RefToBase< Jet >
RecoTauProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: RecoTauProducer.cc:240
RecoTauProducer::jet_token
edm::EDGetTokenT< reco::JetView > jet_token
Definition: RecoTauProducer.cc:68
PFRecoTauChargedHadron.h
funct::arg
A arg
Definition: Factorize.h:31
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ParameterSet.h
RecoTauProducer::ModifierList
std::vector< std::unique_ptr< Modifier > > ModifierList
Definition: RecoTauProducer.cc:51
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15
edm::ParameterSetDescription::addVPSetOptional
ParameterDescriptionBase * addVPSetOptional(U const &iLabel, ParameterSetDescription const &validator, std::vector< ParameterSet > const &defaults)
Definition: ParameterSetDescription.h:163
RecoTauProducer::buildNullTaus_
bool buildNullTaus_
Definition: RecoTauProducer.cc:80
RecoTauProducer::piZeroSrc_
edm::InputTag piZeroSrc_
Definition: RecoTauProducer.cc:63
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
RecoTauProducer::piZero_token
edm::EDGetTokenT< reco::JetPiZeroAssociation > piZero_token
Definition: RecoTauProducer.cc:71
RecoTauProducer::Builder
reco::tau::RecoTauBuilderPlugin Builder
Definition: RecoTauProducer.cc:48