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