LCFIPlus  0.6.5
VertexFinderTearDown.h
Go to the documentation of this file.
1 // VertexFinderTearDown.h
2 
3 #ifndef VertexFinderTearDown_h
4 #define VertexFinderTearDown_h 1
5 
6 #include "lcfiplus.h"
7 #include "VertexFitterLCFI.h"
8 #include "VertexFitterSimple.h"
9 #include "algoEtc.h"
10 
11 #include <list>
12 #include <vector>
13 
14 using namespace std;
15 
16 namespace lcfiplus {
17 
18 class SortTracksByChi2 { // decending order
19  public:
20  bool operator() (const pair<const Track*, double>& p1, const pair<const Track*, double>& p2) {
21  return p1.second > p2.second;
22  }
23 };
24 
25 // Function for recursive search of vertices using TearDown method
26 vector<lcfiplus::Vertex*>* findTearDownVertices(const Event& evt, const Jet& jet);
27 
28 // Primary Vertex finder with TearDown method
29 lcfiplus::Vertex* findPrimaryVertex(TrackVec& tracks, double chi2 = 9.0, bool beamspotConstraint=true, bool smearBeamspot=true);
30 // lcfiplus::Vertex * findPrimaryVertex(const vector<Track *> &tracks, const vector<Track *> &beamTracks, double chi2 = 9.0);
31 
32 // implementation of TearDown method
33 template<template<class T, class Allocator=allocator<T> > class Container = std::vector, template<class Iterator> class VertexFitter = VertexFitterLCFI >
35  public:
36  Vertex* operator () (const Container<const Track*>& tracks, const Container<const Track*>* fixedTracks = 0,
37  double chiSquareThreshold = 9.0, Container<const Track*>* residual = 0, Vertex* pointConstraint = 0) {
38  // copy tracks into a list
39  list<const Track*>trackList;
40  trackList.resize(tracks.size() + (fixedTracks ? fixedTracks->size() : 0));
41  list<const Track*>::iterator listIt = copy(tracks.begin(), tracks.end(), trackList.begin());
42  if (fixedTracks) {
43  copy(fixedTracks->begin(), fixedTracks->end(), listIt);
44  }
45 
46  Vertex* resultVertex = 0;
47  double worstChi2;
48  while (trackList.size() >= 2) {
49  resultVertex = VertexFitter<list<const Track*>::iterator>() (trackList.begin(), trackList.end(), pointConstraint);
50  const Track* worstTrack = resultVertex->getWorstTrack();
51  if (fixedTracks && find(fixedTracks->begin(), fixedTracks->end(), worstTrack) != fixedTracks->end()) {
52  // sort Chi2Tracks
53  vector<pair<const Track*, double> > vpair;
54  const map<const Track*, double>& mpair = resultVertex->getTracksChi2Map();
55  vpair.resize(mpair.size());
56  partial_sort_copy(mpair.begin(), mpair.end(), vpair.begin(), vpair.end(), SortTracksByChi2());
57 
58  unsigned int nworst = 1;
59  do {
60  worstTrack = vpair[nworst++].first;
61  } while (nworst < vpair.size() && find(fixedTracks->begin(), fixedTracks->end(), worstTrack) != fixedTracks->end());
62 
63  cout << "The worst track is fixed, " << nworst << "th track will be removed." << endl;
64  }
65 
66  worstChi2 = resultVertex->getChi2Track(worstTrack);
67  if (worstChi2 > chiSquareThreshold) {
68  trackList.remove(worstTrack);
69  if (residual)
70  residual->push_back(worstTrack);
71  /*
72  cout << "Track removed: chi2 = " << worstChi2 << ", vpos = ("
73  << resultVertex->getX() << ", " << resultVertex->getY() << ", " << resultVertex->getZ() << ")" << endl;
74  //*/
75  delete resultVertex;
76  resultVertex = 0;
77  } else
78  break; // all tracks below chi2 threshold
79  }
80 
81  return resultVertex;
82  }
83 };
84 }
85 
86 #endif
Definition: lcfiplus.h:771
Definition: lcfiplus.h:384
Definition: VertexFinderTearDown.h:34
const map< const lcfiplus::Track *, double > & getTracksChi2Map() const
Definition: lcfiplus.h:826
double getChi2Track(const Track *tr) const
Definition: lcfiplus.h:829
vector< lcfiplus::Vertex * > * findTearDownVertices(const Event &evt, const Jet &jet)
Definition: VertexFinderTearDown.cc:11
lcfiplus::Vertex * findPrimaryVertex(TrackVec &tracks, double chi2=9.0, bool beamspotConstraint=true, bool smearBeamspot=true)
Definition: VertexFinderTearDown.cc:48
Definition: VertexFitterLCFI.h:19
Definition: VertexFinderTearDown.h:18
Definition: lcfiplus.h:980
const Track * getWorstTrack() const
Definition: lcfiplus.cc:835
const vector< const Track * > TrackVec
Definition: lcfiplus.h:72
Definition: lcfiplus.h:291