3#include "BmnFieldPar.h"
4#include "BmnTOF1GeoPar.h"
5#include "CbmGeoStsPar.h"
6#include "CbmGeoSttPar.h"
9#include "CbmMvdGeoPar.h"
10#include "CbmStsStation.h"
11#include "FairBaseParSet.h"
12#include "FairGeoNode.h"
13#include "FairGeoPassivePar.h"
14#include "FairRunAna.h"
15#include "FairRuntimeDb.h"
23CbmKF* CbmKF::fInstance = 0;
50 , fMaterialID2IndexMap()
66 FairRuntimeDb* rtdb = FairRuntimeDb::instance();
67 rtdb->getContainer(
"FairBaseParSet");
68 rtdb->getContainer(
"FairGeoParSet");
69 rtdb->getContainer(
"FairGeoPassivePar");
70 rtdb->getContainer(
"CbmMvdGeoPar");
71 rtdb->getContainer(
"CbmGeoStsPar");
72 rtdb->getContainer(
"BmnTOF1GeoPar");
73 rtdb->getContainer(
"CbmGeoSttPar");
74 rtdb->getContainer(
"BmnFieldPar");
75 rtdb->getContainer(
"CbmStsDigiPar");
101 fMaterialID2IndexMap.clear();
103 FairRuntimeDb* RunDB = FairRuntimeDb::instance();
113 cout <<
"KALMAN FILTER : === INIT MAGNETIC FIELD ===" << endl;
118 if (fVerbose && fMagneticField)
119 cout <<
"Magnetic field done" << endl;
131 cout <<
"KALMAN FILTER : === READ MVD MATERIAL ===" << endl;
137 cout <<
"-E- " << GetName() <<
"::GetGeometry: No MVD node array" << endl;
142 NMvdStations = mvdNodes->GetEntries();
144 for (Int_t ist = 0; ist < NMvdStations; ist++) {
145 FairGeoNode* mvdNode =
reinterpret_cast<FairGeoNode*
>(mvdNodes->At(ist));
147 cout <<
"-W- CbmKF::Init: station#" << ist <<
" not found among sensitive nodes " << endl;
152 if (ReadTube(tube, mvdNode))
154 tube.
ID = 1101 + ist;
159 cout <<
" Mvd detector " << tube.
Info() << endl;
168 cout <<
"KALMAN FILTER : === READ STS MATERIAL ===" << endl;
173 for (Int_t ist = 0; ist <
NStations; ist++) {
188 tube.
rr = tube.
r * tube.
r;
189 tube.
RR = tube.
R * tube.
R;
197 cout <<
" Sts material ( id, z, dz, r, R, RadL )= ( " << tube.
ID <<
", " << tube.
z <<
", " << tube.
dz
198 <<
", " << tube.
r <<
", " << tube.
R <<
", " << tube.
RadLength <<
" )" << endl;
223 cout <<
"KALMAN FILTER : === READ STT DETECTORS ===" << endl;
228 for (Int_t
i = 0;
i < Nodes->GetEntries(); ++
i) {
229 FairGeoNode* node =
dynamic_cast<FairGeoNode*
>(Nodes->At(
i));
233 TString name = node->getName();
234 if (name.Contains(
"C2gas"))
237 if (ReadTube(tube, node))
243 if (name.Contains(
"stt1"))
244 wall.
F = 7.552e-4 / 1.653e-4;
246 wall.
F = 8.378e-4 / 2.479e-4;
249 wall.
F = TMath::Sqrt(wall.
F);
252 for (Int_t lay = 0; lay < 6; ++lay) {
257 wall.
ID = tube.
ID + lay;
263 cout <<
" Stt detector " << name <<
": " << wall.
Info() <<
", station " << ista << endl;
283 cout <<
"KALMAN FILTER : === READ TOF PASSIVE MATERIAL ===" << endl;
285 cout <<
"printout skipped for Verbose mode 1" << endl;
287 for (Int_t
i = 0;
i < Nodes->GetEntries();
i++) {
288 FairGeoNode* node =
dynamic_cast<FairGeoNode*
>(Nodes->At(
i));
291 TString name = node->getName();
296 cout <<
" Tof material " << name <<
" : " << kfmat->
Info() << endl;
300 cout <<
"KALMAN FILTER : === READ TOF DETECTORS ===" << endl;
303 for (Int_t
i = 0;
i < Nodes->GetEntries();
i++) {
304 FairGeoNode* node =
dynamic_cast<FairGeoNode*
>(Nodes->At(
i));
307 TString name = node->getName();
312 cout <<
" Tof material " << name <<
" : " << kfmat->
Info() << endl;
323 FairGeoNode* node = 0;
326 cout <<
"KALMAN FILTER : === READ BEAM PIPE MATERIAL ===" << endl;
328 node =
dynamic_cast<FairGeoNode*
>(Nodes->FindObject(
"pipe1"));
332 TString name = node->getName();
333 TString Sname = node->getShapePointer()->GetName();
335 FairGeoVector nodeV(0, 0, 0);
336 if (node->getMotherNode())
337 nodeV = node->getLabTransform()->getTranslation();
338 FairGeoVector centerV = node->getCenterPosition().getTranslation();
339 TArrayD* P = node->getParameters();
340 Int_t NP = node->getShapePointer()->getNumParam();
341 FairGeoMedium* material = node->getMedium();
342 material->calcRadiationLength();
344 Double_t z = nodeV.Z() + centerV.Z();
346 if (Sname ==
"PCON") {
347 Int_t Nz = (NP - 3) / 3;
348 for (Int_t
i = 0;
i < Nz - 1;
i++) {
350 cone.
ID = node->getMCid();
351 cone.
z1 = P->At(3 +
i * 3 + 0) + z;
352 cone.
r1 = P->At(3 +
i * 3 + 1);
353 cone.
R1 = P->At(3 +
i * 3 + 2);
354 cone.
z2 = P->At(3 + (
i + 1) * 3 + 0) + z;
355 cone.
r2 = P->At(3 + (
i + 1) * 3 + 1);
356 cone.
R2 = P->At(3 + (
i + 1) * 3 + 2);
357 cone.
RadLength = material->getRadiationLength();
363 vPipe.push_back(cone);
366 cout <<
" Pipe material ( id, {z1, r1, R1}, {z2, r2, R2}, RL )= ( " << node->getMCid() <<
", {"
367 << cone.
z1 <<
", " << cone.
r1 <<
", " << cone.
R1 <<
"}, {" << cone.
z2 <<
", " << cone.
r2
368 <<
", " << cone.
R2 <<
"}, " << cone.
RadLength <<
" )" << endl;
371 cout <<
" unknown pipe shape : " << Sname << endl;
376 cout <<
"KALMAN FILTER : === READ TARGET MATERIAL ===" << endl;
379 TGeoVolume* trg =
nullptr;
380 if (gGeoManager !=
nullptr)
381 trg = gGeoManager->GetVolume(
"targ");
390 CbmKFTube tube1(100500, 0.375, -0.006, 0.175 / 2, 0.175, 0, 1.6,
394 cout <<
" Target material " << tube1.
Info() << endl;
398 if (!ReadTube(tube, trg)) {
401 cout <<
" Target material " << tube.
Info() << endl;
402 cout <<
" Target material " << tube.
Info() << endl;
419 for (vector<CbmKFCone>::iterator
i =
vPipe.begin();
i !=
vPipe.end(); ++
i) {
451 fMaterialID2IndexMap.insert(pair<Int_t, Int_t>(
vMaterial[
i]->ID,
i));
453 cout <<
" KF TOTAL MATIREAL: " <<
vMaterial[
i]->ID << endl;
461 map<Int_t, Int_t>::iterator
i = fMaterialID2IndexMap.find(uid);
462 if (
i != fMaterialID2IndexMap.end()) {
470Int_t CbmKF::ReadTube(
CbmKFTube& tube, TGeoVolume* vol)
478 TGeoNode* cave = gGeoManager->FindNode(1000, 1000, 1000);
479 if (TString(cave->GetName()) !=
"cave_1")
482 int nd = cave->GetNdaughters(), ok = 0;
484 for (
int i = 0;
i < nd; ++
i) {
485 TGeoNode* dnode = cave->GetDaughter(
i);
486 if (TString(dnode->GetName()) !=
"targ_0")
489 const Double_t* shift = dnode->GetMatrix()->GetTranslation();
497 Double_t radLeng = vol->GetMedium()->GetMaterial()->GetRadLen();
503 TGeoTube* tu = (TGeoTube*)vol->GetShape();
504 tube.
r = tu->GetRmin();
505 tube.
R = tu->GetRmax();
506 tube.
dz = 2. * tu->GetDz();
508 tube.
rr = tube.
r * tube.
r;
509 tube.
RR = tube.
R * tube.
R;
517Int_t CbmKF::ReadTube(
CbmKFTube& tube, FairGeoNode* node)
523 TString
name = node->getName();
524 TString Sname = node->getShapePointer()->GetName();
525 FairGeoVector nodeV = node->getLabTransform()->getTranslation();
526 FairGeoVector centerV = node->getCenterPosition().getTranslation();
527 TArrayD* P = node->getParameters();
528 Int_t NP = node->getShapePointer()->getNumParam();
529 FairGeoMedium* material = node->getMedium();
530 material->calcRadiationLength();
532 tube.
ID = node->getMCid();
533 tube.
RadLength = material->getRadiationLength();
537 TString Mname = material->GetName();
538 if (Mname ==
"MUCHWolfram") {
540 }
else if (Mname ==
"MUCHiron") {
542 }
else if (Mname ==
"carbon") {
546 tube.
x = nodeV.X() + centerV.X();
547 tube.
y = nodeV.Y() + centerV.Y();
548 tube.
z = nodeV.Z() + centerV.Z();
557 if (Sname ==
"TUBS" || Sname ==
"TUBE") {
560 tube.
dz = 2. * P->At(2);
561 }
else if (Sname ==
"TRAP") {
564 tube.
dz = 2. * P->At(0);
565 }
else if (Sname ==
"SPHE") {
568 tube.
z += 0.5 * (P->At(0) + P->At(1));
569 tube.
dz = (P->At(1) - P->At(0));
570 }
else if (Sname ==
"PCON") {
571 Int_t Nz = (NP - 3) / 3;
572 double Z = -100000, R = -100000, z = 100000, r = 100000;
573 for (Int_t
i = 0;
i < Nz;
i++) {
574 double z1 = P->At(3 +
i * 3 + 0);
575 double r1 = P->At(3 +
i * 3 + 1);
576 double R1 = P->At(3 +
i * 3 + 2);
589 tube.
z += (z + Z) / 2.;
591 }
else if (Sname ==
"PGON") {
592 Int_t Nz = (NP - 4) / 3;
593 double Z = -100000, R = -100000, z = 100000, r = 100000;
594 for (Int_t
i = 0;
i < Nz;
i++) {
595 double z1 = P->At(4 +
i * 3 + 0);
596 double r1 = P->At(4 +
i * 3 + 1);
597 double R1 = P->At(4 +
i * 3 + 2);
609 tube.
z += (z + Z) / 2.;
611 }
else if (Sname ==
"BOX ") {
612 double dx = 2 * P->At(0);
613 double dy = 2 * P->At(1);
614 double dz = 2 * P->At(2);
616 tube.
R = TMath::Sqrt(dx * dx + dy * dy);
619 cout <<
" -E- unknown shape : " << Sname << endl;
620 cout <<
" -E- It does not make sense to go on" << endl;
621 cout <<
" -E- Stop execution here" << endl;
622 Fatal(
"CbmKF::ReadTube",
"Unknown Shape");
624 tube.
rr = tube.
r * tube.
r;
625 tube.
RR = tube.
R * tube.
R;
637 TString
name = node->getName();
638 TString Sname = node->getShapePointer()->GetName();
640 FairGeoTransform trans(*node->getLabTransform());
641 FairGeoNode* nxt = node;
642 while ((nxt = nxt->getMotherNode())) {
643 FairGeoTransform* tm = nxt->getLabTransform();
646 trans.transFrom(*tm);
652 FairGeoVector nodeV = trans.getTranslation();
653 FairGeoVector centerV = nodeV + node->getCenterPosition().getTranslation();
655 TArrayD* P = node->getParameters();
656 Int_t NP = node->getShapePointer()->getNumParam();
657 FairGeoMedium* material = node->getMedium();
658 material->calcRadiationLength();
660 Int_t ID = node->getMCid();
661 Double_t RadLength = material->getRadiationLength();
663 Double_t x0 = centerV.X();
664 Double_t y0 = centerV.Y();
665 Double_t
z0 = centerV.Z();
669 if (Sname ==
"TUBS" || Sname ==
"TUBE") {
670 CbmKFTube tube(ID, x0, y0,
z0, 2. * P->At(2), P->At(0), P->At(1), RadLength);
673 }
else if (Sname ==
"SPHE") {
674 CbmKFTube tube(ID, x0, y0,
z0 + 0.5 * (P->At(0) + P->At(1)), (P->At(1) - P->At(0)), 0, 1000, RadLength);
677 }
else if (Sname ==
"PCON") {
678 Int_t Nz = (NP - 3) / 3;
679 double Z = -100000, R = -100000, z = 100000, r = 100000;
680 for (Int_t
i = 0;
i < Nz;
i++) {
681 double z1 = P->At(3 +
i * 3 + 0);
682 double r1 = P->At(3 +
i * 3 + 1);
683 double R1 = P->At(3 +
i * 3 + 2);
693 CbmKFTube tube(ID, x0, y0,
z0 + 0.5 * (z + Z), (Z - z), r, R, RadLength);
696 }
else if (Sname ==
"PGON") {
697 Int_t Nz = (NP - 4) / 3;
698 double Z = -100000, R = -100000, z = 100000, r = 100000;
699 for (Int_t
i = 0;
i < Nz;
i++) {
700 double z1 = P->At(4 +
i * 3 + 0);
701 double r1 = P->At(4 +
i * 3 + 1);
702 double R1 = P->At(4 +
i * 3 + 2);
712 CbmKFTube tube(ID, x0, y0,
z0 + 0.5 * (z + Z), (Z - z), r, R, RadLength);
715 }
else if (Sname ==
"BOX ") {
716 CbmKFBox box(ID, x0, y0,
z0, 2 * P->At(0), 2 * P->At(1), 2 * P->At(2), RadLength);
719 }
else if (Sname ==
"TRAP") {
720 int np = node->getNumPoints();
721 FairGeoVector vMin = *node->getPoint(0), vMax = vMin;
722 for (
int i = 0;
i < np;
i++) {
723 FairGeoVector*
v = node->getPoint(
i);
724 for (
int j = 0; j < 3; j++) {
725 if (vMin(j) > (*v)(j))
726 (&vMin.X())[j] = (*
v)(j);
727 if (vMax(j) < (*v)(j))
728 (&vMax.X())[j] = (*
v)(j);
731 FairGeoVector v0 = (vMin + vMax);
733 FairGeoVector dv = vMax - vMin;
735 CbmKFBox box(ID, x0 + v0(0), y0 + v0(1),
z0 + v0(2), dv(0), dv(1), dv(2), RadLength);
739 cout <<
" -E- unknown shape : " << Sname << endl;
740 cout <<
" -E- It does not make sense to go on" << endl;
741 cout <<
" -E- Stop execution here" << endl;
742 Fatal(
"CbmKF::ReadPassive",
"Unknown Shape");
756 if (
fabs(T[5] - z_out) < 1.e-5)
762 if (fMagneticField) {
771 if (!fMagneticField || z_out > 500)
780 if (z_out < zmax && zmax <= T[5])
784 if (T[5] < zmax && zmax < z_out) {
789 while (!err && repeat) {
790 const Double_t max_step = 5.;
792 if (
fabs(T[5] - zz) > max_step)
793 zzz = T[5] + ((zz > T[5]) ? max_step : -max_step);
842 Bool_t downstream = (ilst > ifst);
844 Int_t iend = downstream ? ilst + 1 : ilst - 1;
845 for (Int_t
i = ifst;
i != iend; downstream ? ++
i : --
i) {
846 err = err ||
vMaterial[
i]->Pass(track, downstream, QP0);
853 Bool_t downstream = (ilst > ifst);
855 Int_t istart = downstream ? ifst + 1 : ifst - 1;
856 for (Int_t
i = istart;
i != ilst; downstream ? ++
i : --
i) {
857 err = err ||
vMaterial[
i]->Pass(track, downstream, QP0);
vector< Double_t > dist(vector< Double_t > qp, Double_t mu)
friend F32vec4 fabs(const F32vec4 &a)
Double_t GetPositionZ() const
TObjArray * GetGeoSensitiveNodes()
TObjArray * GetGeoPassiveNodes()
TObjArray * GetGeoSensitiveNodes()
static Int_t ExtrapolateRK4(const Double_t T_in[], const Double_t C_in[], Double_t T_out[], Double_t C_out[], Double_t z_out, Double_t qp0, FairField *MF)
static void ExtrapolateLine(const Double_t T_in[], const Double_t C_in[], Double_t T_out[], Double_t C_out[], Double_t z_out)
static Int_t ExtrapolateALight(const Double_t T_in[], const Double_t C_in[], Double_t T_out[], Double_t C_out[], Double_t z_out, Double_t qp0, FairField *MF)
virtual TString Info() const
static Bool_t comparePDown(const CbmKFMaterial *a, const CbmKFMaterial *b)
Int_t Propagate(Double_t *T, Double_t *C, Double_t z_out, Double_t QP0, Bool_t line=false)
std::vector< CbmKFTube > vPassiveTube
std::vector< CbmKFMaterial * > vMaterial
std::map< Int_t, Int_t > MvdStationIDMap
Int_t PassMaterialBetween(CbmKFTrackInterface &track, Double_t &QP0, Int_t ifst, Int_t ilst)
std::vector< CbmKFWall > vPassiveWall
std::vector< CbmKFWall > vSttMaterial
std::vector< CbmKFTube > vTargets
std::vector< CbmKFCone > vPipe
std::map< Int_t, Int_t > StsStationIDMap
std::map< Int_t, Int_t > SttStationIDMap
Int_t GetMaterialIndex(Int_t uid)
std::vector< CbmKFBox > vPassiveBox
std::vector< CbmKFTube > vStsMaterial
CbmKF(const char *name="KF", Int_t iVerbose=1)
CbmStsDigiScheme * StsDigi
Int_t PassMaterial(CbmKFTrackInterface &track, Double_t &QP0, Int_t ifst, Int_t ilst)
std::vector< CbmKFTube > vMvdMaterial
TObjArray * GetGeoSensitiveNodes()
static CbmStsDigiScheme * Instance(int version=1)
CbmStsStation * GetStation(Int_t iStation)
Double_t GetRadLength() const
Double_t GetZ(Int_t it=0)
Int_t GetStationNr() const
TObjArray * GetGeoPassiveNodes()