78 #ifndef ANALYSISTREE_H
79 #define ANALYSISTREE_H
82 #include "art/Framework/Core/ModuleMacros.h"
83 #include "art/Framework/Core/EDAnalyzer.h"
84 #include "art/Framework/Principal/Event.h"
85 #include "art/Framework/Principal/SubRun.h"
86 #include "art/Framework/Principal/Handle.h"
87 #include "art/Framework/Principal/View.h"
88 #include "canvas/Persistency/Common/Ptr.h"
89 #include "canvas/Persistency/Common/PtrVector.h"
90 #include "art/Framework/Services/Registry/ServiceHandle.h"
91 #include "art_root_io/TFileService.h"
92 #include "art_root_io/TFileDirectory.h"
93 #include "canvas/Persistency/Common/FindMany.h"
94 #include "canvas/Persistency/Common/FindOneP.h"
95 #include "fhiclcpp/ParameterSet.h"
96 #include "messagefacility/MessageLogger/MessageLogger.h"
100 #include "nusimdata/SimulationBase/MCTruth.h"
101 #include "nusimdata/SimulationBase/MCFlux.h"
134 #include <functional>
138 #include "TTimeStamp.h"
148 template <
typename T>
165 template <
typename Array_t>
176 { std::memcpy((
char*) &(
data()), (
char*) &(from.
data()),
sizeof(Array_t)); }
202 operator decltype(&
array[0]) ()
const {
return &
array[0]; }
220 template <
typename T>
222 template <
typename T>
224 template <
typename T>
225 using HitData_t = std::vector<BoxedArray<T[kNplanes][kMaxTrackHits]>>;
226 template <
typename T>
305 void Resize(
size_t nTracks);
449 std::vector<Float_t>
Px;
450 std::vector<Float_t>
Py;
451 std::vector<Float_t>
Pz;
452 std::vector<Float_t>
P;
485 template <
typename T>
527 void SetBits(
unsigned int setbits,
bool unset =
false)
528 {
if (unset)
bits &= ~setbits;
else bits |= setbits; }
592 (std::string
name,
void* address, std::string leaflist )
595 TBranch* pBranch =
pTree->GetBranch(
name.c_str());
597 pTree->Branch(
name.c_str(), address, leaflist.c_str() );
598 MF_LOG_DEBUG(
"AnalysisTreeStructure")
599 <<
"Creating branch '" <<
name <<
" with leaf '" << leaflist <<
"'";
601 else if (pBranch->GetAddress() != address) {
602 pBranch->SetAddress(address);
603 MF_LOG_DEBUG(
"AnalysisTreeStructure")
604 <<
"Reassigning address to branch '" <<
name <<
"'";
607 MF_LOG_DEBUG(
"AnalysisTreeStructure")
608 <<
"Branch '" <<
name <<
"' is fine";
612 (std::string
name,
void* address,
const std::stringstream& leaflist )
614 template <
typename T>
616 (std::string
name, std::vector<T>& data, std::string leaflist )
617 {
return this->
operator() (
name, (
void*) data.data(), leaflist ); }
619 template <
typename T>
628 TBranch* pBranch =
pTree->GetBranch(name.c_str());
630 pTree->Branch(name.c_str(), &data);
633 MF_LOG_DEBUG(
"AnalysisTreeStructure")
634 <<
"Creating object branch '" << name
635 <<
" with " << TClass::GetClass(
typeid(T))->ClassName();
638 (*(
reinterpret_cast<std::vector<T>**
>(pBranch->GetAddress())) != &data)
645 pBranch->SetObject(&data);
646 MF_LOG_DEBUG(
"AnalysisTreeStructure")
647 <<
"Reassigning object to branch '" << name <<
"'";
650 MF_LOG_DEBUG(
"AnalysisTreeStructure")
651 <<
"Branch '" << name <<
"' is fine";
686 double length(
const simb::MCParticle& part, TVector3& start, TVector3&
end);
760 throw art::Exception(art::errors::LogicError)
761 <<
"AnalysisTree::SetTrackerAddresses(): no tracker #" << iTracker
778 throw art::Exception(art::errors::LogicError)
779 <<
"AnalysisTree::" << caller <<
": no data";
785 throw art::Exception(art::errors::LogicError)
786 <<
"AnalysisTree::" << caller <<
": no tree";
794 class AutoResettingStringSteam:
public std::ostringstream {
796 AutoResettingStringSteam& operator() () { str(
"");
return *
this; }
800 template <
typename ITER,
typename TYPE>
801 inline void FillWith(ITER
from, ITER to, TYPE
value)
805 template <
typename ITER,
typename TYPE>
806 inline void FillWith(ITER
from,
size_t n, TYPE
value)
810 template <
typename CONT,
typename V>
811 inline void FillWith(CONT& data,
const V&
value)
898 FillWith(trkId , -9999 );
899 FillWith(trkncosmictags_tagger, -9999 );
900 FillWith(trkcosmicscore_tagger, -99999.);
901 FillWith(trkcosmictype_tagger, -9999 );
902 FillWith(trkncosmictags_flashmatch, -9999 );
903 FillWith(trkcosmicscore_flashmatch, -99999.);
904 FillWith(trkcosmictype_flashmatch, -9999 );
905 FillWith(trkstartx , -99999.);
906 FillWith(trkstarty , -99999.);
907 FillWith(trkstartz , -99999.);
908 FillWith(trkstartd , -99999.);
909 FillWith(trkendx , -99999.);
910 FillWith(trkendy , -99999.);
911 FillWith(trkendz , -99999.);
912 FillWith(trkendd , -99999.);
913 FillWith(trktheta , -99999.);
914 FillWith(trkphi , -99999.);
915 FillWith(trkstartdcosx, -99999.);
916 FillWith(trkstartdcosy, -99999.);
917 FillWith(trkstartdcosz, -99999.);
918 FillWith(trkenddcosx , -99999.);
919 FillWith(trkenddcosy , -99999.);
920 FillWith(trkenddcosz , -99999.);
921 FillWith(trkthetaxz , -99999.);
922 FillWith(trkthetayz , -99999.);
927 FillWith(trklen , -99999.);
928 FillWith(trksvtxid , -1);
929 FillWith(trkevtxid , -1);
930 FillWith(trkpidbestplane, -1);
932 for (
size_t iTrk = 0; iTrk < MaxTracks; ++iTrk){
936 FillWith(trkke[iTrk] , -99999.);
937 FillWith(trkrange[iTrk] , -99999.);
938 FillWith(trkidtruth_recoutils_totaltrueenergy[iTrk] , -99999 );
939 FillWith(trkidtruth_recoutils_totalrecocharge[iTrk] , -99999 );
940 FillWith(trkidtruth_recoutils_totalrecohits[iTrk] , -99999 );
941 FillWith(trkidtruth[iTrk] , -99999 );
942 FillWith(trkorigin[iTrk] , -1 );
943 FillWith(trkpdgtruth[iTrk], -99999 );
944 FillWith(trkefftruth[iTrk], -99999.);
945 FillWith(trksimIDEenergytruth[iTrk], -99999.);
946 FillWith(trksimIDExtruth[iTrk], -99999.);
947 FillWith(trksimIDEytruth[iTrk], -99999.);
948 FillWith(trksimIDEztruth[iTrk], -99999.);
949 FillWith(trkpurtruth[iTrk], -99999.);
950 FillWith(trkpitchc[iTrk] , -99999.);
951 FillWith(ntrkhits[iTrk] , -9999 );
953 FillWith(trkdedx[iTrk], 0.);
954 FillWith(trkxp[iTrk], 0.);
955 FillWith(trkyp[iTrk], 0.);
956 FillWith(trkzp[iTrk], 0.);
957 FillWith(trkdqdx[iTrk], 0.);
958 FillWith(trkresrg[iTrk], 0.);
960 FillWith(trkxyz[iTrk], 0.);
962 FillWith(trkpidpdg[iTrk] , -1);
963 FillWith(trkpidchi[iTrk] , -99999.);
964 FillWith(trkpidchipr[iTrk] , -99999.);
965 FillWith(trkpidchika[iTrk] , -99999.);
966 FillWith(trkpidchipi[iTrk] , -99999.);
967 FillWith(trkpidchimu[iTrk] , -99999.);
968 FillWith(trkpidpida[iTrk] , -99999.);
975 TTree* pTree, std::string tracker,
bool isCosmics
977 if (MaxTracks == 0)
return;
981 AutoResettingStringSteam sstr;
983 std::string MaxTrackHitsIndexStr(
"[" + sstr.str() +
"]");
985 std::string TrackLabel = tracker;
986 std::string BranchName;
988 BranchName =
"ntracks_" + TrackLabel;
989 CreateBranch(BranchName, &ntracks, BranchName +
"/S");
990 std::string NTracksIndexStr =
"[" + BranchName +
"]";
992 BranchName =
"trkId_" + TrackLabel;
993 CreateBranch(BranchName, trkId, BranchName + NTracksIndexStr +
"/S");
995 BranchName =
"trkncosmictags_tagger_" + TrackLabel;
996 CreateBranch(BranchName, trkncosmictags_tagger, BranchName + NTracksIndexStr +
"/S");
998 BranchName =
"trkcosmicscore_tagger_" + TrackLabel;
999 CreateBranch(BranchName, trkcosmicscore_tagger, BranchName + NTracksIndexStr +
"/F");
1001 BranchName =
"trkcosmictype_tagger_" + TrackLabel;
1002 CreateBranch(BranchName, trkcosmictype_tagger, BranchName + NTracksIndexStr +
"/S");
1004 BranchName =
"trkncosmictags_flashmatch_" + TrackLabel;
1005 CreateBranch(BranchName, trkncosmictags_flashmatch, BranchName + NTracksIndexStr +
"/S");
1007 BranchName =
"trkcosmicscore_flashmatch_" + TrackLabel;
1008 CreateBranch(BranchName, trkcosmicscore_flashmatch, BranchName + NTracksIndexStr +
"/F");
1010 BranchName =
"trkcosmictype_flashmatch_" + TrackLabel;
1011 CreateBranch(BranchName, trkcosmictype_flashmatch, BranchName + NTracksIndexStr +
"/S");
1013 BranchName =
"trkke_" + TrackLabel;
1014 CreateBranch(BranchName, trkke, BranchName + NTracksIndexStr +
"[3]/F");
1016 BranchName =
"trkrange_" + TrackLabel;
1017 CreateBranch(BranchName, trkrange, BranchName + NTracksIndexStr +
"[3]/F");
1019 BranchName =
"trkidtruth_recoutils_totaltrueenergy_" + TrackLabel;
1020 CreateBranch(BranchName, trkidtruth_recoutils_totaltrueenergy, BranchName + NTracksIndexStr +
"[3]/I");
1022 BranchName =
"trkidtruth_recoutils_totalrecocharge_" + TrackLabel;
1023 CreateBranch(BranchName, trkidtruth_recoutils_totalrecocharge, BranchName + NTracksIndexStr +
"[3]/I");
1025 BranchName =
"trkidtruth_recoutils_totalrecohits_" + TrackLabel;
1026 CreateBranch(BranchName, trkidtruth_recoutils_totalrecohits, BranchName + NTracksIndexStr +
"[3]/I");
1028 BranchName =
"trkidtruth_" + TrackLabel;
1029 CreateBranch(BranchName, trkidtruth, BranchName + NTracksIndexStr +
"[3]/I");
1031 BranchName =
"trkorigin_" + TrackLabel;
1032 CreateBranch(BranchName, trkorigin, BranchName + NTracksIndexStr +
"[3]/S");
1034 BranchName =
"trkpdgtruth_" + TrackLabel;
1035 CreateBranch(BranchName, trkpdgtruth, BranchName + NTracksIndexStr +
"[3]/I");
1037 BranchName =
"trkefftruth_" + TrackLabel;
1038 CreateBranch(BranchName, trkefftruth, BranchName + NTracksIndexStr +
"[3]/F");
1040 BranchName =
"trksimIDEenergytruth_" + TrackLabel;
1041 CreateBranch(BranchName, trksimIDEenergytruth, BranchName + NTracksIndexStr +
"[3]/F");
1043 BranchName =
"trksimIDExtruth_" + TrackLabel;
1044 CreateBranch(BranchName, trksimIDExtruth, BranchName + NTracksIndexStr +
"[3]/F");
1046 BranchName =
"trksimIDEytruth_" + TrackLabel;
1047 CreateBranch(BranchName, trksimIDEytruth, BranchName + NTracksIndexStr +
"[3]/F");
1049 BranchName =
"trksimIDEztruth_" + TrackLabel;
1050 CreateBranch(BranchName, trksimIDEztruth, BranchName + NTracksIndexStr +
"[3]/F");
1052 BranchName =
"trkpurtruth_" + TrackLabel;
1053 CreateBranch(BranchName, trkpurtruth, BranchName + NTracksIndexStr +
"[3]/F");
1055 BranchName =
"trkpitchc_" + TrackLabel;
1056 CreateBranch(BranchName, trkpitchc, BranchName + NTracksIndexStr +
"[3]/F");
1058 BranchName =
"ntrkhits_" + TrackLabel;
1059 CreateBranch(BranchName, ntrkhits, BranchName + NTracksIndexStr +
"[3]/S");
1062 BranchName =
"trkdedx_" + TrackLabel;
1063 CreateBranch(BranchName, trkdedx, BranchName + NTracksIndexStr +
"[3]" + MaxTrackHitsIndexStr +
"/F");
1065 BranchName =
"trkxp_" + TrackLabel;
1066 CreateBranch(BranchName, trkxp, BranchName + NTracksIndexStr +
"[3]" + MaxTrackHitsIndexStr +
"/F");
1068 BranchName =
"trkyp_" + TrackLabel;
1069 CreateBranch(BranchName, trkyp, BranchName + NTracksIndexStr +
"[3]" + MaxTrackHitsIndexStr +
"/F");
1071 BranchName =
"trkzp_" + TrackLabel;
1072 CreateBranch(BranchName, trkzp, BranchName + NTracksIndexStr +
"[3]" + MaxTrackHitsIndexStr +
"/F");
1074 BranchName =
"trkdqdx_" + TrackLabel;
1075 CreateBranch(BranchName, trkdqdx, BranchName + NTracksIndexStr +
"[3]" + MaxTrackHitsIndexStr +
"/F");
1077 BranchName =
"trkresrg_" + TrackLabel;
1078 CreateBranch(BranchName, trkresrg, BranchName + NTracksIndexStr +
"[3]" + MaxTrackHitsIndexStr +
"/F");
1080 BranchName =
"trkxyz_" + TrackLabel;
1081 CreateBranch(BranchName, trkxyz, BranchName + NTracksIndexStr +
"[3]" + MaxTrackHitsIndexStr +
"/F");
1084 BranchName =
"trkstartx_" + TrackLabel;
1085 CreateBranch(BranchName, trkstartx, BranchName + NTracksIndexStr +
"/F");
1087 BranchName =
"trkstarty_" + TrackLabel;
1088 CreateBranch(BranchName, trkstarty, BranchName + NTracksIndexStr +
"/F");
1090 BranchName =
"trkstartz_" + TrackLabel;
1091 CreateBranch(BranchName, trkstartz, BranchName + NTracksIndexStr +
"/F");
1093 BranchName =
"trkstartd_" + TrackLabel;
1094 CreateBranch(BranchName, trkstartd, BranchName + NTracksIndexStr +
"/F");
1096 BranchName =
"trkendx_" + TrackLabel;
1097 CreateBranch(BranchName, trkendx, BranchName + NTracksIndexStr +
"/F");
1099 BranchName =
"trkendy_" + TrackLabel;
1100 CreateBranch(BranchName, trkendy, BranchName + NTracksIndexStr +
"/F");
1102 BranchName =
"trkendz_" + TrackLabel;
1103 CreateBranch(BranchName, trkendz, BranchName + NTracksIndexStr +
"/F");
1105 BranchName =
"trkendd_" + TrackLabel;
1106 CreateBranch(BranchName, trkendd, BranchName + NTracksIndexStr +
"/F");
1108 BranchName =
"trktheta_" + TrackLabel;
1109 CreateBranch(BranchName, trktheta, BranchName + NTracksIndexStr +
"/F");
1111 BranchName =
"trkphi_" + TrackLabel;
1112 CreateBranch(BranchName, trkphi, BranchName + NTracksIndexStr +
"/F");
1114 BranchName =
"trkstartdcosx_" + TrackLabel;
1115 CreateBranch(BranchName, trkstartdcosx, BranchName + NTracksIndexStr +
"/F");
1117 BranchName =
"trkstartdcosy_" + TrackLabel;
1118 CreateBranch(BranchName, trkstartdcosy, BranchName + NTracksIndexStr +
"/F");
1120 BranchName =
"trkstartdcosz_" + TrackLabel;
1121 CreateBranch(BranchName, trkstartdcosz, BranchName + NTracksIndexStr +
"/F");
1123 BranchName =
"trkenddcosx_" + TrackLabel;
1124 CreateBranch(BranchName, trkenddcosx, BranchName + NTracksIndexStr +
"/F");
1126 BranchName =
"trkenddcosy_" + TrackLabel;
1127 CreateBranch(BranchName, trkenddcosy, BranchName + NTracksIndexStr +
"/F");
1129 BranchName =
"trkenddcosz_" + TrackLabel;
1130 CreateBranch(BranchName, trkenddcosz, BranchName + NTracksIndexStr +
"/F");
1132 BranchName =
"trkthetaxz_" + TrackLabel;
1133 CreateBranch(BranchName, trkthetaxz, BranchName + NTracksIndexStr +
"/F");
1135 BranchName =
"trkthetayz_" + TrackLabel;
1136 CreateBranch(BranchName, trkthetayz, BranchName + NTracksIndexStr +
"/F");
1150 BranchName =
"trklen_" + TrackLabel;
1151 CreateBranch(BranchName, trklen, BranchName + NTracksIndexStr +
"/F");
1153 BranchName =
"trksvtxid_" + TrackLabel;
1154 CreateBranch(BranchName, trksvtxid, BranchName + NTracksIndexStr +
"/S");
1156 BranchName =
"trkevtxid_" + TrackLabel;
1157 CreateBranch(BranchName, trkevtxid, BranchName + NTracksIndexStr +
"/S");
1159 BranchName =
"trkpidpdg_" + TrackLabel;
1160 CreateBranch(BranchName, trkpidpdg, BranchName + NTracksIndexStr +
"[3]/I");
1162 BranchName =
"trkpidchi_" + TrackLabel;
1163 CreateBranch(BranchName, trkpidchi, BranchName + NTracksIndexStr +
"[3]/F");
1165 BranchName =
"trkpidchipr_" + TrackLabel;
1166 CreateBranch(BranchName, trkpidchipr, BranchName + NTracksIndexStr +
"[3]/F");
1168 BranchName =
"trkpidchika_" + TrackLabel;
1169 CreateBranch(BranchName, trkpidchika, BranchName + NTracksIndexStr +
"[3]/F");
1171 BranchName =
"trkpidchipi_" + TrackLabel;
1172 CreateBranch(BranchName, trkpidchipi, BranchName + NTracksIndexStr +
"[3]/F");
1174 BranchName =
"trkpidchimu_" + TrackLabel;
1175 CreateBranch(BranchName, trkpidchimu, BranchName + NTracksIndexStr +
"[3]/F");
1177 BranchName =
"trkpidpida_" + TrackLabel;
1178 CreateBranch(BranchName, trkpidpida, BranchName + NTracksIndexStr +
"[3]/F");
1180 BranchName =
"trkpidbestplane_" + TrackLabel;
1181 CreateBranch(BranchName, trkpidbestplane, BranchName + NTracksIndexStr +
"/S");
1253 FillWith(
pdg, -99999);
1254 FillWith(
status, -99999);
1255 FillWith(
Mass, -99999.);
1256 FillWith(
Eng, -99999.);
1257 FillWith(
EndE, -99999.);
1258 FillWith(
Px, -99999.);
1259 FillWith(
Py, -99999.);
1260 FillWith(
Pz, -99999.);
1261 FillWith(
P, -99999.);
1265 FillWith(
StartT, -99999.);
1266 FillWith(
EndT, -99999.);
1270 FillWith(
EndT, -99999.);
1271 FillWith(
theta, -99999.);
1272 FillWith(
phi, -99999.);
1284 FillWith(
Mother, -99999);
1303 FillWith(
cry_Px, -99999.);
1304 FillWith(
cry_Py, -99999.);
1305 FillWith(
cry_Pz, -99999.);
1306 FillWith(
cry_P, -99999.);
1313 FillWith(
cry_ND, -99999);
1320 for (
auto& partInfo:
AuxDetID) FillWith(partInfo, -9999);
1330 for (
auto& partInfo: *cont) FillWith(partInfo, -99999.);
1456 cry_Px.resize(nPrimaries);
1457 cry_Py.resize(nPrimaries);
1458 cry_Pz.resize(nPrimaries);
1459 cry_P.resize(nPrimaries);
1466 cry_ND.resize(nPrimaries);
1473 const std::vector<std::string>& trackers,
1478 CreateBranch(
"run",&
run,
"run/I");
1479 CreateBranch(
"subrun",&
subrun,
"subrun/I");
1480 CreateBranch(
"event",&
event,
"event/I");
1481 CreateBranch(
"evttime",&
evttime,
"evttime/D");
1482 CreateBranch(
"beamtime",&
beamtime,
"beamtime/D");
1484 CreateBranch(
"isdata",&
isdata,
"isdata/B");
1488 CreateBranch(
"no_hits",&
no_hits,
"no_hits/I");
1489 CreateBranch(
"hit_tpc",
hit_tpc,
"hit_tpc[no_hits]/S");
1490 CreateBranch(
"hit_plane",
hit_plane,
"hit_plane[no_hits]/S");
1491 CreateBranch(
"hit_wire",
hit_wire,
"hit_wire[no_hits]/S");
1492 CreateBranch(
"hit_channel",
hit_channel,
"hit_channel[no_hits]/S");
1493 CreateBranch(
"hit_peakT",
hit_peakT,
"hit_peakT[no_hits]/F");
1494 CreateBranch(
"hit_charge",
hit_charge,
"hit_charge[no_hits]/F");
1495 CreateBranch(
"hit_ph",
hit_ph,
"hit_ph[no_hits]/F");
1496 CreateBranch(
"hit_startT",
hit_startT,
"hit_startT[no_hits]/F");
1497 CreateBranch(
"hit_endT",
hit_endT,
"hit_endT[no_hits]/F");
1498 CreateBranch(
"hit_trkid",
hit_trkid,
"hit_trkid[no_hits]/S");
1499 CreateBranch(
"hit_nelec",
hit_nelec,
"hit_nelec[no_hits]/F");
1500 CreateBranch(
"hit_energy",
hit_energy,
"hit_energy[no_hits]/F");
1504 CreateBranch(
"nvtx",&
nvtx,
"nvtx/S");
1505 CreateBranch(
"vtx",
vtx,
"vtx[nvtx][3]/F");
1509 AutoResettingStringSteam sstr;
1511 std::string MaxTrackHitsIndexStr(
"[" + sstr.str() +
"]");
1514 CreateBranch(
"kNTracker",&kNTracker,
"kNTracker/B");
1516 std::string TrackLabel = trackers[i];
1517 std::string BranchName;
1521 TrackData[i].SetAddresses(pTree, TrackLabel, isCosmics);
1526 CreateBranch(
"mcevts_truth",&
mcevts_truth,
"mcevts_truth/I");
1527 CreateBranch(
"nuID_truth",
nuID_truth,
"nuID_truth[mcevts_truth]/I");
1528 CreateBranch(
"nuPDG_truth",
nuPDG_truth,
"nuPDG_truth[mcevts_truth]/I");
1529 CreateBranch(
"ccnc_truth",
ccnc_truth,
"ccnc_truth[mcevts_truth]/I");
1530 CreateBranch(
"mode_truth",
mode_truth,
"mode_truth[mcevts_truth]/I");
1531 CreateBranch(
"enu_truth",
enu_truth,
"enu_truth[mcevts_truth]/F");
1532 CreateBranch(
"Q2_truth",
Q2_truth,
"Q2_truth[mcevts_truth]/F");
1533 CreateBranch(
"W_truth",
W_truth,
"W_truth[mcevts_truth]/F");
1534 CreateBranch(
"hitnuc_truth",
hitnuc_truth,
"hitnuc_truth[mcevts_truth]/I");
1535 CreateBranch(
"nuvtxx_truth",
nuvtxx_truth,
"nuvtxx_truth[mcevts_truth]/F");
1536 CreateBranch(
"nuvtxy_truth",
nuvtxy_truth,
"nuvtxy_truth[mcevts_truth]/F");
1537 CreateBranch(
"nuvtxz_truth",
nuvtxz_truth,
"nuvtxz_truth[mcevts_truth]/F");
1538 CreateBranch(
"nu_dcosx_truth",
nu_dcosx_truth,
"nu_dcosx_truth[mcevts_truth]/F");
1539 CreateBranch(
"nu_dcosy_truth",
nu_dcosy_truth,
"nu_dcosy_truth[mcevts_truth]/F");
1540 CreateBranch(
"nu_dcosz_truth",
nu_dcosz_truth,
"nu_dcosz_truth[mcevts_truth]/F");
1541 CreateBranch(
"lep_mom_truth",
lep_mom_truth,
"lep_mom_truth[mcevts_truth]/F");
1542 CreateBranch(
"lep_dcosx_truth",
lep_dcosx_truth,
"lep_dcosx_truth[mcevts_truth]/F");
1543 CreateBranch(
"lep_dcosy_truth",
lep_dcosy_truth,
"lep_dcosy_truth[mcevts_truth]/F");
1544 CreateBranch(
"lep_dcosz_truth",
lep_dcosz_truth,
"lep_dcosz_truth[mcevts_truth]/F");
1546 CreateBranch(
"tpx_flux",
tpx_flux,
"tpx_flux[mcevts_truth]/F");
1547 CreateBranch(
"tpy_flux",
tpy_flux,
"tpy_flux[mcevts_truth]/F");
1548 CreateBranch(
"tpz_flux",
tpz_flux,
"tpz_flux[mcevts_truth]/F");
1549 CreateBranch(
"tptype_flux",
tptype_flux,
"tptype_flux[mcevts_truth]/I");
1552 CreateBranch(
"genie_primaries_pdg",
genie_primaries_pdg,
"genie_primaries_pdg[genie_no_primaries]/I");
1553 CreateBranch(
"genie_Eng",
genie_Eng,
"genie_Eng[genie_no_primaries]/F");
1554 CreateBranch(
"genie_Px",
genie_Px,
"genie_Px[genie_no_primaries]/F");
1555 CreateBranch(
"genie_Py",
genie_Py,
"genie_Py[genie_no_primaries]/F");
1556 CreateBranch(
"genie_Pz",
genie_Pz,
"genie_Pz[genie_no_primaries]/F");
1557 CreateBranch(
"genie_P",
genie_P,
"genie_P[genie_no_primaries]/F");
1558 CreateBranch(
"genie_status_code",
genie_status_code,
"genie_status_code[genie_no_primaries]/I");
1559 CreateBranch(
"genie_mass",
genie_mass,
"genie_mass[genie_no_primaries]/F");
1560 CreateBranch(
"genie_trackID",
genie_trackID,
"genie_trackID[genie_no_primaries]/I");
1561 CreateBranch(
"genie_ND",
genie_ND,
"genie_ND[genie_no_primaries]/I");
1562 CreateBranch(
"genie_mother",
genie_mother,
"genie_mother[genie_no_primaries]/I");
1568 CreateBranch(
"cry_primaries_pdg",
cry_primaries_pdg,
"cry_primaries_pdg[cry_no_primaries]/I");
1569 CreateBranch(
"cry_Eng",
cry_Eng,
"cry_Eng[cry_no_primaries]/F");
1570 CreateBranch(
"cry_Px",
cry_Px,
"cry_Px[cry_no_primaries]/F");
1571 CreateBranch(
"cry_Py",
cry_Py,
"cry_Py[cry_no_primaries]/F");
1572 CreateBranch(
"cry_Pz",
cry_Pz,
"cry_Pz[cry_no_primaries]/F");
1573 CreateBranch(
"cry_P",
cry_P,
"cry_P[cry_no_primaries]/F");
1574 CreateBranch(
"cry_StartPointx",
cry_StartPointx,
"cry_StartPointx[cry_no_primaries]/F");
1575 CreateBranch(
"cry_StartPointy",
cry_StartPointy,
"cry_StartPointy[cry_no_primaries]/F");
1576 CreateBranch(
"cry_StartPointz",
cry_StartPointz,
"cry_StartPointz[cry_no_primaries]/F");
1577 CreateBranch(
"cry_status_code",
cry_status_code,
"cry_status_code[cry_no_primaries]/I");
1578 CreateBranch(
"cry_mass",
cry_mass,
"cry_mass[cry_no_primaries]/F");
1579 CreateBranch(
"cry_trackID",
cry_trackID,
"cry_trackID[cry_no_primaries]/I");
1580 CreateBranch(
"cry_ND",
cry_ND,
"cry_ND[cry_no_primaries]/I");
1581 CreateBranch(
"cry_mother",
cry_mother,
"cry_mother[cry_no_primaries]/I");
1585 CreateBranch(
"no_primaries",&
no_primaries,
"no_primaries/I");
1588 CreateBranch(
"pdg",
pdg,
"pdg[geant_list_size]/I");
1589 CreateBranch(
"status",
status,
"status[geant_list_size]/I");
1590 CreateBranch(
"Mass",
Mass,
"Mass[geant_list_size]/F");
1591 CreateBranch(
"Eng",
Eng,
"Eng[geant_list_size]/F");
1592 CreateBranch(
"EndE",
EndE,
"EndE[geant_list_size]/F");
1593 CreateBranch(
"Px",
Px,
"Px[geant_list_size]/F");
1594 CreateBranch(
"Py",
Py,
"Py[geant_list_size]/F");
1595 CreateBranch(
"Pz",
Pz,
"Pz[geant_list_size]/F");
1596 CreateBranch(
"P",
P,
"P[geant_list_size]/F");
1597 CreateBranch(
"StartPointx",
StartPointx,
"StartPointx[geant_list_size]/F");
1598 CreateBranch(
"StartPointy",
StartPointy,
"StartPointy[geant_list_size]/F");
1599 CreateBranch(
"StartPointz",
StartPointz,
"StartPointz[geant_list_size]/F");
1600 CreateBranch(
"StartT",
StartT,
"StartT[geant_list_size]/F");
1601 CreateBranch(
"EndPointx",
EndPointx,
"EndPointx[geant_list_size]/F");
1602 CreateBranch(
"EndPointy",
EndPointy,
"EndPointy[geant_list_size]/F");
1603 CreateBranch(
"EndPointz",
EndPointz,
"EndPointz[geant_list_size]/F");
1604 CreateBranch(
"EndT",
EndT,
"EndT[geant_list_size]/F");
1605 CreateBranch(
"theta",
theta,
"theta[geant_list_size]/F");
1606 CreateBranch(
"phi",
phi,
"phi[geant_list_size]/F");
1607 CreateBranch(
"theta_xz",
theta_xz,
"theta_xz[geant_list_size]/F");
1608 CreateBranch(
"theta_yz",
theta_yz,
"theta_yz[geant_list_size]/F");
1609 CreateBranch(
"pathlen",
pathlen,
"pathlen[geant_list_size]/F");
1610 CreateBranch(
"inTPCActive",
inTPCActive,
"inTPCActive[geant_list_size]/I");
1611 CreateBranch(
"StartPointx_tpcAV",
StartPointx_tpcAV,
"StartPointx_tpcAV[geant_list_size]/F");
1612 CreateBranch(
"StartPointy_tpcAV",
StartPointy_tpcAV,
"StartPointy_tpcAV[geant_list_size]/F");
1613 CreateBranch(
"StartPointz_tpcAV",
StartPointz_tpcAV,
"StartPointz_tpcAV[geant_list_size]/F");
1614 CreateBranch(
"EndPointx_tpcAV",
EndPointx_tpcAV,
"EndPointx_tpcAV[geant_list_size]/F");
1615 CreateBranch(
"EndPointy_tpcAV",
EndPointy_tpcAV,
"EndPointy_tpcAV[geant_list_size]/F");
1616 CreateBranch(
"EndPointz_tpcAV",
EndPointz_tpcAV,
"EndPointz_tpcAV[geant_list_size]/F");
1617 CreateBranch(
"NumberDaughters",
NumberDaughters,
"NumberDaughters[geant_list_size]/I");
1618 CreateBranch(
"Mother",
Mother,
"Mother[geant_list_size]/I");
1619 CreateBranch(
"TrackId",
TrackId,
"TrackId[geant_list_size]/I");
1620 CreateBranch(
"MergedId",
MergedId,
"MergedId[geant_list_size]/I");
1621 CreateBranch(
"MotherNuId",
MotherNuId,
"MotherNuId[geant_list_size]/I");
1622 CreateBranch(
"process_primary",
process_primary,
"process_primary[geant_list_size]/I");
1630 throw art::Exception(art::errors::Configuration)
1631 <<
"Saving Auxiliary detector information requies saving GEANT information, "
1632 <<
"please set fSaveGeantInfo flag to true in your fhicl file and rerun.\n";
1634 std::ostringstream sstr;
1636 std::string MaxAuxDetIndexStr = sstr.str();
1637 CreateBranch(
"NAuxDets",
NAuxDets,
"NAuxDets[geant_list_size]/s");
1638 CreateBranch(
"AuxDetID",
AuxDetID,
"AuxDetID[geant_list_size]" + MaxAuxDetIndexStr +
"/S");
1639 CreateBranch(
"AuxDetEntryX",
entryX,
"AuxDetEntryX[geant_list_size]" + MaxAuxDetIndexStr +
"/F");
1640 CreateBranch(
"AuxDetEntryY",
entryY,
"AuxDetEntryY[geant_list_size]" + MaxAuxDetIndexStr +
"/F");
1641 CreateBranch(
"AuxDetEntryZ",
entryZ,
"AuxDetEntryZ[geant_list_size]" + MaxAuxDetIndexStr +
"/F");
1642 CreateBranch(
"AuxDetEntryT",
entryT,
"AuxDetEntryT[geant_list_size]" + MaxAuxDetIndexStr +
"/F");
1643 CreateBranch(
"AuxDetExitX",
exitX,
"AuxDetExitX[geant_list_size]" + MaxAuxDetIndexStr +
"/F");
1644 CreateBranch(
"AuxDetExitY",
exitY,
"AuxDetExitY[geant_list_size]" + MaxAuxDetIndexStr +
"/F");
1645 CreateBranch(
"AuxDetExitZ",
exitZ,
"AuxDetExitZ[geant_list_size]" + MaxAuxDetIndexStr +
"/F");
1646 CreateBranch(
"AuxDetExitT",
exitT,
"AuxDetExitT[geant_list_size]" + MaxAuxDetIndexStr +
"/F");
1647 CreateBranch(
"AuxDetExitPx",
exitPx,
"AuxDetExitPx[geant_list_size]" + MaxAuxDetIndexStr +
"/F");
1648 CreateBranch(
"AuxDetExitPy",
exitPy,
"AuxDetExitPy[geant_list_size]" + MaxAuxDetIndexStr +
"/F");
1649 CreateBranch(
"AuxDetExitPz",
exitPz,
"AuxDetExitPz[geant_list_size]" + MaxAuxDetIndexStr +
"/F");
1651 "CombinedEnergyDep[geant_list_size]" + MaxAuxDetIndexStr +
"/F");
1663 fTree(nullptr), fData(nullptr),
1664 fDigitModuleLabel (pset.
get<
std::string >(
"DigitModuleLabel") ),
1665 fHitsModuleLabel (pset.
get<
std::string >(
"HitsModuleLabel") ),
1666 fLArG4ModuleLabel (pset.
get<
std::string >(
"LArGeantModuleLabel") ),
1667 fCalDataModuleLabel (pset.
get<
std::string >(
"CalDataModuleLabel") ),
1668 fGenieGenModuleLabel (pset.
get<
std::string >(
"GenieGenModuleLabel") ),
1669 fCryGenModuleLabel (pset.
get<
std::string >(
"CryGenModuleLabel") ),
1670 fG4ModuleLabel (pset.
get<
std::string >(
"G4ModuleLabel") ),
1671 fVertexModuleLabel (pset.
get<
std::string> (
"VertexModuleLabel") ),
1672 fTrackModuleLabel (pset.
get<
std::
vector<
std::string> >(
"TrackModuleLabel")),
1673 fCalorimetryModuleLabel (pset.
get<
std::
vector<
std::string> >(
"CalorimetryModuleLabel")),
1674 fParticleIDModuleLabel (pset.
get<
std::
vector<
std::string> >(
"ParticleIDModuleLabel") ),
1675 fPOTModuleLabel (pset.
get<
std::string >(
"POTModuleLabel") ),
1677 fSaveAuxDetInfo (pset.
get<
bool >(
"SaveAuxDetInfo",
false)),
1679 fSaveGenieInfo (pset.
get<
bool >(
"SaveGenieInfo",
false)),
1680 fSaveGeantInfo (pset.
get<
bool >(
"SaveGeantInfo",
false)),
1682 fSaveTrackInfo (pset.
get<
bool >(
"SaveTrackInfo",
false)),
1683 fSaveVertexInfo (pset.
get<
bool >(
"SaveVertexInfo",
false)),
1691 mf::LogInfo(
"AnalysisTree") <<
"Configuration:"
1692 <<
"\n UseBuffers: " << std::boolalpha <<
fUseBuffer
1695 throw art::Exception(art::errors::Configuration)
1696 <<
"AnalysisTree currently supports only up to " <<
kMaxTrackers
1697 <<
" tracking algorithms, but " <<
GetNTrackers() <<
" are specified."
1698 <<
"\nYou can increase kMaxTrackers and recompile.";
1701 throw art::Exception(art::errors::Configuration)
1706 throw art::Exception(art::errors::Configuration)
1720 art::ServiceHandle<art::TFileService>
tfs;
1721 fTree = tfs->make<TTree>(
"anatree",
"analysis tree");
1723 CreateData(bClearData);
1731 art::Handle< sumdata::POTSummary > potListHandle;
1734 if(sr.getByLabel(fPOTModuleLabel,potListHandle))
1735 SubRunData.pot=potListHandle->totpot;
1744 art::ServiceHandle<geo::Geometry> geom;
1745 art::ServiceHandle<cheat::BackTrackerService> backTracker;
1746 art::ServiceHandle<cheat::ParticleInventoryService> partInventory;
1751 bool isMC = !evt.isRealData();
1754 art::Handle< std::vector<recob::Hit> > hitListHandle;
1755 std::vector<art::Ptr<recob::Hit> > hitlist;
1756 if (evt.getByLabel(fHitsModuleLabel,hitListHandle))
1757 art::fill_ptr_vector(hitlist, hitListHandle);
1760 art::Handle< std::vector<recob::Vertex> > vtxListHandle;
1761 std::vector<art::Ptr<recob::Vertex> > vtxlist;
1762 if (evt.getByLabel(fVertexModuleLabel,vtxListHandle))
1763 art::fill_ptr_vector(vtxlist, vtxListHandle);
1767 art::Handle< std::vector<simb::MCTruth> > mctruthListHandle;
1768 std::vector<art::Ptr<simb::MCTruth> > mclist;
1769 if (evt.getByLabel(fGenieGenModuleLabel,mctruthListHandle))
1770 art::fill_ptr_vector(mclist, mctruthListHandle);
1773 art::Handle< std::vector<simb::MCTruth> > mctruthcryListHandle;
1774 std::vector<art::Ptr<simb::MCTruth> > mclistcry;
1776 if (evt.getByLabel(fCryGenModuleLabel,mctruthcryListHandle))
1777 art::fill_ptr_vector(mclistcry, mctruthcryListHandle);
1780 art::Ptr<simb::MCTruth> mctruthcry;
1781 int nCryPrimaries = 0;
1784 mctruthcry = mclistcry[0];
1785 nCryPrimaries = mctruthcry->NParticles();
1788 int nGeniePrimaries = 0, nGEANTparticles = 0, nMCNeutrinos = 0;
1790 auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
1791 art::Ptr<simb::MCTruth> mctruth;
1798 if (!mclist.empty()){
1805 static bool isfirsttime =
true;
1807 for (
size_t i = 0; i<hitlist.size(); i++){
1809 std::vector<sim::TrackIDE> eveIDs = backTracker->HitToEveTrackIDEs(clockData, hitlist[i]);
1810 for (
size_t e = 0;
e<eveIDs.size();
e++){
1811 art::Ptr<simb::MCTruth> ev_mctruth = partInventory->TrackIdToMCTruth_P(eveIDs[
e].trackID);
1817 isfirsttime =
false;
1833 mctruth = mclist[0];
1835 if (mctruth->NeutrinoSet()) nGeniePrimaries = mctruth->NParticles();
1838 const sim::ParticleList& plist = partInventory->ParticleList();
1839 nGEANTparticles = plist.size();
1844 MF_LOG_DEBUG(
"AnalysisTree") <<
"Expected "
1845 << nGEANTparticles <<
" GEANT particles, "
1846 << nGeniePrimaries <<
" GENIE particles";
1851 nMCNeutrinos = mclist.size();
1854 if (fSaveGenieInfo){
1855 fData->ResizeGenie(nGeniePrimaries);
1856 fData->ResizeMCNeutrino(nMCNeutrinos);
1859 fData->ResizeCry(nCryPrimaries);
1861 fData->ResizeGEANT(nGEANTparticles);
1862 fData->ClearLocalData();
1865 const size_t NTrackers = GetNTrackers();
1866 const size_t NHits = hitlist.size();
1867 const size_t NVertices = vtxlist.size();
1873 fData->SubRunData = SubRunData;
1875 fData->isdata = int(!isMC);
1877 std::vector< art::Handle< std::vector<recob::Track> > > trackListHandle(NTrackers);
1878 std::vector< std::vector<art::Ptr<recob::Track> > > tracklist(NTrackers);
1879 for (
unsigned int it = 0; it < NTrackers; ++it){
1880 if (evt.getByLabel(fTrackModuleLabel[it],trackListHandle[it]))
1881 art::fill_ptr_vector(tracklist[it], trackListHandle[it]);
1884 art::Handle< std::vector<simb::MCFlux> > mcfluxListHandle;
1885 std::vector<art::Ptr<simb::MCFlux> > fluxlist;
1886 if (evt.getByLabel(fGenieGenModuleLabel,mcfluxListHandle))
1887 art::fill_ptr_vector(fluxlist, mcfluxListHandle);
1889 std::vector<const sim::AuxDetSimChannel*> fAuxDetSimChannels;
1890 if (fSaveAuxDetInfo && fSaveGeantInfo){
1891 evt.getView(fLArG4ModuleLabel, fAuxDetSimChannels);
1894 std::vector<const sim::SimChannel*> fSimChannels;
1895 if (isMC && fSaveGeantInfo){
1896 evt.getView(fLArG4ModuleLabel, fSimChannels);
1899 fData->run = evt.run();
1900 fData->subrun = evt.subRun();
1901 fData->event = evt.id().event();
1903 art::Timestamp ts = evt.time();
1904 TTimeStamp tts(ts.timeHigh(), ts.timeLow());
1905 fData->evttime = tts.AsDouble();
1908 art::Handle< raw::BeamInfo >
beam;
1909 if (evt.getByLabel(
"beam",beam)){
1910 fData->beamtime = (double)beam->get_t_ms();
1911 fData->beamtime/=1000.;
1920 fData->no_hits = (int) NHits;
1924 mf::LogError(
"AnalysisTree:limits") <<
"event has " << NHits
1925 <<
" hits, only kMaxHits=" <<
kMaxHits <<
" stored in tree";
1927 for (
size_t i = 0; i < NHits && i <
kMaxHits ; ++i){
1928 fData->hit_channel[i] = hitlist[i]->Channel();
1929 fData->hit_tpc[i] = hitlist[i]->WireID().TPC;
1930 fData->hit_plane[i] = hitlist[i]->WireID().Plane;
1931 fData->hit_wire[i] = hitlist[i]->WireID().Wire;
1932 fData->hit_peakT[i] = hitlist[i]->PeakTime();
1933 fData->hit_charge[i] = hitlist[i]->Integral();
1934 fData->hit_ph[i] = hitlist[i]->PeakAmplitude();
1935 fData->hit_startT[i] = hitlist[i]->PeakTimeMinusRMS();
1936 fData->hit_endT[i] = hitlist[i]->PeakTimePlusRMS();
1948 if (!evt.isRealData()){
1949 fData -> hit_nelec[i] = 0;
1950 fData -> hit_energy[i] = 0;
1952 for(
size_t sc = 0; sc < fSimChannels.size(); ++sc){
1953 if(fSimChannels[sc]->Channel() == hitlist[i]->Channel()) chan = fSimChannels[sc];
1956 for (
auto const& tdcide: chan->
TDCIDEMap()) {
1958 std::vector<sim::IDE>
const& idevec = tdcide.second;
1959 for(
auto const& ide: idevec) {
1960 fData -> hit_nelec[i] += ide.numElectrons;
1961 fData -> hit_energy[i] += ide.energy;
1968 if (evt.getByLabel(fHitsModuleLabel,hitListHandle)){
1970 art::FindManyP<recob::Track> fmtk(hitListHandle,evt,fTrackModuleLabel[0]);
1971 for (
size_t i = 0; i < NHits && i <
kMaxHits ; ++i){
1972 if (fmtk.isValid()){
1973 if (fmtk.at(i).size()!=0){
1974 fData->hit_trkid[i] = fmtk.at(i)[0]->ID();
1977 fData->hit_trkid[i] = -1;
1984 if (fSaveVertexInfo){
1985 fData->nvtx = NVertices;
1989 mf::LogError(
"AnalysisTree:limits") <<
"event has " << NVertices
1990 <<
" vertices, only kMaxVertices=" <<
kMaxVertices <<
" stored in tree";
1992 for (
size_t i = 0; i < NVertices && i <
kMaxVertices ; ++i){
1993 Double_t xyz[3] = {};
1994 vtxlist[i]->XYZ(xyz);
1995 for (
size_t j = 0; j<3; ++j) fData->vtx[i][j] = xyz[j];
2000 if (fSaveTrackInfo){
2001 for (
unsigned int iTracker=0; iTracker < NTrackers; ++iTracker){
2004 size_t NTracks = tracklist[iTracker].size();
2006 TrackerData.
SetMaxTracks(std::max(NTracks, (
size_t) 1));
2007 TrackerData.
Clear();
2009 TrackerData.
ntracks = (int) NTracks;
2013 SetTrackerAddresses(iTracker);
2017 mf::LogError(
"AnalysisTree:limits") <<
"event has " << NTracks
2018 <<
" " << fTrackModuleLabel[iTracker] <<
" tracks, only "
2025 for(
size_t iTrk=0; iTrk < NTracks; ++iTrk){
2028 if (fCosmicTaggerAssocLabel.size() > iTracker) {
2029 art::FindManyP<anab::CosmicTag> fmct(trackListHandle[iTracker],evt,fCosmicTaggerAssocLabel[iTracker]);
2030 if (fmct.isValid()){
2032 if (fmct.at(iTrk).size()>0){
2033 if(fmct.at(iTrk).size()>1)
2034 std::cerr <<
"\n Warning : more than one cosmic tag per track in module! assigning the first tag to the track" << fCosmicTaggerAssocLabel[iTracker];
2042 if (fFlashMatchAssocLabel.size() > iTracker) {
2044 art::FindManyP<anab::CosmicTag> fmbfm(trackListHandle[iTracker],evt,fFlashMatchAssocLabel[iTracker]);
2045 if (fmbfm.isValid()){
2047 if (fmbfm.at(iTrk).size()>0){
2048 if(fmbfm.at(iTrk).size()>1)
2049 std::cerr <<
"\n Warning : more than one cosmic tag per track in module! assigning the first tag to the track" << fFlashMatchAssocLabel[iTracker];
2057 art::Ptr<recob::Track> ptrack(trackListHandle[iTracker], iTrk);
2074 tlen = length(track);
2075 TrackID = track.
ID();
2077 double theta_xz = std::atan2(dir_start.X(), dir_start.Z());
2078 double theta_yz = std::atan2(dir_start.Y(), dir_start.Z());
2079 double dpos = bdist(pos);
2080 double dend = bdist(end);
2087 TrackerData.
trkendx[iTrk] = end.X();
2088 TrackerData.
trkendy[iTrk] = end.Y();
2089 TrackerData.
trkendz[iTrk] = end.Z();
2090 TrackerData.
trkendd[iTrk] = dend;
2091 TrackerData.
trktheta[iTrk] = dir_start.Theta();
2092 TrackerData.
trkphi[iTrk] = dir_start.Phi();
2102 TrackerData.
trklen[iTrk] = tlen;
2135 Float_t minsdist = 10000;
2136 Float_t minedist = 10000;
2137 for (
int ivx = 0; ivx < fData->nvtx && ivx <
kMaxVertices; ++ivx){
2138 Float_t sdist = sqrt(pow(TrackerData.
trkstartx[iTrk]-fData->vtx[ivx][0],2)+
2139 pow(TrackerData.
trkstarty[iTrk]-fData->vtx[ivx][1],2)+
2140 pow(TrackerData.
trkstartz[iTrk]-fData->vtx[ivx][2],2));
2141 Float_t edist = sqrt(pow(TrackerData.
trkendx[iTrk]-fData->vtx[ivx][0],2)+
2142 pow(TrackerData.
trkendy[iTrk]-fData->vtx[ivx][1],2)+
2143 pow(TrackerData.
trkendz[iTrk]-fData->vtx[ivx][2],2));
2144 if (sdist<minsdist){
2146 if (minsdist<10) TrackerData.
trksvtxid[iTrk] = ivx;
2148 if (edist<minedist){
2150 if (minedist<10) TrackerData.
trkevtxid[iTrk] = ivx;
2154 art::FindMany<anab::ParticleID> fmpid(trackListHandle[iTracker], evt, fParticleIDModuleLabel[iTracker]);
2155 if(fmpid.isValid()) {
2156 std::vector<const anab::ParticleID*> pids = fmpid.at(iTrk);
2157 if (pids.size() == 0){
2158 mf::LogError(
"AnalysisTree:limits")
2159 <<
"No track-PID association found for " << fTrackModuleLabel[iTracker]
2160 <<
" track " << iTrk <<
". Not saving particleID information.";
2163 double pidpdg[3] = {0,0,0};
2164 double pidchi[3] = {0.,0.,0.};
2165 for(
size_t planenum=0; planenum<3; ++planenum) {
2172 for (
size_t ipid=0; ipid<pids.size(); ipid++){
2173 std::vector<anab::sParticleIDAlgScores> AlgScoresVec = pids[ipid]->ParticleIDAlgScores();
2176 for (
size_t i_algscore=0; i_algscore<AlgScoresVec.size(); i_algscore++){
2189 if (AlgScore.
fPlaneMask.test(0)) planenum = 0;
2190 if (AlgScore.
fPlaneMask.test(1)) planenum = 1;
2191 if (AlgScore.
fPlaneMask.test(2)) planenum = 2;
2192 if (planenum<0 || planenum>2)
continue;
2197 if (AlgScore.
fValue<pidchi[planenum] || (pidchi[planenum] == 0. && AlgScore.
fValue>0.)){
2198 pidchi[planenum] = AlgScore.
fValue;
2199 pidpdg[planenum] = TMath::Abs(AlgScore.
fAssumedPdg);
2202 else if (TMath::Abs(AlgScore.
fAssumedPdg) == 2212){
2204 if (AlgScore.
fValue<pidchi[planenum] || (pidchi[planenum] == 0. && AlgScore.
fValue>0.)){
2205 pidchi[planenum] = AlgScore.
fValue;
2206 pidpdg[planenum] = TMath::Abs(AlgScore.
fAssumedPdg);
2209 else if (TMath::Abs(AlgScore.
fAssumedPdg) == 211){
2211 if (AlgScore.
fValue<pidchi[planenum] || (pidchi[planenum] == 0. && AlgScore.
fValue>0.)){
2212 pidchi[planenum] = AlgScore.
fValue;
2213 pidpdg[planenum] = TMath::Abs(AlgScore.
fAssumedPdg);
2216 else if (TMath::Abs(AlgScore.
fAssumedPdg) == 321){
2218 if (AlgScore.
fValue<pidchi[planenum] || (pidchi[planenum] == 0. && AlgScore.
fValue>0.)){
2219 pidchi[planenum] = AlgScore.
fValue;
2220 pidpdg[planenum] = TMath::Abs(AlgScore.
fAssumedPdg);
2233 for (
size_t planenum=0; planenum<3; planenum++){
2234 TrackerData.
trkpidchi[iTrk][planenum] = pidchi[planenum];
2235 TrackerData.
trkpidpdg[iTrk][planenum] = pidpdg[planenum];
2241 art::FindMany<anab::Calorimetry> fmcal(trackListHandle[iTracker], evt, fCalorimetryModuleLabel[iTracker]);
2242 if (fmcal.isValid()){
2243 std::vector<const anab::Calorimetry*> calos = fmcal.at(iTrk);
2247 mf::LogError(
"AnalysisTree:limits")
2248 <<
"the " << fTrackModuleLabel[iTracker] <<
" track #" << iTrk
2249 <<
" has " << calos.size() <<
" planes for calorimetry , only "
2252 for (
size_t ical = 0; ical<calos.size(); ++ical){
2253 if (!calos[ical])
continue;
2254 if (!calos[ical]->
PlaneID().isValid)
continue;
2255 int planenum = calos[ical]->PlaneID().Plane;
2256 if (planenum<0||planenum>2)
continue;
2257 TrackerData.
trkke[iTrk][planenum] = calos[ical]->KineticEnergy();
2258 TrackerData.
trkrange[iTrk][planenum] = calos[ical]->Range();
2260 TrackerData.
trkpitchc[iTrk][planenum]= calos[ical] -> TrkPitchC();
2261 const size_t NHits = calos[ical] ->
dEdx().size();
2262 TrackerData.
ntrkhits[iTrk][planenum] = (int) NHits;
2265 mf::LogError(
"AnalysisTree:limits")
2266 <<
"the " << fTrackModuleLabel[iTracker] <<
" track #" << iTrk
2267 <<
" has " << NHits <<
" hits on calorimetry plane #" << planenum
2272 for(
size_t iTrkHit = 0; iTrkHit < NHits && iTrkHit < TrackerData.
GetMaxHitsPerTrack(iTrk, planenum); ++iTrkHit) {
2273 TrackerData.
trkdedx[iTrk][planenum][iTrkHit] = (calos[ical] ->
dEdx())[iTrkHit];
2274 TrackerData.
trkdqdx[iTrk][planenum][iTrkHit] = (calos[ical] -> dQdx())[iTrkHit];
2275 TrackerData.
trkresrg[iTrk][planenum][iTrkHit] = (calos[ical] -> ResidualRange())[iTrkHit];
2276 const auto& TrkPos = (calos[ical] -> XYZ())[iTrkHit];
2277 auto& TrkXYZ = TrackerData.
trkxyz[iTrk][planenum][iTrkHit];
2278 TrkXYZ[0] = TrkPos.X();
2279 TrkXYZ[1] = TrkPos.Y();
2280 TrkXYZ[2] = TrkPos.Z();
2281 TrackerData.
trkxp[iTrk][planenum][iTrkHit] = TrkPos.X();
2282 TrackerData.
trkyp[iTrk][planenum][iTrkHit] = TrkPos.Y();
2283 TrackerData.
trkzp[iTrk][planenum][iTrkHit] = TrkPos.Z();
2299 art::FindManyP<recob::Hit> fmht(trackListHandle[iTracker], evt, fTrackModuleLabel[iTracker]);
2300 std::vector< art::Ptr<recob::Hit> > allHits = fmht.at(iTrk);
2301 std::vector< art::Ptr<recob::Hit> > hits[
kNplanes];
2303 for(
size_t ah = 0; ah < allHits.size(); ++ah){
2305 allHits[ah]->
WireID().Plane < 3){
2306 hits[allHits[ah]->WireID().Plane].push_back(allHits[ah]);
2310 for (
size_t ipl = 0; ipl < 3; ++ipl){
2315 HitsPurity(clockData, hits[ipl],TrackerData.
trkidtruth[iTrk][ipl],TrackerData.
trkpurtruth[iTrk][ipl],maxe);
2318 const art::Ptr<simb::MCTruth> mc = partInventory->TrackIdToMCTruth_P(TrackerData.
trkidtruth[iTrk][ipl]);
2319 TrackerData.
trkorigin[iTrk][ipl] = mc->Origin();
2320 const simb::MCParticle *particle = partInventory->TrackIdToParticle_P(TrackerData.
trkidtruth[iTrk][ipl]);
2322 const std::vector<const sim::IDE*> vide(backTracker->TrackIdToSimIDEs_Ps(TrackerData.
trkidtruth[iTrk][ipl]));
2323 for (
auto ide: vide) {
2324 tote += ide->energy;
2330 TrackerData.
trkpdgtruth[iTrk][ipl] = particle->PdgCode();
2347 fData->mcevts_truthcry = mclistcry.size();
2348 fData->cry_no_primaries = nCryPrimaries;
2350 for(Int_t iPartc = 0; iPartc < mctruthcry->NParticles(); ++iPartc){
2351 const simb::MCParticle& partc(mctruthcry->GetParticle(iPartc));
2352 fData->cry_primaries_pdg[iPartc]=partc.PdgCode();
2353 fData->cry_Eng[iPartc]=partc.E();
2354 fData->cry_Px[iPartc]=partc.Px();
2355 fData->cry_Py[iPartc]=partc.Py();
2356 fData->cry_Pz[iPartc]=partc.Pz();
2357 fData->cry_P[iPartc]=partc.P();
2358 fData->cry_StartPointx[iPartc] = partc.Vx();
2359 fData->cry_StartPointy[iPartc] = partc.Vy();
2360 fData->cry_StartPointz[iPartc] = partc.Vz();
2361 fData->cry_status_code[iPartc]=partc.StatusCode();
2362 fData->cry_mass[iPartc]=partc.Mass();
2363 fData->cry_trackID[iPartc]=partc.TrackId();
2364 fData->cry_ND[iPartc]=partc.NumberDaughters();
2365 fData->cry_mother[iPartc]=partc.Mother();
2369 fData->mcevts_truth = mclist.size();
2373 art::FindOneP<simb::MCFlux> fmFluxNeutrino(mctruthListHandle, evt, fGenieGenModuleLabel);
2375 if (fData->mcevts_truth > 0){
2376 if (fSaveGenieInfo){
2382 fData->mcevts_truth = 0;
2383 for (
unsigned int i_mctruth = 0; i_mctruth < mclist.size(); i_mctruth++){
2385 art::Ptr<simb::MCTruth> curr_mctruth = mclist[i_mctruth];
2387 if (!curr_mctruth->NeutrinoSet())
continue;
2388 fData->nuPDG_truth[i_mctruth] = curr_mctruth->GetNeutrino().Nu().PdgCode();
2389 fData->ccnc_truth[i_mctruth] = curr_mctruth->GetNeutrino().CCNC();
2390 fData->mode_truth[i_mctruth] = curr_mctruth->GetNeutrino().Mode();
2391 fData->Q2_truth[i_mctruth] = curr_mctruth->GetNeutrino().QSqr();
2392 fData->W_truth[i_mctruth] = curr_mctruth->GetNeutrino().W();
2393 fData->hitnuc_truth[i_mctruth] = curr_mctruth->GetNeutrino().HitNuc();
2394 fData->enu_truth[i_mctruth] = curr_mctruth->GetNeutrino().Nu().E();
2395 fData->nuvtxx_truth[i_mctruth] = curr_mctruth->GetNeutrino().Nu().Vx();
2396 fData->nuvtxy_truth[i_mctruth] = curr_mctruth->GetNeutrino().Nu().Vy();
2397 fData->nuvtxz_truth[i_mctruth] = curr_mctruth->GetNeutrino().Nu().Vz();
2398 if (curr_mctruth->GetNeutrino().Nu().P()){
2399 fData->nu_dcosx_truth[i_mctruth] = curr_mctruth->GetNeutrino().Nu().Px()/curr_mctruth->GetNeutrino().Nu().P();
2400 fData->nu_dcosy_truth[i_mctruth] = curr_mctruth->GetNeutrino().Nu().Py()/curr_mctruth->GetNeutrino().Nu().P();
2401 fData->nu_dcosz_truth[i_mctruth] = curr_mctruth->GetNeutrino().Nu().Pz()/curr_mctruth->GetNeutrino().Nu().P();
2403 fData->lep_mom_truth[i_mctruth] = curr_mctruth->GetNeutrino().Lepton().P();
2404 if (curr_mctruth->GetNeutrino().Lepton().P()){
2405 fData->lep_dcosx_truth[i_mctruth] = curr_mctruth->GetNeutrino().Lepton().Px()/curr_mctruth->GetNeutrino().Lepton().P();
2406 fData->lep_dcosy_truth[i_mctruth] = curr_mctruth->GetNeutrino().Lepton().Py()/curr_mctruth->GetNeutrino().Lepton().P();
2407 fData->lep_dcosz_truth[i_mctruth] = curr_mctruth->GetNeutrino().Lepton().Pz()/curr_mctruth->GetNeutrino().Lepton().P();
2413 fData->nuID_truth[i_mctruth] = curr_mctruth.key();
2415 if (fmFluxNeutrino.isValid()){
2416 art::Ptr<simb::MCFlux> curr_mcflux = fmFluxNeutrino.at(i_mctruth);
2417 fData->tpx_flux[i_mctruth] = curr_mcflux->ftpx;
2418 fData->tpy_flux[i_mctruth] = curr_mcflux->ftpy;
2419 fData->tpz_flux[i_mctruth] = curr_mcflux->ftpz;
2420 fData->tptype_flux[i_mctruth] = curr_mcflux->ftptype;
2424 fData->mcevts_truth++;
2427 if (mctruth->NeutrinoSet()){
2462 fData->genie_no_primaries = mctruth->NParticles();
2464 size_t StoreParticles = std::min((
size_t) fData->genie_no_primaries, fData->GetMaxGeniePrimaries());
2465 if (fData->genie_no_primaries > (
int) StoreParticles) {
2468 mf::LogError(
"AnalysisTree:limits") <<
"event has "
2469 << fData->genie_no_primaries <<
" MC particles, only "
2470 << StoreParticles <<
" stored in tree";
2472 for(
size_t iPart = 0; iPart < StoreParticles; ++iPart){
2473 const simb::MCParticle& part(mctruth->GetParticle(iPart));
2474 fData->genie_primaries_pdg[iPart]=part.PdgCode();
2475 fData->genie_Eng[iPart]=part.E();
2476 fData->genie_Px[iPart]=part.Px();
2477 fData->genie_Py[iPart]=part.Py();
2478 fData->genie_Pz[iPart]=part.Pz();
2479 fData->genie_P[iPart]=part.P();
2480 fData->genie_status_code[iPart]=part.StatusCode();
2481 fData->genie_mass[iPart]=part.Mass();
2482 fData->genie_trackID[iPart]=part.TrackId();
2483 fData->genie_ND[iPart]=part.NumberDaughters();
2484 fData->genie_mother[iPart]=part.Mother();
2490 if (fSaveGeantInfo){
2491 const sim::ParticleList& plist = partInventory->ParticleList();
2493 std::string pri(
"primary");
2496 int geant_particle=0;
2497 sim::ParticleList::const_iterator itPart = plist.begin(),
2500 for(
size_t iPart = 0; (iPart < plist.size()) && (itPart != pend); ++iPart){
2501 const simb::MCParticle* pPart = (itPart++)->
second;
2503 throw art::Exception(art::errors::LogicError)
2504 <<
"GEANT particle #" << iPart <<
" returned a null pointer";
2508 bool isPrimary = pPart->Process() == pri;
2509 if (isPrimary) ++primary;
2511 int TrackID = pPart->TrackId();
2513 TVector3 mcstart, mcend;
2514 double plen = length(*pPart, mcstart, mcend);
2516 bool isActive = plen != 0;
2519 if (iPart < fData->GetMaxGEANTparticles()) {
2520 if (pPart->E()>
fG4minE||isPrimary){
2521 fData->process_primary[iPart] = int(isPrimary);
2522 fData->processname[iPart]= pPart->Process();
2523 fData->Mother[iPart]=pPart->Mother();
2524 fData->TrackId[iPart]=
TrackID;
2525 fData->pdg[iPart]=pPart->PdgCode();
2526 fData->status[iPart] = pPart->StatusCode();
2527 fData->Eng[iPart]=pPart->E();
2528 fData->EndE[iPart]=pPart->EndE();
2529 fData->Mass[iPart]=pPart->Mass();
2530 fData->Px[iPart]=pPart->Px();
2531 fData->Py[iPart]=pPart->Py();
2532 fData->Pz[iPart]=pPart->Pz();
2533 fData->P[iPart]=pPart->Momentum().Vect().Mag();
2534 fData->StartPointx[iPart]=pPart->Vx();
2535 fData->StartPointy[iPart]=pPart->Vy();
2536 fData->StartPointz[iPart]=pPart->Vz();
2537 fData->StartT[iPart] = pPart->T();
2538 fData->EndPointx[iPart]=pPart->EndPosition()[0];
2539 fData->EndPointy[iPart]=pPart->EndPosition()[1];
2540 fData->EndPointz[iPart]=pPart->EndPosition()[2];
2541 fData->EndT[iPart] = pPart->EndT();
2542 fData->theta[iPart] = pPart->Momentum().Theta();
2543 fData->phi[iPart] = pPart->Momentum().Phi();
2544 fData->theta_xz[iPart] = std::atan2(pPart->Px(), pPart->Pz());
2545 fData->theta_yz[iPart] = std::atan2(pPart->Py(), pPart->Pz());
2546 fData->pathlen[iPart] = plen;
2547 fData->NumberDaughters[iPart]=pPart->NumberDaughters();
2548 fData->inTPCActive[iPart] = int(isActive);
2550 fData->StartPointx_tpcAV[iPart] = mcstart.X();
2551 fData->StartPointy_tpcAV[iPart] = mcstart.Y();
2552 fData->StartPointz_tpcAV[iPart] = mcstart.Z();
2553 fData->EndPointx_tpcAV[iPart] = mcend.X();
2554 fData->EndPointy_tpcAV[iPart] = mcend.Y();
2555 fData->EndPointz_tpcAV[iPart] = mcend.Z();
2561 const art::Ptr<simb::MCTruth>& matched_mctruth = partInventory->ParticleToMCTruth_P(pPart);
2562 fData->MotherNuId[iPart] = matched_mctruth.key();
2565 if (fSaveAuxDetInfo) {
2566 unsigned short nAD = 0;
2573 const std::vector<sim::AuxDetIDE>& setOfIDEs = c->AuxDetIDEs();
2578 std::vector<sim::AuxDetIDE>::const_iterator iIDE
2580 setOfIDEs.begin(), setOfIDEs.end(),
2583 if (iIDE == setOfIDEs.end())
continue;
2591 for(
const auto& adtracks: setOfIDEs) {
2592 if( fabs(adtracks.trackID) ==
TrackID )
2593 totalE += adtracks.energyDeposited;
2598 fData->AuxDetID[iPart][nAD] = c->AuxDetID();
2599 fData->entryX[iPart][nAD] = iIDE->entryX;
2600 fData->entryY[iPart][nAD] = iIDE->entryY;
2601 fData->entryZ[iPart][nAD] = iIDE->entryZ;
2602 fData->entryT[iPart][nAD] = iIDE->entryT;
2603 fData->exitX[iPart][nAD] = iIDE->exitX;
2604 fData->exitY[iPart][nAD] = iIDE->exitY;
2605 fData->exitZ[iPart][nAD] = iIDE->exitZ;
2606 fData->exitT[iPart][nAD] = iIDE->exitT;
2607 fData->exitPx[iPart][nAD] = iIDE->exitMomentumX;
2608 fData->exitPy[iPart][nAD] = iIDE->exitMomentumY;
2609 fData->exitPz[iPart][nAD] = iIDE->exitMomentumZ;
2610 fData->CombinedEnergyDep[iPart][nAD] = totalE;
2614 fData->NAuxDets[iPart] = nAD;
2618 mf::LogError(
"AnalysisTree:limits") <<
"particle #" << iPart
2619 <<
" touches " << nAD <<
" auxiliary detector cells, only "
2620 <<
kMaxAuxDets <<
" of them are saved in the tree";
2624 else if (iPart == fData->GetMaxGEANTparticles()) {
2627 mf::LogError(
"AnalysisTree:limits") <<
"event has "
2628 << plist.size() <<
" MC particles, only "
2629 << fData->GetMaxGEANTparticles() <<
" will be stored in tree";
2633 fData->geant_list_size_in_tpcAV = active;
2634 fData->no_primaries = primary;
2635 fData->geant_list_size = geant_particle;
2637 MF_LOG_DEBUG(
"AnalysisTree") <<
"Counted "
2638 << fData->geant_list_size <<
" GEANT particles ("
2639 << fData->geant_list_size_in_tpcAV <<
" in AV), "
2640 << fData->no_primaries <<
" primaries, "
2641 << fData->genie_no_primaries <<
" GENIE particles";
2643 FillWith(fData->MergedId, 0);
2646 std::map<int, size_t> TrackIDtoIndex;
2647 const size_t nTrackIDs = fData->TrackId.size();
2648 for (
size_t index = 0; index < nTrackIDs; ++index)
2649 TrackIDtoIndex.emplace(fData->TrackId[index], index);
2654 int currentMergedId = 1;
2655 for(
size_t iPart = fData->geant_list_size; iPart-- > 0; ) {
2657 if (fData->MergedId[iPart])
continue;
2659 fData->MergedId[iPart] = currentMergedId;
2662 int currentMotherTrackId = fData->Mother[iPart];
2663 while(currentMotherTrackId > 0) {
2665 std::map<int, size_t>::const_iterator iMother
2666 = TrackIDtoIndex.find(currentMotherTrackId);
2667 if (iMother == TrackIDtoIndex.end())
break;
2668 size_t currentMotherIndex = iMother->second;
2671 if (fData->pdg[iPart] != fData->pdg[currentMotherIndex])
break;
2674 fData->MergedId[currentMotherIndex] = currentMergedId;
2676 currentMotherTrackId = fData->Mother[currentMotherIndex];
2687 if (mf::isDebugEnabled()) {
2690 mf::LogDebug logStream(
"AnalysisTreeStructure");
2692 <<
"Tree data structure contains:"
2693 <<
"\n - " << fData->no_hits <<
" hits (" << fData->GetMaxHits() <<
")"
2694 <<
"\n - " << fData->genie_no_primaries <<
" genie primaries (" << fData->GetMaxGeniePrimaries() <<
")"
2695 <<
"\n - " << fData->geant_list_size <<
" GEANT particles (" << fData->GetMaxGEANTparticles() <<
"), "
2696 << fData->no_primaries <<
" primaries"
2697 <<
"\n - " << fData->geant_list_size_in_tpcAV <<
" GEANT particles in AV "
2698 <<
"\n - " << ((int) fData->kNTracker) <<
" trackers:"
2701 size_t iTracker = 0;
2702 for (
auto tracker = fData->TrackData.cbegin();
2703 tracker != fData->TrackData.cend(); ++tracker, ++iTracker
2706 <<
"\n -> " << tracker->ntracks <<
" " << fTrackModuleLabel[iTracker]
2707 <<
" tracks (" << tracker->GetMaxTracks() <<
")"
2709 for (
int iTrk = 0; iTrk < tracker->ntracks; ++iTrk) {
2710 logStream <<
"\n [" << iTrk <<
"] "<< tracker->ntrkhits[iTrk][0];
2711 for (
size_t ipl = 1; ipl < tracker->GetMaxPlanesPerTrack(iTrk); ++ipl)
2712 logStream <<
" + " << tracker->ntrkhits[iTrk][ipl];
2713 logStream <<
" hits (" << tracker->GetMaxHitsPerTrack(iTrk, 0);
2714 for (
size_t ipl = 1; ipl < tracker->GetMaxPlanesPerTrack(iTrk); ++ipl)
2715 logStream <<
" + " << tracker->GetMaxHitsPerTrack(iTrk, ipl);
2724 MF_LOG_DEBUG(
"AnalysisTreeStructure") <<
"Freeing the tree data structure";
2734 art::ServiceHandle<cheat::BackTrackerService> backTracker;
2736 std::map<int,double> trkide;
2738 for(
size_t h = 0;
h < hits.size(); ++
h){
2740 art::Ptr<recob::Hit>
hit = hits[
h];
2741 std::vector<sim::IDE> ides;
2743 std::vector<sim::TrackIDE> eveIDs = backTracker->HitToEveTrackIDEs(clockData, hit);
2745 for(
size_t e = 0;
e < eveIDs.size(); ++
e){
2747 trkide[eveIDs[
e].trackID] += eveIDs[
e].energy;
2753 for (std::map<int,double>::iterator ii = trkide.begin(); ii!=trkide.end(); ++ii){
2755 if ((ii->second)>maxe){
2757 trackid = ii->first;
2773 art::ServiceHandle<geo::Geometry> geom;
2780 std::cout << xyzcenter00[0] <<
" " << xyzcenter00[1] <<
" " << xyzcenter00[2] << std::endl;
2784 std::cout << xyzcenter01[0] <<
" " << xyzcenter01[1] <<
" " << xyzcenter01[2] << std::endl;
2788 std::cout << xyzcenter10[0] <<
" " << xyzcenter10[1] <<
" " << xyzcenter10[2] << std::endl;
2792 std::cout << xyzcenter11[0] <<
" " << xyzcenter11[1] <<
" " << xyzcenter11[2] << std::endl;
2797 std::cout << h00 <<
" " << w00 <<
" " << l00 << std::endl;
2800 double xmin = xyzcenter10[0]-w00;
2801 double xmax = xyzcenter11[0]+w00;
2802 double ymin = xyzcenter00[1]-h00;
2803 double ymax = xyzcenter00[1]+h00;
2804 double zmin = xyzcenter00[2]-l00/2;
2805 double zmax = xyzcenter00[2]+l00/2;
2815 d1=fabs(pos.X())-xmin;
2816 d2=xmax-fabs(pos.X());
2819 double d3 = pos.Y() -ymin;
2820 double d4 = ymax - pos.Y();
2821 double d5 = pos.Z()-zmin;
2822 double d6 = zmax - pos.Z();
2824 double result = std::min(std::min(std::min(std::min(std::min(d1, d2), d3), d4), d5), d6);
2838 art::ServiceHandle<geo::Geometry> geom;
2850 std::cout << xyzcenter00[0] <<
" " << xyzcenter00[1] <<
" " << xyzcenter00[2] << std::endl;
2854 std::cout << xyzcenter01[0] <<
" " << xyzcenter01[1] <<
" " << xyzcenter01[2] << std::endl;
2858 std::cout << xyzcenter10[0] <<
" " << xyzcenter10[1] <<
" " << xyzcenter10[2] << std::endl;
2862 std::cout << xyzcenter11[0] <<
" " << xyzcenter11[1] <<
" " << xyzcenter11[2] << std::endl;
2867 std::cout << h00 <<
" " << w00 <<
" " << l00 << std::endl;
2870 double xmin = xyzcenter10[0]-w00;
2871 double xmax = xyzcenter11[0]+w00;
2872 double ymin = xyzcenter00[1]-h00;
2873 double ymax = xyzcenter00[1]+h00;
2874 double zmin = xyzcenter00[2]-l00/2;
2875 double zmax = xyzcenter00[2]+l00/2;
2878 std::cout <<
"DET DIMENSIONS: xmin = " << xmin <<
" xmax = " << xmax <<
" ymin = " << ymin <<
" ymax = " << ymax <<
" zmin = " << zmin <<
" zmax = " << zmax << std::endl;
2882 int n = part.NumberTrajectoryPoints();
2885 for(
int i = 0; i <
n; ++i) {
2887 double mypos[3] = {part.Vx(i), part.Vy(i), part.Vz(i)};
2888 if (fabs(mypos[0]) >= xmin && fabs(mypos[0]) <= xmax && mypos[1] >= ymin && mypos[1] <= ymax && mypos[2] >= zmin && mypos[2] <= zmax){
2890 double xGen = part.Vx(i);
2902 TVector3 pos(newX,part.Vy(i),part.Vz(i));
2908 result += disp.Mag();
void ClearLocalData()
Clear all fields if this object (not the tracker algorithm data)
std::string fPOTModuleLabel
std::vector< Int_t > cry_trackID
std::vector< std::string > processname
TrackData_t< Float_t > trkcosmicscore_flashmatch
HitData_t< Float_t > trkyp
TrackData_t< Float_t > trkendd
std::vector< Float_t > cry_StartPointx
std::vector< Float_t > Eng
bool hasHitInfo() const
Returns whether we have Hit data.
AnalysisTreeDataStruct(size_t nTrackers=0)
Constructor; clears all fields.
std::vector< Int_t > process_primary
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
PlaneData_t< Float_t > trkpidchimu
std::remove_all_extents< Array_t >::type Data_t
std::vector< Float_t > StartPointz
std::vector< Float_t > lep_mom_truth
std::vector< Float_t > lep_dcosz_truth
Point GetActiveVolumeCenter() const
Returns the center of the TPC active volume in world coordinates [cm].
std::vector< Float_t > StartPointx
const Array_t & data() const
A wrapper to a C array (needed to embed an array into a vector)
std::vector< Int_t > TrackId
Utilities related to art service access.
bool isCosmics
if it contains cosmics
Short_t hit_tpc[kMaxHits]
std::vector< UShort_t > NAuxDets
Number of AuxDets crossed by this particle.
Float_t hit_nelec[kMaxHits]
std::vector< Float_t > StartPointy_tpcAV
Energy deposited on a readout channel by simulated tracks.
int TrueParticleIDFromTotalTrueEnergy(detinfo::DetectorClocksData const &clockData, const std::vector< art::Ptr< recob::Hit > > &hits, bool rollup_unsaved_ids=1)
double length(const recob::Track &track)
SubRunData_t SubRunData
subrun data collected at begin of subrun
TrackData_t< Short_t > trkcosmictype_flashmatch
std::vector< Float_t > W_truth
void ResizeGenie(int nPrimaries)
Resize the data strutcure for Genie primaries.
BEGIN_PROLOG could also be cerr
Float_t hit_energy[kMaxHits]
void operator()(std::string name, void *address, std::string leaflist)
Create a branch if it does not exist, and set its address.
std::vector< Int_t > genie_trackID
std::vector< Float_t > EndPointy
void ResizeMCNeutrino(int nNeutrinos)
Resize the data structure for MCNeutrino particles.
HitData_t< Float_t > trkdedx
Short_t hit_trkid[kMaxHits]
auto operator-(ptrdiff_t index) -> decltype(&*array)
double ActiveHalfHeight() const
Half height (associated with y coordinate) of active TPC volume [cm].
TrackData_t< Short_t > trkId
PlaneData_t< Int_t > trkpidpdg
std::vector< Float_t > EndPointx_tpcAV
HitData_t< Float_t > trkzp
std::vector< Float_t > lep_dcosx_truth
bool hasAuxDetector() const
Returns whether we have auxiliary detector data.
Int_t geant_list_size_in_tpcAV
Creates a simple ROOT tree with tracking and calorimetry information.
Declaration of signal hit object.
bool fSaveTrackInfo
whether to extract and save Hit information
size_t GetMaxGEANTparticles() const
Returns the number of GEANT particles for which memory is allocated.
AuxDetMCData_t< Float_t > entryY
Entry Y position of particle into AuxDet.
TrackData_t< Float_t > trkenddcosz
Float_t hit_peakT[kMaxHits]
constexpr unsigned short kMaxVertices
size_t GetMaxGeniePrimaries() const
Returns the number of GENIE primaries for which memory is allocated.
Geometry information for a single TPC.
void Clear()
Clear all fields.
PlaneData_t< Float_t > trkke
std::vector< Float_t > cry_Py
AuxDetMCData_t< Float_t > exitPz
Exit z momentum of particle out of AuxDet.
void SetAddresses()
Sets the addresses of all the tree branches, creating the missing ones.
PlaneData_t< Float_t > trkpidchipr
void SetMaxTracks(size_t maxTracks)
size_t NumberTrajectoryPoints() const
Various functions related to the presence and the number of (valid) points.
TrackData_t< Float_t > trkcosmicscore_tagger
Vector_t VertexDirection() const
double bdist(const recob::tracking::Point_t &pos)
size_t MaxTracks
maximum number of storable tracks
PlaneData_t< Short_t > trkorigin
information from the subrun
std::vector< Float_t > theta
std::vector< std::string > fTrackModuleLabel
constexpr int kMaxTrackers
auto operator*() -> decltype(*array)
std::vector< Float_t > nu_dcosy_truth
Definition of basic raw digits.
std::vector< Float_t > Py
std::vector< Float_t > genie_P
bool fSaveAuxDetInfo
whether to extract and save auxiliary detector data
std::string fGenieGenModuleLabel
std::string fCalDataModuleLabel
std::vector< BoxedArray< T[kNplanes]>> PlaneData_t
std::vector< Float_t > lep_dcosy_truth
static constexpr size_t size()
begin/end interface
process_name use argoneut_mc_hitfinder track
TrackDataStruct & GetTrackerData(size_t iTracker)
std::vector< Float_t > nuvtxz_truth
TTree * pTree
the tree to be worked on
AuxDetMCData_t< Float_t > entryX
Entry X position of particle into AuxDet.
std::vector< TrackDataStruct > TrackData
TrackData_t< Short_t > trkncosmictags_flashmatch
bool fUseBuffer
whether to use a permanent buffer (faster, huge memory)
float fValue
Result of Particle ID algorithm/test.
TrackData_t< Float_t > trkphi
Geometry information for a single cryostat.
PlaneData_t< Float_t > trksimIDEztruth
TrackData_t< Float_t > trklen
std::vector< Int_t > genie_mother
std::vector< Float_t > StartPointy
std::vector< Float_t > cry_Px
void DestroyData()
Destroy the local buffers (existing branches will point to invalid address!)
TrackData_t< Float_t > trkstartz
std::vector< std::string > fCosmicTaggerAssocLabel
whether to extract and save Vertex information
AuxDetMCData_t< Float_t > entryZ
Entry Z position of particle into AuxDet.
std::vector< Float_t > nuvtxy_truth
Little helper functor class to create or reset branches in a tree.
std::vector< std::string > fFlashMatchAssocLabel
std::vector< Int_t > inTPCActive
PlaneData_t< Float_t > trksimIDExtruth
bool hasGeantInfo() const
Returns whether we have Geant data.
std::vector< Float_t > genie_Eng
AuxDetMCData_t< Float_t > exitPx
Exit x momentum of particle out of AuxDet.
void SetBits(unsigned int setbits, bool unset=false)
Sets the specified bits.
std::bitset< 8 > fPlaneMask
Bitset for PlaneID used by algorithm, allowing for multiple planes and up to 8 total planes...
std::vector< Int_t > ccnc_truth
total_extent<T>value has the total number of elements of an array
void SetAddresses(TTree *pTree, const std::vector< std::string > &trackers, bool isCosmics)
Connect this object with a tree.
AuxDetMCData_t< Float_t > entryT
Entry T position of particle into AuxDet.
std::vector< Float_t > EndPointy_tpcAV
void SetTrackers(size_t nTrackers)
Allocates data structures for the given number of trackers (no Clear())
IDparameter< geo::PlaneID > PlaneID
Member type of validated geo::PlaneID parameter.
std::string fLArG4ModuleLabel
std::vector< Float_t > Q2_truth
static constexpr value_type value
process_name pandoraGausCryo1 vertexChargeCryo1 vertexStubCryo1 xmin
std::vector< Float_t > EndPointx
std::string fAlgName
< determined particle ID
AnalysisTreeDataStruct::SubRunData_t SubRunData
std::vector< Float_t > cry_Eng
Collection of particles crossing one auxiliary detector cell.
void HitsPurity(detinfo::DetectorClocksData const &clockData, std::vector< art::Ptr< recob::Hit > > const &hits, Int_t &trackid, Float_t &purity, double &maxe)
std::vector< Float_t > nu_dcosx_truth
void SetAddresses(TTree *pTree, std::string tracker, bool isCosmics)
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
void ResizeGEANT(int nParticles)
Resize the data strutcure for GEANT particles.
TrackData_t< Short_t > trksvtxid
std::vector< Float_t > EndE
std::vector< Float_t > StartPointx_tpcAV
PlaneData_t< Float_t > trkpidpida
std::vector< T > TrackData_t
std::vector< Int_t > cry_ND
kVariableType fVariableType
Variable type enum: defined in ParticleID_VariableTypeEnums.h. Set to kNotSet by default.
TrackData_t< Float_t > trktheta
Short_t hit_plane[kMaxHits]
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< Coord_t >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space. See recob::tracking::Coord_t for more details on the ...
object containing MC truth information necessary for making RawDigits and doing back tracking ...
Int_t no_primaries
! how many particles there is currently room for
TrackData_t< Float_t > trkstartdcosx
Int_t mcevts_truth
! The number of MCNeutrinos there is currently room for
unsigned int bits
complementary information
double Length(size_t p=0) const
Access to various track properties.
bool fSaveHitInfo
whether to extract and save Geant information
std::vector< Float_t > phi
std::vector< Float_t > Mass
Float_t vtx[kMaxVertices][3]
std::vector< Int_t > cry_status_code
IDparameter< geo::WireID > WireID
Member type of validated geo::WireID parameter.
AuxDetMCData_t< Float_t > exitT
Exit T position of particle out of AuxDet.
PlaneData_t< Float_t > trksimIDEytruth
std::vector< Float_t > cry_Pz
std::vector< Float_t > genie_Px
std::vector< Float_t > tpy_flux
std::vector< Float_t > pathlen
void Resize(size_t nTracks)
std::vector< Int_t > cry_mother
PlaneData_t< Short_t > ntrkhits
double ActiveHalfWidth() const
Half width (associated with x coordinate) of active TPC volume [cm].
std::string fDigitModuleLabel
bool hasVertexInfo() const
Returns whether we have Vertex data.
std::vector< Float_t > cry_StartPointz
HitData_t< Float_t > trkresrg
std::vector< Int_t > nuID_truth
std::string fHitsModuleLabel
AuxDetMCData_t< Float_t > CombinedEnergyDep
Sum energy of all particles with this trackID (+ID or -ID) in AuxDet.
Point_t const & Vertex() const
AuxDetMCData_t< Float_t > exitX
Exit X position of particle out of AuxDet.
auto end(FixedBins< T, C > const &) noexcept
Float_t hit_endT[kMaxHits]
std::vector< Float_t > Px
fSaveCaloCosmics(pset.get< bool >("SaveCaloCosmics", false))
HitData_t< Float_t > trkxp
TrackData_t< Short_t > trkpidbestplane
TrackData_t< Float_t > trkstartd
size_t GetMaxTrackers() const
Returns the number of trackers for which memory is allocated.
std::vector< Float_t > enu_truth
std::vector< Float_t > StartPointz_tpcAV
auto operator+(ptrdiff_t index) -> decltype(&*array)
PlaneData_t< Float_t > trkpitchc
void fill(const art::PtrVector< recob::Hit > &hits, int only_plane)
std::vector< Int_t > MergedId
std::vector< Int_t > cry_primaries_pdg
PlaneData_t< Int_t > trkidtruth_recoutils_totalrecocharge
bool hasCryInfo() const
Returns whether we have Cry data.
int TrueParticleIDFromTotalRecoHits(detinfo::DetectorClocksData const &clockData, const std::vector< art::Ptr< recob::Hit > > &hits, bool rollup_unsaved_ids=1)
PlaneData_t< Float_t > trkefftruth
std::vector< Int_t > MotherNuId
TrackData_t< Short_t > trkcosmictype_tagger
PlaneData_t< Float_t > trkpidchi
Short_t hit_wire[kMaxHits]
size_t GetMaxHits() const
Returns the number of hits for which memory is allocated.
TrackData_t< Float_t > trkendz
size_t GetMaxHitsPerTrack(int=0, int=0) const
TrackData_t< Float_t > trkstartdcosz
TrackDataStruct(size_t maxTracks)
Creates a tracker data structure allowing up to maxTracks tracks.
HitData_t< Float_t > trkdqdx
Declaration of cluster object.
std::vector< Int_t > mode_truth
TrackData_t< Float_t > trkstartdcosy
Definition of data types for geometry description.
float dEdx(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, const TCSlice &slc, TP3D &tp3d)
Provides recob::Track data product.
std::vector< Float_t > tpx_flux
double ActiveLength() const
Length (associated with z coordinate) of active TPC volume [cm].
Float_t hit_charge[kMaxHits]
std::vector< Float_t > genie_mass
std::vector< std::string > fCalorimetryModuleLabel
bool hasGenieInfo() const
Returns whether we have Genie data.
AuxDetMCData_t< Float_t > exitZ
Exit Z position of particle out of AuxDet.
std::vector< Float_t > cry_mass
void SetTrackerAddresses(size_t iTracker)
std::vector< Int_t > genie_ND
auto begin(FixedBins< T, C > const &) noexcept
TrackData_t< Float_t > trkthetaxz
bool hasTrackInfo() const
Returns whether we have Track data.
std::vector< Float_t > cry_StartPointy
BranchCreator(TTree *tree)
void ResizeCry(int nPrimaries)
Resize the data strutcure for Cry primaries.
std::vector< Int_t > NumberDaughters
constexpr int kMaxTrackHits
TrackData_t< Float_t > trkstarty
std::vector< Float_t > EndPointz
std::vector< Int_t > genie_status_code
Float_t hit_startT[kMaxHits]
PlaneData_t< Int_t > trkidtruth_recoutils_totaltrueenergy
TrackData_t< Float_t > trkendy
size_t GetNTrackers() const
Returns the number of trackers configured.
std::vector< Float_t > Pz
std::vector< Float_t > EndT
const Data_t * begin() const
void CreateTree(bool bClearData=false)
Create the output tree and the data structures, if needed.
TrackData_t< Float_t > trkenddcosx
void analyze(const art::Event &evt)
read access to event
std::string fG4ModuleLabel
std::vector< Float_t > theta_yz
std::vector< std::string > fParticleIDModuleLabel
Contains all timing reference information for the detector.
AnalysisTree(fhicl::ParameterSet const &pset)
const TPCGeo & TPC(unsigned int itpc) const
Return the itpc'th TPC in the cryostat.
TrackData_t< Float_t > trkthetayz
void CheckTree(std::string caller) const
Helper function: throws if no tree is available.
AuxDetMCData_t< Float_t > exitY
Exit Y position of particle out of AuxDet.
AuxDetMCData_t< Short_t > AuxDetID
Which AuxDet this particle went through.
bool fSaveCaloCosmics
save calorimetry information for cosmics
auto operator[](size_t index) -> decltype(*array)
Array interface.
Vector_t EndDirection() const
size_t GetMaxTracks() const
PlaneData_t< Float_t > trkpidchika
MC truth information to make RawDigits and do back tracking.
std::vector< Int_t > tptype_flux
std::vector< Float_t > cry_P
std::vector< Int_t > status
const TrackDataStruct & GetTrackerData(size_t iTracker) const
std::vector< BoxedArray< T[kNplanes][kMaxTrackHits][3]>> HitCoordData_t
Short_t hit_channel[kMaxHits]
object containing MC truth information necessary for making RawDigits and doing back tracking ...
std::vector< BoxedArray< T[kNplanes][kMaxTrackHits]>> HitData_t
std::vector< Int_t > genie_primaries_pdg
std::vector< Float_t > StartT
PlaneData_t< Float_t > trkpidchipi
std::string fCryGenModuleLabel
bool fSaveGenieInfo
whether to extract and save CRY particle data
Point_t const & End() const
PlaneData_t< Float_t > trksimIDEenergytruth
std::vector< Float_t > EndPointz_tpcAV
TDCIDEs_t const & TDCIDEMap() const
Returns all the deposited energy information as stored.
HitCoordData_t< Float_t > trkxyz
void CheckData(std::string caller) const
Helper function: throws if no data structure is available.
std::string fVertexModuleLabel
std::vector< Float_t > genie_Py
int TrueParticleIDFromTotalRecoCharge(detinfo::DetectorClocksData const &clockData, const std::vector< art::Ptr< recob::Hit > > &hits, bool rollup_unsaved_ids=1)
art::ServiceHandle< art::TFileService > tfs
AnalysisTreeDataStruct * fData
void beginSubRun(const art::SubRun &sr)
bool fSaveGeantInfo
whether to extract and save Genie information
TrackData_t< Short_t > trkncosmictags_tagger
PlaneData_t< Int_t > trkidtruth_recoutils_totalrecohits
AuxDetMCData_t< Float_t > exitPy
Exit y momentum of particle out of AuxDet.
TrackData_t< Short_t > trkevtxid
std::vector< Float_t > theta_xz
PlaneData_t< Float_t > trkrange
std::vector< Float_t > tpz_flux
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< Coord_t >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space. See recob::tracking::Coord_t for more detai...
std::vector< Float_t > nuvtxx_truth
TrackDataStruct()
Creates an empty tracker data structure.
BoxedArray(const This_t &from)
std::vector< Float_t > genie_Pz
std::vector< Int_t > hitnuc_truth
void CreateData(bool bClearData=false)
Creates the structure for the tree data; optionally initializes it.
std::vector< Int_t > nuPDG_truth
PlaneData_t< Int_t > trkpdgtruth
PlaneData_t< Int_t > trkidtruth
std::vector< Float_t > nu_dcosz_truth
fG4minE(pset.get< float >("G4minE", 0.01))
TrackData_t< Float_t > trkstartx
art framework interface to geometry description
BEGIN_PROLOG could also be cout
bool fSaveVertexInfo
whether to extract and save Track information
std::vector< Int_t > Mother
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
TrackData_t< Float_t > trkendx
size_t GetMaxPlanesPerTrack(int=0) const
int fAssumedPdg
PDG of particle hypothesis assumed by algorithm, if applicable. Set to 0 by default.
std::vector< BoxedArray< T[kMaxAuxDets]>> AuxDetMCData_t
const Data_t * end() const
constexpr unsigned short kMaxAuxDets
max number of auxiliary detector cells per MC particle
PlaneData_t< Float_t > trkpurtruth
size_t GetNTrackers() const
Returns the number of trackers for which data structures are allocated.
TrackData_t< Float_t > trkenddcosy