CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ValidHitPairFilter.cc
Go to the documentation of this file.
3 
7 
9 
11 
14 
17 
20 
23 
25 
28 
30 
34 
36 
37 using namespace std;
38 
39 enum { BPix1=1, BPix2=2, BPix3=3,
42 
43 /*****************************************************************************/
44 float spin(float ph)
45 {
46  if(ph < 0) ph += 2 * M_PI;
47  return ph;
48 }
49 
50 /*****************************************************************************/
53 {
54 }
55 
56 /*****************************************************************************/
58 {
59 }
60 /*****************************************************************************/
62  //Retrieve tracker topology from geometry
64  es.get<TrackerTopologyRcd>().get(tTopo);
65 
66 
67  // Get tracker
68  edm::ESHandle<TrackerGeometry> trackerHandle;
69  es.get<TrackerDigiGeometryRecord>().get(trackerHandle);
70  theTracker = trackerHandle.product();
71 
72  // Get geometric search tracker
73  edm::ESHandle<GeometricSearchTracker> geometricSearchTrackerHandle;
74  es.get<TrackerRecoGeometryRecord>().get(geometricSearchTrackerHandle);
75  theGSTracker = geometricSearchTrackerHandle.product();
76 
77  // Get magnetic field
78  edm::ESHandle<MagneticField> magneticFieldHandle;
79  es.get<IdealMagneticFieldRecord>().get(magneticFieldHandle);
80  theMagneticField = magneticFieldHandle.product();
81 
82  // Get propagator
83  edm::ESHandle<Propagator> thePropagatorHandle;
84  es.get<TrackingComponentsRecord>().get("AnalyticalPropagator",
85  thePropagatorHandle);
86  thePropagator = thePropagatorHandle.product();
87 
88  // Bounds, hardwired FIXME
89  rzBounds[0].resize(8); phBounds[0].resize(20);
90  rzBounds[1].resize(8); phBounds[1].resize(32);
91  rzBounds[2].resize(8); phBounds[2].resize(44);
92 
93  rzBounds[3].resize(7); phBounds[3].resize(24);
94  rzBounds[4].resize(7); phBounds[4].resize(24);
95  rzBounds[5].resize(7); phBounds[5].resize(24);
96  rzBounds[6].resize(7); phBounds[6].resize(24);
97 
98  LogTrace("MinBiasTracking")
99  << " [ValidHitPairFilter] initializing pixel barrel";
100 
101  for(TrackerGeometry::DetContainer::const_iterator
102  det = theTracker->detsPXB().begin();
103  det!= theTracker->detsPXB().end(); det++)
104  {
105 
106  DetId pid=(*det)->geographicalId();
107  int il = tTopo->pxbLayer(pid) - 1;
108  int irz = tTopo->pxbModule(pid) - 1;
109  int iph = tTopo->pxbLadder(pid) - 1;
110 
111  rzBounds[il][irz] = (*det)->position().z();
112  phBounds[il][iph] = spin((*det)->position().phi());
113  }
114 
115  LogTrace("MinBiasTracking")
116  << " [ValidHitPairFilter] initializing pixel endcap";
117 
118  for(TrackerGeometry::DetContainer::const_iterator
119  det = theTracker->detsPXF().begin();
120  det!= theTracker->detsPXF().end(); det++)
121  {
122 
123 
124  DetId pid=(*det)->geographicalId();
125  int il = BPix3 + ((tTopo->pxfSide(pid) -1) << 1) + (tTopo->pxfDisk(pid) -1);
126  int irz = ((tTopo->pxfModule(pid)-1) << 1) + (tTopo->pxfPanel(pid)-1);
127  int iph = (tTopo->pxfBlade(pid) -1);
128 
129  rzBounds[il][irz] = (*det)->position().perp();
130  phBounds[il][iph] = spin((*det)->position().phi());
131  }
132 
133  for(int i = 0; i < 7; i++)
134  {
135  sort(rzBounds[i].begin(), rzBounds[i].end());
136  sort(phBounds[i].begin(), phBounds[i].end());
137  }
138 }
139 
140 /*****************************************************************************/
141 int ValidHitPairFilter::getLayer(const TrackingRecHit & recHit, const TrackerTopology *tTopo) const
142 {
143  DetId id(recHit.geographicalId());
144 
145  if(id.subdetId() == int(PixelSubdetector::PixelBarrel))
146  {
147 
148  return tTopo->pxbLayer(id);
149  }
150  else
151  {
152 
153  return BPix3 + ((tTopo->pxfSide(id)-1) << 1) + tTopo->pxfDisk(id);
154  }
155 }
156 
157 /*****************************************************************************/
158 vector<int> ValidHitPairFilter::getMissingLayers(int a, int b) const
159 {
160  vector<int> l;
161  pair<int,int> c(a,b);
162 
163  if(c == pair<int,int>(BPix1,BPix2)) { l.push_back(int(BPix3));
164  l.push_back(int(FPix1_pos));
165  l.push_back(int(FPix1_neg)); return l; }
166  if(c == pair<int,int>(BPix1,BPix3)) { l.push_back(int(BPix2)); return l; }
167  if(c == pair<int,int>(BPix2,BPix3)) { l.push_back(int(BPix1)); return l; }
168  if(c == pair<int,int>(BPix1,FPix1_pos)) { l.push_back(int(BPix2));
169  l.push_back(int(FPix2_pos)); return l; }
170  if(c == pair<int,int>(BPix1,FPix1_neg)) { l.push_back(int(BPix2));
171  l.push_back(int(FPix2_neg)); return l; }
172  if(c == pair<int,int>(BPix1,FPix2_pos)) { l.push_back(int(BPix2));
173  l.push_back(int(FPix1_pos)); return l; }
174  if(c == pair<int,int>(BPix1,FPix2_neg)) { l.push_back(int(BPix2));
175  l.push_back(int(FPix1_neg)); return l; }
176  if(c == pair<int,int>(BPix2,FPix1_pos)) { l.push_back(int(BPix1));
177  l.push_back(int(FPix2_pos)); return l; }
178  if(c == pair<int,int>(BPix2,FPix1_neg)) { l.push_back(int(BPix1));
179  l.push_back(int(FPix2_neg)); return l; }
180  if(c == pair<int,int>(BPix2,FPix2_pos)) { l.push_back(int(BPix1));
181  l.push_back(int(FPix1_pos)); return l; }
182  if(c == pair<int,int>(BPix2,FPix2_neg)) { l.push_back(int(BPix1));
183  l.push_back(int(FPix1_neg)); return l; }
184  if(c == pair<int,int>(FPix1_pos,FPix2_pos)) { l.push_back(int(BPix1)); return l; }
185  if(c == pair<int,int>(FPix1_neg,FPix2_neg)) { l.push_back(int(BPix1)); return l; }
186 
187  return l;
188 }
189 
190 /*****************************************************************************/
192  (const reco::Track & track) const
193 {
194  GlobalPoint position(track.vertex().x(),
195  track.vertex().y(),
196  track.vertex().z());
197 
198  GlobalVector momentum(track.momentum().x(),
199  track.momentum().y(),
200  track.momentum().z());
201 
202  GlobalTrajectoryParameters gtp(position, momentum,
203  track.charge(), theMagneticField);
204 
205  FreeTrajectoryState fts(gtp);
206 
207  return fts;
208 }
209 
210 /*****************************************************************************/
211 vector<const GeomDet *> ValidHitPairFilter::getCloseDets
212  (int il,
213  float rz, const vector<float>& rzB,
214  float ph, const vector<float>& phB,
215  const TrackerTopology *tTopo) const
216 {
217  vector<int> rzVec, phVec;
218 
219  // Radius or z
220  vector<float>::const_iterator irz = lower_bound(rzB.begin(),rzB.end(), rz);
221  if(irz > rzB.begin()) rzVec.push_back(irz - rzB.begin() - 1);
222  if(irz < rzB.end() ) rzVec.push_back(irz - rzB.begin() );
223 
224  // Phi, circular
225  vector<float>::const_iterator iph = lower_bound(phB.begin(),phB.end(), ph);
226  if(iph > phB.begin()) phVec.push_back(iph - phB.begin() - 1);
227  else phVec.push_back(phB.end() - phB.begin() - 1);
228  if(iph < phB.end() ) phVec.push_back(iph - phB.begin() );
229  else phVec.push_back(phB.begin() - phB.begin() );
230 
231  // Detectors
232  vector<const GeomDet *> dets;
233 
234  for(vector<int>::const_iterator irz = rzVec.begin(); irz!= rzVec.end(); irz++)
235  for(vector<int>::const_iterator iph = phVec.begin(); iph!= phVec.end(); iph++)
236  {
237  if(il+1 <= BPix3)
238  {
239  int layer = il + 1;
240  int ladder = *iph + 1;
241  int module = *irz + 1;
242 
243  LogTrace("MinBiasTracking")
244  << " [ValidHitPairFilter] third ("<<layer<< "|"<<ladder<<"|"<<module<<")";
245 
246  DetId id=tTopo->pxbDetId(layer,ladder,module);
247  dets.push_back(theTracker->idToDet(id));
248  }
249  else
250  {
251  int side = (il - BPix3) / 2 +1;
252  int disk = (il - BPix3) % 2 + 1;
253  int blade = *iph + 1;
254  int panel = (*irz) % 2 + 1;
255  int module = (*irz) / 2 + 1;
256 
257  LogTrace("MinBiasTracking")
258  << " [ValidHitPairFilter] third ("<<side<<"|"<<disk<<"|"<<blade<<"|"<<panel<<"|"<<module<<")";
259 
260 
261  DetId id=tTopo->pxfDetId(side,disk,blade,panel,module);
262  dets.push_back(theTracker->idToDet(id));
263 
264  }
265  }
266 
267  return dets;
268 }
269 
270 /*****************************************************************************/
272  (const reco::Track * track, const vector<const TrackingRecHit *>& recHits,
273  const TrackerTopology *tTopo) const
274 {
275  bool hasGap = true;
276 
277  if(recHits.size() == 2)
278  {
279  LogTrace("MinBiasTracking")
280  << " [ValidHitPairFilter] pair" << HitInfo::getInfo(*(recHits[0]),tTopo)
281  << HitInfo::getInfo(*(recHits[1]),tTopo);
282 
283  float tol = 0.1; // cm
284  float sc = -1.; // scale, allow 'tol' of edge to count as outside
285  LocalError le(tol*tol, tol*tol, tol*tol);
286 
287  // determine missing layers
288  vector<int> missingLayers = getMissingLayers(getLayer(*(recHits[0]),tTopo),
289  getLayer(*(recHits[1]),tTopo));
290 
291  for(vector<int>::const_iterator missingLayer = missingLayers.begin();
292  missingLayer!= missingLayers.end();
293  missingLayer++)
294  {
295  int il = *missingLayer - 1;
296 
297  // propagate to missing layer
298  FreeTrajectoryState fts = getTrajectory(*track);
300  float rz = 0.;
301 
302  if(il < BPix3)
303  { // barrel
304  const BarrelDetLayer * layer =
305  (theGSTracker->pixelBarrelLayers())[il];
306 
307  tsos = thePropagator->propagate(fts, layer->surface());
308 
309  if(tsos.isValid())
310  rz = tsos.globalPosition().z();
311  }
312  else
313  { // endcap
314  const ForwardDetLayer * layer;
315  if(il - BPix3 < 2)
316  layer = (theGSTracker->negPixelForwardLayers())[il - BPix3 ];
317  else
318  layer = (theGSTracker->posPixelForwardLayers())[il - BPix3 - 2];
319 
320  tsos = thePropagator->propagate(fts, layer->surface());
321 
322  if(tsos.isValid())
323  rz = tsos.globalPosition().perp();
324  }
325 
326  if(tsos.isValid())
327  {
328  float phi = spin(tsos.globalPosition().phi());
329 
330  // check close dets
331  vector<const GeomDet *> closeDets =
332  getCloseDets(il, rz ,rzBounds[il], phi,phBounds[il], tTopo);
333 
334  for(vector<const GeomDet *>::const_iterator det = closeDets.begin();
335  det!= closeDets.end();
336  det++)
337  {
339  thePropagator->propagate(fts, (*det)->surface());
340 
341  if(tsos.isValid())
342  if((*det)->surface().bounds().inside(tsos.localPosition(), le, sc))
343  hasGap = false;
344  }
345  }
346  }
347  }
348 
349 
350  if(hasGap)
351  LogTrace("MinBiasTracking") << " [ValidHitPairFilter] has gap --> good";
352  else
353  LogTrace("MinBiasTracking") << " [ValidHitPairFilter] no gap --> rejected";
354 
355  return hasGap;
356 }
357 
std::vector< const GeomDet * > getCloseDets(int il, float rz, const std::vector< float > &rzB, float ph, const std::vector< float > &phB, const TrackerTopology *tTopo) const
int i
Definition: DBlmapReader.cc:9
T perp() const
Definition: PV3DBase.h:72
unsigned int pxfDisk(const DetId &id) const
virtual const BoundSurface & surface() const
The surface of the GeometricSearchDet.
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
GlobalPoint globalPosition() const
bool ev
const Vector & momentum() const
track momentum vector
Definition: TrackBase.h:662
DetId pxfDetId(uint32_t side, uint32_t disk, uint32_t blade, uint32_t panel, uint32_t module) const
void update(const edm::Event &ev, const edm::EventSetup &es) override
ValidHitPairFilter(const edm::ParameterSet &ps, edm::ConsumesCollector &iC)
const Point & vertex() const
reference point on the track. This method is DEPRECATED, please use referencePoint() instead ...
Definition: TrackBase.h:674
T z() const
Definition: PV3DBase.h:64
#define end
Definition: vmac.h:37
std::vector< int > getMissingLayers(int a, int b) const
#define LogTrace(id)
#define M_PI
unsigned int pxbLayer(const DetId &id) const
Definition: DetId.h:18
virtual const BoundSurface & surface() const
GeometricSearchDet interface.
const T & get() const
Definition: EventSetup.h:56
tuple pid
Definition: sysUtil.py:22
T const * product() const
Definition: ESHandle.h:86
double b
Definition: hdecay.h:120
Geom::Phi< T > phi() const
#define begin
Definition: vmac.h:30
double a
Definition: hdecay.h:121
static int position[264][3]
Definition: ReadPGInfo.cc:509
unsigned int pxfSide(const DetId &id) const
int charge() const
track electric charge
Definition: TrackBase.h:554
DetId geographicalId() const
DetId pxbDetId(uint32_t layer, uint32_t ladder, uint32_t module) const
static std::string getInfo(const DetId &id, const TrackerTopology *tTopo)
Definition: HitInfo.cc:23
Definition: vlib.h:208
int getLayer(const TrackingRecHit &recHit, const TrackerTopology *tTopo) const
float spin(float ph)
FreeTrajectoryState getTrajectory(const reco::Track &track) const