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 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
TTClusterAssociationMap::findTrackingParticlePtrs
const std::vector< TrackingParticlePtr > & findTrackingParticlePtrs(TTClusterRefT< T > aCluster) const
Get all TPs associated to a cluster.
Definition: TTClusterAssociationMap.h:134
TTClusterAssociationMap::setTTClusterToTrackingParticlesMap
void setTTClusterToTrackingParticlesMap(const MapClusToVecTP< T > &aMap)
Definition: TTClusterAssociationMap.h:57
TTClusterAssociationMap
Stores association of Truth Particles (TP) to L1 Track-Trigger Clusters.
Definition: TTClusterAssociationMap.h:44
TTTypes.h
TTClusterAssociationMap::isGenuine
bool isGenuine(TTClusterRefT< T > aCluster) const
Definition: TTClusterAssociationMap.h:177
TrackingParticle::p4
const LorentzVector & p4() const
Four-momentum Lorentz vector. Note this is taken from the first SimTrack only.
Definition: TrackingParticle.h:103
TTClusterAssociationMap::nullVecClusterRef_
static const std::vector< TTClusterRefT< T > > nullVecClusterRef_
Definition: TTClusterAssociationMap.h:91
TTClusterAssociationMap::clusterToTrackingParticleVectorMap_
MapClusToVecTP< T > clusterToTrackingParticleVectorMap_
Data members.
Definition: TTClusterAssociationMap.h:83
MapTPToVecClus
std::map< TrackingParticlePtr, std::vector< TTClusterRefT< T > >> MapTPToVecClus
Definition: TTClusterAssociationMap.h:41
edm::Ptr::get
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:139
TTClusterAssociationMap::isCombinatoric
bool isCombinatoric(TTClusterRefT< T > aCluster) const
Cluster is not "genuine" or "unknown".
Definition: TTClusterAssociationMap.h:270
TTClusterAssociationMap::findTrackingParticlePtr
const TrackingParticlePtr & findTrackingParticlePtr(TTClusterRefT< T > aCluster) const
Get main TP associated to a cluster. (Non-NULL if isGenuine() below is true).
Definition: TTClusterAssociationMap.h:144
edm::Ref
Definition: AssociativeIterator.h:58
TTClusterAssociationMap::isUnknown
bool isUnknown(TTClusterRefT< T > aCluster) const
Cluster "unknown": i.e. not associated with any TP.
Definition: TTClusterAssociationMap.h:235
TTClusterAssociationMap::nullVecTrackingParticlePtr_
static const std::vector< TrackingParticlePtr > nullVecTrackingParticlePtr_
Definition: TTClusterAssociationMap.h:90
TTClusterAssociationMap::nullTrackingParticlePtr_
static const TrackingParticlePtr nullTrackingParticlePtr_
Close class.
Definition: TTClusterAssociationMap.h:89
cmsswSequenceInfo.tp
tp
Definition: cmsswSequenceInfo.py:17
TTClusterAssociationMap::findTTClusterRefs
const std::vector< TTClusterRefT< T > > & findTTClusterRefs(TrackingParticlePtr aTrackingParticle) const
Operations.
Definition: TTClusterAssociationMap.h:124
Phase2TrackerDigi.h
TTClusterAssociationMap::TTClusterAssociationMap
TTClusterAssociationMap()
Constructors.
Definition: TTClusterAssociationMap.h:113
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
Ptr.h
MeasurementPoint.h
MapClusToVecTP
std::map< TTClusterRefT< T >, std::vector< TrackingParticlePtr > > MapClusToVecTP
NOTE: this is needed even if it seems not.
Definition: TTClusterAssociationMap.h:39
TTClusterAssociationMap::getTTClusterToTrackingParticlesMap
const MapClusToVecTP< T > & getTTClusterToTrackingParticlesMap() const
Get/set cluster <-> truth association maps.
Definition: TTClusterAssociationMap.h:54
DetSetVector.h
TTClusterAssociationMap::trackingParticleToClusterVectorMap_
MapTPToVecClus< T > trackingParticleToClusterVectorMap_
Definition: TTClusterAssociationMap.h:84
TTCluster.h
TTClusterAssociationMap::setTrackingParticleToTTClustersMap
void setTrackingParticleToTTClustersMap(const MapTPToVecClus< T > &aMap)
Definition: TTClusterAssociationMap.h:58
edm::Ptr< TrackingParticle >
TrackingParticle.h
Ref.h
tier0.unique
def unique(seq, keepstr=True)
Definition: tier0.py:24
DetId.h
TrackingParticleFwd.h
TTClusterAssociationMap::nclus
int nclus
Definition: TTClusterAssociationMap.h:86
TTClusterAssociationMap::~TTClusterAssociationMap
~TTClusterAssociationMap()
Destructor.
Definition: TTClusterAssociationMap.h:120
DetSet.h
SimTrack.h
TTClusterAssociationMap::getTrackingParticleToTTClustersMap
const MapTPToVecClus< T > & getTrackingParticleToTTClustersMap() const
Definition: TTClusterAssociationMap.h:55
GlobalPoint.h
SimTrackContainer.h
DetSetVectorNew.h
edm::Ptr::isNull
bool isNull() const
Checks for null.
Definition: Ptr.h:142
EncodedEventId.h