92 class MCTruthT0Matching;
150 std::cout <<
"WARNING - You are using deprecated functionality\n";
151 std::cout <<
"MCTruthT0Matching T0 assns will be removed soon\n";
152 std::cout <<
"set your fcl parameter makeT0Assns to false and use MCParticle direct associations instead" << std::endl;
153 produces< std::vector<anab::T0> >();
154 produces< art::Assns<recob::Track , anab::T0> >();
155 produces< art::Assns<recob::Shower, anab::T0> > ();
159 produces< art::Assns<recob::Track , simb::MCParticle, anab::BackTrackerMatchingData > > ();
160 produces< art::Assns<recob::Shower, simb::MCParticle, anab::BackTrackerMatchingData > > ();
162 produces< art::Assns<recob::PFParticle, simb::MCParticle, anab::BackTrackerMatchingData > > ();
166 produces< art::Assns<recob::Hit , simb::MCParticle, anab::BackTrackerHitMatchingData > > ();
188 fTree = tfs->
make<TTree>(
"MCTruthT0Matching",
"MCTruthT0");
206 std::vector<art::Ptr<recob::Track> > tracklist;
213 std::vector<art::Ptr<recob::Shower> > showerlist;
220 std::vector<art::Ptr<recob::PFParticle> > pfparticlelist;
226 auto mcpartHandle = evt.
getValidHandle< std::vector<simb::MCParticle> >(
"largeant");
229 std::unique_ptr< std::vector<anab::T0> > T0col(
new std::vector<anab::T0>);
258 std::unordered_map<int,int> trkid_lookup;
270 auto const& hitList(*hitListHandle);
271 auto const& mcpartList(*mcpartHandle);
272 for(
size_t i_h=0; i_h<hitList.size(); ++i_h){
275 struct TrackIDEinfo {
279 std::map<int, TrackIDEinfo> trkide_collector;
280 maxe = -1; tote = 0; maxtrkid = -1;
281 maxn = -1; totn = 0; maxntrkid = -1;
282 for(
auto const& t : trkide_list){
283 trkide_collector[t.trackID].E += t.energy;
285 if(trkide_collector[t.trackID].E>maxe) { maxe = trkide_collector[t.trackID].E; maxtrkid = t.trackID; }
286 trkide_collector[t.trackID].NumElectrons += t.numElectrons;
287 totn += t.numElectrons;
288 if(trkide_collector[t.trackID].NumElectrons > maxn) {
289 maxn = trkide_collector[t.trackID].NumElectrons;
290 maxntrkid = t.trackID;
294 if(trkid_lookup.find(t.trackID)==trkid_lookup.end()){
296 while(i_p<mcpartList.size()){
297 if(mcpartList[i_p].TrackId() == t.trackID) { trkid_lookup[t.trackID] = (int)i_p;
break;}
300 if(i_p==mcpartList.size()) trkid_lookup[t.trackID] = -1;
306 for(
auto const& t : trkide_collector){
307 int mcpart_i = trkid_lookup[t.first];
308 if(mcpart_i==-1)
continue;
311 bthmd.
isMaxIDE = (t.first==maxtrkid);
313 bthmd.
isMaxIDEN = ( t.first == maxntrkid );
314 MCPartHitassn->addSingle(hitPtr, mcpartPtr, bthmd);
325 if (trackListHandle.
isValid()){
329 size_t NTracks = tracklist.size();
332 for(
size_t iTrk=0; iTrk < NTracks; ++iTrk) {
337 std::vector< art::Ptr<recob::Hit> > allHits = fmtht.at(iTrk);
339 std::map<int,double> trkide;
340 for(
size_t h = 0; h < allHits.size(); ++h){
342 std::vector<sim::IDE> ides;
345 for(
size_t e = 0;
e < TrackIDs.size(); ++
e){
346 trkide[TrackIDs[
e].trackID] += TrackIDs[
e].energy;
355 if ((ii->second)>maxe){
364 if (!tmpParticle)
continue;
367 for (
auto const particle : *mcpartHandle){
369 if (
TrackID == particle.TrackId()){
387 auto diff = mcpart_i;
388 if (diff >= (
int)mcpartHandle->size()){
389 std::cout <<
"Error, the backtracker is doing weird things to your pointers!" << std::endl;
394 MCPartTrackassn->addSingle(tracklist[iTrk], mcpartPtr, btdata);
403 if (showerListHandle.
isValid()){
406 size_t NShowers = showerlist.size();
407 for (
size_t Shower = 0; Shower < NShowers; ++Shower) {
411 std::vector< art::Ptr<recob::Hit> > allHits = fmsht.at(Shower);
414 std::map<int,double> showeride;
415 for(
size_t h = 0; h < allHits.size(); ++h){
417 std::vector<sim::IDE> ides;
420 for(
size_t e = 0;
e < TrackIDs.size(); ++
e){
421 showeride[TrackIDs[
e].trackID] += TrackIDs[
e].energy;
429 if ((ii->second)>maxe){
441 if (!tmpParticle)
continue;
444 for (
auto const particle : *mcpartHandle){
446 if (
ShowerID == particle.TrackId()){
460 auto diff = mcpart_i;
461 if (diff >= (
int)mcpartHandle->size()){
462 std::cout <<
"Error, the backtracker is doing weird things to your pointers!" << std::endl;
469 MCPartShowerassn->addSingle(showerlist[Shower], mcpartPtr, btdata);
475 if (pfparticleListHandle.
isValid()){
480 size_t NPfparticles = pfparticlelist.size();
483 for(
size_t iPfp=0; iPfp < NPfparticles; ++iPfp) {
489 std::vector< art::Ptr<recob::Hit> > allHits;
491 std::vector< art::Ptr<recob::Cluster>> allClusters = fmcp.at(iPfp);
493 for (
size_t iclu = 0; iclu<allClusters.size(); ++iclu){
494 std::vector< art::Ptr<recob::Hit>>
hits = fmhcl.at(iclu);
495 allHits.insert(allHits.end(), hits.begin(), hits.end());
498 std::map<int,double> trkide;
499 for(
size_t h = 0; h < allHits.size(); ++h){
501 std::vector<sim::IDE> ides;
504 for(
size_t e = 0;
e < TrackIDs.size(); ++
e){
505 trkide[TrackIDs[
e].trackID] += TrackIDs[
e].energy;
513 if ((ii->second)>maxe){
522 if (!tmpParticle)
continue;
525 for (
auto const particle : *mcpartHandle){
527 if (
TrackID == particle.TrackId()){
545 auto diff = mcpart_i;
546 if (diff >= (
int)mcpartHandle->size()){
547 std::cout <<
"Error, the backtracker is doing weird things to your pointers!" << std::endl;
558 util::CreateAssn(*
this, evt, *T0col, pfparticlelist[iPfp], *PFParticleassn);
560 MCPartPFParticleassn->addSingle(pfparticlelist[iPfp], mcpartPtr, btdata);
567 evt.
put(std::move(T0col));
568 evt.
put(std::move(Trackassn));
569 evt.
put(std::move(Showerassn));
571 evt.
put(std::move(PFParticleassn));
574 evt.
put(std::move(MCPartTrackassn));
575 evt.
put(std::move(MCPartShowerassn));
577 evt.
put(std::move(MCPartPFParticleassn));
580 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)
Provides recob::Track data product.
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.
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