CMS 3D CMS Logo

TTClusterAssociationMap.h
Go to the documentation of this file.
1 
16 #ifndef SimDataFormats_Associations_TTClusterAssociationMap_h
17 #define SimDataFormats_Associations_TTClusterAssociationMap_h
18 
35 
36 // Templated aliases
37 template <typename T>
38 using MapClusToVecTP = std::map<TTClusterRefT<T>, std::vector<TrackingParticlePtr>>;
39 template <typename T>
40 using MapTPToVecClus = std::map<TrackingParticlePtr, std::vector<TTClusterRefT<T>>>;
41 
42 template <typename T>
44 public:
47 
50 
52 
55 
58 
60  const std::vector<TrackingParticlePtr>& findTrackingParticlePtrs(TTClusterRefT<T> aCluster) const;
61 
64 
65  // Get all clusters associated to TP.
66  const std::vector<TTClusterRefT<T>>& findTTClusterRefs(TrackingParticlePtr aTrackingParticle) const;
67 
70 
74  bool isGenuine(TTClusterRefT<T> aCluster) const;
76  bool isUnknown(TTClusterRefT<T> aCluster) const;
78  bool isCombinatoric(TTClusterRefT<T> aCluster) const;
79 
80 private:
84 
85  int nclus;
86 
87  // Allow functions to return reference to null.
89  static const std::vector<TrackingParticlePtr> nullVecTrackingParticlePtr_;
90  static const std::vector<TTClusterRefT<T>> nullVecClusterRef_;
91 
92 };
93 
101 // Static constant data members.
102 template <typename T>
104 template <typename T>
105 const std::vector<TrackingParticlePtr> TTClusterAssociationMap<T>::nullVecTrackingParticlePtr_;
106 template <typename T>
107 const std::vector<TTClusterRefT<T>> TTClusterAssociationMap<T>::nullVecClusterRef_;
108 
111 template <typename T>
114  nclus = 0;
115 }
116 
118 template <typename T>
120 
122 template <typename T>
123 const std::vector<TTClusterRefT<T>>& TTClusterAssociationMap<T>::findTTClusterRefs(
124  TrackingParticlePtr aTrackingParticle) const {
125  if (trackingParticleToClusterVectorMap_.find(aTrackingParticle) != trackingParticleToClusterVectorMap_.end()) {
126  return trackingParticleToClusterVectorMap_.find(aTrackingParticle)->second;
127  } else {
128  return nullVecClusterRef_;
129  }
130 }
131 
132 template <typename T>
133 const std::vector<TrackingParticlePtr>& TTClusterAssociationMap<T>::findTrackingParticlePtrs(
134  TTClusterRefT<T> aCluster) const {
135  if (clusterToTrackingParticleVectorMap_.find(aCluster) != clusterToTrackingParticleVectorMap_.end()) {
136  return clusterToTrackingParticleVectorMap_.find(aCluster)->second;
137  } else {
138  return nullVecTrackingParticlePtr_;
139  }
140 }
141 
142 template <typename T>
144  if (this->isGenuine(aCluster)) {
145  return this->findTrackingParticlePtrs(aCluster).at(0);
146  } else {
147  return nullTrackingParticlePtr_;
148  }
149 }
150 
165 
174 
175 template <typename T>
178  const std::vector<TrackingParticlePtr>& theseTrackingParticles = this->findTrackingParticlePtrs(aCluster);
179 
181  if (theseTrackingParticles.empty())
182  return false;
183 
185  unsigned int goodDifferentTPs = 0;
186  std::vector<const TrackingParticle*> tpAddressVector;
187 
188  std::vector<float> tp_mom;
189 
190  float tp_tot = 0;
191 
193  for (const auto& tp : theseTrackingParticles) {
195  const TrackingParticlePtr& curTP = tp;
196 
198  if (curTP.isNull()) {
199  tp_mom.push_back(0);
200  } else {
201  tp_mom.push_back(curTP.get()->p4().pt());
202  tp_tot += curTP.get()->p4().pt();
203  }
204  }
205 
206  if (tp_tot == 0)
207  return false;
208 
209  for (unsigned int itp = 0; itp < theseTrackingParticles.size(); itp++) {
211  TrackingParticlePtr curTP = theseTrackingParticles.at(itp);
212 
214  if (tp_mom.at(itp) > 0.01 * tp_tot) {
217  tpAddressVector.push_back(curTP.get());
218  }
219  }
220 
222  std::sort(tpAddressVector.begin(), tpAddressVector.end());
223  tpAddressVector.erase(std::unique(tpAddressVector.begin(), tpAddressVector.end()), tpAddressVector.end());
224  goodDifferentTPs = tpAddressVector.size();
225 
226  return (goodDifferentTPs == 1);
227 }
228 
229 template <typename T>
232  const std::vector<TrackingParticlePtr>& theseTrackingParticles = this->findTrackingParticlePtrs(aCluster);
233 
235  if (theseTrackingParticles.empty())
236  return true;
237 
239  unsigned int goodDifferentTPs = 0;
240  std::vector<const TrackingParticle*> tpAddressVector;
241 
243  for (unsigned int itp = 0; itp < theseTrackingParticles.size(); itp++) {
245  TrackingParticlePtr curTP = theseTrackingParticles.at(itp);
246 
248  if (!curTP.isNull()) {
251  tpAddressVector.push_back(curTP.get());
252  }
253  }
254 
256  std::sort(tpAddressVector.begin(), tpAddressVector.end());
257  tpAddressVector.erase(std::unique(tpAddressVector.begin(), tpAddressVector.end()), tpAddressVector.end());
258  goodDifferentTPs = tpAddressVector.size();
259 
261  return (goodDifferentTPs == 0);
262 }
263 
264 template <typename T>
267  const std::vector<TrackingParticlePtr>& theseTrackingParticles = this->findTrackingParticlePtrs(aCluster);
268 
270  if (theseTrackingParticles.empty())
271  return false;
272 
273  bool genuineClu = this->isGenuine(aCluster);
274  bool unknownClu = this->isUnknown(aCluster);
275 
276  if (genuineClu || unknownClu)
277  return false;
278 
279  return true;
280 
282  unsigned int goodDifferentTPs = 0;
283  std::vector<const TrackingParticle*> tpAddressVector;
284 
286  for (unsigned int itp = 0; itp < theseTrackingParticles.size(); itp++) {
288  TrackingParticlePtr curTP = theseTrackingParticles.at(itp);
289 
291  if (!curTP.isNull()) {
294  tpAddressVector.push_back(curTP.get());
295  }
296  }
297 
299  std::sort(tpAddressVector.begin(), tpAddressVector.end());
300  tpAddressVector.erase(std::unique(tpAddressVector.begin(), tpAddressVector.end()), tpAddressVector.end());
301  goodDifferentTPs = tpAddressVector.size();
302 
303  return (goodDifferentTPs > 1);
304 }
305 
306 #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:144
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:141
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