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::auto_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::auto_ptr< tau::RecoTauVertexAssociatorvertexAssociator_
 

Detailed Description

Definition at line 59 of file PFTauPrimaryVertexProducer.cc.

Member Typedef Documentation

Definition at line 71 of file PFTauPrimaryVertexProducer.cc.

Member Enumeration Documentation

Constructor & Destructor Documentation

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

Definition at line 99 of file PFTauPrimaryVertexProducer.cc.

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

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

Definition at line 137 of file PFTauPrimaryVertexProducer.cc.

137 {}

Member Function Documentation

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

Definition at line 139 of file PFTauPrimaryVertexProducer.cc.

References Algorithm_, ecalDrivenElectronSeedsParameters_cff::beamSpot, beamSpotToken_, TransientTrackBuilder::build(), egammaForCoreTracking_cff::cands, PFTauPrimaryVertexProducer::DiscCutPair::cut_, cut_, PFTauPrimaryVertexProducer::DiscCutPair::cutFormula_, DEFINE_FWK_MODULE, TtSemiLepEvtBuilder_cfi::disc, listHistos::discr, PFTauPrimaryVertexProducer::DiscCutPair::discr_, discriminators_, nanoDQM_cfi::Electron, ElectronToken_, edm::EventSetup::get(), edm::Event::getByToken(), edm::Event::getRefBeforePut(), PFTauPrimaryVertexProducer::DiscCutPair::inputToken_, 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_.

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

Member Data Documentation

int PFTauPrimaryVertexProducer::Algorithm_
private

Definition at line 88 of file PFTauPrimaryVertexProducer.cc.

Referenced by produce().

edm::InputTag PFTauPrimaryVertexProducer::beamSpotTag_
private

Definition at line 86 of file PFTauPrimaryVertexProducer.cc.

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

Definition at line 87 of file PFTauPrimaryVertexProducer.cc.

Referenced by produce().

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

Definition at line 95 of file PFTauPrimaryVertexProducer.cc.

Referenced by PFTauPrimaryVertexProducer(), and produce().

DiscCutPairVec PFTauPrimaryVertexProducer::discriminators_
private

Definition at line 94 of file PFTauPrimaryVertexProducer.cc.

Referenced by PFTauPrimaryVertexProducer(), and produce().

edm::InputTag PFTauPrimaryVertexProducer::ElectronTag_
private

Definition at line 80 of file PFTauPrimaryVertexProducer.cc.

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

Definition at line 81 of file PFTauPrimaryVertexProducer.cc.

Referenced by produce().

edm::InputTag PFTauPrimaryVertexProducer::MuonTag_
private

Definition at line 82 of file PFTauPrimaryVertexProducer.cc.

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

Definition at line 83 of file PFTauPrimaryVertexProducer.cc.

Referenced by produce().

edm::InputTag PFTauPrimaryVertexProducer::PFTauTag_
private

Definition at line 78 of file PFTauPrimaryVertexProducer.cc.

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

Definition at line 79 of file PFTauPrimaryVertexProducer.cc.

Referenced by produce().

edm::InputTag PFTauPrimaryVertexProducer::PVTag_
private

Definition at line 84 of file PFTauPrimaryVertexProducer.cc.

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

Definition at line 85 of file PFTauPrimaryVertexProducer.cc.

Referenced by produce().

edm::ParameterSet PFTauPrimaryVertexProducer::qualityCutsPSet_
private

Definition at line 89 of file PFTauPrimaryVertexProducer.cc.

Referenced by PFTauPrimaryVertexProducer().

bool PFTauPrimaryVertexProducer::RemoveElectronTracks_
private

Definition at line 93 of file PFTauPrimaryVertexProducer.cc.

Referenced by produce().

bool PFTauPrimaryVertexProducer::RemoveMuonTracks_
private

Definition at line 92 of file PFTauPrimaryVertexProducer.cc.

Referenced by produce().

bool PFTauPrimaryVertexProducer::useBeamSpot_
private

Definition at line 90 of file PFTauPrimaryVertexProducer.cc.

Referenced by produce().

bool PFTauPrimaryVertexProducer::useSelectedTaus_
private

Definition at line 91 of file PFTauPrimaryVertexProducer.cc.

Referenced by produce().

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

Definition at line 96 of file PFTauPrimaryVertexProducer.cc.

Referenced by PFTauPrimaryVertexProducer(), and produce().