CMS 3D CMS Logo

RecoTauPiZeroStripPlugin.cc
Go to the documentation of this file.
1 /*
2  * RecoTauPiZeroStripPlugin
3  *
4  * Merges PFGammas in a PFJet into Candidate piZeros defined as
5  * strips in eta-phi.
6  *
7  * Author: Michail Bachtis (University of Wisconsin)
8  *
9  * Code modifications: Evan Friis (UC Davis)
10  *
11  */
12 #include <algorithm>
13 #include <memory>
14 
15 #include "boost/bind.hpp"
16 
18 
27 
32 
33 namespace reco {
34  namespace tau {
35 
36  namespace {
37  // Apply a hypothesis on the mass of the strips.
38  math::XYZTLorentzVector applyMassConstraint(const math::XYZTLorentzVector& vec, double mass) {
39  double factor = sqrt(vec.energy() * vec.energy() - mass * mass) / vec.P();
40  return math::XYZTLorentzVector(vec.px() * factor, vec.py() * factor, vec.pz() * factor, vec.energy());
41  }
42  } // namespace
43 
45  public:
48  // Return type is unique_ptr<PiZeroVector>
49  return_type operator()(const reco::Jet& jet) const override;
50  // Hook to update PV information
51  void beginEvent() override;
52 
53  private:
54  std::unique_ptr<RecoTauQualityCuts> qcuts_;
56 
57  std::vector<int> inputParticleIds_; //type of candidates to clusterize
58  double etaAssociationDistance_; //eta Clustering Association Distance
59  double phiAssociationDistance_; //phi Clustering Association Distance
60 
61  // Parameters for build strip combinations
65 
67  };
68 
71  qcuts_(new RecoTauQualityCuts(pset.getParameterSet("qualityCuts").getParameterSet("signalQualityCuts"))),
72  vertexAssociator_(pset.getParameter<edm::ParameterSet>("qualityCuts"), std::move(iC)) {
73  inputParticleIds_ = pset.getParameter<std::vector<int> >("stripCandidatesParticleIds");
74  etaAssociationDistance_ = pset.getParameter<double>("stripEtaAssociationDistance");
75  phiAssociationDistance_ = pset.getParameter<double>("stripPhiAssociationDistance");
76  combineStrips_ = pset.getParameter<bool>("makeCombinatoricStrips");
77  if (combineStrips_) {
78  maxStrips_ = pset.getParameter<int>("maxInputStrips");
79  combinatoricStripMassHypo_ = pset.getParameter<double>("stripMassWhenCombining");
80  }
81  }
82 
83  // Update the primary vertex
85 
87  // Get list of gamma candidates
88  typedef std::vector<reco::CandidatePtr> CandPtrs;
89  typedef CandPtrs::iterator CandIter;
91 
92  // Get the candidates passing our quality cuts
94  CandPtrs candsVector = qcuts_->filterCandRefs(pfCandidates(jet, inputParticleIds_));
95  //PFCandPtrs candsVector = qcuts_->filterCandRefs(pfGammas(jet));
96 
97  // Convert to stl::list to allow fast deletions
98  typedef std::list<reco::CandidatePtr> CandPtrList;
99  typedef std::list<reco::CandidatePtr>::iterator CandPtrListIter;
100  CandPtrList cands;
101  cands.insert(cands.end(), candsVector.begin(), candsVector.end());
102 
103  while (!cands.empty()) {
104  // Seed this new strip, and delete it from future strips
105  CandidatePtr seed = cands.front();
106  cands.pop_front();
107 
108  // Add a new candidate to our collection using this seed
109  std::unique_ptr<RecoTauPiZero> strip(new RecoTauPiZero(*seed, RecoTauPiZero::kStrips));
110  strip->addDaughter(seed);
111 
112  // Find all other objects in the strip
113  CandPtrListIter stripCand = cands.begin();
114  while (stripCand != cands.end()) {
115  if (fabs(strip->eta() - (*stripCand)->eta()) < etaAssociationDistance_ &&
116  fabs(deltaPhi(*strip, **stripCand)) < phiAssociationDistance_) {
117  // Add candidate to strip
118  strip->addDaughter(*stripCand);
119  // Update the strips four momenta
120  p4Builder_.set(*strip);
121  // Delete this candidate from future strips and move on to
122  // the next potential candidate
123  stripCand = cands.erase(stripCand);
124  } else {
125  // This candidate isn't compatabile - just move to the next candidate
126  ++stripCand;
127  }
128  }
129  // Update the vertex
130  if (strip->daughterPtr(0).isNonnull())
131  strip->setVertex(strip->daughterPtr(0)->vertex());
132  output.push_back(strip.get());
133  }
134 
135  // Check if we want to combine our strips
136  if (combineStrips_ && output.size() > 1) {
137  PiZeroVector stripCombinations;
138  // Sort the output by descending pt
139  output.sort(
140  output.begin(), output.end(), boost::bind(&RecoTauPiZero::pt, _1) > boost::bind(&RecoTauPiZero::pt, _2));
141  // Get the end of interesting set of strips to try and combine
142  PiZeroVector::const_iterator end_iter = takeNElements(output.begin(), output.end(), maxStrips_);
143 
144  // Look at all the combinations
145  for (PiZeroVector::const_iterator first = output.begin(); first != end_iter - 1; ++first) {
146  for (PiZeroVector::const_iterator second = first + 1; second != end_iter; ++second) {
147  Candidate::LorentzVector firstP4 = first->p4();
148  Candidate::LorentzVector secondP4 = second->p4();
149  // If we assume a certain mass for each strip apply it here.
150  firstP4 = applyMassConstraint(firstP4, combinatoricStripMassHypo_);
151  secondP4 = applyMassConstraint(secondP4, combinatoricStripMassHypo_);
152  Candidate::LorentzVector totalP4 = firstP4 + secondP4;
153  // Make our new combined strip
154  std::unique_ptr<RecoTauPiZero> combinedStrips(
155  new RecoTauPiZero(0,
156  totalP4,
157  Candidate::Point(0, 0, 0),
158  //111, 10001, true, RecoTauPiZero::kCombinatoricStrips));
159  111,
160  10001,
161  true,
163 
164  // Now loop over the strip members
165  for (auto const& gamma : first->daughterPtrVector()) {
166  combinedStrips->addDaughter(gamma);
167  }
168  for (auto const& gamma : second->daughterPtrVector()) {
169  combinedStrips->addDaughter(gamma);
170  }
171  // Update the vertex
172  if (combinedStrips->daughterPtr(0).isNonnull())
173  combinedStrips->setVertex(combinedStrips->daughterPtr(0)->vertex());
174  // Add to our collection of combined strips
175  stripCombinations.push_back(combinedStrips.get());
176  }
177  }
178  // When done doing all the combinations, add the combined strips to the
179  // output.
180  output.transfer(output.end(), stripCombinations);
181  }
182 
183  return output.release();
184  }
185  } // namespace tau
186 } // namespace reco
187 
reco::tau::RecoTauEventHolderPlugin::evt
const edm::Event * evt() const
Definition: RecoTauPluginsCommon.cc:16
reco::tau::RecoTauPiZeroStripPlugin::combineStrips_
bool combineStrips_
Definition: RecoTauPiZeroStripPlugin.cc:62
reco::Jet
Base class for all types of Jets.
Definition: Jet.h:20
reco::tau::RecoTauPiZeroStripPlugin::phiAssociationDistance_
double phiAssociationDistance_
Definition: RecoTauPiZeroStripPlugin.cc:59
reco::tau::RecoTauQualityCuts
Definition: RecoTauQualityCuts.h:34
metsig::tau
Definition: SignAlgoResolutions.h:49
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:32
reco::deltaPhi
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:26
edm
HLT enums.
Definition: AlignableModifier.h:19
digitizers_cfi.strip
strip
Definition: digitizers_cfi.py:19
PFJet.h
CustomPhysics_cfi.gamma
gamma
Definition: CustomPhysics_cfi.py:17
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:215
reco::LeafCandidate::pt
double pt() const final
transverse momentum
Definition: LeafCandidate.h:146
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
RecoTauPiZeroPlugins.h
RecoTauPiZero.h
dqmdumpme.first
first
Definition: dqmdumpme.py:55
RecoTauVertexAssociator.h
CandidateFwd.h
reco::tau::RecoTauPiZeroStripPlugin::maxStrips_
int maxStrips_
Definition: RecoTauPiZeroStripPlugin.cc:63
MakerMacros.h
reco::RecoTauPiZero::kUndefined
Definition: RecoTauPiZero.h:11
reco::tau::RecoTauVertexAssociator
Definition: RecoTauVertexAssociator.h:50
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
reco::tau::RecoTauPiZeroStripPlugin::etaAssociationDistance_
double etaAssociationDistance_
Definition: RecoTauPiZeroStripPlugin.cc:58
reco::tau::RecoTauPiZeroStripPlugin::p4Builder_
AddFourMomenta p4Builder_
Definition: RecoTauPiZeroStripPlugin.cc:66
reco::tau::RecoTauPiZeroStripPlugin::qcuts_
std::unique_ptr< RecoTauQualityCuts > qcuts_
Definition: RecoTauPiZeroStripPlugin.cc:54
reco::tau::RecoTauPiZeroStripPlugin::vertexAssociator_
RecoTauVertexAssociator vertexAssociator_
Definition: RecoTauPiZeroStripPlugin.cc:55
DQMScaleToClient_cfi.factor
factor
Definition: DQMScaleToClient_cfi.py:8
RecoTauCommonUtilities.h
DEFINE_EDM_PLUGIN
#define DEFINE_EDM_PLUGIN(factory, type, name)
Definition: PluginFactory.h:124
Vertex.h
reco::tau::RecoTauPiZeroBuilderPlugin::PiZeroVector
boost::ptr_vector< RecoTauPiZero > PiZeroVector
Definition: RecoTauPiZeroPlugins.h:36
RecoTauQualityCuts.h
CombinatoricGenerator.h
reco::tau::RecoTauVertexAssociator::associatedVertex
reco::VertexRef associatedVertex(const Jet &jet) const
Definition: RecoTauVertexAssociator.cc:378
edm::ParameterSet
Definition: ParameterSet.h:36
reco::tau::RecoTauPiZeroStripPlugin
Definition: RecoTauPiZeroStripPlugin.cc:44
ParameterSet
Definition: Functions.h:16
edmplugin::PluginFactory
Definition: PluginFactory.h:34
AddFourMomenta.h
reco::tau::RecoTauPiZeroStripPlugin::RecoTauPiZeroStripPlugin
RecoTauPiZeroStripPlugin(const edm::ParameterSet &pset, edm::ConsumesCollector &&iC)
Definition: RecoTauPiZeroStripPlugin.cc:69
CandPtrs
std::vector< reco::CandidatePtr > CandPtrs
Definition: RecoTauCommonUtilities.cc:13
reco::tau::RecoTauVertexAssociator::setEvent
void setEvent(const edm::Event &evt)
Load the vertices from the event.
Definition: RecoTauVertexAssociator.cc:242
reco::tau::RecoTauPiZeroStripPlugin::operator()
return_type operator()(const reco::Jet &jet) const override
Build a collection of piZeros from objects in the input jet.
Definition: RecoTauPiZeroStripPlugin.cc:86
edm::Ptr< Candidate >
reco::tau::RecoTauPiZeroStripPlugin::~RecoTauPiZeroStripPlugin
~RecoTauPiZeroStripPlugin() override
Definition: RecoTauPiZeroStripPlugin.cc:47
VertexFwd.h
reco::tau::takeNElements
InputIterator takeNElements(const InputIterator &begin, const InputIterator &end, size_t N)
Definition: RecoTauCommonUtilities.h:104
edm::getParameterSet
ParameterSet const & getParameterSet(ParameterSetID const &id)
Definition: ParameterSet.cc:855
reco::RecoTauPiZero
Definition: RecoTauPiZero.h:7
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
reco::tau::RecoTauPiZeroStripPlugin::combinatoricStripMassHypo_
double combinatoricStripMassHypo_
Definition: RecoTauPiZeroStripPlugin.cc:64
math::XYZTLorentzVector
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
metsig::jet
Definition: SignAlgoResolutions.h:47
reco::tau::RecoTauPiZeroBuilderPlugin
Definition: RecoTauPiZeroPlugins.h:33
reco::tau::RecoTauPiZeroStripPlugin::beginEvent
void beginEvent() override
Hook called at the beginning of the event.
Definition: RecoTauPiZeroStripPlugin.cc:84
EgHLTOffHistBins_cfi.mass
mass
Definition: EgHLTOffHistBins_cfi.py:34
AddFourMomenta::set
void set(reco::Candidate &c) const
set up a candidate
Definition: AddFourMomenta.cc:6
HLT_2018_cff.cands
cands
Definition: HLT_2018_cff.py:13762
AddFourMomenta
Definition: AddFourMomenta.h:18
Candidate.h
reco::tau::pfCandidates
std::vector< CandidatePtr > pfCandidates(const Jet &jet, int particleId, bool sort=true)
Definition: RecoTauCommonUtilities.cc:59
CandIter
CandPtrs::iterator CandIter
Definition: RecoTauCommonUtilities.cc:14
reco::Candidate::LorentzVector
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:36
reco::Candidate::Point
math::XYZPoint Point
point in the space
Definition: Candidate.h:40
reco::tau::RecoTauPiZeroStripPlugin::inputParticleIds_
std::vector< int > inputParticleIds_
Definition: RecoTauPiZeroStripPlugin.cc:57
edm::ConsumesCollector
Definition: ConsumesCollector.h:39
deltaPhi.h
SurveyInfoScenario_cff.seed
seed
Definition: SurveyInfoScenario_cff.py:295
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
reco::RecoTauPiZero::kStrips
Definition: RecoTauPiZero.h:14
reco::tau::RecoTauPiZeroBuilderPlugin::return_type
std::unique_ptr< PiZeroVector > return_type
Definition: RecoTauPiZeroPlugins.h:39