17 void generate_distortion_map(const
char * inputpattern="./evgeny_apr/Smooth*.root", const
char *outputfilebase="./apr07_maps/apr07",
bool hasSpacecharge=true,
bool isDigitalCurrent=false){
27 bool usesChargeDensity=
false;
28 float tpc_chargescale=1.6e-19;
29 float spacecharge_cm_per_axis_unit=100;
34 TString sourcefilename;
35 TString outputfilename;
39 TFileCollection *filelist=
new TFileCollection();
40 filelist->Add(inputpattern);
42 printf(
"Using pattern \"%s\", found %d files to read, eg : %s\n",inputpattern,filelist->GetList()->GetEntries(),((TFileInfo*)(filelist->GetList()->At(0)))->GetCurrentUrl()->GetUrl());
72 for (
int i=0;i<filelist->GetNFiles();i++){
74 sourcefilename=((TFileInfo*)(filelist->GetList()->At(i)))->GetCurrentUrl()->GetFile();
75 infile=TFile::Open(sourcefilename.Data(),
"READ");
76 TList *keys=infile->GetListOfKeys();
78 int nKeys=infile->GetNkeys();
80 for (
int j=0;j<nKeys;j++){
81 TObject *tobj=infile->Get(keys->At(j)->GetName());
83 bool isHist=tobj->InheritsFrom(
"TH3");
84 if (!isHist)
continue;
85 TString objname=tobj->GetName();
86 if (objname.Contains(
"IBF"))
continue;
90 if (isDigitalCurrent){
91 tpc->
load_and_resample_spacecharge(8,36,40,sourcefilename.Data(),tobj->GetName(),0,tpc_chargescale,spacecharge_cm_per_axis_unit, usesChargeDensity);
92 if (hasTwin) tpc->
twin->
load_and_resample_spacecharge(8,36,40,sourcefilename.Data(),tobj->GetName(),0,tpc_chargescale,spacecharge_cm_per_axis_unit, usesChargeDensity);
95 tpc->
load_spacecharge(sourcefilename.Data(),tobj->GetName(),0,tpc_chargescale,spacecharge_cm_per_axis_unit, usesChargeDensity);
96 if (hasTwin) tpc->
twin->
load_spacecharge(sourcefilename.Data(),tobj->GetName(),0,tpc_chargescale,spacecharge_cm_per_axis_unit, usesChargeDensity);
100 printf(
"Sanity check: Q has %d elements and dim=%d\n",tpc->
q->
Length(), tpc->
q->
dim);
105 printf(
"Sanity check: Total Q in reported region is %E C\n",totalQ);
109 if (sourcefilename.Contains(
"verage")){
110 outputfilename=Form(
"%s.average.%s.%s",outputfilebase,field_string,lookup_string);
114 printf(
"%s file has %s hist. field=%s, lookup=%s. no scaling.\n",
121 printf(
"distortions mapped.\n");
124 printf(
"fieldslices plotted.\n");
125 printf(
"obj %d: getname: %s inherits from TH3D:%d \n",j,tobj->GetName(),tobj->InheritsFrom(
"TH3"));
127 if (i>maxmaps)
return;
137 TVector3 dummy(20.9034,-2.3553,-103.4712);
138 float dummydest=-103.4752;
140 dummy.SetZ(dummy.Z()*-1);
147 const float tpc_rmin=20.0;
148 const float tpc_rmax=78.0;
149 float tpc_deltar=tpc_rmax-tpc_rmin;
150 const float tpc_z=105.5;
151 const float tpc_cmVolt=-400*tpc_z;
154 const float tpc_driftVel=8.0*1
e6;
155 const float tpc_magField=1.4;
156 const char detgeoname[]=
"sphenix";
163 int nr_roi_max=nr_roi_min+nr_roi;
167 int nphi_roi_max=nphi_roi_min+nphi_roi;
171 int nz_roi_max=nz_roi_min+nz_roi;
181 nr, nr_roi_min,nr_roi_max,1,2,
182 nphi,nphi_roi_min, nphi_roi_max,1,2,
183 nz, nz_roi_min, nz_roi_max,1,2,
187 nr, nr_roi_min,nr_roi_max,1,2,
188 nphi,nphi_roi_min, nphi_roi_max,1,2,
189 nz, nz_roi_min, nz_roi_max,1,2,
197 sprintf(
field_string,
"flat_B%2.1f_E%2.1f",tpc_magField,tpc_cmVolt/tpc_z);
200 tpc->
loadEfield(
"externalEfield.ttree.root",
"fTree");
201 sprintf(
field_string,
"realE_B%2.1f_E%2.1f",tpc_magField,tpc_cmVolt/tpc_z);
204 tpc->
load3dBfield(
"sphenix3dmaprhophiz.root",
"fieldmap",1,-1.4/1.5);
206 sprintf(
field_string,
"realB_B%2.1f_E%2.1f",tpc_magField,tpc_cmVolt/tpc_z);
209 sprintf(
field_string,
"real_B%2.1f_E%2.1f",tpc_magField,tpc_cmVolt/tpc_z);
217 sprintf(
lookup_string,
"ross_phi1_%s_phislice_lookup_r%dxp%dxz%d",detgeoname,nr,nphi,nz);
218 char lookupFilename[300];
220 sprintf(lookupFilename,
"/sphenix/user/rcorliss/rossegger/%s.root",
lookup_string);
221 TFile *fileptr=TFile::Open(lookupFilename,
"READ");
226 printf(
"loaded rossegger greens functions.\n");
234 printf(
"populated lookup.\n");
247 nr, nr_roi_min,nr_roi_max,1,2,
248 nphi,nphi_roi_min, nphi_roi_max,1,2,
249 nz, nz_roi_min, nz_roi_max,1,2,
253 nr, nr_roi_min,nr_roi_max,1,2,
254 nphi,nphi_roi_min, nphi_roi_max,1,2,
255 nz, nz_roi_min, nz_roi_max,1,2,
263 twin->
load3dBfield(
"/sphenix/user/rcorliss/rossegger/sphenix3dmaprhophiz.root",
"fieldmap",1,-1.4/1.5);
264 twin->
loadEfield(
"/sphenix/user/rcorliss/rossegger/externalEfield.ttree.root",
"fTree",-1);
282 const float tpc_rmin=20.0;
283 const float tpc_rmax=78.0;
284 float tpc_deltar=tpc_rmax-tpc_rmin;
285 const float tpc_z=105.5;
286 const float tpc_cmVolt=-400*tpc_z;
289 const float tpc_driftVel=8.0*1
e6;
290 const float tpc_magField=1.4;
291 const char detgeoname[]=
"sphenix";
298 int nr_roi_max=nr_roi_min+nr_roi;
302 int nphi_roi_max=nphi_roi_min+nphi_roi;
306 int nz_roi_max=nz_roi_min+nz_roi;
316 nr, nr_roi_min,nr_roi_max,1,2,
317 nphi,nphi_roi_min, nphi_roi_max,1,2,
318 nz, nz_roi_min, nz_roi_max,1,2,
322 nr, nr_roi_min,nr_roi_max,1,2,
323 nphi,nphi_roi_min, nphi_roi_max,1,2,
324 nz, nz_roi_min, nz_roi_max,1,2,
332 sprintf(
field_string,
"flat_B%2.1f_E%2.1f",tpc_magField,tpc_cmVolt/tpc_z);
335 tpc->
loadEfield(
"externalEfield.ttree.root",
"fTree");
336 sprintf(
field_string,
"realE_B%2.1f_E%2.1f",tpc_magField,tpc_cmVolt/tpc_z);
339 tpc->
load3dBfield(
"sphenix3dmaprhophiz.root",
"fieldmap",1,-1.4/1.5);
341 sprintf(
field_string,
"realB_B%2.1f_E%2.1f",tpc_magField,tpc_cmVolt/tpc_z);
344 sprintf(
field_string,
"real_B%2.1f_E%2.1f",tpc_magField,tpc_cmVolt/tpc_z);
352 sprintf(
lookup_string,
"ross_phi1_%s_phislice_lookup_r%dxp%dxz%d",detgeoname,nr,nphi,nz);
353 char lookupFilename[200];
355 TFile *fileptr=TFile::Open(lookupFilename,
"READ");
360 printf(
"loaded rossegger greens functions.\n");
368 printf(
"populated lookup.\n");
381 nr, nr_roi_min,nr_roi_max,1,2,
382 nphi,nphi_roi_min, nphi_roi_max,1,2,
383 nz, nz_roi_min, nz_roi_max,1,2,
387 nr, nr_roi_min,nr_roi_max,1,2,
388 nphi,nphi_roi_min, nphi_roi_max,1,2,
389 nz, nz_roi_min, nz_roi_max,1,2,
397 twin->
load3dBfield(
"sphenix3dmaprhophiz.root",
"fieldmap",1,-1.4/1.5);
398 twin->
loadEfield(
"externalEfield.ttree.root",
"fTree",-1);
416 TString sourcefilename;
417 TString outputfilename;
419 float integral_sum=0;
421 for (
int i=0;i<filelist->GetNFiles();i++){
423 sourcefilename=((TFileInfo*)(filelist->GetList()->At(i)))->GetCurrentUrl()->GetFile();
424 printf(
"file %d: %s\n", i, sourcefilename.Data());
425 infile=TFile::Open(sourcefilename.Data(),
"READ");
426 TList *keys=infile->GetListOfKeys();
428 int nKeys=infile->GetNkeys();
430 for (
int j=0;j<nKeys;j++){
431 TObject *tobj=infile->Get(keys->At(j)->GetName());
433 bool isHist=tobj->InheritsFrom(
"TH3");
434 if (!isHist)
continue;
435 TString objname=tobj->GetName();
436 printf(
" hist %s ",objname.Data());
437 if (objname.Contains(
"IBF")) {
438 printf(
" is IBF only.\n");
441 float integral=((TH3D*)tobj)->Integral();
442 integral_sum+=integral;
444 printf(
" will be used. Total Q=%3.3E (ave=%3.3E)\n",integral,integral_sum/nhists);