Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
cheat::BackTracker Class Reference

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N19-12-08/MCCheater/BackTracker.h"

Classes

struct  Params
 
class  RawWeightedHit
 Helper for HitCollectionEfficiency and HitCollectionPurity. More...
 

Public Types

using Parameters = art::ServiceTable< Params >
 

Public Member Functions

 BackTracker (const Parameters &params, art::ActivityRegistry &reg)
 
 ~BackTracker ()
 
void Rebuild (const art::Event &evt)
 
bool HaveTruthInfo () const
 Is this a file with truth info in? (Is BackTracker going to be any use to you?) More...
 
const std::vector< sim::PhotonSignalCellToPhotonSignal (unsigned int const &plane, unsigned int const &cell) const
 Returns the PhotonSignals contributing the signal in the specified cell. WARNING: Use with extreme caution! Most users should use HitToPhotonSignal instead. Only use the cell version if you really want to know ALL the photon signals in the cell for the entire time window, NOT time-associated with the hit. More...
 
const std::vector< sim::PhotonSignalHitToPhotonSignal (const art::Ptr< rb::CellHit > &hit) const
 Returns the PhotonSignals contributing the signal in the specified hit. More...
 
const std::vector< sim::FLSHitCellToFLSHit (unsigned int const &plane, unsigned int const &cell) const
 Returns the FLSHits contributing the signal in the specified cell. WARNING: Use with extreme caution! Most users should use HitToFLSHit instead. Only use the cell version if you really want to know ALL the FLSHits in the cell for the entire time window, NOT time-associated with the hit. More...
 
std::vector< sim::FLSHitHitToFLSHit (const rb::CellHit &hit) const
 All the FLSHits that contributed to this hit, sorted from most to least light. More...
 
std::vector< sim::FLSHitHitToFLSHit (const art::Ptr< rb::CellHit > &hit) const
 
std::vector< sim::FLSHitParticleToFLSHit (const int &trackID) const
 All the FLSHits that were created by the track id trackID, sorted from most to least light. More...
 
std::vector< sim::FLSHitParticleToFLSHit (const int trackID, const int pdg) const
 All the FLSHits that were created by the track id trackID, which also have a particular pdg. Most users should use the other version of this function. However, sometimes when our truth is condensed, the same mother track ID is assigned to FLS hits made by non-important daughters, who can have different PDG values. An example of this is a muon track, whose delta rays often have the track id of the mother muon. By using this version of the function, you can ensure you are looking only at the FLS hits deposited by the muon. More...
 
const double EnergyFromTrackId (const art::Ptr< rb::CellHit > &hit, int trackId, bool useBirksE=false) const
 The total energy deposited in this cell by all FLSHits with this trackId. More...
 
const sim::ParticleHitToParticle (art::Ptr< rb::CellHit > const &hit, bool quiet=false) const
 Returns the sim::Particle object contributing the most light to the specified rb::CellHit. More...
 
const sim::ParticleHitToParticle (const rb::CellHit &hit, bool quiet=false) const
 Returns the sim::Particle object contributing the most light to the specified rb::CellHit. More...
 
bool IsNoise (const art::Ptr< rb::CellHit > &hit) const
 Is this hit not associated with any particles? More...
 
bool IsNoise (const rb::CellHit &hit) const
 Is this hit not associated with any particles? More...
 
bool IsHitsNoise (std::vector< art::Ptr< rb::CellHit > > const &hits) const
 Of this collection of hits, is it mostly noise or physics hits? True indicates noise. More...
 
const sim::ParticleTrackIDToParticle (int const &id) const
 Returns a pointer to the sim::Particle object corresponding to the given TrackID. More...
 
const sim::ParticleTrackIDToMotherParticle (int const &id) const
 
const art::Ptr< simb::MCTruth > & TrackIDToMCTruth (int const &id) const
 
const art::Ptr< simb::MCTruth > & ParticleToMCTruth (const sim::Particle *p) const
 
std::vector< const sim::Particle * > MCTruthToParticles (art::Ptr< simb::MCTruth > const &mct) const
 
TVector3 HitToXYZ (art::Ptr< rb::CellHit > const &hit, bool useBirksE=false) const
 Returns the XYZ position of the energy deposition for a given hit. More...
 
std::vector< const sim::Particle * > HitsToParticle (const std::vector< const rb::CellHit * > &hits) const
 Returns vector of sim::Particle objects contributing to the given collection of hits. More...
 
std::vector< const sim::Particle * > HitsToParticle (const std::vector< rb::CellHit > &hits) const
 
std::vector< const sim::Particle * > HitsToParticle (const std::vector< art::Ptr< rb::CellHit >> &hits) const
 
std::vector< const sim::Particle * > HitsToParticle (const art::PtrVector< rb::CellHit > &hits) const
 
std::vector< TrackIDEHitsToTrackIDE (const std::vector< const rb::CellHit * > &hits, bool useBirksE=false) const
 Returns vector of TrackIDE structs contributing to the given collection of hits. More...
 
std::vector< TrackIDEHitsToTrackIDE (const std::vector< rb::CellHit > &hits, bool useBirksE=false) const
 
std::vector< TrackIDEHitsToTrackIDE (const std::vector< art::Ptr< rb::CellHit >> &hits, bool useBirksE=false) const
 
std::vector< TrackIDEHitsToTrackIDE (const art::PtrVector< rb::CellHit > &hits, bool useBirksE=false) const
 
std::vector< TrackIDEHitToTrackIDE (const rb::CellHit &hit, bool useBirksE=false) const
 Convenience function. HitsToTrackIDE but for a single hit. More...
 
std::vector< TrackIDEHitToTrackIDE (const art::Ptr< rb::CellHit > &hit, bool useBirksE=false) const
 
double HitCollectionPurity (const std::set< int > &trackIDs, const std::vector< rb::WeightedHit > &whits, std::map< int, double > *purMap=0, std::map< int, int > *parents=0, bool energyPur=false) const
 Returns the fraction of hits in a collection that come from the specified Geant4 track ids. More...
 
double HitCollectionPurity (const std::set< int > &trackIDs, const std::vector< const rb::CellHit * > &hits, std::map< int, double > *purMap=0, std::map< int, int > *parents=0, bool energyPur=false) const
 Returns the fraction of hits in a collection that come from the specified Geant4 track ids. More...
 
double HitCollectionPurity (const std::set< int > &trackIDs, const std::vector< rb::CellHit > &hits, std::map< int, double > *purMap=0, std::map< int, int > *parents=0, bool energyPur=false) const
 
double HitCollectionPurity (const std::set< int > &trackIDs, const std::vector< art::Ptr< rb::CellHit >> &hits, std::map< int, double > *purMap=0, std::map< int, int > *parents=0, bool energyPur=false) const
 
double HitCollectionPurity (const std::set< int > &trackIDs, const art::PtrVector< rb::CellHit > &hits, std::map< int, double > *purMap=0, std::map< int, int > *parents=0, bool energyPur=false) const
 
double HitCollectionEfficiency (const std::set< int > &trackIDs, const std::vector< rb::WeightedHit > &whits, const std::vector< const rb::CellHit * > &allhits, const geo::View_t &view, std::map< int, double > *effMap=0, bool energyEff=false, double *desiredEnergy=0, double *totalEnergy=0, int *desiredHits=0, int *totalHits=0) const
 Returns the fraction of all energy in an event from a specific set of Geant4 track IDs that are represented in a collection of weighted hits. More...
 
double HitCollectionEfficiency (const std::set< int > &trackIDs, const std::vector< rb::WeightedHit > &whits, const std::vector< rb::CellHit > &allhits, const geo::View_t &view, std::map< int, double > *effMap=0, bool energyEff=false, double *desiredEnergy=0, double *totalEnergy=0, int *desiredHits=0, int *totalHits=0) const
 
double HitCollectionEfficiency (const std::set< int > &trackIDs, const std::vector< rb::WeightedHit > &whits, const std::vector< art::Ptr< rb::CellHit >> &allhits, const geo::View_t &view, std::map< int, double > *effMap=0, bool energyEff=false, double *desiredEnergy=0, double *totalEnergy=0, int *desiredHits=0, int *totalHits=0) const
 
double HitCollectionEfficiency (const std::set< int > &trackIDs, const std::vector< rb::WeightedHit > &whits, const art::PtrVector< rb::CellHit > &allhits, const geo::View_t &view, std::map< int, double > *effMap=0, bool energyEff=false, double *desiredEnergy=0, double *totalEnergy=0, int *desiredHits=0, int *totalHits=0) const
 
double HitCollectionEfficiency (const std::set< int > &trackIDs, const std::vector< const rb::CellHit * > &hits, const std::vector< const rb::CellHit * > &allhits, const geo::View_t &view, std::map< int, double > *effMap=0, bool energyEff=false, double *desiredEnergy=0, double *totalEnergy=0, int *desiredHits=0, int *totalHits=0) const
 Returns the fraction of all hits in an event from a specific set of Geant4 track IDs that are represented in a collection of hits. More...
 
double HitCollectionEfficiency (const std::set< int > &trackIDs, const std::vector< rb::CellHit > &hits, const std::vector< rb::CellHit > &allhits, const geo::View_t &view, std::map< int, double > *effMap=0, bool energyEff=false, double *desiredEnergy=0, double *totalEnergy=0, int *desiredHits=0, int *totalHits=0) const
 
double HitCollectionEfficiency (const std::set< int > &trackIDs, const std::vector< art::Ptr< rb::CellHit >> &hits, const std::vector< art::Ptr< rb::CellHit >> &allhits, const geo::View_t &view, std::map< int, double > *effMap=0, bool energyEff=false, double *desiredEnergy=0, double *totalEnergy=0, int *desiredHits=0, int *totalHits=0) const
 
double HitCollectionEfficiency (std::set< int > trackIDs, const art::PtrVector< rb::CellHit > &hits, const art::PtrVector< rb::CellHit > &allhits, const geo::View_t &view, std::map< int, double > *effMap=0, bool energyEff=false, double *desiredEnergy=0, double *totalEnergy=0, int *desiredHits=0, int *totalHits=0) const
 
bool PassMuonCuts (int trackID, art::PtrVector< rb::CellHit > const &hits) const
 Tool for NumuEAna that allows one to see if primary muon (or any track ID you feed the function) contributes to enough hits in the slice to pass the hit cut. It is currently set at 4 hits in each view. More...
 
std::vector< intSliceToNeutrinoIndex (const std::vector< const rb::CellHit * > &sliceHits, const std::vector< const rb::CellHit * > &allHits, bool sortPur=false) const
 Given a collection of hits (often a slice), returns vector of neutrino indices corresponding to the vector from SliceToNeutrinoInteractions. More...
 
std::vector< NeutrinoEffPurSliceToNeutrinoInteractions (const std::vector< const rb::CellHit * > &sliceHits, const std::vector< const rb::CellHit * > &allHits, bool sortPur=false) const
 Given a collection of hits (often a slice), returns vector of structures of neutrino interactions, efficiency, and purity of that neutrino interaction relative to the slice. Efficiency is defined as FLS energy from neutrino interaction in slice / total FLS energy from neutrino interaction in event. This vector is sorted from the highest efficiency interaction to lowest. More...
 
std::vector< NeutrinoEffPurSliceToNeutrinoInteractions (const std::vector< rb::CellHit > &sliceHits, const std::vector< rb::CellHit > &allHits, bool sortPur=false) const
 
std::vector< NeutrinoEffPurSliceToNeutrinoInteractions (const std::vector< art::Ptr< rb::CellHit >> &sliceHits, const std::vector< art::Ptr< rb::CellHit >> &allHits, bool sortPur=false) const
 
std::vector< NeutrinoEffPurSliceToNeutrinoInteractions (const art::PtrVector< rb::CellHit > &sliceHits, const art::PtrVector< rb::CellHit > &allHits, bool sortPur=false) const
 
std::vector< NeutrinoEffPurSliceToNeutrinoInteractions (const art::Ptr< rb::Cluster > &sliceCluster, const std::vector< const rb::CellHit * > &allHits, bool sortPur=false) const
 
std::vector< NeutrinoEffPurSliceToNeutrinoInteractions (const art::Ptr< rb::Cluster > &sliceCluster, const std::vector< rb::CellHit > &allHits, bool sortPur=false) const
 
std::vector< NeutrinoEffPurSliceToNeutrinoInteractions (const art::Ptr< rb::Cluster > &sliceCluster, const std::vector< art::Ptr< rb::CellHit >> &allHits, bool sortPur=false) const
 
std::vector< NeutrinoEffPurSliceToNeutrinoInteractions (const art::Ptr< rb::Cluster > &sliceCluster, const art::PtrVector< rb::CellHit > &allHits, bool sortPur=false) const
 
std::vector< intSliceToOrderedNuIds (const std::vector< cheat::NeutrinoWithIndex > &nusWithIdx, const std::vector< std::vector< cheat::NeutrinoEffPur >> &slTruthTable, std::function< double(const cheat::NeutrinoEffPur &)> slMetric, std::function< double(const cheat::NeutrinoEffPur &)> nuMetric) const
 Given a vector of indexed neutrino interaction and a vector of slice truth tables, returns a vector of neutrino interaction indices ordered by best match to the corresponding slice. Here, best match is determined according to the given cheat::NeutrinoEffPur functions for the slice and the nu. More...
 
std::vector< intSliceToOrderedNuIdsByEff (const std::vector< cheat::NeutrinoWithIndex > &nusWithIdx, const std::vector< std::vector< cheat::NeutrinoEffPur >> &slTruthTable) const
 
std::vector< intSliceToOrderedNuIdsByPur (const std::vector< cheat::NeutrinoWithIndex > &nusWithIdx, const std::vector< std::vector< cheat::NeutrinoEffPur >> &slTruthTable) const
 
std::vector< intSliceToOrderedNuIdsByEffPur (const std::vector< cheat::NeutrinoWithIndex > &nusWithIdx, const std::vector< std::vector< cheat::NeutrinoEffPur >> &slTruthTable) const
 
std::vector< intSliceToOrderedNuIdsByEnergy (const std::vector< cheat::NeutrinoWithIndex > &nusWithIdx, const std::vector< std::vector< cheat::NeutrinoEffPur >> &slTruthTable) const
 
std::vector< NeutrinoEffPurSliceToMCTruth (const std::vector< const rb::CellHit * > &sliceHits, const std::vector< const rb::CellHit * > &allHits, bool sortPur=false) const
 Given a collection of hits (often a slice), returns vector of structures of MCTruth, efficiency, and purity of that neutrino interaction relative to the slice. Efficiency is defined as FLS energy from neutrino interaction in slice / total FLS energy from neutrino interaction in event. This vector is sorted from the highest efficiency interaction to lowest. This function returns all MCTruth, including those without neutrino interactions, i.e. cosmics. More...
 
std::vector< NeutrinoEffPurSliceToMCTruth (const std::vector< rb::CellHit > &sliceHits, const std::vector< rb::CellHit > &allHits, bool sortPur=false) const
 
std::vector< NeutrinoEffPurSliceToMCTruth (const std::vector< art::Ptr< rb::CellHit >> &sliceHits, const std::vector< art::Ptr< rb::CellHit >> &allHits, bool sortPur=false) const
 
std::vector< NeutrinoEffPurSliceToMCTruth (const art::PtrVector< rb::CellHit > &sliceHits, const art::PtrVector< rb::CellHit > &allHits, bool sortPur=false) const
 
std::vector< NeutrinoEffPurSliceToMCTruth (const art::Ptr< rb::Cluster > &sliceCluster, const std::vector< const rb::CellHit * > &allHits, bool sortPur=false) const
 
std::vector< NeutrinoEffPurSliceToMCTruth (const art::Ptr< rb::Cluster > &sliceCluster, const std::vector< rb::CellHit > &allHits, bool sortPur=false) const
 
std::vector< NeutrinoEffPurSliceToMCTruth (const art::Ptr< rb::Cluster > &sliceCluster, const std::vector< art::Ptr< rb::CellHit >> &allHits, bool sortPur=false) const
 
std::vector< NeutrinoEffPurSliceToMCTruth (const art::Ptr< rb::Cluster > &sliceCluster, const art::PtrVector< rb::CellHit > &allHits, bool sortPur=false) const
 
std::vector< std::vector< cheat::NeutrinoEffPur > > SlicesToMCTruthsTable (const std::vector< const rb::Cluster * > &sliceList) const
 Given ALL the slices in an event, including the noise slice, returns a vector of vector of structures of MCTruth, efficiency, and purity of that MCTruth interaction relative to the slice. The returned vector is the same size as the total number of slices, including the noise slice, which is treated the same as any other slice. It is sorted in the same order as the slice list. For each entry, there is a vector of NeutrinoEffPurs. This vector is the same size as the MCTruth list. It is sorted in the same order as the MCTruth list. Every slice/MCTruth pair shows up, even if the contribution is zero. Efficiency is defined as FLS energy from a MCTruth in a slice / total FLS energy from a MCTruth in event. This function is agnostic to MCTruth and treates them all the same, including those without neutrino interactions, i.e. cosmics. More...
 
std::vector< std::vector< cheat::NeutrinoEffPur > > SlicesToMCTruthsTable (const std::vector< rb::Cluster > &sliceList) const
 
std::vector< std::vector< cheat::NeutrinoEffPur > > SlicesToMCTruthsTable (const std::vector< art::Ptr< rb::Cluster >> &sliceList) const
 
std::vector< std::vector< cheat::NeutrinoEffPur > > SlicesToMCTruthsTable (const art::PtrVector< rb::Cluster > &sliceList) const
 
std::vector< ParticleEffPurTracksToParticles (const std::vector< const rb::Track * > &tracks, const std::set< int > &trkIDs, const std::set< int > &allowedDaughters, const std::vector< const rb::CellHit * > &allHits) const
 Given a collection of reconstructed tracks, this method finds the best match for each reco track to the input track id particles. More...
 
std::vector< ParticleEffPurTracksToParticles (const std::vector< rb::Track > &tracks, const std::set< int > &trkIDs, const std::set< int > &allowedDaughters, const std::vector< rb::CellHit > &allHits) const
 
std::vector< ParticleEffPurTracksToParticles (const std::vector< art::Ptr< rb::Track >> &tracks, const std::set< int > &trkIDs, const std::set< int > &allowedDaughters, const std::vector< art::Ptr< rb::CellHit >> &allHits) const
 
std::vector< ParticleEffPurTracksToParticles (const art::PtrVector< rb::Track > &tracks, const std::set< int > &trkIDs, const std::set< int > &allowedDaughters, const art::PtrVector< rb::CellHit > &allHits) const
 
std::vector< ParticleEffPurTracksToParticles (const std::vector< art::Ptr< rb::Track >> &tracks, const std::set< int > &trkIDs, const std::set< int > &allowedDaughters, const art::PtrVector< rb::CellHit > &allHits) const
 
std::vector< NeutrinoWithIndexallNeutrinoInteractions () const
 Function primarily for CAFMaker - returns a vector of all MCTruth interactions along with their truth vector position. More...
 
std::vector< NeutrinoWithIndexallMCTruth () const
 
const sim::ParticleNavigatorParticleNavigator () const
 Get a reference to the ParticleNavigator. More...
 
const std::set< intGetTrackIDList () const
 Get all G4 track ids present in the event. More...
 
std::vector< rb::ClusterClusterByTruth (std::vector< art::Ptr< rb::CellHit > > const &hits)
 : More...
 
rb::Cluster MCTruthToCluster (art::Ptr< simb::MCTruth > const &truth, std::vector< art::Ptr< rb::CellHit > > const &hits)
 : More...
 
void HitToParticlesMap (const std::vector< const rb::Cluster * > &sliceList, const int &sliceIdx)
 
void HitToParticlesMap (const std::vector< rb::Cluster > &sliceList, const int &sliceIdx)
 
void HitToParticlesMap (const std::vector< art::Ptr< rb::Cluster >> &sliceList, const int &sliceIdx)
 
void HitToParticlesMap (const art::PtrVector< rb::Cluster > &sliceList, const int &sliceIdx)
 
cheat::ParticleEffPur ClusterToParticle (const std::vector< const rb::Cluster * > &sliceList, const std::vector< const rb::CellHit * > &hits, const int &sliceIdx)
 
cheat::ParticleEffPur ClusterToParticle (const std::vector< rb::Cluster > &sliceList, const std::vector< rb::CellHit > &hits, const int &sliceIdx)
 
cheat::ParticleEffPur ClusterToParticle (const std::vector< art::Ptr< rb::Cluster >> &sliceList, const std::vector< art::Ptr< rb::CellHit >> &hits, const int &sliceIdx)
 
cheat::ParticleEffPur ClusterToParticle (const art::PtrVector< rb::Cluster > &sliceList, const art::PtrVector< rb::CellHit > &hits, const int &sliceIdx)
 
float CalcEscapingEnergy (const sim::Particle &Par, bool UseMCPart=true, std::string G4Label="trueens")
 A function to calculate the amount of energy from a given MCParticle which is not contained in the detector. Will return the energy the particle had when it exited the detector. Should a particle stop in the detector then the "Escaping energy" is 0. It has the option of returning the energy that a particle deposited energy in the detector. This is calclated from EnEnt - EnEsc, this has the deficiency that depositions from daughters may be doubly counted, however this is what the function CalcDaughterEscapingEnergy is for. There is a flag "UseMCPart", this controls whether to use the saved MCParticles, or to use the more accurate GEANT4 information, which takes into account all daughter particles. Currently it is defaulted to true, ie use the MCParticles, as the GEANT4 info is not usually in the event record yet. More...
 
float CalcEscapingEnergy (const sim::Particle &Par, float &EnDep, bool UseMCPart=true, std::string G4Label="trueens")
 
float CalcDaughterEscapingEnergy (const sim::Particle &Par)
 A function to be used in conjunction with CalcTotalEscapingEnergy to calculate the energy which the daughters of a a given sim::Particle deposited in the detector. More...
 
float CalcTotalEscapingEnergy (const sim::Particle &Par, bool UseMCPart=true, std::string G4Label="trueens")
 An extension of CalcEscapingEnergy which also takes into account the energy which the daughters of given sim::Particle's deposit in the detector. To do this it calls CalcDaughterEscapingEnergy, which in turn calls CalcEscapingEnergy for all of the daughters. More...
 
float CalcTotalEscapingEnergy (const sim::Particle &Par, float &ParEnDep, bool UseMCPart=true, std::string G4Label="trueens")
 
bool InterceptsDetector (const sim::Particle &Par, int &TrajEnt, int &TrajEx)
 A function which returns the trajectory point at which the particle first enters and leave the detector volume. The trajectory point is returned so that the user can determine the energies etc which the particle had at this point. Should the particle have been generated in the detector then TrajEnt == 0 will be returned. Should the particle stop in the detector then TrajEx == NumberTrajectoryPoints()-1 will be returned. Should the particle never enter the detector then holder values TrajEnter == TrajEx == -5 will be returned. More...
 

Static Public Member Functions

static bool sort_eff (const NeutrinoEffPur &a, const NeutrinoEffPur &b)
 Tool for function SliceToNeutrinoInteractions, tells how to sort by putting structures with highest efficiency first. More...
 
static bool sort_pur (const NeutrinoEffPur &a, const NeutrinoEffPur &b)
 Tool for function SliceToNeutrinoInteractions, tells how to sort by putting structures with highest purity first. More...
 
static bool sort_idxeff (const std::pair< int, NeutrinoEffPur > &a, const std::pair< int, NeutrinoEffPur > &b)
 Tool for function SliceToNeutrinoIndex, tells how to sort by putting structures with highest efficiency first. More...
 
static bool sort_idxpur (const std::pair< int, NeutrinoEffPur > &a, const std::pair< int, NeutrinoEffPur > &b)
 Tool for function SliceToNeutrinoIndex, tells how to sort by putting structures with highest purity first. More...
 

Private Member Functions

template<class T >
std::vector< const T * > PtrVecToVecRawPtr (const art::PtrVector< T > &xs) const
 Helper function for implementing overloads. More...
 
template<class T >
std::vector< const T * > VecPtrToVecRawPtr (const std::vector< art::Ptr< T >> &xs) const
 
template<class T >
std::vector< const T * > VecToVecRawPtr (const std::vector< T > &xs) const
 
double HitCollectionPurity (const std::set< int > &trackIDs, const std::vector< RawWeightedHit > &whits, std::map< int, double > *purMap=0, std::map< int, int > *parents=0, bool energyPur=false) const
 Internal implementation of public HitCollectionPurity. More...
 
double HitCollectionEfficiency (const std::set< int > &trackIDs, const std::vector< RawWeightedHit > &whits, const std::vector< const rb::CellHit * > &allhits, const geo::View_t &view, std::map< int, double > *effMap=0, bool energyEff=false, double *desiredEnergy=0, double *totalEnergy=0, int *desiredHits=0, int *totalHits=0) const
 Internal implementation of public HitCollectionEfficiency. More...
 
bool CloseInTime (const rb::CellHit &chit, const sim::PhotonSignal &phot) const
 Internal helper, decides if a PhotonSignal and CellHit are close enough to match. More...
 
void AccumulateHitContributions (rb::CellHit const &hit, std::map< int, int > &idToNPhot) const
 Internal helper, adds the contributions from each particle in this cell to the map. More...
 

Private Attributes

Params fParams
 
bool fHaveTruthInfo
 Set by Rebuild. More...
 
novadaq::cnv::DetId fDetID
 detector id More...
 
std::unordered_map< geo::OfflineChan, std::list< sim::FLSHit > > fCellToFLSHit
 map of FLSHits in each cell in event More...
 
std::unordered_map< int, std::list< sim::FLSHit > > fTrackIDToFLSHit
 map of G4 track ids to FLSHits More...
 
std::unordered_map< geo::OfflineChan, std::vector< sim::PhotonSignal > > fCellToPhotonSignal
 map of PhotonSignals in each cell in event More...
 
sim::ParticleNavigator fParticleNav
 Particle navigator to map track ID to Particle. More...
 
std::set< intfTrackIDs
 G4 track ids for all particles in the events. More...
 
std::vector< art::Ptr< simb::MCTruth > > fMCTruthList
 all the MCTruths for this event More...
 
std::map< int, intfTrackIDToMCTruthIndex
 map of track id values to MCTruthList entry More...
 
std::vector< art::Ptr< sim::TrueEnergy > > fTrueEnergyList
 all the TrueEnergy's for this event More...
 
std::map< int, intfTrackIDToTrueEIndex
 map of track id values to TrueEnergy entry More...
 
std::map< double, std::vector< cheat::TrackIDE > > fCellToIDs
 
std::map< int, float > fIdToEnergy
 
int fSliceIDForHitParticleMap
 
int fNumTrueEnergyWarnings
 

Detailed Description

Many functions come in four variants. The core implementation is in terms of vector<const T*>, which is the common basis all the others can be converted to. If you have an art::Handle<vector<T>> you can just dereference it to get this type. If you happen to have a vector<T> or vector<Ptr<T>> or PtrVector<T>, overloads are provided so that those are just as easy to work with.

Definition at line 93 of file BackTracker.h.

Member Typedef Documentation

Definition at line 114 of file BackTracker.h.

Constructor & Destructor Documentation

cheat::BackTracker::BackTracker ( const Parameters params,
art::ActivityRegistry reg 
)

Definition at line 70 of file BackTracker_service.cc.

References fNumTrueEnergyWarnings, Rebuild(), and art::ActivityRegistry::sPreProcessEvent.

72  : fParams(params()), fHaveTruthInfo(false)
73  {
74  reg.sPreProcessEvent.watch(this, &BackTracker::Rebuild);
76  }
void Rebuild(const art::Event &evt)
bool fHaveTruthInfo
Set by Rebuild.
Definition: BackTracker.h:935
GlobalSignal< detail::SignalResponseType::FIFO, void(Event const &)> sPreProcessEvent
cheat::BackTracker::~BackTracker ( )

Definition at line 79 of file BackTracker_service.cc.

80  {
81  }

Member Function Documentation

void cheat::BackTracker::AccumulateHitContributions ( rb::CellHit const &  hit,
std::map< int, int > &  idToNPhot 
) const
private

Internal helper, adds the contributions from each particle in this cell to the map.

Definition at line 1493 of file BackTracker_service.cc.

References rb::CellHit::Cell(), CloseInTime(), fCellToPhotonSignal, MECModelEnuComparisons::i, it, sim::PhotonSignal::NPhoton(), rb::CellHit::Plane(), and sim::PhotonSignal::TrackId().

Referenced by HitsToParticle(), HitToFLSHit(), and HitToParticle().

1495  {
1496  auto it = fCellToPhotonSignal.find(geo::OfflineChan(hit.Plane(), hit.Cell()));
1497  // Nothing to accumulate from this cell
1498  if(it == fCellToPhotonSignal.end()) return;
1499 
1500  // Candidate photons, in that they're in the right cell.
1501  const std::vector<sim::PhotonSignal>& phots = it->second;
1502 
1503  // For every photon that's sufficiently in time with the hit,
1504  // accumulate its energy into the relevant trackID.
1505  for(unsigned int i = 0; i < phots.size(); ++i){
1506  const sim::PhotonSignal& phot = phots[i];
1507  if(CloseInTime(hit, phot)){
1508  idToNPhot[phot.TrackId()] += phot.NPhoton();
1509  }
1510  }
1511  }
std::unordered_map< geo::OfflineChan, std::vector< sim::PhotonSignal > > fCellToPhotonSignal
map of PhotonSignals in each cell in event
Definition: BackTracker.h:941
set< int >::iterator it
int TrackId() const
Definition: PhotonSignal.h:33
int NPhoton() const
Definition: PhotonSignal.h:30
Definition: event.h:1
A (plane, cell) pair.
Definition: OfflineChan.h:17
bool CloseInTime(const rb::CellHit &chit, const sim::PhotonSignal &phot) const
Internal helper, decides if a PhotonSignal and CellHit are close enough to match. ...
std::vector< NeutrinoWithIndex > cheat::BackTracker::allMCTruth ( ) const

Definition at line 1449 of file BackTracker_service.cc.

References fMCTruthList.

Referenced by tut::RecoValidationTutorial::analyze(), cvn::CVNEventDump::analyze(), cvn::CVNCosmicEventDump::analyze(), earms::ElasticArmsValidate::analyze(), cvn::CVNEventProngDump::analyze(), fuzz::FuzzyKValidate::analyze(), bpf::BPFCVNAna::analyze(), cvn::CVNAddTrainingData::produce(), fuzz::FuzzyKVertex::produce(), caf::CAFMaker::produce(), skim::SkimmingUtils::SliceMCTruthAssociation(), and SlicesToMCTruthsTable().

1450  {
1451  std::vector <NeutrinoWithIndex> allTruth;
1452 
1453  for (unsigned int s = 0; s < fMCTruthList.size(); s++){
1454  const art::Ptr<simb::MCTruth> neutrinoInteraction = fMCTruthList[s];
1455  NeutrinoWithIndex neutrino = {neutrinoInteraction, s};
1456  allTruth.push_back(neutrino);
1457  }
1458 
1459  return allTruth;
1460  }
std::vector< art::Ptr< simb::MCTruth > > fMCTruthList
all the MCTruths for this event
Definition: BackTracker.h:944
const XML_Char * s
Definition: expat.h:262
std::vector< NeutrinoWithIndex > cheat::BackTracker::allNeutrinoInteractions ( ) const

Function primarily for CAFMaker - returns a vector of all MCTruth interactions along with their truth vector position.

Definition at line 1432 of file BackTracker_service.cc.

References fMCTruthList, and simb::MCTruth::NeutrinoSet().

Referenced by cheat::TestTrackIds::analyze(), and slid::LIDTraining::analyze().

1433  {
1434  std::vector <NeutrinoWithIndex> allNeutrinoInteractions;
1435 
1436  for (unsigned int s = 0; s < fMCTruthList.size(); s++){
1437  const art::Ptr<simb::MCTruth> neutrinoInteraction = fMCTruthList[s];
1438  if(!neutrinoInteraction->NeutrinoSet())
1439  continue;
1440 
1441  NeutrinoWithIndex neutrino = {neutrinoInteraction, s};
1442  allNeutrinoInteractions.push_back(neutrino);
1443  }
1444 
1445  return allNeutrinoInteractions;
1446  }
std::vector< NeutrinoWithIndex > allNeutrinoInteractions() const
Function primarily for CAFMaker - returns a vector of all MCTruth interactions along with their truth...
std::vector< art::Ptr< simb::MCTruth > > fMCTruthList
all the MCTruths for this event
Definition: BackTracker.h:944
const XML_Char * s
Definition: expat.h:262
bool NeutrinoSet() const
Definition: MCTruth.h:77
float cheat::BackTracker::CalcDaughterEscapingEnergy ( const sim::Particle Par)

A function to be used in conjunction with CalcTotalEscapingEnergy to calculate the energy which the daughters of a a given sim::Particle deposited in the detector.

Definition at line 1755 of file BackTracker_service.cc.

References CalcEscapingEnergy(), simb::MCParticle::Daughter(), std::max(), simb::MCParticle::NumberDaughters(), and TrackIDToParticle().

Referenced by CalcTotalEscapingEnergy().

1755  {
1756  float DauEsc = 0.;
1757  int NumDaught = Par.NumberDaughters();
1758  for (int dau=0; dau<NumDaught; ++dau) {
1759  const sim::Particle* ThisDau = TrackIDToParticle( Par.Daughter( dau ) );
1760  float ThisEsc = CalcEscapingEnergy( (*ThisDau), true );
1761  DauEsc += std::max((float)0., ThisEsc);
1762  /*
1763  std::cout << "\tDaughter " << dau << " of " << NumDaught << " was a " << ThisDau->PdgCode() << ", TrackId " << ThisDau->TrackId()
1764  << ", it had " << ThisDau->NumberDaughters() << " daughters itself. "
1765  << " EscEn for this particle = " << ThisEsc << " ==> DauEsc = " << DauEsc
1766  << std::endl;
1767  */
1768  if ( ThisDau->NumberDaughters() ) {
1769  //std::cout << "\t\t****** This particle has daughters, so recall the function... ******" << std::endl;
1770  float DaughtEsc = CalcDaughterEscapingEnergy( (*ThisDau) );
1771  DauEsc += DaughtEsc;
1772  //std::cout << "\t\t****** The sum of all EEscs was " << DaughtEsc << " ==> DauEsc is " << DauEsc << std::endl;
1773  } // If this particle has daughters itself
1774  } // Loop through the daughters of my particle.
1775  //std::cout << "\n\tAt the end of all of that, the sum of all escaping daughters was " << DauEsc << std::endl;
1776  return DauEsc;
1777  } // end of CalcDaughterEscapingEnergy
T max(const caf::Proxy< T > &a, T b)
float CalcEscapingEnergy(const sim::Particle &Par, bool UseMCPart=true, std::string G4Label="trueens")
A function to calculate the amount of energy from a given MCParticle which is not contained in the de...
float CalcDaughterEscapingEnergy(const sim::Particle &Par)
A function to be used in conjunction with CalcTotalEscapingEnergy to calculate the energy which the d...
int NumberDaughters() const
Definition: MCParticle.h:216
int Daughter(const int i) const
Definition: MCParticle.cxx:112
const sim::Particle * TrackIDToParticle(int const &id) const
Returns a pointer to the sim::Particle object corresponding to the given TrackID. ...
float cheat::BackTracker::CalcEscapingEnergy ( const sim::Particle Par,
bool  UseMCPart = true,
std::string  G4Label = "trueens" 
)

A function to calculate the amount of energy from a given MCParticle which is not contained in the detector. Will return the energy the particle had when it exited the detector. Should a particle stop in the detector then the "Escaping energy" is 0. It has the option of returning the energy that a particle deposited energy in the detector. This is calclated from EnEnt - EnEsc, this has the deficiency that depositions from daughters may be doubly counted, however this is what the function CalcDaughterEscapingEnergy is for. There is a flag "UseMCPart", this controls whether to use the saved MCParticles, or to use the more accurate GEANT4 information, which takes into account all daughter particles. Currently it is defaulted to true, ie use the MCParticles, as the GEANT4 info is not usually in the event record yet.

Definition at line 1688 of file BackTracker_service.cc.

Referenced by CalcDaughterEscapingEnergy(), and CalcTotalEscapingEnergy().

1688  {
1689  float TempVar = -5;
1690  return CalcEscapingEnergy( Par, TempVar, UseMCPart, G4Label );
1691  }// end of CalcEscapingEnergy
float CalcEscapingEnergy(const sim::Particle &Par, bool UseMCPart=true, std::string G4Label="trueens")
A function to calculate the amount of energy from a given MCParticle which is not contained in the de...
float cheat::BackTracker::CalcEscapingEnergy ( const sim::Particle Par,
float &  EnDep,
bool  UseMCPart = true,
std::string  G4Label = "trueens" 
)

A function to calculate the amount of energy from a given MCParticle which is not contained in the detector. Will return the energy the particle had when it exited the detector. Should a particle stop in the detector then the "Escaping energy" is 0. It has the option of returning the energy that a particle deposited energy in the detector. This is calclated from EnEnt - EnEsc, this has the deficiency that depositions from daughters may be doubly counted, however this is what the function CalcDaughterEscapingEnergy is for. There is a flag "UseMCPart", this controls whether to use the saved MCParticles, or to use the more accurate GEANT4 information, which takes into account all daughter particles. Currently it is defaulted to true, ie use the MCParticles, as the GEANT4 info is not usually in the event record yet.

Definition at line 1695 of file BackTracker_service.cc.

References simb::MCParticle::E(), fTrackIDToTrueEIndex, fTrueEnergyList, InterceptsDetector(), simb::MCParticle::Mass(), simb::MCParticle::NumberTrajectoryPoints(), sim::TrueEnergy::TotalDepEnergy(), sim::TrueEnergy::TotalEscEnergy(), and simb::MCParticle::TrackId().

1695  {
1696  /// A function to calculate the amount of energy from a given MCParticle which is not contained in the detector.
1697  /// Will return the energy the particle had when it exited the detector.
1698  /// Should a particle stop in the detector then the "Escaping energy" is 0.
1699  /// It has the option of returning the energy that a particle deposited energy in the detector.
1700  /// This is calclated from EnEnt - EnEsc, this has the deficiency that depositions from daughters may be doubly counted,
1701  /// however this is what the function CalcDaughterEscapingEnergy is for.
1702  /// There is a flag "UseMCPart", this controls whether to use the saved MCParticles, or to use the more accurate GEANT4
1703  /// information, which takes into account all daughter particles.
1704  /// Currently it is defaulted to true, ie use the MCParticles, as the GEANT4 info is not usually in the event record yet.
1705 
1706  // Set to some default values.
1707  float EnEsc, EnEnt;
1708  EnEsc = EnEnt = EnDep = -5;
1709 
1710  // --- Do I want to use the information stored in MCParticle?
1711  if (UseMCPart) {
1712  // Make variables to call InterceptsDetector.
1713  int TrajEnter, TrajExit;
1714  TrajEnter = TrajExit = -1;
1715  // Call InterceptsDetector
1716  bool IntDet = InterceptsDetector( Par, TrajEnter, TrajExit );
1717 
1718  // If IntDet == false then the particle never entered the detector, so return 0's.
1719  if (!IntDet) {
1720  return EnEsc;
1721  } else {
1722  // Now work out the energy which the particle deposited...
1723  // Set EnEnt
1724  EnEnt = (float)Par.E( TrajEnter ) - Par.Mass();
1725  // If TrajExit isn't NTraj-1, the particle left the volume then some energy was lost!
1726  // If TrajExit == NTraj-1 then we can just leave EnEsc as 0.
1727  if ( TrajExit != (int)Par.NumberTrajectoryPoints()-1 ) {
1728  EnEsc = (float)Par.E( TrajExit ) - Par.Mass();
1729  }
1730  // The energy deposited is just the entering energy - the exiting energy.
1731  EnDep = EnEnt - EnEsc;
1732  }
1733  // now return
1734  return EnEsc;
1735  } else {
1736  std::map<int, int>::iterator TrEIt = fTrackIDToTrueEIndex.find( Par.TrackId() );
1737  if ( TrEIt != fTrackIDToTrueEIndex.end() ) {
1738  art::Ptr< sim::TrueEnergy > ThisEn = fTrueEnergyList[ TrEIt->second ];
1739  /*
1740  std::cout << "Looking at the sim::TrueEnergy from the data product it is, TrackID " << ThisEn->TrackID() << ", EntEn " << ThisEn->EnteringEnergy()
1741  << ", EscEn " << ThisEn->EscapingEnergy() << ", TotEDep " << ThisEn->TotalDepEnergy() << ", TotEscEn " << ThisEn->TotalEscEnergy()
1742  << std::endl;
1743  */
1744  EnDep = ThisEn->TotalDepEnergy();
1745  return ThisEn->TotalEscEnergy();
1746  } else {
1747  mf::LogWarning("BackTracker") << "Didn't find TrackId " << Par.TrackId() << " in my map of sim::TrueEnergy's, returning -5.";
1748  return -5;
1749  }
1750  }
1751  }// end of CalcEscapingEnergy
double E(const int i=0) const
Definition: MCParticle.h:232
unsigned int NumberTrajectoryPoints() const
Definition: MCParticle.h:217
bool InterceptsDetector(const sim::Particle &Par, int &TrajEnt, int &TrajEx)
A function which returns the trajectory point at which the particle first enters and leave the detect...
double Mass() const
Definition: MCParticle.h:238
float TotalEscEnergy() const
Definition: TrueEnergy.h:40
int TrackId() const
Definition: MCParticle.h:209
std::vector< art::Ptr< sim::TrueEnergy > > fTrueEnergyList
all the TrueEnergy&#39;s for this event
Definition: BackTracker.h:946
std::map< int, int > fTrackIDToTrueEIndex
map of track id values to TrueEnergy entry
Definition: BackTracker.h:947
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
float TotalDepEnergy() const
Definition: TrueEnergy.h:39
Definition: fwd.h:28
float cheat::BackTracker::CalcTotalEscapingEnergy ( const sim::Particle Par,
bool  UseMCPart = true,
std::string  G4Label = "trueens" 
)

An extension of CalcEscapingEnergy which also takes into account the energy which the daughters of given sim::Particle's deposit in the detector. To do this it calls CalcDaughterEscapingEnergy, which in turn calls CalcEscapingEnergy for all of the daughters.

Definition at line 1781 of file BackTracker_service.cc.

Referenced by cheat::TrueEnergy::produce().

1781  {
1782  float TempVar = 0.;
1783  return CalcTotalEscapingEnergy( Par, TempVar, UseMCPart, G4Label );
1784  }
float CalcTotalEscapingEnergy(const sim::Particle &Par, bool UseMCPart=true, std::string G4Label="trueens")
An extension of CalcEscapingEnergy which also takes into account the energy which the daughters of gi...
float cheat::BackTracker::CalcTotalEscapingEnergy ( const sim::Particle Par,
float &  ParEnDep,
bool  UseMCPart = true,
std::string  G4Label = "trueens" 
)

Definition at line 1788 of file BackTracker_service.cc.

References CalcDaughterEscapingEnergy(), CalcEscapingEnergy(), fTrackIDToTrueEIndex, fTrueEnergyList, simb::MCParticle::Mass(), std::max(), simb::MCParticle::PdgCode(), sim::TrueEnergy::TotalDepEnergy(), sim::TrueEnergy::TotalEscEnergy(), and simb::MCParticle::TrackId().

1788  {
1789  if ( UseMCPart ) {
1790  float ParEDep = 0;
1791  float ParEEsc = CalcEscapingEnergy( Par, ParEDep, UseMCPart, G4Label );
1792  float DauEEsc = CalcDaughterEscapingEnergy( Par );
1793 
1794  float TotEnEsc = std::max((float)0., ParEEsc) + std::max((float)0., DauEEsc);
1795  TotEnDep = ParEDep - DauEEsc;
1796  // --- If negative, then had particle had very little energy --> may need to consider rest mass energy.
1797  if ( TotEnDep < 0 ) {
1798  //std::cout << "\t\t ** TotEnDep is negative " << TotEnDep << ", initially set to 0, but will check Part type. " << std::endl;
1799  // --- Default TotEnDep to 0.
1800  TotEnDep = 0;
1801  // --- If this particle decayed in the detector (ParEdep != 0) then it's likely that the particles it produced left the detector,
1802  // and the sum of their energies will be more than the initial KE of the particle.
1803  // For now I will modify this for some choice particles, not sure how best to do this...
1804  if ( ParEDep != 0 &&
1805  ( abs(Par.PdgCode()) == 11 || // Electron
1806  abs(Par.PdgCode()) == 13 || // Muon
1807  abs(Par.PdgCode()) == 111 || // Pi0
1808  abs(Par.PdgCode()) == 211 || // Pion
1809  abs(Par.PdgCode()) == 321 ) // Kaon
1810  ) {
1811  /*
1812  std::cout << "\t\t ** This particle likely decayed, so adding RestMass of " << Par.Mass()
1813  << " --- TotEnDep = " << ParEDep << " - " << DauEEsc << " + " << Par.Mass() << " = " << ParEDep - DauEEsc + Par.Mass()
1814  << std::endl;
1815  */
1816  TotEnDep = std::max( 0., ParEDep - DauEEsc + Par.Mass() );
1817  }
1818  }
1819  /*
1820  std::cout << "\t***The end of CalcTotalEscapingEnergy -- ParEEsc " << ParEEsc << ", ParEDep " << ParEDep << ", DauEEsc " << DauEEsc << ".\n"
1821  << "\t TotEnEsc = " << ParEEsc << " + " << DauEEsc << " = " << TotEnEsc << ".\n"
1822  << "\t TotEnDep = " << ParEDep << " - " << DauEEsc << " = " << TotEnDep << "."
1823  << std::endl;
1824  */
1825  return TotEnEsc;
1826  } else {
1827  std::map<int, int>::iterator TrEIt = fTrackIDToTrueEIndex.find( Par.TrackId() );
1828  if ( TrEIt != fTrackIDToTrueEIndex.end() ) {
1829  art::Ptr< sim::TrueEnergy > ThisEn = fTrueEnergyList[ TrEIt->second ];
1830  /*
1831  std::cout << "Looking at the sim::TrueEnergy from the data product it is, TrackID " << ThisEn->TrackID() << ", EntEn " << ThisEn->EnteringEnergy()
1832  << ", EscEn " << ThisEn->EscapingEnergy() << ", TotEDep " << ThisEn->TotalDepEnergy() << ", TotEscEn " << ThisEn->TotalEscEnergy()
1833  << std::endl;
1834  */
1835  TotEnDep = ThisEn->TotalDepEnergy();
1836  return ThisEn->TotalEscEnergy();
1837  } else {
1838  mf::LogWarning("BackTracker") << "Didn't find TrackId " << Par.TrackId() << " in my map of sim::TrueEnergy's, returning -5.";
1839  return -5;
1840  }
1841  }
1842  }
T max(const caf::Proxy< T > &a, T b)
int PdgCode() const
Definition: MCParticle.h:211
double Mass() const
Definition: MCParticle.h:238
float CalcEscapingEnergy(const sim::Particle &Par, bool UseMCPart=true, std::string G4Label="trueens")
A function to calculate the amount of energy from a given MCParticle which is not contained in the de...
float CalcDaughterEscapingEnergy(const sim::Particle &Par)
A function to be used in conjunction with CalcTotalEscapingEnergy to calculate the energy which the d...
float TotalEscEnergy() const
Definition: TrueEnergy.h:40
int TrackId() const
Definition: MCParticle.h:209
std::vector< art::Ptr< sim::TrueEnergy > > fTrueEnergyList
all the TrueEnergy&#39;s for this event
Definition: BackTracker.h:946
std::map< int, int > fTrackIDToTrueEIndex
map of track id values to TrueEnergy entry
Definition: BackTracker.h:947
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
float TotalDepEnergy() const
Definition: TrueEnergy.h:39
Definition: fwd.h:28
const std::vector< sim::FLSHit > cheat::BackTracker::CellToFLSHit ( unsigned int const &  plane,
unsigned int const &  cell 
) const

Returns the FLSHits contributing the signal in the specified cell. WARNING: Use with extreme caution! Most users should use HitToFLSHit instead. Only use the cell version if you really want to know ALL the FLSHits in the cell for the entire time window, NOT time-associated with the hit.

The vector is sorted to return in order of highest contributing Geant4 track to lowest.

Definition at line 325 of file BackTracker_service.cc.

References fCellToFLSHit, it, and LOG_DEBUG.

Referenced by cheat::TestTrackIds::analyze(), and cheat::CheckBackTracking::CheckFLSHitConsistency().

327  {
328  auto it = fCellToFLSHit.find(geo::OfflineChan(plane, cell));
329 
330  if(it == fCellToFLSHit.end()){
331  LOG_DEBUG("BackTracker") << "no collection of sim::FLSHit for "
332  << " plane = " << plane << " cell = " << cell
333  << " probably this was a noise hit, returning an"
334  << " empty vector";
335  const std::vector<sim::FLSHit> empty;
336  return empty;
337  }
338  return std::vector<sim::FLSHit>(it->second.begin(), it->second.end());
339  }
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
set< int >::iterator it
std::unordered_map< geo::OfflineChan, std::list< sim::FLSHit > > fCellToFLSHit
map of FLSHits in each cell in event
Definition: BackTracker.h:939
A (plane, cell) pair.
Definition: OfflineChan.h:17
const std::vector< sim::PhotonSignal > cheat::BackTracker::CellToPhotonSignal ( unsigned int const &  plane,
unsigned int const &  cell 
) const

Returns the PhotonSignals contributing the signal in the specified cell. WARNING: Use with extreme caution! Most users should use HitToPhotonSignal instead. Only use the cell version if you really want to know ALL the photon signals in the cell for the entire time window, NOT time-associated with the hit.

Sorted from highest signal to lowest (which is probably not much use, since energy from one particle can be split over several signals).

Definition at line 277 of file BackTracker_service.cc.

References fCellToPhotonSignal, it, and LOG_DEBUG.

Referenced by mcchk::CloseInTime::analyze().

279  {
281 
282  if(it == fCellToPhotonSignal.end()){
283  LOG_DEBUG("BackTracker") << "no collection of sim::PhotonSignal for "
284  << " plane = " << plane << " cell = " << cell
285  << " probably this was a noise hit, returning an"
286  << " empty vector";
287  const std::vector<sim::PhotonSignal> empty;
288  return empty;
289  }
290  return it->second;
291  }
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
std::unordered_map< geo::OfflineChan, std::vector< sim::PhotonSignal > > fCellToPhotonSignal
map of PhotonSignals in each cell in event
Definition: BackTracker.h:941
set< int >::iterator it
A (plane, cell) pair.
Definition: OfflineChan.h:17
bool cheat::BackTracker::CloseInTime ( const rb::CellHit chit,
const sim::PhotonSignal phot 
) const
private

Internal helper, decides if a PhotonSignal and CellHit are close enough to match.

Definition at line 1464 of file BackTracker_service.cc.

References fDetID, rb::CellHit::GoodTiming(), novadaq::cnv::kFARDET, novadaq::cnv::kNEARDET, sim::PhotonSignal::TimeMean(), and rb::CellHit::TNS().

Referenced by AccumulateHitContributions(), and HitToPhotonSignal().

1465  {
1466  //The constants used to determine this value change depending on detector
1467  //and hit timing reconstruction. See docdb 9092 to see how the current
1468  //constants were determined (May 2013). To redo the study and see if new
1469  //constants are required, use MCCheckOut/CloseInTime_module.cc.
1470 
1471  // Empirically determined as an over-generous width of the timing reconstruction.
1472  double kWindowNs = 1000;
1473  // Empirically determined as the approximate mean bias of the timing reconstruction.
1474  // This is the amount the CellHit is expected to be earlier than the photons.
1475  double kOffsetNs = 350;
1476 
1477  if ((fDetID == novadaq::cnv::kFARDET)&&(chit.GoodTiming())){
1478  kWindowNs = 500;
1479  kOffsetNs = 10;
1480  }
1481 
1482  if ((fDetID == novadaq::cnv::kNEARDET)&&(chit.GoodTiming())){
1483  kWindowNs = 200;
1484  kOffsetNs = 10;
1485  }
1486 
1487  const double dt = chit.TNS()-phot.TimeMean();
1488 
1489  return fabs(dt+kOffsetNs) <= kWindowNs;
1490  }
float TNS() const
Definition: CellHit.h:46
Definition: Cand.cxx:23
Far Detector at Ash River, MN.
Near Detector in the NuMI cavern.
bool GoodTiming() const
Definition: CellHit.h:48
novadaq::cnv::DetId fDetID
detector id
Definition: BackTracker.h:937
double TimeMean() const
Definition: PhotonSignal.h:29
std::vector< rb::Cluster > cheat::BackTracker::ClusterByTruth ( std::vector< art::Ptr< rb::CellHit > > const &  hits)

:

Definition at line 1550 of file BackTracker_service.cc.

References fMCTruthList, fTrackIDToMCTruthIndex, hits(), HitToParticle(), compare_h5_caf::idx, IsNoise(), part, and simb::MCParticle::TrackId().

Referenced by slicer::TruthSlicer::produce().

1551  {
1552  std::vector<rb::Cluster> clusters(fMCTruthList.size()+1);
1553 
1554  for(unsigned int hiti = 0; hiti < hits.size(); ++hiti) {
1555  art::Ptr<rb::CellHit> hit = hits[hiti];
1556 
1557  // If the hit is noise, put it into the last cluster.
1558  if(this->IsNoise(hit)) {
1559  clusters[fMCTruthList.size()].Add(hit);
1560  continue;
1561  }
1562 
1563  const sim::Particle *part = this->HitToParticle(hit);
1564  unsigned int idx = fTrackIDToMCTruthIndex[part->TrackId()];
1565  clusters[idx].Add(hit);
1566 
1567  } // end loop over hits
1568 
1569  // Label the noise slice.
1570  clusters[fMCTruthList.size()].SetNoise(true);
1571 
1572  return clusters;
1573  }
const sim::Particle * HitToParticle(art::Ptr< rb::CellHit > const &hit, bool quiet=false) const
Returns the sim::Particle object contributing the most light to the specified rb::CellHit.
bool IsNoise(const art::Ptr< rb::CellHit > &hit) const
Is this hit not associated with any particles?
int TrackId() const
Definition: MCParticle.h:209
std::vector< art::Ptr< simb::MCTruth > > fMCTruthList
all the MCTruths for this event
Definition: BackTracker.h:944
TString part[npart]
Definition: Style.C:32
void hits()
Definition: readHits.C:15
std::map< int, int > fTrackIDToMCTruthIndex
map of track id values to MCTruthList entry
Definition: BackTracker.h:945
Definition: event.h:1
cheat::ParticleEffPur cheat::BackTracker::ClusterToParticle ( const std::vector< const rb::Cluster * > &  sliceList,
const std::vector< const rb::CellHit * > &  hits,
const int sliceIdx 
)

Definition at line 1635 of file BackTracker_service.cc.

References rb::CellHit::Cell(), febshutoff_auto::chan, cheat::ParticleEffPur::efficiency, fCellToIDs, fIdToEnergy, fSliceIDForHitParticleMap, HitToParticlesMap(), maxE, maxID(), cheat::ParticleEffPur::pdg, simb::MCParticle::PdgCode(), rb::CellHit::Plane(), cheat::ParticleEffPur::purity, rawdata::RawDigit::TDC(), cheat::ParticleEffPur::trackID, and TrackIDToParticle().

Referenced by caf::FillParticleTruth().

1638  {
1639 
1640  if(sliceIdx != fSliceIDForHitParticleMap){
1641  HitToParticlesMap(sliceList, sliceIdx);
1642  }
1643 
1644  double totalE = 0.0;
1645  unsigned int nh = hits.size();
1646 
1647  // make a map of how much energy each track ID contributes to
1648  // this cluster. Also keep track of how much total true energy
1649  // there is in this cluster.
1650 
1651  std::map< int, double> idToEnergyInProng;
1652  for(unsigned int ih = 0; ih < nh; ih++){
1653  const rb::CellHit* hit = hits[ih];
1654  double chan = (hit->TDC()*1000000) + (hit->Plane()*1000) + hit->Cell();
1655  std::vector<cheat::TrackIDE> ides = fCellToIDs[chan];
1656  for(auto ide: ides){
1657  idToEnergyInProng[ide.trackID] += ide.energy;
1658  totalE += ide.energy;
1659  }// end loop over ides
1660  }// end loop over cluster hits
1661 
1662  // now find which trackID contributed the most energy to
1663  // the cluster
1664  int maxID = -1;
1665  double maxE = -1.0;
1666 
1667  cheat::ParticleEffPur puff = {-1,-1,-1,-1};
1668  if(idToEnergyInProng.size() == 0)
1669  return puff;
1670 
1671  for(auto idtoe: idToEnergyInProng){
1672  if(idtoe.second > maxE ){
1673  maxE = idtoe.second;
1674  maxID = idtoe.first;
1675  }
1676  }// end loop over trackID to energy map
1677 
1678  puff.trackID = maxID;
1679  puff.purity = maxE/totalE;
1680  puff.efficiency = maxE/fIdToEnergy[maxID];
1681  puff.pdg = TrackIDToParticle(maxID)->PdgCode();
1682 
1683  return puff;
1684  }// end of ClusterToParticle
int PdgCode() const
Definition: MCParticle.h:211
int32_t TDC() const
The time of the last baseline sample.
Definition: RawDigit.h:94
void HitToParticlesMap(const std::vector< const rb::Cluster * > &sliceList, const int &sliceIdx)
unsigned short Plane() const
Definition: CellHit.h:39
std::map< double, std::vector< cheat::TrackIDE > > fCellToIDs
Definition: BackTracker.h:951
int trackID
Truth particle track ID.
Definition: BackTracker.h:66
double purity
Putity of particle relative to track.
Definition: BackTracker.h:68
int maxID(double arrayInput[])
unsigned short Cell() const
Definition: CellHit.h:40
std::map< int, float > fIdToEnergy
Definition: BackTracker.h:952
void hits()
Definition: readHits.C:15
double efficiency
Efficiency of particle relative to track.
Definition: BackTracker.h:67
int pdg
Pdg of particle.
Definition: BackTracker.h:69
const sim::Particle * TrackIDToParticle(int const &id) const
Returns a pointer to the sim::Particle object corresponding to the given TrackID. ...
A rawdata::RawDigit with channel information decoded.
Definition: CellHit.h:27
Definition: event.h:1
double maxE
Definition: plot_hist.C:8
cheat::ParticleEffPur cheat::BackTracker::ClusterToParticle ( const std::vector< rb::Cluster > &  sliceList,
const std::vector< rb::CellHit > &  hits,
const int sliceIdx 
)
inline

Definition at line 794 of file BackTracker.h.

797  {
798  return ClusterToParticle(VecToVecRawPtr(sliceList),
800  sliceIdx);
801  }
cheat::ParticleEffPur ClusterToParticle(const std::vector< const rb::Cluster * > &sliceList, const std::vector< const rb::CellHit * > &hits, const int &sliceIdx)
void hits()
Definition: readHits.C:15
std::vector< const T * > VecToVecRawPtr(const std::vector< T > &xs) const
Definition: BackTracker.h:887
cheat::ParticleEffPur cheat::BackTracker::ClusterToParticle ( const std::vector< art::Ptr< rb::Cluster >> &  sliceList,
const std::vector< art::Ptr< rb::CellHit >> &  hits,
const int sliceIdx 
)
inline

Definition at line 803 of file BackTracker.h.

806  {
807  return ClusterToParticle(VecPtrToVecRawPtr(sliceList),
809  sliceIdx);
810  }
std::vector< const T * > VecPtrToVecRawPtr(const std::vector< art::Ptr< T >> &xs) const
Definition: BackTracker.h:874
cheat::ParticleEffPur ClusterToParticle(const std::vector< const rb::Cluster * > &sliceList, const std::vector< const rb::CellHit * > &hits, const int &sliceIdx)
void hits()
Definition: readHits.C:15
cheat::ParticleEffPur cheat::BackTracker::ClusterToParticle ( const art::PtrVector< rb::Cluster > &  sliceList,
const art::PtrVector< rb::CellHit > &  hits,
const int sliceIdx 
)
inline

Definition at line 812 of file BackTracker.h.

815  {
816  return ClusterToParticle(PtrVecToVecRawPtr(sliceList),
817  PtrVecToVecRawPtr(hits),
818  sliceIdx);
819  }
std::vector< const T * > PtrVecToVecRawPtr(const art::PtrVector< T > &xs) const
Helper function for implementing overloads.
Definition: BackTracker.h:861
cheat::ParticleEffPur ClusterToParticle(const std::vector< const rb::Cluster * > &sliceList, const std::vector< const rb::CellHit * > &hits, const int &sliceIdx)
const double cheat::BackTracker::EnergyFromTrackId ( const art::Ptr< rb::CellHit > &  hit,
int  trackId,
bool  useBirksE = false 
) const

The total energy deposited in this cell by all FLSHits with this trackId.

Definition at line 389 of file BackTracker_service.cc.

References rb::CellHit::Cell(), energy, fCellToFLSHit, art::Ptr< T >::get(), HitToParticle(), it, and rb::CellHit::Plane().

390  {
391  auto it = fCellToFLSHit.find(geo::OfflineChan(hit->Plane(), hit->Cell()));
392  if(it == fCellToFLSHit.end()){
393  mf::LogWarning("BackTracker") << "No FLSHits in this cell";
394  return 0;
395  }
396 
397  const std::list<sim::FLSHit>& flshits = it->second;
398 
399  double energy = 0;
400 
401  for(const sim::FLSHit& fls: flshits){
402  if(fls.GetTrackID() == trackId){
403  energy += ((useBirksE) ? fls.GetEdepBirks() : fls.GetEdep());
404  }
405  } // end for flsIdx
406 
407  return energy;
408  }
set< int >::iterator it
unsigned short Plane() const
Definition: CellHit.h:39
A single unit of energy deposition in the liquid scintillator.
Definition: FLSHit.h:19
std::unordered_map< geo::OfflineChan, std::list< sim::FLSHit > > fCellToFLSHit
map of FLSHits in each cell in event
Definition: BackTracker.h:939
unsigned short Cell() const
Definition: CellHit.h:40
double energy
Definition: plottest35.C:25
A (plane, cell) pair.
Definition: OfflineChan.h:17
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
const std::set<int> cheat::BackTracker::GetTrackIDList ( ) const
inline

Get all G4 track ids present in the event.

These do not include ids from EM shower secondaries, tertiaries, etc as they are not saved as particles.

Definition at line 750 of file BackTracker.h.

Referenced by cheat::TestTrackIds::analyze(), remid::ReMIdValidate::analyze(), remid::ReMIdTrain::analyze(), cheat::CheckBackTracking::CheckPurityAndEfficiency(), cheat::RecoCheckAna::CheckRecoClusters(), trk::KalmanTrackAna::CheckRecoTracks(), and cheat::CheckBackTracking::CheckTrackIdToParticle().

750 { return fTrackIDs; }
std::set< int > fTrackIDs
G4 track ids for all particles in the events.
Definition: BackTracker.h:943
bool cheat::BackTracker::HaveTruthInfo ( ) const
inline

Is this a file with truth info in? (Is BackTracker going to be any use to you?)

True if we succeeded in retrieving FLSHits, ie in general for MC files. Expected false in data, and mock data etc.

Definition at line 133 of file BackTracker.h.

References getBrightness::cell, and NDAPDHVSetting::plane.

Referenced by qeef::QeFinderVal::analyze(), calhit::CalHitAna::analyze(), mcchk::CloseInTime::analyze(), mmc::Validation::analyze(), numue::NumuEAna::analyze(), calib::EnergyStandardCandles::analyze(), remid::ReMIdDedx::analyze(), trk::KalmanTrackAna::analyze(), cvn::CVNEventDump::analyze(), cvn::CVNCosmicEventDump::analyze(), mono::SlowMonopoleAna::analyze(), remid::ReMIdDedxRock::analyze(), mono::Monopole::analyze(), remid::ReMIdDedxFD::analyze(), remid::ReMIdDedxStudies::analyze(), CerenkovResponse::analyze(), htk::HoughTrack::analyze(), trk::CosmicTrackAna::analyze(), htk::HoughTrack::beginJob(), numue::NumuEAlg::checkIsMC(), calib::StopperThreshold::FillHist(), calib::StopperThreshold::FillTree(), trk::CosmicTrackAna::FillTrueInfo(), filter::Filter::FillTruthVariables(), nuesand::FillNueSandbox::FillTruthVars(), mono::EventSelector::filter(), mono::MonopoleCluster::filter(), bsf::BremShowerFilter::findShowerByTruth(), calib::EnergyStandardCandles::FindStoppingMuons(), numusand::NumuSandFxs::getMissingE(), cvn::HitClassify(), cvn::HitNuIndex(), cvn::HitObject(), caf::IsTrueDiF(), numue::NumuEAlg::MCTruthEnergyVariables(), mono::Monopole::n_mc_hits(), mmc::Validation::print_truth_info(), mono::SlowMonopoleAna::print_truth_info(), util::TruthExpand::produce(), numusand::FillSandbox::produce(), cosrej::CosRej::produce(), numue::NumuEnergy::produce(), calib::TimingCalibration::produce(), cvn::CVNAddTrainingData::produce(), murem::MuonRemove::produce(), and caf::CAFMaker::produce().

133 {return fHaveTruthInfo;}
bool fHaveTruthInfo
Set by Rebuild.
Definition: BackTracker.h:935
double cheat::BackTracker::HitCollectionEfficiency ( const std::set< int > &  trackIDs,
const std::vector< rb::WeightedHit > &  whits,
const std::vector< const rb::CellHit * > &  allhits,
const geo::View_t view,
std::map< int, double > *  effMap = 0,
bool  energyEff = false,
double *  desiredEnergy = 0,
double *  totalEnergy = 0,
int desiredHits = 0,
int totalHits = 0 
) const

Returns the fraction of all energy in an event from a specific set of Geant4 track IDs that are represented in a collection of weighted hits.

desiredHits and totalHits are also optional parameters that are the number of hits from the given set of trackIds in the given slice and the total number of hits from these trackId's in the detector respectively

Definition at line 808 of file BackTracker_service.cc.

Referenced by remid::ReMIdValidate::analyze(), numue::NumuEAna::analyze(), murem::MuonRemoveAna::analyze(), remid::ReMIdDedx::analyze(), remid::ReMIdDedxStudies::analyze(), fuzz::FuzzyKValidate::analyze(), slid::LIDTraining::analyze(), cheat::CheckBackTracking::CheckPurityAndEfficiency(), cheat::RecoCheckAna::CheckRecoClusters(), trk::KalmanTrackAna::CheckRecoTracks(), trk::CosmicTrackAna::FillTrueInfo(), cvn::Get2DProngEfficiencyByPDG(), cvn::GetProngEfficiencyByPDG(), HitCollectionEfficiency(), HitCollectionPurity(), murem::MuonRemove::RemoveByEfficiency(), SliceToMCTruth(), SliceToNeutrinoIndex(), SliceToNeutrinoInteractions(), and TracksToParticles().

818  {
819  const std::vector<RawWeightedHit> rwh(whits.begin(), whits.end());
820  return HitCollectionEfficiency(trackIDs, rwh, allhits, view,
821  effMap, energyEff, desiredEnergy, totalEnergy, desiredHits, totHits);
822  }
double HitCollectionEfficiency(const std::set< int > &trackIDs, const std::vector< rb::WeightedHit > &whits, const std::vector< const rb::CellHit * > &allhits, const geo::View_t &view, std::map< int, double > *effMap=0, bool energyEff=false, double *desiredEnergy=0, double *totalEnergy=0, int *desiredHits=0, int *totalHits=0) const
Returns the fraction of all energy in an event from a specific set of Geant4 track IDs that are repre...
double cheat::BackTracker::HitCollectionEfficiency ( const std::set< int > &  trackIDs,
const std::vector< rb::WeightedHit > &  whits,
const std::vector< rb::CellHit > &  allhits,
const geo::View_t view,
std::map< int, double > *  effMap = 0,
bool  energyEff = false,
double *  desiredEnergy = 0,
double *  totalEnergy = 0,
int desiredHits = 0,
int totalHits = 0 
) const
inline

Definition at line 337 of file BackTracker.h.

347  {
348  return HitCollectionEfficiency(trackIDs, whits, VecToVecRawPtr(allhits), view, effMap, energyEff, desiredEnergy, totalEnergy, desiredHits, totalHits);
349  }
double HitCollectionEfficiency(const std::set< int > &trackIDs, const std::vector< rb::WeightedHit > &whits, const std::vector< const rb::CellHit * > &allhits, const geo::View_t &view, std::map< int, double > *effMap=0, bool energyEff=false, double *desiredEnergy=0, double *totalEnergy=0, int *desiredHits=0, int *totalHits=0) const
Returns the fraction of all energy in an event from a specific set of Geant4 track IDs that are repre...
std::vector< const T * > VecToVecRawPtr(const std::vector< T > &xs) const
Definition: BackTracker.h:887
double cheat::BackTracker::HitCollectionEfficiency ( const std::set< int > &  trackIDs,
const std::vector< rb::WeightedHit > &  whits,
const std::vector< art::Ptr< rb::CellHit >> &  allhits,
const geo::View_t view,
std::map< int, double > *  effMap = 0,
bool  energyEff = false,
double *  desiredEnergy = 0,
double *  totalEnergy = 0,
int desiredHits = 0,
int totalHits = 0 
) const
inline

Definition at line 351 of file BackTracker.h.

361  {
362  return HitCollectionEfficiency(trackIDs, whits, VecPtrToVecRawPtr(allhits), view, effMap, energyEff, desiredEnergy, totalEnergy, desiredHits, totalHits);
363  }
std::vector< const T * > VecPtrToVecRawPtr(const std::vector< art::Ptr< T >> &xs) const
Definition: BackTracker.h:874
double HitCollectionEfficiency(const std::set< int > &trackIDs, const std::vector< rb::WeightedHit > &whits, const std::vector< const rb::CellHit * > &allhits, const geo::View_t &view, std::map< int, double > *effMap=0, bool energyEff=false, double *desiredEnergy=0, double *totalEnergy=0, int *desiredHits=0, int *totalHits=0) const
Returns the fraction of all energy in an event from a specific set of Geant4 track IDs that are repre...
double cheat::BackTracker::HitCollectionEfficiency ( const std::set< int > &  trackIDs,
const std::vector< rb::WeightedHit > &  whits,
const art::PtrVector< rb::CellHit > &  allhits,
const geo::View_t view,
std::map< int, double > *  effMap = 0,
bool  energyEff = false,
double *  desiredEnergy = 0,
double *  totalEnergy = 0,
int desiredHits = 0,
int totalHits = 0 
) const
inline

Definition at line 365 of file BackTracker.h.

375  {
376  return HitCollectionEfficiency(trackIDs, whits, PtrVecToVecRawPtr(allhits), view, effMap, energyEff, desiredEnergy, totalEnergy, desiredHits, totalHits);
377  }
std::vector< const T * > PtrVecToVecRawPtr(const art::PtrVector< T > &xs) const
Helper function for implementing overloads.
Definition: BackTracker.h:861
double HitCollectionEfficiency(const std::set< int > &trackIDs, const std::vector< rb::WeightedHit > &whits, const std::vector< const rb::CellHit * > &allhits, const geo::View_t &view, std::map< int, double > *effMap=0, bool energyEff=false, double *desiredEnergy=0, double *totalEnergy=0, int *desiredHits=0, int *totalHits=0) const
Returns the fraction of all energy in an event from a specific set of Geant4 track IDs that are repre...
double cheat::BackTracker::HitCollectionEfficiency ( const std::set< int > &  trackIDs,
const std::vector< const rb::CellHit * > &  hits,
const std::vector< const rb::CellHit * > &  allhits,
const geo::View_t view,
std::map< int, double > *  effMap = 0,
bool  energyEff = false,
double *  desiredEnergy = 0,
double *  totalEnergy = 0,
int desiredHits = 0,
int totalHits = 0 
) const

Returns the fraction of all hits in an event from a specific set of Geant4 track IDs that are represented in a collection of hits.

The optional effMap parameter returns the efficiencies for each of the track IDs individually.

The optional energyPur parameter allows the efficiency to be calculated based on FLS energy instead of number of hits desiredHits and totalHits are also optional parameters that are the number of hits from the given set of trackIds in the given slice and the total number of hits from these trackId's in the detector respectively

Definition at line 786 of file BackTracker_service.cc.

References demo3::h, and HitCollectionEfficiency().

796  {
797 
798  // convert cell hits to weighted hits with weight 1
799  std::vector<RawWeightedHit> wHits;
800  for(const rb::CellHit* h: hits) wHits.emplace_back(h, 1);
801 
802  return HitCollectionEfficiency(trackIDs, wHits, allhits, view,
803  effMap, energyEff, desiredEnergy,
804  totalEnergy, desiredHits, totHits);
805  }
double HitCollectionEfficiency(const std::set< int > &trackIDs, const std::vector< rb::WeightedHit > &whits, const std::vector< const rb::CellHit * > &allhits, const geo::View_t &view, std::map< int, double > *effMap=0, bool energyEff=false, double *desiredEnergy=0, double *totalEnergy=0, int *desiredHits=0, int *totalHits=0) const
Returns the fraction of all energy in an event from a specific set of Geant4 track IDs that are repre...
void hits()
Definition: readHits.C:15
A rawdata::RawDigit with channel information decoded.
Definition: CellHit.h:27
h
Definition: demo3.py:41
double cheat::BackTracker::HitCollectionEfficiency ( const std::set< int > &  trackIDs,
const std::vector< rb::CellHit > &  hits,
const std::vector< rb::CellHit > &  allhits,
const geo::View_t view,
std::map< int, double > *  effMap = 0,
bool  energyEff = false,
double *  desiredEnergy = 0,
double *  totalEnergy = 0,
int desiredHits = 0,
int totalHits = 0 
) const
inline

Definition at line 401 of file BackTracker.h.

411  {
412  return HitCollectionEfficiency(trackIDs,
414  VecToVecRawPtr(allhits),
415  view,
416  effMap, energyEff, desiredEnergy,
417  totalEnergy, desiredHits, totalHits);
418  }
double HitCollectionEfficiency(const std::set< int > &trackIDs, const std::vector< rb::WeightedHit > &whits, const std::vector< const rb::CellHit * > &allhits, const geo::View_t &view, std::map< int, double > *effMap=0, bool energyEff=false, double *desiredEnergy=0, double *totalEnergy=0, int *desiredHits=0, int *totalHits=0) const
Returns the fraction of all energy in an event from a specific set of Geant4 track IDs that are repre...
void hits()
Definition: readHits.C:15
std::vector< const T * > VecToVecRawPtr(const std::vector< T > &xs) const
Definition: BackTracker.h:887
double cheat::BackTracker::HitCollectionEfficiency ( const std::set< int > &  trackIDs,
const std::vector< art::Ptr< rb::CellHit >> &  hits,
const std::vector< art::Ptr< rb::CellHit >> &  allhits,
const geo::View_t view,
std::map< int, double > *  effMap = 0,
bool  energyEff = false,
double *  desiredEnergy = 0,
double *  totalEnergy = 0,
int desiredHits = 0,
int totalHits = 0 
) const
inline

Definition at line 420 of file BackTracker.h.

430  {
431  return HitCollectionEfficiency(trackIDs,
433  VecPtrToVecRawPtr(allhits),
434  view,
435  effMap, energyEff, desiredEnergy,
436  totalEnergy, desiredHits, totalHits);
437  }
std::vector< const T * > VecPtrToVecRawPtr(const std::vector< art::Ptr< T >> &xs) const
Definition: BackTracker.h:874
double HitCollectionEfficiency(const std::set< int > &trackIDs, const std::vector< rb::WeightedHit > &whits, const std::vector< const rb::CellHit * > &allhits, const geo::View_t &view, std::map< int, double > *effMap=0, bool energyEff=false, double *desiredEnergy=0, double *totalEnergy=0, int *desiredHits=0, int *totalHits=0) const
Returns the fraction of all energy in an event from a specific set of Geant4 track IDs that are repre...
void hits()
Definition: readHits.C:15
double cheat::BackTracker::HitCollectionEfficiency ( std::set< int trackIDs,
const art::PtrVector< rb::CellHit > &  hits,
const art::PtrVector< rb::CellHit > &  allhits,
const geo::View_t view,
std::map< int, double > *  effMap = 0,
bool  energyEff = false,
double *  desiredEnergy = 0,
double *  totalEnergy = 0,
int desiredHits = 0,
int totalHits = 0 
) const
inline

Definition at line 439 of file BackTracker.h.

References a, and b.

449  {
450  return HitCollectionEfficiency(trackIDs,
451  PtrVecToVecRawPtr(hits),
452  PtrVecToVecRawPtr(allhits),
453  view,
454  effMap, energyEff, desiredEnergy,
455  totalEnergy, desiredHits, totalHits);
456  }
std::vector< const T * > PtrVecToVecRawPtr(const art::PtrVector< T > &xs) const
Helper function for implementing overloads.
Definition: BackTracker.h:861
double HitCollectionEfficiency(const std::set< int > &trackIDs, const std::vector< rb::WeightedHit > &whits, const std::vector< const rb::CellHit * > &allhits, const geo::View_t &view, std::map< int, double > *effMap=0, bool energyEff=false, double *desiredEnergy=0, double *totalEnergy=0, int *desiredHits=0, int *totalHits=0) const
Returns the fraction of all energy in an event from a specific set of Geant4 track IDs that are repre...
double cheat::BackTracker::HitCollectionEfficiency ( const std::set< int > &  trackIDs,
const std::vector< RawWeightedHit > &  whits,
const std::vector< const rb::CellHit * > &  allhits,
const geo::View_t view,
std::map< int, double > *  effMap = 0,
bool  energyEff = false,
double *  desiredEnergy = 0,
double *  totalEnergy = 0,
int desiredHits = 0,
int totalHits = 0 
) const
private

Internal implementation of public HitCollectionEfficiency.

Definition at line 826 of file BackTracker_service.cc.

References cheat::BackTracker::Params::DoHitsCheck, efficiency(), fParams, demo3::h, HitToTrackIDE(), MECModelEnuComparisons::i, makeTrainCVSamples::int, IsNoise(), it, geo::kXorY, cheat::BackTracker::Params::MinContribFrac, getGoodRuns4SAM::n, plotSysts::t, produceInfoGainMatrix::total, rb::CellHit::View(), and plotSysts::weight.

837  {
838 
839  // allhits should be a superset of hits
840  assert(allhits.size() >= whits.size());
841 
842  // to check it's a superset more thoroughly, optional
843  if(fParams.DoHitsCheck()){
844  for(unsigned int n = 0; n < whits.size(); ++n){
845  // TODO: should be checking actual equality not the pointers
846  // assert(std::find(allhits.begin(), allhits.end(), whits[n].hit) != allhits.end());
847  }
848  }
849  std::vector<const rb::CellHit*> hits_copy;
850  for(int i = 0; i < (int)whits.size(); i++)
851  hits_copy.push_back(whits[i].hit);
852 
853  // Check for duplicates
854  std::sort(hits_copy.begin(), hits_copy.end());
855  for(unsigned int n = 0; n+1 < hits_copy.size(); ++n)
856  assert(hits_copy[n] < hits_copy[n+1]);
857 
858  // get the list of EveIDs that correspond to the hits in this collection
859  // and the energy associated with the desired trackID
860 
861  double desired = 0.;
862  double total = 0.;
863 
864  double desiredE = 0.;
865  double totalE = 0.;
866 
867  if(effMap) effMap->clear();
868  std::map<int, double> totMap;
869 
870  for(size_t h = 0; h < whits.size(); ++h){
871 
872  double totalEInCell = 0.;
873  double desiredEInCell = 0.;
874 
875  const rb::CellHit* hit = whits[h].hit;
876  double weight = whits[h].weight;
877  assert( weight <= 1);
878 
879  if(IsNoise(*hit)) continue;
880 
881  bool hitCounted = false;
882 
883  std::vector<TrackIDE> tracks = HitToTrackIDE(*hit);
884 
885  assert(hit->View() == view || view == geo::kXorY);
886 
887  // don't double count if this hit has more than one of the
888  // desired track IDs associated with it
889  for(size_t t = 0; t < tracks.size(); ++t){
890  totalEInCell += tracks[t].energy;
891  if(trackIDs.find(tracks[t].trackID) != trackIDs.end() ){
892  desiredEInCell += tracks[t].energy;
893  if(tracks[t].energyFrac >= fParams.MinContribFrac()){
894  if(!hitCounted){
895  desired += 1.;
896  hitCounted = true;
897  }
898  if(effMap) ++(*effMap)[tracks[t].trackID];
899  }
900  }
901  }// end loop over track IDEs
902 
903  if( (weight*totalEInCell) >= desiredEInCell)
904  desiredE += desiredEInCell;
905  else
906  desiredE += (weight*totalEInCell);
907 
908  }// end loop over hits
909 
910  // now figure out how many hits in the whole collection are associated with this id
911  for(size_t h = 0; h < allhits.size(); ++h){
912  const rb::CellHit* hit = allhits[h];
913  if(IsNoise(*hit)) continue;
914 
915  std::vector<TrackIDE> tracks = HitToTrackIDE(*hit);
916 
917  bool hitCounted = false;
918 
919  // check that we are looking at the appropriate view here
920  // in the case of 3D objects we take all hits
921  if(hit->View() != view && view != geo::kXorY) continue;
922 
923  for(size_t t = 0; t < tracks.size(); ++t){
924  // don't worry about hits where the energy fraction for the chosen
925  // trackID is < MinContribFrac
926  // also don't double count if this hit has more than one of the
927  // desired track IDs associated with it
928  if(trackIDs.find(tracks[t].trackID) != trackIDs.end()){
929  totalE += tracks[t].energy;
930  if(tracks[t].energyFrac >= fParams.MinContribFrac()){
931  if(!hitCounted){
932  total += 1.;
933  hitCounted = true;
934  }
935  if(effMap) ++totMap[tracks[t].trackID];
936  }// end if energy fraction is above threshold
937  }// end if the current track ID is in the list of ones to check
938  }// end loop over tracks
939  }// end loop over all hits
940 
941  double efficiency = 0.;
942  if((total > 0.) && !energyEff) efficiency = desired/total;
943  if((totalE > 0.) && energyEff) efficiency = desiredE/totalE;
944 
945  if((total > 0.) && desiredHits ) *desiredHits = desired;
946  if((total > 0.) && totHits ) *totHits = total;
947  if((totalE > 0.) && desiredEnergy) *desiredEnergy = desiredE;
948  if((totalE > 0.) && totalEnergy ) *totalEnergy = totalE;
949 
950  if(effMap){
951  for(std::map<int, double>::iterator it = effMap->begin(); it != effMap->end(); ++it){
952  if(totMap[it->first] > 0)
953  it->second /= totMap[it->first];
954  // This is an efficiency. It should be between 0-100%
955  assert(it->second >= 0);
956  assert(it->second <= 1);
957  }
958  }
959 
960  return efficiency;
961  }
set< int >::iterator it
std::vector< TrackIDE > HitToTrackIDE(const rb::CellHit &hit, bool useBirksE=false) const
Convenience function. HitsToTrackIDE but for a single hit.
X or Y views.
Definition: PlaneGeo.h:30
geo::View_t View() const
Definition: CellHit.h:41
float weight
Definition: plotSysts.py:333
bool IsNoise(const art::Ptr< rb::CellHit > &hit) const
Is this hit not associated with any particles?
void efficiency()
Definition: efficiency.C:57
A rawdata::RawDigit with channel information decoded.
Definition: CellHit.h:27
Definition: event.h:1
Atom< double > MinContribFrac
Definition: BackTracker.h:105
h
Definition: demo3.py:41
double cheat::BackTracker::HitCollectionPurity ( const std::set< int > &  trackIDs,
const std::vector< rb::WeightedHit > &  whits,
std::map< int, double > *  purMap = 0,
std::map< int, int > *  parents = 0,
bool  energyPur = false 
) const

Returns the fraction of hits in a collection that come from the specified Geant4 track ids.

Definition at line 655 of file BackTracker_service.cc.

Referenced by numue::NumuEAna::analyze(), murem::MuonRemoveAna::analyze(), remid::ReMIdDedx::analyze(), fuzz::FuzzyKValidate::analyze(), remid::ReMIdDedxStudies::analyze(), slid::LIDTraining::analyze(), cheat::CheckBackTracking::CheckPurityAndEfficiency(), cheat::RecoCheckAna::CheckRecoClusters(), trk::KalmanTrackAna::CheckRecoTracks(), trk::CosmicTrackAna::FillTrueInfo(), cvn::Get2DProngPurityByPDG(), cvn::GetProngPurityByPDG(), cvn::HitClassify(), HitCollectionPurity(), cvn::HitObject(), HitToXYZ(), cvn::ProngClassify(), SliceToMCTruth(), SliceToNeutrinoIndex(), SliceToNeutrinoInteractions(), and TracksToParticles().

660  {
661  const std::vector<RawWeightedHit> rwh(whits.begin(), whits.end());
662  return HitCollectionPurity(trackIDs, rwh, purMap, parents, energyPur);
663  }
double HitCollectionPurity(const std::set< int > &trackIDs, const std::vector< rb::WeightedHit > &whits, std::map< int, double > *purMap=0, std::map< int, int > *parents=0, bool energyPur=false) const
Returns the fraction of hits in a collection that come from the specified Geant4 track ids...
double cheat::BackTracker::HitCollectionPurity ( const std::set< int > &  trackIDs,
const std::vector< const rb::CellHit * > &  hits,
std::map< int, double > *  purMap = 0,
std::map< int, int > *  parents = 0,
bool  energyPur = false 
) const

Returns the fraction of hits in a collection that come from the specified Geant4 track ids.

The optional purMap parameter returns the purities for each of the track IDs individually.

The optional parents parameter maps particle IDs to the IDs they

The optional energyPur parameter allows the purity to be calculated based on FLS energy instead of number of hits

Definition at line 770 of file BackTracker_service.cc.

References demo3::h, HitCollectionEfficiency(), and HitCollectionPurity().

775  {
776  // convert all cell hits to weighted hits with weight 1.
777  std::vector<RawWeightedHit> wHits;
778  for(const rb::CellHit* h: hits) wHits.emplace_back(h, 1);
779 
780  return HitCollectionPurity(trackIDs, wHits, purMap, parents, energyPur);
781 
782  }
void hits()
Definition: readHits.C:15
double HitCollectionPurity(const std::set< int > &trackIDs, const std::vector< rb::WeightedHit > &whits, std::map< int, double > *purMap=0, std::map< int, int > *parents=0, bool energyPur=false) const
Returns the fraction of hits in a collection that come from the specified Geant4 track ids...
A rawdata::RawDigit with channel information decoded.
Definition: CellHit.h:27
h
Definition: demo3.py:41
double cheat::BackTracker::HitCollectionPurity ( const std::set< int > &  trackIDs,
const std::vector< rb::CellHit > &  hits,
std::map< int, double > *  purMap = 0,
std::map< int, int > *  parents = 0,
bool  energyPur = false 
) const
inline

Definition at line 293 of file BackTracker.h.

298  {
299  return HitCollectionPurity(trackIDs, VecToVecRawPtr(hits), purMap, parents, energyPur);
300  }
void hits()
Definition: readHits.C:15
double HitCollectionPurity(const std::set< int > &trackIDs, const std::vector< rb::WeightedHit > &whits, std::map< int, double > *purMap=0, std::map< int, int > *parents=0, bool energyPur=false) const
Returns the fraction of hits in a collection that come from the specified Geant4 track ids...
std::vector< const T * > VecToVecRawPtr(const std::vector< T > &xs) const
Definition: BackTracker.h:887
double cheat::BackTracker::HitCollectionPurity ( const std::set< int > &  trackIDs,
const std::vector< art::Ptr< rb::CellHit >> &  hits,
std::map< int, double > *  purMap = 0,
std::map< int, int > *  parents = 0,
bool  energyPur = false 
) const
inline

Definition at line 302 of file BackTracker.h.

307  {
308  return HitCollectionPurity(trackIDs, VecPtrToVecRawPtr(hits), purMap, parents, energyPur);
309  }
std::vector< const T * > VecPtrToVecRawPtr(const std::vector< art::Ptr< T >> &xs) const
Definition: BackTracker.h:874
void hits()
Definition: readHits.C:15
double HitCollectionPurity(const std::set< int > &trackIDs, const std::vector< rb::WeightedHit > &whits, std::map< int, double > *purMap=0, std::map< int, int > *parents=0, bool energyPur=false) const
Returns the fraction of hits in a collection that come from the specified Geant4 track ids...
double cheat::BackTracker::HitCollectionPurity ( const std::set< int > &  trackIDs,
const art::PtrVector< rb::CellHit > &  hits,
std::map< int, double > *  purMap = 0,
std::map< int, int > *  parents = 0,
bool  energyPur = false 
) const
inline

Definition at line 311 of file BackTracker.h.

References POTSpillRate::view.

316  {
317  return HitCollectionPurity(trackIDs, PtrVecToVecRawPtr(hits), purMap, parents, energyPur);
318  }
std::vector< const T * > PtrVecToVecRawPtr(const art::PtrVector< T > &xs) const
Helper function for implementing overloads.
Definition: BackTracker.h:861
double HitCollectionPurity(const std::set< int > &trackIDs, const std::vector< rb::WeightedHit > &whits, std::map< int, double > *purMap=0, std::map< int, int > *parents=0, bool energyPur=false) const
Returns the fraction of hits in a collection that come from the specified Geant4 track ids...
double cheat::BackTracker::HitCollectionPurity ( const std::set< int > &  trackIDs,
const std::vector< RawWeightedHit > &  whits,
std::map< int, double > *  purMap = 0,
std::map< int, int > *  parents = 0,
bool  energyPur = false 
) const
private

Internal implementation of public HitCollectionPurity.

Definition at line 667 of file BackTracker_service.cc.

References demo3::h, HitCollectionPurity(), HitToTrackIDE(), IsNoise(), it, plotConfusion::purity(), plotSysts::t, produceInfoGainMatrix::total, trackID, and plotSysts::weight.

673  {
674  // get the list of EveIDs that correspond to the hits in this collection
675  // if the EveID shows up in the input list of trackIDs, then it counts
676  double total = whits.size();
677  double desired = 0;
678 
679  double desiredE = 0;
680  double totalE = 0;
681 
682  if(purMap) purMap->clear();
683 
684  for(size_t h = 0; h < whits.size(); ++h){
685 
686  double totalEInCell = 0;
687  double desiredEInCell = 0;
688 
689  const rb::CellHit* hit = whits[h].hit;
690  double weight = whits[h].weight;
691 
692  assert( weight <= 1);
693 
694  if(IsNoise(*hit)) continue;
695 
696  std::vector<TrackIDE> tracks = HitToTrackIDE(*hit);
697 
698  // The set of trackIDs (or parents) that contributed to this hit
699  std::set<int> tally;
700 
701  for(size_t t = 0; t < tracks.size(); ++t){
702  const int trackID = tracks[t].trackID;
703  if(trackIDs.find(trackID) != trackIDs.end()){
704  tally.insert(trackID);
705  }
706  if(parents){
707  std::map<int, int>::iterator parentsIt = parents->find(trackID);
708  if(parentsIt != parents->end()){
709  tally.insert(parentsIt->second);
710  }
711  }
712  } // end for t
713 
714 
715  if (energyPur){
716  for(size_t t = 0; t < tracks.size(); ++t){
717  totalEInCell += tracks[t].energy * weight;
718  if(trackIDs.find(tracks[t].trackID) != trackIDs.end()){
719  desiredE += tracks[t].energy;
720  desiredEInCell += tracks[t].energy;
721  }
722  }
723  }//End of loop for counting energy when doing purity based on FLS hits
724 
725  // Purity in a cell can sometimes be greater than one if the weight of
726  // a hit is less than the fraction of energy from desired track IDs
727  // in that cell.
728  if( desiredEInCell >= totalEInCell )
729  totalE += desiredEInCell;
730  else
731  totalE += totalEInCell;
732 
733  if(purMap){
734  for(std::set<int>::iterator it = tally.begin(); it != tally.end(); ++it){
735  ++(*purMap)[*it];
736  }
737  }
738 
739  if(!tally.empty()) ++desired;
740 
741 
742  }// end loop over whits
743 
744  double purity = 0.;
745 
746  if((total > 0) && !energyPur) purity = desired/total;
747  if((totalE > 0) && energyPur) purity = desiredE/totalE;
748 
749  assert(purity >= 0);
750  assert(purity <= 1);
751 
752  if(total > 0 && purMap){
753  for(std::map<int, double>::iterator it = purMap->begin(); it != purMap->end(); ++it){
754  it->second /= total;
755  // This is a purity, it should be between 0-100%
756  assert(it->second >= 0);
757  assert(it->second <= 1);
758  }
759  }
760 
761  return purity;
762 
763  }
set< int >::iterator it
std::vector< TrackIDE > HitToTrackIDE(const rb::CellHit &hit, bool useBirksE=false) const
Convenience function. HitsToTrackIDE but for a single hit.
float weight
Definition: plotSysts.py:333
bool IsNoise(const art::Ptr< rb::CellHit > &hit) const
Is this hit not associated with any particles?
A rawdata::RawDigit with channel information decoded.
Definition: CellHit.h:27
Definition: event.h:1
Int_t trackID
Definition: plot.C:84
h
Definition: demo3.py:41
std::vector< const sim::Particle * > cheat::BackTracker::HitsToParticle ( const std::vector< const rb::CellHit * > &  hits) const

Returns vector of sim::Particle objects contributing to the given collection of hits.

Orders the returned vector with the particle contributing the most light in the collection first.

Definition at line 542 of file BackTracker_service.cc.

References AccumulateHitContributions(), demo3::h, HitsToTrackIDE(), it, make_pair(), getGoodRuns4SAM::n, part, runNovaSAM::ret, moon_position_table_new3::second, and TrackIDToParticle().

Referenced by calib::TestParticleCorrections::analyze(), remid::ReMIdDedx::analyze(), slicer::SlicerAna::analyze(), remid::ReMIdDedxRock::analyze(), remid::ReMIdDedxFD::analyze(), remid::ReMIdDedxStudies::analyze(), bpfit::BPFTmvaTrainer::analyze(), bpfit::BreakPointProtonAna::analyze(), calib::StopperThreshold::FillHist(), calib::CosmicTrends::FillHistograms(), calib::StopperThreshold::FillTree(), trk::CosmicTrackAna::FillTrueInfo(), numusand::NumuSandFxs::getMissingE(), caf::IsTrueDiF(), calib::RockMuonStopperSelection::IsTrulyContainedStopper(), calib::StopperSelection::IsTrulyContainedStopper(), calib::RockMuonStopperSelection::IsTrulyInFiducial(), calib::ThroughgoingSelection::IsTrulyUncontained(), skim::EvaluatorNumuCCpi::KeepSlice(), MCTruthToParticles(), util::TruthExpand::produce(), numusand::FillSandbox::produce(), and cosrej::CosRej::produce().

543  {
544  std::map<int, int> idToNPhot;
545  for(size_t h = 0; h < hits.size(); ++h){
546  AccumulateHitContributions(*hits[h], idToNPhot);
547  }
548 
549  // Now "all" we need to do is sort by number of photons, and discard any IDs
550  // that we can't find particles for. This turns out to be a bit fiddly.
551 
552  std::vector<std::pair<int, int> > nphotToId;
553  for(std::map<int, int>::iterator it = idToNPhot.begin(); it != idToNPhot.end(); ++it){
554  nphotToId.push_back(std::make_pair(it->second, it->first));
555  }
556 
557  // Sort in reverse order (ie increasing number of photons).
558  // Tuples compare by first element first, so this works
559  std::sort(nphotToId.rbegin(), nphotToId.rend());
560 
561  std::vector<const sim::Particle*> ret;
562  for(unsigned int n = 0; n < nphotToId.size(); ++n){
563  const sim::Particle* part = TrackIDToParticle(nphotToId[n].second);
564  if(part) ret.push_back(part);
565  }
566 
567  return ret;
568  }
set< int >::iterator it
std::pair< Spectrum *, CheatDecomp * > make_pair(SpectrumLoaderBase &loader_data, SpectrumLoaderBase &loader_mc, HistAxis *axis, Cut *cut, const SystShifts &shift, const Var &wei)
Definition: DataMCLoad.C:335
void AccumulateHitContributions(rb::CellHit const &hit, std::map< int, int > &idToNPhot) const
Internal helper, adds the contributions from each particle in this cell to the map.
TString part[npart]
Definition: Style.C:32
void hits()
Definition: readHits.C:15
const sim::Particle * TrackIDToParticle(int const &id) const
Returns a pointer to the sim::Particle object corresponding to the given TrackID. ...
h
Definition: demo3.py:41
std::vector<const sim::Particle*> cheat::BackTracker::HitsToParticle ( const std::vector< rb::CellHit > &  hits) const
inline

Definition at line 228 of file BackTracker.h.

229  {
231  }
void hits()
Definition: readHits.C:15
std::vector< const T * > VecToVecRawPtr(const std::vector< T > &xs) const
Definition: BackTracker.h:887
std::vector< const sim::Particle * > HitsToParticle(const std::vector< const rb::CellHit * > &hits) const
Returns vector of sim::Particle objects contributing to the given collection of hits.
std::vector<const sim::Particle*> cheat::BackTracker::HitsToParticle ( const std::vector< art::Ptr< rb::CellHit >> &  hits) const
inline

Definition at line 232 of file BackTracker.h.

233  {
235  }
std::vector< const T * > VecPtrToVecRawPtr(const std::vector< art::Ptr< T >> &xs) const
Definition: BackTracker.h:874
void hits()
Definition: readHits.C:15
std::vector< const sim::Particle * > HitsToParticle(const std::vector< const rb::CellHit * > &hits) const
Returns vector of sim::Particle objects contributing to the given collection of hits.
std::vector<const sim::Particle*> cheat::BackTracker::HitsToParticle ( const art::PtrVector< rb::CellHit > &  hits) const
inline

Definition at line 236 of file BackTracker.h.

237  {
238  return HitsToParticle(PtrVecToVecRawPtr(hits));
239  }
std::vector< const T * > PtrVecToVecRawPtr(const art::PtrVector< T > &xs) const
Helper function for implementing overloads.
Definition: BackTracker.h:861
std::vector< const sim::Particle * > HitsToParticle(const std::vector< const rb::CellHit * > &hits) const
Returns vector of sim::Particle objects contributing to the given collection of hits.
std::vector< TrackIDE > cheat::BackTracker::HitsToTrackIDE ( const std::vector< const rb::CellHit * > &  hits,
bool  useBirksE = false 
) const

Returns vector of TrackIDE structs contributing to the given collection of hits.

Orders the returned vector with the trackID contributing the most energy in the collection first.

Definition at line 574 of file BackTracker_service.cc.

References cheat::CompareByEnergy(), cheat::TrackIDE::energy, cheat::TrackIDE::energyFrac, MakeMiniprodValidationCuts::f, demo3::h, HitToFLSHit(), HitToTrackIDE(), it, and cheat::TrackIDE::trackID.

Referenced by fuzz::FuzzyKValidate::analyze(), slid::LIDTraining::analyze(), calib::EnergyStandardCandles::FindStoppingMuons(), cvn::Get2DProngEfficiencyByPDG(), cvn::Get2DProngEnergyByPDG(), cvn::Get2DProngPurityByPDG(), cvn::GetProngEfficiencyByPDG(), cvn::GetProngEnergyByPDG(), cvn::GetProngPurityByPDG(), HitsToParticle(), HitToTrackIDE(), numusand::FillSandbox::produce(), cosrej::CosRej::produce(), caf::CAFMaker::produce(), and cvn::ProngClassify().

575  {
576 
577  std::map<int, double> sigtracks;
578 
579  double totalE = 0;
580  for(size_t h = 0; h < hits.size(); ++h){
581  const std::vector<sim::FLSHit> fls = HitToFLSHit(*hits[h]);
582  for(size_t f = 0; f < fls.size(); ++f){
583  if( useBirksE){
584  sigtracks[fls[f].GetTrackID()] += fls[f].GetEdepBirks();
585  totalE += fls[f].GetEdepBirks();
586  }
587  else{
588  sigtracks[fls[f].GetTrackID()] += fls[f].GetEdep();
589  totalE += fls[f].GetEdep();
590  }
591  }
592  } // end for h
593 
594  // Make trackIDE objects from our collected energies
595  std::vector<TrackIDE> trackIDE;
596  for(std::map<int, double>::iterator it = sigtracks.begin(); it != sigtracks.end(); ++it){
597  TrackIDE ide;
598  ide.trackID = it->first;
599  ide.energy = it->second;
600  ide.energyFrac = it->second/totalE;
601  trackIDE.push_back(ide);
602  }
603 
604  // Sort TrackIDE objects from most energy contributed to least
605  std::sort(trackIDE.rbegin(), trackIDE.rend(), CompareByEnergy);
606 
607  return trackIDE;
608  }
set< int >::iterator it
void hits()
Definition: readHits.C:15
std::vector< sim::FLSHit > HitToFLSHit(const rb::CellHit &hit) const
All the FLSHits that contributed to this hit, sorted from most to least light.
bool CompareByEnergy(const TrackIDE &a, const TrackIDE &b)
Does a have less energy than b?
h
Definition: demo3.py:41
std::vector<TrackIDE> cheat::BackTracker::HitsToTrackIDE ( const std::vector< rb::CellHit > &  hits,
bool  useBirksE = false 
) const
inline

Definition at line 248 of file BackTracker.h.

249  {
250  return HitsToTrackIDE(VecToVecRawPtr(hits), useBirksE);
251  }
void hits()
Definition: readHits.C:15
std::vector< TrackIDE > HitsToTrackIDE(const std::vector< const rb::CellHit * > &hits, bool useBirksE=false) const
Returns vector of TrackIDE structs contributing to the given collection of hits.
std::vector< const T * > VecToVecRawPtr(const std::vector< T > &xs) const
Definition: BackTracker.h:887
std::vector<TrackIDE> cheat::BackTracker::HitsToTrackIDE ( const std::vector< art::Ptr< rb::CellHit >> &  hits,
bool  useBirksE = false 
) const
inline

Definition at line 253 of file BackTracker.h.

254  {
255  return HitsToTrackIDE(VecPtrToVecRawPtr(hits), useBirksE);
256  }
std::vector< const T * > VecPtrToVecRawPtr(const std::vector< art::Ptr< T >> &xs) const
Definition: BackTracker.h:874
void hits()
Definition: readHits.C:15
std::vector< TrackIDE > HitsToTrackIDE(const std::vector< const rb::CellHit * > &hits, bool useBirksE=false) const
Returns vector of TrackIDE structs contributing to the given collection of hits.
std::vector<TrackIDE> cheat::BackTracker::HitsToTrackIDE ( const art::PtrVector< rb::CellHit > &  hits,
bool  useBirksE = false 
) const
inline

Definition at line 258 of file BackTracker.h.

259  {
260  return HitsToTrackIDE(PtrVecToVecRawPtr(hits), useBirksE);
261  }
std::vector< const T * > PtrVecToVecRawPtr(const art::PtrVector< T > &xs) const
Helper function for implementing overloads.
Definition: BackTracker.h:861
std::vector< TrackIDE > HitsToTrackIDE(const std::vector< const rb::CellHit * > &hits, bool useBirksE=false) const
Returns vector of TrackIDE structs contributing to the given collection of hits.
std::vector< sim::FLSHit > cheat::BackTracker::HitToFLSHit ( const rb::CellHit hit) const

All the FLSHits that contributed to this hit, sorted from most to least light.

Definition at line 342 of file BackTracker_service.cc.

References AccumulateHitContributions(), rb::CellHit::Cell(), fCellToFLSHit, it, LOG_DEBUG, make_pair(), rb::CellHit::Plane(), and runNovaSAM::ret.

Referenced by calhit::CalHitAna::analyze(), ddt::SMMADC::analyze(), calib::TestParticleCorrections::analyze(), calib::AssessCalib::analyze(), showere::ShowerEnergyAna::analyze(), remid::ReMIdDedxRock::analyze(), remid::ReMIdDedxStudies::analyze(), mono::Monopole::analyze(), fuzz::FuzzyKValidate::analyze(), remid::ReMIdDedxFD::analyze(), CerenkovResponse::analyze(), slid::LIDTraining::analyze(), cheat::CheckBackTracking::CheckFLSHitConsistency(), mono::SlowMonopoleAna::fill_hit_tree(), caf::FillParticleTruth(), calhit::CalHitAna::FillTruthInfo(), showere::ShowerEnergyFilterMC::filter(), HitsToTrackIDE(), and HitToXYZ().

343  {
344  std::map<int, int> idToNPhot;
345  AccumulateHitContributions(hit, idToNPhot);
346 
347  // Next, sort by number of photons. This turns out to be a bit fiddly.
348 
349  std::vector<std::pair<int, int> > nphotToId;
350  nphotToId.reserve(idToNPhot.size());
351  for(std::map<int, int>::iterator it = idToNPhot.begin(); it != idToNPhot.end(); ++it){
352  nphotToId.push_back(std::make_pair(it->second, it->first));
353  }
354 
355  if(nphotToId.empty()){
356  LOG_DEBUG("BackTracker") << "No matching photons, this is probably a noise hit. Returning empty vector";
357  return std::vector<sim::FLSHit>();
358  }
359 
360  // Sort in reverse order (ie decreasing number of photons).
361  // Tuples compare by first element first, so this works
362  std::sort(nphotToId.rbegin(), nphotToId.rend());
363 
364  auto it = fCellToFLSHit.find(geo::OfflineChan(hit.Plane(), hit.Cell()));
365  if ( it == fCellToFLSHit.end() ) {
366  throw cet::exception("BackTracker")
367  << "PhotonSignal with no matching FLSHit. That shouldn't be possible\n"
368  << __FILE__ << ":" << __LINE__ << "\n";
369  }
370 
371  std::vector<sim::FLSHit> ret;
372  const std::list<sim::FLSHit>& flshits = it->second;
373 
374  ret.reserve(nphotToId.size()*flshits.size()); // Overestimate
375 
376  for(unsigned int idIdx = 0; idIdx < nphotToId.size(); ++idIdx){
377  const int trackid = nphotToId[idIdx].second;
378  for(const sim::FLSHit& fls: flshits){
379  if(fls.GetTrackID() == trackid){
380  ret.push_back(fls);
381  }
382  } // end for flsIdx
383  } // end for idIdx
384 
385  return ret;
386  }
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
set< int >::iterator it
unsigned short Plane() const
Definition: CellHit.h:39
::xsd::cxx::tree::exception< char > exception
Definition: Database.h:225
A single unit of energy deposition in the liquid scintillator.
Definition: FLSHit.h:19
std::pair< Spectrum *, CheatDecomp * > make_pair(SpectrumLoaderBase &loader_data, SpectrumLoaderBase &loader_mc, HistAxis *axis, Cut *cut, const SystShifts &shift, const Var &wei)
Definition: DataMCLoad.C:335
void AccumulateHitContributions(rb::CellHit const &hit, std::map< int, int > &idToNPhot) const
Internal helper, adds the contributions from each particle in this cell to the map.
std::unordered_map< geo::OfflineChan, std::list< sim::FLSHit > > fCellToFLSHit
map of FLSHits in each cell in event
Definition: BackTracker.h:939
unsigned short Cell() const
Definition: CellHit.h:40
A (plane, cell) pair.
Definition: OfflineChan.h:17
std::vector<sim::FLSHit> cheat::BackTracker::HitToFLSHit ( const art::Ptr< rb::CellHit > &  hit) const
inline

Definition at line 166 of file BackTracker.h.

References hits(), make_root_from_grid_output::pdg, and cheat::TrackIDE::trackID.

167  {
168  return HitToFLSHit(*hit);
169  }
std::vector< sim::FLSHit > HitToFLSHit(const rb::CellHit &hit) const
All the FLSHits that contributed to this hit, sorted from most to least light.
const sim::Particle* cheat::BackTracker::HitToParticle ( art::Ptr< rb::CellHit > const &  hit,
bool  quiet = false 
) const
const sim::Particle * cheat::BackTracker::HitToParticle ( const rb::CellHit hit,
bool  quiet = false 
) const

Returns the sim::Particle object contributing the most light to the specified rb::CellHit.

Definition at line 419 of file BackTracker_service.cc.

References AccumulateHitContributions(), it, and TrackIDToParticle().

421  {
422  std::map<int, int> idToNPhot;
423  AccumulateHitContributions(hit, idToNPhot);
424 
425  // Go through the map and find the particle ID that contributed the most light
426  int bestId = -1;
427  int mostPhot = -1;
428  for(std::map<int, int>::iterator it = idToNPhot.begin(); it != idToNPhot.end(); ++it){
429  if(it->second > mostPhot){
430  mostPhot = it->second;
431  bestId = it->first;
432  }
433  }
434 
435  if(bestId == -1){
436  if(!quiet){
437  mf::LogWarning("BackTracker") << "No photons in this cell are in time with the hit. "
438  << "Returning null pointer";
439  }
440  return 0;
441  }
442 
443  return TrackIDToParticle(bestId);
444  }
set< int >::iterator it
void AccumulateHitContributions(rb::CellHit const &hit, std::map< int, int > &idToNPhot) const
Internal helper, adds the contributions from each particle in this cell to the map.
const sim::Particle * TrackIDToParticle(int const &id) const
Returns a pointer to the sim::Particle object corresponding to the given TrackID. ...
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
void cheat::BackTracker::HitToParticlesMap ( const std::vector< const rb::Cluster * > &  sliceList,
const int sliceIdx 
)

Definition at line 1605 of file BackTracker_service.cc.

References rb::CellHit::Cell(), febshutoff_auto::chan, fCellToIDs, fIdToEnergy, fSliceIDForHitParticleMap, HitToTrackIDE(), IsNoise(), rb::CellHit::Plane(), and rawdata::RawDigit::TDC().

Referenced by ClusterToParticle().

1607  {
1608  fCellToIDs.clear();
1609  fIdToEnergy.clear();
1610 
1611  unsigned int nsli = sliceList.size();
1612 
1613  for (unsigned int isli = 0; isli < nsli; isli++){
1614  unsigned int nh = sliceList[isli]->NCell();
1615  for (unsigned int ih = 0; ih < nh; ih++){
1616 
1617  art::Ptr<rb::CellHit> hit = sliceList[isli]->Cell(ih);
1618 
1619  if (IsNoise(hit)) continue;
1620  double chan = (hit->TDC()*1000000) + (hit->Plane()*1000) + hit->Cell();
1621 
1622  std::vector<cheat::TrackIDE> ides = HitToTrackIDE(hit);
1623  fCellToIDs[chan] = ides;
1624 
1625  for(auto ide : ides)
1626  fIdToEnergy[ide.trackID] += ide.energy;
1627  }// end of loop over slice hits
1628  }// end of loop over slices
1629  fSliceIDForHitParticleMap = sliceIdx;
1630 
1631  }// end of hits to particles table
int32_t TDC() const
The time of the last baseline sample.
Definition: RawDigit.h:94
std::vector< TrackIDE > HitToTrackIDE(const rb::CellHit &hit, bool useBirksE=false) const
Convenience function. HitsToTrackIDE but for a single hit.
unsigned short Plane() const
Definition: CellHit.h:39
std::map< double, std::vector< cheat::TrackIDE > > fCellToIDs
Definition: BackTracker.h:951
bool IsNoise(const art::Ptr< rb::CellHit > &hit) const
Is this hit not associated with any particles?
unsigned short Cell() const
Definition: CellHit.h:40
std::map< int, float > fIdToEnergy
Definition: BackTracker.h:952
Definition: event.h:1
void cheat::BackTracker::HitToParticlesMap ( const std::vector< rb::Cluster > &  sliceList,
const int sliceIdx 
)
inline

Definition at line 772 of file BackTracker.h.

774  {
775  return HitToParticlesMap(VecToVecRawPtr(sliceList), sliceIdx);
776  }
void HitToParticlesMap(const std::vector< const rb::Cluster * > &sliceList, const int &sliceIdx)
std::vector< const T * > VecToVecRawPtr(const std::vector< T > &xs) const
Definition: BackTracker.h:887
void cheat::BackTracker::HitToParticlesMap ( const std::vector< art::Ptr< rb::Cluster >> &  sliceList,
const int sliceIdx 
)
inline

Definition at line 778 of file BackTracker.h.

780  {
781  return HitToParticlesMap(VecPtrToVecRawPtr(sliceList), sliceIdx);
782  }
std::vector< const T * > VecPtrToVecRawPtr(const std::vector< art::Ptr< T >> &xs) const
Definition: BackTracker.h:874
void HitToParticlesMap(const std::vector< const rb::Cluster * > &sliceList, const int &sliceIdx)
void cheat::BackTracker::HitToParticlesMap ( const art::PtrVector< rb::Cluster > &  sliceList,
const int sliceIdx 
)
inline

Definition at line 784 of file BackTracker.h.

786  {
787  return HitToParticlesMap(PtrVecToVecRawPtr(sliceList), sliceIdx);
788  }
std::vector< const T * > PtrVecToVecRawPtr(const art::PtrVector< T > &xs) const
Helper function for implementing overloads.
Definition: BackTracker.h:861
void HitToParticlesMap(const std::vector< const rb::Cluster * > &sliceList, const int &sliceIdx)
const std::vector< sim::PhotonSignal > cheat::BackTracker::HitToPhotonSignal ( const art::Ptr< rb::CellHit > &  hit) const

Returns the PhotonSignals contributing the signal in the specified hit.

Sorted from highest signal to lowest (which is probably not much use, since energy from one particle can be split over several signals).

Definition at line 294 of file BackTracker_service.cc.

References rb::CellHit::Cell(), CloseInTime(), fCellToPhotonSignal, art::Ptr< T >::get(), MECModelEnuComparisons::i, it, LOG_DEBUG, and rb::CellHit::Plane().

Referenced by mcchk::MonopoleAna::analyze(), mcchk::RockAna::analyze(), calib::StopperThreshold::FillHist(), calib::StopperThreshold::FillTree(), and murem::MuonRemove::RemoveByTruth().

295  {
296  auto it = fCellToPhotonSignal.find(geo::OfflineChan(hit->Plane(), hit->Cell()));
297 
298  // Nothing to accumulate from this cell
299  if(it == fCellToPhotonSignal.end()){
300  LOG_DEBUG("BackTracker") << "no collection of sim::PhotonSignal for "
301  << " plane = " << hit->Plane() << " cell = " << hit->Cell()
302  << " probably this was a noise hit, returning an"
303  << " empty vector";
304  const std::vector<sim::PhotonSignal> empty;
305  return empty;
306  }
307 
308  // Candidate photons, in that they're in the right cell.
309  const std::vector<sim::PhotonSignal>& phots = it->second;
310 
311  std::vector<sim::PhotonSignal> hitPhots;
312 
313  // For every photon that's sufficiently in time with the hit,
314  // accumulate its energy into the relevant trackID.
315  for(unsigned int i = 0; i < phots.size(); ++i){
316  const sim::PhotonSignal& phot = phots[i];
317  if(CloseInTime(*hit.get(), phot)){
318  hitPhots.push_back(phot);
319  }
320  }
321  return hitPhots;
322  }
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
std::unordered_map< geo::OfflineChan, std::vector< sim::PhotonSignal > > fCellToPhotonSignal
map of PhotonSignals in each cell in event
Definition: BackTracker.h:941
set< int >::iterator it
unsigned short Plane() const
Definition: CellHit.h:39
unsigned short Cell() const
Definition: CellHit.h:40
T const * get() const
Definition: Ptr.h:321
A (plane, cell) pair.
Definition: OfflineChan.h:17
bool CloseInTime(const rb::CellHit &chit, const sim::PhotonSignal &phot) const
Internal helper, decides if a PhotonSignal and CellHit are close enough to match. ...
std::vector< TrackIDE > cheat::BackTracker::HitToTrackIDE ( const rb::CellHit hit,
bool  useBirksE = false 
) const
std::vector< TrackIDE > cheat::BackTracker::HitToTrackIDE ( const art::Ptr< rb::CellHit > &  hit,
bool  useBirksE = false 
) const

Definition at line 612 of file BackTracker_service.cc.

References art::Ptr< T >::get(), HitsToTrackIDE(), and HitToTrackIDE().

613  {
614  return HitsToTrackIDE(std::vector<const rb::CellHit*>(1, hit.get()), useBirksE);
615  }
std::vector< TrackIDE > HitsToTrackIDE(const std::vector< const rb::CellHit * > &hits, bool useBirksE=false) const
Returns vector of TrackIDE structs contributing to the given collection of hits.
T const * get() const
Definition: Ptr.h:321
TVector3 cheat::BackTracker::HitToXYZ ( art::Ptr< rb::CellHit > const &  hit,
bool  useBirksE = false 
) const

Returns the XYZ position of the energy deposition for a given hit.

Note the return value is in cell coordinates, not detector

Definition at line 625 of file BackTracker_service.cc.

References e, HitCollectionPurity(), HitToFLSHit(), w, plotSysts::weight, submit_syst::x, submit_syst::y, and test::z.

Referenced by cheat::CheckBackTracking::analyze(), mcchk::MonopoleAna::analyze(), and calib::AssessCalib::analyze().

626  {
627  double x = 0.;
628  double y = 0.;
629  double z = 0.;
630  double w = 0.;
631 
632  const std::vector<sim::FLSHit> fhits = this->HitToFLSHit(hit);
633 
634  // loop over the FLSHits for this cell and get the weighted central
635  // position of each track id in it.
636  for(const sim::FLSHit& fhit: fhits){
637  double weight = ((useBirksE) ? fhit.GetEdepBirks() : fhit.GetEdep());
638 
639  w += weight;
640  x += weight * 0.5*(fhit.GetExitX() + fhit.GetEntryX());
641  y += weight * 0.5*(fhit.GetExitY() + fhit.GetEntryY());
642  z += weight * 0.5*(fhit.GetExitZ() + fhit.GetEntryZ());
643 
644  }// end loop over sim::FLSHits
645 
646  // if the sum of the weights is still 0, then return
647  // the obviously stupid default values
648  if(w < 1.e-5) return TVector3(-999, -999, -999);
649 
650  return TVector3(x/w, y/w, z/w);
651  }
float weight
Definition: plotSysts.py:333
A single unit of energy deposition in the liquid scintillator.
Definition: FLSHit.h:19
std::vector< sim::FLSHit > HitToFLSHit(const rb::CellHit &hit) const
All the FLSHits that contributed to this hit, sorted from most to least light.
z
Definition: test.py:28
Float_t e
Definition: plot.C:35
Float_t w
Definition: plot.C:20
bool cheat::BackTracker::InterceptsDetector ( const sim::Particle Par,
int TrajEnt,
int TrajEx 
)

A function which returns the trajectory point at which the particle first enters and leave the detector volume. The trajectory point is returned so that the user can determine the energies etc which the particle had at this point. Should the particle have been generated in the detector then TrajEnt == 0 will be returned. Should the particle stop in the detector then TrajEx == NumberTrajectoryPoints()-1 will be returned. Should the particle never enter the detector then holder values TrajEnter == TrajEx == -5 will be returned.

A function which returns the trajectory point at which the particle first enters and leave the detector volume. The trajectory point is returned so that the user can determine the energies etc which the particle had at this point. Should the particle have been generated in the detector then TrajEnt == 0 will be returned. Should the particle stop in the detector then TrajEx == NumberTrajectoryPoints()-1 will be returned. Should the particle never enter the detector then holder values TrajEnter == TrajEx == -5 will be returned.

Definition at line 1846 of file BackTracker_service.cc.

References DEFINE_ART_SERVICE, geom(), geo::GeometryBase::isInsideDetectorBigBox(), simb::MCParticle::NumberTrajectoryPoints(), simb::MCParticle::Vx(), simb::MCParticle::Vy(), and simb::MCParticle::Vz().

Referenced by CalcEscapingEnergy(), and cheat::TrueEnergy::produce().

1846  {
1847  /// A function which returns the trajectory point at which the particle first enters and leave the detector volume.
1848  /// The trajectory point is returned so that the user can determine the energies etc which the particle had at this
1849  /// point.
1850  /// Should the particle have been generated in the detector then TrajEnt == 0 will be returned.
1851  /// Should the particle stop in the detector then TrajEx == NumberTrajectoryPoints()-1 will be returned.
1852  /// Should the particle never enter the detector then holder values TrajEnter == TrajEx == -5 will be returned.
1853 
1854  // Initially set some holder values.
1855  TrajEnt = TrajEx = -5;
1856  // Make a handle to geometry service
1858  // Get the Number of trajectory points.
1859  unsigned int NumTraj = Par.NumberTrajectoryPoints();
1860  bool EnteredVol = false;
1861  bool PrevHit = false;
1862  for (unsigned int trj=0; trj<NumTraj; ++trj) {
1863  // Is the hit in the detector?
1864  bool InDet = geom->isInsideDetectorBigBox( Par.Vx(trj), Par.Vy(trj), Par.Vz(trj) );
1865  if ( InDet ) {
1866  // If this is the first hit in the volume.
1867  if ( !EnteredVol ) {
1868  TrajEnt = trj;
1869  EnteredVol = true;
1870  }
1871  // If this is the last trajectory point.
1872  if ( EnteredVol && InDet && (trj==NumTraj-1) ) {
1873  TrajEx = trj;
1874  }
1875  }
1876  // If last hit was in volume, and this hit isn't.
1877  if ( PrevHit && !InDet) {
1878  TrajEx = trj-1;
1879  }
1880  // Set the PrevHit variable.
1881  PrevHit = InDet;
1882  } // Loop over TrajPoints
1883  // Finally, return
1884  return EnteredVol;
1885  } //end InterceptsDetector
unsigned int NumberTrajectoryPoints() const
Definition: MCParticle.h:217
bool isInsideDetectorBigBox(const double x_cm, const double y_cm, const double z_cm) const
Is the particle inside the detector Big Box?
double Vx(const int i=0) const
Definition: MCParticle.h:220
void geom(int which=0)
Definition: geom.C:163
double Vz(const int i=0) const
Definition: MCParticle.h:222
double Vy(const int i=0) const
Definition: MCParticle.h:221
bool cheat::BackTracker::IsHitsNoise ( std::vector< art::Ptr< rb::CellHit > > const &  hits) const

Of this collection of hits, is it mostly noise or physics hits? True indicates noise.

Definition at line 459 of file BackTracker_service.cc.

References fParams, demo3::h, hits(), IsNoise(), cheat::BackTracker::Params::MinPhysicsFrac, cheat::BackTracker::Params::MinPhysicsHits, and produceInfoGainMatrix::total.

460  {
461  int totalNoise = 0;
462  int total = hits.size();
463 
464  for(size_t h = 0; h < hits.size(); ++h){
466  if (IsNoise(hit)) totalNoise += 1;
467  }
468 
469  int totalPhysics = total - totalNoise;
470  double physicsFrac = (double)totalPhysics / (double)total;
471 
472  // If at least MinPhysicsHits physics hits in the collection, not a noise group.
473  // If at least MinPhysicsFrac of the hits are physics, not a noise group.
474  // Otherwise, call it a noise group.
475 
476  return((totalPhysics < fParams.MinPhysicsHits()) && (physicsFrac < fParams.MinPhysicsFrac()));
477  }
bool IsNoise(const art::Ptr< rb::CellHit > &hit) const
Is this hit not associated with any particles?
void hits()
Definition: readHits.C:15
Definition: event.h:1
Atom< double > MinPhysicsFrac
Definition: BackTracker.h:107
h
Definition: demo3.py:41
bool cheat::BackTracker::IsNoise ( const art::Ptr< rb::CellHit > &  hit) const
bool cheat::BackTracker::IsNoise ( const rb::CellHit hit) const

Is this hit not associated with any particles?

Definition at line 453 of file BackTracker_service.cc.

References HitToParticle().

454  {
455  return (HitToParticle(hit, true) == 0);
456  }
const sim::Particle * HitToParticle(art::Ptr< rb::CellHit > const &hit, bool quiet=false) const
Returns the sim::Particle object contributing the most light to the specified rb::CellHit.
rb::Cluster cheat::BackTracker::MCTruthToCluster ( art::Ptr< simb::MCTruth > const &  truth,
std::vector< art::Ptr< rb::CellHit > > const &  hits 
)

:

Definition at line 1576 of file BackTracker_service.cc.

References rb::Cluster::Add(), fMCTruthList, fTrackIDToMCTruthIndex, hits(), HitToParticle(), compare_h5_caf::idx, IsNoise(), part, and simb::MCParticle::TrackId().

1578  {
1579  rb::Cluster cluster;
1580 
1581  // figure out where in the MCTruth list mct belongs
1582  unsigned int MCTidx;
1583  for(MCTidx = 0; MCTidx < fMCTruthList.size(); ++MCTidx) {
1584  if(fMCTruthList[MCTidx] == mct) break;
1585  }
1586 
1587  // loop over hits and add to the cluster
1588  for(unsigned int hiti = 0; hiti < hits.size(); ++hiti) {
1589  art::Ptr<rb::CellHit> hit = hits[hiti];
1590 
1591  // If the hit is noise, skip it.
1592  if(this->IsNoise(hit)) continue;
1593 
1594  const sim::Particle *part = this->HitToParticle(hit);
1595  unsigned int idx = fTrackIDToMCTruthIndex[part->TrackId()];
1596  if(idx == MCTidx) cluster.Add(hit);
1597 
1598  } // end loop over hits
1599 
1600  return cluster;
1601  }
A collection of associated CellHits.
Definition: Cluster.h:47
const sim::Particle * HitToParticle(art::Ptr< rb::CellHit > const &hit, bool quiet=false) const
Returns the sim::Particle object contributing the most light to the specified rb::CellHit.
bool IsNoise(const art::Ptr< rb::CellHit > &hit) const
Is this hit not associated with any particles?
int TrackId() const
Definition: MCParticle.h:209
virtual void Add(const art::Ptr< rb::CellHit > &cell, double weight=1)
Definition: Cluster.cxx:84
std::vector< art::Ptr< simb::MCTruth > > fMCTruthList
all the MCTruths for this event
Definition: BackTracker.h:944
TString part[npart]
Definition: Style.C:32
void hits()
Definition: readHits.C:15
std::map< int, int > fTrackIDToMCTruthIndex
map of track id values to MCTruthList entry
Definition: BackTracker.h:945
Definition: event.h:1
std::vector< const sim::Particle * > cheat::BackTracker::MCTruthToParticles ( art::Ptr< simb::MCTruth > const &  mct) const

Definition at line 527 of file BackTracker_service.cc.

References sim::ParticleNavigator::find(), fParticleNav, fTrackIDs, HitsToParticle(), runNovaSAM::ret, and TrackIDToMCTruth().

Referenced by caf::AddCosmicTruthToVec(), caf::CAFMaker::AddMCTruthToVec(), numue::NumuEAna::analyze(), murem::MuonRemoveAna::analyze(), mcchk::LeptonAna::analyze(), earms::ElasticArmsValidate::analyze(), mcchk::DetSimAna::analyze(), fuzz::FuzzyKValidate::analyze(), slid::LIDTraining::analyze(), cheat::CheckBackTracking::CheckTrackIdToParticle(), murem::MuonRemove::FillTruthInfo(), nuesand::FillNueSandbox::FillTruthVars(), nuesand::FillNueSandbox::GetECF(), numue::NumuEAlg::MCTruthEnergyVariables(), SliceToMCTruth(), SliceToNeutrinoIndex(), and SliceToNeutrinoInteractions().

528  {
529  std::vector<const sim::Particle*> ret;
530 
531  for(std::set<int>::const_iterator itr = fTrackIDs.begin(); itr != fTrackIDs.end(); itr++){
532  if( this->TrackIDToMCTruth(*itr) == mct ) ret.push_back(fParticleNav.find(*itr)->second);
533  }
534 
535  return ret;
536  }
std::set< int > fTrackIDs
G4 track ids for all particles in the events.
Definition: BackTracker.h:943
sim::ParticleNavigator fParticleNav
Particle navigator to map track ID to Particle.
Definition: BackTracker.h:942
const art::Ptr< simb::MCTruth > & TrackIDToMCTruth(int const &id) const
iterator find(const key_type &key)
const sim::ParticleNavigator& cheat::BackTracker::ParticleNavigator ( ) const
inline

Get a reference to the ParticleNavigator.

Definition at line 744 of file BackTracker.h.

Referenced by cheat::TestTrackIds::analyze(), ve::VertexEva::analyze(), ddt::SMMEff::analyze(), calib::ParticleCorrections::analyze(), ddt::SMMADC::analyze(), mmc::Validation::analyze(), mcchk::ShowerAnaCheck::analyze(), zcl::SMMTriggerAna::analyze(), mcchk::MonopoleAna::analyze(), mcchk::CosmicAna::analyze(), vf::TrackEva::analyze(), zcl::MMCheater::analyze(), zcl::FmmTriggerAna::analyze(), mcchk::LeptonAna::analyze(), ddt::SlicerEva::analyze(), zcl::FmmTrackerValidation::analyze(), showere::ShowerEnergyAna::analyze(), mono::SlowMonopoleAna::analyze(), mono::Monopole::analyze(), zcl::FastMMStudy::analyze(), ncs::GenieTruth::analyze(), ddt::SuperDDTEva::analyze(), slid::LIDTraining::analyze(), ncs::NCAna::analyze(), htk::HoughTrack::analyze(), cheat::CheckBackTracking::CheckTrackIdToParticle(), trk::CosmicTrackAna::FillEventMCTruthHistograms(), caf::FillParticleTruth(), murem::MuonRemove::FillTruthInfo(), nuesand::FillNueSandbox::FillTruthVars(), tut::TutFilter::filter(), mono::EventSelector::filter(), showere::ShowerEnergyFilterMC::filter(), bsf::BremShowerFilter::findShowerByTruth(), skim::EvaluatorNumuCCpi::KeepEventSlices(), evd::MCTrueView::LoadEvent(), evd::SimulationDrawer::MCTruthLongText(), evd::SimulationDrawer::MCTruthTrajectoriesAnyD(), novaddt::UpMuAna::populateFLSmap(), mmc::Validation::print_truth_info(), mono::SlowMonopoleAna::print_truth_info(), evd::SimulationDrawer::PrintParticleAndOffspring(), cheat::ClusterCheater::produce(), filter::TruthFilter::produce(), cheat::ShowerCheater::produce(), tut::TutProducer::produce(), cheat::ProngCheater::produce(), cheat::TrackCheater::produce(), zcl::SMMCluster::produce(), cheat::MCCheater::produce(), cvn::ProngClassify(), murem::MuonRemove::RemoveByEfficiency(), and murem::MuonRemove::RemoveByTruth().

744 { return fParticleNav; }
sim::ParticleNavigator fParticleNav
Particle navigator to map track ID to Particle.
Definition: BackTracker.h:942
std::vector< sim::FLSHit > cheat::BackTracker::ParticleToFLSHit ( const int trackID) const

All the FLSHits that were created by the track id trackID, sorted from most to least light.

Definition at line 1514 of file BackTracker_service.cc.

References fTrackIDToFLSHit, it, and LOG_DEBUG.

Referenced by ddt::SMMEff::analyze(), mmc::Validation::analyze(), zcl::SMMTriggerAna::analyze(), mcchk::MonopoleAna::analyze(), numue::NumuEAna::analyze(), mcchk::CosmicAna::analyze(), zcl::MMCheater::analyze(), zcl::FmmTriggerAna::analyze(), mcchk::LeptonAna::analyze(), ddt::SlicerEva::analyze(), zcl::FmmTrackerValidation::analyze(), mono::SlowMonopoleAna::analyze(), mcchk::DetSimAna::analyze(), mono::Monopole::analyze(), zcl::FastMMStudy::analyze(), ddt::SuperDDTEva::analyze(), upmuana::UpMuRecoAna::analyze(), htk::HoughTrack::analyze(), trk::CosmicTrackAna::FillEventMCTruthHistograms(), calib::StopperThreshold::FillHist(), calib::StopperThreshold::FillTree(), trk::CosmicTrackAna::FillTrueInfo(), calib::EnergyStandardCandles::FillTrueMichelInfo(), bsf::BremShowerFilter::findShowerByTruth(), numue::NumuEAlg::MCTruthEnergyVariables(), ParticleToFLSHit(), mmc::Validation::print_truth_info(), mono::SlowMonopoleAna::print_truth_info(), and zcl::SMMCluster::produce().

1514  {
1515  std::unordered_map< int, std::list<sim::FLSHit> >::const_iterator it = fTrackIDToFLSHit.find(trackID);
1516  if( it == fTrackIDToFLSHit.end() ){
1517  std::vector<sim::FLSHit> empty;
1518  LOG_DEBUG("BackTracker") << "no collection of sim::FLSHit for "
1519  <<"Track ID "<<trackID
1520  << ". Returning empty vector";
1521 
1522  return empty;
1523  }
1524  else
1525  return std::vector<sim::FLSHit>(it->second.begin(), it->second.end());
1526  }
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
set< int >::iterator it
std::unordered_map< int, std::list< sim::FLSHit > > fTrackIDToFLSHit
map of G4 track ids to FLSHits
Definition: BackTracker.h:940
Int_t trackID
Definition: plot.C:84
std::vector< sim::FLSHit > cheat::BackTracker::ParticleToFLSHit ( const int  trackID,
const int  pdg 
) const

All the FLSHits that were created by the track id trackID, which also have a particular pdg. Most users should use the other version of this function. However, sometimes when our truth is condensed, the same mother track ID is assigned to FLS hits made by non-important daughters, who can have different PDG values. An example of this is a muon track, whose delta rays often have the track id of the mother muon. By using this version of the function, you can ensure you are looking only at the FLS hits deposited by the muon.

Fill only FLSHits with a given PDG

Definition at line 1530 of file BackTracker_service.cc.

References sim::FLSHit::GetPDG(), MECModelEnuComparisons::i, ParticleToFLSHit(), and make_root_from_grid_output::pdg.

1530  {
1531 
1532  const std::vector<sim::FLSHit>& flshits_with_same_track_id = ParticleToFLSHit(trackID);
1533 
1534  std::vector<sim::FLSHit> out_flshits;
1535 
1536  const int nflshits = flshits_with_same_track_id.size();
1537 
1538  /// Fill only FLSHits with a given PDG
1539  for(int i=0; i<nflshits; ++i){
1540  const sim::FLSHit& flshit= flshits_with_same_track_id[i];
1541  if(flshit.GetPDG() == pdg){
1542  out_flshits.push_back(flshit);
1543  }
1544  }
1545 
1546  return out_flshits;
1547  }
std::vector< sim::FLSHit > ParticleToFLSHit(const int &trackID) const
All the FLSHits that were created by the track id trackID, sorted from most to least light...
A single unit of energy deposition in the liquid scintillator.
Definition: FLSHit.h:19
int GetPDG() const
PDG.
Definition: FLSHit.h:43
Int_t trackID
Definition: plot.C:84
const art::Ptr< simb::MCTruth > & cheat::BackTracker::ParticleToMCTruth ( const sim::Particle p) const

Definition at line 521 of file BackTracker_service.cc.

References simb::MCParticle::TrackId(), and TrackIDToMCTruth().

Referenced by cheat::TestTrackIds::analyze(), trk::KalmanTrackAna::CheckRecoTracks(), and cheat::CheckBackTracking::CheckTrackIdToParticle().

522  {
523  return this->TrackIDToMCTruth(p->TrackId());
524  }
int TrackId() const
Definition: MCParticle.h:209
const art::Ptr< simb::MCTruth > & TrackIDToMCTruth(int const &id) const
bool cheat::BackTracker::PassMuonCuts ( int  trackID,
art::PtrVector< rb::CellHit > const &  hits 
) const

Tool for NumuEAna that allows one to see if primary muon (or any track ID you feed the function) contributes to enough hits in the slice to pass the hit cut. It is currently set at 4 hits in each view.

Definition at line 965 of file BackTracker_service.cc.

References demo3::h, HitToTrackIDE(), geo::kX, geo::kY, art::PtrVector< T >::size(), plotSysts::t, and rb::CellHit::View().

Referenced by numue::NumuEAna::analyze(), trk::KalmanTrackAna::CheckRecoTracks(), and numue::NumuEAlg::MCTruthEnergyVariables().

967  {
968  int nxcells = 0;
969  int nycells = 0;
970 
971  for(size_t h = 0; h < hits.size(); ++h){
972 
973  art::Ptr<rb::CellHit> hit = hits[h];
974  std::vector<TrackIDE> tracks = HitToTrackIDE(hit);
975  for(size_t t = 0; t < tracks.size(); ++t){
976  if(tracks[t].trackID == trackID){
977 
978  if (hit->View() == geo::kX){
979  nxcells++;
980  }// end of loop over x hits
981 
982  if (hit->View() == geo::kY){
983  nycells++;
984  }// end of loop over y hits
985 
986  }// end of loop over hits from the muon
987  }// end of loop over tracks
988  }// end loop over hits
989 
990 
991  if ((nxcells >= 3) && (nycells >= 3)) return 1;
992  else return 0;
993  }
std::vector< TrackIDE > HitToTrackIDE(const rb::CellHit &hit, bool useBirksE=false) const
Convenience function. HitsToTrackIDE but for a single hit.
geo::View_t View() const
Definition: CellHit.h:41
Vertical planes which measure X.
Definition: PlaneGeo.h:28
Horizontal planes which measure Y.
Definition: PlaneGeo.h:29
size_type size() const
Definition: PtrVector.h:308
Definition: event.h:1
Int_t trackID
Definition: plot.C:84
h
Definition: demo3.py:41
template<class T >
std::vector<const T*> cheat::BackTracker::PtrVecToVecRawPtr ( const art::PtrVector< T > &  xs) const
inlineprivate

Helper function for implementing overloads.

NB the pointers are only valid so long as the parent xs is still around

Definition at line 861 of file BackTracker.h.

References runNovaSAM::ret, art::PtrVector< T >::size(), and submit_syst::x.

Referenced by SliceToMCTruth(), SliceToNeutrinoInteractions(), and TracksToParticles().

862  {
863  std::vector<const T*> ret;
864  ret.reserve(xs.size());
865  for(const art::Ptr<T>& x: xs) ret.push_back(x.get());
866  return ret;
867  }
size_type size() const
Definition: PtrVector.h:308
Definition: fwd.h:28
void cheat::BackTracker::Rebuild ( const art::Event evt)

This function rebuilds the various maps we need to answer backtracking queries. It is called automatically before each event is processed. For jobs involving Monte Carlo generation, this is too soon. So, ReadoutSim also calls this function when it knows all the relevant products have been produced. Requiring this kind of cooperation from other modules for a service to function properly is not recommended in general. In this case it seems like the least-bad option, but think very carefully before adding any other examples. "Do as I say, not as I do".

Definition at line 84 of file BackTracker_service.cc.

References sim::ParticleNavigator::Add(), sim::PhotonSignal::Cell(), febshutoff_auto::chan, sim::ParticleNavigator::clear(), sim::CompareByNPhoton(), geo::GeometryBase::DetId(), MakeMiniprodValidationCuts::f, art::Handle< T >::failedToGet(), fCellToFLSHit, fCellToPhotonSignal, fDetID, fHaveTruthInfo, fMCTruthList, fNumTrueEnergyWarnings, fParams, fParticleNav, fSliceIDForHitParticleMap, fTrackIDs, fTrackIDToFLSHit, fTrackIDToMCTruthIndex, fTrackIDToTrueEIndex, fTrueEnergyList, cheat::BackTracker::Params::GeantModuleLabel, geom(), art::DataViewImpl::getByLabel(), sim::FLSHit::GetCellID(), sim::FLSHit::GetPlaneID(), sim::FLSHit::GetTrackID(), hits(), MECModelEnuComparisons::i, art::Event::isRealData(), it, novadaq::cnv::kUNKNOWN_DET, submit_hadd::l, LOG_DEBUG, cheat::BackTracker::Params::MCOverlayMode, cheat::BackTracker::Params::MRMode, part, cheat::BackTracker::Params::PhotonModuleLabel, sim::PhotonSignal::Plane(), cheat::sortFLSHit(), and cheat::BackTracker::Params::TrueEnergyModuleLabel.

Referenced by BackTracker(), MergeDaqCollections::MergeDaqCollections::produce(), and rsim::ReadoutSim::produce().

85  {
86  // Clear out anything remaining from previous calls to Rebuild
87  fCellToFLSHit.clear();
88  fTrackIDToFLSHit.clear();
89  fCellToPhotonSignal.clear();
90  fTrackIDs.clear();
92  fMCTruthList.clear();
94  fTrueEnergyList.clear();
95  fTrackIDToTrueEIndex.clear();
96  fHaveTruthInfo = false; // Haven't got anything yet
97  fDetID = novadaq::cnv::kUNKNOWN_DET; // Haven't found detector type yet
98 
99  // do nothing if this is data
100  if(evt.isRealData() && !fParams.MRMode()
101  && !fParams.MCOverlayMode()) return;
102 
103  // get detector for CloseInTime function
105  fDetID = geom->DetId();
106 
107  // fill the map of OfflineChan to std::vector<FLSHit>
108  // first get the FLSHitList from the event
110  evt.getByLabel(fParams.GeantModuleLabel(), flslistHandle);
111 
112  // Probably this is a MC generation job and this is the preEvent callback
113  // which is too early. That's OK, we'll get called at the right time by
114  // ReadoutSim in a moment. Or we're mock data or something.
115  if(flslistHandle.failedToGet()) return;
116 
117  fHaveTruthInfo = true; // We got FLSHits, the rest should go well too
118 
119  // loop over the FLSHits and fill the std::vector for each
120  // channel
121  for( size_t l = 0; l < flslistHandle->size(); ++l){
122  const std::vector<sim::FLSHit> &hits = flslistHandle->at(l).fHits;
123  for( size_t f = 0; f < hits.size(); ++f){
124  const sim::FLSHit& hit = hits[f];
125  const geo::OfflineChan chan(hit.GetPlaneID(), hit.GetCellID());
126  fCellToFLSHit[chan].push_back(hit);
127  fTrackIDToFLSHit[hit.GetTrackID()].push_back(hit);
128  }// end loop over flshits
129  }// end loop over flshit lists
130 
131  // loop over the map and sort the vectors of flshits
132  for(auto itr = fCellToFLSHit.begin(); itr != fCellToFLSHit.end(); itr++){
133  itr->second.sort(sortFLSHit);
134  }
135 
136  // loop over the map and sort the vectors of flshits
137  for(auto pfitr = fTrackIDToFLSHit.begin(); pfitr != fTrackIDToFLSHit.end(); pfitr++){
138  pfitr->second.sort(sortFLSHit);
139  }
140 
141  // Similarly, PhotonSignals
143  evt.getByLabel(fParams.PhotonModuleLabel(), phots);
144 
145  if(!phots.failedToGet()){
146  for(size_t i = 0; i < phots->size(); ++i){
147  const sim::PhotonSignal& phot = (*phots)[i];
148  const geo::OfflineChan chan(phot.Plane(), phot.Cell());
149  fCellToPhotonSignal[chan].push_back(phot);
150  } // end for i
151 
152  for(auto it = fCellToPhotonSignal.begin(); it != fCellToPhotonSignal.end(); ++it){
153  // Sort in reverse order, ie from most photons to least
154  std::sort(it->second.rbegin(), it->second.rend(), sim::CompareByNPhoton);
155  }
156  }
157  else{
158  mf::LogWarning("BackTracker") << "unable to find PhotonTransport "
159  << "created in " << fParams.PhotonModuleLabel() << " "
160  << "any attempt to get the PhotonTransport objects from "
161  << "the backtracker will fail";
162  }
163 
165  evt.getByLabel(fParams.GeantModuleLabel(), pHandle);
166  if(pHandle.failedToGet()){
167  mf::LogWarning("BackTracker") << "unable to find sim::Particles "
168  << "created in " << fParams.GeantModuleLabel() << " "
169  << "any attempt to get the Particles from "
170  << "the backtracker will fail";
171  }
172  else{
173  // Keep track of all the MCTruths we discover associated to the particles
174  std::set<art::Ptr<simb::MCTruth>> truths;
175  // And which truth each particle points at
176  std::map<int, art::Ptr<simb::MCTruth>> trackIDToMCTruthPtr;
177 
179  for(size_t p = 0; p < pHandle->size(); ++p){
180 
181  sim::Particle *part = new sim::Particle(pHandle->at(p));
182  fParticleNav.Add(part);
183 
184  // get the simb::MCTruth associated to this vector<Particle>
185  art::Ptr<simb::MCTruth> mct = fo.at(p);
186  truths.insert(mct);
187  try{
188  trackIDToMCTruthPtr.emplace(pHandle->at(p).TrackId(), mct);
189  }
190  catch(cet::exception &ex){
191  mf::LogWarning("BackTracker") << "unable to find MCTruth from Particle list "
192  << "created in " << fParams.GeantModuleLabel() << " "
193  << "any attempt to get the MCTruth objects from "
194  << "the backtracker will fail\n"
195  << "message from caught exception:\n" << ex;
196  }
197  } // end loop over particles to get MCTruthList
198 
199  // Flatten the MCTruth set into a vector
200  fMCTruthList.insert(fMCTruthList.end(), truths.begin(), truths.end());
201 
202  // Translate all the truth pointers into indices
203  std::map<art::Ptr<simb::MCTruth>, int> truthIdxs;
204  for(unsigned int i = 0; i < fMCTruthList.size(); ++i){
205  truthIdxs.emplace(fMCTruthList[i], i);
206  }
207 
208  // Convert trackIDToMCTruthPtr from Ptrs to indices
209  for(auto it: trackIDToMCTruthPtr){
210  fTrackIDToMCTruthIndex[it.first] = truthIdxs[it.second];
211  }
212  }
213 
214 
215  // fill the set of track ids from the ParticleNavigator
216  fTrackIDs.clear();
217  for(auto& it: fParticleNav) fTrackIDs.insert(it.first);
218 
219  LOG_DEBUG("BackTracker") << fParticleNav;
220 
221  // Get the sim::TrueEnergy data products out of the event. I don't think that I'll be able to utilise the Assn
222  // between sim::Particle and sim::TrueEnergy here, as I would have to somehow have to pass the Assn around.
224  evt.getByLabel(fParams.TrueEnergyModuleLabel(), teHandle);
225  if(!teHandle.failedToGet()) {
226  // Get the TrueEnergy Assn, and loop through the particles.
228  for(size_t p = 0; p < pHandle->size(); ++p){
229  int parTrId = pHandle->at(p).TrackId();
230  // There should just be a 1 to 1 correspondance, however for some reason
231  // the first few particles may have multiple assns, and the last few none.
232  bool match_truep = false;
233  for(size_t te = 0; te < teAssn.at(p).size(); ++te){
234  if (parTrId == teAssn.at(p)[te]->TrackId()) {
235  match_truep = true;
236  fTrueEnergyList.push_back ( teAssn.at(p)[te] );
237  fTrackIDToTrueEIndex.emplace( parTrId, p );
238  }
239  }
240  if (!match_truep) {
241  // If didn't match, then it's one of the last particles, and so has an assn with a particle at the.
242  // start of the particle loop. Lets restart the loop over the particles, pulling those assns...
243  for(size_t par2 = 0; par2 < pHandle->size(); ++par2){
244  for(size_t te = 0; te < teAssn.at(par2).size(); ++te){
245  if (parTrId == teAssn.at(par2)[te]->TrackId()) {
246  fTrueEnergyList.push_back ( teAssn.at(par2)[te] );
247  fTrackIDToTrueEIndex.emplace( parTrId, p );
248  match_truep = true;
249  }
250  if (match_truep) break;
251  }
252  if (match_truep) break;
253  }
254  }
255  }
256 
257  /*
258  // I think that if using the true energy module you may have to use this technique.
259  // Totally my fault, I made the assns in different way for some reason...
260  art::FindOneP<sim::TrueEnergy> teAssn(pHandle, evt, fParams.TrueEnergyModuleLabel());
261  for(size_t p = 0; p < pHandle->size(); ++p){
262  art::Ptr<sim::TrueEnergy > MyEns = teAssn.at( p );
263  fTrueEnergyList.push_back( MyEns );
264  fTrackIDToTrueEIndex.emplace( pHandle->at(p).TrackId(), p );
265  }
266  */
267  } else if (fNumTrueEnergyWarnings<10) {
268  mf::LogWarning("BackTracker") << "unable to find sim::TrueEnergy "
269  << "created in " << fParams.TrueEnergyModuleLabel() << " "
270  << "any attempt to get the sim::TrueEnergy's from "
271  << "the backtracker will fail";
273  }
274  }
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
std::unordered_map< geo::OfflineChan, std::vector< sim::PhotonSignal > > fCellToPhotonSignal
map of PhotonSignals in each cell in event
Definition: BackTracker.h:941
set< int >::iterator it
int GetPlaneID() const
Plane ID.
Definition: FLSHit.h:37
std::set< int > fTrackIDs
G4 track ids for all particles in the events.
Definition: BackTracker.h:943
Atom< std::string > GeantModuleLabel
Definition: BackTracker.h:102
int GetCellID() const
Cell ID.
Definition: FLSHit.h:39
const char * p
Definition: xmltok.h:285
Atom< std::string > PhotonModuleLabel
Definition: BackTracker.h:103
::xsd::cxx::tree::exception< char > exception
Definition: Database.h:225
A single unit of energy deposition in the liquid scintillator.
Definition: FLSHit.h:19
bool isRealData() const
Definition: Event.h:83
std::unordered_map< geo::OfflineChan, std::list< sim::FLSHit > > fCellToFLSHit
map of FLSHits in each cell in event
Definition: BackTracker.h:939
Atom< std::string > TrueEnergyModuleLabel
Definition: BackTracker.h:110
std::vector< art::Ptr< simb::MCTruth > > fMCTruthList
all the MCTruths for this event
Definition: BackTracker.h:944
TString part[npart]
Definition: Style.C:32
std::unordered_map< int, std::list< sim::FLSHit > > fTrackIDToFLSHit
map of G4 track ids to FLSHits
Definition: BackTracker.h:940
void hits()
Definition: readHits.C:15
std::vector< art::Ptr< sim::TrueEnergy > > fTrueEnergyList
all the TrueEnergy&#39;s for this event
Definition: BackTracker.h:946
sim::ParticleNavigator fParticleNav
Particle navigator to map track ID to Particle.
Definition: BackTracker.h:942
novadaq::cnv::DetId DetId() const
Prefer ds::DetectorService::DetId() instead.
Definition: GeometryBase.h:243
std::map< int, int > fTrackIDToTrueEIndex
map of track id values to TrueEnergy entry
Definition: BackTracker.h:947
int Cell() const
Definition: PhotonSignal.h:31
bool CompareByNPhoton(const sim::PhotonSignal &a, const sim::PhotonSignal &b)
Helper for SortByNPhoton.
int GetTrackID() const
Track ID.
Definition: FLSHit.h:45
bool fHaveTruthInfo
Set by Rebuild.
Definition: BackTracker.h:935
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
std::map< int, int > fTrackIDToMCTruthIndex
map of track id values to MCTruthList entry
Definition: BackTracker.h:945
Definition: event.h:1
A (plane, cell) pair.
Definition: OfflineChan.h:17
static bool sortFLSHit(sim::FLSHit const &a, sim::FLSHit const &b)
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
void geom(int which=0)
Definition: geom.C:163
ParticleNavigator Add(const int &offset) const
novadaq::cnv::DetId fDetID
detector id
Definition: BackTracker.h:937
bool failedToGet() const
Definition: Handle.h:196
int Plane() const
Definition: PhotonSignal.h:32
std::vector< std::vector< cheat::NeutrinoEffPur > > cheat::BackTracker::SlicesToMCTruthsTable ( const std::vector< const rb::Cluster * > &  sliceList) const

Given ALL the slices in an event, including the noise slice, returns a vector of vector of structures of MCTruth, efficiency, and purity of that MCTruth interaction relative to the slice. The returned vector is the same size as the total number of slices, including the noise slice, which is treated the same as any other slice. It is sorted in the same order as the slice list. For each entry, there is a vector of NeutrinoEffPurs. This vector is the same size as the MCTruth list. It is sorted in the same order as the MCTruth list. Every slice/MCTruth pair shows up, even if the contribution is zero. Efficiency is defined as FLS energy from a MCTruth in a slice / total FLS energy from a MCTruth in event. This function is agnostic to MCTruth and treates them all the same, including those without neutrino interactions, i.e. cosmics.

Definition at line 1259 of file BackTracker_service.cc.

References allMCTruth(), efficiency(), fTrackIDToMCTruthIndex, demo3::h, HitToTrackIDE(), IsNoise(), cheat::NeutrinoEffPur::neutrinoInt, plotConfusion::purity(), plotSysts::t, getGoodRuns4SAM::table, trackID, and TracksToParticles().

Referenced by tut::RecoValidationTutorial::analyze(), bpfit::BPFEnergyAna::analyze(), cvn::CVNEventDump::analyze(), cvn::CVNCosmicEventDump::analyze(), earms::ElasticArmsValidate::analyze(), cvn::CVNEventProngDump::analyze(), slicer::SlicerAna::analyze(), fuzz::FuzzyKValidate::analyze(), bpfit::BPFTmvaTrainer::analyze(), bpf::BPFCVNAna::analyze(), bpfit::BreakPointProtonAna::analyze(), cvn::CVNAddTrainingData::produce(), murem::FindMREParent::produce(), fuzz::FuzzyKVertex::produce(), caf::CAFMaker::produce(), skim::SkimmingUtils::SliceMCTruthAssociation(), and SliceToMCTruth().

1260  {
1261 
1262  unsigned int numSlices = sliceList.size();
1263  std::vector<NeutrinoWithIndex> truthList = allMCTruth();
1264  unsigned int numTruths = truthList.size();
1265 
1266  //This is what will eventually be returned
1267  std::vector< std::vector<cheat::NeutrinoEffPur> > table(numSlices,std::vector<cheat::NeutrinoEffPur>(numTruths));
1268 
1269  //Loop to fill NeutrinoEffPur's with proper truth information
1270  for (unsigned int s = 0; s < numSlices; s++){
1271  for (unsigned int t = 0; t < numTruths; t++){
1272  cheat::NeutrinoEffPur truthFill = {truthList[t].neutrinoInt,0.0,0.0,truthList[t].truthColIndex,0.0,0.0,0,0};
1273  table[s][t] = truthFill;
1274  }
1275  }//End of defining basic container with truths filled in
1276 
1277  for (unsigned int s = 0; s < numSlices; s++){
1278  //Vector to hold the total energy contributions to slice from each MC Truth
1279  std::vector<double> sliceEnergies(numTruths,0.0);
1280  //Vector to hold the total number of hits in the slice from each MC Truth
1281  std::vector<int> sliceHits(numTruths,0);
1282 
1283  for (unsigned int h = 0; h < sliceList[s]->NCell(); h++){
1284  //Don't worry about noise hits - they can't count towards the energy an interaction deposited
1285  if (IsNoise(sliceList[s]->Cell(h))) continue;
1286  //Vector to hold the total energy contributions to hit from each MC Truth
1287  std::vector<double> hitEnergies(numTruths,0.0);
1288 
1289  const std::vector<TrackIDE> trackIDs = HitToTrackIDE(sliceList[s]->Cell(h));
1290  for (unsigned int id = 0; id < trackIDs.size(); id++){
1291  int trackID = trackIDs[id].trackID;
1292  //Gets the MCTruth index for the particle trackID
1293  int truthID = fTrackIDToMCTruthIndex.find(abs(trackID))->second;
1294  hitEnergies[truthID] += trackIDs[id].energy;
1295  }//End of loop over track ids for the hit
1296 
1297  //Add hit values into the slice vectors
1298  for (unsigned int q = 0; q < numTruths; q++){
1299  if (hitEnergies[q] > 0.0){
1300  sliceEnergies[q] += hitEnergies[q];
1301  sliceHits[q] += 1;
1302  }//Only do for MCTruths with nonzero contributions to hit
1303  }//End of loop adding hit values to slice vectors
1304 
1305  }//End of loop over hits in slice
1306 
1307  double totalSliceE = std::accumulate(sliceEnergies.begin(),sliceEnergies.end(),0.0);
1308  for (unsigned int t = 0; t < numTruths; t++){
1309 
1310  double purity = 0.0;
1311  if (totalSliceE > 0){
1312  purity = (sliceEnergies[t])/totalSliceE;
1313  }
1314 
1315  if ((purity < 0) || (purity > 1)) {
1316  throw cet::exception("BackTrackerIllegalPurity")
1317  << "The purity value "<<purity<<" is not allowed. \n";
1318  }
1319 
1320  table[s][t].purity = purity;
1321  table[s][t].energySlice = sliceEnergies[t];
1322  table[s][t].nSliceHits = sliceHits[t];
1323 
1324  }//End of loop over MCTruths for the slice
1325  }//End of loop over slices
1326 
1327  for (unsigned int t = 0; t < numTruths; t++){
1328 
1329  double totalMCTruthE = 0.0;
1330  int totalMCTruthHits = 0;
1331 
1332  for (unsigned int s = 0; s < numSlices; s++){
1333  totalMCTruthE += table[s][t].energySlice;
1334  totalMCTruthHits += table[s][t].nSliceHits;
1335  }//Loop over slices to find summed values
1336 
1337  for (unsigned int s = 0; s < numSlices; s++){
1338 
1339  double efficiency = 0.0;
1340  if (totalMCTruthE > 0){
1341  efficiency = (table[s][t].energySlice)/totalMCTruthE;
1342  }
1343 
1344  if ((efficiency < 0) || (efficiency > 1)) {
1345  throw cet::exception("BackTrackerIllegalEfficiency")
1346  << "The efficiency value "<<efficiency<<" is not allowed. \n";
1347  }
1348 
1349  table[s][t].efficiency = efficiency;
1350  table[s][t].energyTotal = totalMCTruthE;
1351  table[s][t].nTotalHits = totalMCTruthHits;
1352  }//Loop over slices to insert final values
1353 
1354  }//End of final loop over MCTruths for summed values
1355 
1356  return table;
1357  }
::xsd::cxx::tree::id< char, ncname > id
Definition: Database.h:165
std::vector< TrackIDE > HitToTrackIDE(const rb::CellHit &hit, bool useBirksE=false) const
Convenience function. HitsToTrackIDE but for a single hit.
std::vector< NeutrinoWithIndex > allMCTruth() const
::xsd::cxx::tree::exception< char > exception
Definition: Database.h:225
bool IsNoise(const art::Ptr< rb::CellHit > &hit) const
Is this hit not associated with any particles?
const XML_Char * s
Definition: expat.h:262
void efficiency()
Definition: efficiency.C:57
std::map< int, int > fTrackIDToMCTruthIndex
map of track id values to MCTruthList entry
Definition: BackTracker.h:945
Int_t trackID
Definition: plot.C:84
art::Ptr< simb::MCTruth > neutrinoInt
Truth information about neutrino interaction.
Definition: BackTracker.h:47
h
Definition: demo3.py:41
std::vector<std::vector<cheat::NeutrinoEffPur> > cheat::BackTracker::SlicesToMCTruthsTable ( const std::vector< rb::Cluster > &  sliceList) const
inline

Definition at line 659 of file BackTracker.h.

660  {
661  return SlicesToMCTruthsTable(VecToVecRawPtr(sliceList));
662  }
std::vector< std::vector< cheat::NeutrinoEffPur > > SlicesToMCTruthsTable(const std::vector< const rb::Cluster * > &sliceList) const
Given ALL the slices in an event, including the noise slice, returns a vector of vector of structures...
std::vector< const T * > VecToVecRawPtr(const std::vector< T > &xs) const
Definition: BackTracker.h:887
std::vector<std::vector<cheat::NeutrinoEffPur> > cheat::BackTracker::SlicesToMCTruthsTable ( const std::vector< art::Ptr< rb::Cluster >> &  sliceList) const
inline

Definition at line 665 of file BackTracker.h.

666  {
667  return SlicesToMCTruthsTable(VecPtrToVecRawPtr(sliceList));
668  }
std::vector< const T * > VecPtrToVecRawPtr(const std::vector< art::Ptr< T >> &xs) const
Definition: BackTracker.h:874
std::vector< std::vector< cheat::NeutrinoEffPur > > SlicesToMCTruthsTable(const std::vector< const rb::Cluster * > &sliceList) const
Given ALL the slices in an event, including the noise slice, returns a vector of vector of structures...
std::vector<std::vector<cheat::NeutrinoEffPur> > cheat::BackTracker::SlicesToMCTruthsTable ( const art::PtrVector< rb::Cluster > &  sliceList) const
inline

Definition at line 671 of file BackTracker.h.

672  {
673  return SlicesToMCTruthsTable(PtrVecToVecRawPtr(sliceList));
674  }
std::vector< const T * > PtrVecToVecRawPtr(const art::PtrVector< T > &xs) const
Helper function for implementing overloads.
Definition: BackTracker.h:861
std::vector< std::vector< cheat::NeutrinoEffPur > > SlicesToMCTruthsTable(const std::vector< const rb::Cluster * > &sliceList) const
Given ALL the slices in an event, including the noise slice, returns a vector of vector of structures...
std::vector< NeutrinoEffPur > cheat::BackTracker::SliceToMCTruth ( const std::vector< const rb::CellHit * > &  sliceHits,
const std::vector< const rb::CellHit * > &  allHits,
bool  sortPur = false 
) const

Given a collection of hits (often a slice), returns vector of structures of MCTruth, efficiency, and purity of that neutrino interaction relative to the slice. Efficiency is defined as FLS energy from neutrino interaction in slice / total FLS energy from neutrino interaction in event. This vector is sorted from the highest efficiency interaction to lowest. This function returns all MCTruth, including those without neutrino interactions, i.e. cosmics.

Definition at line 1212 of file BackTracker_service.cc.

References fMCTruthList, HitCollectionEfficiency(), HitCollectionPurity(), MECModelEnuComparisons::i, geo::kXorY, MCTruthToParticles(), demo::particleList, sort_eff(), and sort_pur().

Referenced by showere::ShowerEnergyAna::analyze(), ncid::NCNNKerasVal::analyze(), slid::LIDTraining::analyze(), showere::ShowerEnergyFilterMC::filter(), evd::SliceNavigator::GetProducts(), ncid::NCNNKeras::produce(), SliceToMCTruth(), and SliceToOrderedNuIdsByEnergy().

1215  {
1216  std::vector <NeutrinoEffPur> sliceNeutrinoInteractions;
1217 
1218  for (unsigned int s = 0; s < fMCTruthList.size(); s++){
1219  const art::Ptr<simb::MCTruth> neutrinoInteraction = fMCTruthList[s];
1220 
1221  std::vector<const sim::Particle*> particleList = MCTruthToParticles(neutrinoInteraction);
1222  std::set<int> neutrinoTrackIDs;
1223  for (unsigned int i = 0; i < particleList.size(); ++i){
1224  neutrinoTrackIDs.insert(particleList[i]->TrackId());
1225  }
1226 
1227  double energySlice = -1.0;
1228  double energyTotal = -1.0;
1229  int nSliceHits = 0;
1230  int nTotalHits = 0;
1231 
1232  double sliceEff = HitCollectionEfficiency(neutrinoTrackIDs, sliceHits, allHits, geo::kXorY, 0, true, &energySlice, &energyTotal, &nSliceHits, &nTotalHits);
1233  double slicePur = HitCollectionPurity(neutrinoTrackIDs, sliceHits, 0, 0, true);
1234 
1235  if (sliceEff > 0){
1236  NeutrinoEffPur sliceNeutrinoInteraction = {neutrinoInteraction, sliceEff, slicePur, s, energySlice, energyTotal, nSliceHits, nTotalHits};
1237  sliceNeutrinoInteractions.push_back(sliceNeutrinoInteraction);
1238  }
1239  }//End of loop over neutrino interactions
1240 
1241  if (!sortPur) std::sort(sliceNeutrinoInteractions.begin(),sliceNeutrinoInteractions.end(),sort_eff);
1242  else std::sort(sliceNeutrinoInteractions.begin(),sliceNeutrinoInteractions.end(),sort_pur);
1243 
1244  return sliceNeutrinoInteractions;
1245  }
X or Y views.
Definition: PlaneGeo.h:30
double HitCollectionEfficiency(const std::set< int > &trackIDs, const std::vector< rb::WeightedHit > &whits, const std::vector< const rb::CellHit * > &allhits, const geo::View_t &view, std::map< int, double > *effMap=0, bool energyEff=false, double *desiredEnergy=0, double *totalEnergy=0, int *desiredHits=0, int *totalHits=0) const
Returns the fraction of all energy in an event from a specific set of Geant4 track IDs that are repre...
std::vector< art::Ptr< simb::MCTruth > > fMCTruthList
all the MCTruths for this event
Definition: BackTracker.h:944
const XML_Char * s
Definition: expat.h:262
static bool sort_pur(const NeutrinoEffPur &a, const NeutrinoEffPur &b)
Tool for function SliceToNeutrinoInteractions, tells how to sort by putting structures with highest p...
double HitCollectionPurity(const std::set< int > &trackIDs, const std::vector< rb::WeightedHit > &whits, std::map< int, double > *purMap=0, std::map< int, int > *parents=0, bool energyPur=false) const
Returns the fraction of hits in a collection that come from the specified Geant4 track ids...
static bool sort_eff(const NeutrinoEffPur &a, const NeutrinoEffPur &b)
Tool for function SliceToNeutrinoInteractions, tells how to sort by putting structures with highest e...
particleList
Definition: demo.py:41
std::vector< const sim::Particle * > MCTruthToParticles(art::Ptr< simb::MCTruth > const &mct) const
std::vector<NeutrinoEffPur> cheat::BackTracker::SliceToMCTruth ( const std::vector< rb::CellHit > &  sliceHits,
const std::vector< rb::CellHit > &  allHits,
bool  sortPur = false 
) const
inline

Definition at line 588 of file BackTracker.h.

591  {
592  return SliceToMCTruth(VecToVecRawPtr(sliceHits),
593  VecToVecRawPtr(allHits),
594  sortPur);
595  }
std::vector< const T * > VecToVecRawPtr(const std::vector< T > &xs) const
Definition: BackTracker.h:887
std::vector< NeutrinoEffPur > SliceToMCTruth(const std::vector< const rb::CellHit * > &sliceHits, const std::vector< const rb::CellHit * > &allHits, bool sortPur=false) const
Given a collection of hits (often a slice), returns vector of structures of MCTruth, efficiency, and purity of that neutrino interaction relative to the slice. Efficiency is defined as FLS energy from neutrino interaction in slice / total FLS energy from neutrino interaction in event. This vector is sorted from the highest efficiency interaction to lowest. This function returns all MCTruth, including those without neutrino interactions, i.e. cosmics.
std::vector<NeutrinoEffPur> cheat::BackTracker::SliceToMCTruth ( const std::vector< art::Ptr< rb::CellHit >> &  sliceHits,
const std::vector< art::Ptr< rb::CellHit >> &  allHits,
bool  sortPur = false 
) const
inline

Definition at line 598 of file BackTracker.h.

601  {
602  return SliceToMCTruth(VecPtrToVecRawPtr(sliceHits),
603  VecPtrToVecRawPtr(allHits),
604  sortPur);
605  }
std::vector< const T * > VecPtrToVecRawPtr(const std::vector< art::Ptr< T >> &xs) const
Definition: BackTracker.h:874
std::vector< NeutrinoEffPur > SliceToMCTruth(const std::vector< const rb::CellHit * > &sliceHits, const std::vector< const rb::CellHit * > &allHits, bool sortPur=false) const
Given a collection of hits (often a slice), returns vector of structures of MCTruth, efficiency, and purity of that neutrino interaction relative to the slice. Efficiency is defined as FLS energy from neutrino interaction in slice / total FLS energy from neutrino interaction in event. This vector is sorted from the highest efficiency interaction to lowest. This function returns all MCTruth, including those without neutrino interactions, i.e. cosmics.
std::vector<NeutrinoEffPur> cheat::BackTracker::SliceToMCTruth ( const art::PtrVector< rb::CellHit > &  sliceHits,
const art::PtrVector< rb::CellHit > &  allHits,
bool  sortPur = false 
) const
inline

Definition at line 608 of file BackTracker.h.

611  {
612  return SliceToMCTruth(PtrVecToVecRawPtr(sliceHits),
613  PtrVecToVecRawPtr(allHits),
614  sortPur);
615  }
std::vector< const T * > PtrVecToVecRawPtr(const art::PtrVector< T > &xs) const
Helper function for implementing overloads.
Definition: BackTracker.h:861
std::vector< NeutrinoEffPur > SliceToMCTruth(const std::vector< const rb::CellHit * > &sliceHits, const std::vector< const rb::CellHit * > &allHits, bool sortPur=false) const
Given a collection of hits (often a slice), returns vector of structures of MCTruth, efficiency, and purity of that neutrino interaction relative to the slice. Efficiency is defined as FLS energy from neutrino interaction in slice / total FLS energy from neutrino interaction in event. This vector is sorted from the highest efficiency interaction to lowest. This function returns all MCTruth, including those without neutrino interactions, i.e. cosmics.
std::vector< NeutrinoEffPur > cheat::BackTracker::SliceToMCTruth ( const art::Ptr< rb::Cluster > &  sliceCluster,
const std::vector< const rb::CellHit * > &  allHits,
bool  sortPur = false 
) const

Definition at line 1249 of file BackTracker_service.cc.

References rb::Cluster::AllCells(), PtrVecToVecRawPtr(), SlicesToMCTruthsTable(), and SliceToMCTruth().

1252  {
1253  return SliceToMCTruth(PtrVecToVecRawPtr(sliceCluster->AllCells()),
1254  allHits, sortPur);
1255  }
std::vector< const T * > PtrVecToVecRawPtr(const art::PtrVector< T > &xs) const
Helper function for implementing overloads.
Definition: BackTracker.h:861
art::PtrVector< rb::CellHit > AllCells() const
Get all cells from both views.
Definition: Cluster.cxx:180
std::vector< NeutrinoEffPur > SliceToMCTruth(const std::vector< const rb::CellHit * > &sliceHits, const std::vector< const rb::CellHit * > &allHits, bool sortPur=false) const
Given a collection of hits (often a slice), returns vector of structures of MCTruth, efficiency, and purity of that neutrino interaction relative to the slice. Efficiency is defined as FLS energy from neutrino interaction in slice / total FLS energy from neutrino interaction in event. This vector is sorted from the highest efficiency interaction to lowest. This function returns all MCTruth, including those without neutrino interactions, i.e. cosmics.
std::vector<NeutrinoEffPur> cheat::BackTracker::SliceToMCTruth ( const art::Ptr< rb::Cluster > &  sliceCluster,
const std::vector< rb::CellHit > &  allHits,
bool  sortPur = false 
) const
inline

Definition at line 623 of file BackTracker.h.

626  {
627  return SliceToMCTruth(sliceCluster, VecToVecRawPtr(allHits), sortPur);
628  }
std::vector< const T * > VecToVecRawPtr(const std::vector< T > &xs) const
Definition: BackTracker.h:887
std::vector< NeutrinoEffPur > SliceToMCTruth(const std::vector< const rb::CellHit * > &sliceHits, const std::vector< const rb::CellHit * > &allHits, bool sortPur=false) const
Given a collection of hits (often a slice), returns vector of structures of MCTruth, efficiency, and purity of that neutrino interaction relative to the slice. Efficiency is defined as FLS energy from neutrino interaction in slice / total FLS energy from neutrino interaction in event. This vector is sorted from the highest efficiency interaction to lowest. This function returns all MCTruth, including those without neutrino interactions, i.e. cosmics.
std::vector<NeutrinoEffPur> cheat::BackTracker::SliceToMCTruth ( const art::Ptr< rb::Cluster > &  sliceCluster,
const std::vector< art::Ptr< rb::CellHit >> &  allHits,
bool  sortPur = false 
) const
inline

Definition at line 631 of file BackTracker.h.

634  {
635  return SliceToMCTruth(sliceCluster, VecPtrToVecRawPtr(allHits), sortPur);
636  }
std::vector< const T * > VecPtrToVecRawPtr(const std::vector< art::Ptr< T >> &xs) const
Definition: BackTracker.h:874
std::vector< NeutrinoEffPur > SliceToMCTruth(const std::vector< const rb::CellHit * > &sliceHits, const std::vector< const rb::CellHit * > &allHits, bool sortPur=false) const
Given a collection of hits (often a slice), returns vector of structures of MCTruth, efficiency, and purity of that neutrino interaction relative to the slice. Efficiency is defined as FLS energy from neutrino interaction in slice / total FLS energy from neutrino interaction in event. This vector is sorted from the highest efficiency interaction to lowest. This function returns all MCTruth, including those without neutrino interactions, i.e. cosmics.
std::vector<NeutrinoEffPur> cheat::BackTracker::SliceToMCTruth ( const art::Ptr< rb::Cluster > &  sliceCluster,
const art::PtrVector< rb::CellHit > &  allHits,
bool  sortPur = false 
) const
inline

Definition at line 639 of file BackTracker.h.

642  {
643  return SliceToMCTruth(sliceCluster, PtrVecToVecRawPtr(allHits), sortPur);
644  }
std::vector< const T * > PtrVecToVecRawPtr(const art::PtrVector< T > &xs) const
Helper function for implementing overloads.
Definition: BackTracker.h:861
std::vector< NeutrinoEffPur > SliceToMCTruth(const std::vector< const rb::CellHit * > &sliceHits, const std::vector< const rb::CellHit * > &allHits, bool sortPur=false) const
Given a collection of hits (often a slice), returns vector of structures of MCTruth, efficiency, and purity of that neutrino interaction relative to the slice. Efficiency is defined as FLS energy from neutrino interaction in slice / total FLS energy from neutrino interaction in event. This vector is sorted from the highest efficiency interaction to lowest. This function returns all MCTruth, including those without neutrino interactions, i.e. cosmics.
std::vector< int > cheat::BackTracker::SliceToNeutrinoIndex ( const std::vector< const rb::CellHit * > &  sliceHits,
const std::vector< const rb::CellHit * > &  allHits,
bool  sortPur = false 
) const

Given a collection of hits (often a slice), returns vector of neutrino indices corresponding to the vector from SliceToNeutrinoInteractions.

Definition at line 1016 of file BackTracker_service.cc.

References make_systematics_all::first, fMCTruthList, HitCollectionEfficiency(), HitCollectionPurity(), MECModelEnuComparisons::i, geo::kXorY, make_pair(), MCTruthToParticles(), simb::MCTruth::NeutrinoSet(), demo::particleList, SliceToNeutrinoInteractions(), sort_idxeff(), and sort_idxpur().

Referenced by cvn::HitNuIndex(), and sort_idxpur().

1019  {
1020  std::vector < std::pair<unsigned int,NeutrinoEffPur> > sliceNeutrinoInteractions;
1021 
1022  for (unsigned int s = 0; s < fMCTruthList.size(); s++){
1023  const art::Ptr<simb::MCTruth> neutrinoInteraction = fMCTruthList[s];
1024  if(!neutrinoInteraction->NeutrinoSet())
1025  continue;
1026 
1027  std::vector<const sim::Particle*> particleList = MCTruthToParticles(neutrinoInteraction);
1028  std::set<int> neutrinoTrackIDs;
1029  for (unsigned int i = 0; i < particleList.size(); ++i){
1030  neutrinoTrackIDs.insert(particleList[i]->TrackId());
1031  }
1032 
1033  double energySlice = -1.0;
1034  double energyTotal = -1.0;
1035  int nSliceHits = 0;
1036  int nTotalHits = 0;
1037 
1038  double sliceEff = HitCollectionEfficiency(neutrinoTrackIDs, sliceHits, allHits, geo::kXorY, 0, true, &energySlice, &energyTotal, &nSliceHits, &nTotalHits);
1039  double slicePur = HitCollectionPurity(neutrinoTrackIDs, sliceHits, 0, 0, true);
1040 
1041  if (sliceEff > 0){
1042  NeutrinoEffPur sliceNeutrinoInteraction = {neutrinoInteraction, sliceEff, slicePur, s, energySlice, energyTotal, nSliceHits, nTotalHits};
1043  sliceNeutrinoInteractions.push_back( std::make_pair(s,sliceNeutrinoInteraction) );
1044  }
1045  }//End of loop over neutrino interactions
1046 
1047  if (!sortPur) std::sort(sliceNeutrinoInteractions.begin(),sliceNeutrinoInteractions.end(),sort_idxeff);
1048  else std::sort(sliceNeutrinoInteractions.begin(),sliceNeutrinoInteractions.end(),sort_idxpur);
1049 
1050  std::vector<int> nuIndex;
1051 
1052  for (unsigned int i = 0; i<sliceNeutrinoInteractions.size(); ++i ){
1053  nuIndex.push_back( int(sliceNeutrinoInteractions[i].first) );
1054  }
1055 
1056  return nuIndex;
1057  }
static bool sort_idxeff(const std::pair< int, NeutrinoEffPur > &a, const std::pair< int, NeutrinoEffPur > &b)
Tool for function SliceToNeutrinoIndex, tells how to sort by putting structures with highest efficien...
X or Y views.
Definition: PlaneGeo.h:30
static bool sort_idxpur(const std::pair< int, NeutrinoEffPur > &a, const std::pair< int, NeutrinoEffPur > &b)
Tool for function SliceToNeutrinoIndex, tells how to sort by putting structures with highest purity f...
std::pair< Spectrum *, CheatDecomp * > make_pair(SpectrumLoaderBase &loader_data, SpectrumLoaderBase &loader_mc, HistAxis *axis, Cut *cut, const SystShifts &shift, const Var &wei)
Definition: DataMCLoad.C:335
double HitCollectionEfficiency(const std::set< int > &trackIDs, const std::vector< rb::WeightedHit > &whits, const std::vector< const rb::CellHit * > &allhits, const geo::View_t &view, std::map< int, double > *effMap=0, bool energyEff=false, double *desiredEnergy=0, double *totalEnergy=0, int *desiredHits=0, int *totalHits=0) const
Returns the fraction of all energy in an event from a specific set of Geant4 track IDs that are repre...
std::vector< art::Ptr< simb::MCTruth > > fMCTruthList
all the MCTruths for this event
Definition: BackTracker.h:944
const XML_Char * s
Definition: expat.h:262
double HitCollectionPurity(const std::set< int > &trackIDs, const std::vector< rb::WeightedHit > &whits, std::map< int, double > *purMap=0, std::map< int, int > *parents=0, bool energyPur=false) const
Returns the fraction of hits in a collection that come from the specified Geant4 track ids...
particleList
Definition: demo.py:41
bool NeutrinoSet() const
Definition: MCTruth.h:77
std::vector< const sim::Particle * > MCTruthToParticles(art::Ptr< simb::MCTruth > const &mct) const
std::vector< NeutrinoEffPur > cheat::BackTracker::SliceToNeutrinoInteractions ( const std::vector< const rb::CellHit * > &  sliceHits,
const std::vector< const rb::CellHit * > &  allHits,
bool  sortPur = false 
) const

Given a collection of hits (often a slice), returns vector of structures of neutrino interactions, efficiency, and purity of that neutrino interaction relative to the slice. Efficiency is defined as FLS energy from neutrino interaction in slice / total FLS energy from neutrino interaction in event. This vector is sorted from the highest efficiency interaction to lowest.

Definition at line 1062 of file BackTracker_service.cc.

References fMCTruthList, HitCollectionEfficiency(), HitCollectionPurity(), MECModelEnuComparisons::i, geo::kXorY, MCTruthToParticles(), simb::MCTruth::NeutrinoSet(), demo::particleList, sort_eff(), and sort_pur().

Referenced by qeef::QeFinderVal::analyze(), remid::ReMIdValidate::analyze(), remid::ReMIdTrain::analyze(), numue::NumuEAna::analyze(), murem::MuonRemoveAna::analyze(), remid::ReMIdDedx::analyze(), showere::ShowerEnergyAna::analyze(), remid::ReMIdDedxRock::analyze(), remid::ReMIdDedxStudies::analyze(), ncs::Xbeam::analyze(), ncs::Xeff::analyze(), ncs::NCAna::analyze(), nuesand::FillNueSandbox::FillTruthVars(), numue::NumuEAlg::MCTruthEnergyVariables(), SliceToNeutrinoIndex(), and SliceToNeutrinoInteractions().

1065  {
1066  std::vector <NeutrinoEffPur> sliceNeutrinoInteractions;
1067 
1068  for (unsigned int s = 0; s < fMCTruthList.size(); s++){
1069  const art::Ptr<simb::MCTruth> neutrinoInteraction = fMCTruthList[s];
1070  if(!neutrinoInteraction->NeutrinoSet())
1071  continue;
1072 
1073  std::vector<const sim::Particle*> particleList = MCTruthToParticles(neutrinoInteraction);
1074  std::set<int> neutrinoTrackIDs;
1075  for (unsigned int i = 0; i < particleList.size(); ++i){
1076  neutrinoTrackIDs.insert(particleList[i]->TrackId());
1077  }
1078 
1079  double energySlice = -1.0;
1080  double energyTotal = -1.0;
1081  int nSliceHits = 0;
1082  int nTotalHits = 0;
1083 
1084  double sliceEff = HitCollectionEfficiency(neutrinoTrackIDs, sliceHits, allHits, geo::kXorY, 0, true, &energySlice, &energyTotal, &nSliceHits, &nTotalHits);
1085  double slicePur = HitCollectionPurity(neutrinoTrackIDs, sliceHits, 0, 0, true);
1086 
1087  if (sliceEff > 0){
1088  NeutrinoEffPur sliceNeutrinoInteraction = {neutrinoInteraction, sliceEff, slicePur, s, energySlice, energyTotal, nSliceHits, nTotalHits};
1089  sliceNeutrinoInteractions.push_back(sliceNeutrinoInteraction);
1090  }
1091  }//End of loop over neutrino interactions
1092 
1093  if (!sortPur) std::sort(sliceNeutrinoInteractions.begin(),sliceNeutrinoInteractions.end(),sort_eff);
1094  else std::sort(sliceNeutrinoInteractions.begin(),sliceNeutrinoInteractions.end(),sort_pur);
1095 
1096  return sliceNeutrinoInteractions;
1097  }
X or Y views.
Definition: PlaneGeo.h:30
double HitCollectionEfficiency(const std::set< int > &trackIDs, const std::vector< rb::WeightedHit > &whits, const std::vector< const rb::CellHit * > &allhits, const geo::View_t &view, std::map< int, double > *effMap=0, bool energyEff=false, double *desiredEnergy=0, double *totalEnergy=0, int *desiredHits=0, int *totalHits=0) const
Returns the fraction of all energy in an event from a specific set of Geant4 track IDs that are repre...
std::vector< art::Ptr< simb::MCTruth > > fMCTruthList
all the MCTruths for this event
Definition: BackTracker.h:944
const XML_Char * s
Definition: expat.h:262
static bool sort_pur(const NeutrinoEffPur &a, const NeutrinoEffPur &b)
Tool for function SliceToNeutrinoInteractions, tells how to sort by putting structures with highest p...
double HitCollectionPurity(const std::set< int > &trackIDs, const std::vector< rb::WeightedHit > &whits, std::map< int, double > *purMap=0, std::map< int, int > *parents=0, bool energyPur=false) const
Returns the fraction of hits in a collection that come from the specified Geant4 track ids...
static bool sort_eff(const NeutrinoEffPur &a, const NeutrinoEffPur &b)
Tool for function SliceToNeutrinoInteractions, tells how to sort by putting structures with highest e...
particleList
Definition: demo.py:41
bool NeutrinoSet() const
Definition: MCTruth.h:77
std::vector< const sim::Particle * > MCTruthToParticles(art::Ptr< simb::MCTruth > const &mct) const
std::vector<NeutrinoEffPur> cheat::BackTracker::SliceToNeutrinoInteractions ( const std::vector< rb::CellHit > &  sliceHits,
const std::vector< rb::CellHit > &  allHits,
bool  sortPur = false 
) const
inline

Definition at line 492 of file BackTracker.h.

495  {
497  VecToVecRawPtr(allHits),
498  sortPur);
499  }
std::vector< NeutrinoEffPur > SliceToNeutrinoInteractions(const std::vector< const rb::CellHit * > &sliceHits, const std::vector< const rb::CellHit * > &allHits, bool sortPur=false) const
Given a collection of hits (often a slice), returns vector of structures of neutrino interactions...
std::vector< const T * > VecToVecRawPtr(const std::vector< T > &xs) const
Definition: BackTracker.h:887
std::vector<NeutrinoEffPur> cheat::BackTracker::SliceToNeutrinoInteractions ( const std::vector< art::Ptr< rb::CellHit >> &  sliceHits,
const std::vector< art::Ptr< rb::CellHit >> &  allHits,
bool  sortPur = false 
) const
inline

Definition at line 502 of file BackTracker.h.

505  {
507  VecPtrToVecRawPtr(allHits),
508  sortPur);
509  }
std::vector< const T * > VecPtrToVecRawPtr(const std::vector< art::Ptr< T >> &xs) const
Definition: BackTracker.h:874
std::vector< NeutrinoEffPur > SliceToNeutrinoInteractions(const std::vector< const rb::CellHit * > &sliceHits, const std::vector< const rb::CellHit * > &allHits, bool sortPur=false) const
Given a collection of hits (often a slice), returns vector of structures of neutrino interactions...
std::vector<NeutrinoEffPur> cheat::BackTracker::SliceToNeutrinoInteractions ( const art::PtrVector< rb::CellHit > &  sliceHits,
const art::PtrVector< rb::CellHit > &  allHits,
bool  sortPur = false 
) const
inline

Definition at line 512 of file BackTracker.h.

515  {
517  PtrVecToVecRawPtr(allHits),
518  sortPur);
519  }
std::vector< const T * > PtrVecToVecRawPtr(const art::PtrVector< T > &xs) const
Helper function for implementing overloads.
Definition: BackTracker.h:861
std::vector< NeutrinoEffPur > SliceToNeutrinoInteractions(const std::vector< const rb::CellHit * > &sliceHits, const std::vector< const rb::CellHit * > &allHits, bool sortPur=false) const
Given a collection of hits (often a slice), returns vector of structures of neutrino interactions...
std::vector< NeutrinoEffPur > cheat::BackTracker::SliceToNeutrinoInteractions ( const art::Ptr< rb::Cluster > &  sliceCluster,
const std::vector< const rb::CellHit * > &  allHits,
bool  sortPur = false 
) const

Definition at line 1101 of file BackTracker_service.cc.

References rb::Cluster::AllCells(), PtrVecToVecRawPtr(), SliceToNeutrinoInteractions(), and SliceToOrderedNuIds().

1104  {
1105  return SliceToNeutrinoInteractions(PtrVecToVecRawPtr(sliceCluster->AllCells()),
1106  allHits, sortPur);
1107  }
std::vector< const T * > PtrVecToVecRawPtr(const art::PtrVector< T > &xs) const
Helper function for implementing overloads.
Definition: BackTracker.h:861
std::vector< NeutrinoEffPur > SliceToNeutrinoInteractions(const std::vector< const rb::CellHit * > &sliceHits, const std::vector< const rb::CellHit * > &allHits, bool sortPur=false) const
Given a collection of hits (often a slice), returns vector of structures of neutrino interactions...
art::PtrVector< rb::CellHit > AllCells() const
Get all cells from both views.
Definition: Cluster.cxx:180
std::vector<NeutrinoEffPur> cheat::BackTracker::SliceToNeutrinoInteractions ( const art::Ptr< rb::Cluster > &  sliceCluster,
const std::vector< rb::CellHit > &  allHits,
bool  sortPur = false 
) const
inline

Definition at line 527 of file BackTracker.h.

530  {
531  return SliceToNeutrinoInteractions(sliceCluster,
532  VecToVecRawPtr(allHits),
533  sortPur);
534  }
std::vector< NeutrinoEffPur > SliceToNeutrinoInteractions(const std::vector< const rb::CellHit * > &sliceHits, const std::vector< const rb::CellHit * > &allHits, bool sortPur=false) const
Given a collection of hits (often a slice), returns vector of structures of neutrino interactions...
std::vector< const T * > VecToVecRawPtr(const std::vector< T > &xs) const
Definition: BackTracker.h:887
std::vector<NeutrinoEffPur> cheat::BackTracker::SliceToNeutrinoInteractions ( const art::Ptr< rb::Cluster > &  sliceCluster,
const std::vector< art::Ptr< rb::CellHit >> &  allHits,
bool  sortPur = false 
) const
inline

Definition at line 537 of file BackTracker.h.

540  {
541  return SliceToNeutrinoInteractions(sliceCluster,
542  VecPtrToVecRawPtr(allHits),
543  sortPur);
544  }
std::vector< const T * > VecPtrToVecRawPtr(const std::vector< art::Ptr< T >> &xs) const
Definition: BackTracker.h:874
std::vector< NeutrinoEffPur > SliceToNeutrinoInteractions(const std::vector< const rb::CellHit * > &sliceHits, const std::vector< const rb::CellHit * > &allHits, bool sortPur=false) const
Given a collection of hits (often a slice), returns vector of structures of neutrino interactions...
std::vector<NeutrinoEffPur> cheat::BackTracker::SliceToNeutrinoInteractions ( const art::Ptr< rb::Cluster > &  sliceCluster,
const art::PtrVector< rb::CellHit > &  allHits,
bool  sortPur = false 
) const
inline

Definition at line 547 of file BackTracker.h.

550  {
551  return SliceToNeutrinoInteractions(sliceCluster,
552  PtrVecToVecRawPtr(allHits),
553  sortPur);
554  }
std::vector< const T * > PtrVecToVecRawPtr(const art::PtrVector< T > &xs) const
Helper function for implementing overloads.
Definition: BackTracker.h:861
std::vector< NeutrinoEffPur > SliceToNeutrinoInteractions(const std::vector< const rb::CellHit * > &sliceHits, const std::vector< const rb::CellHit * > &allHits, bool sortPur=false) const
Given a collection of hits (often a slice), returns vector of structures of neutrino interactions...
std::vector< int > cheat::BackTracker::SliceToOrderedNuIds ( const std::vector< cheat::NeutrinoWithIndex > &  nusWithIdx,
const std::vector< std::vector< cheat::NeutrinoEffPur >> &  slTruthTable,
std::function< double(const cheat::NeutrinoEffPur &)>  slMetric,
std::function< double(const cheat::NeutrinoEffPur &)>  nuMetric 
) const

Given a vector of indexed neutrino interaction and a vector of slice truth tables, returns a vector of neutrino interaction indices ordered by best match to the corresponding slice. Here, best match is determined according to the given cheat::NeutrinoEffPur functions for the slice and the nu.

Definition at line 1111 of file BackTracker_service.cc.

References art::Ptr< T >::isNull(), cheat::NeutrinoEffPur::neutrinoInt, and SliceToOrderedNuIdsByEff().

Referenced by tut::RecoValidationTutorial::analyze(), bpf::BPFCVNAna::analyze(), caf::CAFMaker::produce(), skim::SkimmingUtils::SliceMCTruthAssociation(), SliceToNeutrinoInteractions(), SliceToOrderedNuIdsByEff(), SliceToOrderedNuIdsByEffPur(), SliceToOrderedNuIdsByEnergy(), and SliceToOrderedNuIdsByPur().

1115  {
1116 
1117  for( auto slc: slTruthTable )
1118  assert( slc.size() == nusWithIdx.size() && "Badly shaped Slice/truth table!" );
1119 
1120  // Fill with one Nu Id per slice
1121  std::vector<int> nuIds( slTruthTable.size(), -1 );
1122  if( nusWithIdx.empty() ) return nuIds;
1123 
1124  // Find the best slice for each nu
1125  std::vector<int> bestSlices( nusWithIdx.size() );
1126  for( size_t nuIdx = 0; nuIdx < nusWithIdx.size(); ++nuIdx ){
1127  float maxValue = 0;
1128  int bestSlice = -1;
1129 
1130  for( size_t sliceIdx = 0; sliceIdx < slTruthTable.size(); ++sliceIdx ){
1131  const cheat::NeutrinoEffPur& effpur = slTruthTable[sliceIdx][nuIdx];
1132 
1133  if( !effpur.neutrinoInt.isNull() ){
1134  if( slMetric(effpur) > maxValue ){
1135  maxValue = slMetric(effpur);
1136  bestSlice = sliceIdx;
1137  }
1138  }
1139 
1140  } //sliceIdx
1141 
1142  bestSlices[nuIdx] = bestSlice;
1143 
1144  } // nuIdx
1145 
1146  // Find the best nu for each slice.
1147  for( size_t sliceIdx = 0; sliceIdx < slTruthTable.size(); ++sliceIdx ){
1148  float maxValue = 0;
1149  int bestNu = -1;
1150 
1151  for( size_t nuIdx = 0; nuIdx < slTruthTable[sliceIdx].size(); ++nuIdx ){
1152  const cheat::NeutrinoEffPur& effpur = slTruthTable[sliceIdx][nuIdx];
1153 
1154  if( !effpur.neutrinoInt.isNull() ){
1155  if( nuMetric(effpur) > maxValue ){
1156  maxValue = nuMetric(effpur);
1157  bestNu = nuIdx;
1158  }
1159  }
1160  } //nuIdx
1161 
1162  if( bestNu >= 0 && bestSlices[bestNu] == (int)sliceIdx )
1163  nuIds[sliceIdx] = bestNu;
1164 
1165  }//sliceIdx
1166 
1167  return nuIds;
1168  }
bool isNull() const
Definition: Ptr.h:328
art::Ptr< simb::MCTruth > neutrinoInt
Truth information about neutrino interaction.
Definition: BackTracker.h:47
std::vector< int > cheat::BackTracker::SliceToOrderedNuIdsByEff ( const std::vector< cheat::NeutrinoWithIndex > &  nusWithIdx,
const std::vector< std::vector< cheat::NeutrinoEffPur >> &  slTruthTable 
) const

Definition at line 1172 of file BackTracker_service.cc.

References cheat::EffMetric(), SliceToOrderedNuIds(), and SliceToOrderedNuIdsByPur().

Referenced by earms::ElasticArmsValidate::analyze(), fuzz::FuzzyKValidate::analyze(), slid::LIDTraining::analyze(), fuzz::FuzzyKVertex::produce(), and SliceToOrderedNuIds().

1174  {
1175 
1176  return SliceToOrderedNuIds(nusWithIdx, slTruthTable, EffMetric, EffMetric);
1177 
1178  }
std::vector< int > SliceToOrderedNuIds(const std::vector< cheat::NeutrinoWithIndex > &nusWithIdx, const std::vector< std::vector< cheat::NeutrinoEffPur >> &slTruthTable, std::function< double(const cheat::NeutrinoEffPur &)> slMetric, std::function< double(const cheat::NeutrinoEffPur &)> nuMetric) const
Given a vector of indexed neutrino interaction and a vector of slice truth tables, returns a vector of neutrino interaction indices ordered by best match to the corresponding slice. Here, best match is determined according to the given cheat::NeutrinoEffPur functions for the slice and the nu.
double EffMetric(const cheat::NeutrinoEffPur &ep)
Function for NeutrinoEffPur&#39;s nu interaction to slice efficiency.
std::vector< int > cheat::BackTracker::SliceToOrderedNuIdsByEffPur ( const std::vector< cheat::NeutrinoWithIndex > &  nusWithIdx,
const std::vector< std::vector< cheat::NeutrinoEffPur >> &  slTruthTable 
) const

Definition at line 1192 of file BackTracker_service.cc.

References cheat::EffPurMetric(), SliceToOrderedNuIds(), and SliceToOrderedNuIdsByEnergy().

Referenced by SliceToOrderedNuIdsByPur().

1194  {
1195 
1196  return SliceToOrderedNuIds(nusWithIdx, slTruthTable, EffPurMetric, EffPurMetric);
1197 
1198  }
std::vector< int > SliceToOrderedNuIds(const std::vector< cheat::NeutrinoWithIndex > &nusWithIdx, const std::vector< std::vector< cheat::NeutrinoEffPur >> &slTruthTable, std::function< double(const cheat::NeutrinoEffPur &)> slMetric, std::function< double(const cheat::NeutrinoEffPur &)> nuMetric) const
Given a vector of indexed neutrino interaction and a vector of slice truth tables, returns a vector of neutrino interaction indices ordered by best match to the corresponding slice. Here, best match is determined according to the given cheat::NeutrinoEffPur functions for the slice and the nu.
double EffPurMetric(const cheat::NeutrinoEffPur &ep)
Function for NeutrinoEffPur&#39;s nu interaction to slice efficiency * purity.
std::vector< int > cheat::BackTracker::SliceToOrderedNuIdsByEnergy ( const std::vector< cheat::NeutrinoWithIndex > &  nusWithIdx,
const std::vector< std::vector< cheat::NeutrinoEffPur >> &  slTruthTable 
) const

Definition at line 1202 of file BackTracker_service.cc.

References cheat::EnergyMetric(), SliceToMCTruth(), and SliceToOrderedNuIds().

Referenced by cvn::CVNEventDump::analyze(), cvn::CVNCosmicEventDump::analyze(), cvn::CVNEventProngDump::analyze(), cvn::CVNAddTrainingData::produce(), and SliceToOrderedNuIdsByEffPur().

1204  {
1205 
1206  return SliceToOrderedNuIds(nusWithIdx, slTruthTable, EnergyMetric, EnergyMetric);
1207 
1208  }
std::vector< int > SliceToOrderedNuIds(const std::vector< cheat::NeutrinoWithIndex > &nusWithIdx, const std::vector< std::vector< cheat::NeutrinoEffPur >> &slTruthTable, std::function< double(const cheat::NeutrinoEffPur &)> slMetric, std::function< double(const cheat::NeutrinoEffPur &)> nuMetric) const
Given a vector of indexed neutrino interaction and a vector of slice truth tables, returns a vector of neutrino interaction indices ordered by best match to the corresponding slice. Here, best match is determined according to the given cheat::NeutrinoEffPur functions for the slice and the nu.
double EnergyMetric(const cheat::NeutrinoEffPur &ep)
Function for NeutrinoEffPur&#39;s nu interaction to slice energy.
std::vector< int > cheat::BackTracker::SliceToOrderedNuIdsByPur ( const std::vector< cheat::NeutrinoWithIndex > &  nusWithIdx,
const std::vector< std::vector< cheat::NeutrinoEffPur >> &  slTruthTable 
) const

Definition at line 1182 of file BackTracker_service.cc.

References cheat::PurMetric(), SliceToOrderedNuIds(), and SliceToOrderedNuIdsByEffPur().

Referenced by SliceToOrderedNuIdsByEff().

1184  {
1185 
1186  return SliceToOrderedNuIds(nusWithIdx, slTruthTable, PurMetric, PurMetric);
1187 
1188  }
std::vector< int > SliceToOrderedNuIds(const std::vector< cheat::NeutrinoWithIndex > &nusWithIdx, const std::vector< std::vector< cheat::NeutrinoEffPur >> &slTruthTable, std::function< double(const cheat::NeutrinoEffPur &)> slMetric, std::function< double(const cheat::NeutrinoEffPur &)> nuMetric) const
Given a vector of indexed neutrino interaction and a vector of slice truth tables, returns a vector of neutrino interaction indices ordered by best match to the corresponding slice. Here, best match is determined according to the given cheat::NeutrinoEffPur functions for the slice and the nu.
double PurMetric(const cheat::NeutrinoEffPur &ep)
Function for NeutrinoEffPur&#39;s nu interaction to slice purity.
bool cheat::BackTracker::sort_eff ( const NeutrinoEffPur a,
const NeutrinoEffPur b 
)
static

Tool for function SliceToNeutrinoInteractions, tells how to sort by putting structures with highest efficiency first.

Definition at line 997 of file BackTracker_service.cc.

References cheat::NeutrinoEffPur::efficiency.

Referenced by SliceToMCTruth(), and SliceToNeutrinoInteractions().

997  {
998  return a.efficiency>b.efficiency;
999  }
const double a
const hit & b
Definition: hits.cxx:21
bool cheat::BackTracker::sort_idxeff ( const std::pair< int, NeutrinoEffPur > &  a,
const std::pair< int, NeutrinoEffPur > &  b 
)
static

Tool for function SliceToNeutrinoIndex, tells how to sort by putting structures with highest efficiency first.

Definition at line 1006 of file BackTracker_service.cc.

Referenced by SliceToNeutrinoIndex().

1006  {
1007  return a.second.efficiency>b.second.efficiency;
1008  }
const double a
const hit & b
Definition: hits.cxx:21
bool cheat::BackTracker::sort_idxpur ( const std::pair< int, NeutrinoEffPur > &  a,
const std::pair< int, NeutrinoEffPur > &  b 
)
static

Tool for function SliceToNeutrinoIndex, tells how to sort by putting structures with highest purity first.

Definition at line 1010 of file BackTracker_service.cc.

References SliceToNeutrinoIndex().

Referenced by SliceToNeutrinoIndex().

1010  {
1011  return a.second.purity>b.second.purity;
1012  }
const double a
const hit & b
Definition: hits.cxx:21
bool cheat::BackTracker::sort_pur ( const NeutrinoEffPur a,
const NeutrinoEffPur b 
)
static

Tool for function SliceToNeutrinoInteractions, tells how to sort by putting structures with highest purity first.

Definition at line 1002 of file BackTracker_service.cc.

References cheat::NeutrinoEffPur::purity.

Referenced by SliceToMCTruth(), and SliceToNeutrinoInteractions().

1002  {
1003  return a.purity>b.purity;
1004  }
const double a
const hit & b
Definition: hits.cxx:21
const art::Ptr< simb::MCTruth > & cheat::BackTracker::TrackIDToMCTruth ( int const &  id) const

Definition at line 505 of file BackTracker_service.cc.

References fMCTruthList, and fTrackIDToMCTruthIndex.

Referenced by caf::CAFMaker::AddMCTruthToVec(), cheat::CheckBackTracking::CheckTrackIdToParticle(), MCTruthToParticles(), and ParticleToMCTruth().

506  {
507  // find the entry in the MCTruth collection for this track id
508  size_t mct = fTrackIDToMCTruthIndex.find(abs(id))->second;
509 
510  if (mct > fMCTruthList.size() ) {
511  throw cet::exception("BackTracker")
512  << "attempting to find MCTruth index for "
513  << "out of range value: " << mct
514  << "/" << fMCTruthList.size() << "\n"
515  << __FILE__ << ":" << __LINE__ << "\n";
516  }
517  return fMCTruthList[mct];
518  }
::xsd::cxx::tree::exception< char > exception
Definition: Database.h:225
std::vector< art::Ptr< simb::MCTruth > > fMCTruthList
all the MCTruths for this event
Definition: BackTracker.h:944
std::map< int, int > fTrackIDToMCTruthIndex
map of track id values to MCTruthList entry
Definition: BackTracker.h:945
const sim::Particle * cheat::BackTracker::TrackIDToMotherParticle ( int const &  id) const

Definition at line 496 of file BackTracker_service.cc.

References sim::ParticleNavigator::EveId(), fParticleNav, and TrackIDToParticle().

Referenced by remid::ReMIdTrain::analyze(), numue::NumuEAna::analyze(), fuzz::FuzzyKValidate::analyze(), trk::KalmanTrackAna::CheckRecoTracks(), cheat::CheckBackTracking::CheckTrackIdToParticle(), caf::FillParticleTruth(), numue::NumuEAlg::MCTruthEnergyVariables(), and murem::MergeTruth::produce().

497  {
498  // get the mother id from the particle navigator
499  // the EveId was adopted in the Rebuild method
500 
501  return this->TrackIDToParticle(fParticleNav.EveId(abs(id)));
502  }
sim::ParticleNavigator fParticleNav
Particle navigator to map track ID to Particle.
Definition: BackTracker.h:942
const sim::Particle * TrackIDToParticle(int const &id) const
Returns a pointer to the sim::Particle object corresponding to the given TrackID. ...
int EveId(const int trackID) const
const sim::Particle * cheat::BackTracker::TrackIDToParticle ( int const &  id) const

Returns a pointer to the sim::Particle object corresponding to the given TrackID.

Definition at line 481 of file BackTracker_service.cc.

References sim::ParticleNavigator::end(), sim::ParticleNavigator::find(), and fParticleNav.

Referenced by caf::CAFMaker::AddMCTruthToVec(), caf::AddParticleToVec(), cheat::TestTrackIds::analyze(), remid::ReMIdValidate::analyze(), sn::SNBackgroundRejectionAna::analyze(), calib::ParticleCorrections::analyze(), numue::NumuEAna::analyze(), showere::ShowerEnergyAna::analyze(), bpfit::BreakPointProtonAna::analyze(), slid::LIDTraining::analyze(), CalcDaughterEscapingEnergy(), cheat::RecoCheckAna::CheckRecoClusters(), trk::KalmanTrackAna::CheckRecoTracks(), cheat::CheckBackTracking::CheckTrackIdToParticle(), ClusterToParticle(), caf::FillParticleTruth(), calib::EnergyStandardCandles::FillTrueMichelInfo(), calib::EnergyStandardCandles::FillTruthInfo(), showere::ShowerEnergyFilterMC::filter(), caf::FindAndAddMichels(), caf::FindDaughterVisE(), calib::EnergyStandardCandles::FindStoppingMuons(), calib::EnergyStandardCandles::FixPhotonAncestry(), cvn::Get2DProngEfficiencyByPDG(), cvn::Get2DProngEnergyByPDG(), cvn::Get2DProngPurityByPDG(), cvn::GetProngEfficiencyByPDG(), cvn::GetProngEnergyByPDG(), cvn::GetProngPurityByPDG(), cvn::HitClassify(), HitsToParticle(), HitToParticle(), caf::IsTrueDiF(), numue::NumuEAlg::MCTruthEnergyVariables(), lem::MakeLibrary::produce(), cvn::ProngClassify(), TrackIDToMotherParticle(), and TracksToParticles().

482  {
484 
485  if(part_it == fParticleNav.end()){
486  mf::LogWarning("BackTracker") << "can't find particle with track id "
487  << id << " in sim::ParticleNavigator"
488  << " returning null pointer";
489  return 0;
490  }
491 
492  return part_it->second;
493  }
list_type::const_iterator const_iterator
sim::ParticleNavigator fParticleNav
Particle navigator to map track ID to Particle.
Definition: BackTracker.h:942
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
iterator find(const key_type &key)
std::vector< ParticleEffPur > cheat::BackTracker::TracksToParticles ( const std::vector< const rb::Track * > &  tracks,
const std::set< int > &  trkIDs,
const std::set< int > &  allowedDaughters,
const std::vector< const rb::CellHit * > &  allHits 
) const

Given a collection of reconstructed tracks, this method finds the best match for each reco track to the input track id particles.

For each reconstructed track, the true particle that best matches the track by purity from the input trkIDs is determined. Each input track ID is only allowed to match at most one input track and any track IDs specified in the input allowedDaughters are not counted against a tracks purity. The tracks are matched to particles in the order that they appear in the input vector. Each entry in the returned vector of ParticleEffPur corresponds to the track in the same position as the input track vector and holds the matched track id, efficiency, purity, and pdg of the best matched particle for the given track. If no track id is found to match the track, then the purity, efficiency, and pdg will be zero. You need to check that a match exists before trying to use the matched track id in other functions

Definition at line 1361 of file BackTracker_service.cc.

References simb::MCParticle::Daughter(), HitCollectionEfficiency(), HitCollectionPurity(), MECModelEnuComparisons::i, ideff, it, geo::kXorY, cafExposure::match, overlay_prestage_def::matches, simb::MCParticle::NumberDaughters(), genie::utils::res::PdgCode(), simb::MCParticle::PdgCode(), PtrVecToVecRawPtr(), and TrackIDToParticle().

Referenced by remid::ReMIdTrain::analyze(), and SlicesToMCTruthsTable().

1365  {
1366  std::vector<ParticleEffPur> matches;
1367 
1368  std::set<int> trkIDs = trackIDs;
1369  std::set<int> allowedDaughters = allowedDaughterIDs;
1370 
1371  std::map<int, int> parents;
1372  for(std::set<int>::iterator it = trkIDs.begin(); it != trkIDs.end(); ++it){
1373  const sim::Particle* mother = TrackIDToParticle(*it);
1374  if(!mother) continue;
1375  for(int i = 0; i < mother->NumberDaughters(); ++i){
1376  const int id = mother->Daughter(i);
1377  assert(TrackIDToParticle(id));
1378  if(allowedDaughters.count(TrackIDToParticle(id)->PdgCode())){
1379  parents[id] = *it;
1380  }
1381  } // end for i
1382  } // end for it
1383 
1384  // loop over all tracks
1385  for(unsigned int itrack = 0; itrack < tracks.size(); ++itrack){
1386  // get the purity of the track for all track IDs
1387  std::map<int, double> purs;
1388  HitCollectionPurity(trkIDs,tracks[itrack]->AllCells(),&purs,&parents);
1389  // find the most pure trackID for this track
1390  int bestid = -1;
1391  double bestpur = 0.0;
1392  for(std::set<int>::iterator it = trkIDs.begin(); it != trkIDs.end(); ++it){
1393  const double p = purs[*it];
1394  if(p > bestpur){
1395  bestpur = p;
1396  bestid = *it;
1397  }
1398  } // end of loop over track ids
1399 
1400  // update this tracks info for the matched true particle
1401  double recoPur = bestpur;
1402  int recotrkid = bestid;
1403  int recopdg = 0;
1404  double recoEff = 0.0;
1405  if(bestpur > 0.0){
1406  // found a real particle that matched the track, update pdg and efficiency to match this
1407  recopdg = TrackIDToParticle(recotrkid)->PdgCode();
1408  std::set<int> ideff;
1409  ideff.insert(recotrkid);
1410  recoEff = HitCollectionEfficiency(ideff,
1411  PtrVecToVecRawPtr(tracks[itrack]->AllCells()),
1412  allHits, geo::kXorY);
1413  // remove this track id from the set of track ids so no other tracks can try to match to it
1414  trkIDs.erase(trkIDs.find(recotrkid));
1415  // remove any instance where this track id is the parent particle in the parents map
1416  std::map<int, int>::iterator parentsIt = parents.begin();
1417  while(parentsIt != parents.end()){
1418  if(parentsIt->second == recotrkid){ parents.erase(parentsIt++); }
1419  else{ ++parentsIt; }
1420  }
1421  }
1422  // record this tracks match
1423  ParticleEffPur match = {recotrkid, recoEff, recoPur, recopdg};
1424  matches.push_back(match);
1425  } // end of loop over tracks for matching to truth
1426 
1427  return matches;
1428 
1429  }
::xsd::cxx::tree::id< char, ncname > id
Definition: Database.h:165
int PdgCode() const
Definition: MCParticle.h:211
std::vector< const T * > PtrVecToVecRawPtr(const art::PtrVector< T > &xs) const
Helper function for implementing overloads.
Definition: BackTracker.h:861
set< int >::iterator it
X or Y views.
Definition: PlaneGeo.h:30
const char * p
Definition: xmltok.h:285
int NumberDaughters() const
Definition: MCParticle.h:216
double HitCollectionEfficiency(const std::set< int > &trackIDs, const std::vector< rb::WeightedHit > &whits, const std::vector< const rb::CellHit * > &allhits, const geo::View_t &view, std::map< int, double > *effMap=0, bool energyEff=false, double *desiredEnergy=0, double *totalEnergy=0, int *desiredHits=0, int *totalHits=0) const
Returns the fraction of all energy in an event from a specific set of Geant4 track IDs that are repre...
int Daughter(const int i) const
Definition: MCParticle.cxx:112
int PdgCode(Resonance_t res, int Q)
(resonance id, charge) -> PDG code
double HitCollectionPurity(const std::set< int > &trackIDs, const std::vector< rb::WeightedHit > &whits, std::map< int, double > *purMap=0, std::map< int, int > *parents=0, bool energyPur=false) const
Returns the fraction of hits in a collection that come from the specified Geant4 track ids...
const sim::Particle * TrackIDToParticle(int const &id) const
Returns a pointer to the sim::Particle object corresponding to the given TrackID. ...
double ideff[10]
Definition: Xdiff_gwt.C:104
std::vector<ParticleEffPur> cheat::BackTracker::TracksToParticles ( const std::vector< rb::Track > &  tracks,
const std::set< int > &  trkIDs,
const std::set< int > &  allowedDaughters,
const std::vector< rb::CellHit > &  allHits 
) const
inline

Definition at line 694 of file BackTracker.h.

698  {
699  return TracksToParticles(VecToVecRawPtr(tracks),
700  trkIDs, allowedDaughters,
701  VecToVecRawPtr(allHits));
702  }
std::vector< const T * > VecToVecRawPtr(const std::vector< T > &xs) const
Definition: BackTracker.h:887
std::vector< ParticleEffPur > TracksToParticles(const std::vector< const rb::Track * > &tracks, const std::set< int > &trkIDs, const std::set< int > &allowedDaughters, const std::vector< const rb::CellHit * > &allHits) const
Given a collection of reconstructed tracks, this method finds the best match for each reco track to t...
std::vector<ParticleEffPur> cheat::BackTracker::TracksToParticles ( const std::vector< art::Ptr< rb::Track >> &  tracks,
const std::set< int > &  trkIDs,
const std::set< int > &  allowedDaughters,
const std::vector< art::Ptr< rb::CellHit >> &  allHits 
) const
inline

Definition at line 705 of file BackTracker.h.

709  {
710  return TracksToParticles(VecPtrToVecRawPtr(tracks),
711  trkIDs, allowedDaughters,
712  VecPtrToVecRawPtr(allHits));
713  }
std::vector< const T * > VecPtrToVecRawPtr(const std::vector< art::Ptr< T >> &xs) const
Definition: BackTracker.h:874
std::vector< ParticleEffPur > TracksToParticles(const std::vector< const rb::Track * > &tracks, const std::set< int > &trkIDs, const std::set< int > &allowedDaughters, const std::vector< const rb::CellHit * > &allHits) const
Given a collection of reconstructed tracks, this method finds the best match for each reco track to t...
std::vector<ParticleEffPur> cheat::BackTracker::TracksToParticles ( const art::PtrVector< rb::Track > &  tracks,
const std::set< int > &  trkIDs,
const std::set< int > &  allowedDaughters,
const art::PtrVector< rb::CellHit > &  allHits 
) const
inline

Definition at line 716 of file BackTracker.h.

720  {
721  return TracksToParticles(PtrVecToVecRawPtr(tracks),
722  trkIDs, allowedDaughters,
723  PtrVecToVecRawPtr(allHits));
724  }
std::vector< const T * > PtrVecToVecRawPtr(const art::PtrVector< T > &xs) const
Helper function for implementing overloads.
Definition: BackTracker.h:861
std::vector< ParticleEffPur > TracksToParticles(const std::vector< const rb::Track * > &tracks, const std::set< int > &trkIDs, const std::set< int > &allowedDaughters, const std::vector< const rb::CellHit * > &allHits) const
Given a collection of reconstructed tracks, this method finds the best match for each reco track to t...
std::vector<ParticleEffPur> cheat::BackTracker::TracksToParticles ( const std::vector< art::Ptr< rb::Track >> &  tracks,
const std::set< int > &  trkIDs,
const std::set< int > &  allowedDaughters,
const art::PtrVector< rb::CellHit > &  allHits 
) const
inline

Definition at line 727 of file BackTracker.h.

731  {
732  return TracksToParticles(VecPtrToVecRawPtr(tracks),
733  trkIDs, allowedDaughters,
734  PtrVecToVecRawPtr(allHits));
735  }
std::vector< const T * > VecPtrToVecRawPtr(const std::vector< art::Ptr< T >> &xs) const
Definition: BackTracker.h:874
std::vector< const T * > PtrVecToVecRawPtr(const art::PtrVector< T > &xs) const
Helper function for implementing overloads.
Definition: BackTracker.h:861
std::vector< ParticleEffPur > TracksToParticles(const std::vector< const rb::Track * > &tracks, const std::set< int > &trkIDs, const std::set< int > &allowedDaughters, const std::vector< const rb::CellHit * > &allHits) const
Given a collection of reconstructed tracks, this method finds the best match for each reco track to t...
template<class T >
std::vector<const T*> cheat::BackTracker::VecPtrToVecRawPtr ( const std::vector< art::Ptr< T >> &  xs) const
inlineprivate

Helper function for implementing overloads

NB the pointers are only valid so long as the parent xs is still around

Definition at line 874 of file BackTracker.h.

References runNovaSAM::ret, and submit_syst::x.

875  {
876  std::vector<const T*> ret;
877  ret.reserve(xs.size());
878  for(const art::Ptr<T>& x: xs) ret.push_back(x.get());
879  return ret;
880  }
Definition: fwd.h:28
template<class T >
std::vector<const T*> cheat::BackTracker::VecToVecRawPtr ( const std::vector< T > &  xs) const
inlineprivate

Helper function for implementing overloads

NB the pointers are only valid so long as the parent xs is still around

Definition at line 887 of file BackTracker.h.

References runNovaSAM::ret, T, and submit_syst::x.

888  {
889  std::vector<const T*> ret;
890  ret.reserve(xs.size());
891  for(const T& x: xs) ret.push_back(&x);
892  return ret;
893  }
double T
Definition: Xdiff_gwt.C:5

Member Data Documentation

std::unordered_map< geo::OfflineChan, std::list<sim::FLSHit> > cheat::BackTracker::fCellToFLSHit
private

map of FLSHits in each cell in event

Definition at line 939 of file BackTracker.h.

Referenced by CellToFLSHit(), EnergyFromTrackId(), HitToFLSHit(), and Rebuild().

std::map<double, std::vector<cheat::TrackIDE> > cheat::BackTracker::fCellToIDs
private

map of cellHit to trackIDEs that contributed energy to the hit. cellhit information is encoded as TDC*1000,000+Plane*1000+Cell

Definition at line 951 of file BackTracker.h.

Referenced by ClusterToParticle(), and HitToParticlesMap().

std::unordered_map< geo::OfflineChan, std::vector<sim::PhotonSignal> > cheat::BackTracker::fCellToPhotonSignal
private

map of PhotonSignals in each cell in event

Definition at line 941 of file BackTracker.h.

Referenced by AccumulateHitContributions(), CellToPhotonSignal(), HitToPhotonSignal(), and Rebuild().

novadaq::cnv::DetId cheat::BackTracker::fDetID
private

detector id

Definition at line 937 of file BackTracker.h.

Referenced by CloseInTime(), and Rebuild().

bool cheat::BackTracker::fHaveTruthInfo
private

Set by Rebuild.

Definition at line 935 of file BackTracker.h.

Referenced by Rebuild().

std::map<int, float > cheat::BackTracker::fIdToEnergy
private

Definition at line 952 of file BackTracker.h.

Referenced by ClusterToParticle(), and HitToParticlesMap().

std::vector< art::Ptr<simb::MCTruth> > cheat::BackTracker::fMCTruthList
private
int cheat::BackTracker::fNumTrueEnergyWarnings
private

Definition at line 955 of file BackTracker.h.

Referenced by BackTracker(), and Rebuild().

Params cheat::BackTracker::fParams
private

Definition at line 933 of file BackTracker.h.

Referenced by HitCollectionEfficiency(), IsHitsNoise(), and Rebuild().

sim::ParticleNavigator cheat::BackTracker::fParticleNav
private

Particle navigator to map track ID to Particle.

Definition at line 942 of file BackTracker.h.

Referenced by MCTruthToParticles(), Rebuild(), TrackIDToMotherParticle(), and TrackIDToParticle().

int cheat::BackTracker::fSliceIDForHitParticleMap
private

Definition at line 954 of file BackTracker.h.

Referenced by ClusterToParticle(), HitToParticlesMap(), and Rebuild().

std::set<int> cheat::BackTracker::fTrackIDs
private

G4 track ids for all particles in the events.

Definition at line 943 of file BackTracker.h.

Referenced by MCTruthToParticles(), and Rebuild().

std::unordered_map< int, std::list<sim::FLSHit> > cheat::BackTracker::fTrackIDToFLSHit
private

map of G4 track ids to FLSHits

Definition at line 940 of file BackTracker.h.

Referenced by ParticleToFLSHit(), and Rebuild().

std::map<int, int> cheat::BackTracker::fTrackIDToMCTruthIndex
private

map of track id values to MCTruthList entry

Definition at line 945 of file BackTracker.h.

Referenced by ClusterByTruth(), MCTruthToCluster(), Rebuild(), SlicesToMCTruthsTable(), and TrackIDToMCTruth().

std::map<int, int> cheat::BackTracker::fTrackIDToTrueEIndex
private

map of track id values to TrueEnergy entry

Definition at line 947 of file BackTracker.h.

Referenced by CalcEscapingEnergy(), CalcTotalEscapingEnergy(), and Rebuild().

std::vector< art::Ptr<sim::TrueEnergy> > cheat::BackTracker::fTrueEnergyList
private

all the TrueEnergy's for this event

Definition at line 946 of file BackTracker.h.

Referenced by CalcEscapingEnergy(), CalcTotalEscapingEnergy(), and Rebuild().


The documentation for this class was generated from the following files: