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