67 <<
"failed to get handle to simb::MCParticle from " <<
fG4ModuleLabel <<
", return";
80 for (
size_t p = 0; p < pHandle->size(); ++p) {
101 mf::LogWarning(
"PhotonBackTracker") <<
"unable to find MCTruth from ParticleList " 103 <<
"any attempt to get the MCTruth objects from " 104 <<
"the photon backtracker will fail\n" 105 <<
"message from caught exception:\n" 132 std::cout <<
"FAILED BECAUSE " << (*failMode) <<
"\n";
135 <<
"Failed to get BackTrackerRecords from this event. All calls to the PhotonBackTracker " 137 <<
"This message will be generated only once per lar invokation. If this is event one, " 138 "be aware the PhotonBackTracker may not work on any events from this file.\n" 139 <<
"Please change the log level to debug if you need more information for each event.\n" 140 <<
"Failed with :" << (*failMode) <<
"\n";
141 mf::LogDebug(
"PhotonBackTracker") <<
"Failed to get BackTrackerRecords from this event.\n";
144 mf::LogDebug(
"PhotonBackTracker") <<
"Failed to get BackTrackerRecords from this event.\n";
159 <<
" tracks. The particles are:\n" 175 <<
"PhotonBackTracker methods called on a file without OpDetPhotonBacktrackerRecords. " 176 "Backtracked information is not available.";
188 <<
"can't find particle with track id " <<
id <<
" in sim::ParticleList" 189 <<
" returning null pointer";
193 return part_it->second;
215 <<
"attempting to find MCTruth index for " 216 <<
"out of range value: " << mct <<
"/" <<
fMCTruthList.size() <<
"\n";
225 std::vector<sim::SDP> sdps;
233 for (
auto mapitr = pdTimeSDPmap.begin(); mapitr != pdTimeSDPmap.end(); mapitr++) {
236 const std::vector<sim::SDP>& sdpvec = (*mapitr).second;
237 for (
size_t iv = 0; iv < sdpvec.size(); ++iv) {
238 if (
abs(sdpvec[iv].trackID) == id) sdps.push_back(sdpvec[iv]);
260 std::vector<const simb::MCParticle*> ret;
264 if (
TrackIDToMCTruth(TrackIDpair.first) == mct) ret.push_back(TrackIDpair.second);
275 std::vector<sim::TrackSDP> trackSDPs;
276 const double pTime = opHit->
PeakTime();
277 const double pWidth = opHit->
Width();
278 const double start = (pTime - pWidth) * 1000 -
fDelay;
279 const double end = (pTime + pWidth) * 1000 -
fDelay;
289 std::vector<int>
const& tkIDs)
297 std::vector<std::pair<int, art::Ptr<recob::OpHit>>> opHitList;
298 std::vector<sim::TrackSDP> tids;
299 for (
auto itr = allOpHits.begin(); itr != allOpHits.end(); ++itr) {
302 const double pTime = opHit->
PeakTime(), pWidth = opHit->
Width();
303 const double start = (pTime - pWidth) * 1000.0 -
fDelay,
304 end = (pTime + pWidth) * 1000.0 -
fDelay;
306 for (
auto itid = tids.begin(); itid != tids.end(); ++itid) {
307 for (
auto itkid = tkIDs.begin(); itkid != tkIDs.end(); ++itkid) {
308 if (itid->trackID == *itkid) {
310 opHitList.push_back(std::make_pair(*itkid, opHit));
317 std::vector<std::vector<art::Ptr<recob::OpHit>>> truOpHits;
319 std::vector<art::Ptr<recob::OpHit>> tmpOpHits;
320 for (
auto itkid = tkIDs.begin(); itkid != tkIDs.end(); ++itkid) {
322 for (
auto itr = opHitList.begin(); itr != opHitList.end(); ++itr) {
323 if (*itkid == (*itr).first) tmpOpHits.push_back((*itr).second);
325 truOpHits.push_back(tmpOpHits);
340 std::map<int, float> eveIDtoEfrac;
343 for (
size_t t = 0; t < trackSDPs.size(); ++t) {
345 totalE += trackSDPs[t].energy;
349 std::vector<sim::TrackSDP> eveSDPs;
350 eveSDPs.reserve(eveIDtoEfrac.size());
351 for (
auto itr = eveIDtoEfrac.begin(); itr != eveIDtoEfrac.end(); itr++) {
355 temp.
energy = (*itr).second;
356 eveSDPs.push_back(std::move(temp));
364 <<
"PhotonBackTracker::OpHitToEveID is being replaced with " 365 "PhotonBackTracker::OpHitToEveSDPs. Please \n update your code accordingly.\n ";
374 std::set<int> eveIDs;
380 if (eveIDs.find(eveID) == eveIDs.end()) eveIDs.insert(eveID);
392 std::set<int> trackIDs;
394 trackIDs.insert(pl.first);
403 std::set<int> eveIDs;
406 while (itr != opHits.end()) {
409 const std::vector<sim::TrackSDP> sdps =
OpHitToEveID(*itr);
412 for (
size_t i = 0; i < sdps.size(); ++i)
413 eveIDs.insert(sdps[i].trackID);
426 std::set<int> trackIDs;
429 while (itr != opHits.end()) {
431 std::vector<sim::TrackSDP> trackSDPs;
434 const double pTime = (*itr)->PeakTime();
435 const double pWidth = (*itr)->Width();
436 const double start = (pTime - pWidth) * 1000.0 -
fDelay;
437 const double end = (pTime + pWidth) * 1000.0 -
fDelay;
444 for (
size_t i = 0; i < trackSDPs.size(); ++i) {
445 trackIDs.insert(trackSDPs[i].trackID);
461 float total = 1. * opHits.size();
464 for (
size_t h = 0; h < opHits.size(); ++h) {
469 for (
size_t e = 0;
e < opHitTrackSDPs.size(); ++
e) {
470 if (trackIds.find(opHitTrackSDPs[
e].trackID) != trackIds.end()) {
477 if (total > 0) purity = desired / total;
483 std::set<int> trackIDs,
494 for (
size_t h = 0; h < opHits.size(); ++h) {
497 total += opHit->
Area();
500 for (
size_t e = 0;
e < opHitTrackIDs.size(); ++
e) {
501 if (trackIDs.find(opHitTrackIDs[
e].trackID) != trackIDs.end()) {
502 desired += opHit->
Area();
508 if (total > 0) purity = desired / total;
514 std::set<int> trackIDs,
520 <<
"This function is not supported. OpHits do not have type View.\n";
524 std::set<int> trackIds,
531 for (
size_t h = 0; h < opHits.size(); ++h) {
536 for (
size_t e = 0;
e < opHitTrackSDP.size(); ++
e) {
537 if (trackIDs.find(opHitTrackSDPs[
e].trackID) != trackIDs.end() &&
545 for (
size_t h = 0; h < allOpHits.size(); ++h) {
548 for (
size_t e = 0;
e < opHitTrackSDPs.size(); ++
e) {
553 if (trackIDs.find(opHitTrackSDPs[
e].trackID) != trackIDs.end() &&
560 double efficiency = 0.;
561 if (total > 0.) efficiency = desired / total;
567 std::set<int> trackIDs,
573 <<
"This function is not supported. OpHits do not have type View.\n";
576 std::set<int> trackIDs,
589 for (
size_t h = 0; h < opHits.size(); ++h) {
598 for (
size_t e = 0;
e < opHitTrackIDs.size(); ++
e) {
599 if (trackIDs.find(opHitTrackIDs[
e].trackID) != trackIDs.end() &&
601 desired += opHit->
Area();
608 for (
size_t h = 0; h < allOpHits.size(); ++h) {
618 for (
size_t e = 0;
e < opHitTrackIDs.size(); ++
e) {
623 if (trackIDs.find(opHitTrackIDs[
e].trackID) != trackIDs.end() &&
625 total += opHit->
Area();
632 double efficiency = 0.;
633 if (total > 0.) efficiency = desired / total;
652 throw cet::exception(
"PhotonBackTracker2") <<
"No sim::OpDetBacktrackerRecord corresponding " 653 <<
"to opDetNum: " << opDetNum <<
"\n";
662 const double opHit_start_time,
663 const double opHit_end_time)
681 std::vector<sim::SDP> simSDPs =
686 for (
size_t e = 0;
e < simSDPs.size(); ++
e)
690 if (totalE < 1.
e-5) totalE = 1.;
694 for (
size_t e = 0;
e < simSDPs.size(); ++
e) {
701 info.
energy = simSDPs[
e].energy;
703 trackSDPs.push_back(info);
720 double fPeakTime = opHit.
PeakTime();
721 double fWidth = opHit.
Width();
723 ((fPeakTime - fWidth) * 1000.0) -
fDelay;
734 std::vector<double> xyz(3, -999.);
743 for (
auto const& sdp : sdps) {
745 double weight = sdp.numPhotons;
758 <<
"No sim::SDPs providing non-zero number of photons" 759 <<
" can't determine originating location from truth\n";
772 std::vector<sim::SDP> sdps;
const simb::MCParticle * TrackIDToParticle(int const &id) const
const void shouldThisFail() const
std::vector< const simb::MCParticle * > MCTruthToParticles(art::Ptr< simb::MCTruth > const &mct) const
std::map< int, int > fTrackIDToMCTruthIndex
map of track ids to MCTruthList entry
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
list_type::value_type value_type
std::vector< sim::SDP > TrackIDToSimSDP(int const &id) const
list_type::const_iterator const_iterator
std::vector< double > SimSDPsToXYZ(std::vector< sim::SDP > const &sdps)
constexpr auto abs(T v)
Returns the absolute value of the argument.
void Add(simb::MCParticle *value)
double OpHitChargeCollectionPurity(std::set< int > trackIDs, std::vector< art::Ptr< recob::OpHit >> const &hits)
int EveId(const int trackID) const
const art::Ptr< simb::MCTruth > & ParticleToMCTruth(const simb::MCParticle *p) const
std::string fG4ModuleLabel
label for geant4 module
std::vector< double > OpHitToXYZ(art::Ptr< recob::OpHit > const &hit)
unsigned int OpDetFromOpChannel(int opChannel) const
Convert unique channel to detector number.
iterator find(const key_type &key)
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Access the description of detector geometry.
void OpHitToSDPs(recob::OpHit const &hit, std::vector< sim::SDP > &sdps) const
void reconfigure(fhicl::ParameterSet const &pset)
int trackID
Geant4 supplied trackID.
std::vector< sim::TrackSDP > OpHitToEveSDPs(art::Ptr< recob::OpHit > const &hit)
static const int NoParticleId
T get(std::string const &key) const
void ChannelToTrackSDPs(std::vector< sim::TrackSDP > &trackSDPs, int channel, const double hit_start_time, const double hit_end_time)
float energyFrac
fraction of OpHit energy from the particle with this trackID
double timePDclock_t
Type for iTimePDclock tick used in the interface.
back track the reconstruction to the simulation
const simb::MCParticle * TrackIDToMotherParticle(int const &id) const
void Rebuild(const art::Event &evt)
GlobalSignal< detail::SignalResponseType::FIFO, void(Event const &, ScheduleContext)> sPreProcessEvent
std::set< int > GetSetOfTrackIDs()
Ionization photons from a Geant4 track.
#define DEFINE_ART_SERVICE(svc)
std::vector< sim::TrackSDP > OpHitToTrackSDPs(art::Ptr< recob::OpHit > const &hit)
std::vector< sim::TrackSDP > OpHitToEveID(art::Ptr< recob::OpHit > const &hit)
PhotonBackTracker(fhicl::ParameterSet const &pset, art::ActivityRegistry ®)
code to link reconstructed objects back to the MC truth information
const art::Ptr< sim::OpDetBacktrackerRecord > FindOpDetBacktrackerRecord(int channel) const
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Utility object to perform functions of association.
geo::GeometryCore const * geom
Example routine for calculating the "ultimate e-m mother" of a particle in a simulated event...
MaybeLogger_< ELseverityLevel::ELsev_success, false > LogDebug
double OpHitCollectionEfficiency(std::set< int > trackIDs, std::vector< art::Ptr< recob::OpHit >> const &hits, std::vector< art::Ptr< recob::OpHit >> const &allhits)
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
double OpHitCollectionPurity(std::set< int > trackIDs, std::vector< art::Ptr< recob::OpHit >> const &hits)
double fMinOpHitEnergyFraction
minimum fraction of energy a track id has to
std::shared_ptr< art::Exception const > whyFailed() const
std::vector< sim::SDP > TrackIDsAndEnergies(timePDclock_t startTimePDclock, timePDclock_t endTimePDclock) const
Return all the recorded energy deposition within a time interval.
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
float energy
energy from the particle with this trackID [MeV]
std::vector< art::Ptr< sim::OpDetBacktrackerRecord > > cOpDetBacktrackerRecords
all the OpDetBacktrackerRecords for the event
std::vector< art::Ptr< simb::MCTruth > > fMCTruthList
all the MCTruths for the event
static void AdoptEveIdCalculator(EveIdCalculator *)
double OpHitChargeCollectionEfficiency(std::set< int > trackIDs, std::vector< art::Ptr< recob::OpHit >> const &hits, std::vector< art::Ptr< recob::OpHit >> const &allhits)
Tools and modules for checking out the basics of the Monte Carlo.
const std::vector< std::vector< art::Ptr< recob::OpHit > > > TrackIDsToOpHits(std::vector< art::Ptr< recob::OpHit >> const &allhits, std::vector< int > const &tkIDs)
sim::ParticleList fParticleList
ParticleList to map track ID to sim::Particle.
art framework interface to geometry description
cet::coded_exception< error, detail::translate > exception
const art::Ptr< simb::MCTruth > & TrackIDToMCTruth(int const &id) const
std::set< int > GetSetOfEveIDs()