CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Classes | Namespaces | Functions
TrackerStablePhiSort.h File Reference
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
#include <cmath>
#include <boost/bind.hpp>

Go to the source code of this file.

Classes

struct  details::PhiSortElement< Object, Scalar >
 

Namespaces

 details
 

Functions

template<typename RandomAccessIterator , typename Extractor >
void TrackerStablePhiSort (RandomAccessIterator begin, RandomAccessIterator end, const Extractor &extr)
 

Function Documentation

template<typename RandomAccessIterator , typename Extractor >
void TrackerStablePhiSort ( RandomAccessIterator  begin,
RandomAccessIterator  end,
const Extractor &  extr 
)

Definition at line 46 of file TrackerStablePhiSort.h.

References begin, filterCSVwithJSON::copy, M_PI, getGTfromDQMFile::obj, AlCaHLTBitMon_ParallelJobs::p, python.multivaluedict::sort(), svgfig::template(), create_public_lumi_plots::transform, and relativeConstraints::value.

Referenced by CmsTrackerLayerBuilder::sortNS(), CmsTrackerRingBuilder::sortNS(), CmsTrackerOTRingBuilder::sortNS(), CmsTrackerWheelBuilder::sortNS(), and CmsTrackerDiskBuilder::sortNS().

48  {
49 
50  typedef typename Extractor::result_type Scalar;
52 
54 
55 
56 
57  std::vector<Element> tmpvec(end-begin);
58  std::transform(begin,end,tmpvec.begin(),
59  boost::bind(Element::template build<Extractor>,_1, boost::cref(extr))
60  );
61 
62  std::vector<Element> tmpcop(end-begin);
63 
64  std::sort(tmpvec.begin(), tmpvec.end());
65 
66  const unsigned int vecSize = tmpvec.size();
67 
68 
69 
70  // special tratment of the TEC modules of rings in petals near phi=0
71  // there are at most 5 modules, no other structure has less than ~10 elements to order in phi
72  // hence the special case in phi~0 if the size of the elements to order is <=5
73  const unsigned int nMaxModulesPerRing = 5;
74  bool phiZeroCase = true;
75  //
76  const double phiMin = M_PI_4;
77  const double phiMax = 2*M_PI-phiMin;
78  //
79  if( vecSize > nMaxModulesPerRing ) {
80  //stability check
81  // check if the last element is too near to zero --> probably it is zero
82  double tolerance = 0.000001;
83  if( fabs(tmpvec.back().value - 0) < tolerance // near 0
84  ||
85  fabs(tmpvec.back().value - 2*M_PI) < tolerance ) { // near 2pi
86  // move it to front
87  tmpvec.insert(tmpvec.begin(),tmpvec.back());
88  tmpvec.pop_back();
89  }
90  }
91  else {
92  // check if all the elements have phi<phiMin or phi>phiMax to be sure we are near phi~0 (angles are in [0,2pi) range)
93  // if a phi goes out from [0,phiMin]U[phiMax,2pi) it is not the case
94  // sorted. if first > phiMax all other will also...
95  typename std::vector<Element>::iterator p =
96  std::find_if(tmpvec.begin(),tmpvec.end(), boost::bind(&Element::value,_1) > phiMin);
97  phiZeroCase = !(p!=tmpvec.end() && (*p).value<phiMax);
98 
99  // go on if this is the petal phi~0 case, restricted to the case where all the |phi| are in range [0,phiMin]
100  if(phiZeroCase) {
101  // in this case the ordering must be: ('negative' values, >) and then ('positive' values, >) in (-pi,pi] mapping
102  // already sorted, just swap ranges
103  if(p!=tmpvec.end()) {
104  tmpvec.insert(tmpvec.begin(),p,tmpvec.end());
105  tmpvec.resize(vecSize);
106  }
107  }
108  }
109 
110  // overwrite the input range with the sorted values
111  // copy of input container not necessary, but tricky to avoid
112  std::vector<value_type> tmpvecy(vecSize);
113  std::transform(tmpvec.begin(),tmpvec.end(),tmpvecy.begin(),boost::bind(&Element::obj,_1));
114  std::copy(tmpvecy.begin(),tmpvecy.end(),begin);
115 
116 }
double Scalar
Definition: Definitions.h:27
#define end
Definition: vmac.h:37
Container::value_type value_type
#define M_PI
#define begin
Definition: vmac.h:30
def template
Definition: svgfig.py:520