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("hgcalLayerClusters"));
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 }
ConfigurationDescriptions.h
HiggsValidation_cfi.pdg_id
pdg_id
Definition: HiggsValidation_cfi.py:6
ticl::Trackster::ParticleType::neutral_hadron
mps_fire.i
i
Definition: mps_fire.py:355
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
MessageLogger.h
Trackster.h
ESHandle.h
ticl::Trackster::ParticleType::charged_hadron
TICLCandidateFromTrackstersProducer::track_algo_
std::unique_ptr< TracksterTrackPluginBase > track_algo_
Definition: TICLCandidateFromTrackstersProducer.cc:35
TICLCandidateFromTrackstersProducer::~TICLCandidateFromTrackstersProducer
~TICLCandidateFromTrackstersProducer() override
Definition: TICLCandidateFromTrackstersProducer.cc:27
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
HLT_2018_cff.distance
distance
Definition: HLT_2018_cff.py:6417
EDProducer.h
TICLCandidateFromTrackstersProducer::TICLCandidateFromTrackstersProducer
TICLCandidateFromTrackstersProducer(const edm::ParameterSet &)
Definition: TICLCandidateFromTrackstersProducer.cc:63
ticl
Definition: Common.h:8
edm::Handle
Definition: AssociativeIterator.h:50
end
#define end
Definition: vmac.h:39
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
GlobalPosition_Frontier_DevDB_cff.tag
tag
Definition: GlobalPosition_Frontier_DevDB_cff.py:11
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
HCALHighEnergyHPDFilter_cfi.energy
energy
Definition: HCALHighEnergyHPDFilter_cfi.py:5
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:528
ParameterSetDescription.h
ticl::Trackster::ParticleType::photon
TICLCandidateFromTrackstersProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: TICLCandidateFromTrackstersProducer.cc:78
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
ticl::Trackster::ParticleType::muon
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::vector_transform
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
ALCARECOTkAlJpsiMuMu_cff.charge
charge
Definition: ALCARECOTkAlJpsiMuMu_cff.py:47
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
TICLCandidate.h
edm::ParameterSet
Definition: ParameterSet.h:36
Event.h
TracksterTrackPluginBase.h
edm::Event::put
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:132
edm::stream::EDProducer
Definition: EDProducer.h:38
edm::EventSetup
Definition: EventSetup.h:57
get
#define get
edm::Ptr
Definition: AssociationVector.h:31
hgcal_clustering::max_index
size_t max_index(const std::vector< T > &v)
Definition: HGCalClusteringAlgoBase.h:30
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
type
type
Definition: HCALResponse.h:21
eostools.move
def move(src, dest)
Definition: eostools.py:511
TICLCandidateFromTrackstersProducer
Definition: TICLCandidateFromTrackstersProducer.cc:24
Frameworkfwd.h
TICLCandidateFromTrackstersProducer::trackster_tokens_
std::vector< edm::EDGetTokenT< std::vector< Trackster > > > trackster_tokens_
Definition: TICLCandidateFromTrackstersProducer.cc:33
math::XYZTLorentzVector
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
transform.h
TICLCandidateFromTrackstersProducer::min_particle_prob_
float min_particle_prob_
Definition: TICLCandidateFromTrackstersProducer.cc:36
ticl::Trackster::ParticleType::neutral_pion
mps_fire.result
result
Definition: mps_fire.py:303
ConsumesCollector.h
ticl::Trackster::ParticleType
ParticleType
Definition: Trackster.h:24
TICLCandidateFromTrackstersProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: TICLCandidateFromTrackstersProducer.cc:103
edm::Event
Definition: Event.h:73
TICLCandidateFromTrackstersProducer::momentum_algo_
std::unique_ptr< TracksterMomentumPluginBase > momentum_algo_
Definition: TICLCandidateFromTrackstersProducer.cc:34
edm::InputTag
Definition: InputTag.h:15
begin
#define begin
Definition: vmac.h:32
TracksterMomentumPluginBase.h
ticl::Trackster::ParticleType::electron