File indexing completed on 2021-02-14 23:31:28
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 nullTPs = 0;
0187 unsigned int goodDifferentTPs = 0;
0188 std::vector<const TrackingParticle*> tpAddressVector;
0189
0190 std::vector<float> tp_mom;
0191
0192 float tp_tot = 0;
0193
0194
0195 for (const auto& tp : theseTrackingParticles) {
0196
0197 const TrackingParticlePtr& curTP = tp;
0198
0199
0200 if (curTP.isNull()) {
0201
0202 tp_mom.push_back(0);
0203 } else {
0204 tp_mom.push_back(curTP.get()->p4().pt());
0205 tp_tot += curTP.get()->p4().pt();
0206 }
0207 }
0208
0209 if (tp_tot == 0)
0210 return false;
0211
0212 for (unsigned int itp = 0; itp < theseTrackingParticles.size(); itp++) {
0213
0214 TrackingParticlePtr curTP = theseTrackingParticles.at(itp);
0215
0216
0217 if (tp_mom.at(itp) <= 0.01 * tp_tot) {
0218 nullTPs++;
0219 } else {
0220
0221
0222 tpAddressVector.push_back(curTP.get());
0223 }
0224 }
0225
0226
0227 std::sort(tpAddressVector.begin(), tpAddressVector.end());
0228 tpAddressVector.erase(std::unique(tpAddressVector.begin(), tpAddressVector.end()), tpAddressVector.end());
0229 goodDifferentTPs = tpAddressVector.size();
0230
0231 return (goodDifferentTPs == 1);
0232 }
0233
0234 template <typename T>
0235 bool TTClusterAssociationMap<T>::isUnknown(TTClusterRefT<T> aCluster) const {
0236
0237 const std::vector<TrackingParticlePtr>& theseTrackingParticles = this->findTrackingParticlePtrs(aCluster);
0238
0239
0240 if (theseTrackingParticles.empty())
0241 return true;
0242
0243
0244 unsigned int goodDifferentTPs = 0;
0245 std::vector<const TrackingParticle*> tpAddressVector;
0246
0247
0248 for (unsigned int itp = 0; itp < theseTrackingParticles.size(); itp++) {
0249
0250 TrackingParticlePtr curTP = theseTrackingParticles.at(itp);
0251
0252
0253 if (!curTP.isNull()) {
0254
0255
0256 tpAddressVector.push_back(curTP.get());
0257 }
0258 }
0259
0260
0261 std::sort(tpAddressVector.begin(), tpAddressVector.end());
0262 tpAddressVector.erase(std::unique(tpAddressVector.begin(), tpAddressVector.end()), tpAddressVector.end());
0263 goodDifferentTPs = tpAddressVector.size();
0264
0265
0266 return (goodDifferentTPs == 0);
0267 }
0268
0269 template <typename T>
0270 bool TTClusterAssociationMap<T>::isCombinatoric(TTClusterRefT<T> aCluster) const {
0271
0272 const std::vector<TrackingParticlePtr>& theseTrackingParticles = this->findTrackingParticlePtrs(aCluster);
0273
0274
0275 if (theseTrackingParticles.empty())
0276 return false;
0277
0278 bool genuineClu = this->isGenuine(aCluster);
0279 bool unknownClu = this->isUnknown(aCluster);
0280
0281 if (genuineClu || unknownClu)
0282 return false;
0283
0284 return true;
0285
0286
0287 unsigned int nullTPs = 0;
0288 unsigned int goodDifferentTPs = 0;
0289 std::vector<const TrackingParticle*> tpAddressVector;
0290
0291
0292 for (unsigned int itp = 0; itp < theseTrackingParticles.size(); itp++) {
0293
0294 TrackingParticlePtr curTP = theseTrackingParticles.at(itp);
0295
0296
0297 if (curTP.isNull()) {
0298 nullTPs++;
0299 } else {
0300
0301
0302 tpAddressVector.push_back(curTP.get());
0303 }
0304 }
0305
0306
0307 std::sort(tpAddressVector.begin(), tpAddressVector.end());
0308 tpAddressVector.erase(std::unique(tpAddressVector.begin(), tpAddressVector.end()), tpAddressVector.end());
0309 goodDifferentTPs = tpAddressVector.size();
0310
0311
0312
0313
0314 return (goodDifferentTPs > 1);
0315 }
0316
0317 #endif