LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
MCBTDemo_module.cc
Go to the documentation of this file.
1 // 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.
9 
16 
23 #include "larreco/MCComp/MCBTAlg.h"
24 #include <iostream>
25 
26 class MCBTDemo : public art::EDAnalyzer {
27 public:
28  explicit MCBTDemo(fhicl::ParameterSet const& p);
29  // The destructor generated by the compiler is fine for classes
30  // without bare pointers or other resource use.
31 
32  // Plugins should not be copied or assigned.
33  MCBTDemo(MCBTDemo const&) = delete;
34  MCBTDemo(MCBTDemo&&) = delete;
35  MCBTDemo& operator=(MCBTDemo const&) = delete;
36  MCBTDemo& operator=(MCBTDemo&&) = delete;
37 
38 private:
39  // Required functions.
40  void analyze(art::Event const& e) override;
41 
42  // Declare member data here.
43 };
44 
46 
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:94
std::vector< WireID > ChannelToWire(raw::ChannelID_t const channel) const
Returns a list of wires connected to the specified TPC channel.
Declaration of signal hit object.
Class def header for a class MCBTAlg.
MCBTDemo & operator=(MCBTDemo const &)=delete
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.cc:6
bool isValid() const noexcept
Definition: Handle.h:203
void analyze(art::Event const &e) override
void hits()
Definition: readHits.C:15
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
std::vector< double > MCQ(detinfo::DetectorClocksData const &clockData, const WireRange_t &hit) const
Definition: MCBTAlg.cxx:101
MCBTDemo(fhicl::ParameterSet const &p)
Provides recob::Track data product.
Class def header for mctrack data container.
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
std::vector< double > MCQFrac(detinfo::DetectorClocksData const &clockData, const WireRange_t &hit) const
Definition: MCBTAlg.cxx:126
object containing MC truth information necessary for making RawDigits and doing back tracking ...
Planes which measure W (third view for Bo, MicroBooNE, etc).
Definition: geo_types.h:137
Float_t e
Definition: plot.C:35
recob::tracking::Plane Plane
Definition: TrackState.h:17
Namespace collecting geometry-related classes utilities.
art framework interface to geometry description