File indexing completed on 2024-08-09 23:47:42
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef SimDataFormats_Associations_TTClusterAssociationMap_h
0017 #define SimDataFormats_Associations_TTClusterAssociationMap_h
0018
0019 #include "DataFormats/Common/interface/Ref.h"
0020 #include "DataFormats/Common/interface/Ptr.h"
0021 #include "DataFormats/L1TrackTrigger/interface/TTTypes.h"
0022 #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticleFwd.h"
0023 #include "DataFormats/Common/interface/DetSet.h"
0024 #include "DataFormats/Common/interface/DetSetVector.h"
0025 #include "DataFormats/Common/interface/DetSetVectorNew.h"
0026 #include "DataFormats/DetId/interface/DetId.h"
0027 #include "DataFormats/Phase2TrackerDigi/interface/Phase2TrackerDigi.h"
0028 #include "DataFormats/GeometryCommonDetAlgo/interface/MeasurementPoint.h"
0029 #include "DataFormats/GeometryVector/interface/GlobalPoint.h" /// NOTE: this is needed even if it seems not
0030 #include "DataFormats/L1TrackTrigger/interface/TTCluster.h"
0031 #include "SimDataFormats/Track/interface/SimTrack.h"
0032 #include "SimDataFormats/Track/interface/SimTrackContainer.h"
0033 #include "SimDataFormats/EncodedEventId/interface/EncodedEventId.h"
0034 #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h"
0035
0036
0037 template <typename T>
0038 using MapClusToVecTP = std::map<TTClusterRefT<T>, std::vector<TrackingParticlePtr>>;
0039 template <typename T>
0040 using MapTPToVecClus = std::map<TrackingParticlePtr, std::vector<TTClusterRefT<T>>>;
0041
0042 template <typename T>
0043 class TTClusterAssociationMap {
0044 public:
0045
0046 TTClusterAssociationMap();
0047
0048
0049 ~TTClusterAssociationMap();
0050
0051
0052
0053 const MapClusToVecTP<T>& getTTClusterToTrackingParticlesMap() const { return clusterToTrackingParticleVectorMap_; }
0054 const MapTPToVecClus<T>& getTrackingParticleToTTClustersMap() const { return trackingParticleToClusterVectorMap_; }
0055
0056 void setTTClusterToTrackingParticlesMap(const MapClusToVecTP<T>& aMap) { clusterToTrackingParticleVectorMap_ = aMap; }
0057 void setTrackingParticleToTTClustersMap(const MapTPToVecClus<T>& aMap) { trackingParticleToClusterVectorMap_ = aMap; }
0058
0059
0060 const std::vector<TrackingParticlePtr>& findTrackingParticlePtrs(TTClusterRefT<T> aCluster) const;
0061
0062
0063 const TrackingParticlePtr& findTrackingParticlePtr(TTClusterRefT<T> aCluster) const;
0064
0065
0066 const std::vector<TTClusterRefT<T>>& findTTClusterRefs(TrackingParticlePtr aTrackingParticle) const;
0067
0068
0069
0070
0071
0072
0073
0074 bool isGenuine(TTClusterRefT<T> aCluster) const;
0075
0076 bool isUnknown(TTClusterRefT<T> aCluster) const;
0077
0078 bool isCombinatoric(TTClusterRefT<T> aCluster) const;
0079
0080 private:
0081
0082 MapClusToVecTP<T> clusterToTrackingParticleVectorMap_;
0083 MapTPToVecClus<T> trackingParticleToClusterVectorMap_;
0084
0085 int nclus;
0086
0087
0088 static const TrackingParticlePtr nullTrackingParticlePtr_;
0089 static const std::vector<TrackingParticlePtr> nullVecTrackingParticlePtr_;
0090 static const std::vector<TTClusterRefT<T>> nullVecClusterRef_;
0091
0092 };
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102 template <typename T>
0103 const TrackingParticlePtr TTClusterAssociationMap<T>::nullTrackingParticlePtr_;
0104 template <typename T>
0105 const std::vector<TrackingParticlePtr> TTClusterAssociationMap<T>::nullVecTrackingParticlePtr_;
0106 template <typename T>
0107 const std::vector<TTClusterRefT<T>> TTClusterAssociationMap<T>::nullVecClusterRef_;
0108
0109
0110
0111 template <typename T>
0112 TTClusterAssociationMap<T>::TTClusterAssociationMap() {
0113
0114 nclus = 0;
0115 }
0116
0117
0118 template <typename T>
0119 TTClusterAssociationMap<T>::~TTClusterAssociationMap() {}
0120
0121
0122 template <typename T>
0123 const std::vector<TTClusterRefT<T>>& TTClusterAssociationMap<T>::findTTClusterRefs(
0124 TrackingParticlePtr aTrackingParticle) const {
0125 if (trackingParticleToClusterVectorMap_.find(aTrackingParticle) != trackingParticleToClusterVectorMap_.end()) {
0126 return trackingParticleToClusterVectorMap_.find(aTrackingParticle)->second;
0127 } else {
0128 return nullVecClusterRef_;
0129 }
0130 }
0131
0132 template <typename T>
0133 const std::vector<TrackingParticlePtr>& TTClusterAssociationMap<T>::findTrackingParticlePtrs(
0134 TTClusterRefT<T> aCluster) const {
0135 if (clusterToTrackingParticleVectorMap_.find(aCluster) != clusterToTrackingParticleVectorMap_.end()) {
0136 return clusterToTrackingParticleVectorMap_.find(aCluster)->second;
0137 } else {
0138 return nullVecTrackingParticlePtr_;
0139 }
0140 }
0141
0142 template <typename T>
0143 const TrackingParticlePtr& TTClusterAssociationMap<T>::findTrackingParticlePtr(TTClusterRefT<T> aCluster) const {
0144 if (this->isGenuine(aCluster)) {
0145 return this->findTrackingParticlePtrs(aCluster).at(0);
0146 } else {
0147 return nullTrackingParticlePtr_;
0148 }
0149 }
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175 template <typename T>
0176 bool TTClusterAssociationMap<T>::isGenuine(TTClusterRefT<T> aCluster) const {
0177
0178 const std::vector<TrackingParticlePtr>& theseTrackingParticles = this->findTrackingParticlePtrs(aCluster);
0179
0180
0181 if (theseTrackingParticles.empty())
0182 return false;
0183
0184
0185 unsigned int goodDifferentTPs = 0;
0186 std::vector<const TrackingParticle*> tpAddressVector;
0187
0188 std::vector<float> tp_mom;
0189
0190 float tp_tot = 0;
0191
0192
0193 for (const auto& tp : theseTrackingParticles) {
0194
0195 const TrackingParticlePtr& curTP = tp;
0196
0197
0198 if (curTP.isNull()) {
0199 tp_mom.push_back(0);
0200 } else {
0201 tp_mom.push_back(curTP.get()->p4().pt());
0202 tp_tot += curTP.get()->p4().pt();
0203 }
0204 }
0205
0206 if (tp_tot == 0)
0207 return false;
0208
0209 for (unsigned int itp = 0; itp < theseTrackingParticles.size(); itp++) {
0210
0211 TrackingParticlePtr curTP = theseTrackingParticles.at(itp);
0212
0213
0214 if (tp_mom.at(itp) > 0.01 * tp_tot) {
0215
0216
0217 tpAddressVector.push_back(curTP.get());
0218 }
0219 }
0220
0221
0222 std::sort(tpAddressVector.begin(), tpAddressVector.end());
0223 tpAddressVector.erase(std::unique(tpAddressVector.begin(), tpAddressVector.end()), tpAddressVector.end());
0224 goodDifferentTPs = tpAddressVector.size();
0225
0226 return (goodDifferentTPs == 1);
0227 }
0228
0229 template <typename T>
0230 bool TTClusterAssociationMap<T>::isUnknown(TTClusterRefT<T> aCluster) const {
0231
0232 const std::vector<TrackingParticlePtr>& theseTrackingParticles = this->findTrackingParticlePtrs(aCluster);
0233
0234
0235 if (theseTrackingParticles.empty())
0236 return true;
0237
0238
0239 unsigned int goodDifferentTPs = 0;
0240 std::vector<const TrackingParticle*> tpAddressVector;
0241
0242
0243 for (unsigned int itp = 0; itp < theseTrackingParticles.size(); itp++) {
0244
0245 TrackingParticlePtr curTP = theseTrackingParticles.at(itp);
0246
0247
0248 if (!curTP.isNull()) {
0249
0250
0251 tpAddressVector.push_back(curTP.get());
0252 }
0253 }
0254
0255
0256 std::sort(tpAddressVector.begin(), tpAddressVector.end());
0257 tpAddressVector.erase(std::unique(tpAddressVector.begin(), tpAddressVector.end()), tpAddressVector.end());
0258 goodDifferentTPs = tpAddressVector.size();
0259
0260
0261 return (goodDifferentTPs == 0);
0262 }
0263
0264 template <typename T>
0265 bool TTClusterAssociationMap<T>::isCombinatoric(TTClusterRefT<T> aCluster) const {
0266
0267 const std::vector<TrackingParticlePtr>& theseTrackingParticles = this->findTrackingParticlePtrs(aCluster);
0268
0269
0270 if (theseTrackingParticles.empty())
0271 return false;
0272
0273 bool genuineClu = this->isGenuine(aCluster);
0274 bool unknownClu = this->isUnknown(aCluster);
0275
0276 if (genuineClu || unknownClu)
0277 return false;
0278
0279 return true;
0280
0281
0282 unsigned int goodDifferentTPs = 0;
0283 std::vector<const TrackingParticle*> tpAddressVector;
0284
0285
0286 for (unsigned int itp = 0; itp < theseTrackingParticles.size(); itp++) {
0287
0288 TrackingParticlePtr curTP = theseTrackingParticles.at(itp);
0289
0290
0291 if (!curTP.isNull()) {
0292
0293
0294 tpAddressVector.push_back(curTP.get());
0295 }
0296 }
0297
0298
0299 std::sort(tpAddressVector.begin(), tpAddressVector.end());
0300 tpAddressVector.erase(std::unique(tpAddressVector.begin(), tpAddressVector.end()), tpAddressVector.end());
0301 goodDifferentTPs = tpAddressVector.size();
0302
0303 return (goodDifferentTPs > 1);
0304 }
0305
0306 #endif