From 0ebf91b99e23e8d481a39456d084a8c7db546939 Mon Sep 17 00:00:00 2001 From: Javier Galan Date: Wed, 14 Feb 2024 21:16:16 +0100 Subject: [PATCH 1/8] TRestAxionField. Disabling GSL error handler and fixing a bug --- src/TRestAxionField.cxx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/TRestAxionField.cxx b/src/TRestAxionField.cxx index a0706be4..e6964c73 100644 --- a/src/TRestAxionField.cxx +++ b/src/TRestAxionField.cxx @@ -210,6 +210,8 @@ #include #include + +#include #include #include @@ -482,6 +484,8 @@ std::pair TRestAxionField::GammaTransmissionFieldMapProbabil Double_t accuracy, Int_t num_intervals, Int_t qawo_levels) { + gsl_set_error_handler_off(); + if (!fMagneticField) { RESTError << "TRestAxionField::GammaTransmissionFieldMapProbability requires a magnetic field map!" << RESTendl; @@ -489,6 +493,9 @@ std::pair TRestAxionField::GammaTransmissionFieldMapProbabil return {0.0, 0.0}; } + if( fMagneticField->GetTrackLength() <= 0 ) + return {0.0, 0.0}; + double photonMass = 0; // Vacuum if (fBufferGas) photonMass = fBufferGas->GetPhotonMass(Ea); From 27f1d82346be6841a75d6e5a79ca8e582132ed96 Mon Sep 17 00:00:00 2001 From: Javier Galan Date: Wed, 14 Feb 2024 21:10:40 +0100 Subject: [PATCH 2/8] REST_Axion_FieldIntegrationTests.C updating to newest field map --- macros/REST_Axion_FieldIntegrationTests.C | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/macros/REST_Axion_FieldIntegrationTests.C b/macros/REST_Axion_FieldIntegrationTests.C index 6f3788e2..bd2e392e 100644 --- a/macros/REST_Axion_FieldIntegrationTests.C +++ b/macros/REST_Axion_FieldIntegrationTests.C @@ -21,7 +21,7 @@ int REST_Axion_FieldIntegrationTests(Double_t sX = 10, Double_t sY = 10, Double_t sZ = 50, Double_t dm = 0.01, Double_t tolerance = 0.1, Double_t Ea = 4.2) { /// Setting up magnetic field and track to evaluate - TRestAxionMagneticField magneticField("fields.rml", "babyIAXO_HD"); + TRestAxionMagneticField magneticField("fields.rml", "babyIAXO_2024"); for (size_t n = 0; n < magneticField.GetNumberOfVolumes(); n++) magneticField.ReMap(n, TVector3(sX, sY, sZ)); From 1eef1a78b1c7d50933d9f2d4e99582dbf099e4e3 Mon Sep 17 00:00:00 2001 From: Javier Galan Date: Wed, 14 Feb 2024 21:21:41 +0100 Subject: [PATCH 3/8] TRestAxionMagneticField::SetTrack. Adding exit condition when fTrackLenght is zero --- src/TRestAxionMagneticField.cxx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/TRestAxionMagneticField.cxx b/src/TRestAxionMagneticField.cxx index 763819de..66dcedf1 100644 --- a/src/TRestAxionMagneticField.cxx +++ b/src/TRestAxionMagneticField.cxx @@ -1225,6 +1225,7 @@ void TRestAxionMagneticField::SetTrack(const TVector3& position, const TVector3& fTrackStart = TVector3(0, 0, 0); fTrackDirection = TVector3(0, 0, 0); fTrackLength = 0; + return; } fTrackStart = trackBounds[0]; From 18f5bc8cf5b4a577c0ac2d47273ab1a77ccc7bc0 Mon Sep 17 00:00:00 2001 From: Javier Galan Date: Wed, 14 Feb 2024 21:34:50 +0100 Subject: [PATCH 4/8] TRestAxionField. In case of issues with field integration we return the status --- src/TRestAxionField.cxx | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/TRestAxionField.cxx b/src/TRestAxionField.cxx index e6964c73..a3ee7a76 100644 --- a/src/TRestAxionField.cxx +++ b/src/TRestAxionField.cxx @@ -562,9 +562,12 @@ std::pair TRestAxionField::ComputeResonanceIntegral(Double_t auto start = std::chrono::system_clock::now(); - gsl_integration_qag(&F, 0, fMagneticField->GetTrackLength(), accuracy, accuracy, num_intervals, + int status = gsl_integration_qag(&F, 0, fMagneticField->GetTrackLength(), accuracy, accuracy, num_intervals, GSL_INTEG_GAUSS61, workspace, &reprob, &rerr); + if( status > 0 ) + return {0,status}; + auto end = std::chrono::system_clock::now(); auto seconds = std::chrono::duration_cast(end - start); @@ -625,12 +628,20 @@ std::pair TRestAxionField::ComputeOffResonanceIntegral(Doubl gsl_integration_qawo_table* wf = gsl_integration_qawo_table_alloc(q, fMagneticField->GetTrackLength(), GSL_INTEG_COSINE, qawo_levels); - gsl_integration_qawo(&F, 0, accuracy, accuracy, num_intervals, workspace, wf, &reprob, &rerr); + int status = gsl_integration_qawo(&F, 0, accuracy, accuracy, num_intervals, workspace, wf, &reprob, &rerr); + if( status > 0 ) + { + gsl_integration_qawo_table_free(wf); + return {0,status}; + } gsl_integration_qawo_table_set(wf, q, fMagneticField->GetTrackLength(), GSL_INTEG_SINE); - gsl_integration_qawo(&F, 0, accuracy, accuracy, num_intervals, workspace, wf, &improb, &imerr); - - gsl_integration_qawo_table_free(wf); + int status = gsl_integration_qawo(&F, 0, accuracy, accuracy, num_intervals, workspace, wf, &improb, &imerr); + if( status > 0 ) + { + gsl_integration_qawo_table_free(wf); + return {0,status}; + } auto end = std::chrono::system_clock::now(); auto seconds = std::chrono::duration_cast(end - start); From d8e37938c0d25faa2da1d02e87a40fbf2f0e9436 Mon Sep 17 00:00:00 2001 From: Javier Galan Date: Wed, 13 Mar 2024 12:39:32 +0100 Subject: [PATCH 5/8] TRestAxionField. Fixing compilation error --- src/TRestAxionField.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TRestAxionField.cxx b/src/TRestAxionField.cxx index a3ee7a76..47bdbabe 100644 --- a/src/TRestAxionField.cxx +++ b/src/TRestAxionField.cxx @@ -636,7 +636,7 @@ std::pair TRestAxionField::ComputeOffResonanceIntegral(Doubl } gsl_integration_qawo_table_set(wf, q, fMagneticField->GetTrackLength(), GSL_INTEG_SINE); - int status = gsl_integration_qawo(&F, 0, accuracy, accuracy, num_intervals, workspace, wf, &improb, &imerr); + status = gsl_integration_qawo(&F, 0, accuracy, accuracy, num_intervals, workspace, wf, &improb, &imerr); if( status > 0 ) { gsl_integration_qawo_table_free(wf); From 55bb5714e9b58efdce862cc9eae3cfdb9a1cdfc1 Mon Sep 17 00:00:00 2001 From: Javier Galan Date: Fri, 29 Mar 2024 12:48:26 +0100 Subject: [PATCH 6/8] TRestAxionMagneticField::GetComponentAlongPath method added --- inc/TRestAxionMagneticField.h | 5 ++ src/TRestAxionMagneticField.cxx | 106 ++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+) diff --git a/inc/TRestAxionMagneticField.h b/inc/TRestAxionMagneticField.h index bc33354f..77655c0d 100644 --- a/inc/TRestAxionMagneticField.h +++ b/inc/TRestAxionMagneticField.h @@ -161,6 +161,9 @@ class TRestAxionMagneticField : public TRestMetadata { std::vector GetTransversalComponentAlongPath(TVector3 from, TVector3 to, Double_t dl = 1., Int_t Nmax = 0); + std::vector GetComponentAlongPath( Int_t axis, TVector3 from, TVector3 to, Double_t dl = 1., + Int_t Nmax = 0); + Double_t GetTransversalFieldAverage(TVector3 from, TVector3 to, Double_t dl = 1., Int_t Nmax = 0); TVector3 GetFieldAverageTransverseVector(TVector3 from, TVector3 to, Double_t dl = 10., Int_t Nmax = 0); @@ -170,6 +173,8 @@ class TRestAxionMagneticField : public TRestMetadata { TCanvas* DrawTracks(TVector3 vanishingPoint, Int_t divisions, Int_t volId = 0); + TCanvas* DrawComponents(Int_t volId = 0); + void PrintMetadata(); TRestAxionMagneticField(); diff --git a/src/TRestAxionMagneticField.cxx b/src/TRestAxionMagneticField.cxx index 66dcedf1..3cdd40ac 100644 --- a/src/TRestAxionMagneticField.cxx +++ b/src/TRestAxionMagneticField.cxx @@ -584,6 +584,65 @@ TCanvas* TRestAxionMagneticField::DrawHistogram(TString projection, TString Bcom return fCanvas; } +/////////////////////////////////////////////// +/// \brief A method that creates a canvas where tracks traversing the magnetic volume +/// are drawm together with their corresponding field intensity profile along the Z-axis. +/// +TCanvas* TRestAxionMagneticField::DrawComponents(Int_t volId) { + Int_t divisions = 100; + if (fCanvas != NULL) { + delete fCanvas; + fCanvas = NULL; + } + fCanvas = new TCanvas("fCanvas", "", 1600, 600); + + TPad* pad1 = new TPad("pad1", "This is pad1", 0.01, 0.02, 0.99, 0.97); + // pad1->Divide(2, 1); + pad1->Draw(); + pad1->cd(); + + Int_t n = 0; + Double_t genPositionZ = fPositions[volId][2] - fBoundMax[volId].Z() - 2000; + Double_t finalPositionZ = fPositions[volId][2] + fBoundMax[volId].Z() + 2000; + TVector3 position(0, 0, genPositionZ); + TVector3 direction (0,0,1); + + RESTDebug << RESTendl; + RESTDebug << "Start moving along" << RESTendl; + RESTDebug << "++++++++++++++++++" << RESTendl; + + TGraph* fieldGr = new TGraph(); + Double_t posZ = fPositions[volId][2] - fBoundMax[volId].Z() - 10; + Double_t delta = fBoundMax[volId][2] * 2. / divisions; + + while (posZ <= fPositions[volId][2] + fBoundMax[volId].Z()) { + TVector3 posAlongAxis = TVector3(fPositions[volId][0], fPositions[volId][1], posZ); + + position = MoveToPlane(position, direction, TVector3(0, 0, 1), posAlongAxis); + Double_t fieldY = this->GetMagneticField(position).Y(); + + fieldGr->SetPoint(fieldGr->GetN(), posZ, fieldY); + + posZ += delta; + } + + fieldGr->SetLineWidth(3); + fieldGr->SetLineColor(38 + n); + fieldGr->GetXaxis()->SetLimits(genPositionZ - 500, finalPositionZ + 500); + fieldGr->GetHistogram()->SetMaximum(2.5); + fieldGr->GetHistogram()->SetMinimum(0); + fieldGr->GetXaxis()->SetTitle("Z [mm]"); + fieldGr->GetXaxis()->SetTitleSize(0.05); + fieldGr->GetXaxis()->SetLabelSize(0.05); + fieldGr->GetYaxis()->SetTitle("B [T]"); + fieldGr->GetYaxis()->SetTitleOffset(1.3); + fieldGr->GetYaxis()->SetTitleSize(0.05); + fieldGr->GetYaxis()->SetLabelSize(0.05); + fieldGr->Draw("AL"); + + return fCanvas; +} + /////////////////////////////////////////////// /// \brief A method that creates a canvas where tracks traversing the magnetic volume /// are drawm together with their corresponding field intensity profile along the Z-axis. @@ -1214,6 +1273,53 @@ std::vector TRestAxionMagneticField::GetTransversalComponentAlongPath( return Bt; } +/////////////////////////////////////////////// +/// \brief It returns a vector describing the magnetic field profile component requested using the `axis` +/// argument which may take values 0,1,2 for X,Y,Z components. The field profile will be constructed in the +/// track defined between `from` and `to` positions given by argument. +/// +/// The differential element `dl` is by default 1mm, but it can be modified through the third argument of +/// this function. +/// +/// The maximum number of divisions (unlimited by default) of the output vector can be fixed by the forth +/// argument. In that case, the differential element `dl` length might be increased to fullfil such +/// condition. +/// +std::vector TRestAxionMagneticField::GetComponentAlongPath(Int_t axis, TVector3 from, TVector3 to, + Double_t dl, Int_t Nmax) { + std::vector Bt; + if( axis != 0 && axis != 1 && axis != 2 ) + { + RESTError << "TRestAxionMagneticField::GetComponentAlongPath. Axis must take values 0,1 or 2" << RESTendl; + return Bt; + } + Double_t length = (to - from).Mag(); + + Double_t diff = dl; + if (Nmax > 0) { + if (length / dl > Nmax) { + diff = length / Nmax; + RESTWarning << "TRestAxionMagneticField::GetComponentAlongPath. Nmax reached!" + << RESTendl; + RESTWarning << "Nmax = " << Nmax << RESTendl; + RESTWarning << "Adjusting differential step to : " << diff << " mm" << RESTendl; + } + } + + TVector3 direction = (to - from).Unit(); + + for (Double_t d = 0; d < length; d += diff) { + if( axis == 0 ) + Bt.push_back(GetMagneticField(from + d * direction).X()); + if( axis == 1 ) + Bt.push_back(GetMagneticField(from + d * direction).Y()); + if( axis == 2 ) + Bt.push_back(GetMagneticField(from + d * direction).Z()); + } + + return Bt; +} + /////////////////////////////////////////////// /// \brief It initializes the field track boundaries data members of this class using a /// track position and direction so that these values can be used later on in parameterization. From 74793f3c6c9818069104ed71a1aa427b4b9dd6a5 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 3 May 2024 12:46:11 +0000 Subject: [PATCH 7/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- inc/TRestAxionMagneticField.h | 4 +- src/TRestAxionField.cxx | 34 +++++------ src/TRestAxionMagneticField.cxx | 102 +++++++++++++++----------------- 3 files changed, 66 insertions(+), 74 deletions(-) diff --git a/inc/TRestAxionMagneticField.h b/inc/TRestAxionMagneticField.h index 77655c0d..b56720dc 100644 --- a/inc/TRestAxionMagneticField.h +++ b/inc/TRestAxionMagneticField.h @@ -161,8 +161,8 @@ class TRestAxionMagneticField : public TRestMetadata { std::vector GetTransversalComponentAlongPath(TVector3 from, TVector3 to, Double_t dl = 1., Int_t Nmax = 0); - std::vector GetComponentAlongPath( Int_t axis, TVector3 from, TVector3 to, Double_t dl = 1., - Int_t Nmax = 0); + std::vector GetComponentAlongPath(Int_t axis, TVector3 from, TVector3 to, Double_t dl = 1., + Int_t Nmax = 0); Double_t GetTransversalFieldAverage(TVector3 from, TVector3 to, Double_t dl = 1., Int_t Nmax = 0); diff --git a/src/TRestAxionField.cxx b/src/TRestAxionField.cxx index 47bdbabe..a7163735 100644 --- a/src/TRestAxionField.cxx +++ b/src/TRestAxionField.cxx @@ -210,7 +210,6 @@ #include #include - #include #include @@ -484,7 +483,7 @@ std::pair TRestAxionField::GammaTransmissionFieldMapProbabil Double_t accuracy, Int_t num_intervals, Int_t qawo_levels) { - gsl_set_error_handler_off(); + gsl_set_error_handler_off(); if (!fMagneticField) { RESTError << "TRestAxionField::GammaTransmissionFieldMapProbability requires a magnetic field map!" @@ -493,8 +492,7 @@ std::pair TRestAxionField::GammaTransmissionFieldMapProbabil return {0.0, 0.0}; } - if( fMagneticField->GetTrackLength() <= 0 ) - return {0.0, 0.0}; + if (fMagneticField->GetTrackLength() <= 0) return {0.0, 0.0}; double photonMass = 0; // Vacuum if (fBufferGas) photonMass = fBufferGas->GetPhotonMass(Ea); @@ -562,11 +560,10 @@ std::pair TRestAxionField::ComputeResonanceIntegral(Double_t auto start = std::chrono::system_clock::now(); - int status = gsl_integration_qag(&F, 0, fMagneticField->GetTrackLength(), accuracy, accuracy, num_intervals, - GSL_INTEG_GAUSS61, workspace, &reprob, &rerr); + int status = gsl_integration_qag(&F, 0, fMagneticField->GetTrackLength(), accuracy, accuracy, + num_intervals, GSL_INTEG_GAUSS61, workspace, &reprob, &rerr); - if( status > 0 ) - return {0,status}; + if (status > 0) return {0, status}; auto end = std::chrono::system_clock::now(); auto seconds = std::chrono::duration_cast(end - start); @@ -628,20 +625,19 @@ std::pair TRestAxionField::ComputeOffResonanceIntegral(Doubl gsl_integration_qawo_table* wf = gsl_integration_qawo_table_alloc(q, fMagneticField->GetTrackLength(), GSL_INTEG_COSINE, qawo_levels); - int status = gsl_integration_qawo(&F, 0, accuracy, accuracy, num_intervals, workspace, wf, &reprob, &rerr); - if( status > 0 ) - { - gsl_integration_qawo_table_free(wf); - return {0,status}; - } + int status = + gsl_integration_qawo(&F, 0, accuracy, accuracy, num_intervals, workspace, wf, &reprob, &rerr); + if (status > 0) { + gsl_integration_qawo_table_free(wf); + return {0, status}; + } gsl_integration_qawo_table_set(wf, q, fMagneticField->GetTrackLength(), GSL_INTEG_SINE); status = gsl_integration_qawo(&F, 0, accuracy, accuracy, num_intervals, workspace, wf, &improb, &imerr); - if( status > 0 ) - { - gsl_integration_qawo_table_free(wf); - return {0,status}; - } + if (status > 0) { + gsl_integration_qawo_table_free(wf); + return {0, status}; + } auto end = std::chrono::system_clock::now(); auto seconds = std::chrono::duration_cast(end - start); diff --git a/src/TRestAxionMagneticField.cxx b/src/TRestAxionMagneticField.cxx index 3cdd40ac..459571e0 100644 --- a/src/TRestAxionMagneticField.cxx +++ b/src/TRestAxionMagneticField.cxx @@ -589,7 +589,7 @@ TCanvas* TRestAxionMagneticField::DrawHistogram(TString projection, TString Bcom /// are drawm together with their corresponding field intensity profile along the Z-axis. /// TCanvas* TRestAxionMagneticField::DrawComponents(Int_t volId) { - Int_t divisions = 100; + Int_t divisions = 100; if (fCanvas != NULL) { delete fCanvas; fCanvas = NULL; @@ -597,48 +597,48 @@ TCanvas* TRestAxionMagneticField::DrawComponents(Int_t volId) { fCanvas = new TCanvas("fCanvas", "", 1600, 600); TPad* pad1 = new TPad("pad1", "This is pad1", 0.01, 0.02, 0.99, 0.97); - // pad1->Divide(2, 1); + // pad1->Divide(2, 1); pad1->Draw(); pad1->cd(); - Int_t n = 0; + Int_t n = 0; Double_t genPositionZ = fPositions[volId][2] - fBoundMax[volId].Z() - 2000; Double_t finalPositionZ = fPositions[volId][2] + fBoundMax[volId].Z() + 2000; - TVector3 position(0, 0, genPositionZ); - TVector3 direction (0,0,1); - - RESTDebug << RESTendl; - RESTDebug << "Start moving along" << RESTendl; - RESTDebug << "++++++++++++++++++" << RESTendl; - - TGraph* fieldGr = new TGraph(); - Double_t posZ = fPositions[volId][2] - fBoundMax[volId].Z() - 10; - Double_t delta = fBoundMax[volId][2] * 2. / divisions; - - while (posZ <= fPositions[volId][2] + fBoundMax[volId].Z()) { - TVector3 posAlongAxis = TVector3(fPositions[volId][0], fPositions[volId][1], posZ); - - position = MoveToPlane(position, direction, TVector3(0, 0, 1), posAlongAxis); - Double_t fieldY = this->GetMagneticField(position).Y(); - - fieldGr->SetPoint(fieldGr->GetN(), posZ, fieldY); - - posZ += delta; - } - - fieldGr->SetLineWidth(3); - fieldGr->SetLineColor(38 + n); - fieldGr->GetXaxis()->SetLimits(genPositionZ - 500, finalPositionZ + 500); - fieldGr->GetHistogram()->SetMaximum(2.5); - fieldGr->GetHistogram()->SetMinimum(0); - fieldGr->GetXaxis()->SetTitle("Z [mm]"); - fieldGr->GetXaxis()->SetTitleSize(0.05); - fieldGr->GetXaxis()->SetLabelSize(0.05); - fieldGr->GetYaxis()->SetTitle("B [T]"); - fieldGr->GetYaxis()->SetTitleOffset(1.3); - fieldGr->GetYaxis()->SetTitleSize(0.05); - fieldGr->GetYaxis()->SetLabelSize(0.05); - fieldGr->Draw("AL"); + TVector3 position(0, 0, genPositionZ); + TVector3 direction(0, 0, 1); + + RESTDebug << RESTendl; + RESTDebug << "Start moving along" << RESTendl; + RESTDebug << "++++++++++++++++++" << RESTendl; + + TGraph* fieldGr = new TGraph(); + Double_t posZ = fPositions[volId][2] - fBoundMax[volId].Z() - 10; + Double_t delta = fBoundMax[volId][2] * 2. / divisions; + + while (posZ <= fPositions[volId][2] + fBoundMax[volId].Z()) { + TVector3 posAlongAxis = TVector3(fPositions[volId][0], fPositions[volId][1], posZ); + + position = MoveToPlane(position, direction, TVector3(0, 0, 1), posAlongAxis); + Double_t fieldY = this->GetMagneticField(position).Y(); + + fieldGr->SetPoint(fieldGr->GetN(), posZ, fieldY); + + posZ += delta; + } + + fieldGr->SetLineWidth(3); + fieldGr->SetLineColor(38 + n); + fieldGr->GetXaxis()->SetLimits(genPositionZ - 500, finalPositionZ + 500); + fieldGr->GetHistogram()->SetMaximum(2.5); + fieldGr->GetHistogram()->SetMinimum(0); + fieldGr->GetXaxis()->SetTitle("Z [mm]"); + fieldGr->GetXaxis()->SetTitleSize(0.05); + fieldGr->GetXaxis()->SetLabelSize(0.05); + fieldGr->GetYaxis()->SetTitle("B [T]"); + fieldGr->GetYaxis()->SetTitleOffset(1.3); + fieldGr->GetYaxis()->SetTitleSize(0.05); + fieldGr->GetYaxis()->SetLabelSize(0.05); + fieldGr->Draw("AL"); return fCanvas; } @@ -1286,21 +1286,20 @@ std::vector TRestAxionMagneticField::GetTransversalComponentAlongPath( /// condition. /// std::vector TRestAxionMagneticField::GetComponentAlongPath(Int_t axis, TVector3 from, TVector3 to, - Double_t dl, Int_t Nmax) { + Double_t dl, Int_t Nmax) { std::vector Bt; - if( axis != 0 && axis != 1 && axis != 2 ) - { - RESTError << "TRestAxionMagneticField::GetComponentAlongPath. Axis must take values 0,1 or 2" << RESTendl; - return Bt; - } + if (axis != 0 && axis != 1 && axis != 2) { + RESTError << "TRestAxionMagneticField::GetComponentAlongPath. Axis must take values 0,1 or 2" + << RESTendl; + return Bt; + } Double_t length = (to - from).Mag(); Double_t diff = dl; if (Nmax > 0) { if (length / dl > Nmax) { diff = length / Nmax; - RESTWarning << "TRestAxionMagneticField::GetComponentAlongPath. Nmax reached!" - << RESTendl; + RESTWarning << "TRestAxionMagneticField::GetComponentAlongPath. Nmax reached!" << RESTendl; RESTWarning << "Nmax = " << Nmax << RESTendl; RESTWarning << "Adjusting differential step to : " << diff << " mm" << RESTendl; } @@ -1309,12 +1308,9 @@ std::vector TRestAxionMagneticField::GetComponentAlongPath(Int_t axis, TVector3 direction = (to - from).Unit(); for (Double_t d = 0; d < length; d += diff) { - if( axis == 0 ) - Bt.push_back(GetMagneticField(from + d * direction).X()); - if( axis == 1 ) - Bt.push_back(GetMagneticField(from + d * direction).Y()); - if( axis == 2 ) - Bt.push_back(GetMagneticField(from + d * direction).Z()); + if (axis == 0) Bt.push_back(GetMagneticField(from + d * direction).X()); + if (axis == 1) Bt.push_back(GetMagneticField(from + d * direction).Y()); + if (axis == 2) Bt.push_back(GetMagneticField(from + d * direction).Z()); } return Bt; @@ -1331,7 +1327,7 @@ void TRestAxionMagneticField::SetTrack(const TVector3& position, const TVector3& fTrackStart = TVector3(0, 0, 0); fTrackDirection = TVector3(0, 0, 0); fTrackLength = 0; - return; + return; } fTrackStart = trackBounds[0]; From e6b815b157ef44e16176c2dc0d869390657467bd Mon Sep 17 00:00:00 2001 From: Javier Galan Date: Fri, 3 May 2024 15:10:29 +0200 Subject: [PATCH 8/8] TRestAxionMagneticField. Major oversight on data not passed by reference --- inc/TRestAxionMagneticField.h | 2 +- src/TRestAxionMagneticField.cxx | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/inc/TRestAxionMagneticField.h b/inc/TRestAxionMagneticField.h index b56720dc..b2dd1e54 100644 --- a/inc/TRestAxionMagneticField.h +++ b/inc/TRestAxionMagneticField.h @@ -95,7 +95,7 @@ class TRestAxionMagneticField : public TRestMetadata { void LoadMagneticFieldData(MagneticFieldVolume& mVol, std::vector> data); - TVector3 GetMagneticVolumeNode(MagneticFieldVolume mVol, TVector3 pos); + TVector3 GetMagneticVolumeNode(size_t id, TVector3 pos); /// \brief This private method returns true if the magnetic field volumes loaded are the same as /// the volumes defined. diff --git a/src/TRestAxionMagneticField.cxx b/src/TRestAxionMagneticField.cxx index 459571e0..4f15d0f4 100644 --- a/src/TRestAxionMagneticField.cxx +++ b/src/TRestAxionMagneticField.cxx @@ -1025,7 +1025,7 @@ TVector3 TRestAxionMagneticField::GetMagneticField(TVector3 pos, Bool_t showWarn return TVector3(0, 0, 0); } else { if (IsFieldConstant(id)) return fConstantField[id]; - TVector3 node = GetMagneticVolumeNode(fMagneticFieldVolumes[id], pos); + TVector3 node = GetMagneticVolumeNode((size_t)id, pos); Int_t nX = node.X(); Int_t nY = node.Y(); Int_t nZ = node.Z(); @@ -1430,10 +1430,10 @@ TVector3 TRestAxionMagneticField::GetFieldAverageTransverseVector(TVector3 from, /// /// This method will be made private, no reason to use it outside this class. /// -TVector3 TRestAxionMagneticField::GetMagneticVolumeNode(MagneticFieldVolume mVol, TVector3 pos) { - Int_t nx = mVol.mesh.GetNodeX(pos.X()); - Int_t ny = mVol.mesh.GetNodeY(pos.Y()); - Int_t nz = mVol.mesh.GetNodeZ(pos.Z()); +TVector3 TRestAxionMagneticField::GetMagneticVolumeNode(size_t id, TVector3 pos) { + Int_t nx = fMagneticFieldVolumes[id].mesh.GetNodeX(pos.X()); + Int_t ny = fMagneticFieldVolumes[id].mesh.GetNodeY(pos.Y()); + Int_t nz = fMagneticFieldVolumes[id].mesh.GetNodeZ(pos.Z()); return TVector3(nx, ny, nz); }