CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 nullTPs = 0;
187  unsigned int goodDifferentTPs = 0;
188  std::vector<const TrackingParticle*> tpAddressVector;
189 
190  std::vector<float> tp_mom;
191 
192  float tp_tot = 0;
193 
195  for (const auto& tp : theseTrackingParticles) {
197  const TrackingParticlePtr& curTP = tp;
198 
200  if (curTP.isNull()) {
201  // nullTPs++;
202  tp_mom.push_back(0);
203  } else {
204  tp_mom.push_back(curTP.get()->p4().pt());
205  tp_tot += curTP.get()->p4().pt();
206  }
207  }
208 
209  if (tp_tot == 0)
210  return false;
211 
212  for (unsigned int itp = 0; itp < theseTrackingParticles.size(); itp++) {
214  TrackingParticlePtr curTP = theseTrackingParticles.at(itp);
215 
217  if (tp_mom.at(itp) <= 0.01 * tp_tot) {
218  nullTPs++;
219  } else {
222  tpAddressVector.push_back(curTP.get());
223  }
224  }
225 
227  std::sort(tpAddressVector.begin(), tpAddressVector.end());
228  tpAddressVector.erase(std::unique(tpAddressVector.begin(), tpAddressVector.end()), tpAddressVector.end());
229  goodDifferentTPs = tpAddressVector.size();
230 
231  return (goodDifferentTPs == 1);
232 }
233 
234 template <typename T>
237  const std::vector<TrackingParticlePtr>& theseTrackingParticles = this->findTrackingParticlePtrs(aCluster);
238 
240  if (theseTrackingParticles.empty())
241  return true;
242 
244  unsigned int goodDifferentTPs = 0;
245  std::vector<const TrackingParticle*> tpAddressVector;
246 
248  for (unsigned int itp = 0; itp < theseTrackingParticles.size(); itp++) {
250  TrackingParticlePtr curTP = theseTrackingParticles.at(itp);
251 
253  if (!curTP.isNull()) {
256  tpAddressVector.push_back(curTP.get());
257  }
258  }
259 
261  std::sort(tpAddressVector.begin(), tpAddressVector.end());
262  tpAddressVector.erase(std::unique(tpAddressVector.begin(), tpAddressVector.end()), tpAddressVector.end());
263  goodDifferentTPs = tpAddressVector.size();
264 
266  return (goodDifferentTPs == 0);
267 }
268 
269 template <typename T>
272  const std::vector<TrackingParticlePtr>& theseTrackingParticles = this->findTrackingParticlePtrs(aCluster);
273 
275  if (theseTrackingParticles.empty())
276  return false;
277 
278  bool genuineClu = this->isGenuine(aCluster);
279  bool unknownClu = this->isUnknown(aCluster);
280 
281  if (genuineClu || unknownClu)
282  return false;
283 
284  return true;
285 
287  unsigned int nullTPs = 0;
288  unsigned int goodDifferentTPs = 0;
289  std::vector<const TrackingParticle*> tpAddressVector;
290 
292  for (unsigned int itp = 0; itp < theseTrackingParticles.size(); itp++) {
294  TrackingParticlePtr curTP = theseTrackingParticles.at(itp);
295 
297  if (curTP.isNull()) {
298  nullTPs++;
299  } else {
302  tpAddressVector.push_back(curTP.get());
303  }
304  }
305 
307  std::sort(tpAddressVector.begin(), tpAddressVector.end());
308  tpAddressVector.erase(std::unique(tpAddressVector.begin(), tpAddressVector.end()), tpAddressVector.end());
309  goodDifferentTPs = tpAddressVector.size();
310 
313  //return ( ( nullTPs == 0 && goodDifferentTPs > 1 ) || ( nullTPs > 0 && goodDifferentTPs > 0 ) );
314  return (goodDifferentTPs > 1);
315 }
316 
317 #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_
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:139
const std::vector< TrackingParticlePtr > & findTrackingParticlePtrs(TTClusterRefT< T > aCluster) const
Get all TPs associated to a cluster.
def unique
Definition: tier0.py:24
Stores association of Truth Particles (TP) to L1 Track-Trigger Clusters.
bool isUnknown(TTClusterRefT< T > aCluster) const
Cluster &quot;unknown&quot;: i.e. not associated with any TP.
static const TrackingParticlePtr nullTrackingParticlePtr_
Close class.
bool isNull() const
Checks for null.
Definition: Ptr.h:142
const MapClusToVecTP< T > & getTTClusterToTrackingParticlesMap() const
Get/set cluster &lt;-&gt; truth association maps.
void setTrackingParticleToTTClustersMap(const MapTPToVecClus< T > &aMap)
static const std::vector< TrackingParticlePtr > nullVecTrackingParticlePtr_
std::map< TrackingParticlePtr, std::vector< TTClusterRefT< T >>> MapTPToVecClus
const std::vector< TTClusterRefT< T > > & findTTClusterRefs(TrackingParticlePtr aTrackingParticle) const
Operations.
bool isCombinatoric(TTClusterRefT< T > aCluster) const
Cluster is not &quot;genuine&quot; or &quot;unknown&quot;.
MapTPToVecClus< T > trackingParticleToClusterVectorMap_
const TrackingParticlePtr & findTrackingParticlePtr(TTClusterRefT< T > aCluster) const
Get main TP associated to a cluster. (Non-NULL if isGenuine() below is true).
bool isGenuine(TTClusterRefT< T > aCluster) const