CMS 3D CMS Logo

PFTrackProducer.cc
Go to the documentation of this file.
1 #include <memory>
15 
16 using namespace std;
17 using namespace edm;
18 using namespace reco;
20  : transientTrackToken_(esConsumes(edm::ESInputTag("", "TransientTrackBuilder"))),
21  magneticFieldToken_(esConsumes<edm::Transition::BeginRun>()),
22  pfTransformer_() {
23  produces<reco::PFRecTrackCollection>();
24 
25  std::vector<InputTag> tags = iConfig.getParameter<vector<InputTag> >("TkColList");
26  trajinev_ = iConfig.getParameter<bool>("TrajInEvents");
27  tracksContainers_.reserve(tags.size());
28  if (trajinev_) {
29  trajContainers_.reserve(tags.size());
30  }
31  for (auto const& tag : tags) {
32  tracksContainers_.push_back(consumes<reco::TrackCollection>(tag));
33  if (trajinev_) {
34  trajContainers_.push_back(consumes<std::vector<Trajectory> >(tag));
35  }
36  }
37 
38  useQuality_ = iConfig.getParameter<bool>("UseQuality");
39 
40  gsfinev_ = iConfig.getParameter<bool>("GsfTracksInEvents");
41  if (gsfinev_) {
42  gsfTrackLabel_ = consumes<reco::GsfTrackCollection>(iConfig.getParameter<InputTag>("GsfTrackModuleLabel"));
43  }
44 
46 
47  muonColl_ = consumes<reco::MuonCollection>(iConfig.getParameter<InputTag>("MuColl"));
48 
49  vtx_h = consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("PrimaryVertexLabel"));
50 }
51 
53  //create the empty collections
54  auto PfTrColl = std::make_unique<reco::PFRecTrackCollection>();
55 
56  //read track collection
57  Handle<GsfTrackCollection> gsftrackcoll;
58  bool foundgsf = false;
59  if (gsfinev_) {
60  foundgsf = iEvent.getByToken(gsfTrackLabel_, gsftrackcoll);
61  }
62 
63  //Get PV for STIP calculation, if there is none then take the dummy
65  iEvent.getByToken(vtx_h, vertex);
67  const reco::Vertex* pv = &dummy;
68  if (vertex.isValid()) {
69  pv = &*vertex->begin();
70  } else { // create a dummy PV
72  e(0, 0) = 0.0015 * 0.0015;
73  e(1, 1) = 0.0015 * 0.0015;
74  e(2, 2) = 15. * 15.;
75  reco::Vertex::Point p(0, 0, 0);
76  dummy = reco::Vertex(p, e, 0, 0, 0);
77  }
78 
79  //setup transient track builder
80  TransientTrackBuilder const& thebuilder = iSetup.getData(transientTrackToken_);
81 
82  // read muon collection
84  iEvent.getByToken(muonColl_, recMuons);
85 
86  //default value for when trajinev_ is false
87  const vector<Trajectory> dummyTj(0);
88 
89  for (unsigned int istr = 0; istr < tracksContainers_.size(); istr++) {
90  //Track collection
91  Handle<reco::TrackCollection> tkRefCollection;
92  iEvent.getByToken(tracksContainers_[istr], tkRefCollection);
93  reco::TrackCollection Tk = *(tkRefCollection.product());
94 
95  //Use a pointer to aoid unnecessary copying of the collection
96  const vector<Trajectory>* Tj = &dummyTj;
97  if (trajinev_) {
98  //Trajectory collection
99  Handle<vector<Trajectory> > tjCollection;
100  iEvent.getByToken(trajContainers_[istr], tjCollection);
101 
102  Tj = tjCollection.product();
103  }
104 
105  for (unsigned int i = 0; i < Tk.size(); i++) {
106  reco::TrackRef trackRef(tkRefCollection, i);
107 
108  if (useQuality_ && (!(Tk[i].quality(trackQuality_)))) {
109  bool isMuCandidate = false;
110 
111  //TrackRef trackRef(tkRefCollection, i);
112 
113  if (recMuons.isValid()) {
114  for (unsigned j = 0; j < recMuons->size(); j++) {
115  reco::MuonRef muonref(recMuons, j);
116  if (muonref->track().isNonnull())
117  if (muonref->track() == trackRef && muonref->isGlobalMuon()) {
118  isMuCandidate = true;
119  //cout<<" SAVING TRACK "<<endl;
120  break;
121  }
122  }
123  }
124  if (!isMuCandidate) {
125  continue;
126  }
127  }
128 
129  // find the pre-id kf track
130  bool preId = false;
131  if (foundgsf) {
132  //NOTE: foundgsf is only true if gsftrackcoll is valid
133  for (auto const& gsfTrack : *gsftrackcoll) {
134  if (gsfTrack.seedRef().isNull())
135  continue;
136  auto const& seed = *(gsfTrack.extra()->seedRef());
137  auto const& ElSeed = dynamic_cast<ElectronSeed const&>(seed);
138  if (ElSeed.ctfTrack().isNonnull()) {
139  if (ElSeed.ctfTrack() == trackRef) {
140  preId = true;
141  break;
142  }
143  }
144  }
145  }
146  if (preId) {
147  // Set PFRecTrack of type KF_ElCAND
148  reco::PFRecTrack pftrack(trackRef->charge(), reco::PFRecTrack::KF_ELCAND, i, trackRef);
149 
150  bool valid = false;
151  if (trajinev_) {
152  valid = pfTransformer_->addPoints(pftrack, *trackRef, (*Tj)[i]);
153  } else {
154  Trajectory FakeTraj;
155  valid = pfTransformer_->addPoints(pftrack, *trackRef, FakeTraj);
156  }
157  if (valid) {
158  //calculate STIP
159  double stip = -999;
160  const reco::PFTrajectoryPoint& atECAL = pftrack.extrapolatedPoint(reco::PFTrajectoryPoint::ECALEntrance);
161  if (atECAL.isValid()) //if track extrapolates to ECAL
162  {
163  GlobalVector direction(pftrack.extrapolatedPoint(reco::PFTrajectoryPoint::ECALEntrance).position().x(),
164  pftrack.extrapolatedPoint(reco::PFTrajectoryPoint::ECALEntrance).position().y(),
165  pftrack.extrapolatedPoint(reco::PFTrajectoryPoint::ECALEntrance).position().z());
166  stip = IPTools::signedTransverseImpactParameter(thebuilder.build(*trackRef), direction, *pv)
167  .second.significance();
168  }
169  pftrack.setSTIP(stip);
170  PfTrColl->push_back(pftrack);
171  }
172  } else {
173  reco::PFRecTrack pftrack(trackRef->charge(), reco::PFRecTrack::KF, i, trackRef);
174  bool valid = false;
175  if (trajinev_) {
176  valid = pfTransformer_->addPoints(pftrack, *trackRef, (*Tj)[i]);
177  } else {
178  Trajectory FakeTraj;
179  valid = pfTransformer_->addPoints(pftrack, *trackRef, FakeTraj);
180  }
181 
182  if (valid) {
183  double stip = -999;
184  const reco::PFTrajectoryPoint& atECAL = pftrack.extrapolatedPoint(reco::PFTrajectoryPoint::ECALEntrance);
185  if (atECAL.isValid()) {
186  GlobalVector direction(pftrack.extrapolatedPoint(reco::PFTrajectoryPoint::ECALEntrance).position().x(),
187  pftrack.extrapolatedPoint(reco::PFTrajectoryPoint::ECALEntrance).position().y(),
188  pftrack.extrapolatedPoint(reco::PFTrajectoryPoint::ECALEntrance).position().z());
189  stip = IPTools::signedTransverseImpactParameter(thebuilder.build(*trackRef), direction, *pv)
190  .second.significance();
191  }
192  pftrack.setSTIP(stip);
193  PfTrColl->push_back(pftrack);
194  }
195  }
196  }
197  }
198  iEvent.put(std::move(PfTrColl));
199 }
200 
201 // ------------ method called once each job just before starting event loop ------------
202 void PFTrackProducer::beginRun(const edm::Run& run, const EventSetup& iSetup) {
203  auto const& magneticField = iSetup.getData(magneticFieldToken_);
204  pfTransformer_ = std::make_unique<PFTrackTransformer>(math::XYZVector(magneticField.inTesla(GlobalPoint(0, 0, 0))));
205  if (!trajinev_)
206  pfTransformer_->OnlyProp();
207 }
208 
209 // ------------ method called once each job just after ending the event loop ------------
210 void PFTrackProducer::endRun(const edm::Run& run, const EventSetup& iSetup) { pfTransformer_.reset(); }
Vector3DBase
Definition: Vector3DBase.h:8
PFTrackProducer::muonColl_
edm::EDGetTokenT< reco::MuonCollection > muonColl_
Definition: PFTrackProducer.h:52
mps_fire.i
i
Definition: mps_fire.py:428
edm::ESInputTag
Definition: ESInputTag.h:87
Muon.h
edm::Handle::product
T const * product() const
Definition: Handle.h:70
PFTrackProducer::pfTransformer_
std::unique_ptr< PFTrackTransformer > pfTransformer_
PFTrackTransformer.
Definition: PFTrackProducer.h:48
ESHandle.h
PFTrackProducer::gsfTrackLabel_
edm::EDGetTokenT< reco::GsfTrackCollection > gsfTrackLabel_
Definition: PFTrackProducer.h:51
PFTrackProducer::transientTrackToken_
const edm::ESGetToken< TransientTrackBuilder, TransientTrackRecord > transientTrackToken_
Definition: PFTrackProducer.h:44
edm::Run
Definition: Run.h:45
PFTrackProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Produce the PFRecTrack collection.
Definition: PFTrackProducer.cc:52
edm
HLT enums.
Definition: AlignableModifier.h:19
reco::Vertex::Error
math::Error< dimension >::type Error
covariance error matrix (3x3)
Definition: Vertex.h:44
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
PFTrackProducer::tracksContainers_
std::vector< edm::EDGetTokenT< reco::TrackCollection > > tracksContainers_
Definition: PFTrackProducer.h:49
PFTrackProducer::trajinev_
bool trajinev_
Definition: PFTrackProducer.h:57
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:222
reco::PFRecTrack::KF
Definition: PFRecTrack.h:25
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
HLT_FULL_cff.magneticField
magneticField
Definition: HLT_FULL_cff.py:348
IPTools::signedTransverseImpactParameter
std::pair< bool, Measurement1D > signedTransverseImpactParameter(const reco::TransientTrack &track, const GlobalVector &direction, const reco::Vertex &vertex)
Definition: IPTools.cc:57
PFTrackProducer.h
PFTrackTransformer.h
edm::Handle
Definition: AssociativeIterator.h:50
ElectronSeedFwd.h
edm::Ref< TrackCollection >
quality
const uint32_t *__restrict__ Quality * quality
Definition: CAHitNtupletGeneratorKernelsImpl.h:109
fileCollector.seed
seed
Definition: fileCollector.py:127
PFTrackProducer::endRun
void endRun(const edm::Run &, const edm::EventSetup &) override
Definition: PFTrackProducer.cc:210
Track.h
GlobalPosition_Frontier_DevDB_cff.tag
tag
Definition: GlobalPosition_Frontier_DevDB_cff.py:11
PFTrackProducer::PFTrackProducer
PFTrackProducer(const edm::ParameterSet &)
Constructor.
Definition: PFTrackProducer.cc:19
PFTrackProducer::trajContainers_
std::vector< edm::EDGetTokenT< std::vector< Trajectory > > > trajContainers_
Definition: PFTrackProducer.h:50
Point3DBase< float, GlobalTag >
reco::PFRecTrack::KF_ELCAND
Definition: PFRecTrack.h:27
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
Vertex.h
bphysicsOniaDQM_cfi.vertex
vertex
Definition: bphysicsOniaDQM_cfi.py:7
edm::ParameterSet
Definition: ParameterSet.h:47
edm::Transition
Transition
Definition: Transition.h:12
PFTrackProducer::useQuality_
bool useQuality_
TRACK QUALITY.
Definition: PFTrackProducer.h:55
edm::Ref::isNonnull
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
math::XYZVector
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
MetAnalyzer.pv
def pv(vc)
Definition: MetAnalyzer.py:7
iEvent
int iEvent
Definition: GenABIO.cc:224
GsfTrack.h
TransientTrackBuilder
Definition: TransientTrackBuilder.h:16
edm::EventSetup
Definition: EventSetup.h:58
PFRecTrack.h
PFTrackProducer::trackQuality_
reco::TrackBase::TrackQuality trackQuality_
Definition: PFTrackProducer.h:56
reco::PFTrajectoryPoint::isValid
bool isValid() const
is this point valid ?
Definition: PFTrajectoryPoint.h:84
edm::EventSetup::getData
bool getData(T &iHolder) const
Definition: EventSetup.h:127
reco::TrackBase::qualityByName
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:126
reco::PFTrajectoryPoint::ECALEntrance
ECAL front face.
Definition: PFTrajectoryPoint.h:43
Trajectory.h
reco::Vertex::Point
math::XYZPoint Point
point in the space
Definition: Vertex.h:40
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
IPTools.h
writedatasetfile.run
run
Definition: writedatasetfile.py:27
HltBtagValidation_cff.Vertex
Vertex
Definition: HltBtagValidation_cff.py:32
PFTrackProducer::magneticFieldToken_
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > magneticFieldToken_
Definition: PFTrackProducer.h:45
reco::PFRecTrack
reconstructed track used as an input to particle flow
Definition: PFRecTrack.h:20
Trajectory
Definition: Trajectory.h:38
edm::Transition::BeginRun
reco::PFTrajectoryPoint
A PFTrack holds several trajectory points, which basically contain the position and momentum of a tra...
Definition: PFTrajectoryPoint.h:26
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
triggerMatcherToHLTDebug_cfi.tags
tags
Definition: triggerMatcherToHLTDebug_cfi.py:9
PFRecTrackFwd.h
PFTrackProducer::vtx_h
edm::EDGetTokenT< reco::VertexCollection > vtx_h
Definition: PFTrackProducer.h:53
TransientTrackBuilder::build
reco::TransientTrack build(const reco::Track *p) const
Definition: TransientTrackBuilder.cc:20
RunInfoPI::valid
Definition: RunInfoPayloadInspectoHelper.h:16
PFTrackProducer::beginRun
void beginRun(const edm::Run &, const edm::EventSetup &) override
Definition: PFTrackProducer.cc:202
dummy
Definition: DummySelector.h:38
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
DeDxTools::esConsumes
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
edm::Event
Definition: Event.h:73
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
PFTrackProducer::gsfinev_
bool gsfinev_
Definition: PFTrackProducer.h:58
ElectronSeed.h
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37