11 #include<FairRunSim.h>
13 #include<FairPrimaryGenerator.h>
14 #include<FairBoxGenerator.h>
19 #include<FairParRootFileIo.h>
48 PndFieldMap* map_to_interpol,
double weight,
string fileName) {
51 ofstream mapFile((fileName+
".dat").c_str());
52 if (!mapFile.is_open()) {
53 cout <<
"WriteAsciiFile: Could not open file! " << endl;
60 if (map_to_corr->GetType() == 1)
61 mapFile <<
"nosym" << endl;
62 if (map_to_corr->GetType() == 2)
63 mapFile <<
"Solenoid" << endl;
64 if (map_to_corr->GetType() == 3)
65 mapFile <<
"Dipole" << endl;
66 if (map_to_corr->GetType() == 4)
67 mapFile <<
"Trans" << endl;
68 if (map_to_corr->
GetUnit() == 10.0)
69 mapFile <<
"T" << endl;
70 if (map_to_corr->
GetUnit() == 0.001)
71 mapFile <<
"G" << endl;
72 if (map_to_corr->
GetUnit() == 1.0)
73 mapFile <<
"kG" << endl;
75 mapFile << map_to_corr->
GetXmin() <<
" " << map_to_corr->
GetXmax() <<
" "
76 << map_to_corr->
GetNx() << endl;
77 mapFile << map_to_corr->
GetYmin() <<
" " << map_to_corr->
GetYmax() <<
" "
78 << map_to_corr->
GetNy() << endl;
79 mapFile << map_to_corr->
GetZmin() <<
" " << map_to_corr->
GetZmax() <<
" "
80 << map_to_corr->
GetNz() << endl;
85 Int_t nTot = map_to_corr->
GetNx() * map_to_corr->
GetNy() * map_to_corr->
GetNz();
86 cout <<
"-I- PndFieldMap: " << map_to_corr->
GetNx() * map_to_corr->
GetNy() * map_to_corr->
GetNz() <<
" entries to write... "
87 << setw(3) << 0 <<
" % ";
95 for (
int x = 0;
x < map_to_corr->
GetNx();
x++) {
96 for (
int y = 0;
y < map_to_corr->
GetNy();
y++) {
97 for (
int z = 0;
z < map_to_corr->
GetNz();
z++) {
98 index =
x * map_to_corr->
GetNy() * map_to_corr->
GetNz() +
y
99 * map_to_corr->
GetNz() +
z;
100 double Bx1 = (*(map_to_corr->
GetBx()))[index];
101 double Bx2 = (*(map_to_interpol->
GetBx()))[index];
102 double By1 = (*(map_to_corr->
GetBy()))[index];
103 double By2 = (*(map_to_interpol->
GetBy()))[index];
104 double Bz1 = (*(map_to_corr->
GetBz()))[index];
105 double Bz2 = (*(map_to_interpol->
GetBz()))[index];
106 double new_Bx = (Bx2 - Bx1) * weight + Bx1;
107 double new_By = (By2 - By1) * weight + By1;
108 double new_Bz = (Bz2 - Bz1) * weight + Bz1;
111 modul = div(index, iDiv);
112 if (modul.rem == 0) {
114 cout <<
"\b\b\b\b\b\b" << setw(3) << perc <<
" % " << flush;
116 mapFile << new_Bx / factor <<
" " << new_By
117 / factor <<
" " << new_Bz / factor << endl;
129 cout <<
" " << index + 1 <<
" written" << endl;
138 cout <<
" moving ascii file " << fileName <<
" to the PANDAROOT input folder " << endl;
140 string dir = getenv(
"VMCWORKDIR");
141 string moveto = dir +
"/input/" + fileName +
".dat";
142 system((
"mv "+fileName+
".dat"+
" "+moveto).c_str());
143 cout <<
" converting ASCII files to ROOT files " << endl;
146 if (map_to_corr->GetType() == 3) {
147 fieldmap_converted =
new PndDipoleMap(fileName.c_str(),
"A");
150 if (map_to_corr->GetType() == 4) {
151 fieldmap_converted =
new PndTransMap (fileName.c_str(),
"A");
154 if (fieldmap_converted){
155 fieldmap_converted->
Init();
156 stringstream _filename;
157 _filename << fileName;
158 fieldmap_converted->
WriteRootFile((_filename.str()+
".root").c_str(),_filename.str().c_str());
159 cout <<
" converted " << map_to_corr->
GetNx() <<
" x " << map_to_corr->
GetNy() <<
" x " << map_to_corr->
GetNz() << endl;
160 cout <<
" to " << fieldmap_converted->
GetNx() <<
" x " << fieldmap_converted->
GetNy() <<
" x " << fieldmap_converted->
GetNz() << endl;
161 cout <<
" values " << endl;
163 cout <<
" creating comparison plots " << endl;
164 TH1F hist_relative_difference_Bx(
"relative_difference_Bx", (
"relative difference in Bx for map "+_filename.str()).c_str(), 1000, -1, 1);
165 TH1F hist_relative_difference_By(
"relative_difference_By", (
"relative difference in By for map "+_filename.str()).c_str(), 1000, -1, 1);
166 TH1F hist_relative_difference_Bz(
"relative_difference_Bz", (
"relative difference in Bz for map "+_filename.str()).c_str(), 1000, -1, 1);
167 for (
int x = 0;
x < map_to_corr->
GetNx();
x++) {
168 for (
int y = 0;
y < map_to_corr->
GetNy();
y++) {
169 for (
int z = 0;
z < map_to_corr->
GetNz();
z++) {
170 index =
x * map_to_corr->
GetNy() * map_to_corr->
GetNz() +
y
171 * map_to_corr->
GetNz() +
z;
172 double Bx1 = (*(map_to_corr->
GetBx()))[index];
173 double Bx2 = (*(fieldmap_converted->
GetBx()))[index];
174 double By1 = (*(map_to_corr->
GetBy()))[index];
175 double By2 = (*(fieldmap_converted->
GetBy()))[index];
176 double Bz1 = (*(map_to_corr->
GetBz()))[index];
177 double Bz2 = (*(fieldmap_converted->
GetBz()))[index];
185 hist_relative_difference_Bx.Fill(
gDBx/Bx1*100.);
186 hist_relative_difference_By.Fill(
gDBy/By1*100.);
187 hist_relative_difference_Bz.Fill(
gDBz/Bz1*100.);
188 modul = div(index, iDiv);
189 if (modul.rem == 0) {
191 cout <<
"\b\b\b\b\b\b" << setw(3) << perc <<
" % " << flush;
196 hist_relative_difference_Bx.Draw();
197 hist_relative_difference_Bx.SetXTitle(
"#Delta Bx/Bx [%]");
198 gPad->Print(
"relative_fieldmap_differences.ps(");
199 hist_relative_difference_By.Draw();
200 hist_relative_difference_By.SetXTitle(
"#Delta By/By [%]");
201 gPad->Print(
"relative_fieldmap_differences.ps(");
202 hist_relative_difference_Bz.Draw();
203 hist_relative_difference_Bz.SetXTitle(
"#Delta Bz/Bz [%]");
204 gPad->Print(
"relative_fieldmap_differences.ps(");
205 delete fieldmap_converted;
207 cout <<
" moving root file " << _filename.str()+
".root" <<
" to the PANDAROOT input folder " << endl;
208 string _moveto = dir +
"/input/" + _filename.str()+
".root";
209 system((
"mv "+_filename.str()+
".root"+
" "+_moveto).c_str());
222 map < string, string > momenta;
224 map<string, double> weight;
225 momenta[
"0150"] =
"0406";
226 weight[
"0150"] = -0.001;
227 momenta[
"0406"] =
"0150";
228 weight[
"0406"] = 0.00235;
229 momenta[
"0890"] =
"0406";
230 weight[
"0890"] = 0.0032;
231 momenta[
"1191"] =
"0890";
232 weight[
"1191"] = 0.0067;
233 momenta[
"1500"] =
"1191";
234 weight[
"1500"] = 0.0095;
236 map<string, PndDipoleMap*> dipolefieldmaps1;
237 map<string, PndDipoleMap*> dipolefieldmaps2;
238 map<string, PndTransMap*> transfieldmaps;
240 for (map<string, string>::iterator it = momenta.begin(); it
241 != momenta.end(); it++) {
242 string momentum = it->first;
244 (
"DipoleMap1." + (momentum)).c_str(),
"R");
245 dipolefieldmaps1[momentum]->Init();
247 (
"DipoleMap2." + (momentum)).c_str(),
"R");
248 dipolefieldmaps2[momentum]->Init();
250 (
"TransMap." + (momentum)).c_str(),
"R");
251 transfieldmaps[momentum]->Init();
259 TCanvas canvas(
"canvas",
"comparison plots", 600, 600);
261 TFile filetree(
"values.root",
"RECREATE");
273 for (map<string, string>::iterator it = momenta.begin(); it
274 != momenta.end(); it++) {
275 string momentum = it->first;
276 string interpol_mom = it->second;
277 cout <<
" interpolating maps for " << momentum << endl;
280 energy = atoi((it->first).c_str());
283 dipolefieldmaps1[interpol_mom], weight[momentum],
"DipoleMap1"+
name_modification+
"."+momentum);
286 dipolefieldmaps2[interpol_mom], weight[momentum],
"DipoleMap2"+
name_modification+
"."+momentum);
289 transfieldmaps[interpol_mom], weight[momentum],
"TransMap"+
name_modification+
"."+momentum);
293 canvas.Print(
"relative_fieldmap_differences.ps)");
297 map<string, string> drawpairs;
298 drawpairs[
"Bx"]=
"DBx";
299 drawpairs[
"By"]=
"DBy";
300 drawpairs[
"Bz"]=
"DBz";
301 for (map<string, string>::iterator it = momenta.begin(); it
302 != momenta.end(); it++) {
303 string momentum = it->first;
304 energy = atoi((it->first).c_str());
305 for (map<string, string>::iterator itB = drawpairs.begin(); itB != drawpairs.end(); itB++){
308 gtree_values->Draw((itB->first+
":"+itB->second).c_str(),(momentum+
"==energy&&field==31").c_str());
311 gtree_values->Draw((itB->first+
":"+itB->second).c_str(),(momentum+
"==energy&&field==32").c_str());
314 gtree_values->Draw((itB->first+
":"+itB->second).c_str(),(momentum+
"==energy&&field==40").c_str());
315 canvas.Print(
"correlation_histograms.ps(");
319 canvas.Print(
"correlation_histograms.ps)");
322 cout <<
"\n list of created field map names " << endl;
323 cout <<
" ********************************" << endl;
325 cout <<
" " << *it << endl;
327 cout <<
" ********************************" << endl;
330 #include<TApplication.h>
332 int main(
int argc,
char **argv) {
virtual Double_t GetBy(Double_t x, Double_t y, Double_t z)
int main(int argc, char **argv)
Double_t GetScale() const
void WriteRootFile(const char *fileName, const char *mapName)
const string name_modification
TTree * gtree_values(NULL)
void interpolate_fieldmaps()
void interpolate_fieldmap(PndFieldMap *map_to_corr, PndFieldMap *map_to_interpol, double weight, string fileName)
virtual Double_t GetBx(Double_t x, Double_t y, Double_t z)
virtual Double_t GetBz(Double_t x, Double_t y, Double_t z)
vector< string > fieldmapnames