CMS 3D CMS Logo

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