CMS 3D CMS Logo

TTClusterAssociationMap.h
Go to the documentation of this file.
1 
16 #ifndef L1_TRACK_TRIGGER_CLUSTER_ASSOCIATION_FORMAT_H
17 #define L1_TRACK_TRIGGER_CLUSTER_ASSOCIATION_FORMAT_H
18 
36 
37 // Templated aliases
38 template <typename T>
39 using MapClusToVecTP = std::map<TTClusterRefT<T>, std::vector<TrackingParticlePtr>>;
40 template <typename T>
41 using MapTPToVecClus = std::map<TrackingParticlePtr, std::vector<TTClusterRefT<T>>>;
42 
43 template <typename T>
45 public:
48 
51 
53 
56 
59 
61  const std::vector<TrackingParticlePtr>& findTrackingParticlePtrs(TTClusterRefT<T> aCluster) const;
62 
65 
66  // Get all clusters associated to TP.
67  const std::vector<TTClusterRefT<T>>& findTTClusterRefs(TrackingParticlePtr aTrackingParticle) const;
68 
71 
75  bool isGenuine(TTClusterRefT<T> aCluster) const;
77  bool isUnknown(TTClusterRefT<T> aCluster) const;
79  bool isCombinatoric(TTClusterRefT<T> aCluster) const;
80 
81 private:
85 
86  int nclus;
87 
88  // Allow functions to return reference to null.
90  static const std::vector<TrackingParticlePtr> nullVecTrackingParticlePtr_;
91  static const std::vector<TTClusterRefT<T>> nullVecClusterRef_;
92 
93 };
94 
102 // Static constant data members.
103 template <typename T>
105 template <typename T>
106 const std::vector<TrackingParticlePtr> TTClusterAssociationMap<T>::nullVecTrackingParticlePtr_;
107 template <typename T>
108 const std::vector<TTClusterRefT<T>> TTClusterAssociationMap<T>::nullVecClusterRef_;
109 
112 template <typename T>
115  nclus = 0;
116 }
117 
119 template <typename T>
121 
123 template <typename T>
124 const std::vector<TTClusterRefT<T>>& TTClusterAssociationMap<T>::findTTClusterRefs(
125  TrackingParticlePtr aTrackingParticle) const {
126  if (trackingParticleToClusterVectorMap_.find(aTrackingParticle) != trackingParticleToClusterVectorMap_.end()) {
127  return trackingParticleToClusterVectorMap_.find(aTrackingParticle)->second;
128  } else {
129  return nullVecClusterRef_;
130  }
131 }
132 
133 template <typename T>
134 const std::vector<TrackingParticlePtr>& TTClusterAssociationMap<T>::findTrackingParticlePtrs(
135  TTClusterRefT<T> aCluster) const {
136  if (clusterToTrackingParticleVectorMap_.find(aCluster) != clusterToTrackingParticleVectorMap_.end()) {
137  return clusterToTrackingParticleVectorMap_.find(aCluster)->second;
138  } else {
139  return nullVecTrackingParticlePtr_;
140  }
141 }
142 
143 template <typename T>
145  if (this->isGenuine(aCluster)) {
146  return this->findTrackingParticlePtrs(aCluster).at(0);
147  } else {
148  return nullTrackingParticlePtr_;
149  }
150 }
151 
166 
175 
176 template <typename T>
179  const std::vector<TrackingParticlePtr>& theseTrackingParticles = this->findTrackingParticlePtrs(aCluster);
180 
182  if (theseTrackingParticles.empty())
183  return false;
184 
186  unsigned int goodDifferentTPs = 0;
187  std::vector<const TrackingParticle*> tpAddressVector;
188 
189  std::vector<float> tp_mom;
190 
191  float tp_tot = 0;
192 
194  for (const auto& tp : theseTrackingParticles) {
196  const TrackingParticlePtr& curTP = tp;
197 
199  if (curTP.isNull()) {
200  tp_mom.push_back(0);
201  } else {
202  tp_mom.push_back(curTP.get()->p4().pt());
203  tp_tot += curTP.get()->p4().pt();
204  }
205  }
206 
207  if (tp_tot == 0)
208  return false;
209 
210  for (unsigned int itp = 0; itp < theseTrackingParticles.size(); itp++) {
212  TrackingParticlePtr curTP = theseTrackingParticles.at(itp);
213 
215  if (tp_mom.at(itp) > 0.01 * tp_tot) {
218  tpAddressVector.push_back(curTP.get());
219  }
220  }
221 
223  std::sort(tpAddressVector.begin(), tpAddressVector.end());
224  tpAddressVector.erase(std::unique(tpAddressVector.begin(), tpAddressVector.end()), tpAddressVector.end());
225  goodDifferentTPs = tpAddressVector.size();
226 
227  return (goodDifferentTPs == 1);
228 }
229 
230 template <typename T>
233  const std::vector<TrackingParticlePtr>& theseTrackingParticles = this->findTrackingParticlePtrs(aCluster);
234 
236  if (theseTrackingParticles.empty())
237  return true;
238 
240  unsigned int goodDifferentTPs = 0;
241  std::vector<const TrackingParticle*> tpAddressVector;
242 
244  for (unsigned int itp = 0; itp < theseTrackingParticles.size(); itp++) {
246  TrackingParticlePtr curTP = theseTrackingParticles.at(itp);
247 
249  if (!curTP.isNull()) {
252  tpAddressVector.push_back(curTP.get());
253  }
254  }
255 
257  std::sort(tpAddressVector.begin(), tpAddressVector.end());
258  tpAddressVector.erase(std::unique(tpAddressVector.begin(), tpAddressVector.end()), tpAddressVector.end());
259  goodDifferentTPs = tpAddressVector.size();
260 
262  return (goodDifferentTPs == 0);
263 }
264 
265 template <typename T>
268  const std::vector<TrackingParticlePtr>& theseTrackingParticles = this->findTrackingParticlePtrs(aCluster);
269 
271  if (theseTrackingParticles.empty())
272  return false;
273 
274  bool genuineClu = this->isGenuine(aCluster);
275  bool unknownClu = this->isUnknown(aCluster);
276 
277  if (genuineClu || unknownClu)
278  return false;
279 
280  return true;
281 
283  unsigned int goodDifferentTPs = 0;
284  std::vector<const TrackingParticle*> tpAddressVector;
285 
287  for (unsigned int itp = 0; itp < theseTrackingParticles.size(); itp++) {
289  TrackingParticlePtr curTP = theseTrackingParticles.at(itp);
290 
292  if (!curTP.isNull()) {
295  tpAddressVector.push_back(curTP.get());
296  }
297  }
298 
300  std::sort(tpAddressVector.begin(), tpAddressVector.end());
301  tpAddressVector.erase(std::unique(tpAddressVector.begin(), tpAddressVector.end()), tpAddressVector.end());
302  goodDifferentTPs = tpAddressVector.size();
303 
304  return (goodDifferentTPs > 1);
305 }
306 
307 #endif
void setTTClusterToTrackingParticlesMap(const MapClusToVecTP< T > &aMap)
MapClusToVecTP< T > clusterToTrackingParticleVectorMap_
Data members.
const MapTPToVecClus< T > & getTrackingParticleToTTClustersMap() const
std::map< TTClusterRefT< T >, std::vector< TrackingParticlePtr > > MapClusToVecTP
NOTE: this is needed even if it seems not.
static const std::vector< TTClusterRefT< T > > nullVecClusterRef_
bool isUnknown(TTClusterRefT< T > aCluster) const
Cluster "unknown": i.e. not associated with any TP.
bool isCombinatoric(TTClusterRefT< T > aCluster) const
Cluster is not "genuine" or "unknown".
const TrackingParticlePtr & findTrackingParticlePtr(TTClusterRefT< T > aCluster) const
Get main TP associated to a cluster. (Non-NULL if isGenuine() below is true).
Stores association of Truth Particles (TP) to L1 Track-Trigger Clusters.
static const TrackingParticlePtr nullTrackingParticlePtr_
Close class.
bool isNull() const
Checks for null.
Definition: Ptr.h:142
def unique(seq, keepstr=True)
Definition: tier0.py:24
const MapClusToVecTP< T > & getTTClusterToTrackingParticlesMap() const
Get/set cluster <-> truth association maps.
void setTrackingParticleToTTClustersMap(const MapTPToVecClus< T > &aMap)
static const std::vector< TrackingParticlePtr > nullVecTrackingParticlePtr_
const std::vector< TTClusterRefT< T > > & findTTClusterRefs(TrackingParticlePtr aTrackingParticle) const
Operations.
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:139
MapTPToVecClus< T > trackingParticleToClusterVectorMap_
const LorentzVector & p4() const
Four-momentum Lorentz vector. Note this is taken from the first SimTrack only.
std::map< TrackingParticlePtr, std::vector< TTClusterRefT< T > >> MapTPToVecClus
const std::vector< TrackingParticlePtr > & findTrackingParticlePtrs(TTClusterRefT< T > aCluster) const
Get all TPs associated to a cluster.
bool isGenuine(TTClusterRefT< T > aCluster) const