CMS 3D CMS Logo

TracksterP4FromTrackAndPCA.cc
Go to the documentation of this file.
1 // Plugin for getting the four-vector of a Trackster from the track, if
2 // present, or from PCA decomposition.
3 
9 
10 namespace ticl {
12  public:
14  void setP4(const std::vector<const Trackster*>& tracksters,
15  std::vector<TICLCandidate>& ticl_cands,
16  edm::Event& event) const override;
17 
18  private:
19  std::tuple<TracksterMomentumPluginBase::LorentzVector, float> calcP4(const ticl::Trackster& trackster) const;
22  };
23 
26  energy_from_regression_(ps.getParameter<bool>("energyFromRegression")),
27  tracks_token_(ic.consumes<reco::TrackCollection>(ps.getParameter<edm::InputTag>("tracks"))) {}
28 
29  void TracksterP4FromTrackAndPCA::setP4(const std::vector<const Trackster*>& tracksters,
30  std::vector<TICLCandidate>& ticl_cands,
31  edm::Event& event) const {
33  event.getByToken(tracks_token_, tracks_h);
34  edm::ProductID trkId = tracks_h.id();
35  const reco::TrackCollection& trackCollection = *tracks_h.product();
36 
37  auto size = std::min(tracksters.size(), ticl_cands.size());
38  for (size_t i = 0; i < size; ++i) {
39  const auto* trackster = tracksters[i];
40  // If there's a track, use it.
41  if (trackster->seedIndex() != -1) {
42  assert(trackster->seedID() == trkId);
43  auto const& tkRef = trackCollection[trackster->seedIndex()];
44  auto const& three_mom = tkRef.momentum();
45  constexpr double mpion2 = 0.13957 * 0.13957;
46  double energy = std::sqrt(tkRef.momentum().mag2() + mpion2);
47  math::XYZTLorentzVector trk_p4(three_mom.x(), three_mom.y(), three_mom.z(), energy);
48  auto& ticl_cand = ticl_cands[i];
49  ticl_cand.setP4(trk_p4);
50  ticl_cand.setRawEnergy(energy);
51  } else {
52  auto direction = trackster->eigenvectors(0).Unit();
53  auto energy = energy_from_regression_ ? trackster->regressed_energy() : trackster->raw_energy();
54  direction *= energy;
55  math::XYZTLorentzVector cartesian(direction.X(), direction.Y(), direction.Z(), energy);
56  auto& ticl_cand = ticl_cands[i];
57  ticl_cand.setP4(cartesian);
58  ticl_cand.setRawEnergy(energy);
59  }
60  }
61  }
62 } // namespace ticl
63 
ProductID id() const
Definition: HandleBase.cc:29
std::tuple< TracksterMomentumPluginBase::LorentzVector, float > calcP4(const ticl::Trackster &trackster) const
T const * product() const
Definition: Handle.h:70
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
void setP4(const std::vector< const Trackster *> &tracksters, std::vector< TICLCandidate > &ticl_cands, edm::Event &event) const override
assert(be >=bs)
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
edm::EDGetTokenT< reco::TrackCollection > tracks_token_
T sqrt(T t)
Definition: SSEVec.h:23
trackCollection
Definition: JetHT_cfg.py:51
fixed size matrix
HLT enums.
constexpr float mpion2
Definition: Common.h:41
Definition: Common.h:10
#define DEFINE_EDM_PLUGIN(factory, type, name)
TracksterP4FromTrackAndPCA(const edm::ParameterSet &, edm::ConsumesCollector &&iC)
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1