MCBTDemo_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: MCBTDemo
3 // Module Type: analyzer
4 // File: MCBTDemo_module.cc
5 //
6 // Generated at Thu Jan 8 08:16:24 2015 by Kazuhiro Terao using artmod
7 // from cetpkgsupport v1_08_02.
8 ////////////////////////////////////////////////////////////////////////
9 
14 #include "canvas/Persistency/Common/FindManyP.h"
15 
16 #include "MCBTAlg.h"
23 #include <iostream>
24 
25 class MCBTDemo : public art::EDAnalyzer {
26 public:
27  explicit MCBTDemo(fhicl::ParameterSet const& p);
28  // The destructor generated by the compiler is fine for classes
29  // without bare pointers or other resource use.
30 
31  // Plugins should not be copied or assigned.
32  MCBTDemo(MCBTDemo const&) = delete;
33  MCBTDemo(MCBTDemo&&) = delete;
34  MCBTDemo& operator=(MCBTDemo const&) = delete;
35  MCBTDemo& operator=(MCBTDemo&&) = delete;
36 
37 private:
38  // Required functions.
39  void analyze(art::Event const& e) override;
40 
41  // Declare member data here.
42 };
43 
45 
46 void
48 {
49  // Implementation of required member function here.
51  e.getByLabel("mcreco", mctHandle);
52 
54  e.getByLabel("largeant", schHandle);
55 
57  e.getByLabel("trackkalmanhit", trkHandle);
58 
59  if (!mctHandle.isValid() || !schHandle.isValid() || !trkHandle.isValid()) return;
60 
61  // Collect G4 track ID from MCTrack whose energy loss > 100 MeV inside the detector
62  std::vector<unsigned int> g4_track_id;
63  for (auto const& mct : *mctHandle) {
64 
65  if (!mct.size()) continue;
66 
67  double dE = (*mct.begin()).Momentum().E() - (*mct.rbegin()).Momentum().E();
68  if (dE > 100) g4_track_id.push_back(mct.TrackID());
69  }
70 
71  if (g4_track_id.size()) {
72 
74  btutil::MCBTAlg alg_mct(g4_track_id, *schHandle);
75 
76  auto sum_mcq_v = alg_mct.MCQSum(2);
77  std::cout << "Total charge contents on W plane:" << std::endl;
78  for (size_t i = 0; i < sum_mcq_v.size() - 1; ++i)
79  std::cout << " MCTrack " << i << " => " << sum_mcq_v[i] << std::endl;
80  std::cout << " Others => " << (*sum_mcq_v.rbegin()) << std::endl;
81 
82  // Loop over reconstructed tracks and find charge fraction
83  art::FindManyP<recob::Hit> hit_coll_v(trkHandle, e, "trackkalmanhit");
84  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(e);
85 
86  for (size_t i = 0; i < trkHandle->size(); ++i) {
87 
88  const std::vector<art::Ptr<recob::Hit>> hit_coll = hit_coll_v.at(i);
89 
90  std::vector<btutil::WireRange_t> hits;
91 
92  for (auto const& h_ptr : hit_coll) {
93 
94  if (geo->ChannelToWire(h_ptr->Channel())[0].Plane != ::geo::kW) continue;
95 
96  hits.emplace_back(h_ptr->Channel(), h_ptr->StartTick(), h_ptr->EndTick());
97  }
98 
99  auto mcq_v = alg_mct.MCQ(clockData, hits);
100  auto mcq_frac_v = alg_mct.MCQFrac(clockData, hits);
101 
102  std::cout << "Track " << i << " "
103  << "Y plane Charge from first MCTrack: " << mcq_v[0]
104  << " ... Purity: " << mcq_frac_v[0]
105  << " ... Efficiency: " << mcq_v[0] / sum_mcq_v[0] << std::endl;
106  }
107  }
108 }
109 
const std::vector< double > & MCQSum(const size_t plane_id) const
Definition: MCBTAlg.cxx:98
Class def header for a class MCBTAlg.
std::vector< geo::WireID > ChannelToWire(raw::ChannelID_t const channel) const
Returns a list of wires connected to the specified TPC channel.
MCBTDemo & operator=(MCBTDemo const &)=delete
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
art framework interface to geometry description
bool isValid() const noexcept
Definition: Handle.h:191
void analyze(art::Event const &e) override
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:633
const double e
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
std::vector< double > MCQ(detinfo::DetectorClocksData const &clockData, const WireRange_t &hit) const
Definition: MCBTAlg.cxx:106
MCBTDemo(fhicl::ParameterSet const &p)
p
Definition: test.py:223
Class def header for mctrack data container.
Declaration of signal hit object.
std::vector< double > MCQFrac(detinfo::DetectorClocksData const &clockData, const WireRange_t &hit) const
Definition: MCBTAlg.cxx:131
Provides recob::Track data product.
Planes which measure W (third view for Bo, MicroBooNE, etc).
Definition: geo_types.h:131
recob::tracking::Plane Plane
Definition: TrackState.h:17
LArSoft geometry interface.
Definition: ChannelGeo.h:16
QTextStream & endl(QTextStream &s)