47 #include "art_root_io/TFileService.h" 78 class MCTruthT0Matching;
140 std::cout <<
"WARNING - You are using deprecated functionality\n";
141 std::cout <<
"MCTruthT0Matching T0 assns will be removed soon\n";
142 std::cout <<
"set your fcl parameter makeT0Assns to false and use MCParticle direct " 143 "associations instead" 145 produces<std::vector<anab::T0>>();
146 produces<art::Assns<recob::Track, anab::T0>>();
147 produces<art::Assns<recob::Shower, anab::T0>>();
149 produces<art::Assns<recob::PFParticle, anab::T0>>();
153 produces<art::Assns<recob::Track, simb::MCParticle, anab::BackTrackerMatchingData>>();
154 produces<art::Assns<recob::Shower, simb::MCParticle, anab::BackTrackerMatchingData>>();
156 produces<art::Assns<recob::PFParticle, simb::MCParticle, anab::BackTrackerMatchingData>>();
160 produces<art::Assns<recob::Hit, simb::MCParticle, anab::BackTrackerHitMatchingData>>();
167 fTree = tfs->make<TTree>(
"MCTruthT0Matching",
"MCTruthT0");
184 std::vector<art::Ptr<recob::Track>> tracklist;
190 std::vector<art::Ptr<recob::Shower>> showerlist;
196 std::vector<art::Ptr<recob::PFParticle>> pfparticlelist;
200 auto mcpartHandle = evt.
getValidHandle<std::vector<simb::MCParticle>>(
"largeant");
203 std::unique_ptr<std::vector<anab::T0>> T0col(
new std::vector<anab::T0>);
205 std::unique_ptr<art::Assns<recob::Track, anab::T0>> Trackassn(
207 std::unique_ptr<art::Assns<recob::Shower, anab::T0>> Showerassn(
209 std::unique_ptr<art::Assns<recob::PFParticle, anab::T0>> PFParticleassn(
214 std::unique_ptr<art::Assns<recob::Track, simb::MCParticle, anab::BackTrackerMatchingData>>
216 std::unique_ptr<art::Assns<recob::Shower, simb::MCParticle, anab::BackTrackerMatchingData>>
219 std::unique_ptr<art::Assns<recob::PFParticle, simb::MCParticle, anab::BackTrackerMatchingData>>
220 MCPartPFParticleassn(
223 std::unique_ptr<art::Assns<recob::Hit, simb::MCParticle, anab::BackTrackerHitMatchingData>>
235 std::unordered_map<int, int> trkid_lookup;
245 auto const& hitList(*hitListHandle);
246 auto const& mcpartList(*mcpartHandle);
247 for (
size_t i_h = 0; i_h < hitList.size(); ++i_h) {
250 struct TrackIDEinfo {
254 std::map<int, TrackIDEinfo> trkide_collector;
261 for (
auto const& t : trkide_list) {
262 trkide_collector[t.trackID].E += t.energy;
264 if (trkide_collector[t.trackID].E > maxe) {
265 maxe = trkide_collector[t.trackID].E;
266 maxtrkid = t.trackID;
268 trkide_collector[t.trackID].NumElectrons += t.numElectrons;
269 totn += t.numElectrons;
270 if (trkide_collector[t.trackID].NumElectrons > maxn) {
271 maxn = trkide_collector[t.trackID].NumElectrons;
272 maxntrkid = t.trackID;
276 if (trkid_lookup.find(t.trackID) == trkid_lookup.end()) {
278 while (i_p < mcpartList.size()) {
279 if (mcpartList[i_p].TrackId() == t.trackID) {
280 trkid_lookup[t.trackID] = (int)i_p;
285 if (i_p == mcpartList.size()) trkid_lookup[t.trackID] = -1;
291 for (
auto const& t : trkide_collector) {
292 int mcpart_i = trkid_lookup[t.first];
293 if (mcpart_i == -1)
continue;
296 bthmd.
isMaxIDE = (t.first == maxtrkid);
298 bthmd.
isMaxIDEN = (t.first == maxntrkid);
299 MCPartHitassn->addSingle(hitPtr, mcpartPtr, bthmd);
308 if (trackListHandle.
isValid()) {
312 size_t NTracks = tracklist.size();
315 for (
size_t iTrk = 0; iTrk < NTracks; ++iTrk) {
320 std::vector<art::Ptr<recob::Hit>> allHits = fmtht.at(iTrk);
322 std::map<int, double> trkide;
323 for (
size_t h = 0; h < allHits.size(); ++h) {
325 std::vector<sim::IDE> ides;
328 for (
size_t e = 0;
e < TrackIDs.size(); ++
e) {
329 trkide[TrackIDs[
e].trackID] += TrackIDs[
e].energy;
337 if ((ii->second) > maxe) {
350 for (
auto const& particle : *mcpartHandle) {
352 if (
TrackID == particle.TrackId()) {
break; }
361 auto diff = mcpart_i;
362 if (diff >= (
int)mcpartHandle->size()) {
363 std::cout <<
"Error, the backtracker is doing weird things to your pointers!" << std::endl;
368 MCPartTrackassn->addSingle(tracklist[iTrk], mcpartPtr, btdata);
375 if (showerListHandle.
isValid()) {
378 size_t NShowers = showerlist.size();
379 for (
size_t Shower = 0; Shower < NShowers; ++Shower) {
383 std::vector<art::Ptr<recob::Hit>> allHits = fmsht.at(Shower);
386 std::map<int, double> showeride;
387 for (
size_t h = 0; h < allHits.size(); ++h) {
389 std::vector<sim::IDE> ides;
392 for (
size_t e = 0;
e < TrackIDs.size(); ++
e) {
393 showeride[TrackIDs[
e].trackID] += TrackIDs[
e].energy;
401 if ((ii->second) > maxe) {
414 for (
auto const& particle : *mcpartHandle) {
416 if (
ShowerID == particle.TrackId()) {
break; }
424 auto diff = mcpart_i;
425 if (diff >= (
int)mcpartHandle->size()) {
426 std::cout <<
"Error, the backtracker is doing weird things to your pointers!" << std::endl;
431 MCPartShowerassn->addSingle(showerlist[Shower], mcpartPtr, btdata);
436 if (pfparticleListHandle.
isValid()) {
440 size_t NPfparticles = pfparticlelist.size();
443 for (
size_t iPfp = 0; iPfp < NPfparticles; ++iPfp) {
449 std::vector<art::Ptr<recob::Hit>> allHits;
451 std::vector<art::Ptr<recob::Cluster>> allClusters = fmcp.at(iPfp);
453 for (
size_t iclu = 0; iclu < allClusters.size(); ++iclu) {
454 std::vector<art::Ptr<recob::Hit>>
hits = fmhcl.at(iclu);
455 allHits.insert(allHits.end(), hits.begin(), hits.end());
458 std::map<int, double> trkide;
459 for (
size_t h = 0; h < allHits.size(); ++h) {
461 std::vector<sim::IDE> ides;
464 for (
size_t e = 0;
e < TrackIDs.size(); ++
e) {
465 trkide[TrackIDs[
e].trackID] += TrackIDs[
e].energy;
473 if ((ii->second) > maxe) {
486 for (
auto const& particle : *mcpartHandle) {
488 if (
TrackID == particle.TrackId()) {
break; }
500 auto diff = mcpart_i;
501 if (diff >= (
int)mcpartHandle->size()) {
502 std::cout <<
"Error, the backtracker is doing weird things to your pointers!" << std::endl;
513 MCPartPFParticleassn->addSingle(pfparticlelist[iPfp], mcpartPtr, btdata);
520 evt.
put(std::move(T0col));
521 evt.
put(std::move(Trackassn));
522 evt.
put(std::move(Showerassn));
525 evt.
put(std::move(MCPartTrackassn));
526 evt.
put(std::move(MCPartShowerassn));
art::InputTag fPFParticleModuleLabel
code to link reconstructed objects back to the MC truth information
std::vector< sim::TrackIDE > HitToTrackIDEs(detinfo::DetectorClocksData const &clockData, recob::Hit const &hit) const
MCTruthT0Matching & operator=(MCTruthT0Matching const &)=delete
std::vector< TrackID > TrackIDs
const simb::MCParticle * TrackIdToParticle_P(int id) const
Declaration of signal hit object.
EDProducer(fhicl::ParameterSet const &pset)
MCTruthT0Matching(fhicl::ParameterSet const &p)
void produce(art::Event &e) override
bool isValid() const noexcept
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
art::InputTag fHitModuleLabel
#define DEFINE_ART_MODULE(klass)
double T(const int i=0) const
Provides recob::Track data product.
art::InputTag fTrackModuleLabel
Declaration of cluster object.
Detector simulation of raw signals on wires.
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 fMakePFParticleAssns
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Utility object to perform functions of association.
art::InputTag fShowerModuleLabel
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
art framework interface to geometry description
cet::coded_exception< error, detail::translate > exception