24 #include "cetlib_except/exception.h" 58 std::cout<<
"Efield : "<<fEfield<<
std::endl;
92 std::unique_ptr<TFile>
infile(
new TFile(fname.c_str(),
"READ"));
93 if(!infile->IsOpen())
throw cet::exception(
"SpaceChargeProtoDUNEdp") <<
"Could not find the space charge effect file '" << fname <<
"'!\n";
100 TH3F* hEndPoint_sim_orig;
102 hDx_sim_orig= (TH3F*)infile->Get(
"hDeltaLength");
103 hDy_sim_orig = (TH3F*)infile->Get(
"hEndPointDY");
104 hEndPoint_sim_orig = (TH3F*)infile->Get(
"hEndPointX");
105 Anodebin = hEndPoint_sim_orig->GetXaxis()->GetXmax();
108 hDx_sim_orig= (TH3F*)infile->Get(
"hEndPointDX");
109 hDy_sim_orig = (TH3F*)infile->Get(
"hDeltaLength");
110 hEndPoint_sim_orig = (TH3F*)infile->Get(
"hEndPointY");
111 Anodebin = hEndPoint_sim_orig->GetYaxis()->GetXmax();
116 TH3F* hDz_sim_orig = (TH3F*)infile->Get(
"hEndPointDZ");
117 TH3F* hEx_sim_orig = (TH3F*)infile->Get(
"hEx");
118 TH3F* hEy_sim_orig = (TH3F*)infile->Get(
"hEy");
119 TH3F* hEz_sim_orig = (TH3F*)infile->Get(
"hEz");
123 TH3F* hEndPointDrift_sim = (TH3F*) hEndPoint_sim_orig->Clone(
"hEndPointDrift");
125 TH3F* hDx_sim = (TH3F*)hDx_sim_orig->Clone(
"hDx_sim");
126 TH3F* hDy_sim = (TH3F*)hDy_sim_orig->Clone(
"hDy_sim");
127 TH3F* hDz_sim = (TH3F*)hDz_sim_orig->Clone(
"hDz_sim");
128 TH3F* hEx_sim = (TH3F*)hEx_sim_orig->Clone(
"hEx_sim");
129 TH3F* hEy_sim = (TH3F*)hEy_sim_orig->Clone(
"hEy_sim");
130 TH3F* hEz_sim = (TH3F*)hEz_sim_orig->Clone(
"hEz_sim");
132 hEndPointDrift_sim->SetDirectory(0);
134 hDx_sim->SetDirectory(0);
135 hDy_sim->SetDirectory(0);
136 hDz_sim->SetDirectory(0);
137 hEx_sim->SetDirectory(0);
138 hEy_sim->SetDirectory(0);
139 hEz_sim->SetDirectory(0);
143 SCEhistograms = {hDx_sim, hDy_sim, hDz_sim, hEx_sim, hEy_sim, hEz_sim, hEndPointDrift_sim};
148 fEnableCalEfieldSCE =
false;
149 fEnableCalSpatialSCE =
false;
151 if((fEnableCalSpatialSCE ==
true) || (fEnableCalEfieldSCE ==
true))
162 std::unique_ptr<TFile> calinfile(
new TFile(fname.c_str(),
"READ"));
163 if(!calinfile->IsOpen())
throw cet::exception(
"SpaceChargeProtoDUNEdp") <<
"Could not find the space charge effect calibration file '" << fname <<
"'!\n";
165 TH3F* hDx_cal_orig = (TH3F*)calinfile->Get(
"hoffsetX");
166 TH3F* hDy_cal_orig = (TH3F*)calinfile->Get(
"hoffsetY");
167 TH3F* hDz_cal_orig = (TH3F*)calinfile->Get(
"hoffsetZ");
169 TH3F* hEx_cal_orig = (TH3F*)calinfile->Get(
"hEx");
170 TH3F* hEy_cal_orig = (TH3F*)calinfile->Get(
"hEy");
171 TH3F* hEz_cal_orig = (TH3F*)calinfile->Get(
"hEz");
175 TH3F* hDx_cal = (TH3F*)hDx_cal_orig->Clone(
"hDx_cal");
176 TH3F* hDy_cal = (TH3F*)hDy_cal_orig->Clone(
"hDy_cal");
177 TH3F* hDz_cal = (TH3F*)hDz_cal_orig->Clone(
"hDz_cal");
178 TH3F* hEx_cal = (TH3F*)hEx_cal_orig->Clone(
"hEx_cal");
179 TH3F* hEy_cal = (TH3F*)hEy_cal_orig->Clone(
"hEy_cal");
180 TH3F* hEz_cal = (TH3F*)hEz_cal_orig->Clone(
"hEz_cal");
182 hDx_cal->SetDirectory(0);
183 hDy_cal->SetDirectory(0);
184 hDz_cal->SetDirectory(0);
185 hEx_cal->SetDirectory(0);
186 hEy_cal->SetDirectory(0);
187 hEz_cal->SetDirectory(0);
205 if (ts == 0)
return false;
246 std::vector<double> thePosOffsets;
247 geo::Point_t point = {tmp_point.X(), tmp_point.Y(), tmp_point.Z()};
269 return {-thePosOffsets[0], thePosOffsets[1], thePosOffsets[2] };
272 return {thePosOffsets[0], -thePosOffsets[1], thePosOffsets[2] };
279 return {9999999,9999999,9999999 };
289 std::vector<double> thePosOffsets;
299 return { thePosOffsets[0], thePosOffsets[1], thePosOffsets[2] };
307 if( ax->GetNbins()==1)
return true;
308 if( v<= ax->GetBinCenter(1) )
return true;
310 if( v>= ax->GetBinCenter(ax->GetNbins()) )
return true;
330 int binx = hist->GetXaxis()->FindBin(x);
331 int biny = hist->GetYaxis()->FindBin(y);
332 int binz = hist->GetZaxis()->FindBin(z);
336 double xcenter =
IsBorder(hist->GetXaxis(),
x) ? hist->GetXaxis()->GetBinCenter(binx) :
x;
337 double ycenter =
IsBorder(hist->GetYaxis(),
y) ? hist->GetYaxis()->GetBinCenter(biny) :
y;
338 double zcenter =
IsBorder(hist->GetZaxis(),
z) ? hist->GetZaxis()->GetBinCenter(binz) :
z;
340 int Nx = hist->GetXaxis()->GetNbins();
341 int Ny = hist->GetYaxis()->GetNbins();
342 int Nz = hist->GetZaxis()->GetNbins();
349 if(x==xcenter &&
IsBorder(hist->GetXaxis(),
x)){
350 int binx2 = (binx==Nx) ? binx-1 : 2;
351 xcenter = 0.5*(hist->GetXaxis()->GetBinCenter(binx2)+
x);
353 if(y==ycenter&&
IsBorder(hist->GetYaxis(),
y)){
354 int biny2 = (biny==Ny) ? biny-1 : 2;
355 ycenter = 0.5*(hist->GetYaxis()->GetBinCenter(biny2)+
y);
357 if(z==zcenter&&
IsBorder(hist->GetZaxis(),
z)){
358 int binz2 = (binz==Nz) ? binz-1 : 2;
359 zcenter = 0.5*(hist->GetZaxis()->GetBinCenter(binz2)+
z);
369 double xa =
IsBorder(hist->GetXaxis(),
x) ? 0.5*(xcenter+xb) :
x;
370 double ya =
IsBorder(hist->GetYaxis(),
y) ? 0.5*(ycenter+yb) :
y;
371 double za =
IsBorder(hist->GetZaxis(),
z) ? 0.5*(zcenter+zb) :
z;
373 double valb = hist->Interpolate(xb, yb, zb);
374 double vala = hist->Interpolate(xa, ya, za);
378 if(
IsBorder(hist->GetXaxis(),
x)) Nedges = Nedges+1.;
379 if(
IsBorder(hist->GetYaxis(),
y)) Nedges = Nedges+1.;
380 if(
IsBorder(hist->GetZaxis(),
z)) Nedges = Nedges+1.;
384 double delta = vala - valb;
386 double dx =
IsBorder(hist->GetXaxis(),
x) ? xa-xb : 1;
387 double dy =
IsBorder(hist->GetYaxis(),
y) ? ya-yb : 1;
388 double dz =
IsBorder(hist->GetZaxis(),
z) ? za-zb : 1;
390 val = x*delta/dx + (xa*valb - xb*vala)/dx
391 + y*delta/dy + (ya*valb - yb*vala)/dy
392 + z*delta/dz + (za*valb - zb*vala)/dz;
402 if(point.X()> hist->GetXaxis()->GetBinLowEdge(0) &&
403 point.X()< hist->GetXaxis()->GetBinLowEdge(hist->GetXaxis()->GetNbins()+1) &&
404 point.Y()> hist->GetYaxis()->GetBinLowEdge(0) &&
405 point.Y()< hist->GetYaxis()->GetBinLowEdge(hist->GetYaxis()->GetNbins()+1) &&
406 point.Z()> hist->GetZaxis()->GetBinLowEdge(0) &&
407 point.Z()< hist->GetZaxis()->GetBinLowEdge(hist->GetZaxis()->GetNbins()+1) ){
416 if(point.X()> hist->GetXaxis()->GetBinCenter(1) &&
417 point.X()< hist->GetXaxis()->GetBinCenter(hist->GetXaxis()->GetNbins()) &&
418 point.Y()> hist->GetYaxis()->GetBinCenter(1) &&
419 point.Y()< hist->GetYaxis()->GetBinCenter(hist->GetYaxis()->GetNbins()) &&
420 point.Z()> hist->GetZaxis()->GetBinCenter(1) &&
421 point.Z()< hist->GetZaxis()->GetBinCenter(hist->GetZaxis()->GetNbins()) ){
437 hX->Interpolate(point.X(),point.Y(),point.Z()),
438 hY->Interpolate(point.X(),point.Y(),point.Z()),
439 hZ->Interpolate(point.X(),point.Y(),point.Z())
451 return {0.0,0.0,0.0};
465 std::vector<double> theEfieldOffsets;
466 geo::Point_t point = {tmp_point.X(), tmp_point.Y(), tmp_point.Z()};
489 theEfieldOffsets[0]= theEfieldOffsets[0]/(-1000.0);
490 theEfieldOffsets[1]= theEfieldOffsets[1]/(-1000.0);
491 theEfieldOffsets[2]= theEfieldOffsets[2]/(-1000.0);
494 theEfieldOffsets[0]=theEfieldOffsets[0]-
fEfield;
497 theEfieldOffsets[1]=theEfieldOffsets[1]-
fEfield;
499 std::cout<<
" Problem with drift field coordiate system for Efield calculation "<<
std::endl;
501 theEfieldOffsets[0]= theEfieldOffsets[0]/(
fEfield);
502 theEfieldOffsets[1]= theEfieldOffsets[1]/(
fEfield);
503 theEfieldOffsets[2]= theEfieldOffsets[2]/(
fEfield);
513 return { theEfieldOffsets[0], theEfieldOffsets[1], theEfieldOffsets[2] };
523 std::vector<double> theEfieldOffsets;
535 return { -theEfieldOffsets[0], -theEfieldOffsets[1], -theEfieldOffsets[2] };
geo::Vector_t GetCalEfieldOffsets(geo::Point_t const &point, int const &TPCid) const override
bool Configure(fhicl::ParameterSet const &pset, detinfo::DetectorPropertiesData const &)
bool EnableCalEfieldSCE() const override
Return boolean indicating whether or not to apply SCE corrections.
short int driftcoordinate
SpaceChargeProtoDUNEdp(fhicl::ParameterSet const &pset)
geo::Vector_t GetCalPosOffsets(geo::Point_t const &point, int const &TPCid) const override
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space.
art framework interface to geometry description
double Efield(unsigned int planegap=0) const
kV/cm
std::string fInputFilename
double GetSymmetric(double x, double xc)
std::vector< double > GetOffsetsVoxel(geo::Point_t const &point, TH3F *hX, TH3F *hY, TH3F *hZ) const
Provides position offsets using voxelized interpolation.
bool isWithinHistOuter(geo::Point_t const &point, TH3F *hist)
bool Update(uint64_t ts=0)
T get(std::string const &key) const
geo::Vector_t GetPosOffsets(geo::Point_t const &point) const override
double ExtrapolateAtEdge(TH3F *hist, double x, double y, double z)
bool EnableSimSpatialSCE() const override
bool fEnableCalSpatialSCE
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
bool isWithinHist(geo::Point_t const &point, TH3F *hist)
short int DetectDriftDirection() const
Returns the expected drift direction based on geometry.
bool fEnableSimSpatialSCE
std::string find_file(std::string const &filename) const
std::string fCalInputFilename
std::vector< TH3F * > SCEhistograms
std::vector< TH3F * > CalSCEhistograms
geo::Vector_t GetEfieldOffsets(geo::Point_t const &point) const override
TPCGeo const & TPC(unsigned int const tpc=0, unsigned int const cstat=0) const
Returns the specified TPC.
bool EnableSimEfieldSCE() const override
cet::coded_exception< error, detail::translate > exception
QTextStream & endl(QTextStream &s)
bool IsBorder(TAxis *ax, double v)
bool EnableCalSpatialSCE() const override
Return boolean indicating whether or not to apply SCE corrections.