182 auto const clockData =
187 std::vector<art::Ptr<recob::Track>> tracklist;
193 std::vector<art::Ptr<recob::Shower>> showerlist;
199 std::vector<art::Ptr<recob::PFParticle>> pfparticlelist;
203 auto mcpartHandle =
evt.getValidHandle<std::vector<simb::MCParticle>>(
"largeant");
206 std::unique_ptr<std::vector<anab::T0>> T0col(
new std::vector<anab::T0>);
208 std::unique_ptr<art::Assns<recob::Track, anab::T0>> Trackassn(
210 std::unique_ptr<art::Assns<recob::Shower, anab::T0>> Showerassn(
212 std::unique_ptr<art::Assns<recob::PFParticle, anab::T0>> PFParticleassn(
217 std::unique_ptr<art::Assns<recob::Track, simb::MCParticle, anab::BackTrackerMatchingData>>
219 std::unique_ptr<art::Assns<recob::Shower, simb::MCParticle, anab::BackTrackerMatchingData>>
222 std::unique_ptr<art::Assns<recob::PFParticle, simb::MCParticle, anab::BackTrackerMatchingData>>
223 MCPartPFParticleassn(
226 std::unique_ptr<art::Assns<recob::Hit, simb::MCParticle, anab::BackTrackerHitMatchingData>>
238 std::unordered_map<int, int> trkid_lookup;
248 auto const& hitList(*hitListHandle);
249 auto const& mcpartList(*mcpartHandle);
250 for (
size_t i_h = 0; i_h < hitList.size(); ++i_h) {
253 struct TrackIDEinfo {
257 std::map<int, TrackIDEinfo> trkide_collector;
264 for (
auto const&
t : trkide_list) {
265 trkide_collector[
t.trackID].E +=
t.energy;
267 if (trkide_collector[
t.trackID].E > maxe) {
268 maxe = trkide_collector[
t.trackID].E;
269 maxtrkid =
t.trackID;
271 trkide_collector[
t.trackID].NumElectrons +=
t.numElectrons;
272 totn +=
t.numElectrons;
273 if (trkide_collector[
t.trackID].NumElectrons > maxn) {
274 maxn = trkide_collector[
t.trackID].NumElectrons;
275 maxntrkid =
t.trackID;
279 if (trkid_lookup.find(
t.trackID) == trkid_lookup.end()) {
281 while (i_p < mcpartList.size()) {
282 if (mcpartList[i_p].TrackId() ==
t.trackID) {
283 trkid_lookup[
t.trackID] = (
int)i_p;
288 if (i_p == mcpartList.size()) trkid_lookup[
t.trackID] = -1;
294 for (
auto const&
t : trkide_collector) {
295 int mcpart_i = trkid_lookup[
t.first];
296 if (mcpart_i == -1)
continue;
302 MCPartHitassn->addSingle(hitPtr, mcpartPtr, bthmd);
311 if (trackListHandle.
isValid()) {
315 size_t NTracks = tracklist.size();
318 for (
size_t iTrk = 0; iTrk < NTracks; ++iTrk) {
323 std::vector<art::Ptr<recob::Hit>> allHits = fmtht.at(iTrk);
325 std::map<int, double> trkide;
326 for (
size_t h = 0;
h < allHits.size(); ++
h) {
328 std::vector<sim::IDE> ides;
331 for (
size_t e = 0; e < TrackIDs.size(); ++
e) {
332 trkide[TrackIDs[
e].trackID] += TrackIDs[
e].energy;
340 if ((ii->second) > maxe) {
353 for (
auto const particle : *mcpartHandle) {
355 if (
TrackID == particle.TrackId()) {
break; }
364 auto diff = mcpart_i;
365 if (diff >= (
int)mcpartHandle->size()) {
366 std::cout <<
"Error, the backtracker is doing weird things to your pointers!" <<
std::endl;
371 MCPartTrackassn->addSingle(tracklist[iTrk], mcpartPtr, btdata);
378 if (showerListHandle.
isValid()) {
381 size_t NShowers = showerlist.size();
382 for (
size_t Shower = 0; Shower < NShowers; ++Shower) {
386 std::vector<art::Ptr<recob::Hit>> allHits = fmsht.at(Shower);
389 std::map<int, double> showeride;
390 for (
size_t h = 0;
h < allHits.size(); ++
h) {
392 std::vector<sim::IDE> ides;
393 std::vector<sim::TrackIDE> TrackIDs = bt_serv->
HitToTrackIDEs(clockData, hit);
395 for (
size_t e = 0; e < TrackIDs.size(); ++
e) {
396 showeride[TrackIDs[
e].trackID] += TrackIDs[
e].energy;
404 if ((ii->second) > maxe) {
417 for (
auto const particle : *mcpartHandle) {
427 auto diff = mcpart_i;
428 if (diff >= (
int)mcpartHandle->size()) {
429 std::cout <<
"Error, the backtracker is doing weird things to your pointers!" <<
std::endl;
434 MCPartShowerassn->addSingle(showerlist[Shower], mcpartPtr, btdata);
439 if (pfparticleListHandle.
isValid()) {
443 size_t NPfparticles = pfparticlelist.size();
446 for (
size_t iPfp = 0; iPfp < NPfparticles; ++iPfp) {
452 std::vector<art::Ptr<recob::Hit>> allHits;
454 std::vector<art::Ptr<recob::Cluster>> allClusters = fmcp.at(iPfp);
456 for (
size_t iclu = 0; iclu < allClusters.size(); ++iclu) {
457 std::vector<art::Ptr<recob::Hit>> hits = fmhcl.at(iclu);
458 allHits.insert(allHits.end(), hits.begin(), hits.end());
461 std::map<int, double> trkide;
462 for (
size_t h = 0;
h < allHits.size(); ++
h) {
464 std::vector<sim::IDE> ides;
465 std::vector<sim::TrackIDE> TrackIDs = bt_serv->
HitToTrackIDEs(clockData, hit);
467 for (
size_t e = 0; e < TrackIDs.size(); ++
e) {
468 trkide[TrackIDs[
e].trackID] += TrackIDs[
e].energy;
476 if ((ii->second) > maxe) {
489 for (
auto const particle : *mcpartHandle) {
503 auto diff = mcpart_i;
504 if (diff >= (
int)mcpartHandle->size()) {
505 std::cout <<
"Error, the backtracker is doing weird things to your pointers!" <<
std::endl;
518 MCPartPFParticleassn->addSingle(pfparticlelist[iPfp], mcpartPtr, btdata);
art::InputTag fPFParticleModuleLabel
std::vector< sim::TrackIDE > HitToTrackIDEs(detinfo::DetectorClocksData const &clockData, recob::Hit const &hit) const
std::vector< TrackID > TrackIDs
const simb::MCParticle * TrackIdToParticle_P(int id) const
bool isValid() const noexcept
art::InputTag fHitModuleLabel
double T(const int i=0) const
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.
art::InputTag fTrackModuleLabel
Detector simulation of raw signals on wires.
bool fMakePFParticleAssns
art::InputTag fShowerModuleLabel
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
cet::coded_exception< error, detail::translate > exception
QTextStream & endl(QTextStream &s)