9#include "BmnEventHeader.h"
10#include "BmnFieldMap.h"
11#include "BmnGemStripHit.h"
24const std::vector<std::string>
PARTICLES = {
"pi",
"K",
"p",
"d",
"t",
"He3"};
25const std::vector<std::string>
ZONES = {
"clean",
"overlap",
"accepted"};
58 cout <<
"BmnGlobalTracking::Init started\n";
62 FairRootManager* ioman = FairRootManager::Instance();
64 Fatal(
"Init",
"FairRootManager is not instantiated");
80 printf(
"BmnGlobalTracking::Init(): branch with inner tracks was not found! Task will be deactivated \n");
86 TString workdir = getenv(
"VMCWORKDIR");
93 cout <<
"BmnGlobalTracking::Init finished\n";
109 cout <<
"\n======================== Global tracking exec started =====================\n" << endl;
133 Int_t pdg = (globTr.
GetP() > 0) ? 2212 : -211;
153 fKalman->Update(&parF, &virtualVertexHit, chi);
169 cout <<
"\n======================== Global tracking exec finished ====================\n" << endl;
174 Int_t tofID = (tof400) ? 1 : 2;
175 TString tofName = (tof400) ?
"TOF-400" :
"TOF-700";
177 cout <<
"Matching of " << tofName <<
" started" << endl;
187 for (
auto const& distPair : distPairs) {
189 pair<Int_t, Int_t> idxes = distPair.second;
207 Int_t pdg = (track->
GetP() > 0) ? 2212 : -211;
208 fKalman->TGeoTrackPropagate(&par, hit->GetZ(), pdg,
nullptr, &len);
216 Int_t chamber = ((hit->GetDetectorID() & 0x0000FF00) >> 8) - 1;
223 Float_t xDist = xExtr_stage2 - hit->GetX();
224 Float_t yDist = yExtr_stage2 - hit->GetY();
225 bool isWithinSigma = (
Abs(xDist) < 3 * sigmaX_stage2) && (
Abs(yDist) < 3 * sigmaY_stage2);
236 std::string zone =
"accepted";
244 xDist = xExtr_stage2 + xCorr_stage3 - hit->GetX();
245 yDist = yExtr_stage2 + yCorr_stage3 - hit->GetY();
246 isWithinSigma = (
Abs(xDist) < 3 * sigmaX_stage3) && (
Abs(yDist) < 3 * sigmaY_stage3);
264 cout <<
"Matching of ScWall started " <<
fScWall << endl;
279 Int_t pdg = (tr->
GetP() > 0) ? 2212 : -211;
281 if (
fKalman->TGeoTrackPropagate(&par, z, pdg,
nullptr,
nullptr) ==
kBMNERROR)
284 for (
Int_t i = 1;
i <= nCells; ++
i) {
289 Float_t dX = par.GetX() - cell->GetX();
290 Float_t dY = par.GetY() - cell->GetY();
292 if (
Abs(dX) < xCut &&
Abs(dY) < yCut &&
Abs(dX) <
Abs(minDX) &&
Abs(dY) <
Abs(minDY)) {
311 cout <<
"Matching of Ndet started " <<
fNdet << endl;
314 auto* cells =
fNdet->GetCells();
315 if (cells->GetEntriesFast() == 0)
322 for (
int ice = 0, nce = cells->GetEntriesFast(); ice < nce; ++ice) {
323 auto* cell =
static_cast<BmnNdetCell*
>(cells->At(ice));
326 Int_t pdg = (tr->
GetP() > 0) ? 2212 : -211;
328 if (
fKalman->TGeoTrackPropagate(&par, cell->GetZ(), pdg,
nullptr,
nullptr) ==
kBMNERROR)
331 Float_t dX = par.GetX() - cell->GetX();
332 Float_t dY = par.GetY() - cell->GetY();
334 if (
Abs(dX) < 5 * cell->GetDx() &&
Abs(dY) < 5 * cell->GetDy()) {
348 map<Float_t, pair<Int_t, Int_t>> distancesPairs;
353 if (hit->GetZ() < minZ)
360 Int_t pdg = (tr->
GetP() > 0) ? 2212 : -211;
361 if (
fKalman->TGeoTrackPropagate(&parMinZ, minZ, pdg,
nullptr,
nullptr) ==
kBMNERROR)
366 FairTrackParam param = parMinZ;
367 if (
fKalman->TGeoTrackPropagate(¶m, hit->GetZ(), pdg,
nullptr,
nullptr) ==
kBMNERROR)
369 Float_t mom = 1.0 / param.GetQp();
370 Int_t chamber = ((hit->GetDetectorID() & 0x0000FF00) >> 8) - 1;
374 Float_t dX = param.GetX() + xMomCorr - hit->GetX();
375 Float_t dY = param.GetY() + yMomCorr - hit->GetY();
378 distancesPairs.insert(pair<
Float_t, pair<Int_t, Int_t>>(
dist, pair<Int_t, Int_t>(trIdx, hitIdx)));
382 return distancesPairs;
388 Int_t pdg = (par.GetQp() > 0) ? 2212 : -211;
389 fKalman->TGeoTrackPropagate(&par, -200, pdg,
nullptr,
nullptr);
393 fKalman->TGeoTrackPropagate(&par, 600, pdg,
nullptr,
nullptr);
402 if (!
IsNaN(momInt) &&
Abs(momInt) > 0.01 &&
Abs(momInt) < 100) {
413 printf(
"Work time of BmnGlobalTracking: %4.2f sec.\n",
fTime);
423 Int_t pdg = (par.GetQp() > 0.) ? 2212 : -211;
424 FairField* field = FairRunAna::Instance()->GetField();
425 fKalman->TGeoTrackPropagate(&par, zMin, pdg, NULL, NULL,
kTRUE);
430 fKalman->TGeoTrackPropagate(&par, z, pdg, NULL, NULL,
kTRUE);
431 integral += field->GetBy(par.GetX(), par.GetY(), par.GetZ());
439 printf(
"================================================================================\n");
440 printf(
"======= Statistics of Global tracking\n");
441 printf(
"======= Number of input inner tracks: %ld\n",
fNInnerTracks);
442 printf(
"======= Number of input inner tracks with 4+ hits extrapolated to the Vertex: %ld (%4.1f%%)\n",
444 printf(
"======= Number of tracks matched with TOF-400: %ld\n",
fNMatchedTof400);
445 printf(
"======= Number of tracks matched with TOF-700: %ld\n",
fNMatchedTof700);
446 printf(
"================================================================================\n");
462 std::cout <<
"\n=== Loading Akima corrections for " << (isTOF400 ?
"TOF400" :
"TOF700") <<
" ===" << std::endl;
463 std::cout <<
"=== File: " << filename <<
" ===" << std::endl;
469 std::cerr <<
"ERROR: Cannot open file: " << filename << std::endl;
485 while ((key = (
TKey*)next())) {
499 while ((key = (
TKey*)next())) {
513 while ((key = (
TKey*)next())) {
527 while ((key = (
TKey*)next())) {
544 while ((key = (
TKey*)next())) {
552 }
else if (name.
Contains(
"sigma")) {
564 while ((key = (
TKey*)next())) {
572 }
else if (name.
Contains(
"sigma")) {
584 while ((key = (
TKey*)next())) {
592 }
else if (name.
Contains(
"sigma")) {
604 while ((key = (
TKey*)next())) {
612 }
else if (name.
Contains(
"sigma")) {
628 for (
const auto& zone :
ZONES) {
629 TString dxDirName =
Form(
"dx_%s_%s_positive", particle.c_str(), zone.c_str());
634 while ((key = (
TKey*)next())) {
643 }
else if (name.
Contains(
"sigma")) {
651 TString dyDirName =
Form(
"dy_%s_%s_positive", particle.c_str(), zone.c_str());
656 while ((key = (
TKey*)next())) {
665 }
else if (name.
Contains(
"sigma")) {
678 std::cout <<
"Loaded " << cont.
loaded_count <<
" AkimaFunction objects for " << (isTOF400 ?
"TOF400" :
"TOF700")
697 if (stage ==
"stage1") {
699 if (region ==
"negative") {
702 return -it->second->Eval(qp);
705 return -it->second->Eval(-qp);
709 return -it->second->Eval(qp);
712 if (region ==
"negative") {
715 return -it->second->Eval(qp);
718 return -it_pos->second->Eval(-qp);
722 return -it->second->Eval(qp);
725 }
else if (stage ==
"stage2") {
727 if (region ==
"negative") {
730 return -it->second->Eval(qp);
733 return -it_pos->second->Eval(-qp);
737 return -it->second->Eval(qp);
740 if (region ==
"negative") {
743 return -it->second->Eval(qp);
746 return -it_pos->second->Eval(-qp);
750 return -it->second->Eval(qp);
753 }
else if (stage ==
"stage3") {
756 if (particle ==
"" || zone ==
"")
764 return -it->second->Eval(qp);
768 return -it->second->Eval(qp);
791 if (stage ==
"stage2") {
793 if (region ==
"negative") {
796 Float_t sigma = it->second->Eval(qp);
797 return (sigma > 0) ? sigma : 1.0;
801 Float_t sigma = it_pos->second->Eval(-qp);
802 return (sigma > 0) ? sigma : 1.0;
807 Float_t sigma = it->second->Eval(qp);
808 return (sigma > 0) ? sigma : 1.0;
812 if (region ==
"negative") {
815 Float_t sigma = it->second->Eval(qp);
816 return (sigma > 0) ? sigma : 1.0;
820 Float_t sigma = it_pos->second->Eval(-qp);
821 return (sigma > 0) ? sigma : 1.0;
826 Float_t sigma = it->second->Eval(qp);
827 return (sigma > 0) ? sigma : 1.0;
832 }
else if (stage ==
"stage3") {
834 return GetAkimaSigma(chamber, -qp, isDx,
"stage2", isTOF400,
"",
"");
835 if (particle ==
"" || zone ==
"")
843 Float_t sigma = it->second->Eval(qp);
844 return (sigma > 0) ? sigma : 1.0;
849 Float_t sigma = it->second->Eval(qp);
850 return (sigma > 0) ? sigma : 1.0;
861 return (qp < 0) ?
"negative" :
"positive";
867 if (qp < 0 && qp > -0.5)
869 if (qp > 0 && qp < 0.5)
872 if (qp < 0 && qp > -0.7)
874 if (qp > 0 && qp < 0.7)
const std::vector< std::string > PARTICLES
const std::vector< std::string > ZONES
vector< Double_t > dist(vector< Double_t > qp, Double_t mu)
void Fatal(const char *location, const char *msgfmt,...)
char * Form(const char *fmt,...)
BmnStatus
Define status code.
void SetMass2(Int_t tofID, Float_t m2)
void SetResX(Int_t tofID, Float_t res)
TString GetParticleName(ParticleType type)
void SetNdetHitIndex(Int_t iNdet)
void SetDCAInVertex(Float_t chi)
void SetChi2InVertex(Float_t chi)
void SetGemTrackIndex(Int_t iGem)
Modifiers.
void SetTof2HitIndex(Int_t iTof2Hit)
void SetScWallSignal(Float_t sig)
void SetScWallCellId(Int_t iScWall)
void SetResY(Int_t tofID, Float_t res)
void SetTof1HitIndex(Int_t iTof1Hit)
TClonesArray * fGlobalTracks
BmnGlobalTracking()
Constructor.
Float_t AdjustQP(Float_t qp, Bool_t isTOF400=false)
map< Float_t, pair< Int_t, Int_t > > FindPairsTof(TClonesArray *tracks, TClonesArray *hits, Bool_t tof400)
TString fInnerTrackBranchName
virtual ~BmnGlobalTracking()
Destructor.
Float_t GetAkimaSigma(Int_t chamber, Float_t qp, Bool_t isDx, const TString &stage, Bool_t isTOF400, const TString &particle="", const TString &zone="")
virtual void Exec(Option_t *opt)
Inherited from FairTask.
std::string GetRegionFromQP(Float_t qp)
virtual void OnlineWrite(const std::unique_ptr< TTree > &resultTree)
Write task resul to tree.
Float_t GetAkimaCorrection(Int_t chamber, Float_t qp, Bool_t isDx, const TString &stage, Bool_t isTOF400, const TString &particle="", const TString &zone="")
BmnStatus MatchingTOF(Bool_t tof400)
virtual InitStatus Init()
Inherited from FairTask.
BmnStatus UpdateMomentum(BmnGlobalTrack *tr)
TClonesArray * fStsTracks
void LoadAllAkimaCorrections(const TString &filename, Bool_t isTOF400)
BmnKalmanFilter * fKalman
vertex information
BmnStatus MatchingScWall()
Double_t MagFieldIntegral(FairTrackParam &par, Double_t zMin, Double_t zMax, Double_t step)
virtual void Finish()
Inherited from FairTask.
void SetLength(Double_t len)
void SetUsing(Bool_t use)
Class for Bmn Ndet data container in event.
Class for Bmn ScWall module data container in event.
float GetSignal() const
Deposited Signal.
Class for Bmn ScWall data container in event.
void SetChi2(Double_t chi2)
Float_t GetLength() const
void SetParamLast(FairTrackParam &par)
FairTrackParam * GetParamFirst()
Int_t GetNHits() const
Accessors.
void SetUsing(Bool_t flag)
void SetParamFirst(FairTrackParam &par)
Modifiers.
FairTrackParam * GetParamLast()
void SetLength(Double_t length)
FairTrackParam * GetParamLast()
Int_t GetNStsHits() const
Accessors.
FairTrackParam * GetParamFirst()
T * Get(const char *namecycle)
virtual TObject * Get(const char *namecycle)
virtual TList * GetListOfKeys() const
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
void Close(Option_t *option="") override
const char * GetName() const override
Int_t GetEntriesFast() const
TObject * At(Int_t idx) const override
R__ALWAYS_INLINE Bool_t IsZombie() const
virtual Bool_t InheritsFrom(const char *classname) const
void Start(Bool_t reset=kTRUE)
const char * Data() const
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
const UShort_t numChambers
double beta(double x, double y)
Double_t Sqrt(Double_t x)
std::map< Stage3Key, AkimaFunction * > dy_stage3_mean
std::map< Int_t, AkimaFunction * > dx_stage1_neg
std::map< Int_t, AkimaFunction * > dy_stage2_sigma_pos
std::map< Int_t, AkimaFunction * > dy_stage2_mean_neg
std::map< Int_t, AkimaFunction * > dy_stage2_mean_pos
std::map< Stage3Key, AkimaFunction * > dx_stage3_mean
std::map< Int_t, AkimaFunction * > dy_stage2_sigma_neg
std::map< Stage3Key, AkimaFunction * > dy_stage3_sigma
std::map< Int_t, AkimaFunction * > dy_stage1_pos
std::map< Int_t, AkimaFunction * > dx_stage2_sigma_pos
std::map< Int_t, AkimaFunction * > dy_stage1_neg
std::map< Int_t, AkimaFunction * > dx_stage2_mean_pos
std::map< Int_t, AkimaFunction * > dx_stage2_sigma_neg
std::map< Int_t, AkimaFunction * > dx_stage2_mean_neg
std::map< Stage3Key, AkimaFunction * > dx_stage3_sigma
std::map< Int_t, AkimaFunction * > dx_stage1_pos