LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
SpaceChargeStandard.cxx
Go to the documentation of this file.
1 // \file SpaceChargeStandard.cxx
3 //
4 // \brief implementation of class for storing/accessing space charge distortions (exists as an example, by default this does nothing, instead requiring experiment-specific implementation)
5 //
6 // \author mrmooney@bnl.gov
7 //
9 
10 // C++ language includes
11 #include <fstream>
12 
13 // LArSoft includes
15 
16 // Framework includes
18 #include "fhiclcpp/ParameterSet.h"
19 
20 // ROOT includes
21 #include "TFile.h"
22 #include "TGraph.h"
23 #include "TString.h"
24 
25 //-----------------------------------------------
27 {
28  Configure(pset);
29 }
30 
31 //------------------------------------------------
33 {
34  fEnableSimSpatialSCE = pset.get<bool>("EnableSimSpatialSCE");
35  fEnableSimEfieldSCE = pset.get<bool>("EnableSimEfieldSCE");
36  fEnableCalSpatialSCE = pset.get<bool>("EnableCalSpatialSCE");
37  fEnableCalEfieldSCE = pset.get<bool>("EnableCalEfieldSCE");
38  fEnableCorrSCE = pset.get<bool>("EnableCorrSCE");
39 
40  // check that the old obsoleted parameter is not in configuration:
41  if (pset.has_key("EnableSimulationSCE")) {
43  << "Configuration parameter 'EnableSimulationSCE' has been replaced by "
44  "'EnableSimSpatialSCE'.\n";
45  }
46 
47  if ((fEnableSimSpatialSCE == true) | (fEnableSimEfieldSCE == true)) {
48  fRepresentationType = pset.get<std::string>("RepresentationType");
49  fInputFilename = pset.get<std::string>("InputFilename");
50 
51  std::string fname;
52  cet::search_path sp("FW_SEARCH_PATH");
53  sp.find_file(fInputFilename, fname);
54 
55  auto infile = std::make_unique<TFile>(fname.c_str(), "READ");
56  if (!infile->IsOpen())
58  << "Could not find the space charge effect file '" << fname << "'!\n";
59 
60  if (fRepresentationType == "Parametric") {
61  for (int i = 0; i < 5; i++) {
62  g1_x[i] = (TGraph*)infile->Get(Form("deltaX/g1_%d", i));
63  g2_x[i] = (TGraph*)infile->Get(Form("deltaX/g2_%d", i));
64  g3_x[i] = (TGraph*)infile->Get(Form("deltaX/g3_%d", i));
65  g4_x[i] = (TGraph*)infile->Get(Form("deltaX/g4_%d", i));
66  g5_x[i] = (TGraph*)infile->Get(Form("deltaX/g5_%d", i));
67 
68  g1_y[i] = (TGraph*)infile->Get(Form("deltaY/g1_%d", i));
69  g2_y[i] = (TGraph*)infile->Get(Form("deltaY/g2_%d", i));
70  g3_y[i] = (TGraph*)infile->Get(Form("deltaY/g3_%d", i));
71  g4_y[i] = (TGraph*)infile->Get(Form("deltaY/g4_%d", i));
72  g5_y[i] = (TGraph*)infile->Get(Form("deltaY/g5_%d", i));
73  g6_y[i] = (TGraph*)infile->Get(Form("deltaY/g6_%d", i));
74 
75  g1_z[i] = (TGraph*)infile->Get(Form("deltaZ/g1_%d", i));
76  g2_z[i] = (TGraph*)infile->Get(Form("deltaZ/g2_%d", i));
77  g3_z[i] = (TGraph*)infile->Get(Form("deltaZ/g3_%d", i));
78  g4_z[i] = (TGraph*)infile->Get(Form("deltaZ/g4_%d", i));
79 
80  g1_Ex[i] = (TGraph*)infile->Get(Form("deltaExOverE/g1_%d", i));
81  g2_Ex[i] = (TGraph*)infile->Get(Form("deltaExOverE/g2_%d", i));
82  g3_Ex[i] = (TGraph*)infile->Get(Form("deltaExOverE/g3_%d", i));
83  g4_Ex[i] = (TGraph*)infile->Get(Form("deltaExOverE/g4_%d", i));
84  g5_Ex[i] = (TGraph*)infile->Get(Form("deltaExOverE/g5_%d", i));
85 
86  g1_Ey[i] = (TGraph*)infile->Get(Form("deltaEyOverE/g1_%d", i));
87  g2_Ey[i] = (TGraph*)infile->Get(Form("deltaEyOverE/g2_%d", i));
88  g3_Ey[i] = (TGraph*)infile->Get(Form("deltaEyOverE/g3_%d", i));
89  g4_Ey[i] = (TGraph*)infile->Get(Form("deltaEyOverE/g4_%d", i));
90  g5_Ey[i] = (TGraph*)infile->Get(Form("deltaEyOverE/g5_%d", i));
91  g6_Ey[i] = (TGraph*)infile->Get(Form("deltaEyOverE/g6_%d", i));
92 
93  g1_Ez[i] = (TGraph*)infile->Get(Form("deltaEzOverE/g1_%d", i));
94  g2_Ez[i] = (TGraph*)infile->Get(Form("deltaEzOverE/g2_%d", i));
95  g3_Ez[i] = (TGraph*)infile->Get(Form("deltaEzOverE/g3_%d", i));
96  g4_Ez[i] = (TGraph*)infile->Get(Form("deltaEzOverE/g4_%d", i));
97  }
98 
99  g1_x[5] = (TGraph*)infile->Get("deltaX/g1_5");
100  g2_x[5] = (TGraph*)infile->Get("deltaX/g2_5");
101  g3_x[5] = (TGraph*)infile->Get("deltaX/g3_5");
102  g4_x[5] = (TGraph*)infile->Get("deltaX/g4_5");
103  g5_x[5] = (TGraph*)infile->Get("deltaX/g5_5");
104 
105  g1_y[5] = (TGraph*)infile->Get("deltaY/g1_5");
106  g2_y[5] = (TGraph*)infile->Get("deltaY/g2_5");
107  g3_y[5] = (TGraph*)infile->Get("deltaY/g3_5");
108  g4_y[5] = (TGraph*)infile->Get("deltaY/g4_5");
109  g5_y[5] = (TGraph*)infile->Get("deltaY/g5_5");
110  g6_y[5] = (TGraph*)infile->Get("deltaY/g6_5");
111 
112  g1_x[6] = (TGraph*)infile->Get("deltaX/g1_6");
113  g2_x[6] = (TGraph*)infile->Get("deltaX/g2_6");
114  g3_x[6] = (TGraph*)infile->Get("deltaX/g3_6");
115  g4_x[6] = (TGraph*)infile->Get("deltaX/g4_6");
116  g5_x[6] = (TGraph*)infile->Get("deltaX/g5_6");
117 
118  g1_Ex[5] = (TGraph*)infile->Get("deltaExOverE/g1_5");
119  g2_Ex[5] = (TGraph*)infile->Get("deltaExOverE/g2_5");
120  g3_Ex[5] = (TGraph*)infile->Get("deltaExOverE/g3_5");
121  g4_Ex[5] = (TGraph*)infile->Get("deltaExOverE/g4_5");
122  g5_Ex[5] = (TGraph*)infile->Get("deltaExOverE/g5_5");
123 
124  g1_Ey[5] = (TGraph*)infile->Get("deltaEyOverE/g1_5");
125  g2_Ey[5] = (TGraph*)infile->Get("deltaEyOverE/g2_5");
126  g3_Ey[5] = (TGraph*)infile->Get("deltaEyOverE/g3_5");
127  g4_Ey[5] = (TGraph*)infile->Get("deltaEyOverE/g4_5");
128  g5_Ey[5] = (TGraph*)infile->Get("deltaEyOverE/g5_5");
129  g6_Ey[5] = (TGraph*)infile->Get("deltaEyOverE/g6_5");
130 
131  g1_Ex[6] = (TGraph*)infile->Get("deltaExOverE/g1_6");
132  g2_Ex[6] = (TGraph*)infile->Get("deltaExOverE/g2_6");
133  g3_Ex[6] = (TGraph*)infile->Get("deltaExOverE/g3_6");
134  g4_Ex[6] = (TGraph*)infile->Get("deltaExOverE/g4_6");
135  g5_Ex[6] = (TGraph*)infile->Get("deltaExOverE/g5_6");
136  }
137 
138  infile->Close();
139  }
140 
141  if (fEnableCorrSCE == true) {
142  // Grab other parameters from pset
143  }
144 
145  return true;
146 }
147 
148 //------------------------------------------------
150 {
151  if (ts == 0) return false;
152 
153  return true;
154 }
155 
156 //----------------------------------------------------------------------------
160 {
161  return fEnableSimSpatialSCE;
162 }
163 
164 //----------------------------------------------------------------------------
168 {
169  return fEnableSimEfieldSCE;
170 }
171 
172 //----------------------------------------------------------------------------
175 {
176  return fEnableCorrSCE;
177 }
178 
181 {
182  return fEnableCalSpatialSCE;
183 }
184 
187 {
188  return fEnableCalEfieldSCE;
189 }
190 
191 //----------------------------------------------------------------------------
195 {
196  std::vector<double> thePosOffsets;
197 
198  if (IsInsideBoundaries(point.X(), point.Y(), point.Z()) == false) {
199  thePosOffsets.resize(3, 0.0);
200  }
201  else {
202  if (fRepresentationType == "Parametric")
203  thePosOffsets = GetPosOffsetsParametric(point.X(), point.Y(), point.Z());
204  else
205  thePosOffsets.resize(3, 0.0);
206  }
207 
208  return {thePosOffsets[0], thePosOffsets[1], thePosOffsets[2]};
209 }
210 
212  int const& TPCid) const
213 {
214 
215  return {0., 0., 0.};
216 }
217 
218 //----------------------------------------------------------------------------
221  double yVal,
222  double zVal) const
223 {
224  std::vector<double> thePosOffsetsParametric;
225 
226  double xValNew = TransformX(xVal);
227  double yValNew = TransformY(yVal);
228  double zValNew = TransformZ(zVal);
229 
230  thePosOffsetsParametric.push_back(GetOnePosOffsetParametric(xValNew, yValNew, zValNew, "X"));
231  thePosOffsetsParametric.push_back(GetOnePosOffsetParametric(xValNew, yValNew, zValNew, "Y"));
232  thePosOffsetsParametric.push_back(GetOnePosOffsetParametric(xValNew, yValNew, zValNew, "Z"));
233 
234  return thePosOffsetsParametric;
235 }
236 
237 //----------------------------------------------------------------------------
241  double yValNew,
242  double zValNew,
243  std::string axis) const
244 {
245  double parA[6][7];
246  double parB[6];
247 
248  for (int j = 0; j < 6; j++) {
249  for (int i = 0; i < 7; i++)
250  parA[j][i] = 0.0;
251 
252  parB[j] = 0.0;
253  }
254 
255  if (axis == "X") {
256  for (int j = 0; j < 7; j++) {
257  parA[0][j] = g1_x[j]->Eval(zValNew);
258  parA[1][j] = g2_x[j]->Eval(zValNew);
259  parA[2][j] = g3_x[j]->Eval(zValNew);
260  parA[3][j] = g4_x[j]->Eval(zValNew);
261  parA[4][j] = g5_x[j]->Eval(zValNew);
262  }
263 
264  f1_x->SetParameters(parA[0]);
265  f2_x->SetParameters(parA[1]);
266  f3_x->SetParameters(parA[2]);
267  f4_x->SetParameters(parA[3]);
268  f5_x->SetParameters(parA[4]);
269  }
270  else if (axis == "Y") {
271  for (int j = 0; j < 6; j++) {
272  parA[0][j] = g1_y[j]->Eval(zValNew);
273  parA[1][j] = g2_y[j]->Eval(zValNew);
274  parA[2][j] = g3_y[j]->Eval(zValNew);
275  parA[3][j] = g4_y[j]->Eval(zValNew);
276  parA[4][j] = g5_y[j]->Eval(zValNew);
277  parA[5][j] = g6_y[j]->Eval(zValNew);
278  }
279 
280  f1_y->SetParameters(parA[0]);
281  f2_y->SetParameters(parA[1]);
282  f3_y->SetParameters(parA[2]);
283  f4_y->SetParameters(parA[3]);
284  f5_y->SetParameters(parA[4]);
285  f6_y->SetParameters(parA[5]);
286  }
287  else if (axis == "Z") {
288  for (int j = 0; j < 5; j++) {
289  parA[0][j] = g1_z[j]->Eval(zValNew);
290  parA[1][j] = g2_z[j]->Eval(zValNew);
291  parA[2][j] = g3_z[j]->Eval(zValNew);
292  parA[3][j] = g4_z[j]->Eval(zValNew);
293  }
294 
295  f1_z->SetParameters(parA[0]);
296  f2_z->SetParameters(parA[1]);
297  f3_z->SetParameters(parA[2]);
298  f4_z->SetParameters(parA[3]);
299  }
300 
301  double aValNew;
302  double bValNew;
303 
304  if (axis == "Y") {
305  aValNew = xValNew;
306  bValNew = yValNew;
307  }
308  else {
309  aValNew = yValNew;
310  bValNew = xValNew;
311  }
312 
313  double offsetValNew = 0.0;
314  if (axis == "X") {
315  parB[0] = f1_x->Eval(aValNew);
316  parB[1] = f2_x->Eval(aValNew);
317  parB[2] = f3_x->Eval(aValNew);
318  parB[3] = f4_x->Eval(aValNew);
319  parB[4] = f5_x->Eval(aValNew);
320 
321  fFinal_x->SetParameters(parB);
322  offsetValNew = 100.0 * fFinal_x->Eval(bValNew);
323  }
324  else if (axis == "Y") {
325  parB[0] = f1_y->Eval(aValNew);
326  parB[1] = f2_y->Eval(aValNew);
327  parB[2] = f3_y->Eval(aValNew);
328  parB[3] = f4_y->Eval(aValNew);
329  parB[4] = f5_y->Eval(aValNew);
330  parB[5] = f6_y->Eval(aValNew);
331 
332  fFinal_y->SetParameters(parB);
333  offsetValNew = 100.0 * fFinal_y->Eval(bValNew);
334  }
335  else if (axis == "Z") {
336  parB[0] = f1_z->Eval(aValNew);
337  parB[1] = f2_z->Eval(aValNew);
338  parB[2] = f3_z->Eval(aValNew);
339  parB[3] = f4_z->Eval(aValNew);
340 
341  fFinal_z->SetParameters(parB);
342  offsetValNew = 100.0 * fFinal_z->Eval(bValNew);
343  }
344 
345  return offsetValNew;
346 }
347 
348 //----------------------------------------------------------------------------
352 {
353  std::vector<double> theEfieldOffsets;
354 
355  if (fRepresentationType == "Parametric")
356  theEfieldOffsets = GetEfieldOffsetsParametric(point.X(), point.Y(), point.Z());
357  else
358  theEfieldOffsets.resize(3, 0.0);
359 
360  return {-theEfieldOffsets[0], -theEfieldOffsets[1], -theEfieldOffsets[2]};
361 }
362 
364  int const& TPCid) const
365 {
366 
367  return {0., 0., 0.};
368 }
369 
370 //----------------------------------------------------------------------------
373  double yVal,
374  double zVal) const
375 {
376  std::vector<double> theEfieldOffsetsParametric;
377 
378  double xValNew = TransformX(xVal);
379  double yValNew = TransformY(yVal);
380  double zValNew = TransformZ(zVal);
381 
382  theEfieldOffsetsParametric.push_back(
383  GetOneEfieldOffsetParametric(xValNew, yValNew, zValNew, "X"));
384  theEfieldOffsetsParametric.push_back(
385  GetOneEfieldOffsetParametric(xValNew, yValNew, zValNew, "Y"));
386  theEfieldOffsetsParametric.push_back(
387  GetOneEfieldOffsetParametric(xValNew, yValNew, zValNew, "Z"));
388 
389  return theEfieldOffsetsParametric;
390 }
391 
392 //----------------------------------------------------------------------------
396  double yValNew,
397  double zValNew,
398  std::string axis) const
399 {
400  double parA[6][7];
401  double parB[6];
402 
403  for (int j = 0; j < 6; j++) {
404  for (int i = 0; i < 7; i++)
405  parA[j][i] = 0.0;
406 
407  parB[j] = 0.0;
408  }
409 
410  if (axis == "X") {
411  for (int j = 0; j < 7; j++) {
412  parA[0][j] = g1_Ex[j]->Eval(zValNew);
413  parA[1][j] = g2_Ex[j]->Eval(zValNew);
414  parA[2][j] = g3_Ex[j]->Eval(zValNew);
415  parA[3][j] = g4_Ex[j]->Eval(zValNew);
416  parA[4][j] = g5_Ex[j]->Eval(zValNew);
417  }
418 
419  f1_Ex->SetParameters(parA[0]);
420  f2_Ex->SetParameters(parA[1]);
421  f3_Ex->SetParameters(parA[2]);
422  f4_Ex->SetParameters(parA[3]);
423  f5_Ex->SetParameters(parA[4]);
424  }
425  else if (axis == "Y") {
426  for (int j = 0; j < 6; j++) {
427  parA[0][j] = g1_Ey[j]->Eval(zValNew);
428  parA[1][j] = g2_Ey[j]->Eval(zValNew);
429  parA[2][j] = g3_Ey[j]->Eval(zValNew);
430  parA[3][j] = g4_Ey[j]->Eval(zValNew);
431  parA[4][j] = g5_Ey[j]->Eval(zValNew);
432  parA[5][j] = g6_Ey[j]->Eval(zValNew);
433  }
434 
435  f1_Ey->SetParameters(parA[0]);
436  f2_Ey->SetParameters(parA[1]);
437  f3_Ey->SetParameters(parA[2]);
438  f4_Ey->SetParameters(parA[3]);
439  f5_Ey->SetParameters(parA[4]);
440  f6_Ey->SetParameters(parA[5]);
441  }
442  else if (axis == "Z") {
443  for (int j = 0; j < 5; j++) {
444  parA[0][j] = g1_Ez[j]->Eval(zValNew);
445  parA[1][j] = g2_Ez[j]->Eval(zValNew);
446  parA[2][j] = g3_Ez[j]->Eval(zValNew);
447  parA[3][j] = g4_Ez[j]->Eval(zValNew);
448  }
449 
450  f1_Ez->SetParameters(parA[0]);
451  f2_Ez->SetParameters(parA[1]);
452  f3_Ez->SetParameters(parA[2]);
453  f4_Ez->SetParameters(parA[3]);
454  }
455 
456  double aValNew;
457  double bValNew;
458 
459  if (axis == "Y") {
460  aValNew = xValNew;
461  bValNew = yValNew;
462  }
463  else {
464  aValNew = yValNew;
465  bValNew = xValNew;
466  }
467 
468  double offsetValNew = 0.0;
469  if (axis == "X") {
470  parB[0] = f1_Ex->Eval(aValNew);
471  parB[1] = f2_Ex->Eval(aValNew);
472  parB[2] = f3_Ex->Eval(aValNew);
473  parB[3] = f4_Ex->Eval(aValNew);
474  parB[4] = f5_Ex->Eval(aValNew);
475 
476  fFinal_Ex->SetParameters(parB);
477  offsetValNew = fFinal_Ex->Eval(bValNew);
478  }
479  else if (axis == "Y") {
480  parB[0] = f1_Ey->Eval(aValNew);
481  parB[1] = f2_Ey->Eval(aValNew);
482  parB[2] = f3_Ey->Eval(aValNew);
483  parB[3] = f4_Ey->Eval(aValNew);
484  parB[4] = f5_Ey->Eval(aValNew);
485  parB[5] = f6_Ey->Eval(aValNew);
486 
487  fFinal_Ey->SetParameters(parB);
488  offsetValNew = fFinal_Ey->Eval(bValNew);
489  }
490  else if (axis == "Z") {
491  parB[0] = f1_Ez->Eval(aValNew);
492  parB[1] = f2_Ez->Eval(aValNew);
493  parB[2] = f3_Ez->Eval(aValNew);
494  parB[3] = f4_Ez->Eval(aValNew);
495 
496  fFinal_Ez->SetParameters(parB);
497  offsetValNew = fFinal_Ez->Eval(bValNew);
498  }
499 
500  return offsetValNew;
501 }
502 
503 //----------------------------------------------------------------------------
506 {
507  double xValNew;
508  xValNew = xVal / 100.0;
509 
510  return xValNew;
511 }
512 
513 //----------------------------------------------------------------------------
516 {
517  double yValNew;
518  yValNew = yVal / 100.0;
519 
520  return yValNew;
521 }
522 
523 //----------------------------------------------------------------------------
526 {
527  double zValNew;
528  zValNew = zVal / 100.0;
529 
530  return zValNew;
531 }
532 
533 //----------------------------------------------------------------------------
536  double yVal,
537  double zVal) const
538 {
539  bool isInside = false;
540 
541  return isInside;
542 }
bool IsInsideBoundaries(double xVal, double yVal, double zVal) const
Check to see if point is inside boundaries of map - redefine this in experiment-specific implementati...
std::vector< double > GetEfieldOffsetsParametric(double xVal, double yVal, double zVal) const
Provides E field offsets using a parametric representation.
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space.
Definition: geo_vectors.h:160
geo::Vector_t GetCalEfieldOffsets(geo::Point_t const &point, int const &TPCid) const override
double GetOnePosOffsetParametric(double xVal, double yVal, double zVal, std::string axis) const
std::vector< double > GetPosOffsetsParametric(double xVal, double yVal, double zVal) const
Provides position offsets using a parametric representation.
double TransformY(double yVal) const
Transform Y to SCE Y coordinate - redefine this in experiment-specific implementation! ...
bool EnableCalSpatialSCE() const override
Return boolean indicating whether or not to apply SCE corrections.
SpaceChargeStandard(fhicl::ParameterSet const &pset)
double TransformX(double xVal) const
Transform X to SCE X coordinate - redefine this in experiment-specific implementation! ...
geo::Vector_t GetEfieldOffsets(geo::Point_t const &point) const override
T get(std::string const &key) const
Definition: ParameterSet.h:314
double TransformZ(double zVal) const
Transform Z to SCE Z coordinate - redefine this in experiment-specific implementation! ...
bool has_key(std::string const &key) const
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
Definition: geo_vectors.h:180
geo::Vector_t GetPosOffsets(geo::Point_t const &point) const override
bool EnableCorrSCE() const override
Return boolean indicating whether or not to apply SCE corrections.
bool EnableCalEfieldSCE() const override
Return boolean indicating whether or not to apply SCE corrections.
geo::Vector_t GetCalPosOffsets(geo::Point_t const &point, int const &TPCid) const override
bool Configure(fhicl::ParameterSet const &pset)
double GetOneEfieldOffsetParametric(double xVal, double yVal, double zVal, std::string axis) const