Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean-up of L1 Tracker cluster, stub & track truth-reco association code #32549

Merged
merged 6 commits into from Jan 12, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 22 additions & 6 deletions DataFormats/L1TrackTrigger/interface/TTTypes.h
Expand Up @@ -19,15 +19,31 @@
#include "DataFormats/L1TrackTrigger/interface/TTTrack.h"
#include "DataFormats/L1TrackTrigger/interface/TTTrack_TrackWord.h"

/// The reference types
typedef edm::Ref<edm::DetSetVector<Phase2TrackerDigi>, Phase2TrackerDigi> Ref_Phase2TrackerDigi_;
/// Templated aliases
template <typename T>
using TTClusterDetSetVecT = edmNew::DetSetVector<TTCluster<T> >;
template <typename T>
using TTStubDetSetVecT = edmNew::DetSetVector<TTStub<T> >;

template <typename T>
using TTClusterRefT = edm::Ref<TTClusterDetSetVecT<T>, TTCluster<T> >;
template <typename T>
using TTStubRefT = edm::Ref<TTStubDetSetVecT<T>, TTStub<T> >;

typedef edmNew::DetSetVector<TTCluster<Ref_Phase2TrackerDigi_> > TTClusterDetSetVec;
typedef edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_> > TTStubDetSetVec;
template <typename T>
using TTTrackPtrT = edm::Ptr<TTTrack<T> >;

typedef edm::Ref<TTStubDetSetVec, TTStub<Ref_Phase2TrackerDigi_> > TTStubRef;
typedef edm::Ref<TTClusterDetSetVec, TTCluster<Ref_Phase2TrackerDigi_> > TTClusterRef;
/// Specialized aliases
typedef edm::Ref<edm::DetSetVector<Phase2TrackerDigi>, Phase2TrackerDigi> Ref_Phase2TrackerDigi_;

typedef edmNew::DetSet<TTStub<Ref_Phase2TrackerDigi_> > TTStubDetSet;

typedef TTClusterDetSetVecT<Ref_Phase2TrackerDigi_> TTClusterDetSetVec;
typedef TTStubDetSetVecT<Ref_Phase2TrackerDigi_> TTStubDetSetVec;

typedef TTClusterRefT<Ref_Phase2TrackerDigi_> TTClusterRef;
typedef TTStubRefT<Ref_Phase2TrackerDigi_> TTStubRef;

typedef TTTrackPtrT<Ref_Phase2TrackerDigi_> TTTrackPtr;

#endif
@@ -1,12 +1,14 @@
#ifndef TrackingAnalysis_TrackingParticleFwd_h
#define TrackingAnalysis_TrackingParticleFwd_h
#include <vector>
#include "DataFormats/Common/interface/Ptr.h"
#include "DataFormats/Common/interface/Ref.h"
#include "DataFormats/Common/interface/RefVector.h"
#include "DataFormats/Common/interface/RefProd.h"

class TrackingParticle;
typedef std::vector<TrackingParticle> TrackingParticleCollection;
typedef edm::Ptr<TrackingParticle> TrackingParticlePtr;
typedef edm::Ref<TrackingParticleCollection> TrackingParticleRef;
typedef edm::RefVector<TrackingParticleCollection> TrackingParticleRefVector;
typedef edm::RefProd<TrackingParticleCollection> TrackingParticleRefProd;
Expand Down
130 changes: 65 additions & 65 deletions SimTracker/TrackTriggerAssociation/interface/TTClusterAssociationMap.h
@@ -1,20 +1,25 @@
/*! \class TTClusterAssociationMap
* \brief Class to store the MC truth of L1 Track Trigger clusters
* \details After moving from SimDataFormats to DataFormats,
* the template structure of the class was maintained
* in order to accomodate any types other than PixelDigis
* in case there is such a need in the future.
* \brief Stores association of Truth Particles (TP) to L1 Track-Trigger Clusters
*
* \details Contains two maps. One associates each cluster to a vector
* of all TPs that made its hits. The other associates each TP
* to a vector of all clusters it contributed to.
*
* (The template structure is used to accomodate types
* other than PixelDigis, in case they are needed in future).
*
* \author Nicola Pozzobon
* \date 2013, Jul 19
*
* (tidy up: Ian Tomalin, 2020)
*/

#ifndef L1_TRACK_TRIGGER_CLUSTER_ASSOCIATION_FORMAT_H
#define L1_TRACK_TRIGGER_CLUSTER_ASSOCIATION_FORMAT_H

#include "DataFormats/Common/interface/Ref.h"
#include "DataFormats/Common/interface/Ptr.h"
#include "DataFormats/L1TrackTrigger/interface/TTTypes.h"
#include "SimDataFormats/TrackingAnalysis/interface/TrackingParticleFwd.h"
#include "DataFormats/Common/interface/DetSet.h"
#include "DataFormats/Common/interface/DetSetVector.h"
#include "DataFormats/Common/interface/DetSetVectorNew.h"
Expand All @@ -29,6 +34,12 @@
#include "SimDataFormats/EncodedEventId/interface/EncodedEventId.h"
#include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h"

// Templated aliases
template <typename T>
using MapClusToVecTP = std::map<TTClusterRefT<T>, std::vector<TrackingParticlePtr>>;
template <typename T>
using MapTPToVecClus = std::map<TrackingParticlePtr, std::vector<TTClusterRefT<T>>>;

template <typename T>
class TTClusterAssociationMap {
public:
Expand All @@ -38,48 +49,38 @@ class TTClusterAssociationMap {
/// Destructor
~TTClusterAssociationMap();

/// Data members: getABC( ... )
/// Helper methods: findABC( ... )
/// Get/set cluster <-> truth association maps

/// Maps
std::map<edm::Ref<edmNew::DetSetVector<TTCluster<T> >, TTCluster<T> >, std::vector<edm::Ptr<TrackingParticle> > >
getTTClusterToTrackingParticlesMap() const {
return clusterToTrackingParticleVectorMap;
}
std::map<edm::Ptr<TrackingParticle>, std::vector<edm::Ref<edmNew::DetSetVector<TTCluster<T> >, TTCluster<T> > > >
getTrackingParticleToTTClustersMap() const {
return trackingParticleToClusterVectorMap;
}
const MapClusToVecTP<T>& getTTClusterToTrackingParticlesMap() const { return clusterToTrackingParticleVectorMap; }
const MapTPToVecClus<T>& getTrackingParticleToTTClustersMap() const { return trackingParticleToClusterVectorMap; }

void setTTClusterToTrackingParticlesMap(std::map<edm::Ref<edmNew::DetSetVector<TTCluster<T> >, TTCluster<T> >,
std::vector<edm::Ptr<TrackingParticle> > > aMap) {
clusterToTrackingParticleVectorMap = aMap;
}
void setTrackingParticleToTTClustersMap(
std::map<edm::Ptr<TrackingParticle>, std::vector<edm::Ref<edmNew::DetSetVector<TTCluster<T> >, TTCluster<T> > > >
aMap) {
trackingParticleToClusterVectorMap = aMap;
}
void setTTClusterToTrackingParticlesMap(const MapClusToVecTP<T>& aMap) { clusterToTrackingParticleVectorMap = aMap; }
void setTrackingParticleToTTClustersMap(const MapTPToVecClus<T>& aMap) { trackingParticleToClusterVectorMap = aMap; }

/// Operations
std::vector<edm::Ptr<TrackingParticle> > findTrackingParticlePtrs(
edm::Ref<edmNew::DetSetVector<TTCluster<T> >, TTCluster<T> > aCluster) const;
edm::Ptr<TrackingParticle> findTrackingParticlePtr(
edm::Ref<edmNew::DetSetVector<TTCluster<T> >, TTCluster<T> > aCluster) const;
std::vector<edm::Ref<edmNew::DetSetVector<TTCluster<T> >, TTCluster<T> > > findTTClusterRefs(
edm::Ptr<TrackingParticle> aTrackingParticle) const;
/// Get all TPs associated to a cluster
std::vector<TrackingParticlePtr> findTrackingParticlePtrs(TTClusterRefT<T> aCluster) const;
/// Get main TP associated to a cluster. (Non-NULL if isGenuine() below is true).
TrackingParticlePtr findTrackingParticlePtr(TTClusterRefT<T> aCluster) const;

/// MC Truth methods
bool isGenuine(edm::Ref<edmNew::DetSetVector<TTCluster<T> >, TTCluster<T> > aCluster) const;
bool isCombinatoric(edm::Ref<edmNew::DetSetVector<TTCluster<T> >, TTCluster<T> > aCluster) const;
bool isUnknown(edm::Ref<edmNew::DetSetVector<TTCluster<T> >, TTCluster<T> > aCluster) const;
// Get all clusters associated to TP.
std::vector<TTClusterRefT<T>> findTTClusterRefs(TrackingParticlePtr aTrackingParticle) const;

///--- Get quality of L1 cluster based on truth info.
/// (exactly 1 of following 3 functions is always true)

/// Cluster "genuine": i.e. cluster associated to exactly 1 TP.
/// (If other TPs are associated, but have in total < 1% of Pt of main TP,
/// or if they are null, then they are neglected here).
bool isGenuine(TTClusterRefT<T> aCluster) const;
/// Cluster "unknown": i.e. not associated with any TP.
bool isUnknown(TTClusterRefT<T> aCluster) const;
/// Cluster is not "genuine" or "unknown".
bool isCombinatoric(TTClusterRefT<T> aCluster) const;

private:
/// Data members
std::map<edm::Ref<edmNew::DetSetVector<TTCluster<T> >, TTCluster<T> >, std::vector<edm::Ptr<TrackingParticle> > >
clusterToTrackingParticleVectorMap;
std::map<edm::Ptr<TrackingParticle>, std::vector<edm::Ref<edmNew::DetSetVector<TTCluster<T> >, TTCluster<T> > > >
trackingParticleToClusterVectorMap;
MapClusToVecTP<T> clusterToTrackingParticleVectorMap;
tomalin marked this conversation as resolved.
Show resolved Hide resolved
MapTPToVecClus<T> trackingParticleToClusterVectorMap;

int nclus;

Expand Down Expand Up @@ -108,25 +109,24 @@ TTClusterAssociationMap<T>::~TTClusterAssociationMap() {}

/// Operations
template <typename T>
std::vector<edm::Ref<edmNew::DetSetVector<TTCluster<T> >, TTCluster<T> > >
TTClusterAssociationMap<T>::findTTClusterRefs(edm::Ptr<TrackingParticle> aTrackingParticle) const {
std::vector<TTClusterRefT<T>> TTClusterAssociationMap<T>::findTTClusterRefs(
TrackingParticlePtr aTrackingParticle) const {
if (trackingParticleToClusterVectorMap.find(aTrackingParticle) != trackingParticleToClusterVectorMap.end()) {
return trackingParticleToClusterVectorMap.find(aTrackingParticle)->second;
}

std::vector<edm::Ref<edmNew::DetSetVector<TTCluster<T> >, TTCluster<T> > > tempVector;
std::vector<TTClusterRefT<T>> tempVector;
tempVector.clear();
return tempVector;
}

template <typename T>
std::vector<edm::Ptr<TrackingParticle> > TTClusterAssociationMap<T>::findTrackingParticlePtrs(
edm::Ref<edmNew::DetSetVector<TTCluster<T> >, TTCluster<T> > aCluster) const {
std::vector<TrackingParticlePtr> TTClusterAssociationMap<T>::findTrackingParticlePtrs(TTClusterRefT<T> aCluster) const {
if (clusterToTrackingParticleVectorMap.find(aCluster) != clusterToTrackingParticleVectorMap.end()) {
return clusterToTrackingParticleVectorMap.find(aCluster)->second;
}

std::vector<edm::Ptr<TrackingParticle> > tempVector;
std::vector<TrackingParticlePtr> tempVector;
tempVector.clear();
return tempVector;
}
Expand All @@ -137,26 +137,28 @@ std::vector<edm::Ptr<TrackingParticle> > TTClusterAssociationMap<T>::findTrackin
/// N = number of NULL TP pointers
/// D = number of GOOD TP pointers different from each other
///
/// OLD DEFINITION
///
/// N / D--> | 0 | 1 | >1
/// ----------------------
/// 0 | U | G | C
/// ----------------------
/// >0 | U | C | C
///

/// NEW SV 060617
/// NEW DEFINITION SV 060617
///
/// N / D--> | 0 | 1 | >1 (with 1 TP getting >99 of the total pT) | >1
/// N / D--> | 0 | 1 | >1 (with 1 TP getting >99% of the total pT) | >1
/// -------------------------------------------------------------------
/// 0 | U | G | G | C
/// 0 | U | G | G | C
/// -------------------------------------------------------------------
/// >0 | U | G | G | C
/// >0 | U | G | G | C
///

template <typename T>
bool TTClusterAssociationMap<T>::isGenuine(edm::Ref<edmNew::DetSetVector<TTCluster<T> >, TTCluster<T> > aCluster) const {
bool TTClusterAssociationMap<T>::isGenuine(TTClusterRefT<T> aCluster) const {
/// Get the TrackingParticles
std::vector<edm::Ptr<TrackingParticle> > theseTrackingParticles = this->findTrackingParticlePtrs(aCluster);
std::vector<TrackingParticlePtr> theseTrackingParticles = this->findTrackingParticlePtrs(aCluster);

/// If the vector is empty, then the cluster is UNKNOWN
if (theseTrackingParticles.empty())
Expand All @@ -174,7 +176,7 @@ bool TTClusterAssociationMap<T>::isGenuine(edm::Ref<edmNew::DetSetVector<TTClust
/// Loop over the TrackingParticles
for (const auto& tp : theseTrackingParticles) {
/// Get the TrackingParticle
const edm::Ptr<TrackingParticle>& curTP = tp;
const TrackingParticlePtr& curTP = tp;

/// Count the NULL TrackingParticles
if (curTP.isNull()) {
Expand All @@ -191,7 +193,7 @@ bool TTClusterAssociationMap<T>::isGenuine(edm::Ref<edmNew::DetSetVector<TTClust

for (unsigned int itp = 0; itp < theseTrackingParticles.size(); itp++) {
/// Get the TrackingParticle
edm::Ptr<TrackingParticle> curTP = theseTrackingParticles.at(itp);
TrackingParticlePtr curTP = theseTrackingParticles.at(itp);

/// Count the NULL TrackingParticles
if (tp_mom.at(itp) <= 0.01 * tp_tot) {
Expand All @@ -212,9 +214,9 @@ bool TTClusterAssociationMap<T>::isGenuine(edm::Ref<edmNew::DetSetVector<TTClust
}

template <typename T>
bool TTClusterAssociationMap<T>::isUnknown(edm::Ref<edmNew::DetSetVector<TTCluster<T> >, TTCluster<T> > aCluster) const {
bool TTClusterAssociationMap<T>::isUnknown(TTClusterRefT<T> aCluster) const {
/// Get the TrackingParticles
std::vector<edm::Ptr<TrackingParticle> > theseTrackingParticles = this->findTrackingParticlePtrs(aCluster);
std::vector<TrackingParticlePtr> theseTrackingParticles = this->findTrackingParticlePtrs(aCluster);

/// If the vector is empty, then the cluster is UNKNOWN
if (theseTrackingParticles.empty())
Expand All @@ -227,7 +229,7 @@ bool TTClusterAssociationMap<T>::isUnknown(edm::Ref<edmNew::DetSetVector<TTClust
/// Loop over the TrackingParticles
for (unsigned int itp = 0; itp < theseTrackingParticles.size(); itp++) {
/// Get the TrackingParticle
edm::Ptr<TrackingParticle> curTP = theseTrackingParticles.at(itp);
TrackingParticlePtr curTP = theseTrackingParticles.at(itp);

/// Count the non-NULL TrackingParticles
if (!curTP.isNull()) {
Expand All @@ -247,10 +249,9 @@ bool TTClusterAssociationMap<T>::isUnknown(edm::Ref<edmNew::DetSetVector<TTClust
}

template <typename T>
bool TTClusterAssociationMap<T>::isCombinatoric(
edm::Ref<edmNew::DetSetVector<TTCluster<T> >, TTCluster<T> > aCluster) const {
bool TTClusterAssociationMap<T>::isCombinatoric(TTClusterRefT<T> aCluster) const {
/// Get the TrackingParticles
std::vector<edm::Ptr<TrackingParticle> > theseTrackingParticles = this->findTrackingParticlePtrs(aCluster);
std::vector<TrackingParticlePtr> theseTrackingParticles = this->findTrackingParticlePtrs(aCluster);

/// If the vector is empty, then the cluster is UNKNOWN
if (theseTrackingParticles.empty())
Expand All @@ -272,7 +273,7 @@ bool TTClusterAssociationMap<T>::isCombinatoric(
/// Loop over the TrackingParticles
for (unsigned int itp = 0; itp < theseTrackingParticles.size(); itp++) {
/// Get the TrackingParticle
edm::Ptr<TrackingParticle> curTP = theseTrackingParticles.at(itp);
TrackingParticlePtr curTP = theseTrackingParticles.at(itp);

/// Count the NULL TrackingParticles
if (curTP.isNull()) {
Expand All @@ -296,13 +297,12 @@ bool TTClusterAssociationMap<T>::isCombinatoric(
}

template <typename T>
edm::Ptr<TrackingParticle> TTClusterAssociationMap<T>::findTrackingParticlePtr(
edm::Ref<edmNew::DetSetVector<TTCluster<T> >, TTCluster<T> > aCluster) const {
TrackingParticlePtr TTClusterAssociationMap<T>::findTrackingParticlePtr(TTClusterRefT<T> aCluster) const {
if (this->isGenuine(aCluster)) {
return this->findTrackingParticlePtrs(aCluster).at(0);
}

edm::Ptr<TrackingParticle>* temp = new edm::Ptr<TrackingParticle>();
TrackingParticlePtr* temp = new TrackingParticlePtr();
tomalin marked this conversation as resolved.
Show resolved Hide resolved
return *temp;
}

Expand Down