28 #include "nug4/ParticleNavigation/EmEveIdCalculator.h"
31 #include "art/Framework/Core/EDProducer.h"
32 #include "art/Framework/Core/ModuleMacros.h"
33 #include "art/Framework/Principal/Event.h"
34 #include "art/Framework/Principal/Handle.h"
35 #include "art/Framework/Services/Registry/ServiceHandle.h"
36 #include "fhiclcpp/ParameterSet.h"
37 #include "messagefacility/MessageLogger/MessageLogger.h"
74 return a->WireID().Wire < b->WireID().Wire;
80 fMCGeneratorLabel = pset.get<std::string>(
"MCGeneratorLabel",
"generator");
81 fHitModuleLabel = pset.get<std::string>(
"HitModuleLabel",
"hit");
82 fG4ModuleLabel = pset.get<std::string>(
"G4ModuleLabel",
"largeant");
83 fMinHits = pset.get<
unsigned int>(
"MinHits", 1);
85 produces<std::vector<recob::Cluster>>();
86 produces<art::Assns<recob::Cluster, recob::Hit>>();
93 art::ServiceHandle<geo::Geometry const> geo;
94 art::ServiceHandle<cheat::BackTrackerService const> bt_serv;
95 art::ServiceHandle<cheat::ParticleInventoryService> pi_serv;
98 art::Handle<std::vector<recob::Hit>> hitcol;
103 std::vector<art::Ptr<recob::Hit>> hits;
104 art::fill_ptr_vector(hits, hitcol);
109 pi_serv->SetEveIdCalculator(
new sim::EmEveIdCalculator);
111 MF_LOG_DEBUG(
"ClusterCheater") << pi_serv->ParticleList();
115 std::map<eveLoc, std::vector<art::Ptr<recob::Hit>>> eveHitMap;
117 auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
120 for (
auto const& itr : hits) {
122 std::vector<sim::TrackIDE> eveides = bt_serv->HitToEveTrackIDEs(clockData, itr);
125 for (
size_t e = 0;
e < eveides.size(); ++
e) {
129 if (eveides[
e].energyFrac < 0.1)
continue;
131 eveLoc el(eveides[
e].trackID, itr->WireID().planeID());
133 eveHitMap[el].push_back(itr);
140 std::unique_ptr<std::vector<recob::Cluster>> clustercol(
new std::vector<recob::Cluster>);
141 std::unique_ptr<art::Assns<recob::Cluster, recob::Hit>> assn(
142 new art::Assns<recob::Cluster, recob::Hit>);
145 art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(evt, clockData);
153 for (
auto hitMapItr : eveHitMap) {
158 if (hitMapItr.second.size() <
fMinHits)
continue;
161 double xyz[3] = {0.};
162 double xyz2[3] = {0.};
163 double local[3] = {0.};
164 unsigned int cryostat = hitMapItr.first.planeID.Cryostat;
165 unsigned int tpc = hitMapItr.first.planeID.TPC;
166 unsigned int plane = hitMapItr.first.planeID.Plane;
167 geo->Cryostat(cryostat).TPC(tpc).Plane(plane).LocalToWorld(local, xyz);
169 MF_LOG_DEBUG(
"ClusterCheater")
170 <<
"make cluster for eveID: " << hitMapItr.first.eveID <<
" in cryostat: " << cryostat
171 <<
" tpc: " << tpc <<
" plane: " << plane <<
" view: " << hitMapItr.second.at(0)->View();
174 const simb::MCParticle* part = pi_serv->TrackIdToParticle_P(hitMapItr.first.eveID);
184 xyz2[1] = xyz[1] + 10. * part->Py() / part->P();
185 xyz2[2] = xyz[2] + 10. * part->Pz() / part->P();
192 w1 = geo->NearestWire(xyz, plane, tpc, cryostat);
194 catch (cet::exception&
e) {
195 w1 = atoi(e.explain_self().substr(e.explain_self().find(
"#") + 1, 5).c_str());
198 w2 = geo->NearestWire(xyz2, plane, tpc, cryostat);
200 catch (cet::exception& e) {
201 w2 = atoi(e.explain_self().substr(e.explain_self().find(
"#") + 1, 5).c_str());
206 std::sort(hitMapItr.second.rbegin(), hitMapItr.second.rend(),
sortHitsByWire);
208 std::sort(hitMapItr.second.begin(), hitMapItr.second.end(),
sortHitsByWire);
211 double startWire = hitMapItr.second.front()->WireID().Wire;
212 double startTime = hitMapItr.second.front()->PeakTimeMinusRMS();
213 double endWire = hitMapItr.second.back()->WireID().Wire;
214 double endTime = hitMapItr.second.back()->PeakTimePlusRMS();
221 (((hitMapItr.first.eveID) * 10 + planeID.
Plane) * 10 +
228 ClusterParamAlgo.
ImportHits(gser, hitMapItr.second);
242 hitMapItr.second.at(0)->View(),
247 clustercol->emplace_back(
cluster.move());
252 mf::LogInfo(
"ClusterCheater") <<
"adding cluster: \n"
253 << clustercol->back() <<
"\nto collection.";
257 evt.put(std::move(clustercol));
258 evt.put(std::move(assn));
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)
Declaration of signal hit object.
The data type to uniquely identify a Plane.
CryostatID_t Cryostat
Index of cryostat.
void produce(art::Event &evt) override
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.
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)
ClusterCheater(fhicl::ParameterSet const &pset)
Helper functions to create a cluster.
Wrapper for ClusterParamsAlgBase objects to accept diverse input.
Wrapper for ClusterParamsAlgBase objects to accept arbitrary input.
PlaneID_t Plane
Index of the plane within its TPC.
Declaration of cluster object.
Definition of data types for geometry description.
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.
Encapsulate the construction of a single detector plane.
friend bool operator<(eveLoc const &a, eveLoc const &b)
Interface to class computing cluster parameters.
TPCID_t TPC
Index of the TPC within its cryostat.
std::string fG4ModuleLabel
label for module running G4 and making particles, etc
art framework interface to geometry description
int ID_t
Type of cluster ID.
Encapsulate the construction of a single detector plane.