File indexing completed on 2025-08-06 08:13:59
0001 #include "InttDummyData.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 InttDummyData::InttDummyData(const std::string &name, const std::string &filename)
0046 : SubsysReco(name)
0047 , inttEvt_(nullptr)
0048 , ievent_(0)
0049 {
0050 fname_ = filename;
0051 }
0052
0053
0054
0055
0056 InttDummyData::~InttDummyData()
0057 {
0058 if(inttEvt_!=nullptr) delete inttEvt_;
0059 }
0060
0061
0062
0063
0064 int InttDummyData::Init(PHCompositeNode * )
0065 {
0066 if (Verbosity() > 5)
0067 {
0068 std::cout << "Beginning Init in InttDummyData" << std::endl;
0069 }
0070
0071 return 0;
0072 }
0073
0074 int InttDummyData::InitRun(PHCompositeNode * topNode)
0075 {
0076 if (Verbosity() > 5)
0077 {
0078 std::cout << "Beginning InitRun in InttDummyData" << std::endl;
0079 }
0080
0081 if(!topNode)
0082 {
0083 std::cout << "InttDummyData::InitRun(PHCompositeNode* topNode)" << std::endl;
0084 std::cout << "\tCould not retrieve topNode; doing nothing" << std::endl;
0085
0086 return -1;
0087 }
0088
0089 PHNodeIterator dst_itr(topNode);
0090 PHCompositeNode* dst_node = dynamic_cast<PHCompositeNode*>(dst_itr.findFirst("PHCompositeNode", "DST"));
0091 if(!dst_node)
0092 {
0093 if(Verbosity())std::cout << "InttDummyData::InitRun(PHCompositeNode* topNode)" << std::endl;
0094 if(Verbosity())std::cout << "\tCould not retrieve dst_node; doing nothing" << std::endl;
0095
0096 return -1;
0097 }
0098
0099 PHNodeIterator trkr_itr(dst_node);
0100 PHCompositeNode* trkr_node = dynamic_cast<PHCompositeNode*>(trkr_itr.findFirst("PHCompositeNode", "TRKR"));
0101 if(!trkr_node)
0102 {
0103 trkr_node = new PHCompositeNode("TRKR");
0104 dst_node->addNode(trkr_node);
0105 }
0106
0107 TrkrHitSetContainer* trkr_hit_set_container = findNode::getClass<TrkrHitSetContainer>(topNode, "TRKR_HITSET");
0108 if(!trkr_hit_set_container)
0109 {
0110 if(Verbosity())std::cout << "InttDummyData::InitRun(PHCompositeNode* topNode)" << std::endl;
0111 if(Verbosity())std::cout << "\tMaking TrkrHitSetContainer" << std::endl;
0112
0113 trkr_hit_set_container = new TrkrHitSetContainerv1;
0114 PHIODataNode<PHObject>* new_node = new PHIODataNode<PHObject>(trkr_hit_set_container, "TRKR_HITSET", "PHObject");
0115 trkr_node->addNode(new_node);
0116 }
0117
0118
0119 inttEvt_ = new InttEvent();
0120 ievent_ = 0;
0121
0122 return Fun4AllReturnCodes::EVENT_OK;
0123 }
0124
0125
0126
0127
0128
0129 int InttDummyData::process_event(PHCompositeNode *topNode)
0130 {
0131 cout<<"InttDummyData process event"<<endl;
0132 if (Verbosity() > 5)
0133 {
0134 std::cout << "Beginning process_event in AnaTutorial" << std::endl;
0135 }
0136
0137 TrkrHitSetContainer* trkr_hit_set_container = findNode::getClass<TrkrHitSetContainer>(topNode, "TRKR_HITSET");
0138 if(!trkr_hit_set_container)
0139 {
0140 std::cout << PHWHERE << std::endl;
0141 std::cout << "InttDummyDataDecoder::process_event(PHCompositeNode* topNode)" << std::endl;
0142 std::cout << "Could not get \"TRKR_HITSET\" from Node Tree" << std::endl;
0143 std::cout << "Exiting" << std::endl;
0144 exit(1);
0145
0146 return Fun4AllReturnCodes::DISCARDEVENT;
0147 }
0148
0149
0150
0151 if(ievent_>=120){
0152 cout<<"all events are already processed. quit InttDummyData"<<endl;
0153 return Fun4AllReturnCodes::EVENT_OK;
0154 }
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172 setDummyInttEvent(ievent_);
0173
0174 int adc = 0;
0175
0176 int bco = 0;
0177
0178 TrkrDefs::hitsetkey hit_set_key = 0;
0179 TrkrDefs::hitkey hit_key = 0;
0180 TrkrHitSetContainer::Iterator hit_set_container_itr;
0181 TrkrHit* hit = nullptr;
0182
0183 int nskip=0;
0184 for(int n = 0; n < inttEvt_->getNHits(); ++n)
0185 {
0186 InttHit* rawhit = inttEvt_->getHit(n);
0187 cout<<"inputhit : "<<rawhit->pid<<" "<<flush;
0188 rawhit->show();
0189
0190 struct InttNameSpace::RawData_s rawdata;
0191 rawdata.felix_server = rawhit->pid - 3001;
0192 rawdata.felix_channel = rawhit->module;
0193 rawdata.chip = rawhit->chip_id;
0194 rawdata.channel = rawhit->chan_id;
0195
0196 adc = rawhit->adc;
0197
0198 bco = 0;
0199
0200 struct InttNameSpace::Offline_s offline = InttNameSpace::ToOffline(rawdata);
0201
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217 hit_set_key = InttDefs::genHitSetKey(offline.layer, offline.ladder_z, offline.ladder_phi, bco);
0218 hit_set_container_itr = trkr_hit_set_container->findOrAddHitSet(hit_set_key);
0219
0220
0221 hit_key = InttDefs::genHitKey(offline.strip_y, offline.strip_x);
0222 hit = hit_set_container_itr->second->getHit(hit_key);
0223 if(hit) {
0224 nskip++;
0225 continue;
0226 }
0227
0228 hit = new TrkrHitv2;
0229 hit->setAdc(adc);
0230 hit_set_container_itr->second->addHitSpecificKey(hit_key, hit);
0231 }
0232 cout<<"Nskip of copyhit : "<<nskip<<endl;
0233
0234
0235 ievent_++;
0236 return Fun4AllReturnCodes::EVENT_OK;
0237 }
0238
0239
0240
0241
0242
0243 int InttDummyData::End(PHCompositeNode * )
0244 {
0245 if (Verbosity() > 1)
0246 {
0247 std::cout << "Ending InttDummyData analysis package" << std::endl;
0248 }
0249
0250
0251 return 0;
0252 }
0253
0254 void InttDummyData::setDummyInttEvent(const int ievent)
0255 {
0256 struct inputdata {
0257 inputdata()
0258 :pid(0), module(0), chip_id(0), chan_id(0), adc(0)
0259 { }
0260
0261 int pid;
0262 int module;
0263 int chip_id;
0264 int chan_id;
0265 int adc;
0266
0267 void set(int Pid, int Mod, int Chip, int Chan, int Adc){
0268 pid = Pid;
0269 module = Mod;
0270 chip_id = Chip;
0271 chan_id = Chan;
0272 adc = Adc;
0273 }
0274
0275 void set(InttEvent* inttEvt){
0276 InttHit * hit = inttEvt->addHit();
0277 hit->pid = pid;
0278 hit->module = module;
0279 hit->chip_id = chip_id;
0280 hit->chan_id = chan_id;
0281 hit->adc = adc;
0282 }
0283 };
0284
0285
0286 inputdata input;
0287
0288 if(ievent<8){
0289 input.set(3001+ievent, 0, 1, 0, 0);
0290 }
0291 else if(ievent<8+14*8){
0292 int pid = (ievent-8)/14;
0293 int mod = (ievent-8)%14;
0294 input.set(3001+pid, mod, 1, 0, 0);
0295 cout<<"set : "<<ievent<<" : "<<pid<<" "<<mod<<endl;
0296 }
0297
0298 inttEvt_->clear();
0299 input.set(inttEvt_);
0300 }
0301