File indexing completed on 2025-08-06 08:14:00
0001 #include "InttRawData.h"
0002
0003
0004
0005
0006 #include <fun4all/Fun4AllHistoManager.h>
0007 #include <fun4all/Fun4AllReturnCodes.h>
0008 #include <phool/PHCompositeNode.h>
0009 #include <phool/getClass.h>
0010
0011 #include <trackbase/InttDefs.h>
0012 #include <trackbase/TrkrHitv2.h>
0013 #include <trackbase/TrkrHitSet.h>
0014 #include <trackbase/TrkrHitSetContainerv1.h>
0015
0016
0017 #include <TFile.h>
0018 #include <TH1.h>
0019 #include <TH2.h>
0020 #include <TNtuple.h>
0021 #include <TTree.h>
0022
0023
0024 #include <cassert>
0025 #include <cmath>
0026 #include <sstream>
0027 #include <string>
0028
0029 #include <intt/InttMapping.h>
0030
0031 #include "InttEvent.h"
0032
0033 using namespace std;
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045 InttRawData::InttRawData(const std::string &name, const std::string &filename)
0046 : SubsysReco(name)
0047 , inFile_(nullptr)
0048 , tree_(nullptr)
0049 , inttEvt_(nullptr)
0050 , ievent_(0)
0051 {
0052 fname_ = filename;
0053 }
0054
0055
0056
0057
0058 InttRawData::~InttRawData()
0059 {
0060 }
0061
0062
0063
0064
0065 int InttRawData::Init(PHCompositeNode * )
0066 {
0067 if (Verbosity() > 5)
0068 {
0069 std::cout << "Beginning Init in InttRawData" << std::endl;
0070 }
0071
0072 return 0;
0073 }
0074
0075 int InttRawData::InitRun(PHCompositeNode * topNode)
0076 {
0077 if (Verbosity() > 5)
0078 {
0079 std::cout << "Beginning InitRun in InttRawData" << std::endl;
0080 }
0081
0082 if(!topNode)
0083 {
0084 std::cout << "InttRawData::InitRun(PHCompositeNode* topNode)" << std::endl;
0085 std::cout << "\tCould not retrieve topNode; doing nothing" << std::endl;
0086
0087 return -1;
0088 }
0089
0090 PHNodeIterator dst_itr(topNode);
0091 PHCompositeNode* dst_node = dynamic_cast<PHCompositeNode*>(dst_itr.findFirst("PHCompositeNode", "DST"));
0092 if(!dst_node)
0093 {
0094 if(Verbosity())std::cout << "InttRawData::InitRun(PHCompositeNode* topNode)" << std::endl;
0095 if(Verbosity())std::cout << "\tCould not retrieve dst_node; doing nothing" << std::endl;
0096
0097 return -1;
0098 }
0099
0100 PHNodeIterator trkr_itr(dst_node);
0101 PHCompositeNode* trkr_node = dynamic_cast<PHCompositeNode*>(trkr_itr.findFirst("PHCompositeNode", "TRKR"));
0102 if(!trkr_node)
0103 {
0104 trkr_node = new PHCompositeNode("TRKR");
0105 dst_node->addNode(trkr_node);
0106 }
0107
0108 TrkrHitSetContainer* trkr_hit_set_container = findNode::getClass<TrkrHitSetContainer>(topNode, "TRKR_HITSET");
0109 if(!trkr_hit_set_container)
0110 {
0111 if(Verbosity())std::cout << "InttRawData::InitRun(PHCompositeNode* topNode)" << std::endl;
0112 if(Verbosity())std::cout << "\tMaking TrkrHitSetContainer" << std::endl;
0113
0114 trkr_hit_set_container = new TrkrHitSetContainerv1;
0115 PHIODataNode<PHObject>* new_node = new PHIODataNode<PHObject>(trkr_hit_set_container, "TRKR_HITSET", "PHObject");
0116 trkr_node->addNode(new_node);
0117 }
0118
0119
0120 inFile_ = TFile::Open(fname_.c_str());
0121 tree_ = (TTree*)inFile_->Get("tree");
0122 if(tree_==nullptr){
0123 cout<<"no tree found"<<endl;
0124 }
0125
0126 tree_->SetBranchAddress("event", &inttEvt_);
0127 ievent_ = 0;
0128
0129 cout<<"Nevent in file : "<<tree_->GetEntries()<<endl;
0130
0131 hotmap_.setDebug(true);
0132 if( hotmap_.Readfile(hotfilename_.c_str())) {
0133 cout<<"successfully read hotmap file : "<<hotfilename_.c_str()<<endl;
0134 }
0135 else {
0136 cout<<"failed to read hotmap file : "<<hotfilename_.c_str()<<endl;
0137 }
0138
0139 return Fun4AllReturnCodes::EVENT_OK;
0140 }
0141
0142
0143
0144
0145
0146 int InttRawData::process_event(PHCompositeNode *topNode)
0147 {
0148 cout<<"InttRawData process event"<<endl;
0149 if (Verbosity() > 5)
0150 {
0151 std::cout << "Beginning process_event in AnaTutorial" << std::endl;
0152 }
0153
0154 TrkrHitSetContainer* trkr_hit_set_container = findNode::getClass<TrkrHitSetContainer>(topNode, "TRKR_HITSET");
0155 if(!trkr_hit_set_container)
0156 {
0157 std::cout << PHWHERE << std::endl;
0158 std::cout << "InttRawDataDecoder::process_event(PHCompositeNode* topNode)" << std::endl;
0159 std::cout << "Could not get \"TRKR_HITSET\" from Node Tree" << std::endl;
0160 std::cout << "Exiting" << std::endl;
0161 exit(1);
0162
0163 return Fun4AllReturnCodes::DISCARDEVENT;
0164 }
0165
0166
0167
0168 if(ievent_>=tree_->GetEntries()){
0169 cout<<"all events are already processed. quit InttRawData"<<endl;
0170
0171 return Fun4AllReturnCodes::ABORTRUN;
0172 }
0173
0174 tree_->GetEntry(ievent_++);
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190 cout<<"InttEvent: "<<inttEvt_->evtSeq<<" "<<inttEvt_->bco<<" "<<hex<<inttEvt_->bco<<dec<<endl;
0191
0192
0193
0194 int adc = 0;
0195
0196 int bco = 0;
0197
0198 TrkrDefs::hitsetkey hit_set_key = 0;
0199 TrkrDefs::hitkey hit_key = 0;
0200 TrkrHitSetContainer::Iterator hit_set_container_itr;
0201 TrkrHit* hit = nullptr;
0202
0203
0204 static const int DAC[8] = {15, 30, 60, 90, 120, 150, 180, 210};
0205
0206 int nskip=0;
0207 for(int n = 0; n < inttEvt_->getNHits(); ++n)
0208 {
0209 InttHit* rawhit = inttEvt_->getHit(n);
0210
0211 int chip = rawhit->chip_id - 1;
0212 if(chip<0) chip+=26;
0213
0214 struct InttNameSpace::RawData_s rawdata;
0215 rawdata.felix_server = rawhit->pid - 3001;
0216 rawdata.felix_channel = rawhit->module;
0217 rawdata.chip = chip;
0218 rawdata.channel = rawhit->chan_id;
0219
0220 adc = rawhit->adc;
0221
0222 bco = 0;
0223
0224 struct InttNameSpace::Offline_s offline = InttNameSpace::ToOffline(rawdata);
0225
0226
0227
0228
0229
0230
0231
0232
0233
0234
0235
0236
0237
0238
0239
0240
0241
0242
0243 hit_set_key = InttDefs::genHitSetKey(offline.layer, offline.ladder_z, offline.ladder_phi, bco);
0244 hit_set_container_itr = trkr_hit_set_container->findOrAddHitSet(hit_set_key);
0245
0246
0247 hit_key = InttDefs::genHitKey(offline.strip_y, offline.strip_x);
0248 hit = hit_set_container_itr->second->getHit(hit_key);
0249 if(hit) {
0250 nskip++;
0251 continue;
0252 }
0253
0254
0255
0256 if(hotmap_.isHot(rawdata.felix_server,
0257 rawdata.felix_channel,
0258 rawdata.chip+1,
0259 rawdata.channel))
0260 {
0261 cout<<" hotchanel : "<<rawdata.felix_server<<" "<<rawdata.felix_channel<<" "
0262 <<rawdata.chip<<" "<< rawdata.channel<<endl;
0263 continue;
0264 }
0265
0266
0267
0268 cout<<" ch: "<<rawdata.felix_server<<" "<<rawdata.felix_channel<<" "
0269 <<rawdata.chip<<" "<< rawdata.channel<<endl;
0270
0271 hit = new TrkrHitv2;
0272 hit->setAdc(DAC[adc]);
0273 hit_set_container_itr->second->addHitSpecificKey(hit_key, hit);
0274 }
0275 cout<<"Nskip of copyhit : "<<nskip<<endl;
0276
0277
0278 return Fun4AllReturnCodes::EVENT_OK;
0279 }
0280
0281
0282
0283
0284
0285 int InttRawData::End(PHCompositeNode * )
0286 {
0287 if (Verbosity() > 1)
0288 {
0289 std::cout << "Ending InttRawData analysis package" << std::endl;
0290 }
0291
0292
0293 return 0;
0294 }
0295