BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
createRootMagField.C
Go to the documentation of this file.
1#include "TArrayF.h"
2#include "TFile.h"
3#include "TMath.h"
4#include "TTree.h"
5
6#include <Rtypes.h>
7#include <fstream>
8#include <iomanip>
9#include <iostream>
10#include <string>
11#include <vector>
12
13using namespace std;
14
15R__ADD_INCLUDE_PATH($VMCWORKDIR)
16#include "macro/run/bmnloadlibs.C"
17
18typedef struct
19{
20 Int_t N;
23 Float_t step;
25
26vector<Double_t> Field_remaking(Double_t* B);
27
28void createRootMagField(TString in = "", TString out = "")
29{
30 bmnloadlibs(); // load BmnRoot libraries
31
32 BmnFieldMap* magField = new BmnNewFieldMap(in.Data());
33 magField->SetScale(1.);
34
35 magField->Init();
36
40
41 TString field_type;
42
43 Double_t B[3];
44 vector<Double_t> Field;
45
46 // ofstream myout("ASCII_field_data_test.dat");
47
48 TFile* f = new TFile(out.Data(), "RECREATE");
49 TTree* tree = new TTree("Main_info", "data from ASCII");
50 TTree* t = new TTree("Field_map", "data from ASCII");
51
52 tree->Branch("Field_type", &field_type);
53 tree->Branch("Main_info_X", &X, "N/I:min/F:max:step");
54 tree->Branch("Main_info_Y", &Y, "N/I:min/F:max:step");
55 tree->Branch("Main_info_Z", &Z, "N/I:min/F:max:step");
56 t->Branch("field_map", &Field);
57
58 TString dir = getenv("VMCWORKDIR");
59 ifstream mapFile(TString(dir + "/input/" + in).Data());
60 mapFile >> field_type;
61
62 X.N = magField->GetNx();
63 X.min = magField->GetXmin();
64 X.max = magField->GetXmax();
65 X.step = (X.max - X.min) / Float_t(X.N - 1);
66
67 Y.N = magField->GetNy();
68 Y.min = magField->GetYmin();
69 Y.max = magField->GetYmax();
70 Y.step = (Y.max - Y.min) / Float_t(Y.N - 1);
71
72 Z.N = magField->GetNz();
73 Z.min = magField->GetZmin();
74 Z.max = magField->GetZmax();
75 Z.step = (Z.max - Z.min) / Float_t(Z.N - 1);
76
77 for (Int_t i = X.min; i <= X.max; i += Int_t(Z.step))
78 for (Int_t j = Y.min; j <= Y.max; j += Int_t(Y.step))
79 for (Int_t k = Z.min; k <= Z.max; k += Int_t(Z.step)) {
80 B[0] = magField->GetBx(i, j, k);
81 B[1] = magField->GetBy(i, j, k);
82 B[2] = magField->GetBz(i, j, k);
83 Field.clear();
84 Field = Field_remaking(B);
85 t->Fill();
86 }
87
88 tree->Fill();
89
90 delete magField;
91
92 f->Write();
93}
94
95vector<Double_t> Field_remaking(Double_t* B)
96{
97 vector<Double_t> field_parameters;
98 for (int i = 0; i < 3; ++i) {
99 field_parameters.push_back(B[i]);
100 }
101 return field_parameters;
102}
int i
Definition P4_F32vec4.h:22
friend F32vec4 min(const F32vec4 &a, const F32vec4 &b)
Definition P4_F32vec4.h:30
friend F32vec4 max(const F32vec4 &a, const F32vec4 &b)
Definition P4_F32vec4.h:31
int Int_t
float Float_t
double Double_t
#define R__ADD_INCLUDE_PATH(PATH)
Int_t GetNz() const
Definition BmnFieldMap.h:82
virtual Double_t GetBz(Double_t x, Double_t y, Double_t z)=0
virtual Double_t GetBy(Double_t x, Double_t y, Double_t z)=0
Double_t GetZmin() const
Definition BmnFieldMap.h:70
Double_t GetYmin() const
Definition BmnFieldMap.h:69
void SetScale(Double_t factor)
Set a global field scaling factor.
Definition BmnFieldMap.h:55
virtual Double_t GetBx(Double_t x, Double_t y, Double_t z)=0
Double_t GetXmax() const
Definition BmnFieldMap.h:72
Int_t GetNy() const
Definition BmnFieldMap.h:81
Int_t GetNx() const
Definition BmnFieldMap.h:80
virtual void Init()
Double_t GetXmin() const
Accessors to field parameters in local coordinate system.
Definition BmnFieldMap.h:68
Double_t GetZmax() const
Definition BmnFieldMap.h:74
Double_t GetYmax() const
Definition BmnFieldMap.h:73
Field Map does not have any symmetries w.r.t coordinate axises.
virtual Int_t Fill()
virtual Int_t Branch(const char *folder, Int_t bufsize=32000, Int_t splitlevel=99)
void createRootMagField(TString in="", TString out="")
vector< Double_t > Field_remaking(Double_t *B)
Definition json.hpp:4446