LArSoft  v07_13_02
Liquid Argon Software toolkit - http://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 
18 #include "fhiclcpp/ParameterSet.h"
20 
21 #include <iostream>
28 #include "MCBTAlg.h"
29 
30 class MCBTDemo : public art::EDAnalyzer {
31 public:
32  explicit MCBTDemo(fhicl::ParameterSet const & p);
33  // The destructor generated by the compiler is fine for classes
34  // without bare pointers or other resource use.
35 
36  // Plugins should not be copied or assigned.
37  MCBTDemo(MCBTDemo const &) = delete;
38  MCBTDemo(MCBTDemo &&) = delete;
39  MCBTDemo & operator = (MCBTDemo const &) = delete;
40  MCBTDemo & operator = (MCBTDemo &&) = delete;
41 
42  // Required functions.
43  void analyze(art::Event const & e) override;
44 
45 
46 private:
47 
48  // Declare member data here.
49 
50 };
51 
52 
54  :
55  EDAnalyzer(p) // ,
56  // More initializers here.
57 {}
58 
60 {
61  // Implementation of required member function here.
63  e.getByLabel("mcreco",mctHandle);
64 
66  e.getByLabel("largeant",schHandle);
67 
69  e.getByLabel("trackkalmanhit",trkHandle);
70 
71  if(!mctHandle.isValid() || !schHandle.isValid() || !trkHandle.isValid()) return;
72 
73  // Collect G4 track ID from MCTrack whose energy loss > 100 MeV inside the detector
74  std::vector<unsigned int> g4_track_id;
75  for(auto const& mct : *mctHandle) {
76 
77  if(!mct.size()) continue;
78 
79  double dE = (*mct.begin()).Momentum().E() - (*mct.rbegin()).Momentum().E();
80  if(dE > 100) g4_track_id.push_back(mct.TrackID());
81 
82  }
83 
84  if(g4_track_id.size()) {
85 
87  btutil::MCBTAlg alg_mct(g4_track_id,*schHandle);
88 
89  auto sum_mcq_v = alg_mct.MCQSum(2);
90  std::cout<<"Total charge contents on W plane:"<<std::endl;
91  for(size_t i=0; i<sum_mcq_v.size()-1; ++i)
92  std::cout<<" MCTrack " << i << " => " << sum_mcq_v[i] <<std::endl;
93  std::cout<<" Others => "<<(*sum_mcq_v.rbegin())<<std::endl;
94 
95  // Loop over reconstructed tracks and find charge fraction
96  art::FindManyP<recob::Hit> hit_coll_v(trkHandle, e, "trackkalmanhit");
97 
98  for(size_t i=0; i<trkHandle->size(); ++i) {
99 
100  const std::vector<art::Ptr<recob::Hit> > hit_coll = hit_coll_v.at(i);
101 
102  std::vector<btutil::WireRange_t> hits;
103 
104  for(auto const& h_ptr : hit_coll) {
105 
106  if(geo->ChannelToWire(h_ptr->Channel())[0].Plane != ::geo::kW) continue;
107 
108  hits.emplace_back(h_ptr->Channel(),h_ptr->StartTick(), h_ptr->EndTick());
109 
110  }
111 
112  auto mcq_v = alg_mct.MCQ(hits);
113 
114  auto mcq_frac_v = alg_mct.MCQFrac(hits);
115 
116  std::cout << "Track " << i << " "
117  << "Y plane Charge from first MCTrack: " << mcq_v[0]
118  << " ... Purity: " << mcq_frac_v[0]
119  << " ... Efficiency: " << mcq_v[0] / sum_mcq_v[0] << std::endl;
120  }
121  }
122 }
123 
const std::vector< double > & MCQSum(const size_t plane_id) const
Definition: MCBTAlg.cxx:88
Declaration of signal hit object.
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
std::vector< double > MCQFrac(const WireRange_t &hit) const
Definition: MCBTAlg.cxx:123
bool isValid() const
Definition: Handle.h:190
void analyze(art::Event const &e) override
void hits()
Definition: readHits.C:15
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
Provides recob::Track data product.
MCBTDemo(fhicl::ParameterSet const &p)
EDAnalyzer(Table< Config > const &config)
Definition: EDAnalyzer.h:100
Class def header for mctrack data container.
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
std::vector< double > MCQ(const WireRange_t &hit) const
Definition: MCBTAlg.cxx:95
object containing MC truth information necessary for making RawDigits and doing back tracking ...
Class def header for MCShower data container.
Planes which measure W (third view for Bo, MicroBooNE, etc).
Definition: geo_types.h:78
Float_t e
Definition: plot.C:34
recob::tracking::Plane Plane
Definition: TrackState.h:17
Namespace collecting geometry-related classes utilities.
art framework interface to geometry description