-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmakemap.C
More file actions
57 lines (42 loc) · 1.39 KB
/
makemap.C
File metadata and controls
57 lines (42 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
#include <fstream>
#include <sstream>
#include "TFile.h"
#include "TNtuple.h"
Int_t makemap( std::string filename = "TPC_fld_map_f_shiftby2p85cm.table" )
{
std::ifstream ifs( filename );
std::string line;
double x,y,z;
double bx,by,bz;
double rho,phi;
double brho,bphi;
double gauss2tesla = 1.0/10000.0;
// unit vector from the origin to (x,y)
double vx,vy;
std::string rootfile = "sphenix3dmaprhophiz.root";
TFile *f = new TFile(rootfile.c_str(),"recreate");
TNtuple fieldmap("fieldmap","sPHENIX 3D Field Map TPC_fld_map_f_shiftby2p85cm 2020.01.16 (Gauss)","rho:phi:z:brho:bphi:bz");
int linenum = 0;
while (getline (ifs, line)) {
// std::cout << line << std::endl;
std::istringstream iss(line);
iss >> x >> y >> z >> bx >> by >> bz;
if ( iss.rdstate() & std::ios::failbit ) {
std::cout << "ignore line: " << line << std::endl;
continue;
}
// std::cout << linenum << ": (" << x << "," << y << "," << z << ")" << std::endl;
rho = sqrt(x*x + y*y);
phi = atan2(y,x);
vx = x/rho;
vy = y/rho;
brho = bx*vx + by*vy;
bphi = -by*vx + bx*vy;
fieldmap.Fill(rho,phi,z,brho*gauss2tesla,bphi*gauss2tesla,bz*gauss2tesla);
std::cout << rho << "," << phi << "," << z << "," << brho << "," << bphi << "," << bz << std::endl;
linenum++;
}
f->Write();
return linenum;
}