EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RawDigitBuilderTTL.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file RawDigitBuilderTTL.cc
1 #include "RawDigitBuilderTTL.h"
2 
3 
4 
7 #include <trackbase/TrkrDefs.h> // for hitkey, getLayer
8 #include <trackbase/TrkrHitv2.h>
9 #include <trackbase/TrkrHitSet.h>
12 // #include <calobase/RawTowerContainer.h>
13 // #include <calobase/RawTowerv1.h>
14 // #include <calobase/RawTowerv2.h>
15 
16 // #include <calobase/RawTower.h> // for RawTower
17 // #include <calobase/RawTowerDefs.h> // for convert_name_to_caloid
18 // #include <calobase/RawTowerGeom.h> // for RawTowerGeom
19 // #include <calobase/RawTowerGeomContainer.h> // for RawTowerGeomContainer
20 // #include <calobase/RawTowerGeomContainerv1.h>
21 // #include <calobase/RawTowerGeomv3.h>
22 
23 
25 #include <fun4all/SubsysReco.h> // for SubsysReco
26 
27 #include <phool/PHCompositeNode.h>
28 #include <phool/PHIODataNode.h>
29 #include <phool/PHNode.h> // for PHNode
30 #include <phool/PHNodeIterator.h>
31 #include <phool/PHObject.h> // for PHObject
32 #include <phool/getClass.h>
33 #include <phool/phool.h> // for PHWHERE
34 
35 #include <TRotation.h>
36 #include <TVector3.h>
37 
38 
39 #include <cstdlib> // for exit
40 #include <exception> // for exception
41 #include <fstream>
42 #include <iostream>
43 #include <map>
44 #include <sstream>
45 #include <stdexcept>
46 #include <utility> // for pair, make_pair
47 
48 using namespace std;
49 
51  : SubsysReco(name)
52  // , m_Towers(nullptr)
53  // , m_Geoms(nullptr)
54  // , m_hits(nullptr)
55  , m_clusterlist(nullptr)
56  // , m_clusterhitassoc(nullptr)
57  , m_Detector("NONE")
58  , m_Emin(1e-6)
59 {
60 }
61 
63 {
64  PHNodeIterator iter(topNode);
65 
66  // Looking for the DST node
67  PHCompositeNode *dstNode;
68  dstNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "DST"));
69  if (!dstNode)
70  {
71  std::cout << PHWHERE << "DST Node missing, doing nothing." << std::endl;
72  exit(1);
73  }
74 
75  try
76  {
77  CreateNodes(topNode);
78  }
79  catch (std::exception &e)
80  {
81  std::cout << e.what() << std::endl;
82  //exit(1);
83  }
84 
85 
86  std::cout << "adding TRKR_CLUSTER nodes" << std::endl;
87  // Create the Cluster node if required
88  auto trkrclusters = findNode::getClass<TrkrClusterContainer>(dstNode, "TRKR_CLUSTER");
89  if (!trkrclusters)
90  {
91  PHNodeIterator dstiter(dstNode);
92  PHCompositeNode *DetNode = dynamic_cast<PHCompositeNode *>(dstiter.findFirst("PHCompositeNode", "TRKR"));
93  if (!DetNode)
94  {
95  DetNode = new PHCompositeNode("TRKR");
96  dstNode->addNode(DetNode);
97  }
98 
99  trkrclusters = new TrkrClusterContainerv3;
100  PHIODataNode<PHObject> *TrkrClusterContainerNode =
101  new PHIODataNode<PHObject>(trkrclusters, "TRKR_CLUSTER", "PHObject");
102  DetNode->addNode(TrkrClusterContainerNode);
103  }
104 
106 }
107 
109 {
110  // get hits
111  string NodeNameHits = "G4HIT_" + m_Detector;
112  PHG4HitContainer *g4hit = findNode::getClass<PHG4HitContainer>(topNode, NodeNameHits);
113  if (!g4hit)
114  {
115  cout << "Could not locate g4 hit node " << NodeNameHits << endl;
116  exit(1);
117  }
118 
119  // get node for clusters
120  m_clusterlist = findNode::getClass<TrkrClusterContainer>(topNode, "TRKR_CLUSTER");
121  if (!m_clusterlist)
122  {
123  cout << PHWHERE << " ERROR: Can't find TRKR_CLUSTER." << endl;
125  }
126 
127  // loop over all hits in the event
129  PHG4HitContainer::ConstRange hit_begin_end = g4hit->getHits();
130  int clusid =0;
131  for (hiter = hit_begin_end.first; hiter != hit_begin_end.second; hiter++)
132  {
133  PHG4Hit *g4hit_i = hiter->second;
134 
135  // Don't include hits with zero energy
136  if (g4hit_i->get_edep() <= 0 && g4hit_i->get_edep() != -1) continue;
137 
138  auto clus = std::make_unique<TrkrClusterv2>();
139 
141  TrkrDefs::hitsetkey tmps = g4hit_i->get_strip_z_index();
142  ckey |= (tmps << 8);
143  tmps = g4hit_i->get_strip_y_index();
144  ckey |= (tmps << 0);
145 
146  TrkrDefs::cluskey tmp = ckey;
147  TrkrDefs::cluskey key = (tmp << TrkrDefs::kBitShiftClusId);
148  key |= clusid;
149  clus->setClusKey(key);
150 
151  // G4double clusx,clusy,clusz;
152  // GetPixelGlobalCoordinates(g4hit_i,clusx,clusy,clusz);
153  clus->setPosition(0, g4hit_i->get_local_x(0));
154  clus->setPosition(1, g4hit_i->get_local_y(0));
155  clus->setPosition(2, g4hit_i->get_local_z(0));
156  clus->setGlobal();
157 
158  m_clusterlist->addCluster(clus.release());
159 
160  clusid++;
161  }
162 
164 }
165 
166 
167 void RawDigitBuilderTTL::Detector(const std::string &d)
168 {
169  m_Detector = d;
170  // m_CaloId = RawTowerDefs::convert_name_to_caloid(m_Detector);
171 }
172 
174 {
175  PHNodeIterator iter(topNode);
176  PHCompositeNode *runNode = static_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "RUN"));
177  if (!runNode)
178  {
179  std::cerr << PHWHERE << "Run Node missing, doing nothing." << std::endl;
180  throw std::runtime_error("Failed to find Run node in RawDigitBuilderTTL::CreateNodes");
181  }
182 
183  PHCompositeNode *dstNode = static_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "DST"));
184  if (!dstNode)
185  {
186  std::cerr << PHWHERE << "DST Node missing, doing nothing." << std::endl;
187  throw std::runtime_error("Failed to find DST node in RawDigitBuilderTTL::CreateNodes");
188  }
189 
190  // Find detector node (or create new one if not found)
191  PHNodeIterator dstiter(dstNode);
192  PHCompositeNode *DetNode = dynamic_cast<PHCompositeNode *>(dstiter.findFirst(
193  "PHCompositeNode", m_Detector));
194  if (!DetNode)
195  {
196  DetNode = new PHCompositeNode(m_Detector);
197  dstNode->addNode(DetNode);
198  }
199  return;
200 }
201 
202 
204 {
205  if (Verbosity() >= 1)
206  {
207  TrkrClusterContainer *clusterlist = findNode::getClass<TrkrClusterContainer>(topNode, "TRKR_CLUSTER");
208  if (!clusterlist) return;
209 
210  cout << "================= Aftyer MvtxClusterizer::process_event() ====================" << endl;
211 
212  cout << " There are " << clusterlist->size() << " clusters recorded: " << endl;
213 
214  clusterlist->identify();
215 
216  cout << "===========================================================================" << endl;
217  }
218 
219  return;
220 }