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 
24 
27 
32 
43 
47 
48 #include <memory>
49 
50 using namespace reco;
51 using namespace edm;
52 using namespace std;
53 
55 public:
56  enum Alg { useInputPV = 0, usePVwithMaxSumPt, useTauPV };
57 
58  explicit PFTauSecondaryVertexProducer(const edm::ParameterSet& iConfig);
59  ~PFTauSecondaryVertexProducer() override;
60  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
61  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
62 
63 private:
66 };
67 
69  : PFTauTag_(iConfig.getParameter<edm::InputTag>("PFTauTag")),
70  PFTauToken_(consumes<std::vector<reco::PFTau>>(iConfig.getParameter<edm::InputTag>("PFTauTag"))) {
71  produces<edm::AssociationVector<PFTauRefProd, std::vector<std::vector<reco::VertexRef>>>>();
72  produces<VertexCollection>("PFTauSecondaryVertices");
73 }
74 
76 
77 namespace {
78  const reco::Track* getTrack(const reco::Candidate& cand) {
79  const reco::PFCandidate* pfCand = dynamic_cast<const reco::PFCandidate*>(&cand);
80  if (pfCand != nullptr) {
81  if (pfCand->trackRef().isNonnull())
82  return &*pfCand->trackRef();
83  else if (pfCand->gsfTrackRef().isNonnull())
84  return &*pfCand->gsfTrackRef();
85  }
86  const pat::PackedCandidate* pCand = dynamic_cast<const pat::PackedCandidate*>(&cand);
87  if (pCand != nullptr && pCand->hasTrackDetails())
88  return &pCand->pseudoTrack();
89  return nullptr;
90  }
91 } // namespace
93  // Obtain
94  edm::ESHandle<TransientTrackBuilder> transTrackBuilder;
95  iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder", transTrackBuilder);
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 
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
const edm::EDGetTokenT< std::vector< reco::PFTau > > PFTauToken_
PFTauSecondaryVertexProducer(const edm::ParameterSet &iConfig)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
reco::TransientTrack build(const reco::Track *p) const
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
bool hasRefittedTracks() const
edm::RefProd< PFTauCollection > PFTauRefProd
references to PFTau collection
Definition: PFTauFwd.h:15
uint16_t size_type
reco::TrackRef trackRef() const
Definition: PFCandidate.cc:408
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
CachingVertex< 5 > vertex(const std::vector< reco::TransientTrack > &tracks) const override
virtual const reco::Track & pseudoTrack() const
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool isValid() const
Definition: HandleBase.h:70
RefProd< PROD > getRefBeforePut()
Definition: Event.h:156
bool hasTrackDetails() const
Return true if a bestTrack can be extracted from this Candidate.
static const TrackGhostTrackState * getTrack(const BasicGhostTrackState *basic)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:40
fixed size matrix
HLT enums.
T get() const
Definition: EventSetup.h:73
reco::GsfTrackRef gsfTrackRef() const
Definition: PFCandidate.cc:440
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::vector< reco::TransientTrack > const & refittedTracks() const
def move(src, dest)
Definition: eostools.py:511