CMS 3D CMS Logo

Functions
trackerStablePhiSort.h File Reference
#include <vector>
#include <algorithm>
#include <cmath>

Go to the source code of this file.

Functions

template<class RandomAccessIterator , class Extractor >
void trackerStablePhiSort (RandomAccessIterator begin, RandomAccessIterator end, const Extractor &extr)
 

Function Documentation

◆ trackerStablePhiSort()

template<class RandomAccessIterator , class Extractor >
void trackerStablePhiSort ( RandomAccessIterator  begin,
RandomAccessIterator  end,
const Extractor &  extr 
)

Definition at line 9 of file trackerStablePhiSort.h.

9  {
10  using Scalar = decltype(extr(*begin));
12  using Element = std::pair<Scalar, Value*>;
13 
14  std::vector<Element> tmpvec(end - begin);
15  std::transform(begin, end, tmpvec.begin(), [&extr](Value& it) { return Element(extr(it), &it); });
16 
17  std::sort(tmpvec.begin(), tmpvec.end());
18 
19  // special tratment of the TEC modules of rings in petals near phi=0 there
20  // are at most 5 modules, no other structure has less than ~10 elements to
21  // order in phi hence the special case in phi~0 if the size of the elements
22  // to order is <=5
23  constexpr unsigned int nMaxModulesPerRing = 5;
24  constexpr double phiMin = M_PI_4;
25  constexpr double phiMax = 2 * M_PI - phiMin;
26  constexpr double tolerance = 0.000001;
27 
28  const unsigned int n = tmpvec.size();
29 
30  if (n > nMaxModulesPerRing) {
31  // stability check
32  // check if the last element is too near to zero --> probably it is zero
33  if (std::abs(tmpvec.back().first - 0) < tolerance // near 0
34  || std::abs(tmpvec.back().first - 2 * M_PI) < tolerance) // near 2pi
35  {
36  // move it to front
37  tmpvec.insert(tmpvec.begin(), tmpvec.back());
38  tmpvec.pop_back();
39  }
40  } else {
41  // check if all the elements have phi<phiMin or phi>phiMax to be sure we
42  // are near phi~0 (angles are in [0,2pi) range) if a phi goes out from
43  // [0,phiMin]U[phiMax,2pi) it is not the case sorted. if first > phiMax all
44  // other will also...
45  auto p = std::find_if(tmpvec.begin(), tmpvec.end(), [&phiMin](auto const& x) { return x.first > phiMin; });
46 
47  // go on if this is the petal phi~0 case, restricted to the case where all
48  // the |phi| are in range [0,phiMin]
49  if (p == tmpvec.end() || p->first >= phiMax) {
50  // in this case the ordering must be: ('negative' values, >) and then
51  // ('positive' values, >) in (-pi,pi] mapping already sorted, just swap
52  // ranges
53  if (p != tmpvec.end()) {
54  tmpvec.insert(tmpvec.begin(), p, tmpvec.end());
55  tmpvec.resize(n);
56  }
57  }
58  }
59 
60  // overwrite the input range with the sorted values
61  // copy of input container not necessary, but tricky to avoid
62  std::vector<Value> tmpvecy(n);
63  std::transform(tmpvec.begin(), tmpvec.end(), tmpvecy.begin(), [](auto& x) { return *x.second; });
64  std::copy(tmpvecy.begin(), tmpvecy.end(), begin);
65 }

References funct::abs(), filterCSVwithJSON::copy, mps_fire::end, M_PI, dqmiodumpmetadata::n, AlCaHLTBitMon_ParallelJobs::p, AlignmentTrackSelector_cfi::phiMax, AlignmentTrackSelector_cfi::phiMin, jetUpdater_cfi::sort, tolerance, HcalDetIdTransform::transform(), and genVertex_cff::x.

Referenced by CmsTrackerDiskBuilder< FilteredView >::sortNS(), CmsTrackerWheelBuilder< FilteredView >::sortNS(), CmsTrackerRingBuilder< FilteredView >::sortNS(), CmsTrackerPixelPhase2RingBuilder< FilteredView >::sortNS(), CmsTrackerOTRingBuilder< FilteredView >::sortNS(), CmsTrackerOTLayerBuilder< FilteredView >::sortNS(), and CmsTrackerLayerBuilder< FilteredView >::sortNS().

dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
filterCSVwithJSON.copy
copy
Definition: filterCSVwithJSON.py:36
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
align::Scalar
double Scalar
Definition: Definitions.h:25
AlignmentTrackSelector_cfi.phiMin
phiMin
Definition: AlignmentTrackSelector_cfi.py:18
mps_fire.end
end
Definition: mps_fire.py:242
AlignmentTrackSelector_cfi.phiMax
phiMax
Definition: AlignmentTrackSelector_cfi.py:17
HcalDetIdTransform::transform
unsigned transform(const HcalDetId &id, unsigned transformCode)
Definition: HcalDetIdTransform.cc:7
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
tolerance
const double tolerance
Definition: HGCalGeomParameters.cc:29
M_PI
#define M_PI
Definition: BXVectorInputProducer.cc:49
reco::JetExtendedAssociation::value_type
Container::value_type value_type
Definition: JetExtendedAssociation.h:30
genVertex_cff.x
x
Definition: genVertex_cff.py:12
reco::JetExtendedAssociation::Value
reco::JetExtendedAssociation::JetExtendedData Value
Definition: JetExtendedAssociation.h:27
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22