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 {
72  produces<edm::AssociationVector<PFTauRefProd, std::vector<std::vector<reco::VertexRef> > > >();
73  produces<VertexCollection>("PFTauSecondaryVertices");
74 }
75 
77 
78 }
79 
80 namespace {
81  const reco::Track* getTrack(const reco::Candidate& cand) {
82  const reco::PFCandidate* pfCand = dynamic_cast<const reco::PFCandidate*>(&cand);
83  if (pfCand != nullptr) {
84  if (pfCand->trackRef().isNonnull())
85  return &*pfCand->trackRef();
86  else if (pfCand->gsfTrackRef().isNonnull())
87  return &*pfCand->gsfTrackRef();
88  }
89  const pat::PackedCandidate* pCand = dynamic_cast<const pat::PackedCandidate*>(&cand);
90  if (pCand != nullptr && pCand->hasTrackDetails())
91  return &pCand->pseudoTrack();
92  return nullptr;
93  }
94 }
96  // Obtain
97  edm::ESHandle<TransientTrackBuilder> transTrackBuilder;
98  iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder",transTrackBuilder);
99 
101  iEvent.getByToken(PFTauToken_,Tau);
102 
103  // Set Association Map
104  auto AVPFTauSV = std::make_unique<edm::AssociationVector<PFTauRefProd, std::vector<std::vector<reco::VertexRef>>>>(PFTauRefProd(Tau));
105  auto VertexCollection_out = std::make_unique<VertexCollection>();
106  reco::VertexRefProd VertexRefProd_out = iEvent.getRefBeforePut<reco::VertexCollection>("PFTauSecondaryVertices");
107 
108  // For each Tau Run Algorithim
109  if(Tau.isValid()) {
110  for(reco::PFTauCollection::size_type iPFTau = 0; iPFTau < Tau->size(); iPFTau++) {
111  reco::PFTauRef RefPFTau(Tau, iPFTau);
112  std::vector<reco::VertexRef> SV;
113  if(RefPFTau->decayMode()>=5){
115  // Get tracks form PFTau daugthers
116  std::vector<reco::TransientTrack> transTrk;
117  TransientVertex transVtx;
118  const std::vector<edm::Ptr<reco::Candidate> > cands = RefPFTau->signalChargedHadrCands();
119  for (const auto& cand : cands) {
120  if (cand.isNull()) continue;
121  const reco::Track* track = getTrack(*cand);
122  if (track != nullptr)
123  transTrk.push_back(transTrackBuilder->build(*track));
124  }
126  // Fit the secondary vertex
127  bool FitOk(true);
128  KalmanVertexFitter kvf(true);
129  if(transTrk.size() > 1) {
130  transVtx = kvf.vertex(transTrk); //KalmanVertexFitter
131  } else {
132  FitOk = false;
133  }
134  if(!transVtx.hasRefittedTracks()) FitOk=false;
135  if(transVtx.refittedTracks().size()!=transTrk.size()) FitOk=false;
136  if(FitOk){
137  SV.push_back(reco::VertexRef(VertexRefProd_out, VertexCollection_out->size()));
138  VertexCollection_out->push_back(transVtx);
139  }
140  }
141  AVPFTauSV->setValue(iPFTau, SV);
142  }
143  }
144  iEvent.put(std::move(VertexCollection_out),"PFTauSecondaryVertices");
145  iEvent.put(std::move(AVPFTauSV));
146 }
147 
148 void
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:125
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:251
const edm::EDGetTokenT< std::vector< reco::PFTau > > PFTauToken_
PFTauSecondaryVertexProducer(const edm::ParameterSet &iConfig)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
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:442
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:74
RefProd< PROD > getRefBeforePut()
Definition: Event.h:150
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:71
reco::GsfTrackRef gsfTrackRef() const
Definition: PFCandidate.cc:480
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::vector< reco::TransientTrack > const & refittedTracks() const
def move(src, dest)
Definition: eostools.py:511