27 #include "messagefacility/MessageLogger/MessageLogger.h"
43 fDelay (config.Delay()),
44 fG4ModuleLabel(config.G4ModuleLabel()),
45 fG4ModuleLabels(config.G4ModuleLabels()),
49 fMinOpHitEnergyFraction(config.MinOpHitEnergyFraction())
60 fDelay(pSet.
get<double>(
"Delay")),
61 fG4ModuleLabel(pSet.
get<art::InputTag>(
"G4ModuleLabel",
"largeant")),
62 fG4ModuleLabels(pSet.
get<
std::
vector<art::InputTag>>(
"G4ModuleLabels", {})),
63 fOpHitLabel(pSet.get<art::InputTag>(
"OpHitLabel",
"ophit")),
64 fOpFlashLabel(pSet.get<art::InputTag>(
"OpFlashLabel",
"opflash")),
65 fMinOpHitEnergyFraction(pSet.get<
double>(
"MinimumOpHitEnergyFraction", 0.1))
99 std::vector< const sim::SDP* > sdp_Ps;
101 const auto & pdTimeSDPmap =
priv_OpDetBTRs[odet]->timePDclockSDPsMap();
102 for(
auto mapitr = pdTimeSDPmap.begin(); mapitr != pdTimeSDPmap.
end(); mapitr++){
103 std::vector<sim::SDP>
const& sdpvec = (*mapitr).second;
104 for(
size_t iv = 0; iv < sdpvec.size(); ++iv){
106 if(
abs(sdpvec[iv].trackID) == id) sdp_Ps.push_back(&(sdpvec[iv]));
118 throw cet::exception(
"PhotonBackTracker")
119 <<
"PhotonBackTracker is not equiped to handle geo::Views.";
125 art::Ptr< sim::OpDetBacktrackerRecord > opDet;
132 throw cet::exception(
"PhotonBackTracker2") <<
"No sim:: OpDetBacktrackerRecord corresponding "
133 <<
"to opDetNum: " << opDetNum <<
"\n";
140 double const& opHit_start_time,
double const& opHit_end_time)
const
142 std::vector< sim::TrackSDP > tSDPs;
145 const art::Ptr< sim::OpDetBacktrackerRecord > opDetBTR =
148 std::vector<sim::SDP> simSDPs =
149 opDetBTR->TrackIDsAndEnergies(opHit_start_time, opHit_end_time);
150 for(
size_t e = 0;
e < simSDPs.size(); ++
e)
151 totalE += simSDPs[
e].energy;
152 if(totalE < 1.
e-5) totalE = 1.;
153 for(
size_t e = 0;
e < simSDPs.size(); ++
e){
158 info.
energy = simSDPs[
e].energy;
159 tSDPs.push_back(info);
162 catch(cet::exception
const&
e){
163 mf::LogWarning(
"PhotonBackTracker")<<
"Exception caught\n"
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;
184 const double pTime = opHit.
PeakTime();
185 const double pWidth= opHit.
Width();
186 const double start = (pTime-pWidth)*1000-
fDelay;
187 const double end = (pTime+pWidth)*1000-
fDelay;
194 std::vector< int > retVec;
196 retVec.push_back( trackSDP.trackID);
210 std::vector< int > retVec;
212 retVec.push_back( trackSDP.trackID);
236 std::map<int, float> eveIDtoEfrac;
239 for(
size_t t = 0; t < trackSDPs.size(); ++t){
241 totalE += trackSDPs[t].energy;
245 std::vector<sim::TrackSDP> eveSDPs;
246 eveSDPs.reserve(eveIDtoEfrac.size());
247 for(
auto itr = eveIDtoEfrac.begin(); itr != eveIDtoEfrac.end(); itr++){
251 temp.
energy = (*itr).second;
252 eveSDPs.push_back(std::move(temp));
262 std::vector<int> tkidFake(1, tkId);
265 const std::vector<art::Ptr<recob::OpHit>> out = (this->
TrackIdsToOpHits_Ps(tkidFake, hitsIn)).at(0);
272 std::vector<std::pair<int, art::Ptr<recob::OpHit>>> opHitList;
273 for(
auto itr = hitsIn.begin(); itr != hitsIn.end(); ++itr) {
274 art::Ptr<recob::OpHit>
const& opHit = *itr;
276 const double pTime = opHit->PeakTime(), pWidth= opHit->Width();
277 const double start = (pTime-pWidth)*1000.0-
fDelay,
end = (pTime+ pWidth)*1000.0-
fDelay;
280 for(
auto itid = tids.begin(); itid != tids.end(); ++itid) {
281 for(
auto itkid = tkIds.begin(); itkid != tkIds.end(); ++itkid) {
282 if(itid->trackID == *itkid) {
284 opHitList.push_back(std::make_pair(*itkid, opHit));
290 std::vector<std::vector<art::Ptr<recob::OpHit>>> truOpHits;
292 std::vector<art::Ptr<recob::OpHit>> tmpOpHits;
293 for(
auto itkid = tkIds.begin(); itkid != tkIds.end(); ++itkid) {
295 for(
auto itr = opHitList.begin(); itr != opHitList.end(); ++itr) {
296 if(*itkid == (*itr).first) tmpOpHits.push_back((*itr).second);
298 truOpHits.push_back(tmpOpHits);
306 std::vector<const sim::SDP*> retVec;
307 double fPeakTime = opHit.
PeakTime();
308 double fWidth = opHit.
Width();
311 if(start_time > end_time){
throw;}
314 const std::vector<std::pair<double, std::vector<sim::SDP>> >& timeSDPMap
318 std::vector<const std::pair<double, std::vector<sim::SDP>>*> timePDclockSDPMap_SortedPointers;
319 for (
auto& pair : timeSDPMap ){ timePDclockSDPMap_SortedPointers.push_back(&pair); }
320 auto pairSort = [](
auto&
a,
auto& b) {
return a->first < b->first ; } ;
321 if( !std::is_sorted( timePDclockSDPMap_SortedPointers.begin(), timePDclockSDPMap_SortedPointers.end(), pairSort)){
322 std::sort(timePDclockSDPMap_SortedPointers.begin(), timePDclockSDPMap_SortedPointers.end(), pairSort);
326 std::vector<sim::SDP> dummyVec;
327 std::pair<double, std::vector<sim::SDP>> start_timePair = std::make_pair(start_time, dummyVec);
328 std::pair<double, std::vector<sim::SDP>> end_timePair = std::make_pair(end_time, dummyVec);
329 auto start_timePair_P = &start_timePair;
330 auto end_timePair_P = &end_timePair;
332 auto mapFirst = std::lower_bound(timePDclockSDPMap_SortedPointers.begin(), timePDclockSDPMap_SortedPointers.end(), start_timePair_P, pairSort);
334 auto mapLast = std::upper_bound(mapFirst, timePDclockSDPMap_SortedPointers.end(), end_timePair_P, pairSort);
336 for(
auto& mapitr = mapFirst; mapitr != mapLast; ++mapitr )
337 for(
auto& sdp : (*mapitr)->second)
338 retVec.push_back(&sdp);
357 std::vector<double> xyz(3, -999.);
363 for(
auto const& sdp : sdps) {
364 double weight = sdp.numPhotons;
373 throw cet::exception(
"PhotonBackTracker") <<
"No sim::SDPs providing non-zero number of photons"
374 <<
" can't determine originating location from truth\n";
384 std::vector<double> xyz(3, -999.);
390 for(
const sim::SDP* sdp_P : sdps_Ps) {
392 double weight = sdp.numPhotons;
401 throw cet::exception(
"PhotonBackTracker") <<
"No sim::SDPs providing non-zero number of photons"
402 <<
" can't determine originating location from truth\n";
426 std::vector < const sim::SDP* > sdps_Ps;
427 for (
auto opHit_P : opHits_Ps ){
428 std::vector < const sim::SDP* > to_add_sdps_Ps = this->
OpHitToSimSDPs_Ps(opHit_P);
429 sdps_Ps.insert( sdps_Ps.end(), to_add_sdps_Ps.begin(), to_add_sdps_Ps.end() );
445 std::unordered_set <const sim::SDP* > sdps;
446 for(
auto const&
id : ids ){
448 for(
const sim::SDP* tmp_sdp : tmp_sdps ){
449 sdps.insert(tmp_sdp);
459 std::unordered_set <const sim::SDP* > sdps;
460 for(
auto const&
id : ids ){
462 for(
const sim::SDP* tmp_sdp : tmp_sdps ){
463 sdps.insert(tmp_sdp);
486 std::set<int> eveIds;
487 for(
auto const& opHit_P : opHits_Ps){
489 for(
auto const& sdp : sdps){eveIds.insert(sdp.trackID);}
497 std::set<int> eveIds;
498 for(
auto const& opHit : opHits){
500 for(
auto const& sdp : sdps){eveIds.insert(sdp.trackID);}
509 for(
auto const& opHit : opHits){
511 tids.insert(sdp.trackID);
521 for(
auto const& opHit : opHits){
523 tids.insert(sdp.trackID);
531 std::vector< art::Ptr<recob::OpHit> >
const& opHits)
535 float total = 1.*opHits.size();;
537 for(
size_t h = 0;
h < opHits.size(); ++
h){
538 art::Ptr<recob::OpHit> opHit = opHits[
h];
542 for(
size_t e = 0;
e < opHitTrackSDPs.size(); ++
e){
543 if(tkIds.find(opHitTrackSDPs[
e].trackID) != tkIds.end()){
550 if(total > 0) purity = desired/total;
556 std::vector< art::Ptr<recob::OpHit> >
const& opHits)
565 for(
size_t h = 0;
h < opHits.size(); ++
h){
566 art::Ptr<recob::OpHit> opHit = opHits[
h];
568 total+=opHit->Area();
571 for(
size_t e = 0;
e < opHitTrackIDs.size(); ++
e){
572 if(tkIds.find(opHitTrackIDs[
e].trackID) != tkIds.end()){
573 desired += opHit->Area();
579 if(total > 0) purity = desired/total;
585 std::vector< art::Ptr<recob::OpHit> >
const& opHits,
586 std::vector< art::Ptr<recob::OpHit> >
const& opHitsIn,
589 throw cet::exception(
"PhotonBackTracker")<<
"This function is not supported. OpHits do not have type View.\n";
594 std::vector< art::Ptr<recob::OpHit> >
const& opHits,
595 std::vector< art::Ptr<recob::OpHit> >
const& opHitsIn)
599 for(
size_t h = 0;
h < opHits.size(); ++
h){
600 art::Ptr<recob::OpHit> opHit = opHits[
h];
604 for(
size_t e = 0; e < opHitTrackSDPs.size(); ++
e){
605 if(tkIds.find(opHitTrackSDPs[e].trackID) != tkIds.end() &&
613 for(
size_t h = 0;
h < opHitsIn.size(); ++
h){
614 art::Ptr<recob::OpHit> opHit = opHitsIn[
h];
616 for(
size_t e = 0; e < opHitTrackSDPs.size(); ++
e){
621 if(tkIds.find(opHitTrackSDPs[e].trackID) != tkIds.end() &&
628 double efficiency = 0.;
629 if(total > 0.) efficiency = desired/total;
635 std::vector< art::Ptr<recob::OpHit> >
const& opHits,
636 std::vector< art::Ptr<recob::OpHit> >
const& opHitsIn,
639 throw cet::exception(
"PhotonBackTracker")<<
"This function is not supported. OpHits do not have type View.\n";
644 std::vector< art::Ptr<recob::OpHit> >
const& opHits,
645 std::vector< art::Ptr<recob::OpHit> >
const& opHitsIn)
653 for(
size_t h = 0;
h < opHits.size(); ++
h){
655 art::Ptr<recob::OpHit> opHit = opHits[
h];
662 for(
size_t e = 0; e < opHitTrackIDs.size(); ++
e){
663 if(tkIds.find(opHitTrackIDs[e].trackID) != tkIds.end() &&
665 desired += opHit->Area();
670 for(
size_t h = 0;
h < opHitsIn.size(); ++
h){
671 art::Ptr<recob::OpHit> opHit = opHitsIn[
h];
676 for(
size_t e = 0; e < opHitTrackIDs.size(); ++
e){
681 if(tkIds.find(opHitTrackIDs[e].trackID) != tkIds.end() &&
683 total += opHit->Area();
688 double efficiency = 0.;
689 if(total > 0.) efficiency = desired/total;
697 std::vector<art::Ptr<recob::OpHit>>
const& hits_Ps = priv_OpFlashToOpHits.at(flash_P);
704 const std::vector< art::Ptr< recob::OpHit > > opHits_Ps = this->
OpFlashToOpHits_Ps(flash_P);
705 const std::vector<double> retVec = this->
OpHitsToXYZ(opHits_Ps);
715 for(
auto& opHit_P : opHits_Ps){
const std::unordered_set< const sim::SDP * > OpHitToEveSimSDPs_Ps(recob::OpHit const &opHit)
const art::Ptr< sim::OpDetBacktrackerRecord > FindOpDetBTR(int const &opDetNum) const
process_name opflash particleana ie ie ie z
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
const std::vector< const sim::SDP * > OpHitsToSimSDPs_Ps(std::vector< art::Ptr< recob::OpHit > > const &opHits_Ps) const
std::vector< double > OpHitToXYZ(art::Ptr< recob::OpHit > const &hit)
process_name opflash particleana ie x
fOpHitLabel(pSet.get< art::InputTag >("OpHitLabel","ophit"))
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
std::vector< double > SimSDPsToXYZ(std::vector< sim::SDP > const &sdps)
const std::vector< art::Ptr< recob::OpHit > > OpFlashToOpHits_Ps(art::Ptr< recob::OpFlash > &flash_P) const
double OpHitCollectionPurity(std::set< int > trackIDs, std::vector< art::Ptr< recob::OpHit > > const &hits)
const std::set< int > OpFlashToTrackIds(art::Ptr< recob::OpFlash > &flash_P) const
unsigned int OpDetFromOpChannel(int opChannel) const
Convert unique channel to detector number.
const std::vector< const sim::SDP * > TrackIdToSimSDPs_Ps(int const &id)
const std::vector< const sim::SDP * > OpHitToSimSDPs_Ps(recob::OpHit const &opHit) const
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Access the description of detector geometry.
then echo fcl sbnd_project sbnd_project sbnd_project sbnd_project production production end_time
process_name opflash particleana ie ie y
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 std::set< int > GetSetOfEveIds() const
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.
auto end(FixedBins< T, C > const &) noexcept
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
const std::set< int > GetSetOfTrackIds() const
back track the reconstruction to the simulation
const std::vector< sim::TrackSDP > OpHitToEveTrackSDPs(art::Ptr< recob::OpHit > const &opHit_P) const
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< double > OpFlashToXYZ(art::Ptr< recob::OpFlash > &flash_P) const
const std::vector< int > OpHitToEveTrackIds(recob::OpHit const &opHit)
Ionization photons from a Geant4 track.
std::vector< sim::TrackSDP > OpHitToTrackSDPs(art::Ptr< recob::OpHit > const &hit)
then echo fcl sbnd_project sbnd_project sbnd_project sbnd_project production production start_time
PhotonBackTracker(fhicl::ParameterSet const &pset, art::ActivityRegistry ®)
std::vector< art::Ptr< sim::OpDetBacktrackerRecord > > const & OpDetBTRs()
const std::vector< int > OpHitToTrackIds(recob::OpHit const &opHit) const
const std::vector< double > OpHitsToXYZ(std::vector< art::Ptr< recob::OpHit > > const &opHits_Ps) const
fOpFlashLabel(pSet.get< art::InputTag >("OpFlashLabel","opflash"))
Header for the ParticleInvenotry Service Provider.
double fMinOpHitEnergyFraction
minimum fraction of energy a track id has to
const std::vector< art::Ptr< recob::OpHit > > TrackIdToOpHits_Ps(int const &tkId, std::vector< art::Ptr< recob::OpHit >> const &hitsIn)
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< std::vector< art::Ptr< recob::OpHit > > > TrackIdsToOpHits_Ps(std::vector< int > const &tkIds, std::vector< art::Ptr< recob::OpHit >> const &hitsIn)
const std::vector< sim::TrackSDP > OpDetToTrackSDPs(int const &OpDetNum, double const &opHit_start_time, double const &opHit_end_time) const