CbmRoot
Loading...
Searching...
No Matches
CbmTofTrackFinderNN.cxx
Go to the documentation of this file.
1/* Copyright (C) 2015-2021 PI-UHd, GSI
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Norbert Herrmann [committer], Pierre-Alain Loizeau */
4
5// ROOT Classes and includes
6#include "TClonesArray.h"
7#include "TDirectory.h"
8#include "TGeoManager.h"
9#include "TROOT.h"
10
11#include <TCanvas.h>
12#include <TF2.h>
13#include <TGraph2D.h>
14#include <TGraph2DErrors.h>
15#include <TH1.h>
16#include <TMath.h>
17#include <TRandom2.h>
18#include <TStyle.h>
19
20// FAIR classes and includes
21#include "FairEventManager.h" // for FairEventManager
22#include "FairRootManager.h"
23#include "FairRunAna.h"
24#include "FairRuntimeDb.h"
25#include "TEveManager.h" // for TEveManager, gEve
26
27#include <Logger.h>
28
29// CBMroot classes and includes
30#include "CbmMatch.h"
31#include "CbmTofAddress.h" // in cbmdata/tof
32#include "CbmTofCell.h" // in tof/TofData
34#include "CbmTofDetectorId_v12b.h" // in cbmdata/tof
35#include "CbmTofDetectorId_v14a.h" // in cbmdata/tof
36#include "CbmTofDigiBdfPar.h" // in tof/TofParam
37#include "CbmTofDigiPar.h" // in tof/TofParam
38#include "CbmTofFindTracks.h"
39#include "CbmTofGeoHandler.h" // in tof/TofTools
40#include "CbmTofHit.h" // in cbmdata/tof
41#include "CbmTofTrackFinderNN.h"
42#include "CbmTofTracklet.h"
43#include "CbmTofTrackletParam.h"
44#include "LKFMinuit.h"
45#include <CbmEvDisTracks.h> // in eventdisplay/tof
46
47// C++ includes
48#include <map>
49#include <vector>
50using std::cout;
51using std::endl;
52using std::map;
53
54//const Int_t DetMask = 0x3FFFFF; // check for consistency with v14a geometry
55//const Int_t DetMask = 0x1FFFFF; // check for consistency with v21a geometry
57
59 : fHits(NULL)
60 , fOutTracks(NULL)
61 , fiNtrks(0)
62 , fFindTracks(NULL)
63 , fDigiPar(NULL)
64 , fMaxTofTimeDifference(0.)
65 , fTxLIM(0.)
66 , fTyLIM(0.)
67 , fTxMean(0.)
68 , fTyMean(0.)
69 , fSIGLIM(4.)
70 , fSIGLIMMOD(1.)
71 , fChiMaxAccept(3.)
72 , fPosYMaxScal(0.55)
73 , fTracks()
74 , fvTrkVec()
75{
76}
77
79
80//Copy constructor
82 : fHits(NULL)
83 , fOutTracks(NULL)
84 , fiNtrks(0)
85 , fFindTracks(NULL)
86 , fDigiPar(NULL)
87 , fMaxTofTimeDifference(0.)
88 , fTxLIM(0.)
89 , fTyLIM(0.)
90 , fTxMean(0.)
91 , fTyMean(0.)
92 , fSIGLIM(4.)
93 , fSIGLIMMOD(1.)
94 , fChiMaxAccept(3.)
95 , fPosYMaxScal(0.55)
96 , fTracks()
97 , fvTrkVec()
98 , fiAddVertex(0)
99 , fiVtxNbTrksMin(0)
100{
101 // action
102 fHits = finder.fHits;
103 fTracks = finder.fTracks;
104 fiNtrks = finder.fiNtrks;
105}
106
107// assignment operator
109{
110 // do copy
111 // ... (too lazy) ...
112 // return the existing object
113 return *this;
114}
115
117{
118 FairRunAna* ana = FairRunAna::Instance();
119 FairRuntimeDb* rtdb = ana->GetRuntimeDb();
120 fDigiPar = (CbmTofDigiPar*) (rtdb->getContainer("CbmTofDigiPar"));
121 if (NULL == fDigiPar) {
122 LOG(error) << "CbmTofTrackFinderNN::Init => Could not obtain the CbmTofDigiPar ";
123 }
124
126 if (NULL == fFindTracks) LOG(fatal) << Form(" CbmTofTrackFinderNN::Init : no FindTracks instance found");
127
129
130 LOG(info) << "MaxTofTimeDifference = " << fMaxTofTimeDifference;
131 if (fiAddVertex > 0)
132 LOG(info) << "AddVertex() will be used with option " << fiAddVertex;
133 else
134 LOG(info) << "AddVertex() will not be used";
135}
136
137Int_t CbmTofTrackFinderNN::DoFind(TClonesArray* fTofHits, TClonesArray* fTofTracks)
138{
139 fiNtrks = 0; // initialize
140 fHits = fTofHits;
141 fOutTracks = fTofTracks; //new TClonesArray("CbmTofTracklet");
142 //fTracks = new TClonesArray("CbmTofTracklet");
143 //if (0 == fFindTracks->GetStationType(0)){ // Generate Pseudo TofHit at origin
144 // fvTrkMap.resize(fHits->GetEntriesFast());
145 fvTrkVec.resize(fHits->GetEntriesFast());
146 LOG(debug2) << "<I> TrkMap/Vec resized for " << fHits->GetEntriesFast() << " entries ";
147 // for (Int_t iHit=0; iHit<fHits->GetEntriesFast(); iHit++) { fvTrkMap[iHit].clear();}
148 for (Int_t iHit = 0; iHit < fHits->GetEntriesFast(); iHit++) {
149 fvTrkVec[iHit].clear();
150 }
151
152 LOG(debug1) << "MaxTofTimeDifference = " << fMaxTofTimeDifference;
153 Int_t iNTrks = 0;
154 Int_t iSt0 = -1;
155 Int_t iSt1 = 0;
156 while (iSt0 < fFindTracks->GetNofStations() - fFindTracks->GetMinNofHits()) { // seed loop, all combinations as seeds
157 iSt0++;
158 iSt1 = iSt0;
159 while (iSt1 < fFindTracks->GetNofStations() - fFindTracks->GetMinNofHits() + 1) {
160 iSt1++;
161 for (Int_t iHit = 0; iHit < fHits->GetEntriesFast(); iHit++) { // loop over Hits
162 CbmTofHit* pHit = (CbmTofHit*) fHits->At(iHit);
163 Int_t iAddr = (pHit->GetAddress() & DetMask);
164 // Int_t iSmType = CbmTofAddress::GetSmType( iAddr ); (VF) not used
165 if (HitUsed(iHit) == 1 && iAddr != fFindTracks->GetBeamCounter())
166 continue; // skip used Hits except for BeamCounter
167 LOG(debug2) << Form("<I> TofTracklet Chkseed St0 %2d, St1 %2d, Mul %2d, Hit %2d, addr = "
168 "0x%08x - X %6.2f, Y %6.2f Z %6.2f R %6.2f T %6.2f TM %lu",
169 iSt0, iSt1, fiNtrks, iHit, pHit->GetAddress(), pHit->GetX(), pHit->GetY(), pHit->GetZ(),
170 pHit->GetR(), pHit->GetTime(), fvTrkVec[iHit].size());
171 if (iAddr == fFindTracks->GetAddrOfStation(iSt0)) { // generate new track seed
172 LOG(debug1) << Form("<I> TofTracklet seed St0 %2d, St1 %2d, Mul %2d, Hit %2d, addr = "
173 "0x%08x - X %6.2f, Y %6.2f Z %6.2f T %6.2f TM %lu",
174 iSt0, iSt1, fiNtrks, iHit, pHit->GetAddress(), pHit->GetX(), pHit->GetY(), pHit->GetZ(),
175 pHit->GetTime(), fvTrkVec[iHit].size());
176
177 Int_t iChId = pHit->GetAddress();
178 CbmTofCell* fChannelInfo = fDigiPar->GetCell(iChId);
179 Int_t iCh = CbmTofAddress::GetChannelId(iChId);
180 Double_t hitpos[3] = {3 * 0.};
181 Double_t hitpos_local[3] = {3 * 0.};
182 Double_t dSizey = 1.;
183
184 if (1) { // iSmType>0) { // prevent geometry inspection for FAKE hits
185 if (NULL == fChannelInfo) {
186 LOG(fatal) << "<D> CbmTofTrackFinderNN::DoFind0: Invalid Channel Pointer for ChId "
187 << Form(" 0x%08x ", iChId) << ", Ch " << iCh;
188 // continue;
189 }
190 else {
191 /*TGeoNode *fNode= */ // prepare global->local trafo
192 gGeoManager->FindNode(fChannelInfo->GetX(), fChannelInfo->GetY(), fChannelInfo->GetZ());
194 hitpos[0] = pHit->GetX();
195 hitpos[1] = pHit->GetY();
196 hitpos[2] = pHit->GetZ();
197 /*TGeoNode* cNode=*/gGeoManager->GetCurrentNode();
198 gGeoManager->MasterToLocal(hitpos, hitpos_local);
199 }
200 dSizey = fChannelInfo->GetSizey();
201 }
202 }
203 LOG(debug1) << Form(
204 "<D> Tracklet start %d, Hit %d - yloc %6.2f, dy %6.2f, scal %6.2f -> addrs 0x%08x, 0x%08x", fiNtrks, iHit,
205 hitpos_local[1], dSizey, fPosYMaxScal, fFindTracks->GetAddrOfStation(iSt0),
207
208 if (TMath::Abs(hitpos_local[1]) < dSizey * fPosYMaxScal)
209 for (Int_t iHit1 = 0; iHit1 < fHits->GetEntriesFast(); iHit1++) // loop over all Hits (order unknown)
210 {
211 if (HitUsed(iHit1) == 1) continue; // skip used Hits
212 CbmTofHit* pHit1 = (CbmTofHit*) fHits->At(iHit1);
213 // Int_t iSmType1 = CbmTofAddress::GetSmType( pHit1->GetAddress() & DetMask ); (VF) not used
214 Int_t iAddr1 = (pHit1->GetAddress() & DetMask);
215 //if (iSmType1 == fFindTracks->GetStationType(1)) { // generate new track seed
216 if (iAddr1 == fFindTracks->GetAddrOfStation(iSt1)) { // generate new track seed
217 Int_t iChId1 = pHit1->GetAddress();
218 CbmTofCell* fChannelInfo1 = fDigiPar->GetCell(iChId1);
219 Int_t iCh1 = CbmTofAddress::GetChannelId(iChId1);
220 Double_t hitpos1[3] = {3 * 0.};
221 Double_t hitpos1_local[3] = {3 * 0.};
222 Double_t dSizey1 = 1.;
223 if (NULL == fChannelInfo1) {
224 LOG(debug1) << "CbmTofTrackFinderNN::DoFindi: Invalid Channel "
225 "Pointer for ChId "
226 << Form(" 0x%08x ", iChId1) << ", Ch " << iCh1;
227 // continue;
228 }
229 else {
230 /*TGeoNode *fNode1=*/ // prepare global->local trafo
231 gGeoManager->FindNode(fChannelInfo1->GetX(), fChannelInfo1->GetY(), fChannelInfo1->GetZ());
232 hitpos1[0] = pHit1->GetX();
233 hitpos1[1] = pHit1->GetY();
234 hitpos1[2] = pHit1->GetZ();
235 /*TGeoNode* cNode1=*/gGeoManager->GetCurrentNode();
236 gGeoManager->MasterToLocal(hitpos1, hitpos1_local);
237 dSizey1 = fChannelInfo1->GetSizey();
238 }
239 Double_t dDT = pHit1->GetTime() - pHit->GetTime();
240 //if(dDT<0.) continue; // request forward propagation in time
241
242 Double_t dLz = pHit1->GetZ() - pHit->GetZ();
243 Double_t dTx = (pHit1->GetX() - pHit->GetX()) / dLz;
244 Double_t dTy = (pHit1->GetY() - pHit->GetY()) / dLz;
245 Double_t dDist = TMath::Sqrt(TMath::Power((pHit->GetX() - pHit1->GetX()), 2)
246 + TMath::Power((pHit->GetY() - pHit1->GetY()), 2)
247 + TMath::Power((pHit->GetZ() - pHit1->GetZ()), 2));
248 LOG(debug2) << Form("<I> TofTracklet %d, Hits %d, %d, add = 0x%08x,0x%08x - DT "
249 "%6.2f, DD %6.2f, Tx %6.2f Ty %6.2f Tt %6.2f pos %6.2f %6.2f %6.2f ",
250 fiNtrks, iHit, iHit1, pHit->GetAddress(), pHit1->GetAddress(), dDT, dDist, dTx, dTy,
251 dDT / dLz, hitpos1_local[0], hitpos1_local[1], hitpos1_local[2]);
252 LOG(debug3) << Form(" DT %f from %f - %f ", dDT, pHit1->GetTime(), pHit->GetTime());
253 LOG(debug3) << Form(" selection: y %6.2f < %6.2f, T %f < %6.5f, "
254 "Tx Abs(%6.2f - %6.2f) < %6.2f, Ty Abs(%6.2f - %6.2f) < %6.2f",
255 hitpos1_local[1], dSizey1 * fPosYMaxScal, dDT / dLz, fMaxTofTimeDifference, dTx,
256 fTxMean, fTxLIM, dTy, fTyMean, fTyLIM);
257
258 if (TMath::Abs(hitpos1_local[1]) < dSizey1 * fPosYMaxScal)
259 if (TMath::Abs(dDT / dLz) < fMaxTofTimeDifference
260 //&& TMath::Abs(dDT / dDist) > 0.0001 // FIXME: numeric constant in code
261 && TMath::Abs(dTx - fTxMean) < fTxLIM && TMath::Abs(dTy - fTyMean) < fTyLIM) {
262 LOG(debug3) << "Construct new tracklet";
263 CbmTofTracklet* pTrk = new CbmTofTracklet();
264 fTracks.push_back(pTrk);
265 pTrk->SetTofHitIndex(iHit, iAddr, pHit); // store 1. Hit index
266 pTrk->AddTofHitIndex(iHit1, iAddr1, pHit1); // store 2. Hit index
267 fiNtrks = fTracks.size();
268
269 fvTrkVec[iHit].push_back(pTrk);
270 fvTrkVec[iHit1].push_back(pTrk);
271
272 pTrk->SetTime(pHit->GetTime()); // define reference time from 1. plane
273 //Double_t dR = pHit1->GetR() - pHit->GetR();
274 Double_t dR = pTrk->Dist3D(pHit1, pHit);
275 Double_t dTt = fFindTracks->GetTtTarg(); // assume calibration target value
276 if (0) { //== iSmType) { // disabled
277 Double_t T0Fake = pHit->GetTime();
278 Double_t w = fvTrkVec[iHit].size();
279 T0Fake = (T0Fake * (w - 1.) + (pHit1->GetTime() - dTt * dR)) / w;
280 LOG(debug1) << Form("<I> TofTracklet %d, Fake T0, old %8.0f -> new %8.0f", fiNtrks,
281 pHit->GetTime(), T0Fake);
282 pHit->SetTime(T0Fake);
283 }
284 Double_t dSign = 1.;
285 if (pHit1->GetZ() < pHit->GetZ()) dSign = -1.;
286 dTt = dSign * dDT / dR;
287 pTrk->SetTt(dTt); // store inverse velocity
288 pTrk->UpdateT0();
290 tPar->SetX(pHit->GetX()); // fill TrackParam
291 tPar->SetY(pHit->GetY()); // fill TrackParam
292 tPar->SetZ(pHit->GetZ()); // fill TrackParam
293 tPar->SetLz(dLz);
294 tPar->SetTx(dTx);
295 tPar->SetTy(dTy);
296
297 LOG(debug1) << Form("<I> TofTracklet %d, Hits %d, %d initialized, "
298 "add 0x%08x,0x%08x, DT %6.3f, Sgn %2.0f, DR "
299 "%6.3f, T0 %6.2f, Tt %6.4f ",
300 fiNtrks, iHit, iHit1, pHit->GetAddress(), pHit1->GetAddress(), dDT, dSign, dR,
301 pTrk->GetT0(), pTrk->GetTt())
302 // << tPar->ToString()
303 ;
304 }
305 }
306 }
307 } // iSt0 condition end
308 } // Loop on Hits end
309
310 if (iNTrks >= 0 && static_cast<size_t>(iNTrks) == fTracks.size()) continue; // nothing new
311 iNTrks = fTracks.size();
312 PrintStatus((char*) Form("after seeds of St0 %d, St1 %d, Mul %d", iSt0, iSt1, iNTrks));
313
314 const Int_t MAXNCAND = 1000; // Max number of hits matchable to current tracklets
315 // Propagate track seeds to remaining detectors
316 for (Int_t iDet = iSt1 + 1; iDet < fFindTracks->GetNStations(); iDet++) {
317 Int_t iNCand = 0;
318 Int_t iHitInd[MAXNCAND];
319 CbmTofTracklet* pTrkInd[MAXNCAND];
320 Double_t dChi2[MAXNCAND];
321 for (size_t iTrk = 0; iTrk < fTracks.size(); iTrk++) { // loop over Trackseeds
322 CbmTofTracklet* pTrk = (CbmTofTracklet*) fTracks[iTrk];
323 LOG(debug3) << " Propagate Loop " << iTrk << " pTrk " << pTrk
324 << Form(" to station %d, addr: 0x%08x ", iDet, fFindTracks->GetAddrOfStation(iDet));
325 if (NULL == pTrk) continue;
326
327 for (Int_t iHit = 0; iHit < fHits->GetEntriesFast(); iHit++) { // loop over Hits
328 if (HitUsed(iHit) == 1) continue; // skip used Hits
329 CbmTofHit* pHit = (CbmTofHit*) fHits->At(iHit);
330 Int_t iAddr = (pHit->GetAddress() & DetMask);
331 if (iAddr != fFindTracks->GetAddrOfStation(iDet)) continue;
332
333 // Int_t iSmType = CbmTofAddress::GetSmType( pHit->GetAddress() & DetMask ); (VF) not used
334 Int_t iChId = pHit->GetAddress();
335 CbmTofCell* fChannelInfo = fDigiPar->GetCell(iChId);
336 Int_t iCh = CbmTofAddress::GetChannelId(iChId);
337 Double_t hitpos[3] = {3 * 0.};
338 Double_t hitpos_local[3] = {3 * 0.};
339 Double_t dSizey = 1.;
340
341 if (NULL == fChannelInfo) {
342 LOG(debug1) << "CbmTofTrackFinderNN::DoFind: Invalid Channel "
343 "Pointer from Hit "
344 << iHit << " for ChId " << Form(" 0x%08x ", iChId) << ", Ch " << iCh;
345 // continue;
346 }
347 else {
348 /*TGeoNode *fNode=*/ // prepare global->local trafo
349 gGeoManager->FindNode(fChannelInfo->GetX(), fChannelInfo->GetY(), fChannelInfo->GetZ());
350 hitpos[0] = pHit->GetX();
351 hitpos[1] = pHit->GetY();
352 hitpos[2] = pHit->GetZ();
353 /*TGeoNode* cNode=*/gGeoManager->GetCurrentNode();
354 gGeoManager->MasterToLocal(hitpos, hitpos_local);
355 dSizey = fChannelInfo->GetSizey();
356 }
357 if (TMath::Abs(hitpos_local[1]) < dSizey * fPosYMaxScal) { // extrapolate Tracklet to this station
358 if (pTrk->GetStationHitIndex(iAddr) > -1) continue; // Station already part of this tracklet
360 Int_t iHit0 = pTrk->GetTofHitIndex(0);
361 Int_t iHit1 = pTrk->GetTofHitIndex(1);
362 // CbmTofHit* pHit0 = (CbmTofHit*) fHits->At( iHit0 ); (VF) not used
363 // CbmTofHit* pHit1 = (CbmTofHit*) fHits->At( iHit1 ); (VF) not used
364 if (iHit0 < 0 || iHit0 >= fHits->GetEntriesFast())
365 LOG(fatal) << "CbmTofTrackFinderNN::DoFind Invalid Hit Index " << iHit0 << " for Track " << iTrk << "("
366 << fTracks.size() << ")";
367 Double_t dDz = pHit->GetZ() - tPar->GetZ();
368 Double_t dXex = tPar->GetX() + tPar->GetTx() * dDz; // pTrk->GetFitX(pHit->GetZ());
369 Double_t dYex = tPar->GetY() + tPar->GetTy() * dDz; // pTrk->GetFitY(pHit->GetZ());
370 /*
371 Double_t dDr = pHit->GetR() - pHit0->GetR();
372 Double_t dTex = pHit0->GetTime() + (pHit1->GetTime()-pHit0->GetTime())/(pHit1->GetR()-pHit0->GetR())*dDr;
373 */
374 Double_t dTex = pTrk->GetTex(pHit);
375 // pTrk->GetFitT(pHit->GetR());
376
377 Double_t dChi =
378 TMath::Sqrt((TMath::Power(TMath::Abs(dTex - pHit->GetTime()) / fFindTracks->GetStationSigT(iDet), 2)
379 + TMath::Power(TMath::Abs(dXex - pHit->GetX()) / fFindTracks->GetStationSigX(iDet), 2)
380 + TMath::Power(TMath::Abs(dYex - pHit->GetY()) / fFindTracks->GetStationSigY(iDet), 2))
381 / 3);
382
383 LOG(debug2) << Form("<IP> TofTracklet %lu, HMul %d, Hits %d, %d check %d, Station "
384 "%d: DT %f, DX %f, DY %f, Chi %f",
385 iTrk, pTrk->GetNofHits(), iHit0, iHit1, iHit, iDet,
386 (dTex - pHit->GetTime()) / fFindTracks->GetStationSigT(iDet),
387 (dXex - pHit->GetX()) / fFindTracks->GetStationSigX(iDet),
388 (dYex - pHit->GetY()) / fFindTracks->GetStationSigY(iDet), dChi);
389
390 if (fFindTracks->GetStationSigT(iDet) == 0 || fFindTracks->GetStationSigX(iDet) == 0
391 || fFindTracks->GetStationSigY(iDet) == 0)
392 LOG(fatal) << Form("Missing resolution for station %d, addr 0x%08x", iDet, iAddr);
393
394 if (dChi < fSIGLIM // FIXME: should scale limit with material budget between hit and track reference
395 * (pTrk->GetNofHits() < fFindTracks->GetNReqStations() - 1
396 ? 1.
397 : fSIGLIMMOD)) { // extend and update tracklet
398 LOG(debug1) << Form("<IP> TofTracklet %lu, HMul %d, Hits %d, %d "
399 "mark for extension by %d, add = 0x%08x, DT "
400 "%6.2f, DX %6.2f, DY=%6.2f ",
401 iTrk, pTrk->GetNofHits(), iHit0, iHit1, iHit, pHit->GetAddress(),
402 dTex - pHit->GetTime(), dXex - pHit->GetX(), dYex - pHit->GetY())
403 << tPar->ToString();
404
405 if (iNCand > 0) {
406 LOG(debug1) << Form("CbmTofTrackFinderNN::DoFind new match %d "
407 "of Hit %d, Trk %lu, chi2 = %f",
408 iNCand, iHit, iTrk, dChi);
409 iNCand++;
410 if (iNCand == MAXNCAND) iNCand--; // Limit index to maximum
411
412 for (Int_t iCand = 0; iCand < iNCand; iCand++) {
413 if (dChi < dChi2[iCand]) {
414 for (Int_t iCC = iNCand; iCC > iCand; iCC--) {
415 pTrkInd[iCC] = pTrkInd[iCC - 1];
416 iHitInd[iCC] = iHitInd[iCC - 1];
417 dChi2[iCC] = dChi2[iCC - 1];
418 }
419 pTrkInd[iCand] = pTrk;
420 iHitInd[iCand] = iHit;
421 dChi2[iCand] = dChi;
422 dChi2[iNCand] = 1.E8;
423 LOG(debug2) << Form(" <D> candidate inserted at pos %d", iCand);
424 break;
425 }
426 }
427 }
428 else {
429 LOG(debug1) << Form("CbmTofTrackFinderNN::DoFind first match "
430 "%d of Hit %d, Trk %p, chi2 = %f",
431 iNCand, iHit, pTrk, dChi);
432 pTrkInd[iNCand] = pTrk;
433 iHitInd[iNCand] = iHit;
434 dChi2[iNCand] = dChi; // relative quality measure
435 iNCand++;
436 dChi2[iNCand] = 1.E8;
437 }
438 }
439
440 } // hit y position check end
441 } // hit loop end
442 } // loop over tracklets end
443
444 while (iNCand > 0) { // at least one matching hit - trk pair found
445 CbmTofTracklet* pTrk = pTrkInd[0];
446 if (NULL == pTrk) continue;
447 LOG(debug1) << Form("%d hit match candidates in station %d to %lu TofTracklets", iNCand, iDet,
448 fTracks.size());
449 for (Int_t iM = 0; iM < iNCand; iM++) {
450 pTrk = (CbmTofTracklet*) pTrkInd[iM];
451 if (NULL == pTrk) break;
452 std::vector<CbmTofTracklet*>::iterator it = std::find(fTracks.begin(), fTracks.end(), pTrk);
453 if (it == fTracks.end()) break; // track candidate not existing
454
455 LOG(debug2) << "\t"
456 << Form("Hit %d, Trk %p with chi2 %f (%f)", iHitInd[iM], pTrkInd[iM], dChi2[iM],
458 }
459 PrintStatus((char*) "starting NCand");
460
461 // check if best pTrk still active
462 pTrk = (CbmTofTracklet*) pTrkInd[0];
463 size_t iTr = 0;
464 for (; iTr < fTracks.size(); iTr++) {
465 if (fTracks[iTr] == pTrk) {
466 LOG(debug1) << "Track " << pTrk << " active at pos " << iTr;
467 break;
468 }
469 }
470 if (iTr == fTracks.size()) {
471 iNCand--;
472 for (Int_t iCand = 0; iCand < iNCand; iCand++) {
473 pTrkInd[iCand] = pTrkInd[iCand + 1];
474 iHitInd[iCand] = iHitInd[iCand + 1];
475 dChi2[iCand] = dChi2[iCand + 1];
476 }
477 continue;
478 }
479
480 // CbmTofTrackletParam *tPar = pTrk->GetTrackParameter(); (VF) not used
481 Int_t iHit0 = pTrk->GetTofHitIndex(0);
482 Int_t iHit1 = pTrk->GetTofHitIndex(1);
483 if (pTrk->GetNofHits() > fFindTracks->GetNStations() || pTrk->GetNofHits() <= 0)
484 LOG(fatal) << " No or more Tracklet hits than stations ! Stop ";
485 // check if tracklet already contains a hit of this layer
486 Int_t iHit = iHitInd[0];
487 CbmTofHit* pHit = (CbmTofHit*) fHits->At(iHit);
488 Int_t iAddr = (pHit->GetAddress() & DetMask);
489 if (Double_t dLastChi2 = pTrk->GetMatChi2(fFindTracks->GetAddrOfStation(iDet)) == -1.) {
490 LOG(debug2) << Form(" -D- Add hit %d at %p, Addr 0x%08x, Chi2 %6.2f to size %u", iHit, pHit, iAddr,
491 dChi2[0], pTrk->GetNofHits());
492 pTrk->AddTofHitIndex(iHit, iAddr, pHit,
493 dChi2[0]); // store next Hit index with matching chi2
494 // pTrk->PrintInfo();
495 fvTrkVec[iHit].push_back(pTrk);
496 Line3Dfit(pTrk); // full MINUIT fit overwrites ParamLast!
497 Bool_t bkeep = kFALSE;
498 if ((pTrk->GetChiSq() > fChiMaxAccept)
499 || (fFindTracks->GetR0Lim() > 0 && pTrk->GetR0() > fFindTracks->GetR0Lim())) {
500 LOG(debug1) << Form("Add hit %d invalidates tracklet with Chi "
501 "%6.2f > %6.2f -> undo ",
502 iHit, pTrk->GetChiSq(), fChiMaxAccept);
503 fvTrkVec[iHit].pop_back();
504 pTrk->RemoveTofHitIndex(iHit, iAddr, pHit, dChi2[0]);
505 Line3Dfit(pTrk); //restore old status
506 bkeep = kTRUE;
507 }
508
509 if (bkeep) {
510 iNCand--;
511 for (Int_t iCand = 0; iCand < iNCand; iCand++) {
512 pTrkInd[iCand] = pTrkInd[iCand + 1];
513 iHitInd[iCand] = iHitInd[iCand + 1];
514 dChi2[iCand] = dChi2[iCand + 1];
515 }
516 }
517 else { // update chi2 array
518 PrintStatus((char*) "before UpdateTrackList");
519 UpdateTrackList(pTrk);
520 Int_t iNCandNew = 0;
521 for (Int_t iCand = 0; iCand < iNCand; iCand++) {
522 if (pTrk != pTrkInd[iCand] && iHit != iHitInd[iCand]) {
523 pTrkInd[iNCandNew] = pTrkInd[iCand];
524 iHitInd[iNCandNew] = iHitInd[iCand];
525 dChi2[iNCandNew] = dChi2[iCand];
526 iNCandNew++;
527 }
528 }
529 iNCand = iNCandNew;
530 }
531 }
532 else {
533 if (dChi2[0] < dLastChi2) { // replace hit index
534 LOG(fatal) << Form("-D- Replace %d, Addr 0x%08x, at %p, Chi2 %6.2f", iHit, iAddr, pHit, dChi2[0]);
535 //cout << " -D- Replace " << endl;
536 pTrk->ReplaceTofHitIndex(iHit, iAddr, pHit, dChi2[0]);
537 // TODO remove tracklet assigment of old hit! FIXME
538 }
539 else {
540 LOG(debug1) << Form(" -D- Ignore %d, Det %d, Addr 0x%08x, at 0x%p, Chi2 %6.2f", iHit, iDet, iAddr,
541 pHit, dChi2[0]);
542 // Form new seeds
543 //if (iDet<(fFindTracks->GetNStations()-1)) TrklSeed(fHits,fTracks,iHit);
544 break;
545 }
546 }
547
548 // pTrk->SetParamLast(tPar); // Initialize FairTrackParam for KF
549 //pTrk->GetFairTrackParamLast(); // transfer fit result to CbmTofTracklet
550 //pTrk->SetTime(pHit->GetTime()); // update reference time
551
552 //Line3Dfit(pTrk); // full MINUIT fit for debugging overwrites ParamLast!
553
554 pTrk->SetTime(pTrk->UpdateT0()); // update reference time (and fake hit time)
555
556 // check with ROOT fitting method
557 //TLinearFitter *lf=new TLinearFitter(3);
558 //lf->SetFormula("hyp3");
559
560 // update inverse velocity
561 Double_t dTt = pTrk->GetTt();
562
563 LOG(debug1) << Form("<Res> TofTracklet %p, HMul %d, Hits %d, %d, %d, "
564 "NDF %d, Chi2 %6.2f, T0 %6.2f, Tt %6.4f ",
565 pTrk, pTrk->GetNofHits(), iHit0, iHit1, iHit, pTrk->GetNDF(), pTrk->GetChiSq(),
566 pTrk->GetTime(), dTt);
567 PrintStatus((char*) "<Res> ");
568 LOG(debug2) << " Match loop status: NCand " << iNCand << ", iDet " << iDet;
569
570 /* live display insert
571 if(fair::Logger::Logging(fair::Severity::debug3)) // update event display, if initialized
572 {
573 Int_t ii;
574 CbmEvDisTracks* fDis = CbmEvDisTracks::Instance();
575 if(NULL != fDis) {
576 //gEve->Redraw3D(kTRUE);
577 //gEve->FullRedraw3D();
578 fiNtrks=0;
579 for(Int_t iTr=0; iTr<fTracks.size(); iTr++){
580 if(fTracks[iTr]==NULL) continue;
581 CbmTofTracklet* pTrkDis = new((*fTofTracks)[fiNtrks++]) CbmTofTracklet (*fTracks[iTr]);
582 }
583 fDis->Exec("");
584 }
585 cout << " fDis "<<fDis<<" with "<<fiNtrks<<" tracks, to continue type 0 ! "<<endl;
586 scanf("%d",&ii);
587 } // end of live display
588 */
589 } // end of while(iNCand>0)
590 } // detector loop (propagate) end
591 } // iSt1 while condition end
592 } // iSt0 while condition end
593 //fTracks->Compress();
594 //fTofTracks = fTracks;
595
596 //fFindTracks->PrintSetup();
597 // Add Vertex as additional point
598 //if(fbAddVertex) LOG(fatal)<<"Debugging step found AddVertex";
599 if (fiAddVertex > 0) AddVertex();
600
601 //fFindTracks->PrintSetup();
602
603 // copy fTracks -> fTofTracks / fOutTracks
604 LOG(debug1) << "Clean-up " << fTracks.size() << " tracklet candidates";
605 fiNtrks = 0;
606 for (size_t iTr = 0; iTr < fTracks.size(); iTr++) {
607 if (fTracks[iTr] == NULL) continue;
608 if (fTracks[iTr]->GetNofHits() < 3) continue; // request minimum number of hits (3)
609 if (fTracks[iTr]->GetChiSq() > fChiMaxAccept) continue; // request minimum ChiSq (3)
610 CbmTofTracklet* pTrk = new ((*fTofTracks)[fiNtrks++]) CbmTofTracklet(*fTracks[iTr]);
611
612 if (fair::Logger::Logging(fair::Severity::debug)) {
613 LOG(info) << "Found Trkl " << iTr;
614 pTrk->PrintInfo();
615 }
616 for (Int_t iHit = 0; iHit < pTrk->GetNofHits(); iHit++) { // mark used Hit
617 CbmTofHit* pHit = (CbmTofHit*) fHits->At(pTrk->GetHitIndex(iHit));
618 pHit->SetFlag(pHit->GetFlag() + 100.);
619 LOG(debug1) << Form(" hit %d at %d flagged to %d ", iHit, pTrk->GetHitIndex(iHit), pHit->GetFlag());
620 }
621 }
622 if (fair::Logger::Logging(fair::Severity::debug)) {
624 PrintStatus((char*) "<D> Final result");
625 }
626
627 for (size_t iTr = 0; iTr < fTracks.size(); iTr++) {
628 if (fTracks[iTr] == NULL) continue;
629 fTracks[iTr]->Delete();
630 //delete fTracks[iTr];
631 LOG(debug1) << Form("<I> TofTracklet %lu, %p deleted", iTr, fTracks[iTr]);
632 }
633 fTracks.resize(0); //cleanup
634 // fFindTracks->PrintSetup();
635 return 0;
636} // DoFind end
637
639{
640 CbmTofHit* pHit = (CbmTofHit*) fHits->At(iHit);
641 // Int_t iSmType = CbmTofAddress::GetSmType( pHit->GetAddress() & DetMask ); (VF) not used
642 Int_t iAddr = (pHit->GetAddress() & DetMask);
643 //Int_t iDet = fFindTracks->GetTypeStation(iSmType);
644 Int_t iDet = fFindTracks->GetStationOfAddr(iAddr);
645 if (iDet == fFindTracks->GetNofStations()) return; // hit not in tracking setup
646 for (Int_t iDet1 = 0; iDet1 < iDet; iDet1++) { // build new seeds
647 for (Int_t iHit1 = 0; iHit1 < fHits->GetEntriesFast(); iHit1++) { // loop over previous Hits
648 CbmTofHit* pHit1 = (CbmTofHit*) fHits->At(iHit1);
649 // Int_t iSmType1 = CbmTofAddress::GetSmType( pHit1->GetAddress() & DetMask ); (VF) not used
650 Int_t iAddr1 = (pHit1->GetAddress() & DetMask);
651 if (iAddr1 == iAddr) continue;
652 //if (iSmType1 == fFindTracks->GetStationType(iDet1)) { // generate candidate for new track seed
653 if (iAddr1 == fFindTracks->GetAddrOfStation(iDet1)) { // generate candidate for new track seed
654 Int_t iChId1 = pHit1->GetAddress();
655 CbmTofCell* fChannelInfo1 = fDigiPar->GetCell(iChId1);
656 Int_t iCh1 = CbmTofAddress::GetChannelId(iChId1);
657 Double_t hitpos1[3] = {3 * 0.};
658 Double_t hitpos1_local[3] = {3 * 0.};
659 Double_t dSizey1 = 1.;
660
661 if (NULL == fChannelInfo1) {
662 LOG(debug1) << "CbmTofTrackFinderNN::DoFindp: Invalid Channel Pointer for ChId " << Form(" 0x%08x ", iChId1)
663 << ", Ch " << iCh1;
664 // continue;
665 }
666 else {
667 /*TGeoNode *fNode1=*/ // prepare global->local trafo
668 gGeoManager->FindNode(fChannelInfo1->GetX(), fChannelInfo1->GetY(), fChannelInfo1->GetZ());
669 hitpos1[0] = pHit1->GetX();
670 hitpos1[1] = pHit1->GetY();
671 hitpos1[2] = pHit1->GetZ();
672 /*TGeoNode* cNode1=*/gGeoManager->GetCurrentNode();
673 gGeoManager->MasterToLocal(hitpos1, hitpos1_local);
674 dSizey1 = fChannelInfo1->GetSizey();
675 }
676 Double_t dDT = pHit->GetTime() - pHit1->GetTime();
677 Double_t dLz = pHit->GetZ() - pHit1->GetZ();
678 Double_t dTx = (pHit->GetX() - pHit1->GetX()) / dLz;
679 Double_t dTy = (pHit->GetY() - pHit1->GetY()) / dLz;
680 Int_t iUsed = HitUsed(iHit1);
681 LOG(debug2) << Form("<ISeed> TofTracklet %d, Hits %d, %d, used %d check, add = "
682 "0x%08x,0x%08x - DT %6.2f, Tx %6.2f Ty %6.2f ",
683 fiNtrks, iHit, iHit1, iUsed, pHit->GetAddress(), pHit1->GetAddress(), dDT, dTx, dTy);
684 if (TMath::Abs(hitpos1_local[1]) < dSizey1 * fPosYMaxScal)
685 if (TMath::Abs(dDT / dLz) < fMaxTofTimeDifference && TMath::Abs(dTx - fTxMean) < fTxLIM
686 && TMath::Abs(dTy - fTyMean) < fTyLIM && iUsed == 0) {
687 // CbmTofTracklet* pTrk = new((*fTracks)[++fiNtrks]) CbmTofTracklet(); // generate new track seed
688 CbmTofTracklet* pTrk = new CbmTofTracklet();
689 ++fiNtrks;
690 fTracks.push_back(pTrk);
691 pTrk->SetTofHitIndex(iHit1, iAddr1, pHit1); // store Hit index
692 //Int_t NTrks1=fvTrkMap[iHit1].size()+1;
693 //fvTrkMap[iHit1].insert(std::pair<CbmTofTracklet*,Int_t>(pTrk,NTrks1));
694 fvTrkVec[iHit1].push_back(pTrk);
695
696 pTrk->AddTofHitIndex(iHit, iAddr, pHit); // store 2. Hit index
697 //Int_t NTrks=fvTrkMap[iHit].size()+1;
698 //fvTrkMap[iHit].insert(std::pair<CbmTofTracklet*,Int_t>(pTrk,NTrks));
699 fvTrkVec[iHit].push_back(pTrk);
700
701 pTrk->SetTime(pHit->GetTime()); // define reference time from 2. plane
702 Double_t dR = pHit->GetR() - pHit1->GetR();
703 Double_t dTt = 1. / 30.; // assume speed of light: 1 / 30 cm/ns
704 // if( 0 == iSmType) pHit1->SetTime(pHit->GetTime() - dTt * dR);
705 dTt = (pHit->GetTime() - pHit1->GetTime()) / dR;
706 pTrk->SetTt(dTt);
707 pTrk->UpdateT0();
708
710 tPar->SetX(pHit->GetX()); // fill TrackParam
711 tPar->SetY(pHit->GetY()); // fill TrackParam
712 tPar->SetZ(pHit->GetZ()); // fill TrackParam
713 tPar->SetLz(dLz);
714 tPar->SetTx(dTx);
715 tPar->SetTy(dTy);
716 LOG(debug1) << Form("<DSeed> TofTracklet %d, Hits %d, %d add "
717 "initialized, add = 0x%08x,0x%08x ",
718 fiNtrks, iHit, iHit1, pHit->GetAddress(), pHit1->GetAddress());
719 PrintStatus((char*) "after DSeed");
720 }
721 }
722 } // hit loop end
723 } // Station loop end
724}
725
727{
728 // CbmTofHit* pHit = (CbmTofHit*) fHits->At( iHit ); (VF) not used
729 //Int_t iSmType = CbmTofAddress::GetSmType( pHit->GetAddress() & DetMask );
730 //Int_t iDet = fFindTracks->GetTypeStation(iSmType);
731 Int_t iUsed = 0;
732
733 // LOG(debug1)<<"CbmTofTrackFinderNN::HitUsed of Hind "<<iHit<<", TrkMap.size "<<fvTrkMap[iHit].size()
734 LOG(debug4) << "CbmTofTrackFinderNN::HitUsed of Hind " << iHit << ", TrkVec.size " << fvTrkVec[iHit].size();
735 /*
736 for ( std::map<CbmTofTracklet*,Int_t>::iterator it=fvTrkMap[iHit].begin(); it != fvTrkMap[iHit].end(); it++){
737 if(it->first->GetNofHits() > 2) return iUsed=1;
738 }
739 */
740 if (fvTrkVec[iHit].size() > 0) {
741 if (fvTrkVec[iHit][0]->GetNofHits() > 2) iUsed = 1;
742 }
743 return iUsed;
744}
745
747{
748 CbmTofTracklet* pTrk = (CbmTofTracklet*) fTracks[iTrk];
749 UpdateTrackList(pTrk);
750}
751
753{
754 for (Int_t iHit = 0; iHit < pTrk->GetNofHits(); iHit++) { // loop over Tracklet Hits
755 Int_t iHitInd = pTrk->GetHitIndex(iHit); // Hit index in fHits
756 //Int_t NTrks=fvTrkMap[iHitInd].size(); // Number of tracks containing this hit
757 Int_t NTrks = fvTrkVec[iHitInd].size(); // Number of tracks containing this hit
758 Int_t iAddr = (pTrk->GetTofHitPointer(iHit)->GetAddress() & DetMask);
759 if (iAddr == fFindTracks->GetBeamCounter()) continue; // keep all tracklets from common beam reference counter
760
761 // Int_t iSmType = CbmTofAddress::GetSmType( iAddr ); (VF) not used
762 //if(iSmType==0) continue; // keep all tracklets with common target faked hit
763
764 if (NTrks == 0)
765 LOG(fatal) << "UpdateTrackList NTrks=0 for event " << fFindTracks->GetEventNumber() << ", pTrk " << pTrk
766 << ", iHit " << iHit;
767 if (NTrks > 0) {
768 //PrintStatus((char*)"UpdateTrackList::cleanup1");
769 Int_t iterClean = 1;
770 while (iterClean > 0) {
771 LOG(debug2) << " <D1> UpdateTrackList for Trk " << pTrk
772 << Form(", %d.Hit(%d) at ind %d with %d(%d) registered tracks", iHit, pTrk->GetNofHits(), iHitInd,
773 (int) fvTrkVec[iHitInd].size(), NTrks);
774 //if(fvTrkVec[iHitInd].size()==1) break;
775 Int_t iTrkPos = 0;
776 for (std::vector<CbmTofTracklet*>::iterator iT = fvTrkVec[iHitInd].begin(); iT != fvTrkVec[iHitInd].end();
777 iT++) {
778 iterClean = 0;
779 LOG(debug2) << "Inspect track " << iTrkPos << " of " << fvTrkVec[iHitInd].size() << " for HitInd " << iHitInd;
780 if (iTrkPos >= (Int_t) fvTrkVec[iHitInd].size()) break;
781 iTrkPos++;
782 if (!Active(*iT)) break; // check whether tracklet is still active
783 LOG(debug2) << " <D2> process Trk " << *iT << " with " << (*iT)->GetNofHits() << " hits";
784 if (*iT == pTrk) {
785 LOG(debug2) << " <D2a> continue with next tracklet ";
786 continue;
787 }
788 for (Int_t iH = 0; iH < (*iT)->GetNofHits(); iH++) {
789 if (!Active(*iT)) break; // check whether tracklet is still active
790 Int_t iHi = (*iT)->GetTofHitIndex(iH);
791 LOG(debug2) << " <D3> process Hit " << iH << " at index " << iHi;
792 Int_t iAddri = ((*iT)->GetTofHitPointer(iH)->GetAddress() & DetMask);
793 LOG(debug2) << " --- iHitInd " << iHitInd << "(" << fvTrkVec.size() << "), size "
794 << fvTrkVec[iHitInd].size() << " - iH " << iH << "(" << (*iT)->GetNofHits() << "), iHi " << iHi
795 << " Hi vec size " << fvTrkVec[iHi].size()
796 << Form(" poi %p, iTpoi %p, SmAddr 0x%08x, 0x%08x, 0x%08x ", pTrk, *iT,
797 (*iT)->GetTofHitPointer(iH)->GetAddress(), iAddri, fFindTracks->GetBeamCounter());
798
799 if (iAddri == fFindTracks->GetBeamCounter()) {
800 LOG(debug2) << " Hit in beam counter, continue ...";
801 continue;
802 }
803 if (fvTrkVec[iHi].size() == 0) {
804 LOG(fatal) << "CbmTofTrackFinderNN::UpdateTrackList no track "
805 << " for hit " << iH << ", Hind " << iHi << ", size " << fvTrkVec[iHi].size();
806 break;
807 }
808 else { // loop over tracks referenced by hit iHi
809 for (std::vector<CbmTofTracklet*>::iterator it = fvTrkVec[iHi].begin(); it != fvTrkVec[iHi].end(); it++) {
810 LOG(debug2) << " UpdateTrackList for pTrk " << pTrk << " <-> " << *iT << " <-> " << *it << ", clean "
811 << iterClean << ", hit " << iHi << ", size " << fvTrkVec[iHi].size();
812 if (*it != pTrk) {
813 size_t iTr = 0;
814 for (iTr = 0; iTr < fTracks.size(); iTr++) {
815 if (fTracks[iTr] == *it) {
816 LOG(debug2) << Form(" found track entry %p(%d) at %lu "
817 "of iHi %d, pTrk %p",
818 *it, (int) fvTrkVec[iHi].size(), iTr, iHi, pTrk);
819 break;
820 }
821 }
822
823 if (iTr == fTracks.size()) {
824 LOG(fatal) << "CbmTofTrackFinderNN::UpdateTrackList: "
825 "Invalid iTr for pTrk "
826 << pTrk << ", iTr " << iTr << ", size " << fvTrkVec[iHi].size();
827 break;
828 }
829
830 LOG(debug2) << Form("<D4> number of registered hits %3d at "
831 "%p while keeping iHi = %d, pTrk at %p",
832 (*it)->GetNofHits(), (*it), iHi, pTrk);
833
834 CbmTofTracklet* pKill = *it;
835 // remove track link registered for each associated hit to the track that is going to be removed
836 for (Int_t iht = 0; iht < pKill->GetNofHits(); iht++) {
837 Int_t iHI = pKill->GetHitIndex(iht);
838 LOG(debug2) << Form("<D5> remove track link %p for hit iHi "
839 "= %d, loop index %d: iHI = %3d ",
840 pKill, iHi, iht, iHI);
841
842 for (std::vector<CbmTofTracklet*>::iterator itt = fvTrkVec[iHI].begin(); itt != fvTrkVec[iHI].end();
843 itt++) {
844 if ((*itt) == pTrk) continue;
845 if ((*itt) == pKill) {
846 LOG(debug2) << Form("<D6> remove track link %p for hit "
847 "iHi = %d, iHI = %3d, #Trks %3d",
848 pKill, iHi, iHI, (int) fvTrkVec[iHI].size());
849 if (fvTrkVec[iHI].size() == 1) {
850 LOG(debug2) << "<D6a> clear vector fvTrkVec for " << iHI;
851 fvTrkVec[iHI].clear();
852 // it =fvTrkVec[iHi].begin();
853 break;
854 }
855 else {
856 itt = fvTrkVec[iHI].erase(itt); // costly operation
857 LOG(debug2) << "<D6b> reduce fvTrkVec size of " << iHI << " to " << fvTrkVec[iHI].size();
858 break;
859 }
860 }
861 }
862 LOG(debug2) << Form("<D7> removed track link %p for hit "
863 "iHi = %d, loop %d: iHI = %3d ",
864 pKill, iHi, iht, iHI);
865
866 // PrintStatus((char*)"UpdateTrackList::Remove1");
867 } // loop on associated hits end
868 pKill->Delete(); //delete tracklet *it;
869 LOG(debug2) << "<D8> remove tracklet at pos " << iTr;
870 fTracks.erase(fTracks.begin() + iTr);
871 fiNtrks--;
872 if (fair::Logger::Logging(fair::Severity::debug2)) {
873 LOG(debug2) << "Erase1 for pTrk " << pTrk << ", at " << iTr << ", hit " << iHi << ", size "
874 << fvTrkVec[iHi].size();
875 PrintStatus((char*) "UpdateTrackList::Erase1");
876 }
877
878 /*
879 if(fvTrkVec[iHi].size() == 1) {
880 fvTrkVec[iHi].clear();
881 LOG(debug2) << " clear1 for pTrk "<<pTrk<<", hit "<<iHi<<", size "<<fvTrkVec[iHi].size()
882 ;
883 goto loopclean;
884 }else{
885 it=fvTrkVec[iHi].erase(it);
886 //NTrks--;
887 LOG(debug2) << " erase3 for "<<iTrk<<" at "<<pTrk<<", hit "<<iHi
888 <<", size "<<fvTrkVec[iHi].size()<<", "<<NTrks
889 ;
890 }
891
892 */
893 //if(iHi == iHitInd) NTrks--;
894 //PrintStatus((char*)"UpdateTrackList::cleanup2");
895 iterClean = 2;
896 break;
897 }
898 else { // *it==pTrk
899 if (fvTrkVec[iHi].size() < 2) break;
900 // if(pTrk == *iT) goto loopclean; //
901 }
902 } // end of loop over tracks referenced by hit iHi
903 LOG(debug2) << "Track loop of iHi = " << iHi << " finished";
904 }
905 if (!Active(*iT)) break; // check whether tracklet is still active
906 }
907 LOG(debug2) << "Hit loop of iTrkPos = " << iTrkPos << " finished";
908 }
909 LOG(debug2) << "Track loop of iHitInd = " << iHitInd << " finished";
910 }
911 }
912 }
913}
914
916{
917 LOG(debug1) << Form("<PS %s> for fiNtrks = %d tracks of %d, %d assigned hits ", cComment, fiNtrks,
918 (int) fTracks.size(), (int) fvTrkVec.size());
919
920 for (size_t it = 0; it < fTracks.size(); it++) {
922 if (NULL == pTrk) continue;
923 if (pTrk->GetNofHits() < 2) {
924 LOG(fatal) << "Invalid track found";
925 }
926
927 TString sTrk = "";
928 sTrk += Form(" Track %lu at %p, Hits: ", it, pTrk);
929 for (Int_t ih = 0; ih < pTrk->GetNofHits(); ih++) {
930 sTrk += Form(" %3d ", pTrk->GetHitIndex(ih));
931 }
932 sTrk += Form(", ChiSq %7.1f", pTrk->GetChiSq());
933 sTrk += Form(", Tt %6.4f", pTrk->GetTt());
934 LOG(debug1) << sTrk;
935 }
936
937 for (size_t ih = 0; ih < fvTrkVec.size(); ih++) {
938 CbmTofHit* pHit = (CbmTofHit*) fHits->At(ih);
939 if (NULL == pHit) LOG(fatal) << "<E> missing pointer for hit " << ih;
940 Int_t iAddr = (pHit->GetAddress() & DetMask);
941 Int_t iSt = fFindTracks->GetStationOfAddr(iAddr);
942 TString sTrk = "";
943 sTrk += Form(" Hit %lu, A 0x%08x, St %d, T %6.2f, Tracks(%d): ", ih, pHit->GetAddress(), iSt, pHit->GetTime(),
944 (int) fvTrkVec[ih].size());
945 if (iSt < fFindTracks->GetNStations()) {
946 for (size_t it = 0; it < fvTrkVec[ih].size(); it++) {
947 CbmTofTracklet* pTrk = fvTrkVec[ih][it];
948 sTrk += Form(" %p ", pTrk);
949 }
950 }
951 LOG(debug1) << sTrk;
952 }
953}
954
956{
957 for (size_t it = 0; it < fTracks.size(); it++) {
959 if (NULL == pTrk) continue;
960 if (pCheck == pTrk) return kTRUE;
961 }
962 return kFALSE;
963}
964
966{
967 Int_t iDetAddr = 0;
968 Line3Dfit(pTrk, iDetAddr);
969}
970
972{
973 TGraph2DErrors* gr = new TGraph2DErrors();
974
975 // Fill the 2D graph
976 // generate graph with the 3d points
977 Int_t Np = 0;
978 for (Int_t N = 0; N < pTrk->GetNofHits(); N++) {
979 if (((pTrk->GetTofHitPointer(N))->GetAddress() & DetMask) == iDetAddr) continue; //skip specific detector
980 Np++;
981 double x, y, z = 0;
982 x = (pTrk->GetTofHitPointer(N))->GetX();
983 y = (pTrk->GetTofHitPointer(N))->GetY();
984 z = (pTrk->GetTofHitPointer(N))->GetZ();
985 gr->SetPoint(N, x, y, z);
986 double dx, dy, dz = 0.;
987 dx = (pTrk->GetTofHitPointer(N))->GetDx();
988 dy = (pTrk->GetTofHitPointer(N))->GetDy();
989 dz = (pTrk->GetTofHitPointer(N))->GetDz(); //FIXME
990 gr->SetPointError(N, dx, dy, dz);
991 LOG(debug2) << "Line3Dfit add N = " << N << ",\t" << pTrk->GetTofHitIndex(N) << ",\t" << x << ",\t" << y << ",\t"
992 << z << ",\t" << dx << ",\t" << dy << ",\t" << dz;
993 }
994 // fit the graph now
995 Double_t pStart[4] = {0., 0., 0., 0.};
996 pStart[0] = pTrk->GetFitX(0.);
997 pStart[1] = (pTrk->GetTrackParameter())->GetTx();
998 pStart[2] = pTrk->GetFitY(0.);
999 pStart[3] = (pTrk->GetTrackParameter())->GetTy();
1000 LOG(debug2) << "Line3Dfit init: X0 " << pStart[0] << ", TX " << pStart[1] << ", Y0 " << pStart[2] << ", TY "
1001 << pStart[3];
1002
1003 fMinuit.DoFit(gr, pStart);
1004 //gr->Draw("err p0");
1005 gr->Delete();
1006 Double_t* dRes;
1007 dRes = fMinuit.GetParFit();
1008 LOG(debug2) << "Line3Dfit result: " << gMinuit->fCstatu << " : X0 " << dRes[0] << ", TX " << dRes[1] << ", Y0 "
1009 << dRes[2] << ", TY " << dRes[3] << ", Chi2DoF: " << fMinuit.GetChi2DoF();
1010
1011 (pTrk->GetTrackParameter())->SetX(dRes[0]);
1012 (pTrk->GetTrackParameter())->SetY(dRes[2]);
1013 (pTrk->GetTrackParameter())->SetZ(0.);
1014 (pTrk->GetTrackParameter())->SetTx(dRes[1]);
1015 (pTrk->GetTrackParameter())->SetTy(dRes[3]);
1016 (pTrk->GetTrackParameter())->SetQp(1.); // FIXME
1017 pTrk->SetChiSq(fMinuit.GetChi2DoF() / Np); //pTrk->GetNofHits());
1018 // empirical to equilibrate bias on hit multiplicity!!!
1019}
1020
1022{
1023 if (fTracks.size() < 2) return;
1024
1025 Double_t dTvtx = 0.;
1026 Double_t dT2vtx = 0.;
1027 Double_t dSigTvtx = 0.;
1028 Double_t nValidTracks = 0.;
1029 Double_t dToff = 0.;
1030 double dVx = 0.;
1031 double dVy = 0.;
1032 double dVx2 = 0.;
1033 double dVy2 = 0.;
1034 for (size_t it = 0; it < fTracks.size(); it++) {
1035 CbmTofTracklet* pTrk = (CbmTofTracklet*) fTracks[it];
1036 if (NULL == pTrk) continue;
1037 if (pTrk->GetR0() < fFindTracks->GetR0Lim()) {
1038 if (nValidTracks == 0) dToff = pTrk->GetT0();
1039 dTvtx += pTrk->GetT0() - dToff;
1040 dVx += pTrk->GetFitX(0.);
1041 dVy += pTrk->GetFitY(0.);
1042 dVx2 += dVx * dVx;
1043 dVy2 += dVy * dVy;
1044 dT2vtx += (pTrk->GetT0() - dToff) * (pTrk->GetT0() - dToff);
1045 nValidTracks += 1;
1046 }
1047 }
1048 LOG(debug1) << Form("AddVertex valid tracks %3.0f: %6.3f, %6.3f, %15.3f", nValidTracks, dTvtx, dT2vtx, dToff);
1049 if (nValidTracks >= fiVtxNbTrksMin) { // generate virtual hit
1050 dTvtx /= nValidTracks;
1051 dT2vtx /= nValidTracks;
1052 dSigTvtx = TMath::Sqrt(dT2vtx - dTvtx * dTvtx);
1053 dVx /= nValidTracks;
1054 dVy /= nValidTracks;
1055 dVx2 /= nValidTracks;
1056 dVy2 /= nValidTracks;
1057 LOG(debug1) << Form("AddVertex time %15.3f, sig %8.3f from %3.0f tracks ", dTvtx, dSigTvtx, nValidTracks);
1058 if (dSigTvtx < 1. * fChiMaxAccept) // FIXME constant in code
1059 {
1060 const Int_t iDetId = CbmTofAddress::GetUniqueAddress(0, 0, 0, 0, 10);
1061 if (fiAddVertex == 10) {
1062 dVx = 0.;
1063 dVy = 0.;
1064 }
1065 double dSigVx = TMath::Sqrt(dVx2 - dVx * dVx);
1066 double dSigVy = TMath::Sqrt(dVy2 - dVy * dVy);
1067 if (fiAddVertex > 1) {
1068 dSigVx /= nValidTracks;
1069 dSigVy /= nValidTracks;
1070 }
1071 const TVector3 hitPos(dVx, dVy, 0.);
1072 const TVector3 hitPosErr(dSigVx, dSigVy, 0.1); // initialize fake hit error
1073 const Double_t dTime0 = dTvtx + dToff; // FIXME
1074 /*
1075 if( fFindTracks->GetStationOfAddr(iDetId) < 0) {
1076 fFindTracks->SetStation(fFindTracks->GetNStations(), 10, 0, 0);
1077 fFindTracks->SetNStations(fFindTracks->GetNStations()+1);
1078 LOG(warn)<<"AddVertex increased NStations to "<<fFindTracks->GetNStations();
1079 }
1080 */
1081 Int_t iHitVtx = fHits->GetEntriesFast();
1082 CbmTofHit* pHitVtx =
1083 new ((*fHits)[iHitVtx]) CbmTofHit(iDetId, hitPos,
1084 hitPosErr, // local detector coordinates
1085 iHitVtx, // this number is used as reference!!
1086 dTime0, // Time of hit
1087 0, //vPtsRef.size(), // flag = number of TofPoints generating the cluster
1088 0);
1089 LOG(debug1) << "CbmTofTrackFinderNN::DoFind: Fake Vtx Hit at pos " << iHitVtx << Form(", T0 %f ", dTime0)
1090 << Form(", DetId 0x%08x TSR %d%d%d ", iDetId, CbmTofAddress::GetSmType(iDetId),
1092 pHitVtx->SetTimeError(dSigTvtx);
1093
1094 PrintStatus((char*) "InAddVertex");
1095
1096 fvTrkVec.resize(fHits->GetEntriesFast());
1097 LOG(debug2) << "<I> TrkMap/Vec resized for " << fHits->GetEntriesFast() << " entries ";
1098
1099 for (size_t it = 0; it < fTracks.size(); it++) {
1100 CbmTofTracklet* pTrk = (CbmTofTracklet*) fTracks[it];
1101 if (NULL == pTrk) continue;
1102 if (pTrk->GetR0() < fFindTracks->GetR0Lim()) {
1103 pTrk->AddTofHitIndex(iHitVtx, iDetId, pHitVtx);
1104 fvTrkVec[iHitVtx].push_back(pTrk);
1105 Line3Dfit(pTrk); // full MINUIT fit overwrites ParamLast!
1106 if (pTrk->GetChiSq() > fChiMaxAccept) {
1107 LOG(debug1) << Form("Add hit %d invalidates tracklet with Chi "
1108 "%6.2f > %6.2f -> undo ",
1109 iHitVtx, pTrk->GetChiSq(), fChiMaxAccept);
1110 fvTrkVec[iHitVtx].pop_back();
1111 pTrk->RemoveTofHitIndex(iHitVtx, iDetId, pHitVtx, 0.);
1112 Line3Dfit(pTrk); //restore old status
1113 }
1114 else {
1115 // update times fit
1116 Double_t dTt = pTrk->GetTt();
1117 LOG(debug1) << "Vtx added to track " << it << "; chi2 " << pTrk->GetChiSq() << ", Tt " << dTt;
1118 }
1119 }
1120 } //loop on tracks finished
1121 PrintStatus((char*) "PostAddVertex");
1122 }
1123 }
1124 /*
1125 // fvTrkMap.resize(fHits->GetEntriesFast());
1126 // for (Int_t iHit=0; iHit<fHits->GetEntriesFast(); iHit++) { fvTrkMap[iHit].clear();}
1127 for (Int_t iHit = 0; iHit < fHits->GetEntriesFast(); iHit++) {
1128 fvTrkVec[iHit].clear();
1129 }
1130*/
1131}
1132
ClassImp(CbmConverterManager)
Char_t * gr
TClonesArray * fTofTracks
const Int_t DetMask
Data class for track parameters.
static constexpr size_t size()
Definition KfSimdPseudo.h:2
void SetTimeError(double error)
Definition CbmHit.h:91
double GetTime() const
Definition CbmHit.h:76
int32_t GetAddress() const
Definition CbmHit.h:74
double GetZ() const
Definition CbmHit.h:71
void SetTime(double time)
Definition CbmHit.h:85
double GetY() const
Definition CbmPixelHit.h:74
double GetX() const
Definition CbmPixelHit.h:73
static uint32_t GetUniqueAddress(uint32_t Sm, uint32_t Rpc, uint32_t Channel, uint32_t Side=0, uint32_t SmType=0, uint32_t RpcType=0)
static int32_t GetSmId(uint32_t address)
static int32_t GetRpcId(uint32_t address)
static int32_t GetSmType(uint32_t address)
static int32_t GetChannelId(uint32_t address)
Double_t GetSizey() const
Definition CbmTofCell.h:40
Double_t GetY() const
Definition CbmTofCell.h:36
Double_t GetX() const
Definition CbmTofCell.h:35
Double_t GetZ() const
Definition CbmTofCell.h:37
CbmTofCell * GetCell(Int_t i)
Int_t GetBeamCounter() const
Double_t GetStationSigT(Int_t iSt)
Int_t GetStationOfAddr(Int_t iAddr)
static CbmTofFindTracks * Instance()
Double_t GetStationSigX(Int_t iSt)
Double_t GetTtTarg() const
Int_t GetMinNofHits() const
Double_t GetStationSigY(Int_t iSt)
Int_t GetAddrOfStation(Int_t iVal)
Int_t GetNReqStations() const
Int_t GetNStations() const
Int_t GetEventNumber() const
void SetFlag(int32_t flag)
Definition CbmTofHit.h:92
double GetR() const
Definition CbmTofHit.h:78
int32_t GetFlag() const
Definition CbmTofHit.h:75
std::vector< CbmTofTracklet * > fTracks
CbmTofTrackFinderNN & operator=(const CbmTofTrackFinderNN &fSource)
CbmTofFindTracks * fFindTracks
Int_t DoFind(TClonesArray *fTofHits, TClonesArray *fTofTracks)
CbmTofTrackFinderNN()
Constructor.
void Init()
Inherited from CbmTofTrackFinder.
Bool_t Active(CbmTofTracklet *pTrk)
std::vector< std::vector< CbmTofTracklet * > > fvTrkVec
static void Line3Dfit(CbmTofTracklet *pTrk)
void PrintStatus(char *cComm)
void UpdateTrackList(Int_t iTrk)
virtual ~CbmTofTrackFinderNN()
Destructor.
std::string ToString() const
Return string representation of class.
Provides information on attaching a TofHit to a TofTrack.
void SetTofHitIndex(int32_t ind, int32_t i)
int32_t GetNDF() const
double GetFitY(double Z)
int32_t GetTofHitIndex(int32_t ind) const
void SetChiSq(double chiSq)
int32_t GetHitIndex(int32_t ind) const
void AddTofHitIndex(int32_t tofHitIndex, int32_t iDet, CbmTofHit *pHit)
int32_t GetStationHitIndex(int32_t iSm) const
void SetTime(double val)
void ReplaceTofHitIndex(int32_t tofHitIndex, int32_t iDet, CbmTofHit *pHit, double chi2)
virtual void PrintInfo()
void RemoveTofHitIndex(int32_t, int32_t iDet, CbmTofHit *, double)
double GetTt() const
int32_t GetNofHits() const
CbmTofHit * GetTofHitPointer(int32_t ind)
virtual double GetMatChi2(int32_t iSm)
double GetTime() const
double GetTex(CbmTofHit *pHit)
void SetTt(double val)
double GetT0() const
double GetChiSq() const
CbmTofTrackletParam * GetTrackParameter()
double GetFitX(double Z)
virtual double Dist3D(CbmTofHit *pHit0, CbmTofHit *pHit1)
int DoFit(TGraph2DErrors *gr, double pStart[])
Definition LKFMinuit.cxx:36
int Initialize()
Definition LKFMinuit.cxx:23
double * GetParFit()
Definition LKFMinuit.h:37
double GetChi2DoF()
Definition LKFMinuit.h:39