CMS 3D CMS Logo

CrossingPtBasedLinearizationPointFinder.cc
Go to the documentation of this file.
8 #include <cmath>
9 #include <algorithm>
10 
11 // #define Use_GraphicsHarvester
12 #ifdef Use_GraphicsHarvester
13 #include "RecoVertex/VertexSimpleVis/interface/PrimitivesHarvester.h"
14 #include "Utilities/UI/interface/SimpleConfigurable.h"
18 #endif
19 
20 namespace {
21  inline GlobalPoint operator-(const GlobalPoint& a, const GlobalPoint& b) {
22  return GlobalPoint(a.x() - b.x(), a.y() - b.y(), a.z() - b.z());
23  }
24 
25  inline GlobalPoint operator+(const GlobalPoint& a, const GlobalPoint& b) {
26  return GlobalPoint(a.x() + b.x(), a.y() + b.y(), a.z() + b.z());
27  }
28 
29  inline GlobalPoint operator/(const GlobalPoint& a, const double b) {
30  return GlobalPoint(a.x() / b, a.y() / b, a.z() / b);
31  }
32 
33 #ifndef __clang__
34  inline GlobalPoint operator*(const GlobalPoint& a, const double b) {
35  return GlobalPoint(a.x() * b, a.y() * b, a.z() * b);
36  }
37 
38  inline GlobalPoint operator*(const double b, const GlobalPoint& a) {
39  return GlobalPoint(a.x() * b, a.y() * b, a.z() * b);
40  }
41 #endif
42 
43  inline unsigned int sum(unsigned int nr) {
44  /*
45  int ret=0;
46  for ( int i=1; i<= nr ; i++ )
47  {
48  ret+=i;
49  }
50  return ret;
51  */
52  return (nr * (nr + 1)) / 2;
53  }
54 
55 #ifdef Use_GraphicsHarvester
56 
57  void graphicsDebug(const std::vector<PointAndDistance>& input) {
58  bool sve = SimpleConfigurable<bool>(false, "CrossingPointStudy:Harvest").value();
59  std::string fname = SimpleConfigurable<string>("crossingpoints.txt", "CrossingPointStudy:FileName").value();
60  if (sve) {
61  for (std::vector<PointAndDistance>::const_iterator i = input.begin(); i != input.end(); ++i) {
62  std::map<std::string, MultiType> attrs;
63  attrs["name"] = "GlobalPoint";
64  attrs["color"] = "yellow";
65  attrs["mag"] = .7;
66  attrs["comment"] = "Input for CrossingPtBasedLinearizationPointFinder";
67  PrimitivesHarvester(fname).save(i->first, attrs);
68  }
69  std::map<std::string, MultiType> attrs;
70  attrs["name"] = "The Mode(*theAlgo)";
71  attrs["color"] = "green";
72  attrs["comment"] = "Output from CrossingPtBasedLinearizationPointFinder";
73  PrimitivesHarvester(fname).save(ret, attrs);
75  attrs["name"] = "The Mode(SubsetHSM)";
76  attrs["color"] = "red";
77  PrimitivesHarvester(fname).save(subsethsm, attrs);
79  attrs["name"] = "The Mode(HSM)";
80  attrs["color"] = "blue";
81  PrimitivesHarvester(fname).save(hsm, attrs);
83  attrs["name"] = "The Mode(LMS)";
84  attrs["color"] = "gold";
85  PrimitivesHarvester(fname).save(lms, attrs);
86  }
87  }
88 #endif
89 } // namespace
90 
92  const signed int n_pairs)
93  : useMatrix(false), theNPairs(n_pairs), theMatrix(nullptr), theAlgo(algo.clone()) {}
94 
96  const ModeFinder3d& algo,
97  const signed int n_pairs)
98  : useMatrix(m->hasCrossingPoints()), theNPairs(n_pairs), theMatrix(m), theAlgo(algo.clone()) {}
99 
102  : useMatrix(o.useMatrix),
103  theNPairs(o.theNPairs),
104  theMatrix(o.theMatrix /* nope, we dont clone!! */),
105  theAlgo(o.theAlgo->clone()) {}
106 
108 
110  const std::vector<reco::TransientTrack>& tracks) const {
111  unsigned int n_tracks = (2 * (unsigned int)(theNPairs)) < tracks.size() ? 2 * theNPairs : tracks.size();
112 
113  std::vector<reco::TransientTrack> newtracks = tracks;
114  partial_sort(newtracks.begin(), newtracks.begin() + n_tracks, newtracks.end(), CompareTwoTracks());
115  newtracks.erase(newtracks.begin() + n_tracks, newtracks.end());
116 
117  /*
118  * old version, when we have a default constructor
119  *
120 
121  std::vector <reco::TransientTrack> newtracks ( n_tracks );
122  partial_sort_copy ( tracks.begin(), tracks.end(), newtracks.begin(),
123  newtracks.begin() + n_tracks , CompareTwoTracks() );
124  */
125 
126  return newtracks;
127 }
128 
129 typedef std::pair<GlobalPoint, float> PointAndDistance;
130 
132  const std::vector<reco::TransientTrack>& tracks) const {
133  std::vector<PointAndDistance> vgp;
134  // vgp.reserve ( ( tracks.size() * ( tracks.size()-1 ) ) / 2 - 1 );
136  bool status;
137  std::vector<reco::TransientTrack>::const_iterator end = tracks.end();
138  std::vector<reco::TransientTrack>::const_iterator endm1 = (end - 1);
139  for (std::vector<reco::TransientTrack>::const_iterator x = tracks.begin(); x != endm1; ++x) {
140  for (std::vector<reco::TransientTrack>::const_iterator y = x + 1; y != end; ++y) {
141  status = ttmd.calculate((*x).impactPointState(), (*y).impactPointState());
142  if (status) {
143  std::pair<GlobalPoint, GlobalPoint> pts = ttmd.points();
144  std::pair<GlobalPoint, float> v((pts.second + pts.first) / 2., (pts.second - pts.first).mag());
145  vgp.push_back(v);
146  } // If sth goes wrong, we just dont add. Who cares?
147  }
148  }
149  if (vgp.empty()) {
151  }
152  return find(vgp);
153 }
154 
156  const std::vector<reco::TransientTrack>& tracks) const {
157  std::vector<PointAndDistance> vgp;
158  vgp.reserve((int)(tracks.size() * (tracks.size() - 1) / 2. - 1));
159  std::vector<reco::TransientTrack>::const_iterator end = tracks.end();
160  std::vector<reco::TransientTrack>::const_iterator endm1 = (end - 1);
161  for (std::vector<reco::TransientTrack>::const_iterator x = tracks.begin(); x != endm1; ++x) {
162  for (std::vector<reco::TransientTrack>::const_iterator y = x + 1; y != end; ++y) {
164  vgp.push_back(v);
165  }
166  }
167  if (vgp.empty()) {
169  }
170  return find(vgp);
171 }
172 
174  const std::vector<FreeTrajectoryState>& tracks) const {
176 }
177 
178 GlobalPoint CrossingPtBasedLinearizationPointFinder::find(const std::vector<PointAndDistance>& input) const {
179  /*
180  std::cout << "[CrossingPtBasedLinearizationPointFinder] input size="
181  << input.size() << std::endl;*/
182  GlobalPoint ret = (*theAlgo)(input);
183 #ifdef Use_GraphicsHarvester
184 
185  graphicsDebug(input);
186 #endif
187 
188  return ret;
189 }
190 
192  const std::vector<reco::TransientTrack>& tracks) const {
193  if (tracks.size() < 2)
194  throw LinPtException("CrossingPtBasedLinPtFinder: too few tracks given.");
195  std::vector<PointAndDistance> vgp;
196  if (theNPairs == -1) {
197  if (useMatrix) {
198  return useFullMatrix(tracks);
199  } else {
200  return useAllTracks(tracks);
201  }
202  }
203 
204  if (sum(tracks.size() - 1) < ((unsigned int)(theNPairs))) {
205  /*
206  std::cout << "[CrossingPtBasedLinearizationPointFinder] we exploit all track pairs"
207  << std::endl;*/
208  // we have fewer track pair options than is foreseen
209  // in the quota.
210  // so we exploit all tracks pairs.
211  return useAllTracks(tracks);
212  }
213 
214  std::vector<reco::TransientTrack> goodtracks = getBestTracks(tracks);
215 
216  // we sort according to momenta.
217  if (goodtracks.size() < 2)
218  throw LinPtException("CrossingPtBasedLinPtFinder: less than two tracks given");
219  // vgp.reserve ( theNPairs - 1 );
220  unsigned int t_first = 0;
221  unsigned int t_interval = goodtracks.size() / 2;
222  unsigned int lim = goodtracks.size() - 1;
223 
224  /*
225  std::cout << "[CrossingPtBasedLinearizationPointFinder] we start: npairs=" << theNPairs
226  << std::endl;
227  std::cout << "[CrossingPtBasedLinearizationPointFinder] t_interval=" << t_interval << std::endl;
228  std::cout << "[CrossingPtBasedLinearizationPointFinder goodtracks.size=" << goodtracks.size()
229  << std::endl;*/
230 
231  // the 'direction' false: intervals will expand
232  // true: intervals will shrink
233  bool dir = false;
234 
235  while (vgp.size() < ((unsigned int)(theNPairs))) {
236  reco::TransientTrack rt1 = goodtracks[t_first];
237  reco::TransientTrack rt2 = goodtracks[t_first + t_interval];
238  // std::cout << "Considering now: " << t_first << ", " << t_first+t_interval << std::endl;
239  if (useMatrix) {
241  vgp.push_back(v);
242  } else { // No DistanceMatrix available
244  bool status = ttmd.calculate(rt1.impactPointState(), rt2.impactPointState());
245  if (status) {
246  std::pair<GlobalPoint, GlobalPoint> pts = ttmd.points();
247  PointAndDistance v((pts.second + pts.first) / 2., (pts.second - pts.first).mag());
248  vgp.push_back(v);
249  }
250  }
251  if ((t_first + t_interval) < lim) {
252  t_first++;
253  } else if (dir) {
254  t_first = 0;
255  t_interval--;
256  if (t_interval == 0) {
257  /* std::cout << "[CrossingPtBasedLinearizationPointFinder] t_interval=0. break."
258  << std::endl;*/
259  break;
260  }
261  } else {
262  t_first = 0;
263  t_interval++;
264  if (t_interval == goodtracks.size()) {
265  /* std::cout << "[CrossingPtBasedLinearizationPointFinder] t_interval="
266  << goodtracks.size() << "(max). start to decrease intervals"
267  << std::endl; */
268  dir = true;
269  t_interval = goodtracks.size() / 2 - 1;
270  }
271  }
272  }
273  if (vgp.empty()) {
274  // no crossing points? Fallback to a crossingpoint-less lin pt finder!
276  }
277  return find(vgp);
278 
279  return GlobalPoint(0., 0., 0.); // if nothing else, then return 0,0,0
280 }
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:543
DDAxes::y
mps_fire.i
i
Definition: mps_fire.py:428
input
static const std::string input
Definition: EdmProvDump.cc:48
funct::false
false
Definition: Factorize.h:29
operator*
MatrixMeschach operator*(const MatrixMeschach &mat1, const MatrixMeschach &mat2)
Definition: MatrixMeschach.cc:117
CrossingPtBasedLinearizationPointFinder::getLinearizationPoint
GlobalPoint getLinearizationPoint(const std::vector< reco::TransientTrack > &) const override
Definition: CrossingPtBasedLinearizationPointFinder.cc:191
mps_update.status
status
Definition: mps_update.py:68
TwoTrackMinimumDistance
Definition: TwoTrackMinimumDistance.h:20
CrossingPtBasedLinearizationPointFinder::CrossingPtBasedLinearizationPointFinder
CrossingPtBasedLinearizationPointFinder(const ModeFinder3d &algo, const signed int n_pairs=5)
Definition: CrossingPtBasedLinearizationPointFinder.cc:91
ModeFinder3d
Definition: ModeFinder3d.h:14
RecTracksDistanceMatrix
Definition: RecTracksDistanceMatrix.h:17
SubsetHsmModeFinder3d.h
ModeFinder3d.h
DDAxes::x
TransientTrack.h
findQualityFiles.v
v
Definition: findQualityFiles.py:179
LmsModeFinder3d.h
TwoTrackMinimumDistance.h
CrossingPtBasedLinearizationPointFinder::~CrossingPtBasedLinearizationPointFinder
~CrossingPtBasedLinearizationPointFinder() override
Definition: CrossingPtBasedLinearizationPointFinder.cc:107
EcalTangentSkim_cfg.o
o
Definition: EcalTangentSkim_cfg.py:42
TwoTrackMinimumDistance::calculate
bool calculate(const TrajectoryStateOnSurface &sta, const TrajectoryStateOnSurface &stb) override
Definition: TwoTrackMinimumDistance.cc:83
RecTracksDistanceMatrix::distance
virtual double distance(const reco::TransientTrack, const reco::TransientTrack) const =0
CrossingPtBasedLinearizationPointFinder.h
cmsdt::algo
algo
Definition: constants.h:171
operator-
MatrixMeschach operator-(const MatrixMeschach &mat1, const MatrixMeschach &mat2)
Definition: MatrixMeschach.cc:167
clone
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:78
CrossingPtBasedLinearizationPointFinder::theAlgo
ModeFinder3d * theAlgo
Definition: CrossingPtBasedLinearizationPointFinder.h:67
mps_fire.end
end
Definition: mps_fire.py:242
CrossingPtBasedLinearizationPointFinder::useFullMatrix
GlobalPoint useFullMatrix(const std::vector< reco::TransientTrack > &) const
Definition: CrossingPtBasedLinearizationPointFinder.cc:155
GlobalPoint
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
Point3DBase< float, GlobalTag >
b
double b
Definition: hdecay.h:118
TwoTrackMinimumDistance::points
std::pair< GlobalPoint, GlobalPoint > points() const override
Definition: TwoTrackMinimumDistance.cc:75
a
double a
Definition: hdecay.h:119
EgHLTOffHistBins_cfi.nr
nr
Definition: EgHLTOffHistBins_cfi.py:4
tracks
const uint32_t *__restrict__ const HitContainer *__restrict__ TkSoA *__restrict__ tracks
Definition: CAHitNtupletGeneratorKernelsImpl.h:176
CrossingPtBasedLinearizationPointFinder::useMatrix
const bool useMatrix
Definition: CrossingPtBasedLinearizationPointFinder.h:54
reco::TransientTrack::impactPointState
TrajectoryStateOnSurface impactPointState() const
Definition: TransientTrack.h:96
CrossingPtBasedLinearizationPointFinder::getBestTracks
std::vector< reco::TransientTrack > getBestTracks(const std::vector< reco::TransientTrack > &) const
Definition: CrossingPtBasedLinearizationPointFinder.cc:109
createfilelist.int
int
Definition: createfilelist.py:10
SubsetHsmModeFinder3d
Definition: SubsetHsmModeFinder3d.h:14
CrossingPtBasedLinearizationPointFinder::theNPairs
signed int theNPairs
Definition: CrossingPtBasedLinearizationPointFinder.h:58
RPCpg::pts
static const double pts[33]
Definition: Constants.h:30
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
LinPtException.h
alignmentValidation.fname
string fname
main script
Definition: alignmentValidation.py:959
FallbackLinearizationPointFinder::getLinearizationPoint
GlobalPoint getLinearizationPoint(const std::vector< reco::TransientTrack > &) const override
Definition: FallbackLinearizationPointFinder.cc:13
LinPtException
Definition: LinPtException.h:10
reco::TransientTrack
Definition: TransientTrack.h:19
Geom::operator/
T operator/(const OnePiRange< T > &a, const OnePiRange< T > &b)
Division.
Definition: OnePiRange.h:122
LmsModeFinder3d
Definition: LmsModeFinder3d.h:8
RecTracksDistanceMatrix::crossingPoint
virtual GlobalPoint crossingPoint(const reco::TransientTrack, const reco::TransientTrack) const =0
CrossingPtBasedLinearizationPointFinder
Definition: CrossingPtBasedLinearizationPointFinder.h:26
PointAndDistance
std::pair< GlobalPoint, float > PointAndDistance
Definition: CrossingPtBasedLinearizationPointFinder.cc:129
LinearizationPointFinder::getLinearizationPoint
virtual GlobalPoint getLinearizationPoint(const std::vector< reco::TransientTrack > &) const =0
FallbackLinearizationPointFinder
Definition: FallbackLinearizationPointFinder.h:13
HsmModeFinder3d
Definition: HsmModeFinder3d.h:12
CrossingPtBasedLinearizationPointFinder::theMatrix
const RecTracksDistanceMatrix * theMatrix
Definition: CrossingPtBasedLinearizationPointFinder.h:59
FallbackLinearizationPointFinder.h
CrossingPtBasedLinearizationPointFinder::CompareTwoTracks
Definition: CrossingPtBasedLinearizationPointFinder.h:71
GlobalPoint.h
CrossingPtBasedLinearizationPointFinder::find
GlobalPoint find(const std::vector< std::pair< GlobalPoint, float > > &) const
Definition: CrossingPtBasedLinearizationPointFinder.cc:178
operator+
MatrixMeschach operator+(const MatrixMeschach &mat1, const MatrixMeschach &mat2)
Definition: MatrixMeschach.cc:154
CrossingPtBasedLinearizationPointFinder::useAllTracks
GlobalPoint useAllTracks(const std::vector< reco::TransientTrack > &) const
Definition: CrossingPtBasedLinearizationPointFinder.cc:131
HsmModeFinder3d.h
DeadROC_duringRun.dir
dir
Definition: DeadROC_duringRun.py:23