Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FieldMaps.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file FieldMaps.cxx
1 #include "FieldMaps.h"
2 #include <string>
3 
4 #include "TH3F.h"
5 #include "TFile.h"
6 #include "TMath.h"
7 
8 //=====================
10  fDebug = 0;
11  fRadialBin = -1;
12  fEr = NULL;
13  fEp = NULL;
14  fEz = NULL;
15  fRho = NULL;
16  fInnerRadius=1.;
17  fOutterRadius=2.;
18  fHalfLength=1.;
19  fNRadialSteps=1;
22  fFileNameRoot="rho";
23  fLSNameRoot="none";
24  fMirrorZ=false;
25 }
26 //=====================
28 }
29 //=====================
30 void FieldMaps::Make(int n) {
31  fRadialBin = n;
32  InitMaps();
33  ComputeE();
34  SaveMaps();
35 }
36 //=====================
38  if(fDebug>0) printf("FieldMaps is initializing field maps... ");
39  fEr = new TH3F("Er","Er [V/cm];Radial [cm];Azimuthal [rad];Longitudinal [cm]",
43  fEp = new TH3F("Ep","Ephi [V/cm];Radial [cm];Azimuthal [rad];Longitudinal [cm]",
47  fEz = new TH3F("Ez","Ez [V/cm];Radial [cm];Azimuthal [rad];Longitudinal [cm]",
51  if(fDebug>0) printf("[DONE]\n");
52  ReadFile();
53 }
54 //=====================
56  const char *inputfile= Form("%s_0.root",fFileNameRoot.data());
57  if(fDebug>0) printf("FieldMaps is reading from %s... ",inputfile);
58  TFile *ifile = new TFile(inputfile);
59  if(ifile->IsZombie()) ifile=NULL;
60  if(!ifile) exit(1);
61  fRho = (TH3F*) ifile->Get("rho");
62  if(fDebug>0) printf("[DONE]\n");
63  // PLUG Gr Gz HERE
64 }
65 //=====================
67  TString filename;
68  if(fRadialBin<0) filename = Form("%s_1.root",fFileNameRoot.data());
69  else filename = Form("%s_1_%d.root",fFileNameRoot.data(),fRadialBin);
70  if(fDebug>1) printf("FieldMaps saving field maps into %s... ",filename.Data());
71  TFile *ofile = new TFile(filename.Data(),"RECREATE");
72  ofile->WriteObject(fEr,"Er");
73  ofile->WriteObject(fEp,"Ep");
74  ofile->WriteObject(fEz,"Ez");
75  ofile->Close();
76  if(fDebug>1) printf("[DONE]\n");
77 }
78 //=====================
79 float FieldMaps::ReadCharge(float rprime, float phiprime, float zprime, float dr, float dphi,float dz) {
80  int brmin = fRho->GetXaxis()->FindBin(rprime - dr/2 + 1e-8);
81  int brmax = fRho->GetXaxis()->FindBin(rprime + dr/2 - 1e-8);
82  int bpmin = fRho->GetYaxis()->FindBin(phiprime - dphi/2 + 1e-8);
83  int bpmax = fRho->GetYaxis()->FindBin(phiprime + dphi/2 - 1e-8);
84  int bzmin = fRho->GetZaxis()->FindBin(zprime - dz/2 + 1e-8);
85  int bzmax = fRho->GetZaxis()->FindBin(zprime + dz/2 - 1e-8);
86  if(brmin<1||bpmin<1||bzmin<1) return 0;
87  if(brmax<brmin) brmax = brmin +1;
88  if(bpmax<bpmin) bpmax = bpmin +1;
89  if(bzmax<bzmin) bzmax = bzmin +1;
90 
91  float ddr = fRho->GetXaxis()->GetBinWidth(1);
92  float ddp = fRho->GetYaxis()->GetBinWidth(1);
93  float ddz = fRho->GetZaxis()->GetBinWidth(1);
94  float totalQ = 0;
95  for(int br=brmin; br!=brmax+1; ++br)
96  for(int bp=bpmin; bp!=bpmax+1; ++bp)
97  for(int bz=bzmin; bz!=bzmax+1; ++bz) {
98  float rho = fRho->GetBinContent(br,bp,bz);
99  float r = fRho->GetXaxis()->GetBinCenter( br );
100  float dv = r*ddp*ddr*ddz;
101  totalQ += rho*dv;
102  }
103  //return rprime*fRho->Integral( brmin,brmax , bpmin,bpmax , bzmin,bzmax );
104  return totalQ;
105 }