CMS 3D CMS Logo

PFTrackProducer.cc
Go to the documentation of this file.
1 
27 
29 public:
31  explicit PFTrackProducer(const edm::ParameterSet&);
32 
33 private:
34  void beginRun(const edm::Run&, const edm::EventSetup&) override;
35  void endRun(const edm::Run&, const edm::EventSetup&) override;
36 
38  void produce(edm::Event&, const edm::EventSetup&) override;
39 
42 
44  std::unique_ptr<PFTrackTransformer> pfTransformer_;
45  std::vector<edm::EDGetTokenT<reco::TrackCollection>> tracksContainers_;
46  std::vector<edm::EDGetTokenT<std::vector<Trajectory>>> trajContainers_;
53  bool trajinev_;
54  bool gsfinev_;
55 };
56 
59 
60 using namespace std;
61 using namespace edm;
62 using namespace reco;
64  : transientTrackToken_(esConsumes(edm::ESInputTag("", "TransientTrackBuilder"))),
65  magneticFieldToken_(esConsumes<edm::Transition::BeginRun>()),
66  pfTransformer_() {
67  produces<reco::PFRecTrackCollection>();
68 
69  std::vector<InputTag> tags = iConfig.getParameter<vector<InputTag>>("TkColList");
70  trajinev_ = iConfig.getParameter<bool>("TrajInEvents");
71  tracksContainers_.reserve(tags.size());
72  if (trajinev_) {
73  trajContainers_.reserve(tags.size());
74  }
75  for (auto const& tag : tags) {
76  tracksContainers_.push_back(consumes<reco::TrackCollection>(tag));
77  if (trajinev_) {
78  trajContainers_.push_back(consumes<std::vector<Trajectory>>(tag));
79  }
80  }
81 
82  useQuality_ = iConfig.getParameter<bool>("UseQuality");
83 
84  gsfinev_ = iConfig.getParameter<bool>("GsfTracksInEvents");
85  if (gsfinev_) {
86  gsfTrackLabel_ = consumes<reco::GsfTrackCollection>(iConfig.getParameter<InputTag>("GsfTrackModuleLabel"));
87  }
88 
90 
91  muonColl_ = consumes<reco::MuonCollection>(iConfig.getParameter<InputTag>("MuColl"));
92 
93  vtx_h = consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("PrimaryVertexLabel"));
94 }
95 
97  //create the empty collections
98  auto PfTrColl = std::make_unique<reco::PFRecTrackCollection>();
99 
100  //read track collection
101  Handle<GsfTrackCollection> gsftrackcoll;
102  bool foundgsf = false;
103  if (gsfinev_) {
104  foundgsf = iEvent.getByToken(gsfTrackLabel_, gsftrackcoll);
105  }
106 
107  //Get PV for STIP calculation, if there is none then take the dummy
109  iEvent.getByToken(vtx_h, vertex);
111  const reco::Vertex* pv = &dummy;
112  if (vertex.isValid()) {
113  pv = &*vertex->begin();
114  } else { // create a dummy PV
116  e(0, 0) = 0.0015 * 0.0015;
117  e(1, 1) = 0.0015 * 0.0015;
118  e(2, 2) = 15. * 15.;
119  reco::Vertex::Point p(0, 0, 0);
120  dummy = reco::Vertex(p, e, 0, 0, 0);
121  }
122 
123  //setup transient track builder
124  TransientTrackBuilder const& thebuilder = iSetup.getData(transientTrackToken_);
125 
126  // read muon collection
128  iEvent.getByToken(muonColl_, recMuons);
129 
130  //default value for when trajinev_ is false
131  const vector<Trajectory> dummyTj(0);
132 
133  for (unsigned int istr = 0; istr < tracksContainers_.size(); istr++) {
134  //Track collection
135  Handle<reco::TrackCollection> tkRefCollection;
136  iEvent.getByToken(tracksContainers_[istr], tkRefCollection);
137  reco::TrackCollection Tk = *(tkRefCollection.product());
138 
139  //Use a pointer to aoid unnecessary copying of the collection
140  const vector<Trajectory>* Tj = &dummyTj;
141  if (trajinev_) {
142  //Trajectory collection
143  Handle<vector<Trajectory>> tjCollection;
144  iEvent.getByToken(trajContainers_[istr], tjCollection);
145 
146  Tj = tjCollection.product();
147  }
148 
149  for (unsigned int i = 0; i < Tk.size(); i++) {
150  reco::TrackRef trackRef(tkRefCollection, i);
151 
152  if (useQuality_ && (!(Tk[i].quality(trackQuality_)))) {
153  bool isMuCandidate = false;
154 
155  //TrackRef trackRef(tkRefCollection, i);
156 
157  if (recMuons.isValid()) {
158  for (unsigned j = 0; j < recMuons->size(); j++) {
159  reco::MuonRef muonref(recMuons, j);
160  if (muonref->track().isNonnull())
161  if (muonref->track() == trackRef && muonref->isGlobalMuon()) {
162  isMuCandidate = true;
163  //cout<<" SAVING TRACK "<<endl;
164  break;
165  }
166  }
167  }
168  if (!isMuCandidate) {
169  continue;
170  }
171  }
172 
173  // find the pre-id kf track
174  bool preId = false;
175  if (foundgsf) {
176  //NOTE: foundgsf is only true if gsftrackcoll is valid
177  for (auto const& gsfTrack : *gsftrackcoll) {
178  if (gsfTrack.seedRef().isNull())
179  continue;
180  auto const& seed = *(gsfTrack.extra()->seedRef());
181  auto const& ElSeed = dynamic_cast<ElectronSeed const&>(seed);
182  if (ElSeed.ctfTrack().isNonnull()) {
183  if (ElSeed.ctfTrack() == trackRef) {
184  preId = true;
185  break;
186  }
187  }
188  }
189  }
190  if (preId) {
191  // Set PFRecTrack of type KF_ElCAND
192  reco::PFRecTrack pftrack(trackRef->charge(), reco::PFRecTrack::KF_ELCAND, i, trackRef);
193 
194  bool valid = false;
195  if (trajinev_) {
196  valid = pfTransformer_->addPoints(pftrack, *trackRef, (*Tj)[i]);
197  } else {
198  Trajectory FakeTraj;
199  valid = pfTransformer_->addPoints(pftrack, *trackRef, FakeTraj);
200  }
201  if (valid) {
202  //calculate STIP
203  double stip = -999;
204  const reco::PFTrajectoryPoint& atECAL = pftrack.extrapolatedPoint(reco::PFTrajectoryPoint::ECALEntrance);
205  if (atECAL.isValid()) //if track extrapolates to ECAL
206  {
207  GlobalVector direction(pftrack.extrapolatedPoint(reco::PFTrajectoryPoint::ECALEntrance).position().x(),
208  pftrack.extrapolatedPoint(reco::PFTrajectoryPoint::ECALEntrance).position().y(),
209  pftrack.extrapolatedPoint(reco::PFTrajectoryPoint::ECALEntrance).position().z());
210  stip = IPTools::signedTransverseImpactParameter(thebuilder.build(*trackRef), direction, *pv)
211  .second.significance();
212  }
213  pftrack.setSTIP(stip);
214  PfTrColl->push_back(pftrack);
215  }
216  } else {
217  reco::PFRecTrack pftrack(trackRef->charge(), reco::PFRecTrack::KF, i, trackRef);
218  bool valid = false;
219  if (trajinev_) {
220  valid = pfTransformer_->addPoints(pftrack, *trackRef, (*Tj)[i]);
221  } else {
222  Trajectory FakeTraj;
223  valid = pfTransformer_->addPoints(pftrack, *trackRef, FakeTraj);
224  }
225 
226  if (valid) {
227  double stip = -999;
228  const reco::PFTrajectoryPoint& atECAL = pftrack.extrapolatedPoint(reco::PFTrajectoryPoint::ECALEntrance);
229  if (atECAL.isValid()) {
230  GlobalVector direction(pftrack.extrapolatedPoint(reco::PFTrajectoryPoint::ECALEntrance).position().x(),
231  pftrack.extrapolatedPoint(reco::PFTrajectoryPoint::ECALEntrance).position().y(),
232  pftrack.extrapolatedPoint(reco::PFTrajectoryPoint::ECALEntrance).position().z());
233  stip = IPTools::signedTransverseImpactParameter(thebuilder.build(*trackRef), direction, *pv)
234  .second.significance();
235  }
236  pftrack.setSTIP(stip);
237  PfTrColl->push_back(pftrack);
238  }
239  }
240  }
241  }
242  iEvent.put(std::move(PfTrColl));
243 }
244 
245 // ------------ method called once each job just before starting event loop ------------
246 void PFTrackProducer::beginRun(const edm::Run& run, const EventSetup& iSetup) {
247  auto const& magneticField = iSetup.getData(magneticFieldToken_);
248  pfTransformer_ = std::make_unique<PFTrackTransformer>(math::XYZVector(magneticField.inTesla(GlobalPoint(0, 0, 0))));
249  if (!trajinev_)
250  pfTransformer_->OnlyProp();
251 }
252 
253 // ------------ method called once each job just after ending the event loop ------------
254 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.cc:48
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.cc:44
ESHandle.h
PFTrackProducer::gsfTrackLabel_
edm::EDGetTokenT< reco::GsfTrackCollection > gsfTrackLabel_
Definition: PFTrackProducer.cc:47
PFTrackProducer::transientTrackToken_
const edm::ESGetToken< TransientTrackBuilder, TransientTrackRecord > transientTrackToken_
Definition: PFTrackProducer.cc:40
edm::Run
Definition: Run.h:45
PFTrackProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Produce the PFRecTrack collection.
Definition: PFTrackProducer.cc:96
edm::EDGetTokenT< reco::GsfTrackCollection >
edm
HLT enums.
Definition: AlignableModifier.h:19
PFTrackProducer
Abstract.
Definition: PFTrackProducer.cc:28
reco::Vertex::Error
math::Error< dimension >::type Error
covariance error matrix (3x3)
Definition: Vertex.h:44
PFTrackProducer::tracksContainers_
std::vector< edm::EDGetTokenT< reco::TrackCollection > > tracksContainers_
Definition: PFTrackProducer.cc:45
PFTrackProducer::trajinev_
bool trajinev_
Definition: PFTrackProducer.cc:53
reco::TrackBase::TrackQuality
TrackQuality
track quality
Definition: TrackBase.h:150
EDProducer.h
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:46
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
PFTrackTransformer.h
edm::Handle
Definition: AssociativeIterator.h:50
edm::Ref< TrackCollection >
quality
const uint32_t *__restrict__ Quality * quality
Definition: CAHitNtupletGeneratorKernelsImpl.h:122
fileCollector.seed
seed
Definition: fileCollector.py:127
PFTrackProducer::endRun
void endRun(const edm::Run &, const edm::EventSetup &) override
Definition: PFTrackProducer.cc:254
MakerMacros.h
Track.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
MuonFwd.h
IdealMagneticFieldRecord.h
PFTrackProducer::PFTrackProducer
PFTrackProducer(const edm::ParameterSet &)
Constructor.
Definition: PFTrackProducer.cc:63
PFTrackProducer::trajContainers_
std::vector< edm::EDGetTokenT< std::vector< Trajectory > > > trajContainers_
Definition: PFTrackProducer.cc:46
Point3DBase< float, GlobalTag >
reco::PFRecTrack::KF_ELCAND
Definition: PFRecTrack.h:27
bphysicsOniaDQM_cfi.vertex
vertex
Definition: bphysicsOniaDQM_cfi.py:7
TransientTrackBuilder.h
edm::ParameterSet
Definition: ParameterSet.h:47
edm::Transition
Transition
Definition: Transition.h:12
PFTrackProducer::useQuality_
bool useQuality_
TRACK QUALITY.
Definition: PFTrackProducer.cc:51
AlCaHLTBitMon_ParallelJobs.p
def p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
Event.h
makeGlobalPositionRcd_cfg.tag
tag
Definition: makeGlobalPositionRcd_cfg.py:6
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
edm::stream::EDProducer
Definition: EDProducer.h:36
TransientTrackBuilder
Definition: TransientTrackBuilder.h:16
MagneticField.h
edm::EventSetup
Definition: EventSetup.h:58
TransientTrackRecord.h
PFRecTrack.h
PFTrackProducer::trackQuality_
reco::TrackBase::TrackQuality trackQuality_
Definition: PFTrackProducer.cc:52
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ESGetToken< TransientTrackBuilder, TransientTrackRecord >
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.cc:41
Vertex.h
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
PFTrackProducer::vtx_h
edm::EDGetTokenT< reco::VertexCollection > vtx_h
Definition: PFTrackProducer.cc:49
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:246
ParameterSet.h
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.cc:54
ElectronSeed.h
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37