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 <functional>
14 #include <memory>
15 
17 
26 
31 
32 namespace reco {
33  namespace tau {
34 
35  namespace {
36  // Apply a hypothesis on the mass of the strips.
37  math::XYZTLorentzVector applyMassConstraint(const math::XYZTLorentzVector& vec, double mass) {
38  double factor = sqrt(vec.energy() * vec.energy() - mass * mass) / vec.P();
39  return math::XYZTLorentzVector(vec.px() * factor, vec.py() * factor, vec.pz() * factor, vec.energy());
40  }
41  } // namespace
42 
44  public:
47  // Return type is unique_ptr<PiZeroVector>
48  return_type operator()(const reco::Jet& jet) const override;
49  // Hook to update PV information
50  void beginEvent() override;
51 
52  private:
53  std::unique_ptr<RecoTauQualityCuts> qcuts_;
55 
56  std::vector<int> inputParticleIds_; //type of candidates to clusterize
57  double etaAssociationDistance_; //eta Clustering Association Distance
58  double phiAssociationDistance_; //phi Clustering Association Distance
59 
60  // Parameters for build strip combinations
64 
66  };
67 
70  qcuts_(new RecoTauQualityCuts(pset.getParameterSet("qualityCuts").getParameterSet("signalQualityCuts"))),
71  vertexAssociator_(pset.getParameter<edm::ParameterSet>("qualityCuts"), std::move(iC)) {
72  inputParticleIds_ = pset.getParameter<std::vector<int> >("stripCandidatesParticleIds");
73  etaAssociationDistance_ = pset.getParameter<double>("stripEtaAssociationDistance");
74  phiAssociationDistance_ = pset.getParameter<double>("stripPhiAssociationDistance");
75  combineStrips_ = pset.getParameter<bool>("makeCombinatoricStrips");
76  if (combineStrips_) {
77  maxStrips_ = pset.getParameter<int>("maxInputStrips");
78  combinatoricStripMassHypo_ = pset.getParameter<double>("stripMassWhenCombining");
79  }
80  }
81 
82  // Update the primary vertex
84 
86  // Get list of gamma candidates
87  typedef std::vector<reco::CandidatePtr> CandPtrs;
88  typedef CandPtrs::iterator CandIter;
90 
91  // Get the candidates passing our quality cuts
93  CandPtrs candsVector = qcuts_->filterCandRefs(pfCandidates(jet, inputParticleIds_));
94  //PFCandPtrs candsVector = qcuts_->filterCandRefs(pfGammas(jet));
95 
96  // Convert to stl::list to allow fast deletions
97  typedef std::list<reco::CandidatePtr> CandPtrList;
98  typedef std::list<reco::CandidatePtr>::iterator CandPtrListIter;
99  CandPtrList cands;
100  cands.insert(cands.end(), candsVector.begin(), candsVector.end());
101 
102  while (!cands.empty()) {
103  // Seed this new strip, and delete it from future strips
104  CandidatePtr seed = cands.front();
105  cands.pop_front();
106 
107  // Add a new candidate to our collection using this seed
108  std::unique_ptr<RecoTauPiZero> strip(new RecoTauPiZero(*seed, RecoTauPiZero::kStrips));
109  strip->addDaughter(seed);
110 
111  // Find all other objects in the strip
112  CandPtrListIter stripCand = cands.begin();
113  while (stripCand != cands.end()) {
114  if (fabs(strip->eta() - (*stripCand)->eta()) < etaAssociationDistance_ &&
115  fabs(deltaPhi(*strip, **stripCand)) < phiAssociationDistance_) {
116  // Add candidate to strip
117  strip->addDaughter(*stripCand);
118  // Update the strips four momenta
119  p4Builder_.set(*strip);
120  // Delete this candidate from future strips and move on to
121  // the next potential candidate
122  stripCand = cands.erase(stripCand);
123  } else {
124  // This candidate isn't compatabile - just move to the next candidate
125  ++stripCand;
126  }
127  }
128  // Update the vertex
129  if (strip->daughterPtr(0).isNonnull())
130  strip->setVertex(strip->daughterPtr(0)->vertex());
131  output.push_back(strip.get());
132  }
133 
134  // Check if we want to combine our strips
135  if (combineStrips_ && output.size() > 1) {
136  PiZeroVector stripCombinations;
137  // Sort the output by descending pt
138  output.sort(output.begin(), output.end(), [&](auto& arg1, auto& arg2) { return arg1.pt() > arg2.pt(); });
139  // Get the end of interesting set of strips to try and combine
140  PiZeroVector::const_iterator end_iter = takeNElements(output.begin(), output.end(), maxStrips_);
141 
142  // Look at all the combinations
143  for (PiZeroVector::const_iterator first = output.begin(); first != end_iter - 1; ++first) {
144  for (PiZeroVector::const_iterator second = first + 1; second != end_iter; ++second) {
145  Candidate::LorentzVector firstP4 = first->p4();
146  Candidate::LorentzVector secondP4 = second->p4();
147  // If we assume a certain mass for each strip apply it here.
148  firstP4 = applyMassConstraint(firstP4, combinatoricStripMassHypo_);
149  secondP4 = applyMassConstraint(secondP4, combinatoricStripMassHypo_);
150  Candidate::LorentzVector totalP4 = firstP4 + secondP4;
151  // Make our new combined strip
152  std::unique_ptr<RecoTauPiZero> combinedStrips(
153  new RecoTauPiZero(0,
154  totalP4,
155  Candidate::Point(0, 0, 0),
156  //111, 10001, true, RecoTauPiZero::kCombinatoricStrips));
157  111,
158  10001,
159  true,
161 
162  // Now loop over the strip members
163  for (auto const& gamma : first->daughterPtrVector()) {
164  combinedStrips->addDaughter(gamma);
165  }
166  for (auto const& gamma : second->daughterPtrVector()) {
167  combinedStrips->addDaughter(gamma);
168  }
169  // Update the vertex
170  if (combinedStrips->daughterPtr(0).isNonnull())
171  combinedStrips->setVertex(combinedStrips->daughterPtr(0)->vertex());
172  // Add to our collection of combined strips
173  stripCombinations.push_back(combinedStrips.get());
174  }
175  }
176  // When done doing all the combinations, add the combined strips to the
177  // output.
178  output.transfer(output.end(), stripCombinations);
179  }
180 
181  return output.release();
182  }
183  } // namespace tau
184 } // namespace reco
185 
reco::tau::RecoTauEventHolderPlugin::evt
const edm::Event * evt() const
Definition: RecoTauPluginsCommon.cc:16
reco::tau::RecoTauPiZeroStripPlugin::combineStrips_
bool combineStrips_
Definition: RecoTauPiZeroStripPlugin.cc:61
reco::Jet
Base class for all types of Jets.
Definition: Jet.h:20
reco::tau::RecoTauPiZeroStripPlugin::phiAssociationDistance_
double phiAssociationDistance_
Definition: RecoTauPiZeroStripPlugin.cc:58
reco::tau::RecoTauQualityCuts
Definition: RecoTauQualityCuts.h:35
metsig::tau
Definition: SignAlgoResolutions.h:49
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:72
reco::deltaPhi
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:26
deltaPhi.h
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:222
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
RecoTauPiZeroPlugins.h
RecoTauPiZero.h
RecoTauVertexAssociator.h
CandidateFwd.h
reco::tau::RecoTauPiZeroStripPlugin::maxStrips_
int maxStrips_
Definition: RecoTauPiZeroStripPlugin.cc:62
fileCollector.seed
seed
Definition: fileCollector.py:127
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:57
reco::tau::RecoTauPiZeroStripPlugin::p4Builder_
AddFourMomenta p4Builder_
Definition: RecoTauPiZeroStripPlugin.cc:65
reco::tau::RecoTauPiZeroStripPlugin::qcuts_
std::unique_ptr< RecoTauQualityCuts > qcuts_
Definition: RecoTauPiZeroStripPlugin.cc:53
reco::tau::RecoTauPiZeroStripPlugin::vertexAssociator_
RecoTauVertexAssociator vertexAssociator_
Definition: RecoTauPiZeroStripPlugin.cc:54
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
first
auto first
Definition: CAHitNtupletGeneratorKernelsImpl.h:112
Vertex.h
reco::tau::RecoTauPiZeroBuilderPlugin::PiZeroVector
boost::ptr_vector< RecoTauPiZero > PiZeroVector
Definition: RecoTauPiZeroPlugins.h:36
RecoTauQualityCuts.h
HLT_FULL_cff.cands
cands
Definition: HLT_FULL_cff.py:15146
CombinatoricGenerator.h
reco::tau::RecoTauVertexAssociator::associatedVertex
reco::VertexRef associatedVertex(const Jet &jet) const
Definition: RecoTauVertexAssociator.cc:378
edm::ParameterSet
Definition: ParameterSet.h:47
reco::tau::RecoTauPiZeroStripPlugin
Definition: RecoTauPiZeroStripPlugin.cc:43
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:68
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:85
edm::Ptr< Candidate >
reco::tau::RecoTauPiZeroStripPlugin::~RecoTauPiZeroStripPlugin
~RecoTauPiZeroStripPlugin() override
Definition: RecoTauPiZeroStripPlugin.cc:46
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:862
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:63
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:83
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
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:56
edm::ConsumesCollector
Definition: ConsumesCollector.h:45
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