LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
CheckBackTracking_module.cc
Go to the documentation of this file.
1 //
3 // CheckBackTracking module
4 //
5 // brebel@fnal.gov
6 //
8 #ifndef CHEAT_CHECKBACKTRACKING_H
9 #define CHEAT_CHECKBACKTRACKING_H
10 #include <string>
11 #include <vector>
12 
13 // ROOT includes
14 
15 // LArSoft includes
20 
21 
22 // Framework includes
25 #include "fhiclcpp/ParameterSet.h"
32 
33 
34 namespace cheat {
36  public:
37  explicit CheckBackTracking(fhicl::ParameterSet const& pset);
38  virtual ~CheckBackTracking();
39 
40  void analyze(art::Event const& evt);
41 
42  void reconfigure(fhicl::ParameterSet const& pset);
43 
44  private:
45 
46  std::string fHitModuleLabel;
47  std::string fG4ModuleLabel;
48 
49  };
50 }
51 
52 namespace cheat{
53 
54  //--------------------------------------------------------------------
56  : EDAnalyzer(pset)
57  {
58  this->reconfigure(pset);
59  }
60 
61  //--------------------------------------------------------------------
63  {
64  }
65 
66  //--------------------------------------------------------------------
68  {
69  fHitModuleLabel = pset.get< std::string >("HitModuleLabel", "ffthit" );
70  fG4ModuleLabel = pset.get< std::string >("G4ModuleLabel", "largeant");
71 
72  return;
73  }
74 
75  //--------------------------------------------------------------------
77  {
78 
79  // grab the hits that have been reconstructed
81  evt.getByLabel(fHitModuleLabel, hitcol);
82 
83  // make a vector of them - we aren't writing anything out to a file
84  // so no need for a art::PtrVector here
85  std::vector< art::Ptr<recob::Hit> > hits;
86  art::fill_ptr_vector(hits, hitcol);
87 
88  // loop over the hits and figure out which particle contributed to each one
89  std::vector< art::Ptr<recob::Hit> >::iterator itr = hits.begin();
90 
93 
94  // make a collection of the distinct eve ID values
95  std::set<int> eveIDs;
96 
97  while( itr != hits.end() ){
98 
99  // print the truth information for this hit
100  mf::LogInfo("CheckBackTracking") << *((*itr).get()) << "\n channel is: " << (*itr)->Channel();
101 
102  std::vector<sim::TrackIDE> trackides = bt_serv->HitToTrackIDEs(*itr);
103  std::vector<sim::TrackIDE> eveides = bt_serv->HitToEveTrackIDEs(*itr);
104  std::vector<double> xyz = bt_serv->HitToXYZ(*itr);
105 
106  mf::LogInfo("CheckBackTracking") << "hit weighted mean position is ("
107  << xyz[0] << "," << xyz[1] << "," << xyz[2] << ")";
108 
109  for(size_t t = 0; t < trackides.size(); ++t){
110 
111  // find the Eve particle for the current trackID
112  int eveID = pi_serv->ParticleList().EveId( trackides[t].trackID );
113 
114  mf::LogInfo("CheckBackTracking") << "track id: " << trackides[t].trackID
115  << " contributed " << trackides[t].energy << "/"
116  << trackides[t].energyFrac
117  << " to the current hit and has eveID: "
118  << eveID;
119  }
120 
121  for(size_t e = 0; e < eveides.size(); ++e){
122  mf::LogInfo("CheckBackTracking") << "eve id: " << eveides[e].trackID
123  << " contributed " << eveides[e].energy << "/"
124  << eveides[e].energyFrac
125  << " to the current hit";
126 
127  if(eveIDs.find(eveides[e].trackID) == eveIDs.end()) eveIDs.insert(eveides[e].trackID);
128  }
129 
130  itr++;
131  }// end loop over hits
132 
133  // loop over the eveID values and calculate the purity and efficiency for each
134  std::set<int>::iterator setitr = eveIDs.begin();
135  while( setitr != eveIDs.end() ){
136 
137  std::set<int> id;
138  id.insert(*setitr);
139  mf::LogInfo("CheckBackTracking") << "eve ID: " << *setitr
140  << " purity: "
141  << bt_serv->HitCollectionPurity(id, hits)
142  << " efficiency: "
143  << bt_serv->HitCollectionEfficiency(id, hits, hits, geo::k3D);
144 
145 
146  setitr++;
147  }
148 
149  return;
150 
151  } // end analyze
152 
153 } // end namespace
154 
155 namespace cheat{
156 
158 
159 }
160 
161 #endif
std::string fHitModuleLabel
label for module creating recob::Hit objects
const std::vector< double > HitToXYZ(const recob::Hit &hit)
intermediate_table::iterator iterator
const std::vector< sim::TrackIDE > HitToTrackIDEs(recob::Hit const &hit)
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
void reconfigure(fhicl::ParameterSet const &pset)
Declaration of signal hit object.
CheckBackTracking(fhicl::ParameterSet const &pset)
int EveId(const int trackID) const
3-dimensional objects, potentially hits, clusters, prongs, etc.
Definition: geo_types.h:82
void hits()
Definition: readHits.C:15
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
T get(std::string const &key) const
Definition: ParameterSet.h:231
EDAnalyzer(Table< Config > const &config)
Definition: EDAnalyzer.h:100
const double HitCollectionEfficiency(std::set< int > const &trackIds, std::vector< art::Ptr< recob::Hit > > const &hits, std::vector< art::Ptr< recob::Hit > > const &allhits, geo::View_t const &view)
std::string fG4ModuleLabel
label for module running G4 and making particles, etc
code to link reconstructed objects back to the MC truth information
Definition: BackTracker.cc:26
const double HitCollectionPurity(std::set< int > const &trackIds, std::vector< art::Ptr< recob::Hit > > const &hits)
const std::vector< sim::TrackIDE > HitToEveTrackIDEs(recob::Hit const &hit)
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:464
void analyze(art::Event const &evt)
Float_t e
Definition: plot.C:34
art framework interface to geometry description