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 all 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
176 changes: 92 additions & 84 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,51 +49,47 @@ 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; }

/// Get all TPs associated to a cluster
const std::vector<TrackingParticlePtr>& findTrackingParticlePtrs(TTClusterRefT<T> aCluster) const;

/// Get main TP associated to a cluster. (Non-NULL if isGenuine() below is true).
const TrackingParticlePtr& findTrackingParticlePtr(TTClusterRefT<T> aCluster) const;

/// 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 clusters associated to TP.
const std::vector<TTClusterRefT<T>>& findTTClusterRefs(TrackingParticlePtr aTrackingParticle) 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 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_;
MapTPToVecClus<T> trackingParticleToClusterVectorMap_;

int nclus;

// Allow functions to return reference to null.
static const TrackingParticlePtr nullTrackingParticlePtr_;
static const std::vector<TrackingParticlePtr> nullVecTrackingParticlePtr_;
static const std::vector<TTClusterRefT<T>> nullVecClusterRef_;

}; /// Close class

/*! \brief Implementation of methods
Expand All @@ -92,13 +99,19 @@ class TTClusterAssociationMap {
* in the source file.
*/

// Static constant data members.
template <typename T>
const TrackingParticlePtr TTClusterAssociationMap<T>::nullTrackingParticlePtr_;
template <typename T>
const std::vector<TrackingParticlePtr> TTClusterAssociationMap<T>::nullVecTrackingParticlePtr_;
template <typename T>
const std::vector<TTClusterRefT<T>> TTClusterAssociationMap<T>::nullVecClusterRef_;

/// Default Constructor
/// NOTE: to be used with setSomething(...) methods
template <typename T>
TTClusterAssociationMap<T>::TTClusterAssociationMap() {
/// Set default data members
clusterToTrackingParticleVectorMap.clear();
trackingParticleToClusterVectorMap.clear();
nclus = 0;
}

Expand All @@ -108,27 +121,32 @@ 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 {
if (trackingParticleToClusterVectorMap.find(aTrackingParticle) != trackingParticleToClusterVectorMap.end()) {
return trackingParticleToClusterVectorMap.find(aTrackingParticle)->second;
const std::vector<TTClusterRefT<T>>& TTClusterAssociationMap<T>::findTTClusterRefs(
TrackingParticlePtr aTrackingParticle) const {
if (trackingParticleToClusterVectorMap_.find(aTrackingParticle) != trackingParticleToClusterVectorMap_.end()) {
return trackingParticleToClusterVectorMap_.find(aTrackingParticle)->second;
} else {
return nullVecClusterRef_;
}

std::vector<edm::Ref<edmNew::DetSetVector<TTCluster<T> >, TTCluster<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 {
if (clusterToTrackingParticleVectorMap.find(aCluster) != clusterToTrackingParticleVectorMap.end()) {
return clusterToTrackingParticleVectorMap.find(aCluster)->second;
const std::vector<TrackingParticlePtr>& TTClusterAssociationMap<T>::findTrackingParticlePtrs(
TTClusterRefT<T> aCluster) const {
if (clusterToTrackingParticleVectorMap_.find(aCluster) != clusterToTrackingParticleVectorMap_.end()) {
return clusterToTrackingParticleVectorMap_.find(aCluster)->second;
} else {
return nullVecTrackingParticlePtr_;
}
}

std::vector<edm::Ptr<TrackingParticle> > tempVector;
tempVector.clear();
return tempVector;
template <typename T>
const TrackingParticlePtr& TTClusterAssociationMap<T>::findTrackingParticlePtr(TTClusterRefT<T> aCluster) const {
if (this->isGenuine(aCluster)) {
return this->findTrackingParticlePtrs(aCluster).at(0);
} else {
return nullTrackingParticlePtr_;
}
}

/// MC truth
Expand All @@ -137,26 +155,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);
const std::vector<TrackingParticlePtr>& theseTrackingParticles = this->findTrackingParticlePtrs(aCluster);

/// If the vector is empty, then the cluster is UNKNOWN
if (theseTrackingParticles.empty())
Expand All @@ -174,7 +194,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 +211,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 +232,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);
const std::vector<TrackingParticlePtr>& theseTrackingParticles = this->findTrackingParticlePtrs(aCluster);

/// If the vector is empty, then the cluster is UNKNOWN
if (theseTrackingParticles.empty())
Expand All @@ -227,7 +247,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 +267,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);
const std::vector<TrackingParticlePtr>& theseTrackingParticles = this->findTrackingParticlePtrs(aCluster);

/// If the vector is empty, then the cluster is UNKNOWN
if (theseTrackingParticles.empty())
Expand All @@ -272,7 +291,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 @@ -295,15 +314,4 @@ bool TTClusterAssociationMap<T>::isCombinatoric(
return (goodDifferentTPs > 1);
}

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

edm::Ptr<TrackingParticle>* temp = new edm::Ptr<TrackingParticle>();
return *temp;
}

#endif