CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ClusterStorer.cc
Go to the documentation of this file.
2 
4 
11 // FastSim hits:
14 
15 
17 
18 namespace helper {
19 
20  // -------------------------------------------------------------
22  {
23  TrackingRecHit &newHit = hits[index];
24  const std::type_info &hit_type = typeid(newHit);
25  if (hit_type == typeid(SiPixelRecHit)) {
26  //std::cout << "| It is a Pixel hit !!" << std::endl;
27  pixelClusterRecords_.push_back(PixelClusterHitRecord(static_cast<SiPixelRecHit&>(newHit),
28  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),
32  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),
36  hits, index));
37  } else if (hit_type == typeid(SiStripMatchedRecHit2D)) {
38  //std::cout << "| It is a SiStripMatchedRecHit2D hit !!" << std::endl;
39  SiStripMatchedRecHit2D &mhit = static_cast<SiStripMatchedRecHit2D&>(newHit);
40  stripClusterRecords_.push_back(StripClusterHitRecord(*mhit.monoHit(), hits, index));
41  stripClusterRecords_.push_back(StripClusterHitRecord(*mhit.stereoHit(), hits, index));
42  } else if (hit_type == typeid(ProjectedSiStripRecHit2D)) {
43  //std::cout << "| It is a ProjectedSiStripRecHit2D hit !!" << std::endl;
44  ProjectedSiStripRecHit2D &phit = static_cast<ProjectedSiStripRecHit2D&>(newHit);
46  } else {
47  if (hit_type == typeid(SiTrackerGSMatchedRecHit2D)
48  || hit_type == typeid(SiTrackerGSRecHit2D)) {
49  //std::cout << "| It is a " << hit_type.name() << " hit !!" << std::endl;
50  // FastSim hits: Do nothing instead of caring about FastSim clusters,
51  // not even sure whether these really exist.
52  // At least predecessor code in TrackSelector and MuonSelector
53  // did not treat them.
54  } else {
55  // through for unknown types
56  throw cms::Exception("UnknownHitType") << "helper::ClusterStorer::addCluster: "
57  << "Unknown hit type " << hit_type.name()
58  << ".\n";
59  }
60  } // end 'switch' on hit type
61 
62  }
63 
64  // -------------------------------------------------------------
66  {
67  pixelClusterRecords_.clear();
68  stripClusterRecords_.clear();
69  }
70 
71  // -------------------------------------------------------------
72  void ClusterStorer::
77  {
78  if (!pixelClusterRecords_.empty()) {
79  this->processClusters<SiPixelRecHit, SiPixelCluster>
80  (pixelClusterRecords_, pixelDsvToFill, refPixelClusters);
81  }
82  if (!stripClusterRecords_.empty()) {
83  // All we need from the HitType 'SiStripRecHit2D' is the
84  // typedef for 'SiStripRecHit2D::ClusterRef'.
85  // The fact that rekey<SiStripRecHit2D> is called is irrelevant since
86  // ClusterHitRecord<typename SiStripRecHit2D::ClusterRef>::rekey<RecHitType>
87  // is specialised such that 'RecHitType' is not used...
88  this->processClusters<SiStripRecHit2D, SiStripCluster>
89  (stripClusterRecords_, stripDsvToFill, refStripClusters);
90  }
91  }
92 
93  //-------------------------------------------------------------
94  template<typename HitType, typename ClusterType>
95  void ClusterStorer::
99  {
100  std::sort(clusterRecords.begin(), clusterRecords.end()); // this sorts them by detid
101  typedef
102  typename std::vector<ClusterHitRecord<typename HitType::ClusterRef> >::const_iterator
103  RIT;
104  RIT it = clusterRecords.begin(), end = clusterRecords.end();
105  size_t clusters = 0;
106  while (it != end) {
107  RIT it2 = it;
108  uint32_t detid = it->detid();
109 
110  // first isolate all clusters on the same detid
111  while ( (it2 != end) && (it2->detid() == detid)) { ++it2; }
112  // now [it, it2] bracket one detid
113 
114  // then prepare to copy the clusters
115  typename edmNew::DetSetVector<ClusterType>::FastFiller filler(dsvToFill, detid);
116  typename HitType::ClusterRef lastRef, newRef;
117  for ( ; it != it2; ++it) { // loop on the detid
118  // first check if we need to clone the hit
119  if (it->clusterRef() != lastRef) {
120  lastRef = it->clusterRef();
121  // clone cluster
122  filler.push_back( *lastRef );
123  // make new ref
124  newRef = typename HitType::ClusterRef( refprod, clusters++ );
125  }
126  it->template rekey<HitType>(newRef);
127  } // end of the loop on a single detid
128 
129  } // end of the loop on all clusters
130  }
131 
132  //-------------------------------------------------------------
133  // helper classes
134  //-------------------------------------------------------------
135  // generic rekey (in practise for pixel only...)
136  template<typename ClusterRefType> // template for class
137  template<typename RecHitType> // template for member function
139  rekey(const ClusterRefType &newRef) const
140  {
141  TrackingRecHit & genericHit = (*hits_)[index_];
142  RecHitType *hit = 0;
143  if (genericHit.geographicalId().rawId() == detid_) { // a hit on this det, so it's simple
144  hit = dynamic_cast<RecHitType *>(&genericHit); //static_cast<RecHitType *>(&genericHit);
145  }
146  assert (hit != 0);
147  assert (hit->cluster() == ref_); // otherwise something went wrong
148  hit->setClusterRef(newRef);
149  }
150 
151  // -------------------------------------------------------------
152  // Specific rekey for class template ClusterRefType = SiStripRecHit2D::ClusterRef,
153  // RecHitType is not used.
154  template<>
155  template<typename RecHitType> // or template<> to specialise also here?
157  // rekey<SiStripRecHit2D>(const SiStripRecHit2D::ClusterRef &newRef) const
158  rekey(const SiStripRecHit2D::ClusterRef &newRef) const
159  {
160  TrackingRecHit &genericHit = (*hits_)[index_];
161  const std::type_info &hit_type = typeid(genericHit);
162 
163  if (typeid(SiStripRecHit1D) == hit_type) {
164  // case of SiStripRecHit1D
165  SiStripRecHit1D *hit = &static_cast<SiStripRecHit1D&>(genericHit);
166  assert(hit->cluster() == ref_); // otherwise something went wrong
167  hit->setClusterRef(newRef);
168  } else {
169  // various cases resolving to SiStripRecHit2D
170  SiStripRecHit2D *hit = 0;
171  if (typeid(SiStripRecHit2D) == hit_type) {
172  hit = &static_cast<SiStripRecHit2D&>(genericHit);
173  } else if (typeid(SiStripMatchedRecHit2D) == hit_type) {
174  SiStripMatchedRecHit2D &mhit = static_cast<SiStripMatchedRecHit2D&>(genericHit);
175  hit = (SiStripDetId(detid_).stereo() ? mhit.stereoHit() : mhit.monoHit());
176  } else if (typeid(ProjectedSiStripRecHit2D) == hit_type) {
177  ProjectedSiStripRecHit2D &phit = static_cast<ProjectedSiStripRecHit2D&>(genericHit);
178  hit = &phit.originalHit();
179  }
180  assert(hit != 0); // to catch missing RecHit types
181  assert(hit->cluster() == ref_); // otherwise something went wrong
182  hit->setClusterRef(newRef);
183  }
184 
185  }
186 
187 } // end namespace 'helper'
A struct for clusters associated to hits.
Definition: ClusterStorer.h:46
void push_back(data_type const &d)
ClusterHitRecord< SiStripRecHit2D::ClusterRef > StripClusterHitRecord
Assuming that the ClusterRef is the same for all SiStripRecHit*:
Definition: ClusterStorer.h:76
virtual uint32_t stereo() const
Definition: SiStripDetId.h:150
const SiStripRecHit2D * stereoHit() const
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)
void setClusterRef(ClusterRef const &ref)
void setClusterRef(ClusterRef const &ref)
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
#define end
Definition: vmac.h:38
ClusterHitRecord< SiPixelRecHit::ClusterRef > PixelClusterHitRecord
Definition: ClusterStorer.h:74
std::vector< PixelClusterHitRecord > pixelClusterRecords_
Definition: ClusterStorer.h:89
Detector identifier class for the strip tracker.
Definition: SiStripDetId.h:17
ClusterRef const & cluster() const
void clear()
clear records
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)
ClusterRef const & cluster() const
DetId geographicalId() const
const SiStripRecHit2D * monoHit() const
const SiStripRecHit2D & originalHit() const
Our base class.
Definition: SiPixelRecHit.h:27
std::vector< StripClusterHitRecord > stripClusterRecords_
Definition: ClusterStorer.h:90