Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MvtxHitPruner.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file MvtxHitPruner.cc
1 
7 #include "MvtxHitPruner.h"
8 #include "CylinderGeom_Mvtx.h"
9 
12 
16 #include <trackbase/TrkrDefs.h> // for hitkey, getLayer
17 #include <trackbase/MvtxDefs.h>
18 #include <trackbase/TrkrHitv2.h>
19 #include <trackbase/TrkrHitSet.h>
22 
24 #include <fun4all/SubsysReco.h> // for SubsysReco
25 
26 #include <phool/PHCompositeNode.h>
27 #include <phool/PHIODataNode.h>
28 #include <phool/PHNode.h> // for PHNode
29 #include <phool/PHNodeIterator.h>
30 #include <phool/PHObject.h> // for PHObject
31 #include <phool/getClass.h>
32 #include <phool/phool.h> // for PHWHERE
33 
34 #include <TMatrixFfwd.h> // for TMatrixF
35 #include <TMatrixT.h> // for TMatrixT, operator*
36 #include <TMatrixTUtils.h> // for TMatrixTRow
37 #include <TVector3.h>
38 
39 #pragma GCC diagnostic push
40 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
41 #include <boost/graph/adjacency_list.hpp>
42 #pragma GCC diagnostic pop
43 
44 #include <boost/graph/connected_components.hpp>
45 
46 #include <array>
47 #include <cmath>
48 #include <cstdlib> // for exit
49 #include <iostream>
50 #include <map> // for multimap<>::iterator
51 #include <set> // for set, set<>::iterator
52 #include <string>
53 #include <vector> // for vector
54 
55 using namespace boost;
56 using namespace std;
57 
59  : SubsysReco(name)
60  , m_hits(nullptr)
61 {
62 }
63 
65 {
66  //-----------------
67  // Add Cluster Node
68  //-----------------
69 
70  //----------------
71  // Report Settings
72  //----------------
73 
74  if (Verbosity() > 0)
75  {
76  cout << "====================== MvtxHitPruner::InitRun() =====================" << endl;
77  }
78 
80 }
81 
83 {
84  // get node containing the digitized hits
85  m_hits = findNode::getClass<TrkrHitSetContainer>(topNode, "TRKR_HITSET");
86  if (!m_hits)
87  {
88  cout << PHWHERE << "ERROR: Can't find node TRKR_HITSET" << endl;
90  }
91 
92  // We want to combine all strobe values for a given hitset
93  // Start by looping over all MVTX hitsets and making a map of physical sensor to hitsetkey-with-strobe
94  //=============================================================================
95  std::multimap<TrkrDefs::hitsetkey, TrkrDefs::hitsetkey> hitset_multimap; // will map (bare hitset, hitset with strobe)
96  std::set<TrkrDefs::hitsetkey> bare_hitset_set; // list of all physical sensor hitsetkeys (i.e. with strobe set to zero)
97 
100  for (TrkrHitSetContainer::ConstIterator hitsetitr = hitsetrange.first;
101  hitsetitr != hitsetrange.second;
102  ++hitsetitr)
103  {
104  auto hitsetkey = hitsetitr->first;
105 
106  // get the hitsetkey value for strobe 0
107  unsigned int layer = TrkrDefs::getLayer(hitsetitr->first);
108  unsigned int stave = MvtxDefs::getStaveId(hitsetitr->first);
109  unsigned int chip = MvtxDefs::getChipId(hitsetitr->first);
110  auto bare_hitsetkey = MvtxDefs::genHitSetKey(layer, stave, chip, 0);
111 
112  hitset_multimap.insert(std::make_pair(bare_hitsetkey, hitsetkey));
113  bare_hitset_set.insert(bare_hitsetkey);
114 
115  if(Verbosity() > 0) cout << " found hitsetkey " << hitsetkey << " for bare_hitsetkey " << bare_hitsetkey << endl;
116  }
117 
118  // Now consolidate all hits into the hitset with strobe 0, and delete the other hitsets
119  //==============================================================
120  for(auto bare_it = bare_hitset_set.begin(); bare_it != bare_hitset_set.end(); ++bare_it)
121  {
122  auto bare_hitsetkey = *bare_it;
123  TrkrHitSet* bare_hitset = (m_hits->findOrAddHitSet(bare_hitsetkey))->second;
124  if(Verbosity() > 0) std::cout << " bare_hitset " << bare_hitsetkey << " initially has " << bare_hitset->size() << " hits " << std::endl;
125 
126  auto bare_hitsetrange= hitset_multimap.equal_range(bare_hitsetkey);
127  for(auto it = bare_hitsetrange.first; it != bare_hitsetrange.second; ++ it)
128  {
129  auto hitsetkey = it->second;
130 
131  int strobe = MvtxDefs::getStrobeId(hitsetkey);
132  if(strobe != 0)
133  {
134  if(Verbosity() > 0) cout << " process hitsetkey " << hitsetkey << " for bare_hitsetkey " << bare_hitsetkey << endl;
135 
136  // copy all hits to the hitset with strobe 0
137  TrkrHitSet* hitset = m_hits->findHitSet(hitsetkey);
138 
139  if(Verbosity() > 0)
140  std::cout << " hitsetkey " << hitsetkey << " has strobe " << strobe << " and has " << hitset->size() << " hits, so copy it" << std::endl;
141 
142  TrkrHitSet::ConstRange hitrangei = hitset->getHits();
143  for (TrkrHitSet::ConstIterator hitr = hitrangei.first;
144  hitr != hitrangei.second;
145  ++hitr)
146  {
147  auto hitkey = hitr->first;
148  if(Verbosity() > 0) std::cout << " found hitkey " << hitkey << std::endl;
149  // if it is already there, leave it alone, this is a duplicate hit
150  auto tmp_hit = bare_hitset->getHit(hitkey);
151  if(tmp_hit)
152  {
153  if(Verbosity() > 0) std::cout << " hitkey " << hitkey << " is already in bare hitsest, do not copy" << std::endl;
154  continue;
155  }
156 
157  // otherwise copy the hit over
158  if(Verbosity() > 0) std::cout << " copying over hitkey " << hitkey << std::endl;
159  auto old_hit = hitr->second;
160  TrkrHit *new_hit = new TrkrHitv2();
161  new_hit->setAdc(old_hit->getAdc());
162  bare_hitset->addHitSpecificKey(hitkey, new_hit);
163  }
164 
165  // all hits are copied over to the strobe zero hitset, remove this hitset
167  }
168  }
169  }
170 
172 }
173