All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
10 #include "art/Framework/Core/EDAnalyzer.h"
11 #include "art/Framework/Core/ModuleMacros.h"
12 #include "art/Framework/Principal/Event.h"
13 #include "art/Framework/Principal/Handle.h"
14 #include "art/Framework/Services/Registry/ServiceHandle.h"
15 #include "canvas/Persistency/Common/FindManyP.h"
16 
17 #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 
45 MCBTDemo::MCBTDemo(fhicl::ParameterSet const& p) : EDAnalyzer(p) {}
46 
47 void
48 MCBTDemo::analyze(art::Event const& e)
49 {
50  // Implementation of required member function here.
51  art::Handle<std::vector<sim::MCTrack>> mctHandle;
52  e.getByLabel("mcreco", mctHandle);
53 
54  art::Handle<std::vector<sim::SimChannel>> schHandle;
55  e.getByLabel("largeant", schHandle);
56 
57  art::Handle<std::vector<recob::Track>> trkHandle;
58  e.getByLabel("trackkalmanhit", trkHandle);
59 
60  if (!mctHandle.isValid() || !schHandle.isValid() || !trkHandle.isValid()) return;
61 
62  // Collect G4 track ID from MCTrack whose energy loss > 100 MeV inside the detector
63  std::vector<unsigned int> g4_track_id;
64  for (auto const& mct : *mctHandle) {
65 
66  if (!mct.size()) continue;
67 
68  double dE = (*mct.begin()).Momentum().E() - (*mct.rbegin()).Momentum().E();
69  if (dE > 100) g4_track_id.push_back(mct.TrackID());
70  }
71 
72  if (g4_track_id.size()) {
73 
74  art::ServiceHandle<geo::Geometry const> geo;
75  btutil::MCBTAlg alg_mct(g4_track_id, *schHandle);
76 
77  auto sum_mcq_v = alg_mct.MCQSum(2);
78  std::cout << "Total charge contents on W plane:" << std::endl;
79  for (size_t i = 0; i < sum_mcq_v.size() - 1; ++i)
80  std::cout << " MCTrack " << i << " => " << sum_mcq_v[i] << std::endl;
81  std::cout << " Others => " << (*sum_mcq_v.rbegin()) << std::endl;
82 
83  // Loop over reconstructed tracks and find charge fraction
84  art::FindManyP<recob::Hit> hit_coll_v(trkHandle, e, "trackkalmanhit");
85  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(e);
86 
87  for (size_t i = 0; i < trkHandle->size(); ++i) {
88 
89  const std::vector<art::Ptr<recob::Hit>> hit_coll = hit_coll_v.at(i);
90 
91  std::vector<btutil::WireRange_t> hits;
92 
93  for (auto const& h_ptr : hit_coll) {
94 
95  if (geo->ChannelToWire(h_ptr->Channel())[0].Plane != ::geo::kW) continue;
96 
97  hits.emplace_back(h_ptr->Channel(), h_ptr->StartTick(), h_ptr->EndTick());
98  }
99 
100  auto mcq_v = alg_mct.MCQ(clockData, hits);
101  auto mcq_frac_v = alg_mct.MCQFrac(clockData, hits);
102 
103  std::cout << "Track " << i << " "
104  << "Y plane Charge from first MCTrack: " << mcq_v[0]
105  << " ... Purity: " << mcq_frac_v[0]
106  << " ... Efficiency: " << mcq_v[0] / sum_mcq_v[0] << std::endl;
107  }
108  }
109 }
110 
111 DEFINE_ART_MODULE(MCBTDemo)
BEGIN_PROLOG true icarus_rawdigitfilter FilterTools FilterPlane1 Plane
const std::vector< double > & MCQSum(const size_t plane_id) const
Definition: MCBTAlg.cxx:98
Declaration of signal hit object.
Class def header for a class MCBTAlg.
pdgs p
Definition: selectors.fcl:22
MCBTDemo & operator=(MCBTDemo const &)=delete
void analyze(art::Event const &e) override
std::vector< double > MCQ(detinfo::DetectorClocksData const &clockData, const WireRange_t &hit) const
Definition: MCBTAlg.cxx:106
MCBTDemo(fhicl::ParameterSet const &p)
Class def header for mctrack data container.
Provides recob::Track data product.
std::vector< double > MCQFrac(detinfo::DetectorClocksData const &clockData, const WireRange_t &hit) const
Definition: MCBTAlg.cxx:131
object containing MC truth information necessary for making RawDigits and doing back tracking ...
do i e
Planes which measure W (third view for Bo, MicroBooNE, etc).
Definition: geo_types.h:131
art framework interface to geometry description
BEGIN_PROLOG could also be cout