File indexing completed on 2025-08-06 08:21:59
0001 #include "MvtxUnpackPRDF.h"
0002
0003 #include <Event/Event.h>
0004 #include <Event/EventTypes.h>
0005 #include <Event/packetConstants.h>
0006 #include <Event/packet.h>
0007 #include <Event/packet_hbd_fpgashort.h>
0008 #include <phool/PHCompositeNode.h>
0009 #include <phool/phool.h>
0010 #include <phool/getClass.h>
0011 #include <fun4all/Fun4AllReturnCodes.h>
0012 #include <pdbcalbase/PdbParameterMap.h>
0013 #include <phparameter/PHParameters.h>
0014
0015 #include <trackbase/TrkrDefUtil.h>
0016 #include <trackbase/TrkrHitSetContainer.h>
0017 #include <trackbase/TrkrHitSet.h>
0018 #include <trackbase/TrkrHitSetv1.h>
0019 #include <mvtx/MvtxDefUtil.h>
0020 #include <mvtx/MvtxHitSetv1.h>
0021
0022 #include <iostream>
0023 #include <string>
0024 #include <cassert>
0025
0026 using namespace std;
0027
0028
0029 MvtxUnpackPRDF::MvtxUnpackPRDF() :
0030 SubsysReco("MvtxUnpackPRDF"),
0031 dstNode(NULL),
0032 _event(NULL),
0033 _packet(NULL),
0034 _nevents(0),
0035 _verbosity(0),
0036 _first(true)
0037 {
0038 for (int ichip=0; ichip<NCHIP; ichip++){
0039 _nevent_per_chip[ichip] = 0;
0040 _npixel_per_chip[ichip] = 0;
0041 }
0042 }
0043
0044
0045 int
0046 MvtxUnpackPRDF::Init(PHCompositeNode *topNode)
0047 {
0048
0049 cout << "-----MvtxUnpackPRDF::Init-----" << endl;
0050 return Fun4AllReturnCodes::EVENT_OK;
0051 }
0052
0053
0054 int
0055 MvtxUnpackPRDF::InitRun(PHCompositeNode *topNode)
0056 {
0057
0058 CreateNodeTree(topNode);
0059
0060 cout << "-----MvtxUnpackPRDF::Init-----" << endl;
0061 return Fun4AllReturnCodes::EVENT_OK;
0062 }
0063
0064
0065 int
0066 MvtxUnpackPRDF::process_event(PHCompositeNode *topNode)
0067 {
0068 _nevents++;
0069 _event = findNode::getClass<Event>(topNode, "PRDF");
0070 if (_event==0)
0071 {
0072 cout << "MvtxUnpackPRDF::Process_Event - Event not found" << endl;
0073 return -1;
0074 }
0075 if (_event->getEvtType()!=1)
0076 {
0077 cout << "MvtxUnpackPRDF::Process_Event - non-data event type " << _event->getEvtType() << endl;
0078 return -1;
0079 }
0080
0081 _hitsetcon = findNode::getClass<TrkrHitSetContainer>(topNode, "TrkrHitSetContainer");
0082 if (_hitsetcon==0)
0083 {
0084 cout << "MvtxUnpackPRDF::Process_Event - TrkrHitSetContainer not found" << endl;
0085 return -1;
0086 }
0087 else{
0088
0089 MvtxDefUtil *mvtxdef = new MvtxDefUtil();
0090
0091 for (int ichip=0; ichip<NCHIP; ichip++){
0092 MvtxHitSetv1 *hitset = new MvtxHitSetv1();
0093 hitset->SetHitSetKey(mvtxdef->GenHitSetKey(char(ichip),uint8_t(0),uint8_t(ichip)));
0094 _hitsetcon->AddHitSetSpecifyKey(hitset->GetHitSetKey(),hitset);
0095 if ( _verbosity>10 )
0096 {
0097 cout << "-----MvtxUnpackPRDF::CreateNodeTree, Create hitset " << hitset->GetHitSetKey() << endl;
0098 }
0099 }
0100
0101 if ( _verbosity>10 )
0102 {
0103 cout << "-----MvtxUnpackPRDF::process_event Create HitSet" << endl;
0104 _hitsetcon->identify();
0105 }
0106 delete mvtxdef;
0107 }
0108
0109 if ( _verbosity>90 )
0110 {
0111 cout << "EVENT: " << _nevents << endl;
0112 }
0113
0114 MakeHits();
0115
0116 return Fun4AllReturnCodes::EVENT_OK;
0117 }
0118
0119
0120 void
0121 MvtxUnpackPRDF::CreateNodeTree(PHCompositeNode *topNode)
0122 {
0123
0124 PHNodeIterator nodeItr(topNode);
0125
0126 dstNode = static_cast<PHCompositeNode *>(nodeItr.findFirst("PHCompositeNode",
0127 "DST"));
0128 if (!dstNode)
0129 {
0130 cout << "PHComposite node created: DST" << endl;
0131 dstNode = new PHCompositeNode("DST");
0132 topNode->addNode(dstNode);
0133 }
0134
0135 PHCompositeNode* trkrNode
0136 = dynamic_cast<PHCompositeNode*>(nodeItr.findFirst("PHCompositeNode","TRKR"));
0137 if (!trkrNode) {
0138 trkrNode = new PHCompositeNode("TRKR");
0139 dstNode->addNode(trkrNode);
0140 }
0141
0142 TrkrHitSetContainer *hitsetcon = findNode::getClass<TrkrHitSetContainer>(dstNode,"TrkrHitSetContainer");
0143 if (!hitsetcon) {
0144 hitsetcon = new TrkrHitSetContainer();
0145 PHIODataNode<PHObject> *hitsetconNode =
0146 new PHIODataNode<PHObject>(hitsetcon,"TrkrHitSetContainer","PHObject");
0147 trkrNode->addNode(hitsetconNode);
0148 }
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162 }
0163
0164
0165 void
0166 MvtxUnpackPRDF::MakeHits()
0167 {
0168
0169 int nhits_for_this = 0;
0170
0171 Packet *p = _event->getPacket(2000);
0172 if (p)
0173 {
0174
0175
0176 int chipmax = p->iValue(0, "HIGHEST_CHIP") + 1;
0177 if ( _verbosity>100 )
0178 {
0179 cout << "CHIPMAX: " << chipmax << endl;
0180 }
0181
0182 if ( chipmax>NCHIP )
0183 {
0184 cout << "WARNING!! Event: " << _nevents << " More chips than expected!"
0185 << " NCHIP:" << NCHIP << " HIGHEST_CHIP:" << chipmax << endl;
0186
0187 chipmax = NCHIP;
0188 }
0189
0190 int excess_data_bytes = p->iValue(0, "EXCESS_DATA_BYTES");
0191 if ( excess_data_bytes>0 )
0192 {
0193 cout << "WARNING!! Event: " << _nevents << " Data found past chip trailer"
0194 << " EXCESS_DATA_BYTES: " << excess_data_bytes << endl;
0195 }
0196
0197
0198
0199
0200 for (int ichip=0; ichip<NCHIP; ichip++)
0201 {
0202 int header_found = p->iValue(ichip, "HEADER_FOUND");
0203 int trailer_found = p->iValue(ichip, "TRAILER_FOUND");
0204 int bunchcounter = p->iValue(ichip, "BUNCHCOUNTER");
0205
0206
0207
0208 if ( header_found==0 || trailer_found==0 )
0209 {
0210 if ( _verbosity>100 )
0211 {
0212 cout << "WARNING!! Event: " << _nevents << " Missing chip " << ichip << " HEADER_FOUND: " << header_found << " TRAILER_FOUND: " << trailer_found << " BUNCHCOUNTER: " << bunchcounter << endl;
0213 }
0214
0215 }
0216 }
0217
0218 MvtxDefUtil *mvtxdef = new MvtxDefUtil();
0219
0220 for (int ichip=0; ichip<chipmax; ichip++)
0221 {
0222
0223 int header_found = p->iValue(ichip, "HEADER_FOUND");
0224 int trailer_found = p->iValue(ichip, "TRAILER_FOUND");
0225 if (header_found==0 || trailer_found==0) continue;
0226 TrkrDefs::hitsetkey mvtx_hitsetkey = mvtxdef->GenHitSetKey(char(ichip),uint8_t(0),uint8_t(ichip));
0227
0228 for (int irow=0; irow<NROW; irow++)
0229 {
0230 int regions = p->iValue(ichip, irow);
0231 if ( regions==0 ) continue;
0232
0233 if ( _verbosity>100 )
0234 cout << "ICHIP: " << ichip << ",IROW: " << irow << ", REGIONS: " << regions << endl;
0235
0236 for (int iregion=0; iregion<NREGION; iregion++)
0237 {
0238 if ( (regions>>iregion)&1 )
0239 {
0240 if ( _verbosity>100 )
0241 cout << "REGIONS: " << regions << ", I: " << iregion << endl;
0242
0243 int bits = p->iValue(ichip, iregion, irow);
0244 if ( bits==0 ) continue;
0245
0246 for (int icol=0; icol<NCOL_PER_REGION; icol++)
0247 {
0248 if ( (bits>>icol)&1 )
0249 {
0250 _npixel_per_chip[ichip]++;
0251 int row = irow;
0252 int col = iregion*NCOL_PER_REGION + icol;
0253
0254 MvtxHitSetv1 *hitset = static_cast<MvtxHitSetv1 *>(_hitsetcon->FindOrAddHitSet(mvtx_hitsetkey)->second);
0255 if ( hitset )
0256 {
0257
0258 hitset->AddHit(uint16_t(col),uint16_t(row));
0259 nhits_for_this++;
0260 }
0261 else
0262 {
0263 cout << "NO HITSET!" << endl;
0264 }
0265
0266 }
0267 }
0268
0269 }
0270 }
0271 }
0272
0273 _nevent_per_chip[ichip]++;
0274
0275 }
0276
0277 if ( _verbosity>10 )
0278 {
0279 cout << "-----MvtxUnpackPRDF::process_event Check HitSetCon" << endl;
0280 _hitsetcon->identify();
0281
0282 int nhits = 0;
0283 for (int ichip=0; ichip<NCHIP; ichip++){
0284 TrkrDefs::hitsetkey mvtx_hitsetkey = mvtxdef->GenHitSetKey(char(ichip),uint8_t(0),uint8_t(ichip));
0285 MvtxHitSetv1 *hitset = static_cast<MvtxHitSetv1 *>(_hitsetcon->FindHitSet(mvtx_hitsetkey));
0286 MvtxHitSetv1::ConstRange itr_range = hitset->GetHits();
0287
0288 for (MvtxHitSetv1::ConstIterator itr = itr_range.first; itr != itr_range.second; ++itr){
0289 nhits++;
0290 }
0291 }
0292 cout << "N HITS: " << nhits_for_this << ", " << nhits << endl;
0293 }
0294
0295 delete mvtxdef;
0296 delete p;
0297 }
0298
0299 }
0300
0301
0302 int
0303 MvtxUnpackPRDF::End(PHCompositeNode *topNode)
0304 {
0305 cout << "-----MvtxUnpackPRDF::End-----" << endl;
0306 if ( _verbosity>10 )
0307 {
0308
0309 MvtxDefUtil *mvtxdef = new MvtxDefUtil();
0310
0311 cout << "-----MvtxUnpackPRDF::End::PrintSummary-----" << endl;
0312 for (int ichip=0; ichip<NCHIP; ichip++){
0313
0314 cout << "CHIP, " << ichip << ", "
0315 << ", N EVENT: " << _nevent_per_chip[ichip]
0316 << ", N HITS: " << _npixel_per_chip[ichip]
0317 << endl;
0318 }
0319
0320 delete mvtxdef;
0321 }
0322
0323 return Fun4AllReturnCodes::EVENT_OK;
0324 }
0325