CMS 3D CMS Logo

RecoTauPiZeroProducer.cc
Go to the documentation of this file.
1 /*
2  * RecoTauPiZeroProducer
3  *
4  * Author: Evan K. Friis, UC Davis
5  *
6  * Associates reconstructed PiZeros to PFJets. The PiZeros are built using one
7  * or more RecoTauBuilder plugins. Any overlaps (PiZeros sharing constituents)
8  * are removed, with the best PiZero candidates taken. The 'best' are defined
9  * via the input list of RecoTauPiZeroQualityPlugins, which form a
10  * lexicograpical ranking.
11  *
12  */
13 
14 #include <boost/ptr_container/ptr_vector.hpp>
15 #include <boost/ptr_container/ptr_list.hpp>
16 #include <algorithm>
17 #include <functional>
18 
28 
32 
37 
40 
42  public:
45 
47  ~RecoTauPiZeroProducer() override {}
48  void produce(edm::Event& evt, const edm::EventSetup& es) override;
49  void print(const std::vector<reco::RecoTauPiZero>& piZeros,
50  std::ostream& out);
51 
52  static void fillDescriptions(edm::ConfigurationDescriptions & descriptions);
53 
54  private:
55  typedef boost::ptr_vector<Builder> builderList;
56  typedef boost::ptr_vector<Ranker> rankerList;
57  typedef boost::ptr_vector<reco::RecoTauPiZero> PiZeroVector;
58  typedef boost::ptr_list<reco::RecoTauPiZero> PiZeroList;
59 
62 
63  builderList builders_;
64  rankerList rankers_;
65  std::auto_ptr<PiZeroPredicate> predicate_;
66  double piZeroMass_;
67 
68  // Output selector
69  std::auto_ptr<StringCutObjectSelector<reco::RecoTauPiZero> >
71 
72  //consumes interface
74 
75  double minJetPt_;
76  double maxJetAbsEta_;
77 
79 };
80 
82 {
83  cand_token = consumes<reco::JetView>( pset.getParameter<edm::InputTag>("jetSrc"));
84  minJetPt_ = pset.getParameter<double>("minJetPt");
85  maxJetAbsEta_ = pset.getParameter<double>("maxJetAbsEta");
86 
87  typedef std::vector<edm::ParameterSet> VPSet;
88  // Get the mass hypothesis for the pizeros
89  piZeroMass_ = pset.getParameter<double>("massHypothesis");
90 
91  // Get each of our PiZero builders
92  const VPSet& builders = pset.getParameter<VPSet>("builders");
93 
94  for (VPSet::const_iterator builderPSet = builders.begin();
95  builderPSet != builders.end(); ++builderPSet) {
96  // Get plugin name
97  const std::string& pluginType =
98  builderPSet->getParameter<std::string>("plugin");
99  // Build the plugin
101  pluginType, *builderPSet, consumesCollector()));
102  }
103 
104  // Get each of our quality rankers
105  const VPSet& rankers = pset.getParameter<VPSet>("ranking");
106  for (VPSet::const_iterator rankerPSet = rankers.begin();
107  rankerPSet != rankers.end(); ++rankerPSet) {
108  const std::string& pluginType =
109  rankerPSet->getParameter<std::string>("plugin");
111  pluginType, *rankerPSet));
112  }
113 
114  // Build the sorting predicate
115  predicate_ = std::auto_ptr<PiZeroPredicate>(new PiZeroPredicate(rankers_));
116 
117  // now all producers apply a final output selection
118  std::string selection = pset.getParameter<std::string>("outputSelection");
119  if (!selection.empty()) {
120  outputSelector_.reset(
122  }
123 
124  verbosity_ = pset.getParameter<int>("verbosity");
125 
126  produces<reco::JetPiZeroAssociation>();
127 }
128 
130 {
131  // Get a view of our jets via the base candidates
133  evt.getByToken(cand_token, jetView);
134 
135  // Give each of our plugins a chance at doing something with the edm::Event
136  for(auto& builder : builders_) {
137  builder.setup(evt, es);
138  }
139 
140  // Make our association
141  std::unique_ptr<reco::JetPiZeroAssociation> association;
142 
143  association = std::make_unique<reco::JetPiZeroAssociation>(reco::JetRefBaseProd(jetView));
144 
145  // Loop over our jets
146  size_t nJets = jetView->size();
147  for (size_t i = 0; i < nJets; ++i) {
148  const reco::JetBaseRef jet(jetView->refAt(i));
149 
150  if(jet->pt() - minJetPt_ < 1e-5) continue;
151  if(std::abs(jet->eta()) - maxJetAbsEta_ > -1e-5) continue;
152  // Build our global list of RecoTauPiZero
153  PiZeroList dirtyPiZeros;
154 
155  // Compute the pi zeros from this jet for all the desired algorithms
156  for(auto const& builder : builders_) {
157  try {
158  PiZeroVector result(builder(*jet));
159  dirtyPiZeros.transfer(dirtyPiZeros.end(), result);
160  } catch ( cms::Exception &exception) {
161  edm::LogError("BuilderPluginException")
162  << "Exception caught in builder plugin " << builder.name()
163  << ", rethrowing" << std::endl;
164  throw exception;
165  }
166  }
167  // Rank the candidates according to our quality plugins
168  dirtyPiZeros.sort(*predicate_);
169 
170  // Keep track of the photons in the clean collection
171  std::vector<reco::RecoTauPiZero> cleanPiZeros;
172  std::set<reco::CandidatePtr> photonsInCleanCollection;
173  while (!dirtyPiZeros.empty()) {
174  // Pull our candidate pi zero from the front of the list
175  std::auto_ptr<reco::RecoTauPiZero> toAdd(
176  dirtyPiZeros.pop_front().release());
177  // If this doesn't pass our basic selection, discard it.
178  if (!(*outputSelector_)(*toAdd)) {
179  continue;
180  }
181  // Find the sub-gammas that are not already in the cleaned collection
182  std::vector<reco::CandidatePtr> uniqueGammas;
183  std::set_difference(toAdd->daughterPtrVector().begin(),
184  toAdd->daughterPtrVector().end(),
185  photonsInCleanCollection.begin(),
186  photonsInCleanCollection.end(),
187  std::back_inserter(uniqueGammas));
188  // If the pi zero has no unique gammas, discard it. Note toAdd is deleted
189  // when it goes out of scope.
190  if (uniqueGammas.empty()) {
191  continue;
192  } else if (uniqueGammas.size() == toAdd->daughterPtrVector().size()) {
193  // Check if it is composed entirely of unique gammas. In this case
194  // immediately add it to the clean collection.
195  photonsInCleanCollection.insert(toAdd->daughterPtrVector().begin(),
196  toAdd->daughterPtrVector().end());
197  cleanPiZeros.push_back(*toAdd);
198  } else {
199  // Otherwise update the pizero that contains only the unique gammas and
200  // add it back into the sorted list of dirty PiZeros
201  toAdd->clearDaughters();
202  // Add each of the unique daughters back to the pizero
203  for(auto const& gamma : uniqueGammas) {
204  toAdd->addDaughter(gamma);
205  }
206  // Update the four vector
207  AddFourMomenta p4Builder_;
208  p4Builder_.set(*toAdd);
209  // Put this pi zero back into the collection of sorted dirty pizeros
210  PiZeroList::iterator insertionPoint = std::lower_bound(
211  dirtyPiZeros.begin(), dirtyPiZeros.end(), *toAdd, *predicate_);
212  dirtyPiZeros.insert(insertionPoint, toAdd);
213  }
214  }
215  // Apply the mass hypothesis if desired
216  if (piZeroMass_ >= 0) {
217  for( auto& cleanPiZero: cleanPiZeros )
218  { cleanPiZero.setMass(this->piZeroMass_);};
219  }
220  // Add to association
221  if ( verbosity_ >= 2 ) {
222  print(cleanPiZeros, std::cout);
223  }
224  association->setValue(jet.key(), cleanPiZeros);
225  }
226  evt.put(std::move(association));
227 }
228 
229 // Print some helpful information
231  const std::vector<reco::RecoTauPiZero>& piZeros, std::ostream& out) {
232  const unsigned int width = 25;
233  for(auto const& piZero : piZeros) {
234  out << piZero;
235  out << "* Rankers:" << std::endl;
236  for (rankerList::const_iterator ranker = rankers_.begin();
237  ranker != rankers_.end(); ++ranker) {
238  out << "* " << std::setiosflags(std::ios::left)
239  << std::setw(width) << ranker->name()
240  << " " << std::resetiosflags(std::ios::left)
241  << std::setprecision(3) << (*ranker)(piZero);
242  out << std::endl;
243  }
244  }
245 }
246 
247 void
249  // common parameter descriptions
250  edm::ParameterSetDescription desc_ranking;
251  desc_ranking.add<std::string>("selectionPassFunction","Func");
252  desc_ranking.add<double>("selectionFailValue",1000);
253  desc_ranking.add<std::string>("selection","Sel");
254  desc_ranking.add<std::string>("name","name");
255  desc_ranking.add<std::string>("plugin","plugin");
256  edm::ParameterSet pset_ranking;
257  pset_ranking.addParameter<std::string>("selectionPassFunction","");
258  pset_ranking.addParameter<double>("selectionFailValue",1000);
259  pset_ranking.addParameter<std::string>("selection","");
260  pset_ranking.addParameter<std::string>("name","");
261  pset_ranking.addParameter<std::string>("plugin","");
262  std::vector<edm::ParameterSet> vpsd_ranking;
263  vpsd_ranking.push_back(pset_ranking);
264 
265  edm::ParameterSetDescription desc_signalQualityCuts;
266  desc_signalQualityCuts.add<double>("maxDeltaZ", 0.4);
267  desc_signalQualityCuts.add<double>("minTrackPt", 0.5);
268  desc_signalQualityCuts.add<double>("minTrackVertexWeight", -1.0);
269  desc_signalQualityCuts.add<double>("maxTrackChi2", 100.0);
270  desc_signalQualityCuts.add<unsigned int>("minTrackPixelHits", 0);
271  desc_signalQualityCuts.add<double>("minGammaEt", 1.0);
272  desc_signalQualityCuts.add<unsigned int>("minTrackHits", 3);
273  desc_signalQualityCuts.addOptional<double>("minNeutralHadronEt");
274  desc_signalQualityCuts.add<double>("maxTransverseImpactParameter", 0.1);
275  desc_signalQualityCuts.addOptional<bool>("useTracksInsteadOfPFHadrons");
276 
277  edm::ParameterSetDescription desc_vxAssocQualityCuts;
278  desc_vxAssocQualityCuts.add<double>("minTrackPt", 0.5);
279  desc_vxAssocQualityCuts.add<double>("minTrackVertexWeight", -1.0);
280  desc_vxAssocQualityCuts.add<double>("maxTrackChi2", 100.0);
281  desc_vxAssocQualityCuts.add<unsigned int>("minTrackPixelHits", 0);
282  desc_vxAssocQualityCuts.add<double>("minGammaEt", 1.0);
283  desc_vxAssocQualityCuts.add<unsigned int>("minTrackHits", 3);
284  desc_vxAssocQualityCuts.add<double>("maxTransverseImpactParameter", 0.1);
285  desc_vxAssocQualityCuts.addOptional<bool>("useTracksInsteadOfPFHadrons");
286 
287  edm::ParameterSetDescription desc_isolationQualityCuts;
288  desc_isolationQualityCuts.add<double>("maxDeltaZ", 0.2);
289  desc_isolationQualityCuts.add<double>("minTrackPt", 1.0);
290  desc_isolationQualityCuts.add<double>("minTrackVertexWeight", -1.0);
291  desc_isolationQualityCuts.add<double>("maxTrackChi2", 100.0);
292  desc_isolationQualityCuts.add<unsigned int>("minTrackPixelHits", 0);
293  desc_isolationQualityCuts.add<double>("minGammaEt", 1.5);
294  desc_isolationQualityCuts.add<unsigned int>("minTrackHits", 8);
295  desc_isolationQualityCuts.add<double>("maxTransverseImpactParameter", 0.03);
296  desc_isolationQualityCuts.addOptional<bool>("useTracksInsteadOfPFHadrons");
297 
298  edm::ParameterSetDescription desc_qualityCuts;
299  desc_qualityCuts.add<edm::ParameterSetDescription>("signalQualityCuts", desc_signalQualityCuts);
300  desc_qualityCuts.add<edm::ParameterSetDescription>("vxAssocQualityCuts", desc_vxAssocQualityCuts);
301  desc_qualityCuts.add<edm::ParameterSetDescription>("isolationQualityCuts", desc_isolationQualityCuts);
302  desc_qualityCuts.add<std::string>("leadingTrkOrPFCandOption", "leadPFCand");
303  desc_qualityCuts.add<std::string>("pvFindingAlgo", "closestInDeltaZ");
304  desc_qualityCuts.add<edm::InputTag>("primaryVertexSrc", edm::InputTag("offlinePrimaryVertices"));
305  desc_qualityCuts.add<bool>("vertexTrackFiltering", false);
306  desc_qualityCuts.add<bool>("recoverLeadingTrk", false);
307 
308  edm::ParameterSet pset_builders;
309  pset_builders.addParameter<std::string>("name","");
310  pset_builders.addParameter<std::string>("plugin","");
312  pset_builders.addParameter<edm::ParameterSet>("qualityCuts",qualityCuts);
313  pset_builders.addParameter<int>("verbosity",0);
314 
315  {
316  // Tailored on ak4PFJetsLegacyHPSPiZeros
318  desc.add<double>("massHypothesis", 0.136);
319  desc.addVPSet("ranking", desc_ranking, vpsd_ranking);
320  desc.add<int>("verbosity", 0);
321  desc.add<double>("maxJetAbsEta", 2.5);
322  desc.add<std::string>("outputSelection", "pt > 0");
323  desc.add<double>("minJetPt", 14.0);
324  desc.add<edm::InputTag>("jetSrc", edm::InputTag("ak4PFJets"));
325 
326  edm::ParameterSetDescription desc_builders;
327  {
329  psd0.add<std::string>("function", "TMath::Min(0.3, TMath::Max(0.05, [0]*TMath::Power(pT, -[1])))");
330  psd0.add<double>("par1", 0.707716);
331  psd0.add<double>("par0", 0.352476);
332  desc_builders.addOptional<edm::ParameterSetDescription>("stripPhiAssociationDistanceFunc", psd0);
333  }
334  {
336  psd0.add<std::string>("function", "TMath::Min(0.15, TMath::Max(0.05, [0]*TMath::Power(pT, -[1])))");
337  psd0.add<double>("par1", 0.658701);
338  psd0.add<double>("par0", 0.197077);
339  desc_builders.addOptional<edm::ParameterSetDescription>("stripEtaAssociationDistanceFunc", psd0);
340  }
341  desc_builders.addOptional<double>("stripEtaAssociationDistance", 0.05);
342  desc_builders.addOptional<double>("stripPhiAssociationDistance", 0.2);
343 
344  desc_builders.add<edm::ParameterSetDescription>("qualityCuts", desc_qualityCuts);
345 
346  desc_builders.add<std::string>("name");
347  desc_builders.add<std::string>("plugin");
348  desc_builders.add<int>("verbosity", 0);
349 
350  desc_builders.addOptional<bool>("makeCombinatoricStrips");
351  desc_builders.addOptional<int>("maxStripBuildIterations");
352  desc_builders.addOptional<double>("minGammaEtStripAdd");
353  desc_builders.addOptional<double>("minGammaEtStripSeed");
354  desc_builders.addOptional<double>("minStripEt");
355  desc_builders.addOptional<std::vector<int>>("stripCandidatesParticleIds");
356  desc_builders.addOptional<bool>("updateStripAfterEachDaughter");
357  desc_builders.addOptional<bool>("applyElecTrackQcuts");
358 
359  std::vector<edm::ParameterSet> vpsd_builders;
360  vpsd_builders.push_back(pset_builders);
361  desc.addVPSet("builders", desc_builders, vpsd_builders);
362 
363  descriptions.add("recoTauPiZeroProducer", desc);
364 
365  }
366 
367 }
368 
T getParameter(std::string const &) const
void produce(edm::Event &evt, const edm::EventSetup &es) override
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)
def create(alignables, pedeDump, additionalData, outputFile, config)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
reco::tau::RecoTauPiZeroQualityPlugin Ranker
selection
main part
Definition: corrVsCorr.py:100
RecoTauPiZeroProducer(const edm::ParameterSet &pset)
size_type size() const
reco::tau::RecoTauLexicographicalRanking< rankerList, reco::RecoTauPiZero > PiZeroPredicate
void print(const std::vector< reco::RecoTauPiZero > &piZeros, std::ostream &out)
RefToBase< value_type > refAt(size_type i) const
edm::RefToBaseProd< reco::Jet > JetRefBaseProd
Definition: JetCollection.h:14
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
reco::tau::RecoTauPiZeroBuilderPlugin Builder
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:125
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ParameterDescriptionBase * add(U const &iLabel, T const &value)
boost::ptr_vector< reco::RecoTauPiZero > PiZeroVector
boost::ptr_vector< Builder > builderList
boost::ptr_list< reco::RecoTauPiZero > PiZeroList
void add(std::string const &label, ParameterSetDescription const &psetDescription)
edm::EDGetTokenT< reco::JetView > cand_token
boost::ptr_vector< Ranker > rankerList
void set(reco::Candidate &c) const
set up a candidate
std::auto_ptr< StringCutObjectSelector< reco::RecoTauPiZero > > outputSelector_
def move(src, dest)
Definition: eostools.py:511
T get(const Candidate &c)
Definition: component.h:55
std::auto_ptr< PiZeroPredicate > predicate_