1 #include "ERmuSiVertexFinder.h" 12 #include "Fit/BinData.h" 13 #include "Fit/Fitter.h" 14 #include "Math/WrappedMultiTF1.h" 16 #include "FairRootManager.h" 17 #include "FairRunAna.h" 18 #include "FairRuntimeDb.h" 21 #include "ERDetectorList.h" 22 #include "ERmuSiTrack.h" 23 #include "ERmuSiPoint.h" 27 : FairTask(
"ER muSi vertex finding scheme")
34 : FairTask(
"ER muSi vertex finding scheme ", verbose)
46 void ERmuSiVertexFinder::SetParContainers()
49 FairRunAna* run = FairRunAna::Instance();
50 if ( ! run ) Fatal(
"SetParContainers",
"No analysis run");
52 FairRuntimeDb* rtdb = run->GetRuntimeDb();
53 if ( ! rtdb ) Fatal(
"SetParContainers",
"No runtime database");
61 FairRootManager* ioman = FairRootManager::Instance();
62 if ( ! ioman ) Fatal(
"Init",
"No FairRootManager");
64 fmuSiTracks = (TClonesArray*) ioman->GetObject(
"muSiTrack");
68 fmuSiVertices =
new TClonesArray(
"ERmuSiVertex",1000);
70 ioman->Register(
"muSiVertex",
"muSi", fmuSiVertices, kTRUE);
80 std::cout << std::endl;
81 std::cout <<
"ERmuSiVertexFinder started:" << std::endl;
83 for(Int_t iTrack = 0; iTrack <
fmuSiTracks->GetEntriesFast(); iTrack++){
87 ROOT::Fit::BinData data(3,2);
89 xx[0] = track1->Hit(0)->GetX();
90 xx[1] = track1->Hit(0)->GetY();
91 data.Add(xx,track1->Hit(0)->GetZ(), 0.001);
92 xx[0] = track1->Hit(1)->GetX();
93 xx[1] = track1->Hit(1)->GetY();
94 data.Add(xx,track1->Hit(1)->GetZ(), 0.001);
95 xx[0] = track1->Hit(2)->GetX();
96 xx[1] = track1->Hit(2)->GetY();
97 data.Add(xx,track1->Hit(2)->GetZ(), 0.001);
99 TF2 * f =
new TF2(
"f2",
"[0]*x + [1]*y + [2]*1");
100 f->SetParameters(2,2,2);
101 ROOT::Fit::Fitter fitter;
102 ROOT::Math::WrappedMultiTF1 wf(*f,2);
103 fitter.SetFunction(wf);
104 bool ret = fitter.Fit(data);
105 const ROOT::Fit::FitResult & res = fitter.Result();
107 f->SetFitResult(res);
109 TVector3 directTrack1(track1->Hit(0)->GetX()-track1->Hit(1)->GetX(),
110 track1->Hit(0)->GetY()-track1->Hit(1)->GetY(),
111 f->Eval(track1->Hit(0)->GetX(),track1->Hit(0)->GetY())
112 - f->Eval(track1->Hit(1)->GetX(),track1->Hit(1)->GetY()));
113 for(Int_t jTrack = iTrack+1; jTrack <
fmuSiTracks->GetEntriesFast(); jTrack++){
114 if (iTrack == jTrack)
118 ROOT::Fit::BinData data2(3,2);
119 xx[0] = track2->Hit(0)->GetX();
120 xx[1] = track2->Hit(0)->GetY();
121 data2.Add(xx,track2->Hit(0)->GetZ(), 0.001);
122 xx[0] = track2->Hit(1)->GetX();
123 xx[1] = track2->Hit(1)->GetY();
124 data2.Add(xx,track2->Hit(1)->GetZ(), 0.001);
125 xx[0] = track2->Hit(2)->GetX();
126 xx[1] = track2->Hit(2)->GetY();
127 data2.Add(xx,track2->Hit(2)->GetZ(), 0.001);
129 ROOT::Fit::Fitter fitter2;
130 ROOT::Math::WrappedMultiTF1 wf2(*f,3);
131 fitter2.SetFunction(wf2);
132 bool ret2 = fitter2.Fit(data2);
133 const ROOT::Fit::FitResult & res2 = fitter2.Result();
135 f->SetFitResult(res2);
137 TVector3 directTrack2(track2->Hit(0)->GetX()-track2->Hit(1)->GetX(),
138 track2->Hit(0)->GetY()-track2->Hit(1)->GetY(),
139 f->Eval(track2->Hit(0)->GetX(),track2->Hit(0)->GetY())
140 - f->Eval(track2->Hit(1)->GetX(),track2->Hit(1)->GetY()));
143 TVector3 p = directTrack1.Cross(directTrack2);
147 TMatrixT<double> mat(3,3);
148 mat(0,0) = directTrack1.X();
149 mat(0,1) = -directTrack2.X();
151 mat(1,0) = directTrack1.Y();
152 mat(1,1) = -directTrack2.Y();
154 mat(2,0) = directTrack1.Z();
155 mat(2,1) = -directTrack2.Z();
158 TMatrixT<double> right(3,1);
160 right(0,0) = track2->Hit(0)->GetX()-track1->Hit(0)->GetX();
161 right(1,0) = track2->Hit(0)->GetY()-track1->Hit(0)->GetY();
162 right(2,0) = track2->Hit(0)->GetZ()-track1->Hit(0)->GetZ();
164 TMatrixT<double> matInv(3,3);
165 matInv = mat.Invert();
166 TMatrixT<double> lamda(3,1);
167 lamda = matInv*right;
168 TVector3 orig(track1->Hit(0)->GetX(), track1->Hit(0)->GetY(), track1->Hit(0)->GetZ());
169 TVector3 orig2(track2->Hit(0)->GetX(), track2->Hit(0)->GetY(), track2->Hit(0)->GetZ());
170 TVector3 vertex = orig + lamda(0,0)*directTrack1;
171 TVector3 vertex2 = orig2 + lamda(1,0)*directTrack2;
172 if (lamda(2,0) < fDistanceCut){
173 ERmuSiVertex* vert = AddVertex((vertex.X() + vertex2.X())/2., (vertex.Y() + vertex2.Y())/2.,(vertex.Z() + vertex2.Z())/2.);
174 vert->AddTrack(iTrack);
175 vert->AddTrack(jTrack);
181 for (Int_t iVert = 0; iVert < fmuSiVertices->GetEntriesFast(); iVert++){
183 for (Int_t jVert = iVert+1; jVert < fmuSiVertices->GetEntriesFast(); jVert++){
185 Float_t dist = TMath::Sqrt((vert2->X()-vert1->X())*(vert2->X()-vert1->X()) +
186 (vert2->Y()-vert1->Y())*(vert2->Y()-vert1->Y()) +
187 (vert2->Z()-vert1->Z())*(vert2->Z()-vert1->Z()));
189 std::cout <<
"Vertecies merging!" << std::endl;
190 vert1->SetX((vert1->X()+vert2->X())/2.);
191 vert1->SetY((vert1->Y()+vert2->Y())/2.);
192 vert1->SetZ((vert1->Z()+vert2->Z())/2.);
193 for (Int_t iTrack = 0; iTrack < vert2->TrackNb(); iTrack++){
194 vert1->AddTrack(vert2->Track(iTrack));
197 fmuSiVertices->RemoveAt(jVert);
199 fmuSiVertices->Compress();
202 std::cout <<
"Vertecies count: " << fmuSiVertices->GetEntriesFast() << std::endl;
203 for(Int_t iVert=0; iVert < fmuSiVertices->GetEntriesFast(); iVert++){
205 std::cout <<
"Vertex "<< iVert <<
": (" << vert->X() <<
"," << vert->Y() <<
"," << vert->Z() <<
")" << std::endl;
214 fmuSiVertices->Delete();
227 ERmuSiVertex* ERmuSiVertexFinder::AddVertex(Float_t x, Float_t y, Float_t z){
228 ERmuSiVertex *vertex =
new((*fmuSiVertices)[fmuSiVertices->GetEntriesFast()])
virtual void Exec(Option_t *opt)
virtual InitStatus Init()
TClonesArray * fmuSiTracks