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 10 of file GeneralTracksImporter.cc.

Constructor & Destructor Documentation

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

Definition at line 12 of file GeneralTracksImporter.cc.

References pfmu_.

13  :
14  BlockElementImporterBase(conf,sumes),
17  _DPtovPtCut(conf.getParameter<std::vector<double> >("DPtOverPtCuts_byTrackAlgo")),
18  _NHitCut(conf.getParameter<std::vector<unsigned> >("NHitCuts_byTrackAlgo")),
19  _useIterTracking(conf.getParameter<bool>("useIterativeTracking")),
20  _cleanBadConvBrems(conf.existsAs<bool>("cleanBadConvertedBrems") ? conf.getParameter<bool>("cleanBadConvertedBrems") : false),
21  _debug(conf.getUntrackedParameter<bool>("debug",false)) {
22 
23  pfmu_ = std::unique_ptr<PFMuonAlgo>(new PFMuonAlgo());
24  pfmu_->setParameters(conf);
25 
26  }
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 148 of file GeneralTracksImporter.cc.

References _debug, _DPtovPtCut, _NHitCut, _useIterTracking, gather_cfg::cout, reco::TrackBase::ctf, reco::TrackBase::detachedTripletStep, reco::TrackBase::hltIter0, reco::TrackBase::hltIter1, reco::TrackBase::hltIter2, reco::TrackBase::hltIter3, reco::TrackBase::hltIter4, reco::TrackBase::hltIterX, reco::TrackBase::initialStep, reco::TrackBase::jetCoreRegionalStep, reco::TrackBase::lowPtTripletStep, reco::TrackBase::mixedTripletStep, reco::TrackBase::muonSeededStepInOut, reco::TrackBase::muonSeededStepOutIn, P, reco::TrackBase::pixelLessStep, reco::TrackBase::pixelPairStep, reco::tau::disc::Pt(), mathSSE::sqrt(), reco::TrackBase::tobTecStep, and reco::HitPattern::TRACK_HITS.

Referenced by importToBlock().

148  {
149 
150  const double P = trackref->p();
151  const double Pt = trackref->pt();
152  const double DPt = trackref->ptError();
153  const unsigned int NHit =
154  trackref->hitPattern().trackerLayersWithMeasurement();
155  const unsigned int NLostHit =
156  trackref->hitPattern().trackerLayersWithoutMeasurement(reco::HitPattern::TRACK_HITS);
157  const unsigned int LostHits = trackref->numberOfLostHits();
158  const double sigmaHad = sqrt(1.20*1.20/P+0.06*0.06) / (1.+LostHits);
159 
160  // iteration 1,2,3,4,5 correspond to algo = 1/4,5,6,7,8,9
161  unsigned int Algo = 0;
162  switch (trackref->algo()) {
168  Algo = 0;
169  break;
171  Algo = 1;
172  break;
174  Algo = 2;
175  break;
177  Algo = 3;
178  break;
180  Algo = 4;
181  break;
184  Algo = 5;
185  break;
189  Algo = _useIterTracking ? 0 : 0;
190  break;
192  Algo = _useIterTracking ? 1 : 0;
193  break;
195  Algo = _useIterTracking ? 2 : 0;
196  break;
198  Algo = _useIterTracking ? 0 : 0;
199  break;
200  default:
201  Algo = _useIterTracking ? 6 : 0;
202  break;
203  }
204 
205  // Protection against 0 momentum tracks
206  if ( P < 0.05 ) return false;
207 
208 
209  if (_debug) std::cout << " PFBlockAlgo: PFrecTrack->Track Pt= "
210  << Pt << " DPt = " << DPt << std::endl;
211  if ( ( _DPtovPtCut[Algo] > 0. &&
212  DPt/Pt > _DPtovPtCut[Algo]*sigmaHad ) ||
213  NHit < _NHitCut[Algo] ) {
214  if (_debug) std::cout << " PFBlockAlgo: skip badly measured track"
215  << ", P = " << P
216  << ", Pt = " << Pt
217  << " DPt = " << DPt
218  << ", N(hits) = " << NHit << " (Lost : " << LostHits << "/" << NLostHit << ")"
219  << ", Algo = " << Algo
220  << std::endl;
221  if (_debug) std::cout << " cut is DPt/Pt < " << _DPtovPtCut[Algo] * sigmaHad << std::endl;
222  if (_debug) std::cout << " cut is NHit >= " << _NHitCut[Algo] << std::endl;
223  return false;
224  }
225 
226  return true;
227 }
const std::vector< double > _DPtovPtCut
#define P
const std::vector< unsigned > _NHitCut
T sqrt(T t)
Definition: SSEVec.h:48
tuple cout
Definition: gather_cfg.py:121
Definition: fakeMenu.h:6
void GeneralTracksImporter::importToBlock ( const edm::Event e,
BlockElementImporterBase::ElementList elems 
) const
overridevirtual

Implements BlockElementImporterBase.

Definition at line 51 of file GeneralTracksImporter.cc.

References _cleanBadConvBrems, _debug, _muons, _src, a, reco::PFBlockElementTrack::convRefs(), gather_cfg::cout, reco::PFBlockElementTrack::displacedVertexRef(), HLT_25ns14e33_v1_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().

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

Definition at line 230 of file GeneralTracksImporter.cc.

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

Referenced by importToBlock().

231  {
232  auto muon = std::find_if(muonh->cbegin(),muonh->cend(),
233  [&](const reco::Muon& m) {
234  return ( m.track().isNonnull() &&
235  m.track() == trackref );
236  });
237  return ( muon != muonh->cend() ? std::distance(muonh->cbegin(),muon) : -1 );
238 }

Member Data Documentation

const bool GeneralTracksImporter::_cleanBadConvBrems
private

Definition at line 40 of file GeneralTracksImporter.cc.

Referenced by importToBlock().

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

Definition at line 38 of file GeneralTracksImporter.cc.

Referenced by goodPtResolution().

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

Definition at line 37 of file GeneralTracksImporter.cc.

Referenced by importToBlock().

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

Definition at line 39 of file GeneralTracksImporter.cc.

Referenced by goodPtResolution().

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

Definition at line 36 of file GeneralTracksImporter.cc.

Referenced by importToBlock().

const bool GeneralTracksImporter::_useIterTracking
private

Definition at line 40 of file GeneralTracksImporter.cc.

Referenced by goodPtResolution().

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

Definition at line 42 of file GeneralTracksImporter.cc.

Referenced by GeneralTracksImporter(), and importToBlock().