CMS 3D CMS Logo

MTDTrayBarrelLayer.cc
Go to the documentation of this file.
1 
14 
17 
18 #include "GeneralBinFinderInPhi.h"
19 #include "PhiBorderFinder.h"
20 
21 #include <algorithm>
22 #include <iostream>
23 
24 using namespace std;
25 
26 MTDTrayBarrelLayer::MTDTrayBarrelLayer(vector<const DetRod*>& rods) :
28  theRods(rods),
29  theBinFinder(nullptr),
30  isOverlapping(false)
31 {
32  // Sort rods in phi
34 
35  theComponents.reserve(theRods.size());
36  std::copy(theRods.begin(),theRods.end(),back_inserter(theComponents));
37 
38  const std::string metname = "MTD|RecoMTD|RecoMTDDetLayers|MTDTrayBarrelLayer";
39 
40  // Cache chamber pointers (the basic components_)
41  for (vector<const DetRod*>::const_iterator it=rods.begin();
42  it!=rods.end(); it++) {
43  vector<const GeomDet*> tmp2 = (*it)->basicComponents();
44  theBasicComps.insert(theBasicComps.end(),tmp2.begin(),tmp2.end());
45  }
46 
47  // Initialize the binfinder
50 
51  if ( bf.isPhiPeriodic() ) {
53  (theRods.front()->position().phi(),theRods.size());
54  } else {
56  }
57 
58  // Compute the layer's surface and bounds (from the components())
60 
61  LogTrace(metname) << "Constructing MTDTrayBarrelLayer: "
62  << basicComponents().size() << " Dets "
63  << theRods.size() << " Rods "
64  << " R: " << specificSurface().radius()
65  << " Per.: " << bf.isPhiPeriodic()
66  << " Overl.: " << isOverlapping;
67 }
68 
69 
71  delete theBinFinder;
72  for (vector <const DetRod*>::iterator i = theRods.begin();
73  i<theRods.end(); i++) {delete *i;}
74 }
75 
76 
77 vector<GeometricSearchDet::DetWithState>
79  const Propagator& prop,
80  const MeasurementEstimator& est) const {
81 
82  const std::string metname = "MTD|RecoMTD|RecoMTDDetLayers|MTDTrayBarrelLayer";
83  vector<DetWithState> result;
84 
85 
86  LogTrace(metname) << "MTDTrayBarrelLayer::compatibleDets, Cyl R: "
87  << specificSurface().radius()
88  << " TSOS at R= " << startingState.globalPosition().perp()
89  << " phi= " << startingState.globalPosition().phi();
90 
91  pair<bool, TrajectoryStateOnSurface> compat =
92  compatible(startingState, prop, est);
93  if (!compat.first) {
94  LogTrace(metname) << " MTDTrayBarrelLayer::compatibleDets: not compatible"
95  << " (should not have been selected!)";
96  return vector<DetWithState>();
97  }
98 
99  TrajectoryStateOnSurface& tsos = compat.second;
100 
101  LogTrace(metname) << " MTDTrayBarrelLayer::compatibleDets, reached layer at: "
102  << tsos.globalPosition()
103  << " R = " << tsos.globalPosition().perp()
104  << " phi = " << tsos.globalPosition().phi();
105 
106  int closest = theBinFinder->binIndex(tsos.globalPosition().phi());
107  const DetRod* closestRod = theRods[closest];
108 
109  // Check the closest rod
110  LogTrace(metname) << " MTDTrayBarrelLayer::compatibleDets, closestRod: " << closest
111  << " phi : " << closestRod->surface().position().phi()
112  << " FTS phi: " << tsos.globalPosition().phi();
113 
114  result = closestRod->compatibleDets(tsos, prop, est);
115 
116 #ifdef EDM_ML_DEBUG
117  int nclosest = result.size(); // Debug counter
118 #endif
119 
120  bool checknext = false ;
121  double dist;
122 
123  if (!result.empty()) {
124  // Check if the track go outside closest rod, then look for closest.
125  TrajectoryStateOnSurface& predictedState = result.front().second;
126  float xErr = xError(predictedState, est);
127  float halfWid = closestRod->surface().bounds().width()/2.;
128  dist = predictedState.localPosition().x();
129 
130  // If the layer is overlapping, additionally reduce halfWid by 10%
131  // to account for overlap.
132  // FIXME: should we account for the real amount of overlap?
133  if (isOverlapping) halfWid *= 0.9;
134 
135  if (fabs(dist) + xErr > halfWid) {
136  checknext = true;
137  }
138  } else { // Rod is not compatible
139  //FIXME: Usually next cannot be either. Implement proper logic.
140  // (in general at least one rod should be when this method is called by
141  // compatibleDets() which calls compatible())
142  checknext = true;
143 
144  // Look for the next-to closest in phi.
145  // Note Geom::Phi, subtraction is pi-border-safe
146  if ( tsos.globalPosition().phi()-closestRod->surface().position().phi()>0.)
147  {
148  dist = -1.;
149  } else {
150  dist = +1.;
151  }
152 
153 
154  LogTrace(metname) << " MTDTrayBarrelLayer::fastCompatibleDets, none on closest rod!";
155  }
156 
157  if (checknext) {
158  int next;
159  if (dist<0.) next = closest+1;
160  else next = closest-1;
161 
162  next = theBinFinder->binIndex(next); // Bin Periodicity
163  const DetRod* nextRod = theRods[next];
164 
165 
166  LogTrace(metname) << " MTDTrayBarrelLayer::fastCompatibleDets, next-to closest"
167  << " rod: " << next << " dist " << dist
168  << " phi : " << nextRod->surface().position().phi()
169  << " FTS phi: " << tsos.globalPosition().phi();
170 
171  vector<DetWithState> nextRodDets =
172  nextRod->compatibleDets(tsos, prop, est);
173  result.insert(result.end(),
174  nextRodDets.begin(), nextRodDets.end());
175  }
176 
177 #ifdef EDM_ML_DEBUG
178  LogTrace(metname) << " MTDTrayBarrelLayer::fastCompatibleDets: found: "
179  << result.size()
180  << " on closest: " << nclosest
181  << " # checked rods: " << 1 + int(checknext);
182 #endif
183 
184  return result;
185 }
186 
187 
188 vector<DetGroup>
190  const Propagator& prop,
191  const MeasurementEstimator& est) const {
192  // FIXME should return only 1 group
193  cout << "dummy implementation of MTDTrayBarrelLayer::groupedCompatibleDets()" << endl;
194  return vector<DetGroup>();
195 }
196 
197 
198 
200  return theBasicComps.front()->subDetector();
201 }
202 
203 const vector<const GeometricSearchDet*>&
205  return theComponents;
206 }
207 
209  const MeasurementEstimator& est) const {
210  const float nSigmas = 3.f;
211  if (tsos.hasError()) {
212  return nSigmas * sqrt(tsos.localError().positionError().xx());
213  }
214  else return nSigmas * 0.5;
215 }
float xx() const
Definition: LocalError.h:24
T perp() const
Definition: PV3DBase.h:72
virtual int binIndex(T pos) const =0
Return the index of bin at given position.
virtual void initialize()
def copy(args, dbName)
const BoundSurface & surface() const final
The surface of the GeometricSearchDet.
Definition: DetRod.h:21
const std::string metname
MTDTrayBarrelLayer(std::vector< const DetRod * > &rods)
Constructor, takes ownership of pointers.
std::vector< const DetRod * > theRods
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
GlobalPoint globalPosition() const
~MTDTrayBarrelLayer() override
const Bounds & bounds() const
Definition: Surface.h:120
#define nullptr
LocalError positionError() const
virtual std::vector< DetWithState > compatibleDets(const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est) const
SubDetector subDetector() const override
virtual float width() const =0
std::vector< const GeomDet * > theBasicComps
float xError(const TrajectoryStateOnSurface &tsos, const MeasurementEstimator &est) const
T sqrt(T t)
Definition: SSEVec.h:18
const std::vector< const GeometricSearchDet * > & components() const override
const LocalTrajectoryError & localError() const
#define LogTrace(id)
bool isPhiPeriodic() const
Returns true if the Dets are periodic in phi.
Definition: DetRod.h:13
void precomputed_value_sort(RandomAccessIterator begin, RandomAccessIterator end, const Extractor &extr, const Compare &comp)
BaseBinFinder< double > * theBinFinder
const std::vector< const GeomDet * > & basicComponents() const override
std::vector< DetWithState > compatibleDets(const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est) const override
bool isPhiOverlapping() const
Returns true if any 2 of the Det overlap in phi.
T x() const
Definition: PV3DBase.h:62
const PositionType & position() const
std::vector< DetGroup > groupedCompatibleDets(const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est) const override
std::vector< const GeometricSearchDet * > theComponents