Skip to content

Commit

Permalink
Merge pull request #28116 from steggema/TICLtoPF
Browse files Browse the repository at this point in the history
TICL: Create PF candidates as output of TICL
  • Loading branch information
cmsbuild committed Oct 23, 2019
2 parents b93fe86 + b4bbe6f commit 5a7a185
Show file tree
Hide file tree
Showing 25 changed files with 691 additions and 11 deletions.
3 changes: 3 additions & 0 deletions DataFormats/HGCalReco/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<use name="DataFormats/Math"/>
<use name="DataFormats/Provenance"/>
<use name="DataFormats/Candidate"/>
<use name="DataFormats/Common"/>
<use name="DataFormats/TrackReco"/>

<export>
<lib name="1"/>
Expand Down
63 changes: 63 additions & 0 deletions DataFormats/HGCalReco/interface/TICLCandidate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#ifndef DataFormats_HGCalReco_TICLCandidate_h
#define DataFormats_HGCalReco_TICLCandidate_h

#include "DataFormats/Candidate/interface/LeafCandidate.h"
#include "DataFormats/Common/interface/Ref.h"
#include "DataFormats/HGCalReco/interface/Trackster.h"
#include "DataFormats/Math/interface/Point3D.h"
#include "DataFormats/TrackReco/interface/Track.h"
#include "DataFormats/TrackReco/interface/TrackFwd.h"

// A TICLCandidate is a lightweight physics object made from one or multiple Tracksters.

class TICLCandidate : public reco::LeafCandidate {
public:
typedef ticl::Trackster::ParticleType ParticleType;

TICLCandidate(Charge q, const LorentzVector& p4)
: LeafCandidate(q, p4), time_(0.f), timeError_(-1.f), rawEnergy_(0.f) {}

TICLCandidate() : LeafCandidate(), time_(0.f), timeError_(-1.f), rawEnergy_(0.f) {}

TICLCandidate(const edm::Ptr<ticl::Trackster>& trackster)
: LeafCandidate(), time_(0.f), timeError_(-1.f), rawEnergy_(0.f), tracksters_({trackster}) {}

inline float time() const { return time_; }
inline float timeError() const { return timeError_; }

void setTime(float time) { time_ = time; };
void setTimeError(float timeError) { timeError_ = timeError; }

inline const edm::Ptr<reco::Track> trackPtr() const { return trackPtr_; }
void setTrackPtr(const edm::Ptr<reco::Track>& trackPtr) { trackPtr_ = trackPtr; }

inline float rawEnergy() const { return rawEnergy_; }
void setRawEnergy(float rawEnergy) { rawEnergy_ = rawEnergy; }

inline const std::vector<edm::Ptr<ticl::Trackster> > tracksters() const { return tracksters_; };

void setTracksters(const std::vector<edm::Ptr<ticl::Trackster> >& tracksters) { tracksters_ = tracksters; }
void addTrackster(const edm::Ptr<ticl::Trackster>& trackster) { tracksters_.push_back(trackster); }
// convenience method to return the ID probability for a certain particle type
inline float id_probability(ParticleType type) const {
// probabilities are stored in the same order as defined in the ParticleType enum
return idProbabilities_[(int)type];
}

void setIdProbabilities(const std::array<float, 8>& idProbs) { idProbabilities_ = idProbs; }

private:
float time_;
float timeError_;
edm::Ptr<reco::Track> trackPtr_;

float rawEnergy_;

// vector of Ptr so Tracksters can come from different collections
// and there can be derived classes
std::vector<edm::Ptr<ticl::Trackster> > tracksters_;

// Since it contains multiple tracksters, duplicate the probability interface
std::array<float, 8> idProbabilities_;
};
#endif
1 change: 1 addition & 0 deletions DataFormats/HGCalReco/src/classes.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
#include "DataFormats/HGCalReco/interface/Trackster.h"
#include "DataFormats/HGCalReco/interface/TICLLayerTile.h"
#include "DataFormats/HGCalReco/interface/TICLSeedingRegion.h"
#include "DataFormats/HGCalReco/interface/TICLCandidate.h"
#include "DataFormats/Common/interface/Wrapper.h"
7 changes: 7 additions & 0 deletions DataFormats/HGCalReco/src/classes_def.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,11 @@
<class name="std::vector<TICLSeedingRegion>" />
<class name="edm::Wrapper<TICLSeedingRegion>" />
<class name="edm::Wrapper<std::vector<TICLSeedingRegion> >" />

<class name="TICLCandidate" ClassVersion="3">
<version ClassVersion="3" checksum="450468662"/>
</class>
<class name="std::vector<TICLCandidate>" />
<class name="edm::Wrapper<TICLCandidate>" />
<class name="edm::Wrapper<std::vector<TICLCandidate> >" />
</lcgdict>
7 changes: 7 additions & 0 deletions RecoHGCal/TICL/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<use name="DataFormats/Candidate"/>
<use name="DataFormats/HGCalReco"/>
<use name="DataFormats/VertexReco"/>
<use name="FWCore/PluginManager"/>
<export>
<lib name="1"/>
</export>
29 changes: 29 additions & 0 deletions RecoHGCal/TICL/interface/TracksterMomentumPluginBase.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef RecoHGCal_TICL_TracksterMomentumPluginBase_H__
#define RecoHGCal_TICL_TracksterMomentumPluginBase_H__

#include "DataFormats/Candidate/interface/Candidate.h"
#include "DataFormats/VertexReco/interface/Vertex.h"
#include "DataFormats/CaloRecHit/interface/CaloCluster.h"
#include "DataFormats/HGCalReco/interface/Trackster.h"
#include "DataFormats/HGCalReco/interface/TICLCandidate.h"
#include "FWCore/Framework/interface/ConsumesCollector.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/PluginManager/interface/PluginFactory.h"

namespace ticl {
class TracksterMomentumPluginBase {
public:
TracksterMomentumPluginBase(const edm::ParameterSet&, edm::ConsumesCollector&& iC) {}
typedef reco::Candidate::LorentzVector LorentzVector;
virtual ~TracksterMomentumPluginBase() {}
virtual void setP4(const std::vector<const Trackster*>& tracksters,
std::vector<TICLCandidate>& ticl_cands,
edm::Event& event) const = 0;
};
} // namespace ticl

typedef edmplugin::PluginFactory<ticl::TracksterMomentumPluginBase*(const edm::ParameterSet&,
edm::ConsumesCollector&& iC)>
TracksterMomentumPluginFactory;

#endif
30 changes: 30 additions & 0 deletions RecoHGCal/TICL/interface/TracksterTrackPluginBase.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Base class for plugins that set the track reference(s) in the Trackster -> TICLCandidate conversion.

#ifndef RecoHGCal_TICL_TracksterTrackPluginBase_H__
#define RecoHGCal_TICL_TracksterTrackPluginBase_H__

#include "DataFormats/Candidate/interface/Candidate.h"
#include "DataFormats/VertexReco/interface/Vertex.h"
#include "DataFormats/CaloRecHit/interface/CaloCluster.h"
#include "DataFormats/HGCalReco/interface/Trackster.h"
#include "DataFormats/HGCalReco/interface/TICLCandidate.h"
#include "FWCore/Framework/interface/ConsumesCollector.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/PluginManager/interface/PluginFactory.h"

namespace ticl {
class TracksterTrackPluginBase {
public:
TracksterTrackPluginBase(const edm::ParameterSet&, edm::ConsumesCollector&& iC) {}
typedef reco::Candidate::LorentzVector LorentzVector;
virtual ~TracksterTrackPluginBase() {}
virtual void setTrack(const std::vector<const Trackster*>& tracksters,
std::vector<TICLCandidate>& ticl_cands,
edm::Event& event) const = 0;
};
} // namespace ticl

typedef edmplugin::PluginFactory<ticl::TracksterTrackPluginBase*(const edm::ParameterSet&, edm::ConsumesCollector&& iC)>
TracksterTrackPluginFactory;

#endif
4 changes: 4 additions & 0 deletions RecoHGCal/TICL/plugins/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<use name="FWCore/Framework"/>
<use name="FWCore/ParameterSet"/>
<use name="FWCore/PluginManager"/>
<use name="DataFormats/Candidate"/>
<use name="DataFormats/CaloRecHit"/>
<use name="DataFormats/ParticleFlowCandidate"/>
<use name="DataFormats/HGCDigi"/>
<use name="DataFormats/HGCRecHit"/>
<use name="DataFormats/HGCalReco"/>
Expand All @@ -15,6 +18,7 @@
<use name="TrackingTools/Records"/>
<use name="Geometry/Records"/>
<use name="PhysicsTools/TensorFlow"/>
<use name="RecoHGCal/TICL"/>

<library file="*.cc" name="RecoHGCalTICLPlugins">
<flags EDM_PLUGIN="1"/>
Expand Down
File renamed without changes.
91 changes: 91 additions & 0 deletions RecoHGCal/TICL/plugins/PFTICLProducer.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// This producer converts a list of TICLCandidates to a list of PFCandidates.

#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/global/EDProducer.h"

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"

#include "DataFormats/Common/interface/View.h"

#include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"
#include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"

#include "DataFormats/HGCalReco/interface/TICLCandidate.h"

class PFTICLProducer : public edm::global::EDProducer<> {
public:
PFTICLProducer(const edm::ParameterSet&);
~PFTICLProducer() override {}

static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);

void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;

private:
// inputs
const edm::EDGetTokenT<edm::View<TICLCandidate>> ticl_candidates_;
};

DEFINE_FWK_MODULE(PFTICLProducer);

PFTICLProducer::PFTICLProducer(const edm::ParameterSet& conf)
: ticl_candidates_(consumes<edm::View<TICLCandidate>>(conf.getParameter<edm::InputTag>("ticlCandidateSrc"))) {
produces<reco::PFCandidateCollection>();
}

void PFTICLProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
desc.add<edm::InputTag>("ticlCandidateSrc", edm::InputTag("ticlCandidateFromTrackstersProducer"));
descriptions.add("pfTICLProducer", desc);
}

void PFTICLProducer::produce(edm::StreamID, edm::Event& evt, const edm::EventSetup& es) const {
//get TICLCandidates
edm::Handle<edm::View<TICLCandidate>> ticl_cand_h;
evt.getByToken(ticl_candidates_, ticl_cand_h);
const auto ticl_candidates = *ticl_cand_h;

auto candidates = std::make_unique<reco::PFCandidateCollection>();

for (const auto& ticl_cand : ticl_candidates) {
const auto abs_pdg_id = std::abs(ticl_cand.pdgId());
const auto charge = ticl_cand.charge();
const auto& four_mom = ticl_cand.p4();

reco::PFCandidate::ParticleType part_type;
switch (abs_pdg_id) {
case 11:
part_type = reco::PFCandidate::e;
break;
case 13:
part_type = reco::PFCandidate::mu;
break;
case 22:
part_type = reco::PFCandidate::gamma;
break;
case 130:
part_type = reco::PFCandidate::h0;
break;
case 211:
part_type = reco::PFCandidate::h;
break;
// default also handles neutral pions (111) for the time being (not yet foreseen in PFCandidate)
default:
part_type = reco::PFCandidate::X;
}

candidates->emplace_back(charge, four_mom, part_type);

auto& candidate = candidates->back();
if (candidate.charge()) { // otherwise PFCandidate throws
// Construct edm::Ref from edm::Ptr. As of now, assumes type to be reco::Track. To be extended (either via
// dynamic type checking or configuration) if additional track types are needed.
reco::TrackRef ref(ticl_cand.trackPtr().id(), int(ticl_cand.trackPtr().key()), &evt.productGetter());
candidate.setTrackRef(ref);
}
candidate.setTime(ticl_cand.time(), ticl_cand.timeError());
}

evt.put(std::move(candidates));
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "DataFormats/HGCalReco/interface/TICLSeedingRegion.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "DataFormats/Common/interface/ValueMap.h"
#include "RecoHGCal/TICL/interface/GlobalCache.h"
#include "RecoHGCal/TICL/plugins/GlobalCache.h"

namespace edm {
class Event;
Expand Down
2 changes: 1 addition & 1 deletion RecoHGCal/TICL/plugins/PatternRecognitionbyCA.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#ifndef __RecoHGCal_TICL_PRbyCA_H__
#define __RecoHGCal_TICL_PRbyCA_H__
#include <memory> // unique_ptr
#include "RecoHGCal/TICL/interface/PatternRecognitionAlgoBase.h"
#include "RecoHGCal/TICL/plugins/PatternRecognitionAlgoBase.h"
#include "RecoLocalCalo/HGCalRecAlgos/interface/RecHitTools.h"
#include "PhysicsTools/TensorFlow/interface/TensorFlow.h"

Expand Down
2 changes: 1 addition & 1 deletion RecoHGCal/TICL/plugins/PatternRecognitionbyMultiClusters.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#ifndef __RecoHGCal_TICL_PRbyMultiClusters_H__
#define __RecoHGCal_TICL_PRbyMultiClusters_H__
#include "RecoHGCal/TICL/interface/PatternRecognitionAlgoBase.h"
#include "RecoHGCal/TICL/plugins/PatternRecognitionAlgoBase.h"

#include <iostream>

Expand Down
2 changes: 1 addition & 1 deletion RecoHGCal/TICL/plugins/SeedingRegionByTracks.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#define RecoHGCal_TICL_SeedingRegionByTracks_h
#include <memory> // unique_ptr
#include <string>
#include "RecoHGCal/TICL/interface/SeedingRegionAlgoBase.h"
#include "RecoHGCal/TICL/plugins/SeedingRegionAlgoBase.h"

#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/Event.h"
Expand Down
2 changes: 1 addition & 1 deletion RecoHGCal/TICL/plugins/SeedingRegionGlobal.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#define __RecoHGCal_TICL_SeedingRegionGlobal_H__
#include <memory> // unique_ptr
#include <string>
#include "RecoHGCal/TICL/interface/SeedingRegionAlgoBase.h"
#include "RecoHGCal/TICL/plugins/SeedingRegionAlgoBase.h"

#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/Event.h"
Expand Down

0 comments on commit 5a7a185

Please sign in to comment.