CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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
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
end
#define end
Definition: vmac.h:39
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
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:23
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
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
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:67
helper::ClusterStorer::phase2OTClusterRecords_
std::vector< Phase2OTClusterHitRecord > phase2OTClusterRecords_
Definition: ClusterStorer.h:94
TrackingRecHit
Definition: TrackingRecHit.h:21
SiStripRecHit1D.h
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:246
helper::ClusterStorer::ClusterHitRecord::rekey
void rekey(const ClusterRefType &newRef) const
Definition: ClusterStorer.cc:134
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:236
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:92
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
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:73