14 #include "CbmTofHit.h"
17 #include "FairRootManager.h"
19 #include <TClonesArray.h>
21 #include <TGeoManager.h>
23 #include <TMatrixDSym.h>
37 : FairTask(
"Trd2TofVec")
60 FairRootManager* ioman = FairRootManager::Instance();
61 if (ioman == NULL) Fatal(
"Init",
"RootManager not instantiated!");
66 fTrackArray =
new TClonesArray(
"CbmMuchTrack", 100);
67 ioman->Register(
"TofVector",
"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 fTrdTracks =
static_cast<TClonesArray*
>(ioman->GetObject(
"TrdVector"));
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());
195 for (Int_t j = 0; j < nvec; ++j)
202 cout <<
" TRD tracks: " << nTrd << endl;
204 for (Int_t iv = 0; iv < nTrd; ++iv) {
208 line.SetUniqueID(iv);
210 for (Int_t
i = 0;
i < 2; ++
i) {
211 Double_t dz =
fZ[
i] - param.GetZ();
213 line.SetX1(param.GetX() + param.GetTx() * dz);
214 line.SetY1(param.GetY() + param.GetTy() * dz);
216 line.SetX2(param.GetX() + param.GetTx() * dz);
217 line.SetY2(param.GetY() + param.GetTy() * dz);
221 pair<Double_t, TLine>(TMath::Min(line.GetX1(), line.GetX2()), line));
231 const Double_t window = 50.0;
232 multimap<Double_t, Int_t>::iterator mitb, mite, mit1;
233 multimap<Double_t, pair<Int_t, Int_t>> rads;
234 map<pair<Int_t, Int_t>, pair<Double_t, Double_t>> dtdl;
235 set<Int_t> setVec, setHit;
237 for (multimap<Double_t, TLine>::iterator mit =
fLineX.begin();
240 Double_t rmin = 999999, dtmin = 0, dlmin = 0;
241 TVector3 trd(mit->second.GetX2() - mit->second.GetX1(),
242 mit->second.GetY2() - mit->second.GetY1(),
244 Double_t trdLeng = trd.Mag();
245 Int_t indVec = mit->second.GetUniqueID();
247 Int_t
id = tr->
GetFlag(), ihit = -1;
250 mitb =
fHitX.lower_bound(mit->first - window);
251 mite =
fHitX.upper_bound(
252 TMath::Max(mit->second.GetX1(), mit->second.GetX2()) + window);
254 for (mit1 = mitb; mit1 != mite; ++mit1)
255 inds.insert(mit1->second);
256 mitb =
fHitY.lower_bound(
257 TMath::Min(mit->second.GetY1(), mit->second.GetY2()) - window);
258 mite =
fHitY.upper_bound(
259 TMath::Max(mit->second.GetY1(), mit->second.GetY2()) + window);
261 for (mit1 = mitb; mit1 != mite; ++mit1) {
262 if (inds.find(mit1->second) == inds.end())
continue;
264 TVector3 tof(hit->
GetX() - mit->second.GetX1(),
265 hit->
GetY() - mit->second.GetY1(),
267 Double_t dt = TMath::Abs(trd.Cross(tof).Z()) / trdLeng;
268 Double_t dl = trd * tof / trdLeng;
273 Double_t rad = dl * dl + dt * dt;
275 rads.insert(pair<Double_t, pair<Int_t, Int_t>>(
276 rad, pair<Int_t, Int_t>(indVec, mit1->second)));
277 dtdl[pair<Int_t, Int_t>(indVec, mit1->second)] =
278 pair<Double_t, Double_t>(dt, dl);
279 setVec.insert(indVec);
280 setHit.insert(mit1->second);
309 for (multimap<Double_t, pair<Int_t, Int_t>>::iterator rmit = rads.begin();
312 Int_t indVec = rmit->second.first, ihit = rmit->second.second;
313 if (setVec.find(indVec) == setVec.end())
315 if (setHit.find(ihit) == setHit.end())
continue;
317 Bool_t match = kFALSE;
324 FairTrackParam param;
325 param.SetX(dtdl[rmit->second].first);
326 param.SetY(dtdl[rmit->second].second);
327 param.SetZ(rmit->first);
330 trTof->SetUniqueID(
id);
335 setVec.erase(indVec);
336 if (setVec.size() == 0)
break;
338 if (setHit.size() == 0)
break;
348 const Double_t cut[2] = {0.6, 0.6};
352 for (Int_t iv = 0; iv < nvec; ++iv) {
355 Double_t dTx = params->GetTx() - params->GetX() / params->GetZ();
356 if (TMath::Abs(dTx) > cut[0])
359 Double_t dTy = params->GetTy() - params->GetY() / params->GetZ();
360 if (TMath::Abs(dTy) > cut[1]) vec->
SetChiSq(-1.0);
364 for (Int_t iv = nvec - 1; iv >= 0; --iv) {
371 cout <<
" Vectors after parameter check: " << nvec <<
" " <<
fVectors.size()
381 Int_t nthr = 2, planes[20];
386 multimap<Double_t, CbmMuchTrack*> qMap;
387 multimap<Double_t, CbmMuchTrack*>::iterator it, it1;
389 for (Int_t
i = 0;
i < nvec; ++
i) {
393 qMap.insert(pair<Double_t, CbmMuchTrack*>(-qual, vec));
396 for (it = qMap.begin(); it != qMap.end(); ++it) {
403 for (Int_t ih = 0; ih < nhits; ++ih) {
410 for (++it1; it1 != qMap.end(); ++it1) {
418 for (Int_t ih = 0; ih < nhits1; ++ih) {
421 if (planes[lay] >= 0) {
422 if (vec1->
GetHitIndex(ih) == planes[lay]) same[lay] = 1;
426 for (Int_t lay = 0; lay <
fgkPlanes; ++lay)
432 if (nhits > nhits1 + 0)
442 for (Int_t iv = nvec - 1; iv >= 0; --iv) {
449 cout <<
" CbmTrdToTofVector:: Vectors after clones removed: " << nvec <<
" "
459 Int_t nHitsTot =
fHits->GetEntriesFast();
464 for (Int_t iv = 0; iv < nvec; ++iv) {
474 Int_t ihit =
fVectors[iv]->GetNDF();
475 for (set<Int_t>::iterator sit =
fHitIds[ihit].begin();
489 const Double_t cut[2] = {0.6, 0.6};
491 Double_t pars[4] = {0.0};
493 multimap<Int_t, Int_t>::iterator mit;
563 Bool_t ok = kFALSE, onoff;
592 Double_t chi2 = 0,
x = 0,
y = 0;
616 Bool_t refit = kFALSE;
657 map<Int_t, Int_t> ids;