CMS 3D CMS Logo

PATTracksToPackedCandidates.cc
Go to the documentation of this file.
1 //Based on: PhysicsTools/PatAlgos/plugins/PATLostTracks.cc
2 
3 // system include files
4 #include <memory>
5 
6 // user include files
9 
12 
15 
21 
25 
26 #include <vector>
27 
28 //
29 // class declaration
30 //
31 
33 public:
35 
36  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
37 
38  void addPackedCandidate(std::vector<pat::PackedCandidate>& cands,
39  const reco::Track trk,
40  const reco::VertexRef& pvSlimmed,
41  const reco::VertexRefProd& pvSlimmedColl,
42  bool passPixelTrackSel) const;
43 
44 private:
45  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
46 
47  // ----------member data ---------------------------
51  const double dzSigCut_;
52  const double dxySigCut_;
53  const double dzSigHP_;
54  const double dxySigHP_;
55  const double ptMax_;
56  const double ptMin_;
57  const bool resetHP_;
58  const int covarianceVersion_;
59  const int covarianceSchema_;
60 };
61 
62 //
63 // constants, enums and typedefs
64 //
65 
66 //
67 // static data member definitions
68 //
69 
70 //
71 // constructors and destructor
72 //
74  : srcTracks_(consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("srcTracks"))),
75  srcPrimaryVertices_(consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("srcPrimaryVertices"))),
76  srcOfflineBeamSpot_(consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("srcOfflineBeamSpot"))),
77  dzSigCut_(iConfig.getParameter<double>("dzSigCut")),
78  dxySigCut_(iConfig.getParameter<double>("dxySigCut")),
79  dzSigHP_(iConfig.getParameter<double>("dzSigHP")),
80  dxySigHP_(iConfig.getParameter<double>("dxySigHP")),
81  ptMax_(iConfig.getParameter<double>("ptMax")),
82  ptMin_(iConfig.getParameter<double>("ptMin")),
83  resetHP_(iConfig.getParameter<bool>("resetHP")),
84  covarianceVersion_(iConfig.getParameter<int>("covarianceVersion")),
85  covarianceSchema_(iConfig.getParameter<int>("covarianceSchema")) {
86  produces<std::vector<pat::PackedCandidate>>();
87  produces<edm::Association<pat::PackedCandidateCollection>>();
88 }
89 
90 //
91 // member functions
92 //
93 
94 // ------------ method called to produce the data ------------
96  using namespace edm;
97  using namespace std;
98 
99  //track collection
100  auto tracks = iEvent.getHandle(srcTracks_);
101 
102  auto outPtrTrksAsCands = std::make_unique<std::vector<pat::PackedCandidate>>();
103 
104  //vtx collection
105  auto pvs = iEvent.getHandle(srcPrimaryVertices_);
106  reco::VertexRef pv(pvs.id());
107  reco::VertexRefProd pvRefProd(pvs);
108 
109  //best vertex
110  double bestvzError;
111  math::XYZPoint bestvtx;
112  math::Error<3>::type vtx_cov;
113  if (!pvs->empty()) {
114  pv = reco::VertexRef(pvs, 0);
115  const reco::Vertex& vtx = (*pvs)[0];
116  bestvzError = vtx.zError();
117  bestvtx = vtx.position();
118  vtx_cov = vtx.covariance();
119  } else {
120  const auto& bs = iEvent.get(srcOfflineBeamSpot_);
121  bestvzError = bs.z0Error();
122  bestvtx = bs.position();
123  vtx_cov = bs.covariance3D();
124  }
125 
126  std::vector<int> mapping(tracks->size(), -1);
127  int savedCandIndx = 0;
128  int trkIndx = -1;
129  for (auto const& trk : *tracks) {
130  trkIndx++;
131  double dzvtx = std::abs(trk.dz(bestvtx));
132  double dxyvtx = std::abs(trk.dxy(bestvtx));
133  double dzerror = std::hypot(trk.dzError(), bestvzError);
134  double dxyerror = trk.dxyError(bestvtx, vtx_cov);
135 
136  if (dzvtx >= dzSigCut_ * dzerror)
137  continue;
138  if (dxyvtx >= dxySigCut_ * dxyerror)
139  continue;
140  if (trk.pt() >= ptMax_ || trk.pt() <= ptMin_)
141  continue;
142 
143  bool passSelection = (dzvtx < dzSigHP_ * dzerror && dxyvtx < dxySigHP_ * dxyerror);
144 
145  addPackedCandidate(*outPtrTrksAsCands, trk, pv, pvRefProd, passSelection);
146 
147  //for creating the reco::Track -> pat::PackedCandidate map
148  mapping[trkIndx] = savedCandIndx;
149  savedCandIndx++;
150  }
152  auto tk2pc = std::make_unique<edm::Association<pat::PackedCandidateCollection>>(oh);
154  tk2pcFiller.insert(tracks, mapping.begin(), mapping.end());
155  tk2pcFiller.fill();
156  iEvent.put(std::move(tk2pc));
157 }
158 
159 void PATTracksToPackedCandidates::addPackedCandidate(std::vector<pat::PackedCandidate>& cands,
160  const reco::Track trk,
161  const reco::VertexRef& pvSlimmed,
162  const reco::VertexRefProd& pvSlimmedColl,
163  bool passPixelTrackSel) const {
164  const float mass = 0.13957018;
165 
166  int id = 211 * trk.charge();
167 
168  reco::Candidate::PolarLorentzVector p4(trk.pt(), trk.eta(), trk.phi(), mass);
169  cands.emplace_back(p4, trk.vertex(), trk.pt(), trk.eta(), trk.phi(), id, pvSlimmedColl, pvSlimmed.key());
170 
171  if (resetHP_) {
172  if (passPixelTrackSel)
173  cands.back().setTrackHighPurity(true);
174  else
175  cands.back().setTrackHighPurity(false);
176  } else {
178  cands.back().setTrackHighPurity(true);
179  else
180  cands.back().setTrackHighPurity(false);
181  }
182 
183  cands.back().setTrackProperties(trk, covarianceSchema_, covarianceVersion_);
184 }
185 
186 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
188  //The following says we do not know what parameters are allowed so do no validation
189  // Please change this to state exactly what you do use, even if it is no parameters
191  desc.add<edm::InputTag>("srcTracks", {"hiConformalPixelTracks"});
192  desc.add<edm::InputTag>("srcPrimaryVertices", {"offlineSlimmedPrimaryVertices"});
193  desc.add<edm::InputTag>("srcOfflineBeamSpot", {"offlineBeamSpot"})
194  ->setComment("use BeamSpot if empty vtx collection");
195  desc.add<double>("dzSigCut", 10.0);
196  desc.add<double>("dxySigCut", 25.0);
197  desc.add<double>("dzSigHP", 7.0)->setComment("to set HighPurity flag for pixel tracks");
198  desc.add<double>("dxySigHP", 20.0)->setComment("to set HighPurity flag for pixel tracks");
199  desc.add<double>("ptMax", 1.0)->setComment("max pT for pixel tracks - above this will use general tracks");
200  desc.add<double>("ptMin", 0.3)->setComment("min pT for pixel tracks");
201  desc.add<bool>("resetHP", true)
202  ->setComment("pixel tracks do not have HP flag set. Use False if does not want to reset HP flag");
203  desc.add<int>("covarianceVersion", 0)->setComment("so far: 0 is Phase0, 1 is Phase1");
204  desc.add<int>("covarianceSchema", 520)->setComment("use less accurate schema - reduce size of collection");
205  descriptions.addWithDefaultLabel(desc);
206 }
207 
208 //define this as a plug-in
edm::RefProd< VertexCollection >
edm::StreamID
Definition: StreamID.h:30
electrons_cff.bool
bool
Definition: electrons_cff.py:366
edm::Association::Filler
Definition: Association.h:78
PATTracksToPackedCandidates::ptMax_
const double ptMax_
Definition: PATTracksToPackedCandidates.cc:55
align::BeamSpot
Definition: StructureType.h:95
PATTracksToPackedCandidates::dzSigCut_
const double dzSigCut_
Definition: PATTracksToPackedCandidates.cc:51
edm::EDGetTokenT< reco::TrackCollection >
edm
HLT enums.
Definition: AlignableModifier.h:19
reco::Candidate::PolarLorentzVector
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
Definition: Candidate.h:38
reco::VertexCollection
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
PATTracksToPackedCandidates::covarianceVersion_
const int covarianceVersion_
Definition: PATTracksToPackedCandidates.cc:58
PATTracksToPackedCandidates::srcPrimaryVertices_
const edm::EDGetTokenT< reco::VertexCollection > srcPrimaryVertices_
Definition: PATTracksToPackedCandidates.cc:49
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89285
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
PATTracksToPackedCandidates::covarianceSchema_
const int covarianceSchema_
Definition: PATTracksToPackedCandidates.cc:59
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
Association.h
PATTracksToPackedCandidates::produce
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
Definition: PATTracksToPackedCandidates.cc:95
edm::Ref< VertexCollection >
reco::TrackBase::pt
double pt() const
track transverse momentum
Definition: TrackBase.h:637
MakerMacros.h
cms::cuda::bs
bs
Definition: HistoContainer.h:127
Track.h
TrackFwd.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
BeamSpot.h
PATTracksToPackedCandidates::dxySigHP_
const double dxySigHP_
Definition: PATTracksToPackedCandidates.cc:54
PATTracksToPackedCandidates::dxySigCut_
const double dxySigCut_
Definition: PATTracksToPackedCandidates.cc:52
reco::Track
Definition: Track.h:27
PATTracksToPackedCandidates::srcTracks_
const edm::EDGetTokenT< reco::TrackCollection > srcTracks_
Definition: PATTracksToPackedCandidates.cc:48
reco::TrackBase::charge
int charge() const
track electric charge
Definition: TrackBase.h:596
PATTracksToPackedCandidates
Definition: PATTracksToPackedCandidates.cc:32
PATTracksToPackedCandidates::PATTracksToPackedCandidates
PATTracksToPackedCandidates(const edm::ParameterSet &)
Definition: PATTracksToPackedCandidates.cc:73
PATTracksToPackedCandidates::srcOfflineBeamSpot_
const edm::EDGetTokenT< reco::BeamSpot > srcOfflineBeamSpot_
Definition: PATTracksToPackedCandidates.cc:50
reco::TrackBase::phi
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:649
edm::global::EDProducer
Definition: EDProducer.h:32
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
Vertex.h
PATTracksToPackedCandidates::addPackedCandidate
void addPackedCandidate(std::vector< pat::PackedCandidate > &cands, const reco::Track trk, const reco::VertexRef &pvSlimmed, const reco::VertexRefProd &pvSlimmedColl, bool passPixelTrackSel) const
Definition: PATTracksToPackedCandidates.cc:159
HLT_FULL_cff.cands
cands
Definition: HLT_FULL_cff.py:15146
edm::ParameterSet
Definition: ParameterSet.h:47
math::XYZPoint
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
Event.h
tracks
const uint32_t *__restrict__ const HitContainer *__restrict__ TkSoA *__restrict__ tracks
Definition: CAHitNtupletGeneratorKernelsImpl.h:159
PATTracksToPackedCandidates::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: PATTracksToPackedCandidates.cc:187
PackedCandidate.h
PATTracksToPackedCandidates::resetHP_
const bool resetHP_
Definition: PATTracksToPackedCandidates.cc:57
reco::TrackBase::eta
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:652
reco::VertexRef
edm::Ref< VertexCollection > VertexRef
persistent reference to a Vertex
Definition: VertexFwd.h:13
createfilelist.int
int
Definition: createfilelist.py:10
MetAnalyzer.pv
def pv(vc)
Definition: MetAnalyzer.py:7
iEvent
int iEvent
Definition: GenABIO.cc:224
p4
double p4[4]
Definition: TauolaWrapper.h:92
edm::EventSetup
Definition: EventSetup.h:58
FSQDQM_cfi.pvs
pvs
Definition: FSQDQM_cfi.py:12
reco::TrackBase::vertex
const Point & vertex() const
reference point on the track. This method is DEPRECATED, please use referencePoint() instead
Definition: TrackBase.h:676
PATTracksToPackedCandidates::dzSigHP_
const double dzSigHP_
Definition: PATTracksToPackedCandidates.cc:53
VertexFwd.h
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
edm::OrphanHandle
Definition: EDProductfwd.h:39
extraflags_cff.vtx
vtx
Definition: extraflags_cff.py:18
Frameworkfwd.h
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
math::Error::type
ErrorD< N >::type type
Definition: Error.h:32
EgHLTOffHistBins_cfi.mass
mass
Definition: EgHLTOffHistBins_cfi.py:34
edm::Ref::key
key_type key() const
Accessor for product key.
Definition: Ref.h:250
Candidate.h
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ParameterSet.h
EDProducer.h
edm::Event
Definition: Event.h:73
StreamID.h
taus_updatedMVAIds_cff.mapping
mapping
Definition: taus_updatedMVAIds_cff.py:29
reco::TrackBase::quality
bool quality(const TrackQuality) const
Track quality.
Definition: TrackBase.h:552
edm::InputTag
Definition: InputTag.h:15
reco::TrackCollection
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
reco::Vertex
Definition: Vertex.h:35
edm::ConfigurationDescriptions::addWithDefaultLabel
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:87
PATTracksToPackedCandidates::ptMin_
const double ptMin_
Definition: PATTracksToPackedCandidates.cc:56
reco::TrackBase::highPurity
Definition: TrackBase.h:154