CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 actaul 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  * Author: Evan K. Friis (UC Davis)
16  *
17  */
18 #include <boost/ptr_container/ptr_vector.hpp>
19 #include <boost/foreach.hpp>
20 
21 #include <algorithm>
22 #include <functional>
23 
29 
32 
38 
40 
42  public:
45  typedef boost::ptr_vector<Builder> BuilderList;
46  typedef boost::ptr_vector<Modifier> ModifierList;
47 
48  explicit RecoTauProducer(const edm::ParameterSet& pset);
50  void produce(edm::Event& evt, const edm::EventSetup& es);
51 
52  private:
58  // Optional selection on the output of the taus
59  std::auto_ptr<StringCutObjectSelector<reco::PFTau> > outputSelector_;
60  // Whether or not to add build a tau from a jet for which the builders
61  // return no taus. The tau will have no content, only the four vector of
62  // the orginal jet.
64 };
65 
67  jetSrc_ = pset.getParameter<edm::InputTag>("jetSrc");
68  jetRegionSrc_ = pset.getParameter<edm::InputTag>("jetRegionSrc");
69  piZeroSrc_ = pset.getParameter<edm::InputTag>("piZeroSrc");
70 
71  typedef std::vector<edm::ParameterSet> VPSet;
72  // Get each of our tau builders
73  const VPSet& builders = pset.getParameter<VPSet>("builders");
74  for (VPSet::const_iterator builderPSet = builders.begin();
75  builderPSet != builders.end(); ++builderPSet) {
76  // Get plugin name
77  const std::string& pluginType =
78  builderPSet->getParameter<std::string>("plugin");
79  // Build the plugin
80  builders_.push_back(
82  pluginType, *builderPSet));
83 
84  }
85 
86  const VPSet& modfiers = pset.getParameter<VPSet>("modifiers");
87  for (VPSet::const_iterator modfierPSet = modfiers.begin();
88  modfierPSet != modfiers.end(); ++modfierPSet) {
89  // Get plugin name
90  const std::string& pluginType =
91  modfierPSet->getParameter<std::string>("plugin");
92  // Build the plugin
93  modifiers_.push_back(
95  pluginType, *modfierPSet));
96 
97  }
98 
99  // Check if we want to apply a final output selection
100  if (pset.exists("outputSelection")) {
101  std::string selection = pset.getParameter<std::string>("outputSelection");
102  if (selection != "") {
103  outputSelector_.reset(
104  new StringCutObjectSelector<reco::PFTau>(selection));
105  }
106  }
107  buildNullTaus_ = pset.getParameter<bool>("buildNullTaus");
108  produces<reco::PFTauCollection>();
109 }
110 
112  // Get the jet input collection via a view of Candidates
114  evt.getByLabel(jetSrc_, jetView);
115 
116  // Convert to a vector of PFJetRefs
118  reco::tau::castView<reco::PFJetRefVector>(jetView);
119 
120  // Get the jet region producer
122  evt.getByLabel(jetRegionSrc_, jetRegionHandle);
123 
124  // Get the pizero input collection
126  evt.getByLabel(piZeroSrc_, piZeroAssoc);
127 
128  // Update all our builders and modifiers with the event info
129  for (BuilderList::iterator builder = builders_.begin();
130  builder != builders_.end(); ++builder) {
131  builder->setup(evt, es);
132  }
133  for (ModifierList::iterator modifier = modifiers_.begin();
134  modifier != modifiers_.end(); ++modifier) {
135  modifier->setup(evt, es);
136  }
137 
138  // Create output collection
139  std::auto_ptr<reco::PFTauCollection> output(new reco::PFTauCollection());
140 
141  // Loop over the jets and build the taus for each jet
142  BOOST_FOREACH(reco::PFJetRef jetRef, jets) {
143  // Get the jet with extra constituents from an area around the jet
144  reco::PFJetRef jetRegionRef = (*jetRegionHandle)[jetRef];
145  if (jetRegionRef.isNull()) {
146  throw cms::Exception("BadJetRegionRef") << "No jet region can be"
147  << " found for the current jet: " << jetRef.id();
148  }
149  // Remove all the jet constituents from the jet extras
150  std::vector<reco::PFCandidatePtr> jetCands = jetRef->getPFConstituents();
151  std::vector<reco::PFCandidatePtr> allRegionalCands =
152  jetRegionRef->getPFConstituents();
153  // Sort both by ref key
154  std::sort(jetCands.begin(), jetCands.end());
155  std::sort(allRegionalCands.begin(), allRegionalCands.end());
156  // Get the regional junk candidates not in the jet.
157  std::vector<reco::PFCandidatePtr> uniqueRegionalCands;
158 
159  // This can actually be less than zero, if the jet has really crazy soft
160  // stuff really far away from the jet axis.
161  if (allRegionalCands.size() > jetCands.size())
162  uniqueRegionalCands.reserve(allRegionalCands.size() - jetCands.size());
163 
164  // Subtract the jet cands from the regional cands
165  std::set_difference(allRegionalCands.begin(), allRegionalCands.end(),
166  jetCands.begin(), jetCands.end(),
167  std::back_inserter(uniqueRegionalCands));
168 
169  // Get the PiZeros associated with this jet
170  const std::vector<reco::RecoTauPiZero>& piZeros = (*piZeroAssoc)[jetRef];
171  // Loop over our builders and create the set of taus for this jet
172  unsigned int nTausBuilt = 0;
173  for (BuilderList::const_iterator builder = builders_.begin();
174  builder != builders_.end(); ++builder) {
175  // Get a ptr_vector of taus from the builder
177  (*builder)(jetRef, piZeros, uniqueRegionalCands));
178  // Make sure all taus have their jetref set correctly
179  std::for_each(taus.begin(), taus.end(),
180  boost::bind(&reco::PFTau::setjetRef, _1, jetRef));
181  // Check this size of the taus built.
182  // Grow the vector if necessary
183  output->reserve(output->size() + taus.size());
184  // Copy without selection
185  if (!outputSelector_.get()) {
186  output->insert(output->end(), taus.begin(), taus.end());
187  nTausBuilt += taus.size();
188  } else {
189  // Copy only those that pass the selection.
190  BOOST_FOREACH(const reco::PFTau& tau, taus) {
191  if ((*outputSelector_)(tau)) {
192  nTausBuilt++;
193  output->push_back(tau);
194  }
195  }
196  }
197  }
198  // If we didn't build *any* taus for this jet, build a null tau if desired.
199  // The null PFTau has no content, but it's four vector is set to that of the
200  // jet.
201  if (!nTausBuilt && buildNullTaus_) {
202  reco::PFTau nullTau(std::numeric_limits<int>::quiet_NaN(), jetRef->p4());
203  nullTau.setjetRef(jetRef);
204  output->push_back(nullTau);
205  }
206  }
207 
208  // Loop over the taus we have created and apply our modifiers to the taus
209  for (reco::PFTauCollection::iterator tau = output->begin();
210  tau != output->end(); ++tau) {
211  for (ModifierList::const_iterator modifier = modifiers_.begin();
212  modifier != modifiers_.end(); ++modifier) {
213  (*modifier)(*tau);
214  }
215  }
216  evt.put(output);
217 }
218 
T getParameter(std::string const &) const
edm::InputTag piZeroSrc_
boost::ptr_vector< Modifier > ModifierList
std::vector< PFTau > PFTauCollection
collection of PFTau objects
Definition: PFTauFwd.h:9
BuilderList builders_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
selection
main part
Definition: corrVsCorr.py:98
bool exists(std::string const &parameterName) const
checks if a parameter exists
boost::ptr_vector< reco::PFTau > output_type
ModifierList modifiers_
std::auto_ptr< StringCutObjectSelector< reco::PFTau > > outputSelector_
void setjetRef(const PFJetRef &)
Definition: PFTau.cc:51
bool isNull() const
Checks for null.
Definition: Ref.h:247
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:94
RecoTauProducer(const edm::ParameterSet &pset)
vector< PseudoJet > jets
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
edm::InputTag jetSrc_
reco::tau::RecoTauModifierPlugin Modifier
reco::tau::RecoTauBuilderPlugin Builder
ProductID id() const
Accessor for product ID.
Definition: Ref.h:256
edm::InputTag jetRegionSrc_
void produce(edm::Event &evt, const edm::EventSetup &es)
boost::ptr_vector< Builder > BuilderList
SurfaceDeformation * create(int type, const std::vector< double > &params)
T get(const Candidate &c)
Definition: component.h:56