CMS 3D CMS Logo

LowPtClusterShapeSeedComparitor.cc
Go to the documentation of this file.
1 #include <cmath>
2 
22 
23 namespace {
25 
26  inline float sqr(float x) { return x*x; }
27 
28  /*****************************************************************************/
29  inline
30  float areaParallelogram
31  (const Vector2D& a, const Vector2D& b)
32  {
33  return a.x() * b.y() - a.y() * b.x();
34  }
35 
36  /*****************************************************************************/
37 
38  inline
39  bool getGlobalDirs(GlobalPoint const * g, GlobalVector * globalDirs)
40  {
41 
42 
43  // Determine circle
44  CircleFromThreePoints circle(g[0],g[1],g[2]);
45 
46  float curvature = circle.curvature();
47  if(0.f == curvature) {
48  LogDebug("LowPtClusterShapeSeedComparitor")<<"the curvature is null:"
49  <<"\n point1: "<<g[0]
50  <<"\n point2: "<<g[1]
51  <<"\n point3: "<<g[2];
52  return false;
53  }
54 
55  // Get 2d points
56  Vector2D p[3];
57  Vector2D c = circle.center();
58  for(int i=0; i!=3; i++)
59  p[i] = g[i].basicVector().xy() -c;
60 
61 
62  float area = std::abs(areaParallelogram(p[1] - p[0], p[1]));
63 
64  float a12 = std::asin(std::min(area*curvature*curvature,1.f));
65 
66  float slope = (g[1].z() - g[0].z()) / a12;
67 
68  // Calculate globalDirs
69 
70  float cotTheta = slope * curvature;
71  float sinTheta = 1.f/std::sqrt(1.f + sqr(cotTheta));
72  float cosTheta = cotTheta*sinTheta;
73 
74  if (areaParallelogram(p[0], p[1] ) < 0) sinTheta = - sinTheta;
75 
76  for(int i = 0; i!=3; i++) {
77  Vector2D vl = p[i]*(curvature*sinTheta);
78  globalDirs[i] = GlobalVector(-vl.y(),
79  vl.x(),
80  cosTheta
81  );
82  }
83  return true;
84  }
85 
86  /*****************************************************************************/
87 
88 
89  inline
90  void getGlobalPos(const SeedingHitSet &hits, GlobalPoint * globalPoss)
91  {
92 
93  for(unsigned int i=0; i!=hits.size(); ++i)
94  globalPoss[i] = hits[i]->globalPosition();
95  }
96 
97 } // namespace
98 
99 /*****************************************************************************/
101  thePixelClusterShapeCacheToken(iC.consumes<SiPixelClusterShapeCache>(ps.getParameter<edm::InputTag>("clusterShapeCacheSrc"))),
102  theShapeFilterLabel_(ps.getParameter<std::string>("clusterShapeHitFilter"))
103 {}
104 
105 /*****************************************************************************/
108  es.get<TrackerTopologyRcd>().get(theTTopo);
109 
111 }
112 
114 //(const reco::Track* track, const vector<const TrackingRecHit *> & recHits) const
115 {
116  assert(hits.size()==3);
117 
119  if(filter == nullptr)
120  throw cms::Exception("LogicError") << "LowPtClusterShapeSeedComparitor: init(EventSetup) method was not called";
121 
122  // Get global positions
123  GlobalPoint globalPoss[3];
124  getGlobalPos(hits, globalPoss);
125 
126  // Get global directions
127  GlobalVector globalDirs[3];
128 
129  bool ok = getGlobalDirs(globalPoss,globalDirs);
130 
131  // Check whether shape of pixel cluster is compatible
132  // with local track direction
133 
134  if (!ok)
135  {
136  LogDebug("LowPtClusterShapeSeedComparitor")<<"curvarture 0:"
137  <<"\nnHits: "<<hits.size()
138  <<" will say the seed is good anyway.";
139  return true;
140  }
141 
142  for(int i = 0; i < 3; i++)
143  {
144  const SiPixelRecHit* pixelRecHit =
145  dynamic_cast<const SiPixelRecHit *>(hits[i]->hit());
146 
147  if (!pixelRecHit){
148  edm::LogError("LowPtClusterShapeSeedComparitor")<<"this is not a pixel cluster";
149  ok = false; break;
150  }
151 
152  if(!pixelRecHit->isValid())
153  {
154  ok = false; break;
155  }
156 
157  LogDebug("LowPtClusterShapeSeedComparitor")<<"about to compute compatibility."
158  <<"hit ptr: "<<pixelRecHit
159  <<"global direction:"<< globalDirs[i];
160 
161 
162  if(! filter->isCompatible(*pixelRecHit, globalDirs[i], *thePixelClusterShapeCache) )
163  {
164  LogTrace("LowPtClusterShapeSeedComparitor")
165  << " clusShape is not compatible"
166  << HitInfo::getInfo(*hits[i]->hit(),theTTopo.product());
167 
168  ok = false; break;
169  }
170  }
171 
172  return ok;
173 }
174 
#define LogDebug(id)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
static const double slope[3]
edm::ESHandle< ClusterShapeHitFilter > theShapeFilter
something
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
edm::ESHandle< TrackerTopology > theTTopo
T curvature(T InversePt, const edm::EventSetup &iSetup)
Basic2DVector< double >::MathVector Vector2D
Definition: LinkByRecHit.cc:7
bool compatible(const SeedingHitSet &hits) const override
T sqrt(T t)
Definition: SSEVec.h:18
T z() const
Definition: PV3DBase.h:64
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
LowPtClusterShapeSeedComparitor(const edm::ParameterSet &ps, edm::ConsumesCollector &iC)
double f[11][100]
T min(T a, T b)
Definition: MathUtil.h:58
edm::Handle< SiPixelClusterShapeCache > thePixelClusterShapeCache
#define LogTrace(id)
edm::EDGetTokenT< SiPixelClusterShapeCache > thePixelClusterShapeCacheToken
void init(const edm::Event &e, const edm::EventSetup &es) override
bool isValid() const
double b
Definition: hdecay.h:120
HLT enums.
double a
Definition: hdecay.h:121
Square< F >::type sqr(const F &f)
Definition: Square.h:13
T get() const
Definition: EventSetup.h:62
unsigned int size() const
Definition: SeedingHitSet.h:46
static std::string getInfo(const DetId &id, const TrackerTopology *tTopo)
Definition: HitInfo.cc:23
T const * product() const
Definition: ESHandle.h:86
Global3DVector GlobalVector
Definition: GlobalVector.h:10
Our base class.
Definition: SiPixelRecHit.h:23