17 #include "art_root_io/TFileService.h" 22 #include "canvas/Persistency/Common/FindOne.h" 23 #include "canvas/Persistency/Common/FindOneP.h" 24 #include "canvas/Persistency/Common/FindMany.h" 25 #include "canvas/Persistency/Common/FindManyP.h" 30 #include "MCCheater/BackTracker.h" 51 #include "nurandom/RandomUtils/NuRandomService.h" 53 #include "CoreUtils/ServiceUtil.h" 57 #include "TDatabasePDG.h" 58 #include "TParticlePDG.h" 63 #include "CLHEP/Random/RandFlat.h" 67 #include <unordered_map> 69 #include "StandardRecord/StandardRecord.h" 73 typedef std::pair<float, std::string>
P;
103 float& forwardIonVal,
float& backwardIonVal);
105 float ionizeTruncate);
108 {
return a.first < b.first;}
202 fGeo = gar::providerFrom<geo::GeometryGAr>();
208 bool usegeniegenlabels =
242 float MCPtoVertDefault = 10.0*std::numeric_limits<Float_t>::epsilon();
266 consumesMany<std::vector<simb::MCTruth> >();
269 if (usegeniegenlabels) {
274 consumesMany<std::vector<simb::GTruth> >();
277 consumesMany<std::vector<sdp::GenieParticle> >();
279 consumes<std::vector<simb::MCParticle> >(
fGeantLabel);
282 consumes<std::vector<sdp::EnergyDeposit> >(
fGeantLabel);
285 consumes<std::vector<rec::Hit> >(
fHitLabel);
289 consumes<art::Assns<rec::Track, rec::Vertex> >(
fVertexLabel);
290 consumes<std::vector<rec::Vee> >(
fVeeLabel);
291 consumes<art::Assns<rec::Track, rec::Vee> >(
fVeeLabel);
292 consumes<std::vector<rec::TrackIoniz>>(
fTrackLabel);
293 consumes<art::Assns<rec::TrackIoniz, rec::Track>>(
fTrackLabel);
297 consumes<std::vector<gar::sdp::CaloDeposit> >(ecalgeanttag);
299 art::InputTag ecalrawtag(fRawCaloHitLabel, fInstanceLabelCalo);
300 consumes<std::vector<raw::CaloRawDigit> >(ecalrawtag);
303 consumes<std::vector<rec::CaloHit> >(ecalhittag);
305 art::InputTag ecalclustertag(fClusterLabel, fInstanceLabelCalo);
306 consumes<std::vector<rec::Cluster> >(ecalclustertag);
307 consumes<art::Assns<rec::Cluster, rec::CaloHit>>(ecalclustertag);
312 consumes<std::vector<gar::sdp::CaloDeposit> >(muidgeanttag);
314 art::InputTag muidrawtag(fRawMuIDHitLabel, fInstanceLabelMuID);
315 consumes<std::vector<raw::CaloRawDigit> >(muidrawtag);
318 consumes<std::vector<rec::CaloHit> >(muidhittag);
320 art::InputTag muidclustertag(fClusterMuIDLabel, fInstanceLabelMuID);
321 consumes<std::vector<rec::Cluster> >(muidclustertag);
322 consumes<art::Assns<rec::Cluster, rec::CaloHit>>(muidclustertag);
345 fTree = tfs->make<TTree>(
"recTree",
"recTree");
349 fTree->Branch(
"rec", &rec);
358 <<
" fWriteMCPTrajectory, but !fWriteMCinfo." 359 <<
" Line " << __LINE__ <<
" in file " << __FILE__ <<
std::endl;
366 <<
" fWriteMCCaloInfo, but !fWriteMCinfo." 367 <<
" Line " << __LINE__ <<
" in file " << __FILE__ <<
std::endl;
375 <<
" fWriteVertices, but !fWriteTracks." 376 <<
" Line " << __LINE__ <<
" in file " << __FILE__ <<
std::endl;
384 <<
" fWriteVees, but !fWriteTracks." 385 <<
" Line " << __LINE__ <<
" in file " << __FILE__ <<
std::endl;
392 <<
" fWriteMatchedTracks, but (!fWriteTracks || !fWriteCaloClusters)." 393 <<
" Line " << __LINE__ <<
" in file " << __FILE__ <<
std::endl;
398 TFile
infile(filename.c_str(),
"READ");
402 for (
int q = 0; q < 501; ++q) {
403 sprintf(str,
"%d", q);
408 m_pidinterp.insert( std::make_pair(q, (TH2F*)
infile.Get(s.c_str())->Clone(
"pidinterp")) );
423 fTree->SetBranchAddress(
"rec", &prec);
460 fPOTHist->Fill(.5, potsum->totgoodpot);
471 std::vector< art::Handle< std::vector<simb::MCTruth> > > mcthandlelist;
472 std::vector< art::Handle< std::vector<simb::GTruth> > > gthandlelist;
475 mcthandlelist = e.
getMany<std::vector<simb::MCTruth> >();
481 mcthandlelist.at(i) = e.
getHandle< std::vector<simb::MCTruth> >(itag);
482 if (!mcthandlelist.at(i)) {
484 <<
" Line " << __LINE__ <<
" in file " << __FILE__ <<
std::endl;
490 gthandlelist = e.
getMany<std::vector<simb::GTruth> >();
496 if (!gthandlelist.at(i)) {
498 <<
" Line " << __LINE__ <<
" in file " << __FILE__ <<
std::endl;
504 for (
size_t imchl = 0; imchl < mcthandlelist.size(); ++imchl) {
505 for (
auto const& mct : (*mcthandlelist.at(imchl)) ) {
506 if (mct.NeutrinoSet()) {
524 rec.
mc.
nu.push_back(srnu);
531 unsigned int nuidx = 0;
533 for (
size_t igthl = 0; igthl < gthandlelist.size(); ++igthl) {
534 for (
auto const&
gt : (*gthandlelist.at(igthl)) ) {
535 if(nuidx >= rec.
mc.
nu.size()) abort();
539 rec.
mc.
nu[nuidx].gint =
gt.fGint;
540 rec.
mc.
nu[nuidx].tgtPDG =
gt.ftgtPDG;
541 rec.
mc.
nu[nuidx].weight =
gt.fweight;
542 rec.
mc.
nu[nuidx].gT =
gt.fgT;
550 auto gparthandlelist = e.
getMany<std::vector<sdp::GenieParticle>>();
552 for (
size_t igphl = 0; igphl < gparthandlelist.size(); ++igphl) {
553 for (
auto const& gpart : (*gparthandlelist.at(igphl)) ) {
555 srgpart.
intidx = gpart.InteractionIndex();
556 srgpart.
idx = gpart.Index();
557 srgpart.
pdg = gpart.Pdg();
558 srgpart.
status = gpart.Status();
559 srgpart.
name = gpart.Name();
560 srgpart.
firstmom = gpart.FirstMother();
561 srgpart.
lastmom = gpart.LastMother();
563 srgpart.
lastdaugh = gpart.LastDaughter();
565 srgpart.
E = gpart.E();
566 srgpart.
mass = gpart.Mass();
568 rec.
mc.
gpart.push_back(srgpart);
576 throw cet::exception(
"CAFMaker") <<
" No simb::MCParticle branch." 577 <<
" Line " << __LINE__ <<
" in file " << __FILE__ <<
std::endl;
589 for (
auto const& mcp : (*MCPHandle) ) {
590 int TrackId = mcp.TrackId();
594 for (
auto const& mcp : (*MCPHandle) ) {
596 srpart.
trkid = mcp.TrackId();
597 srpart.
pdg = mcp.PdgCode();
601 TrkId momTrkId = mcp.Mother();
608 momPDG = (*MCPHandle).at(momIndex).PdgCode();
611 <<
" mcp trkid " << mcp.TrackId()
612 <<
" pdg code " << mcp.PdgCode()
613 <<
" could not find mother trk id " << momTrkId
614 <<
" in the TrackIdToIndex map" 615 <<
" creating process is [ " << mcp.Process() <<
" ]";
623 const TLorentzVector&
position = mcp.Position(0);
624 const TLorentzVector&
momentum = mcp.Momentum(0);
625 srpart.
start.
x = position.X();
626 srpart.
start.
y = position.Y();
627 srpart.
start.
z = position.Z();
628 srpart.
time = mcp.T();
629 srpart.
startp.
x = momentum.Px();
630 srpart.
startp.
y = momentum.Py();
631 srpart.
startp.
z = momentum.Pz();
633 const TLorentzVector& positionEnd = mcp.EndPosition();
634 const TLorentzVector& momentumEnd = mcp.EndMomentum();
635 srpart.
end.
x = positionEnd.X();
636 srpart.
end.
y = positionEnd.Y();
637 srpart.
end.
z = positionEnd.Z();
638 srpart.
endp.
x = momentumEnd.Px();
639 srpart.
endp.
y = momentumEnd.Py();
640 srpart.
endp.
z = momentumEnd.Pz();
641 srpart.
proc = mcp.Process();
642 srpart.
endproc = mcp.EndProcess();
644 rec.
mc.
part.push_back(srpart);
656 size_t nMCParticles = (*MCPHandle).size();
657 size_t iMCParticle = 0;
658 for (; iMCParticle<nMCParticles; ++iMCParticle) {
660 rec.
mc.
part[iMCParticle].vtxidx = -1;
662 if (rec.
mc.
part[iMCParticle].momidx!=-1)
break;
663 Float_t trackX = rec.
mc.
part[iMCParticle].start.x;
664 Float_t trackY = rec.
mc.
part[iMCParticle].start.y;
665 Float_t trackZ = rec.
mc.
part[iMCParticle].start.z;
667 for (
size_t imchl = 0; imchl < mcthandlelist.size(); ++imchl) {
668 for (
auto const& mct : (*mcthandlelist.at(imchl)) ) {
669 if (mct.NeutrinoSet()) {
671 Float_t vertX = nuw.
Nu().
EndX();
672 Float_t vertY = nuw.
Nu().
EndY();
673 Float_t vertZ = nuw.
Nu().
EndZ();
674 Float_t
dist =
std::hypot(trackX-vertX,trackY-vertY,trackZ-vertZ);
676 rec.
mc.
part[iMCParticle].vtxidx = vertexIndex;
688 for (; iMCParticle<nMCParticles; ++iMCParticle) {
689 int momIndex = rec.
mc.
part[iMCParticle].momidx;
690 int lastMCParticle = iMCParticle;
691 while (momIndex != -1) {
692 lastMCParticle = momIndex;
693 momIndex = rec.
mc.
part[momIndex].momidx;
695 rec.
mc.
part[iMCParticle].vtxidx = rec.
mc.
part[lastMCParticle].vtxidx;
701 for (
auto const& mcp : (*MCPHandle) ) {
702 const TDatabasePDG* databasePDG = TDatabasePDG::Instance();
703 const TParticlePDG* definition = databasePDG->GetParticle( mcp.PdgCode() );
705 if (definition==
nullptr || definition->Charge() == 0)
continue;
707 int trackId = mcp.TrackId();
708 for(
uint iTraj=0; iTraj < mcp.Trajectory().size(); iTraj++) {
709 float xTraj = mcp.Trajectory().X(iTraj);
710 float yTraj = mcp.Trajectory().Y(iTraj);
711 float zTraj = mcp.Trajectory().Z(iTraj);
715 if (rTraj >
rTPC)
continue;
721 srtrajpt.
t = mcp.Trajectory().T(iTraj);
723 srtrajpt.
px = mcp.Trajectory().Px(iTraj);
724 srtrajpt.
py = mcp.Trajectory().Py(iTraj);
725 srtrajpt.
pz = mcp.Trajectory().Pz(iTraj);
727 srtrajpt.
E = mcp.Trajectory().E(iTraj);
729 rec.
mc.
part[mcpIndex].traj.push_back(srtrajpt);
731 rec.
mc.
part[mcpIndex].trkid = trackId;
743 SimHitHandle = e.
getHandle< std::vector<gar::sdp::CaloDeposit> >(ecalgeanttag);
745 throw cet::exception(
"CAFMaker") <<
" No gar::sdp::CaloDeposit branch." 746 <<
" Line " << __LINE__ <<
" in file " << __FILE__ <<
std::endl;
751 MuIDSimHitHandle = e.
getHandle< std::vector<gar::sdp::CaloDeposit> >(muidgeanttag);
752 if (!MuIDSimHitHandle) {
753 throw cet::exception(
"CAFMaker") <<
" No gar::sdp::CaloDeposit branch." 754 <<
" Line " << __LINE__ <<
" in file " << __FILE__ <<
std::endl;
760 for (
auto const& SimHit : (*SimHitHandle) ) {
762 srsimhit.
x = SimHit.X();
763 srsimhit.
y = SimHit.Y();
764 srsimhit.
z = SimHit.Z();
765 srsimhit.
t = SimHit.Time();
766 srsimhit.
E = SimHit.Energy();
767 srsimhit.
trkid = SimHit.TrackID();
768 srsimhit.
cellid = SimHit.CellID();
778 for (
auto const& SimHit : (*MuIDSimHitHandle) ) {
780 srsimhit.
x = SimHit.X();
781 srsimhit.
y = SimHit.Y();
782 srsimhit.
z = SimHit.Z();
783 srsimhit.
t = SimHit.Time();
784 srsimhit.
E = SimHit.Energy();
785 srsimhit.
trkid = SimHit.TrackID();
786 srsimhit.
cellid = SimHit.CellID();
807 auto RawHitHandle = e.
getHandle<std::vector<gar::raw::CaloRawDigit> >(ecalrawtag);
809 throw cet::exception(
"CAFMaker") <<
" No :raw::CaloRawDigit branch." 810 <<
" Line " << __LINE__ <<
" in file " << __FILE__ <<
std::endl;
817 MuIDRawHitHandle = e.
getHandle< std::vector<gar::raw::CaloRawDigit> >(muidrawtag);
818 if (!MuIDRawHitHandle) {
819 throw cet::exception(
"CAFMaker") <<
" No :raw::CaloRawDigit branch." 820 <<
" Line " << __LINE__ <<
" in file " << __FILE__ <<
std::endl;
825 for (
auto const& DigiHit : (*RawHitHandle) ) {
827 srdig.
x = DigiHit.X();
828 srdig.
y = DigiHit.Y();
829 srdig.
z = DigiHit.Z();
830 srdig.
t = (DigiHit.Time().first + DigiHit.Time().second) / 2.0 ;
831 srdig.
adc = DigiHit.ADC().first;
832 srdig.
cellid = DigiHit.CellID();
839 for (
auto const& DigiHit : (*MuIDRawHitHandle) ) {
841 srdig.
x = DigiHit.X();
842 srdig.
y = DigiHit.Y();
843 srdig.
z = DigiHit.Z();
844 srdig.
t = (DigiHit.Time().first + DigiHit.Time().second) / 2.0 ;
845 srdig.
adc = DigiHit.ADC().first;
846 srdig.
cellid = DigiHit.CellID();
863 <<
" Line " << __LINE__ <<
" in file " << __FILE__ <<
std::endl;
867 for (
auto const&
Hit : (*HitHandle) ) {
869 srhit.
x =
Hit.Position()[0];
870 srhit.
y =
Hit.Position()[1];
871 srhit.
z =
Hit.Position()[2];
875 rec.
hit.
tpc.push_back(srhit);
885 auto RecoHitHandle = e.
getHandle< std::vector<rec::CaloHit> >(ecalrecotag);
886 if (!RecoHitHandle) {
888 <<
" Line " << __LINE__ <<
" in file " << __FILE__ <<
std::endl;
892 for (
auto const&
Hit : (*RecoHitHandle) ) {
894 srhit.
id =
Hit.getIDNumber();
895 srhit.
x =
Hit.Position()[0];
896 srhit.
y =
Hit.Position()[1];
897 srhit.
z =
Hit.Position()[2];
898 srhit.
t =
Hit.Time().first;
899 srhit.
E =
Hit.Energy();
913 MuIDRecoHitHandle = e.
getHandle< std::vector<rec::CaloHit> >(muirecotag);
914 if(!MuIDRecoHitHandle) {
916 <<
" Line " << __LINE__ <<
" in file " << __FILE__ <<
std::endl;
919 for (
auto const&
Hit : (*MuIDRecoHitHandle) ) {
921 srhit.
id =
Hit.getIDNumber();
922 srhit.
x =
Hit.Position()[0];
923 srhit.
y =
Hit.Position()[1];
924 srhit.
z =
Hit.Position()[2];
925 srhit.
t =
Hit.Time().first;
926 srhit.
E =
Hit.Energy();
950 if (!TPCClusterHandle) {
952 <<
" Line " << __LINE__ <<
" in file " << __FILE__ <<
std::endl;
960 art::FindManyP<rec::TPCCluster>* findManyTPCClusters = NULL;
961 art::FindOneP<rec::TrackIoniz>* findIonization = NULL;
966 <<
" Line " << __LINE__ <<
" in file " << __FILE__ <<
std::endl;
969 if (!TrackIonHandle) {
971 <<
" Line " << __LINE__ <<
" in file " << __FILE__ <<
std::endl;
974 findManyTPCClusters =
new art::FindManyP<rec::TPCCluster>(TrackHandle,
e,
fTrackLabel);
975 findIonization =
new art::FindOneP<rec::TrackIoniz>(TrackHandle,
e,
fTrackLabel);
979 if (!TrackTrajHandle) {
980 throw cet::exception(
"CAFMaker") <<
" No rec::TrackTrajectory branch." 981 <<
" Line " << __LINE__ <<
" in file " << __FILE__ <<
std::endl;
988 art::FindManyP<rec::Track, rec::TrackEnd>* findManyTrackEnd = NULL;
993 <<
" Line " << __LINE__ <<
" in file " << __FILE__ <<
std::endl;
995 findManyTrackEnd =
new art::FindManyP<rec::Track, rec::TrackEnd>(VertexHandle,
e,
fVertexLabel);
1000 art::FindManyP<rec::Track, rec::TrackEnd>* findManyVeeTrackEnd = NULL;
1005 <<
" Line " << __LINE__ <<
" in file " << __FILE__ <<
std::endl;
1007 findManyVeeTrackEnd =
new art::FindManyP<rec::Track, rec::TrackEnd>(VeeHandle,
e,
fVeeLabel);
1015 art::FindManyP<rec::Track, rec::TrackEnd>* findManyCALTrackEnd = NULL;
1020 RecoClusterHandle = e.
getHandle< std::vector<rec::Cluster> >(ecalclustertag);
1021 if (!RecoClusterHandle) {
1023 <<
" Line " << __LINE__ <<
" in file " << __FILE__ <<
std::endl;
1029 RecoClusterMuIDHandle = e.
getHandle< std::vector<rec::Cluster> >(muidclustertag);
1030 if (!RecoClusterMuIDHandle) {
1031 throw cet::exception(
"CAFMaker") <<
" No rec::Cluster (MuID) branch." 1032 <<
" Line " << __LINE__ <<
" in file " << __FILE__ <<
std::endl;
1043 findManyCALTrackEnd =
new art::FindManyP<rec::Track, rec::TrackEnd>(RecoClusterHandle,
e,
fECALAssnLabel);
1050 for (
auto const& TPCCluster : (*TPCClusterHandle) ) {
1052 srclust.
x = TPCCluster.Position()[0];
1053 srclust.
y = TPCCluster.Position()[1];
1054 srclust.
z = TPCCluster.Position()[2];
1055 srclust.
sig = TPCCluster.Signal();
1056 srclust.
rms = TPCCluster.RMS();
1057 const float* cov = TPCCluster.CovMatPacked();
1058 srclust.
cov.
xx = cov[0];
1059 srclust.
cov.
xy = cov[1];
1060 srclust.
cov.
xz = cov[2];
1061 srclust.
cov.
yy = cov[3];
1062 srclust.
cov.
yz = cov[4];
1063 srclust.
cov.
zz = cov[5];
1065 Int_t trackForThisTPCluster = -1;
1068 for (
auto const& track : (*TrackHandle) ) {
1069 for (
size_t iCluster=0; iCluster<track.NHits(); iCluster++) {
1070 auto const& trackedCluster =
1071 *(findManyTPCClusters->at(iTrack).at(iCluster));
1072 if (TPCCluster==trackedCluster) {
1073 trackForThisTPCluster = track.getIDNumber();
1082 srclust.
trkid = trackForThisTPCluster;
1092 for (
auto const& track : (*TrackHandle) ) {
1096 srtrk.
id = track.getIDNumber();
1102 track.Momentum_beg()*track.VtxDir()[1],
1103 track.Momentum_beg()*track.VtxDir()[2]);
1104 srtrk.
startq = track.ChargeBeg();
1110 track.Momentum_end()*track.EndDir()[1],
1111 track.Momentum_end()*track.EndDir()[2]);
1112 srtrk.
endq = track.ChargeEnd();
1114 srtrk.
fwd.
len = track.LengthForward();
1115 srtrk.
bak.
len = track.LengthBackward();
1116 srtrk.
fwd.
chi2 = track.ChisqForward();
1117 srtrk.
bak.
chi2 = track.ChisqBackward();
1121 TVector3 momF(track.Momentum_beg()*track.VtxDir()[0], track.Momentum_beg()*track.VtxDir()[1], track.Momentum_beg()*track.VtxDir()[2]);
1122 TVector3 momB(track.Momentum_end()*track.EndDir()[0], track.Momentum_end()*track.EndDir()[1], track.Momentum_end()*track.EndDir()[2]);
1125 float pF = momF.Mag();
1126 float pB = momB.Mag();
1127 std::vector< std::pair<int, float> > pidF =
processPIDInfo( pF );
1128 std::vector< std::pair<int, float> > pidB =
processPIDInfo( pB );
1131 for(
size_t ipid = 0; ipid < pidF.size(); ipid++) {
1133 srpid.
id = pidF.at(ipid).first;
1134 srpid.
prob = pidF.at(ipid).second;
1135 srtrk.
fwd.
pid.push_back(srpid);
1137 for(
size_t ipid = 0; ipid < pidB.size(); ipid++) {
1139 srpid.
id = pidB.at(ipid).first;
1140 srpid.
prob = pidB.at(ipid).second;
1141 srtrk.
bak.
pid.push_back(srpid);
1145 std::vector<std::pair<simb::MCParticle*,float>> trakt;
1152 if (srtrk.
mcidx > -1) {
1153 srtrk.
mcfrac = trakt[0].second;
1158 if (findIonization->isValid()) {
1161 float avgIonF, avgIonB;
1171 rec.
trk.push_back(srtrk);
1179 size_t iTrackTraj = 0;
1180 for (
auto const& tracktraj : (*TrackTrajHandle) ) {
1183 std::vector<TVector3>
temp = tracktraj.getFWDTrajectory();
1184 for(
size_t i = 0; i < temp.size(); i++) {
1185 srtrk.
fwd.
traj.emplace_back(temp.at(i).X(),
1190 temp = tracktraj.getBAKTrajectory();
1191 for(
size_t i = 0; i < temp.size(); i++) {
1192 srtrk.
bak.
traj.emplace_back(temp.at(i).X(),
1203 for (
auto const&
vertex : (*VertexHandle) ) {
1206 srvtx.
x =
vertex.Position()[0];
1207 srvtx.
y =
vertex.Position()[1];
1208 srvtx.
z =
vertex.Position()[2];
1212 if ( findManyTrackEnd->isValid() ) {
1213 srvtx.
ntrks = findManyTrackEnd->at(iVertex).size();
1216 int vertexCharge = 0;
1217 for (
int iVertexedTrack=0; iVertexedTrack < srvtx.
ntrks; ++iVertexedTrack) {
1223 rec::Track track = *(findManyTrackEnd->at(iVertex).at(iVertexedTrack));
1231 rec::TrackEnd fee = *(findManyTrackEnd->data(iVertex).at(iVertexedTrack));
1235 rec.
assn.
vtx.push_back(srassn);
1243 srvtx.
Q = vertexCharge;
1246 rec.
vtx.push_back(srvtx);
1256 for (
auto const& vee : (*VeeHandle) ) {
1258 srvee.
id = vee.getIDNumber();
1259 srvee.
x = vee.Position()[0];
1260 srvee.
y = vee.Position()[1];
1261 srvee.
z = vee.Position()[2];
1262 srvee.
t = vee.Time();
1263 srvee.
Kpipi.
p.
x = vee.FourMomentum(0).X();
1264 srvee.
Kpipi.
p.
y = vee.FourMomentum(0).Y();
1265 srvee.
Kpipi.
p.
z = vee.FourMomentum(0).Z();
1266 srvee.
Kpipi.
E = vee.FourMomentum(0).E();
1267 srvee.
Kpipi.
m = vee.FourMomentum(0).M();
1268 srvee.
Lppi.
p.
x = vee.FourMomentum(1).X();
1269 srvee.
Lppi.
p.
y = vee.FourMomentum(1).Y();
1270 srvee.
Lppi.
p.
z = vee.FourMomentum(1).Z();
1271 srvee.
Lppi.
E = vee.FourMomentum(1).E();
1272 srvee.
Lppi.
m = vee.FourMomentum(1).M();
1273 srvee.
Lpip.
p.
x = vee.FourMomentum(2).X();
1274 srvee.
Lpip.
p.
y = vee.FourMomentum(2).Y();
1275 srvee.
Lpip.
p.
z = vee.FourMomentum(2).Z();
1276 srvee.
Lpip.
E = vee.FourMomentum(2).E();
1277 srvee.
Lpip.
m = vee.FourMomentum(2).M();
1279 rec.
vee.push_back(srvee);
1282 if ( findManyVeeTrackEnd->isValid() ) {
1283 nVeeTracks = findManyVeeTrackEnd->at(iVee).size();
1286 for (
int iVeeTrack=0; iVeeTrack<nVeeTracks; ++iVeeTrack) {
1288 srassn.
veeid = vee.getIDNumber();
1291 rec::Track track = *(findManyVeeTrackEnd->at(iVee).at(iVeeTrack));
1294 rec::TrackEnd fee = *(findManyVeeTrackEnd->data(iVee).at(iVeeTrack));
1298 rec.
assn.
vee.push_back(srassn);
1309 for (
auto const&
cluster : (*RecoClusterHandle) ) {
1328 std::vector<std::pair<simb::MCParticle*,float>> trakt;
1334 if (srclust.
mcidx > -1) {
1335 srclust.
mcfrac = trakt[0].second;
1344 for (
auto const&
cluster : (*RecoClusterMuIDHandle) ) {
1363 std::vector<std::pair<simb::MCParticle*,float>> trakt;
1369 if (srclust.
mcidx > -1) {
1370 srclust.
mcfrac = trakt[0].second;
1385 size_t iCluster = 0;
1386 for (
auto const&
cluster : (*RecoClusterHandle) ) {
1387 int nCALedTracks(0);
1388 if ( findManyCALTrackEnd->isValid() ) {
1389 nCALedTracks = findManyCALTrackEnd->at(iCluster).size();
1391 for (
int iCALedTrack=0; iCALedTrack<nCALedTracks; ++iCALedTrack) {
1394 rec::Track track = *(findManyCALTrackEnd->at(iCluster).at(iCALedTrack));
1397 rec::TrackEnd fee = *(findManyCALTrackEnd->data(iCluster).at(iCALedTrack));
1417 float& forwardIonVal,
float& backwardIonVal) {
1421 std::vector<std::pair<float,float>> SigData = ion.
getFWD_dSigdXs();
1434 std::vector<std::pair<float,float>> dEvsX;
1442 if (SigData.size()==0)
return 0.0;
1443 float distAlongTrack = 0;
1444 std::vector<std::pair<float,float>>
::iterator littlebit = SigData.begin();
1445 for (; littlebit<(SigData.end()-1); ++littlebit) {
1446 float dE = std::get<0>(*littlebit);
1449 float dX = std::get<1>(*littlebit);
1450 distAlongTrack += dX;
1452 dX += std::get<1>(*(littlebit+1));
1453 float dEdX = dE/(0.5*dX);
1455 std::pair pushme = std::make_pair(dEdX,distAlongTrack);
1456 dEvsX.push_back( pushme );
1463 int goUpTo = ionizeTruncate * dEvsX.size() +0.5;
1464 if (goUpTo > (
int)dEvsX.size()) goUpTo = dEvsX.size();
1465 int i = 1;
float returnvalue = 0;
1466 littlebit = dEvsX.begin();
1467 for (; littlebit<dEvsX.end(); ++littlebit) {
1468 returnvalue += std::get<0>(*littlebit);
1470 if (i>goUpTo)
break;
1472 returnvalue /= goUpTo;
1486 float E[3], Px[3], Py[3], Pz[3];
1487 E[nu] = E[mu] = E[
pi] = -1e42;
1489 for (
int i=0; i<3;++i) {
1496 for (
int iPart=0; iPart<nPart; iPart++) {
1502 if (
abs(code) == 12 ||
abs(code) == 14 ||
abs(code) == 16 ) {
1504 E[nu] = Part.
E(); Px[nu] = Part.
Px(); Py[nu] = Part.
Py(); Pz[nu] = Part.
Pz();
1509 if (
abs(code) == 11 ||
abs(code) == 13 ||
abs(code) == 15 ) {
1511 E[mu] = Part.
E(); Px[mu] = Part.
Px(); Py[mu] = Part.
Py(); Pz[mu] = Part.
Pz();
1516 if ( code==111 ||
abs(code)==211 ) {
1518 E[
pi] = Part.
E(); Px[
pi] = Part.
Px(); Py[
pi] = Part.
Py(); Pz[
pi] = Part.
Pz();
1523 if ( E[nu]!=0 && E[mu]!=0 && E[pi]!=0)
break;
1528 E[nu] -= E[mu]; Px[nu] -= Px[mu]; Py[nu] -= Py[mu]; Pz[nu] -= Pz[mu];
1529 E[nu] -= E[
pi]; Px[nu] -= Px[
pi]; Py[nu] -= Py[
pi]; Pz[nu] -= Pz[
pi];
1530 float t = E[nu]*E[nu] -Px[nu]*Px[nu] -Py[nu]*Py[nu] -Pz[nu]*Pz[nu];
1541 std::vector<std::string> recopnamelist = {
"#pi",
"#mu",
"p",
"K",
"d",
"e"};
1542 std::vector<int> pdg_charged = {211, 13, 2212, 321, 1000010020, 11};
1543 std::vector< std::pair<int, float> >
pid;
1547 float dist = 100000000.;
1548 CLHEP::RandFlat FlatRand(
fEngine);
1550 for (
int q = 0; q < 501; ++q) {
1553 unsigned first = fulltitle.find(
"=");
1554 unsigned last = fulltitle.find(
"GeV");
1555 std::string substr = fulltitle.substr(first+1, last - first-1);
1556 float pidinterp_mom = std::atof(substr.c_str());
1558 float disttemp =
std::abs(pidinterp_mom - p);
1560 if( disttemp < dist ) {
1568 for (
int pidm = 0; pidm < 6; ++pidm) {
1571 std::vector< std::pair<float, std::string> > v_prob;
1574 for (
int pidr = 0; pidr < 6; ++pidr) {
1576 float prob =
m_pidinterp[qclosest]->GetBinContent(pidm+1, pidr+1);
1578 v_prob.push_back( std::make_pair(prob, recoparticlename) );
1582 if (v_prob.size() > 1) {
1584 std::sort(v_prob.begin(), v_prob.end());
1586 float random_number = FlatRand.fire();
1588 std::partial_sum(v_prob.begin(), v_prob.end(), v_prob.begin(), [](
const P& _x,
const P& _y){
return P(_x.first + _y.first, _y.second);});
1590 for(
size_t ivec = 0; ivec < v_prob.size()-1; ivec++) {
1591 if( random_number < v_prob.at(ivec+1).first && random_number >= v_prob.at(ivec).first ) {
1592 pid.push_back( std::make_pair(pdg_charged.at(
std::distance( recopnamelist.begin(), std::find(recopnamelist.begin(), recopnamelist.end(), v_prob.at(ivec+1).second) ) ), v_prob.at(ivec+1).first) );
1596 pid.push_back( std::make_pair(pdg_charged.at(
std::distance( recopnamelist.begin(), std::find(recopnamelist.begin(), recopnamelist.end(), v_prob.at(0).second) ) ), v_prob.at(0).first) );
double E(const int i=0) const
std::vector< SRGenieParticle > gpart
base_engine_t & createEngine(seed_t seed)
std::string fClusterLabel
module label for calo clusters rec::Cluster
std::vector< SRTrackPID > pid
bool fWriteCaloClusters
Write ECAL clusters. Default=true.
double Theta() const
angle between incoming and outgoing leptons, in radians
A 3-vector with more efficient storage than TVector3.
double Py(const int i=0) const
std::string fRawCaloHitLabel
module label for digitized calo hits raw::CaloRawDigit
std::string fInstanceLabelCalo
Instance name for ECAL.
float processOneDirection(std::vector< std::pair< float, float >> SigData, float ionizeTruncate)
SRHeader hdr
global event info
bool fWriteMCinfo
Info from MCTruth, GTruth Default=true.
std::vector< SRSimHit > muid
std::string fTPCClusterLabel
module label for TPC Clusters rec::TPCCluster
std::vector< SRDigit > muid
Handle< PROD > getHandle(SelectorBase const &) const
void endRun(const art::Run &run) override
const simb::MCParticle & Nu() const
CAFMaker & operator=(CAFMaker const &)=delete
bool fWriteCaloDigits
Raw digits for calorimetry. Default=false.
double Px(const int i=0) const
bool fWriteTPCClusters
Write TPCClusters info Default=true.
void FillRawInfo(art::Event const &e, caf::StandardRecord &rec)
bool fWriteMCCaloInfo
Write MC info for calorimeter Default=true.
bool fWriteVertices
Reco vertexes & their tracks Default=true.
float TPCXCent() const
Returns the X location of the center of the TPC in cm.
std::pair< float, std::string > P
Description of geometry of one entire detector.
bool fWriteCaloHits
Write ECAL hits. Default=true.
Cluster finding and building.
EDAnalyzer(fhicl::ParameterSet const &pset)
void analyze(art::Event const &e) override
bool fWriteMCPTrajectory
Write MCP Trajectory Default=true.
std::vector< SRClusterAssn > ecalclust
std::string fRawMuIDHitLabel
std::vector< SRRecoHit > muid
void FillHighLevelRecoInfo(art::Event const &e, caf::StandardRecord &rec)
std::vector< SRRecoHit > ecal
double dEdX(double KE, const simb::MCParticle *part)
std::string fMuIDHitLabel
std::enable_if_t< std::is_arithmetic_v< T >, T > hypot(T x, T y)
std::vector< SRVeeAssn > vee
bool fWriteTracks
Start/end X, P for tracks Default=true.
std::vector< std::string > fGeneratorLabels
std::string fTrackLabel
module label for TPC Tracks rec:Track
std::vector< SRDigit > ecal
int InteractionType() const
void processIonizationInfo(rec::TrackIoniz &ion, float ionizeTruncate, float &forwardIonVal, float &backwardIonVal)
std::vector< std::pair< simb::MCParticle *, float > > ClusterToMCParticles(rec::Cluster *const c)
const geo::GeometryCore * fGeo
pointer to the geometry
std::unordered_map< TrkId, Int_t > TrackIdToIndex
#define DEFINE_ART_MODULE(klass)
bool fWriteVees
Reco vees & their tracks Default=true.
float TPCRadius() const
Returns the radius of the TPC (y or z direction)
std::string fGeantLabel
module label for geant4 simulated hits
std::vector< Handle< PROD > > getMany(SelectorBase const &selector=MatchAllSelector{}) const
std::vector< SRTPCRecoHit > tpc
float avgion
average ionization
cheat::BackTrackerCore * BackTrack
T get(std::string const &key) const
bool fWriteMatchedTracks
Write ECAL-track Assns Default=true.
bool fWriteCohInfo
MC level t for coherent pi+. Default=false.
std::string fPOTSummaryLabel
std::vector< SRTrack > trk
SRVector3D start
Track 3D start point.
virtual void beginJob() override
void FillRecoInfo(art::Event const &e, caf::StandardRecord &rec)
float TPCZCent() const
Returns the Z location of the center of the TPC in cm.
void FillGeneratorMonteCarloInfo(art::Event const &e, caf::StandardRecord &rec)
SubRunNumber_t subRun() const
CodeOutputInterface * code
std::vector< SRSimHit > ecal
Definition of basic calo raw digits.
double distance(double x1, double y1, double z1, double x2, double y2, double z2)
SRVector3D end
Track 3D end point.
std::string fClusterMuIDLabel
module label for calo clusters rec::Cluster in MuID
std::string fPFLabel
module label for reco particles rec::PFParticle
float fMatchMCPtoVertDist
MCParticle to MC vertex match Default=roundoff.
static bool lessThan_byE(std::pair< float, float > a, std::pair< float, float > b)
Float_t fTPC_X
center of TPC stored as per-event & compressed by root
std::string fVertexLabel
module label for vertexes rec:Vertex
std::string fCaloHitLabel
module label for reco calo hits rec::CaloHit
std::vector< SRNeutrino > nu
std::vector< SRVector3D > traj
const simb::MCParticle & GetParticle(int i) const
std::vector< SRMuIDCluster > muid
std::vector< std::pair< int, float > > processPIDInfo(float p)
std::string fTrackTrajectoryLabel
module label for TPC Track Trajectories rec:TrackTrajectory
std::unordered_map< int, TH2F * > m_pidinterp
General GArSoft Utilities.
The StandardRecord is the primary top-level object in the Common Analysis File trees.
std::vector< std::string > fGENIEGeneratorLabels
std::vector< SRParticle > part
TrackEnd const TrackEndBeg
bool fWriteTrackTrajectories
Point traj of reco tracks Default=false.
float fIonizTruncate
Default=1.00;.
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
float TPCYCent() const
Returns the Y location of the center of the TPC in cm.
std::vector< std::pair< simb::MCParticle *, float > > TrackToMCParticles(rec::Track *const t)
std::optional< T > get_if_present(std::string const &key) const
std::string fHitLabel
module label for reco TPC hits rec::Hit
bool HasMuonDetector() const
CAFMaker(fhicl::ParameterSet const &p)
double Pz(const int i=0) const
std::string fVeeLabel
module label for conversion/decay vertexes rec:Vee
EventNumber_t event() const
float TPCLength() const
Returns the length of the TPC (x direction)
bool fWriteHits
Write info about TPC Hits Default=false.
bool fWriteMCPTrajMomenta
Write Momenta associated with MCP Trajectory Default=false.
gar::rec::IDNumber getIDNumber() const
Event generator information.
CLHEP::HepRandomEngine & fEngine
random engine
const std::vector< std::pair< float, float > > getBAK_dSigdXs() const
def momentum(x1, x2, x3, scale=1.)
float computeT(simb::MCTruth theMCTruth)
const std::vector< std::pair< float, float > > getFWD_dSigdXs() const
Event generator information.
art framework interface to geometry description
std::vector< SRECalCluster > ecal
std::string fInstanceLabelMuID
Instance name for MuID.
std::vector< SRVertexAssn > vtx
std::vector< SRVertex > vtx
cet::coded_exception< error, detail::translate > exception
QTextStream & endl(QTextStream &s)
QCString & append(const char *s)
std::string fECALAssnLabel
module label for track-clusters associations
std::vector< SRTPCCluster > tpc