CMS 3D CMS Logo

MuRodBarrelLayer.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 MuRodBarrelLayer::MuRodBarrelLayer(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 = "Muon|RecoMuon|RecoMuonDetLayers|MuRodBarrelLayer";
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 MuRodBarrelLayer: "
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 = "Muon|RecoMuon|RecoMuonDetLayers|MuRodBarrelLayer";
83  vector<DetWithState> result;
84 
85 
86  LogTrace(metname) << "MuRodBarrelLayer::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) << " MuRodBarrelLayer::compatibleDets: not compatible"
95  << " (should not have been selected!)";
96  return vector<DetWithState>();
97  }
98 
99  TrajectoryStateOnSurface& tsos = compat.second;
100 
101  LogTrace(metname) << " MuRodBarrelLayer::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) << " MuRodBarrelLayer::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  int nclosest = result.size(); // Debug counter
117 
118  bool checknext = false ;
119  double dist;
120 
121  if (!result.empty()) {
122  // Check if the track go outside closest rod, then look for closest.
123  TrajectoryStateOnSurface& predictedState = result.front().second;
124  float xErr = xError(predictedState, est);
125  float halfWid = closestRod->surface().bounds().width()/2.;
126  dist = predictedState.localPosition().x();
127 
128  // If the layer is overlapping, additionally reduce halfWid by 10%
129  // to account for overlap.
130  // FIXME: should we account for the real amount of overlap?
131  if (isOverlapping) halfWid *= 0.9;
132 
133  if (fabs(dist) + xErr > halfWid) {
134  checknext = true;
135  }
136  } else { // Rod is not compatible
137  //FIXME: Usually next cannot be either. Implement proper logic.
138  // (in general at least one rod should be when this method is called by
139  // compatibleDets() which calls compatible())
140  checknext = true;
141 
142  // Look for the next-to closest in phi.
143  // Note Geom::Phi, subtraction is pi-border-safe
144  if ( tsos.globalPosition().phi()-closestRod->surface().position().phi()>0.)
145  {
146  dist = -1.;
147  } else {
148  dist = +1.;
149  }
150 
151 
152  LogTrace(metname) << " MuRodBarrelLayer::fastCompatibleDets, none on closest rod!";
153  }
154 
155  if (checknext) {
156  int next;
157  if (dist<0.) next = closest+1;
158  else next = closest-1;
159 
160  next = theBinFinder->binIndex(next); // Bin Periodicity
161  const DetRod* nextRod = theRods[next];
162 
163 
164  LogTrace(metname) << " MuRodBarrelLayer::fastCompatibleDets, next-to closest"
165  << " rod: " << next << " dist " << dist
166  << " phi : " << nextRod->surface().position().phi()
167  << " FTS phi: " << tsos.globalPosition().phi();
168 
169  vector<DetWithState> nextRodDets =
170  nextRod->compatibleDets(tsos, prop, est);
171  result.insert(result.end(),
172  nextRodDets.begin(), nextRodDets.end());
173  }
174 
175 
176  LogTrace(metname) << " MuRodBarrelLayer::fastCompatibleDets: found: "
177  << result.size()
178  << " on closest: " << nclosest
179  << " # checked rods: " << 1 + int(checknext);
180 
181  return result;
182 }
183 
184 
185 vector<DetGroup>
187  const Propagator& prop,
188  const MeasurementEstimator& est) const {
189  // FIXME should return only 1 group
190  cout << "dummy implementation of MuRodBarrelLayer::groupedCompatibleDets()" << endl;
191  return vector<DetGroup>();
192 }
193 
194 
195 
197  return theBasicComps.front()->subDetector();
198 }
199 
200 const vector<const GeometricSearchDet*>&
202  return theComponents;
203 }
204 
206  const MeasurementEstimator& est) const {
207  const float nSigmas = 3.f;
208  if (tsos.hasError()) {
209  return nSigmas * sqrt(tsos.localError().positionError().xx());
210  }
211  else return nSigmas * 0.5;
212 }
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.
std::vector< DetWithState > compatibleDets(const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est) const override
virtual void initialize()
def copy(args, dbName)
const BoundSurface & surface() const final
The surface of the GeometricSearchDet.
Definition: DetRod.h:21
const std::vector< const GeomDet * > & basicComponents() const override
const std::string metname
#define nullptr
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
GlobalPoint globalPosition() const
const Bounds & bounds() const
Definition: Surface.h:120
LocalError positionError() const
virtual std::vector< DetWithState > compatibleDets(const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est) const
const std::vector< const GeometricSearchDet * > & components() const override
virtual float width() const =0
std::vector< const GeomDet * > theBasicComps
BaseBinFinder< double > * theBinFinder
T sqrt(T t)
Definition: SSEVec.h:18
std::vector< const GeometricSearchDet * > theComponents
std::vector< const DetRod * > theRods
const LocalTrajectoryError & localError() const
std::vector< DetGroup > groupedCompatibleDets(const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est) const override
SubDetector subDetector() const override
#define LogTrace(id)
float xError(const TrajectoryStateOnSurface &tsos, const MeasurementEstimator &est) const
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)
~MuRodBarrelLayer() 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
MuRodBarrelLayer(std::vector< const DetRod * > &rods)
Constructor, takes ownership of pointers.