LCFIVertex  0.7.2
trackattach.cpp
1 #include <inc/vertex.h>
2 #include <inc/decaychain.h>
3 #include <inc/jet.h>
4 #include <util/inc/matrix.h>
5 #include <util/inc/helixrep.h>
6 #include <util/inc/string.h>
7 #include <algo/inc/trackattach.h>
8 #include <vector>
9 #include <string>
10 #include <math.h>
11 #include <inc/trackstate.h>
12 #include <inc/track.h>
13 #include <util/inc/memorymanager.h>
14 
15 
16 // author Erik Devetak
17 
18 using std::string;
19 
20 
21 namespace vertex_lcfi
22 {
23 
24  TrackAttach::TrackAttach()
25  {
26  //default values
27  _LoDCutmin = 0.18;
28  _LoDCutmax = 2.5 ;
29  _CloseapproachCut = 1.0;
30  _AddAllTracksFromSecondary = false;
31  _ParameterNames.push_back("LoDCutmin");
32  _ParameterNames.push_back("LoDCutmax");
33  _ParameterNames.push_back("CloseapproachCut");
34  _ParameterNames.push_back("AddAllTracksFromSecondary");
35  }
36 
37  string TrackAttach::name() const
38  {
39  return _Name;
40  }
41 
42  std::vector<string> TrackAttach::parameterNames() const
43  {
44  return _ParameterNames;
45  }
46 
47  std::vector<string> TrackAttach::parameterValues() const
48  {
49  _ParameterValues.clear();
50  _ParameterValues.push_back(makeString(_LoDCutmin));
51  _ParameterValues.push_back(makeString(_LoDCutmax));
52  _ParameterValues.push_back(makeString(_CloseapproachCut));
53  _ParameterValues.push_back(makeString(_AddAllTracksFromSecondary));
54  return _ParameterValues;
55  }
56 
57  void TrackAttach::setStringParameter(const string & Parameter, const string & Value)
58  {
59  this->badParameter(Parameter);
60  }
61 
62  void TrackAttach::setDoubleParameter(const string & Parameter, const double Value)
63  {
64  if (Parameter == "LoDCutmin")
65  {
66  _LoDCutmin = Value;
67  return;
68  }
69  if (Parameter == "LoDCutmax")
70  {
71  _LoDCutmax = Value;
72  return;
73  }
74  if (Parameter == "CloseapproachCut")
75  {
76  _CloseapproachCut = Value;
77  return;
78  }
79  if (Parameter == "AddAllTracksFromSecondary")
80  {
81  _AddAllTracksFromSecondary = Value;
82  return;
83  }
84  this->badParameter(Parameter);
85  }
86 
87  void TrackAttach::setPointerParameter(const string & Parameter, void * Value)
88  {
89  this->badParameter(Parameter);
90  }
91 
92 
94  {
95  double distance = 0;
96  double Theta = 0;
97  double Phi = 0;
98  Vector3 VertexPos;
99  SymMatrix5x5 dummy;
100  dummy.clear();
101  double closeapproach;
102  double LoD;
103  int numberoftracks = 0;
104  int vertexcounter = 0;
105  int tempvertex =0;
106  DecayChain* DecaywithAtTracks = new DecayChain(*MyDecayChain);
107  MemoryManager<DecayChain> ::Event()->registerObject(DecaywithAtTracks);
108  std::vector<vertex_lcfi::Track > AttachedTracks;
109  std::vector<Track*> Innertracks;
110 
111  for (std::vector<Vertex*>::const_iterator iVertex = (MyDecayChain->vertices().begin()); iVertex != MyDecayChain->vertices().end() ;++iVertex)
112  {
113 
114  numberoftracks = (*iVertex)->tracks( ).size();
115 
116  if ( numberoftracks > 1 || vertexcounter > 0 )
117  {
118  tempvertex = vertexcounter;
119  }
120  vertexcounter++;
121  }
122 
123  tempvertex = (MyDecayChain->vertices().size()-1);
124 
125  if (MyDecayChain->vertices().empty())
126  std::cerr << "Empty Decay Chain - trackattach.cpp:119" << std::endl;
127 
128 
129  VertexPos = (MyDecayChain->vertices()[tempvertex]->position()).subtract( (MyDecayChain->vertices()[0])->position() );
130 
131  distance = VertexPos.mag();
132 
133  //effectively if distance bigger than 0 within rounding errors hence not a parameter
134  if (distance > 0.00001)
135  {
136 
137  //Make a straight track from IP to vertex so then we can use swimmer
138 
139 
140  Theta = acos( VertexPos.unit().z() );
141  Phi = acos( VertexPos.unit().x()/sin(Theta));
142  if (VertexPos.unit().y()<0.0) Phi = (2*3.141592654) - Phi;
143 
144  HelixRep LinearHelix;
145 
146  LinearHelix.d0() = 0;
147 
148  LinearHelix.z0() = 0.0;
149  LinearHelix.invR() = 0.0;
150  LinearHelix.phi() = Phi;
151  LinearHelix.tanLambda() = tan((3.141592654/2.0)-Theta);
152 
153  Vector3 mom(cos(Phi)*sin(Theta),sin(Phi)*sin(Theta),cos(Theta));
154 
155  Track LinearTrack(0,LinearHelix,mom,0.0,dummy,std::vector<int>());
156 
157  TrackState* TSLin = LinearTrack.makeState();
158  TrackState* TSHel;
159 
160 
161  for (std::vector<Track*>::const_iterator iTrack = (MyDecayChain->jet()->tracks().begin()); iTrack != MyDecayChain->jet()->tracks().end() ;++iTrack)
162  {
163 
164 
165  //new addition to find tracks not from primary but associated with a vertex
166 
167  if (_AddAllTracksFromSecondary == true )
168  {
169  for (std::vector<Vertex*>::const_iterator iVertex = (++MyDecayChain->vertices().begin()); iVertex != MyDecayChain->vertices().end() ;++iVertex)
170  {
171 
172  if((*iVertex)->hasTrack(*iTrack))
173  {
174 
175  Innertracks.push_back(*iTrack);
176  }
177  }
178  }
179 
180  TSHel = (**iTrack).makeState();
181 
182  //this is a smart way of solving many problems
183  // we swim near to the vertex since the cut is then perfomed at the vertex.
184  //so if we have too many iterations we can cut the track
185 
186  TSLin->swimToStateNearest( MyDecayChain->vertices()[tempvertex]->position() );
187 
188  TSLin->swimToStateNearest( TSHel );
189  TSHel->swimToStateNearest( TSLin );
190 
191  closeapproach = ((*TSHel).position().subtract((*TSLin).position())).mag();
192 
193  LoD = (TSLin->position().subtract((MyDecayChain->vertices()[0])->position())).mag();
194 
195  if( 0 > TSLin->position().subtract(MyDecayChain->vertices()[0]->position()).dot( VertexPos ) )
196  {
197  LoD = LoD * (-1);
198  }
199 
200  if ( (LoD/distance)> _LoDCutmin && (LoD/distance)< _LoDCutmax && (closeapproach < _CloseapproachCut) )
201  {
202 
203  if( DecaywithAtTracks->hasTrack(*iTrack) == 0 )
204  {
205 
206  DecaywithAtTracks->addTrack(*iTrack);
207  }
208  }
209  else
210  {
211  if (_AddAllTracksFromSecondary == true )
212  {
213  std::vector<Track*>::const_iterator Inner = find(Innertracks.begin(),Innertracks.end(),*iTrack );
214  if(Inner == Innertracks.end())
215  {
216  if(DecaywithAtTracks->hasTrack(*iTrack) == 1)
217  {
218  DecaywithAtTracks->removeTrack(*iTrack);
219  }
220  }
221  }
222  else
223  {
224  if(DecaywithAtTracks->hasTrack(*iTrack) == 1)
225  {
226  DecaywithAtTracks->removeTrack(*iTrack);
227  }
228  }
229  }
230 
231  }
232  }
233  else
234  {
235  for (std::vector<Track*>::const_iterator iTrack = (MyDecayChain->jet()->tracks().begin()); iTrack != MyDecayChain->jet()->tracks().end() ;++iTrack)
236  {
237  if(DecaywithAtTracks->hasTrack(*iTrack) == 1)
238  {
239  DecaywithAtTracks->removeTrack(*iTrack);
240  }
241  }
242  }
243 
244  // std::cout<<"I AM FINISHED"<<std::endl;
245  return DecaywithAtTracks;
246 
247  }
248 
249 
250 
251 }
DecayChain * calculateFor(DecayChain *MyDecayChain) const
Run the algorithm on a jet.
Definition: trackattach.cpp:93
bool removeTrack(Track *Track)
Remove Track.
Definition: decaychain.cpp:140
std::vector< string > parameterValues() const
Parameter Values.
Definition: trackattach.cpp:47
const std::vector< Track * > & tracks() const
Tracks.
Definition: jet.cpp:23
TrackState * makeState() const
Create a TrackState of this track.
Definition: track.cpp:27
void addTrack(Track *Track)
Add Track.
Definition: decaychain.cpp:133
bool hasTrack(Track *Track) const
Does the DecayChain have this Track?
Definition: decaychain.cpp:164
const std::vector< Vertex * > & vertices() const
Vertices contained in DecayChain.
Definition: decaychain.cpp:80
static MemoryManager< T > * Event()
Returns the Event duration singleton instance of the MemoryManager for type T.
void setPointerParameter(const string &Parameter, void *Value)
Set Pointer Parameter.
Definition: trackattach.cpp:87
void setDoubleParameter(const string &Parameter, const double Value)
Set Double Parameter.
Definition: trackattach.cpp:62
Unique Track representation.
std::vector< string > parameterNames() const
Parameter Names.
Definition: trackattach.cpp:42
string name() const
Name.
Definition: trackattach.cpp:37
const Vector3 & position() const
Current position of the trackstate.
Definition: trackstate.cpp:440
void setStringParameter(const string &Parameter, const string &Value)
Set String Parameter.
Definition: trackattach.cpp:57
void swimToStateNearest(const Vector3 &Point)
Swim to the point of closest approach to Point.
Definition: trackstate.cpp:46