79 msg +=
"Could not find a data product by: " + producer;
80 std::cout<<msg.c_str()<<std::endl;
215 msg +=
"\033[93m[ERROR]\033[00m <<";
217 msg +=
">> Producer's name not set!";
218 std::cout<<msg.c_str()<<std::endl;
219 throw ::showerreco::ShowerRecoException(msg.c_str());
226 fTree = tfs->
make<TTree>(
"fShowerQualityTree",
"");
234 "Shower 2D Cluster Matching Correctness; Correctness; Showers",
246 "Reco - MC Start X [cm] Displacement; #DeltaX [cm]; Showers",
250 "Reco - MC Start Y [cm] Displacement; #DeltaY [cm]; Showers",
254 "Reco - MC Start Z [cm] Displacement; #DeltaZ [cm]; Showers",
258 "Reco - MC Start 3D Vtx Displacement; #DeltaR [cm]; Showers",
270 "Direction Unit Vector Reco - MC #DeltaX; #DeltaCosX; Showers",
274 "Direction Unit Vector Reco - MC #DeltaY; #DeltaCosY; Showers",
278 "Direction Unit Vector Reco - MC #DeltaZ; #DeltaCosZ; Showers",
282 "3D Opening Angle Between Reco & MC; Opening Angle [degrees]; Showers",
293 "Reco (x) vs. MC (y) Energy Comparison; Reco Energy [MeV]; MC Energy [MeV]",
294 200,0,1000,200,0,1000);
297 "MC - Reco Energy Fractional Difference; Assymetry; Showers",
301 "MC - Reco Energy Difference; Energy Difference [MeV]; Showers",
311 "Matched Shower Cluster's Charge Efficiency; Efficiency; Clusters",
315 "Matched Shower Cluster's Charge Purity; Purity; Clusters",
323 "Best Plane (for energy & dE/dx estimate); Plane ID; Showers",
324 geo->Nplanes(),-0.5,geo->Nplanes()-0.5);
338 auto resHandle = GetDataOrDie< std::vector<recob::Shower > > (
e,
fShowerProducer);
340 const std::vector<sim::MCShower>& ev_mcs (*mcsHandle);
341 const std::vector<recob::Shower>& ev_shower (*resHandle);
342 const std::vector<sim::SimChannel>& ev_simch (*schHandle);
344 if(!(ev_shower.size()))
return;
353 e.get(cluster_m.at(0).front().id(),clsHandle);
354 if(!clsHandle.
isValid()) throw ::showerreco::ShowerRecoException(
"Failed to retrieve cluster handle!");
355 const std::vector<recob::Cluster>& ev_cluster (*clsHandle);
359 std::vector<std::vector<art::Ptr<recob::Hit> > > ev_cluster_hit;
360 ev_cluster_hit.reserve(clsHandle->size());
361 std::map<art::Ptr<recob::Cluster>,
size_t> cluster_ptr_map;
362 for(
size_t i=0; i<ev_cluster.size(); ++i) {
364 cluster_ptr_map[cluster_ptr] = ev_cluster_hit.size();
365 ev_cluster_hit.push_back(hit_m.at(i));
369 std::vector<std::vector<unsigned int> > ass_cluster_v;
370 ass_cluster_v.reserve(ev_shower.size());
371 for(
size_t shower_index=0; shower_index < ev_shower.size(); ++shower_index) {
372 ass_cluster_v.push_back(std::vector<unsigned int>());
373 for(
auto const& p : cluster_m.at(shower_index))
374 ass_cluster_v.back().push_back(cluster_ptr_map[p]);
378 std::vector<std::vector<unsigned int> > g4_trackid_v;
379 std::vector<unsigned int> mc_index_v;
380 g4_trackid_v.reserve(ev_mcs.size());
381 for(
size_t mc_index=0; mc_index<ev_mcs.size(); ++mc_index) {
382 auto const& mcs = ev_mcs[mc_index];
383 double energy = mcs.DetProfile().E();
384 std::vector<unsigned int> id_v;
385 id_v.reserve(mcs.DaughterTrackID().size());
387 for(
auto const&
id : mcs.DaughterTrackID()) {
388 if(
id == mcs.TrackID())
continue;
391 id_v.push_back(mcs.TrackID());
392 g4_trackid_v.push_back(id_v);
393 mc_index_v.push_back(mc_index);
398 std::cerr<<
"\033[93m[ERROR]\033[00m <<ShowerQuality::analyze>> Failed to build back-tracking map for MC..."<<std::endl;
403 std::vector<std::vector<double> > shower_mcq_vv(ev_shower.size(),std::vector<double>(mc_index_v.size(),0));
405 for(
size_t shower_index=0; shower_index < ass_cluster_v.size(); ++shower_index) {
407 auto const& ass_cluster = ass_cluster_v[shower_index];
409 std::vector< ::btutil::WireRange_t> w_v;
411 for(
auto const& cluster_index : ass_cluster) {
413 auto const& ass_hit = ev_cluster_hit[cluster_index];
415 w_v.reserve(ass_hit.size()+w_v.size());
417 for(
auto const& hit_ptr : ass_hit) {
420 hit_ptr->StartTick(),
428 auto& shower_mcq_v = shower_mcq_vv[shower_index];
430 for(
size_t mcs_index = 0; mcs_index < (mcq_v.size()-1); ++mcs_index) {
432 shower_mcq_v[mcs_index] = mcq_v[mcs_index];
438 for(
size_t mcs_index = 0; mcs_index < mc_index_v.size(); ++mcs_index) {
440 auto const& mc_shower = ev_mcs[mc_index_v[mcs_index]];
443 size_t best_shower_index = shower_mcq_vv.size();
445 for(
size_t shower_index = 0; shower_index < shower_mcq_vv.size(); ++shower_index) {
447 if( shower_mcq_vv[shower_index][mcs_index] > max_mcq)
448 best_shower_index = shower_index;
451 if(best_shower_index == shower_mcq_vv.size()) {
453 std::cerr <<
"\033[93m[ERROR]\033[00m <<ShowerQuality::analyze>> " 454 <<
"Failed to find a corresponding shower for MCShower " 455 << mc_index_v[mcs_index]
460 auto const& reco_shower = ev_shower[best_shower_index];
467 std::cerr <<
"\033[93m[ERROR]\033[00m <<ShowerQuality::analyze>> " 468 <<
"Failed to find a corresponding MCShower for shower " << best_shower_index
511 for(
auto const& cluster_index : ass_cluster_v[best_shower_index]) {
513 if(ep.first==0 && ep.second==0)
continue;
TH1D * hMatchedClusterPur
Matched 3D shower's cluster purity (combined across planes)
TH1D * hVtxDR
3D vtx distance between reco to MC in cm
void SetSimChannelProducer(const std::string name)
void SetMinEnergyCut(const double energy)
Set minimum energy for MCShowers to be considered.
TH1D * h3DAngleDiff
Opening angle between reco & MC 3D direction.
Class def header for a class MCMatchAlg.
Declaration of signal hit object.
ShowerQuality(fhicl::ParameterSet const &p)
const MCBTAlg & BTAlg() const
BTAlgo getter.
TH1D * hVtxDZ
Z difference (reco-MC) in cm.
std::string fMCShowerProducer
MCShower Producer's Name.
TH1D * hVtxDX
X difference (reco-MC) in cm.
TH1D * hDCosX
Direction unit vector X component difference.
TH1D * hVtxDY
Y difference (reco-MC) in cm.
bool BuildMap(const std::vector< unsigned int > &g4_trackid_v, const std::vector< sim::SimChannel > &simch_v, const std::vector< std::vector< art::Ptr< recob::Hit > > > &cluster_v)
Constructs needed information for Reco=>MC matching.
std::map< int, TH1D * > mDEDX
dEdx per particle per PDG code
void SetShowerProducer(const std::string name)
TH1D * hEnergyAssym
Energy assym. parameter: (reco E - MC E) / (reco E + MC E) * 2.
std::pair< double, double > ClusterEP(const size_t cluster_index, const size_t mcshower_index) const
For a specified cluster, compute cluster efficiency and purity in terms of specified MC object...
TH1D * hEnergyDiff
Energy difference: reco E - MC E.
std::string fShowerProducer
Shower Producer's Name.
#define DEFINE_ART_MODULE(klass)
::btutil::MCMatchAlg fBTAlg
Shower back tracking algorithm.
Provenance const * provenance() const
art::Handle< T > GetDataOrDie(art::Event const &e, std::string producer)
T get(std::string const &key) const
double _mc_energy_min
Minimum MC shower energy cut.
For convenience: struct to define a set of parameters per shower to be stored in TTree.
void SetMaxEnergyCut(const double energy)
Set maximum energy for MCShowers to be considered.
EDAnalyzer(Table< Config > const &config)
Declaration of cluster object.
TH2D * hEnergyCorr
Energy correlation reco (x) vs. MC (y)
ShowerQuality & operator=(ShowerQuality const &)=delete
T * make(ARGS...args) const
struct ShowerQuality::TreeParams_t fTreeParams
void InitializeAnaTree()
Function to prepare TTree.
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
void SetMCShowerProducer(const std::string name)
std::vector< double > MCQ(const WireRange_t &hit) const
Class def header for MCShower data container.
TTree * fTree
Analysis TTree.
TH1D * hMatchCorrectness
Matching correctness.
TH1D * hDCosZ
Direction unit vector Z component difference.
double _mc_energy_max
Maximum MC shower energy cut.
TH1D * hMatchedClusterEff
Matched 3D shower's cluster efficiency (combined across planes)
std::pair< size_t, double > ShowerCorrectness(const std::vector< unsigned int > cluster_indices) const
TH1D * hDCosY
Direction unit vector Y component difference.
std::string fSimChannelProducer
SimChannel Producer's Name.
Namespace collecting geometry-related classes utilities.
void analyze(art::Event const &e) override
TH1D * hBestPlane
Best plane id.
art framework interface to geometry description
Class def header for exception classes in ShowerReco3D package.