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

[MTD simulation, validation]: implementation of MTD clusters association maps #43913

Merged
merged 7 commits into from
Mar 3, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Geometry/MTDGeometryBuilder/interface/MTDGeomUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ namespace mtd {
std::pair<uint8_t, uint8_t> pixelInModule(const DetId& id, const LocalPoint& local_point) const;
int crystalInModule(const DetId&) const;

uint32_t sensorModuleId(const DetId& id) const;

// 4-vector helper functions using GlobalPoint
float eta(const GlobalPoint& position, const float& vertex_z = 0.) const;
float phi(const GlobalPoint& position) const;
Expand Down
13 changes: 13 additions & 0 deletions Geometry/MTDGeometryBuilder/src/MTDGeomUtil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,19 @@ int MTDGeomUtil::crystalInModule(const DetId& id) const {
return hid.crystal();
}

// returns the sensor module id
uint32_t MTDGeomUtil::sensorModuleId(const DetId& id) const {
if (isBTL(id)) {
BTLDetId detId(id);
DetId geoId = detId.geographicalId(MTDTopologyMode::crysLayoutFromTopoMode(topology_->getMTDTopologyMode()));
return (geoId.rawId());
} else {
ETLDetId detId(id);
DetId geoId = detId.geographicalId();
return (geoId.rawId());
}
}

float MTDGeomUtil::eta(const GlobalPoint& position, const float& vertex_z) const {
GlobalPoint corrected_position = GlobalPoint(position.x(), position.y(), position.z() - vertex_z);
return corrected_position.eta();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#ifndef SimDataFormats_Associations_MtdRecoClusterToSimLayerClusterAssociationMap_h
#define SimDataFormats_Associations_MtdRecoClusterToSimLayerClusterAssociationMap_h

#include "DataFormats/Provenance/interface/ProductID.h"
#include "DataFormats/Common/interface/HandleBase.h"
#include "DataFormats/FTLRecHit/interface/FTLClusterCollections.h"
#include "SimDataFormats/CaloAnalysis/interface/MtdSimLayerClusterFwd.h"

#include <vector>
#include <utility>
#include <algorithm>

/**
* Maps FTLCluserRef to SimLayerClusterRef
*
*/
class MtdRecoClusterToSimLayerClusterAssociationMap {
public:
using key_type = FTLClusterRef;
using mapped_type = MtdSimLayerClusterRef;
using value_type = std::pair<key_type, std::vector<mapped_type>>;
using map_type = std::vector<value_type>;
using const_iterator = typename map_type::const_iterator;
using range = std::pair<const_iterator, const_iterator>;

/// Constructor
MtdRecoClusterToSimLayerClusterAssociationMap();
/// Destructor
~MtdRecoClusterToSimLayerClusterAssociationMap();

void emplace_back(const FTLClusterRef& recoClus, std::vector<MtdSimLayerClusterRef>& simClusVect) {
map_.emplace_back(recoClus, simClusVect);
}

void post_insert() { std::sort(map_.begin(), map_.end(), compare); }

bool empty() const { return map_.empty(); }
size_t size() const { return map_.size(); }

const_iterator begin() const { return map_.begin(); }
const_iterator cbegin() const { return map_.cbegin(); }
const_iterator end() const { return map_.end(); }
const_iterator cend() const { return map_.cend(); }

range equal_range(const FTLClusterRef& key) const {
return std::equal_range(map_.begin(), map_.end(), value_type(key, std::vector<MtdSimLayerClusterRef>()), compare);
}

const map_type& map() const { return map_; }

private:
static bool compare(const value_type& i, const value_type& j) { return (i.first < j.first); }

map_type map_;
};

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#ifndef SimDataFormats_Associations_MtdRecoClusterToSimLayerClusterAssociator_h
#define SimDataFormats_Associations_MtdRecoClusterToSimLayerClusterAssociator_h
// Original Author: Martina Malberti

// system include files
#include <memory>

// user include files
#include "SimDataFormats/Associations/interface/MtdRecoClusterToSimLayerClusterAssociatorBaseImpl.h"

// forward declarations

namespace reco {

class MtdRecoClusterToSimLayerClusterAssociator {
public:
MtdRecoClusterToSimLayerClusterAssociator(std::unique_ptr<reco::MtdRecoClusterToSimLayerClusterAssociatorBaseImpl>);
MtdRecoClusterToSimLayerClusterAssociator() = default;
MtdRecoClusterToSimLayerClusterAssociator(MtdRecoClusterToSimLayerClusterAssociator &&) = default;
MtdRecoClusterToSimLayerClusterAssociator &operator=(MtdRecoClusterToSimLayerClusterAssociator &&) = default;
MtdRecoClusterToSimLayerClusterAssociator(const MtdRecoClusterToSimLayerClusterAssociator &) =
delete; // stop default

~MtdRecoClusterToSimLayerClusterAssociator() = default;
const MtdRecoClusterToSimLayerClusterAssociator &operator=(const MtdRecoClusterToSimLayerClusterAssociator &) =
delete; // stop default

// ---------- const member functions ---------------------
/// Associate RecoCluster to MtdSimLayerCluster
reco::RecoToSimCollectionMtd associateRecoToSim(const edm::Handle<FTLClusterCollection> &btlRecoClusH,
const edm::Handle<FTLClusterCollection> &etlRecoClusH,
const edm::Handle<MtdSimLayerClusterCollection> &simClusH) const {
return m_impl->associateRecoToSim(btlRecoClusH, etlRecoClusH, simClusH);
};

/// Associate MtdSimLayerCluster to RecoCluster
reco::SimToRecoCollectionMtd associateSimToReco(const edm::Handle<FTLClusterCollection> &btlRecoClusH,
const edm::Handle<FTLClusterCollection> &etlRecoClusH,
const edm::Handle<MtdSimLayerClusterCollection> &simClusH) const {
return m_impl->associateSimToReco(btlRecoClusH, etlRecoClusH, simClusH);
};

private:
// ---------- member data --------------------------------
std::unique_ptr<MtdRecoClusterToSimLayerClusterAssociatorBaseImpl> m_impl;
};
} // namespace reco

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#ifndef SimDataFormats_Associations_MtdRecoClusterToSimLayerClusterAssociatorBaseImpl_h
#define SimDataFormats_Associations_MtdRecoClusterToSimLayerClusterAssociatorBaseImpl_h

#include "DataFormats/Common/interface/Handle.h"
#include "DataFormats/FTLRecHit/interface/FTLClusterCollections.h"
#include "SimDataFormats/CaloAnalysis/interface/MtdSimLayerCluster.h"
#include "SimDataFormats/CaloAnalysis/interface/MtdSimLayerClusterFwd.h"
#include "SimDataFormats/Associations/interface/MtdRecoClusterToSimLayerClusterAssociationMap.h"
#include "SimDataFormats/Associations/interface/MtdSimLayerClusterToRecoClusterAssociationMap.h"

namespace reco {

using RecoToSimCollectionMtd = MtdRecoClusterToSimLayerClusterAssociationMap;
using SimToRecoCollectionMtd = MtdSimLayerClusterToRecoClusterAssociationMap;

class MtdRecoClusterToSimLayerClusterAssociatorBaseImpl {
public:
/// Constructor
MtdRecoClusterToSimLayerClusterAssociatorBaseImpl();
/// Destructor
virtual ~MtdRecoClusterToSimLayerClusterAssociatorBaseImpl();

/// Associate a MtdRecoCluster to MtdSimLayerClusters
virtual reco::RecoToSimCollectionMtd associateRecoToSim(
const edm::Handle<FTLClusterCollection> &btlRecoClusH,
const edm::Handle<FTLClusterCollection> &etlRecoClusH,
const edm::Handle<MtdSimLayerClusterCollection> &simClusH) const;

/// Associate a MtdSimLayerClusters to MtdRecoClusters
virtual reco::SimToRecoCollectionMtd associateSimToReco(
const edm::Handle<FTLClusterCollection> &btlRecoClusH,
const edm::Handle<FTLClusterCollection> &etlRecoClusH,
const edm::Handle<MtdSimLayerClusterCollection> &simClusH) const;
};
} // namespace reco

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#ifndef SimDataFormats_Associations_MtdSimLayerClusterToRecoClusterAssociationMap_h
#define SimDataFormats_Associations_MtdSimLayerClusterToRecoClusterAssociationMap_h

#include "DataFormats/Provenance/interface/ProductID.h"
#include "DataFormats/Common/interface/HandleBase.h"
#include "DataFormats/FTLRecHit/interface/FTLClusterCollections.h"
#include "SimDataFormats/CaloAnalysis/interface/MtdSimLayerClusterFwd.h"

#include <vector>
#include <utility>
#include <algorithm>

/**
* Maps MtdSimLayerCluserRef to FTLClusterRef
*
*/
class MtdSimLayerClusterToRecoClusterAssociationMap {
public:
using key_type = MtdSimLayerClusterRef;
using mapped_type = FTLClusterRef;
using value_type = std::pair<key_type, std::vector<mapped_type>>;
using map_type = std::vector<value_type>;
using const_iterator = typename map_type::const_iterator;
using range = std::pair<const_iterator, const_iterator>;

/// Constructor
MtdSimLayerClusterToRecoClusterAssociationMap();
/// Destructor
~MtdSimLayerClusterToRecoClusterAssociationMap();

void emplace_back(const MtdSimLayerClusterRef& simClus, std::vector<FTLClusterRef>& recoClusVect) {
map_.emplace_back(simClus, recoClusVect);
}

void post_insert() { std::sort(map_.begin(), map_.end(), compare); }

bool empty() const { return map_.empty(); }
size_t size() const { return map_.size(); }

const_iterator begin() const { return map_.begin(); }
const_iterator cbegin() const { return map_.cbegin(); }
const_iterator end() const { return map_.end(); }
const_iterator cend() const { return map_.cend(); }

range equal_range(const MtdSimLayerClusterRef& key) const {
return std::equal_range(map_.begin(), map_.end(), value_type(key, std::vector<FTLClusterRef>()), compare);
}

const map_type& map() const { return map_; }

private:
static bool compare(const value_type& i, const value_type& j) {
const auto& i_hAndE = (i.first)->hits_and_energies();
const auto& j_hAndE = (j.first)->hits_and_energies();

auto imin = std::min_element(i_hAndE.begin(),
i_hAndE.end(),
[](std::pair<uint64_t, float> a, std::pair<uint64_t, float> b) { return a < b; });

auto jmin = std::min_element(j_hAndE.begin(),
j_hAndE.end(),
[](std::pair<uint64_t, float> a, std::pair<uint64_t, float> b) { return a < b; });

return (*imin < *jmin);
}

map_type map_;
};

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#ifndef SimDataFormats_Associations_MtdSimLayerClusterToTPAssociator_h
#define SimDataFormats_Associations_MtdSimLayerClusterToTPAssociator_h
// Author: M. Malberti

// system include files
#include <memory>

// user include files

#include "SimDataFormats/Associations/interface/MtdSimLayerClusterToTPAssociatorBaseImpl.h"

// forward declarations

namespace reco {
class MtdSimLayerClusterToTPAssociator {
public:
MtdSimLayerClusterToTPAssociator(std::unique_ptr<reco::MtdSimLayerClusterToTPAssociatorBaseImpl>);
MtdSimLayerClusterToTPAssociator() = default;
MtdSimLayerClusterToTPAssociator(MtdSimLayerClusterToTPAssociator &&) = default;
MtdSimLayerClusterToTPAssociator &operator=(MtdSimLayerClusterToTPAssociator &&) = default;
MtdSimLayerClusterToTPAssociator(const MtdSimLayerClusterToTPAssociator &) = delete; // stop default
const MtdSimLayerClusterToTPAssociator &operator=(const MtdSimLayerClusterToTPAssociator &) =
delete; // stop default

~MtdSimLayerClusterToTPAssociator() = default;

// ---------- const member functions ---------------------
/// Associate MtdSimLayerCluster to TrackingParticle
reco::SimToTPCollectionMtd associateSimToTP(const edm::Handle<MtdSimLayerClusterCollection> &simClusH,
const edm::Handle<TrackingParticleCollection> &trackingParticleH) const {
return m_impl->associateSimToTP(simClusH, trackingParticleH);
};

/// Associate TrackingParticle to MtdSimLayerCluster
reco::TPToSimCollectionMtd associateTPToSim(const edm::Handle<MtdSimLayerClusterCollection> &simClusH,
const edm::Handle<TrackingParticleCollection> &trackingParticleH) const {
return m_impl->associateTPToSim(simClusH, trackingParticleH);
};

private:
// ---------- member data --------------------------------
std::unique_ptr<MtdSimLayerClusterToTPAssociatorBaseImpl> m_impl;
};
} // namespace reco

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#ifndef SimDataFormats_Associations_MtdSimLayerClusterToTPAssociatorBaseImpl_h
#define SimDataFormats_Associations_MtdSimLayerClusterToTPAssociatorBaseImpl_h

/** \class MtdSimLayerClusterToTPAssociatorBaseImpl
*
* Base class for MtdSimLayerClusterToTPAssociator. Methods take as input
* the handles of MtdSimLayerCluster and TrackingParticle collections and return an
* AssociationMap (oneToMany)
*
* \author M. Malberti
*/

#include "DataFormats/Common/interface/Handle.h"
#include "SimDataFormats/CaloAnalysis/interface/MtdSimLayerCluster.h"
#include "SimDataFormats/CaloAnalysis/interface/MtdSimLayerClusterFwd.h"
#include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h"
#include "SimDataFormats/TrackingAnalysis/interface/TrackingParticleFwd.h"
#include "DataFormats/Common/interface/OneToManyWithQualityGeneric.h"
#include "DataFormats/Common/interface/OneToMany.h"
#include "DataFormats/Common/interface/AssociationMap.h"

namespace reco {

typedef edm::AssociationMap<edm::OneToMany<MtdSimLayerClusterCollection, TrackingParticleCollection> >
SimToTPCollectionMtd;
typedef edm::AssociationMap<edm::OneToMany<TrackingParticleCollection, MtdSimLayerClusterCollection> >
TPToSimCollectionMtd;

class MtdSimLayerClusterToTPAssociatorBaseImpl {
public:
/// Constructor
MtdSimLayerClusterToTPAssociatorBaseImpl();
/// Destructor
virtual ~MtdSimLayerClusterToTPAssociatorBaseImpl();

/// Associate a MtdSimLayerCluster to TrackingParticle
virtual SimToTPCollectionMtd associateSimToTP(
const edm::Handle<MtdSimLayerClusterCollection> &simClusH,
const edm::Handle<TrackingParticleCollection> &trackingParticleH) const;

/// Associate a TrackingParticle to MtdSimLayerCluster
virtual TPToSimCollectionMtd associateTPToSim(
const edm::Handle<MtdSimLayerClusterCollection> &simClusH,
const edm::Handle<TrackingParticleCollection> &trackingParticleH) const;
};
} // namespace reco

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "SimDataFormats/Associations/interface/MtdRecoClusterToSimLayerClusterAssociationMap.h"

MtdRecoClusterToSimLayerClusterAssociationMap::MtdRecoClusterToSimLayerClusterAssociationMap() {}

MtdRecoClusterToSimLayerClusterAssociationMap::~MtdRecoClusterToSimLayerClusterAssociationMap() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "SimDataFormats/Associations/interface/MtdRecoClusterToSimLayerClusterAssociator.h"

reco::MtdRecoClusterToSimLayerClusterAssociator::MtdRecoClusterToSimLayerClusterAssociator(
std::unique_ptr<reco::MtdRecoClusterToSimLayerClusterAssociatorBaseImpl> ptr)
: m_impl(std::move(ptr)) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "SimDataFormats/Associations/interface/MtdRecoClusterToSimLayerClusterAssociatorBaseImpl.h"

namespace reco {
MtdRecoClusterToSimLayerClusterAssociatorBaseImpl::MtdRecoClusterToSimLayerClusterAssociatorBaseImpl(){};
MtdRecoClusterToSimLayerClusterAssociatorBaseImpl::~MtdRecoClusterToSimLayerClusterAssociatorBaseImpl(){};

reco::RecoToSimCollectionMtd MtdRecoClusterToSimLayerClusterAssociatorBaseImpl::associateRecoToSim(
const edm::Handle<FTLClusterCollection> &btlRecoClusH,
const edm::Handle<FTLClusterCollection> &etlRecoClusH,
const edm::Handle<MtdSimLayerClusterCollection> &simClusH) const {
return reco::RecoToSimCollectionMtd();
}

reco::SimToRecoCollectionMtd MtdRecoClusterToSimLayerClusterAssociatorBaseImpl::associateSimToReco(
const edm::Handle<FTLClusterCollection> &btlRecoClusH,
const edm::Handle<FTLClusterCollection> &etlRecoClusH,
const edm::Handle<MtdSimLayerClusterCollection> &simClusH) const {
return reco::SimToRecoCollectionMtd();
}

} // namespace reco
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "SimDataFormats/Associations/interface/MtdSimLayerClusterToRecoClusterAssociationMap.h"

MtdSimLayerClusterToRecoClusterAssociationMap::MtdSimLayerClusterToRecoClusterAssociationMap() {}

MtdSimLayerClusterToRecoClusterAssociationMap::~MtdSimLayerClusterToRecoClusterAssociationMap() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "SimDataFormats/Associations/interface/MtdSimLayerClusterToTPAssociator.h"

reco::MtdSimLayerClusterToTPAssociator::MtdSimLayerClusterToTPAssociator(
std::unique_ptr<reco::MtdSimLayerClusterToTPAssociatorBaseImpl> ptr)
: m_impl(std::move(ptr)) {}
Loading