21 #include "FairRootManager.h"
23 #include <TClonesArray.h>
24 #include <TGeoManager.h>
37 : FairTask(
"TrdFindVectors")
59 FairRootManager* ioman = FairRootManager::Instance();
60 if (ioman == NULL) Fatal(
"Init",
"RootManager not instantiated!");
65 fTrackArray =
new TClonesArray(
"CbmMuchTrack", 100);
66 ioman->Register(
"TrdVector",
"Trd",
fTrackArray, kTRUE);
68 fHits =
static_cast<TClonesArray*
>(ioman->GetObject(
"TrdHit"));
69 fClusters =
static_cast<TClonesArray*
>(ioman->GetObject(
"TrdCluster"));
73 if (NULL == mcManager) LOG(fatal) << GetName() <<
": No CbmMCDataManager!";
75 fDigiMatches =
static_cast<TClonesArray*
>(ioman->GetObject(
"TrdDigiMatch"));
79 cout <<
" ******* digiPar ******** " << tag << endl;
86 TGeoVolume* trdV = gGeoManager->GetVolume(tag);
89 TGeoNode* cave = gGeoManager->GetCurrentNode();
90 for (Int_t iNode = 0; iNode < cave->GetNdaughters(); iNode++) {
91 TGeoNode* node = cave->GetDaughter(iNode);
92 TString name = node->GetName();
93 if (name.Contains(
"trd")) {
95 gGeoManager->CdDown(iNode);
100 cout <<
"-E- CbmTrdFindVectors::Init: Cannot find top TRD node" << endl;
104 Int_t nlays = trdV->GetNdaughters();
107 for (Int_t
i = 0;
i < nlays; ++
i) {
108 TGeoVolume* lay = trdV->GetNode(
i)->GetVolume();
109 if (!(TString(lay->GetName()).Contains(
"layer")))
continue;
110 gGeoManager->CdDown(
i);
111 Int_t nmod = lay->GetNdaughters();
114 for (Int_t j = 0; j < nmod; ++j) {
115 TGeoVolume* mod = lay->GetNode(j)->GetVolume();
116 if (!(TString(mod->GetName()).Contains(
"module")))
continue;
117 gGeoManager->CdDown(j);
118 Int_t nparts = mod->GetNdaughters();
121 for (Int_t k = 0; k < nparts; ++k) {
122 TGeoNode* part = mod->GetNode(k);
123 if (!(TString(part->GetName()).Contains(
"gas")))
continue;
124 gGeoManager->CdDown(k);
125 Double_t posLoc[3] = {0}, posGlob[3] = {0};
126 gGeoManager->LocalToMaster(posLoc, posGlob);
127 cout <<
" gas " << gGeoManager->GetPath() <<
" " << std::setprecision(4)
128 << posGlob[2] << endl;
129 if (
i == 0)
fZ0 = posGlob[2];
164 for (Int_t j = 0; j < nVecs; ++j)
208 Int_t pattMax = 1 <<
fgkPlanes, nDouble = 0, nTot = 0;
211 for (Int_t ipat = 1; ipat < pattMax; ++ipat) {
217 if (ipat & (1 << j)) ++nDouble;
218 if (nDouble < 3)
continue;
222 onoff[j] = (ipat & (1 << j));
226 if (!onoff[
i])
continue;
229 coef(0, 2) +=
fDz[
i];
233 if (!onoff[
i])
continue;
237 coef(1, 3) +=
fDz[
i];
240 if (!onoff[
i])
continue;
241 coef(2, 0) +=
fDz[
i];
243 coef(2, 2) += dz2[
i];
247 if (!onoff[
i])
continue;
249 coef(3, 1) +=
fDz[
i];
251 coef(3, 3) += dz2[
i];
254 TDecompLU* lu =
new TDecompLU(4);
256 lu->SetTol(0.1 * lu->GetTol());
261 cov.SetMatrixArray(coef.GetMatrixArray());
264 fMatr[ipat] =
new TMatrixDSym(cov);
267 buf += Bool_t(ipat & (1 << jp));
268 Info(
"ComputeMatrix",
269 " Determinant: %s %i %f",
276 cout << TMath::Sqrt(cov(0, 0)) <<
" " << TMath::Sqrt(cov(1, 1)) <<
" "
277 << TMath::Sqrt(cov(2, 2)) <<
" " << TMath::Sqrt(cov(3, 3)) << endl;
278 cov *= (1.7 * 1.7 / 1.2 / 1.2);
279 cout << TMath::Sqrt(cov(0, 0)) <<
" " << TMath::Sqrt(cov(1, 1)) <<
" "
280 << TMath::Sqrt(cov(2, 2)) <<
" " << TMath::Sqrt(cov(3, 3)) << endl;
294 Int_t nHits =
fHits->GetEntriesFast(), sel = 0;
296 for (Int_t
i = 0;
i < nHits; ++
i) {
310 fHitPl[layer].insert(pair<Int_t, Int_t>(colId,
i));
311 fHitX[layer].insert(pair<Double_t, Int_t>(hit->
GetX(),
i));
321 for (Int_t j = 0; j < nvec; ++j)
326 cout <<
" TRD hits: " <<
fHits->GetEntriesFast() << endl;
327 for (Int_t lay = 0; lay < 2; ++lay) {
328 Int_t patt = 0, flag = 1, nhits =
fHitPl[lay].size();
329 cout <<
" Hits: " << lay <<
" " << nhits << endl;
330 multimap<Int_t, Int_t>::iterator mit;
332 for (mit =
fHitPl[lay].begin(); mit !=
fHitPl[lay].end(); ++mit) {
333 Int_t indx = mit->second;
357 const Double_t cut[2] = {0.6, 0.5};
361 for (Int_t iv = 0; iv < nvec; ++iv) {
364 Double_t dTx = params->GetTx() - params->GetX() / params->GetZ();
365 if (TMath::Abs(dTx) > cut[0])
368 Double_t dTy = params->GetTy() - params->GetY() / params->GetZ();
369 if (TMath::Abs(dTy) > cut[1]) vec->
SetChiSq(-1.0);
373 for (Int_t iv = nvec - 1; iv >= 0; --iv) {
380 cout <<
" Vectors after parameter check: " << nvec <<
" " <<
fVectors.size()
390 Int_t nthr = 2, planes[20];
395 multimap<Double_t, CbmMuchTrack*> qMap;
396 multimap<Double_t, CbmMuchTrack*>::iterator it, it1;
398 for (Int_t
i = 0;
i < nvec; ++
i) {
402 qMap.insert(pair<Double_t, CbmMuchTrack*>(-qual, vec));
405 for (it = qMap.begin(); it != qMap.end(); ++it) {
412 for (Int_t ih = 0; ih < nhits; ++ih) {
419 for (++it1; it1 != qMap.end(); ++it1) {
427 for (Int_t ih = 0; ih < nhits1; ++ih) {
430 if (planes[lay] >= 0) {
431 if (vec1->
GetHitIndex(ih) == planes[lay]) same[lay] = 1;
435 for (Int_t lay = 0; lay <
fgkPlanes; ++lay)
441 if (nhits > nhits1 + 0)
451 for (Int_t iv = nvec - 1; iv >= 0; --iv) {
458 cout <<
" Vectors after clones removed: " << nvec <<
" " <<
fVectors.size()
468 Int_t nHitsTot =
fHits->GetEntriesFast();
473 for (Int_t iv = 0; iv < nvec; ++iv) {
488 const Double_t cut[2] = {0.6,
490 const Double_t cut1[2] = {
493 Double_t pars[4] = {0.0};
495 multimap<Int_t, Int_t>::iterator mit;
499 for (mit =
fHitPl[lay].begin(); mit !=
fHitPl[lay].end(); ++mit) {
500 Int_t indx = mit->second;
515 if (!(patt & (1 << lay0))) ++lay0;
517 if (TString::Itoa(patt, 2).CountChar(
'1') < 2) {
519 Double_t dx =
fXy[lay][0] -
fXy[lay0][0];
520 Double_t dz =
fXy[lay][4] -
fXy[lay0][4];
522 Double_t dTx = dx / dz -
fXy[lay][0] /
fXy[lay][4];
523 if (TMath::Abs(dTx) > cut[0])
continue;
524 Double_t dy =
fXy[lay][1] -
fXy[lay0][1];
526 Double_t dTy = dy / dz -
fXy[lay][1] /
fXy[lay][4];
527 if (TMath::Abs(dTy) > cut[1])
continue;
529 Double_t dx =
fXy[lay][0] -
fXy[lay0][0];
530 Double_t dz =
fXy[lay][4] -
fXy[lay0][4];
531 Int_t lay1 = lay - 1;
532 if (!(patt & (1 << lay1))) --lay1;
534 Double_t dx1 =
fXy[lay][0] -
fXy[lay1][0];
535 Double_t dz1 =
fXy[lay][4] -
fXy[lay1][4];
536 Double_t dTx = dx / dz - dx1 / dz1;
537 if (TMath::Abs(dTx) > cut1[0])
continue;
538 Double_t dy =
fXy[lay][1] -
fXy[lay0][1];
539 Double_t dy1 =
fXy[lay][1] -
fXy[lay1][1];
540 Double_t dTy = dy / dz - dy1 / dz1;
541 if (TMath::Abs(dTy) > cut1[1])
continue;
553 else if (TString::Itoa(patt, 2).CountChar(
'1') > 2) {
556 Double_t chi2 =
FindChi2(patt, pars);
557 cout <<
" *** Stat: " << chi2 <<
" " << pars[0] <<
" " << pars[1] << endl;
566 if (flag0 == 0)
return;
571 else if (TString::Itoa(patt, 2).CountChar(
'1') > 2) {
574 Double_t chi2 =
FindChi2(patt, pars);
575 cout <<
" *** Stat: " << chi2 <<
" " << pars[0] <<
" " << pars[1] << endl;
588 Bool_t ok = kFALSE, onoff;
591 onoff = patt & (1 <<
i);
592 if (!onoff)
continue;
600 TVectorD solve =
fLus[patt]->Solve(b, ok);
603 for (Int_t
i = 0;
i < 4; ++
i)
616 Double_t chi2 = 0,
x = 0,
y = 0;
620 onoff = patt & (1 <<
i);
621 if (!onoff)
continue;
622 x = pars[0] + pars[2] *
fDz[
i];
623 y = pars[1] + pars[3] *
fDz[
i];
640 Bool_t refit = kFALSE;
657 FairTrackParam par(pars[0], pars[1],
fZ0, pars[2], pars[3], 0.0, cov);
665 for (Int_t ipl = 0; ipl <
fgkPlanes; ++ipl) {
666 if (!(patt & (1 << ipl)))
continue;
680 map<Int_t, Int_t> ids;
684 for (Int_t ih = 0; ih < nhits; ++ih) {
690 for (Int_t j = 0; j < nDigis; ++j) {
694 for (Int_t ip = 0; ip < np; ++ip) {
699 id = point->GetTrackID();
701 if (ids.find(
id) == ids.end())
702 ids.insert(pair<Int_t, Int_t>(
id, 1));
709 Int_t maxim = -1, idmax = -9;
710 for (map<Int_t, Int_t>::iterator it = ids.begin(); it != ids.end(); ++it) {
711 if (it->second > maxim) {