CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Types | Public Member Functions | Private Attributes
PFTauPrimaryVertexProducer Class Reference
Inheritance diagram for PFTauPrimaryVertexProducer:
edm::EDProducer edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Classes

struct  DiscCutPair
 

Public Types

enum  Alg { useInputPV =0, useFontPV }
 
typedef std::vector
< DiscCutPair * > 
DiscCutPairVec
 
- Public Types inherited from edm::EDProducer
typedef EDProducer ModuleType
 
- Public Types inherited from edm::ProducerBase
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 

Public Member Functions

 PFTauPrimaryVertexProducer (const edm::ParameterSet &iConfig)
 
virtual void produce (edm::Event &, const edm::EventSetup &)
 
 ~PFTauPrimaryVertexProducer ()
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
ModuleDescription const & moduleDescription () const
 
virtual ~EDProducer ()
 
- Public Member Functions inherited from edm::ProducerBase
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription
const &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 
- Public Member Functions inherited from edm::EDConsumerBase
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

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::VertexCollection
PVToken_
 
bool RemoveElectronTracks_
 
bool RemoveMuonTracks_
 
edm::InputTag TrackCollectionTag_
 
edm::EDGetTokenT
< reco::TrackCollection
TrackCollectionToken_
 
edm::InputTag TracksTag_
 
bool useBeamSpot_
 
bool useSelectedTaus_
 

Additional Inherited Members

- Static Public Member Functions inherited from edm::EDProducer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

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_, RecoTauValidation_cfi::discriminators, discriminators_, edm::ParameterSet::exists(), edm::ParameterSet::existsAs(), edm::ParameterSet::getParameter(), PFTauPrimaryVertexProducer::DiscCutPair::inputToken_, and AlCaHLTBitMon_QueryRunRegistry::string.

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  TrackCollectionTag_(iConfig.getParameter<edm::InputTag>("TrackCollectionTag")),
110  TrackCollectionToken_(consumes<reco::TrackCollection>(TrackCollectionTag_)),
111  Algorithm_(iConfig.getParameter<int>("Algorithm")),
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  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 }
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_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
edm::EDGetTokenT< std::vector< reco::Muon > > MuonToken_
edm::EDGetTokenT< reco::TrackCollection > TrackCollectionToken_
std::auto_ptr< StringCutObjectSelector< reco::PFTau > > cut_
edm::EDGetTokenT< std::vector< reco::Electron > > ElectronToken_
PFTauPrimaryVertexProducer::~PFTauPrimaryVertexProducer ( )

Definition at line 134 of file PFTauPrimaryVertexProducer.cc.

134  {
135 
136 }

Member Function Documentation

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

Implements edm::EDProducer.

Definition at line 138 of file PFTauPrimaryVertexProducer.cc.

References Algorithm_, SiPixelRawToDigiRegional_cfi::beamSpot, beamSpotToken_, PFTauPrimaryVertexProducer::DiscCutPair::cut_, cut_, PFTauPrimaryVertexProducer::DiscCutPair::cutFormula_, listHistos::discr, PFTauPrimaryVertexProducer::DiscCutPair::discr_, discriminators_, ElectronToken_, edm::EventSetup::get(), edm::Event::getByToken(), edm::Event::getRefBeforePut(), getHLTprescales::index, PFTauPrimaryVertexProducer::DiscCutPair::inputToken_, edm::Ref< C, T, F >::isNonnull(), edm::HandleBase::isValid(), Mu, MuonToken_, PFTauToken_, edm::Event::put(), PVToken_, RemoveElectronTracks_, RemoveMuonTracks_, AdaptiveVertexFitter::setWeightThreshold(), metsig::tau, TrackCollectionToken_, reco::Vertex::tracks_begin(), reco::Vertex::tracks_end(), useBeamSpot_, useFontPV, useInputPV, useSelectedTaus_, and AdaptiveVertexFitter::vertex().

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  edm::Handle<reco::TrackCollection> trackCollection;
159  iEvent.getByToken(TrackCollectionToken_,trackCollection);
160 
161  // Set Association Map
162  auto_ptr<edm::AssociationVector<PFTauRefProd, std::vector<reco::VertexRef> > > AVPFTauPV(new edm::AssociationVector<PFTauRefProd, std::vector<reco::VertexRef> >(PFTauRefProd(Tau)));
163  std::auto_ptr<VertexCollection> VertexCollection_out= std::auto_ptr<VertexCollection>(new VertexCollection);
164  reco::VertexRefProd VertexRefProd_out = iEvent.getRefBeforePut<reco::VertexCollection>("PFTauPrimaryVertices");
165 
166  // Load each discriminator
167  BOOST_FOREACH(DiscCutPair *disc, discriminators_) {
169  iEvent.getByToken(disc->inputToken_, discr);
170  disc->discr_ = &(*discr);
171  }
172 
173  // For each Tau Run Algorithim
174  if(Tau.isValid()){
175  unsigned int index(0);
176  for(reco::PFTauCollection::size_type iPFTau = 0; iPFTau < Tau->size(); iPFTau++) {
177  std::vector<reco::TrackBaseRef> SignalTracks;
178  reco::PFTauRef tau(Tau, iPFTau);
179  reco::Vertex thePV;
180  if(useInputPV==Algorithm_){
181  if(Tau->size()==PV->size()){
182  thePV=PV->at(index);
183  }
184  else{
185  thePV=PV->front();
186  edm::LogError("PFTauPrimaryVertexProducer") <<"PFTauPrimaryVertexProducer Number of Tau do not match Number of Primary Vertices for useInputPV Algorithim. Using Tau Primary Vertes Instead";
187  }
188  }
189  if(useFontPV==Algorithm_){
190  thePV=PV->front();
191  }
193  // Check if it passed all the discrimiantors
194  bool passed(true);
195  BOOST_FOREACH(const DiscCutPair* disc, discriminators_) {
196  // Check this discriminator passes
197  bool passedDisc = true;
198  if ( disc->cutFormula_ )passedDisc = (disc->cutFormula_->Eval((*disc->discr_)[tau]) > 0.5);
199  else passedDisc = ((*disc->discr_)[tau] > disc->cut_);
200  if ( !passedDisc ){passed = false; break;}
201  }
202  if (passed && cut_.get()){passed = (*cut_)(*tau);}
203  if (passed){
204  for(reco::PFTauCollection::size_type jPFTau = 0; jPFTau < Tau->size(); jPFTau++) {
205  if(useSelectedTaus_ || iPFTau==jPFTau){
206  reco::PFTauRef RefPFTau(Tau, jPFTau);
208  // Get tracks from PFTau daugthers
209  const std::vector<edm::Ptr<reco::PFCandidate> > cands = RefPFTau->signalPFChargedHadrCands();
210  for (std::vector<edm::Ptr<reco::PFCandidate> >::const_iterator iter = cands.begin(); iter!=cands.end(); iter++){
211  if(iter->get()->trackRef().isNonnull()) SignalTracks.push_back(reco::TrackBaseRef(iter->get()->trackRef()));
212  else if(iter->get()->gsfTrackRef().isNonnull()){SignalTracks.push_back(reco::TrackBaseRef(((iter)->get()->gsfTrackRef())));}
213  }
214  }
215  }
216  // Get Muon tracks
217  if(RemoveMuonTracks_){
218 
219  if(Mu.isValid()) {
220  for(reco::MuonCollection::size_type iMuon = 0; iMuon< Mu->size(); iMuon++){
221  reco::MuonRef RefMuon(Mu, iMuon);
222  if(RefMuon->track().isNonnull()) SignalTracks.push_back(reco::TrackBaseRef(RefMuon->track()));
223  }
224  }
225  }
226  // Get Electron Tracks
228  if(Electron.isValid()) {
229  for(reco::ElectronCollection::size_type iElectron = 0; iElectron<Electron->size(); iElectron++){
230  reco::ElectronRef RefElectron(Electron, iElectron);
231  if(RefElectron->track().isNonnull()) SignalTracks.push_back(reco::TrackBaseRef(RefElectron->track()));
232  }
233  }
234  }
236  // Get Non-Tau tracks
237  reco::TrackCollection nonTauTracks;
238 // if (trackCollection.isValid()) {
239 // // remove tau tracks and only tracks associated with the vertex
240 // unsigned int idx = 0;
241 // for (reco::TrackCollection::const_iterator iTrk = trackCollection->begin(); iTrk != trackCollection->end(); ++iTrk, idx++) {
242 // reco::TrackRef tmpRef(trackCollection, idx);
243 // reco::TrackRef tmpRefForBase=tmpRef;
244 // bool isSigTrk = false;
245 // bool fromVertex=false;
246 // for (unsigned int sigTrk = 0; sigTrk < SignalTracks.size(); sigTrk++) {
247 // if (reco::TrackBaseRef(tmpRefForBase)==SignalTracks.at(sigTrk)){isSigTrk = true; break;}
248 // }
249 // if (!isSigTrk) nonSigTracks.push_back(*iTrk);
250 // }
251 // }
252 
253  for(std::vector<reco::TrackBaseRef>::const_iterator vtxTrkRef=thePV.tracks_begin();vtxTrkRef<thePV.tracks_end();vtxTrkRef++){
254  for (unsigned int sigTrk = 0; sigTrk < SignalTracks.size(); sigTrk++) {
255  if((*vtxTrkRef)!=SignalTracks[sigTrk] ){
256  nonTauTracks.push_back(**vtxTrkRef);
257  }
258  }
259  }
261  // Refit the vertex
262  TransientVertex transVtx;
263  std::vector<reco::TransientTrack> transTracks;
264  for (reco::TrackCollection::iterator iter=nonTauTracks.begin(); iter!=nonTauTracks.end(); ++iter){
265  transTracks.push_back(transTrackBuilder->build(*iter));
266  }
267  bool FitOk(true);
268  if ( transTracks.size() >= 3 ) {
270  avf.setWeightThreshold(0.1); //weight per track. allow almost every fit, else --> exception
271  try {
272  if ( !useBeamSpot_ ){
273  transVtx = avf.vertex(transTracks);
274  } else {
275  transVtx = avf.vertex(transTracks, *beamSpot);
276  }
277  } catch (...) {
278  FitOk = false;
279  }
280  } else FitOk = false;
281  if ( FitOk ) thePV = transVtx;
282  }
283  VertexRef VRef = reco::VertexRef(VertexRefProd_out, VertexCollection_out->size());
284  VertexCollection_out->push_back(thePV);
285  AVPFTauPV->setValue(iPFTau, VRef);
286  }
287  }
288  iEvent.put(VertexCollection_out,"PFTauPrimaryVertices");
289  iEvent.put(AVPFTauPV);
290 }
trackRef_iterator tracks_end() const
last iterator over tracks
Definition: Vertex.cc:44
edm::EDGetTokenT< reco::BeamSpot > beamSpotToken_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
edm::EDGetTokenT< std::vector< reco::PFTau > > PFTauToken_
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:10
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_
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
edm::EDGetTokenT< std::vector< reco::Muon > > MuonToken_
virtual CachingVertex< 5 > vertex(const std::vector< reco::TransientTrack > &) const
edm::EDGetTokenT< reco::TrackCollection > TrackCollectionToken_
bool isValid() const
Definition: HandleBase.h:76
edm::Ref< VertexCollection > VertexRef
persistent reference to a Vertex
Definition: VertexFwd.h:13
RefProd< PROD > getRefBeforePut()
Definition: Event.h:128
std::auto_ptr< StringCutObjectSelector< reco::PFTau > > cut_
Definition: L1GtObject.h:30
const T & get() const
Definition: EventSetup.h:55
trackRef_iterator tracks_begin() const
first iterator over tracks
Definition: Vertex.cc:39
tuple discr
Definition: listHistos.py:51
edm::EDGetTokenT< std::vector< reco::Electron > > ElectronToken_

Member Data Documentation

int PFTauPrimaryVertexProducer::Algorithm_
private

Definition at line 89 of file PFTauPrimaryVertexProducer.cc.

Referenced by produce().

edm::InputTag PFTauPrimaryVertexProducer::beamSpotTag_
private

Definition at line 84 of file PFTauPrimaryVertexProducer.cc.

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

Definition at line 85 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 78 of file PFTauPrimaryVertexProducer.cc.

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

Definition at line 79 of file PFTauPrimaryVertexProducer.cc.

Referenced by produce().

edm::InputTag PFTauPrimaryVertexProducer::MuonTag_
private

Definition at line 80 of file PFTauPrimaryVertexProducer.cc.

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

Definition at line 81 of file PFTauPrimaryVertexProducer.cc.

Referenced by produce().

edm::InputTag PFTauPrimaryVertexProducer::PFTauTag_
private

Definition at line 76 of file PFTauPrimaryVertexProducer.cc.

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

Definition at line 77 of file PFTauPrimaryVertexProducer.cc.

Referenced by produce().

edm::InputTag PFTauPrimaryVertexProducer::PVTag_
private

Definition at line 82 of file PFTauPrimaryVertexProducer.cc.

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

Definition at line 83 of file PFTauPrimaryVertexProducer.cc.

Referenced by produce().

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().

edm::InputTag PFTauPrimaryVertexProducer::TrackCollectionTag_
private

Definition at line 86 of file PFTauPrimaryVertexProducer.cc.

edm::EDGetTokenT<reco::TrackCollection> PFTauPrimaryVertexProducer::TrackCollectionToken_
private

Definition at line 87 of file PFTauPrimaryVertexProducer.cc.

Referenced by produce().

edm::InputTag PFTauPrimaryVertexProducer::TracksTag_
private

Definition at line 88 of file PFTauPrimaryVertexProducer.cc.

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().