17 #include "canvas/Utilities/Exception.h"
18 #include "fhiclcpp/ParameterSet.h"
27 fhicl::ParameterSet
const& pset
36 fEnableSimSpatialSCE = pset.get<
bool>(
"EnableSimSpatialSCE");
37 fEnableSimEfieldSCE = pset.get<
bool>(
"EnableSimEfieldSCE");
38 fEnableCalSpatialSCE = pset.get<
bool>(
"EnableCalSpatialSCE");
39 fEnableCalEfieldSCE = pset.get<
bool>(
"EnableCalEfieldSCE");
40 fEnableCorrSCE = pset.get<
bool>(
"EnableCorrSCE");
43 if (pset.has_key(
"EnableSimulationSCE")) {
44 throw art::Exception(art::errors::Configuration)
45 <<
"Configuration parameter 'EnableSimulationSCE' has been replaced by 'EnableSimSpatialSCE'.\n";
48 if((fEnableSimSpatialSCE ==
true) | (fEnableSimEfieldSCE ==
true))
50 fRepresentationType = pset.get<std::string>(
"RepresentationType");
51 fInputFilename = pset.get<std::string>(
"InputFilename");
54 cet::search_path sp(
"FW_SEARCH_PATH");
55 sp.find_file(fInputFilename,fname);
57 auto infile = std::make_unique<TFile>(fname.c_str(),
"READ");
58 if(!infile->IsOpen())
throw art::Exception(art::errors::Configuration) <<
"Could not find the space charge effect file '" << fname <<
"'!\n";
60 if(fRepresentationType ==
"Parametric")
62 for(
int i = 0; i < 5; i++)
64 g1_x[i] = (TGraph*)infile->Get(Form(
"deltaX/g1_%d",i));
65 g2_x[i] = (TGraph*)infile->Get(Form(
"deltaX/g2_%d",i));
66 g3_x[i] = (TGraph*)infile->Get(Form(
"deltaX/g3_%d",i));
67 g4_x[i] = (TGraph*)infile->Get(Form(
"deltaX/g4_%d",i));
68 g5_x[i] = (TGraph*)infile->Get(Form(
"deltaX/g5_%d",i));
70 g1_y[i] = (TGraph*)infile->Get(Form(
"deltaY/g1_%d",i));
71 g2_y[i] = (TGraph*)infile->Get(Form(
"deltaY/g2_%d",i));
72 g3_y[i] = (TGraph*)infile->Get(Form(
"deltaY/g3_%d",i));
73 g4_y[i] = (TGraph*)infile->Get(Form(
"deltaY/g4_%d",i));
74 g5_y[i] = (TGraph*)infile->Get(Form(
"deltaY/g5_%d",i));
75 g6_y[i] = (TGraph*)infile->Get(Form(
"deltaY/g6_%d",i));
77 g1_z[i] = (TGraph*)infile->Get(Form(
"deltaZ/g1_%d",i));
78 g2_z[i] = (TGraph*)infile->Get(Form(
"deltaZ/g2_%d",i));
79 g3_z[i] = (TGraph*)infile->Get(Form(
"deltaZ/g3_%d",i));
80 g4_z[i] = (TGraph*)infile->Get(Form(
"deltaZ/g4_%d",i));
82 g1_Ex[i] = (TGraph*)infile->Get(Form(
"deltaExOverE/g1_%d",i));
83 g2_Ex[i] = (TGraph*)infile->Get(Form(
"deltaExOverE/g2_%d",i));
84 g3_Ex[i] = (TGraph*)infile->Get(Form(
"deltaExOverE/g3_%d",i));
85 g4_Ex[i] = (TGraph*)infile->Get(Form(
"deltaExOverE/g4_%d",i));
86 g5_Ex[i] = (TGraph*)infile->Get(Form(
"deltaExOverE/g5_%d",i));
88 g1_Ey[i] = (TGraph*)infile->Get(Form(
"deltaEyOverE/g1_%d",i));
89 g2_Ey[i] = (TGraph*)infile->Get(Form(
"deltaEyOverE/g2_%d",i));
90 g3_Ey[i] = (TGraph*)infile->Get(Form(
"deltaEyOverE/g3_%d",i));
91 g4_Ey[i] = (TGraph*)infile->Get(Form(
"deltaEyOverE/g4_%d",i));
92 g5_Ey[i] = (TGraph*)infile->Get(Form(
"deltaEyOverE/g5_%d",i));
93 g6_Ey[i] = (TGraph*)infile->Get(Form(
"deltaEyOverE/g6_%d",i));
95 g1_Ez[i] = (TGraph*)infile->Get(Form(
"deltaEzOverE/g1_%d",i));
96 g2_Ez[i] = (TGraph*)infile->Get(Form(
"deltaEzOverE/g2_%d",i));
97 g3_Ez[i] = (TGraph*)infile->Get(Form(
"deltaEzOverE/g3_%d",i));
98 g4_Ez[i] = (TGraph*)infile->Get(Form(
"deltaEzOverE/g4_%d",i));
101 g1_x[5] = (TGraph*)infile->Get(
"deltaX/g1_5");
102 g2_x[5] = (TGraph*)infile->Get(
"deltaX/g2_5");
103 g3_x[5] = (TGraph*)infile->Get(
"deltaX/g3_5");
104 g4_x[5] = (TGraph*)infile->Get(
"deltaX/g4_5");
105 g5_x[5] = (TGraph*)infile->Get(
"deltaX/g5_5");
107 g1_y[5] = (TGraph*)infile->Get(
"deltaY/g1_5");
108 g2_y[5] = (TGraph*)infile->Get(
"deltaY/g2_5");
109 g3_y[5] = (TGraph*)infile->Get(
"deltaY/g3_5");
110 g4_y[5] = (TGraph*)infile->Get(
"deltaY/g4_5");
111 g5_y[5] = (TGraph*)infile->Get(
"deltaY/g5_5");
112 g6_y[5] = (TGraph*)infile->Get(
"deltaY/g6_5");
114 g1_x[6] = (TGraph*)infile->Get(
"deltaX/g1_6");
115 g2_x[6] = (TGraph*)infile->Get(
"deltaX/g2_6");
116 g3_x[6] = (TGraph*)infile->Get(
"deltaX/g3_6");
117 g4_x[6] = (TGraph*)infile->Get(
"deltaX/g4_6");
118 g5_x[6] = (TGraph*)infile->Get(
"deltaX/g5_6");
120 g1_Ex[5] = (TGraph*)infile->Get(
"deltaExOverE/g1_5");
121 g2_Ex[5] = (TGraph*)infile->Get(
"deltaExOverE/g2_5");
122 g3_Ex[5] = (TGraph*)infile->Get(
"deltaExOverE/g3_5");
123 g4_Ex[5] = (TGraph*)infile->Get(
"deltaExOverE/g4_5");
124 g5_Ex[5] = (TGraph*)infile->Get(
"deltaExOverE/g5_5");
126 g1_Ey[5] = (TGraph*)infile->Get(
"deltaEyOverE/g1_5");
127 g2_Ey[5] = (TGraph*)infile->Get(
"deltaEyOverE/g2_5");
128 g3_Ey[5] = (TGraph*)infile->Get(
"deltaEyOverE/g3_5");
129 g4_Ey[5] = (TGraph*)infile->Get(
"deltaEyOverE/g4_5");
130 g5_Ey[5] = (TGraph*)infile->Get(
"deltaEyOverE/g5_5");
131 g6_Ey[5] = (TGraph*)infile->Get(
"deltaEyOverE/g6_5");
133 g1_Ex[6] = (TGraph*)infile->Get(
"deltaExOverE/g1_6");
134 g2_Ex[6] = (TGraph*)infile->Get(
"deltaExOverE/g2_6");
135 g3_Ex[6] = (TGraph*)infile->Get(
"deltaExOverE/g3_6");
136 g4_Ex[6] = (TGraph*)infile->Get(
"deltaExOverE/g4_6");
137 g5_Ex[6] = (TGraph*)infile->Get(
"deltaExOverE/g5_6");
143 if(fEnableCorrSCE ==
true)
154 if (ts == 0)
return false;
164 return fEnableSimSpatialSCE;
172 return fEnableSimEfieldSCE;
179 return fEnableCorrSCE;
185 return fEnableCalSpatialSCE;
191 return fEnableCalEfieldSCE;
199 std::vector<double> thePosOffsets;
201 if(IsInsideBoundaries(point.X(), point.Y(), point.Z()) ==
false)
203 thePosOffsets.resize(3,0.0);
207 if(fRepresentationType ==
"Parametric")
208 thePosOffsets = GetPosOffsetsParametric(point.X(), point.Y(), point.Z());
210 thePosOffsets.resize(3,0.0);
213 return { thePosOffsets[0], thePosOffsets[1], thePosOffsets[2] };
226 std::vector<double> thePosOffsetsParametric;
228 double xValNew = TransformX(xVal);
229 double yValNew = TransformY(yVal);
230 double zValNew = TransformZ(zVal);
232 thePosOffsetsParametric.push_back(GetOnePosOffsetParametric(xValNew,yValNew,zValNew,
"X"));
233 thePosOffsetsParametric.push_back(GetOnePosOffsetParametric(xValNew,yValNew,zValNew,
"Y"));
234 thePosOffsetsParametric.push_back(GetOnePosOffsetParametric(xValNew,yValNew,zValNew,
"Z"));
236 return thePosOffsetsParametric;
247 for(
int j = 0; j < 6; j++)
249 for(
int i = 0; i < 7; i++)
257 for(
int j = 0; j < 7; j++)
259 parA[0][j] = g1_x[j]->Eval(zValNew);
260 parA[1][j] = g2_x[j]->Eval(zValNew);
261 parA[2][j] = g3_x[j]->Eval(zValNew);
262 parA[3][j] = g4_x[j]->Eval(zValNew);
263 parA[4][j] = g5_x[j]->Eval(zValNew);
266 f1_x->SetParameters(parA[0]);
267 f2_x->SetParameters(parA[1]);
268 f3_x->SetParameters(parA[2]);
269 f4_x->SetParameters(parA[3]);
270 f5_x->SetParameters(parA[4]);
274 for(
int j = 0; j < 6; j++)
276 parA[0][j] = g1_y[j]->Eval(zValNew);
277 parA[1][j] = g2_y[j]->Eval(zValNew);
278 parA[2][j] = g3_y[j]->Eval(zValNew);
279 parA[3][j] = g4_y[j]->Eval(zValNew);
280 parA[4][j] = g5_y[j]->Eval(zValNew);
281 parA[5][j] = g6_y[j]->Eval(zValNew);
284 f1_y->SetParameters(parA[0]);
285 f2_y->SetParameters(parA[1]);
286 f3_y->SetParameters(parA[2]);
287 f4_y->SetParameters(parA[3]);
288 f5_y->SetParameters(parA[4]);
289 f6_y->SetParameters(parA[5]);
293 for(
int j = 0; j < 5; j++)
295 parA[0][j] = g1_z[j]->Eval(zValNew);
296 parA[1][j] = g2_z[j]->Eval(zValNew);
297 parA[2][j] = g3_z[j]->Eval(zValNew);
298 parA[3][j] = g4_z[j]->Eval(zValNew);
301 f1_z->SetParameters(parA[0]);
302 f2_z->SetParameters(parA[1]);
303 f3_z->SetParameters(parA[2]);
304 f4_z->SetParameters(parA[3]);
321 double offsetValNew = 0.0;
324 parB[0] = f1_x->Eval(aValNew);
325 parB[1] = f2_x->Eval(aValNew);
326 parB[2] = f3_x->Eval(aValNew);
327 parB[3] = f4_x->Eval(aValNew);
328 parB[4] = f5_x->Eval(aValNew);
330 fFinal_x->SetParameters(parB);
331 offsetValNew = 100.0*fFinal_x->Eval(bValNew);
335 parB[0] = f1_y->Eval(aValNew);
336 parB[1] = f2_y->Eval(aValNew);
337 parB[2] = f3_y->Eval(aValNew);
338 parB[3] = f4_y->Eval(aValNew);
339 parB[4] = f5_y->Eval(aValNew);
340 parB[5] = f6_y->Eval(aValNew);
342 fFinal_y->SetParameters(parB);
343 offsetValNew = 100.0*fFinal_y->Eval(bValNew);
347 parB[0] = f1_z->Eval(aValNew);
348 parB[1] = f2_z->Eval(aValNew);
349 parB[2] = f3_z->Eval(aValNew);
350 parB[3] = f4_z->Eval(aValNew);
352 fFinal_z->SetParameters(parB);
353 offsetValNew = 100.0*fFinal_z->Eval(bValNew);
364 std::vector<double> theEfieldOffsets;
366 if(fRepresentationType ==
"Parametric")
367 theEfieldOffsets = GetEfieldOffsetsParametric(point.X(), point.Y(), point.Z());
369 theEfieldOffsets.resize(3,0.0);
371 return { -theEfieldOffsets[0], -theEfieldOffsets[1], -theEfieldOffsets[2] };
384 std::vector<double> theEfieldOffsetsParametric;
386 double xValNew = TransformX(xVal);
387 double yValNew = TransformY(yVal);
388 double zValNew = TransformZ(zVal);
390 theEfieldOffsetsParametric.push_back(GetOneEfieldOffsetParametric(xValNew,yValNew,zValNew,
"X"));
391 theEfieldOffsetsParametric.push_back(GetOneEfieldOffsetParametric(xValNew,yValNew,zValNew,
"Y"));
392 theEfieldOffsetsParametric.push_back(GetOneEfieldOffsetParametric(xValNew,yValNew,zValNew,
"Z"));
394 return theEfieldOffsetsParametric;
405 for(
int j = 0; j < 6; j++)
407 for(
int i = 0; i < 7; i++)
415 for(
int j = 0; j < 7; j++)
417 parA[0][j] = g1_Ex[j]->Eval(zValNew);
418 parA[1][j] = g2_Ex[j]->Eval(zValNew);
419 parA[2][j] = g3_Ex[j]->Eval(zValNew);
420 parA[3][j] = g4_Ex[j]->Eval(zValNew);
421 parA[4][j] = g5_Ex[j]->Eval(zValNew);
424 f1_Ex->SetParameters(parA[0]);
425 f2_Ex->SetParameters(parA[1]);
426 f3_Ex->SetParameters(parA[2]);
427 f4_Ex->SetParameters(parA[3]);
428 f5_Ex->SetParameters(parA[4]);
432 for(
int j = 0; j < 6; j++)
434 parA[0][j] = g1_Ey[j]->Eval(zValNew);
435 parA[1][j] = g2_Ey[j]->Eval(zValNew);
436 parA[2][j] = g3_Ey[j]->Eval(zValNew);
437 parA[3][j] = g4_Ey[j]->Eval(zValNew);
438 parA[4][j] = g5_Ey[j]->Eval(zValNew);
439 parA[5][j] = g6_Ey[j]->Eval(zValNew);
442 f1_Ey->SetParameters(parA[0]);
443 f2_Ey->SetParameters(parA[1]);
444 f3_Ey->SetParameters(parA[2]);
445 f4_Ey->SetParameters(parA[3]);
446 f5_Ey->SetParameters(parA[4]);
447 f6_Ey->SetParameters(parA[5]);
451 for(
int j = 0; j < 5; j++)
453 parA[0][j] = g1_Ez[j]->Eval(zValNew);
454 parA[1][j] = g2_Ez[j]->Eval(zValNew);
455 parA[2][j] = g3_Ez[j]->Eval(zValNew);
456 parA[3][j] = g4_Ez[j]->Eval(zValNew);
459 f1_Ez->SetParameters(parA[0]);
460 f2_Ez->SetParameters(parA[1]);
461 f3_Ez->SetParameters(parA[2]);
462 f4_Ez->SetParameters(parA[3]);
479 double offsetValNew = 0.0;
482 parB[0] = f1_Ex->Eval(aValNew);
483 parB[1] = f2_Ex->Eval(aValNew);
484 parB[2] = f3_Ex->Eval(aValNew);
485 parB[3] = f4_Ex->Eval(aValNew);
486 parB[4] = f5_Ex->Eval(aValNew);
488 fFinal_Ex->SetParameters(parB);
489 offsetValNew = fFinal_Ex->Eval(bValNew);
493 parB[0] = f1_Ey->Eval(aValNew);
494 parB[1] = f2_Ey->Eval(aValNew);
495 parB[2] = f3_Ey->Eval(aValNew);
496 parB[3] = f4_Ey->Eval(aValNew);
497 parB[4] = f5_Ey->Eval(aValNew);
498 parB[5] = f6_Ey->Eval(aValNew);
500 fFinal_Ey->SetParameters(parB);
501 offsetValNew = fFinal_Ey->Eval(bValNew);
505 parB[0] = f1_Ez->Eval(aValNew);
506 parB[1] = f2_Ez->Eval(aValNew);
507 parB[2] = f3_Ez->Eval(aValNew);
508 parB[3] = f4_Ez->Eval(aValNew);
510 fFinal_Ez->SetParameters(parB);
511 offsetValNew = fFinal_Ez->Eval(bValNew);
522 xValNew = xVal/100.0;
532 yValNew = yVal/100.0;
542 zValNew = zVal/100.0;
551 bool isInside =
false;
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...
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space.
std::vector< double > GetEfieldOffsetsParametric(double xVal, double yVal, double zVal) const
Provides E field offsets using a parametric representation.
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.
bool EnableSimEfieldSCE() const override
bool EnableCalEfieldSCE() const override
Return boolean indicating whether or not to apply SCE corrections.
double TransformY(double yVal) const
Transform Y to SCE Y coordinate - redefine this in experiment-specific implementation! ...
SpaceChargeStandard(fhicl::ParameterSet const &pset)
double TransformX(double xVal) const
Transform X to SCE X coordinate - redefine this in experiment-specific implementation! ...
bool EnableSimSpatialSCE() const override
bool Update(uint64_t ts=0)
double TransformZ(double zVal) const
Transform Z to SCE Z coordinate - redefine this in experiment-specific implementation! ...
geo::Vector_t GetPosOffsets(geo::Point_t const &point) const override
geo::Vector_t GetCalPosOffsets(geo::Point_t const &point, int const &TPCid) const override
bool EnableCorrSCE() const override
Return boolean indicating whether or not to apply SCE corrections.
bool EnableCalSpatialSCE() const override
Return boolean indicating whether or not to apply SCE corrections.
geo::Vector_t GetCalEfieldOffsets(geo::Point_t const &point, int const &TPCid) const override
geo::Vector_t GetEfieldOffsets(geo::Point_t const &point) const override
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
bool Configure(fhicl::ParameterSet const &pset)
double GetOneEfieldOffsetParametric(double xVal, double yVal, double zVal, std::string axis) const