LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
ClusterCheater_module.cc
Go to the documentation of this file.
1 //
3 // ClusterCheater module
4 //
5 // brebel@fnal.gov
6 //
8 #include <algorithm>
9 #include <string>
10 
11 // LArSoft includes
29 
30 // Framework includes
36 #include "fhiclcpp/ParameterSet.h"
38 
39 namespace cluster {
41  public:
42  explicit ClusterCheater(fhicl::ParameterSet const& pset);
43 
44  private:
45  void produce(art::Event& evt) override;
46 
47  std::string fMCGeneratorLabel;
48  std::string fHitModuleLabel;
49  std::string fG4ModuleLabel;
50  unsigned int fMinHits;
51  };
52 }
53 
54 namespace cluster {
55 
56  struct eveLoc {
57  eveLoc(int id, geo::PlaneID plnID) : eveID(id), planeID(plnID) {}
58 
59  friend bool operator<(eveLoc const& a, eveLoc const& b)
60  {
61  if (a.eveID != b.eveID) return a.eveID < b.eveID;
62 
63  return a.planeID < b.planeID;
64  }
65 
66  int eveID;
68  };
69 
71  {
72  return a->WireID().Wire < b->WireID().Wire;
73  }
74 
75  //--------------------------------------------------------------------
77  {
78  fMCGeneratorLabel = pset.get<std::string>("MCGeneratorLabel", "generator");
79  fHitModuleLabel = pset.get<std::string>("HitModuleLabel", "hit");
80  fG4ModuleLabel = pset.get<std::string>("G4ModuleLabel", "largeant");
81  fMinHits = pset.get<unsigned int>("MinHits", 1);
82 
83  produces<std::vector<recob::Cluster>>();
84  produces<art::Assns<recob::Cluster, recob::Hit>>();
85  }
86 
87  //--------------------------------------------------------------------
89  {
93 
94  // grab the hits that have been reconstructed
96  evt.getByLabel(fHitModuleLabel, hitcol);
97 
98  // make a vector of them - we aren't writing anything out to a file
99  // so no need for a art::PtrVector here
100  std::vector<art::Ptr<recob::Hit>> hits;
101  art::fill_ptr_vector(hits, hitcol);
102 
103  // adopt an EmEveIdCalculator to find the eve ID.
104  // will return a primary particle if it doesn't find
105  // a responsible particle for an EM process
107 
108  MF_LOG_DEBUG("ClusterCheater") << pi_serv->ParticleList();
109 
110  // make a map of vectors of art::Ptrs keyed by eveID values and
111  // location in cryostat, TPC, plane coordinates of where the hit originated
112  std::map<eveLoc, std::vector<art::Ptr<recob::Hit>>> eveHitMap;
113 
114  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
115 
116  // loop over all hits and fill in the map
117  for (auto const& itr : hits) {
118 
119  std::vector<sim::TrackIDE> eveides = bt_serv->HitToEveTrackIDEs(clockData, itr);
120 
121  // loop over all eveides for this hit
122  for (size_t e = 0; e < eveides.size(); ++e) {
123 
124  // don't worry about eve particles that contribute less than 10% of the
125  // energy in the current hit
126  if (eveides[e].energyFrac < 0.1) continue;
127 
128  eveLoc el(eveides[e].trackID, itr->WireID().planeID());
129 
130  eveHitMap[el].push_back(itr);
131 
132  } // end loop over eve IDs for this hit
133 
134  } // end loop over hits
135 
136  // loop over the map and make clusters
137  std::unique_ptr<std::vector<recob::Cluster>> clustercol(new std::vector<recob::Cluster>);
138  std::unique_ptr<art::Assns<recob::Cluster, recob::Hit>> assn(
140 
141  auto const detProp =
143  util::GeometryUtilities const gser{*geo, clockData, detProp};
144 
145  // prepare the algorithm to compute the cluster characteristics;
146  // we use the "standard" one here; configuration would happen here,
147  // but we are using the default configuration for that algorithm
149 
150  for (auto hitMapItr : eveHitMap) {
151 
152  // ================================================================================
153  // === Only keeping clusters with fMinHits
154  // ================================================================================
155  if (hitMapItr.second.size() < fMinHits) continue;
156 
157  // get the center of this plane in world coordinates
158  auto const& planeID = hitMapItr.first.planeID;
159  unsigned int cryostat = planeID.Cryostat;
160  unsigned int tpc = planeID.TPC;
161  unsigned int plane = planeID.Plane;
162  auto xyz = geo->Plane(planeID).GetBoxCenter();
163 
164  MF_LOG_DEBUG("ClusterCheater")
165  << "make cluster for eveID: " << hitMapItr.first.eveID << " in cryostat: " << cryostat
166  << " tpc: " << tpc << " plane: " << plane << " view: " << hitMapItr.second.at(0)->View();
167 
168  // get the direction of this particle in the current cryostat, tpc and plane
169  const simb::MCParticle* part = pi_serv->TrackIdToParticle_P(hitMapItr.first.eveID);
170  if (!part) continue;
171 
172  // now set the y and z coordinates of xyz to be the first point on the particle
173  // trajectory and use the initial directions to determine the dT/dW
174  // multiply the direction cosine by 10 to give a decent lever arm for determining
175  // dW
176  xyz.SetY(part->Vy());
177  xyz.SetZ(part->Vz());
178  auto xyz2 = xyz;
179  xyz2.SetY(xyz.Y() + 10. * part->Py() / part->P());
180  xyz2.SetZ(xyz.Z() + 10. * part->Pz() / part->P());
181 
182  // convert positions to wire and time
183  unsigned int w1 = 0;
184  unsigned int w2 = 0;
185 
186  try {
187  w1 = geo->NearestWireID(xyz, planeID).Wire;
188  }
189  catch (cet::exception& e) {
190  w1 = atoi(e.explain_self().substr(e.explain_self().find("#") + 1, 5).c_str());
191  }
192  try {
193  w2 = geo->NearestWireID(xyz2, planeID).Wire;
194  }
195  catch (cet::exception& e) {
196  w2 = atoi(e.explain_self().substr(e.explain_self().find("#") + 1, 5).c_str());
197  }
198 
199  // sort the vector of hits with respect to the directionality of the wires determined by
200  if (w2 < w1)
201  std::sort(hitMapItr.second.rbegin(), hitMapItr.second.rend(), sortHitsByWire);
202  else
203  std::sort(hitMapItr.second.begin(), hitMapItr.second.end(), sortHitsByWire);
204 
205  // set the start and end wires and times
206  double startWire = hitMapItr.second.front()->WireID().Wire;
207  double startTime = hitMapItr.second.front()->PeakTimeMinusRMS();
208  double endWire = hitMapItr.second.back()->WireID().Wire;
209  double endTime = hitMapItr.second.back()->PeakTimePlusRMS();
210 
211  // add a cluster to the collection. Make the ID be the eve particle
212  // trackID*1000 + plane number*100 + tpc*10 + cryostat that the current hits are from
214  recob::Cluster::ID_t clusterID =
215  (((hitMapItr.first.eveID) * 10 + planeID.Plane) * 10 +
216  planeID.TPC // 10 is weird choice for DUNE FD... should be 1000! FIXME
217  ) *
218  10 +
219  planeID.Cryostat;
220 
221  // feed the algorithm with all the cluster hits
222  ClusterParamAlgo.ImportHits(gser, hitMapItr.second);
223 
224  // create the recob::Cluster directly in the vector
225  ClusterCreator cluster(gser,
226  ClusterParamAlgo, // algo
227  startWire, // start_wire
228  0., // sigma_start_wire
229  startTime, // start_tick
230  0., // sigma_start_tick
231  endWire, // end_wire
232  0., // sigma_end_wire
233  endTime, // end_tick
234  0., // sigma_end_tick
235  clusterID, // ID
236  hitMapItr.second.at(0)->View(), // view
237  planeID, // plane
238  recob::Cluster::Sentry // sentry
239  );
240 
241  clustercol->emplace_back(cluster.move());
242 
243  // association the hits to this cluster
244  util::CreateAssn(evt, *clustercol, hitMapItr.second, *assn);
245 
246  mf::LogInfo("ClusterCheater") << "adding cluster: \n"
247  << clustercol->back() << "\nto collection.";
248 
249  } // end loop over the map
250 
251  evt.put(std::move(clustercol));
252  evt.put(std::move(assn));
253  } // end produce
254 
256 }
double Py(const int i=0) const
Definition: MCParticle.h:232
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)
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
const simb::MCParticle * TrackIdToParticle_P(int id) const
Declaration of signal hit object.
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.cc:6
void SetEveIdCalculator(sim::EveIdCalculator *ec)
The data type to uniquely identify a Plane.
Definition: geo_types.h:463
WireID_t Wire
Index of the wire within its plane.
Definition: geo_types.h:563
geo::WireID const & WireID() const
Initial tdc tick for hit.
Definition: Hit.h:280
void produce(art::Event &evt) override
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:174
void ImportHits(util::GeometryUtilities const &gser, Iter begin, Iter end)
Calls SetHits() with the hits in the sequence.
bool sortHitsByWire(art::Ptr< recob::Hit > a, art::Ptr< recob::Hit > b)
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: Event.h:77
ClusterCheater(fhicl::ParameterSet const &pset)
PlaneGeo const & Plane(PlaneID const &planeid) const
Returns the specified wire.
TString part[npart]
Definition: Style.C:32
void hits()
Definition: readHits.C:15
Point_t GetBoxCenter() const
Returns the centre of the box representing the plane.
Definition: PlaneGeo.h:449
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
Helper functions to create a cluster.
Wrapper for ClusterParamsAlgBase objects to accept diverse input.
double P(const int i=0) const
Definition: MCParticle.h:235
Wrapper for ClusterParamsAlgBase objects to accept arbitrary input.
Declaration of cluster object.
Definition of data types for geometry description.
const sim::ParticleList & ParticleList() const
bool CreateAssn(art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t index=UINT_MAX)
Creates a single one-to-one association.
WireID NearestWireID(Point_t const &point, PlaneID const &planeid) const
Returns the ID of wire closest to position in the specified TPC.
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
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...
std::vector< sim::TrackIDE > HitToEveTrackIDEs(detinfo::DetectorClocksData const &clockData, recob::Hit const &hit) const
#define MF_LOG_DEBUG(id)
double Pz(const int i=0) const
Definition: MCParticle.h:233
friend bool operator<(eveLoc const &a, eveLoc const &b)
double Vz(const int i=0) const
Definition: MCParticle.h:224
Interface to class computing cluster parameters.
TCEvent evt
Definition: DataStructs.cxx:8
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:306
Float_t e
Definition: plot.C:35
Namespace collecting geometry-related classes utilities.
std::string fG4ModuleLabel
label for module running G4 and making particles, etc
double Vy(const int i=0) const
Definition: MCParticle.h:223
art framework interface to geometry description
int ID_t
Type of cluster ID.
Definition: Cluster.h:72
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
Encapsulate the construction of a single detector plane.