CMS 3D CMS Logo

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