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