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>
10 
11 using namespace std;
12 
15  TSOS propState;
16  //self propagating. step one: go close to the center
17  GlobalPoint initialPoint = fts.position();
19  GlobalPoint center(0,0,0);
20  propState = middle.extrapolate(fts, center, propagator(dir));
21  if ( !propState.isValid()) return TrajectoryStateOnSurface();
22 
23  FreeTrajectoryState & dest = *propState.freeState();
24  GlobalPoint middlePoint = dest.position();
25  const double toCloseToEachOther=1e-4;
26  if ( (middlePoint-initialPoint).mag() < toCloseToEachOther){
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  std::string dirS;
32  if (dir==alongMomentum) dirS = "alongMomentum";
33  else if (dir==oppositeToMomentum) dirS = "oppositeToMomentum";
34  else dirS = "anyDirection";
35 
36  LogDebug("SimpleNavigableLayer")<<"self propagating("<< dir <<") from:\n"
37  <<fts<<"\n"
38  <<dest<<"\n"
39  <<" and the direction is: "<<dir<<" = "<<dirS;
40 
41  //second propagation to go on the other side of the barrel
42  //propState = propagator(dir).propagate( dest, detLayer()->specificSurface());
43  propState = propagator(dir).propagate( dest, detLayer()->surface());
44  if ( !propState.isValid()) return TrajectoryStateOnSurface();
45 
46  FreeTrajectoryState & dest2 = *propState.freeState();
47  GlobalPoint finalPoint = dest2.position();
48  LogDebug("SimpleNavigableLayer")<<"second propagation("<< dir <<") to: \n"
49  <<dest2;
50  double finalDot = (middlePoint - initialPoint).basicVector().dot((finalPoint-middlePoint).basicVector());
51  if (finalDot<0){ // check that before and after are in different side.
52  LogDebug("SimpleNavigableLayer")<<"switch side back: ABORT.";
53  return TrajectoryStateOnSurface();
54  }
55  return propState;
56 }
57 
60  const BarrelDetLayer* bl,
61  DLC& result) const
62 {
63  TSOS propState ;
64 
65  if (bl==detLayer()){
66  propState = crossingState(fts,dir);
67  if (!propState.isValid()) return false;
68  }else{
69  propState= propagator(dir).propagate( fts, bl->specificSurface());
70  }
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()<<","<< propState.globalPosition().z()<<","<<propState.globalPosition().perp()<<")";
84  return false;
85 
86  /*
87  //we have to check the crossing side only if we are going to something smaller
88  if (fts.position().perp()>bl->specificSurface().radius() ||
89  fabs(fts.position().z())>bl->surface().bounds().length()/2. ){
90  if (propState.globalPosition().basicVector().dot(fts.position().basicVector())<0){
91  LogTrace("TkNavigation") << "Crossing over prevented!\nStaring from (x,y,z,r) ("
92  << fts.position().x()<<","<< fts.position().y()<<","<< fts.position().z()<<","<<fts.position().perp()
93  << ") going to TSOS (x,y,z,r)"
94  << propState.globalPosition().x()<<","<< propState.globalPosition().y()<<","<< propState.globalPosition().z()<<","<<propState.globalPosition().perp()<<")";;
95  return false;
96  }
97  }
98  */
99  }}
100 
101  const Bounds& bounds( bl->specificSurface().bounds());
102  float length = bounds.length() / 2.f;
103 
104  // take into account the thickness of the layer
105  float deltaZ = bounds.thickness()/2. /
106  fabs( tan( propState.globalDirection().theta()));
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 ( fabs( zpos) < length + deltaZ) result.push_back( bl);
118 
119  if ( fabs( zpos) < length - deltaZ) return true;
120  else return false;
121 }
122 
125  const ForwardDetLayer* fl,
126  DLC& result) const
127 {
128  TSOS propState = propagator(dir).propagate( fts, fl->specificSurface());
129  if ( !propState.isValid()) return false;
130 
131  if (fl==detLayer()){
132  LogDebug("SimpleNavigableLayer")<<"self propagating from:\n"
133  <<fts<<"\n to \n"
134  <<*propState.freeState();
135  }
136 
137  //if requested avoids crossing over the tracker
138  if (theCheckCrossingSide){
139  bool backTobackTransverse = (fts.position().x()*propState.globalPosition().x() + fts.position().y()*propState.globalPosition().y())<0;
140  bool backToback = propState.globalPosition().basicVector().dot(fts.position().basicVector())<0;
141 
142  if (backTobackTransverse || backToback ){
143  LogTrace("TkNavigation") << "Crossing over prevented!\nStaring from (x,y,z,r) ("
144  << fts.position().x()<<","<< fts.position().y()<<","<< fts.position().z()<<","<<fts.position().perp()
145  << ") going to TSOS (x,y,z,r)"
146  << propState.globalPosition().x()<<","<< propState.globalPosition().y()<<","<< 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 = fl->surface().bounds().thickness()/2. *
159  fabs( tan( propState.localDirection().theta()));
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 
173  if ( innerR+deltaR < rpos && rpos < outerR-deltaR) return true;
174  else return false;
175 }
176 
179  const DLC& layers,
180  DLC& result) const
181 {
182 
183  // cout << "Entering SimpleNavigableLayer::wellInside" << endl;
184 
185  for (DLC::const_iterator i = layers.begin(); i != layers.end(); i++) {
186  const BarrelDetLayer* bl = dynamic_cast<const BarrelDetLayer*>(*i);
187  if ( bl != 0) {
188  if (wellInside( fts, dir, bl, result)) return true;
189  }
190  else {
191  const ForwardDetLayer* fl = dynamic_cast<const ForwardDetLayer*>(*i);
192  if ( fl == 0) edm::LogError("TkNavigation") << "dynamic_cast<const ForwardDetLayer*> failed" ;
193  if (wellInside( fts, dir, fl, result)) return true;
194  }
195  }
196  return false;
197 }
198 
202  DLC& result) const
203 {
204  for ( ConstBDLI i = begin; i < end; i++) {
205  if (wellInside( fts, dir, *i, result)) return true;
206  }
207  return false;
208 }
209 
213  DLC& result) const
214 {
215  for ( ConstFDLI i = begin; i < end; i++) {
216  if (wellInside( fts, dir, *i, result)) return true;
217  }
218  return false;
219 }
220 
222 {
223 #ifndef CMS_NO_MUTABLE
224  thePropagator.setPropagationDirection(dir);
225  return thePropagator;
226 #else
227  SimpleNavigableLayer* mthis = const_cast<SimpleNavigableLayer*>(this);
229  return mthis->thePropagator;
230 #endif
231 }
232 
234 {
235  for ( ConstBDLI i = tmp.begin(); i != tmp.end(); i++) {
236  result.push_back(*i);
237  }
238 }
239 
241 {
242  for ( ConstFDLI i = tmp.begin(); i != tmp.end(); i++) {
243  result.push_back(*i);
244  }
245 }
246 
247 std::vector< const DetLayer * > SimpleNavigableLayer::compatibleLayers (const FreeTrajectoryState &fts,
248  PropagationDirection timeDirection,
249  int& counter) const {
250  typedef std::vector<const DetLayer*> Lvect;
251  typedef std::set<const DetLayer *> Lset;
252 
253  Lvect empty,result;
254  result.reserve(15); //that's a max
255  Lset collect; //a container of unique instances. to avoid duplicates
256 
257  Lset layerToTry,nextLayerToTry;//set used for iterations
258  //initiate the first iteration
259  Lvect someLayers(nextLayers(fts,timeDirection));
260  layerToTry.insert(someLayers.begin(),someLayers.end());
261 
262  while (!layerToTry.empty() && (counter++)<=150){
263  LogDebug("SimpleNavigableLayer")
264  <<counter<<"] going to check on : "<<layerToTry.size()<<" next layers.";
265  //clear this set first, it will be swaped with layerToTry
266  nextLayerToTry.clear();
267  for (Lset::iterator toTry=layerToTry.begin();toTry!=layerToTry.end();++toTry){
268  //add the layer you tried.
269  LogDebug("SimpleNavigableLayer")
270  <<counter<<"] adding layer with pointer: "<<(*toTry)
271  <<" first detid: "<<DetIdInfo::info((*toTry)->basicComponents().front()->geographicalId());
272  collect.insert( (*toTry) );
273 
274  //find the next layers from it
275  Lvect nextLayers( (*toTry)->nextLayers(fts,timeDirection) );
276  LogDebug("SimpleNavigableLayer")
277  <<counter<<"] this layer has : "<<nextLayers.size()<<" next layers.";
278  for (Lvect::iterator next=nextLayers.begin();next!=nextLayers.end();++next){
279  //if the next layer is not already in the collected layers, add it for next round.
280  bool alreadyTested=false;
281  for (Lset::iterator testMe=collect.begin();testMe!=collect.end();++testMe){ //find method does not work well!
282  if ((*testMe) == (*next))
283  {alreadyTested=true;break;}
284  }
285  // if ( collect.find(*next)!=collect.end()){ //find method does not work it seems...
286  if (!alreadyTested){
287  nextLayerToTry.insert( *next );
288  LogDebug("SimpleNavigableLayer")
289  <<counter<<"] to try next, layer with pointer: "<<(*next)
290  <<" first detid: "<<DetIdInfo::info((*next)->basicComponents().front()->geographicalId());
291  }
292  else{
293  LogDebug("SimpleNavigableLayer")
294  <<counter<<"] skipping for next tryout, layer with pointer: "<<(*next)
295  <<" first detid: "<<DetIdInfo::info((*next)->basicComponents().front()->geographicalId());
296  //for (Lset::iterator testMe=collect.begin();testMe!=collect.end();++testMe){ LogTrace("SimpleNavigableLayer") <<"pointer collected:" <<(*testMe); }
297  }
298  }
299  LogDebug("SimpleNavigableLayer")
300  <<counter<<"] "<<nextLayerToTry.size()<<" layers to try next so far.";
301  }
302  //swap now that you where to go next.
303  layerToTry.swap(nextLayerToTry);
304  }
305  if(counter>=150) {
306  edm::LogWarning("SimpleNavigableLayer") << "WARNING: compatibleLayers() more than 150 iterations!!! Bailing out..";
307  counter = -1;return empty;
308  }
309 
310  result.insert(result.end(),collect.begin(),collect.end()); //cannot do a swap it seems
311  LogDebug("SimpleNavigableLayer")
312  <<"Number of compatible layers: "<<result.size();
313  return result;
314 
315 
316 }
#define LogDebug(id)
int i
Definition: DBlmapReader.cc:9
float xx() const
Definition: LocalError.h:24
CartesianTrajectoryError cartesianError() const
virtual float length() const =0
T perp() const
Definition: PV3DBase.h:71
void pushResult(DLC &result, const FDLC &tmp) const
std::vector< BarrelDetLayer * > BDLC
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
LocalVector localDirection() const
virtual const BoundSurface & surface() const
The surface of the GeometricSearchDet.
T y() const
Definition: PV3DBase.h:62
GlobalPoint globalPosition() const
PropagationDirection
LocalError positionError() const
Geom::Theta< T > theta() const
Definition: PV3DBase.h:74
virtual float thickness() const =0
FreeTrajectoryState * freeState(bool withErrors=true) const
float yy() const
Definition: LocalError.h:26
T sqrt(T t)
Definition: SSEVec.h:46
T z() const
Definition: PV3DBase.h:63
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
FDLC::const_iterator ConstFDLI
std::vector< const DetLayer * > DLC
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
static std::string info(const DetId &)
Definition: DetIdInfo.cc:28
#define end
Definition: vmac.h:38
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 Bounds & bounds() const
Definition: BoundSurface.h:89
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
Propagator & propagator(PropagationDirection dir) const
TrajectoryStateOnSurface extrapolate(const FreeTrajectoryState &fts, const GlobalPoint &vtx) const
extrapolation with default (=geometrical) propagator
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
std::vector< ForwardDetLayer * > FDLC
#define begin
Definition: vmac.h:31
AnalyticalPropagator thePropagator
float outerRadius() const
The outer radius of the disk.
Definition: BoundDisk.h:75
virtual void setPropagationDirection(PropagationDirection dir) const
Definition: Propagator.h:132
float innerRadius() const
The inner radius of the disk.
Definition: BoundDisk.h:72
Definition: Bounds.h:18
dbl *** dir
Definition: mlp_gen.cc:35
T x() const
Definition: PV3DBase.h:61
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.