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