CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TIDLayer.cc
Go to the documentation of this file.
1 #include "TIDLayer.h"
2 
4 
6 
9 
10 #include<array>
11 #include "DetGroupMerger.h"
12 
13 
14 //#include "CommonDet/DetLayout/src/DetLessR.h"
15 
16 
17 using namespace std;
18 
20 
21 namespace {
22 
23 // 2 0 1
24 /*
25 class TIDringLess {
26  // z-position ordering of TID rings indices
27 public:
28  bool operator()( const pair<vector<DetGroup> const *,int> & a,const pair<vector<DetGroup>const *,int> & b) const {
29  if(a.second==2) {return true;}
30  else if(a.second==0) {
31  if(b.second==2) return false;
32  if(b.second==1) return true;
33  }
34  return false;
35  };
36 };
37 */
38 
39  // groups in correct order: one may be empty
40  inline
41  void mergeOutward(std::array<vector<DetGroup>,3> & groups,
42  std::vector<DetGroup> & result ) {
43  typedef DetGroupMerger Merger;
44  Merger::orderAndMergeTwoLevels(std::move(groups[0]),
45  std::move(groups[1]),result,1,1);
46  if(!groups[2].empty()) {
47  std::vector<DetGroup> tmp;
48  tmp.swap(result);
49  Merger::orderAndMergeTwoLevels(std::move(tmp),std::move(groups[2]),result,1,1);
50  }
51 
52  }
53 
54  inline
55  void mergeInward(std::array<vector<DetGroup>,3> & groups,
56  std::vector<DetGroup> & result ) {
57  typedef DetGroupMerger Merger;
58  Merger::orderAndMergeTwoLevels(std::move(groups[2]),
59  std::move(groups[1]),result,1,1);
60  if(!groups[0].empty()) {
61  std::vector<DetGroup> tmp;
62  tmp.swap(result);
63  Merger::orderAndMergeTwoLevels(std::move(tmp),std::move(groups[0]),result,1,1);
64  }
65 
66  }
67 
68 
69  void
70  orderAndMergeLevels(const TrajectoryStateOnSurface& tsos,
71  const Propagator& prop,
72  std::array<vector<DetGroup>,3> & groups,
73  std::vector<DetGroup> & result ) {
74 
75  float zpos = tsos.globalPosition().z();
76  if(tsos.globalMomentum().z()*zpos>0){ // momentum points outwards
78  mergeOutward(groups,result);
79  else
80  mergeInward(groups,result);
81  }
82  else{ // momentum points inwards
84  mergeOutward(groups,result);
85  else
86  mergeInward(groups,result);
87  }
88 
89  }
90 
91 }
92 
93 //hopefully is never called!
94 const std::vector<const GeometricSearchDet*>& TIDLayer::components() const{
95  static std::vector<const GeometricSearchDet*> crap;
96  for ( auto c: theComps) crap.push_back(c);
97  return crap;
98  }
99 
100 
101 void
103  const BoundDisk& ringDisk = static_cast<const BoundDisk&>(theComps[i]->surface());
104  float ringMinZ = fabs( ringDisk.position().z()) - ringDisk.bounds().thickness()/2.;
105  float ringMaxZ = fabs( ringDisk.position().z()) + ringDisk.bounds().thickness()/2.;
106  ringPars[i].thetaRingMin = ringDisk.innerRadius()/ ringMaxZ;
107  ringPars[i].thetaRingMax = ringDisk.outerRadius()/ ringMinZ;
108  ringPars[i].theRingR=( ringDisk.innerRadius() +
109  ringDisk.outerRadius())/2.;
110 
111 }
112 
113 
114 TIDLayer::TIDLayer(vector<const TIDRing*>& rings) :
116  //They should be already R-ordered. TO BE CHECKED!!
117  //sort( theRings.begin(), theRings.end(), DetLessR());
118 
119  if ( rings.size() != 3) throw DetLayerException("Number of rings in TID layer is not equal to 3 !!");
120  setSurface( computeDisk( rings ) );
121 
122  for(int i=0; i!=3; ++i) {
123  theComps[i]=rings[i];
124  fillRingPars(i);
125  theBasicComps.insert(theBasicComps.end(),
126  (*rings[i]).basicComponents().begin(),
127  (*rings[i]).basicComponents().end());
128  }
129 
130 
131  LogDebug("TkDetLayers") << "==== DEBUG TIDLayer =====" ;
132  LogDebug("TkDetLayers") << "r,zed pos , thickness, innerR, outerR: "
133  << this->position().perp() << " , "
134  << this->position().z() << " , "
135  << this->specificSurface().bounds().thickness() << " , "
136  << this->specificSurface().innerRadius() << " , "
137  << this->specificSurface().outerRadius() ;
138 }
139 
140 
141 BoundDisk*
142 TIDLayer::computeDisk( const vector<const TIDRing*>& rings) const
143 {
144  float theRmin = rings.front()->specificSurface().innerRadius();
145  float theRmax = rings.front()->specificSurface().outerRadius();
146  float theZmin = rings.front()->position().z() -
147  rings.front()->surface().bounds().thickness()/2;
148  float theZmax = rings.front()->position().z() +
149  rings.front()->surface().bounds().thickness()/2;
150 
151  for (vector<const TIDRing*>::const_iterator i = rings.begin(); i != rings.end(); i++) {
152  float rmin = (**i).specificSurface().innerRadius();
153  float rmax = (**i).specificSurface().outerRadius();
154  float zmin = (**i).position().z() - (**i).surface().bounds().thickness()/2.;
155  float zmax = (**i).position().z() + (**i).surface().bounds().thickness()/2.;
156  theRmin = min( theRmin, rmin);
157  theRmax = max( theRmax, rmax);
158  theZmin = min( theZmin, zmin);
159  theZmax = max( theZmax, zmax);
160  }
161 
162  float zPos = (theZmax+theZmin)/2.;
163  PositionType pos(0.,0.,zPos);
165 
166  return new BoundDisk( pos, rot, new SimpleDiskBounds(theRmin, theRmax,
167  theZmin-zPos, theZmax-zPos));
168 
169 }
170 
171 
173  for (auto c : theComps) delete c;
174 }
175 
176 
177 
178 void
180  const Propagator& prop,
181  const MeasurementEstimator& est,
182  std::vector<DetGroup> & result) const
183 {
184  std::array<int,3> const & ringIndices = ringIndicesByCrossingProximity(startingState,prop);
185  if ( ringIndices[0]==-1 ) {
186  edm::LogError("TkDetLayers") << "TkRingedForwardLayer::groupedCompatibleDets : error in CrossingProximity";
187  return;
188  }
189 
190  std::array<vector<DetGroup>,3> groupsAtRingLevel;
191  //order is ring3,ring1,ring2 i.e. 2 0 1
192  // 0 1 2
193  constexpr int ringOrder[3]{1,2,0};
194  auto index = [&ringIndices,& ringOrder](int i) { return ringOrder[ringIndices[i]];};
195 
196  auto & closestResult = groupsAtRingLevel[index(0)];
197  theComps[ringIndices[0]]->groupedCompatibleDetsV( startingState, prop, est, closestResult);
198  if ( closestResult.empty() ){
199  theComps[ringIndices[1]]->groupedCompatibleDetsV( startingState, prop, est, result);
200  return;
201  }
202 
203  DetGroupElement closestGel( closestResult.front().front());
204  float rWindow = computeWindowSize( closestGel.det(), closestGel.trajectoryState(), est);
205 
206  if(!overlapInR(closestGel.trajectoryState(),ringIndices[1],rWindow)) {
207  result.swap(closestResult);
208  return;
209  }
210 
211 
212  auto & nextResult = groupsAtRingLevel[index(1)];
213  theComps[ringIndices[1]]->groupedCompatibleDetsV( startingState, prop, est, nextResult);
214  if(nextResult.empty()) {
215  result.swap(closestResult);
216  return;
217  }
218 
219  if(!overlapInR(closestGel.trajectoryState(),ringIndices[2],rWindow) ) {
220  //then merge 2 levels & return
221  orderAndMergeLevels(closestGel.trajectoryState(),prop,groupsAtRingLevel,result);
222  return;
223  }
224 
225  auto & nextNextResult = groupsAtRingLevel[index(2)];
226  theComps[ringIndices[2]]->groupedCompatibleDetsV( startingState, prop, est, nextNextResult);
227  if(nextNextResult.empty()) {
228  // then merge 2 levels and return
229  orderAndMergeLevels(closestGel.trajectoryState(),prop,groupsAtRingLevel,result); //
230  return;
231  }
232 
233  // merge 3 level and return merged
234  orderAndMergeLevels(closestGel.trajectoryState(),prop,groupsAtRingLevel, result);
235 }
236 
237 
238 std::array<int,3>
240  const Propagator& prop ) const
241 {
242  typedef HelixForwardPlaneCrossing Crossing;
244 
245  HelixPlaneCrossing::PositionType startPos( startingState.globalPosition());
246  HelixPlaneCrossing::DirectionType startDir( startingState.globalMomentum());
248  float rho( startingState.transverseCurvature());
249 
250  // calculate the crossings with the ring surfaces
251  // rings are assumed to be sorted in R !
252 
253  Crossing myXing( startPos, startDir, rho, propDir );
254 
255  GlobalPoint ringCrossings[3];
256  // vector<GlobalVector> ringXDirections;
257 
258  for (int i = 0; i < 3 ; i++ ) {
259  const BoundDisk & theRing = static_cast<const BoundDisk &>(theComps[i]->surface());
260  pair<bool,double> pathlen = myXing.pathLength( theRing);
261  if ( pathlen.first ) {
262  ringCrossings[i] = GlobalPoint( myXing.position(pathlen.second ));
263  // ringXDirections.push_back( GlobalVector( myXing.direction(pathlen.second )));
264  } else {
265  // TO FIX.... perhaps there is something smarter to do
266  //throw DetLayerException("trajectory doesn't cross TID rings");
267  ringCrossings[i] = GlobalPoint( 0.,0.,0.);
268  // ringXDirections.push_back( GlobalVector( 0.,0.,0.));
269  }
270  }
271 
272  int closestIndex = findClosest(ringCrossings);
273  int nextIndex = findNextIndex(ringCrossings,closestIndex);
274  if ( closestIndex<0 || nextIndex<0 ) return std::array<int,3>{{-1,-1,-1}};
275  int nextNextIndex = -1;
276  for(int i=0; i<3 ; i++){
277  if(i!= closestIndex && i!=nextIndex) {
278  nextNextIndex = i;
279  break;
280  }
281  }
282 
283  std::array<int,3> indices{{closestIndex,nextIndex,nextNextIndex}};
284  return indices;
285 }
286 
287 
288 
289 
290 float
292  const TrajectoryStateOnSurface& tsos,
293  const MeasurementEstimator& est) const
294 {
295  const Plane& startPlane = det->surface();
297  est.maximalLocalDisplacement( tsos, startPlane);
298  return maxDistance.y();
299 }
300 
301 
302 int
303 TIDLayer::findClosest(const GlobalPoint ringCrossing[3] ) const
304 {
305  int theBin = 0;
306  float initialR = ringPars[0].theRingR;
307  float rDiff = fabs( ringCrossing[0].perp() - initialR);
308  for (int i = 1; i < 3 ; i++){
309  float ringR = ringPars[i].theRingR;
310  float testDiff = fabs( ringCrossing[i].perp() - ringR);
311  if ( testDiff<rDiff ) {
312  rDiff = testDiff;
313  theBin = i;
314  }
315  }
316  return theBin;
317 }
318 
319 int
320 TIDLayer::findNextIndex(const GlobalPoint ringCrossing[3], int closest ) const
321 {
322 
323  int firstIndexToCheck = (closest != 0)? 0 : 1;
324  float initialR = ringPars[firstIndexToCheck].theRingR;
325  float rDiff = fabs( ringCrossing[0].perp() - initialR);
326  int theBin = firstIndexToCheck;
327  for (int i = firstIndexToCheck+1; i < 3 ; i++){
328  if ( i != closest) {
329  float ringR = ringPars[i].theRingR;
330  float testDiff = fabs( ringCrossing[i].perp() - ringR);
331  if ( testDiff<rDiff ) {
332  rDiff = testDiff;
333  theBin = i;
334  }
335  }
336  }
337  return theBin;
338 }
339 
340 
341 
342 bool
343 TIDLayer::overlapInR( const TrajectoryStateOnSurface& tsos, int index, double ymax ) const
344 {
345  // assume "fixed theta window", i.e. margin in local y = r is changing linearly with z
346  float tsRadius = tsos.globalPosition().perp();
347  float thetamin = ( max(0.,tsRadius-ymax))/(fabs(tsos.globalPosition().z())+10.f); // add 10 cm contingency
348  float thetamax = ( tsRadius + ymax)/(fabs(tsos.globalPosition().z())-10.f);
349 
350  // do the theta regions overlap ?
351 
352  return !( thetamin > ringPars[index].thetaRingMax || ringPars[index].thetaRingMin > thetamax);
353 }
354 
355 
#define LogDebug(id)
TkRotation< Scalar > RotationType
Definition: Definitions.h:29
Common base class.
int i
Definition: DBlmapReader.cc:9
T y() const
Definition: PV2DBase.h:46
virtual const std::vector< const GeometricSearchDet * > & components() const __attribute__((cold))
Definition: TIDLayer.cc:94
T perp() const
Definition: PV3DBase.h:72
virtual PropagationDirection propagationDirection() const
Definition: Propagator.h:155
std::vector< GeomDet const * > theBasicComps
Definition: TIDLayer.h:59
double zPos
Definition: DDAxes.h:10
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
std::array< int, 3 > ringIndicesByCrossingProximity(const TrajectoryStateOnSurface &startingState, const Propagator &prop) const
Definition: TIDLayer.cc:239
GlobalPoint globalPosition() const
Vector2DBase< float, LocalTag > Local2DVector
PropagationDirection
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:35
Definition: Plane.h:17
#define constexpr
float thetaRingMin
Definition: TIDLayer.h:61
Point3DBase< Scalar, GlobalTag > PositionType
Definition: Definitions.h:30
float thetaRingMax
Definition: TIDLayer.h:61
virtual const std::vector< const GeomDet * > & basicComponents() const
Definition: TIDLayer.h:22
RingPar ringPars[3]
Definition: TIDLayer.h:62
T z() const
Definition: PV3DBase.h:64
tuple result
Definition: query.py:137
TIDLayer(std::vector< const TIDRing * > &rings) __attribute__((cold))
Definition: TIDLayer.cc:114
~TIDLayer() __attribute__((cold))
Definition: TIDLayer.cc:172
double f[11][100]
Definition: Merger.h:31
T min(T a, T b)
Definition: MathUtil.h:58
std::pair< const GeomDet *, TrajectoryStateOnSurface > DetWithState
virtual const BoundSurface & surface() const
The surface of the GeometricSearchDet.
Definition: TIDRing.h:21
void fillRingPars(int i) __attribute__((cold))
Definition: TIDLayer.cc:102
virtual Local2DVector maximalLocalDisplacement(const TrajectoryStateOnSurface &ts, const Plane &plane) const
bool overlapInR(const TrajectoryStateOnSurface &tsos, int i, double ymax) const __attribute__((hot))
Definition: TIDLayer.cc:343
Disk BoundDisk
Definition: BoundDisk.h:62
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
T perp() const
Magnitude of transverse component.
GlobalVector globalMomentum() const
static int position[264][3]
Definition: ReadPGInfo.cc:509
float computeWindowSize(const GeomDet *det, const TrajectoryStateOnSurface &tsos, const MeasurementEstimator &est) const __attribute__((hot))
Definition: TIDLayer.cc:291
BoundDisk * computeDisk(const std::vector< const TIDRing * > &rings) const __attribute__((cold))
Definition: TIDLayer.cc:142
std::pair< const GeomDet *, TrajectoryStateOnSurface > DetWithState
const TIDRing * theComps[3]
Definition: TIDLayer.h:60
int findClosest(const GlobalPoint[3]) const __attribute__((hot))
Definition: TIDLayer.cc:303
void groupedCompatibleDetsV(const TrajectoryStateOnSurface &tsos, const Propagator &prop, const MeasurementEstimator &est, std::vector< DetGroup > &result) const __attribute__((hot))
Definition: TIDRing.cc:92
int findNextIndex(const GlobalPoint[3], int) const __attribute__((hot))
Definition: TIDLayer.cc:320
void groupedCompatibleDetsV(const TrajectoryStateOnSurface &tsos, const Propagator &prop, const MeasurementEstimator &est, std::vector< DetGroup > &result) const __attribute__((hot))
Definition: TIDLayer.cc:179