CMS 3D CMS Logo

ClusterStorer.cc
Go to the documentation of this file.
2 
4 
13 // FastSim hits:
17 
19 
20 namespace helper {
21 
22  // -------------------------------------------------------------
23  //FIXME (push cluster pointers...)
25  TrackingRecHit &newHit = hits[index];
26  const std::type_info &hit_type = typeid(newHit);
27  if (hit_type == typeid(SiPixelRecHit)) {
28  //std::cout << "| It is a Pixel hit !!" << std::endl;
29  pixelClusterRecords_.push_back(PixelClusterHitRecord(static_cast<SiPixelRecHit &>(newHit), hits, index));
30  } else if (hit_type == typeid(SiStripRecHit1D)) {
31  //std::cout << "| It is a SiStripRecHit1D hit !!" << std::endl;
32  stripClusterRecords_.push_back(StripClusterHitRecord(static_cast<SiStripRecHit1D &>(newHit), hits, index));
33  } else if (hit_type == typeid(SiStripRecHit2D)) {
34  //std::cout << "| It is a SiStripRecHit2D hit !!" << std::endl;
35  stripClusterRecords_.push_back(StripClusterHitRecord(static_cast<SiStripRecHit2D &>(newHit), hits, index));
36  } else if (hit_type == typeid(SiStripMatchedRecHit2D)) {
37  //std::cout << "| It is a SiStripMatchedRecHit2D hit !!" << std::endl;
38  SiStripMatchedRecHit2D &mhit = static_cast<SiStripMatchedRecHit2D &>(newHit);
41  } else if (hit_type == typeid(ProjectedSiStripRecHit2D)) {
42  //std::cout << "| It is a ProjectedSiStripRecHit2D hit !!" << std::endl;
43  ProjectedSiStripRecHit2D &phit = static_cast<ProjectedSiStripRecHit2D &>(newHit);
45  } else if (hit_type == typeid(Phase2TrackerRecHit1D)) {
46  //FIXME:: this is just temporary solution for phase2,
47  //it is not really running in the phase2 tracking wf - yet...
48  phase2OTClusterRecords_.push_back(
49  Phase2OTClusterHitRecord(static_cast<Phase2TrackerRecHit1D &>(newHit), hits, index));
50  } else if (hit_type == typeid(VectorHit)) {
51  //FIXME:: this is just temporary solution for phase2,
52  //the VectorHit has 2 clusters but just a hit!
53  phase2OTClusterRecords_.push_back(Phase2OTClusterHitRecord(static_cast<VectorHit &>(newHit), hits, index));
54  } else {
55  if (hit_type == typeid(FastTrackerRecHit) || hit_type == typeid(FastProjectedTrackerRecHit) ||
56  hit_type == typeid(FastMatchedTrackerRecHit)) {
57  //std::cout << "| It is a " << hit_type.name() << " hit !!" << std::endl;
58  // FastSim hits: Do nothing instead of caring about FastSim clusters,
59  // not even sure whether these really exist.
60  // At least predecessor code in TrackSelector and MuonSelector
61  // did not treat them.
62  } else {
63  // through for unknown types
64  throw cms::Exception("UnknownHitType") << "helper::ClusterStorer::addCluster: "
65  << "Unknown hit type " << hit_type.name() << ".\n";
66  }
67  } // end 'switch' on hit type
68  }
69 
70  // -------------------------------------------------------------
72  pixelClusterRecords_.clear();
73  stripClusterRecords_.clear();
74  }
75 
76  // -------------------------------------------------------------
81  if (!pixelClusterRecords_.empty()) {
82  this->processClusters<SiPixelRecHit, SiPixelCluster>(pixelClusterRecords_, pixelDsvToFill, refPixelClusters);
83  }
84  if (!stripClusterRecords_.empty()) {
85  // All we need from the HitType 'SiStripRecHit2D' is the
86  // typedef for 'SiStripRecHit2D::ClusterRef'.
87  // The fact that rekey<SiStripRecHit2D> is called is irrelevant since
88  // ClusterHitRecord<typename SiStripRecHit2D::ClusterRef>::rekey<RecHitType>
89  // is specialised such that 'RecHitType' is not used...
90  this->processClusters<SiStripRecHit2D, SiStripCluster>(stripClusterRecords_, stripDsvToFill, refStripClusters);
91  }
92  }
93 
94  //-------------------------------------------------------------
95  template <typename HitType, typename ClusterType>
99  std::sort(clusterRecords.begin(), clusterRecords.end()); // this sorts them by detid
100  typedef typename std::vector<ClusterHitRecord<typename HitType::ClusterRef> >::const_iterator RIT;
101  RIT it = clusterRecords.begin(), end = clusterRecords.end();
102  size_t clusters = 0;
103  while (it != end) {
104  RIT it2 = it;
105  uint32_t detid = it->detid();
106 
107  // first isolate all clusters on the same detid
108  while ((it2 != end) && (it2->detid() == detid)) {
109  ++it2;
110  }
111  // now [it, it2] bracket one detid
112 
113  // then prepare to copy the clusters
114  typename edmNew::DetSetVector<ClusterType>::FastFiller filler(dsvToFill, detid);
115  typename HitType::ClusterRef lastRef, newRef;
116  for (; it != it2; ++it) { // loop on the detid
117  // first check if we need to clone the hit
118  if (it->clusterRef() != lastRef) {
119  lastRef = it->clusterRef();
120  // clone cluster
121  filler.push_back(*lastRef);
122  // make new ref
123  newRef = typename HitType::ClusterRef(refprod, clusters++);
124  }
125  it->template rekey<HitType>(newRef);
126  } // end of the loop on a single detid
127 
128  } // end of the loop on all clusters
129  }
130 
131  //-------------------------------------------------------------
132  // helper classes
133  //-------------------------------------------------------------
134  // FIXME (migrate to new RTTI and interface)
135  // generic rekey (in practise for pixel only...)
136  template <typename ClusterRefType> // template for class
137  template <typename RecHitType> // template for member function
138  void ClusterStorer::ClusterHitRecord<ClusterRefType>::rekey(const ClusterRefType &newRef) const {
139  TrackingRecHit &genericHit = (*hits_)[index_];
140  RecHitType *hit = nullptr;
141  if (genericHit.geographicalId().rawId() == detid_) { // a hit on this det, so it's simple
142  hit = dynamic_cast<RecHitType *>(&genericHit); //static_cast<RecHitType *>(&genericHit);
143  }
144  assert(hit != nullptr);
145  assert(hit->cluster() == ref_); // otherwise something went wrong
146  hit->setClusterRef(newRef);
147  }
148 
149  // -------------------------------------------------------------
150  // Specific rekey for class template ClusterRefType = SiStripRecHit2D::ClusterRef,
151  // RecHitType is not used.
152  template <>
153  template <typename RecHitType> // or template<> to specialise also here?
155  // rekey<SiStripRecHit2D>(const SiStripRecHit2D::ClusterRef &newRef) const
156  rekey(const SiStripRecHit2D::ClusterRef &newRef) const {
157  TrackingRecHit &genericHit = (*hits_)[index_];
158  const std::type_info &hit_type = typeid(genericHit);
159 
160  OmniClusterRef *cluRef = nullptr;
161  if (typeid(SiStripRecHit1D) == hit_type) {
162  cluRef = &static_cast<SiStripRecHit1D &>(genericHit).omniCluster();
163  } else if (typeid(SiStripRecHit2D) == hit_type) {
164  cluRef = &static_cast<SiStripRecHit2D &>(genericHit).omniCluster();
165  } else if (typeid(SiStripMatchedRecHit2D) == hit_type) {
166  SiStripMatchedRecHit2D &mhit = static_cast<SiStripMatchedRecHit2D &>(genericHit);
167  cluRef = (SiStripDetId(detid_).stereo() ? &mhit.stereoClusterRef() : &mhit.monoClusterRef());
168  } else if (typeid(ProjectedSiStripRecHit2D) == hit_type) {
169  cluRef = &static_cast<ProjectedSiStripRecHit2D &>(genericHit).originalHit().omniCluster();
170  }
171 
172  assert(cluRef != nullptr); // to catch missing RecHit types
173  assert(cluRef->key() == ref_.key()); // otherwise something went wrong
174  (*cluRef) = OmniClusterRef(newRef);
175  }
176 
177 } // namespace helper
edm::RefProd
Definition: EDProductfwd.h:25
FastMatchedTrackerRecHit
Definition: FastMatchedTrackerRecHit.h:7
hfClusterShapes_cfi.hits
hits
Definition: hfClusterShapes_cfi.py:5
helper::ClusterStorer::StripClusterHitRecord
ClusterHitRecord< SiStripRecHit2D::ClusterRef > StripClusterHitRecord
Assuming that the ClusterRef is the same for all SiStripRecHit*:
Definition: ClusterStorer.h:77
cms::cuda::assert
assert(be >=bs)
FastProjectedTrackerRecHit.h
ClusterStorer.h
FastTrackerRecHit
Definition: FastTrackerRecHit.h:40
SiStripDetId.h
SiStripRecHit2D
Definition: SiStripRecHit2D.h:7
OmniClusterRef
Definition: OmniClusterRef.h:12
TrackingRecHit::geographicalId
DetId geographicalId() const
Definition: TrackingRecHit.h:120
ProjectedSiStripRecHit2D
Definition: ProjectedSiStripRecHit2D.h:8
SiPixelRecHit
Our base class.
Definition: SiPixelRecHit.h:23
edm::Ref
Definition: AssociativeIterator.h:58
reco::RecHitType
RecHitType
Definition: TrackInfoEnum.h:16
TrackingRecHit.h
helper::ClusterStorer::PixelClusterHitRecord
ClusterHitRecord< SiPixelRecHit::ClusterRef > PixelClusterHitRecord
Definition: ClusterStorer.h:75
mps_fire.end
end
Definition: mps_fire.py:242
FastProjectedTrackerRecHit
Definition: FastProjectedTrackerRecHit.h:8
SiStripMatchedRecHit2D::stereoHit
SiStripRecHit2D stereoHit() const
Definition: SiStripMatchedRecHit2D.h:25
ProjectedSiStripRecHit2D::originalHit
SiStripRecHit2D originalHit() const
Definition: ProjectedSiStripRecHit2D.h:56
helper::ClusterStorer::addCluster
void addCluster(TrackingRecHitCollection &hits, size_t index)
add cluster of newHit to list (throws if hit is of unknown type)
Definition: ClusterStorer.cc:24
SiPixelRecHit.h
bsc_activity_cfg.clusters
clusters
Definition: bsc_activity_cfg.py:36
helper::ClusterStorer::Phase2OTClusterHitRecord
ClusterHitRecord< Phase2TrackerRecHit1D::CluRef > Phase2OTClusterHitRecord
Definition: ClusterStorer.h:80
Phase2TrackerRecHit1D.h
SiStripMatchedRecHit2D::stereoClusterRef
OmniClusterRef const & stereoClusterRef() const
Definition: SiStripMatchedRecHit2D.h:34
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
trigObjTnPSource_cfi.filler
filler
Definition: trigObjTnPSource_cfi.py:21
helper
Definition: helper.py:1
SiStripMatchedRecHit2D::monoHit
SiStripRecHit2D monoHit() const
Definition: SiStripMatchedRecHit2D.h:26
helper::ClusterStorer::pixelClusterRecords_
std::vector< PixelClusterHitRecord > pixelClusterRecords_
Definition: ClusterStorer.h:92
lowPtGsfElectronSeedValueMaps_cff.rekey
rekey
Definition: lowPtGsfElectronSeedValueMaps_cff.py:7
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
ProjectedSiStripRecHit2D.h
SiStripRecHit1D
Definition: SiStripRecHit1D.h:8
SiStripMatchedRecHit2D::monoClusterRef
OmniClusterRef const & monoClusterRef() const
Definition: SiStripMatchedRecHit2D.h:35
helper::ClusterStorer::clear
void clear()
clear records
Definition: ClusterStorer.cc:71
helper::ClusterStorer::phase2OTClusterRecords_
std::vector< Phase2OTClusterHitRecord > phase2OTClusterRecords_
Definition: ClusterStorer.h:94
TrackingRecHit
Definition: TrackingRecHit.h:21
SiStripRecHit1D.h
VectorHit
Definition: VectorHit.h:28
edmNew::DetSetVector
Definition: DetSetNew.h:13
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
SiStripMatchedRecHit2D
Definition: SiStripMatchedRecHit2D.h:8
Exception
Definition: hltDiff.cc:245
helper::ClusterStorer::ClusterHitRecord::rekey
void rekey(const ClusterRefType &newRef) const
Definition: ClusterStorer.cc:138
helper::ClusterStorer::stripClusterRecords_
std::vector< StripClusterHitRecord > stripClusterRecords_
Definition: ClusterStorer.h:93
Exception.h
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
FastMatchedTrackerRecHit.h
edmNew::DetSetVector::FastFiller
Definition: DetSetVectorNew.h:202
FastTrackerRecHit.h
SiStripDetId
Detector identifier class for the strip tracker.
Definition: SiStripDetId.h:18
SiStripMatchedRecHit2D.h
helper::ClusterStorer::processClusters
void processClusters(std::vector< ClusterHitRecord< typename HitType::ClusterRef > > &clusterRecords, edmNew::DetSetVector< ClusterType > &dsvToFill, edm::RefProd< edmNew::DetSetVector< ClusterType > > &refprod)
Definition: ClusterStorer.cc:96
OmniClusterRef::key
unsigned int key() const
Definition: OmniClusterRef.h:70
SiStripRecHit2D.h
helper::ClusterStorer::ClusterHitRecord
A struct for clusters associated to hits.
Definition: ClusterStorer.h:47
hit
Definition: SiStripHitEffFromCalibTree.cc:88
Phase2TrackerRecHit1D
Definition: Phase2TrackerRecHit1D.h:10
edm::OwnVector< TrackingRecHit >
SiStripDetId::stereo
uint32_t stereo() const
Definition: SiStripDetId.h:168
VectorHit.h
helper::ClusterStorer::processAllClusters
void processAllClusters(edmNew::DetSetVector< SiPixelCluster > &pixelDsvToFill, edm::RefProd< edmNew::DetSetVector< SiPixelCluster > > refPixelClusters, edmNew::DetSetVector< SiStripCluster > &stripDsvToFill, edm::RefProd< edmNew::DetSetVector< SiStripCluster > > refStripClusters)
Definition: ClusterStorer.cc:77