8 R__LOAD_LIBRARY(libfieldsim.so)
19 void generate_distortion_map(const
char *inputname, const
char* gainName, const
char *outputname, const
char *ibfName, const
char *primName,
bool hasSpacecharge=true,
bool isAdc=false,
int nSteps=500,
bool scanSteps=false){
20 printf(
"generating single distortion map. Caution: This is vastly less efficient than re-using the tpc model once it is set up\n");
23 TString gainHistName[2]={
"hIbfGain_posz",
"hIbfGFain_negz"};
26 bool usesChargeDensity=
false;
27 float tpc_chargescale=1.6e-19;
28 float spacecharge_cm_per_axis_unit=0.1;
33 TString sourcefilename=inputname;
34 TString outputfilename=outputname;
44 infile=TFile::Open(sourcefilename.Data(),
"READ");
49 TH3* hCharge=(TH3*)(infile->Get(ibfName));
51 hCharge->Add((TH3*)(infile->Get(primName)));
60 chargestring=Form(
"%s:(%s+%s)",inputname,ibfName,primName);
61 tpc->
load_spacecharge(hCharge,0,tpc_chargescale,spacecharge_cm_per_axis_unit, usesChargeDensity, chargestring.Data());
62 if (hasTwin) tpc->
twin->
load_spacecharge(hCharge,0,tpc_chargescale,spacecharge_cm_per_axis_unit, usesChargeDensity);
65 gainfile=TFile::Open(gainName,
"READ");
67 hGain[0]=(TH2*)(gainfile->Get(gainHistName[0]));
68 chargestring=Form(
"%s:(dc:%s g:%s:%s)",inputname,ibfName,gainName,gainHistName[0].
Data());
69 tpc->
load_digital_current(hCharge,hGain[0],tpc_chargescale,spacecharge_cm_per_axis_unit,chargestring.Data());
71 hGain[1]=(TH2*)(gainfile->Get(gainHistName[1]));
81 for(
int i=0;
i<10;
i++){
82 TString study_filestring=Form(
"%s.steps%d.hist.root",
"study_file_changinginterval",50*(
i+1));
91 printf(
"distortions mapped.\n");
94 printf(
"fieldslices plotted.\n");
97 printf(
"input closed. All done. Anything else is root's problem.\n");
104 void generate_distortion_map(
const char * inputpattern=
"./evgeny_apr/Smooth*.root",
const char *outputfilebase=
"./apr07_maps/apr07",
bool hasSpacecharge=
true,
bool isDigitalCurrent=
false,
int nSteps=500){
108 int maxmapsperfile=2;
115 bool usesChargeDensity=
false;
116 float tpc_chargescale=1.6e-19;
117 float spacecharge_cm_per_axis_unit=0.1;
122 TString sourcefilename;
123 TString outputfilename;
127 TFileCollection *filelist=
new TFileCollection();
128 filelist->Add(inputpattern);
130 printf(
"Using pattern \"%s\", found %d files to read, eg : %s\n",inputpattern,filelist->GetList()->GetEntries(),((TFileInfo*)(filelist->GetList()->At(0)))->GetCurrentUrl()->GetUrl());
151 TVector3
pos=0.5*(tpc->GetOuterEdge()+tpc->GetInnerEdge());;
160 for (
int i=0;
i<filelist->GetNFiles();
i++){
162 sourcefilename=((TFileInfo*)(filelist->GetList()->At(
i)))->GetCurrentUrl()->GetFile();
163 infile=TFile::Open(sourcefilename.Data(),
"READ");
164 TList *keys=infile->GetListOfKeys();
166 int nKeys=infile->GetNkeys();
168 for (
int j=0;
j<nKeys;
j++){
169 TObject *tobj=infile->Get(keys->At(
j)->GetName());
171 bool isHist=tobj->InheritsFrom(
"TH3");
172 if (!isHist)
continue;
173 TString objname=tobj->GetName();
174 if (objname.Contains(
"IBF"))
continue;
178 if (isDigitalCurrent){
179 tpc->load_and_resample_spacecharge(8,36,40,sourcefilename.Data(),tobj->GetName(),0,tpc_chargescale,spacecharge_cm_per_axis_unit, usesChargeDensity);
180 if (hasTwin) tpc->twin->load_and_resample_spacecharge(8,36,40,sourcefilename.Data(),tobj->GetName(),0,tpc_chargescale,spacecharge_cm_per_axis_unit, usesChargeDensity);
185 tpc->load_spacecharge(sourcefilename.Data(),tobj->GetName(),0,tpc_chargescale,spacecharge_cm_per_axis_unit, usesChargeDensity);
186 if (hasTwin) tpc->twin->load_spacecharge(sourcefilename.Data(),tobj->GetName(),0,tpc_chargescale,spacecharge_cm_per_axis_unit, usesChargeDensity);
195 printf(
"Sanity check: Total Q in reported region is %E C\n",totalQ);
197 tpc->populate_fieldmap();
198 if (hasTwin) tpc->twin->populate_fieldmap();
199 if (sourcefilename.Contains(
"verage")){
204 printf(
"%s file has %s hist. field=%s, lookup=%s. no scaling.\n",
212 tpc->GenerateSeparateDistortionMaps(outputfilename,2,2,2,1,
true,nSteps);
214 printf(
"distortions mapped.\n");
215 tpc->PlotFieldSlices(outputfilename.Data(),
pos);
216 tpc->PlotFieldSlices(outputfilename.Data(),
pos,
'B');
217 printf(
"fieldslices plotted.\n");
218 printf(
"obj %d: getname: %s inherits from TH3D:%d \n",
j,tobj->GetName(),tobj->InheritsFrom(
"TH3"));
220 if (
i>maxmaps)
return;
230 TVector3
dummy(20.9034,-2.3553,-103.4712);
231 float dummydest=-103.4752;
233 dummy.SetZ(dummy.Z()*-1);
240 const float tpc_rmin=20.0;
241 const float tpc_rmax=78.0;
242 float tpc_deltar=tpc_rmax-tpc_rmin;
243 const float tpc_z=105.5;
244 const float tpc_cmVolt=-400*tpc_z;
247 const float tpc_driftVel=8.0*1e6;
248 const float tpc_magField=1.4;
249 const char detgeoname[]=
"sphenix";
260 int nr_roi_max=nr_roi_min+nr_roi;
264 int nphi_roi_max=nphi_roi_min+nphi_roi;
268 int nz_roi_max=nz_roi_min+nz_roi;
282 nr, nr_roi_min,nr_roi_max,1,2,
283 nphi,nphi_roi_min, nphi_roi_max,1,2,
284 nz, nz_roi_min, nz_roi_max,1,2,
288 nr, nr_roi_min,nr_roi_max,1,2,
289 nphi,nphi_roi_min, nphi_roi_max,1,2,
290 nz, nz_roi_min, nz_roi_max,1,2,
298 sprintf(
field_string,
"flat_B%2.1f_E%2.1f",tpc_magField,tpc_cmVolt/tpc_z);
301 tpc->
loadEfield(
"/sphenix/user/rcorliss/field/externalEfield.ttree.root",
"fTree");
302 sprintf(
field_string,
"realE_B%2.1f_E%2.1f",tpc_magField,tpc_cmVolt/tpc_z);
305 tpc->
load3dBfield(
"/sphenix/user/rcorliss/field/sphenix3dmaprhophiz.root",
"fieldmap",1,-1.4/1.5);
307 sprintf(
field_string,
"realB_B%2.1f_E%2.1f",tpc_magField,tpc_cmVolt/tpc_z);
310 sprintf(
field_string,
"real_B%2.1f_E%2.1f",tpc_magField,tpc_cmVolt/tpc_z);
318 sprintf(
lookup_string,
"ross_phi1_%s_phislice_lookup_r%dxp%dxz%d",detgeoname,nr,nphi,nz);
319 char lookupFilename[300];
321 sprintf(lookupFilename,
"/sphenix/user/rcorliss/rossegger/%s.root",
lookup_string);
322 TFile *fileptr=TFile::Open(lookupFilename,
"READ");
327 printf(
"loaded rossegger greens functions.\n");
335 printf(
"populated lookup.\n");
348 nr, nr_roi_min,nr_roi_max,1,2,
349 nphi,nphi_roi_min, nphi_roi_max,1,2,
350 nz, nz_roi_min, nz_roi_max,1,2,
354 nr, nr_roi_min,nr_roi_max,1,2,
355 nphi,nphi_roi_min, nphi_roi_max,1,2,
356 nz, nz_roi_min, nz_roi_max,1,2,
364 twin->
load3dBfield(
"/sphenix/user/rcorliss/rossegger/sphenix3dmaprhophiz.root",
"fieldmap",1,-1.4/1.5);
365 twin->
loadEfield(
"/sphenix/user/rcorliss/rossegger/externalEfield.ttree.root",
"fTree",-1);
383 const float tpc_rmin=20.0;
384 const float tpc_rmax=78.0;
385 float tpc_deltar=tpc_rmax-tpc_rmin;
386 const float tpc_z=105.5;
387 const float tpc_cmVolt=-400*tpc_z;
390 const float tpc_driftVel=8.0*1e6;
391 const float tpc_magField=1.4;
392 const char detgeoname[]=
"sphenix";
403 int nr_roi_max=nr_roi_min+nr_roi;
407 int nphi_roi_max=nphi_roi_min+nphi_roi;
411 int nz_roi_max=nz_roi_min+nz_roi;
423 nr, nr_roi_min,nr_roi_max,1,2,
424 nphi,nphi_roi_min, nphi_roi_max,1,2,
425 nz, nz_roi_min, nz_roi_max,1,2,
429 nr, nr_roi_min,nr_roi_max,1,2,
430 nphi,nphi_roi_min, nphi_roi_max,1,2,
431 nz, nz_roi_min, nz_roi_max,1,2,
439 sprintf(
field_string,
"flat_B%2.1f_E%2.1f",tpc_magField,tpc_cmVolt/tpc_z);
442 tpc->
loadEfield(
"externalEfield.ttree.root",
"fTree");
443 sprintf(
field_string,
"realE_B%2.1f_E%2.1f",tpc_magField,tpc_cmVolt/tpc_z);
446 tpc->
load3dBfield(
"sphenix3dmaprhophiz.root",
"fieldmap",1,-1.4/1.5);
448 sprintf(
field_string,
"realB_B%2.1f_E%2.1f",tpc_magField,tpc_cmVolt/tpc_z);
451 sprintf(
field_string,
"real_B%2.1f_E%2.1f",tpc_magField,tpc_cmVolt/tpc_z);
459 sprintf(
lookup_string,
"ross_phi1_%s_phislice_lookup_r%dxp%dxz%d",detgeoname,nr,nphi,nz);
460 char lookupFilename[200];
462 TFile *fileptr=TFile::Open(lookupFilename,
"READ");
467 printf(
"loaded rossegger greens functions.\n");
475 printf(
"populated lookup.\n");
488 nr, nr_roi_min,nr_roi_max,1,2,
489 nphi,nphi_roi_min, nphi_roi_max,1,2,
490 nz, nz_roi_min, nz_roi_max,1,2,
494 nr, nr_roi_min,nr_roi_max,1,2,
495 nphi,nphi_roi_min, nphi_roi_max,1,2,
496 nz, nz_roi_min, nz_roi_max,1,2,
504 twin->
load3dBfield(
"sphenix3dmaprhophiz.root",
"fieldmap",1,-1.4/1.5);
505 twin->
loadEfield(
"externalEfield.ttree.root",
"fTree",-1);
523 TString sourcefilename;
524 TString outputfilename;
526 float integral_sum=0;
528 for (
int i=0;
i<filelist->GetNFiles();
i++){
530 sourcefilename=((TFileInfo*)(filelist->GetList()->At(
i)))->GetCurrentUrl()->GetFile();
531 printf(
"file %d: %s\n",
i, sourcefilename.Data());
532 infile=TFile::Open(sourcefilename.Data(),
"READ");
533 TList *keys=infile->GetListOfKeys();
535 int nKeys=infile->GetNkeys();
537 for (
int j=0;
j<nKeys;
j++){
538 TObject *tobj=infile->Get(keys->At(
j)->GetName());
540 bool isHist=tobj->InheritsFrom(
"TH3");
541 if (!isHist)
continue;
542 TString objname=tobj->GetName();
543 printf(
" hist %s ",objname.Data());
544 if (objname.Contains(
"IBF")) {
545 printf(
" is IBF only.\n");
548 float integral=((TH3D*)tobj)->Integral();
551 printf(
" will be used. Total Q=%3.3E (ave=%3.3E)\n",integral,integral_sum/nhists);