LArSoft  v10_04_05
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
30 
31 // Framework includes
37 #include "fhiclcpp/ParameterSet.h"
39 
40 namespace cluster {
42  public:
43  explicit ClusterCheater(fhicl::ParameterSet const& pset);
44 
45  private:
46  void produce(art::Event& evt) override;
47 
48  std::string fMCGeneratorLabel;
49  std::string fHitModuleLabel;
50  std::string fG4ModuleLabel;
51  unsigned int fMinHits;
52  };
53 }
54 
55 namespace cluster {
56 
57  struct eveLoc {
58  eveLoc(int id, geo::PlaneID plnID) : eveID(id), planeID(plnID) {}
59 
60  friend bool operator<(eveLoc const& a, eveLoc const& b)
61  {
62  if (a.eveID != b.eveID) return a.eveID < b.eveID;
63 
64  return a.planeID < b.planeID;
65  }
66 
67  int eveID;
69  };
70 
72  {
73  return a->WireID().Wire < b->WireID().Wire;
74  }
75 
76  //--------------------------------------------------------------------
78  {
79  fMCGeneratorLabel = pset.get<std::string>("MCGeneratorLabel", "generator");
80  fHitModuleLabel = pset.get<std::string>("HitModuleLabel", "hit");
81  fG4ModuleLabel = pset.get<std::string>("G4ModuleLabel", "largeant");
82  fMinHits = pset.get<unsigned int>("MinHits", 1);
83 
84  produces<std::vector<recob::Cluster>>();
85  produces<art::Assns<recob::Cluster, recob::Hit>>();
86  }
87 
88  //--------------------------------------------------------------------
90  {
94 
95  // grab the hits that have been reconstructed
97  evt.getByLabel(fHitModuleLabel, hitcol);
98 
99  // make a vector of them - we aren't writing anything out to a file
100  // so no need for a art::PtrVector here
101  std::vector<art::Ptr<recob::Hit>> hits;
102  art::fill_ptr_vector(hits, hitcol);
103 
104  // adopt an EmEveIdCalculator to find the eve ID.
105  // will return a primary particle if it doesn't find
106  // a responsible particle for an EM process
108 
109  MF_LOG_DEBUG("ClusterCheater") << pi_serv->ParticleList();
110 
111  // make a map of vectors of art::Ptrs keyed by eveID values and
112  // location in cryostat, TPC, plane coordinates of where the hit originated
113  std::map<eveLoc, std::vector<art::Ptr<recob::Hit>>> eveHitMap;
114 
115  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
116 
117  // loop over all hits and fill in the map
118  for (auto const& itr : hits) {
119 
120  std::vector<sim::TrackIDE> eveides = bt_serv->HitToEveTrackIDEs(clockData, itr);
121 
122  // loop over all eveides for this hit
123  for (size_t e = 0; e < eveides.size(); ++e) {
124 
125  // don't worry about eve particles that contribute less than 10% of the
126  // energy in the current hit
127  if (eveides[e].energyFrac < 0.1) continue;
128 
129  eveLoc el(eveides[e].trackID, itr->WireID().planeID());
130 
131  eveHitMap[el].push_back(itr);
132 
133  } // end loop over eve IDs for this hit
134 
135  } // end loop over hits
136 
137  // loop over the map and make clusters
138  std::unique_ptr<std::vector<recob::Cluster>> clustercol(new std::vector<recob::Cluster>);
139  std::unique_ptr<art::Assns<recob::Cluster, recob::Hit>> assn(
141 
142  auto const detProp =
144  auto const& wireReadoutGeom = art::ServiceHandle<geo::WireReadout const>()->Get();
145 
146  util::GeometryUtilities const gser{*geo, wireReadoutGeom, clockData, detProp};
147 
148  // prepare the algorithm to compute the cluster characteristics;
149  // we use the "standard" one here; configuration would happen here,
150  // but we are using the default configuration for that algorithm
152 
153  for (auto hitMapItr : eveHitMap) {
154 
155  // ================================================================================
156  // === Only keeping clusters with fMinHits
157  // ================================================================================
158  if (hitMapItr.second.size() < fMinHits) continue;
159 
160  // get the center of this plane in world coordinates
161  auto const& planeID = hitMapItr.first.planeID;
162  unsigned int cryostat = planeID.Cryostat;
163  unsigned int tpc = planeID.TPC;
164  unsigned int plane = planeID.Plane;
165  auto xyz = wireReadoutGeom.Plane(planeID).GetBoxCenter();
166 
167  MF_LOG_DEBUG("ClusterCheater")
168  << "make cluster for eveID: " << hitMapItr.first.eveID << " in cryostat: " << cryostat
169  << " tpc: " << tpc << " plane: " << plane << " view: " << hitMapItr.second.at(0)->View();
170 
171  // get the direction of this particle in the current cryostat, tpc and plane
172  const simb::MCParticle* part = pi_serv->TrackIdToParticle_P(hitMapItr.first.eveID);
173  if (!part) continue;
174 
175  // now set the y and z coordinates of xyz to be the first point on the particle
176  // trajectory and use the initial directions to determine the dT/dW
177  // multiply the direction cosine by 10 to give a decent lever arm for determining
178  // dW
179  xyz.SetY(part->Vy());
180  xyz.SetZ(part->Vz());
181  auto xyz2 = xyz;
182  xyz2.SetY(xyz.Y() + 10. * part->Py() / part->P());
183  xyz2.SetZ(xyz.Z() + 10. * part->Pz() / part->P());
184 
185  // convert positions to wire and time
186  unsigned int w1 = 0;
187  unsigned int w2 = 0;
188 
189  auto const& planeg = wireReadoutGeom.Plane(planeID);
190  try {
191  w1 = planeg.NearestWireID(xyz).Wire;
192  }
193  catch (cet::exception& e) {
194  w1 = atoi(e.explain_self().substr(e.explain_self().find("#") + 1, 5).c_str());
195  }
196  try {
197  w2 = planeg.NearestWireID(xyz2).Wire;
198  }
199  catch (cet::exception& e) {
200  w2 = atoi(e.explain_self().substr(e.explain_self().find("#") + 1, 5).c_str());
201  }
202 
203  // sort the vector of hits with respect to the directionality of the wires determined by
204  if (w2 < w1)
205  std::sort(hitMapItr.second.rbegin(), hitMapItr.second.rend(), sortHitsByWire);
206  else
207  std::sort(hitMapItr.second.begin(), hitMapItr.second.end(), sortHitsByWire);
208 
209  // set the start and end wires and times
210  double startWire = hitMapItr.second.front()->WireID().Wire;
211  double startTime = hitMapItr.second.front()->PeakTimeMinusRMS();
212  double endWire = hitMapItr.second.back()->WireID().Wire;
213  double endTime = hitMapItr.second.back()->PeakTimePlusRMS();
214 
215  // add a cluster to the collection. Make the ID be the eve particle
216  // trackID*1000 + plane number*100 + tpc*10 + cryostat that the current hits are from
218  recob::Cluster::ID_t clusterID =
219  (((hitMapItr.first.eveID) * 10 + planeID.Plane) * 10 +
220  planeID.TPC // 10 is weird choice for DUNE FD... should be 1000! FIXME
221  ) *
222  10 +
223  planeID.Cryostat;
224 
225  // feed the algorithm with all the cluster hits
226  ClusterParamAlgo.ImportHits(gser, hitMapItr.second);
227 
228  // create the recob::Cluster directly in the vector
229  ClusterCreator cluster(gser,
230  ClusterParamAlgo, // algo
231  startWire, // start_wire
232  0., // sigma_start_wire
233  startTime, // start_tick
234  0., // sigma_start_tick
235  endWire, // end_wire
236  0., // sigma_end_wire
237  endTime, // end_tick
238  0., // sigma_end_tick
239  clusterID, // ID
240  hitMapItr.second.at(0)->View(), // view
241  planeID, // plane
242  recob::Cluster::Sentry // sentry
243  );
244 
245  clustercol->emplace_back(cluster.move());
246 
247  // association the hits to this cluster
248  util::CreateAssn(evt, *clustercol, hitMapItr.second, *assn);
249 
250  mf::LogInfo("ClusterCheater") << "adding cluster: \n"
251  << clustercol->back() << "\nto collection.";
252 
253  } // end loop over the map
254 
255  evt.put(std::move(clustercol));
256  evt.put(std::move(assn));
257  } // end produce
258 
260 }
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:364
cout<< "Opened file "<< fin<< " ixs= "<< ixs<< endl;if(ixs==0) hhh=(TH1F *) fff-> Get("h1")
Definition: AddMC.C:8
WireID_t Wire
Index of the wire within its plane.
Definition: geo_types.h:430
geo::WireID const & WireID() const
Initial tdc tick for hit.
Definition: Hit.h:290
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)
TString part[npart]
Definition: Style.C:32
void hits()
Definition: readHits.C:15
#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.
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
ROOT libraries.
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 .