CMS 3D CMS Logo

List of all members | Classes | Public Types | Public Member Functions | Private Attributes
PFTauPrimaryVertexProducer Class Referencefinal
Inheritance diagram for PFTauPrimaryVertexProducer:
edm::stream::EDProducer<>

Classes

struct  DiscCutPair
 

Public Types

enum  Alg { useInputPV =0, useFontPV }
 
typedef std::vector< DiscCutPair * > DiscCutPairVec
 
- Public Types inherited from edm::stream::EDProducer<>
typedef CacheContexts< T... > CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T... > HasAbility
 
typedef CacheTypes::LuminosityBlockCache LuminosityBlockCache
 
typedef LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCacheLuminosityBlockContext
 
typedef CacheTypes::LuminosityBlockSummaryCache LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache, GlobalCacheRunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 

Public Member Functions

 PFTauPrimaryVertexProducer (const edm::ParameterSet &iConfig)
 
void produce (edm::Event &, const edm::EventSetup &) override
 
 ~PFTauPrimaryVertexProducer () override
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
bool hasAbilityToProduceInLumis () const final
 
bool hasAbilityToProduceInRuns () const final
 

Private Attributes

int Algorithm_
 
edm::InputTag beamSpotTag_
 
edm::EDGetTokenT< reco::BeamSpotbeamSpotToken_
 
std::unique_ptr< StringCutObjectSelector< reco::PFTau > > cut_
 
DiscCutPairVec discriminators_
 
edm::InputTag ElectronTag_
 
edm::EDGetTokenT< std::vector< reco::Electron > > ElectronToken_
 
edm::InputTag MuonTag_
 
edm::EDGetTokenT< std::vector< reco::Muon > > MuonToken_
 
edm::InputTag PFTauTag_
 
edm::EDGetTokenT< std::vector< reco::PFTau > > PFTauToken_
 
edm::InputTag PVTag_
 
edm::EDGetTokenT< reco::VertexCollectionPVToken_
 
edm::ParameterSet qualityCutsPSet_
 
bool RemoveElectronTracks_
 
bool RemoveMuonTracks_
 
bool useBeamSpot_
 
bool useSelectedTaus_
 
std::unique_ptr< tau::RecoTauVertexAssociatorvertexAssociator_
 

Detailed Description

Definition at line 58 of file PFTauPrimaryVertexProducer.cc.

Member Typedef Documentation

Definition at line 70 of file PFTauPrimaryVertexProducer.cc.

Member Enumeration Documentation

Constructor & Destructor Documentation

PFTauPrimaryVertexProducer::PFTauPrimaryVertexProducer ( const edm::ParameterSet iConfig)
explicit

Definition at line 98 of file PFTauPrimaryVertexProducer.cc.

References PFTauPrimaryVertexProducer::DiscCutPair::cut_, cut_, PFTauPrimaryVertexProducer::DiscCutPair::cutFormula_, pfDeepCMVADiscriminatorsJetTags_cfi::discriminators, discriminators_, edm::ParameterSet::exists(), edm::ParameterSet::getParameter(), PFTauPrimaryVertexProducer::DiscCutPair::inputToken_, muonDTDigis_cfi::pset, qualityCutsPSet_, AlCaHLTBitMon_QueryRunRegistry::string, and vertexAssociator_.

98  :
99  PFTauTag_(iConfig.getParameter<edm::InputTag>("PFTauTag")),
100  PFTauToken_(consumes<std::vector<reco::PFTau> >(PFTauTag_)),
101  ElectronTag_(iConfig.getParameter<edm::InputTag>("ElectronTag")),
102  ElectronToken_(consumes<std::vector<reco::Electron> >(ElectronTag_)),
103  MuonTag_(iConfig.getParameter<edm::InputTag>("MuonTag")),
104  MuonToken_(consumes<std::vector<reco::Muon> >(MuonTag_)),
105  PVTag_(iConfig.getParameter<edm::InputTag>("PVTag")),
106  PVToken_(consumes<reco::VertexCollection>(PVTag_)),
107  beamSpotTag_(iConfig.getParameter<edm::InputTag>("beamSpot")),
108  beamSpotToken_(consumes<reco::BeamSpot>(beamSpotTag_)),
109  Algorithm_(iConfig.getParameter<int>("Algorithm")),
110  qualityCutsPSet_(iConfig.getParameter<edm::ParameterSet>("qualityCuts")),
111  useBeamSpot_(iConfig.getParameter<bool>("useBeamSpot")),
112  useSelectedTaus_(iConfig.getParameter<bool>("useSelectedTaus")),
113  RemoveMuonTracks_(iConfig.getParameter<bool>("RemoveMuonTracks")),
114  RemoveElectronTracks_(iConfig.getParameter<bool>("RemoveElectronTracks"))
115 {
117  std::vector<edm::ParameterSet> discriminators =iConfig.getParameter<std::vector<edm::ParameterSet> >("discriminators");
118  // Build each of our cuts
119  for(auto const& pset : discriminators) {
120  DiscCutPair* newCut = new DiscCutPair();
121  newCut->inputToken_ =consumes<reco::PFTauDiscriminator>(pset.getParameter<edm::InputTag>("discriminator"));
122 
123  if ( pset.existsAs<std::string>("selectionCut") ) newCut->cutFormula_ = new TFormula("selectionCut", pset.getParameter<std::string>("selectionCut").data());
124  else newCut->cut_ = pset.getParameter<double>("selectionCut");
125  discriminators_.push_back(newCut);
126  }
127  // Build a string cut if desired
128  if (iConfig.exists("cut")) cut_.reset(new StringCutObjectSelector<reco::PFTau>(iConfig.getParameter<std::string>( "cut" )));
130  produces<edm::AssociationVector<PFTauRefProd, std::vector<reco::VertexRef> > >();
131  produces<VertexCollection>("PFTauPrimaryVertices");
132 
133  vertexAssociator_.reset(new tau::RecoTauVertexAssociator(qualityCutsPSet_,consumesCollector()));
134 }
T getParameter(std::string const &) const
edm::EDGetTokenT< reco::BeamSpot > beamSpotToken_
edm::EDGetTokenT< std::vector< reco::PFTau > > PFTauToken_
bool exists(std::string const &parameterName) const
checks if a parameter exists
edm::EDGetTokenT< reco::VertexCollection > PVToken_
edm::EDGetTokenT< std::vector< reco::Muon > > MuonToken_
std::unique_ptr< StringCutObjectSelector< reco::PFTau > > cut_
std::unique_ptr< tau::RecoTauVertexAssociator > vertexAssociator_
edm::EDGetTokenT< std::vector< reco::Electron > > ElectronToken_
PFTauPrimaryVertexProducer::~PFTauPrimaryVertexProducer ( )
override

Definition at line 136 of file PFTauPrimaryVertexProducer.cc.

136 {}

Member Function Documentation

void PFTauPrimaryVertexProducer::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
override

Definition at line 138 of file PFTauPrimaryVertexProducer.cc.

References Algorithm_, ecalDrivenElectronSeedsParameters_cff::beamSpot, beamSpotToken_, TransientTrackBuilder::build(), egammaForCoreTracking_cff::cands, cut_, DEFINE_FWK_MODULE, TtSemiLepEvtBuilder_cfi::disc, listHistos::discr, discriminators_, nanoDQM_cff::Electron, ElectronToken_, edm::EventSetup::get(), edm::Event::getByToken(), edm::Event::getRefBeforePut(), edm::Ref< C, T, F >::isNonnull(), edm::HandleBase::isValid(), electrons_cff::matched, eostools::move(), Mu, MuonToken_, TriggerAnalyzer::passed, PFTauToken_, edm::Event::put(), nanoDQM_cfi::PV, PVToken_, RemoveElectronTracks_, RemoveMuonTracks_, AdaptiveVertexFitter::setWeightThreshold(), metsig::tau, reco::Vertex::tracks_begin(), reco::Vertex::tracks_end(), useBeamSpot_, useFontPV, useInputPV, useSelectedTaus_, AdaptiveVertexFitter::vertex(), and vertexAssociator_.

138  {
139  // Obtain Collections
140  edm::ESHandle<TransientTrackBuilder> transTrackBuilder;
141  iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder",transTrackBuilder);
142 
144  iEvent.getByToken(PFTauToken_,Tau);
145 
147  iEvent.getByToken(ElectronToken_,Electron);
148 
150  iEvent.getByToken(MuonToken_,Mu);
151 
153  iEvent.getByToken(PVToken_,PV);
154 
156  iEvent.getByToken(beamSpotToken_,beamSpot);
157 
158  // Set Association Map
159  auto AVPFTauPV = std::make_unique<edm::AssociationVector<PFTauRefProd, std::vector<reco::VertexRef>>>(PFTauRefProd(Tau));
160  auto VertexCollection_out = std::make_unique<VertexCollection>();
161  reco::VertexRefProd VertexRefProd_out = iEvent.getRefBeforePut<reco::VertexCollection>("PFTauPrimaryVertices");
162 
163  // Load each discriminator
164  for(auto& disc : discriminators_) {
166  iEvent.getByToken(disc->inputToken_, discr);
167  disc->discr_ = &(*discr);
168  }
169 
170  // Set event for VerexAssociator if needed
172  vertexAssociator_->setEvent(iEvent);
173 
174  // For each Tau Run Algorithim
175  if(Tau.isValid()){
176  for(reco::PFTauCollection::size_type iPFTau = 0; iPFTau < Tau->size(); iPFTau++) {
177  reco::PFTauRef tau(Tau, iPFTau);
178  reco::Vertex thePV;
179  if(useInputPV==Algorithm_){
180  thePV =(*( vertexAssociator_->associatedVertex(*tau)));
181  }
182  else if(useFontPV==Algorithm_){
183  thePV=PV->front();
184  }
186  // Check if it passed all the discrimiantors
187  bool passed(true);
188  for(auto const& disc : discriminators_) {
189  // Check this discriminator passes
190  bool passedDisc = true;
191  if ( disc->cutFormula_ )passedDisc = (disc->cutFormula_->Eval((*disc->discr_)[tau]) > 0.5);
192  else passedDisc = ((*disc->discr_)[tau] > disc->cut_);
193  if ( !passedDisc ){passed = false; break;}
194  }
195  if (passed && cut_.get()){passed = (*cut_)(*tau);}
196  if (passed){
197  std::vector<reco::TrackBaseRef> SignalTracks;
198  for(reco::PFTauCollection::size_type jPFTau = 0; jPFTau < Tau->size(); jPFTau++) {
199  if(useSelectedTaus_ || iPFTau==jPFTau){
200  reco::PFTauRef RefPFTau(Tau, jPFTau);
202  // Get tracks from PFTau daugthers
203  const std::vector<edm::Ptr<reco::PFCandidate> > cands = RefPFTau->signalPFChargedHadrCands();
204  for (std::vector<edm::Ptr<reco::PFCandidate> >::const_iterator iter = cands.begin(); iter!=cands.end(); iter++){
205  if(iter->get()->trackRef().isNonnull()) SignalTracks.push_back(reco::TrackBaseRef(iter->get()->trackRef()));
206  else if(iter->get()->gsfTrackRef().isNonnull()){SignalTracks.push_back(reco::TrackBaseRef(((iter)->get()->gsfTrackRef())));}
207  }
208  }
209  }
210  // Get Muon tracks
211  if(RemoveMuonTracks_){
212 
213  if(Mu.isValid()) {
214  for(reco::MuonCollection::size_type iMuon = 0; iMuon< Mu->size(); iMuon++){
215  reco::MuonRef RefMuon(Mu, iMuon);
216  if(RefMuon->track().isNonnull()) SignalTracks.push_back(reco::TrackBaseRef(RefMuon->track()));
217  }
218  }
219  }
220  // Get Electron Tracks
222  if(Electron.isValid()) {
223  for(reco::ElectronCollection::size_type iElectron = 0; iElectron<Electron->size(); iElectron++){
224  reco::ElectronRef RefElectron(Electron, iElectron);
225  if(RefElectron->track().isNonnull()) SignalTracks.push_back(reco::TrackBaseRef(RefElectron->track()));
226  }
227  }
228  }
230  // Get Non-Tau tracks
231  reco::TrackCollection nonTauTracks;
232  for(std::vector<reco::TrackBaseRef>::const_iterator vtxTrkRef=thePV.tracks_begin();vtxTrkRef<thePV.tracks_end();vtxTrkRef++){
233  bool matched = false;
234  for (unsigned int sigTrk = 0; sigTrk < SignalTracks.size(); sigTrk++) {
235  if ( (*vtxTrkRef) == SignalTracks[sigTrk] ) {
236  matched = true;
237  }
238  }
239  if ( !matched ) nonTauTracks.push_back(**vtxTrkRef);
240  }
242  // Refit the vertex
243  TransientVertex transVtx;
244  std::vector<reco::TransientTrack> transTracks;
245  for (reco::TrackCollection::iterator iter=nonTauTracks.begin(); iter!=nonTauTracks.end(); ++iter){
246  transTracks.push_back(transTrackBuilder->build(*iter));
247  }
248  bool FitOk(true);
249  if ( transTracks.size() >= 2 ) {
251  avf.setWeightThreshold(0.1); //weight per track. allow almost every fit, else --> exception
252  try {
253  if ( !useBeamSpot_ ){
254  transVtx = avf.vertex(transTracks);
255  } else {
256  transVtx = avf.vertex(transTracks, *beamSpot);
257  }
258  } catch (...) {
259  FitOk = false;
260  }
261  } else FitOk = false;
262  if ( FitOk ) thePV = transVtx;
263  }
264  VertexRef VRef = reco::VertexRef(VertexRefProd_out, VertexCollection_out->size());
265  VertexCollection_out->push_back(thePV);
266  AVPFTauPV->setValue(iPFTau, VRef);
267  }
268  }
269  iEvent.put(std::move(VertexCollection_out),"PFTauPrimaryVertices");
270  iEvent.put(std::move(AVPFTauPV));
271 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
trackRef_iterator tracks_end() const
last iterator over tracks
Definition: Vertex.cc:81
edm::EDGetTokenT< reco::BeamSpot > beamSpotToken_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
edm::EDGetTokenT< std::vector< reco::PFTau > > PFTauToken_
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
reco::TransientTrack build(const reco::Track *p) const
CachingVertex< 5 > vertex(const std::vector< reco::TransientTrack > &) const override
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
edm::RefProd< PFTauCollection > PFTauRefProd
references to PFTau collection
Definition: PFTauFwd.h:15
uint16_t size_type
edm::EDGetTokenT< reco::VertexCollection > PVToken_
edm::EDGetTokenT< std::vector< reco::Muon > > MuonToken_
bool isValid() const
Definition: HandleBase.h:74
edm::Ref< VertexCollection > VertexRef
persistent reference to a Vertex
Definition: VertexFwd.h:13
RefProd< PROD > getRefBeforePut()
Definition: Event.h:167
Definition: L1GtObject.h:30
std::unique_ptr< StringCutObjectSelector< reco::PFTau > > cut_
T get() const
Definition: EventSetup.h:68
std::unique_ptr< tau::RecoTauVertexAssociator > vertexAssociator_
trackRef_iterator tracks_begin() const
first iterator over tracks
Definition: Vertex.cc:76
def move(src, dest)
Definition: eostools.py:511
edm::EDGetTokenT< std::vector< reco::Electron > > ElectronToken_

Member Data Documentation

int PFTauPrimaryVertexProducer::Algorithm_
private

Definition at line 87 of file PFTauPrimaryVertexProducer.cc.

Referenced by produce().

edm::InputTag PFTauPrimaryVertexProducer::beamSpotTag_
private

Definition at line 85 of file PFTauPrimaryVertexProducer.cc.

edm::EDGetTokenT<reco::BeamSpot> PFTauPrimaryVertexProducer::beamSpotToken_
private

Definition at line 86 of file PFTauPrimaryVertexProducer.cc.

Referenced by produce().

std::unique_ptr<StringCutObjectSelector<reco::PFTau> > PFTauPrimaryVertexProducer::cut_
private

Definition at line 94 of file PFTauPrimaryVertexProducer.cc.

Referenced by PFTauPrimaryVertexProducer(), and produce().

DiscCutPairVec PFTauPrimaryVertexProducer::discriminators_
private

Definition at line 93 of file PFTauPrimaryVertexProducer.cc.

Referenced by PFTauPrimaryVertexProducer(), and produce().

edm::InputTag PFTauPrimaryVertexProducer::ElectronTag_
private

Definition at line 79 of file PFTauPrimaryVertexProducer.cc.

edm::EDGetTokenT<std::vector<reco::Electron> > PFTauPrimaryVertexProducer::ElectronToken_
private

Definition at line 80 of file PFTauPrimaryVertexProducer.cc.

Referenced by produce().

edm::InputTag PFTauPrimaryVertexProducer::MuonTag_
private

Definition at line 81 of file PFTauPrimaryVertexProducer.cc.

edm::EDGetTokenT<std::vector<reco::Muon> > PFTauPrimaryVertexProducer::MuonToken_
private

Definition at line 82 of file PFTauPrimaryVertexProducer.cc.

Referenced by produce().

edm::InputTag PFTauPrimaryVertexProducer::PFTauTag_
private

Definition at line 77 of file PFTauPrimaryVertexProducer.cc.

edm::EDGetTokenT<std::vector<reco::PFTau> > PFTauPrimaryVertexProducer::PFTauToken_
private

Definition at line 78 of file PFTauPrimaryVertexProducer.cc.

Referenced by produce().

edm::InputTag PFTauPrimaryVertexProducer::PVTag_
private

Definition at line 83 of file PFTauPrimaryVertexProducer.cc.

edm::EDGetTokenT<reco::VertexCollection> PFTauPrimaryVertexProducer::PVToken_
private

Definition at line 84 of file PFTauPrimaryVertexProducer.cc.

Referenced by produce().

edm::ParameterSet PFTauPrimaryVertexProducer::qualityCutsPSet_
private

Definition at line 88 of file PFTauPrimaryVertexProducer.cc.

Referenced by PFTauPrimaryVertexProducer().

bool PFTauPrimaryVertexProducer::RemoveElectronTracks_
private

Definition at line 92 of file PFTauPrimaryVertexProducer.cc.

Referenced by produce().

bool PFTauPrimaryVertexProducer::RemoveMuonTracks_
private

Definition at line 91 of file PFTauPrimaryVertexProducer.cc.

Referenced by produce().

bool PFTauPrimaryVertexProducer::useBeamSpot_
private

Definition at line 89 of file PFTauPrimaryVertexProducer.cc.

Referenced by produce().

bool PFTauPrimaryVertexProducer::useSelectedTaus_
private

Definition at line 90 of file PFTauPrimaryVertexProducer.cc.

Referenced by produce().

std::unique_ptr<tau::RecoTauVertexAssociator> PFTauPrimaryVertexProducer::vertexAssociator_
private

Definition at line 95 of file PFTauPrimaryVertexProducer.cc.

Referenced by PFTauPrimaryVertexProducer(), and produce().