CMS 3D CMS Logo

TIBRing.cc
Go to the documentation of this file.
1 #include "TIBRing.h"
2 
4 
12 
13 #include "LayerCrossingSide.h"
14 #include "DetGroupMerger.h"
16 
17 using namespace std;
18 
20 
21 TIBRing::TIBRing(vector<const GeomDet*>& theGeomDets)
22  : GeometricSearchDet(true), theDets(theGeomDets.begin(), theGeomDets.end()) {
23  //checkRadius( first, last);
24  //sort( theDets.begin(), theDets.end(), DetLessPhi());
25  //checkPeriodicity( theDets.begin(), theDets.end());
26 
27  theBinFinder = BinFinderType(theDets.front()->surface().position().phi(), theDets.size());
28 
30 
32 
33  LogDebug("TkDetLayers") << "==== DEBUG TIBRing =====";
34  LogDebug("TkDetLayers") << "radius, thickness, lenght: " << theCylinder->radius() << " , "
35  << theCylinder->bounds().thickness() << " , " << theCylinder->bounds().length();
36 
37  for (vector<const GeomDet*>::const_iterator i = theDets.begin(); i != theDets.end(); i++) {
38  LogDebug("TkDetLayers") << "Ring's Det pos z,perp,eta,phi: " << (**i).position().z() << " , "
39  << (**i).position().perp() << " , " << (**i).position().eta() << " , "
40  << (**i).position().phi();
41  }
42  LogDebug("TkDetLayers") << "==== end DEBUG TIBRing =====";
43 }
44 
45 const vector<const GeometricSearchDet*>& TIBRing::components() const {
46  throw DetLayerException("TIBRing doesn't have GeometricSearchDet components");
47 }
48 
49 void TIBRing::checkRadius(vector<const GeomDet*>::const_iterator first, vector<const GeomDet*>::const_iterator last) {
50  // check radius range
51  float rMin = 10000.;
52  float rMax = 0.;
53  for (vector<const GeomDet*>::const_iterator i = first; i != last; i++) {
54  float r = (**i).surface().position().perp();
55  if (r < rMin)
56  rMin = r;
57  if (r > rMax)
58  rMax = r;
59  }
60  if (rMax - rMin > 0.1)
61  throw DetLayerException("TIBRing construction failed: detectors not at constant radius");
62 }
63 
64 void TIBRing::checkPeriodicity(vector<const GeomDet*>::const_iterator first,
65  vector<const GeomDet*>::const_iterator last) {
66  vector<double> adj_diff(last - first - 1);
67  for (int i = 0; i < static_cast<int>(adj_diff.size()); i++) {
68  vector<const GeomDet*>::const_iterator curent = first + i;
69  adj_diff[i] = (**(curent + 1)).surface().position().phi() - (**curent).surface().position().phi();
70  }
71  double step = stat_mean(adj_diff);
72  double phi_step = 2. * Geom::pi() / (last - first);
73 
74  if (std::abs(step - phi_step) / phi_step > 0.01) {
75  int ndets = last - first;
76  edm::LogError("TkDetLayers") << "TIBRing Warning: not periodic. ndets=" << ndets;
77  for (int j = 0; j < ndets; j++) {
78  edm::LogError("TkDetLayers") << "Dets(r,phi): (" << theDets[j]->surface().position().perp() << ","
79  << theDets[j]->surface().position().phi() << ") ";
80  }
81  throw DetLayerException("Error: TIBRing is not periodic");
82  }
83 }
84 
86  const GeomDet& det = *theDets.front();
87  GlobalVector radial = det.surface().position() - GlobalPoint(0, 0, 0);
88  GlobalVector normal = det.surface().toGlobal(LocalVector(0, 0, 1));
89  if (normal.dot(radial) <= 0)
90  normal *= -1;
91  // edm::LogInfo(TkDetLayers) << "BarrelDetRing::computeHelicity: phi(normal) " << normal.phi()
92  // << " phi(radial) " << radial.phi() ;
93  if (Geom::phiLess(normal.phi(), radial.phi())) {
94  theHelicity = 1; // smaller phi angles mean "inner" group
95  } else {
96  theHelicity = 0; // smaller phi angles mean "outer" group
97  }
98 }
99 
101 
102 pair<bool, TrajectoryStateOnSurface> TIBRing::compatible(const TrajectoryStateOnSurface& ts,
103  const Propagator&,
104  const MeasurementEstimator&) const {
105  edm::LogError("TkDetLayers") << "temporary dummy implementation of TIBRing::compatible()!!";
106  return pair<bool, TrajectoryStateOnSurface>();
107 }
108 
110  const Propagator& prop,
111  const MeasurementEstimator& est,
112  vector<DetGroup>& result) const {
113  vector<DetGroup> closestResult;
114  SubRingCrossings crossings;
115  crossings = computeCrossings(tsos, prop.propagationDirection());
116  if (!crossings.isValid_)
117  return;
118 
119  typedef CompatibleDetToGroupAdder Adder;
120  Adder::add(*theDets[theBinFinder.binIndex(crossings.closestIndex)], tsos, prop, est, closestResult);
121 
122  if (closestResult.empty()) {
123  Adder::add(*theDets[theBinFinder.binIndex(crossings.nextIndex)], tsos, prop, est, result);
124  return;
125  }
126 
127  DetGroupElement closestGel(closestResult.front().front());
128  float window = computeWindowSize(closestGel.det(), closestGel.trajectoryState(), est);
129 
130  float detWidth = closestGel.det()->surface().bounds().width();
131  if (crossings.nextDistance < detWidth + window) {
132  vector<DetGroup> nextResult;
133  if (Adder::add(*theDets[theBinFinder.binIndex(crossings.nextIndex)], tsos, prop, est, nextResult)) {
134  int crossingSide = LayerCrossingSide::barrelSide(tsos, prop);
135  if (crossings.closestIndex < crossings.nextIndex) {
137  std::move(closestResult), std::move(nextResult), result, theHelicity, crossingSide);
138  } else {
140  std::move(nextResult), std::move(closestResult), result, theHelicity, crossingSide);
141  }
142  } else {
143  result.swap(closestResult);
144  }
145  } else {
146  result.swap(closestResult);
147  }
148 
149  // only loop over neighbors (other than closest and next) if window is BIG
150  if (window > 0.5f * detWidth) {
151  searchNeighbors(tsos, prop, est, crossings, window, result);
152  }
153 }
154 
156  const Propagator& prop,
157  const MeasurementEstimator& est,
158  const SubRingCrossings& crossings,
159  float window,
160  vector<DetGroup>& result) const {
161  typedef CompatibleDetToGroupAdder Adder;
162  int crossingSide = LayerCrossingSide::barrelSide(tsos, prop);
163  typedef DetGroupMerger Merger;
164 
165  int negStart = std::min(crossings.closestIndex, crossings.nextIndex) - 1;
166  int posStart = std::max(crossings.closestIndex, crossings.nextIndex) + 1;
167 
168  int quarter = theDets.size() / 4;
169  for (int idet = negStart; idet >= negStart - quarter + 1; idet--) {
170  const GeomDet* neighbor = theDets[theBinFinder.binIndex(idet)];
171  // if (!overlap( gCrossingPos, *neighbor, window)) break; // mybe not needed?
172  // maybe also add shallow crossing angle test here???
173  vector<DetGroup> tmp1;
174  if (!Adder::add(*neighbor, tsos, prop, est, tmp1))
175  break;
176  vector<DetGroup> tmp2;
177  tmp2.swap(result);
178  vector<DetGroup> newResult;
179  Merger::orderAndMergeTwoLevels(std::move(tmp1), std::move(tmp2), newResult, theHelicity, crossingSide);
180  result.swap(newResult);
181  }
182  for (int idet = posStart; idet < posStart + quarter - 1; idet++) {
183  const GeomDet* neighbor = theDets[theBinFinder.binIndex(idet)];
184  // if (!overlap( gCrossingPos, *neighbor, window)) break; // mybe not needed?
185  // maybe also add shallow crossing angle test here???
186  vector<DetGroup> tmp1;
187  if (!Adder::add(*neighbor, tsos, prop, est, tmp1))
188  break;
189  vector<DetGroup> tmp2;
190  tmp2.swap(result);
191  vector<DetGroup> newResult;
192  Merger::orderAndMergeTwoLevels(std::move(tmp2), std::move(tmp1), newResult, theHelicity, crossingSide);
193  result.swap(newResult);
194  }
195 }
196 
198  PropagationDirection propDir) const {
199  typedef HelixBarrelPlaneCrossing2OrderLocal Crossing;
201 
202  GlobalPoint startPos(startingState.globalPosition());
203  GlobalVector startDir(startingState.globalMomentum());
204  auto rho = startingState.transverseCurvature();
205 
206  HelixBarrelCylinderCrossing cylCrossing(
207  startPos, startDir, rho, propDir, specificSurface(), HelixBarrelCylinderCrossing::bestSol);
208 
209  if (!cylCrossing.hasSolution())
210  return SubRingCrossings();
211 
212  GlobalPoint cylPoint(cylCrossing.position());
213  GlobalVector cylDir(cylCrossing.direction());
214  int closestIndex = theBinFinder.binIndex(cylPoint.barePhi());
215 
216  const Plane& closestPlane(theDets[closestIndex]->surface());
217 
218  LocalPoint closestPos = Crossing::positionOnly(cylPoint, cylDir, rho, closestPlane);
219  float closestDist = closestPos.x(); // use fact that local X perp to global Z
220 
221  //int next = cylPoint.phi() - closestPlane.position().phi() > 0 ? closest+1 : closest-1;
222  int nextIndex =
223  Geom::phiLess(closestPlane.position().barePhi(), cylPoint.barePhi()) ? closestIndex + 1 : closestIndex - 1;
224 
225  const Plane& nextPlane(theDets[theBinFinder.binIndex(nextIndex)]->surface());
226  LocalPoint nextPos = Crossing::positionOnly(cylPoint, cylDir, rho, nextPlane);
227  float nextDist = nextPos.x();
228 
229  if (std::abs(closestDist) < std::abs(nextDist)) {
230  return SubRingCrossings(closestIndex, nextIndex, nextDist);
231  } else {
232  return SubRingCrossings(nextIndex, closestIndex, closestDist);
233  }
234 }
235 
237  const TrajectoryStateOnSurface& tsos,
238  const MeasurementEstimator& est) const {
239  return est.maximalLocalDisplacement(tsos, det->surface()).x();
240 }
Vector3DBase
Definition: Vector3DBase.h:8
TIBRing::checkRadius
void checkRadius(std::vector< const GeomDet * >::const_iterator first, std::vector< const GeomDet * >::const_iterator last) __attribute__((cold))
Definition: TIBRing.cc:49
MeasurementEstimator
Definition: MeasurementEstimator.h:19
HelixBarrelCylinderCrossing.h
photonAnalyzer_cfi.rMax
rMax
Definition: photonAnalyzer_cfi.py:91
mps_fire.i
i
Definition: mps_fire.py:355
HelixBarrelPlaneCrossing2OrderLocal.h
MessageLogger.h
GeomDet
Definition: GeomDet.h:27
LayerCrossingSide.h
step
step
Definition: StallMonitor.cc:94
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
PV3DBase::x
T x() const
Definition: PV3DBase.h:59
min
T min(T a, T b)
Definition: MathUtil.h:58
VectorUtil.h
HelixBarrelCylinderCrossing::hasSolution
bool hasSolution() const
Definition: HelixBarrelCylinderCrossing.h:34
TrajectoryStateOnSurface::globalPosition
GlobalPoint globalPosition() const
Definition: TrajectoryStateOnSurface.h:65
TIBRing::SubRingCrossings::closestIndex
int closestIndex
Definition: TIBRing.h:56
CylinderBuilderFromDet.h
svgfig.window
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:643
simple_stat.h
TrajectoryStateOnSurface::transverseCurvature
double transverseCurvature() const
Definition: TrajectoryStateOnSurface.h:70
DDAxes::x
HLT_2018_cff.Merger
Merger
Definition: HLT_2018_cff.py:5945
dqmdumpme.first
first
Definition: dqmdumpme.py:55
end
#define end
Definition: vmac.h:39
TIBRing::TIBRing
TIBRing(std::vector< const GeomDet * > &theGeomDets) __attribute__((cold))
Definition: TIBRing.cc:21
Propagator
Definition: Propagator.h:44
HelixBarrelCylinderCrossing::bestSol
Definition: HelixBarrelCylinderCrossing.h:18
GeomDet::surface
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
TrajectoryStateOnSurface
Definition: TrajectoryStateOnSurface.h:16
dqmdumpme.last
last
Definition: dqmdumpme.py:56
DetLayerException.h
TIBRing::SubRingCrossings::isValid_
bool isValid_
Definition: TIBRing.h:55
TIBRing::compatible
std::pair< bool, TrajectoryStateOnSurface > compatible(const TrajectoryStateOnSurface &ts, const Propagator &, const MeasurementEstimator &) const override __attribute__((cold))
Definition: TIBRing.cc:102
TIBRing::theBinFinder
BinFinderType theBinFinder
Definition: TIBRing.h:77
MeasurementEstimator.h
Propagator::propagationDirection
virtual PropagationDirection propagationDirection() const final
Definition: Propagator.h:139
Surface::toGlobal
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:79
Geom::pi
constexpr double pi()
Definition: Pi.h:31
Vector2DBase
Definition: Vector2DBase.h:8
CylinderBuilderFromDet
Definition: CylinderBuilderFromDet.h:18
DetGroupMerger.h
GlobalPoint
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
Point3DBase< float, GlobalTag >
DDAxes::rho
DetGroupMerger::orderAndMergeTwoLevels
static void orderAndMergeTwoLevels(std::vector< DetGroup > &&one, std::vector< DetGroup > &&two, std::vector< DetGroup > &result, int firstIndex, int firstCrossed)
Definition: DetGroupMerger.cc:6
HelixBarrelCylinderCrossing::direction
DirectionType direction() const
Definition: HelixBarrelCylinderCrossing.h:61
DetWithState
GeometricSearchDet::DetWithState DetWithState
Definition: TIBRing.cc:19
funct::true
true
Definition: Factorize.h:173
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
edm::LogError
Definition: MessageLogger.h:183
Geom::phiLess
bool phiLess(float phi1, float phi2)
Definition: VectorUtil.h:18
PV3DBase::barePhi
T barePhi() const
Definition: PV3DBase.h:65
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
PVValHelper::add
void add(std::map< std::string, TH1 * > &h, TH1 *hist)
Definition: PVValidationHelpers.cc:12
TIBRing::SubRingCrossings::nextDistance
float nextDistance
Definition: TIBRing.h:58
TIBRing::theCylinder
ReferenceCountingPointer< BoundCylinder > theCylinder
Definition: TIBRing.h:80
LocalVector
Local3DVector LocalVector
Definition: LocalVector.h:12
HelixBarrelCylinderCrossing::position
PositionType position() const
Definition: HelixBarrelCylinderCrossing.h:48
TIBRing::~TIBRing
~TIBRing() override __attribute__((cold))
Definition: TIBRing.cc:100
TIBRing.h
Local2DVector
Vector2DBase< float, LocalTag > Local2DVector
Definition: FourPointPlaneBounds.h:8
DetGroupElement
Definition: DetGroup.h:10
GeometricSearchDet::DetWithState
std::pair< const GeomDet *, TrajectoryStateOnSurface > DetWithState
Definition: GeometricSearchDet.h:19
Vector3DBase::dot
PreciseFloatType< T, U >::Type dot(const Vector3DBase< U, FrameTag > &v) const
Definition: Vector3DBase.h:99
CompatibleDetToGroupAdder.h
TIBRing::theDets
std::vector< const GeomDet * > theDets
Definition: TIBRing.h:79
alignCSCRings.r
r
Definition: alignCSCRings.py:93
DetLayerException
Common base class.
Definition: DetLayerException.h:15
GloballyPositioned::position
const PositionType & position() const
Definition: GloballyPositioned.h:36
TrajectoryStateOnSurface::globalMomentum
GlobalVector globalMomentum() const
Definition: TrajectoryStateOnSurface.h:66
TIBRing::computeCrossings
SubRingCrossings computeCrossings(const TrajectoryStateOnSurface &startingState, PropagationDirection propDir) const __attribute__((hot))
Definition: TIBRing.cc:197
DetGroupMerger
Definition: DetGroupMerger.h:7
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
TIBRing::computeWindowSize
float computeWindowSize(const GeomDet *det, const TrajectoryStateOnSurface &tsos, const MeasurementEstimator &est) const __attribute__((hot))
Definition: TIBRing.cc:236
TIBRing::specificSurface
virtual const BoundCylinder & specificSurface() const
Return the ring surface as a.
Definition: TIBRing.h:37
PropagationDirection
PropagationDirection
Definition: PropagationDirection.h:4
CompatibleDetToGroupAdder
Definition: CompatibleDetToGroupAdder.h:13
Plane
Definition: Plane.h:16
LayerCrossingSide::barrelSide
static int barrelSide(const TrajectoryStateOnSurface &startingState, const Propagator &prop)
returns 0 if barrel layer crossed from inside, 1 if from outside
Definition: LayerCrossingSide.h:18
PeriodicBinFinderInPhi::binIndex
int binIndex(T phi) const override
returns an index in the valid range for the bin that contains phi
Definition: PeriodicBinFinderInPhi.h:25
TIBRing::SubRingCrossings
Definition: TIBRing.h:51
stat_mean
double stat_mean(const CONT &cont)
Definition: simple_stat.h:13
photonAnalyzer_cfi.rMin
rMin
Definition: photonAnalyzer_cfi.py:90
HelixBarrelCylinderCrossing
Definition: HelixBarrelCylinderCrossing.h:16
mps_fire.result
result
Definition: mps_fire.py:303
TIBRing::checkPeriodicity
void checkPeriodicity(std::vector< const GeomDet * >::const_iterator first, std::vector< const GeomDet * >::const_iterator last) __attribute__((cold))
Definition: TIBRing.cc:64
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
TIBRing::surface
const BoundSurface & surface() const override
The surface of the GeometricSearchDet.
Definition: TIBRing.h:18
GeometricSearchDet
Definition: GeometricSearchDet.h:17
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
TIBRing::theHelicity
int theHelicity
Definition: TIBRing.h:81
TIBRing::SubRingCrossings::nextIndex
int nextIndex
Definition: TIBRing.h:57
TIBRing::components
const std::vector< const GeometricSearchDet * > & components() const override __attribute__((cold))
Returns basic components, if any.
Definition: TIBRing.cc:45
TIBRing::groupedCompatibleDetsV
void groupedCompatibleDetsV(const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est, std::vector< DetGroup > &result) const override __attribute__((hot))
Definition: TIBRing.cc:109
HelixBarrelPlaneCrossing2OrderLocal
Definition: HelixBarrelPlaneCrossing2OrderLocal.h:12
TIBRing::searchNeighbors
void searchNeighbors(const TrajectoryStateOnSurface &tsos, const Propagator &prop, const MeasurementEstimator &est, const SubRingCrossings &crossings, float window, std::vector< DetGroup > &result) const __attribute__((hot))
Definition: TIBRing.cc:155
begin
#define begin
Definition: vmac.h:32
PV3DBase::phi
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
TIBRing::BinFinderType
PeriodicBinFinderInPhi< float > BinFinderType
Definition: TIBRing.h:76
MeasurementEstimator::maximalLocalDisplacement
virtual Local2DVector maximalLocalDisplacement(const TrajectoryStateOnSurface &ts, const Plane &plane) const =0
TIBRing::computeHelicity
void computeHelicity() __attribute__((cold))
Definition: TIBRing.cc:85