CMS 3D CMS Logo

PixelVertexProducerClusters.cc
Go to the documentation of this file.
2 
7 
10 
14 
16 
19 
21 
22 #include <vector>
23 #include <algorithm>
24 
25 using namespace std;
26 
27 namespace {
28  class VertexHit {
29  public:
30  float z;
31  float r;
32  int w;
33  };
34 
35  /*****************************************************************************/
36  int getContainedHits(const vector<VertexHit>& hits, float z0, float& chi) {
37  int n = 0;
38  chi = 0.;
39 
40  for (vector<VertexHit>::const_iterator hit = hits.begin(); hit != hits.end(); hit++) {
41  // Predicted cluster width in y direction
42  float p = 2 * fabs(hit->z - z0) / hit->r + 0.5; // FIXME
43 
44  if (fabs(p - hit->w) <= 1.) {
45  chi += fabs(p - hit->w);
46  n++;
47  }
48  }
49 
50  return n;
51  }
52 } // namespace
53 
54 /*****************************************************************************/
56  : geomToken_(esConsumes()), pixelToken_(consumes<SiPixelRecHitCollection>(edm::InputTag("siPixelRecHits"))) {
57  // Product
58  produces<reco::VertexCollection>();
59 }
60 
61 /*****************************************************************************/
63 
64 /*****************************************************************************/
66  // Get tracker geometry
67  const TrackerGeometry* theTracker = &es.getData(geomToken_);
68 
69  // Get pixel hit collections
71  ev.getByToken(pixelToken_, pixelColl);
72 
73  const SiPixelRecHitCollection* thePixelHits = pixelColl.product();
74 
75  auto vertices = std::make_unique<reco::VertexCollection>();
76 
77  if (!thePixelHits->empty()) {
78  vector<VertexHit> hits;
79 
81  recHitEnd = thePixelHits->data().end();
82  recHit != recHitEnd;
83  ++recHit) {
84  if (recHit->isValid()) {
85  // if(!(recHit->isOnEdge() || recHit->hasBadPixels()))
86  DetId id = recHit->geographicalId();
87  const PixelGeomDetUnit* pgdu = dynamic_cast<const PixelGeomDetUnit*>(theTracker->idToDetUnit(id));
88  const PixelTopology* theTopol = (&(pgdu->specificTopology()));
89  vector<SiPixelCluster::Pixel> pixels = recHit->cluster()->pixels();
90 
91  bool pixelOnEdge = false;
92  for (vector<SiPixelCluster::Pixel>::const_iterator pixel = pixels.begin(); pixel != pixels.end(); pixel++) {
93  int pos_x = (int)pixel->x;
94  int pos_y = (int)pixel->y;
95 
96  if (theTopol->isItEdgePixelInX(pos_x) || theTopol->isItEdgePixelInY(pos_y)) {
97  pixelOnEdge = true;
98  break;
99  }
100  }
101 
102  if (!pixelOnEdge)
103  if (id.subdetId() == int(PixelSubdetector::PixelBarrel)) {
104  LocalPoint lpos =
105  LocalPoint(recHit->localPosition().x(), recHit->localPosition().y(), recHit->localPosition().z());
106 
107  GlobalPoint gpos = theTracker->idToDet(id)->toGlobal(lpos);
108 
109  VertexHit hit;
110  hit.z = gpos.z();
111  hit.r = gpos.perp();
112  hit.w = recHit->cluster()->sizeY();
113 
114  hits.push_back(hit);
115  }
116  }
117  }
118 
119  int nhits;
120  int nhits_max = 0;
121  float chi;
122  float chi_max = 1e+9;
123 
124  float zest = 0;
125 
126  for (float z0 = -15.9; z0 <= 15.95; z0 += 0.1) {
127  nhits = getContainedHits(hits, z0, chi);
128 
129  if (nhits > 0) {
130  if (nhits > nhits_max) {
131  chi_max = 1e+9;
132  nhits_max = nhits;
133  }
134 
135  if (nhits >= nhits_max)
136  if (chi < chi_max) {
137  chi_max = chi;
138  zest = z0;
139  }
140  }
141  }
142 
143  LogTrace("MinBiasTracking") << " [vertex position] estimated = " << zest
144  << " | pixel barrel hits = " << thePixelHits->size();
145 
147  err(2, 2) = 0.6 * 0.6;
148  reco::Vertex ver(reco::Vertex::Point(0, 0, zest), err, 0, 1, 1);
149  vertices->push_back(ver);
150  }
151 
152  ev.put(std::move(vertices));
153 }
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
Point3DBase< Scalar, LocalTag > LocalPoint
Definition: Definitions.h:30
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
const TrackerGeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > geomToken_
T w() const
edm::EDGetTokenT< SiPixelRecHitCollection > pixelToken_
T const * product() const
Definition: Handle.h:70
data_type const * data(size_t cell) const
math::Error< dimension >::type Error
covariance error matrix (3x3)
Definition: Vertex.h:44
void produce(edm::StreamID, edm::Event &ev, const edm::EventSetup &es) const override
float float float z
#define LogTrace(id)
virtual bool isItEdgePixelInX(int ixbin) const =0
math::XYZPoint Point
point in the space
Definition: Vertex.h:40
const TrackerGeomDet * idToDet(DetId) const override
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:49
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
Definition: DetId.h:17
size_type size() const
virtual bool isItEdgePixelInY(int iybin) const =0
HLT enums.
virtual const PixelTopology & specificTopology() const
Returns a reference to the pixel proxy topology.
PixelVertexProducerClusters(const edm::ParameterSet &ps)
def move(src, dest)
Definition: eostools.py:511