Skip to content

Commit fa4ef29

Browse files
authored
Merge pull request cms-sw#43913 from martinamalberti/mm_MTDAssociationMaps
[MTD simulation, validation]: implementation of MTD clusters association maps
2 parents 85c8117 + 1cebff7 commit fa4ef29

File tree

36 files changed

+2215
-124
lines changed

36 files changed

+2215
-124
lines changed

Geometry/MTDGeometryBuilder/interface/MTDGeomUtil.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ namespace mtd {
4343
std::pair<uint8_t, uint8_t> pixelInModule(const DetId& id, const LocalPoint& local_point) const;
4444
int crystalInModule(const DetId&) const;
4545

46+
uint32_t sensorModuleId(const DetId& id) const;
47+
4648
// 4-vector helper functions using GlobalPoint
4749
float eta(const GlobalPoint& position, const float& vertex_z = 0.) const;
4850
float phi(const GlobalPoint& position) const;

Geometry/MTDGeometryBuilder/src/MTDGeomUtil.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,19 @@ int MTDGeomUtil::crystalInModule(const DetId& id) const {
161161
return hid.crystal();
162162
}
163163

164+
// returns the sensor module id
165+
uint32_t MTDGeomUtil::sensorModuleId(const DetId& id) const {
166+
if (isBTL(id)) {
167+
BTLDetId detId(id);
168+
DetId geoId = detId.geographicalId(MTDTopologyMode::crysLayoutFromTopoMode(topology_->getMTDTopologyMode()));
169+
return (geoId.rawId());
170+
} else {
171+
ETLDetId detId(id);
172+
DetId geoId = detId.geographicalId();
173+
return (geoId.rawId());
174+
}
175+
}
176+
164177
float MTDGeomUtil::eta(const GlobalPoint& position, const float& vertex_z) const {
165178
GlobalPoint corrected_position = GlobalPoint(position.x(), position.y(), position.z() - vertex_z);
166179
return corrected_position.eta();
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#ifndef SimDataFormats_Associations_MtdRecoClusterToSimLayerClusterAssociationMap_h
2+
#define SimDataFormats_Associations_MtdRecoClusterToSimLayerClusterAssociationMap_h
3+
4+
#include "DataFormats/Provenance/interface/ProductID.h"
5+
#include "DataFormats/Common/interface/HandleBase.h"
6+
#include "DataFormats/FTLRecHit/interface/FTLClusterCollections.h"
7+
#include "SimDataFormats/CaloAnalysis/interface/MtdSimLayerClusterFwd.h"
8+
9+
#include <vector>
10+
#include <utility>
11+
#include <algorithm>
12+
13+
/**
14+
* Maps FTLCluserRef to SimLayerClusterRef
15+
*
16+
*/
17+
class MtdRecoClusterToSimLayerClusterAssociationMap {
18+
public:
19+
using key_type = FTLClusterRef;
20+
using mapped_type = MtdSimLayerClusterRef;
21+
using value_type = std::pair<key_type, std::vector<mapped_type>>;
22+
using map_type = std::vector<value_type>;
23+
using const_iterator = typename map_type::const_iterator;
24+
using range = std::pair<const_iterator, const_iterator>;
25+
26+
/// Constructor
27+
MtdRecoClusterToSimLayerClusterAssociationMap();
28+
/// Destructor
29+
~MtdRecoClusterToSimLayerClusterAssociationMap();
30+
31+
void emplace_back(const FTLClusterRef& recoClus, std::vector<MtdSimLayerClusterRef>& simClusVect) {
32+
map_.emplace_back(recoClus, simClusVect);
33+
}
34+
35+
void post_insert() { std::sort(map_.begin(), map_.end(), compare); }
36+
37+
bool empty() const { return map_.empty(); }
38+
size_t size() const { return map_.size(); }
39+
40+
const_iterator begin() const { return map_.begin(); }
41+
const_iterator cbegin() const { return map_.cbegin(); }
42+
const_iterator end() const { return map_.end(); }
43+
const_iterator cend() const { return map_.cend(); }
44+
45+
range equal_range(const FTLClusterRef& key) const {
46+
return std::equal_range(map_.begin(), map_.end(), value_type(key, std::vector<MtdSimLayerClusterRef>()), compare);
47+
}
48+
49+
const map_type& map() const { return map_; }
50+
51+
private:
52+
static bool compare(const value_type& i, const value_type& j) { return (i.first < j.first); }
53+
54+
map_type map_;
55+
};
56+
57+
#endif
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#ifndef SimDataFormats_Associations_MtdRecoClusterToSimLayerClusterAssociator_h
2+
#define SimDataFormats_Associations_MtdRecoClusterToSimLayerClusterAssociator_h
3+
// Original Author: Martina Malberti
4+
5+
// system include files
6+
#include <memory>
7+
8+
// user include files
9+
#include "SimDataFormats/Associations/interface/MtdRecoClusterToSimLayerClusterAssociatorBaseImpl.h"
10+
11+
// forward declarations
12+
13+
namespace reco {
14+
15+
class MtdRecoClusterToSimLayerClusterAssociator {
16+
public:
17+
MtdRecoClusterToSimLayerClusterAssociator(std::unique_ptr<reco::MtdRecoClusterToSimLayerClusterAssociatorBaseImpl>);
18+
MtdRecoClusterToSimLayerClusterAssociator() = default;
19+
MtdRecoClusterToSimLayerClusterAssociator(MtdRecoClusterToSimLayerClusterAssociator &&) = default;
20+
MtdRecoClusterToSimLayerClusterAssociator &operator=(MtdRecoClusterToSimLayerClusterAssociator &&) = default;
21+
MtdRecoClusterToSimLayerClusterAssociator(const MtdRecoClusterToSimLayerClusterAssociator &) =
22+
delete; // stop default
23+
24+
~MtdRecoClusterToSimLayerClusterAssociator() = default;
25+
const MtdRecoClusterToSimLayerClusterAssociator &operator=(const MtdRecoClusterToSimLayerClusterAssociator &) =
26+
delete; // stop default
27+
28+
// ---------- const member functions ---------------------
29+
/// Associate RecoCluster to MtdSimLayerCluster
30+
reco::RecoToSimCollectionMtd associateRecoToSim(const edm::Handle<FTLClusterCollection> &btlRecoClusH,
31+
const edm::Handle<FTLClusterCollection> &etlRecoClusH,
32+
const edm::Handle<MtdSimLayerClusterCollection> &simClusH) const {
33+
return m_impl->associateRecoToSim(btlRecoClusH, etlRecoClusH, simClusH);
34+
};
35+
36+
/// Associate MtdSimLayerCluster to RecoCluster
37+
reco::SimToRecoCollectionMtd associateSimToReco(const edm::Handle<FTLClusterCollection> &btlRecoClusH,
38+
const edm::Handle<FTLClusterCollection> &etlRecoClusH,
39+
const edm::Handle<MtdSimLayerClusterCollection> &simClusH) const {
40+
return m_impl->associateSimToReco(btlRecoClusH, etlRecoClusH, simClusH);
41+
};
42+
43+
private:
44+
// ---------- member data --------------------------------
45+
std::unique_ptr<MtdRecoClusterToSimLayerClusterAssociatorBaseImpl> m_impl;
46+
};
47+
} // namespace reco
48+
49+
#endif
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#ifndef SimDataFormats_Associations_MtdRecoClusterToSimLayerClusterAssociatorBaseImpl_h
2+
#define SimDataFormats_Associations_MtdRecoClusterToSimLayerClusterAssociatorBaseImpl_h
3+
4+
#include "DataFormats/Common/interface/Handle.h"
5+
#include "DataFormats/FTLRecHit/interface/FTLClusterCollections.h"
6+
#include "SimDataFormats/CaloAnalysis/interface/MtdSimLayerCluster.h"
7+
#include "SimDataFormats/CaloAnalysis/interface/MtdSimLayerClusterFwd.h"
8+
#include "SimDataFormats/Associations/interface/MtdRecoClusterToSimLayerClusterAssociationMap.h"
9+
#include "SimDataFormats/Associations/interface/MtdSimLayerClusterToRecoClusterAssociationMap.h"
10+
11+
namespace reco {
12+
13+
using RecoToSimCollectionMtd = MtdRecoClusterToSimLayerClusterAssociationMap;
14+
using SimToRecoCollectionMtd = MtdSimLayerClusterToRecoClusterAssociationMap;
15+
16+
class MtdRecoClusterToSimLayerClusterAssociatorBaseImpl {
17+
public:
18+
/// Constructor
19+
MtdRecoClusterToSimLayerClusterAssociatorBaseImpl();
20+
/// Destructor
21+
virtual ~MtdRecoClusterToSimLayerClusterAssociatorBaseImpl();
22+
23+
/// Associate a MtdRecoCluster to MtdSimLayerClusters
24+
virtual reco::RecoToSimCollectionMtd associateRecoToSim(
25+
const edm::Handle<FTLClusterCollection> &btlRecoClusH,
26+
const edm::Handle<FTLClusterCollection> &etlRecoClusH,
27+
const edm::Handle<MtdSimLayerClusterCollection> &simClusH) const;
28+
29+
/// Associate a MtdSimLayerClusters to MtdRecoClusters
30+
virtual reco::SimToRecoCollectionMtd associateSimToReco(
31+
const edm::Handle<FTLClusterCollection> &btlRecoClusH,
32+
const edm::Handle<FTLClusterCollection> &etlRecoClusH,
33+
const edm::Handle<MtdSimLayerClusterCollection> &simClusH) const;
34+
};
35+
} // namespace reco
36+
37+
#endif
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#ifndef SimDataFormats_Associations_MtdSimLayerClusterToRecoClusterAssociationMap_h
2+
#define SimDataFormats_Associations_MtdSimLayerClusterToRecoClusterAssociationMap_h
3+
4+
#include "DataFormats/Provenance/interface/ProductID.h"
5+
#include "DataFormats/Common/interface/HandleBase.h"
6+
#include "DataFormats/FTLRecHit/interface/FTLClusterCollections.h"
7+
#include "SimDataFormats/CaloAnalysis/interface/MtdSimLayerClusterFwd.h"
8+
9+
#include <vector>
10+
#include <utility>
11+
#include <algorithm>
12+
13+
/**
14+
* Maps MtdSimLayerCluserRef to FTLClusterRef
15+
*
16+
*/
17+
class MtdSimLayerClusterToRecoClusterAssociationMap {
18+
public:
19+
using key_type = MtdSimLayerClusterRef;
20+
using mapped_type = FTLClusterRef;
21+
using value_type = std::pair<key_type, std::vector<mapped_type>>;
22+
using map_type = std::vector<value_type>;
23+
using const_iterator = typename map_type::const_iterator;
24+
using range = std::pair<const_iterator, const_iterator>;
25+
26+
/// Constructor
27+
MtdSimLayerClusterToRecoClusterAssociationMap();
28+
/// Destructor
29+
~MtdSimLayerClusterToRecoClusterAssociationMap();
30+
31+
void emplace_back(const MtdSimLayerClusterRef& simClus, std::vector<FTLClusterRef>& recoClusVect) {
32+
map_.emplace_back(simClus, recoClusVect);
33+
}
34+
35+
void post_insert() { std::sort(map_.begin(), map_.end(), compare); }
36+
37+
bool empty() const { return map_.empty(); }
38+
size_t size() const { return map_.size(); }
39+
40+
const_iterator begin() const { return map_.begin(); }
41+
const_iterator cbegin() const { return map_.cbegin(); }
42+
const_iterator end() const { return map_.end(); }
43+
const_iterator cend() const { return map_.cend(); }
44+
45+
range equal_range(const MtdSimLayerClusterRef& key) const {
46+
return std::equal_range(map_.begin(), map_.end(), value_type(key, std::vector<FTLClusterRef>()), compare);
47+
}
48+
49+
const map_type& map() const { return map_; }
50+
51+
private:
52+
static bool compare(const value_type& i, const value_type& j) {
53+
const auto& i_hAndE = (i.first)->hits_and_energies();
54+
const auto& j_hAndE = (j.first)->hits_and_energies();
55+
56+
auto imin = std::min_element(i_hAndE.begin(),
57+
i_hAndE.end(),
58+
[](std::pair<uint64_t, float> a, std::pair<uint64_t, float> b) { return a < b; });
59+
60+
auto jmin = std::min_element(j_hAndE.begin(),
61+
j_hAndE.end(),
62+
[](std::pair<uint64_t, float> a, std::pair<uint64_t, float> b) { return a < b; });
63+
64+
return (*imin < *jmin);
65+
}
66+
67+
map_type map_;
68+
};
69+
70+
#endif
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#ifndef SimDataFormats_Associations_MtdSimLayerClusterToTPAssociator_h
2+
#define SimDataFormats_Associations_MtdSimLayerClusterToTPAssociator_h
3+
// Author: M. Malberti
4+
5+
// system include files
6+
#include <memory>
7+
8+
// user include files
9+
10+
#include "SimDataFormats/Associations/interface/MtdSimLayerClusterToTPAssociatorBaseImpl.h"
11+
12+
// forward declarations
13+
14+
namespace reco {
15+
class MtdSimLayerClusterToTPAssociator {
16+
public:
17+
MtdSimLayerClusterToTPAssociator(std::unique_ptr<reco::MtdSimLayerClusterToTPAssociatorBaseImpl>);
18+
MtdSimLayerClusterToTPAssociator() = default;
19+
MtdSimLayerClusterToTPAssociator(MtdSimLayerClusterToTPAssociator &&) = default;
20+
MtdSimLayerClusterToTPAssociator &operator=(MtdSimLayerClusterToTPAssociator &&) = default;
21+
MtdSimLayerClusterToTPAssociator(const MtdSimLayerClusterToTPAssociator &) = delete; // stop default
22+
const MtdSimLayerClusterToTPAssociator &operator=(const MtdSimLayerClusterToTPAssociator &) =
23+
delete; // stop default
24+
25+
~MtdSimLayerClusterToTPAssociator() = default;
26+
27+
// ---------- const member functions ---------------------
28+
/// Associate MtdSimLayerCluster to TrackingParticle
29+
reco::SimToTPCollectionMtd associateSimToTP(const edm::Handle<MtdSimLayerClusterCollection> &simClusH,
30+
const edm::Handle<TrackingParticleCollection> &trackingParticleH) const {
31+
return m_impl->associateSimToTP(simClusH, trackingParticleH);
32+
};
33+
34+
/// Associate TrackingParticle to MtdSimLayerCluster
35+
reco::TPToSimCollectionMtd associateTPToSim(const edm::Handle<MtdSimLayerClusterCollection> &simClusH,
36+
const edm::Handle<TrackingParticleCollection> &trackingParticleH) const {
37+
return m_impl->associateTPToSim(simClusH, trackingParticleH);
38+
};
39+
40+
private:
41+
// ---------- member data --------------------------------
42+
std::unique_ptr<MtdSimLayerClusterToTPAssociatorBaseImpl> m_impl;
43+
};
44+
} // namespace reco
45+
46+
#endif
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#ifndef SimDataFormats_Associations_MtdSimLayerClusterToTPAssociatorBaseImpl_h
2+
#define SimDataFormats_Associations_MtdSimLayerClusterToTPAssociatorBaseImpl_h
3+
4+
/** \class MtdSimLayerClusterToTPAssociatorBaseImpl
5+
*
6+
* Base class for MtdSimLayerClusterToTPAssociator. Methods take as input
7+
* the handles of MtdSimLayerCluster and TrackingParticle collections and return an
8+
* AssociationMap (oneToMany)
9+
*
10+
* \author M. Malberti
11+
*/
12+
13+
#include "DataFormats/Common/interface/Handle.h"
14+
#include "SimDataFormats/CaloAnalysis/interface/MtdSimLayerCluster.h"
15+
#include "SimDataFormats/CaloAnalysis/interface/MtdSimLayerClusterFwd.h"
16+
#include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h"
17+
#include "SimDataFormats/TrackingAnalysis/interface/TrackingParticleFwd.h"
18+
#include "DataFormats/Common/interface/OneToManyWithQualityGeneric.h"
19+
#include "DataFormats/Common/interface/OneToMany.h"
20+
#include "DataFormats/Common/interface/AssociationMap.h"
21+
22+
namespace reco {
23+
24+
typedef edm::AssociationMap<edm::OneToMany<MtdSimLayerClusterCollection, TrackingParticleCollection> >
25+
SimToTPCollectionMtd;
26+
typedef edm::AssociationMap<edm::OneToMany<TrackingParticleCollection, MtdSimLayerClusterCollection> >
27+
TPToSimCollectionMtd;
28+
29+
class MtdSimLayerClusterToTPAssociatorBaseImpl {
30+
public:
31+
/// Constructor
32+
MtdSimLayerClusterToTPAssociatorBaseImpl();
33+
/// Destructor
34+
virtual ~MtdSimLayerClusterToTPAssociatorBaseImpl();
35+
36+
/// Associate a MtdSimLayerCluster to TrackingParticle
37+
virtual SimToTPCollectionMtd associateSimToTP(
38+
const edm::Handle<MtdSimLayerClusterCollection> &simClusH,
39+
const edm::Handle<TrackingParticleCollection> &trackingParticleH) const;
40+
41+
/// Associate a TrackingParticle to MtdSimLayerCluster
42+
virtual TPToSimCollectionMtd associateTPToSim(
43+
const edm::Handle<MtdSimLayerClusterCollection> &simClusH,
44+
const edm::Handle<TrackingParticleCollection> &trackingParticleH) const;
45+
};
46+
} // namespace reco
47+
48+
#endif
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include "SimDataFormats/Associations/interface/MtdRecoClusterToSimLayerClusterAssociationMap.h"
2+
3+
MtdRecoClusterToSimLayerClusterAssociationMap::MtdRecoClusterToSimLayerClusterAssociationMap() {}
4+
5+
MtdRecoClusterToSimLayerClusterAssociationMap::~MtdRecoClusterToSimLayerClusterAssociationMap() {}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include "SimDataFormats/Associations/interface/MtdRecoClusterToSimLayerClusterAssociator.h"
2+
3+
reco::MtdRecoClusterToSimLayerClusterAssociator::MtdRecoClusterToSimLayerClusterAssociator(
4+
std::unique_ptr<reco::MtdRecoClusterToSimLayerClusterAssociatorBaseImpl> ptr)
5+
: m_impl(std::move(ptr)) {}

0 commit comments

Comments
 (0)