CMS 3D CMS Logo

GeneralTracksImporterWithVeto.cc
Go to the documentation of this file.
10 
12 public:
14  : BlockElementImporterBase(conf, sumes),
15  src_(sumes.consumes<reco::PFRecTrackCollection>(conf.getParameter<edm::InputTag>("source"))),
16  veto_(sumes.consumes<reco::PFRecTrackCollection>(conf.getParameter<edm::InputTag>("veto"))),
17  muons_(sumes.consumes<reco::MuonCollection>(conf.getParameter<edm::InputTag>("muonSrc"))),
18  trackQuality_(reco::TrackBase::qualityByName(conf.getParameter<std::string>("trackQuality"))),
19  DPtovPtCut_(conf.getParameter<std::vector<double> >("DPtOverPtCuts_byTrackAlgo")),
20  NHitCut_(conf.getParameter<std::vector<unsigned> >("NHitCuts_byTrackAlgo")),
21  useIterTracking_(conf.getParameter<bool>("useIterativeTracking")),
22  cleanBadConvBrems_(conf.getParameter<bool>("cleanBadConvertedBrems")),
23  muonMaxDPtOPt_(conf.getParameter<double>("muonMaxDPtOPt")) {}
24 
25  void importToBlock(const edm::Event&, ElementList&) const override;
26 
27 private:
28  int muAssocToTrack(const reco::TrackRef& trackref, const edm::Handle<reco::MuonCollection>& muonh) const;
29 
33  const std::vector<double> DPtovPtCut_;
34  const std::vector<unsigned> NHitCut_;
36  const double muonMaxDPtOPt_;
37 };
38 
40 
44  auto tracks = e.getHandle(src_);
45  auto vetosH = e.getHandle(veto_);
46  const auto& vetos = *vetosH;
47  std::unordered_set<unsigned> vetoed;
48  for (unsigned i = 0; i < vetos.size(); ++i) {
49  vetoed.insert(vetos[i].trackRef().key());
50  }
51  auto muons = e.getHandle(muons_);
52  elems.reserve(elems.size() + tracks->size());
53  std::vector<bool> mask(tracks->size(), true);
54  reco::MuonRef muonref;
55 
56  // remove converted brems with bad pT resolution if requested
57  // this reproduces the old behavior of PFBlockAlgo
58  if (cleanBadConvBrems_) {
59  auto itr = elems.begin();
60  while (itr != elems.end()) {
61  if ((*itr)->type() == reco::PFBlockElement::TRACK) {
62  const reco::PFBlockElementTrack* trkel = static_cast<reco::PFBlockElementTrack*>(itr->get());
63  const reco::ConversionRefVector& cRef = trkel->convRefs();
65  const reco::VertexCompositeCandidateRef& v0Ref = 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
68  if (trkel->trackType(reco::PFBlockElement::T_FROM_GAMMACONV) && cRef.empty() && dvRef.isNull() &&
69  v0Ref.isNull()) {
70  // if the Pt resolution is bad we kill this element
73  itr = elems.erase(itr);
74  continue;
75  }
76  }
77  }
78  ++itr;
79  } // loop on existing elements
80  }
81  // preprocess existing tracks in the element list and create a mask
82  // so that we do not import tracks twice, tag muons we find
83  // in this collection
84  auto TKs_end = std::partition(
85  elems.begin(), elems.end(), [](const ElementType& a) { return a->type() == reco::PFBlockElement::TRACK; });
86  auto btk_elems = elems.begin();
87  auto btrack = tracks->cbegin();
88  auto etrack = tracks->cend();
89  for (auto track = btrack; track != etrack; ++track) {
90  auto tk_elem =
91  std::find_if(btk_elems, TKs_end, [&](const ElementType& a) { return (a->trackRef() == track->trackRef()); });
92  if (tk_elem != TKs_end) {
93  mask[std::distance(tracks->cbegin(), track)] = false;
94  // check and update if this track is a muon
95  const int muId = muAssocToTrack((*tk_elem)->trackRef(), muons);
96  if (muId != -1) {
97  muonref = reco::MuonRef(muons, muId);
98  if (PFMuonAlgo::isLooseMuon(muonref) || PFMuonAlgo::isMuon(muonref)) {
99  static_cast<reco::PFBlockElementTrack*>(tk_elem->get())->setMuonRef(muonref);
100  }
101  }
102  }
103  }
104  // now we actually insert tracks, again tagging muons along the way
105  reco::PFRecTrackRef pftrackref;
106  reco::PFBlockElementTrack* trkElem = nullptr;
107  for (auto track = btrack; track != etrack; ++track) {
108  const unsigned idx = std::distance(btrack, track);
109  // since we already set muon refs in the previously imported tracks,
110  // here we can skip everything that is already imported
111  if (!mask[idx])
112  continue;
113  muonref = reco::MuonRef();
114  pftrackref = reco::PFRecTrackRef(tracks, idx);
115  // Get the eventual muon associated to this track
116  const int muId = muAssocToTrack(pftrackref->trackRef(), muons);
117  bool thisIsAPotentialMuon = false;
118  if (muId != -1) {
119  muonref = reco::MuonRef(muons, muId);
120  thisIsAPotentialMuon =
121  ((PFMuonAlgo::hasValidTrack(muonref, true, muonMaxDPtOPt_) && PFMuonAlgo::isLooseMuon(muonref)) ||
122  (PFMuonAlgo::hasValidTrack(muonref, false, muonMaxDPtOPt_) && PFMuonAlgo::isMuon(muonref)));
123  }
124  if (thisIsAPotentialMuon || PFTrackAlgoTools::goodPtResolution(
125  pftrackref->trackRef(), DPtovPtCut_, NHitCut_, useIterTracking_, trackQuality_)) {
126  trkElem = new reco::PFBlockElementTrack(pftrackref);
127  if (thisIsAPotentialMuon) {
128  LogDebug("GeneralTracksImporterWithVeto")
129  << "Potential Muon P " << pftrackref->trackRef()->p() << " pt " << pftrackref->trackRef()->p() << std::endl;
130  }
131  if (muId != -1)
132  trkElem->setMuonRef(muonref);
133  if (vetoed.count(pftrackref->trackRef().key()) == 0 || muonref.isNonnull()) {
134  elems.emplace_back(trkElem);
135  } else
136  delete trkElem;
137  }
138  }
139  elems.shrink_to_fit();
140 }
141 
143  const edm::Handle<reco::MuonCollection>& muonh) const {
144  auto muon = std::find_if(muonh->cbegin(), muonh->cend(), [&](const reco::Muon& m) {
145  return (m.track().isNonnull() && m.track() == trackref);
146  });
147  return (muon != muonh->cend() ? std::distance(muonh->cbegin(), muon) : -1);
148 }
GeneralTracksImporterWithVeto::trackQuality_
const reco::TrackBase::TrackQuality trackQuality_
Definition: GeneralTracksImporterWithVeto.cc:32
reco::PFBlockElementTrack::trackType
bool trackType(TrackType trType) const override
Definition: PFBlockElementTrack.h:28
PDWG_BPHSkim_cff.muons
muons
Definition: PDWG_BPHSkim_cff.py:47
PDWG_EXOHSCP_cff.tracks
tracks
Definition: PDWG_EXOHSCP_cff.py:28
electrons_cff.bool
bool
Definition: electrons_cff.py:393
mps_fire.i
i
Definition: mps_fire.py:428
HLT_FULL_cff.track
track
Definition: HLT_FULL_cff.py:11776
Muon.h
MessageLogger.h
PFMuonAlgo.h
GeneralTracksImporterWithVeto::DPtovPtCut_
const std::vector< double > DPtovPtCut_
Definition: GeneralTracksImporterWithVeto.cc:33
muon
Definition: MuonCocktails.h:17
reco::PFBlockElementTrack::V0Ref
const VertexCompositeCandidateRef & V0Ref() const override
Definition: PFBlockElementTrack.h:100
edm::EDGetTokenT< reco::PFRecTrackCollection >
edm::Ref::isNull
bool isNull() const
Checks for null.
Definition: Ref.h:235
edm
HLT enums.
Definition: AlignableModifier.h:19
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:85964
reco::PFBlockElementTrack::trackRef
const reco::TrackRef & trackRef() const override
Definition: PFBlockElementTrack.h:49
GeneralTracksImporterWithVeto::veto_
edm::EDGetTokenT< reco::PFRecTrackCollection > veto_
Definition: GeneralTracksImporterWithVeto.cc:30
reco::TrackBase::TrackQuality
TrackQuality
track quality
Definition: TrackBase.h:150
GeneralTracksImporterWithVeto::cleanBadConvBrems_
const bool cleanBadConvBrems_
Definition: GeneralTracksImporterWithVeto.cc:35
edm::RefVector< ConversionCollection >
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
GeneralTracksImporterWithVeto
Definition: GeneralTracksImporterWithVeto.cc:11
edm::Handle< reco::MuonCollection >
reco::Muon
Definition: Muon.h:27
edm::Ref< TrackCollection >
heavyIonCSV_trainingSettings.idx
idx
Definition: heavyIonCSV_trainingSettings.py:5
GeneralTracksImporterWithVeto::muons_
edm::EDGetTokenT< reco::MuonCollection > muons_
Definition: GeneralTracksImporterWithVeto.cc:31
reco::PFBlockElementTrack::displacedVertexRef
const PFDisplacedTrackerVertexRef & displacedVertexRef(TrackType trType) const override
Definition: PFBlockElementTrack.h:61
Track.h
BlockElementImporterBase.h
reco::PFBlockElementTrack::setMuonRef
void setMuonRef(const MuonRef &muref) override
\set reference to the Muon
Definition: PFBlockElementTrack.h:85
HLT_FULL_cff.muon
muon
Definition: HLT_FULL_cff.py:11773
reco::PFBlockElement::TRACK
Definition: PFBlockElement.h:32
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:72
reco::MuonCollection
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
reco::MuonRef
edm::Ref< MuonCollection > MuonRef
presistent reference to a Muon
Definition: MuonFwd.h:13
reco::PFRecTrackRef
edm::Ref< PFRecTrackCollection > PFRecTrackRef
persistent reference to PFRecTrack objects
Definition: PFRecTrackFwd.h:15
GeneralTracksImporterWithVeto::useIterTracking_
const bool useIterTracking_
Definition: GeneralTracksImporterWithVeto.cc:35
DEFINE_EDM_PLUGIN
#define DEFINE_EDM_PLUGIN(factory, type, name)
Definition: PluginFactory.h:124
GeneralTracksImporterWithVeto::importToBlock
void importToBlock(const edm::Event &, ElementList &) const override
Definition: GeneralTracksImporterWithVeto.cc:41
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
BlockElementImporterBase::ElementList
std::vector< std::unique_ptr< reco::PFBlockElement > > ElementList
Definition: BlockElementImporterBase.h:16
reco::PFBlockElement::T_FROM_DISP
Definition: PFBlockElement.h:47
PFTrackAlgoTools.h
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:223
edm::ParameterSet
Definition: ParameterSet.h:47
GeneralTracksImporterWithVeto::src_
edm::EDGetTokenT< reco::PFRecTrackCollection > src_
Definition: GeneralTracksImporterWithVeto.cc:30
a
double a
Definition: hdecay.h:119
edmplugin::PluginFactory
Definition: PluginFactory.h:34
PFMuonAlgo::hasValidTrack
static bool hasValidTrack(const reco::MuonRef &muonRef, bool loose, double maxDPtOPt)
Definition: PFMuonAlgo.cc:348
reco::PFBlockElement::T_FROM_GAMMACONV
Definition: PFBlockElement.h:47
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
reco::JetExtendedAssociation::value_type
Container::value_type value_type
Definition: JetExtendedAssociation.h:30
itr
std::vector< std::pair< float, float > >::iterator itr
Definition: HGCDigitizer.cc:29
PFTrackAlgoTools::goodPtResolution
bool goodPtResolution(const reco::TrackRef &, const std::vector< double > &DPtovPtCut, const std::vector< unsigned > &NHitCut, bool useIterTracking, const reco::TrackBase::TrackQuality trackQuality)
Definition: PFTrackAlgoTools.cc:236
PFRecTrack.h
ValueMap.h
std
Definition: JetResolutionObject.h:76
GeneralTracksImporterWithVeto::muAssocToTrack
int muAssocToTrack(const reco::TrackRef &trackref, const edm::Handle< reco::MuonCollection > &muonh) const
Definition: GeneralTracksImporterWithVeto.cc:142
PFMuonAlgo::isMuon
static bool isMuon(const reco::PFBlockElement &elt)
Definition: PFMuonAlgo.cc:48
GeneralTracksImporterWithVeto::NHitCut_
const std::vector< unsigned > NHitCut_
Definition: GeneralTracksImporterWithVeto.cc:34
reco::PFBlockElementTrack
Track Element.
Definition: PFBlockElementTrack.h:17
GeneralTracksImporterWithVeto::GeneralTracksImporterWithVeto
GeneralTracksImporterWithVeto(const edm::ParameterSet &conf, edm::ConsumesCollector &sumes)
Definition: GeneralTracksImporterWithVeto.cc:13
reco::PFRecTrackCollection
std::vector< PFRecTrack > PFRecTrackCollection
collection of PFRecTrack objects
Definition: PFRecTrackFwd.h:9
edm::Ref::key
key_type key() const
Accessor for product key.
Definition: Ref.h:250
edm::Event
Definition: Event.h:73
HLT_FULL_cff.distance
distance
Definition: HLT_FULL_cff.py:7796
crabWrapper.key
key
Definition: crabWrapper.py:19
GeneralTracksImporterWithVeto::muonMaxDPtOPt_
const double muonMaxDPtOPt_
Definition: GeneralTracksImporterWithVeto.cc:36
boostedElectronIsolation_cff.vetos
vetos
Definition: boostedElectronIsolation_cff.py:79
edm::ConsumesCollector
Definition: ConsumesCollector.h:45
PFBlockElementTrack.h
PFMuonAlgo::isLooseMuon
static bool isLooseMuon(const reco::PFBlockElement &elt)
Definition: PFMuonAlgo.cc:57
reco::PFBlockElementTrack::convRefs
const ConversionRefVector & convRefs() const override
Definition: PFBlockElementTrack.h:91
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
BlockElementImporterBase
Definition: BlockElementImporterBase.h:14