5 #include "CLHEP/Units/SystemOfUnits.h" 42 #include <unordered_map> 72 const std::vector<edm::EDGetTokenT<reco::TrackToTrackingParticleAssociator>>
associators_;
83 desc.add<std::vector<edm::InputTag>>(
"associators",
85 {
"quickTrackAssociatorByHits"},
87 desc.add<
edm::InputTag>(
"pfRecTrackSrc", {
"hgcalTrackCollection",
"TracksInHGCal"});
89 desc.add<
double>(
"neutralEMThreshold", 0.25);
91 desc.add<
double>(
"superClusterThreshold", 4.0);
94 desc.add<
double>(
"neutralHADThreshold", 0.25);
98 desc.add<
bool>(
"useTiming",
false);
99 desc.add<
bool>(
"useTimingQuality",
false);
103 desc.add<
double>(
"timingQualityThreshold", 0);
113 template <
typename T>
114 uint64_t hashSimInfo(
const T& simTruth,
size_t i = 0) {
116 uint64_t trackid = simTruth.g4Tracks()[
i].trackId();
117 return ((
evtid << 3) + 23401923) ^ trackid;
122 : superClusterThreshold_(conf.getParameter<double>(
"superClusterThreshold")),
123 neutralEMThreshold_(conf.getParameter<double>(
"neutralEMThreshold")),
124 neutralHADThreshold_(conf.getParameter<double>(
"neutralHADThreshold")),
125 useTiming_(conf.getParameter<
bool>(
"useTiming")),
126 useTimingQuality_(conf.getParameter<
bool>(
"useTimingQuality")),
127 timingQualityThreshold_(useTimingQuality_ ? conf.getParameter<double>(
"timingQualityThreshold") : -99.),
132 srcTrackTime_(useTiming_ ? consumes<
edm::ValueMap<
float>>(conf.getParameter<
edm::
InputTag>(
"trackTimeValueMap"))
134 srcTrackTimeError_(useTiming_
137 srcTrackTimeQuality_(useTimingQuality_
140 srcGsfTrackTime_(useTiming_
143 srcGsfTrackTimeError_(
144 useTiming_ ? consumes<
edm::ValueMap<
float>>(conf.getParameter<
edm::
InputTag>(
"gsfTrackTimeErrorMap"))
146 srcGsfTrackTimeQuality_(
147 useTimingQuality_ ? consumes<
edm::ValueMap<
float>>(conf.getParameter<
edm::
InputTag>(
"gsfTrackTimeQualityMap"))
155 [this](
const edm::
InputTag&
tag) {
return this->consumes<reco::TrackToTrackingParticleAssociator>(
tag); })) {
156 produces<reco::PFBlockCollection>();
157 produces<reco::SuperClusterCollection>(
"perfect");
158 produces<reco::PFCandidateCollection>();
163 std::vector<edm::Handle<reco::TrackToTrackingParticleAssociator>>
associators;
174 std::unordered_set<unsigned> PFTrackToGeneralTrack;
177 PFTrackToGeneralTrack.insert(ptr->trackRef().key());
187 std::unordered_set<unsigned> MuonTrackToGeneralTrack;
188 for (
auto const&
mu : *
muons.product()) {
191 MuonTrackToGeneralTrack.insert(muTrkRef.
key());
225 const std::vector<reco::PFCluster>& SimClusters = *SimClustersH;
227 std::unordered_map<uint64_t, size_t> hashToSimCluster;
229 for (
unsigned i = 0;
i < SimClustersTruth.size(); ++
i) {
230 const auto& simTruth = SimClustersTruth[
i];
231 hashToSimCluster[hashSimInfo(simTruth)] =
i;
235 std::vector<reco::RecoToSimCollection> associatedTracks, associatedTracksGsf;
237 associatedTracks.emplace_back(
associator->associateRecoToSim(TrackCollectionH, TPCollectionH));
243 auto superclusters = std::make_unique<reco::SuperClusterCollection>();
244 auto blocks = std::make_unique<reco::PFBlockCollection>();
245 std::unordered_map<size_t, size_t> simCluster2Block;
246 std::unordered_map<size_t, size_t> simCluster2BlockIndex;
247 std::unordered_multimap<size_t, size_t> caloParticle2SimCluster;
248 std::vector<int> caloParticle2SuperCluster;
249 for (
unsigned icp = 0; icp < CaloParticles.size(); ++icp) {
252 const auto&
simclusters = CaloParticles[icp].simClusters();
255 std::vector<size_t> good_simclusters;
256 for (
unsigned isc = 0; isc <
simclusters.size(); ++isc) {
262 good_simclusters.push_back(isc);
263 etot += clusterRef->energy();
264 pttot += clusterRef->pt();
266 block.addElement(bec.get());
267 simCluster2Block[simc.key()] = icp;
268 simCluster2BlockIndex[simc.key()] = bec->index();
269 caloParticle2SimCluster.emplace(CaloParticles[icp].g4Tracks()[0].trackId(), simc.key());
275 caloParticle2SuperCluster.push_back(-1);
277 caloParticle2SuperCluster[icp] = superclusters->size();
282 for (
auto idx : good_simclusters) {
290 superclusters->emplace_back(etot, seedpos,
seed,
clusters);
295 auto superClustersHandle = evt.
put(
std::move(superclusters),
"perfect");
300 usedSimCluster(SimClusters.size(),
false);
302 auto candidates = std::make_unique<reco::PFCandidateCollection>();
307 if (PFTrackToGeneralTrack.count(itk) == 0)
315 if (assoc_tps == associatedTracks.back().end())
321 const auto charge = tkRef->charge();
322 const auto three_mom = tkRef->momentum();
349 candidate.setTime((*trackTimeH)[tkRef], (*trackTimeErrH)[tkRef]);
351 candidate.setTime(0., -1.);
358 if (hashToSimCluster.count(
hash)) {
359 auto simcHash = hashToSimCluster[
hash];
361 if (!usedSimCluster[simcHash]) {
362 if (simCluster2Block.count(simcHash) && simCluster2BlockIndex.count(simcHash)) {
363 size_t block = simCluster2Block.find(simcHash)->second;
364 size_t blockIdx = simCluster2BlockIndex.find(simcHash)->second;
366 candidate.addElementInBlock(blockRef,
blockIdx);
367 usedSimCluster[simcHash] =
true;
370 if (absPdgId == 11) {
371 if (simCluster2Block.count(simcHash)) {
372 auto block_index = simCluster2Block.find(simcHash)->second;
373 auto supercluster_index = caloParticle2SuperCluster[block_index];
374 if (supercluster_index != -1) {
376 for (
const auto& elem : blockRef->elements()) {
377 const auto& ref = elem.clusterRef();
378 if (!usedSimCluster[ref.key()]) {
379 candidate.addElementInBlock(blockRef, elem.
index());
380 usedSimCluster[ref.key()] =
true;
394 if (caloParticle2SimCluster.count(
match.first->g4Tracks()[0].trackId())) {
395 auto range = caloParticle2SimCluster.equal_range(
match.first->g4Tracks()[0].trackId());
397 if (!usedSimCluster[
it->second]) {
398 usedSimCluster[
it->second] =
true;
399 if (simCluster2Block.find(
it->second) != simCluster2Block.end()) {
400 size_t block = simCluster2Block.find(
it->second)->second;
401 size_t blockIdx = simCluster2BlockIndex.find(
it->second)->second;
403 candidate.addElementInBlock(blockRef,
blockIdx);
409 usedTrack[tkRef.key()] =
true;
411 if (MuonTrackToGeneralTrack.count(itk) || absPdgId == 13)
417 const auto& theblocks = *blocksHandle;
418 for (
unsigned ibl = 0; ibl < theblocks.size(); ++ibl) {
420 const auto&
elements = theblocks[ibl].elements();
422 const auto& ref = elem.clusterRef();
423 const auto& simtruth = SimClustersTruth[ref.key()];
425 if (!usedSimCluster[ref.key()]) {
426 auto absPdgId =
std::abs(simtruth.pdgId());
435 const auto three_mom = (ref->position() -
math::XYZPoint(0, 0, 0)).
unit() * ref->correctedEnergy();
437 candidates->emplace_back(0, clu_p4, part_type);
439 candidate.addElementInBlock(blref, elem.
index());
const math::XYZPoint & position() const
cluster centroid position
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
const edm::EDGetTokenT< edm::ValueMap< float > > srcTrackTimeError_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
ParticleType
particle types
std::vector< Track > TrackCollection
collection of Tracks
bool isNonnull() const
Checks for non-null.
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
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 >
muons
the two sets of parameters below are mutually exclusive, depending if RECO or ALCARECO is used the us...
key_type key() const
Accessor for product key.
std::vector< Muon > MuonCollection
collection of Muon objects
std::tuple< layerClusterToCaloParticle, caloParticleToLayerCluster > association
const double neutralHADThreshold_
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
const edm::EDGetTokenT< edm::ValueMap< float > > srcTrackTimeQuality_
const double timingQualityThreshold_
const edm::EDGetTokenT< CaloParticleCollection > caloParticles_
const std::vector< edm::EDGetTokenT< reco::TrackToTrackingParticleAssociator > > associators_
double energy() const
cluster energy
Abs< T >::type abs(const T &t)
key
prepare the HTCondor submission files and eventually submit them
const edm::EDGetTokenT< edm::View< reco::Track > > tracks_
#define DEFINE_FWK_MODULE(type)
const edm::EDGetTokenT< edm::ValueMap< float > > srcGsfTrackTime_
Basic3DVector unit() const
const edm::EDGetTokenT< edm::View< reco::PFRecTrack > > pfRecTracks_
const edm::EDGetTokenT< SimClusterCollection > simClustersTruth_
const edm::EDGetTokenT< TrackingParticleCollection > trackingParticles_
unsigned long long uint64_t
const bool useTimingQuality_
XYZPointD XYZPoint
point in space with cartesian internal representation
SimPFProducer(const edm::ParameterSet &)
const double superClusterThreshold_
const edm::EDGetTokenT< reco::MuonCollection > muons_
const edm::EDGetTokenT< edm::ValueMap< float > > srcGsfTrackTimeQuality_
std::vector< l1t::PFTrack > PFTrackCollection
const edm::EDGetTokenT< edm::ValueMap< float > > srcTrackTime_
std::vector< CaloParticle > CaloParticleCollection
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const edm::EDGetTokenT< edm::ValueMap< float > > srcGsfTrackTimeError_
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
const double neutralEMThreshold_
std::vector< TrackingParticle > TrackingParticleCollection
std::vector< SimCluster > SimClusterCollection
const edm::EDGetTokenT< std::vector< reco::PFCluster > > simClusters_
const edm::EDGetTokenT< edm::View< reco::Track > > gsfTracks_