CMS 3D CMS Logo

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

Public Member Functions

 GeneralTracksImporter (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_
 

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 GeneralTracksImporter.cc.

Constructor & Destructor Documentation

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

Definition at line 14 of file GeneralTracksImporter.cc.

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

15  :
16  BlockElementImporterBase(conf,sumes),
19  DPtovPtCut_(conf.getParameter<std::vector<double> >("DPtOverPtCuts_byTrackAlgo")),
20  NHitCut_(conf.getParameter<std::vector<unsigned> >("NHitCuts_byTrackAlgo")),
21  useTiming_(conf.existsAs<edm::InputTag>("timeValueMap")),
24  useIterTracking_(conf.getParameter<bool>("useIterativeTracking")),
25  cleanBadConvBrems_(conf.existsAs<bool>("cleanBadConvertedBrems") ? conf.getParameter<bool>("cleanBadConvertedBrems") : false),
26  debug_(conf.getUntrackedParameter<bool>("debug",false)) {
27 
28  pfmu_ = std::unique_ptr<PFMuonAlgo>(new PFMuonAlgo());
29  pfmu_->setParameters(conf);
30 
31  }
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< edm::ValueMap< float > > srcTime_
const std::vector< double > DPtovPtCut_
edm::EDGetTokenT< reco::MuonCollection > muons_
std::unique_ptr< PFMuonAlgo > pfmu_
edm::EDGetTokenT< reco::PFRecTrackCollection > src_
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
const std::vector< unsigned > NHitCut_
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

Member Function Documentation

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

Implements BlockElementImporterBase.

Definition at line 57 of file GeneralTracksImporter.cc.

References a, cleanBadConvBrems_, reco::PFBlockElementTrack::convRefs(), gather_cfg::cout, debug_, reco::PFBlockElementTrack::displacedVertexRef(), SoftLeptonByDistance_cfi::distance, DPtovPtCut_, edm::Event::getByToken(), PFTrackAlgoTools::goodPtResolution(), training_settings::idx, PFMuonAlgo::isLooseMuon(), PFMuonAlgo::isMuon(), edm::Ref< C, T, F >::isNull(), 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_, and reco::PFBlockElementTrack::V0Ref().

Referenced by GeneralTracksImporter().

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

Definition at line 162 of file GeneralTracksImporter.cc.

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

Referenced by GeneralTracksImporter(), and importToBlock().

163  {
164  auto muon = std::find_if(muonh->cbegin(),muonh->cend(),
165  [&](const reco::Muon& m) {
166  return ( m.track().isNonnull() &&
167  m.track() == trackref );
168  });
169  return ( muon != muonh->cend() ? std::distance(muonh->cbegin(),muon) : -1 );
170 }

Member Data Documentation

const bool GeneralTracksImporter::cleanBadConvBrems_
private

Definition at line 46 of file GeneralTracksImporter.cc.

Referenced by importToBlock().

const bool GeneralTracksImporter::debug_
private

Definition at line 46 of file GeneralTracksImporter.cc.

Referenced by importToBlock().

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

Definition at line 42 of file GeneralTracksImporter.cc.

Referenced by importToBlock().

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

Definition at line 41 of file GeneralTracksImporter.cc.

Referenced by importToBlock().

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

Definition at line 43 of file GeneralTracksImporter.cc.

Referenced by importToBlock().

std::unique_ptr<PFMuonAlgo> GeneralTracksImporter::pfmu_
private

Definition at line 48 of file GeneralTracksImporter.cc.

Referenced by GeneralTracksImporter(), and importToBlock().

edm::EDGetTokenT<reco::PFRecTrackCollection> GeneralTracksImporter::src_
private

Definition at line 40 of file GeneralTracksImporter.cc.

Referenced by importToBlock().

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

Definition at line 45 of file GeneralTracksImporter.cc.

Referenced by importToBlock().

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

Definition at line 45 of file GeneralTracksImporter.cc.

Referenced by importToBlock().

const bool GeneralTracksImporter::useIterTracking_
private

Definition at line 46 of file GeneralTracksImporter.cc.

Referenced by importToBlock().

const bool GeneralTracksImporter::useTiming_
private

Definition at line 44 of file GeneralTracksImporter.cc.

Referenced by importToBlock().