20#include "FairRunAna.h"
21#include "FairRuntimeDb.h"
36#include <boost/assign/list_of.hpp>
43using boost::assign::list_of;
59 , fOutputDir(
"./field/")
60 , fAcceptanceAngleX(25.)
61 , fAcceptanceAngleY(25.)
64 , fUseEllipseAcc(true)
65 , fPolynomDegreeIndex(1)
106 fField = FairRunAna::Instance()->GetField();
145 string names[] = {
"Bx",
"By",
"Bz",
"Mod"};
146 string zTitle[] = {
"B_{x} [kGauss]",
"B_{y} [kGauss]",
"B_{z} [kGauss]",
"|B| [kGauss]"};
147 for (Int_t
v = 0;
v < 4;
v++) {
149 TGraph2D* graph =
new TGraph2D();
151 string title = name +
";X [cm];Y [cm];" + zTitle[
v];
152 graph->SetNameTitle(name.c_str(), title.c_str());
160 string names[] = {
"Bx",
"By",
"Bz",
"Mod"};
164 Int_t nofBinsErrB = 100;
165 Int_t nofBinsRelErrB = 100;
166 Int_t nofBinsErrX = 100;
167 Int_t nofBinsErrY = 100;
168 Double_t minErrB = 0., maxErrB = 0., minRelErrB = 0., maxRelErrB = 0.;
176 string zTitle[] = {
"B_{x} [kGauss]",
"B_{y} [kGauss]",
"B_{z} [kGauss]",
"|B| [kGauss]"};
177 string errTitle[] = {
"B_{x} error [kGauss]",
"B_{y} error [kGauss]",
"B_{z} error [kGauss]",
"|B| error [kGauss]"};
178 string relErrTitle[] = {
"B_{x} relative error [%]",
"B_{y} relative error [%]",
"B_{z} relative error [%]",
179 "|B| relative error [%]"};
182 for (Int_t
v = 0;
v < 4;
v++) {
185 TGraph2D* graph =
new TGraph2D();
188 string title = name +
";X [cm];Y [cm];" + zTitle[
v];
189 graph->SetNameTitle(name.c_str(), title.c_str());
194 title = name +
";" + errTitle[
v] +
";Counter";
195 fHM->
Add(name,
new TH1D(name.c_str(), title.c_str(), nofBinsErrB, minErrB, maxErrB));
199 title = name +
";X [cm];Y [cm];" + errTitle[
v];
205 title = name +
";" + relErrTitle[
v] +
";Counter";
206 fHM->
Add(name,
new TH1D(name.c_str(), title.c_str(), nofBinsRelErrB, minRelErrB, maxRelErrB));
210 title = name +
";X [cm];Y [cm];" + relErrTitle[
v];
216 cout <<
"-I- CbmLitFieldApproximationQa::CreateFitterErrHistos: Field fitter "
217 "error histograms created"
223 string names[] = {
"Bx",
"By",
"Bz",
"Mod"};
227 Int_t nofBinsErrB = 100;
228 Int_t nofBinsRelErrB = 100;
229 Int_t nofBinsErrX = 100;
230 Int_t nofBinsErrY = 100;
231 Double_t minErrB = 0., maxErrB = 0., minRelErrB = 0., maxRelErrB = 0.;
239 string zTitle[] = {
"B_{x} [kGauss]",
"B_{y} [kGauss]",
"B_{z} [kGauss]",
"|B| [kGauss]"};
240 string errTitle[] = {
"B_{x} error [kGauss]",
"B_{y} error [kGauss]",
"B_{z} error [kGauss]",
"|B| error [kGauss]"};
241 string relErrTitle[] = {
"B_{x} relative error [%]",
"B_{y} relative error [%]",
"B_{z} relative error [%]",
242 "|B| relative error [%]"};
245 for (Int_t
v = 0;
v < 4;
v++) {
247 TGraph2D* graph =
new TGraph2D();
249 string title = name +
";X [cm]; Y [cm];" + zTitle[
v];
250 graph->SetNameTitle(name.c_str(), title.c_str());
254 title = name +
";" + errTitle[
v] +
";Counter";
255 fHM->
Add(name,
new TH1D(name.c_str(), title.c_str(), nofBinsErrB, minErrB, maxErrB));
258 title = name +
";X [cm];Y [cm];" + errTitle[
v];
263 title = name +
";" + relErrTitle[
v] +
";Counter";
264 fHM->
Add(name,
new TH1D(name.c_str(), title.c_str(), nofBinsRelErrB, minRelErrB, maxRelErrB));
267 title = name +
";X [cm];Y [cm];" + relErrTitle[
v];
272 cout <<
"-I- CbmLitFieldApproximationQa::CreateGridErrHistos(): Grid creator "
273 "error histograms created"
280 for (Int_t iSlice = 0; iSlice <
fNofSlices; iSlice++) {
286 for (Int_t iX = 0; iX <
fNofBinsX; iX++) {
288 for (Int_t iY = 0; iY <
fNofBinsY; iY++) {
299 Double_t
pos[3] = {X, Y, Z};
303 Double_t Bmod =
sqrt(B[0] * B[0] + B[1] * B[1] + B[2] * B[2]);
306 fHM->
G2(
string(
"hfa_Bx_Graph2D_") + s)->SetPoint(cnt, X, Y, B[0]);
307 fHM->
G2(
string(
"hfa_By_Graph2D_") + s)->SetPoint(cnt, X, Y, B[1]);
308 fHM->
G2(
string(
"hfa_Bz_Graph2D_") + s)->SetPoint(cnt, X, Y, B[2]);
309 fHM->
G2(
string(
"hfa_Mod_Graph2D_") + s)->SetPoint(cnt, X, Y, Bmod);
318 vector<vector<LitFieldSliceScal>> slices;
328 cout <<
"-I- CbmLitFieldApproximationQa::FillFieldApproximationHistos: "
334 for (Int_t iSlice = 0; iSlice <
fNofSlices; iSlice++) {
340 for (Int_t iX = 0; iX <
fNofBinsX; iX++) {
342 for (Int_t iY = 0; iY <
fNofBinsY; iY++) {
354 slices[p][iSlice].GetFieldValue(X, Y,
v);
355 Double_t mod =
sqrt(
v.Bx *
v.Bx +
v.By *
v.By +
v.Bz *
v.Bz);
357 fHM->
G2(
string(
"hfa_BxApr_Graph2D_") + s)->SetPoint(cnt, X, Y,
v.Bx);
358 fHM->
G2(
string(
"hfa_ByApr_Graph2D_") + s)->SetPoint(cnt, X, Y,
v.By);
359 fHM->
G2(
string(
"hfa_BzApr_Graph2D_") + s)->SetPoint(cnt, X, Y,
v.Bz);
360 fHM->
G2(
string(
"hfa_ModApr_Graph2D_") + s)->SetPoint(cnt, X, Y, mod);
368 Int_t nofBinsX = 100;
369 Int_t nofBinsY = 100;
370 for (Int_t iSlice = 0; iSlice <
fNofSlices; iSlice++) {
374 for (Int_t iX = 0; iX < nofBinsX; iX++) {
376 for (Int_t iY = 0; iY < nofBinsY; iY++) {
387 Double_t
pos[3] = {X, Y, Z};
391 Double_t Bmod =
sqrt(B[0] * B[0] + B[1] * B[1] + B[2] * B[2]);
395 slices[p][iSlice].GetFieldValue(X, Y,
v);
396 Double_t mod =
sqrt(
v.Bx *
v.Bx +
v.By *
v.By +
v.Bz *
v.Bz);
398 Double_t errBx = B[0] -
v.Bx;
399 Double_t errBy = B[1] -
v.By;
400 Double_t errBz = B[2] -
v.Bz;
401 Double_t errMod = Bmod - mod;
402 Double_t relErrBx = (B[0] != 0.) ? (errBx / B[0]) * 100. : 0.;
403 Double_t relErrBy = (B[1] != 0.) ? (errBy / B[1]) * 100. : 0.;
404 Double_t relErrBz = (B[2] != 0.) ? (errBz / B[2]) * 100. : 0.;
405 Double_t relErrMod = (Bmod != 0.) ? (errMod / Bmod) * 100. : 0;
408 fHM->
H1(
string(
"hfa_BxErrApr_H1_") + s)->Fill(errBx);
409 fHM->
H1(
string(
"hfa_BxRelErrApr_H1_") + s)->Fill(relErrBx);
410 fHM->
H2(
string(
"hfa_BxErrApr_H2_") + s)->Fill(X, Y, errBx);
411 fHM->
H2(
string(
"hfa_BxRelErrApr_H2_") + s)->Fill(X, Y, relErrBx);
412 fHM->
H1(
string(
"hfa_ByErrApr_H1_") + s)->Fill(errBy);
413 fHM->
H1(
string(
"hfa_ByRelErrApr_H1_") + s)->Fill(relErrBy);
414 fHM->
H2(
string(
"hfa_ByErrApr_H2_") + s)->Fill(X, Y, errBy);
415 fHM->
H2(
string(
"hfa_ByRelErrApr_H2_") + s)->Fill(X, Y, relErrBy);
416 fHM->
H1(
string(
"hfa_BzErrApr_H1_") + s)->Fill(errBz);
417 fHM->
H1(
string(
"hfa_BzRelErrApr_H1_") + s)->Fill(relErrBz);
418 fHM->
H2(
string(
"hfa_BzErrApr_H2_") + s)->Fill(X, Y, errBz);
419 fHM->
H2(
string(
"hfa_BzRelErrApr_H2_") + s)->Fill(X, Y, relErrBz);
420 fHM->
H1(
string(
"hfa_ModErrApr_H1_") + s)->Fill(errMod);
421 fHM->
H1(
string(
"hfa_ModRelErrApr_H1_") + s)->Fill(relErrMod);
422 fHM->
H2(
string(
"hfa_ModErrApr_H2_") + s)->Fill(X, Y, errMod);
423 fHM->
H2(
string(
"hfa_ModRelErrApr_H2_") + s)->Fill(X, Y, relErrMod);
432 vector<LitFieldGrid> grids;
434 for (Int_t iSlice = 0; iSlice <
fNofSlices; iSlice++) {
439 for (Int_t iSlice = 0; iSlice <
fNofSlices; iSlice++) {
444 for (Int_t iX = 0; iX <
fNofBinsX; iX++) {
446 for (Int_t iY = 0; iY <
fNofBinsY; iY++) {
449 grids[iSlice].GetFieldValue(X, Y,
v);
450 Double_t mod =
sqrt(
v.Bx *
v.Bx +
v.By *
v.By +
v.Bz *
v.Bz);
452 fHM->
G2(
string(
"hfa_BxGrid_Graph2D_") + s)->SetPoint(cnt, X, Y,
v.Bx);
453 fHM->
G2(
string(
"hfa_ByGrid_Graph2D_") + s)->SetPoint(cnt, X, Y,
v.By);
454 fHM->
G2(
string(
"hfa_BzGrid_Graph2D_") + s)->SetPoint(cnt, X, Y,
v.Bz);
455 fHM->
G2(
string(
"hfa_ModGrid_Graph2D_") + s)->SetPoint(cnt, X, Y, mod);
462 Int_t nofBinsX = 100;
463 Int_t nofBinsY = 100;
464 for (Int_t iSlice = 0; iSlice <
fNofSlices; iSlice++) {
468 for (Int_t iX = 0; iX < nofBinsX; iX++) {
470 for (Int_t iY = 0; iY < nofBinsY; iY++) {
474 Double_t
pos[3] = {X, Y, Z};
478 Double_t Bmod =
sqrt(B[0] * B[0] + B[1] * B[1] + B[2] * B[2]);
481 grids[iSlice].GetFieldValue(X, Y,
v);
482 Double_t mod =
sqrt(
v.Bx *
v.Bx +
v.By *
v.By +
v.Bz *
v.Bz);
484 Double_t errBx = B[0] -
v.Bx;
485 Double_t errBy = B[1] -
v.By;
486 Double_t errBz = B[2] -
v.Bz;
487 Double_t errMod = Bmod - mod;
488 Double_t relErrBx = (B[0] != 0.) ? (errBx / B[0]) * 100. : 0.;
489 Double_t relErrBy = (B[1] != 0.) ? (errBy / B[1]) * 100. : 0.;
490 Double_t relErrBz = (B[2] != 0.) ? (errBz / B[2]) * 100. : 0.;
491 Double_t relErrMod = (Bmod != 0.) ? (errMod / Bmod) * 100. : 0;
494 fHM->
H1(
string(
"hfa_BxErrGrid_H1_") + s)->Fill(errBx);
495 fHM->
H1(
string(
"hfa_BxRelErrGrid_H1_") + s)->Fill(relErrBx);
496 fHM->
H2(
string(
"hfa_BxErrGrid_H2_") + s)->Fill(X, Y, errBx);
497 fHM->
H2(
string(
"hfa_BxRelErrGrid_H2_") + s)->Fill(X, Y, relErrBx);
498 fHM->
H1(
string(
"hfa_ByErrGrid_H1_") + s)->Fill(errBy);
499 fHM->
H1(
string(
"hfa_ByRelErrGrid_H1_") + s)->Fill(relErrBy);
500 fHM->
H2(
string(
"hfa_ByErrGrid_H2_") + s)->Fill(X, Y, errBy);
501 fHM->
H2(
string(
"hfa_ByRelErrGrid_H2_") + s)->Fill(X, Y, relErrBy);
502 fHM->
H1(
string(
"hfa_BzErrGrid_H1_") + s)->Fill(errBz);
503 fHM->
H1(
string(
"hfa_BzRelErrGrid_H1_") + s)->Fill(relErrBz);
504 fHM->
H2(
string(
"hfa_BzErrGrid_H2_") + s)->Fill(X, Y, errBz);
505 fHM->
H2(
string(
"hfa_BzRelErrGrid_H2_") + s)->Fill(X, Y, relErrBz);
506 fHM->
H1(
string(
"hfa_ModErrGrid_H1_") + s)->Fill(errMod);
507 fHM->
H1(
string(
"hfa_ModRelErrGrid_H1_") + s)->Fill(relErrMod);
508 fHM->
H2(
string(
"hfa_ModErrGrid_H2_") + s)->Fill(X, Y, errMod);
509 fHM->
H2(
string(
"hfa_ModRelErrGrid_H2_") + s)->Fill(X, Y, relErrMod);
std::string ToString(ECbmModuleId modId)
Helper functions for drawing 1D and 2D histograms and graphs.
ClassImp(CbmLitFieldApproximationQa)
Field map approximation QA.
Implementation of the polynomial field approximation.
Class creates grid with magnetic field values at a certain Z position.
Define floating point number type litfloat.
friend fvec sqrt(const fvec &a)
Class stores a grid of magnetic field values in XY slice at Z position.
Approximated magnetic field slice in XY plane perpendicular to Z.
Magnetic field value at a certain point in the space.
TGraph2D * G2(const std::string &name) const
Return pointer to TGraph2D.
TH2 * H2(const std::string &name) const
Return pointer to TH2 histogram.
void WriteToFile()
Write all objects to current opened file.
void Add(const std::string &name, TNamed *object)
Add new named object to manager.
std::string ToString() const
Return string representation of class.
TH1 * H1(const std::string &name) const
Return pointer to TH1 histogram.
Field map approximation QA.
void CreateGridHistos()
Create histograms for grid creator.
void CreateFitterHistos()
Create histograms for field approximation.
CbmLitFieldApproximationQa()
Constructor.
virtual ~CbmLitFieldApproximationQa()
Destructor.
void FillGridCreatorHistos()
fill histograms for grid creator tool.
Double_t fAcceptanceAngleX
virtual InitStatus Init()
Inherited from FairTask.
void FillBHistos()
Fill graphs and histos for field map for each field component (Bx, By, Bz, |B|).
vector< CbmLitFieldFitter * > fFitter
vector< Double_t > fXSlicePosition
vector< Double_t > fZSlicePosition
Double_t fAcceptanceAngleY
CbmLitFieldGridCreator * fGridCreator
virtual void Exec(Option_t *opt)
Inherited from FairTask.
void CreateFieldHistos()
Create field histograms.
vector< Double_t > fYSlicePosition
void CreateHistos()
Create histograms.
vector< UInt_t > fPolynomDegrees
virtual void Finish()
Inherited from FairTask.
void FillFieldApproximationHistos()
Fill histograms for polynomial field approximation.
Implementation of the polynomial field approximation.
void CreateGrid(fscal Z, lit::parallel::LitFieldGrid &grid)
Main function which creates grid with magnetic field values in (X, Y) slice.
Base class for simulation reports.
void Create(CbmHistManager *histManager, const std::string &outputDir)
Main function which creates report data.
Class stores a grid of magnetic field values in XY slice at Z position.
Approximated magnetic field slice in XY plane perpendicular to Z.
Magnetic field value at a certain point in the space.
void SaveCanvasAsImage(TCanvas *c, const string &dir, const string &option)
std::string ToString(const T &value)