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