CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SimpleNavigableLayer.cc
Go to the documentation of this file.
2 
4 
8 #include <set>
9 
10 using namespace std;
11 
14  //self propagating. step one: go close to the center
15  GlobalPoint initialPoint = fts.position();
17  GlobalPoint center(0,0,0);
18  TSOS propState = middle.extrapolate(fts, center, propagator(dir));
19  if ( !propState.isValid()) return TrajectoryStateOnSurface();
20 
21  FreeTrajectoryState const & dest = *propState.freeState();
22  GlobalPoint middlePoint = dest.position();
23  const float toCloseToEachOther2 = 1e-4*1e-4;
24  if unlikely( (middlePoint-initialPoint).mag2() < toCloseToEachOther2){
25  LogDebug("SimpleNavigableLayer")<<"initial state and PCA are identical. Things are bound to fail. Do not add the link.";
26  return TrajectoryStateOnSurface();
27  }
28 
29 
30  /*
31  std::string dirS;
32  if (dir==alongMomentum) dirS = "alongMomentum";
33  else if (dir==oppositeToMomentum) dirS = "oppositeToMomentum";
34  else dirS = "anyDirection";
35  */
36 
37  LogDebug("SimpleNavigableLayer")<<"self propagating("<< dir <<") from:\n"
38  <<fts<<"\n"
39  <<dest<<"\n"
40  <<" and the direction is: "<<dir;
41 
42  //second propagation to go on the other side of the barrel
43  //propState = propagator(dir).propagate( dest, detLayer()->specificSurface());
44  propState = propagator(dir).propagate( dest, detLayer()->surface());
45  if ( !propState.isValid()) return TrajectoryStateOnSurface();
46 
47  const FreeTrajectoryState & dest2 = *propState.freeState();
48  GlobalPoint finalPoint = dest2.position();
49  LogDebug("SimpleNavigableLayer")<<"second propagation("<< dir <<") to: \n"
50  <<dest2;
51  double finalDot = (middlePoint - initialPoint).basicVector().dot((finalPoint-middlePoint).basicVector());
52  if unlikely(finalDot<0){ // check that before and after are in different side.
53  LogDebug("SimpleNavigableLayer")<<"switch side back: ABORT.";
54  return TrajectoryStateOnSurface();
55  }
56  return propState;
57 }
58 
61  const BarrelDetLayer* bl,
62  DLC& result) const
63 {
64 
65  TSOS propState = (bl==detLayer()) ?
66  crossingState(fts,dir)
67  :
68  propagator(dir).propagate( fts, bl->specificSurface());
69 
70  if ( !propState.isValid()) return false;
71 
72  //if requested check that the layer is crossed on the right side
73  if (theCheckCrossingSide){
74  bool backTobackTransverse = (fts.position().x()*propState.globalPosition().x() + fts.position().y()*propState.globalPosition().y())<0;
75  bool backToback = propState.globalPosition().basicVector().dot(fts.position().basicVector())<0;
76 
77  if (backTobackTransverse || backToback ){
78  LogTrace("TkNavigation") << "Crossing over prevented!\nStaring from (x,y,z,r) ("
79  << fts.position().x()<<","<< fts.position().y()<<","<< fts.position().z()<<","<<fts.position().perp()
80  << ") going to TSOS (x,y,z,r)"
81  << propState.globalPosition().x()<<","<< propState.globalPosition().y()
82  <<","<< propState.globalPosition().z()<<","<<propState.globalPosition().perp()<<")";
83  return false;
84 
85  /*
86  //we have to check the crossing side only if we are going to something smaller
87  if (fts.position().perp()>bl->specificSurface().radius() ||
88  fabs(fts.position().z())>bl->surface().bounds().length()/2. ){
89  if (propState.globalPosition().basicVector().dot(fts.position().basicVector())<0){
90  LogTrace("TkNavigation") << "Crossing over prevented!\nStaring from (x,y,z,r) ("
91  << fts.position().x()<<","<< fts.position().y()<<","<< fts.position().z()<<","<<fts.position().perp()
92  << ") going to TSOS (x,y,z,r)"
93  << propState.globalPosition().x()<<","<< propState.globalPosition().y()<<","<< propState.globalPosition().z()<<","<<propState.globalPosition().perp()<<")";;
94  return false;
95  }
96  }
97  */
98  }}
99 
100  const Bounds& bounds( bl->specificSurface().bounds());
101  float length = bounds.length()*0.5f;
102 
103  // take into account the thickness of the layer
104  float deltaZ = 0.5f*bounds.thickness() *
105  std::abs(propState.globalDirection().z())/propState.globalDirection().perp();
106 
107 
108  // take into account the error on the predicted state
109  const float nSigma = theEpsilon; // temporary reuse of epsilon
110  if (propState.hasError()) {
111  deltaZ += nSigma * sqrt( fts.cartesianError().position().czz());
112  }
113 
114  // cout << "SimpleNavigableLayer BarrelDetLayer deltaZ = " << deltaZ << endl;
115 
116  float zpos = propState.globalPosition().z();
117  if ( std::abs( zpos) < length + deltaZ) result.push_back( bl);
118 
119  return std::abs( zpos) < length - deltaZ;
120 }
121 
124  const ForwardDetLayer* fl,
125  DLC& result) const
126 {
127  TSOS propState = propagator(dir).propagate( fts, fl->specificSurface());
128  if ( !propState.isValid()) return false;
129 
130  if (fl==detLayer()){
131  LogDebug("SimpleNavigableLayer")<<"self propagating from:\n"
132  <<fts<<"\n to \n"
133  <<*propState.freeState();
134  }
135 
136  //if requested avoids crossing over the tracker
137  if (theCheckCrossingSide){
138  bool backTobackTransverse = (fts.position().x()*propState.globalPosition().x() + fts.position().y()*propState.globalPosition().y())<0;
139  bool backToback = propState.globalPosition().basicVector().dot(fts.position().basicVector())<0;
140 
141  if (backTobackTransverse || backToback ){
142  LogTrace("TkNavigation") << "Crossing over prevented!\nStaring from (x,y,z,r) ("
143  << fts.position().x()<<","<< fts.position().y()<<","<< fts.position().z()<<","<<fts.position().perp()
144  << ") going to TSOS (x,y,z,r)"
145  << propState.globalPosition().x()<<","<< propState.globalPosition().y()
146  <<","<< propState.globalPosition().z()<<","<<propState.globalPosition().perp()<<")";;
147  return false;
148 
149  // if (fts.position().z()*propState.globalPosition().z() < 0) return false;
150  }}
151 
152 
153  float rpos = propState.globalPosition().perp();
154  float innerR = fl->specificSurface().innerRadius();
155  float outerR = fl->specificSurface().outerRadius();
156 
157  // take into account the thickness of the layer
158  float deltaR = 0.5f*fl->surface().bounds().thickness() *
159  propState.localDirection().perp()/std::abs(propState.localDirection().z());
160 
161  // take into account the error on the predicted state
162  const float nSigma = theEpsilon;
163  if (propState.hasError()) {
164  LocalError err = propState.localError().positionError();
165  // ignore correlation for the moment...
166  deltaR += nSigma * sqrt(err.xx() + err.yy());
167  }
168 
169  // cout << "SimpleNavigableLayer BarrelDetLayer deltaR = " << deltaR << endl;
170 
171  if ( innerR-deltaR < rpos && rpos < outerR+deltaR) result.push_back( fl);
172  return ( innerR+deltaR < rpos && rpos < outerR-deltaR);
173 }
174 
177  const DLC& layers,
178  DLC& result) const
179 {
180  for (auto l : layers) {
181  if (l->isBarrel()) {
182  const BarrelDetLayer * bl = reinterpret_cast<const BarrelDetLayer *>(l);
183  if (wellInside( fts, dir, bl, result)) return true;
184  }
185  else {
186  const ForwardDetLayer* fl = reinterpret_cast<const ForwardDetLayer*>(l);
187  if (wellInside( fts, dir, fl, result)) return true;
188  }
189  }
190  return false;
191 }
192 
196  DLC& result) const
197 {
198  for ( ConstBDLI i = begin; i < end; i++) {
199  if (wellInside( fts, dir, *i, result)) return true;
200  }
201  return false;
202 }
203 
207  DLC& result) const
208 {
209  for ( ConstFDLI i = begin; i < end; i++) {
210  if (wellInside( fts, dir, *i, result)) return true;
211  }
212  return false;
213 }
214 
215 
216 std::vector< const DetLayer * > SimpleNavigableLayer::compatibleLayers (const FreeTrajectoryState &fts,
217  PropagationDirection timeDirection,
218  int& counter) const {
219  typedef std::vector<const DetLayer*> Lvect;
220  typedef std::set<const DetLayer *> Lset;
221 
222  //initiate the first iteration
223  Lvect && someLayers = nextLayers(fts,timeDirection);
224  if (someLayers.empty()) {
225  LogDebug("SimpleNavigableLayer") <<"Number of compatible layers: "<< 0;
226  return someLayers;
227  }
228 
229 
230  Lset collect; //a container of unique instances. to avoid duplicates
231  Lset layerToTry, nextLayerToTry;//set used for iterations
232  layerToTry.insert(someLayers.begin(),someLayers.end());
233 
234  while (!layerToTry.empty() && (counter++)<=150){
235  LogDebug("SimpleNavigableLayer")
236  <<counter<<"] going to check on : "<<layerToTry.size()<<" next layers.";
237  //clear this set first, it will be swaped with layerToTry
238  nextLayerToTry.clear();
239  for (auto toTry : layerToTry){
240  //add the layer you tried.
241  LogDebug("SimpleNavigableLayer")
242  <<counter<<"] adding layer with pointer: "<<(toTry)
243  <<" first detid: "<< (toTry)->basicComponents().front()->geographicalId();
244  if (!collect.insert(toTry).second) continue;
245 
246  //find the next layers from it
247  Lvect && nextLayers = (toTry)->nextLayers(fts,timeDirection);
248  LogDebug("SimpleNavigableLayer")
249  <<counter<<"] this layer has : "<<nextLayers.size()<<" next layers.";
250  nextLayerToTry.insert(nextLayers.begin(),nextLayers.end());
251  } // layerToTry
252  //swap now that you where to go next.
253  layerToTry.swap(nextLayerToTry);
254  }
255  if(counter>=150) {
256  edm::LogWarning("SimpleNavigableLayer") << "WARNING: compatibleLayers() more than 150 iterations!!! Bailing out..";
257  counter = -1;
258  return Lvect();
259  }
260 
261  LogDebug("SimpleNavigableLayer")
262  <<"Number of compatible layers: "<< collect.size();
263 
264  return Lvect(collect.begin(),collect.end());
265 
266 }
#define LogDebug(id)
int i
Definition: DBlmapReader.cc:9
float xx() const
Definition: LocalError.h:24
virtual std::vector< const DetLayer * > compatibleLayers(const FreeTrajectoryState &fts, PropagationDirection timeDirection, int &counter) const GCC11_FINAL
std::vector< LayerSetAndLayers > layers(const SeedingLayerSetsHits &sets)
Definition: LayerTriplets.cc:4
CartesianTrajectoryError cartesianError() const
virtual float length() const =0
T perp() const
Definition: PV3DBase.h:72
LocalVector localDirection() const
T y() const
Definition: PV3DBase.h:63
GlobalPoint globalPosition() const
const Bounds & bounds() const
Definition: Surface.h:128
PropagationDirection
TSOS crossingState(const FreeTrajectoryState &fts, PropagationDirection dir) const dso_internal
LocalError positionError() const
bool wellInside(const FreeTrajectoryState &fts, PropagationDirection dir, const BarrelDetLayer *bl, DLC &result) const dso_internal
virtual float thickness() const =0
#define unlikely(x)
Definition: Likely.h:21
float yy() const
Definition: LocalError.h:26
virtual const BoundSurface & surface() const GCC11_FINAL
The surface of the GeometricSearchDet.
T sqrt(T t)
Definition: SSEVec.h:48
FreeTrajectoryState const * freeState(bool withErrors=true) const
T z() const
Definition: PV3DBase.h:64
tuple result
Definition: query.py:137
T mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)
FDLC::const_iterator ConstFDLI
std::vector< const DetLayer * > DLC
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define end
Definition: vmac.h:37
const LocalTrajectoryError & localError() const
#define LogTrace(id)
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
GlobalPoint position() const
const GlobalError position() const
Position error submatrix.
virtual const BoundDisk & specificSurface() const GCC11_FINAL
TrajectoryStateOnSurface extrapolate(const FreeTrajectoryState &fts, const GlobalPoint &vtx) const
extrapolation with default (=geometrical) propagator
#define begin
Definition: vmac.h:30
static std::atomic< unsigned int > counter
Definition: Bounds.h:22
dbl *** dir
Definition: mlp_gen.cc:35
T x() const
Definition: PV3DBase.h:62
const BasicVectorType & basicVector() const
Definition: PV3DBase.h:56
virtual const BoundCylinder & specificSurface() const GCC11_FINAL
Extension of the interface.
BDLC::const_iterator ConstBDLI
GlobalVector globalDirection() const
T dot(const Basic3DVector &rh) const
Scalar product, or &quot;dot&quot; product, with a vector of same type.