CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
HIPixelClusterVtxProducer.cc
Go to the documentation of this file.
2 
6 
9 
13 
16 
18 
19 #include <fstream>
20 #include <iostream>
21 #include <vector>
22 #include <algorithm>
23 
24 /*****************************************************************************/
26  : srcPixelsString_(ps.getParameter<std::string>("pixelRecHits")),
27  trackerToken_(esConsumes()),
28  minZ_(ps.getParameter<double>("minZ")),
29  maxZ_(ps.getParameter<double>("maxZ")),
30  zStep_(ps.getParameter<double>("zStep"))
31 
32 {
33  // Constructor
34  produces<reco::VertexCollection>();
35  srcPixels_ = (consumes<SiPixelRecHitCollection>(srcPixelsString_));
36 }
37 
38 /*****************************************************************************/
40  // Destructor
41 }
42 
43 /*****************************************************************************/
45  // new vertex collection
46  auto vertices = std::make_unique<reco::VertexCollection>();
47 
48  // get pixel rechits
50  ev.getByToken(srcPixels_, hRecHits);
51 
52  // get tracker geometry
53  if (hRecHits.isValid()) {
54  const TrackerGeometry *tgeo = &es.getData(trackerToken_);
55  const SiPixelRecHitCollection *hits = hRecHits.product();
56 
57  // loop over pixel rechits
58  std::vector<VertexHit> vhits;
59  for (SiPixelRecHitCollection::DataContainer::const_iterator hit = hits->data().begin(), end = hits->data().end();
60  hit != end;
61  ++hit) {
62  if (!hit->isValid())
63  continue;
64  DetId id(hit->geographicalId());
65  if (id.subdetId() != int(PixelSubdetector::PixelBarrel))
66  continue;
67  const PixelGeomDetUnit *pgdu = static_cast<const PixelGeomDetUnit *>(tgeo->idToDet(id));
68  if (true) {
69  const PixelTopology *pixTopo = &(pgdu->specificTopology());
70  std::vector<SiPixelCluster::Pixel> pixels(hit->cluster()->pixels());
71  bool pixelOnEdge = false;
72  for (std::vector<SiPixelCluster::Pixel>::const_iterator pixel = pixels.begin(); pixel != pixels.end();
73  ++pixel) {
74  int pixelX = pixel->x;
75  int pixelY = pixel->y;
76  if (pixTopo->isItEdgePixelInX(pixelX) || pixTopo->isItEdgePixelInY(pixelY)) {
77  pixelOnEdge = true;
78  break;
79  }
80  }
81  if (pixelOnEdge)
82  continue;
83  }
84 
85  LocalPoint lpos = LocalPoint(hit->localPosition().x(), hit->localPosition().y(), hit->localPosition().z());
86  GlobalPoint gpos = pgdu->toGlobal(lpos);
87  VertexHit vh;
88  vh.z = gpos.z();
89  vh.r = gpos.perp();
90  vh.w = hit->cluster()->sizeY();
91  vhits.push_back(vh);
92  }
93 
94  // estimate z-position from cluster lengths
95  double zest = 0.0;
96  int nhits = 0, nhits_max = 0;
97  double chi = 0, chi_max = 1e+9;
98  for (double z0 = minZ_; z0 <= maxZ_; z0 += zStep_) {
99  nhits = getContainedHits(vhits, z0, chi);
100  if (nhits == 0)
101  continue;
102  if (nhits > nhits_max) {
103  chi_max = 1e+9;
104  nhits_max = nhits;
105  }
106  if (nhits >= nhits_max && chi < chi_max) {
107  chi_max = chi;
108  zest = z0;
109  }
110  }
111 
112  LogTrace("MinBiasTracking") << " [vertex position] estimated = " << zest
113  << " | pixel barrel hits = " << vhits.size();
114 
115  // put 1-d vertex and dummy errors into collection
117  err(2, 2) = 0.6 * 0.6;
118  reco::Vertex ver(reco::Vertex::Point(0, 0, zest), err, 0, 1, 1);
119  vertices->push_back(ver);
120  }
121 
122  ev.put(std::move(vertices));
123 }
124 
125 /*****************************************************************************/
126 int HIPixelClusterVtxProducer::getContainedHits(const std::vector<VertexHit> &hits, double z0, double &chi) {
127  // Calculate number of hits contained in v-shaped window in cluster y-width vs. z-position.
128  int n = 0;
129  chi = 0.;
130 
131  for (std::vector<VertexHit>::const_iterator hit = hits.begin(); hit != hits.end(); hit++) {
132  double p = 2 * fabs(hit->z - z0) / hit->r + 0.5; // FIXME
133  if (TMath::Abs(p - hit->w) <= 1.) {
134  chi += fabs(p - hit->w);
135  n++;
136  }
137  }
138  return n;
139 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
Point3DBase< Scalar, LocalTag > LocalPoint
Definition: Definitions.h:30
int getContainedHits(const std::vector< VertexHit > &hits, double z0, double &chi)
uint16_t *__restrict__ id
HIPixelClusterVtxProducer(const edm::ParameterSet &ps)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:49
math::Error< dimension >::type Error
covariance error matrix (3x3)
Definition: Vertex.h:44
#define LogTrace(id)
void produce(edm::Event &ev, const edm::EventSetup &es) override
bool getData(T &iHolder) const
Definition: EventSetup.h:122
virtual bool isItEdgePixelInX(int ixbin) const =0
def move
Definition: eostools.py:511
data_type const * data(size_t cell) const
math::XYZPoint Point
point in the space
Definition: Vertex.h:40
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > trackerToken_
edm::EDGetTokenT< SiPixelRecHitCollection > srcPixels_
const TrackerGeomDet * idToDet(DetId) const override
ValidHit vh
Definition: classes.h:14
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
Definition: DetId.h:17
virtual const PixelTopology & specificTopology() const
Returns a reference to the pixel proxy topology.
virtual bool isItEdgePixelInY(int iybin) const =0
string end
Definition: dataset.py:937
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283