CMS 3D CMS Logo

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