645 { G4cout <<
"LBNEAnalysis::FillNeutrinoNtuple() called." << G4endl;}
653 G4int evtno = pRunManager->GetCurrentEvent()->GetEventID();
657 G4ThreeVector
pos = track.GetPosition()/CLHEP::mm;
658 bool validTrack =
true;
659 if (std::isnan(pos.x()) || std::isnan(pos.y()) || std::isnan(pos.z())) {
660 std::cerr <<
" LBNEAnalysis::FillNeutrinoNtuple Bogus track position for track ID " 661 << track.GetTrackID() <<
" parentID " << track.GetParentID() <<
std::endl;
669 G4int parentID = track.GetParentID();
674 { std::cout <<
"Event no: " << evtno <<
" LBNEAnalysis::FillNeutrinoNtuple - " 675 <<
"PROBLEM: Direct Nu Parent has track ID = 0." <<
std::endl;
686 G4ThreeVector ParentMomentumFinal = NuParentTrack->
GetMomentum(point_no-1);
687 G4ThreeVector vertex_r = NuParentTrack->
GetPoint(point_no-1)->GetPosition();
689 G4double Parent_mass = NuParentTrack->
GetMass();
690 G4double gamma = sqrt(ParentMomentumFinal*ParentMomentumFinal+Parent_mass*Parent_mass)/Parent_mass;
691 G4double Parent_energy = gamma*Parent_mass;
692 G4ThreeVector beta_vec = ParentMomentumFinal/Parent_energy;
693 G4double partial = gamma*(beta_vec*
NuMomentum);
694 G4double enuzr = gamma*(track.GetTotalEnergy())-partial;
695 G4double enuzrInGeV = enuzr/CLHEP::GeV;
699 std::cerr <<
" More info about bogus track... Parent name " << parent_name <<
" Mom " 700 << ParentMomentumFinal.x() <<
" / " << ParentMomentumFinal.y() <<
" / " << ParentMomentumFinal.z()
743 if ((parent_name==
"mu+") || (parent_name==
"mu-")) Norig = 3;
745 if (firstvolname.contains(
"Baffle") || firstvolname.contains(
"TGT")) Norig = 1;
760 G4ParticleDefinition * particleType = track.GetDefinition();
770 G4ThreeVector ParentMomentumProduction = NuParentTrack->
GetMomentum(0);
775 G4double parentp = sqrt(ParentMomentumProduction*ParentMomentumProduction);
783 G4ThreeVector production_vertex = NuParentTrack->
GetPoint(0)->GetPosition();
789 if ((parent_name==
"mu+" || parent_name==
"mu-") && NuParentTrack->
GetParentID()!=0)
794 G4ThreeVector muparp = MuParentTrack->
GetMomentum(nopoint_mupar-1);
795 G4double muparm = MuParentTrack->
GetMass();
842 fDk2Nu->job = theRunManager->GetCurrentRun()->GetRunID();
843 fDk2Nu->potnum = G4EventManager::GetEventManager()->GetConstCurrentEvent()->GetEventID();
849 track.GetTotalEnergy()/CLHEP::GeV, 1);
851 fDk2Nu->nuray.push_back(myNu);
852 fDk2Nu->decay.norig=Norig;
854 fDk2Nu->decay.ntype=track.GetDefinition()->GetPDGEncoding();
856 fDk2Nu->decay.vx =
x/CLHEP::cm;
857 fDk2Nu->decay.vy =
y/CLHEP::cm;
858 fDk2Nu->decay.vz =
z/CLHEP::cm;
859 fDk2Nu->decay.pdpx = ParentMomentumFinal[0]/CLHEP::GeV;
860 fDk2Nu->decay.pdpy = ParentMomentumFinal[1]/CLHEP::GeV;
861 fDk2Nu->decay.pdpz = ParentMomentumFinal[2]/CLHEP::GeV;
862 G4ThreeVector ParentMomentumProduction = NuParentTrack->
GetMomentum(0);
863 fDk2Nu->decay.ppdxdz = ParentMomentumProduction[0]/ParentMomentumProduction[2];
864 fDk2Nu->decay.ppdydz = ParentMomentumProduction[1]/ParentMomentumProduction[2];
865 fDk2Nu->decay.pppz = ParentMomentumProduction[2]/CLHEP::GeV;
868 std::cerr <<
" Anomalous value for the transverse momentum of parent of neutrino " <<
871 G4double parentp = sqrt(ParentMomentumProduction*ParentMomentumProduction);
872 fDk2Nu->decay.ppenergy = sqrt((parentp*parentp+Parent_mass*Parent_mass))/CLHEP::GeV;
875 if ((parent_name==
"mu+" || parent_name==
"mu-") && NuParentTrack->
GetParentID()!=0)
880 G4ThreeVector muparp = MuParentTrack->
GetMomentum(nopoint_mupar-1);
881 G4double muparm = MuParentTrack->
GetMass();
882 fDk2Nu->decay.muparpx = muparp[0]/CLHEP::GeV;
883 fDk2Nu->decay.muparpy = muparp[1]/CLHEP::GeV;
884 fDk2Nu->decay.muparpz = muparp[2]/CLHEP::GeV;
885 fDk2Nu->decay.mupare = (sqrt(muparp*muparp+muparm*muparm))/CLHEP::GeV;
889 fDk2Nu->decay.muparpx = -9999999.;
890 fDk2Nu->decay.muparpy = -9999999.;
891 fDk2Nu->decay.muparpz = -9999999.;
892 fDk2Nu->decay.mupare = -9999999.;
894 fDk2Nu->decay.necm = enuzrInGeV;
906 G4ThreeVector TParticleMomentum = G4ThreeVector(-999999,-999999,-999999);
907 G4ThreeVector TParticlePosition = G4ThreeVector(-999999,-999999,-999999);
912 size_t ntraj = history.size();
913 std::vector<G4VTrajectory*>TempHistory(history);
914 std::vector<int>catchercontainer;
915 std::vector<int>trackcontainer;
916 for (
size_t iA=0; iA != ntraj; iA++) {
922 int transit = Points-1;
923 while (transit != 0){
925 if(volmat.contains(
"Target")){
926 catchercontainer.push_back(transit);
927 trackcontainer.push_back(iA);
941 if(trackcontainer.size() != 0){
942 int trackno = trackcontainer.at(0);
943 int pointno = catchercontainer.at(0);
945 TParticleMomentum = tgtraj->
GetMomentum(pointno)/CLHEP::GeV;
946 TParticlePosition = tgtraj->
GetPoint(pointno)->GetPosition()/CLHEP::cm;
949 tgt.tvx = TParticlePosition[0];
950 tgt.tvy = TParticlePosition[1];
951 tgt.tvz = TParticlePosition[2];
952 tgt.tpx = TParticleMomentum[0];
953 tgt.tpy = TParticleMomentum[1];
954 tgt.tpz = TParticleMomentum[2];
963 size_t numAncestors = 0;
964 G4int trackIDTmp = track.GetParentID();
967 std::vector<G4String> Horn2ICList = aPlacementHandler->
GetHorn2ICList();
968 std::vector<G4String>Horn1ICList = aPlacementHandler->
GetHorn1ICList();
969 while (trackIDTmp > 0) {
974 std::vector<LBNETrajectory *> trajs(numAncestors, 0);
976 size_t nAnces = numAncestors;
977 trackIDTmp = track.GetParentID();
979 while (trackIDTmp > 0) {
981 trajs[nAnces] = tmpTraj;
990 int idx_tar_in_chain = -1;
991 size_t ntrajectory = history.size();
992 std::vector<G4VTrajectory*>TmpHistory(history);
996 for (
size_t iA=0;iA<ntrajectory;++iA){
1002 G4ThreeVector x1rst = t->
GetPoint(0)->GetPosition();
1003 a.startx = x1rst[0]/CLHEP::cm;
1004 a.starty = x1rst[1]/CLHEP::cm;
1005 a.startz = x1rst[2]/CLHEP::cm;
1008 a.startpx = p1rst[0]/CLHEP::GeV;
1009 a.startpy = p1rst[1]/CLHEP::GeV;
1010 a.startpz = p1rst[2]/CLHEP::GeV;
1013 a.stoppx = pLast[0]/CLHEP::GeV;
1014 a.stoppy = pLast[1]/CLHEP::GeV;
1015 a.stoppz = pLast[2]/CLHEP::GeV;
1028 a.pprodpx = momatProd[0]/CLHEP::GeV;
1029 a.pprodpy = momatProd[1]/CLHEP::GeV;
1030 a.pprodpz = momatProd[2]/CLHEP::GeV;
1037 for(
size_t j = 0;j != Horn1ICList.size();j++)
1039 if(volname==Horn1ICList.at(j))volname=
"Horn1IC";
1041 for(
size_t j = 0;j!=Horn2ICList.size();j++){
1042 if(volname==Horn2ICList.at(j))volname=
"Horn2IC";
1046 if(volname==
"TargetUpstrDownstrSegmentRight"||volname==
"TargetUpstrDownstrSegmentLeft"||volname==
"RAL-Target"){
1047 volname=
"TargetNoSplitSegment";
1055 if(t->
GetMaterialName(np-1).contains(
"Target"))idx_tar_in_chain =
int (iA);
1056 fDk2Nu->ancestor.push_back(a);
1059 fDk2Nu->vint.push_back(idx_tar_in_chain);
1061 fDk2Nu->vint.push_back(-1);
1067 const double fact_Al = (26.98/2.7);
1068 const double fact_steel316 = (52.73/8.0);
1069 const double fact_concrete = (33.63/2.03);
1070 const double fact_water = (18.01/1.0);
1071 const double fact_iron = (207.19/11.35);
1072 const double fact_helium = (4.003/0.000145);
1074 for(
int ii = 0;ii<Nanc;ii++){
1081 if(history.size()!=0){
1083 for(
int ii = 0;ii<Nanc;ii++){
1095 for(
int ii = 1; ii<4;ii++){
1096 if(history.size()-ii<1)
continue;
1107 if(horn1IC != 0.)
dist_IC1[ii]=horn1IC/fact_Al;
1109 if(horn2IC != 0.)
dist_IC2[ii]=horn2IC/fact_Al;
1116 for(
int ii=0;ii<3;ii++){
1134 bsim::Traj tmp_traj;
1142 for (
int ii = 0;ii<10;++ii)
1154 G4ThreeVector ParentMomentum;
1155 G4ThreeVector ParentPosition;
1159 std::vector<int> h2exitindex;
1161 points = size_t(npoint);
1162 h2exitindex.clear();
1163 for(
size_t ii = 0;ii != points-1;ii++){
1166 if(h2volname.contains(
"Horn2")&&(NuParentTrack->
GetMaterialName(iii).contains(
"Aluminum"))){
1167 h2exitindex.push_back(iii);
1174 if(!h2exitindex.empty())h2exit = h2exitindex.back();
1175 if(!h2exitindex.empty())h2entry = h2exitindex.front();
1179 for(G4int ii = 0; ii<npoint-1;ii++){
1181 ParentPosition = NuParentTrack->
GetPoint(ii)->GetPosition();
1182 G4String postvolname =
" ";
1186 if((prevolname.contains(
"TargetNoSplitSegment")||prevolname.contains(
"TargetFinHorizontal"))&&ii==0){
1187 trkx[0] = ParentPosition[0]/CLHEP::cm;
1188 trky[0] = ParentPosition[1]/CLHEP::cm;
1189 trkz[0] = ParentPosition[2]/CLHEP::cm;
1190 trkpx[0] = ParentMomentum[0]/CLHEP::GeV;
1191 trkpy[0] = ParentMomentum[1]/CLHEP::GeV;
1192 trkpz[0] = ParentMomentum[2]/CLHEP::GeV;
1195 if(prevolname.contains(
"TargetNoSplitM1")&&postvolname.contains(
"TargetHallAndHorn1")){
1198 trkx[1] = ParentPosition[0]/CLHEP::cm;
1199 trky[1] = ParentPosition[1]/CLHEP::cm;
1200 trkz[1] = ParentPosition[2]/CLHEP::cm;
1201 trkpx[1] = ParentMomentum[0]/CLHEP::GeV;
1202 trkpy[1] = ParentMomentum[1]/CLHEP::GeV;
1203 trkpz[1] = ParentMomentum[2]/CLHEP::GeV;
1209 if(prevolname.contains(
"TargetHallAndHorn1") && postvolname.contains(
"Horn1PolyM1"))
1213 trkx[2] = ParentPosition[0]/CLHEP::cm;
1214 trky[2] = ParentPosition[1]/CLHEP::cm;
1215 trkz[2] = ParentPosition[2]/CLHEP::cm;
1216 trkpx[2] = ParentMomentum[0]/CLHEP::GeV;
1217 trkpy[2] = ParentMomentum[1]/CLHEP::GeV;
1218 trkpz[2] = ParentMomentum[2]/CLHEP::GeV;
1222 if(prevolname.contains(
"Horn1PolyM1")&& postvolname.contains(
"TargetHallAndHorn1"))
1225 trkx[3] = ParentPosition[0]/CLHEP::cm;
1226 trky[3] = ParentPosition[1]/CLHEP::cm;
1227 trkz[3] = ParentPosition[2]/CLHEP::cm;
1228 trkpx[3] = ParentMomentum[0]/CLHEP::GeV;
1229 trkpy[3] = ParentMomentum[1]/CLHEP::GeV;
1230 trkpz[3] = ParentMomentum[2]/CLHEP::GeV;
1235 trkx[4] = ParentPosition[0]/CLHEP::cm;
1236 trky[4] = ParentPosition[1]/CLHEP::cm;
1237 trkz[4] = ParentPosition[2]/CLHEP::cm;
1238 trkpx[4] = ParentMomentum[0]/CLHEP::GeV;
1239 trkpy[4] = ParentMomentum[1]/CLHEP::GeV;
1240 trkpz[4] = ParentMomentum[2]/CLHEP::GeV;
1247 trkx[5] = ParentPosition[0]/CLHEP::cm;
1248 trky[5] = ParentPosition[1]/CLHEP::cm;
1249 trkz[5] = ParentPosition[2]/CLHEP::cm;
1250 trkpx[5] = ParentMomentum[0]/CLHEP::GeV;
1251 trkpy[5] = ParentMomentum[1]/CLHEP::GeV;
1252 trkpz[5] = ParentMomentum[2]/CLHEP::GeV;
1255 if(prevolname.contains(
"DecayPipeHall")&&postvolname.contains(
"DecayPipeVolume"))
1258 trkx[6] = ParentPosition[0]/CLHEP::cm;
1259 trky[6] = ParentPosition[1]/CLHEP::cm;
1260 trkz[6] = ParentPosition[2]/CLHEP::cm;
1261 trkpx[6] = ParentMomentum[0]/CLHEP::GeV;
1262 trkpy[6] = ParentMomentum[1]/CLHEP::GeV;
1263 trkpz[6] = ParentMomentum[2]/CLHEP::GeV;
1268 double OptH1InnerRad = 0.0;
1269 double OptH1NeckZLoc = 0.0;
1275 double H1NeckInnerRad = 0.0;
1276 double H1NeckZLoc = 0.0;
1277 if(NomH1InnerRad != 0){
1278 H1NeckInnerRad = NomH1InnerRad;
1279 H1NeckZLoc = NomH1NeckZloc;
1282 H1NeckInnerRad = OptH1InnerRad;
1283 H1NeckZLoc = OptH1NeckZLoc;
1292 if((sqrt(ParentPosition[0]*ParentPosition[0]+ParentPosition[1]*ParentPosition[1])<H1NeckInnerRad)&&ParentPosition[2]>H1NeckZLoc)
1298 if(sqrt(ParentPosition[0]*ParentPosition[0]+ParentPosition[1]*ParentPosition[1])<H2NeckInnerRad)
1306 ParentMomentum = NuParentTrack->
GetMomentum(npoint-1);
1308 trkx[7] = ParentPosition[0]/CLHEP::cm;
1309 trky[7] = ParentPosition[1]/CLHEP::cm;
1310 trkz[7] = ParentPosition[2]/CLHEP::cm;
1311 trkpx[7] = ParentMomentum[0]/CLHEP::GeV;
1312 trkpy[7] = ParentMomentum[1]/CLHEP::GeV;
1313 trkpz[7] = ParentMomentum[2]/CLHEP::GeV;
1318 for(G4int ii = 0;ii<10;++ii)
1321 tmp_traj.trkx = trkx[ii];
1322 tmp_traj.trky = trky[ii];
1323 tmp_traj.trkz = trkz[ii];
1324 tmp_traj.trkpx = trkpx[ii];
1325 tmp_traj.trkpy = trkpy[ii];
1326 tmp_traj.trkpz = trkpz[ii];
1327 fDk2Nu->traj.push_back(tmp_traj);
1338 for (
size_t kLoc = 0; kLoc !=
fDkMeta->location.size(); kLoc++) {
1339 if ((!std::isnan(
fDk2Nu->nuray[kLoc].E)) && (!std::isnan(
fDk2Nu->nuray[kLoc].wgt)))
continue;
1340 std::cerr <<
" LBNEAnalysis::FillNeutrinoNtuple Problem with detector weight calculation for location " 1343 std::cerr <<
" Decay Vertex : X = " <<
fDk2Nu->decay.vx <<
" Y = " 1345 std::cerr <<
" Original track position " << pos.x() <<
" / " << pos.y() <<
" / " << pos.z() <<
std::endl;
1346 std::cerr <<
" Decay Momentum : " <<
fDk2Nu->decay.pdpx
1348 std::cerr <<
" Neutrino from G4 decay momentum " <<
NuMomentum[0]/CLHEP::GeV
1350 std::cerr <<
" decay type " <<
fDk2Nu->decay.ptype <<
" parent name " << parent_name <<
std::endl;
1360 for(
unsigned int idet = 0; idet < ndets; ++idet)
1368 std::vector<double> r_det;
1385 G4cout <<
"LBNEAnalysis::FillNeutrinoNtuple - " 1386 <<
"Far Detector vectors are not the same size." << G4endl;
1393 for(
unsigned int idet = 0; idet < ndets; ++idet)
1401 std::vector<double> r_det;
1402 r_det.push_back(
fXdet_far[idet]/CLHEP::cm);
1403 r_det.push_back(
fYdet_far[idet]/CLHEP::cm);
1404 r_det.push_back(
fZdet_far[idet]/CLHEP::cm);
1417 G4ThreeVector ParticlePosition1 = NuParentTrack->
GetPoint(0)->GetPosition();
1419 for (G4int ii=numberOfPoints-1; ii > -1; --ii)
1424 G4String postvolname =
"";
1427 G4ThreeVector ParticleMomentum = NuParentTrack->
GetMomentum(ii);
1429 G4ThreeVector ParticlePosition = NuParentTrack->
GetPoint(ii)->GetPosition();
1430 if (((numberOfPoints - ii) < 3) || (ii < 2))
1443 if (prevolname.contains(
"Horn1TrackingPlane"))
1454 if(prevolname.contains(
"Horn2TrackingPlane"))
1469 G4int trackID = track.GetParentID();
1502 std::ofstream asciiFile(asciiFileName.c_str(), std::ios::app);
1503 if(asciiFile.is_open())
G4String GetVolName1rst() const
G4double GetTimeStart() const
LBNETrajectory * GetParentTrajectory(G4int parentID)
G4ThreeVector GetPolarization() const
double GetWeight(const LBNEDataNtp_t *nudata, const std::vector< double > xdet, double &nu_wght, double &nu_energy)
virtual G4String GetMaterialName(G4int i) const
static LBNEVolumePlacements * Instance()
double GetBeamSigmaX() const
std::vector< G4double > fXdet_far
double GetBeamSigmaY() const
G4ThreeVector GetProtonOrigin()
bool GetCreateASCIIOutput() const
std::vector< G4String > GetHorn2ICList() const
LBNETrajectory * GetTrajectory(G4int trackID)
bool GetUseHorn1Polycone() const
G4ThreeVector GetProtonMomentum()
void blessPion(int trNum1, double e, G4ThreeVector p)
G4int GetDecayCode() const
std::vector< G4double > fYdet_far
LBNEParticleCode_t StringToEnum(G4String particleName)
void TrackThroughGeometry(const LBNETrajectory *TrackTrajectory)
double GetHorn1NeckInnerRadius() const
LBNEDataNtp_t * fLBNEOutNtpData
G4int GetPDGNucleus() const
std::vector< G4double > fXdet_near
G4ThreeVector GetParticlePosition()
void CalcLocationWeights(const bsim::DkMeta *dkmeta, bsim::Dk2Nu *dk2nu, bool useRealisticNearDetectorVolume)
G4String GetOutputASCIIFileName() const
bool GetDoComputeEDepInHorns() const
double GetHorn2NeckInnerRadius() const
virtual G4String GetPreStepVolumeName(G4int i) const
const G4ThreeVector GetParentMomentumAtThisProduction() const
std::vector< G4double > fZdet_far
static LBNEQuickPiToNuVect * Instance()
virtual G4VTrajectoryPoint * GetPoint(G4int i) const
G4String GetProcessName() const
G4int GetMaterialNumber1rst() const
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
double GetHorn1NeckZPosition() const
double GetHorn1PolyInnerConductorRadius(size_t numPts) const
G4ThreeVector GetParticleMomentum()
bool GetCreateOutput() const
double GetBeamOffsetX() const
static unsigned int reverse(QString &chars, unsigned char *level, unsigned int a, unsigned int b)
double GetHorn1PolyInnerConductorZCoord(size_t numPts) const
std::vector< G4double > fYdet_near
double GetBeamOffsetY() const
double GetTargetLengthIntoHorn() const
G4int GetPDGEncoding() const
G4int GetParentID() const
int GetVerboseLevel() const
G4String GetMaterialName1rst() const
G4String GetParticleName() const
bool GetUseRealisticNearDetectorVolume() const
G4double GetDistanceInVolume(LBNETrajectory *wanted_traj, G4String wanted_vol)
int GetNumberOfHornsPolycone() const
virtual int GetPointEntries() const
bool GetCreateDk2NuOutput() const
virtual G4ThreeVector GetMomentum(G4int i) const
G4int AsInt(LBNEParticleCode_t pCode)
double GetHornCurrent() const
std::vector< G4String > GetHorn1ICList() const
QTextStream & endl(QTextStream &s)
std::vector< G4double > fZdet_near