CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GeneralTracksImporter.cc
Go to the documentation of this file.
9 
11 public:
13  edm::ConsumesCollector& sumes) :
14  BlockElementImporterBase(conf,sumes),
15  _src(sumes.consumes<reco::PFRecTrackCollection>(conf.getParameter<edm::InputTag>("source"))),
16  _muons(sumes.consumes<reco::MuonCollection>(conf.getParameter<edm::InputTag>("muonSrc"))),
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  void importToBlock( const edm::Event& ,
24  ElementList& ) const override;
25 
26 private:
27  bool goodPtResolution( const reco::TrackRef& trackref) const;
28  int muAssocToTrack( const reco::TrackRef& trackref,
29  const edm::Handle<reco::MuonCollection>& muonh) const;
30 
33  const std::vector<double> _DPtovPtCut;
34  const std::vector<unsigned> _NHitCut;
36 };
37 
40  "GeneralTracksImporter");
41 
47  e.getByToken(_src,tracks);
49  e.getByToken(_muons,muons);
50  elems.reserve(elems.size() + tracks->size());
51  std::vector<bool> mask(tracks->size(),true);
52  reco::MuonRef muonref;
53  // remove converted brems with bad pT resolution if requested
54  // this reproduces the old behavior of PFBlockAlgo
55  if( _cleanBadConvBrems ) {
56  auto itr = elems.begin();
57  while( itr != elems.end() ) {
58  if( (*itr)->type() == reco::PFBlockElement::TRACK ) {
59  const reco::PFBlockElementTrack* trkel =
60  static_cast<reco::PFBlockElementTrack*>(itr->get());
61  const reco::ConversionRefVector& cRef = trkel->convRefs();
62  const reco::PFDisplacedTrackerVertexRef& dvRef =
65  trkel->V0Ref();
66  // if there is no displaced vertex reference and it is marked
67  // as a conversion it's gotta be a converted brem
69  cRef.size() == 0 && dvRef.isNull() && v0Ref.isNull() ) {
70  // if the Pt resolution is bad we kill this element
71  if( !goodPtResolution( trkel->trackRef() ) ) {
72  itr = elems.erase(itr);
73  continue;
74  }
75  }
76  }
77  ++itr;
78  } // loop on existing elements
79  }
80  // preprocess existing tracks in the element list and create a mask
81  // so that we do not import tracks twice, tag muons we find
82  // in this collection
83  auto TKs_end = std::partition(elems.begin(),elems.end(),
84  [](const ElementType& a){
85  return a->type() == reco::PFBlockElement::TRACK;
86  });
87  auto btk_elems = elems.begin();
88  auto btrack = tracks->cbegin();
89  auto etrack = tracks->cend();
90  for( auto track = btrack; track != etrack; ++track) {
91  auto tk_elem = std::find_if(btk_elems,TKs_end,
92  [&](const ElementType& a){
93  return ( a->trackRef() ==
94  track->trackRef() );
95  });
96  if( tk_elem != TKs_end ) {
97  mask[std::distance(tracks->cbegin(),track)] = false;
98  // check and update if this track is a muon
99  const int muId = muAssocToTrack( (*tk_elem)->trackRef(), muons );
100  if( muId != -1 ) {
101  muonref= reco::MuonRef( muons, muId );
102  if( PFMuonAlgo::isLooseMuon(muonref) || PFMuonAlgo::isMuon(muonref) ) {
103  static_cast<reco::PFBlockElementTrack*>(tk_elem->get())->setMuonRef(muonref);
104  }
105  }
106  }
107  }
108  // now we actually insert tracks, again tagging muons along the way
109  reco::PFRecTrackRef pftrackref;
110  reco::PFBlockElementTrack* trkElem = NULL;
111  for( auto track = btrack; track != etrack; ++track) {
112  const unsigned idx = std::distance(btrack,track);
113  // since we already set muon refs in the previously imported tracks,
114  // here we can skip everything that is already imported
115  if( !mask[idx] ) continue;
116  muonref = reco::MuonRef();
117  pftrackref = reco::PFRecTrackRef(tracks,idx);
118  // Get the eventual muon associated to this track
119  const int muId = muAssocToTrack( pftrackref->trackRef(), muons );
120  bool thisIsAPotentialMuon = false;
121  if( muId != -1 ) {
122  muonref= reco::MuonRef( muons, muId );
123  thisIsAPotentialMuon = ( PFMuonAlgo::isLooseMuon(muonref) ||
124  PFMuonAlgo::isMuon(muonref) );
125  }
126  if(thisIsAPotentialMuon || goodPtResolution( pftrackref->trackRef() ) ) {
127  trkElem = new reco::PFBlockElementTrack( pftrackref );
128  if (thisIsAPotentialMuon && _debug) {
129  std::cout << "Potential Muon P " << pftrackref->trackRef()->p()
130  << " pt " << pftrackref->trackRef()->p() << std::endl;
131  }
132  if( muId != -1 ) trkElem->setMuonRef(muonref);
133  elems.emplace_back(trkElem);
134  }
135  }
136  elems.shrink_to_fit();
137 }
138 
140 goodPtResolution( const reco::TrackRef& trackref) const {
141 
142  const double P = trackref->p();
143  const double Pt = trackref->pt();
144  const double DPt = trackref->ptError();
145  const unsigned int NHit =
146  trackref->hitPattern().trackerLayersWithMeasurement();
147  const unsigned int NLostHit =
148  trackref->hitPattern().trackerLayersWithoutMeasurement(reco::HitPattern::TRACK_HITS);
149  const unsigned int LostHits = trackref->numberOfLostHits();
150  const double sigmaHad = sqrt(1.20*1.20/P+0.06*0.06) / (1.+LostHits);
151 
152  // iteration 1,2,3,4,5 correspond to algo = 1/4,5,6,7,8,9
153  unsigned int Algo = 0;
154  switch (trackref->algo()) {
162  Algo = 0;
163  break;
165  Algo = 1;
166  break;
168  Algo = 2;
169  break;
171  Algo = 3;
172  break;
174  Algo = 4;
175  break;
176  default:
177  Algo = _useIterTracking ? 5 : 0;
178  break;
179  }
180 
181  // Protection against 0 momentum tracks
182  if ( P < 0.05 ) return false;
183 
184  // Temporary : Reject all tracking iteration beyond 5th step.
185 // if ( Algo > 4 ) return false;
186 
187  if (_debug) std::cout << " PFBlockAlgo: PFrecTrack->Track Pt= "
188  << Pt << " DPt = " << DPt << std::endl;
189  if ( ( _DPtovPtCut[Algo] > 0. &&
190  DPt/Pt > _DPtovPtCut[Algo]*sigmaHad ) ||
191  NHit < _NHitCut[Algo] ) {
192  // (Algo >= 3 && LostHits != 0) ) {
193  if (_debug) std::cout << " PFBlockAlgo: skip badly measured track"
194  << ", P = " << P
195  << ", Pt = " << Pt
196  << " DPt = " << DPt
197  << ", N(hits) = " << NHit << " (Lost : " << LostHits << "/" << NLostHit << ")"
198  << ", Algo = " << Algo
199  << std::endl;
200  if (_debug) std::cout << " cut is DPt/Pt < " << _DPtovPtCut[Algo] * sigmaHad << std::endl;
201  if (_debug) std::cout << " cut is NHit >= " << _NHitCut[Algo] << std::endl;
202  /*
203  std::cout << "Track REJECTED : ";
204  std::cout << ", P = " << P
205  << ", Pt = " << Pt
206  << " DPt = " << DPt
207  << ", N(hits) = " << NHit << " (Lost : " << LostHits << "/" << NLostHit << ")"
208  << ", Algo = " << Algo
209  << std::std::endl;
210  */
211  return false;
212  }
213 
214  /*
215  std::cout << "Track Accepted : ";
216  std::cout << ", P = " << P
217  << ", Pt = " << Pt
218  << " DPt = " << DPt
219  << ", N(hits) = " << NHit << " (Lost : " << LostHits << "/" << NLostHit << ")"
220  << ", Algo = " << Algo
221  << std::std::endl;
222  */
223  return true;
224 }
225 
228  const edm::Handle<reco::MuonCollection>& muonh) const {
229  auto muon = std::find_if(muonh->cbegin(),muonh->cend(),
230  [&](const reco::Muon& m) {
231  return ( m.track().isNonnull() &&
232  m.track() == trackref );
233  });
234  return ( muon != muonh->cend() ? std::distance(muonh->cbegin(),muon) : -1 );
235 }
const VertexCompositeCandidateRef & V0Ref() const
const reco::TrackRef & trackRef() const
GeneralTracksImporter(const edm::ParameterSet &conf, edm::ConsumesCollector &sumes)
static bool isMuon(const reco::PFBlockElement &elt)
Definition: PFMuonAlgo.cc:153
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:446
const std::vector< double > _DPtovPtCut
#define P
#define NULL
Definition: scimark2.h:8
int muAssocToTrack(const reco::TrackRef &trackref, const edm::Handle< reco::MuonCollection > &muonh) const
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
bool goodPtResolution(const reco::TrackRef &trackref) const
void importToBlock(const edm::Event &, ElementList &) const override
const std::vector< unsigned > _NHitCut
T sqrt(T t)
Definition: SSEVec.h:48
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:247
tuple conf
Definition: dbtoconf.py:185
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:166
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:89
tuple cout
Definition: gather_cfg.py:121
#define DEFINE_EDM_PLUGIN(factory, type, name)
std::vector< std::unique_ptr< reco::PFBlockElement > > ElementList
volatile std::atomic< bool > shutdown_flag false
std::vector< PFRecTrack > PFRecTrackCollection
collection of PFRecTrack objects
Definition: PFRecTrackFwd.h:9
Definition: fakeMenu.h:6