43 fDelay (config.Delay()),
44 fG4ModuleLabel(config.G4ModuleLabel()),
45 fOpHitLabel(config.OpHitLabel()),
46 fOpFlashLabel(config.OpFlashLabel()),
48 fMinOpHitEnergyFraction(config.MinOpHitEnergyFraction())
59 fDelay(pSet.get<double>(
"Delay")),
97 std::vector< const sim::SDP* > sdp_Ps;
99 const auto & pdTimeSDPmap =
priv_OpDetBTRs[odet]->timePDclockSDPsMap();
100 for(
auto mapitr = pdTimeSDPmap.begin(); mapitr != pdTimeSDPmap.
end(); mapitr++){
101 std::vector<sim::SDP>
const& sdpvec = (*mapitr).second;
102 for(
size_t iv = 0; iv < sdpvec.size(); ++iv){
104 if( abs(sdpvec[iv].trackID) == id) sdp_Ps.push_back(&(sdpvec[iv]));
117 <<
"PhotonBackTracker is not equiped to handle geo::Views.";
130 throw cet::exception(
"PhotonBackTracker2") <<
"No sim:: OpDetBacktrackerRecord corresponding " 131 <<
"to opDetNum: " << opDetNum <<
"\n";
138 double const& opHit_start_time,
double const& opHit_end_time)
const 140 std::vector< sim::TrackSDP > tSDPs;
146 std::vector<sim::SDP> simSDPs =
148 for(
size_t e = 0;
e < simSDPs.size(); ++
e)
150 if(totalE < 1.
e-5) totalE = 1.;
151 for(
size_t e = 0;
e < simSDPs.size(); ++
e){
156 info.
energy = simSDPs[
e].energy;
157 tSDPs.push_back(info);
172 std::vector<sim::TrackSDP> trackSDPs;
173 const double pTime = opHit_P->
PeakTime();
174 const double pWidth= opHit_P->
Width();
175 const double start = (pTime-pWidth)*1000-
fDelay;
176 const double end = (pTime+pWidth)*1000-
fDelay;
191 std::vector<sim::TrackSDP> trackSDPs;
192 const double pTime = opHit.
PeakTime();
193 const double pWidth= opHit.
Width();
194 const double start = (pTime-pWidth)*1000-
fDelay;
195 const double end = (pTime+pWidth)*1000-
fDelay;
205 std::vector< int > retVec;
207 retVec.push_back( trackSDP.trackID);
221 std::vector< int > retVec;
223 retVec.push_back( trackSDP.trackID);
247 std::map<int, float> eveIDtoEfrac;
250 for(
size_t t = 0; t < trackSDPs.size(); ++t){
252 totalE += trackSDPs[t].energy;
256 std::vector<sim::TrackSDP> eveSDPs;
257 eveSDPs.reserve(eveIDtoEfrac.size());
258 for(
auto itr = eveIDtoEfrac.begin(); itr != eveIDtoEfrac.end(); itr++){
262 temp.
energy = (*itr).second;
263 eveSDPs.push_back(std::move(temp));
273 std::vector<int> tkidFake(1, tkId);
276 const std::vector<art::Ptr<recob::OpHit>> out = (this->
TrackIdsToOpHits_Ps(tkidFake, hitsIn)).at(0);
283 std::vector<std::pair<int, art::Ptr<recob::OpHit>>> opHitList;
284 for(
auto itr = hitsIn.begin(); itr != hitsIn.end(); ++itr) {
287 const double pTime = opHit->
PeakTime(), pWidth= opHit->
Width();
288 const double start = (pTime-pWidth)*1000.0-
fDelay,
end = (pTime+ pWidth)*1000.0-
fDelay;
291 for(
auto itid = tids.begin(); itid != tids.end(); ++itid) {
292 for(
auto itkid = tkIds.begin(); itkid != tkIds.end(); ++itkid) {
293 if(itid->trackID == *itkid) {
295 opHitList.push_back(std::make_pair(*itkid, opHit));
301 std::vector<std::vector<art::Ptr<recob::OpHit>>> truOpHits;
303 std::vector<art::Ptr<recob::OpHit>> tmpOpHits;
304 for(
auto itkid = tkIds.begin(); itkid != tkIds.end(); ++itkid) {
306 for(
auto itr = opHitList.begin(); itr != opHitList.end(); ++itr) {
307 if(*itkid == (*itr).first) tmpOpHits.push_back((*itr).second);
309 truOpHits.push_back(tmpOpHits);
317 std::vector<const sim::SDP*> retVec;
318 double fPeakTime = opHit.
PeakTime();
319 double fWidth = opHit.
Width();
322 if(start_time > end_time){
throw;}
325 const std::vector<std::pair<double, std::vector<sim::SDP>> >& timeSDPMap
329 std::vector<const std::pair<double, std::vector<sim::SDP>>*> timePDclockSDPMap_SortedPointers;
330 for (
auto& pair : timeSDPMap ){ timePDclockSDPMap_SortedPointers.push_back(&pair); }
331 auto pairSort = [](
auto& a,
auto& b) {
return a->first < b->first ; } ;
332 if( !std::is_sorted( timePDclockSDPMap_SortedPointers.begin(), timePDclockSDPMap_SortedPointers.end(), pairSort)){
333 std::sort(timePDclockSDPMap_SortedPointers.begin(), timePDclockSDPMap_SortedPointers.end(), pairSort);
337 std::vector<sim::SDP> dummyVec;
338 std::pair<double, std::vector<sim::SDP>> start_timePair = std::make_pair(start_time, dummyVec);
339 std::pair<double, std::vector<sim::SDP>> end_timePair = std::make_pair(end_time, dummyVec);
340 auto start_timePair_P = &start_timePair;
341 auto end_timePair_P = &end_timePair;
343 auto mapFirst = std::lower_bound(timePDclockSDPMap_SortedPointers.begin(), timePDclockSDPMap_SortedPointers.end(), start_timePair_P, pairSort);
345 auto mapLast = std::upper_bound(mapFirst, timePDclockSDPMap_SortedPointers.end(), end_timePair_P, pairSort);
347 for(
auto& mapitr = mapFirst; mapitr != mapLast; ++mapitr )
348 for(
auto& sdp : (*mapitr)->second)
349 retVec.push_back(&sdp);
368 std::vector<double> xyz(3, -999.);
374 for(
auto const& sdp : sdps) {
375 double weight = sdp.numPhotons;
384 throw cet::exception(
"PhotonBackTracker") <<
"No sim::SDPs providing non-zero number of photons" 385 <<
" can't determine originating location from truth\n";
395 std::vector<double> xyz(3, -999.);
401 for(
const sim::SDP* sdp_P : sdps_Ps) {
403 double weight = sdp.numPhotons;
412 throw cet::exception(
"PhotonBackTracker") <<
"No sim::SDPs providing non-zero number of photons" 413 <<
" can't determine originating location from truth\n";
437 std::vector < const sim::SDP* > sdps_Ps;
438 for (
auto opHit_P : opHits_Ps ){
439 std::vector < const sim::SDP* > to_add_sdps_Ps = this->
OpHitToSimSDPs_Ps(opHit_P);
440 sdps_Ps.insert( sdps_Ps.end(), to_add_sdps_Ps.begin(), to_add_sdps_Ps.end() );
456 std::unordered_set <const sim::SDP* > sdps;
457 for(
auto const&
id : ids ){
459 for(
const sim::SDP* tmp_sdp : tmp_sdps ){
460 sdps.insert(tmp_sdp);
470 std::unordered_set <const sim::SDP* > sdps;
471 for(
auto const&
id : ids ){
473 for(
const sim::SDP* tmp_sdp : tmp_sdps ){
474 sdps.insert(tmp_sdp);
497 std::set<int> eveIds;
498 for(
auto const& opHit_P : opHits_Ps){
500 for(
auto const& sdp : sdps){eveIds.insert(sdp.trackID);}
508 std::set<int> eveIds;
509 for(
auto const& opHit : opHits){
511 for(
auto const& sdp : sdps){eveIds.insert(sdp.trackID);}
520 for(
auto const& opHit : opHits){
522 tids.insert(sdp.trackID);
532 for(
auto const& opHit : opHits){
534 tids.insert(sdp.trackID);
546 float total = 1.*opHits.size();;
548 for(
size_t h = 0; h < opHits.size(); ++h){
553 for(
size_t e = 0;
e < opHitTrackSDPs.size(); ++
e){
554 if(tkIds.find(opHitTrackSDPs[
e].trackID) != tkIds.end()){
561 if(total > 0) purity = desired/total;
576 for(
size_t h = 0; h < opHits.size(); ++h){
579 total+=opHit->
Area();
582 for(
size_t e = 0;
e < opHitTrackIDs.size(); ++
e){
583 if(tkIds.find(opHitTrackIDs[
e].trackID) != tkIds.end()){
584 desired += opHit->
Area();
590 if(total > 0) purity = desired/total;
600 throw cet::exception(
"PhotonBackTracker")<<
"This function is not supported. OpHits do not have type View.\n";
610 for(
size_t h = 0; h < opHits.size(); ++h){
615 for(
size_t e = 0;
e < opHitTrackSDPs.size(); ++
e){
616 if(tkIds.find(opHitTrackSDPs[
e].trackID) != tkIds.end() &&
624 for(
size_t h = 0; h < opHitsIn.size(); ++h){
627 for(
size_t e = 0;
e < opHitTrackSDPs.size(); ++
e){
632 if(tkIds.find(opHitTrackSDPs[
e].trackID) != tkIds.end() &&
639 double efficiency = 0.;
640 if(total > 0.) efficiency = desired/total;
650 throw cet::exception(
"PhotonBackTracker")<<
"This function is not supported. OpHits do not have type View.\n";
664 for(
size_t h = 0; h < opHits.size(); ++h){
673 for(
size_t e = 0;
e < opHitTrackIDs.size(); ++
e){
674 if(tkIds.find(opHitTrackIDs[
e].trackID) != tkIds.end() &&
676 desired += opHit->
Area();
681 for(
size_t h = 0; h < opHitsIn.size(); ++h){
687 for(
size_t e = 0;
e < opHitTrackIDs.size(); ++
e){
692 if(tkIds.find(opHitTrackIDs[
e].trackID) != tkIds.end() &&
694 total += opHit->
Area();
699 double efficiency = 0.;
700 if(total > 0.) efficiency = desired/total;
715 const std::vector< art::Ptr< recob::OpHit > > opHits_Ps = this->
OpFlashToOpHits_Ps(flash_P);
716 const std::vector<double> retVec = this->
OpHitsToXYZ(opHits_Ps);
726 for(
auto& opHit_P : opHits_Ps){
const art::Ptr< sim::OpDetBacktrackerRecord > FindOpDetBTR(int const &opDetNum) const
Utilities related to art service access.
const std::unordered_set< const sim::SDP * > OpHitToEveSimSDPs_Ps(recob::OpHit const &opHit)
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)
const std::vector< const sim::SDP * > TrackIdToSimSDPs_Ps(int const &id)
double OpHitCollectionPurity(std::set< int > trackIDs, std::vector< art::Ptr< recob::OpHit > > const &hits)
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.
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< 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
const double OpHitLightCollectionEfficiency(std::set< int > const &tkIds, std::vector< art::Ptr< recob::OpHit > > const &opHits, std::vector< art::Ptr< recob::OpHit > > const &opHitsIn)
float energyFrac
fraction of OpHit energy from the particle with this trackID
double timePDclock_t
Type for iTimePDclock tick used in the interface.
double OpHitCollectionEfficiency(std::set< int > trackIDs, std::vector< art::Ptr< recob::OpHit > > const &hits, std::vector< art::Ptr< recob::OpHit > > const &allhits)
std::set< int > GetSetOfTrackIds() const
back track the reconstruction to the simulation
std::set< int > GetSetOfEveIds() const
const double OpHitLightCollectionPurity(std::set< int > const &tkIds, std::vector< art::Ptr< recob::OpHit > > const &opHits)
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)
PhotonBackTracker(fhicl::ParameterSet const &pset, art::ActivityRegistry ®)
code to link reconstructed objects back to the MC truth information
const std::set< int > GetSetOfTrackIds() const
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
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
const std::vector< double > OpHitsToXYZ(std::vector< art::Ptr< recob::OpHit > > const &opHits_Ps) const
const std::vector< const sim::SDP * > OpHitToSimSDPs_Ps(recob::OpHit const &opHit) const
double fMinOpHitEnergyFraction
minimum fraction of energy a track id has to
const art::InputTag fOpHitLabel
std::vector< evd::details::RawDigitInfo_t >::const_iterator end(RawDigitCacheDataClass const &cache)
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()
std::map< art::Ptr< recob::OpFlash >, std::vector< art::Ptr< recob::OpHit > > > priv_OpFlashToOpHits
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
art framework interface to geometry description
cet::coded_exception< error, detail::translate > exception
const std::vector< art::Ptr< recob::OpHit > > OpFlashToOpHits_Ps(art::Ptr< recob::OpFlash > &flash_P) const