CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Phase2OTECRingedLayer.cc
Go to the documentation of this file.
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 //hopefully is never called!
22 const std::vector<const GeometricSearchDet*>& Phase2OTECRingedLayer::components() const{
23  if (not theComponents) {
24  std::unique_ptr<std::vector<const GeometricSearchDet*>> temp( new std::vector<const GeometricSearchDet*>() );
25  temp->reserve(NOTECRINGS);
26  for ( auto c: theComps) temp->push_back(c);
27  std::vector<const GeometricSearchDet*>* expected = nullptr;
28  if(theComponents.compare_exchange_strong(expected,temp.get())) {
29  //this thread set the value
30  temp.release();
31  }
32  }
33  return *theComponents;
34  }
35 
36 
37 void
39  const BoundDisk& ringDisk = static_cast<const BoundDisk&>(theComps[i]->surface());
40  float ringMinZ = std::abs( ringDisk.position().z()) - ringDisk.bounds().thickness()/2.;
41  float ringMaxZ = std::abs( ringDisk.position().z()) + ringDisk.bounds().thickness()/2.;
42  ringPars[i].thetaRingMin = ringDisk.innerRadius()/ ringMaxZ;
43  ringPars[i].thetaRingMax = ringDisk.outerRadius()/ ringMinZ;
44  ringPars[i].theRingR=( ringDisk.innerRadius() +
45  ringDisk.outerRadius())/2.;
46 
47 }
48 
49 
50 Phase2OTECRingedLayer::Phase2OTECRingedLayer(vector<const Phase2OTECRing*>& rings):
52  theComponents{nullptr}
53 {
54  //They should be already R-ordered. TO BE CHECKED!!
55  //sort( theRings.begin(), theRings.end(), DetLessR());
56 
57  if ( rings.size() != NOTECRINGS) throw DetLayerException("Number of rings in Phase2 OT EC layer is not equal to NOTECRINGS !!");
58  setSurface( computeDisk( rings ) );
59 
60  for(int i=0; i!=NOTECRINGS; ++i) {
61  theComps[i]=rings[i];
62  fillRingPars(i);
63  theBasicComps.insert(theBasicComps.end(),
64  (*rings[i]).basicComponents().begin(),
65  (*rings[i]).basicComponents().end());
66  }
67 
68 
69  LogDebug("TkDetLayers") << "==== DEBUG Phase2OTECRingedLayer =====" ;
70  LogDebug("TkDetLayers") << "r,zed pos , thickness, innerR, outerR: "
71  << this->position().perp() << " , "
72  << this->position().z() << " , "
73  << this->specificSurface().bounds().thickness() << " , "
74  << this->specificSurface().innerRadius() << " , "
75  << this->specificSurface().outerRadius() ;
76 }
77 
78 
79 BoundDisk*
80 Phase2OTECRingedLayer::computeDisk( const vector<const Phase2OTECRing*>& rings) const
81 {
82  float theRmin = rings.front()->specificSurface().innerRadius();
83  float theRmax = rings.front()->specificSurface().outerRadius();
84  float theZmin = rings.front()->position().z() -
85  rings.front()->surface().bounds().thickness()/2;
86  float theZmax = rings.front()->position().z() +
87  rings.front()->surface().bounds().thickness()/2;
88 
89  for (vector<const Phase2OTECRing*>::const_iterator i = rings.begin(); i != rings.end(); i++) {
90  float rmin = (**i).specificSurface().innerRadius();
91  float rmax = (**i).specificSurface().outerRadius();
92  float zmin = (**i).position().z() - (**i).surface().bounds().thickness()/2.;
93  float zmax = (**i).position().z() + (**i).surface().bounds().thickness()/2.;
94  theRmin = min( theRmin, rmin);
95  theRmax = max( theRmax, rmax);
96  theZmin = min( theZmin, zmin);
97  theZmax = max( theZmax, zmax);
98  }
99 
100  float zPos = (theZmax+theZmin)/2.;
101  PositionType pos(0.,0.,zPos);
103 
104  return new BoundDisk( pos, rot, new SimpleDiskBounds(theRmin, theRmax,
105  theZmin-zPos, theZmax-zPos));
106 
107 }
108 
109 
111  for (auto c : theComps) delete c;
112 
113  delete theComponents.load();
114 }
115 
116 
117 
118 void
120  const Propagator& prop,
121  const MeasurementEstimator& est,
122  std::vector<DetGroup> & result) const
123 {
124  std::array<int,3> const & ringIndices = ringIndicesByCrossingProximity(startingState,prop);
125  if ( ringIndices[0]==-1 || ringIndices[1] ==-1 || ringIndices[2] == -1 ) {
126  edm::LogError("TkDetLayers") << "TkRingedForwardLayer::groupedCompatibleDets : error in CrossingProximity";
127  return;
128  }
129 
130  //order is odd rings in front of even rings
131  constexpr int ringOrder[NOTECRINGS]{0,1,0,1,0,1,0,1,0,1,0,1,0,1,0};
132  auto index = [&ringIndices,& ringOrder](int i) { return ringOrder[ringIndices[i]];};
133 
134  std::vector<DetGroup> closestResult;
135  theComps[ringIndices[0]]->groupedCompatibleDetsV( startingState, prop, est, closestResult);
136  // if the closest is empty, use the next one and exit: inherited from TID !
137  if ( closestResult.empty() ){
138  theComps[ringIndices[1]]->groupedCompatibleDetsV( startingState, prop, est, result);
139  return;
140  }
141 
142  DetGroupElement closestGel( closestResult.front().front());
143  float rWindow = computeWindowSize( closestGel.det(), closestGel.trajectoryState(), est);
144 
145  // check if next ring and next next ring are found and if there is overlap
146 
147  bool ring1ok = ringIndices[1] != -1 && overlapInR(closestGel.trajectoryState(),ringIndices[1],rWindow);
148  bool ring2ok = ringIndices[2] != -1 && overlapInR(closestGel.trajectoryState(),ringIndices[2],rWindow);
149 
150  // look for the two rings in the same plane (are they only two?)
151 
152  // determine if we are propagating from in to out (0) or from out to in (1)
153 
154  int direction = 0;
155  if(startingState.globalPosition().z()*startingState.globalMomentum().z()>0) {
156  if(prop.propagationDirection() == alongMomentum) direction=0;
157  else direction=1;
158  }
159  else{
160  if(prop.propagationDirection() == alongMomentum) direction=1;
161  else direction=0;
162  }
163 
164  if((index(0) == index(1)) && (index(0) == index(2))) {
165  edm::LogInfo("AllRingsInOnePlane") << " All rings: "
166  << ringIndices[0] << " "
167  << ringIndices[1] << " "
168  << ringIndices[2] << " in one plane. Only the first two will be considered";
169  ring2ok=false;
170  }
171 
172  if(index(0) == index(1)) {
173  if(ring1ok) {
174  std::vector<DetGroup> ring1res;
175  theComps[ringIndices[1]]->groupedCompatibleDetsV( startingState, prop, est, ring1res);
176  DetGroupMerger::addSameLevel(std::move(ring1res),closestResult);
177  }
178  if(ring2ok) {
179  std::vector<DetGroup> ring2res;
180  theComps[ringIndices[2]]->groupedCompatibleDetsV( startingState, prop, est, ring2res);
181  DetGroupMerger::orderAndMergeTwoLevels(std::move(closestResult),std::move(ring2res),result,index(0),direction);
182  return;
183  }
184  else {
185  result.swap(closestResult);
186  return;
187  }
188  }
189  else if(index(0) == index(2)) {
190  if(ring2ok) {
191  std::vector<DetGroup> ring2res;
192  theComps[ringIndices[2]]->groupedCompatibleDetsV( startingState, prop, est, ring2res);
193  DetGroupMerger::addSameLevel(std::move(ring2res),closestResult);
194  }
195  if(ring1ok) {
196  std::vector<DetGroup> ring1res;
197  theComps[ringIndices[1]]->groupedCompatibleDetsV( startingState, prop, est, ring1res);
198  DetGroupMerger::orderAndMergeTwoLevels(std::move(closestResult),std::move(ring1res),result,index(0),direction);
199  return;
200  }
201  else {
202  result.swap(closestResult);
203  return;
204  }
205  }
206  else {
207  std::vector<DetGroup> ring12res;
208  if(ring1ok) {
209  std::vector<DetGroup> ring1res;
210  theComps[ringIndices[1]]->groupedCompatibleDetsV( startingState, prop, est, ring1res);
211  ring12res.swap(ring1res);
212  }
213  if(ring2ok) {
214  std::vector<DetGroup> ring2res;
215  theComps[ringIndices[2]]->groupedCompatibleDetsV( startingState, prop, est, ring2res);
216  DetGroupMerger::addSameLevel(std::move(ring2res),ring12res);
217  }
218  if(!ring12res.empty()) {
219  DetGroupMerger::orderAndMergeTwoLevels(std::move(closestResult),std::move(ring12res),result,index(0),direction);
220  return;
221  }
222  else {
223  result.swap(closestResult);
224  return;
225  }
226  }
227 }
228 
229 
230 std::array<int,3>
232  const Propagator& prop ) const
233 {
234  typedef HelixForwardPlaneCrossing Crossing;
236 
237  HelixPlaneCrossing::PositionType startPos( startingState.globalPosition());
238  HelixPlaneCrossing::DirectionType startDir( startingState.globalMomentum());
240  float rho( startingState.transverseCurvature());
241 
242  // calculate the crossings with the ring surfaces
243  // rings are assumed to be sorted in R !
244 
245  Crossing myXing( startPos, startDir, rho, propDir );
246 
247  GlobalPoint ringCrossings[NOTECRINGS];
248  // vector<GlobalVector> ringXDirections;
249 
250  for (int i = 0; i < NOTECRINGS ; i++ ) {
251  const BoundDisk & theRing = static_cast<const BoundDisk &>(theComps[i]->surface());
252  pair<bool,double> pathlen = myXing.pathLength( theRing);
253  if ( pathlen.first ) {
254  ringCrossings[i] = GlobalPoint( myXing.position(pathlen.second ));
255  // ringXDirections.push_back( GlobalVector( myXing.direction(pathlen.second )));
256  } else {
257  // TO FIX.... perhaps there is something smarter to do
258  //throw DetLayerException("trajectory doesn't cross TID rings");
259  ringCrossings[i] = GlobalPoint( 0.,0.,0.);
260  // ringXDirections.push_back( GlobalVector( 0.,0.,0.));
261  }
262  }
263 
264  //find three closest rings to the crossing
265 
266  std::array<int,3> closests = findThreeClosest(ringCrossings);
267 
268  return closests;
269 }
270 
271 
272 
273 
274 float
276  const TrajectoryStateOnSurface& tsos,
277  const MeasurementEstimator& est) const
278 {
279  const Plane& startPlane = det->surface();
281  est.maximalLocalDisplacement( tsos, startPlane);
282  return maxDistance.y();
283 }
284 
285 std::array<int,3>
287 {
288  std::array<int,3> theBins={{-1,-1,-1}};
289  theBins[0] = 0;
290  float initialR = ringPars[0].theRingR;
291  float rDiff0 = std::abs( ringCrossing[0].perp() - initialR);
292  float rDiff1 = -1.;
293  float rDiff2 = -1.;
294  for (int i = 1; i < NOTECRINGS ; i++){
295  float ringR = ringPars[i].theRingR;
296  float testDiff = std::abs( ringCrossing[i].perp() - ringR);
297  if ( testDiff<rDiff0 ) {
298  rDiff2 = rDiff1;
299  rDiff1 = rDiff0;
300  rDiff0 = testDiff;
301  theBins[2] = theBins[1];
302  theBins[1] = theBins[0];
303  theBins[0] = i;
304  }
305  else
306  if ( rDiff1 < 0 || testDiff<rDiff1 ) {
307  rDiff2 = rDiff1;
308  rDiff1 = testDiff;
309  theBins[2] = theBins[1];
310  theBins[1] = i;
311  }
312  else
313  if ( rDiff2 < 0 || testDiff<rDiff2 ) {
314  rDiff2 = testDiff;
315  theBins[2] = i;
316  }
317  }
318 
319  return theBins;
320 }
321 
322 bool
324 {
325  // assume "fixed theta window", i.e. margin in local y = r is changing linearly with z
326  float tsRadius = tsos.globalPosition().perp();
327  float thetamin = ( max(0.,tsRadius-ymax))/(std::abs(tsos.globalPosition().z())+10.f); // add 10 cm contingency
328  float thetamax = ( tsRadius + ymax)/(std::abs(tsos.globalPosition().z())-10.f);
329 
330  // do the theta regions overlap ?
331 
332  return !( thetamin > ringPars[index].thetaRingMax || ringPars[index].thetaRingMin > thetamax);
333 }
334 
335 
#define LogDebug(id)
TkRotation< Scalar > RotationType
Definition: Definitions.h:29
Common base class.
void fillRingPars(int i) __attribute__((cold))
int i
Definition: DBlmapReader.cc:9
T y() const
Definition: PV2DBase.h:46
T perp() const
Definition: PV3DBase.h:72
virtual PropagationDirection propagationDirection() const
Definition: Propagator.h:155
const Phase2OTECRing * theComps[15]
virtual const std::vector< const GeometricSearchDet * > & components() const __attribute__((cold))
double zPos
Definition: DDAxes.h:10
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
GlobalPoint globalPosition() const
virtual const BoundSurface & surface() const
The surface of the GeometricSearchDet.
Vector2DBase< float, LocalTag > Local2DVector
PropagationDirection
std::array< int, 3 > findThreeClosest(const GlobalPoint[15]) const __attribute__((hot))
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:40
Definition: Plane.h:17
#define constexpr
BoundDisk * computeDisk(const std::vector< const Phase2OTECRing * > &rings) const __attribute__((cold))
Point3DBase< Scalar, GlobalTag > PositionType
Definition: Definitions.h:30
static void addSameLevel(std::vector< DetGroup > &&gvec, std::vector< DetGroup > &result)
void groupedCompatibleDetsV(const TrajectoryStateOnSurface &tsos, const Propagator &prop, const MeasurementEstimator &est, std::vector< DetGroup > &result) const __attribute__((hot))
T z() const
Definition: PV3DBase.h:64
tuple result
Definition: query.py:137
def move
Definition: eostools.py:508
Phase2OTECRingedLayer(std::vector< const Phase2OTECRing * > &rings) __attribute__((cold))
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
bool overlapInR(const TrajectoryStateOnSurface &tsos, int i, double ymax) const __attribute__((hot))
T min(T a, T b)
Definition: MathUtil.h:58
std::pair< const GeomDet *, TrajectoryStateOnSurface > DetWithState
float computeWindowSize(const GeomDet *det, const TrajectoryStateOnSurface &tsos, const MeasurementEstimator &est) const __attribute__((hot))
virtual Local2DVector maximalLocalDisplacement(const TrajectoryStateOnSurface &ts, const Plane &plane) const
void groupedCompatibleDetsV(const TrajectoryStateOnSurface &tsos, const Propagator &prop, const MeasurementEstimator &est, std::vector< DetGroup > &result) const __attribute__((hot))
std::array< int, 3 > ringIndicesByCrossingProximity(const TrajectoryStateOnSurface &startingState, const Propagator &prop) const
Disk BoundDisk
Definition: BoundDisk.h:62
std::atomic< std::vector< const GeometricSearchDet * > * > theComponents
T perp() const
Magnitude of transverse component.
GlobalVector globalMomentum() const
static int position[264][3]
Definition: ReadPGInfo.cc:509
#define NOTECRINGS
std::pair< const GeomDet *, TrajectoryStateOnSurface > DetWithState
static void orderAndMergeTwoLevels(std::vector< DetGroup > &&one, std::vector< DetGroup > &&two, std::vector< DetGroup > &result, int firstIndex, int firstCrossed)
~Phase2OTECRingedLayer() __attribute__((cold))