EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fieldconverter.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file fieldconverter.C
1 // Convert ECCE's root-based field map to .Bmap format
2 // r, z, B_r, Bz
3 // Leave second argument empty to just replace .root with .Bmap
4 // run with root -l -q fieldconverter.C
5 
6 #include <TString.h>
7 #include <TFile.h>
8 #include <TTreeReader.h>
9 #include <TTreeReader.h>
10 
11 #include <fstream>
12 
13 int fieldconverter( TString infilename="sPHENIX.2d.root",
14  TString outfilename ="",
15  float scalefactor = -1.4 / 1.5 // BaBar -> sPHENIX
16  ){
17  if (outfilename==""){
18  outfilename=infilename;
19  outfilename.ReplaceAll(".root",".Bmap");
20  }
21 
22  auto infile = TFile::Open(infilename);
23  TTreeReader reader("fieldmap", infile);
24  TTreeReaderValue<float> r(reader, "r");
25  TTreeReaderValue<float> z(reader, "z");
26  TTreeReaderValue<float> br(reader, "br");
27  TTreeReaderValue<float> bz(reader, "bz");
28 
29  ofstream outfile;
30  outfile.open(outfilename);
31 
32  while (reader.Next()){
33  outfile << *r << '\t'
34  << *z << '\t'
35  << *br *scalefactor << '\t'
36  << *bz *scalefactor << endl;
37  }
38 
39  return 0;
40 }