14 #include "CbmTofHit.h"
17 #include "FairRootManager.h"
19 #include <TClonesArray.h>
21 #include <TGeoManager.h>
23 #include <TMatrixDSym.h>
37 : FairTask(
"Much2TofVec")
60 FairRootManager* ioman = FairRootManager::Instance();
61 if (ioman == NULL) Fatal(
"Init",
"RootManager not instantiated!");
66 fTrackArray =
new TClonesArray(
"CbmMuchTrack", 100);
67 ioman->Register(
"Tof1Vector",
"Tof",
fTrackArray, kTRUE);
69 fHits =
static_cast<TClonesArray*
>(ioman->GetObject(
"TofHit"));
70 fHitMatches =
static_cast<TClonesArray*
>(ioman->GetObject(
"TofDigiMatch"));
74 if (NULL == mcManager) LOG(fatal) << GetName() <<
": No CbmMCDataManager!";
76 fDigis =
static_cast<TClonesArray*
>(ioman->GetObject(
"TofDigi"));
78 static_cast<TClonesArray*
>(ioman->GetObject(
"TofDigiMatchPoints"));
79 fMuchTracks =
static_cast<TClonesArray*
>(ioman->GetObject(
"MuchVectorTrack"));
83 cout <<
" ******* TOF tag ******** " << tag << endl;
90 TGeoVolume* tofV = gGeoManager->GetVolume(tag);
91 TGeoBBox*
shape = (TGeoBBox*) tofV->GetShape();
93 cout <<
" TOF span in Z: " <<
fZ[0] <<
" " <<
fZ[1] << endl;
150 Int_t nHits =
fHits->GetEntriesFast(), sel = 0;
152 for (Int_t
i = 0;
i < nHits; ++
i) {
159 fHitX.insert(pair<Double_t, Int_t>(hit->
GetX(),
i));
160 fHitY.insert(pair<Double_t, Int_t>(hit->
GetY(),
i));
166 for (Int_t il = 0; il < nlinks; ++il) {
173 for (Int_t ip = 0; ip < npoints; ++ip) {
178 fHitIds[
i].insert(point->GetTrackID());
194 const Int_t nMinSeg = 5;
196 for (Int_t j = 0; j < nvec; ++j)
203 cout <<
" MUCH tracks: " << nMuch << endl;
205 for (Int_t iv = 0; iv < nMuch; ++iv) {
210 line.SetUniqueID(iv);
212 for (Int_t
i = 0;
i < 2; ++
i) {
213 Double_t dz =
fZ[
i] - param.GetZ();
215 line.SetX1(param.GetX() + param.GetTx() * dz);
216 line.SetY1(param.GetY() + param.GetTy() * dz);
218 line.SetX2(param.GetX() + param.GetTx() * dz);
219 line.SetY2(param.GetY() + param.GetTy() * dz);
223 pair<Double_t, TLine>(TMath::Min(line.GetX1(), line.GetX2()), line));
233 const Double_t window = 50.0;
234 multimap<Double_t, Int_t>::iterator mitb, mite, mit1;
235 multimap<Double_t, pair<Int_t, Int_t>> rads;
236 map<pair<Int_t, Int_t>, pair<Double_t, Double_t>> dtdl;
237 set<Int_t> setVec, setHit;
239 for (multimap<Double_t, TLine>::iterator mit =
fLineX.begin();
242 Double_t rmin = 999999, dtmin = 0, dlmin = 0;
243 TVector3 trd(mit->second.GetX2() - mit->second.GetX1(),
244 mit->second.GetY2() - mit->second.GetY1(),
246 Double_t trdLeng = trd.Mag();
247 Int_t indVec = mit->second.GetUniqueID();
249 Int_t
id = tr->
GetFlag(), ihit = -1;
252 mitb =
fHitX.lower_bound(mit->first - window);
253 mite =
fHitX.upper_bound(
254 TMath::Max(mit->second.GetX1(), mit->second.GetX2()) + window);
256 for (mit1 = mitb; mit1 != mite; ++mit1)
257 inds.insert(mit1->second);
258 mitb =
fHitY.lower_bound(
259 TMath::Min(mit->second.GetY1(), mit->second.GetY2()) - window);
260 mite =
fHitY.upper_bound(
261 TMath::Max(mit->second.GetY1(), mit->second.GetY2()) + window);
263 for (mit1 = mitb; mit1 != mite; ++mit1) {
264 if (inds.find(mit1->second) == inds.end())
continue;
266 TVector3 tof(hit->
GetX() - mit->second.GetX1(),
267 hit->
GetY() - mit->second.GetY1(),
269 Double_t dt = TMath::Abs(trd.Cross(tof).Z()) / trdLeng;
270 Double_t dl = trd * tof / trdLeng;
275 Double_t rad = dl * dl + dt * dt;
277 rads.insert(pair<Double_t, pair<Int_t, Int_t>>(
278 rad, pair<Int_t, Int_t>(indVec, mit1->second)));
279 dtdl[pair<Int_t, Int_t>(indVec, mit1->second)] =
280 pair<Double_t, Double_t>(dt, dl);
281 setVec.insert(indVec);
282 setHit.insert(mit1->second);
311 for (multimap<Double_t, pair<Int_t, Int_t>>::iterator rmit = rads.begin();
314 Int_t indVec = rmit->second.first, ihit = rmit->second.second;
315 if (setVec.find(indVec) == setVec.end())
317 if (setHit.find(ihit) == setHit.end())
continue;
319 Bool_t match = kFALSE;
322 if (
id < 0)
id = 9999;
327 FairTrackParam param;
328 param.SetX(dtdl[rmit->second].first);
329 param.SetY(dtdl[rmit->second].second);
330 param.SetZ(rmit->first);
333 trTof->SetUniqueID(
id);
338 setVec.erase(indVec);
339 if (setVec.size() == 0)
break;
341 if (setHit.size() == 0)
break;
351 const Double_t cut[2] = {0.6, 0.6};
355 for (Int_t iv = 0; iv < nvec; ++iv) {
358 Double_t dTx = params->GetTx() - params->GetX() / params->GetZ();
359 if (TMath::Abs(dTx) > cut[0])
362 Double_t dTy = params->GetTy() - params->GetY() / params->GetZ();
363 if (TMath::Abs(dTy) > cut[1]) vec->
SetChiSq(-1.0);
367 for (Int_t iv = nvec - 1; iv >= 0; --iv) {
374 cout <<
" Vectors after parameter check: " << nvec <<
" " <<
fVectors.size()
384 Int_t nthr = 2, planes[20];
389 multimap<Double_t, CbmMuchTrack*> qMap;
390 multimap<Double_t, CbmMuchTrack*>::iterator it, it1;
392 for (Int_t
i = 0;
i < nvec; ++
i) {
396 qMap.insert(pair<Double_t, CbmMuchTrack*>(-qual, vec));
399 for (it = qMap.begin(); it != qMap.end(); ++it) {
406 for (Int_t ih = 0; ih < nhits; ++ih) {
413 for (++it1; it1 != qMap.end(); ++it1) {
421 for (Int_t ih = 0; ih < nhits1; ++ih) {
424 if (planes[lay] >= 0) {
425 if (vec1->
GetHitIndex(ih) == planes[lay]) same[lay] = 1;
429 for (Int_t lay = 0; lay <
fgkPlanes; ++lay)
435 if (nhits > nhits1 + 0)
445 for (Int_t iv = nvec - 1; iv >= 0; --iv) {
452 cout <<
" CbmTrdToTofVector:: Vectors after clones removed: " << nvec <<
" "
462 Int_t nHitsTot =
fHits->GetEntriesFast();
467 for (Int_t iv = 0; iv < nvec; ++iv) {
477 Int_t ihit =
fVectors[iv]->GetNDF();
478 for (set<Int_t>::iterator sit =
fHitIds[ihit].begin();
492 const Double_t cut[2] = {0.6, 0.6};
494 Double_t pars[4] = {0.0};
496 multimap<Int_t, Int_t>::iterator mit;
566 Bool_t ok = kFALSE, onoff;
595 Double_t chi2 = 0,
x = 0,
y = 0;
619 Bool_t refit = kFALSE;
660 map<Int_t, Int_t> ids;