42 fDelay (config.Delay()),
43 fG4ModuleLabel(config.G4ModuleLabel()),
44 fOpHitLabel(config.OpHitLabel()),
45 fOpFlashLabel(config.OpFlashLabel()),
46 fMinOpHitEnergyFraction(config.MinOpHitEnergyFraction())
57 fDelay(pSet.get<double>(
"Delay")),
90 std::vector< const sim::SDP* > sdp_Ps;
92 const auto & pdTimeSDPmap =
priv_OpDetBTRs[odet]->timePDclockSDPsMap();
93 for(
auto mapitr = pdTimeSDPmap.begin(); mapitr != pdTimeSDPmap.
end(); mapitr++){
94 std::vector<sim::SDP>
const& sdpvec = (*mapitr).second;
95 for(
size_t iv = 0; iv < sdpvec.size(); ++iv){
97 if( abs(sdpvec[iv].trackID) == id) sdp_Ps.push_back(&(sdpvec[iv]));
110 <<
"PhotonBackTracker is not equiped to handle geo::Views.";
123 throw cet::exception(
"PhotonBackTracker2") <<
"No sim:: OpDetBacktrackerRecord corresponding " 124 <<
"to opDetNum: " << opDetNum <<
"\n";
131 double const& opHit_start_time,
double const& opHit_end_time)
const 133 std::vector< sim::TrackSDP > tSDPs;
139 std::vector<sim::SDP> simSDPs =
141 for(
size_t e = 0;
e < simSDPs.size(); ++
e)
143 if(totalE < 1.
e-5) totalE = 1.;
144 for(
size_t e = 0;
e < simSDPs.size(); ++
e){
149 info.
energy = simSDPs[
e].energy;
150 tSDPs.push_back(info);
165 std::vector<sim::TrackSDP> trackSDPs;
166 const double pTime = opHit_P->
PeakTime();
167 const double pWidth= opHit_P->
Width();
168 const double start = (pTime-pWidth)*1000-
fDelay;
169 const double end = (pTime+pWidth)*1000-
fDelay;
184 std::vector<sim::TrackSDP> trackSDPs;
185 const double pTime = opHit.
PeakTime();
186 const double pWidth= opHit.
Width();
187 const double start = (pTime-pWidth)*1000-
fDelay;
188 const double end = (pTime+pWidth)*1000-
fDelay;
198 std::vector< int > retVec;
200 retVec.push_back( trackSDP.trackID);
214 std::vector< int > retVec;
216 retVec.push_back( trackSDP.trackID);
240 std::map<int, float> eveIDtoEfrac;
243 for(
size_t t = 0; t < trackSDPs.size(); ++t){
245 totalE += trackSDPs[t].energy;
249 std::vector<sim::TrackSDP> eveSDPs;
250 eveSDPs.reserve(eveIDtoEfrac.size());
251 for(
auto itr = eveIDtoEfrac.begin(); itr != eveIDtoEfrac.end(); itr++){
255 temp.
energy = (*itr).second;
256 eveSDPs.push_back(std::move(temp));
266 std::vector<int> tkidFake(1, tkId);
269 const std::vector<art::Ptr<recob::OpHit>> out = (this->
TrackIdsToOpHits_Ps(tkidFake, hitsIn)).at(0);
276 std::vector<std::pair<int, art::Ptr<recob::OpHit>>> opHitList;
277 for(
auto itr = hitsIn.begin(); itr != hitsIn.end(); ++itr) {
280 const double pTime = opHit->
PeakTime(), pWidth= opHit->
Width();
281 const double start = (pTime-pWidth)*1000.0-
fDelay,
end = (pTime+ pWidth)*1000.0-
fDelay;
284 for(
auto itid = tids.begin(); itid != tids.end(); ++itid) {
285 for(
auto itkid = tkIds.begin(); itkid != tkIds.end(); ++itkid) {
286 if(itid->trackID == *itkid) {
288 opHitList.push_back(std::make_pair(*itkid, opHit));
294 std::vector<std::vector<art::Ptr<recob::OpHit>>> truOpHits;
296 std::vector<art::Ptr<recob::OpHit>> tmpOpHits;
297 for(
auto itkid = tkIds.begin(); itkid != tkIds.end(); ++itkid) {
299 for(
auto itr = opHitList.begin(); itr != opHitList.end(); ++itr) {
300 if(*itkid == (*itr).first) tmpOpHits.push_back((*itr).second);
302 truOpHits.push_back(tmpOpHits);
310 std::vector<const sim::SDP*> retVec;
311 double fPeakTime = opHit.
PeakTime();
312 double fWidth = opHit.
Width();
315 if(start_time > end_time){
throw;}
318 const std::vector<std::pair<double, std::vector<sim::SDP>> >& timeSDPMap
322 std::vector<const std::pair<double, std::vector<sim::SDP>>*> timePDclockSDPMap_SortedPointers;
323 for (
auto& pair : timeSDPMap ){ timePDclockSDPMap_SortedPointers.push_back(&pair); }
324 auto pairSort = [](
auto& a,
auto& b) {
return a->first < b->first ; } ;
325 if( !std::is_sorted( timePDclockSDPMap_SortedPointers.begin(), timePDclockSDPMap_SortedPointers.end(), pairSort)){
326 std::sort(timePDclockSDPMap_SortedPointers.begin(), timePDclockSDPMap_SortedPointers.end(), pairSort);
330 std::vector<sim::SDP> dummyVec;
331 std::pair<double, std::vector<sim::SDP>> start_timePair = std::make_pair(start_time, dummyVec);
332 std::pair<double, std::vector<sim::SDP>> end_timePair = std::make_pair(end_time, dummyVec);
333 auto start_timePair_P = &start_timePair;
334 auto end_timePair_P = &end_timePair;
336 auto mapFirst = std::lower_bound(timePDclockSDPMap_SortedPointers.begin(), timePDclockSDPMap_SortedPointers.end(), start_timePair_P, pairSort);
338 auto mapLast = std::upper_bound(mapFirst, timePDclockSDPMap_SortedPointers.end(), end_timePair_P, pairSort);
340 for(
auto& mapitr = mapFirst; mapitr != mapLast; ++mapitr )
341 for(
auto& sdp : (*mapitr)->second)
342 retVec.push_back(&sdp);
360 std::vector<double> xyz(3, -999.);
366 for(
auto const& sdp : sdps) {
367 double weight = sdp.numPhotons;
376 throw cet::exception(
"PhotonBackTracker") <<
"No sim::SDPs providing non-zero number of photons" 377 <<
" can't determine originating location from truth\n";
387 std::vector<double> xyz(3, -999.);
393 for(
const sim::SDP* sdp_P : sdps_Ps) {
395 double weight = sdp.numPhotons;
404 throw cet::exception(
"PhotonBackTracker") <<
"No sim::SDPs providing non-zero number of photons" 405 <<
" can't determine originating location from truth\n";
429 std::vector < const sim::SDP* > sdps_Ps;
430 for (
auto opHit_P : opHits_Ps ){
431 std::vector < const sim::SDP* > to_add_sdps_Ps = this->
OpHitToSimSDPs_Ps(opHit_P);
432 sdps_Ps.insert( sdps_Ps.end(), to_add_sdps_Ps.begin(), to_add_sdps_Ps.end() );
448 std::unordered_set <const sim::SDP* > sdps;
449 for(
auto const&
id : ids ){
451 for(
const sim::SDP* tmp_sdp : tmp_sdps ){
452 sdps.insert(tmp_sdp);
462 std::unordered_set <const sim::SDP* > sdps;
463 for(
auto const&
id : ids ){
465 for(
const sim::SDP* tmp_sdp : tmp_sdps ){
466 sdps.insert(tmp_sdp);
489 std::set<int> eveIds;
490 for(
auto const& opHit_P : opHits_Ps){
492 for(
auto const& sdp : sdps){eveIds.insert(sdp.trackID);}
500 std::set<int> eveIds;
501 for(
auto const& opHit : opHits){
503 for(
auto const& sdp : sdps){eveIds.insert(sdp.trackID);}
512 for(
auto const& opHit : opHits){
514 tids.insert(sdp.trackID);
524 for(
auto const& opHit : opHits){
526 tids.insert(sdp.trackID);
538 float total = 1.*opHits.size();;
540 for(
size_t h = 0; h < opHits.size(); ++h){
545 for(
size_t e = 0;
e < opHitTrackSDPs.size(); ++
e){
546 if(tkIds.find(opHitTrackSDPs[
e].trackID) != tkIds.end()){
553 if(total > 0) purity = desired/total;
568 for(
size_t h = 0; h < opHits.size(); ++h){
571 total+=opHit->
Area();
574 for(
size_t e = 0;
e < opHitTrackIDs.size(); ++
e){
575 if(tkIds.find(opHitTrackIDs[
e].trackID) != tkIds.end()){
576 desired += opHit->
Area();
582 if(total > 0) purity = desired/total;
592 throw cet::exception(
"PhotonBackTracker")<<
"This function is not supported. OpHits do not have type View.\n";
602 for(
size_t h = 0; h < opHits.size(); ++h){
607 for(
size_t e = 0;
e < opHitTrackSDPs.size(); ++
e){
608 if(tkIds.find(opHitTrackSDPs[
e].trackID) != tkIds.end() &&
616 for(
size_t h = 0; h < opHitsIn.size(); ++h){
619 for(
size_t e = 0;
e < opHitTrackSDPs.size(); ++
e){
624 if(tkIds.find(opHitTrackSDPs[
e].trackID) != tkIds.end() &&
631 double efficiency = 0.;
632 if(total > 0.) efficiency = desired/total;
642 throw cet::exception(
"PhotonBackTracker")<<
"This function is not supported. OpHits do not have type View.\n";
656 for(
size_t h = 0; h < opHits.size(); ++h){
665 for(
size_t e = 0;
e < opHitTrackIDs.size(); ++
e){
666 if(tkIds.find(opHitTrackIDs[
e].trackID) != tkIds.end() &&
668 desired += opHit->
Area();
673 for(
size_t h = 0; h < opHitsIn.size(); ++h){
679 for(
size_t e = 0;
e < opHitTrackIDs.size(); ++
e){
684 if(tkIds.find(opHitTrackIDs[
e].trackID) != tkIds.end() &&
686 total += opHit->
Area();
691 double efficiency = 0.;
692 if(total > 0.) efficiency = desired/total;
702 std::vector<art::Ptr<recob::OpHit>>
const& hits_Ps =
fOpFlashToOpHits.at(flash_P);
710 const std::vector< art::Ptr<recob::OpHit>> opHits_Ps = this->
OpFlashToOpHits_Ps(flash_P);
711 const std::vector<double> retVec = this->
OpHitsToXYZ(opHits_Ps);
719 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)
std::map< art::Ptr< recob::OpFlash >, std::vector< art::Ptr< recob::OpHit > > > fOpFlashToOpHits
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()
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