CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
GeneralTracksImporterWithVeto Class Reference
Inheritance diagram for GeneralTracksImporterWithVeto:
BlockElementImporterBase

Public Member Functions

 GeneralTracksImporterWithVeto (const edm::ParameterSet &conf, edm::ConsumesCollector &sumes)
 
void importToBlock (const edm::Event &, ElementList &) const override
 
- Public Member Functions inherited from BlockElementImporterBase
 BlockElementImporterBase (const edm::ParameterSet &conf, edm::ConsumesCollector &sumes)
 
 BlockElementImporterBase (const BlockElementImporterBase &)=delete
 
const std::string & name () const
 
BlockElementImporterBaseoperator= (const BlockElementImporterBase &)=delete
 
virtual void updateEventSetup (const edm::EventSetup &)
 
virtual ~BlockElementImporterBase ()=default
 

Private Member Functions

int muAssocToTrack (const reco::TrackRef &trackref, const edm::Handle< reco::MuonCollection > &muonh) const
 

Private Attributes

const bool cleanBadConvBrems_
 
const bool debug_
 
const std::vector< double > DPtovPtCut_
 
edm::EDGetTokenT< reco::MuonCollectionmuons_
 
const std::vector< unsigned > NHitCut_
 
std::unique_ptr< PFMuonAlgopfmu_
 
edm::EDGetTokenT< reco::PFRecTrackCollectionsrc_
 
edm::EDGetTokenT< edm::ValueMap< float > > srcTime_
 
edm::EDGetTokenT< edm::ValueMap< float > > srcTimeError_
 
const bool useIterTracking_
 
const bool useTiming_
 
edm::EDGetTokenT< reco::PFRecTrackCollectionveto_
 

Additional Inherited Members

- Public Types inherited from BlockElementImporterBase
typedef std::vector< std::unique_ptr< reco::PFBlockElement > > ElementList
 

Detailed Description

Definition at line 12 of file GeneralTracksImporterWithVeto.cc.

Constructor & Destructor Documentation

GeneralTracksImporterWithVeto::GeneralTracksImporterWithVeto ( const edm::ParameterSet conf,
edm::ConsumesCollector sumes 
)
inline

Definition at line 14 of file GeneralTracksImporterWithVeto.cc.

References importToBlock(), muAssocToTrack(), and pfmu_.

15  :
16  BlockElementImporterBase(conf,sumes),
20  DPtovPtCut_(conf.getParameter<std::vector<double> >("DPtOverPtCuts_byTrackAlgo")),
21  NHitCut_(conf.getParameter<std::vector<unsigned> >("NHitCuts_byTrackAlgo")),
22  useTiming_(conf.existsAs<edm::InputTag>("timeValueMap")),
25  useIterTracking_(conf.getParameter<bool>("useIterativeTracking")),
26  cleanBadConvBrems_(conf.existsAs<bool>("cleanBadConvertedBrems") ? conf.getParameter<bool>("cleanBadConvertedBrems") : false),
27  debug_(conf.getUntrackedParameter<bool>("debug",false)) {
28 
29  pfmu_ = std::unique_ptr<PFMuonAlgo>(new PFMuonAlgo());
30  pfmu_->setParameters(conf);
31 
32  }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:186
edm::EDGetTokenT< reco::MuonCollection > muons_
edm::EDGetTokenT< reco::PFRecTrackCollection > veto_
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
edm::EDGetTokenT< reco::PFRecTrackCollection > src_
edm::EDGetTokenT< edm::ValueMap< float > > srcTimeError_
BlockElementImporterBase(const edm::ParameterSet &conf, edm::ConsumesCollector &sumes)
std::vector< PFRecTrack > PFRecTrackCollection
collection of PFRecTrack objects
Definition: PFRecTrackFwd.h:9
const std::vector< unsigned > NHitCut_
edm::EDGetTokenT< edm::ValueMap< float > > srcTime_

Member Function Documentation

void GeneralTracksImporterWithVeto::importToBlock ( const edm::Event e,
BlockElementImporterBase::ElementList elems 
) const
overridevirtual

Implements BlockElementImporterBase.

Definition at line 58 of file GeneralTracksImporterWithVeto.cc.

References a, cleanBadConvBrems_, reco::PFBlockElementTrack::convRefs(), gather_cfg::cout, debug_, reco::PFBlockElementTrack::displacedVertexRef(), SoftLeptonByDistance_cfi::distance, DPtovPtCut_, edm::Event::getByToken(), PFTrackAlgoTools::goodPtResolution(), mps_fire::i, training_settings::idx, PFMuonAlgo::isLooseMuon(), PFMuonAlgo::isMuon(), edm::Ref< C, T, F >::isNull(), crabWrapper::key, edm::Ref< C, T, F >::key(), RecoTauDiscriminantConfiguration::mask, muAssocToTrack(), electronCleaner_cfi::muons, muons_, NHitCut_, NULL, pfmu_, reco::PFBlockElementTrack::setMuonRef(), reco::PFBlockElement::setTime(), edm::RefVector< C, T, F >::size(), src_, srcTime_, srcTimeError_, reco::PFBlockElement::T_FROM_DISP, reco::PFBlockElement::T_FROM_GAMMACONV, HiIsolationCommonParameters_cff::track, reco::PFBlockElement::TRACK, reco::PFBlockElementTrack::trackRef(), l1t::tracks, reco::PFBlockElementTrack::trackType(), useIterTracking_, useTiming_, reco::PFBlockElementTrack::V0Ref(), veto_, and boostedElectronIsolation_cff::vetos.

Referenced by GeneralTracksImporterWithVeto().

59  {
62  e.getByToken(src_,tracks);
64  e.getByToken(veto_,vetosH);
65  const auto& vetos = *vetosH;
66  std::unordered_set<unsigned> vetoed;
67  for(unsigned i = 0; i < vetos.size(); ++i ) {
68  vetoed.insert(vetos[i].trackRef().key());
69  }
71  e.getByToken(muons_,muons);
72  elems.reserve(elems.size() + tracks->size());
73  std::vector<bool> mask(tracks->size(),true);
74  reco::MuonRef muonref;
75  edm::Handle<edm::ValueMap<float>> timeH, timeErrH;
76  if (useTiming_) {
77  e.getByToken(srcTime_, timeH);
78  e.getByToken(srcTimeError_, timeErrH);
79  }
80  // remove converted brems with bad pT resolution if requested
81  // this reproduces the old behavior of PFBlockAlgo
82  if( cleanBadConvBrems_ ) {
83  auto itr = elems.begin();
84  while( itr != elems.end() ) {
85  if( (*itr)->type() == reco::PFBlockElement::TRACK ) {
86  const reco::PFBlockElementTrack* trkel =
87  static_cast<reco::PFBlockElementTrack*>(itr->get());
88  const reco::ConversionRefVector& cRef = trkel->convRefs();
89  const reco::PFDisplacedTrackerVertexRef& dvRef =
92  trkel->V0Ref();
93  // if there is no displaced vertex reference and it is marked
94  // as a conversion it's gotta be a converted brem
96  cRef.size() == 0 && dvRef.isNull() && v0Ref.isNull() ) {
97  // if the Pt resolution is bad we kill this element
99  itr = elems.erase(itr);
100  continue;
101  }
102  }
103  }
104  ++itr;
105  } // loop on existing elements
106  }
107  // preprocess existing tracks in the element list and create a mask
108  // so that we do not import tracks twice, tag muons we find
109  // in this collection
110  auto TKs_end = std::partition(elems.begin(),elems.end(),
111  [](const ElementType& a){
112  return a->type() == reco::PFBlockElement::TRACK;
113  });
114  auto btk_elems = elems.begin();
115  auto btrack = tracks->cbegin();
116  auto etrack = tracks->cend();
117  for( auto track = btrack; track != etrack; ++track) {
118  auto tk_elem = std::find_if(btk_elems,TKs_end,
119  [&](const ElementType& a){
120  return ( a->trackRef() ==
121  track->trackRef() );
122  });
123  if( tk_elem != TKs_end ) {
124  mask[std::distance(tracks->cbegin(),track)] = false;
125  // check and update if this track is a muon
126  const int muId = muAssocToTrack( (*tk_elem)->trackRef(), muons );
127  if( muId != -1 ) {
128  muonref= reco::MuonRef( muons, muId );
129  if( PFMuonAlgo::isLooseMuon(muonref) || PFMuonAlgo::isMuon(muonref) ) {
130  static_cast<reco::PFBlockElementTrack*>(tk_elem->get())->setMuonRef(muonref);
131  }
132  }
133  }
134  }
135  // now we actually insert tracks, again tagging muons along the way
136  reco::PFRecTrackRef pftrackref;
137  reco::PFBlockElementTrack* trkElem = NULL;
138  for( auto track = btrack; track != etrack; ++track) {
139  const unsigned idx = std::distance(btrack,track);
140  // since we already set muon refs in the previously imported tracks,
141  // here we can skip everything that is already imported
142  if( !mask[idx] ) continue;
143  muonref = reco::MuonRef();
144  pftrackref = reco::PFRecTrackRef(tracks,idx);
145  // Get the eventual muon associated to this track
146  const int muId = muAssocToTrack( pftrackref->trackRef(), muons );
147  bool thisIsAPotentialMuon = false;
148  if( muId != -1 ) {
149  muonref= reco::MuonRef( muons, muId );
150  thisIsAPotentialMuon = ( (pfmu_->hasValidTrack(muonref,true)&&PFMuonAlgo::isLooseMuon(muonref)) ||
151  (pfmu_->hasValidTrack(muonref,false)&&PFMuonAlgo::isMuon(muonref)));
152  }
153  if(thisIsAPotentialMuon || PFTrackAlgoTools::goodPtResolution( pftrackref->trackRef(), DPtovPtCut_, NHitCut_, useIterTracking_, debug_ ) ) {
154  trkElem = new reco::PFBlockElementTrack( pftrackref );
155  if (thisIsAPotentialMuon && debug_) {
156  std::cout << "Potential Muon P " << pftrackref->trackRef()->p()
157  << " pt " << pftrackref->trackRef()->p() << std::endl;
158  }
159  if( muId != -1 ) trkElem->setMuonRef(muonref);
160  if ( useTiming_ ) {
161  trkElem->setTime( (*timeH)[pftrackref->trackRef()], (*timeErrH)[pftrackref->trackRef()] );
162  }
163  if( vetoed.count(pftrackref->trackRef().key()) == 0 || muonref.isNonnull()){
164  elems.emplace_back(trkElem);
165  }
166  }
167  }
168  elems.shrink_to_fit();
169 }
const VertexCompositeCandidateRef & V0Ref() const
const reco::TrackRef & trackRef() const
int muAssocToTrack(const reco::TrackRef &trackref, const edm::Handle< reco::MuonCollection > &muonh) const
static bool isMuon(const reco::PFBlockElement &elt)
Definition: PFMuonAlgo.cc:155
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
edm::EDGetTokenT< reco::MuonCollection > muons_
#define NULL
Definition: scimark2.h:8
edm::EDGetTokenT< reco::PFRecTrackCollection > veto_
key_type key() const
Accessor for product key.
Definition: Ref.h:264
const ConversionRefVector & convRefs() const
edm::EDGetTokenT< reco::PFRecTrackCollection > src_
edm::Ref< PFRecTrackCollection > PFRecTrackRef
persistent reference to PFRecTrack objects
Definition: PFRecTrackFwd.h:15
edm::Ref< MuonCollection > MuonRef
presistent reference to a Muon
Definition: MuonFwd.h:13
edm::EDGetTokenT< edm::ValueMap< float > > srcTimeError_
bool isNull() const
Checks for null.
Definition: Ref.h:249
virtual bool trackType(TrackType trType) const
void setMuonRef(const MuonRef &muref)
reference to the Muon
static bool isLooseMuon(const reco::PFBlockElement &elt)
Definition: PFMuonAlgo.cc:168
double a
Definition: hdecay.h:121
const PFDisplacedTrackerVertexRef & displacedVertexRef(TrackType trType) const
size_type size() const
Size of the RefVector.
Definition: RefVector.h:107
bool goodPtResolution(const reco::TrackRef &, const std::vector< double > &DPtovPtCut, const std::vector< unsigned > &NHitCut, bool useIterTracking, bool debug=false)
void setTime(float time, float timeError=0.f)
the timing information
const std::vector< unsigned > NHitCut_
edm::EDGetTokenT< edm::ValueMap< float > > srcTime_
int GeneralTracksImporterWithVeto::muAssocToTrack ( const reco::TrackRef trackref,
const edm::Handle< reco::MuonCollection > &  muonh 
) const
private

Definition at line 172 of file GeneralTracksImporterWithVeto.cc.

References SoftLeptonByDistance_cfi::distance, funct::m, and metsig::muon.

Referenced by GeneralTracksImporterWithVeto(), and importToBlock().

173  {
174  auto muon = std::find_if(muonh->cbegin(),muonh->cend(),
175  [&](const reco::Muon& m) {
176  return ( m.track().isNonnull() &&
177  m.track() == trackref );
178  });
179  return ( muon != muonh->cend() ? std::distance(muonh->cbegin(),muon) : -1 );
180 }

Member Data Documentation

const bool GeneralTracksImporterWithVeto::cleanBadConvBrems_
private

Definition at line 47 of file GeneralTracksImporterWithVeto.cc.

Referenced by importToBlock().

const bool GeneralTracksImporterWithVeto::debug_
private

Definition at line 47 of file GeneralTracksImporterWithVeto.cc.

Referenced by importToBlock().

const std::vector<double> GeneralTracksImporterWithVeto::DPtovPtCut_
private

Definition at line 43 of file GeneralTracksImporterWithVeto.cc.

Referenced by importToBlock().

edm::EDGetTokenT<reco::MuonCollection> GeneralTracksImporterWithVeto::muons_
private

Definition at line 42 of file GeneralTracksImporterWithVeto.cc.

Referenced by importToBlock().

const std::vector<unsigned> GeneralTracksImporterWithVeto::NHitCut_
private

Definition at line 44 of file GeneralTracksImporterWithVeto.cc.

Referenced by importToBlock().

std::unique_ptr<PFMuonAlgo> GeneralTracksImporterWithVeto::pfmu_
private
edm::EDGetTokenT<reco::PFRecTrackCollection> GeneralTracksImporterWithVeto::src_
private

Definition at line 41 of file GeneralTracksImporterWithVeto.cc.

Referenced by importToBlock().

edm::EDGetTokenT<edm::ValueMap<float> > GeneralTracksImporterWithVeto::srcTime_
private

Definition at line 46 of file GeneralTracksImporterWithVeto.cc.

Referenced by importToBlock().

edm::EDGetTokenT<edm::ValueMap<float> > GeneralTracksImporterWithVeto::srcTimeError_
private

Definition at line 46 of file GeneralTracksImporterWithVeto.cc.

Referenced by importToBlock().

const bool GeneralTracksImporterWithVeto::useIterTracking_
private

Definition at line 47 of file GeneralTracksImporterWithVeto.cc.

Referenced by importToBlock().

const bool GeneralTracksImporterWithVeto::useTiming_
private

Definition at line 45 of file GeneralTracksImporterWithVeto.cc.

Referenced by importToBlock().

edm::EDGetTokenT<reco::PFRecTrackCollection> GeneralTracksImporterWithVeto::veto_
private

Definition at line 41 of file GeneralTracksImporterWithVeto.cc.

Referenced by importToBlock().