Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:14:00

0001 #include "InttOfflineDummyData.h"
0002 
0003 /// Cluster/Calorimeter includes
0004 
0005 /// Fun4All includes
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 /// ROOT includes
0017 #include <TFile.h>
0018 #include <TH1.h>
0019 #include <TH2.h>
0020 #include <TNtuple.h>
0021 #include <TTree.h>
0022 
0023 /// C++ includes
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 std::vector<InttNameSpace::Offline_s> setDummyInttEvent(const int ievent);
0036 
0037 /**
0038  * This class demonstrates the construction and use of an analysis module
0039  * within the sPHENIX Fun4All framework. It is intended to show how to
0040  * obtain physics objects from the analysis tree, and then write them out
0041  * to a ROOT tree and file for further offline analysis.
0042  */
0043 
0044 /**
0045  * Constructor of module
0046  */
0047 InttOfflineDummyData::InttOfflineDummyData(const std::string &name, const std::string &filename)
0048   : SubsysReco(name)
0049   , inttEvt_(nullptr)
0050   , ievent_(0)
0051 {
0052   fname_ = filename;
0053 }
0054 
0055 /**
0056  * Destructor of module
0057  */
0058 InttOfflineDummyData::~InttOfflineDummyData()
0059 {
0060   if(inttEvt_!=nullptr) delete inttEvt_;
0061 }
0062 
0063 /**
0064  * Initialize the module and prepare looping over events
0065  */
0066 int InttOfflineDummyData::Init(PHCompositeNode * /*topNode*/)
0067 {
0068   if (Verbosity() > 5)
0069   {
0070     std::cout << "Beginning Init in InttOfflineDummyData" << std::endl;
0071   }
0072 
0073   return 0;
0074 }
0075 
0076 int InttOfflineDummyData::InitRun(PHCompositeNode * topNode)
0077 {
0078   if (Verbosity() > 5)
0079   {
0080     std::cout << "Beginning InitRun in InttOfflineDummyData" << std::endl;
0081   }
0082 
0083   if(!topNode)
0084   {
0085       std::cout << "InttOfflineDummyData::InitRun(PHCompositeNode* topNode)" << std::endl;
0086       std::cout << "\tCould not retrieve topNode; doing nothing" << std::endl;
0087 
0088       return -1;
0089   }
0090 
0091   PHNodeIterator dst_itr(topNode);
0092   PHCompositeNode* dst_node = dynamic_cast<PHCompositeNode*>(dst_itr.findFirst("PHCompositeNode", "DST"));
0093   if(!dst_node)
0094   {
0095       if(Verbosity())std::cout << "InttOfflineDummyData::InitRun(PHCompositeNode* topNode)" << std::endl;
0096       if(Verbosity())std::cout << "\tCould not retrieve dst_node; doing nothing" << std::endl;
0097 
0098       return -1;
0099   }
0100 
0101   PHNodeIterator trkr_itr(dst_node);
0102   PHCompositeNode* trkr_node = dynamic_cast<PHCompositeNode*>(trkr_itr.findFirst("PHCompositeNode", "TRKR"));
0103   if(!trkr_node)
0104   {
0105       trkr_node = new PHCompositeNode("TRKR");
0106       dst_node->addNode(trkr_node);
0107   }
0108 
0109   TrkrHitSetContainer* trkr_hit_set_container = findNode::getClass<TrkrHitSetContainer>(topNode, "TRKR_HITSET");
0110   if(!trkr_hit_set_container)
0111   {
0112       if(Verbosity())std::cout << "InttOfflineDummyData::InitRun(PHCompositeNode* topNode)" << std::endl;
0113       if(Verbosity())std::cout << "\tMaking TrkrHitSetContainer" << std::endl;
0114 
0115       trkr_hit_set_container = new TrkrHitSetContainerv1;
0116       PHIODataNode<PHObject>* new_node = new PHIODataNode<PHObject>(trkr_hit_set_container, "TRKR_HITSET", "PHObject");
0117       trkr_node->addNode(new_node);
0118   }
0119 
0120 
0121   inttEvt_ = new InttEvent();
0122   ievent_ = 0;
0123 
0124   return Fun4AllReturnCodes::EVENT_OK;
0125 }
0126 
0127 /**
0128  * Main workhorse function where each event is looped over and
0129  * data from each event is collected from the node tree for analysis
0130  */
0131 int InttOfflineDummyData::process_event(PHCompositeNode *topNode)
0132 {
0133     cout<<"InttOfflineDummyData process event"<<endl;
0134     if (Verbosity() > 5)
0135     {
0136         std::cout << "Beginning process_event in AnaTutorial" << std::endl;
0137     }
0138 
0139     TrkrHitSetContainer* trkr_hit_set_container = findNode::getClass<TrkrHitSetContainer>(topNode, "TRKR_HITSET");
0140     if(!trkr_hit_set_container)
0141     {
0142         std::cout << PHWHERE << std::endl;
0143         std::cout << "InttOfflineDummyDataDecoder::process_event(PHCompositeNode* topNode)" << std::endl;
0144         std::cout << "Could not get \"TRKR_HITSET\" from Node Tree" << std::endl;
0145         std::cout << "Exiting" << std::endl;
0146         exit(1);
0147 
0148         return Fun4AllReturnCodes::DISCARDEVENT;
0149     }
0150 
0151 
0152     /////////////////////
0153     //if(ievent_>=1000){
0154     //  cout<<"all events are already processed. quit InttOfflineDummyData"<<endl;
0155     //  return Fun4AllReturnCodes::EVENT_OK;
0156     //}
0157 
0158 
0159 
0160     vector<InttNameSpace::Offline_s> vdata = setDummyInttEvent(ievent_);
0161 
0162     int adc = 0;
0163     //int amp = 0;
0164     int bco = 0;
0165 
0166     TrkrDefs::hitsetkey hit_set_key = 0;
0167     TrkrDefs::hitkey hit_key = 0;
0168     TrkrHitSetContainer::Iterator hit_set_container_itr;
0169     TrkrHit* hit = nullptr;
0170 
0171     int nskip=0;
0172     for(uint n = 0; n < vdata.size(); ++n)
0173     {
0174 
0175         adc = 0;
0176         bco = 0; // always 0 until time-in issue fixed; //-- rawhit->bco;
0177 
0178         struct InttNameSpace::Offline_s offline = vdata[n];
0179 
0180                 //--//------------------
0181                 //--// change the ladder id by hand
0182                 //--int nladder = (offline.layer<5) ? 12 : 16;
0183                 //--int offset  = 2;
0184                 //--if(     offline.layer==4) offset=3;
0185                 //--else if(offline.layer==5) offset=3;
0186                 //--else if(offline.layer==6) offset=4;
0187                 //--offline.ladder_phi -= offset; 
0188                 //--if(offline.ladder_phi<0) offline.ladder_phi += nladder;
0189                 //--//------------------
0190 
0191         hit_set_key = InttDefs::genHitSetKey(offline.layer,  offline.ladder_z, offline.ladder_phi, bco); 
0192         hit_set_container_itr = trkr_hit_set_container->findOrAddHitSet(hit_set_key);
0193                 //cout<<"offline layer : "<<offline.layer<<endl;
0194 
0195         hit_key = InttDefs::genHitKey(offline.strip_y, offline.strip_x);
0196         hit     = hit_set_container_itr->second->getHit(hit_key);
0197         if(hit) {
0198             nskip++;
0199             continue;
0200         }
0201 
0202         hit = new TrkrHitv2;
0203         hit->setAdc(adc);
0204         hit_set_container_itr->second->addHitSpecificKey(hit_key, hit);
0205     }
0206     cout<<"Nskip of copyhit : "<<nskip<<endl;
0207 
0208 
0209     ievent_++;
0210     return Fun4AllReturnCodes::EVENT_OK;
0211 }
0212 
0213 /**
0214  * End the module and finish any data collection. Clean up any remaining
0215  * loose ends
0216  */
0217 int InttOfflineDummyData::End(PHCompositeNode * /*topNode*/)
0218 {
0219   if (Verbosity() > 1)
0220   {
0221     std::cout << "Ending InttOfflineDummyData analysis package" << std::endl;
0222   }
0223 
0224 
0225   return 0;
0226 }
0227 
0228 
0229 //      hit_set_key = InttDefs::genHitSetKey(offline.layer,  offline.ladder_z, offline.ladder_phi, bco); 
0230 //      hit_key = InttDefs::genHitKey(offline.strip_y, offline.strip_x);
0231 void SetOfflineHit(InttNameSpace::Offline_s* hit, int layer, int ladder_z, int ladder_phi, int strip_y, int strip_x) 
0232 {
0233   hit->layer      = layer;
0234   hit->ladder_z   = ladder_z;
0235   hit->ladder_phi = ladder_phi;
0236   hit->strip_y    = strip_y;
0237   hit->strip_x    = strip_x;
0238 
0239 }
0240 
0241 std::vector<InttNameSpace::Offline_s> setDummyInttEvent(const int ievent)
0242 {
0243   vector<InttNameSpace::Offline_s> vdata;
0244 
0245   // ievent:0-7 for felix check
0246   if(ievent==0){
0247        InttNameSpace::Offline_s hit0[10];
0248        SetOfflineHit(&hit0[0], 3, 0,  1, 5,  45);
0249        SetOfflineHit(&hit0[1], 3, 0,  2, 0, 111);
0250        SetOfflineHit(&hit0[2], 3, 0,  2, 3, 128);
0251        SetOfflineHit(&hit0[3], 3, 2,  6, 2,   8);
0252        SetOfflineHit(&hit0[4], 3, 2,  6, 2,   9);
0253        SetOfflineHit(&hit0[5], 4, 0,  6, 7,   6);
0254        SetOfflineHit(&hit0[6], 5, 0,  1, 6, 180);
0255        SetOfflineHit(&hit0[7], 6, 0,  2, 2, 216);
0256        SetOfflineHit(&hit0[8], 6, 1,  2, 4, 195);
0257        SetOfflineHit(&hit0[9], 6, 2,  7, 4, 217);
0258       for(int i=0; i<10; i++) vdata.push_back(hit0[i]);
0259   }
0260   else if(ievent<25){
0261     int layer      = (ievent-1)/12;
0262     int ladder_phi = (ievent-1)%12;
0263 
0264     InttNameSpace::Offline_s hit1;
0265     SetOfflineHit(&hit1, layer+3, 0, ladder_phi, 0, 0);
0266     vdata.push_back(hit1);
0267     cout<<"set : "<<ievent<<" : "<<layer<<" "<<ladder_phi<<endl;
0268   }
0269   else if(ievent<57){
0270     int layer      = (ievent-25)/16;
0271     int ladder_phi = (ievent-25)%16;
0272 
0273     InttNameSpace::Offline_s hit1;
0274     SetOfflineHit(&hit1, layer+5, 0, ladder_phi, 0, 0);
0275     vdata.push_back(hit1);
0276     cout<<"set : "<<ievent<<" : "<<layer<<" "<<ladder_phi<<endl;
0277   }
0278   else if(ievent<(57+56*26)){
0279     //0-25
0280     int seed_lad  = (ievent-57);
0281         int ladder_idx = seed_lad/26; // 0-55
0282         int layer=0, lad_phi=0; 
0283         if(ladder_idx<24){
0284           layer   = ladder_idx/12;
0285           lad_phi = ladder_idx%12;
0286         }
0287         else if(ladder_idx<56){
0288           layer   = (ladder_idx-24)/16 + 2;
0289           lad_phi = (ladder_idx-24)%16;
0290         }
0291     else { cout<<"exceed range2 : "<<ievent<<endl; }
0292 
0293         // same for all ladders
0294         int seed  = seed_lad%26;
0295     int lad_z = 0;
0296     int sen_z = 0;
0297     if(seed<8) {
0298       lad_z = 0;
0299       sen_z = seed;
0300     }
0301     else if(seed<13) {
0302       lad_z = 1;
0303       sen_z = seed-8;
0304     }
0305     else if(seed<21) {
0306       lad_z = 2;
0307       sen_z = seed-13;
0308     }
0309     else if(seed<26) {
0310       lad_z = 3;
0311       sen_z = seed-21;
0312     }
0313     else { cout<<"exceed range"<<endl; }
0314 
0315     InttNameSpace::Offline_s hit1;
0316     SetOfflineHit(&hit1, layer+3, lad_z, lad_phi, sen_z, 0);
0317     vdata.push_back(hit1);
0318     cout<<"set : "<<ievent<<" : "<<lad_z<<" "<<sen_z<<" "<<lad_phi<<" "<<layer<<endl;
0319   }
0320   else if(ievent<(57+56*26+256*2)){
0321     //0-25
0322     int seed = (ievent-(57+56*26));
0323 
0324         int lad = seed/256;
0325 
0326         int ch = seed%256;
0327 
0328 
0329         int layer=0, lad_z=0, lad_phi=0, sen_z=0;
0330 
0331     InttNameSpace::Offline_s hit1;
0332     SetOfflineHit(&hit1, layer+3, 2*lad, lad_phi, sen_z, ch);
0333     vdata.push_back(hit1);
0334     cout<<"set : "<<ievent<<" : "<<lad_z<<" "<<sen_z<<" "<<lad_phi<<" "<<layer<<" "<<ch<<endl;
0335   }
0336 
0337 
0338   return vdata;
0339 }
0340