/
MTDDetTray.cc
144 lines (119 loc) · 5.74 KB
/
MTDDetTray.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
//#define EDM_ML_DEBUG
/** \file
*
* \author L. Gray - FNAL
*/
#include "RecoMTD/DetLayers/interface/MTDDetTray.h"
#include "Geometry/CommonDetUnit/interface/GeomDet.h"
#include "TrackingTools/GeomPropagators/interface/Propagator.h"
#include "TrackingTools/DetLayers/interface/MeasurementEstimator.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include <iostream>
using namespace std;
MTDDetTray::MTDDetTray(vector<const GeomDet*>::const_iterator first, vector<const GeomDet*>::const_iterator last)
: DetRodOneR(first, last) {
init();
}
MTDDetTray::MTDDetTray(const vector<const GeomDet*>& vdets) : DetRodOneR(vdets) { init(); }
void MTDDetTray::init() { theBinFinder = BinFinderType(basicComponents().begin(), basicComponents().end()); }
MTDDetTray::~MTDDetTray() {}
const vector<const GeometricSearchDet*>& MTDDetTray::components() const {
// FIXME dummy impl.
edm::LogError("MTDDetLayers") << "temporary dummy implementation of MTDDetTray::components()!!";
static const vector<const GeometricSearchDet*> result;
return result;
}
pair<bool, TrajectoryStateOnSurface> MTDDetTray::compatible(const TrajectoryStateOnSurface& ts,
const Propagator& prop,
const MeasurementEstimator& est) const {
TrajectoryStateOnSurface ms = prop.propagate(ts, specificSurface());
return make_pair(ms.isValid() and est.estimate(ms, specificSurface()) != 0, ms);
}
vector<GeometricSearchDet::DetWithState> MTDDetTray::compatibleDets(const TrajectoryStateOnSurface& startingState,
const Propagator& prop,
const MeasurementEstimator& est) const {
LogTrace("MTDDetLayers") << "MTDDetTray::compatibleDets, Surface at R,phi: " << surface().position().perp() << ","
<< surface().position().phi() << " DetRod pos."
<< " TS at R,phi: " << startingState.globalPosition().perp() << ","
<< startingState.globalPosition().phi() << " TSOS dx/dy "
<< std::sqrt(startingState.localError().positionError().xx()) << " "
<< std::sqrt(startingState.localError().positionError().yy());
vector<DetWithState> result;
// Propagate and check that the result is within bounds
pair<bool, TrajectoryStateOnSurface> compat = compatible(startingState, prop, est);
if (!compat.first) {
LogTrace("MTDDetLayers") << " MTDDetTray::compatibleDets: not compatible"
<< " (should not have been selected!)";
return result;
}
// Find the most probable destination component
TrajectoryStateOnSurface& tsos = compat.second;
GlobalPoint startPos = tsos.globalPosition();
int closest = theBinFinder.binIndex(startPos.z());
const vector<const GeomDet*> dets = basicComponents();
LogTrace("MTDDetLayers") << " MTDDetTray::compatibleDets, closest det: " << closest
<< " pos: " << dets[closest]->surface().position() << " impact " << startPos;
// Add this detector, if it is compatible
// NOTE: add performs a null propagation
add(closest, result, tsos, prop, est);
#ifdef EDM_ML_DEBUG
int nclosest = result.size();
int nnextdet = 0; // just DEBUG counters
#endif
// Try the neighbors on each side until no more compatible.
// If closest is not compatible the next cannot be either
if (!result.empty()) {
const BoundPlane& closestPlane(dets[closest]->surface());
MeasurementEstimator::Local2DVector maxDistance = est.maximalLocalDisplacement(result.front().second, closestPlane);
// detHalfLen is assumed to be the same for all detectors.
float detHalfLen = closestPlane.bounds().length() / 2.;
for (unsigned int idet = closest + 1; idet < dets.size(); idet++) {
LocalPoint nextPos(dets[idet]->toLocal(startPos));
if (fabs(nextPos.y()) < detHalfLen + maxDistance.y()) {
#ifdef EDM_ML_DEBUG
LogTrace("MTDDetLayers") << " negativeZ: det:" << idet << " pos " << nextPos.y() << " maxDistance "
<< maxDistance.y();
nnextdet++;
#endif
if (!add(idet, result, tsos, prop, est))
break;
} else {
break;
}
}
for (int idet = closest - 1; idet >= 0; idet--) {
LocalPoint nextPos(dets[idet]->toLocal(startPos));
if (fabs(nextPos.y()) < detHalfLen + maxDistance.y()) {
#ifdef EDM_ML_DEBUG
LogTrace("MTDDetLayers") << " positiveZ: det:" << idet << " pos " << nextPos.y() << " maxDistance "
<< maxDistance.y();
nnextdet++;
#endif
if (!add(idet, result, tsos, prop, est))
break;
} else {
break;
}
}
}
#ifdef EDM_ML_DEBUG
LogTrace("MTDDetLayers") << " MTDDetTray::compatibleDets, size: " << result.size() << " on closest: " << nclosest
<< " # checked dets: " << nnextdet + 1;
if (result.empty()) {
LogTrace("MTDDetLayers") << " ***Rod not compatible---should have been discarded before!!!";
}
#endif
return result;
}
vector<DetGroup> MTDDetTray::groupedCompatibleDets(const TrajectoryStateOnSurface& startingState,
const Propagator& prop,
const MeasurementEstimator& est) const {
vector<GeometricSearchDet::DetWithState> detWithStates;
detWithStates = compatibleDets(startingState, prop, est);
vector<DetGroup> result;
if (!detWithStates.empty()) {
result.push_back(DetGroup(detWithStates));
}
LogTrace("MTDDetLayers") << "MTDdetTray Compatible modules: " << result.size();
return result;
}