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" 33 #include "MCCheater/BackTracker.h" 52 #include "nurandom/RandomUtils/NuRandomService.h" 54 #include "CoreUtils/ServiceUtil.h" 59 #include "TDatabasePDG.h" 60 #include "TParticlePDG.h" 65 #include "CLHEP/Random/RandFlat.h" 69 #include <unordered_map> 75 typedef std::pair<float, std::string>
P;
107 float& forwardIonVal,
float& backwardIonVal);
109 float ionizeTruncate);
112 {
return a.first < b.first;}
214 std::vector<Float_t>
fW;
215 std::vector<Float_t>
fX;
216 std::vector<Float_t>
fY;
218 std::vector<Float_t>
fT;
520 fGeo = gar::providerFrom<geo::GeometryGAr>();
534 bool usegeniegenlabels =
568 float MCPtoVertDefault = 10.0*std::numeric_limits<Float_t>::epsilon();
592 consumesMany<std::vector<simb::MCTruth> >();
595 if (usegeniegenlabels) {
600 consumesMany<std::vector<simb::GTruth> >();
603 consumesMany<std::vector<sdp::GenieParticle> >();
605 consumes<std::vector<simb::MCParticle> >(
fGeantLabel);
608 consumes<std::vector<sdp::EnergyDeposit> >(
fGeantLabel);
611 consumes<std::vector<rec::Hit> >(
fHitLabel);
615 consumes<art::Assns<rec::Track, rec::Vertex> >(
fVertexLabel);
616 consumes<std::vector<rec::Vee> >(
fVeeLabel);
617 consumes<art::Assns<rec::Track, rec::Vee> >(
fVeeLabel);
618 consumes<std::vector<rec::TrackIoniz>>(
fTrackLabel);
619 consumes<art::Assns<rec::TrackIoniz, rec::Track>>(
fTrackLabel);
623 consumes<std::vector<gar::sdp::CaloDeposit> >(ecalgeanttag);
625 art::InputTag ecalrawtag(fRawCaloHitLabel, fInstanceLabelCalo);
626 consumes<std::vector<raw::CaloRawDigit> >(ecalrawtag);
629 consumes<std::vector<rec::CaloHit> >(ecalhittag);
631 art::InputTag ecalclustertag(fClusterLabel, fInstanceLabelCalo);
632 consumes<std::vector<rec::Cluster> >(ecalclustertag);
633 consumes<art::Assns<rec::Cluster, rec::CaloHit>>(ecalclustertag);
638 consumes<std::vector<gar::sdp::CaloDeposit> >(muidgeanttag);
640 art::InputTag muidrawtag(fRawMuIDHitLabel, fInstanceLabelMuID);
641 consumes<std::vector<raw::CaloRawDigit> >(muidrawtag);
644 consumes<std::vector<rec::CaloHit> >(muidhittag);
646 art::InputTag muidclustertag(fClusterMuIDLabel, fInstanceLabelMuID);
647 consumes<std::vector<rec::Cluster> >(muidclustertag);
648 consumes<art::Assns<rec::Cluster, rec::CaloHit>>(muidclustertag);
671 fTree = tfs->make<TTree>(
"GArAnaTree",
"GArAnaTree");
750 <<
" fWriteMCPTrajectory, but !fWriteMCinfo." 751 <<
" Line " << __LINE__ <<
" in file " << __FILE__ <<
std::endl;
772 <<
" fWriteMCCaloInfo, but !fWriteMCinfo." 773 <<
" Line " << __LINE__ <<
" in file " << __FILE__ <<
std::endl;
879 <<
" fWriteVertices, but !fWriteTracks." 880 <<
" Line " << __LINE__ <<
" in file " << __FILE__ <<
std::endl;
900 <<
" fWriteVees, but !fWriteTracks." 901 <<
" Line " << __LINE__ <<
" in file " << __FILE__ <<
std::endl;
1027 <<
" fWriteMatchedTracks, but (!fWriteTracks || !fWriteCaloClusters)." 1028 <<
" Line " << __LINE__ <<
" in file " << __FILE__ <<
std::endl;
1037 TFile
infile(filename.c_str(),
"READ");
1041 for (
int q = 0; q < 501; ++q) {
1042 sprintf(str,
"%d", q);
1047 m_pidinterp.insert( std::make_pair(q, (TH2F*)
infile.Get(s.c_str())->Clone(
"pidinterp")) );
1057 auto const&
ID = run.
id();
1060 if (!summaryHandle) {
1061 MF_LOG_DEBUG(
"anatree") <<
" No sumdata::POTSummary branch for run " <<
ID 1062 <<
" Line " << __LINE__ <<
" in file " << __FILE__ <<
std::endl;
1071 <<
" The number of spills is " <<
fNSpills;
1433 std::vector< art::Handle< std::vector<simb::MCTruth> > > mcthandlelist;
1434 std::vector< art::Handle< std::vector<simb::GTruth> > > gthandlelist;
1437 mcthandlelist = e.
getMany<std::vector<simb::MCTruth> >();
1443 if (!mcthandlelist.at(i)) {
1445 <<
" Line " << __LINE__ <<
" in file " << __FILE__ <<
std::endl;
1451 gthandlelist = e.
getMany< std::vector<simb::GTruth> >();
1457 if (!gthandlelist.at(i)) {
1459 <<
" Line " << __LINE__ <<
" in file " << __FILE__ <<
std::endl;
1465 for (
size_t imchl = 0; imchl < mcthandlelist.size(); ++imchl) {
1466 for (
auto const& mct : (*mcthandlelist.at(imchl)) ) {
1467 if (mct.NeutrinoSet()) {
1474 fW.push_back(nuw.
W());
1475 fX.push_back(nuw.
X());
1476 fY.push_back(nuw.
Y());
1480 fT.push_back( static_cast<Float_t>(getT) );
1493 for (
size_t igthl = 0; igthl < gthandlelist.size(); ++igthl) {
1494 for (
auto const&
gt : (*gthandlelist.at(igthl)) ) {
1498 fgT.push_back(
gt.fgT);
1503 auto gparthandlelist = e.
getMany<std::vector<sdp::GenieParticle>>();
1505 for (
size_t igphl = 0; igphl < gparthandlelist.size(); ++igphl) {
1506 unsigned int nGPart = 0;
1507 for (
auto const& gpart : (*gparthandlelist.at(igphl)) ) {
1529 throw cet::exception(
"anatree") <<
" No simb::MCParticle branch." 1530 <<
" Line " << __LINE__ <<
" in file " << __FILE__ <<
std::endl;
1542 for (
auto const& mcp : (*MCPHandle) ) {
1543 int TrackId = mcp.TrackId();
1547 for (
auto const& mcp : (*MCPHandle) ) {
1549 fMCPDG.push_back(mcp.PdgCode());
1553 TrkId momTrkId = mcp.Mother();
1554 Int_t momIndex = -1;
1560 momPDG = (*MCPHandle).at(momIndex).PdgCode();
1563 <<
" mcp trkid " << mcp.TrackId()
1564 <<
" pdg code " << mcp.PdgCode()
1565 <<
" could not find mother trk id " << momTrkId
1566 <<
" in the TrackIdToIndex map" 1567 <<
" creating process is [ " << mcp.Process() <<
" ]";
1575 const TLorentzVector&
position = mcp.Position(0);
1576 const TLorentzVector&
momentum = mcp.Momentum(0);
1585 const TLorentzVector& positionEnd = mcp.EndPosition();
1586 const TLorentzVector& momentumEnd = mcp.EndMomentum();
1587 fMCPEndX.push_back(positionEnd.X());
1588 fMCPEndY.push_back(positionEnd.Y());
1589 fMCPEndZ.push_back(positionEnd.Z());
1604 size_t nMCParticles = (*MCPHandle).size();
1605 size_t iMCParticle = 0;
1607 for (; iMCParticle<nMCParticles; ++iMCParticle) {
1615 int vertexIndex = 0;
1616 for (
size_t imchl = 0; imchl < mcthandlelist.size(); ++imchl) {
1617 for (
auto const& mct : (*mcthandlelist.at(imchl)) ) {
1618 if (mct.NeutrinoSet()) {
1620 Float_t vertX = nuw.
Nu().
EndX();
1621 Float_t vertY = nuw.
Nu().
EndY();
1622 Float_t vertZ = nuw.
Nu().
EndZ();
1623 Float_t
dist =
std::hypot(trackX-vertX,trackY-vertY,trackZ-vertZ);
1637 for (; iMCParticle<nMCParticles; ++iMCParticle) {
1639 int lastMCParticle = iMCParticle;
1640 while (momIndex != -1) {
1641 lastMCParticle = momIndex;
1650 for (
auto const& mcp : (*MCPHandle) ) {
1651 const TDatabasePDG* databasePDG = TDatabasePDG::Instance();
1652 const TParticlePDG* definition = databasePDG->GetParticle( mcp.PdgCode() );
1656 if (mcp.PdgCode() != 1000020040)
1658 if (definition==
nullptr || definition->Charge() == 0)
continue;
1661 int trackId = mcp.TrackId();
1662 for(
uint iTraj=0; iTraj < mcp.Trajectory().size(); iTraj++) {
1663 float xTraj = mcp.Trajectory().X(iTraj);
1664 float yTraj = mcp.Trajectory().Y(iTraj);
1665 float zTraj = mcp.Trajectory().Z(iTraj);
1669 if (rTraj >
rTPC)
continue;
1674 fTrajMCPT.push_back(mcp.Trajectory().T(iTraj));
1676 fTrajMCPPX.push_back(mcp.Trajectory().Px(iTraj));
1677 fTrajMCPPY.push_back(mcp.Trajectory().Py(iTraj));
1678 fTrajMCPPZ.push_back(mcp.Trajectory().Pz(iTraj));
1680 fTrajMCPE.push_back(mcp.Trajectory().E(iTraj));
1692 auto SimHitHandle = e.
getHandle<std::vector<gar::sdp::CaloDeposit> >(ecalgeanttag);
1693 if (!SimHitHandle) {
1694 throw cet::exception(
"anatree") <<
" No gar::sdp::CaloDeposit branch." 1695 <<
" Line " << __LINE__ <<
" in file " << __FILE__ <<
std::endl;
1699 for (
auto const& SimHit : (*SimHitHandle) ) {
1716 MuIDSimHitHandle = e.
getHandle< std::vector<gar::sdp::CaloDeposit> >(muidgeanttag);
1717 if (!MuIDSimHitHandle) {
1718 throw cet::exception(
"anatree") <<
" No gar::sdp::CaloDeposit branch." 1719 <<
" Line " << __LINE__ <<
" in file " << __FILE__ <<
std::endl;
1724 for (
auto const& SimHit : (*MuIDSimHitHandle) ) {
1748 auto RawHitHandle = e.
getHandle<std::vector<gar::raw::CaloRawDigit> >(ecalrawtag);
1749 if (!RawHitHandle) {
1750 throw cet::exception(
"anatree") <<
" No :raw::CaloRawDigit branch." 1751 <<
" Line " << __LINE__ <<
" in file " << __FILE__ <<
std::endl;
1753 for (
auto const& DigiHit : (*RawHitHandle) ) {
1758 fDigiHitTime.push_back( (DigiHit.Time().first + DigiHit.Time().second) / 2.0 );
1768 MuIDRawHitHandle = e.
getHandle<std::vector<gar::raw::CaloRawDigit> >(muidrawtag);
1769 if (!MuIDRawHitHandle) {
1770 throw cet::exception(
"anatree") <<
" No :raw::CaloRawDigit branch." 1771 <<
" Line " << __LINE__ <<
" in file " << __FILE__ <<
std::endl;
1775 for (
auto const& DigiHit : (*MuIDRawHitHandle) ) {
1780 fDigiHitTime_MuID.push_back( (DigiHit.Time().first + DigiHit.Time().second) / 2.0 );
1799 <<
" Line " << __LINE__ <<
" in file " << __FILE__ <<
std::endl;
1803 for (
auto const&
Hit : (*HitHandle) ) {
1804 fHitX.push_back(
Hit.Position()[0]);
1805 fHitY.push_back(
Hit.Position()[1]);
1806 fHitZ.push_back(
Hit.Position()[2]);
1815 auto RecoHitHandle = e.
getHandle<std::vector<rec::CaloHit> >(ecalrecotag);
1816 if (!RecoHitHandle) {
1818 <<
" Line " << __LINE__ <<
" in file " << __FILE__ <<
std::endl;
1821 for (
auto const&
Hit : (*RecoHitHandle) ) {
1838 MuIDRecoHitHandle = e.
getHandle<std::vector<rec::CaloHit> >(muirecotag);
1839 if (!MuIDRecoHitHandle) {
1841 <<
" Line " << __LINE__ <<
" in file " << __FILE__ <<
std::endl;
1844 for (
auto const&
Hit : (*MuIDRecoHitHandle) ) {
1867 art::FindManyP<rec::Hit>* findManyHits = NULL;
1870 if (!TPCClusterHandle) {
1872 <<
" Line " << __LINE__ <<
" in file " << __FILE__ <<
std::endl;
1874 findManyHits =
new art::FindManyP<rec::Hit>(TPCClusterHandle,
e,
fTPCClusterLabel);
1882 art::FindManyP<rec::TPCCluster>* findManyTPCClusters = NULL;
1883 art::FindOneP<rec::TrackIoniz>* findIonization = NULL;
1888 <<
" Line " << __LINE__ <<
" in file " << __FILE__ <<
std::endl;
1891 if (!TrackIonHandle) {
1893 <<
" Line " << __LINE__ <<
" in file " << __FILE__ <<
std::endl;
1896 findManyTPCClusters =
new art::FindManyP<rec::TPCCluster>(TrackHandle,
e,
fTrackLabel);
1897 findIonization =
new art::FindOneP<rec::TrackIoniz>(TrackHandle,
e,
fTrackLabel);
1901 if (!TrackTrajHandle) {
1902 throw cet::exception(
"anatree") <<
" No rec::TrackTrajectory branch." 1903 <<
" Line " << __LINE__ <<
" in file " << __FILE__ <<
std::endl;
1910 art::FindManyP<rec::Track, rec::TrackEnd>* findManyTrackEnd = NULL;
1913 if (!VertexHandle) {
1915 <<
" Line " << __LINE__ <<
" in file " << __FILE__ <<
std::endl;
1917 findManyTrackEnd =
new art::FindManyP<rec::Track, rec::TrackEnd>(VertexHandle,
e,
fVertexLabel);
1922 art::FindManyP<rec::Track, rec::TrackEnd>* findManyVeeTrackEnd = NULL;
1927 <<
" Line " << __LINE__ <<
" in file " << __FILE__ <<
std::endl;
1929 findManyVeeTrackEnd =
new art::FindManyP<rec::Track, rec::TrackEnd>(VeeHandle,
e,
fVeeLabel);
1937 art::FindManyP<rec::Track, rec::TrackEnd>* findManyCALTrackEnd = NULL;
1938 art::FindManyP<gar::rec::CaloHit>* findManyClusterRecoHit = NULL;
1939 art::FindManyP<gar::rec::CaloHit>* findManyClusterMuIDHit = NULL;
1942 RecoClusterHandle = e.
getHandle< std::vector<rec::Cluster> >(ecalclustertag);
1943 if (!RecoClusterHandle) {
1945 <<
" Line " << __LINE__ <<
" in file " << __FILE__ <<
std::endl;
1950 RecoClusterMuIDHandle = e.
getHandle< std::vector<rec::Cluster> >(muidclustertag);
1951 if (!RecoClusterMuIDHandle) {
1952 throw cet::exception(
"anatree") <<
" No rec::Cluster (MuID) branch." 1953 <<
" Line " << __LINE__ <<
" in file " << __FILE__ <<
std::endl;
1958 findManyClusterRecoHit =
new art::FindManyP<gar::rec::CaloHit>(RecoClusterHandle,
e,ecalclustertag);
1961 findManyClusterMuIDHit =
new art::FindManyP<gar::rec::CaloHit>(RecoClusterMuIDHandle,e,muidclustertag);
1965 findManyCALTrackEnd =
new art::FindManyP<rec::Track, rec::TrackEnd>(RecoClusterHandle,
e,
fECALAssnLabel);
1973 size_t iTPCCluster = 0;
1974 for (
auto const& TPCCluster : (*TPCClusterHandle) ) {
1981 cov = TPCCluster.CovMatPacked();
1990 int indexToPush = -1;
float valueToPush = 0;
1991 if ( findManyHits->isValid() ) {
1992 std::map<int,float> sumEforTrkID;
1993 float eTotCluster = 0;
1994 auto const& hitsInTPCCluster = findManyHits->at(iTPCCluster);
1995 for (
size_t iHits = 0; iHits<hitsInTPCCluster.size(); ++iHits) {
1997 for (
size_t iIDE = 0; iIDE<IDEs.size(); ++iIDE) {
1998 int trackID = IDEs[iIDE].trackID;
1999 float thisEdepE = IDEs[iIDE].energyTot;
2000 if ( sumEforTrkID.find(trackID) == sumEforTrkID.end() ) {
2001 sumEforTrkID[trackID] = 0;
2003 sumEforTrkID[trackID] += thisEdepE;
2004 eTotCluster += thisEdepE;
2007 if (sumEforTrkID.size()!=0) {
2009 typedef std::function<bool(std::pair<int,float>, std::pair<int,float>)> Comparator;
2011 std::set<std::pair<int,float>, Comparator> setOfTrkIDs(
2012 sumEforTrkID.begin(), sumEforTrkID.end(),
2013 [](std::pair<int,float>
a ,std::pair<int,float>
b) {
2014 return a.second >
b.second;
2017 auto iReturnSet = setOfTrkIDs.begin();
2019 valueToPush = iReturnSet->second/eTotCluster;
2025 Int_t trackForThisTPCluster = -1;
2028 for (
auto const& track : (*TrackHandle) ) {
2029 for (
size_t iCluster=0; iCluster<track.NHits(); iCluster++) {
2030 auto const& trackedCluster =
2031 *(findManyTPCClusters->at(iTrack).at(iCluster));
2032 if (TPCCluster==trackedCluster) {
2033 trackForThisTPCluster = track.getIDNumber();
2050 for (
auto const& track : (*TrackHandle) ) {
2057 fTrackStartPX.push_back(track.Momentum_beg()*track.VtxDir()[0]);
2058 fTrackStartPY.push_back(track.Momentum_beg()*track.VtxDir()[1]);
2059 fTrackStartPZ.push_back(track.Momentum_beg()*track.VtxDir()[2]);
2065 fTrackEndPX.push_back(track.Momentum_end()*track.EndDir()[0]);
2066 fTrackEndPY.push_back(track.Momentum_end()*track.EndDir()[1]);
2067 fTrackEndPZ.push_back(track.Momentum_end()*track.EndDir()[2]);
2071 fTrackLenB.push_back(track.LengthBackward());
2077 TVector3 momF(track.Momentum_beg()*track.VtxDir()[0], track.Momentum_beg()*track.VtxDir()[1], track.Momentum_beg()*track.VtxDir()[2]);
2078 TVector3 momB(track.Momentum_end()*track.EndDir()[0], track.Momentum_end()*track.EndDir()[1], track.Momentum_end()*track.EndDir()[2]);
2081 float pF = momF.Mag();
2082 float pB = momB.Mag();
2083 std::vector< std::pair<int, float> > pidF =
processPIDInfo( pF );
2084 std::vector< std::pair<int, float> > pidB =
processPIDInfo( pB );
2087 for(
size_t ipid = 0; ipid < pidF.size(); ipid++) {
2091 for(
size_t ipid = 0; ipid < pidB.size(); ipid++) {
2097 std::vector<std::pair<simb::MCParticle*,float>> trakt;
2110 if (findIonization->isValid()) {
2113 float avgIonF, avgIonB;
2128 size_t iTrackTraj = 0;
2129 for (
auto const& tracktraj : (*TrackTrajHandle) ) {
2131 std::vector<TVector3>
temp = tracktraj.getFWDTrajectory();
2132 for(
size_t i = 0; i < temp.size(); i++) {
2139 temp = tracktraj.getBAKTrajectory();
2140 for(
size_t i = 0; i < temp.size(); i++) {
2153 for (
auto const&
vertex : (*VertexHandle) ) {
2160 int nVertexedTracks = 0;
2161 if ( findManyTrackEnd->isValid() ) {
2162 nVertexedTracks = findManyTrackEnd->at(iVertex).size();
2164 fVertexN.push_back(nVertexedTracks);
2166 int vertexCharge = 0;
2167 for (
int iVertexedTrack=0; iVertexedTrack<nVertexedTracks; ++iVertexedTrack) {
2171 rec::Track track = *(findManyTrackEnd->at(iVertex).at(iVertexedTrack));
2179 rec::TrackEnd fee = *(findManyTrackEnd->data(iVertex).at(iVertexedTrack));
2197 for (
auto const& vee : (*VeeHandle) ) {
2199 fVeeX.push_back(vee.Position()[0]);
2200 fVeeY.push_back(vee.Position()[1]);
2201 fVeeZ.push_back(vee.Position()[2]);
2202 fVeeT.push_back(vee.Time());
2206 fVeeEKpipi.push_back(vee.FourMomentum(0).E());
2207 fVeeMKpipi.push_back(vee.FourMomentum(0).M());
2208 fVeePXLppi.push_back(vee.FourMomentum(1).X());
2209 fVeePYLppi.push_back(vee.FourMomentum(1).Y());
2210 fVeePZLppi.push_back(vee.FourMomentum(1).Z());
2211 fVeeELppi.push_back(vee.FourMomentum(1).E());
2212 fVeeMLppi.push_back(vee.FourMomentum(1).M());
2213 fVeePXLpip.push_back(vee.FourMomentum(2).X());
2214 fVeePYLpip.push_back(vee.FourMomentum(2).Y());
2215 fVeePZLpip.push_back(vee.FourMomentum(2).Z());
2216 fVeeELpip.push_back(vee.FourMomentum(2).E());
2217 fVeeMLpip.push_back(vee.FourMomentum(2).M());
2220 if ( findManyVeeTrackEnd->isValid() ) {
2221 nVeeTracks = findManyVeeTrackEnd->at(iVee).size();
2224 for (
int iVeeTrack=0; iVeeTrack<nVeeTracks; ++iVeeTrack) {
2228 rec::Track track = *(findManyVeeTrackEnd->at(iVee).at(iVeeTrack));
2231 rec::TrackEnd fee = *(findManyVeeTrackEnd->data(iVee).at(iVeeTrack));
2241 size_t iCluster = 0;
2242 for (
auto const&
cluster : (*RecoClusterHandle) ) {
2261 std::vector<ULong64_t> fVecHitIDs = {};
2262 if (findManyClusterRecoHit->isValid()) {
2263 int nClusterHit = findManyClusterRecoHit->at(iCluster).size();
2264 for (
int iClusterHit=0; iClusterHit<nClusterHit; ++iClusterHit) {
2265 rec::CaloHit hit = *(findManyClusterRecoHit->at(iCluster).at(iClusterHit));
2273 std::vector<std::pair<simb::MCParticle*,float>> trakt;
2289 size_t iCluster_local = 0;
2290 for (
auto const&
cluster : (*RecoClusterMuIDHandle) ) {
2309 std::vector<ULong64_t> fVecHitIDs = {};
2310 if (findManyClusterMuIDHit->isValid()) {
2311 int nClusterHit = findManyClusterMuIDHit->at(iCluster_local).size();
2312 for (
int iClusterHit=0; iClusterHit<nClusterHit; ++iClusterHit) {
2313 rec::CaloHit hit = *(findManyClusterMuIDHit->at(iCluster_local).at(iClusterHit));
2343 size_t iCluster = 0;
2344 for (
auto const&
cluster : (*RecoClusterHandle) ) {
2345 int nCALedTracks(0);
2346 if ( findManyCALTrackEnd->isValid() ) {
2347 nCALedTracks = findManyCALTrackEnd->at(iCluster).size();
2349 for (
int iCALedTrack=0; iCALedTrack<nCALedTracks; ++iCALedTrack) {
2351 rec::Track track = *(findManyCALTrackEnd->at(iCluster).at(iCALedTrack));
2354 rec::TrackEnd fee = *(findManyCALTrackEnd->data(iCluster).at(iCALedTrack));
2371 float& forwardIonVal,
float& backwardIonVal) {
2375 std::vector<std::pair<float,float>> SigData = ion.
getFWD_dSigdXs();
2388 std::vector<std::pair<float,float>> dEvsX;
2396 if (SigData.size()==0)
return 0.0;
2397 float distAlongTrack = 0;
2398 std::vector<std::pair<float,float>>
::iterator littlebit = SigData.begin();
2399 for (; littlebit<(SigData.end()-1); ++littlebit) {
2400 float dE = std::get<0>(*littlebit);
2403 float dX = std::get<1>(*littlebit);
2404 distAlongTrack += dX;
2406 dX += std::get<1>(*(littlebit+1));
2407 float dEdX = dE/(0.5*dX);
2409 std::pair pushme = std::make_pair(dEdX,distAlongTrack);
2410 dEvsX.push_back( pushme );
2417 int goUpTo = ionizeTruncate * dEvsX.size() +0.5;
2418 if (goUpTo > (
int)dEvsX.size()) goUpTo = dEvsX.size();
2419 int i = 1;
float returnvalue = 0;
2420 littlebit = dEvsX.begin();
2421 for (; littlebit<dEvsX.end(); ++littlebit) {
2422 returnvalue += std::get<0>(*littlebit);
2424 if (i>goUpTo)
break;
2426 returnvalue /= goUpTo;
2440 float E[3], Px[3], Py[3], Pz[3];
2441 E[nu] = E[mu] = E[
pi] = -1e42;
2443 for (
int i=0; i<3;++i) {
2450 for (
int iPart=0; iPart<nPart; iPart++) {
2456 if (
abs(code) == 12 ||
abs(code) == 14 ||
abs(code) == 16 ) {
2458 E[nu] = Part.
E(); Px[nu] = Part.
Px(); Py[nu] = Part.
Py(); Pz[nu] = Part.
Pz();
2463 if (
abs(code) == 11 ||
abs(code) == 13 ||
abs(code) == 15 ) {
2465 E[mu] = Part.
E(); Px[mu] = Part.
Px(); Py[mu] = Part.
Py(); Pz[mu] = Part.
Pz();
2470 if ( code==111 ||
abs(code)==211 ) {
2472 E[
pi] = Part.
E(); Px[
pi] = Part.
Px(); Py[
pi] = Part.
Py(); Pz[
pi] = Part.
Pz();
2477 if ( E[nu]!=0 && E[mu]!=0 && E[pi]!=0)
break;
2482 E[nu] -= E[mu]; Px[nu] -= Px[mu]; Py[nu] -= Py[mu]; Pz[nu] -= Pz[mu];
2483 E[nu] -= E[
pi]; Px[nu] -= Px[
pi]; Py[nu] -= Py[
pi]; Pz[nu] -= Pz[
pi];
2484 float t = E[nu]*E[nu] -Px[nu]*Px[nu] -Py[nu]*Py[nu] -Pz[nu]*Pz[nu];
2495 std::vector<std::string> recopnamelist = {
"#pi",
"#mu",
"p",
"K",
"d",
"e"};
2496 std::vector<int> pdg_charged = {211, 13, 2212, 321, 1000010020, 11};
2497 std::vector< std::pair<int, float> >
pid;
2501 float dist = 100000000.;
2502 CLHEP::RandFlat FlatRand(
fEngine);
2504 for (
int q = 0; q < 501; ++q) {
2507 unsigned first = fulltitle.find(
"=");
2508 unsigned last = fulltitle.find(
"GeV");
2509 std::string substr = fulltitle.substr(first+1, last - first-1);
2510 float pidinterp_mom = std::atof(substr.c_str());
2512 float disttemp =
std::abs(pidinterp_mom - p);
2514 if( disttemp < dist ) {
2522 for (
int pidm = 0; pidm < 6; ++pidm) {
2525 std::vector< std::pair<float, std::string> > v_prob;
2528 for (
int pidr = 0; pidr < 6; ++pidr) {
2530 float prob =
m_pidinterp[qclosest]->GetBinContent(pidm+1, pidr+1);
2532 v_prob.push_back( std::make_pair(prob, recoparticlename) );
2536 if (v_prob.size() > 1) {
2538 std::sort(v_prob.begin(), v_prob.end());
2540 float random_number = FlatRand.fire();
2542 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);});
2544 for(
size_t ivec = 0; ivec < v_prob.size()-1; ivec++) {
2545 if( random_number < v_prob.at(ivec+1).first && random_number >= v_prob.at(ivec).first ) {
2546 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) );
2550 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) );
std::vector< ULong64_t > fRecoHitCellID
double E(const int i=0) const
base_engine_t & createEngine(seed_t seed)
bool fWriteHits
Write info about TPC Hits Default=false.
std::vector< Float_t > fVeeY
float fIonizTruncate
Default=1.00;.
std::vector< Float_t > fClusterPhi
std::vector< Float_t > fRecoHitY_MuID
std::vector< Float_t > fSimHitTime_MuID
std::vector< std::string > fGENIEGeneratorLabels
std::vector< Float_t > fVertexY
std::vector< Int_t > fMCPDGMother
std::vector< Float_t > fMCPStartX
std::vector< Float_t > fTrackChi2F
std::vector< Int_t > fGPartFirstDaugh
std::vector< ULong64_t > fVTAssn_TrackIDNumber
std::vector< Int_t > fGPartFirstMom
double Theta() const
angle between incoming and outgoing leptons, in radians
std::vector< Float_t > fY
double Py(const int i=0) const
Int_t fRun
number of the run being processed
std::vector< std::pair< int, float > > processPIDInfo(float p)
std::vector< Float_t > fRecoHitZ
std::vector< UInt_t > fDigiHitADC_MuID
std::vector< Float_t > fMCPStartPZ
bool fWriteTPCClusters
Write TPCClusters info Default=true.
std::vector< UInt_t > fDigiHitADC
std::vector< Float_t > fClusterZ
Float_t fTPC_X
center of TPC stored as per-event & compressed by root
std::vector< Float_t > fTrackLenB
std::vector< Int_t > fGint
bool fWriteMCCaloInfo
Write MC info for calorimeter Default=true.
bool fWriteVees
Reco vees & their tracks Default=true.
const std::string GetMuIDCellIDEncoding() const
std::vector< Float_t > fClusterX
std::vector< Int_t > fMCPVertIndex
std::vector< Float_t > fSimHitX
std::vector< Float_t > fX
std::vector< Float_t > fDigiHitZ_MuID
std::vector< Float_t > fVeePXLpip
std::vector< ULong64_t > fVeeIDNumber
Handle< PROD > getHandle(SelectorBase const &) const
static bool lessThan_byE(std::pair< float, float > a, std::pair< float, float > b)
std::vector< Float_t > fClusterY_MuID
bool fWriteMCinfo
Info from MCTruth, GTruth Default=true.
std::vector< Float_t > fTrackEndX
std::vector< Float_t > fTPCClusterCovYZ
std::vector< Int_t > fTPCClusterMCindex
std::vector< Int_t > fNeutrinoType
std::string fTPCClusterLabel
module label for TPC Clusters rec::TPCCluster
bool fWriteTrackTrajectories
Point traj of reco tracks Default=false.
bool fWriteVertices
Reco vertexes & their tracks Default=true.
std::vector< Float_t > fTrackEndPZ
std::vector< std::vector< ULong64_t > > fClusterMuIDAssn_MuIDHitIDNumber
std::vector< ULong64_t > fVeeTAssn_VeeIDNumber
std::vector< Float_t > fHitZ
std::vector< Float_t > fClusterTheta
std::vector< Int_t > fSimHitTrackID
const simb::MCParticle & Nu() const
std::vector< gar::rec::TrackEnd > fVeeTAssn_TrackEnd
std::vector< Float_t > fDigiHitZ
std::vector< UInt_t > fClusterNhits_MuID
std::vector< Float_t > fWeight
virtual void beginJob() override
double Px(const int i=0) const
std::vector< Float_t > fClusterZ_MuID
float computeT(simb::MCTruth theMCTruth)
const geo::GeometryCore * fGeo
pointer to the geometry
std::vector< std::string > fMCPProc
std::vector< ULong64_t > fReconHitIDNumber_MuID
std::vector< Float_t > fClusterTimeDiffFirstLast
std::vector< Float_t > fT
void FillRawInfo(art::Event const &e)
std::vector< ULong64_t > fSimHitCellID
std::vector< Float_t > fTrackTrajectoryFWDZ
std::vector< Float_t > fVertexX
std::vector< Float_t > fDigiHitX_MuID
std::vector< Float_t > fVeePZLppi
std::vector< Int_t > fTrajMCPTrackID
float TPCXCent() const
Returns the X location of the center of the TPC in cm.
std::vector< Float_t > fTrackStartPZ
std::pair< float, std::string > P
std::vector< Float_t > fTPCClusterY
Description of geometry of one entire detector.
std::vector< Int_t > fNTPCClustersOnTrack
std::string fTrackTrajectoryLabel
module label for TPC Track Trajectories rec:TrackTrajectory
std::vector< Float_t > fTrajMCPT
std::vector< Float_t > fVeePZKpipi
std::vector< Float_t > fMCnuPx
Cluster finding and building.
std::vector< Int_t > fVertexN
std::vector< Float_t > fMCPStartPX
std::vector< Int_t > fGPartPdg
void FillHighLevelRecoInfo(art::Event const &e)
EDAnalyzer(fhicl::ParameterSet const &pset)
std::vector< Float_t > fTrajMCPPZ
std::vector< Float_t > fClusterPhi_MuID
anatree(fhicl::ParameterSet const &p)
std::vector< Float_t > fTrackTrajectoryBWDZ
float fMatchMCPtoVertDist
MCParticle to MC vertex match Default=roundoff.
std::vector< ULong64_t > fTPCClusterTrkIDNumber
std::vector< Float_t > fTrackEndPY
bool fWriteCaloHits
Write ECAL hits. Default=true.
std::vector< Float_t > fMCnuPz
std::vector< Float_t > fVertexZ
std::vector< Int_t > fClusterMCindex_MuID
std::vector< Float_t > fClusterMainAxisZ_MuID
double dEdX(double KE, const simb::MCParticle *part)
std::vector< Float_t > fMCPStartY
std::vector< Float_t > fSimHitY_MuID
std::enable_if_t< std::is_arithmetic_v< T >, T > hypot(T x, T y)
std::vector< Float_t > fQ2
std::string fClusterLabel
module label for calo clusters rec::Cluster
std::vector< Int_t > fSimHitTrackID_MuID
double const & TotalPOT() const
std::vector< Int_t > fInteractionType
std::vector< Float_t > fVeeMLppi
std::vector< Float_t > fTrackEndY
std::vector< Int_t > fGPartLastMom
std::vector< Float_t > fMCPEndPY
std::vector< Float_t > fTPCClusterSig
std::vector< Float_t > fVeePXLppi
std::vector< Float_t > fTrackPIDProbF
std::vector< ULong64_t > fTrackIDNumber
std::vector< Float_t > fTrackStartX
void FillGeneratorMonteCarloInfo(art::Event const &e)
std::vector< Int_t > fTrackMCindex
std::vector< Int_t > fMCMotherIndex
gar::rec::IDNumber getIDNumber() const
int InteractionType() const
std::vector< Float_t > fMCPEndPZ
std::vector< Int_t > fTrackTrajectoryFWDID
std::vector< std::pair< simb::MCParticle *, float > > ClusterToMCParticles(rec::Cluster *const c)
std::vector< Int_t > fGPartLastDaugh
std::vector< Float_t > fMCPEndZ
std::vector< Float_t > fSimHitX_MuID
std::vector< Float_t > fVeeELpip
std::vector< Float_t > fTrackEndZ
std::vector< Float_t > fSimHitEnergy
std::vector< Float_t > fGPartPy
std::vector< ULong64_t > fVeeTAssn_TrackIDNumber
std::vector< std::string > fGeneratorLabels
std::vector< Float_t > fRecoHitX
std::vector< Float_t > fTrackEndPX
std::vector< Int_t > fRecoHitLayer_MuID
#define DEFINE_ART_MODULE(klass)
std::vector< Float_t > fTrackAvgIonF
Float_t fRecoEnergySum_MuID
std::vector< Int_t > fRecoHitLayer
std::vector< Float_t > fVeePYLppi
std::vector< Float_t > fVeePYLpip
float TPCRadius() const
Returns the radius of the TPC (y or z direction)
std::vector< Float_t > fTrackTrajectoryBWDX
std::vector< Int_t > fGPartStatus
std::vector< ULong64_t > fDigiHitCellID
gar::geo::BitFieldCoder * fFieldDecoder_ECAL
std::vector< Int_t > fnGPart
std::vector< Float_t > fSimHitTime
std::vector< Float_t > fTPCClusterCovXZ
std::vector< Float_t > fHitX
Helper class for decoding and encoding a bit field of 64bits for convenient declaration.
std::vector< Float_t > fClusterPID_MuID
std::vector< Handle< PROD > > getMany(SelectorBase const &selector=MatchAllSelector{}) const
std::string fGeantLabel
module label for geant4 simulated hits
T get(std::string const &key) const
std::vector< Float_t > fClusterEnergy_MuID
std::string fVeeLabel
module label for conversion/decay vertexes rec:Vee
std::vector< ULong64_t > fDigiHitCellID_MuID
std::vector< Int_t > fClusterMCindex
std::vector< Float_t > fTrackAvgIonB
std::vector< ULong64_t > fCALAssn_TrackIDNumber
anatree & operator=(anatree const &)=delete
std::vector< ULong64_t > fClusterIDNumber_MuID
float TPCZCent() const
Returns the Z location of the center of the TPC in cm.
std::vector< ULong64_t > fClusterIDNumber
std::vector< Float_t > fClusterTime_MuID
SubRunNumber_t subRun() const
std::vector< std::vector< ULong64_t > > fClusterAssn_RecoHitIDNumber
std::string fMuIDHitLabel
std::vector< Float_t > fMCPStartPY
CodeOutputInterface * code
std::string fRawCaloHitLabel
module label for digitized calo hits raw::CaloRawDigit
std::string fPFLabel
module label for reco particles rec::PFParticle
std::vector< HitIDE > HitToHitIDEs(art::Ptr< rec::Hit > const &hit) const
Definition of basic calo raw digits.
double distance(double x1, double y1, double z1, double x2, double y2, double z2)
std::vector< std::string > fGPartName
std::vector< Float_t > fTrackStartY
#define MF_LOG_INFO(category)
std::vector< Float_t > fSimHitZ
std::vector< Float_t > fClusterMCfrac_MuID
std::vector< Float_t > fTPCClusterX
std::vector< Int_t > fMode
std::vector< Int_t > fMCPDG
std::vector< Float_t > fClusterTimeDiffFirstLast_MuID
Detector simulation of raw signals on wires.
std::string fClusterMuIDLabel
module label for calo clusters rec::Cluster in MuID
std::vector< Float_t > fRecoHitEnergy_MuID
std::string fMuIDEncoding
std::vector< Float_t > fTrackTrajectoryFWDY
const simb::MCParticle & GetParticle(int i) const
std::vector< Float_t > fTrajMCPPX
std::vector< ULong64_t > fVeeT
std::vector< Float_t > fVeePYKpipi
std::vector< ULong64_t > fVertexIDNumber
std::vector< Int_t > fTrackEndQ
bool fWriteCaloDigits
Raw digits for calorimetry. Default=false.
std::vector< Float_t > fSimHitY
std::vector< Float_t > fVeeMKpipi
std::vector< ULong64_t > fReconHitIDNumber
CLHEP::HepRandomEngine & fEngine
random engine
General GArSoft Utilities.
std::vector< gar::rec::TrackEnd > fVTAssn_TrackEnd
std::vector< Int_t > fMCTrkID
long64 get(long64 bitfield, size_t index) const
std::vector< ULong64_t > fVTAssn_VertIDNumber
std::vector< Float_t > fRecoHitY
TrackEnd const TrackEndBeg
std::vector< Float_t > fVeeEKpipi
std::vector< Float_t > fClusterMainAxisZ
std::vector< Float_t > fClusterMCfrac
std::string fECALAssnLabel
module label for track-clusters associations
std::vector< Float_t > fgT
std::vector< Float_t > fTrajMCPE
std::vector< Float_t > fTrajMCPX
std::vector< Float_t > fDigiHitY
cheat::BackTrackerCore * BackTrack
std::vector< Float_t > fTPCClusterCovYY
std::vector< ULong64_t > fVertexT
std::vector< Float_t > fClusterEnergy
std::vector< Float_t > fRecoHitEnergy
std::string fCaloHitLabel
module label for reco calo hits rec::CaloHit
bool fWriteMCPTrajectory
Write MCP Trajectory Default=true.
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
std::vector< Float_t > fMCPStartZ
float TPCYCent() const
Returns the Y location of the center of the TPC in cm.
std::vector< Float_t > fW
std::vector< Float_t > fVeeELppi
std::vector< Float_t > fSimHitZ_MuID
Int_t fSubRun
number of the sub-run being processed
std::vector< Int_t > fTrackPIDB
std::vector< Float_t > fRecoHitZ_MuID
std::vector< Float_t > fTrackStartPY
std::vector< Float_t > fClusterTime
std::vector< std::pair< simb::MCParticle *, float > > TrackToMCParticles(rec::Track *const t)
std::vector< Float_t > fTPCClusterCovZZ
std::optional< T > get_if_present(std::string const &key) const
std::vector< UInt_t > fHitChan
std::vector< Float_t > fTrackPIDProbB
float processOneDirection(std::vector< std::pair< float, float >> SigData, float ionizeTruncate)
bool HasMuonDetector() const
std::vector< Float_t > fClusterMainAxisY
const std::string GetECALCellIDEncoding() const
virtual void endRun(art::Run const &run) override
double Pz(const int i=0) const
std::vector< Float_t > fMCVertexZ
std::vector< Float_t > fGPartMass
std::vector< Float_t > fClusterPID
std::vector< Float_t > fTPCClusterMCfrac
std::vector< Float_t > fMCPEndPX
std::vector< Float_t > fDigiHitTime_MuID
std::vector< Float_t > fTPCClusterRMS
std::vector< Int_t > fTgtPDG
std::vector< Float_t > fVeeX
std::vector< Float_t > fTrajMCPY
std::vector< Float_t > fVeePXKpipi
bool fWriteTracks
Start/end X, P for tracks Default=true.
std::vector< Float_t > fVeeZ
std::unordered_map< TrkId, Int_t > TrackIdToIndex
EventNumber_t event() const
std::vector< Float_t > fDigiHitTime
std::vector< Float_t > fMCPTime
std::vector< Float_t > fSimHitEnergy_MuID
std::vector< Float_t > fGPartPx
std::vector< Float_t > fTrajMCPZ
std::string fInstanceLabelCalo
Instance name for ECAL.
std::vector< Float_t > fTrackChi2B
std::vector< Float_t > fDigiHitX
std::vector< Float_t > fHitSig
float TPCLength() const
Returns the length of the TPC (x direction)
bool fWriteMatchedTracks
Write ECAL-track Assns Default=true.
gar::geo::BitFieldCoder * fFieldDecoder_MuID
gar::rec::IDNumber getIDNumber() const
bool fWriteMCPTrajMomenta
Write Momenta associated with MCP Trajectory Default=false.
std::vector< Float_t > fMCnuPy
std::vector< Float_t > fClusterMainAxisY_MuID
std::vector< Float_t > fMCPEndY
Float_t fSimEnergySum_MuID
std::vector< gar::rec::TrackEnd > fCALAssn_TrackEnd
std::string fHitLabel
module label for reco TPC hits rec::Hit
Event generator information.
std::vector< Float_t > fTPCClusterCovXY
std::vector< Float_t > fTrackStartZ
std::vector< ULong64_t > fRecoHitCellID_MuID
const std::vector< std::pair< float, float > > getBAK_dSigdXs() const
def momentum(x1, x2, x3, scale=1.)
bool fWriteCohInfo
MC level t for coherent pi+. Default=false.
std::vector< std::string > fMCPEndProc
std::vector< Int_t > fTrackStartQ
Int_t fEvent
number of the event being processed
std::vector< Float_t > fTrackMCfrac
std::vector< Int_t > fTrajMCPIndex
std::vector< Float_t > fTrackTrajectoryBWDY
second_as<> second
Type of time stored in seconds, in double precision.
void FillRecoInfo(art::Event const &e)
std::vector< Float_t > fVeePZLpip
const std::vector< std::pair< float, float > > getFWD_dSigdXs() const
Event generator information.
std::vector< Float_t > fTrackTrajectoryFWDX
art framework interface to geometry description
unsigned int const & TotalSpills() const
std::vector< Int_t > fCCNC
std::vector< Float_t > fGPartPz
std::vector< Float_t > fRecoHitX_MuID
std::vector< Int_t > fTrackPIDF
std::vector< Float_t > fTrackStartPX
std::vector< Float_t > fGPartE
std::vector< Int_t > fGPartIdx
std::string fTrackLabel
module label for TPC Tracks rec:Track
std::vector< Float_t > fClusterX_MuID
std::string fVertexLabel
module label for vertexes rec:Vertex
std::unordered_map< int, TH2F * > m_pidinterp
std::string fInstanceLabelMuID
Instance name for MuID.
std::vector< ULong64_t > fCALAssn_ClusIDNumber
void processIonizationInfo(rec::TrackIoniz &ion, float ionizeTruncate, float &forwardIonVal, float &backwardIonVal)
std::vector< Float_t > fTPCClusterZ
std::vector< Float_t > fHitRMS
std::vector< Float_t > fMCPEndX
bool fWriteCaloClusters
Write ECAL clusters. Default=true.
std::vector< Float_t > fMCVertexY
std::vector< Int_t > fVertexQ
std::vector< Float_t > fClusterMainAxisX
std::vector< Int_t > fTrackTrajectoryBWDID
std::vector< Float_t > fTPCClusterCovXX
std::vector< Float_t > fDigiHitY_MuID
std::string fRawMuIDHitLabel
std::vector< Float_t > fClusterMainAxisX_MuID
cet::coded_exception< error, detail::translate > exception
std::vector< Float_t > fRecoHitTime_MuID
std::vector< Float_t > fRecoHitTime
std::vector< Float_t > fHitY
QTextStream & endl(QTextStream &s)
QCString & append(const char *s)
std::vector< Float_t > fMCVertexX
std::vector< ULong64_t > fSimHitCellID_MuID
std::vector< UInt_t > fClusterNhits
std::vector< Int_t > fMCMotherTrkID
std::vector< Float_t > fTheta
std::vector< Float_t > fTrackLenF
std::vector< Float_t > fVeeMLpip
std::string fECALEncoding
std::vector< Float_t > fClusterTheta_MuID
std::vector< Float_t > fTrajMCPPY
std::vector< Int_t > fGPartIntIdx
void analyze(art::Event const &e) override
std::vector< Float_t > fClusterY