LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
fluxr::DK2NuInterface Class Reference

#include "DK2NuInterface.h"

Inheritance diagram for fluxr::DK2NuInterface:
fluxr::FluxInterface

Public Member Functions

Long64_t GetEntries () const
 
int GetRun () const
 
float GetPOT () const
 
TLorentzVector GetNuPosition () const
 
TLorentzVector GetNuMomentum () const
 
void SetRootFile (TFile *rootFile)
 
bool FillMCFlux (Long64_t ientry, simb::MCFlux &mcflux)
 
bsim::Dk2Nu * GetDk2Nu ()
 
bsim::NuChoice * GetNuChoice ()
 
void Init (fhicl::ParameterSet const &ps)
 
void User2BeamPos (const TLorentzVector &usrxyz, TLorentzVector &beamxyz) const
 
void Beam2UserPos (const TLorentzVector &beamxyz, TLorentzVector &usrxyz) const
 
void Beam2UserP4 (const TLorentzVector &beamp4, TLorentzVector &usrp4) const
 
TVector3 AnglesToAxis (double theta, double phi)
 

Private Attributes

TTree * fDk2NuTree
 
TTree * fDkMetaTree
 
bsim::Dk2Nu * fDk2Nu
 
bsim::DkMeta * fDkMeta
 
bsim::NuChoice * fNuChoice
 
Long64_t fNEntries
 
int fRun
 
float fPOT
 
TLorentzVector fNuPos
 
TLorentzVector fNuMom
 
TRotation fBeamRotXML
 
TRotation fTempRot
 
TLorentzRotation fBeamRot
 
TLorentzRotation fBeamRotInv
 
TVector3 fBeamPosXML
 
TLorentzVector fBeamZero
 
TVector3 detAV_rand_user
 
TLorentzVector fRandUser
 
TLorentzVector fRandBeam
 

Detailed Description

Definition at line 20 of file DK2NuInterface.h.

Member Function Documentation

TVector3 fluxr::DK2NuInterface::AnglesToAxis ( double  theta,
double  phi 
)

Definition at line 161 of file DK2NuInterface.cxx.

Referenced by GetNuChoice(), and Init().

162  {
163  //theta,phi in rad
164  double xyz[3];
165  xyz[0] = TMath::Cos(phi) * TMath::Sin(theta);
166  xyz[1] = TMath::Sin(phi) * TMath::Sin(theta);
167  xyz[2] = TMath::Cos(theta);
168  // condition vector to eliminate most floating point errors
169  for (int i = 0; i < 3; ++i) {
170  const double eps = 1.0e-15;
171  if (TMath::Abs(xyz[i]) < eps) xyz[i] = 0;
172  if (TMath::Abs(xyz[i] - 1) < eps) xyz[i] = 1;
173  if (TMath::Abs(xyz[i] + 1) < eps) xyz[i] = -1;
174  }
175  return TVector3(xyz[0], xyz[1], xyz[2]);
176  }
void fluxr::DK2NuInterface::Beam2UserP4 ( const TLorentzVector &  beamp4,
TLorentzVector &  usrp4 
) const

Definition at line 156 of file DK2NuInterface.cxx.

References fBeamRot.

Referenced by FillMCFlux(), and GetNuChoice().

157  {
158  usrp4 = fBeamRot * beamp4;
159  }
TLorentzRotation fBeamRot
void fluxr::DK2NuInterface::Beam2UserPos ( const TLorentzVector &  beamxyz,
TLorentzVector &  usrxyz 
) const

Definition at line 152 of file DK2NuInterface.cxx.

References fBeamRot, and fBeamZero.

Referenced by FillMCFlux(), and GetNuChoice().

153  {
154  usrxyz = fBeamRot * beamxyz + fBeamZero;
155  }
TLorentzVector fBeamZero
TLorentzRotation fBeamRot
bool fluxr::DK2NuInterface::FillMCFlux ( Long64_t  ientry,
simb::MCFlux mcflux 
)
virtual

Implements fluxr::FluxInterface.

Definition at line 178 of file DK2NuInterface.cxx.

References Beam2UserP4(), Beam2UserPos(), simb::MCFlux::fdk2gen, fDk2Nu, fDk2NuTree, simb::MCFlux::fevtno, simb::MCFlux::fmupare, simb::MCFlux::fmuparpx, simb::MCFlux::fmuparpy, simb::MCFlux::fmuparpz, simb::MCFlux::fndecay, simb::MCFlux::fnecm, simb::MCFlux::fnenergyf, simb::MCFlux::fnenergyn, simb::MCFlux::fnimpwt, simb::MCFlux::fntype, fNuChoice, fNuMom, fNuPos, simb::MCFlux::fnwtfar, simb::MCFlux::fnwtnear, simb::MCFlux::fpdpx, simb::MCFlux::fpdpy, simb::MCFlux::fpdpz, simb::MCFlux::fppdxdz, simb::MCFlux::fppdydz, simb::MCFlux::fppmedium, simb::MCFlux::fpppz, simb::MCFlux::fptype, fRandBeam, simb::MCFlux::frun, simb::MCFlux::ftgen, simb::MCFlux::ftgptype, simb::MCFlux::ftptype, simb::MCFlux::ftpx, simb::MCFlux::ftpy, simb::MCFlux::ftpz, simb::MCFlux::fvx, simb::MCFlux::fvy, and simb::MCFlux::fvz.

Referenced by GetNuMomentum().

180  {
181  if (!fDk2NuTree->GetEntry(ientry)) return false;
182 
183  // error handling
184  // Veto the neutrons and unphysical muon decay
185  // Returns default mcflux with nu id = -999
186  if (fDk2Nu->decay.ptype == 2112) return true;
187  if ((fDk2Nu->decay.ptype == 13 || fDk2Nu->decay.ptype == -13) &&
188  (fDk2Nu->decay.ntype == 14 || fDk2Nu->decay.ntype == -14)) {
189  // Calculate xnu
190  double xnu = (2 * fDk2Nu->decay.necm) / 0.105658389; //
191  if (xnu > 1) return true;
192  }
193 
194  // bypass flux window method in favor of random point in detector
195  TLorentzVector x4beam = fRandBeam;
196 
197  // enu = resulting energy when the neutrino is redirected
198  // wgt = output probability weight
199  double enu, wgt;
200  bsim::calcEnuWgt(fDk2Nu, x4beam.Vect(), enu, wgt);
201 
202  TLorentzVector x4usr;
203  Beam2UserPos(x4beam, x4usr);
204 
205  bsim::NuRay rndnuray = fDk2Nu->nuray[0];
206  fDk2Nu->nuray.clear();
207 
208  TVector3 xyzDk(fDk2Nu->decay.vx, fDk2Nu->decay.vy, fDk2Nu->decay.vz); // origin of decay
209  TVector3 p3beam = enu * (x4beam.Vect() - xyzDk).Unit();
210 
211  // divide output wgt by pi so it is in unit area (output wgt is returned as flux/(pi*m^2))
212  wgt *= 1 / TMath::Pi();
213 
214  // with the recalculated energy, compute the momentum components
215  bsim::NuRay anuray(p3beam.x(), p3beam.y(), p3beam.z(), enu, wgt);
216  fDk2Nu->nuray.push_back(rndnuray);
217  fDk2Nu->nuray.push_back(anuray);
218 
219  TLorentzVector p4beam(p3beam, enu);
220  TLorentzVector p4usr;
221  Beam2UserP4(p4beam, p4usr);
222 
223  fNuPos = TLorentzVector(x4usr);
224  fNuMom = TLorentzVector(p4usr);
225 
226  x4usr.SetX(x4usr.X() / 100.); // from cm --> m
227  x4usr.SetY(x4usr.Y() / 100.);
228  x4usr.SetZ(x4usr.Z() / 100.);
229 
230  // overwrite nuchoice
231  fNuChoice->clear();
232  fNuChoice->pdgNu = fDk2Nu->decay.ntype;
233  fNuChoice->xyWgt = fDk2Nu->nuray[1].wgt;
234  fNuChoice->impWgt = fDk2Nu->decay.nimpwt;
235  fNuChoice->x4NuBeam = x4beam;
236  fNuChoice->p4NuBeam = TLorentzVector(
237  fDk2Nu->nuray[1].px, fDk2Nu->nuray[1].py, fDk2Nu->nuray[1].pz, fDk2Nu->nuray[1].E);
238  //need rotation matrix here to fill these
239  fNuChoice->x4NuUser = x4usr;
240  fNuChoice->p4NuUser = p4usr;
241 
242  flux.fntype = fDk2Nu->decay.ntype;
243  flux.fnimpwt = fDk2Nu->decay.nimpwt;
244  flux.fvx = fDk2Nu->decay.vx;
245  flux.fvy = fDk2Nu->decay.vy;
246  flux.fvz = fDk2Nu->decay.vz;
247  flux.fpdpx = fDk2Nu->decay.pdpx;
248  flux.fpdpy = fDk2Nu->decay.pdpy;
249  flux.fpdpz = fDk2Nu->decay.pdpz;
250  flux.fppdxdz = fDk2Nu->decay.ppdxdz;
251  flux.fppdydz = fDk2Nu->decay.ppdydz;
252  flux.fpppz = fDk2Nu->decay.pppz;
253  flux.fppmedium = fDk2Nu->decay.ppmedium;
254  flux.fptype = fDk2Nu->decay.ptype;
255  flux.fndecay = fDk2Nu->decay.ndecay;
256  flux.fmuparpx = fDk2Nu->decay.muparpx;
257  flux.fmuparpy = fDk2Nu->decay.muparpy;
258  flux.fmuparpz = fDk2Nu->decay.muparpz;
259  flux.fmupare = fDk2Nu->decay.mupare;
260  flux.fnecm = fDk2Nu->decay.necm;
261 
262  flux.ftpx = fDk2Nu->tgtexit.tpx;
263  flux.ftpy = fDk2Nu->tgtexit.tpy;
264  flux.ftpz = fDk2Nu->tgtexit.tpz;
265  flux.ftptype = fDk2Nu->tgtexit.tptype;
266  flux.ftgen = fDk2Nu->tgtexit.tgen;
267 
268  flux.frun = fDk2Nu->job;
269  flux.fevtno = fDk2Nu->potnum;
270  flux.fnenergyn = flux.fnenergyf = enu;
271  flux.fnwtnear = flux.fnwtfar = wgt;
272  flux.fdk2gen = (x4beam.Vect() - xyzDk).Mag();
273  flux.ftgptype = fDk2Nu->ancestor[1].pdg;
274 
275  return true;
276  }
TLorentzVector fNuPos
TLorentzVector fRandBeam
bsim::NuChoice * fNuChoice
TLorentzVector fNuMom
void Beam2UserPos(const TLorentzVector &beamxyz, TLorentzVector &usrxyz) const
void Beam2UserP4(const TLorentzVector &beamp4, TLorentzVector &usrp4) const
bsim::Dk2Nu * fDk2Nu
bsim::Dk2Nu* fluxr::DK2NuInterface::GetDk2Nu ( )
inline

Definition at line 31 of file DK2NuInterface.h.

References fDk2Nu.

31 { return fDk2Nu; };
bsim::Dk2Nu * fDk2Nu
Long64_t fluxr::DK2NuInterface::GetEntries ( ) const
inlinevirtual

Implements fluxr::FluxInterface.

Definition at line 22 of file DK2NuInterface.h.

References fNEntries.

22 { return fNEntries; };
bsim::NuChoice* fluxr::DK2NuInterface::GetNuChoice ( )
inline

Definition at line 32 of file DK2NuInterface.h.

References AnglesToAxis(), Beam2UserP4(), Beam2UserPos(), fNuChoice, Init(), and User2BeamPos().

32 { return fNuChoice; };
bsim::NuChoice * fNuChoice
TLorentzVector fluxr::DK2NuInterface::GetNuMomentum ( ) const
inlinevirtual

Implements fluxr::FluxInterface.

Definition at line 26 of file DK2NuInterface.h.

References FillMCFlux(), fNuMom, and SetRootFile().

26 { return fNuMom; };
TLorentzVector fNuMom
TLorentzVector fluxr::DK2NuInterface::GetNuPosition ( ) const
inlinevirtual

Implements fluxr::FluxInterface.

Definition at line 25 of file DK2NuInterface.h.

References fNuPos.

25 { return fNuPos; };
TLorentzVector fNuPos
float fluxr::DK2NuInterface::GetPOT ( ) const
inlinevirtual

Implements fluxr::FluxInterface.

Definition at line 24 of file DK2NuInterface.h.

References fPOT.

24 { return fPOT; };
int fluxr::DK2NuInterface::GetRun ( ) const
inlinevirtual

Implements fluxr::FluxInterface.

Definition at line 23 of file DK2NuInterface.h.

References fRun.

23 { return fRun; };
void fluxr::DK2NuInterface::Init ( fhicl::ParameterSet const &  ps)

Definition at line 33 of file DK2NuInterface.cxx.

References AnglesToAxis(), detAV_rand_user, fBeamPosXML, fBeamRot, fBeamRotInv, fBeamRotXML, fBeamZero, fDkMeta, fRandBeam, fRandUser, fTempRot, fhicl::ParameterSet::get(), fhicl::ParameterSet::is_key_to_table(), User2BeamPos(), and w.

Referenced by GetNuChoice().

34  {
35  // Code to handle flux window adapted from
36  // GENIE_R21210/src/FluxDrivers/GNuMIFlux.cxx
37  if (ps.is_key_to_table("rotmatrix")) {
38  // Matrix defined with series of rotations
39  fhicl::ParameterSet rotps = ps.get<fhicl::ParameterSet>("rotmatrix");
40  fTempRot.RotateX(rotps.get<double>("x"));
41  fTempRot.RotateY(rotps.get<double>("y"));
42  fTempRot.RotateZ(rotps.get<double>("z"));
43  }
44  else {
45  std::vector<double> rotmat = ps.get<std::vector<double>>("rotmatrix");
46  TVector3 newX, newY, newZ;
47 
48  if (rotmat.size() == 9) {
49  // Matrix defined with new axis values
50  newX = TVector3(rotmat[0], rotmat[1], rotmat[2]);
51  newY = TVector3(rotmat[3], rotmat[4], rotmat[5]);
52  newZ = TVector3(rotmat[6], rotmat[7], rotmat[8]);
53  }
54  else if (rotmat.size() == 6) {
55  // Matrix defined with theta phi rotations
56  newX = AnglesToAxis(rotmat[0], rotmat[1]);
57  newY = AnglesToAxis(rotmat[2], rotmat[3]);
58  newZ = AnglesToAxis(rotmat[4], rotmat[5]);
59  fTempRot.RotateAxes(newX, newY, newZ);
61  }
62 
63  fTempRot.RotateAxes(newX, newY, newZ);
64  }
65 
66  fBeamRotXML = fTempRot.Inverse();
67  fBeamRot = TLorentzRotation(fBeamRotXML);
68  fBeamRotInv = fBeamRot.Inverse();
69 
70  int w = 10, p = 6;
71  std::cout << " fBeamRotXML: " << std::setprecision(p) << std::endl;
72  std::cout << " [ " << std::setw(w) << fBeamRotXML.XX() << " " << std::setw(w)
73  << fBeamRotXML.XY() << " " << std::setw(w) << fBeamRotXML.XZ() << std::endl
74  << " " << std::setw(w) << fBeamRotXML.YX() << " " << std::setw(w)
75  << fBeamRotXML.YY() << " " << std::setw(w) << fBeamRotXML.YZ() << std::endl
76  << " " << std::setw(w) << fBeamRotXML.ZX() << " " << std::setw(w)
77  << fBeamRotXML.ZY() << " " << std::setw(w) << fBeamRotXML.ZZ() << " ] " << std::endl;
78  std::cout << std::endl;
79 
80  std::vector<double> detxyz = ps.get<std::vector<double>>("userbeam");
81  if (detxyz.size() == 3) { fBeamPosXML = TVector3(detxyz[0], detxyz[1], detxyz[2]); }
82  else if (detxyz.size() == 6) {
83  TVector3 userpos = TVector3(detxyz[0], detxyz[1], detxyz[2]);
84  TVector3 beampos = TVector3(detxyz[3], detxyz[4], detxyz[5]);
85  fBeamPosXML = userpos - fBeamRotXML * beampos;
86  }
87  else {
88  std::cout << "userbeam needs 3 or 6 numbers to be properly defined" << std::endl;
89  }
90 
91  fBeamZero = TLorentzVector(fBeamPosXML, 0);
92 
93  w = 16;
94  p = 10;
95  std::cout << " fBeamPosXML: [ " << std::setprecision(p) << std::setw(w) << fBeamPosXML.X()
96  << " , " << std::setw(w) << fBeamPosXML.Y() << " , " << std::setw(w)
97  << fBeamPosXML.Z() << " ] " << std::endl;
98 
101  //
102  // calculation from flux window
103  // discontinued in favor of random point in active volume
104 
105  //
108 
109  // calculation from random point in detector
110 
111  std::vector<double> x_detAV = ps.get<std::vector<double>>("x_detAV");
112  std::vector<double> y_detAV = ps.get<std::vector<double>>("y_detAV");
113  std::vector<double> z_detAV = ps.get<std::vector<double>>("z_detAV");
114 
115  // assign random point
116 
117  detAV_rand_user[0] = gRandom->Uniform(x_detAV[0], x_detAV[1]);
118  detAV_rand_user[1] = gRandom->Uniform(y_detAV[0], y_detAV[1]);
119  detAV_rand_user[2] = gRandom->Uniform(z_detAV[0], z_detAV[1]);
120 
121  // convert to beam coordinates
122  fRandUser = TLorentzVector(detAV_rand_user, 0);
124 
125  // this will serve as the input point for calcEnuWgt function
126 
129 
130  //overwrite dkmeta
131  fDkMeta->location.clear();
132  fDkMeta->location.resize(2);
133  fDkMeta->location[0].x = 0;
134  fDkMeta->location[0].y = 0;
135  fDkMeta->location[0].z = 0;
136  TLorentzVector detVec;
137  User2BeamPos(TLorentzVector(0, 0, 0, 0), detVec);
138  fDkMeta->location[1].x = detVec.Vect().X();
139  fDkMeta->location[1].y = detVec.Vect().Y();
140  fDkMeta->location[1].z = detVec.Vect().Z();
141 
142  std::cout << "Locations " << std::endl;
143  for (unsigned int i = 0; i < fDkMeta->location.size(); i++) {
144  std::cout << i << "\t" << fDkMeta->location[i].x << "\t" << fDkMeta->location[i].y << "\t"
145  << fDkMeta->location[i].z << std::endl;
146  }
147  }
bsim::DkMeta * fDkMeta
TLorentzVector fBeamZero
TLorentzVector fRandBeam
T get(std::string const &key) const
Definition: ParameterSet.h:314
TLorentzVector fRandUser
void User2BeamPos(const TLorentzVector &usrxyz, TLorentzVector &beamxyz) const
TVector3 AnglesToAxis(double theta, double phi)
TLorentzRotation fBeamRotInv
Float_t w
Definition: plot.C:20
TLorentzRotation fBeamRot
void fluxr::DK2NuInterface::SetRootFile ( TFile *  rootFile)

Definition at line 16 of file DK2NuInterface.cxx.

References fDk2Nu, fDk2NuTree, fDkMeta, fDkMetaTree, fNEntries, fNuChoice, fPOT, and fRun.

Referenced by GetNuMomentum().

17  {
18  fDk2NuTree = dynamic_cast<TTree*>(rootFile->Get("dk2nuTree"));
19  fDkMetaTree = dynamic_cast<TTree*>(rootFile->Get("dkmetaTree"));
20 
21  fDk2Nu = new bsim::Dk2Nu;
22  fDkMeta = new bsim::DkMeta;
23  fNuChoice = new bsim::NuChoice;
24  fDk2NuTree->SetBranchAddress("dk2nu", &fDk2Nu);
25  fDkMetaTree->SetBranchAddress("dkmeta", &fDkMeta);
26 
27  fNEntries = fDk2NuTree->GetEntries();
28  fDkMetaTree->GetEntry(0);
29  fRun = fDkMeta->job;
30  fPOT = fDkMeta->pots;
31  }
bsim::DkMeta * fDkMeta
bsim::NuChoice * fNuChoice
bsim::Dk2Nu * fDk2Nu
void fluxr::DK2NuInterface::User2BeamPos ( const TLorentzVector &  usrxyz,
TLorentzVector &  beamxyz 
) const

Definition at line 148 of file DK2NuInterface.cxx.

References fBeamRotInv, and fBeamZero.

Referenced by GetNuChoice(), and Init().

149  {
150  beamxyz = fBeamRotInv * (usrxyz - fBeamZero);
151  }
TLorentzVector fBeamZero
TLorentzRotation fBeamRotInv

Member Data Documentation

TVector3 fluxr::DK2NuInterface::detAV_rand_user
private

Definition at line 57 of file DK2NuInterface.h.

Referenced by Init().

TVector3 fluxr::DK2NuInterface::fBeamPosXML
private

Definition at line 55 of file DK2NuInterface.h.

Referenced by Init().

TLorentzRotation fluxr::DK2NuInterface::fBeamRot
private

Definition at line 54 of file DK2NuInterface.h.

Referenced by Beam2UserP4(), Beam2UserPos(), and Init().

TLorentzRotation fluxr::DK2NuInterface::fBeamRotInv
private

Definition at line 54 of file DK2NuInterface.h.

Referenced by Init(), and User2BeamPos().

TRotation fluxr::DK2NuInterface::fBeamRotXML
private

Definition at line 53 of file DK2NuInterface.h.

Referenced by Init().

TLorentzVector fluxr::DK2NuInterface::fBeamZero
private

Definition at line 56 of file DK2NuInterface.h.

Referenced by Beam2UserPos(), Init(), and User2BeamPos().

bsim::Dk2Nu* fluxr::DK2NuInterface::fDk2Nu
private

Definition at line 43 of file DK2NuInterface.h.

Referenced by FillMCFlux(), GetDk2Nu(), and SetRootFile().

TTree* fluxr::DK2NuInterface::fDk2NuTree
private

Definition at line 41 of file DK2NuInterface.h.

Referenced by FillMCFlux(), and SetRootFile().

bsim::DkMeta* fluxr::DK2NuInterface::fDkMeta
private

Definition at line 44 of file DK2NuInterface.h.

Referenced by Init(), and SetRootFile().

TTree* fluxr::DK2NuInterface::fDkMetaTree
private

Definition at line 42 of file DK2NuInterface.h.

Referenced by SetRootFile().

Long64_t fluxr::DK2NuInterface::fNEntries
private

Definition at line 46 of file DK2NuInterface.h.

Referenced by GetEntries(), and SetRootFile().

bsim::NuChoice* fluxr::DK2NuInterface::fNuChoice
private

Definition at line 45 of file DK2NuInterface.h.

Referenced by FillMCFlux(), GetNuChoice(), and SetRootFile().

TLorentzVector fluxr::DK2NuInterface::fNuMom
private

Definition at line 51 of file DK2NuInterface.h.

Referenced by FillMCFlux(), and GetNuMomentum().

TLorentzVector fluxr::DK2NuInterface::fNuPos
private

Definition at line 50 of file DK2NuInterface.h.

Referenced by FillMCFlux(), and GetNuPosition().

float fluxr::DK2NuInterface::fPOT
private

Definition at line 48 of file DK2NuInterface.h.

Referenced by GetPOT(), and SetRootFile().

TLorentzVector fluxr::DK2NuInterface::fRandBeam
private

Definition at line 58 of file DK2NuInterface.h.

Referenced by FillMCFlux(), and Init().

TLorentzVector fluxr::DK2NuInterface::fRandUser
private

Definition at line 58 of file DK2NuInterface.h.

Referenced by Init().

int fluxr::DK2NuInterface::fRun
private

Definition at line 47 of file DK2NuInterface.h.

Referenced by GetRun(), and SetRootFile().

TRotation fluxr::DK2NuInterface::fTempRot
private

Definition at line 53 of file DK2NuInterface.h.

Referenced by Init().


The documentation for this class was generated from the following files: