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 
29 
39 
43 
44 #include <memory>
45 
46 using namespace reco;
47 using namespace edm;
48 using namespace std;
49 
51  public:
52  enum Alg{useInputPV=0, usePVwithMaxSumPt, useTauPV};
53 
54  explicit PFTauSecondaryVertexProducer(const edm::ParameterSet& iConfig);
56  virtual void produce(edm::StreamID, edm::Event&,const edm::EventSetup&) const override;
57  private:
60 };
61 
63  PFTauTag_(iConfig.getParameter<edm::InputTag>("PFTauTag")),
64  PFTauToken_(consumes<std::vector<reco::PFTau> >(iConfig.getParameter<edm::InputTag>("PFTauTag")))
65 {
66  produces<edm::AssociationVector<PFTauRefProd, std::vector<std::vector<reco::VertexRef> > > >();
67  produces<VertexCollection>("PFTauSecondaryVertices");
68 }
69 
71 
72 }
73 
75  // Obtain
76  edm::ESHandle<TransientTrackBuilder> transTrackBuilder;
77  iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder",transTrackBuilder);
78 
80  iEvent.getByToken(PFTauToken_,Tau);
81 
82  // Set Association Map
83  auto AVPFTauSV = std::make_unique<edm::AssociationVector<PFTauRefProd, std::vector<std::vector<reco::VertexRef>>>>(PFTauRefProd(Tau));
84  auto VertexCollection_out = std::make_unique<VertexCollection>();
85  reco::VertexRefProd VertexRefProd_out = iEvent.getRefBeforePut<reco::VertexCollection>("PFTauSecondaryVertices");
86 
87  // For each Tau Run Algorithim
88  if(Tau.isValid()) {
89  for(reco::PFTauCollection::size_type iPFTau = 0; iPFTau < Tau->size(); iPFTau++) {
90  reco::PFTauRef RefPFTau(Tau, iPFTau);
91  std::vector<reco::VertexRef> SV;
92  if(RefPFTau->decayMode()>=5){
94  // Get tracks form PFTau daugthers
95  std::vector<reco::TransientTrack> transTrk;
96  TransientVertex transVtx;
97  const std::vector<edm::Ptr<reco::PFCandidate> > cands = RefPFTau->signalPFChargedHadrCands();
98  for (std::vector<edm::Ptr<reco::PFCandidate> >::const_iterator iter = cands.begin(); iter!=cands.end(); ++iter) {
99  if(iter->get()->trackRef().isNonnull())transTrk.push_back(transTrackBuilder->build(iter->get()->trackRef()));
100  else if(iter->get()->gsfTrackRef().isNonnull())transTrk.push_back(transTrackBuilder->build(iter->get()->gsfTrackRef()));
101  }
103  // Fit the secondary vertex
104  bool FitOk(true);
105  KalmanVertexFitter kvf(true);
106  try{
107  transVtx = kvf.vertex(transTrk); //KalmanVertexFitter
108  }catch(...){
109  FitOk=false;
110  }
111  if(!transVtx.hasRefittedTracks()) FitOk=false;
112  if(transVtx.refittedTracks().size()!=transTrk.size()) FitOk=false;
113  if(FitOk){
114  SV.push_back(reco::VertexRef(VertexRefProd_out, VertexCollection_out->size()));
115  VertexCollection_out->push_back(transVtx);
116  }
117  }
118  AVPFTauSV->setValue(iPFTau, SV);
119  }
120  }
121  iEvent.put(std::move(VertexCollection_out),"PFTauSecondaryVertices");
122  iEvent.put(std::move(AVPFTauSV));
123 }
124 
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
const edm::EDGetTokenT< std::vector< reco::PFTau > > PFTauToken_
PFTauSecondaryVertexProducer(const edm::ParameterSet &iConfig)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual CachingVertex< 5 > vertex(const std::vector< reco::TransientTrack > &tracks) const
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
int iEvent
Definition: GenABIO.cc:230
bool isValid() const
Definition: HandleBase.h:74
RefProd< PROD > getRefBeforePut()
Definition: Event.h:134
const T & get() const
Definition: EventSetup.h:56
virtual void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
fixed size matrix
HLT enums.
std::vector< reco::TransientTrack > const & refittedTracks() const
def move(src, dest)
Definition: eostools.py:510