CMS 3D CMS Logo

PixelBlade.cc
Go to the documentation of this file.
1 #include "PixelBlade.h"
2 
4 
6 #include "LayerCrossingSide.h"
7 #include "DetGroupMerger.h"
9 
13 
14 using namespace std;
15 
17 
19 
20 PixelBlade::PixelBlade(vector<const GeomDet*>& frontDets,
21  vector<const GeomDet*>& backDets):
23  theFrontDets(frontDets), theBackDets(backDets)
24 {
25  theDets.assign(theFrontDets.begin(),theFrontDets.end());
26  theDets.insert(theDets.end(),theBackDets.begin(),theBackDets.end());
27 
31 
32 
33  //--------- DEBUG INFO --------------
34  LogDebug("TkDetLayers") << "DEBUG INFO for PixelBlade" ;
35  LogDebug("TkDetLayers") << "Blade z, perp, innerRadius, outerR: "
36  << this->position().z() << " , "
37  << this->position().perp() << " , "
38  << theDiskSector->innerRadius() << " , "
39  << theDiskSector->outerRadius() ;
40 
41  for(vector<const GeomDet*>::const_iterator it=theFrontDets.begin();
42  it!=theFrontDets.end(); it++){
43  LogDebug("TkDetLayers") << "frontDet phi,z,r: "
44  << (*it)->position().phi() << " , "
45  << (*it)->position().z() << " , "
46  << (*it)->position().perp() ;;
47  }
48 
49  for(vector<const GeomDet*>::const_iterator it=theBackDets.begin();
50  it!=theBackDets.end(); it++){
51  LogDebug("TkDetLayers") << "backDet phi,z,r: "
52  << (*it)->position().phi() << " , "
53  << (*it)->position().z() << " , "
54  << (*it)->position().perp() ;
55  }
56  //-----------------------------------
57 
58 }
59 
60 
61 const vector<const GeometricSearchDet*>&
63  throw DetLayerException("TOBRod doesn't have GeometricSearchDet components");
64 }
65 
66 pair<bool, TrajectoryStateOnSurface>
68  const MeasurementEstimator&) const{
69  edm::LogError("TkDetLayers") << "temporary dummy implementation of PixelBlade::compatible()!!" ;
70  return pair<bool,TrajectoryStateOnSurface>();
71 }
72 
73 
74 
75 void
77  const Propagator& prop,
78  const MeasurementEstimator& est,
79  std::vector<DetGroup> & result) const{
80  SubLayerCrossings crossings;
81  crossings = computeCrossings( tsos, prop.propagationDirection());
82  if(! crossings.isValid()) return;
83 
84  vector<DetGroup> closestResult;
85  addClosest( tsos, prop, est, crossings.closest(), closestResult);
86 
87  if (closestResult.empty()){
88  vector<DetGroup> nextResult;
89  addClosest( tsos, prop, est, crossings.other(), nextResult);
90  if(nextResult.empty()) return;
91 
92  DetGroupElement nextGel( nextResult.front().front());
93  int crossingSide = LayerCrossingSide().endcapSide( nextGel.trajectoryState(), prop);
94 
95  DetGroupMerger::orderAndMergeTwoLevels( std::move(closestResult), std::move(nextResult), result,
96  crossings.closestIndex(), crossingSide);
97  }
98  else {
99  DetGroupElement closestGel( closestResult.front().front());
100  float window = computeWindowSize( closestGel.det(), closestGel.trajectoryState(), est);
101 
102  searchNeighbors( tsos, prop, est, crossings.closest(), window,
103  closestResult, false);
104 
105  vector<DetGroup> nextResult;
106  searchNeighbors( tsos, prop, est, crossings.other(), window,
107  nextResult, true);
108 
109  int crossingSide = LayerCrossingSide().endcapSide( closestGel.trajectoryState(), prop);
110  DetGroupMerger::orderAndMergeTwoLevels( std::move(closestResult), std::move(nextResult), result,
111  crossings.closestIndex(), crossingSide);
112  }
113 }
114 
117  PropagationDirection propDir) const
118 {
119  HelixPlaneCrossing::PositionType startPos( startingState.globalPosition());
120  HelixPlaneCrossing::DirectionType startDir( startingState.globalMomentum());
121  double rho( startingState.transverseCurvature());
122 
123  HelixArbitraryPlaneCrossing crossing( startPos, startDir, rho, propDir);
124 
125  pair<bool,double> innerPath = crossing.pathLength( *theFrontDiskSector);
126  if (!innerPath.first) return SubLayerCrossings();
127 
128  GlobalPoint gInnerPoint( crossing.position(innerPath.second));
129  //Code for use of binfinder
130  //int innerIndex = theInnerBinFinder.binIndex(gInnerPoint.perp());
131  //float innerDist = std::abs( theInnerBinFinder.binPosition(innerIndex) - gInnerPoint.z());
132  int innerIndex = findBin(gInnerPoint.perp(),0);
133  float innerDist = std::abs( findPosition(innerIndex,0).perp() - gInnerPoint.perp());
134  SubLayerCrossing innerSLC( 0, innerIndex, gInnerPoint);
135 
136  pair<bool,double> outerPath = crossing.pathLength( *theBackDiskSector);
137  if (!outerPath.first) return SubLayerCrossings();
138 
139  GlobalPoint gOuterPoint( crossing.position(outerPath.second));
140  //Code for use of binfinder
141  //int outerIndex = theOuterBinFinder.binIndex(gOuterPoint.perp());
142  //float outerDist = std::abs( theOuterBinFinder.binPosition(outerIndex) - gOuterPoint.perp());
143  int outerIndex = findBin(gOuterPoint.perp(),1);
144  float outerDist = std::abs( findPosition(outerIndex,1).perp() - gOuterPoint.perp());
145  SubLayerCrossing outerSLC( 1, outerIndex, gOuterPoint);
146 
147  if (innerDist < outerDist) {
148  return SubLayerCrossings( innerSLC, outerSLC, 0);
149  }
150  else {
151  return SubLayerCrossings( outerSLC, innerSLC, 1);
152  }
153 }
154 
155 
156 
157 
158 bool
160  const Propagator& prop,
161  const MeasurementEstimator& est,
162  const SubLayerCrossing& crossing,
163  vector<DetGroup>& result) const
164 {
165 
166  const vector<const GeomDet*>& sBlade( subBlade( crossing.subLayerIndex()));
167  return CompatibleDetToGroupAdder().add( *sBlade[crossing.closestDetIndex()],
168  tsos, prop, est, result);
169 }
170 
171 
173  const TrajectoryStateOnSurface& tsos,
174  const MeasurementEstimator& est) const
175 {
176  return
177  est.maximalLocalDisplacement(tsos, det->surface()).x();
178 }
179 
180 
181 
182 
184  const Propagator& prop,
185  const MeasurementEstimator& est,
186  const SubLayerCrossing& crossing,
187  float window,
188  vector<DetGroup>& result,
189  bool checkClosest) const
190 {
191  GlobalPoint gCrossingPos = crossing.position();
192 
193  const vector<const GeomDet*>& sBlade( subBlade( crossing.subLayerIndex()));
194 
195  int closestIndex = crossing.closestDetIndex();
196  int negStartIndex = closestIndex-1;
197  int posStartIndex = closestIndex+1;
198 
199  if (checkClosest) { // must decide if the closest is on the neg or pos side
200  if (gCrossingPos.perp() < sBlade[closestIndex]->surface().position().perp()) {
201  posStartIndex = closestIndex;
202  }
203  else {
204  negStartIndex = closestIndex;
205  }
206  }
207 
208  typedef CompatibleDetToGroupAdder Adder;
209  for (int idet=negStartIndex; idet >= 0; idet--) {
210  if (!overlap( gCrossingPos, *sBlade[idet], window)) break;
211  if (!Adder::add( *sBlade[idet], tsos, prop, est, result)) break;
212  }
213  for (int idet=posStartIndex; idet < static_cast<int>(sBlade.size()); idet++) {
214  if (!overlap( gCrossingPos, *sBlade[idet], window)) break;
215  if (!Adder::add( *sBlade[idet], tsos, prop, est, result)) break;
216  }
217 }
218 
219 
220 
221 bool PixelBlade::overlap( const GlobalPoint& crossPoint, const GeomDet& det, float window) const
222 {
223  // check if the z window around TSOS overlaps with the detector theDet (with a 1% margin added)
224 
225  // const float tolerance = 0.1;
226  const float relativeMargin = 1.01;
227 
228  LocalPoint localCrossPoint( det.surface().toLocal(crossPoint));
229  // if (std::abs(localCrossPoint.z()) > tolerance) {
230  // edm::LogInfo(TkDetLayers) << "PixelBlade::overlap calculation assumes point on surface, but it is off by "
231  // << localCrossPoint.z() ;
232  // }
233 
234  float localX = localCrossPoint.x();
235  float detHalfLength = det.surface().bounds().length()/2.;
236 
237  // edm::LogInfo(TkDetLayers) << "PixelBlade::overlap: Det at " << det.position() << " hit at " << localY
238  // << " Window " << window << " halflength " << detHalfLength ;
239 
240  if ( ( std::abs(localX)-window) < relativeMargin*detHalfLength ) { // FIXME: margin hard-wired!
241  return true;
242  } else {
243  return false;
244  }
245 }
246 
247 int
248 PixelBlade::findBin( float R,int diskSectorIndex) const
249 {
250  vector<const GeomDet*> localDets = diskSectorIndex==0 ? theFrontDets : theBackDets;
251 
252  int theBin = 0;
253  float rDiff = std::abs( R - localDets.front()->surface().position().perp());;
254  for (vector<const GeomDet*>::const_iterator i=localDets.begin(); i !=localDets.end(); i++){
255  float testDiff = std::abs( R - (**i).surface().position().perp());
256  if ( testDiff < rDiff) {
257  rDiff = testDiff;
258  theBin = i - localDets.begin();
259  }
260  }
261  return theBin;
262 }
263 
264 
265 
267 PixelBlade::findPosition(int index,int diskSectorType) const
268 {
269  vector<const GeomDet*> diskSector = diskSectorType == 0 ? theFrontDets : theBackDets;
270  return (diskSector[index])->surface().position();
271 }
272 
#define LogDebug(id)
Common base class.
virtual float length() const =0
ReferenceCountingPointer< BoundDiskSector > theFrontDiskSector
Definition: PixelBlade.h:89
T perp() const
Definition: PV3DBase.h:72
ReferenceCountingPointer< BoundDiskSector > theBackDiskSector
Definition: PixelBlade.h:90
int closestIndex() const
int closestDetIndex() const
bool addClosest(const TrajectoryStateOnSurface &tsos, const Propagator &prop, const MeasurementEstimator &est, const SubLayerCrossing &crossing, std::vector< DetGroup > &result) const __attribute__((hot))
Definition: PixelBlade.cc:159
GlobalPoint globalPosition() const
const Bounds & bounds() const
Definition: Surface.h:120
float computeWindowSize(const GeomDet *det, const TrajectoryStateOnSurface &tsos, const MeasurementEstimator &est) const
Definition: PixelBlade.cc:172
PropagationDirection
std::vector< const GeomDet * > theFrontDets
Definition: PixelBlade.h:85
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:42
GlobalPoint findPosition(int index, int diskSectorIndex) const
Definition: PixelBlade.cc:267
~PixelBlade() __attribute__((cold))
Definition: PixelBlade.cc:18
std::vector< const GeomDet * > theBackDets
Definition: PixelBlade.h:86
const std::vector< const GeomDet * > & subBlade(int ind) const
Definition: PixelBlade.h:77
const GlobalPoint & position() const
bool overlap(const GlobalPoint &gpos, const GeomDet &det, float phiWin) const
Definition: PixelBlade.cc:221
int findBin(float R, int layer) const
Definition: PixelBlade.cc:248
virtual PropagationDirection propagationDirection() const final
Definition: Propagator.h:151
LocalPoint toLocal(const GlobalPoint &gp) const
int subLayerIndex() const
T z() const
Definition: PV3DBase.h:64
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
static int endcapSide(const TrajectoryStateOnSurface &startingState, const Propagator &prop)
def window(xmin, xmax, ymin, ymax, x=0, y=0, width=100, height=100, xlogbase=None, ylogbase=None, minusInfinity=-1000, flipx=False, flipy=True)
Definition: svgfig.py:642
PixelBlade(std::vector< const GeomDet * > &frontDets, std::vector< const GeomDet * > &backDets) __attribute__((cold))
Definition: PixelBlade.cc:20
std::pair< bool, TrajectoryStateOnSurface > compatible(const TrajectoryStateOnSurface &ts, const Propagator &, const MeasurementEstimator &) const __attribute__((cold))
Definition: PixelBlade.cc:67
const SubLayerCrossing & other() const
static bool add(const GeometricSearchDet &det, const TrajectoryStateOnSurface &tsos, const Propagator &prop, const MeasurementEstimator &est, std::vector< DetGroup > &result) __attribute__((hot))
void add(std::map< std::string, TH1 * > &h, TH1 *hist)
static BoundDiskSector * build(const std::vector< const GeomDet * > &dets) __attribute__((cold))
virtual const Surface::PositionType & position() const
Returns position of the surface.
virtual const std::vector< const GeometricSearchDet * > & components() const __attribute__((cold))
Returns basic components, if any.
Definition: PixelBlade.cc:62
std::vector< const GeomDet * > theDets
Definition: PixelBlade.h:84
const SubLayerCrossing & closest() const
T perp() const
Magnitude of transverse component.
GlobalVector globalMomentum() const
virtual Local2DVector maximalLocalDisplacement(const TrajectoryStateOnSurface &ts, const Plane &plane) const =0
std::pair< const GeomDet *, TrajectoryStateOnSurface > DetWithState
static void orderAndMergeTwoLevels(std::vector< DetGroup > &&one, std::vector< DetGroup > &&two, std::vector< DetGroup > &result, int firstIndex, int firstCrossed)
virtual void groupedCompatibleDetsV(const TrajectoryStateOnSurface &tsos, const Propagator &prop, const MeasurementEstimator &est, std::vector< DetGroup > &result) const __attribute__((hot))
Definition: PixelBlade.cc:76
T x() const
Definition: PV3DBase.h:62
ReferenceCountingPointer< BoundDiskSector > theDiskSector
Definition: PixelBlade.h:88
SubLayerCrossings computeCrossings(const TrajectoryStateOnSurface &tsos, PropagationDirection propDir) const __attribute__((hot))
Definition: PixelBlade.cc:116
def move(src, dest)
Definition: eostools.py:510
void searchNeighbors(const TrajectoryStateOnSurface &tsos, const Propagator &prop, const MeasurementEstimator &est, const SubLayerCrossing &crossing, float window, std::vector< DetGroup > &result, bool checkClosest) const __attribute__((hot))
Definition: PixelBlade.cc:183
GeometricSearchDet::DetWithState DetWithState
Definition: PixelBlade.cc:16