Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SvtxHitEval.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file SvtxHitEval.cc
1 #include "SvtxHitEval.h"
2 
4 #include <trackbase/TrkrDefs.h>
5 #include <trackbase/TrkrHitSet.h>
8 
9 #include <g4main/PHG4Hit.h>
11 #include <g4main/PHG4HitDefs.h>
12 #include <g4main/PHG4Particle.h>
14 
15 #include <phool/getClass.h>
16 #include <phool/phool.h>
17 
18 #include <cassert>
19 #include <cfloat>
20 #include <cmath>
21 #include <iostream> // for operator<<, endl, basic_...
22 #include <map>
23 #include <set>
24 
25 class TrkrHit;
26 
28  : _trutheval(topNode)
29 {
30  get_node_pointers(topNode);
31 }
32 
34 {
35  if (_verbosity > 0)
36  {
37  if ((_errors > 0) || (_verbosity > 1))
38  {
39  std::cout << "SvtxHitEval::~SvtxHitEval() - Error Count: " << _errors << std::endl;
40  }
41  }
42 }
43 
45 {
46  _cache_all_truth_hits.clear();
55 
56  _trutheval.next_event(topNode);
57 
58  get_node_pointers(topNode);
59 }
60 
61 /*
62 PHG4Cell* SvtxHitEval::get_cell(SvtxHit* hit)
63 {
64  if (!has_node_pointers())
65  {
66  ++_errors;
67  std::cout << PHWHERE << " nerr: " << _errors << std::endl;
68  return nullptr;
69  }
70 
71  if (_strict)
72  {
73  assert(hit);
74  }
75  else if (!hit)
76  {
77  ++_errors;
78  std::cout << PHWHERE << " nerr: " << _errors << std::endl;
79  return nullptr;
80  }
81 
82  // hop from reco hit to g4cell
83  PHG4Cell* cell = nullptr;
84  if (_g4cells_svtx) cell = _g4cells_svtx->findCell(hit->get_cellid());
85  if (!cell && _g4cells_tracker) cell = _g4cells_tracker->findCell(hit->get_cellid());
86  if (!cell && _g4cells_maps) cell = _g4cells_maps->findCell(hit->get_cellid());
87 
88  // only noise hits (cellid left at default value) should not trace
89  if ((_strict) && (hit->get_cellid() != 0xFFFFFFFF))
90  {
91  assert(cell);
92  }
93  else if (!cell)
94  {
95  ++_errors;
96  std::cout << PHWHERE << " nerr: " << _errors << std::endl;
97  }
98 
99  return cell;
100 }
101 */
102 
104 {
105  if (!has_node_pointers())
106  {
107  ++_errors;
108  if (_verbosity > 0)
109  {
110  std::cout << PHWHERE << " nerr: " << _errors << std::endl;
111  }
112  return std::set<PHG4Hit*>();
113  }
114 
115  if (_strict)
116  {
117  assert(hit_key);
118  }
119  else if (!hit_key)
120  {
121  ++_errors;
122  if (_verbosity > 0)
123  {
124  std::cout << PHWHERE << " nerr: " << _errors << std::endl;
125  }
126  return std::set<PHG4Hit*>();
127  }
128 
129  if (_do_cache)
130  {
131  std::map<TrkrDefs::hitkey, std::set<PHG4Hit*> >::iterator iter =
132  _cache_all_truth_hits.find(hit_key);
133  if (iter != _cache_all_truth_hits.end())
134  {
135  return iter->second;
136  }
137  }
138 
139  std::set<PHG4Hit*> truth_hits;
140 
141  /*
142  // hop from reco hit to g4cell
143  PHG4Cell* cell = nullptr;
144  if (_g4cells_svtx) cell = _g4cells_svtx->findCell(hit->get_cellid());
145  if (!cell && _g4cells_tracker) cell = _g4cells_tracker->findCell(hit->get_cellid());
146  if (!cell && _g4cells_maps) cell = _g4cells_maps->findCell(hit->get_cellid());
147 
148  // only noise hits (cellid left at default value) should not trace
149  if ((_strict) && (hit->get_cellid() != 0xFFFFFFFF))
150  assert(cell);
151  else if (!cell)
152  {
153  ++_errors;
154  std::cout << PHWHERE << " nerr: " << _errors << std::endl;
155  return truth_hits;
156  }
157 
158  //std::cout << "Eval: hitid " << hit->get_id() << " cellid " << cell->get_cellid() << std::endl;
159  // loop over all the g4hits in this cell
160  for (PHG4Cell::EdepConstIterator g4iter = cell->get_g4hits().first;
161  g4iter != cell->get_g4hits().second;
162  ++g4iter)
163  {
164  //std::cout << " Looking for hit " << g4iter->first << " in layer " << cell->get_layer() << " with edep " << g4iter->second << std::endl;
165  PHG4Hit* g4hit = nullptr;
166  if (_g4hits_svtx) g4hit = _g4hits_svtx->findHit(g4iter->first);
167  if (!g4hit && _g4hits_tracker) g4hit = _g4hits_tracker->findHit(g4iter->first);
168  if (!g4hit && _g4hits_maps) g4hit = _g4hits_maps->findHit(g4iter->first);
169  if (!g4hit) std::cout << " Failed to find g4hit " << g4iter->first << " with edep " << g4iter->second << std::endl;
170  if (_strict)
171  assert(g4hit);
172  else if (!g4hit)
173  {
174  ++_errors;
175  std::cout << PHWHERE << " nerr: " << _errors << std::endl;
176  continue;
177  }
178  */
179 
180  // get all of the g4hits for this hit_key
181  // have to start with all hitsets, unfortunately
183  for (TrkrHitSetContainer::ConstIterator iter = all_hitsets.first; iter != all_hitsets.second; ++iter)
184  {
185  TrkrDefs::hitsetkey hitset_key = iter->first;
186  unsigned int trkrid = TrkrDefs::getTrkrId(hitset_key);
187  TrkrHitSet* hitset = iter->second;
188 
189  // does this hitset contain our hitkey?
190  TrkrHit* hit = nullptr;
191  hit = hitset->getHit(hit_key);
192  if (hit)
193  {
194  // get g4hits for this hit
195 
196  std::multimap<TrkrDefs::hitsetkey, std::pair<TrkrDefs::hitkey, PHG4HitDefs::keytype> > temp_map;
197  _hit_truth_map->getG4Hits(hitset_key, hit_key, temp_map); // returns pairs (hitsetkey, std::pair(hitkey, g4hitkey)) for this hitkey only
198  for (auto& htiter : temp_map)
199  {
200  // extract the g4 hit key here and add the g4hit to the set
201  PHG4HitDefs::keytype g4hitkey = htiter.second.second;
202  // std::cout << " hitkey " << hitkey << " g4hitkey " << g4hitkey << std::endl;
203  PHG4Hit* g4hit = nullptr;
204  switch (trkrid)
205  {
206  case TrkrDefs::tpcId:
207  g4hit = _g4hits_tpc->findHit(g4hitkey);
208  break;
209  case TrkrDefs::inttId:
210  g4hit = _g4hits_intt->findHit(g4hitkey);
211  break;
212  case TrkrDefs::mvtxId:
213  g4hit = _g4hits_mvtx->findHit(g4hitkey);
214  break;
216  g4hit = _g4hits_mms->findHit(g4hitkey);
217  break;
218  default:
219  break;
220  }
221  // fill output set
222  if (g4hit)
223  {
224  truth_hits.insert(g4hit);
225  }
226  }
227  }
228  }
229 
230  if (_do_cache)
231  {
232  _cache_all_truth_hits.insert(std::make_pair(hit_key, truth_hits));
233  }
234 
235  return truth_hits;
236 }
237 
238 std::set<PHG4Hit*> SvtxHitEval::all_truth_hits(TrkrDefs::hitkey hit_key, const TrkrDefs::TrkrId trkrid)
239 {
240  if (!has_node_pointers())
241  {
242  ++_errors;
243  if (_verbosity > 0)
244  {
245  std::cout << PHWHERE << " nerr: " << _errors << std::endl;
246  }
247  return std::set<PHG4Hit*>();
248  }
249 
250  if (_strict)
251  {
252  assert(hit_key);
253  }
254  else if (!hit_key)
255  {
256  ++_errors;
257  if (_verbosity > 0)
258  {
259  std::cout << PHWHERE << " nerr: " << _errors << std::endl;
260  }
261  return std::set<PHG4Hit*>();
262  }
263 
264  if (_do_cache)
265  {
266  std::map<TrkrDefs::hitkey, std::set<PHG4Hit*> >::iterator iter =
267  _cache_all_truth_hits.find(hit_key);
268  if (iter != _cache_all_truth_hits.end())
269  {
270  return iter->second;
271  }
272  }
273 
274  std::set<PHG4Hit*> truth_hits;
275  TrkrHitSetContainer::ConstRange all_hitsets = _hitmap->getHitSets(trkrid);
276 
277  for (TrkrHitSetContainer::ConstIterator iter = all_hitsets.first; iter != all_hitsets.second; ++iter)
278  {
279  TrkrDefs::hitsetkey hitset_key = iter->first;
280  TrkrHitSet* hitset = iter->second;
281 
282  // does this hitset contain our hitkey?
283  TrkrHit* hit = nullptr;
284  hit = hitset->getHit(hit_key);
285  if (hit)
286  {
287  // get g4hits for this hit
288 
289  std::multimap<TrkrDefs::hitsetkey, std::pair<TrkrDefs::hitkey, PHG4HitDefs::keytype> > temp_map;
290  _hit_truth_map->getG4Hits(hitset_key, hit_key, temp_map); // returns pairs (hitsetkey, std::pair(hitkey, g4hitkey)) for this hitkey only
291  for (auto& htiter : temp_map)
292  {
293  // extract the g4 hit key here and add the g4hit to the set
294  PHG4HitDefs::keytype g4hitkey = htiter.second.second;
295  // std::cout << " hitkey " << hitkey << " g4hitkey " << g4hitkey << std::endl;
296  PHG4Hit* g4hit = nullptr;
297  switch (trkrid)
298  {
299  case TrkrDefs::tpcId:
300  g4hit = _g4hits_tpc->findHit(g4hitkey);
301  break;
302  case TrkrDefs::inttId:
303  g4hit = _g4hits_intt->findHit(g4hitkey);
304  break;
305  case TrkrDefs::mvtxId:
306  g4hit = _g4hits_mvtx->findHit(g4hitkey);
307  break;
309  g4hit = _g4hits_mms->findHit(g4hitkey);
310  break;
311  default:
312  break;
313  }
314  // fill output set
315  if (g4hit)
316  {
317  truth_hits.insert(g4hit);
318  }
319  }
320  }
321  }
322 
323  if (_do_cache)
324  {
325  _cache_all_truth_hits.insert(std::make_pair(hit_key, truth_hits));
326  }
327 
328  return truth_hits;
329 }
330 
332 {
333  if (!has_node_pointers())
334  {
335  ++_errors;
336  if (_verbosity > 0)
337  {
338  std::cout << PHWHERE << " nerr: " << _errors << std::endl;
339  }
340  return nullptr;
341  }
342 
343  if (_strict)
344  {
345  assert(hit_key);
346  }
347  else if (!hit_key)
348  {
349  ++_errors;
350  if (_verbosity > 0)
351  {
352  std::cout << PHWHERE << " nerr: " << _errors << std::endl;
353  }
354  return nullptr;
355  }
356 
357  if (_do_cache)
358  {
359  std::map<TrkrDefs::hitkey, PHG4Hit*>::iterator iter =
360  _cache_max_truth_hit_by_energy.find(hit_key);
361  if (iter != _cache_max_truth_hit_by_energy.end())
362  {
363  return iter->second;
364  }
365  }
366 
367  std::set<PHG4Hit*> hits = all_truth_hits(hit_key);
368  PHG4Hit* max_hit = nullptr;
369  float max_e = FLT_MAX * -1.0;
370  for (auto hit : hits)
371  {
372  if (hit->get_edep() > max_e)
373  {
374  max_e = hit->get_edep();
375  max_hit = hit;
376  }
377  }
378 
379  if (_do_cache)
380  {
381  _cache_max_truth_hit_by_energy.insert(std::make_pair(hit_key, max_hit));
382  }
383 
384  return max_hit;
385 }
386 
388 {
389  if (!has_node_pointers())
390  {
391  ++_errors;
392  if (_verbosity > 0)
393  {
394  std::cout << PHWHERE << " nerr: " << _errors << std::endl;
395  }
396  return nullptr;
397  }
398 
399  if (_strict)
400  {
401  assert(hit_key);
402  }
403  else if (!hit_key)
404  {
405  ++_errors;
406  if (_verbosity > 0)
407  {
408  std::cout << PHWHERE << " nerr: " << _errors << std::endl;
409  }
410  return nullptr;
411  }
412 
413  if (_do_cache)
414  {
415  std::map<TrkrDefs::hitkey, PHG4Hit*>::iterator iter =
416  _cache_max_truth_hit_by_energy.find(hit_key);
417  if (iter != _cache_max_truth_hit_by_energy.end())
418  {
419  return iter->second;
420  }
421  }
422 
423  std::set<PHG4Hit*> hits = all_truth_hits(hit_key, trkrid);
424  PHG4Hit* max_hit = nullptr;
425  float max_e = FLT_MAX * -1.0;
426  for (auto hit : hits)
427  {
428  if (hit->get_edep() > max_e)
429  {
430  max_e = hit->get_edep();
431  max_hit = hit;
432  }
433  }
434 
435  if (_do_cache)
436  {
437  _cache_max_truth_hit_by_energy.insert(std::make_pair(hit_key, max_hit));
438  }
439 
440  return max_hit;
441 }
442 
443 std::set<PHG4Particle*> SvtxHitEval::all_truth_particles(TrkrDefs::hitkey hit_key)
444 {
445  if (!has_node_pointers())
446  {
447  ++_errors;
448  if (_verbosity > 0)
449  {
450  std::cout << PHWHERE << " nerr: " << _errors << std::endl;
451  }
452  return std::set<PHG4Particle*>();
453  }
454 
455  if (_strict)
456  {
457  assert(hit_key);
458  }
459  else if (!hit_key)
460  {
461  ++_errors;
462  if (_verbosity > 0)
463  {
464  std::cout << PHWHERE << " nerr: " << _errors << std::endl;
465  }
466  return std::set<PHG4Particle*>();
467  }
468 
469  if (_do_cache)
470  {
471  std::map<TrkrDefs::hitkey, std::set<PHG4Particle*> >::iterator iter =
472  _cache_all_truth_particles.find(hit_key);
473  if (iter != _cache_all_truth_particles.end())
474  {
475  return iter->second;
476  }
477  }
478 
479  std::set<PHG4Particle*> truth_particles;
480 
481  std::set<PHG4Hit*> g4hits = all_truth_hits(hit_key);
482 
483  for (auto g4hit : g4hits)
484  {
486 
487  if (_strict)
488  {
489  assert(particle);
490  }
491  else if (!particle)
492  {
493  ++_errors;
494  if (_verbosity > 0)
495  {
496  std::cout << PHWHERE << " nerr: " << _errors << std::endl;
497  }
498  continue;
499  }
500 
501  truth_particles.insert(particle);
502  }
503 
504  if (_do_cache)
505  {
506  _cache_all_truth_particles.insert(std::make_pair(hit_key, truth_particles));
507  }
508 
509  return truth_particles;
510 }
511 
512 std::set<PHG4Particle*> SvtxHitEval::all_truth_particles(TrkrDefs::hitkey hit_key, const TrkrDefs::TrkrId trkrid)
513 {
514  if (!has_node_pointers())
515  {
516  ++_errors;
517  if (_verbosity > 0)
518  {
519  std::cout << PHWHERE << " nerr: " << _errors << std::endl;
520  }
521  return std::set<PHG4Particle*>();
522  }
523 
524  if (_strict)
525  {
526  assert(hit_key);
527  }
528  else if (!hit_key)
529  {
530  ++_errors;
531  if (_verbosity > 0)
532  {
533  std::cout << PHWHERE << " nerr: " << _errors << std::endl;
534  }
535  return std::set<PHG4Particle*>();
536  }
537 
538  if (_do_cache)
539  {
540  std::map<TrkrDefs::hitkey, std::set<PHG4Particle*> >::iterator iter =
541  _cache_all_truth_particles.find(hit_key);
542  if (iter != _cache_all_truth_particles.end())
543  {
544  return iter->second;
545  }
546  }
547 
548  std::set<PHG4Particle*> truth_particles;
549 
550  std::set<PHG4Hit*> g4hits = all_truth_hits(hit_key, trkrid);
551 
552  for (auto g4hit : g4hits)
553  {
555 
556  if (_strict)
557  {
558  assert(particle);
559  }
560  else if (!particle)
561  {
562  ++_errors;
563  if (_verbosity > 0)
564  {
565  std::cout << PHWHERE << " nerr: " << _errors << std::endl;
566  }
567  continue;
568  }
569 
570  truth_particles.insert(particle);
571  }
572 
573  if (_do_cache)
574  {
575  _cache_all_truth_particles.insert(std::make_pair(hit_key, truth_particles));
576  }
577 
578  return truth_particles;
579 }
580 
582 {
583  if (!has_node_pointers())
584  {
585  ++_errors;
586  if (_verbosity > 0)
587  {
588  std::cout << PHWHERE << " nerr: " << _errors << std::endl;
589  }
590  return nullptr;
591  }
592 
593  if (_strict)
594  {
595  assert(hit_key);
596  }
597  else if (!hit_key)
598  {
599  ++_errors;
600  if (_verbosity > 0)
601  {
602  std::cout << PHWHERE << " nerr: " << _errors << std::endl;
603  }
604  return nullptr;
605  }
606 
607  if (_do_cache)
608  {
609  std::map<TrkrDefs::hitkey, PHG4Particle*>::iterator iter =
611  if (iter != _cache_max_truth_particle_by_energy.end())
612  {
613  return iter->second;
614  }
615  }
616 
617  // loop over all particles associated with this hit and
618  // get the energy contribution for each one, record the max
619  PHG4Particle* max_particle = nullptr;
620  float max_e = FLT_MAX * -1.0;
621  std::set<PHG4Particle*> particles = all_truth_particles(hit_key);
622  for (auto particle : particles)
623  {
624  float e = get_energy_contribution(hit_key, particle);
625  if (e > max_e)
626  {
627  max_e = e;
628  max_particle = particle;
629  }
630  }
631 
632  if (_do_cache)
633  {
634  _cache_max_truth_particle_by_energy.insert(std::make_pair(hit_key, max_particle));
635  }
636 
637  return max_particle;
638 }
639 
641 {
642  if (!has_node_pointers())
643  {
644  ++_errors;
645  if (_verbosity > 0)
646  {
647  std::cout << PHWHERE << " nerr: " << _errors << std::endl;
648  }
649  return nullptr;
650  }
651 
652  if (_strict)
653  {
654  assert(hit_key);
655  }
656  else if (!hit_key)
657  {
658  ++_errors;
659  if (_verbosity > 0)
660  {
661  std::cout << PHWHERE << " nerr: " << _errors << std::endl;
662  }
663  return nullptr;
664  }
665 
666  if (_do_cache)
667  {
668  std::map<TrkrDefs::hitkey, PHG4Particle*>::iterator iter =
670  if (iter != _cache_max_truth_particle_by_energy.end())
671  {
672  return iter->second;
673  }
674  }
675 
676  // loop over all particles associated with this hit and
677  // get the energy contribution for each one, record the max
678  PHG4Particle* max_particle = nullptr;
679  float max_e = FLT_MAX * -1.0;
680  std::set<PHG4Particle*> particles = all_truth_particles(hit_key, trkrid);
681  for (auto particle : particles)
682  {
683  float e = get_energy_contribution(hit_key, particle);
684  if (e > max_e)
685  {
686  max_e = e;
687  max_particle = particle;
688  }
689  }
690 
691  if (_do_cache)
692  {
693  _cache_max_truth_particle_by_energy.insert(std::make_pair(hit_key, max_particle));
694  }
695 
696  return max_particle;
697 }
698 
699 std::set<TrkrDefs::hitkey> SvtxHitEval::all_hits_from(PHG4Particle* g4particle)
700 {
701  if (!has_node_pointers())
702  {
703  ++_errors;
704  if (_verbosity > 0)
705  {
706  std::cout << PHWHERE << " nerr: " << _errors << std::endl;
707  }
708  return std::set<TrkrDefs::hitkey>();
709  }
710 
711  if (_strict)
712  {
713  assert(g4particle);
714  }
715  else if (!g4particle)
716  {
717  ++_errors;
718  if (_verbosity > 0)
719  {
720  std::cout << PHWHERE << " nerr: " << _errors << std::endl;
721  }
722  return std::set<TrkrDefs::hitkey>();
723  }
724 
725  if (_do_cache)
726  {
727  std::map<PHG4Particle*, std::set<TrkrDefs::hitkey> >::iterator iter =
728  _cache_all_hits_from_particle.find(g4particle);
729  if (iter != _cache_all_hits_from_particle.end())
730  {
731  return iter->second;
732  }
733  }
734 
735  std::set<TrkrDefs::hitkey> hits;
736 
737  // loop over all the hits
739  for (TrkrHitSetContainer::ConstIterator iter = all_hitsets.first;
740  iter != all_hitsets.second;
741  ++iter)
742  {
743  TrkrHitSet::ConstRange range = iter->second->getHits();
744  for (TrkrHitSet::ConstIterator hitr = range.first; hitr != range.second; ++hitr)
745  {
746  TrkrDefs::hitkey hit_key = hitr->first;
747 
748  // loop over all truth hits connected to this hit
749  std::set<PHG4Hit*> g4hits = all_truth_hits(hit_key);
750  for (auto candidate : g4hits)
751  {
752  PHG4Particle* particle = _truthinfo->GetParticle(candidate->get_trkid());
753  if (g4particle->get_track_id() == particle->get_track_id())
754  {
755  hits.insert(hit_key);
756  }
757  }
758  }
759  }
760 
761  if (_do_cache)
762  {
763  _cache_all_hits_from_particle.insert(std::make_pair(g4particle, hits));
764  }
765 
766  return hits;
767 }
768 
769 std::set<TrkrDefs::hitkey> SvtxHitEval::all_hits_from(PHG4Hit* g4hit)
770 {
771  if (!has_node_pointers())
772  {
773  ++_errors;
774  if (_verbosity > 0)
775  {
776  std::cout << PHWHERE << " nerr: " << _errors << std::endl;
777  }
778  return std::set<TrkrDefs::hitkey>();
779  }
780 
781  if (_strict)
782  {
783  assert(g4hit);
784  }
785  else if (!g4hit)
786  {
787  ++_errors;
788  if (_verbosity > 0)
789  {
790  std::cout << PHWHERE << " nerr: " << _errors << std::endl;
791  }
792  return std::set<TrkrDefs::hitkey>();
793  }
794 
795  if (_do_cache)
796  {
797  std::map<PHG4Hit*, std::set<TrkrDefs::hitkey> >::iterator iter =
798  _cache_all_hits_from_g4hit.find(g4hit);
799  if (iter != _cache_all_hits_from_g4hit.end())
800  {
801  return iter->second;
802  }
803  }
804 
805  std::set<TrkrDefs::hitkey> hits;
806 
807  unsigned int hit_layer = g4hit->get_layer();
808 
809  // loop over all the hits
811  for (TrkrHitSetContainer::ConstIterator iter = all_hitsets.first;
812  iter != all_hitsets.second;
813  ++iter)
814  {
815  TrkrHitSet::ConstRange range = iter->second->getHits();
816  for (TrkrHitSet::ConstIterator hitr = range.first; hitr != range.second; ++hitr)
817  {
818  TrkrDefs::hitkey hit_key = hitr->first;
819 
820  if (TrkrDefs::getLayer(hit_key) != hit_layer)
821  {
822  continue;
823  }
824 
825  // loop over all truth hits connected to this hit
826  std::set<PHG4Hit*> g4hits = all_truth_hits(hit_key);
827  for (auto candidate : g4hits)
828  {
829  if (candidate->get_hit_id() == g4hit->get_hit_id())
830  {
831  hits.insert(hit_key);
832  }
833  }
834  }
835  }
836 
837  if (_do_cache)
838  {
839  _cache_all_hits_from_g4hit.insert(std::make_pair(g4hit, hits));
840  }
841 
842  return hits;
843 }
844 
846 {
847  if (!has_node_pointers())
848  {
849  ++_errors;
850  if (_verbosity > 0)
851  {
852  std::cout << PHWHERE << " nerr: " << _errors << std::endl;
853  }
854  return 0;
855  }
856 
857  if (_strict)
858  {
859  assert(g4hit);
860  }
861  else if (!g4hit)
862  {
863  ++_errors;
864  if (_verbosity > 0)
865  {
866  std::cout << PHWHERE << " nerr: " << _errors << std::endl;
867  }
868  return 0;
869  }
870 
871  if (_do_cache)
872  {
873  std::map<PHG4Hit*, TrkrDefs::hitkey>::iterator iter =
874  _cache_best_hit_from_g4hit.find(g4hit);
875  if (iter != _cache_best_hit_from_g4hit.end())
876  {
877  return iter->second;
878  }
879  }
880 
881  TrkrDefs::hitkey best_hit = 0;
882  float best_energy = 0.0;
883  std::set<TrkrDefs::hitkey> hits = all_hits_from(g4hit);
884  for (unsigned int hit_key : hits)
885  {
886  float energy = get_energy_contribution(hit_key, g4hit);
887  if (energy > best_energy)
888  {
889  best_hit = hit_key;
890  best_energy = energy;
891  }
892  }
893 
894  if (_do_cache)
895  {
896  _cache_best_hit_from_g4hit.insert(std::make_pair(g4hit, best_hit));
897  }
898 
899  return best_hit;
900 }
901 
902 // overlap calculations
904 {
905  if (!has_node_pointers())
906  {
907  ++_errors;
908  if (_verbosity > 0)
909  {
910  std::cout << PHWHERE << " nerr: " << _errors << std::endl;
911  }
912  return NAN;
913  }
914 
915  if (_strict)
916  {
917  assert(hit_key);
918  assert(particle);
919  }
920  else if (!hit_key || !particle)
921  {
922  ++_errors;
923  if (_verbosity > 0)
924  {
925  std::cout << PHWHERE << " nerr: " << _errors << std::endl;
926  }
927  return NAN;
928  }
929 
930  if (_do_cache)
931  {
932  std::map<std::pair<TrkrDefs::hitkey, PHG4Particle*>, float>::iterator iter =
933  _cache_get_energy_contribution_g4particle.find(std::make_pair(hit_key, particle));
935  {
936  return iter->second;
937  }
938  }
939 
940  float energy = 0.0;
941  std::set<PHG4Hit*> g4hits = all_truth_hits(hit_key);
942  for (auto g4hit : g4hits)
943  {
944  if (get_truth_eval()->is_g4hit_from_particle(g4hit, particle))
945  {
946  energy += g4hit->get_edep();
947  }
948  }
949 
950  if (_do_cache)
951  {
952  _cache_get_energy_contribution_g4particle.insert(std::make_pair(std::make_pair(hit_key, particle), energy));
953  }
954 
955  return energy;
956 }
957 
959 {
960  if (!has_node_pointers())
961  {
962  ++_errors;
963  if (_verbosity > 0)
964  {
965  std::cout << PHWHERE << " nerr: " << _errors << std::endl;
966  }
967  return NAN;
968  }
969 
970  if (_strict)
971  {
972  assert(hit_key);
973  assert(g4hit);
974  }
975  else if (!hit_key || !g4hit)
976  {
977  ++_errors;
978  if (_verbosity > 0)
979  {
980  std::cout << PHWHERE << " nerr: " << _errors << std::endl;
981  }
982  return NAN;
983  }
984 
985  if (_do_cache)
986  {
987  std::map<std::pair<TrkrDefs::hitkey, PHG4Hit*>, float>::iterator iter =
988  _cache_get_energy_contribution_g4hit.find(std::make_pair(hit_key, g4hit));
989  if (iter != _cache_get_energy_contribution_g4hit.end())
990  {
991  return iter->second;
992  }
993  }
994 
995  // this is a fairly simple existance check right now, but might be more
996  // complex in the future, so this is here mostly as future-proofing.
997 
998  float energy = 0.0;
999  std::set<PHG4Hit*> g4hits = all_truth_hits(hit_key);
1000  for (auto candidate : g4hits)
1001  {
1002  if (candidate->get_hit_id() != g4hit->get_hit_id())
1003  {
1004  continue;
1005  }
1006  energy += candidate->get_edep();
1007  }
1008 
1009  if (_do_cache)
1010  {
1011  _cache_get_energy_contribution_g4hit.insert(std::make_pair(std::make_pair(hit_key, g4hit), energy));
1012  }
1013 
1014  return energy;
1015 }
1016 
1018 {
1019  // need things off of the DST...
1020  _hitmap = findNode::getClass<TrkrHitSetContainer>(topNode, "TRKR_HITSET");
1021 
1022  _clustermap = findNode::getClass<TrkrClusterContainer>(topNode, "CORRECTED_TRKR_CLUSTER");
1023  if (!_clustermap)
1024  {
1025  _clustermap = findNode::getClass<TrkrClusterContainer>(topNode, "TRKR_CLUSTER");
1026  }
1027 
1028  _hit_truth_map = findNode::getClass<TrkrHitTruthAssoc>(topNode, "TRKR_HITTRUTHASSOC");
1029 
1030  // need things off of the DST...
1031  _g4hits_tpc = findNode::getClass<PHG4HitContainer>(topNode, "G4HIT_TPC");
1032  _g4hits_intt = findNode::getClass<PHG4HitContainer>(topNode, "G4HIT_INTT");
1033  _g4hits_mvtx = findNode::getClass<PHG4HitContainer>(topNode, "G4HIT_MVTX");
1034  _g4hits_mms = findNode::getClass<PHG4HitContainer>(topNode, "G4HIT_MICROMEGAS");
1035 
1036  _truthinfo = findNode::getClass<PHG4TruthInfoContainer>(topNode, "G4TruthInfo");
1037 
1038  return;
1039 }
1040 
1042 {
1043  if (_strict)
1044  {
1045  assert(_hitmap);
1046  }
1047  else if (!_hitmap)
1048  {
1049  return false;
1050  }
1051 
1052  if (_strict)
1053  {
1055  }
1056  else if (!_g4hits_mms && !_g4hits_tpc && !_g4hits_intt && !_g4hits_mvtx)
1057  {
1058  std::cout << "no hits" << std::endl;
1059  return false;
1060  }
1061  if (_strict)
1062  {
1063  assert(_truthinfo);
1064  }
1065  else if (!_truthinfo)
1066  {
1067  std::cout << " no truth" << std::endl;
1068  return false;
1069  }
1070 
1071  return true;
1072 }