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