LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
ClusterCheater_module.cc
Go to the documentation of this file.
1 //
3 // ClusterCheater module
4 //
5 // brebel@fnal.gov
6 //
8 #ifndef CLUSTER_CLUSTERCHEATER_H
9 #define CLUSTER_CLUSTERCHEATER_H
10 #include <string>
11 #include <vector>
12 #include <algorithm>
13 
14 // ROOT includes
15 #include "TStopwatch.h"
16 
17 // LArSoft includes
30 
31 
32 // Framework includes
34 #include "fhiclcpp/ParameterSet.h"
45 
46 namespace cluster {
48  public:
49  explicit ClusterCheater(fhicl::ParameterSet const& pset);
50  virtual ~ClusterCheater();
51 
52  void produce(art::Event& evt);
53 
54  void reconfigure(fhicl::ParameterSet const& pset);
55 
56  private:
57 
58  std::string fMCGeneratorLabel;
59  std::string fHitModuleLabel;
60  std::string fG4ModuleLabel;
61  unsigned int fMinHits;
62 
63  };
64 }
65 
66 namespace cluster{
67 
68  struct eveLoc{
69 
70  eveLoc(int id, geo::PlaneID plnID)
71  : eveID(id)
72  , planeID(plnID)
73  {}
74 
75  friend bool operator < (eveLoc const& a, eveLoc const& b)
76  {
77  if(a.eveID != b.eveID)
78  return a.eveID < b.eveID;
79 
80  return a.planeID < b.planeID;
81  }
82 
83  int eveID;
85  };
86 
88  {
89  return a->WireID().Wire < b->WireID().Wire;
90  }
91 
92  //--------------------------------------------------------------------
94  {
95  this->reconfigure(pset);
96 
97  produces< std::vector<recob::Cluster> >();
98  produces< art::Assns<recob::Cluster, recob::Hit> >();
99  }
100 
101  //--------------------------------------------------------------------
103  {
104  }
105 
106  //--------------------------------------------------------------------
108  {
109  fMCGeneratorLabel = pset.get< std::string >("MCGeneratorLabel", "generator");
110  fHitModuleLabel = pset.get< std::string >("HitModuleLabel", "hit" );
111  fG4ModuleLabel = pset.get< std::string >("G4ModuleLabel", "largeant" );
112  fMinHits = pset.get< unsigned int >("MinHits", 1 );
113 
114  return;
115  }
116 
117  //--------------------------------------------------------------------
119  {
123 
124  // grab the hits that have been reconstructed
126  evt.getByLabel(fHitModuleLabel, hitcol);
127 
128  // make a vector of them - we aren't writing anything out to a file
129  // so no need for a art::PtrVector here
130  std::vector< art::Ptr<recob::Hit> > hits;
131  art::fill_ptr_vector(hits, hitcol);
132 
133  // adopt an EmEveIdCalculator to find the eve ID.
134  // will return a primary particle if it doesn't find
135  // a responsible particle for an EM process
137 
138  LOG_DEBUG("ClusterCheater") << pi_serv->ParticleList();
139 
140  // make a map of vectors of art::Ptrs keyed by eveID values and
141  // location in cryostat, TPC, plane coordinates of where the hit originated
142  std::map< eveLoc, std::vector< art::Ptr<recob::Hit> > > eveHitMap;
143 
144  // loop over all hits and fill in the map
145  for( auto const& itr : hits ){
146 
147  std::vector<sim::TrackIDE> eveides = bt_serv->HitToEveTrackIDEs(itr);
148 
149  // loop over all eveides for this hit
150  for(size_t e = 0; e < eveides.size(); ++e){
151 
152  // don't worry about eve particles that contribute less than 10% of the
153  // energy in the current hit
154  if( eveides[e].energyFrac < 0.1) continue;
155 
156  eveLoc el(eveides[e].trackID,
157  itr->WireID().planeID());
158 
159  eveHitMap[el].push_back(itr);
160 
161  } // end loop over eve IDs for this hit
162 
163  }// end loop over hits
164 
165  // loop over the map and make clusters
166  std::unique_ptr< std::vector<recob::Cluster> > clustercol(new std::vector<recob::Cluster>);
167  std::unique_ptr< art::Assns<recob::Cluster, recob::Hit> > assn(new art::Assns<recob::Cluster, recob::Hit>);
168 
169  // prepare the algorithm to compute the cluster characteristics;
170  // we use the "standard" one here; configuration would happen here,
171  // but we are using the default configuration for that algorithm
173 
174  for(auto hitMapItr : eveHitMap){
175 
176  // ================================================================================
177  // === Only keeping clusters with fMinHits
178  // ================================================================================
179  if(hitMapItr.second.size() < fMinHits) continue;
180 
181  // get the center of this plane in world coordinates
182  double xyz[3] = {0.};
183  double xyz2[3] = {0.};
184  double local[3] = {0.};
185  unsigned int cryostat = hitMapItr.first.planeID.Cryostat;
186  unsigned int tpc = hitMapItr.first.planeID.TPC;
187  unsigned int plane = hitMapItr.first.planeID.Plane;
188  geo->Cryostat(cryostat).TPC(tpc).Plane(plane).LocalToWorld(local, xyz);
189 
190  LOG_DEBUG("ClusterCheater") << "make cluster for eveID: " << hitMapItr.first.eveID
191  << " in cryostat: " << cryostat
192  << " tpc: " << tpc
193  << " plane: " << plane
194  << " view: " << hitMapItr.second.at(0)->View();
195 
196  // get the direction of this particle in the current cryostat, tpc and plane
197  const simb::MCParticle *part = pi_serv->TrackIdToParticle_P(hitMapItr.first.eveID);
198  if(!part) continue;
199 
200  // now set the y and z coordinates of xyz to be the first point on the particle
201  // trajectory and use the initial directions to determine the dT/dW
202  // multiply the direction cosine by 10 to give a decent lever arm for determining
203  // dW
204  xyz[1] = part->Vy();
205  xyz[2] = part->Vz();
206  xyz2[0] = xyz[0];
207  xyz2[1] = xyz[1] + 10.*part->Py()/part->P();
208  xyz2[2] = xyz[2] + 10.*part->Pz()/part->P();
209 
210  // convert positions to wire and time
211  unsigned int w1 = 0;
212  unsigned int w2 = 0;
213 
214  try{
215  w1 = geo->NearestWire(xyz, plane, tpc, cryostat);
216  }
217  catch(cet::exception& e){
218  w1 = atoi(e.explain_self().substr(e.explain_self().find("#")+1,5).c_str());
219  }
220  try{
221  w2 = geo->NearestWire(xyz2, plane, tpc, cryostat);
222  }
223  catch(cet::exception& e){
224  w2 = atoi(e.explain_self().substr(e.explain_self().find("#")+1,5).c_str());
225  }
226 
227  // sort the vector of hits with respect to the directionality of the wires determined by
228  if(w2 < w1)
229  std::sort(hitMapItr.second.rbegin(), hitMapItr.second.rend(), sortHitsByWire);
230  else
231  std::sort(hitMapItr.second.begin(), hitMapItr.second.end(), sortHitsByWire);
232 
233  // set the start and end wires and times
234  double startWire = hitMapItr.second.front()->WireID().Wire;
235  double startTime = hitMapItr.second.front()->PeakTimeMinusRMS();
236  double endWire = hitMapItr.second.back()->WireID().Wire;
237  double endTime = hitMapItr.second.back()->PeakTimePlusRMS();
238 
239  // add a cluster to the collection. Make the ID be the eve particle
240  // trackID*1000 + plane number*100 + tpc*10 + cryostat that the current hits are from
242  const geo::PlaneID& planeID = hitMapItr.first.planeID;
243  recob::Cluster::ID_t clusterID = (((
244  hitMapItr.first.eveID
245  )*10 + planeID.Plane
246  )*10 + planeID.TPC // 10 is weird choice for DUNE FD... should be 1000! FIXME
247  )*10 + planeID.Cryostat
248  ;
249 
250  // feed the algorithm with all the cluster hits
251  ClusterParamAlgo.ImportHits(hitMapItr.second);
252 
253  // create the recob::Cluster directly in the vector
255  ClusterParamAlgo, // algo
256  startWire, // start_wire
257  0., // sigma_start_wire
258  startTime, // start_tick
259  0., // sigma_start_tick
260  endWire, // end_wire
261  0., // sigma_end_wire
262  endTime, // end_tick
263  0., // sigma_end_tick
264  clusterID, // ID
265  hitMapItr.second.at(0)->View(), // view
266  planeID, // plane
267  recob::Cluster::Sentry // sentry
268  );
269 
270  clustercol->emplace_back(cluster.move());
271 
272  // association the hits to this cluster
273  util::CreateAssn(*this, evt, *clustercol, hitMapItr.second, *assn);
274 
275  mf::LogInfo("ClusterCheater") << "adding cluster: \n"
276  << clustercol->back()
277  << "\nto collection.";
278 
279  } // end loop over the map
280 
281  evt.put(std::move(clustercol));
282  evt.put(std::move(assn));
283 
284  return;
285 
286  } // end produce
287 
288 } // end namespace
289 
290 namespace cluster{
291 
293 
294 }
295 
296 #endif
297 
298 
const simb::MCParticle * TrackIdToParticle_P(int const &id)
double Py(const int i=0) const
Definition: MCParticle.h:235
Class managing the creation of a new recob::Cluster object.
std::string fMCGeneratorLabel
label for module to get MC truth information
Encapsulate the construction of a single cyostat.
eveLoc(int id, geo::PlaneID plnID)
bool operator<(CryostatID const &a, CryostatID const &b)
Order cryostats with increasing ID.
Definition: geo_types.h:413
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
geo::WireID WireID() const
Initial tdc tick for hit.
Definition: Hit.h:234
Declaration of signal hit object.
void SetEveIdCalculator(sim::EveIdCalculator *ec)
The data type to uniquely identify a Plane.
Definition: geo_types.h:250
CryostatID_t Cryostat
Index of cryostat.
Definition: geo_types.h:130
WireID_t Wire
Index of the wire within its plane.
Definition: geo_types.h:313
Cluster finding and building.
unsigned int fMinHits
minimum number of hits to make a cluster
std::string fHitModuleLabel
label for module creating recob::Hit objects
static const SentryArgument_t Sentry
An instance of the sentry object.
Definition: Cluster.h:182
bool sortHitsByWire(art::Ptr< recob::Hit > a, art::Ptr< recob::Hit > b)
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
ClusterCheater(fhicl::ParameterSet const &pset)
void hits()
Definition: readHits.C:15
void produce(art::Event &evt)
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
void reconfigure(fhicl::ParameterSet const &pset)
Helper functions to create a cluster.
Wrapper for ClusterParamsAlgBase objects to accept diverse input.
double P(const int i=0) const
Definition: MCParticle.h:238
T get(std::string const &key) const
Definition: ParameterSet.h:231
geo::WireID::WireID_t NearestWire(geo::Point_t const &point, geo::PlaneID const &planeid) const
Returns the index of wire closest to position in the specified TPC.
TString part[npart]
Definition: Style.C:32
CryostatGeo const & Cryostat(geo::CryostatID const &cryoid) const
Returns the specified cryostat.
Wrapper for ClusterParamsAlgBase objects to accept arbitrary input.
bool CreateAssn(PRODUCER const &prod, art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t indx=UINT_MAX)
Creates a single one-to-one association.
PlaneID_t Plane
Index of the plane within its TPC.
Definition: geo_types.h:258
Declaration of cluster object.
Definition of data types for geometry description.
Utility object to perform functions of association.
Encapsulate the construction of a single detector plane.
Example routine for calculating the "ultimate e-m mother" of a particle in a simulated event...
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
const TPCGeo & TPC(unsigned int itpc) const
Return the itpc&#39;th TPC in the cryostat.
void ImportHits(Iter begin, Iter end)
Calls SetHits() with the hits in the sequence.
double Pz(const int i=0) const
Definition: MCParticle.h:236
double Vz(const int i=0) const
Definition: MCParticle.h:227
#define LOG_DEBUG(id)
PlaneGeo const & Plane(geo::View_t view) const
Return the plane in the tpc with View_t view.
Definition: TPCGeo.cxx:298
Interface to class computing cluster parameters.
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:464
TPCID_t TPC
Index of the TPC within its cryostat.
Definition: geo_types.h:203
Float_t e
Definition: plot.C:34
Namespace collecting geometry-related classes utilities.
std::string fG4ModuleLabel
label for module running G4 and making particles, etc
void LocalToWorld(const double *plane, double *world) const
Transform point from local plane frame to world frame.
Definition: PlaneGeo.h:1124
double Vy(const int i=0) const
Definition: MCParticle.h:226
art framework interface to geometry description
int ID_t
Type of cluster ID.
Definition: Cluster.h:74
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
Encapsulate the construction of a single detector plane.