17 #include <TStopwatch.h> 25 #include "G4SteppingManager.hh" 26 #include "G4ThreeVector.hh" 27 #include "G4TrajectoryContainer.hh" 28 #include "G4EventManager.hh" 30 #include "G4ParticleDefinition.hh" 31 #include "G4ParticleTypes.hh" 32 #include "G4Navigator.hh" 33 #include "G4TransportationManager.hh" 35 #include "G4Version.hh" 36 #include "G4VProcess.hh" 49 #include "dk2nu/tree/readWeightLocations.h" 50 #include "dk2nu/tree/calcLocationWeights.h" 58 fDk2NuDetectorFileRead(false),
59 fHorn1TrackingTree(0),
60 fHorn2TrackingTree(0),
80 std::cout <<
"LBNEAnalysis Constructor Called." <<
std::endl;
126 std::cout <<
"LBNEAnalysis Destructor Called." <<
std::endl;
129 #ifdef G4ANALYSIS_USE 148 G4String spaces =
" ";
149 std::cout <<
" LBNEAnalysis::CreateOutput() - Creating output ntuple..." <<
std::endl;
162 fOutTree =
new TTree(
"nudata",
"g4lbne Neutrino ntuple");
167 std::cout << spaces <<
"Creating Tracking Plane Ntuple..." <<
std::endl;
168 fTrackingTree =
new TTree(
"trackingdata",
"Particles in Tracking Plane");
184 std::cout << spaces <<
"Creating Horn1 Tracking Plane Ntuple..." <<
std::endl;
185 fHorn1TrackingTree =
new TTree(
"H1trackingdata",
"Particles in Horn1 Tracking Plane");
214 fDPTrackingTree =
new TTree(
"DecayPipetrackingdata",
"Particles Making to the Decay Pipe");
215 std::cerr << spaces <<
"Creating DecaypipeOutput Ntuples"<<
std::endl;
232 std::cout<<spaces<<
"Creating TargetOutPut Ntuples"<<
std::endl;
233 fTargetOutputTree =
new TTree(
"TargetOutputData",
"Particles Produced in the Target");
249 std::cout << spaces <<
"Creating Horn2 Tracking Plane Ntuple..." <<
std::endl;
250 fHorn2TrackingTree =
new TTree(
"H2trackingdata",
"Particles in Horn2 Tracking Plane");
279 std::cout << spaces <<
"Creating Sculpted Absorber Alcove Tracking Plane Ntuple..." <<
std::endl;
342 G4String spaces =
" ";
343 std::cout <<
" LBNEAnalysis::CreateOutput() - Creating output ntuple..." <<
std::endl;
350 pRunManager =
dynamic_cast<LBNERunManager*
>(G4RunManager::GetRunManager());
358 fOutTreeDk2Nu =
new TTree(
"dk2nuTree",
"g4lbne neutrino ntuple, dk2Nu format");
360 fOutTreeDk2NuMeta =
new TTree(
"dkmetaTree",
"g4lbne neutrino ntuple, dk2Nu format, metadata");
384 fDkMeta->job = theRunManager->GetCurrentRun()->GetRunID();
397 std::ostringstream oStrStr;
399 fDkMeta->physcuts += oStrStr.str();
406 std::ostringstream oStrStr;
407 oStrStr.precision(4);
415 std::ostringstream oStrStr;
416 oStrStr.precision(4);
419 oStrStr <<
"Current-" << pDet->
GetHornCurrent()/(CLHEP::ampere*1000.);
421 oStrStr <<
"Current-" << pDet->
GetHornCurrent()/(CLHEP::ampere*1000.);
429 std::ostringstream oStrStr;
430 oStrStr.precision(4);
448 G4String name_gen[] = {
"parent",
"granparent",
"greatgranparent"};
449 G4String name_vol[] = {
"PHorn1IC",
"PHorn2IC",
"DPIP",
"DVOL"};
450 for(G4int ii=0;ii<
nGenAbs;ii++){
453 for(G4int ii=0;ii<
nVolAbs;ii++){
457 for(
int ii=0; ii<
nVolAbs; ii++){
458 for(
int jj=0; jj<
nGenAbs; jj++){
462 std::ostringstream nameVarStrStr; nameVarStrStr <<
"Material_" <<
VolAbsName[ii] <<
"_" <<
GenAbsName[jj];
472 G4String name_vint[] = {
"Index_Tar_In_Ancestry",
"playlistID"};
492 if (aFileName == G4String(
"?")) {
493 char *G4WORKDIRC =
getenv(
"G4LBNE_DIR");
494 if (G4WORKDIRC == 0) {
495 G4WORKDIRC =
getenv(
"G4LBNE_DIR");
496 if (G4WORKDIRC == 0) {
497 G4Exception(
"LBNEAnalysis::LBNEAnalysis::fillDkMeta",
"InvalidSetup",
498 FatalErrorInArgument,
499 "Environmental variable G4LBNE_DIR or G4LBNE not set, can't find default Det. loc. file ");
503 std::cerr <<
" ... And this file name is ... " << aFileName <<
std::endl;
507 fStr.open(aFileName.c_str());
508 if (!fStr.is_open()) {
510 std::cerr <<
" can't open detector location file ... " << aFileName <<
std::endl;
511 G4Exception(
"LBNEAnalysis::LBNEAnalysis::fillDkMeta",
"InvalidSetup",
512 FatalErrorInArgument,
"Invalid Detector FileName (not found or corrupted)");
516 bsim::readWeightLocations(aFileName,
fDkMeta);
534 std::cout <<
" Writing out Tracking Plane Ntuple to " <<
fOutFile -> GetName() <<
std::endl;
542 std::cout <<
" Writing out Tracking Plane Ntuple to " <<
fOutFile -> GetName() <<
std::endl;
548 std::cout <<
" Writing out Tracking Plane Ntuple to " <<
fOutFile -> GetName() <<
std::endl;
554 std::cout <<
" Writing out Tracking Plane Ntuple to " <<
fOutFile -> GetName() <<
std::endl;
560 std::cout <<
" Writing out Tracking Plane Ntuple to " <<
fOutFile -> GetName() <<
std::endl;
566 std::cout <<
" Writeing out sculpted absorber tracking plane to "<<
fOutFile->GetName()<<
std::endl;
582 std::cout <<
" Sucessfully closed Output Ntuple " <<
fOutFile -> GetName() <<
std::endl;
597 std::cerr <<
" Writing the Dk2Nu Ntuple ... " <<
std::endl;
600 std::cerr <<
" Written the Dk2Nu Ntuple and meta data.. ... " <<
std::endl;
635 std::vector<G4VTrajectory*>& history)
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())
1560 G4int trackID = track.GetTrackID();
1561 G4String currentTrackVolName = track.GetVolume() -> GetName();
1585 G4int trackID = TrackTrajectory-> GetTrackID();
1589 for (G4int ii=numberOfPoints-1; ii > -1; --ii)
1593 G4String postvolname =
"";
1596 G4ThreeVector ParticleMomentum = TrackTrajectory->
GetMomentum(ii);
1597 G4ThreeVector ParticlePosition = TrackTrajectory->
GetPoint(ii)->GetPosition();
1599 if (((numberOfPoints - ii) < 3) || (ii < 2))
1612 TrkPt.
x = ParticlePosition[0]/CLHEP::cm;
1613 TrkPt.
y = ParticlePosition[1]/CLHEP::cm;
1614 TrkPt.
z = ParticlePosition[2]/CLHEP::cm;
1615 TrkPt.
px = ParticleMomentum[0]/CLHEP::GeV;
1616 TrkPt.
py = ParticleMomentum[1]/CLHEP::GeV;
1617 TrkPt.
pz = ParticleMomentum[2]/CLHEP::GeV;
1618 TrkPt.
trkid = trackID;
1625 if (prevolname.contains(
"TargetFin") && ii==0)
1632 if ((prevolname.contains(
"Target")) &&
1633 postvolname.contains(
"Horn1") && (!postvolname.contains(
"Target")))
1665 if (prevolname.contains(
"TgtEndPlane"))
1677 if ((prevolname.contains(
"Horn1TopLevelDownstr")) && postvolname.contains(
"Horn1TopLevelDownstr"))
1683 if (prevolname.contains(
"Horn1DownstrPart1"))
1688 if ((prevolname.contains(
"Horn1")) && postvolname.contains(
"Tunnel"))
1693 if (prevolname.contains(
"PH01EndPlane"))
1698 if ((prevolname.contains(
"Tunnel")) && postvolname.contains(
"Horn2"))
1703 if (prevolname.contains(
"Horn2Part2"))
1708 if ((prevolname.contains(
"Horn2")) && postvolname.contains(
"Tunnel"))
1713 if (prevolname.contains(
"PH02EndPlane"))
1718 if ( (prevolname.contains(
"DecayPipeUsptrWindow")) &&
1719 (postvolname.contains(
"DecayPipeVolume"))) {
1724 if ( (prevolname.contains(
"DecayPipe")) && (postvolname.contains(
"Tunnel")))
1743 G4cout <<
"LBNEAnalysis::GetParentTrajectory() called." << G4endl;
1746 G4TrajectoryContainer* container =
1747 G4RunManager::GetRunManager()->GetCurrentEvent()->GetTrajectoryContainer();
1748 if(container==0)
return 0;
1750 TrajectoryVector* vect = container->GetVector();
1753 while (ii<G4int(vect->size())){
1756 if(tr1->
GetTrackID() == parentID)
return tr1;
1766 G4TrajectoryContainer* container = G4RunManager::GetRunManager()->GetCurrentEvent()->GetTrajectoryContainer();
1770 G4cout <<
"LBNEAnalysis::GetTrajectory - PROBLEM: No Trajectory Container for track ID = " << trackID <<
endl;
1774 TrajectoryVector* vect = container->GetVector();
1777 while (ii < G4int(vect->size()))
1785 G4cout <<
"LBNEAnalysis::GetTrajectory - PROBLEM: Failed to find track with ID = " << trackID <<
endl;
1795 G4double xdetNear[] = { 0. , 0. , 11.50, 0. , 25.84 };
1796 G4double ydetNear[] = { 0. , 0. , -3.08, 0. , 78.42 };
1797 G4double zdetNear[] = {574. ,1036.49 , 1000.97, 1030.99 , 745.25 };
1804 G4double xdetFar[] = { 0. , 0. , 11040. };
1805 G4double ydetFar[] = { 0. , 0. , -4200. };
1806 G4double zdetFar[] = { 1297000. , 735340. , 810450. };
1827 for(G4int ii=0;ii<nNear;ii++){
1843 for(G4int ii=0;ii<nFar;ii++){
1861 G4Track *track = step.GetTrack();
1867 G4StepPoint *point = step.GetPostStepPoint();
1868 G4ThreeVector
pos = point->GetPosition();
1869 G4ThreeVector
dir = point->GetMomentumDirection();
1870 G4ParticleDefinition *def = track->GetDefinition();
1897 G4Track *track = step.GetTrack();
1905 G4ParticleDefinition *def = track->GetDefinition();
1908 G4StepPoint *point = step.GetPostStepPoint();
1909 G4ThreeVector
pos = point->GetPosition();
1910 G4ThreeVector mom = point->GetMomentum();
1912 const G4ThreeVector ppoint = track->GetVertexPosition();
1913 const G4ThreeVector pmom = track->GetVertexMomentumDirection();
1925 G4ThreeVector
dir = point->GetMomentumDirection();
1955 G4Track *track = step.GetTrack();
1962 if(track->GetCreatorProcess()!=0){
1964 fH2CProcess = track->GetCreatorProcess()->GetProcessName();
1997 const G4ThreeVector ppoint = track->GetVertexPosition();
1998 const G4ThreeVector pmom = track->GetVertexMomentumDirection();
2002 G4StepPoint *point = step.GetPostStepPoint();
2003 G4ThreeVector
pos = point->GetPosition();
2004 G4ThreeVector
dir = point->GetMomentumDirection();
2005 G4ParticleDefinition *def = track->GetDefinition();
2006 G4ThreeVector mom = point->GetMomentum();
2046 G4Track *track = step.GetTrack();
2053 G4StepPoint *point = step.GetPostStepPoint();
2054 G4ThreeVector
pos = point->GetPosition();
2055 G4ThreeVector mom = point->GetMomentum();
2056 const G4ThreeVector ppoint = track->GetVertexPosition();
2057 const G4ThreeVector pmom = track->GetVertexMomentumDirection();
2069 G4ThreeVector
dir = point->GetMomentumDirection();
2070 G4ParticleDefinition *def = track->GetDefinition();
2097 G4Track *track = step.GetTrack();
2105 G4String prematerial = step.GetPreStepPoint()->GetPhysicalVolume()->GetLogicalVolume()->GetMaterial()->GetName();
2106 G4String posmaterial = step.GetPostStepPoint()->GetPhysicalVolume()->GetLogicalVolume()->GetMaterial()->GetName();
2107 G4StepPoint *point = step.GetPostStepPoint();
2108 G4ThreeVector
pos = point->GetPosition();
2109 G4ThreeVector mom = point->GetMomentum();
2116 G4ParticleDefinition *def = track->GetDefinition();
2137 G4Track *track = aStep.GetTrack();
2140 G4StepPoint *point = aStep.GetPostStepPoint();
2141 G4ThreeVector mom = point->GetMomentum();
2142 G4ThreeVector
pos = point->GetPosition();
2144 int theTrackID = aStep.GetTrack()->GetTrackID();
2159 fMuDE[
index] += aStep.GetTotalEnergyDeposit()/CLHEP::MeV;
2160 fMuDEion[
index] += (aStep.GetTotalEnergyDeposit()- aStep.GetNonIonizingEnergyDeposit())/CLHEP::MeV;
2168 G4cout <<
"Alcove Tracking: Max Number of Particles Reached. Not saving ... " <<G4endl;
2172 fMuEvtNo = pRunManager->GetCurrentEvent()->GetEventID();
2173 fMuRunNo = pRunManager->GetCurrentRun()->GetRunID();
2175 G4ThreeVector vpos = track->GetVertexPosition();
2180 G4ParticleDefinition* theParticle = track->GetDefinition();
2195 fMuTheta[
index] = mom.z()/sqrt(mom.z()*mom.z()+mom.y()*mom.y()+mom.x()*mom.x());
2202 fMuDE[
index] = aStep.GetTotalEnergyDeposit()/CLHEP::MeV;
2231 double dist_vol = 0;
2232 if(wanted_traj==0)
return -1.;
2241 G4ThreeVector ParticlePos;
2244 G4ThreeVector tmp_ipos,tmp_fpos;
2245 G4ThreeVector tmp_disp;
2247 G4double tmp_dist = 0.0;
2248 G4bool enter_vol =
false;
2249 G4bool exit_vol =
false;
2250 for(G4int ii=0; ii<npoints; ++ii){
2252 G4String postvol =
"";
2256 G4bool vol_in = (!(prevol.contains(wanted_vol)) && (postvol.contains(wanted_vol)) ) || ( ii==0 && prevol.contains(wanted_vol));
2257 G4bool vol_out = (prevol.contains(wanted_vol)) && (!postvol.contains(wanted_vol));
2258 G4bool vol_through = (prevol.contains(wanted_vol))&&(postvol.contains(wanted_vol));
2266 tmp_ipos = G4ThreeVector(ParticlePos[0]/CLHEP::cm,ParticlePos[1]/CLHEP::cm,ParticlePos[2]/CLHEP::cm);
2269 if(enter_vol &&vol_through&& !exit_vol){
2270 tmp_fpos = G4ThreeVector(ParticlePos[0]/CLHEP::cm,ParticlePos[1]/CLHEP::cm,ParticlePos[2]/CLHEP::cm);
2271 tmp_disp = tmp_fpos - tmp_ipos;
2272 tmp_dist += tmp_disp.mag();
2273 tmp_ipos = tmp_fpos;
2275 if(enter_vol && vol_out){
2276 tmp_fpos = G4ThreeVector(ParticlePos[0]/CLHEP::cm,ParticlePos[1]/CLHEP::cm,ParticlePos[2]/CLHEP::cm);
2277 tmp_disp = tmp_fpos - tmp_ipos;
2278 tmp_dist += tmp_disp.mag();
2279 tmp_ipos = tmp_fpos;
2282 dist_vol += tmp_dist;
2328 size_t nloc = dkmeta->location.size();
2329 for (
size_t iloc = 0; iloc < nloc; ++iloc ) {
2332 if ( dkmeta->location[iloc].name == rkey ) {
2334 std::cerr <<
"calcLocationWeights \"" << rkey <<
"\"" 2335 <<
" isn't the 0-th entry" <<
std::endl;
2338 if ( dk2nu->nuray.size() != 1 ) {
2339 std::cerr <<
"calcLocationWeights \"" << rkey <<
"\"" 2340 <<
" nuenergy[" << iloc <<
"] not filled" <<
std::endl;
2345 double xdet = dkmeta->location[iloc].x;
2346 double ydet = dkmeta->location[iloc].y;
2347 double zdet = dkmeta->location[iloc].z;
2349 if(useRealisticNearDetectorVolume) {
2352 xdet += 200*(CLHEP::HepRandom::getTheEngine()->flat()-0.5);
2353 ydet += 200*(CLHEP::HepRandom::getTheEngine()->flat()-0.5);
2354 zdet += 600*(CLHEP::HepRandom::getTheEngine()->flat()-0.5);
2357 TVector3 xyzDet(xdet,
2362 int status = bsim::calcEnuWgt(dk2nu,xyzDet,enu_xy,wgt_xy);
2363 if ( status != 0 ) {
2364 std::cerr <<
"bsim::calcEnuWgt returned " << status <<
" for " 2365 << dkmeta->location[iloc].name <<
std::endl;
2368 TVector3 xyzDk(dk2nu->decay.vx,dk2nu->decay.vy,dk2nu->decay.vz);
2369 TVector3 p3 = enu_xy * (xyzDet - xyzDk).Unit();
2370 bsim::NuRay anuray(p3.x(), p3.y(), p3.z(), enu_xy, wgt_xy);
2371 dk2nu->nuray.push_back(anuray);
G4String GetVolName1rst() const
void FillTrackingPlaneH1Data(const G4Step &aStep)
G4double GetTimeStart() const
TTree * fHorn2TrackingTree
LBNETrajectory * GetParentTrajectory(G4int parentID)
void FillNeutrinoNtuple(const G4Track &track, const std::vector< G4VTrajectory * > &nuHistory)
G4ThreeVector GetPolarization() const
double GetWeight(const LBNEDataNtp_t *nudata, const std::vector< double > xdet, double &nu_wght, double &nu_energy)
bool GetCreateTrkPlaneH1Output() const
virtual G4String GetMaterialName(G4int i) const
static LBNEVolumePlacements * Instance()
double GetBeamSigmaX() const
bool GetCreateAlcoveTrackingOutput() const
std::vector< G4double > fXdet_far
std::string GetGitDescription() const
double GetBeamSigmaY() const
double fMudEdx_ion[kMaxP]
G4String GetDetectorLocationFileName() const
std::vector< G4String > fDetNameNear
G4ThreeVector GetProtonOrigin()
G4String GetPhysicsListName() const
bool GetCreateASCIIOutput() const
double fParticleMass[kMaxP]
void FillTrackingPlaneH2Data(const G4Step &aStep)
std::vector< G4String > GetHorn2ICList() const
LBNETrajectory * GetTrajectory(G4int trackID)
bool GetCreateTrkPlaneDPOutput() const
bool GetUseHorn1Polycone() const
void SetEntry(G4int entry)
double GetTargetSLengthGraphite() const
TTree * fOutTreeDk2NuMeta
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
void SetCount(G4int count)
G4ThreeVector GetProtonMomentum()
void blessPion(int trNum1, double e, G4ThreeVector p)
G4int GetDecayCode() const
double fParticleEnergy[kMaxP]
bool GetCreateTargetOutput() const
static VersionAndContext * Instance()
std::vector< G4double > fYdet_far
LBNEParticleCode_t StringToEnum(G4String particleName)
double GetDecayPipeLength() const
bool fDk2NuDetectorFileRead
void FillTrackingNtuple(const G4Track &track, LBNETrajectory *currTrajectory)
void TrackThroughGeometry(const LBNETrajectory *TrackTrajectory)
void FillAlcoveTrackingPlaneData(const G4Step &aStep)
double GetHorn1NeckInnerRadius() const
LBNEDataNtp_t * fLBNEOutNtpData
G4int GetPDGNucleus() const
std::vector< G4double > fXdet_near
G4ThreeVector GetParticlePosition()
G4String GetDecayPipeGas() const
static LBNEAnalysis * getInstance()
static LBNEAnalysis * instance
std::string GetG4lbnfDir() const
void setDetectorPositions()
void CalcLocationWeights(const bsim::DkMeta *dkmeta, bsim::Dk2Nu *dk2nu, bool useRealisticNearDetectorVolume)
virtual G4double GetNImpWt() const
int GetNumberOfEventsLBNE()
G4String GetOutputASCIIFileName() const
bool GetDoComputeEDepInHorns() const
double GetHorn2NeckInnerRadius() const
bool GetCreateTrkPlaneOutput() const
virtual G4String GetPreStepVolumeName(G4int i) const
void FillTrackingPlaneData(const G4Step &aStep)
std::string getenv(std::string const &name)
const G4ThreeVector GetParentMomentumAtThisProduction() const
std::vector< G4double > fZdet_far
char nuNtupleFileName[1024]
static LBNEQuickPiToNuVect * Instance()
TrkPoint_t StringToEnum(const std::string &trkpt)
virtual G4VTrajectoryPoint * GetPoint(G4int i) const
virtual G4int GetTgen() const
TTree * fAlcoveTrackingTree
double fParticleDZ[kMaxP]
LBNESteppingAction * GetLBNESteppingManager()
double GetBeamAngleTheta() const
G4String GetOutputNtpFileName() 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 fParticleDY[kMaxP]
void FillTrackingPlaneDPData(const G4Step &aStep)
double GetBeamOffsetX() const
std::string GetBuildTimeStamp() 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
G4String GetOutputDk2NuFileName() const
int GetVerboseLevel() const
G4bool CreateDk2NuOutput()
TTree * fTargetOutputTree
G4String GetMaterialName1rst() const
G4String GetParticleName() const
bool GetUseRealisticNearDetectorVolume() const
TTree * fHorn1TrackingTree
G4double GetDistanceInVolume(LBNETrajectory *wanted_traj, G4String wanted_vol)
int GetNumberOfHornsPolycone() const
void FillTargetOutputData(const G4Step &aStep)
virtual int GetPointEntries() const
bool GetCreateDk2NuOutput() const
virtual G4ThreeVector GetMomentum(G4int i) const
G4int AsInt(LBNEParticleCode_t pCode)
double GetHornCurrent() const
double GetBeamOffsetZ() const
LBNEDataNtp_t * fTrackingPlaneData
std::vector< G4String > fDetNameFar
std::vector< G4String > GetHorn1ICList() const
QTextStream & endl(QTextStream &s)
double fParticleDX[kMaxP]
double GetKillTrackingThreshold() const
std::vector< G4double > fZdet_near
bool GetCreateTrkPlaneH2Output() const