CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TIBRing.cc
Go to the documentation of this file.
2 
4 
12 
16 
17 using namespace std;
18 
20 
21 TIBRing::TIBRing(vector<const GeomDet*>& theGeomDets):
22  theDets(theGeomDets.begin(),theGeomDets.end())
23 {
24  //checkRadius( first, last);
25  //sort( theDets.begin(), theDets.end(), DetLessPhi());
26  //checkPeriodicity( theDets.begin(), theDets.end());
27 
28  theBinFinder = BinFinderType( theDets.front()->surface().position().phi(),
29  theDets.size());
30 
32 
34 
35 
36  LogDebug("TkDetLayers") << "==== DEBUG TIBRing =====" ;
37  LogDebug("TkDetLayers") << "radius, thickness, lenght: "
38  << theCylinder->radius() << " , "
39  << theCylinder->bounds().thickness() << " , "
40  << theCylinder->bounds().length() ;
41 
42  for (vector<const GeomDet*>::const_iterator i=theDets.begin();
43  i != theDets.end(); i++){
44  LogDebug("TkDetLayers") << "Ring's Det pos z,perp,eta,phi: "
45  << (**i).position().z() << " , "
46  << (**i).position().perp() << " , "
47  << (**i).position().eta() << " , "
48  << (**i).position().phi() ;
49  }
50  LogDebug("TkDetLayers") << "==== end DEBUG TIBRing =====" ;
51 
52 
53 }
54 
55 
56 const vector<const GeometricSearchDet*>&
58 {
59  throw DetLayerException("TIBRing doesn't have GeometricSearchDet components");
60 }
61 
62 void TIBRing::checkRadius(vector<const GeomDet*>::const_iterator first,
63  vector<const GeomDet*>::const_iterator last)
64 {
65  // check radius range
66  float rMin = 10000.;
67  float rMax = 0.;
68  for (vector<const GeomDet*>::const_iterator i=first; i!=last; i++) {
69  float r = (**i).surface().position().perp();
70  if (r < rMin) rMin = r;
71  if (r > rMax) rMax = r;
72  }
73  if (rMax - rMin > 0.1) throw DetLayerException(
74  "TIBRing construction failed: detectors not at constant radius");
75 }
76 
77 
78 void TIBRing::checkPeriodicity(vector<const GeomDet*>::const_iterator first,
79  vector<const GeomDet*>::const_iterator last)
80 {
81  vector<double> adj_diff(last-first-1);
82  for (int i=0; i < static_cast<int>(adj_diff.size()); i++) {
83  vector<const GeomDet*>::const_iterator curent = first + i;
84  adj_diff[i] = (**(curent+1)).surface().position().phi() -
85  (**curent).surface().position().phi();
86  }
87  double step = stat_mean( adj_diff);
88  double phi_step = 2.*Geom::pi()/(last-first);
89 
90  if ( fabs(step-phi_step)/phi_step > 0.01) {
91  int ndets = last-first;
92  edm::LogError("TkDetLayers") << "TIBRing Warning: not periodic. ndets=" << ndets ;
93  for (int j=0; j<ndets; j++) {
94  edm::LogError("TkDetLayers") << "Dets(r,phi): (" << theDets[j]->surface().position().perp()
95  << "," << theDets[j]->surface().position().phi() << ") " ;
96  }
97  throw DetLayerException( "Error: TIBRing is not periodic");
98  }
99 }
100 
102 
103  const GeomDet& det = *theDets.front();
104  GlobalVector radial = det.surface().position() - GlobalPoint(0,0,0);
105  GlobalVector normal = det.surface().toGlobal( LocalVector(0,0,1));
106  if(normal.dot(radial)<=0)normal*=-1;
107 // edm::LogInfo(TkDetLayers) << "BarrelDetRing::computeHelicity: phi(normal) " << normal.phi()
108 // << " phi(radial) " << radial.phi() ;
109  if (PhiLess()( normal.phi(), radial.phi())) {
110  theHelicity = 1; // smaller phi angles mean "inner" group
111  }
112  else {
113  theHelicity = 0; // smaller phi angles mean "outer" group
114  }
115 }
116 
117 
119 
120 }
121 
122 
123 pair<bool, TrajectoryStateOnSurface>
125  const MeasurementEstimator&) const{
126  edm::LogError("TkDetLayers") << "temporary dummy implementation of TIBRing::compatible()!!" ;
127  return pair<bool,TrajectoryStateOnSurface>();
128 }
129 
130 
131 void
133  const Propagator& prop,
134  const MeasurementEstimator& est,
135  vector<DetGroup> & result) const
136 {
137  vector<DetGroup> closestResult;
138  SubRingCrossings crossings;
139  crossings = computeCrossings( tsos, prop.propagationDirection());
140  if(! crossings.isValid_) return;
141 
142  typedef CompatibleDetToGroupAdder Adder;
144  tsos, prop, est, closestResult);
145 
146  if(closestResult.empty()){
148  tsos, prop, est, result);
149  return;
150  }
151 
152  DetGroupElement closestGel( closestResult.front().front());
153  float window = computeWindowSize( closestGel.det(), closestGel.trajectoryState(), est);
154 
155  //vector<DetGroup> result;
156  float detWidth = closestGel.det()->surface().bounds().width();
157  if (crossings.nextDistance < detWidth + window) {
158  vector<DetGroup> nextResult;
159  if (Adder::add( *theDets[theBinFinder.binIndex(crossings.nextIndex)],
160  tsos, prop, est, nextResult)) {
161  int crossingSide = LayerCrossingSide().barrelSide( tsos, prop);
162  if (crossings.closestIndex < crossings.nextIndex) {
163  DetGroupMerger::orderAndMergeTwoLevels( closestResult, nextResult,
164  result,
165  theHelicity, crossingSide);
166  }
167  else {
168  DetGroupMerger::orderAndMergeTwoLevels( nextResult, closestResult,
169  result,
170  theHelicity, crossingSide);
171  }
172  }
173  else {
174  result.swap(closestResult);
175  }
176  }else{
177  result.swap(closestResult);
178  }
179 
180  // only loop over neighbors (other than closest and next) if window is BIG
181  if (window > 0.5*detWidth) {
182  searchNeighbors( tsos, prop, est, crossings, window, result);
183  }
184 }
185 
187  const Propagator& prop,
188  const MeasurementEstimator& est,
189  const SubRingCrossings& crossings,
190  float window,
191  vector<DetGroup>& result) const
192 {
193  typedef CompatibleDetToGroupAdder Adder;
194  int crossingSide = LayerCrossingSide().barrelSide( tsos, prop);
195  typedef DetGroupMerger Merger;
196 
197  int negStart = min( crossings.closestIndex, crossings.nextIndex) - 1;
198  int posStart = max( crossings.closestIndex, crossings.nextIndex) + 1;
199 
200  int quarter = theDets.size()/4;
201  vector<DetGroup> tmp;
202  vector<DetGroup> newResult;
203  for (int idet=negStart; idet >= negStart - quarter+1; idet--) {
204  const GeomDet* neighbor = theDets[theBinFinder.binIndex(idet)];
205  // if (!overlap( gCrossingPos, *neighbor, window)) break; // mybe not needed?
206  // maybe also add shallow crossing angle test here???
207  tmp.clear();
208  newResult.clear();
209  if (!Adder::add( *neighbor, tsos, prop, est, tmp)) break;
210  Merger::orderAndMergeTwoLevels( tmp, result, newResult, theHelicity, crossingSide);
211  result.swap(newResult);
212  }
213  for (int idet=posStart; idet < posStart + quarter-1; idet++) {
214  const GeomDet* neighbor = theDets[theBinFinder.binIndex(idet)];
215  // if (!overlap( gCrossingPos, *neighbor, window)) break; // mybe not needed?
216  // maybe also add shallow crossing angle test here???
217  tmp.clear();
218  newResult.clear();
219  if (!Adder::add( *neighbor, tsos, prop, est, tmp)) break;
220  Merger::orderAndMergeTwoLevels( result, tmp, newResult, theHelicity, crossingSide);
221  result.swap(newResult);
222  }
223 }
224 
225 
228  PropagationDirection propDir) const
229 {
230  typedef HelixBarrelPlaneCrossing2OrderLocal Crossing;
232 
233  GlobalPoint startPos( startingState.globalPosition());
234  GlobalVector startDir( startingState.globalMomentum());
235  double rho( startingState.transverseCurvature());
236 
237  HelixBarrelCylinderCrossing cylCrossing( startPos, startDir, rho,
238  propDir,specificSurface());
239 
240  if (!cylCrossing.hasSolution()) return SubRingCrossings();
241 
242  GlobalPoint cylPoint( cylCrossing.position());
243  GlobalVector cylDir( cylCrossing.direction());
244  int closestIndex = theBinFinder.binIndex(cylPoint.phi());
245 
246  const BoundPlane& closestPlane( theDets[closestIndex]->surface());
247 
248  LocalPoint closestPos = Crossing( cylPoint, cylDir, rho, closestPlane).position();
249  float closestDist = closestPos.x(); // use fact that local X perp to global Z
250 
251  //int next = cylPoint.phi() - closestPlane.position().phi() > 0 ? closest+1 : closest-1;
252  int nextIndex = PhiLess()( closestPlane.position().phi(), cylPoint.phi()) ?
253  closestIndex+1 : closestIndex-1;
254 
255  const BoundPlane& nextPlane( theDets[ theBinFinder.binIndex(nextIndex)]->surface());
256  LocalPoint nextPos = Crossing( cylPoint, cylDir, rho, nextPlane).position();
257  float nextDist = nextPos.x();
258 
259  if (fabs(closestDist) < fabs(nextDist)) {
260  return SubRingCrossings( closestIndex, nextIndex, nextDist);
261  }
262  else {
263  return SubRingCrossings( nextIndex, closestIndex, closestDist);
264  }
265 }
266 
268  const TrajectoryStateOnSurface& tsos,
269  const MeasurementEstimator& est) const
270 {
271  return est.maximalLocalDisplacement(tsos, det->surface()).x();
272 }
273 
274 
275 
#define LogDebug(id)
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:78
Common base class.
int i
Definition: DBlmapReader.cc:9
static void orderAndMergeTwoLevels(const std::vector< DetGroup > &one, const std::vector< DetGroup > &two, std::vector< DetGroup > &result, int firstIndex, int firstCrossed)
def window
Definition: svgfig.py:642
Local3DVector LocalVector
Definition: LocalVector.h:12
virtual const std::vector< const GeometricSearchDet * > & components() const
Returns basic components, if any.
Definition: TIBRing.cc:57
BinFinderType theBinFinder
Definition: TIBRing.h:86
virtual const BoundSurface & surface() const
The surface of the GeometricSearchDet.
Definition: TIBRing.h:18
virtual PropagationDirection propagationDirection() const
Definition: Propagator.h:143
PeriodicBinFinderInPhi< double > BinFinderType
Definition: TIBRing.h:85
Definition: DDAxes.h:10
Geom::Phi< T > phi() const
Definition: PV3DBase.h:63
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
std::vector< const GeomDet * > theDets
Definition: TIBRing.h:88
GlobalPoint globalPosition() const
void add(const std::vector< const T * > &source, std::vector< const T * > &dest)
PreciseFloatType< T, U >::Type dot(const Vector3DBase< U, FrameTag > &v) const
Definition: Vector3DBase.h:107
void checkRadius(std::vector< const GeomDet * >::const_iterator first, std::vector< const GeomDet * >::const_iterator last)
Definition: TIBRing.cc:62
#define min(a, b)
Definition: mlp_lapack.h:161
Vector2DBase< float, LocalTag > Local2DVector
PropagationDirection
virtual Local2DVector maximalLocalDisplacement(const TrajectoryStateOnSurface &ts, const BoundPlane &plane) const
double stat_mean(const CONT &cont)
Definition: simple_stat.h:9
virtual int binIndex(T phi) const
returns an index in the valid range for the bin that contains phi
ReferenceCountingPointer< BoundCylinder > theCylinder
Definition: TIBRing.h:89
void searchNeighbors(const TrajectoryStateOnSurface &tsos, const Propagator &prop, const MeasurementEstimator &est, const SubRingCrossings &crossings, float window, std::vector< DetGroup > &result) const
Definition: TIBRing.cc:186
void checkPeriodicity(std::vector< const GeomDet * >::const_iterator first, std::vector< const GeomDet * >::const_iterator last)
Definition: TIBRing.cc:78
int theHelicity
Definition: TIBRing.h:90
const T & max(const T &a, const T &b)
virtual std::pair< bool, TrajectoryStateOnSurface > compatible(const TrajectoryStateOnSurface &ts, const Propagator &, const MeasurementEstimator &) const
Definition: TIBRing.cc:124
tuple result
Definition: query.py:137
TIBRing(std::vector< const GeomDet * > &theGeomDets)
Definition: TIBRing.cc:21
int j
Definition: DBlmapReader.cc:9
#define end
Definition: vmac.h:38
bool first
Definition: L1TdeRCT.cc:79
float computeWindowSize(const GeomDet *det, const TrajectoryStateOnSurface &tsos, const MeasurementEstimator &est) const
Definition: TIBRing.cc:267
void computeHelicity()
Definition: TIBRing.cc:101
SubRingCrossings computeCrossings(const TrajectoryStateOnSurface &startingState, PropagationDirection propDir) const
Definition: TIBRing.cc:227
~TIBRing()
Definition: TIBRing.cc:118
virtual const BoundCylinder & specificSurface() const
Return the ring surface as a.
Definition: TIBRing.h:40
int barrelSide(const TrajectoryStateOnSurface &startingState, const Propagator &prop) const
returns 0 if barrel layer crossed from inside, 1 if from outside
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
#define begin
Definition: vmac.h:31
GlobalVector globalMomentum() const
double pi()
Definition: Pi.h:31
std::pair< const GeomDet *, TrajectoryStateOnSurface > DetWithState
std::pair< const GeomDet *, TrajectoryStateOnSurface > DetWithState
virtual void groupedCompatibleDetsV(const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est, std::vector< DetGroup > &result) const
Definition: TIBRing.cc:132
T x() const
Definition: PV3DBase.h:56
const PositionType & position() const
virtual const BoundPlane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37