CMS 3D CMS Logo

PFTauSecondaryVertexProducer.cc
Go to the documentation of this file.
1 /* class PFTauSecondaryVertexProducer
2  * EDProducer of the
3  * authors: Ian M. Nugent
4  * This work is based on the impact parameter work by Rosamaria Venditti and reconstructing the 3 prong taus.
5  * The idea of the fully reconstructing the tau using a kinematic fit comes from
6  * Lars Perchalla and Philip Sauerland Theses under Achim Stahl supervision. This
7  * work was continued by Ian M. Nugent and Vladimir Cherepanov.
8  * Thanks goes to Christian Veelken and Evan Klose Friis for their help and suggestions.
9  */
10 
14 
23 
26 
31 
42 
46 
47 #include <memory>
48 
49 using namespace reco;
50 using namespace edm;
51 using namespace std;
52 
54 public:
55  enum Alg { useInputPV = 0, usePVwithMaxSumPt, useTauPV };
56 
57  explicit PFTauSecondaryVertexProducer(const edm::ParameterSet& iConfig);
58  ~PFTauSecondaryVertexProducer() override;
59  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
60  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
61 
62 private:
66 };
67 
69  : PFTauTag_(iConfig.getParameter<edm::InputTag>("PFTauTag")),
70  PFTauToken_(consumes<std::vector<reco::PFTau>>(iConfig.getParameter<edm::InputTag>("PFTauTag"))),
71  transTrackBuilderToken_(esConsumes(edm::ESInputTag{"", "TransientTrackBuilder"})) {
72  produces<edm::AssociationVector<PFTauRefProd, std::vector<std::vector<reco::VertexRef>>>>();
73  produces<VertexCollection>("PFTauSecondaryVertices");
74 }
75 
77 
78 namespace {
79  const reco::Track* getTrack(const reco::Candidate& cand) {
80  const reco::PFCandidate* pfCand = dynamic_cast<const reco::PFCandidate*>(&cand);
81  if (pfCand != nullptr) {
82  if (pfCand->trackRef().isNonnull())
83  return &*pfCand->trackRef();
84  else if (pfCand->gsfTrackRef().isNonnull())
85  return &*pfCand->gsfTrackRef();
86  }
87  const pat::PackedCandidate* pCand = dynamic_cast<const pat::PackedCandidate*>(&cand);
88  if (pCand != nullptr && pCand->hasTrackDetails())
89  return &pCand->pseudoTrack();
90  return nullptr;
91  }
92 } // namespace
94  // Obtain
95  auto const& transTrackBuilder = iSetup.getData(transTrackBuilderToken_);
96 
98  iEvent.getByToken(PFTauToken_, Tau);
99 
100  // Set Association Map
101  auto AVPFTauSV = std::make_unique<edm::AssociationVector<PFTauRefProd, std::vector<std::vector<reco::VertexRef>>>>(
102  PFTauRefProd(Tau));
103  auto VertexCollection_out = std::make_unique<VertexCollection>();
104  reco::VertexRefProd VertexRefProd_out = iEvent.getRefBeforePut<reco::VertexCollection>("PFTauSecondaryVertices");
105 
106  // For each Tau Run Algorithim
107  if (Tau.isValid()) {
108  for (reco::PFTauCollection::size_type iPFTau = 0; iPFTau < Tau->size(); iPFTau++) {
109  reco::PFTauRef RefPFTau(Tau, iPFTau);
110  std::vector<reco::VertexRef> SV;
111  if (RefPFTau->decayMode() >= 5) {
113  // Get tracks form PFTau daugthers
114  std::vector<reco::TransientTrack> transTrk;
115  TransientVertex transVtx;
116  const std::vector<edm::Ptr<reco::Candidate>> cands = RefPFTau->signalChargedHadrCands();
117  for (const auto& cand : cands) {
118  if (cand.isNull())
119  continue;
120  const reco::Track* track = getTrack(*cand);
121  if (track != nullptr)
122  transTrk.push_back(transTrackBuilder.build(*track));
123  }
125  // Fit the secondary vertex
126  bool FitOk(true);
127  KalmanVertexFitter kvf(true);
128  if (transTrk.size() > 1) {
129  transVtx = kvf.vertex(transTrk); //KalmanVertexFitter
130  } else {
131  FitOk = false;
132  }
133  if (!transVtx.hasRefittedTracks())
134  FitOk = false;
135  if (transVtx.refittedTracks().size() != transTrk.size())
136  FitOk = false;
137  if (FitOk) {
138  SV.push_back(reco::VertexRef(VertexRefProd_out, VertexCollection_out->size()));
139  VertexCollection_out->push_back(transVtx);
140  }
141  }
142  AVPFTauSV->setValue(iPFTau, SV);
143  }
144  }
145  iEvent.put(std::move(VertexCollection_out), "PFTauSecondaryVertices");
146  iEvent.put(std::move(AVPFTauSV));
147 }
148 
150  // PFTauSecondaryVertexProducer
152  desc.add<edm::InputTag>("PFTauTag", edm::InputTag("hpsPFTauProducer"));
153  descriptions.add("PFTauSecondaryVertexProducer", desc);
154 }
155 
reco::GsfTrackRef gsfTrackRef() const
Definition: PFCandidate.cc:462
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
const edm::EDGetTokenT< std::vector< reco::PFTau > > PFTauToken_
PFTauSecondaryVertexProducer(const edm::ParameterSet &iConfig)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
edm::RefProd< PFTauCollection > PFTauRefProd
references to PFTau collection
Definition: PFTauFwd.h:15
uint16_t size_type
CachingVertex< 5 > vertex(const std::vector< reco::TransientTrack > &tracks) const override
int iEvent
Definition: GenABIO.cc:224
bool getData(T &iHolder) const
Definition: EventSetup.h:122
Definition: Tau.py:1
static const TrackGhostTrackState * getTrack(const BasicGhostTrackState *basic)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
bool hasRefittedTracks() const
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:41
fixed size matrix
HLT enums.
const edm::ESGetToken< TransientTrackBuilder, TransientTrackRecord > transTrackBuilderToken_
reco::TrackRef trackRef() const
Definition: PFCandidate.cc:430
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
def move(src, dest)
Definition: eostools.py:511
virtual const reco::Track & pseudoTrack() const
std::vector< reco::TransientTrack > const & refittedTracks() const
bool hasTrackDetails() const
Return true if a bestTrack can be extracted from this Candidate.