test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 &)
 

Private Member Functions

bool goodPtResolution (const reco::TrackRef &trackref) const
 
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::MuonCollection
_muons
 
const std::vector< unsigned > _NHitCut
 
edm::EDGetTokenT
< reco::PFRecTrackCollection
_src
 
const bool _useIterTracking
 
std::unique_ptr< PFMuonAlgopfmu_
 

Additional Inherited Members

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

Detailed Description

Definition at line 11 of file GeneralTracksImporter.cc.

Constructor & Destructor Documentation

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

Definition at line 13 of file GeneralTracksImporter.cc.

References pfmu_.

14  :
15  BlockElementImporterBase(conf,sumes),
18  _DPtovPtCut(conf.getParameter<std::vector<double> >("DPtOverPtCuts_byTrackAlgo")),
19  _NHitCut(conf.getParameter<std::vector<unsigned> >("NHitCuts_byTrackAlgo")),
20  _useIterTracking(conf.getParameter<bool>("useIterativeTracking")),
21  _cleanBadConvBrems(conf.existsAs<bool>("cleanBadConvertedBrems") ? conf.getParameter<bool>("cleanBadConvertedBrems") : false),
22  _debug(conf.getUntrackedParameter<bool>("debug",false)) {
23 
24  pfmu_ = std::unique_ptr<PFMuonAlgo>(new PFMuonAlgo());
25  pfmu_->setParameters(conf);
26 
27  }
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
std::unique_ptr< PFMuonAlgo > pfmu_
const std::vector< double > _DPtovPtCut
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
const std::vector< unsigned > _NHitCut
edm::EDGetTokenT< reco::MuonCollection > _muons
edm::EDGetTokenT< reco::PFRecTrackCollection > _src
BlockElementImporterBase(const edm::ParameterSet &conf, edm::ConsumesCollector &sumes)
std::vector< PFRecTrack > PFRecTrackCollection
collection of PFRecTrack objects
Definition: PFRecTrackFwd.h:9

Member Function Documentation

bool GeneralTracksImporter::goodPtResolution ( const reco::TrackRef trackref) const
private

Definition at line 149 of file GeneralTracksImporter.cc.

References _debug, _DPtovPtCut, _NHitCut, _useIterTracking, gather_cfg::cout, PFTrackAlgoTools::dPtCut(), PFTrackAlgoTools::nHitCut(), P, reco::tau::disc::Pt(), mathSSE::sqrt(), and reco::HitPattern::TRACK_HITS.

Referenced by importToBlock().

149  {
150 
151  const double P = trackref->p();
152  const double Pt = trackref->pt();
153  const double DPt = trackref->ptError();
154  const unsigned int NHit =
155  trackref->hitPattern().trackerLayersWithMeasurement();
156  const unsigned int NLostHit =
157  trackref->hitPattern().trackerLayersWithoutMeasurement(reco::HitPattern::TRACK_HITS);
158  const unsigned int LostHits = trackref->numberOfLostHits();
159  const double sigmaHad = sqrt(1.20*1.20/P+0.06*0.06) / (1.+LostHits);
160 
161  // Protection against 0 momentum tracks
162  if ( P < 0.05 ) return false;
163 
164  if (_debug) std::cout << " PFBlockAlgo: PFrecTrack->Track Pt= "
165  << Pt << " DPt = " << DPt << std::endl;
166 
167 
168  double dptCut = PFTrackAlgoTools::dPtCut(trackref->algo(),_DPtovPtCut,_useIterTracking);
169  unsigned int nhitCut = PFTrackAlgoTools::nHitCut(trackref->algo(),_NHitCut,_useIterTracking);
170 
171  if ( ( dptCut > 0. &&
172  DPt/Pt > dptCut*sigmaHad ) ||
173  NHit < nhitCut ) {
174  if (_debug) std::cout << " PFBlockAlgo: skip badly measured track"
175  << ", P = " << P
176  << ", Pt = " << Pt
177  << " DPt = " << DPt
178  << ", N(hits) = " << NHit << " (Lost : " << LostHits << "/" << NLostHit << ")"
179  << ", Algo = " << trackref->algo()
180  << std::endl;
181  if (_debug) std::cout << " cut is DPt/Pt < " << dptCut * sigmaHad << std::endl;
182  if (_debug) std::cout << " cut is NHit >= " << nhitCut << std::endl;
183  return false;
184  }
185 
186  return true;
187 }
const std::vector< double > _DPtovPtCut
#define P
unsigned int nHitCut(const reco::TrackBase::TrackAlgorithm &, const std::vector< unsigned int > &, bool)
const std::vector< unsigned > _NHitCut
T sqrt(T t)
Definition: SSEVec.h:18
double dPtCut(const reco::TrackBase::TrackAlgorithm &, const std::vector< double > &, bool)
tuple cout
Definition: gather_cfg.py:145
void GeneralTracksImporter::importToBlock ( const edm::Event e,
BlockElementImporterBase::ElementList elems 
) const
overridevirtual

Implements BlockElementImporterBase.

Definition at line 52 of file GeneralTracksImporter.cc.

References _cleanBadConvBrems, _debug, _muons, _src, a, reco::PFBlockElementTrack::convRefs(), gather_cfg::cout, reco::PFBlockElementTrack::displacedVertexRef(), HLT_25ns10e33_v2_cff::distance, edm::Event::getByToken(), goodPtResolution(), customizeTrackingMonitorSeedNumber::idx, PFMuonAlgo::isLooseMuon(), PFMuonAlgo::isMuon(), edm::Ref< C, T, F >::isNull(), muAssocToTrack(), patZpeak::muons, NULL, pfmu_, reco::PFBlockElementTrack::setMuonRef(), edm::RefVector< C, T, F >::size(), reco::PFBlockElement::T_FROM_DISP, reco::PFBlockElement::T_FROM_GAMMACONV, reco::PFBlockElement::TRACK, reco::PFBlockElementTrack::trackRef(), testEve_cfg::tracks, reco::PFBlockElementTrack::trackType(), and reco::PFBlockElementTrack::V0Ref().

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

Definition at line 190 of file GeneralTracksImporter.cc.

References HLT_25ns10e33_v2_cff::distance, visualization-live-secondInstance_cfg::m, and metsig::muon.

Referenced by importToBlock().

191  {
192  auto muon = std::find_if(muonh->cbegin(),muonh->cend(),
193  [&](const reco::Muon& m) {
194  return ( m.track().isNonnull() &&
195  m.track() == trackref );
196  });
197  return ( muon != muonh->cend() ? std::distance(muonh->cbegin(),muon) : -1 );
198 }

Member Data Documentation

const bool GeneralTracksImporter::_cleanBadConvBrems
private

Definition at line 41 of file GeneralTracksImporter.cc.

Referenced by importToBlock().

const bool GeneralTracksImporter::_debug
private
const std::vector<double> GeneralTracksImporter::_DPtovPtCut
private

Definition at line 39 of file GeneralTracksImporter.cc.

Referenced by goodPtResolution().

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

Definition at line 38 of file GeneralTracksImporter.cc.

Referenced by importToBlock().

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

Definition at line 40 of file GeneralTracksImporter.cc.

Referenced by goodPtResolution().

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

Definition at line 37 of file GeneralTracksImporter.cc.

Referenced by importToBlock().

const bool GeneralTracksImporter::_useIterTracking
private

Definition at line 41 of file GeneralTracksImporter.cc.

Referenced by goodPtResolution().

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

Definition at line 43 of file GeneralTracksImporter.cc.

Referenced by GeneralTracksImporter(), and importToBlock().