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(); }
reconstructed track used as an input to particle flow
Definition: PFRecTrack.h:20
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
TrackQuality
track quality
Definition: TrackBase.h:150
PFTrackProducer(const edm::ParameterSet &)
Constructor.
const edm::ESGetToken< TransientTrackBuilder, TransientTrackRecord > transientTrackToken_
std::pair< bool, Measurement1D > signedTransverseImpactParameter(const reco::TransientTrack &track, const GlobalVector &direction, const reco::Vertex &vertex)
Definition: IPTools.cc:57
T const * product() const
Definition: Handle.h:70
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
math::Error< dimension >::type Error
covariance error matrix (3x3)
Definition: Vertex.h:45
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
edm::EDGetTokenT< reco::GsfTrackCollection > gsfTrackLabel_
edm::EDGetTokenT< reco::VertexCollection > vtx_h
std::vector< edm::EDGetTokenT< reco::TrackCollection > > tracksContainers_
reco::TransientTrack build(const reco::Track *p) const
U second(std::pair< T, U > const &p)
string quality
bool isValid() const
is this point valid ?
int iEvent
Definition: GenABIO.cc:224
void endRun(const edm::Run &, const edm::EventSetup &) override
bool useQuality_
TRACK QUALITY.
def pv(vc)
Definition: MetAnalyzer.py:7
Transition
Definition: Transition.h:12
math::XYZPoint Point
point in the space
Definition: Vertex.h:40
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< reco::MuonCollection > muonColl_
void beginRun(const edm::Run &, const edm::EventSetup &) override
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > magneticFieldToken_
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:126
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
std::vector< edm::EDGetTokenT< std::vector< Trajectory > > > trajContainers_
bool isValid() const
Definition: HandleBase.h:70
void produce(edm::Event &, const edm::EventSetup &) override
Produce the PFRecTrack collection.
fixed size matrix
HLT enums.
reco::TrackBase::TrackQuality trackQuality_
A PFTrack holds several trajectory points, which basically contain the position and momentum of a tra...
def move(src, dest)
Definition: eostools.py:511
std::unique_ptr< PFTrackTransformer > pfTransformer_
PFTrackTransformer.
Definition: Run.h:45