5 #include <TObjString.h>
11 #include <G4UnitsTable.hh>
19 for(
int i = 0;
i < 3;
i++)
if(
mom(
i)*diff(
i) < 0) back =
false;
96 pdg = TDatabasePDG::Instance();
97 pdg -> ReadPDGTable();
110 _filter = TFormula(
"formula",
"1");
116 pdg = TDatabasePDG::Instance();
117 pdg -> ReadPDGTable();
120 std::cout <<
"PndRadMapBoxMesh::PndRadMapBoxMesh()\n"
224 pdg = TDatabasePDG::Instance();
225 pdg -> ReadPDGTable();
230 std::cout <<
"PndRadMapBoxMesh::~PndRadMapBoxMesh()\n";
238 std::cout <<
"PndRadMapBoxMesh::SetFilter(" << filter <<
")\n";
240 temps.ReplaceAll(
"Pid",
"x");
241 temps.ReplaceAll(
"Ch" ,
"y");
242 temps.ReplaceAll(
"Mom",
"z");
244 _filter = TFormula(
"formula", temps.Data());
249 std::cout <<
"PndRadMapBoxMesh::SetQuantity(" << Quantity <<
")\n";
257 std::cout <<
"PndRadMapBoxMesh::SetOrientation(" << plane <<
", " << rotate <<
", " << Ax <<
")\n";
266 std::cout <<
"PndRadMapBoxMesh::SetOrientation(" << rotate <<
", " << Ax <<
")\n";
268 _rotate = (rotate == 99999) ? 0 : rotate;
271 std::cout <<
"Volume[" <<
_Name.Data() <<
"][("
326 std::cout <<
"Volume: "
341 std::cout <<
"PndRadMapBoxMesh::Transform(" << X <<
", " << Y <<
", " << Z <<
")\n";
352 std::cout <<
"PndRadMapBoxMesh::Transform(" << X <<
", " << Y <<
", " << Z <<
")\n";
353 std::cout <<
" " << X0 <<
", " << Y0 <<
", " << Z0 <<
")\n";
357 X0 =
X; Y0 =
Y; Z0 =
Z;
387 Double_t rot0 = TMath::ATan(V1/V2)*TMath::RadToDeg();
388 if(V2 < 0) rot0 += 180;
454 std::cout <<
" -> PndRadMapBoxMesh::Transform(" << X <<
", " << Y <<
", " << Z <<
")\n";
455 std::cout <<
" " << X0 <<
", " << Y0 <<
", " << Z0 <<
")\n";
461 std::cout <<
"void PndRadMapBoxMesh::Fill(FairRadMapPoint *p)\n";
463 Int_t
pid = p->GetPdg();
465 (p->GetPy()*p->GetPy()) +
466 (p->GetPz()*p->GetPz()));
475 TVector3 poststepv, prestepv;
483 if(
_filter.Eval(pid, cha, mom)){
487 edep = p->GetEnergyLoss()*1.60217657*1e-10;
488 dens = p->GetDensity();
491 poststepv = TVector3(p->GetXOut(), p->GetYOut(), p->GetZOut());
492 prestepv = TVector3(p->GetX(), p->GetY(), p->GetZ());
498 std::cout <<
"Density: " << dens
499 <<
", mass: " << mass
503 <<
"charge: " << cha <<
"\n";
514 if(!std::isnan(val) && val !=0)
516 Fill(lX, lY, lZ, val);
521 if(!std::isnan(val) && val !=0){
523 Fill(lX, lY, lZ, val);
585 if(!std::isnan(val) && val !=0){
586 Fill(lX, lY, lZ, val);
593 if(!std::isnan(val) && val !=0){
594 Fill(lX, lY, lZ, val);
600 poststepv = TVector3(p->GetXOut(), p->GetYOut(), p->GetZOut());
601 prestepv = TVector3(p->GetX(), p->GetY(), p->GetZ());
602 val = (poststepv-prestepv).Mag()/1e2;
604 if(!std::isnan(val) && val!=0){
606 std::cout <<
"Pre: " << prestepv.X() <<
", " << prestepv.Y() <<
", " << prestepv.Z() <<
"\n";
607 std::cout <<
"Pre: " << poststepv.X() <<
", " << poststepv.Y() <<
", " << poststepv.Z() <<
"\n";
608 std::cout <<
"diff: " << (poststepv-prestepv).Mag() <<
"; val: " << val << std::endl;
609 std::cout <<
"volume: " <<
_volume <<
"\n\n";
611 Fill(lX, lY, lZ, val);
618 if(!std::isnan(val) && val !=0){
619 Fill(lX, lY, lZ, val);
636 std::cout <<
"PndRadMapBoxMesh::Fill(" << gBin <<
", " << val <<
")\n";
638 Int_t binX, binY, binZ;
639 _MeshHisto->GetBinXYZ(gBin, binX, binY, binZ);
640 Fill(binX, binY, binZ, val);
645 std::cout <<
"PndRadMapBoxMesh::Fill(" << X <<
", " << Y <<
", " << Z <<
", " << we <<
")\n";
690 std::cout <<
"PndRadMapBoxMesh::Scale(" << sca <<
")" << std::endl;
696 std::cout <<
"PndRadMapBoxMesh::GetHisto()\n";
702 std::cout <<
"PndRadMapBoxMesh::GetPlane()\n";
708 std::cout <<
"PndRadMapBoxMesh::Save(TFile* fout)\n";
711 TString dirname = ((TObjString*)toa->At(0))->GetString();
713 dirname += ((TObjString*)toa->At(2))->GetString().Data();
715 dirname += ((TObjString*)toa->At(3))->GetString().Data();
716 std::cout << dirname.Data() << std::endl;
720 fout->mkdir(dirname.Data());
721 fout->cd (dirname.Data());
730 std::cout <<
"PndRadMapBoxMesh::Save()\n";
738 std::cout <<
"PndRadMapBoxMesh::IsInside(" << X <<
", " << Y <<
", " << Z <<
")\n";
751 std::cout <<
"PndRadMapBoxMesh::IsInside()\n";
782 std::cout <<
"PndRadMapBoxMesh::IsInside(FairRadMapPoint *p)\n";
785 double xin, yin, zin, xout, yout, zout;
786 Transform(p->GetX(), p->GetY(), p->GetZ(),
788 Transform(p->GetXOut(), p->GetYOut(), p->GetZOut(),
810 std::cout <<
"PndRadMapBoxMesh::makeHisto(" << Orient <<
", " << rotate <<
",\n";
811 std::cout <<
" " << Hbins <<
", " << Hlow <<
", " << Hhigh <<
",\n";
812 std::cout <<
" " << Vbins <<
", " << Vlow <<
", " << Vhigh <<
")\n";
815 sprintf(C,
"%s_Histo_%s_%g",
_Name.Data(), Orient,
_rotate);
819 sprintf(C,
"%s_StatHisto_%s_%g",
_Name.Data(), Orient,
_rotate);
825 sprintf(C,
"%s_EnergyHisto_%s_%g",
_Name.Data(), Orient,
_rotate);
837 std::cout <<
"PndRadMapBoxMesh::CalcFluence(FairRadMapPoint *p)" << std::endl;
841 std::vector<Corner> CV;
842 std::vector<PndRadMapPlane> PV;
844 Transform(p->GetXOut(), p->GetYOut(), p->GetZOut(),
846 std::pair<int, double> minp;
847 bool OK=
false, OK2=
false;
863 TVector3 poststepv = TVector3(p->GetXOut(), p->GetYOut(), p->GetZOut());
864 TVector3 prestepv = TVector3(p->GetX(), p->GetY(), p->GetZ());
865 unsigned int prebin =
_MeshHisto->FindBin(prestepv.X(),
867 unsigned int postbin =
_MeshHisto->FindBin(poststepv.X(),
870 int prebinX = 0, prebinY = 0, prebinZ = 0;
871 int postbinX = 0, postbinY = 0, postbinZ = 0;
872 _MeshHisto->GetBinXYZ(postbin, postbinX, postbinY, postbinZ);
873 _MeshHisto->GetBinXYZ(prebin, prebinX, prebinY, prebinZ);
874 TVector3 tn(0, 0, 0);
876 if(
verbose) std::cout <<
"PndRadMapBoxMesh::CalcFluence - 1" << std::endl;
884 TVector3 isl, lbeg, lend;
885 double min_x, min_y, min_z, max_x, max_y, max_z;
890 if(
verbose) std::cout <<
"PndRadMapBoxMesh::CalcFluence - 2" << std::endl;
899 if(
verbose) std::cout <<
"min_z: " << min_z <<
' ' << max_z <<
' ' <<
dz << std::endl;
903 TVector3(max_x+dx, min_y+
dy, min_z+
dz),
904 TVector3(min_x+dx, max_y+
dy, min_z+
dz));
906 if(((min_x < isl.X()) && (isl.X() < max_x)) &&
907 ((min_y < isl.Y()) && (isl.Y() < max_y))){
911 std::cout <<
"Xcross1: " << min_x <<
' ' << isl.X() <<
' ' << max_x << std::endl;
912 std::cout <<
"Ycross1: " << min_y <<
' ' << isl.Y() <<
' ' << max_y << std::endl;
913 std::cout <<
"=> " << OK2 << std::endl;
918 TVector3(max_x+dx, min_y+
dy, max_z+
dz),
919 TVector3(min_x+dx, max_y+
dy, max_z+
dz));
921 if(((min_x < isl.X()) && (isl.X() < max_x)) &&
922 ((min_y < isl.Y()) && (isl.Y() < max_y))){
926 std::cout <<
"Xcross2: " << min_x <<
' ' << isl.X() <<
' ' << max_x << std::endl;
927 std::cout <<
"Ycross2: " << min_y <<
' ' << isl.Y() <<
' ' << max_y << std::endl;
928 std::cout <<
"=> " << OK2 << std::endl;
933 if(
verbose) std::cout <<
"PndRadMapBoxMesh::CalcFluence - 3" << std::endl;
940 _MeshHisto->GetBinXYZ(prebin, prebinX, prebinY, prebinZ);
941 _MeshHisto->GetBinXYZ(postbin, postbinX, postbinY, postbinZ);
943 if(
verbose) std::cout <<
"PndRadMapBoxMesh::CalcFluence - 4" << std::endl;
948 while((prebin != postbin) && !tn.Z()){
977 min_x = (
_MeshHisto->GetXaxis()->GetBinLowEdge(prebinX) < 0) ? 0 :
_MeshHisto->GetXaxis()->GetBinLowEdge(prebinX);
978 min_y = (
_MeshHisto->GetYaxis()->GetBinLowEdge(prebinY) < 0) ? 0 :
_MeshHisto->GetYaxis()->GetBinLowEdge(prebinY);
979 min_z = (
_MeshHisto->GetZaxis()->GetBinLowEdge(prebinZ) < 0) ? 0 :
_MeshHisto->GetZaxis()->GetBinLowEdge(prebinZ);
981 max_x = (
_MeshHisto->GetXaxis()->GetBinUpEdge(prebinX) < 0) ? 0 :
_MeshHisto->GetXaxis()->GetBinUpEdge(prebinX);
982 max_y = (
_MeshHisto->GetYaxis()->GetBinUpEdge(prebinY) < 0) ? 0 :
_MeshHisto->GetYaxis()->GetBinUpEdge(prebinY);
983 max_z = (
_MeshHisto->GetZaxis()->GetBinUpEdge(prebinZ) < 0) ? 0 :
_MeshHisto->GetZaxis()->GetBinUpEdge(prebinZ);
984 max_z +=
_MeshHisto->GetZaxis()->GetBinWidth(1);
987 std::cout << counter <<
" - Corners [[" << min_x <<
", " << min_y <<
", " << min_z <<
"] - ";
988 std::cout <<
"[" << max_x <<
", " << max_y <<
", " << max_z <<
"]]\n";
993 TVector3(min_x+dx, min_y+
dy, max_z+
dz),
994 TVector3(max_x+dx, min_y+
dy, min_z+
dz));
998 TVector3(max_x+dx, min_y+
dy, min_z+
dz),
999 TVector3(min_x+dx, max_y+
dy, min_z+
dz));
1000 PV.push_back(plane);
1003 TVector3(min_x+dx, min_y+
dy, max_z+
dz),
1004 TVector3(min_x+dx, max_y+
dy, min_z+
dz));
1005 PV.push_back(plane);
1008 TVector3(min_x+dx, max_y+
dy, max_z+
dz),
1009 TVector3(max_x+dx, max_y+
dy, min_z+
dz));
1010 PV.push_back(plane);
1013 TVector3(max_x+dx, min_y+
dy, max_z+
dz),
1014 TVector3(min_x+dx, max_y+
dy, max_z+
dz));
1015 PV.push_back(plane);
1018 TVector3(max_x+dx, min_y+
dy, max_z+
dz),
1019 TVector3(max_x+dx, max_y+
dy, min_z+
dz));
1020 PV.push_back(plane);
1023 std::cout <<
"Start\n["
1024 << prebin <<
" {" << prestepv.X() <<
' ' << prestepv.Y() <<
' ' << prestepv.Z() <<
"}("
1025 << prebinX <<
' ' << prebinY <<
' ' << prebinZ <<
")\n"
1026 <<
' ' << postbin <<
" {" << poststepv.X() <<
' ' << poststepv.Y() <<
' ' << poststepv.Z() <<
"}("
1027 << postbinX <<
' ' << postbinY <<
' ' << postbinZ <<
")]\n\n";
1029 minp = std::make_pair(-1, 111111);
1032 isl = PV.at(0).LineIntersection(prestepv, poststepv);
1033 if(
momentumfilter(TVector3(p->GetPx(), p->GetPy(), p->GetPz()), (isl-prestepv)))
1034 if(minp.second > (isl-prestepv).Mag())
1035 minp = std::make_pair(0, (isl-prestepv).Mag());
1037 std::cout <<
"XZ (" << (isl).
X() <<
", " << (isl).
Y() <<
", " << (isl).
Z() <<
") "
1038 << (poststepv-prestepv).Mag() <<
", "
1039 <<
"(" << (isl-prestepv).
X() <<
", " << (isl-prestepv).
Y() <<
", " << (isl-prestepv).
Z() <<
") "
1040 << (isl-prestepv).Mag() <<
' '
1041 <<
momentumfilter(TVector3(p->GetPx(), p->GetPy(), p->GetPz()), (isl-prestepv)) <<
' '
1042 << (minp.second > (isl-prestepv).Mag()) <<
' '
1043 <<
"[" << minp.first <<
", " << minp.second << std::endl;
1047 isl = PV.at(1).LineIntersection(prestepv, poststepv);
1048 if(
momentumfilter(TVector3(p->GetPx(), p->GetPy(), p->GetPz()), (isl-prestepv)))
1049 if(minp.second > (isl-prestepv).Mag())
1050 minp = std::make_pair(1, (isl-prestepv).Mag());
1052 std::cout <<
"XY (" << (isl).
X() <<
", " << (isl).
Y() <<
", " << (isl).
Z() <<
") "
1053 << (poststepv-prestepv).Mag() <<
", "
1054 <<
"(" << (isl-prestepv).
X() <<
", " << (isl-prestepv).
Y() <<
", " << (isl-prestepv).
Z() <<
") "
1055 << (isl-prestepv).Mag() <<
' '
1056 <<
momentumfilter(TVector3(p->GetPx(), p->GetPy(), p->GetPz()), (isl-prestepv)) <<
' '
1057 << (minp.second > (isl-prestepv).Mag()) <<
' '
1058 <<
"[" << minp.first <<
", " << minp.second <<
"]" << std::endl;
1061 isl = PV.at(2).LineIntersection(prestepv, poststepv);
1062 if(
momentumfilter(TVector3(p->GetPx(), p->GetPy(), p->GetPz()), (isl-prestepv)))
1063 if(minp.second > (isl-prestepv).Mag())
1064 minp = std::make_pair(2, (isl-prestepv).Mag());
1066 std::cout <<
"YZ (" << (isl).
X() <<
", " << (isl).
Y() <<
", " << (isl).
Z() <<
") "
1067 << (poststepv-prestepv).Mag() <<
", "
1068 <<
"(" << (isl-prestepv).
X() <<
", " << (isl-prestepv).
Y() <<
", " << (isl-prestepv).
Z() <<
") "
1069 << (isl-prestepv).Mag() <<
' '
1070 <<
momentumfilter(TVector3(p->GetPx(), p->GetPy(), p->GetPz()), (isl-prestepv)) <<
' '
1071 << (minp.second > (isl-prestepv).Mag()) <<
' '
1072 <<
"[" << minp.first <<
", " << minp.second <<
"]" << std::endl;
1074 isl = PV.at(3).LineIntersection(prestepv, poststepv);
1075 if(
momentumfilter(TVector3(p->GetPx(), p->GetPy(), p->GetPz()), (isl-prestepv)))
1076 if(minp.second > (isl-prestepv).Mag())
1077 minp = std::make_pair(3, (isl-prestepv).Mag());
1079 std::cout <<
"XZ (" << (isl).
X() <<
", " << (isl).
Y() <<
", " << (isl).
Z() <<
") "
1080 << (poststepv-prestepv).Mag() <<
", "
1081 <<
"(" << (isl-prestepv).
X() <<
", " << (isl-prestepv).
Y() <<
", " << (isl-prestepv).
Z() <<
") "
1082 << (isl-prestepv).Mag() <<
' '
1083 <<
momentumfilter(TVector3(p->GetPx(), p->GetPy(), p->GetPz()), (isl-prestepv)) <<
' '
1084 << (minp.second > (isl-prestepv).Mag()) <<
' '
1085 <<
"[" << minp.first <<
", " << minp.second <<
"]" << std::endl;
1088 isl = PV.at(4).LineIntersection(prestepv, poststepv);
1089 if(
momentumfilter(TVector3(p->GetPx(), p->GetPy(), p->GetPz()), (isl-prestepv)))
1090 if(minp.second > (isl-prestepv).Mag())
1091 minp = std::make_pair(4, (isl-prestepv).Mag());
1093 std::cout <<
"XY (" << (isl).
X() <<
", " << (isl).
Y() <<
", " << (isl).
Z() <<
") "
1094 << (poststepv-prestepv).Mag() <<
", "
1095 <<
"(" << (isl-prestepv).
X() <<
", " << (isl-prestepv).
Y() <<
", " << (isl-prestepv).
Z() <<
") "
1096 << (isl-prestepv).Mag() <<
' '
1097 <<
momentumfilter(TVector3(p->GetPx(), p->GetPy(), p->GetPz()), (isl-prestepv)) <<
' '
1098 << (minp.second > (isl-prestepv).Mag()) <<
' '
1099 <<
"[" << minp.first <<
", " << minp.second <<
"]" << std::endl;
1102 isl = PV.at(5).LineIntersection(prestepv, poststepv);
1103 if(
momentumfilter(TVector3(p->GetPx(), p->GetPy(), p->GetPz()), (isl-prestepv)))
1104 if(minp.second > (isl-prestepv).Mag())
1105 minp = std::make_pair(5, (isl-prestepv).Mag());
1107 std::cout <<
"YZ (" << (isl).
X() <<
", " << (isl).
Y() <<
", " << (isl).
Z() <<
") "
1108 << (poststepv-prestepv).Mag() <<
", "
1109 <<
"(" << (isl-prestepv).
X() <<
", " << (isl-prestepv).
Y() <<
", " << (isl-prestepv).
Z() <<
") "
1110 << (isl-prestepv).Mag() <<
' '
1111 <<
momentumfilter(TVector3(p->GetPx(), p->GetPy(), p->GetPz()), (isl-prestepv)) <<
' '
1112 << (minp.second > (isl-prestepv).Mag()) <<
' '
1113 <<
"[" << minp.first <<
", " << minp.second <<
"]" << std::endl;
1116 std::cout <<
"\nmomentum: "
1117 << p->GetPx() <<
' '
1118 << p->GetPy() <<
' '
1119 << p->GetPz() << std::endl;
1122 if(0 <= minp.first){
1124 std::cout <<
"\nmomentum: "
1125 << p->GetPx() <<
' '
1126 << p->GetPy() <<
' '
1127 << p->GetPz() << std::endl;
1128 std::cout <<
"[(----)] " << minp.first <<
' ' << minp.second << std::endl;
1129 std::cout <<
"normal: "
1130 << PV.at(minp.first).Normal().X() <<
' '
1131 << PV.at(minp.first).Normal().Y() <<
' '
1132 << PV.at(minp.first).Normal().Z() << std::endl;
1135 isl = PV.at(minp.first).LineIntersection(prestepv, poststepv);
1136 Double_t step = (isl-prestepv).Mag();
1139 _MeshHisto->Fill(prestepv.X(), prestepv.Y(), step);
1140 _StatHisto->Fill(prestepv.X(), prestepv.Y());
1142 tn = PV.at(minp.first).Normal();
1145 ds =
_MeshHisto->GetXaxis()->GetBinWidth(1)/10.;
1146 if(
verbose) std::cout <<
"Xprebin: " << prebin <<
" ---> ";
1150 if(
verbose) std::cout <<
"(" << isl.X() <<
" ---> " << isl.X() + ds <<
' ' << p->GetPx() <<
" ) ";
1154 if(
verbose) std::cout <<
"(" << isl.X() <<
" ---> " << isl.X() - ds <<
' ' << p->GetPx() <<
" ) ";
1156 if(
verbose) std::cout << prebin << std::endl;
1159 ds =
_MeshHisto->GetYaxis()->GetBinWidth(1)/10.;
1160 if(
verbose) std::cout <<
"Yprebin: " << prebin <<
" ---> ";
1164 if(
verbose) std::cout <<
"1(" << isl.Y() <<
" ---> " << isl.Y() + ds <<
" ) ";
1168 if(
verbose) std::cout <<
"1(" << isl.Y() <<
" ---> " << isl.Y() - ds <<
" ) ";
1170 if(
verbose) std::cout << prebin << std::endl;
1173 _MeshHisto->GetBinXYZ(prebin, prebinX, prebinY, prebinZ);
1174 if(
verbose) std::cout <<
"Stop\n["
1175 << prebin <<
" {" << prestepv.X() <<
' ' << prestepv.Y() <<
' ' << prestepv.Z() <<
"}("
1176 << prebinX <<
' ' << prebinY <<
' ' << prebinZ <<
")\n"
1177 <<
' ' << postbin <<
" {" << poststepv.X() <<
' ' << poststepv.Y() <<
' ' << poststepv.Z() <<
"}("
1178 << postbinX <<
' ' << postbinY <<
' ' << postbinZ <<
")]\n\n";
1180 if(
IsInside(p->GetX(), p->GetY(), p->GetZ())){
1181 if(
verbose) std::cout <<
" Bingo\n";
1195 for(
int i = 0;
i < 3;
i++){
1197 for(
int j = 0; j < 3; j++){
1198 val+=imat[
i][j]*vec[j];
1202 res = TVector3(resl[0], resl[1], resl[2]);
void InvMatVecProd(TMatrixD mat, TVector3 vec, TVector3 &res)
void makeHisto(const char *Orient, Double_t rotate, int Hbins, Double_t Hlow, Double_t Hhigh, int Vbins, Double_t Vlow, Double_t Vhigh, Double_t dlow)
void Fill(FairRadMapPoint *p)
Double_t val[nBoxes][nFEBox]
TVector3 LineIntersection(TVector3 begline, TVector3 endline)
static T Sqrt(const T &x)
Double_t CalcFluence(FairRadMapPoint *p)
void SetOrientation(orientation plane, Double_t rotate=99999, axis Ax=Xx)
void SetQuantity(quantity Quantity=Edep)
bool momentumfilter(TVector3 mom, TVector3 diff)
PndRadMapPlane * GetPlane()
void Transform(Double_t X, Double_t Y, Double_t Z)
void SetFilter(const char *filter)
void SetVerbosityLevel(int verbose=0)
TVector3 rotate(TVector3 vec, TGeoRotation *rotma)
TMatrixT< double > TMatrixD