43 fDelay(config.Delay())
44 , fG4ModuleLabel(config.G4ModuleLabel())
45 , fG4ModuleLabels(config.G4ModuleLabels())
46 , fOpHitLabel(config.OpHitLabel())
47 , fOpFlashLabel(config.OpFlashLabel())
50 fMinOpHitEnergyFraction(config.MinOpHitEnergyFraction())
104 std::vector<const sim::SDP*> sdp_Ps;
106 const auto& pdTimeSDPmap =
priv_OpDetBTRs[odet]->timePDclockSDPsMap();
107 for (
auto mapitr = pdTimeSDPmap.begin(); mapitr != pdTimeSDPmap.end(); mapitr++) {
108 std::vector<sim::SDP>
const& sdpvec = (*mapitr).second;
109 for (
size_t iv = 0; iv < sdpvec.size(); ++iv) {
111 if (
abs(sdpvec[iv].trackID) == id) sdp_Ps.push_back(&(sdpvec[iv]));
124 <<
"PhotonBackTracker is not equiped to handle geo::Views.";
129 int const& opDetNum)
const 137 throw cet::exception(
"PhotonBackTracker2") <<
"No sim:: OpDetBacktrackerRecord corresponding " 138 <<
"to opDetNum: " << opDetNum <<
"\n";
146 double const& opHit_start_time,
147 double const& opHit_end_time)
const 149 std::vector<sim::TrackSDP> tSDPs;
154 std::vector<sim::SDP> simSDPs =
156 for (
size_t e = 0;
e < simSDPs.size(); ++
e)
158 if (totalE < 1.
e-5) totalE = 1.;
159 for (
size_t e = 0;
e < simSDPs.size(); ++
e) {
164 info.
energy = simSDPs[
e].energy;
165 tSDPs.push_back(info);
181 const double pTime = opHit_P->
PeakTime();
182 const double pWidth = opHit_P->
Width();
183 const double start = (pTime - pWidth) * 1000 -
fDelay;
184 const double end = (pTime + pWidth) * 1000 -
fDelay;
193 const double pTime = opHit.
PeakTime();
194 const double pWidth = opHit.
Width();
195 const double start = (pTime - pWidth) * 1000 -
fDelay;
196 const double end = (pTime + pWidth) * 1000 -
fDelay;
203 std::vector<int> retVec;
205 retVec.push_back(trackSDP.trackID);
220 std::vector<int> retVec;
222 retVec.push_back(trackSDP.trackID);
249 std::map<int, float> eveIDtoEfrac;
252 for (
size_t t = 0; t < trackSDPs.size(); ++t) {
254 totalE += trackSDPs[t].energy;
258 std::vector<sim::TrackSDP> eveSDPs;
259 eveSDPs.reserve(eveIDtoEfrac.size());
260 for (
auto itr = eveIDtoEfrac.begin(); itr != eveIDtoEfrac.end(); itr++) {
264 temp.
energy = (*itr).second;
265 eveSDPs.push_back(std::move(temp));
277 std::vector<int> tkidFake(1, tkId);
280 const std::vector<art::Ptr<recob::OpHit>> out =
287 std::vector<int>
const& tkIds,
290 std::vector<std::pair<int, art::Ptr<recob::OpHit>>> opHitList;
291 for (
auto itr = hitsIn.begin(); itr != hitsIn.end(); ++itr) {
294 const double pTime = opHit->
PeakTime(), pWidth = opHit->
Width();
295 const double start = (pTime - pWidth) * 1000.0 -
fDelay,
296 end = (pTime + pWidth) * 1000.0 -
fDelay;
299 for (
auto itid = tids.begin(); itid != tids.end(); ++itid) {
300 for (
auto itkid = tkIds.begin(); itkid != tkIds.end(); ++itkid) {
301 if (itid->trackID == *itkid) {
303 opHitList.push_back(std::make_pair(*itkid, opHit));
309 std::vector<std::vector<art::Ptr<recob::OpHit>>> truOpHits;
311 std::vector<art::Ptr<recob::OpHit>> tmpOpHits;
312 for (
auto itkid = tkIds.begin(); itkid != tkIds.end(); ++itkid) {
314 for (
auto itr = opHitList.begin(); itr != opHitList.end(); ++itr) {
315 if (*itkid == (*itr).first) tmpOpHits.push_back((*itr).second);
317 truOpHits.push_back(tmpOpHits);
326 std::vector<const sim::SDP*> retVec;
327 double fPeakTime = opHit.
PeakTime();
328 double fWidth = opHit.
Width();
330 ((fPeakTime - fWidth) * 1000.0) -
fDelay;
332 if (start_time > end_time) {
throw; }
335 const std::vector<std::pair<double, std::vector<sim::SDP>>>& timeSDPMap =
337 ->timePDclockSDPsMap();
340 std::vector<const std::pair<double, std::vector<sim::SDP>>*> timePDclockSDPMap_SortedPointers;
341 for (
auto& pair : timeSDPMap) {
342 timePDclockSDPMap_SortedPointers.push_back(&pair);
344 auto pairSort = [](
auto& a,
auto& b) {
return a->first < b->first; };
345 if (!std::is_sorted(timePDclockSDPMap_SortedPointers.begin(),
346 timePDclockSDPMap_SortedPointers.end(),
349 timePDclockSDPMap_SortedPointers.begin(), timePDclockSDPMap_SortedPointers.end(), pairSort);
353 std::vector<sim::SDP> dummyVec;
354 std::pair<double, std::vector<sim::SDP>> start_timePair = std::make_pair(start_time, dummyVec);
355 std::pair<double, std::vector<sim::SDP>> end_timePair = std::make_pair(end_time, dummyVec);
356 auto start_timePair_P = &start_timePair;
357 auto end_timePair_P = &end_timePair;
359 auto mapFirst = std::lower_bound(timePDclockSDPMap_SortedPointers.begin(),
360 timePDclockSDPMap_SortedPointers.end(),
365 std::upper_bound(mapFirst, timePDclockSDPMap_SortedPointers.end(), end_timePair_P, pairSort);
367 for (
auto& mapitr = mapFirst; mapitr != mapLast; ++mapitr)
368 for (
auto& sdp : (*mapitr)->second)
369 retVec.push_back(&sdp);
386 std::vector<sim::SDP>
const& sdps)
const&
388 std::vector<double> xyz(3, -999.);
394 for (
auto const& sdp : sdps) {
395 double weight = sdp.numPhotons;
405 <<
"No sim::SDPs providing non-zero number of photons" 406 <<
" can't determine originating location from truth\n";
415 std::vector<const sim::SDP*>
const& sdps_Ps)
const&
417 std::vector<double> xyz(3, -999.);
423 for (
const sim::SDP* sdp_P : sdps_Ps) {
425 double weight = sdp.numPhotons;
435 <<
"No sim::SDPs providing non-zero number of photons" 436 <<
" can't determine originating location from truth\n";
461 std::vector<const sim::SDP*> sdps_Ps;
462 for (
auto opHit_P : opHits_Ps) {
464 sdps_Ps.insert(sdps_Ps.end(), to_add_sdps_Ps.begin(), to_add_sdps_Ps.end());
482 std::unordered_set<const sim::SDP*> sdps;
483 for (
auto const&
id : ids) {
485 for (
const sim::SDP* tmp_sdp : tmp_sdps) {
486 sdps.insert(tmp_sdp);
497 std::unordered_set<const sim::SDP*> sdps;
498 for (
auto const&
id : ids) {
500 for (
const sim::SDP* tmp_sdp : tmp_sdps) {
501 sdps.insert(tmp_sdp);
525 std::set<int> eveIds;
526 for (
auto const& opHit_P : opHits_Ps) {
528 for (
auto const& sdp : sdps) {
529 eveIds.insert(sdp.trackID);
537 std::vector<recob::OpHit>
const& opHits)
const 539 std::set<int> eveIds;
540 for (
auto const& opHit : opHits) {
542 for (
auto const& sdp : sdps) {
543 eveIds.insert(sdp.trackID);
554 for (
auto const& opHit : opHits) {
556 tids.insert(sdp.trackID);
564 std::vector<recob::OpHit>
const& opHits)
const 567 for (
auto const& opHit : opHits) {
569 tids.insert(sdp.trackID);
577 std::set<int>
const& tkIds,
582 float total = 1. * opHits.size();
585 for (
size_t h = 0; h < opHits.size(); ++h) {
590 for (
size_t e = 0;
e < opHitTrackSDPs.size(); ++
e) {
591 if (tkIds.find(opHitTrackSDPs[
e].trackID) != tkIds.end()) {
598 if (total > 0) purity = desired / total;
604 std::set<int>
const& tkIds,
614 for (
size_t h = 0; h < opHits.size(); ++h) {
617 total += opHit->
Area();
620 for (
size_t e = 0;
e < opHitTrackIDs.size(); ++
e) {
621 if (tkIds.find(opHitTrackIDs[
e].trackID) != tkIds.end()) {
622 desired += opHit->
Area();
628 if (total > 0) purity = desired / total;
634 std::set<int>
const& tkIds,
640 <<
"This function is not supported. OpHits do not have type View.\n";
645 std::set<int>
const& tkIds,
651 for (
size_t h = 0; h < opHits.size(); ++h) {
656 for (
size_t e = 0;
e < opHitTrackSDPs.size(); ++
e) {
657 if (tkIds.find(opHitTrackSDPs[
e].trackID) != tkIds.end() &&
665 for (
size_t h = 0; h < opHitsIn.size(); ++h) {
668 for (
size_t e = 0;
e < opHitTrackSDPs.size(); ++
e) {
673 if (tkIds.find(opHitTrackSDPs[
e].trackID) != tkIds.end() &&
680 double efficiency = 0.;
681 if (total > 0.) efficiency = desired / total;
687 std::set<int>
const& tkIds,
693 <<
"This function is not supported. OpHits do not have type View.\n";
698 std::set<int>
const& tkIds,
708 for (
size_t h = 0; h < opHits.size(); ++h) {
717 for (
size_t e = 0;
e < opHitTrackIDs.size(); ++
e) {
718 if (tkIds.find(opHitTrackIDs[
e].trackID) != tkIds.end() &&
720 desired += opHit->
Area();
725 for (
size_t h = 0; h < opHitsIn.size(); ++h) {
731 for (
size_t e = 0;
e < opHitTrackIDs.size(); ++
e) {
736 if (tkIds.find(opHitTrackIDs[
e].trackID) != tkIds.end() &&
738 total += opHit->
Area();
743 double efficiency = 0.;
744 if (total > 0.) efficiency = desired / total;
760 const std::vector<art::Ptr<recob::OpHit>> opHits_Ps = this->
OpFlashToOpHits_Ps(flash_P);
761 const std::vector<double> retVec = this->
OpHitsToXYZ(opHits_Ps);
771 for (
auto& opHit_P : opHits_Ps) {
const art::Ptr< sim::OpDetBacktrackerRecord > FindOpDetBTR(int const &opDetNum) const
const std::unordered_set< const sim::SDP * > OpHitToEveSimSDPs_Ps(recob::OpHit const &opHit)
std::map< art::Ptr< recob::OpFlash >, std::vector< art::Ptr< recob::OpHit > > > priv_OpFlashToOpHits
const std::vector< art::Ptr< recob::OpHit > > TrackIdToOpHits_Ps(int const &tkId, std::vector< art::Ptr< recob::OpHit >> const &hitsIn)
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
std::vector< double > SimSDPsToXYZ(std::vector< sim::SDP > const &sdps)
constexpr auto abs(T v)
Returns the absolute value of the argument.
const std::vector< const sim::SDP * > TrackIdToSimSDPs_Ps(int const &id)
std::string fG4ModuleLabel
label for geant4 module
std::vector< double > OpHitToXYZ(art::Ptr< recob::OpHit > const &hit)
const std::vector< sim::TrackSDP > OpHitToEveTrackSDPs(art::Ptr< recob::OpHit > const &opHit_P) const
unsigned int OpDetFromOpChannel(int opChannel) const
Convert unique channel to detector number.
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.
const std::set< int > OpFlashToTrackIds(art::Ptr< recob::OpFlash > &flash_P) const
const std::set< int > GetSetOfEveIds() const
const std::vector< double > OpHitsToXYZ(std::vector< art::Ptr< recob::OpHit >> const &opHits_Ps) const
const std::vector< std::vector< art::Ptr< recob::OpHit > > > TrackIdsToOpHits_Ps(std::vector< int > const &tkIds, std::vector< art::Ptr< recob::OpHit >> const &hitsIn)
int trackID
Geant4 supplied trackID.
const cheat::ParticleInventory * fPartInv
std::vector< art::Ptr< sim::OpDetBacktrackerRecord > > priv_OpDetBTRs
static const int NoParticleId
const geo::GeometryCore * fGeom
float energyFrac
fraction of OpHit energy from the particle with this trackID
double timePDclock_t
Type for iTimePDclock tick used in the interface.
std::set< int > GetSetOfTrackIds() const
back track the reconstruction to the simulation
std::set< int > GetSetOfEveIds() const
Description of geometry of one entire detector.
const std::vector< int > OpHitToEveTrackIds(recob::OpHit const &opHit)
Ionization photons from a Geant4 track.
const art::InputTag fOpFlashLabel
std::vector< sim::TrackSDP > OpHitToTrackSDPs(art::Ptr< recob::OpHit > const &hit)
decltype(auto) get(T &&obj)
ADL-aware version of std::to_string.
PhotonBackTracker(fhicl::ParameterSet const &pset, art::ActivityRegistry ®)
code to link reconstructed objects back to the MC truth information
const std::set< int > GetSetOfTrackIds() const
const std::vector< art::InputTag > fG4ModuleLabels
geo::GeometryCore const * geom
const std::vector< int > OpHitToTrackIds(recob::OpHit const &opHit) const
const std::vector< const sim::SDP * > OpHitsToSimSDPs_Ps(std::vector< art::Ptr< recob::OpHit >> const &opHits_Ps) const
double OpHitCollectionEfficiency(std::set< int > trackIDs, std::vector< art::Ptr< recob::OpHit >> const &hits, std::vector< art::Ptr< recob::OpHit >> const &allhits)
const double OpHitLightCollectionEfficiency(std::set< int > const &tkIds, std::vector< art::Ptr< recob::OpHit >> const &opHits, std::vector< art::Ptr< recob::OpHit >> const &opHitsIn)
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
Header for the ParticleInvenotry Service Provider.
const std::vector< const sim::SDP * > OpHitToSimSDPs_Ps(recob::OpHit const &opHit) const
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
const art::InputTag fOpHitLabel
std::vector< sim::SDP > TrackIDsAndEnergies(timePDclock_t startTimePDclock, timePDclock_t endTimePDclock) const
Return all the recorded energy deposition within a time interval.
std::vector< art::Ptr< sim::OpDetBacktrackerRecord > > const & OpDetBTRs()
const std::vector< double > OpFlashToXYZ(art::Ptr< recob::OpFlash > &flash_P) const
float energy
energy from the particle with this trackID [MeV]
const bool OpFlashToOpHitsReady()
Tools and modules for checking out the basics of the Monte Carlo.
const sim::ParticleList & ParticleList() const
const std::vector< sim::TrackSDP > OpDetToTrackSDPs(int const &OpDetNum, double const &opHit_start_time, double const &opHit_end_time) const
cet::coded_exception< error, detail::translate > exception
const std::vector< art::Ptr< recob::OpHit > > OpFlashToOpHits_Ps(art::Ptr< recob::OpFlash > &flash_P) const
const double OpHitLightCollectionPurity(std::set< int > const &tkIds, std::vector< art::Ptr< recob::OpHit >> const &opHits)