CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ClusterShapeSeedComparitor.cc
Go to the documentation of this file.
15 #include <cstdio>
16 #include <cassert>
17 
18 #include<iostream>
19 
21  public:
24  virtual void init(const edm::EventSetup& es) override ;
25  virtual bool compatible(const SeedingHitSet &hits, const TrackingRegion & region) const override { return true; }
26  virtual bool compatible(const TrajectorySeed &seed) const override { return true; }
27  virtual bool compatible(const TrajectoryStateOnSurface &,
28  const TransientTrackingRecHit::ConstRecHitPointer &hit) const override ;
29  virtual bool compatible(const SeedingHitSet &hits,
30  const GlobalTrajectoryParameters &helixStateAtVertex,
31  const FastHelix &helix,
32  const TrackingRegion & region) const override ;
33  virtual bool compatible(const SeedingHitSet &hits,
34  const GlobalTrajectoryParameters &straightLineStateAtVertex,
35  const TrackingRegion & region) const override ;
36 
37  private:
38  bool compatibleHit(const TransientTrackingRecHit &hit, const GlobalVector &direction) const ;
39 
44 };
45 
46 
48  filterName_(cfg.getParameter<std::string>("ClusterShapeHitFilterName")),
49  filterAtHelixStage_(cfg.getParameter<bool>("FilterAtHelixStage")),
50  filterPixelHits_(cfg.getParameter<bool>("FilterPixelHits")),
51  filterStripHits_(cfg.getParameter<bool>("FilterStripHits"))
52 {
53 }
54 
56 {
57 }
58 
59 void
62 }
63 
64 
65 bool
68 {
69  if (filterAtHelixStage_) return true;
70  assert(hit->isValid() && tsos.isValid());
71  return compatibleHit(*hit, tsos.globalDirection());
72 }
73 
74 bool
76  const GlobalTrajectoryParameters &straightLineStateAtVertex,
77  const TrackingRegion & region) const
78 {
79  return true;
80 }
81 
82 bool
84  const GlobalTrajectoryParameters &helixStateAtVertex,
85  const FastHelix &helix,
86  const TrackingRegion & region) const
87 {
88  if (!filterAtHelixStage_) return true;
89 
90  if(!helix.isValid()) edm::LogWarning("InvalidHelix") << "PixelClusterShapeSeedComparitor helix is not valid, result is bad";
91 
92  float xc = helix.circle().x0(), yc = helix.circle().y0();
93 
94  GlobalPoint vertex = helixStateAtVertex.position();
95  GlobalVector momvtx = helixStateAtVertex.momentum();
96  float x0 = vertex.x(), y0 = vertex.y();
97  for (unsigned int i = 0, n = hits.size(); i < n; ++i) {
98  const TransientTrackingRecHit &hit = *hits[i];
99  GlobalPoint pos = hit.globalPosition();
100  float x1 = pos.x(), y1 = pos.y(), dx1 = x1 - xc, dy1 = y1 - yc;
101 
102  // now figure out the proper tangent vector
103  float perpx = -dy1, perpy = dx1;
104  if (perpx * (x1-x0) + perpy * (y1 - y0) < 0) {
105  perpy = -perpy; perpx = -perpx;
106  }
107 
108  // now normalize (perpx, perpy, 1.0) to momentum (px, py, pz)
109  float perp2 = perpx*perpx + perpy*perpy;
110  float pmom2 = momvtx.x()*momvtx.x() + momvtx.y()*momvtx.y(), momz2 = momvtx.z()*momvtx.z(), mom2 = pmom2 + momz2;
111  float perpscale = sqrt(pmom2/mom2 / perp2), zscale = sqrt((1-pmom2/mom2));
112  GlobalVector gdir(perpx*perpscale, perpy*perpscale, (momvtx.z() > 0 ? zscale : -zscale));
113 
114  if (!compatibleHit(hit, gdir)) {
115  return false; // not yet
116  }
117  }
118  return true;
119 }
120 
121 bool
123 {
124  if (hit.geographicalId().subdetId() <= 2) {
125  if (!filterPixelHits_) return true;
126  const SiPixelRecHit *pixhit = dynamic_cast<const SiPixelRecHit *>(hit.hit());
127  if (pixhit == 0) throw cms::Exception("LogicError", "Found a valid hit on the pixel detector which is not a SiPixelRecHit\n");
128  //printf("Cheching hi hit on detid %10d, local direction is x = %9.6f, y = %9.6f, z = %9.6f\n", hit.geographicalId().rawId(), direction.x(), direction.y(), direction.z());
129  return filterHandle_->isCompatible(*pixhit, direction);
130  } else {
131  if (!filterStripHits_) return true;
132  const std::type_info &tid = typeid(*hit.hit());
133  if (tid == typeid(SiStripMatchedRecHit2D)) {
134  const SiStripMatchedRecHit2D* matchedHit = dynamic_cast<const SiStripMatchedRecHit2D *>(hit.hit());
135  assert(matchedHit != 0);
136  return (filterHandle_->isCompatible(DetId(matchedHit->monoId()), matchedHit->monoCluster(), direction) &&
137  filterHandle_->isCompatible(DetId(matchedHit->stereoId()), matchedHit->stereoCluster(), direction));
138  } else if (tid == typeid(SiStripRecHit2D)) {
139  const SiStripRecHit2D* recHit = dynamic_cast<const SiStripRecHit2D *>(hit.hit());
140  assert(recHit != 0);
141  return filterHandle_->isCompatible(*recHit, direction);
142  } else if (tid == typeid(ProjectedSiStripRecHit2D)) {
143  const ProjectedSiStripRecHit2D* precHit = dynamic_cast<const ProjectedSiStripRecHit2D *>(hit.hit());
144  assert(precHit != 0);
145  return filterHandle_->isCompatible(precHit->originalHit(), direction);
146  } else {
147  //printf("Questo e' un %s, che ci fo?\n", tid.name());
148  return true;
149  }
150  }
151 }
152 
153 DEFINE_EDM_PLUGIN(SeedComparitorFactory, PixelClusterShapeSeedComparitor, "PixelClusterShapeSeedComparitor");
virtual bool compatible(const TrajectorySeed &seed) const override
int i
Definition: DBlmapReader.cc:9
bool isValid() const
Definition: FastHelix.h:63
virtual bool compatible(const SeedingHitSet &hits, const TrackingRegion &region) const override
double x0() const
Definition: FastCircle.h:50
T y() const
Definition: PV3DBase.h:63
virtual const TrackingRecHit * hit() const =0
edm::ESHandle< ClusterShapeHitFilter > filterHandle_
const FastCircle & circle() const
Definition: FastHelix.h:67
virtual void init(const edm::EventSetup &es) override
virtual GlobalPoint globalPosition() const =0
T sqrt(T t)
Definition: SSEVec.h:48
T z() const
Definition: PV3DBase.h:64
PixelClusterShapeSeedComparitor(const edm::ParameterSet &cfg)
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
Definition: DetId.h:18
const T & get() const
Definition: EventSetup.h:55
T perp2() const
Squared magnitude of transverse component.
bool compatibleHit(const TransientTrackingRecHit &hit, const GlobalVector &direction) const
double y0() const
Definition: FastCircle.h:52
unsigned int size() const
Definition: SeedingHitSet.h:41
#define DEFINE_EDM_PLUGIN(factory, type, name)
DetId geographicalId() const
T x() const
Definition: PV3DBase.h:62
const SiStripRecHit2D & originalHit() const
GlobalVector globalDirection() const
Pixel Reconstructed Hit.