131 std::vector<edm::Handle<reco::TrackToTrackingParticleAssociator>>
associators;
133 associators.emplace_back();
134 auto& back = associators.back();
142 std::unordered_set<unsigned> PFTrackToGeneralTrack;
143 for (
unsigned i = 0;
i < PFTrackCollection.
size(); ++
i) {
144 const auto ptr = PFTrackCollection.
ptrAt(
i);
145 PFTrackToGeneralTrack.insert(ptr->trackRef().key());
155 std::unordered_set<unsigned> MuonTrackToGeneralTrack;
156 for (
auto const&
mu : *muons.
product()) {
159 MuonTrackToGeneralTrack.insert(muTrkRef.
key());
187 const std::vector<reco::PFCluster>& SimClusters = *SimClustersH;
189 std::unordered_map<uint64_t, size_t> hashToSimCluster;
191 for (
unsigned i = 0;
i < SimClustersTruth.size(); ++
i) {
192 const auto& simTruth = SimClustersTruth[
i];
193 hashToSimCluster[hashSimInfo(simTruth)] =
i;
197 std::vector<reco::RecoToSimCollection> associatedTracks, associatedTracksGsf;
199 associatedTracks.emplace_back(
associator->associateRecoToSim(TrackCollectionH, TPCollectionH));
205 auto superclusters = std::make_unique<reco::SuperClusterCollection>();
206 auto blocks = std::make_unique<reco::PFBlockCollection>();
207 std::unordered_map<size_t, size_t> simCluster2Block;
208 std::unordered_map<size_t, size_t> simCluster2BlockIndex;
209 std::unordered_multimap<size_t, size_t> caloParticle2SimCluster;
210 std::vector<int> caloParticle2SuperCluster;
211 for (
unsigned icp = 0; icp < CaloParticles.size(); ++icp) {
212 blocks->emplace_back();
213 auto&
block = blocks->back();
214 const auto& simclusters = CaloParticles[icp].simClusters();
217 std::vector<size_t> good_simclusters;
218 for (
unsigned isc = 0; isc < simclusters.size(); ++isc) {
219 auto simc = simclusters[isc];
224 good_simclusters.push_back(isc);
225 etot += clusterRef->energy();
226 pttot += clusterRef->pt();
228 block.addElement(bec.get());
229 simCluster2Block[simc.key()] = icp;
230 simCluster2BlockIndex[simc.key()] = bec->index();
231 caloParticle2SimCluster.emplace(CaloParticles[icp].g4Tracks()[0].trackId(), simc.key());
237 caloParticle2SuperCluster.push_back(-1);
239 caloParticle2SuperCluster[icp] = superclusters->size();
244 for (
auto idx : good_simclusters) {
247 if (seed.
isNull() || seed->energy() < ptr->energy()) {
249 seedpos = ptr->position();
252 superclusters->emplace_back(etot, seedpos, seed, clusters);
257 auto superClustersHandle = evt.
put(
std::move(superclusters),
"perfect");
260 std::vector<bool> usedTrack(TrackCollection.
size(),
false),
262 usedSimCluster(SimClusters.size(),
false);
264 auto candidates = std::make_unique<reco::PFCandidateCollection>();
266 for (
unsigned itk = 0; itk < TrackCollection.
size(); ++itk) {
267 auto tkRef = TrackCollection.
refAt(itk);
269 if (PFTrackToGeneralTrack.count(itk) == 0)
277 if (assoc_tps == associatedTracks.back().end())
280 const auto&
matches = assoc_tps->val;
283 const auto charge = tkRef->charge();
284 const auto three_mom = tkRef->momentum();
285 constexpr double mpion2 = 0.13957 * 0.13957;
302 candidates->emplace_back(charge, trk_p4, part_type);
303 auto& candidate = candidates->back();
308 candidate.setTime((*trackTimeH)[tkRef], (*trackTimeErrH)[tkRef]);
313 if (hashToSimCluster.count(hash)) {
314 auto simcHash = hashToSimCluster[
hash];
316 if (!usedSimCluster[simcHash]) {
317 if (simCluster2Block.count(simcHash) && simCluster2BlockIndex.count(simcHash)) {
318 size_t block = simCluster2Block.find(simcHash)->second;
319 size_t blockIdx = simCluster2BlockIndex.find(simcHash)->second;
321 candidate.addElementInBlock(blockRef, blockIdx);
322 usedSimCluster[simcHash] =
true;
325 if (absPdgId == 11) {
326 if (simCluster2Block.count(simcHash)) {
327 auto block_index = simCluster2Block.find(simcHash)->second;
328 auto supercluster_index = caloParticle2SuperCluster[block_index];
329 if (supercluster_index != -1) {
331 for (
const auto&
elem : blockRef->elements()) {
332 const auto& ref =
elem.clusterRef();
333 if (!usedSimCluster[ref.key()]) {
334 candidate.addElementInBlock(blockRef,
elem.index());
335 usedSimCluster[ref.key()] =
true;
349 if (caloParticle2SimCluster.count(
match.first->g4Tracks()[0].trackId())) {
350 auto range = caloParticle2SimCluster.equal_range(
match.first->g4Tracks()[0].trackId());
351 for (
auto it =
range.first; it !=
range.second; ++it) {
352 if (!usedSimCluster[it->second]) {
353 usedSimCluster[it->second] =
true;
354 if (simCluster2Block.find(it->second) != simCluster2Block.end()) {
355 size_t block = simCluster2Block.find(it->second)->second;
356 size_t blockIdx = simCluster2BlockIndex.find(it->second)->second;
358 candidate.addElementInBlock(blockRef, blockIdx);
364 usedTrack[tkRef.key()] =
true;
366 if (MuonTrackToGeneralTrack.count(itk) || absPdgId == 13)
367 candidates->pop_back();
372 const auto& theblocks = *blocksHandle;
373 for (
unsigned ibl = 0; ibl < theblocks.size(); ++ibl) {
375 const auto&
elements = theblocks[ibl].elements();
377 const auto& ref =
elem.clusterRef();
378 const auto& simtruth = SimClustersTruth[ref.key()];
380 if (!usedSimCluster[ref.key()]) {
381 auto absPdgId =
std::abs(simtruth.pdgId());
390 const auto three_mom = (ref->position() -
math::XYZPoint(0, 0, 0)).
unit() * ref->correctedEnergy();
392 candidates->emplace_back(0, clu_p4, part_type);
393 auto& candidate = candidates->back();
394 candidate.addElementInBlock(blref,
elem.index());
395 candidate.setTime(ref->time(), ref->timeError());
const edm::EDGetTokenT< edm::ValueMap< float > > srcTrackTimeError_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
ParticleType
particle types
bool isNonnull() const
Checks for non-null.
friend struct const_iterator
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Ptr< value_type > ptrAt(size_type i) const
void push_back(Ptr< T > const &iPtr)
std::vector< Track > TrackCollection
collection of Tracks
key_type key() const
Accessor for product key.
const double neutralHADThreshold_
RefToBase< value_type > refAt(size_type i) const
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
const edm::EDGetTokenT< CaloParticleCollection > caloParticles_
const std::vector< edm::EDGetTokenT< reco::TrackToTrackingParticleAssociator > > associators_
bool isNull() const
Checks for null.
Abs< T >::type abs(const T &t)
const edm::EDGetTokenT< edm::View< reco::Track > > tracks_
const edm::EDGetTokenT< edm::ValueMap< float > > srcGsfTrackTime_
const edm::EDGetTokenT< edm::View< reco::PFRecTrack > > pfRecTracks_
const edm::EDGetTokenT< SimClusterCollection > simClustersTruth_
def elem(elemtype, innerHTML='', html_class='', kwargs)
const edm::EDGetTokenT< TrackingParticleCollection > trackingParticles_
T const * product() const
unsigned long long uint64_t
XYZPointD XYZPoint
point in space with cartesian internal representation
const double superClusterThreshold_
const edm::EDGetTokenT< reco::MuonCollection > muons_
const edm::EDGetTokenT< edm::ValueMap< float > > srcTrackTime_
std::vector< CaloParticle > CaloParticleCollection
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< SimCluster > SimClusterCollection
const edm::EDGetTokenT< std::vector< reco::PFCluster > > simClusters_
Basic3DVector unit() const