173 std::vector<std::vector<TVector3>> allIntersections;
174 std::vector<TLorentzVector> allHMom;
176 for (
unsigned i = 0; i <=
fNThrows; i++) {
178 std::vector<TVector3> box_intersections =
fBox.
GetIntersections(flux.pos.Vect(), mevprtl_mom.Vect().Unit());
181 if (box_intersections.size() != 2) {
185 TVector3
A = box_intersections[0];
188 if (mevprtl_mom.Vect().Unit().Dot((A - flux.pos.Vect()).Unit()) < 0.) {
189 std::cout <<
"RAYTRACE: MeVPrtl points wrong way" << std::endl;
190 std::cout <<
"Pos: " << flux.pos.X() <<
" " << flux.pos.Y() <<
" " << flux.pos.Z() << std::endl;
191 std::cout <<
"A: " << A.X() <<
" " << A.Y() <<
" " << A.Z() << std::endl;
192 std::cout <<
"P: " << mevprtl_mom.Vect().Unit().X() <<
" " << mevprtl_mom.Vect().Unit().Y() <<
" " << mevprtl_mom.Vect().Unit().Z() << std::endl;
197 allIntersections.push_back(box_intersections);
198 allHMom.push_back(mevprtl_mom);
201 std::cout <<
"Prtl intersected (" << allIntersections.size() <<
" / " <<
fNThrows <<
") times.\n";
204 if (allIntersections.size() == 0) {
208 unsigned ind = CLHEP::RandFlat::shootInt(
fEngine, 0, allIntersections.size()-1);
210 TLorentzVector mevprtl_mom = allHMom[ind];
211 std::vector<TVector3> box_intersections = allIntersections[ind];
213 TVector3 A = box_intersections[0];
214 TVector3 B = box_intersections[1];
217 if ((flux.pos.Vect() -
A).Mag() < (A-B).Mag() && (flux.pos.Vect() - B).Mag() < (A-B).Mag()) {
218 throw cet::exception(
"ReThrowRayTraceBox Exception",
"Input mevprtl flux starts inside detector volume: "
226 weight = (double)allIntersections.size() /
fNThrows;
227 flux.mom = mevprtl_mom;
229 flux.mom_beamcoord = mevprtl_mom;
230 flux.mom_beamcoord.Boost(-flux.kmom.BoostVector());
231 flux.mom_beamcoord.Boost(flux.kmom_beamcoord.BoostVector());
235 flux.sec = flux.kmom - flux.mom;
236 flux.sec_beamcoord = flux.kmom_beamcoord - flux.mom_beamcoord;
238 if ((flux.pos.Vect() -
A).Mag() < (flux.pos.Vect() - B).Mag()) {
239 intersection = {
A, B};
242 intersection = {B, A};
245 std::cout <<
"Kaon 4P: " << flux.kmom.E() <<
" " << flux.kmom.Px() <<
" " << flux.kmom.Py() <<
" " << flux.kmom.Pz() << std::endl;
246 std::cout <<
"Selected Prtl 4P: " << flux.mom.E() <<
" " << flux.mom.Px() <<
" " << flux.mom.Py() <<
" " << flux.mom.Pz() << std::endl;
247 std::cout <<
"Selected Scdy 4P: " << flux.sec.E() <<
" " << flux.sec.Px() <<
" " << flux.sec.Py() <<
" " << flux.sec.Pz() << std::endl;
CLHEP::HepRandomEngine * fEngine
TLorentzVector ThrowMeVPrtlMomentum(const MeVPrtlFlux &flux)
std::string to_string(WindowPattern const &pattern)
std::vector< TVector3 > GetIntersections(TVector3 const &TrajectoryStart, TVector3 const &TrajectoryDirect) const
Calculates the entry and exit points of a trajectory on the box surface.
BEGIN_PROLOG could also be cout