19 #include "art/Framework/Core/EDAnalyzer.h"
20 #include "art/Framework/Core/ModuleMacros.h"
21 #include "art/Framework/Principal/Event.h"
22 #include "art/Framework/Principal/Handle.h"
23 #include "art/Framework/Services/Registry/ServiceHandle.h"
24 #include "art_root_io/TFileService.h"
25 #include "canvas/Persistency/Common/Assns.h"
26 #include "canvas/Persistency/Common/FindManyP.h"
27 #include "canvas/Persistency/Common/Ptr.h"
28 #include "canvas/Persistency/Provenance/EventID.h"
29 #include "fhiclcpp/ParameterSet.h"
30 #include "messagefacility/MessageLogger/MessageLogger.h"
43 #include "nug4/ParticleNavigation/ParticleList.h"
44 #include "nusimdata/SimulationBase/MCParticle.h"
55 void analyze(art::Event
const&
e)
override;
56 void beginRun(art::Run
const&
r)
override;
63 std::map<std::pair<int, int>, std::pair<double, double>>& g4RecoBaseIDToPurityEfficiency);
65 std::string
const& label,
66 art::Handle<std::vector<recob::Cluster>>
const& clscol,
69 std::string
const& label,
70 art::Handle<std::vector<recob::Track>>
const& tcol,
73 std::string
const& label,
74 art::Handle<std::vector<recob::Shower>>
const& scol,
77 std::string
const& label,
78 art::Handle<std::vector<recob::Vertex>>
const& vtxcol,
81 std::string
const& label,
82 art::Handle<std::vector<recob::Event>>
const& evtcol,
90 std::map<std::pair<int, int>, std::pair<double, double>>
const& g4RecoBaseIDToPurityEfficiency,
91 std::map<
int,
std::vector<std::pair<
int, std::pair<double, double>>>>&
92 g4IDToRecoBasePurityEfficiency,
95 TH1D* purityEfficiency,
96 TH2D* purityEfficiency2D);
98 art::ServiceHandle<cheat::BackTrackerService const>
fBT;
99 art::ServiceHandle<cheat::ParticleInventoryService const>
fPI;
164 , fHitModuleLabel{p.get<std::string>(
"HitModuleLabel")}
182 if (e.isRealData()) {
183 mf::LogWarning(
"RecoVetter") <<
"attempting to run MC truth check on "
184 <<
"real data, bail";
189 art::Handle<std::vector<recob::Hit>> hithdl;
191 std::vector<art::Ptr<recob::Hit>> allhits;
192 art::fill_ptr_vector(allhits, hithdl);
195 art::Handle<std::vector<recob::Cluster>> clscol;
196 art::Handle<std::vector<recob::Track>> trkcol;
197 art::Handle<std::vector<recob::Shower>> shwcol;
198 art::Handle<std::vector<recob::Vertex>> vtxcol;
199 art::Handle<std::vector<recob::Event>> evtcol;
225 auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(e);
235 art::ServiceHandle<art::TFileService const>
tfs;
238 fEventPurity = tfs->make<TH1D>(
"eventPurity",
";Purity;Events", 100, 0., 1.1);
239 fEventEfficiency = tfs->make<TH1D>(
"eventEfficiency",
";Efficiency;Events", 100, 0., 1.1);
241 tfs->make<TH1D>(
"eventPurityEfficiency",
";purityEfficiency;Events", 110, 0., 1.1);
244 fVertexPurity = tfs->make<TH1D>(
"vertexPurity",
";Purity;Vertices", 100, 0., 1.1);
245 fVertexEfficiency = tfs->make<TH1D>(
"vertexEfficiency",
";Efficiency;Vertices", 100, 0., 1.1);
247 tfs->make<TH1D>(
"vertexPurityEfficiency",
";purityEfficiency;Vertex", 110, 0., 1.1);
250 fTrackPurity = tfs->make<TH1D>(
"trackPurity",
";Purity;Tracks", 100, 0., 1.1);
251 fTrackEfficiency = tfs->make<TH1D>(
"trackEfficiency",
";Efficiency;Tracks", 100, 0., 1.1);
253 tfs->make<TH1D>(
"trackPurityEfficiency",
";purityEfficiency;Tracks", 110, 0., 1.1);
255 tfs->make<TH2D>(
"trackPurityEfficiency2D",
";purity;efficiency", 110, 0., 1.1, 110, 0., 1.1);
258 fShowerPurity = tfs->make<TH1D>(
"showerPurity",
";Purity;Showers", 100, 0., 1.1);
259 fShowerEfficiency = tfs->make<TH1D>(
"showerEfficiency",
";Efficiency;Showers", 100, 0., 1.1);
261 tfs->make<TH1D>(
"showerPurityEfficiency",
";purityEfficiency;Showers", 110, 0., 1.1);
263 tfs->make<TH2D>(
"showerPurityEfficiency2D",
";purity;efficiency", 110, 0., 1.1, 110, 0., 1.1);
266 fClusterPurity = tfs->make<TH1D>(
"clusterPurity",
";Purity;Clusters", 110, 0., 1.1);
267 fClusterEfficiency = tfs->make<TH1D>(
"clusterEfficiency",
";Efficiency;Clusters", 110, 0., 1.1);
269 tfs->make<TH1D>(
"clusterPurityEfficiency",
";purityEfficiency;Clusters", 110, 0., 1.1);
271 "clusterPurityEfficiency2D",
";purity;efficiency", 110, 0., 1.1, 110, 0., 1.1);
274 fTree = tfs->make<TTree>(
"cheatertree",
"cheater tree");
306 std::map<std::pair<int, int>, std::pair<double, double>>& g4RecoBaseIDToPurityEfficiency)
310 std::set<int> trackIDs =
fBT->GetSetOfTrackIds(clockData, colHits);
314 std::set<int>::iterator itr = trackIDs.begin();
315 while (itr != trackIDs.end()) {
322 double purity =
fBT->HitCollectionPurity(clockData,
id, colHits);
323 double efficiency =
fBT->HitCollectionEfficiency(clockData,
id, colHits, allhits, view);
326 std::pair<double, double> pe(purity, efficiency);
329 std::pair<int, int> g4reco(*itr, colID);
332 g4RecoBaseIDToPurityEfficiency[g4reco] = pe;
344 std::string
const& label,
345 art::Handle<std::vector<recob::Cluster>>
const& clscol,
348 auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
349 art::FindManyP<recob::Hit> fmh(clscol, evt, label);
351 for (
size_t c = 0; c < clscol->size(); ++c) {
354 std::vector<art::Ptr<recob::Hit>> hits = fmh.at(c);
366 std::string
const& label,
367 art::Handle<std::vector<recob::Track>>
const& tcol,
370 auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
371 art::FindManyP<recob::Hit> fmh(tcol, evt, label);
373 for (
size_t p = 0; p < tcol->size(); ++
p) {
376 std::vector<art::Ptr<recob::Hit>> hits = fmh.at(p);
388 std::string
const& label,
389 art::Handle<std::vector<recob::Shower>>
const& scol,
392 auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
393 art::FindManyP<recob::Hit> fmh(scol, evt, label);
395 for (
size_t p = 0; p < scol->size(); ++
p) {
398 std::vector<art::Ptr<recob::Hit>> hits = fmh.at(p);
412 std::string
const& label,
413 art::Handle<std::vector<recob::Vertex>>
const& vtxcol,
416 const sim::ParticleList& plist =
fPI->ParticleList();
418 std::vector<std::set<int>> ids(1);
423 for (
const auto& PartPair : plist) {
424 auto trackID = PartPair.first;
425 if (!plist.IsPrimary(trackID))
continue;
426 const simb::MCParticle& part = *(PartPair.second);
427 ids[0].insert(trackID);
428 if (part.NumberDaughters() > 0) {
430 for (
int d = 0; d < part.NumberDaughters(); ++d)
431 dv.insert(part.Daughter(d));
432 ids.push_back(std::move(dv));
436 art::FindManyP<recob::Hit> fmh(vtxcol, evt, label);
438 auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
440 for (
size_t v = 0; v < vtxcol->size(); ++v) {
443 std::vector<art::Ptr<recob::Hit>> hits = fmh.at(v);
445 double maxPurity = -1.;
446 double maxEfficiency = -1.;
448 for (
size_t tv = 0; tv < ids.size(); ++tv) {
452 double purity =
fBT->HitCollectionPurity(clockData, ids[tv], hits);
453 double efficiency =
fBT->HitCollectionEfficiency(clockData, ids[tv], hits, allhits,
geo::k3D);
455 if (purity > maxPurity) maxPurity = purity;
456 if (efficiency > maxEfficiency) maxEfficiency = efficiency;
474 std::string
const& label,
475 art::Handle<std::vector<recob::Event>>
const& evtcol,
478 const sim::ParticleList& plist =
fPI->ParticleList();
483 for (
const auto& PartPair : plist) {
484 auto trackID = PartPair.first;
485 if (!plist.IsPrimary(trackID))
continue;
486 const simb::MCParticle& part = *(PartPair.second);
488 for (
int d = 0; d < part.NumberDaughters(); ++d)
489 ids.insert(part.Daughter(d));
492 art::FindManyP<recob::Hit> fmh(evtcol, evt, label);
494 auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
495 for (
size_t ev = 0; ev < evtcol->size(); ++ev) {
498 std::vector<art::Ptr<recob::Hit>> hits = fmh.at(ev);
502 double purity =
fBT->HitCollectionPurity(clockData, ids, hits);
503 double efficiency =
fBT->HitCollectionEfficiency(clockData, ids, hits, allhits,
geo::k3D);
517 std::map<std::pair<int, int>, std::pair<double, double>>
const& g4RecoBaseIDToPurityEfficiency,
518 std::map<
int,
std::vector<std::pair<
int, std::pair<double, double>>>>&
519 g4IDToRecoBasePurityEfficiency,
522 TH1D* purityEfficiency,
523 TH2D* purityEfficiency2D)
526 std::map<std::pair<int, int>, std::pair<double, double>>::const_iterator rbItr =
527 g4RecoBaseIDToPurityEfficiency.begin();
530 std::map<int, std::pair<double, double>> recoBIDToPurityEfficiency;
531 std::map<int, std::pair<double, double>>::iterator rbpeItr;
533 while (rbItr != g4RecoBaseIDToPurityEfficiency.end()) {
536 std::pair<int, int> g4cl = rbItr->first;
538 std::pair<double, double> pe = rbItr->second;
543 std::pair<int, std::pair<double, double>> clpe(g4cl.second, pe);
545 g4IDToRecoBasePurityEfficiency[g4cl.first].push_back(clpe);
549 rbpeItr = recoBIDToPurityEfficiency.find(g4cl.second);
550 if (rbpeItr != recoBIDToPurityEfficiency.end()) {
551 std::pair<double, double> curpe = rbpeItr->second;
552 if (pe.first > curpe.first) recoBIDToPurityEfficiency[g4cl.second] = pe;
555 recoBIDToPurityEfficiency[g4cl.second] = pe;
560 rbpeItr = recoBIDToPurityEfficiency.begin();
563 while (rbpeItr != recoBIDToPurityEfficiency.end()) {
564 purity->Fill(rbpeItr->second.first);
565 efficiency->Fill(rbpeItr->second.second);
566 purityEfficiency->Fill(rbpeItr->second.first * rbpeItr->second.second);
567 purityEfficiency2D->Fill(rbpeItr->second.first, rbpeItr->second.second);
580 std::map<int, double> g4IDToHitEnergy;
581 for (
size_t h = 0;
h < allhits.size(); ++
h) {
582 const std::vector<sim::TrackIDE> hitTrackIDs =
fBT->HitToTrackIDEs(clockData, allhits[
h]);
583 for (
size_t e = 0;
e < hitTrackIDs.size(); ++
e) {
584 g4IDToHitEnergy[hitTrackIDs[
e].trackID] += hitTrackIDs[
e].energy;
590 std::map<int, std::vector<std::pair<int, std::pair<double, double>>>>
591 g4IDToClusterPurityEfficiency;
592 std::map<int, std::vector<std::pair<int, std::pair<double, double>>>>
593 g4IDToShowerPurityEfficiency;
594 std::map<int, std::vector<std::pair<int, std::pair<double, double>>>> g4IDToTrackPurityEfficiency;
595 std::map<int, std::vector<std::pair<int, std::pair<double, double>>>>::iterator g4peItr;
599 g4IDToClusterPurityEfficiency,
606 g4IDToShowerPurityEfficiency,
613 g4IDToTrackPurityEfficiency,
621 std::set<int> trackIDs =
fBT->GetSetOfTrackIds();
622 std::set<int>::const_iterator trackItr = trackIDs.begin();
625 while (trackItr != trackIDs.end()) {
627 const simb::MCParticle* part =
fPI->TrackIdToParticle_P(*trackItr);
630 fpdg = part->PdgCode();
634 std::vector<const sim::IDE*> ides =
fBT->TrackIdToSimIDEs_Ps(*trackItr);
635 double totalDep = 0.;
636 for (
size_t i = 0; i < ides.size(); ++i)
637 totalDep += ides[i]->energy;
639 if (totalDep > 0.)
fhiteff = g4IDToHitEnergy[*trackItr] / totalDep;
641 std::vector<std::pair<int, std::pair<double, double>>> clVec;
642 std::vector<std::pair<int, std::pair<double, double>>> shVec;
643 std::vector<std::pair<int, std::pair<double, double>>> trVec;
645 if (g4IDToClusterPurityEfficiency.find(*trackItr) != g4IDToClusterPurityEfficiency.end())
646 clVec = g4IDToClusterPurityEfficiency.find(*trackItr)->second;
648 if (g4IDToShowerPurityEfficiency.find(*trackItr) != g4IDToShowerPurityEfficiency.end())
649 shVec = g4IDToShowerPurityEfficiency.find(*trackItr)->second;
651 if (g4IDToTrackPurityEfficiency.find(*trackItr) != g4IDToTrackPurityEfficiency.end())
652 trVec = g4IDToTrackPurityEfficiency.find(*trackItr)->second;
654 fnclu = clVec.size();
655 fnshw = shVec.size();
656 fntrk = trVec.size();
658 for (
size_t c = 0; c < clVec.size(); ++c) {
664 for (
size_t s = 0;
s < shVec.size(); ++
s) {
670 for (
size_t t = 0; t < trVec.size(); ++t) {
art::ServiceHandle< cheat::BackTrackerService const > fBT
the back tracker service
int fpdg
particle pdg code
int fnshw
number of showers for this particle
then if[["$THISISATEST"==1]]
void analyze(art::Event const &e) override
TH1D * fTrackPurityEfficiency
histogram of track efficiency times purity
bool fCheckVertices
should we check the reconstruction of vertices?
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
double fhiteff
hitfinder efficiency for this particle
TH1D * fClusterPurityEfficiency
histogram of cluster efficiency times purity
Declaration of signal hit object.
int fnclu
number of clusters for this particle
void CheckReco(detinfo::DetectorClocksData const &clockData, int const &colID, std::vector< art::Ptr< recob::Hit >> const &allhits, std::vector< art::Ptr< recob::Hit >> const &colHits, std::map< std::pair< int, int >, std::pair< double, double >> &g4RecoBaseIDToPurityEfficiency)
void CheckRecoEvents(art::Event const &evt, std::string const &label, art::Handle< std::vector< recob::Event >> const &evtcol, std::vector< art::Ptr< recob::Hit >> const &allhits)
art::ServiceHandle< cheat::ParticleInventoryService const > fPI
the back tracker service
int fntrk
number of tracks for this particle
RecoCheckAna(fhicl::ParameterSet const &p)
TH1D * fEventPurity
histogram of event purity
bool fCheckEvents
should we check the reconstruction of events?
std::map< std::pair< int, int >, std::pair< double, double > > fG4ClusterIDToPurityEfficiency
TH2D * fTrackPurityEfficiency2D
scatter histogram of cluster purity and efficiency
void beginRun(art::Run const &r) override
TH1D * fEventEfficiency
histogram of event efficiency
TH1D * fVertexPurity
histogram of vertex purity
TH1D * fEventPurityEfficiency
histogram of event efficiency times purity
3-dimensional objects, potentially hits, clusters, prongs, etc.
TH1D * fVertexPurityEfficiency
histogram of vertex efficiency times purity
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
void CheckRecoTracks(art::Event const &evt, std::string const &label, art::Handle< std::vector< recob::Track >> const &tcol, std::vector< art::Ptr< recob::Hit >> const &allhits)
std::vector< double > fclupur
cluster purities
std::vector< double > fshweff
shower efficiencies
bool fCheckClusters
should we check the reconstruction of clusters?
std::vector< double > fshwpur
shower purities
TTree * fTree
TTree to save efficiencies.
std::vector< int > fshwid
shower IDs
TH1D * fVertexEfficiency
histogram of vertex efficiency
std::vector< int > ftrkid
track IDs
std::vector< double > ftrkeff
track efficiencies
bool fCheckTracks
should we check the reconstruction of tracks?
std::vector< double > fclueff
cluster efficiencies
std::string fTrackModuleLabel
label for module making the tracks
double fpmom
particle momentum
void FlattenMap(std::map< std::pair< int, int >, std::pair< double, double >> const &g4RecoBaseIDToPurityEfficiency, std::map< int, std::vector< std::pair< int, std::pair< double, double >>>> &g4IDToRecoBasePurityEfficiency, TH1D *purity, TH1D *efficiency, TH1D *purityEfficiency, TH2D *purityEfficiency2D)
std::vector< int > fcluid
cluster IDs
Declaration of cluster object.
std::vector< double > ftrkpur
track purities
Definition of data types for geometry description.
Provides recob::Track data product.
bool fCheckShowers
should we check the reconstruction of showers?
std::map< std::pair< int, int >, std::pair< double, double > > fG4TrackIDToPurityEfficiency
void CheckRecoShowers(art::Event const &evt, std::string const &label, art::Handle< std::vector< recob::Shower >> const &scol, std::vector< art::Ptr< recob::Hit >> const &allhits)
int ftrackid
geant track ID
Represents the Event implemented as a self balancing binary search tree.
Contains all timing reference information for the detector.
TH1D * fShowerPurityEfficiency
histogram of shower efficiency times purity
TH1D * fClusterPurity
histogram of cluster purity
std::map< std::pair< int, int >, std::pair< double, double > > fG4ShowerIDToPurityEfficiency
then echo File list $list not found else cat $list while read file do echo $file sed s
void FillResults(detinfo::DetectorClocksData const &clockData, std::vector< art::Ptr< recob::Hit >> const &allhits)
void CheckRecoVertices(art::Event const &evt, std::string const &label, art::Handle< std::vector< recob::Vertex >> const &vtxcol, std::vector< art::Ptr< recob::Hit >> const &allhits)
object containing MC truth information necessary for making RawDigits and doing back tracking ...
std::string fClusterModuleLabel
label for module making the clusters
TH1D * fClusterEfficiency
histogram of cluster efficiency
TH1D * fShowerPurity
histogram of shower purity
void CheckRecoClusters(art::Event const &evt, std::string const &label, art::Handle< std::vector< recob::Cluster >> const &clscol, std::vector< art::Ptr< recob::Hit >> const &allhits)
std::string fShowerModuleLabel
label for module making the showers
TH1D * fShowerEfficiency
histogram of shower efficiency
art::ServiceHandle< art::TFileService > tfs
std::string fEventModuleLabel
label for module making the events
TH1D * fTrackPurity
histogram of track purity
TH2D * fClusterPurityEfficiency2D
scatter histogram of cluster purity and efficiency
std::string fVertexModuleLabel
label for module making the vertices
TH1D * fTrackEfficiency
histogram of track efficiency
TH2D * fShowerPurityEfficiency2D
scatter histogram of cluster purity and efficiency
std::string fHitModuleLabel
label for module making the hits