CMS 3D CMS Logo

TICLCandidateFromTrackstersProducer.cc
Go to the documentation of this file.
1 // user include files
2 #include <algorithm>
3 #include <vector>
4 
14 
16 
21 
22 using namespace ticl;
23 
25 public:
28  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
29 
30  void produce(edm::Event&, const edm::EventSetup&) override;
31 
32 private:
33  std::vector<edm::EDGetTokenT<std::vector<Trackster>>> trackster_tokens_;
34  std::unique_ptr<TracksterMomentumPluginBase> momentum_algo_;
35  std::unique_ptr<TracksterTrackPluginBase> track_algo_;
37 };
39 
40 namespace {
41  int pdg_id_from_particle_type(ticl::Trackster::ParticleType type) {
42  switch (type) {
44  return 22;
46  // Pick IDs with positive charge so they can be reset with charge * id downstream
47  return -11;
49  return -13;
51  return 111;
53  return 211;
55  return 130;
56  default:
57  return 0;
58  }
59  return 0;
60  }
61 } // namespace
62 
64  : min_particle_prob_(ps.getParameter<double>("minParticleProbability")) {
66  edm::vector_transform(ps.getParameter<std::vector<edm::InputTag>>("tracksterCollections"),
67  [this](edm::InputTag const& tag) { return consumes<std::vector<Trackster>>(tag); });
68  produces<std::vector<TICLCandidate>>();
69  auto pset_momentum = ps.getParameter<edm::ParameterSet>("momentumPlugin");
71  pset_momentum.getParameter<std::string>("plugin"), pset_momentum, consumesCollector());
72 
73  auto pset_track = ps.getParameter<edm::ParameterSet>("trackPlugin");
75  pset_track.getParameter<std::string>("plugin"), pset_track, consumesCollector());
76 }
77 
80 
81  std::vector<edm::InputTag> source_vector{edm::InputTag("trackstersTrk"),
82  edm::InputTag("trackstersMIP"),
83  edm::InputTag("trackstersEM"),
84  edm::InputTag("trackstersHAD")};
85  desc.add<std::vector<edm::InputTag>>("tracksterCollections", source_vector);
86  desc.add<double>("minParticleProbability", 0.);
87 
88  edm::ParameterSetDescription desc_momentum;
89  desc_momentum.add<std::string>("plugin", "TracksterP4FromEnergySum");
90  desc_momentum.add<bool>("energyFromRegression", false);
91  desc_momentum.add<edm::InputTag>("vertices", edm::InputTag("offlinePrimaryVertices"));
92  desc_momentum.add<edm::InputTag>("layerClusters", edm::InputTag("hgcalMergeLayerClusters"));
93  desc_momentum.add<edm::InputTag>("tracks", edm::InputTag("generalTracks"));
94  desc.add<edm::ParameterSetDescription>("momentumPlugin", desc_momentum);
95 
97  desc_track.add<std::string>("plugin", "TracksterRecoTrackPlugin");
98  desc.add<edm::ParameterSetDescription>("trackPlugin", desc_track);
99 
100  descriptions.add("ticlCandidateFromTrackstersProducer", desc);
101 }
102 
104  auto result = std::make_unique<std::vector<TICLCandidate>>();
105 
106  std::vector<const Trackster*> trackster_ptrs;
107 
108  // adds one TICLCandidate for each trackster that has a minimum particle probability
109  for (auto& trackster_token : trackster_tokens_) {
111  evt.getByToken(trackster_token, trackster_h);
112  for (size_t i_trackster = 0; i_trackster < trackster_h->size(); ++i_trackster) {
113  auto const& trackster = trackster_h->at(i_trackster);
114  auto id_prob_begin = std::begin(trackster.id_probabilities());
115  auto max_id_prob_it = std::max_element(id_prob_begin, std::end(trackster.id_probabilities()));
116  float max_id_prob = *max_id_prob_it;
117  if (max_id_prob < min_particle_prob_)
118  continue;
119 
120  trackster_ptrs.push_back(&trackster);
121  auto& ticl_cand = result->emplace_back(edm::Ptr<ticl::Trackster>(trackster_h, i_trackster));
122  auto max_index = std::distance(id_prob_begin, max_id_prob_it);
123  auto pdg_id = pdg_id_from_particle_type(static_cast<ticl::Trackster::ParticleType>(max_index));
124  ticl_cand.setPdgId(pdg_id);
125  }
126  }
127 
128  momentum_algo_->setP4(trackster_ptrs, *result, evt);
129  track_algo_->setTrack(trackster_ptrs, *result, evt);
130 
131  // charge assignment
132  for (size_t i = 0; i < result->size(); ++i) {
133  auto& ticl_cand = result->at(i);
134  auto pdg_id = ticl_cand.pdgId();
135  if (pdg_id == -11 || pdg_id == -13 || pdg_id == 211) {
136  if (ticl_cand.trackPtr().isNonnull()) {
137  auto charge = ticl_cand.trackPtr()->charge();
138  ticl_cand.setCharge(charge);
139  ticl_cand.setPdgId(pdg_id * charge);
140  // If this is a special 0 energy trackster that has been injected
141  // starting from a seed that has not been linked to any shower,
142  // re-assign the energy and momentum to be the ones of the track linked
143  // to the original seeding region.
144  if (ticl_cand.rawEnergy() == 0.) {
145  auto const& three_mom = ticl_cand.trackPtr()->momentum();
146  constexpr double mpion2 = 0.13957 * 0.13957;
147  double energy = std::sqrt(three_mom.mag2() + mpion2);
148  math::XYZTLorentzVector trk_p4(three_mom.x(), three_mom.y(), three_mom.z(), energy);
149  ticl_cand.setP4(trk_p4);
150  ticl_cand.setRawEnergy(energy);
151  }
152  } else {
153  // Demote them to be neutral, since there's not track associated.
154  ticl_cand.setCharge(0);
155  if (pdg_id == -11) {
156  ticl_cand.setPdgId(22);
157  } else {
158  ticl_cand.setPdgId(130);
159  }
160  }
161  }
162  }
163 
164  evt.put(std::move(result));
165 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
std::unique_ptr< TracksterTrackPluginBase > track_algo_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:528
auto vector_transform(std::vector< InputType > const &input, Function predicate) -> std::vector< typename std::remove_cv< typename std::remove_reference< decltype(predicate(input.front()))>::type >::type >
Definition: transform.h:11
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
T sqrt(T t)
Definition: SSEVec.h:23
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ParameterDescriptionBase * add(U const &iLabel, T const &value)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::unique_ptr< TracksterMomentumPluginBase > momentum_algo_
constexpr float mpion2
Definition: Common.h:41
void produce(edm::Event &, const edm::EventSetup &) override
std::vector< edm::EDGetTokenT< std::vector< Trackster > > > trackster_tokens_
Definition: Common.h:10
size_t max_index(const std::vector< T > &v)
#define get
def move(src, dest)
Definition: eostools.py:511