Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MvtxUnpackPRDF.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file MvtxUnpackPRDF.C
1 #include "MvtxUnpackPRDF.h"
2 
3 #include <Event/Event.h>
4 #include <Event/EventTypes.h>
5 #include <Event/packetConstants.h>
6 #include <Event/packet.h>
7 #include <Event/packet_hbd_fpgashort.h>
9 #include <phool/phool.h>
10 #include <phool/getClass.h>
12 #include <pdbcalbase/PdbParameterMap.h>
13 #include <phparameter/PHParameters.h>
14 
15 #include <trackbase/TrkrDefUtil.h>
17 #include <trackbase/TrkrHitSet.h>
18 #include <trackbase/TrkrHitSetv1.h>
19 #include <mvtx/MvtxDefUtil.h>
20 #include <mvtx/MvtxHitSetv1.h>
21 
22 #include <iostream>
23 #include <string>
24 #include <cassert>
25 
26 using namespace std;
27 
28 //____________________________________
30  SubsysReco("MvtxUnpackPRDF"),
31  /*PHCompositeNode **/ dstNode(NULL),
32  /*Event**/_event(NULL),
33  /*Packet_hbd_fpgashort**/_packet(NULL),
34  /*int*/_nevents(0),
35  /*int*/_verbosity(0),
36  /*bool*/_first(true)
37 {
38  for (int ichip=0; ichip<NCHIP; ichip++){
39  _nevent_per_chip[ichip] = 0;
40  _npixel_per_chip[ichip] = 0;
41  }
42 }
43 
44 //____________________________________
45 int
47 {
48 
49  cout << "-----MvtxUnpackPRDF::Init-----" << endl;
51 }
52 
53 //_____________________________________
54 int
56 {
57 
58  CreateNodeTree(topNode);
59 
60  cout << "-----MvtxUnpackPRDF::Init-----" << endl;
62 }
63 
64 //____________________________________
65 int
67 {
68  _nevents++;
69  _event = findNode::getClass<Event>(topNode, "PRDF");
70  if (_event==0)
71  {
72  cout << "MvtxUnpackPRDF::Process_Event - Event not found" << endl;
73  return -1;
74  }
75  if (_event->getEvtType()!=1)
76  {
77  cout << "MvtxUnpackPRDF::Process_Event - non-data event type " << _event->getEvtType() << endl;
78  return -1;
79  }
80 
81  _hitsetcon = findNode::getClass<TrkrHitSetContainer>(topNode, "TrkrHitSetContainer");
82  if (_hitsetcon==0)
83  {
84  cout << "MvtxUnpackPRDF::Process_Event - TrkrHitSetContainer not found" << endl;
85  return -1;
86  }
87  else{
88 
89  MvtxDefUtil *mvtxdef = new MvtxDefUtil();
90 
91  for (int ichip=0; ichip<NCHIP; ichip++){
92  MvtxHitSetv1 *hitset = new MvtxHitSetv1();
93  hitset->SetHitSetKey(mvtxdef->GenHitSetKey(char(ichip),uint8_t(0),uint8_t(ichip)));
94  _hitsetcon->AddHitSetSpecifyKey(hitset->GetHitSetKey(),hitset);
95  if ( _verbosity>10 )
96  {
97  cout << "-----MvtxUnpackPRDF::CreateNodeTree, Create hitset " << hitset->GetHitSetKey() << endl;
98  }
99  }
100 
101  if ( _verbosity>10 )
102  {
103  cout << "-----MvtxUnpackPRDF::process_event Create HitSet" << endl;
104  _hitsetcon->identify();
105  }
106  delete mvtxdef;
107  }
108 
109  if ( _verbosity>90 )
110  {
111  cout << "EVENT: " << _nevents << endl;
112  }
113 
114  MakeHits();
115 
117 }
118 
119 //_______________________________________
120 void
122 {
123 
124  PHNodeIterator nodeItr(topNode);
125  //DST node
126  dstNode = static_cast<PHCompositeNode *>(nodeItr.findFirst("PHCompositeNode",
127  "DST"));
128  if (!dstNode)
129  {
130  cout << "PHComposite node created: DST" << endl;
131  dstNode = new PHCompositeNode("DST");
132  topNode->addNode(dstNode);
133  }
134 
135  PHCompositeNode* trkrNode
136  = dynamic_cast<PHCompositeNode*>(nodeItr.findFirst("PHCompositeNode","TRKR"));
137  if (!trkrNode) {
138  trkrNode = new PHCompositeNode("TRKR");
139  dstNode->addNode(trkrNode);
140  }
141 
142  TrkrHitSetContainer *hitsetcon = findNode::getClass<TrkrHitSetContainer>(dstNode,"TrkrHitSetContainer");
143  if (!hitsetcon) {
144  hitsetcon = new TrkrHitSetContainer();
145  PHIODataNode<PHObject> *hitsetconNode =
146  new PHIODataNode<PHObject>(hitsetcon,"TrkrHitSetContainer","PHObject");
147  trkrNode->addNode(hitsetconNode);
148  }//
149 
150  //DATA nodes
151  /*
152  data_node = static_cast<PHCompositeNode *>(nodeItr.findFirst("PHCompositeNode",
153  "RAW_DATA"));
154  if (!data_node)
155  {
156  cout << "PHComposite node created: RAW_DATA" << endl;
157  data_node = new PHCompositeNode("RAW_DATA");
158  dst_node->addNode(data_node);
159  }
160  */
161 
162 }
163 
164 //_______________________________________
165 void
167 {
168 
169  int nhits_for_this = 0;
170 
171  Packet *p = _event->getPacket(2000);
172  if (p)
173  {
174 
175 
176  int chipmax = p->iValue(0, "HIGHEST_CHIP") + 1;
177  if ( _verbosity>100 )
178  {
179  cout << "CHIPMAX: " << chipmax << endl;
180  }
181 
182  if ( chipmax>NCHIP )
183  {
184  cout << "WARNING!! Event: " << _nevents << " More chips than expected!"
185  << " NCHIP:" << NCHIP << " HIGHEST_CHIP:" << chipmax << endl;
186 
187  chipmax = NCHIP;
188  }
189 
190  int excess_data_bytes = p->iValue(0, "EXCESS_DATA_BYTES");
191  if ( excess_data_bytes>0 )
192  {
193  cout << "WARNING!! Event: " << _nevents << " Data found past chip trailer"
194  << " EXCESS_DATA_BYTES: " << excess_data_bytes << endl;
195  }
196 
197  //float mrow_chip0 = -1;
198  //float mcol_chip0 = -1;
199 
200  for (int ichip=0; ichip<NCHIP; ichip++)
201  {
202  int header_found = p->iValue(ichip, "HEADER_FOUND");
203  int trailer_found = p->iValue(ichip, "TRAILER_FOUND");
204  int bunchcounter = p->iValue(ichip, "BUNCHCOUNTER");
205  //int unexpected_bytes = p->iValue(ichip, "UNEXPECTED_BYTES");
206  //int readout_flags = p->iValue(ichip, "READOUT_FLAGS");
207 
208  if ( header_found==0 || trailer_found==0 )
209  {
210  if ( _verbosity>100 )
211  {
212  cout << "WARNING!! Event: " << _nevents << " Missing chip " << ichip << " HEADER_FOUND: " << header_found << " TRAILER_FOUND: " << trailer_found << " BUNCHCOUNTER: " << bunchcounter << endl;
213  }
214  //continue;
215  }
216  }//ichip
217 
218  MvtxDefUtil *mvtxdef = new MvtxDefUtil();
219 
220  for (int ichip=0; ichip<chipmax; ichip++)
221  {
222 
223  int header_found = p->iValue(ichip, "HEADER_FOUND");
224  int trailer_found = p->iValue(ichip, "TRAILER_FOUND");
225  if (header_found==0 || trailer_found==0) continue;
226  TrkrDefs::hitsetkey mvtx_hitsetkey = mvtxdef->GenHitSetKey(char(ichip),uint8_t(0),uint8_t(ichip));
227 
228  for (int irow=0; irow<NROW; irow++)
229  {
230  int regions = p->iValue(ichip, irow);
231  if ( regions==0 ) continue;
232 
233  if ( _verbosity>100 )
234  cout << "ICHIP: " << ichip << ",IROW: " << irow << ", REGIONS: " << regions << endl;
235 
236  for (int iregion=0; iregion<NREGION; iregion++)
237  {
238  if ( (regions>>iregion)&1 )
239  {
240  if ( _verbosity>100 )
241  cout << "REGIONS: " << regions << ", I: " << iregion << endl;
242 
243  int bits = p->iValue(ichip, iregion, irow);
244  if ( bits==0 ) continue;
245 
246  for (int icol=0; icol<NCOL_PER_REGION; icol++)
247  {
248  if ( (bits>>icol)&1 )
249  {
250  _npixel_per_chip[ichip]++;
251  int row = irow;
252  int col = iregion*NCOL_PER_REGION + icol;
253 
254  MvtxHitSetv1 *hitset = static_cast<MvtxHitSetv1 *>(_hitsetcon->FindOrAddHitSet(mvtx_hitsetkey)->second);
255  if ( hitset )
256  {
257  //cout << "ADD HIT, COL: " << col << ", ROW: " << row << endl;
258  hitset->AddHit(uint16_t(col),uint16_t(row));
259  nhits_for_this++;
260  }
261  else
262  {
263  cout << "NO HITSET!" << endl;
264  }
265 
266  }
267  }//icol
268 
269  }
270  }//iregion
271  }//irow
272 
273  _nevent_per_chip[ichip]++;
274 
275  }//ichip
276 
277  if ( _verbosity>10 )
278  {
279  cout << "-----MvtxUnpackPRDF::process_event Check HitSetCon" << endl;
280  _hitsetcon->identify();
281 
282  int nhits = 0;
283  for (int ichip=0; ichip<NCHIP; ichip++){
284  TrkrDefs::hitsetkey mvtx_hitsetkey = mvtxdef->GenHitSetKey(char(ichip),uint8_t(0),uint8_t(ichip));
285  MvtxHitSetv1 *hitset = static_cast<MvtxHitSetv1 *>(_hitsetcon->FindHitSet(mvtx_hitsetkey));
286  MvtxHitSetv1::ConstRange itr_range = hitset->GetHits();
287 
288  for (MvtxHitSetv1::ConstIterator itr = itr_range.first; itr != itr_range.second; ++itr){
289  nhits++;
290  }
291  }
292  cout << "N HITS: " << nhits_for_this << ", " << nhits << endl;
293  }
294 
295  delete mvtxdef;
296  delete p;
297  }//p
298 
299 }
300 
301 //___________________________________
302 int
304 {
305  cout << "-----MvtxUnpackPRDF::End-----" << endl;
306  if ( _verbosity>10 )
307  {
308 
309  MvtxDefUtil *mvtxdef = new MvtxDefUtil();
310 
311  cout << "-----MvtxUnpackPRDF::End::PrintSummary-----" << endl;
312  for (int ichip=0; ichip<NCHIP; ichip++){
313 
314  cout << "CHIP, " << ichip << ", "
315  << ", N EVENT: " << _nevent_per_chip[ichip]
316  << ", N HITS: " << _npixel_per_chip[ichip]
317  << endl;
318  }
319 
320  delete mvtxdef;
321  }
322 
324 }
325