92 class MCTruthT0Matching;
148 std::cout <<
"WARNING - You are using deprecated functionality\n";
149 std::cout <<
"MCTruthT0Matching T0 assns will be removed soon\n";
150 std::cout <<
"set your fcl parameter makeT0Assns to false and use MCParticle direct associations instead" << std::endl;
151 produces< std::vector<anab::T0> >();
152 produces< art::Assns<recob::Track , anab::T0> >();
153 produces< art::Assns<recob::Shower, anab::T0> > ();
157 produces< art::Assns<recob::Track , simb::MCParticle, anab::BackTrackerMatchingData > > ();
158 produces< art::Assns<recob::Shower, simb::MCParticle, anab::BackTrackerMatchingData > > ();
160 produces< art::Assns<recob::PFParticle, simb::MCParticle, anab::BackTrackerMatchingData > > ();
164 produces< art::Assns<recob::Hit , simb::MCParticle, anab::BackTrackerHitMatchingData > > ();
184 fTree = tfs->
make<TTree>(
"MCTruthT0Matching",
"MCTruthT0");
202 std::vector<art::Ptr<recob::Track> > tracklist;
209 std::vector<art::Ptr<recob::Shower> > showerlist;
216 std::vector<art::Ptr<recob::PFParticle> > pfparticlelist;
222 auto mcpartHandle = evt.
getValidHandle< std::vector<simb::MCParticle> >(
"largeant");
225 std::unique_ptr< std::vector<anab::T0> > T0col(
new std::vector<anab::T0>);
254 std::unordered_map<int,int> trkid_lookup;
266 auto const& hitList(*hitListHandle);
267 auto const& mcpartList(*mcpartHandle);
268 for(
size_t i_h=0; i_h<hitList.size(); ++i_h){
271 struct TrackIDEinfo {
275 std::map<int, TrackIDEinfo> trkide_collector;
276 maxe = -1; tote = 0; maxtrkid = -1;
277 maxn = -1; totn = 0; maxntrkid = -1;
278 for(
auto const& t : trkide_list){
279 trkide_collector[t.trackID].E += t.energy;
281 if(trkide_collector[t.trackID].E>maxe) { maxe = trkide_collector[t.trackID].E; maxtrkid = t.trackID; }
282 trkide_collector[t.trackID].NumElectrons += t.numElectrons;
283 totn += t.numElectrons;
284 if(trkide_collector[t.trackID].NumElectrons > maxn) {
285 maxn = trkide_collector[t.trackID].NumElectrons;
286 maxntrkid = t.trackID;
290 if(trkid_lookup.find(t.trackID)==trkid_lookup.end()){
292 while(i_p<mcpartList.size()){
293 if(mcpartList[i_p].TrackId() == t.trackID) { trkid_lookup[t.trackID] = (int)i_p;
break;}
296 if(i_p==mcpartList.size()) trkid_lookup[t.trackID] = -1;
302 for(
auto const& t : trkide_collector){
303 int mcpart_i = trkid_lookup[t.first];
304 if(mcpart_i==-1)
continue;
307 bthmd.
isMaxIDE = (t.first==maxtrkid);
309 bthmd.
isMaxIDEN = ( t.first == maxntrkid );
310 MCPartHitassn->addSingle(hitPtr, mcpartPtr, bthmd);
321 if (trackListHandle.
isValid()){
325 size_t NTracks = tracklist.size();
328 for(
size_t iTrk=0; iTrk < NTracks; ++iTrk) {
333 std::vector< art::Ptr<recob::Hit> > allHits = fmtht.at(iTrk);
335 std::map<int,double> trkide;
336 for(
size_t h = 0; h < allHits.size(); ++h){
338 std::vector<sim::IDE> ides;
341 for(
size_t e = 0;
e < TrackIDs.size(); ++
e){
342 trkide[TrackIDs[
e].trackID] += TrackIDs[
e].energy;
351 if ((ii->second)>maxe){
360 if (!tmpParticle)
continue;
363 for (
auto const particle : *mcpartHandle){
365 if (
TrackID == particle.TrackId()){
383 auto diff = mcpart_i;
384 if (diff >= (
int)mcpartHandle->size()){
385 std::cout <<
"Error, the backtracker is doing weird things to your pointers!" << std::endl;
390 MCPartTrackassn->addSingle(tracklist[iTrk], mcpartPtr, btdata);
399 if (showerListHandle.
isValid()){
402 size_t NShowers = showerlist.size();
403 for (
size_t Shower = 0; Shower < NShowers; ++Shower) {
407 std::vector< art::Ptr<recob::Hit> > allHits = fmsht.at(Shower);
410 std::map<int,double> showeride;
411 for(
size_t h = 0; h < allHits.size(); ++h){
413 std::vector<sim::IDE> ides;
416 for(
size_t e = 0;
e < TrackIDs.size(); ++
e){
417 showeride[TrackIDs[
e].trackID] += TrackIDs[
e].energy;
425 if ((ii->second)>maxe){
437 if (!tmpParticle)
continue;
440 for (
auto const particle : *mcpartHandle){
442 if (
ShowerID == particle.TrackId()){
456 auto diff = mcpart_i;
457 if (diff >= (
int)mcpartHandle->size()){
458 std::cout <<
"Error, the backtracker is doing weird things to your pointers!" << std::endl;
465 MCPartShowerassn->addSingle(showerlist[Shower], mcpartPtr, btdata);
471 if (pfparticleListHandle.
isValid()){
476 size_t NPfparticles = pfparticlelist.size();
479 for(
size_t iPfp=0; iPfp < NPfparticles; ++iPfp) {
485 std::vector< art::Ptr<recob::Hit> > allHits;
487 std::vector< art::Ptr<recob::Cluster>> allClusters = fmcp.at(iPfp);
489 for (
size_t iclu = 0; iclu<allClusters.size(); ++iclu){
490 std::vector< art::Ptr<recob::Hit>>
hits = fmhcl.at(iclu);
491 allHits.insert(allHits.end(), hits.begin(), hits.end());
494 std::map<int,double> trkide;
495 for(
size_t h = 0; h < allHits.size(); ++h){
497 std::vector<sim::IDE> ides;
500 for(
size_t e = 0;
e < TrackIDs.size(); ++
e){
501 trkide[TrackIDs[
e].trackID] += TrackIDs[
e].energy;
509 if ((ii->second)>maxe){
518 if (!tmpParticle)
continue;
521 for (
auto const particle : *mcpartHandle){
523 if (
TrackID == particle.TrackId()){
541 auto diff = mcpart_i;
542 if (diff >= (
int)mcpartHandle->size()){
543 std::cout <<
"Error, the backtracker is doing weird things to your pointers!" << std::endl;
554 util::CreateAssn(*
this, evt, *T0col, pfparticlelist[iPfp], *PFParticleassn);
556 MCPartPFParticleassn->addSingle(pfparticlelist[iPfp], mcpartPtr, btdata);
563 evt.
put(std::move(T0col));
564 evt.
put(std::move(Trackassn));
565 evt.
put(std::move(Showerassn));
567 evt.
put(std::move(PFParticleassn));
570 evt.
put(std::move(MCPartTrackassn));
571 evt.
put(std::move(MCPartShowerassn));
573 evt.
put(std::move(MCPartPFParticleassn));
576 evt.
put(std::move(MCPartHitassn));
art::InputTag fPFParticleModuleLabel
code to link reconstructed objects back to the MC truth information
const simb::MCParticle * TrackIdToParticle_P(int const &id)
MCTruthT0Matching & operator=(MCTruthT0Matching const &)=delete
const std::vector< sim::TrackIDE > HitToTrackIDEs(recob::Hit const &hit)
std::vector< TrackID > TrackIDs
Declaration of signal hit object.
TNtupleSim Fill(f1, f2, f3, f4)
MCTruthT0Matching(fhicl::ParameterSet const &p)
void produce(art::Event &e) override
ProductID put(std::unique_ptr< PROD > &&product)
art::InputTag fHitModuleLabel
#define DEFINE_ART_MODULE(klass)
T get(std::string const &key) const
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
Declaration of cluster object.
Provides recob::Track data product.
Detector simulation of raw signals on wires.
Encapsulate the geometry of a wire.
bool fMakePFParticleAssns
T * make(ARGS...args) const
Utility object to perform functions of association.
Encapsulate the construction of a single detector plane.
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
art::InputTag fShowerModuleLabel
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
void reconfigure(fhicl::ParameterSet const &p)
art framework interface to geometry description
cet::coded_exception< error, detail::translate > exception