Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GenericUnpackPRDF.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file GenericUnpackPRDF.cc
1 #include "GenericUnpackPRDF.h"
2 
3 #include "PROTOTYPE3_FEM.h"
4 #include "RawTower_Prototype3.h"
5 
6 #include <calobase/RawTower.h> // for RawTower
7 #include <calobase/RawTowerContainer.h>
8 #include <calobase/RawTowerDefs.h> // for NONE
9 
10 #include <fun4all/Fun4AllBase.h> // for Fun4AllBase::VERBOSITY_SOME
12 #include <fun4all/SubsysReco.h> // for SubsysReco
13 
14 #include <phool/PHCompositeNode.h>
15 #include <phool/PHIODataNode.h> // for PHIODataNode
16 #include <phool/PHNodeIterator.h> // for PHNodeIterator
17 #include <phool/PHObject.h> // for PHObject
18 #include <phool/getClass.h>
19 
20 #include <Event/Event.h>
21 #include <Event/packet.h> // for Packet
22 
23 #include <cassert>
24 #include <cmath> // for NAN
25 #include <cstdlib> // for exit
26 #include <iostream>
27 #include <string>
28 
29 using namespace std;
30 
31 //____________________________________
33  : SubsysReco("GenericUnpackPRDF_" + detector)
34  , //
35  _detector(detector)
36  , _towers(nullptr)
37 {
38 }
39 
40 //_____________________________________
42 {
43  CreateNodeTree(topNode);
45 }
46 
47 //____________________________________
49 {
50  Event *_event = findNode::getClass<Event>(topNode, "PRDF");
51  if (!_event)
52  {
53  if (Verbosity() >= VERBOSITY_SOME)
54  cout << "GenericUnpackPRDF::Process_Event - Event not found" << endl;
56  }
57 
58  if (Verbosity() >= VERBOSITY_SOME)
59  _event->identify();
60 
61  map<int, Packet *> packet_list;
62 
63  for (hbd_channel_map::const_iterator it = _hbd_channel_map.begin();
64  it != _hbd_channel_map.end(); ++it)
65  {
66  const int packet_id = it->first.first;
67  const int channel = it->first.second;
68  const int tower_id = it->second;
69 
70  if (packet_list.find(packet_id) == packet_list.end())
71  {
72  packet_list[packet_id] = _event->getPacket(packet_id);
73  }
74 
75  Packet *packet = packet_list[packet_id];
76 
77  if (!packet)
78  {
79  // if (Verbosity() >= VERBOSITY_SOME)
80  cout << "GenericUnpackPRDF::process_event - failed to locate packet "
81  << packet_id << endl;
82  continue;
83  }
84  assert(packet);
85 
86 // packet->setNumSamples(PROTOTYPE3_FEM::NSAMPLES);
88 
90  dynamic_cast<RawTower_Prototype3 *>(_towers->getTower(tower_id));
91  if (!tower)
92  {
93  tower = new RawTower_Prototype3();
94  tower->set_energy(NAN);
95  _towers->AddTower(tower_id, tower);
96  }
97  tower->set_HBD_channel_number(channel);
98  for (int isamp = 0; isamp < PROTOTYPE3_FEM::NSAMPLES; isamp++)
99  {
100  tower->set_signal_samples(isamp, packet->iValue(channel, isamp));
101  }
102  }
103 
104  for (map<int, Packet *>::iterator it = packet_list.begin();
105  it != packet_list.end(); ++it)
106  {
107  if (it->second)
108  delete it->second;
109  }
110 
112 }
113 
114 //_______________________________________
116 {
117  PHNodeIterator nodeItr(topNode);
118  // DST node
119  PHCompositeNode *dst_node = static_cast<PHCompositeNode *>(
120  nodeItr.findFirst("PHCompositeNode", "DST"));
121  if (!dst_node)
122  {
123  cout << "PHComposite node created: DST" << endl;
124  dst_node = new PHCompositeNode("DST");
125  topNode->addNode(dst_node);
126  }
127 
128  // DATA nodes
129  PHCompositeNode *data_node = static_cast<PHCompositeNode *>(
130  nodeItr.findFirst("PHCompositeNode", "RAW_DATA"));
131  if (!data_node)
132  {
133  if (Verbosity())
134  cout << "PHComposite node created: RAW_DATA" << endl;
135  data_node = new PHCompositeNode("RAW_DATA");
136  dst_node->addNode(data_node);
137  }
138 
139  // output as towers
141  PHIODataNode<PHObject> *towerNode =
142  new PHIODataNode<PHObject>(_towers, "TOWER_RAW_" + _detector, "PHObject");
143  data_node->addNode(towerNode);
144 }
145 
146 void GenericUnpackPRDF::add_channel(const int packet_id,
147  const int channel,
148  const int tower_id
149 )
150 {
151  hbd_channel_typ hbd_channel(packet_id, channel);
152 
153  if (_hbd_channel_map.find(hbd_channel) != _hbd_channel_map.end())
154  {
155  cout << "GenericUnpackPRDF::add_channel - packet " << packet_id
156  << ", channel " << channel << " is already registered as tower "
157  << _hbd_channel_map.find(hbd_channel)->second << endl;
158  exit(12);
159  }
160  _hbd_channel_map[hbd_channel] = tower_id;
161 }