ClusterCheater_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 ///
3 /// \brief TODO
4 /// \author brebel@fnal.gov
5 ///
6 ////////////////////////////////////////////////////////////////////////
7 
8 #include <string>
9 #include <vector>
10 
11 // NOvASoft includes
12 #include "MCCheater/BackTracker.h"
13 #include "RecoBase/CellHit.h"
14 #include "RecoBase/Cluster.h"
16 #include "Utilities/AssociationUtil.h"
17 
18 // Framework includes
20 #include "fhiclcpp/ParameterSet.h"
28 
29 namespace cheat {
31  public:
32  explicit ClusterCheater(fhicl::ParameterSet const& pset);
33  virtual ~ClusterCheater();
34 
35  void produce(art::Event& evt);
36 
37  void reconfigure(fhicl::ParameterSet const& pset);
38 
39  private:
40 
41  std::string fHitModuleLabel; ///< label for module creating rb::CellHit objects
42  std::string fG4ModuleLabel; ///< label for module running G4 and making particles, etc
43 
44  };
45 }
46 
47 namespace cheat{
48 
49  //--------------------------------------------------------------------
51  {
52  this->reconfigure(pset);
53 
54  produces< std::vector<rb::Cluster> >();
55  produces< art::Assns<rb::Cluster, rb::CellHit> >();
56  }
57 
58  //--------------------------------------------------------------------
60  {
61  }
62 
63  //--------------------------------------------------------------------
65  {
66  fHitModuleLabel = pset.get< std::string >("HitModuleLabel", "calhit" );
67  fG4ModuleLabel = pset.get< std::string >("G4ModuleLabel", "geantgen");
68 
69  return;
70  }
71 
72  //--------------------------------------------------------------------
74  {
75  // get a back tracker
77 
78  const sim::ParticleNavigator& pnav = bt->ParticleNavigator();
79 
80  // grab the hits that have been reconstructed
82  evt.getByLabel(fHitModuleLabel, hitcol);
83 
84  // make a vector of them
85  std::vector< art::Ptr<rb::CellHit> > hits;
86  art::fill_ptr_vector(hits, hitcol);
87 
88  // loop over the hits and figure out which particle contributed to each one
89  // make a map of vectors of art::Ptrs keyed by trackID values
90  std::map< int, std::vector< art::Ptr<rb::CellHit> > > trackHitMap;
91 
92  // loop over all hits and fill in the map
93  for(auto itr : hits ){
94 
95  std::vector<cheat::TrackIDE> trackides = bt->HitToTrackIDE(itr);
96 
97  // loop over all trackides for this hit
98  for(auto const& e : trackides){
99 
100  // don't worry about eve particles that contribute less than 10% of the
101  // energy in the current hit
102  if( e.energyFrac < 0.1) continue;
103 
104  trackHitMap[e.trackID].push_back(itr);
105 
106  } // end loop over eve IDs for this hit
107  }// end loop over hits
108 
109  // loop over the map and make clusters
110  std::unique_ptr< std::vector<rb::Cluster> > clustercol(new std::vector<rb::Cluster>);
111  std::unique_ptr< art::Assns<rb::Cluster, rb::CellHit> > assn(new art::Assns<rb::Cluster, rb::CellHit>);
112 
113  for(auto hitMapItr : trackHitMap){
114 
115  // separate out the hits for each particle into the different views
116  std::vector< art::Ptr<rb::CellHit> > trackHits( hitMapItr.second );
117 
120 
121  for(auto h : trackHits){
122 
123  if(h->View() == geo::kX) ptrvsX.push_back(h);
124  if(h->View() == geo::kY) ptrvsY.push_back(h);
125 
126  } // end loop over hits for this particle
127 
128  // check to see if the particle id for this cluster lives in the
129  // ParticleNavigator, if not, don't make a cluster and spew a warning
130  if( pnav.find(hitMapItr.first) == pnav.end() ){
131  mf::LogWarning("ClusterCheater") << " no particle in ParticleNavigator has track id "
132  << hitMapItr.first
133  << " this could be a problem. Certainly won't make a"
134  << " Cluster for it.";
135  continue;
136  }
137 
138  if( std::abs(pnav[hitMapItr.first]->PdgCode()) != 11 &&
139  std::abs(pnav[hitMapItr.first]->PdgCode()) != 22 &&
140  std::abs(pnav[hitMapItr.first]->PdgCode()) != 111 )
141  if(ptrvsX.size() < 1 || ptrvsY.size() < 1)
142  LOG_WARNING("ClusterCheater") << "no cluster in a view, " << ptrvsX.size()
143  << ", " << ptrvsY.size() << " for particle\n"
144  << *(pnav[hitMapItr.first]);
145 
146  if(ptrvsX.size() > 0 ){
147  clustercol->push_back(rb::Cluster(geo::kX,
148  ptrvsX,
149  (hitMapItr.first * 1000) + geo::kX*10));
150  // associate the hits to this cluster
151  util::CreateAssn(*this, evt, *clustercol, ptrvsX, *assn);
152  }
153 
154  LOG_DEBUG("ClusterCheater") << "adding cluster: \n"
155  << clustercol->back()
156  << "\nto collection.";
157 
158  if(ptrvsY.size() > 0){
159  clustercol->push_back(rb::Cluster(geo::kY,
160  ptrvsY,
161  (hitMapItr.first * 1000) + geo::kY*10));
162  // associate the hits to this cluster
163  util::CreateAssn(*this, evt, *clustercol, ptrvsY, *assn);
164  }
165 
166  LOG_DEBUG("ClusterCheater") << "adding cluster: \n"
167  << clustercol->back()
168  << "\nto collection.";
169 
170  } // end loop over the map
171 
172  evt.put(std::move(clustercol));
173  evt.put(std::move(assn));
174 
175  return;
176 
177  } // end produce
178 
179 } // end namespace cheat
180 
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
back track the reconstruction to the simulation
static bool CreateAssn(art::EDProducer const &prod, art::Event &evt, std::vector< T > &a, art::Ptr< U > b, art::Assns< T, U > &assn, size_t indx=UINT_MAX, std::string const &instance=std::string())
Create a 1 to 1 association between a new product and one already in the event.
std::vector< TrackIDE > HitToTrackIDE(const rb::CellHit &hit, bool useBirksE=false) const
Convenience function. HitsToTrackIDE but for a single hit.
const sim::ParticleNavigator & ParticleNavigator() const
Get a reference to the ParticleNavigator.
Definition: BackTracker.h:744
std::string fG4ModuleLabel
label for module running G4 and making particles, etc
Vertical planes which measure X.
Definition: PlaneGeo.h:28
A collection of associated CellHits.
Definition: Cluster.h:47
void reconfigure(fhicl::ParameterSet const &pset)
std::string fHitModuleLabel
label for module creating rb::CellHit objects
DEFINE_ART_MODULE(TestTMapFile)
float abs(float number)
Definition: d0nt_math.hpp:39
Horizontal planes which measure Y.
Definition: PlaneGeo.h:29
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
void hits()
Definition: readHits.C:15
void push_back(Ptr< U > const &p)
Definition: PtrVector.h:441
T get(std::string const &key) const
Definition: ParameterSet.h:231
size_type size() const
Definition: PtrVector.h:308
#define LOG_WARNING(category)
void produce(art::Event &evt)
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
code to link reconstructed objects back to the MC truth information
Definition: FillTruth.h:16
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:464
Float_t e
Definition: plot.C:35
ClusterCheater(fhicl::ParameterSet const &pset)
iterator find(const key_type &key)