Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:13:59

0001 #include "InttDummyData.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 /**
0036  * This class demonstrates the construction and use of an analysis module
0037  * within the sPHENIX Fun4All framework. It is intended to show how to
0038  * obtain physics objects from the analysis tree, and then write them out
0039  * to a ROOT tree and file for further offline analysis.
0040  */
0041 
0042 /**
0043  * Constructor of module
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  * Destructor of module
0055  */
0056 InttDummyData::~InttDummyData()
0057 {
0058   if(inttEvt_!=nullptr) delete inttEvt_;
0059 }
0060 
0061 /**
0062  * Initialize the module and prepare looping over events
0063  */
0064 int InttDummyData::Init(PHCompositeNode * /*topNode*/)
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  * Main workhorse function where each event is looped over and
0127  * data from each event is collected from the node tree for analysis
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        offlineRawdata data[12];
0158        data[0].set(3, 0,  1, 0, 5,  45, 0);
0159        data[1].set(3, 0,  2, 0, 0, 111, 0);
0160        data[2].set(3, 0,  2, 0, 3, 128, 0);
0161        data[3].set(3, 2,  6, 0, 2,   8, 0);
0162        data[4].set(3, 2,  6, 0, 2,   9, 0);
0163        data[5].set(4, 0,  6, 0, 7,   6, 0);
0164        data[6].set(5, 0,  1, 0, 6, 180, 0);
0165        data[7].set(6, 0,  2, 0, 2, 216, 0);
0166        data[8].set(6, 1,  2, 0, 4, 195, 0);
0167        data[9].set(6, 2,  7, 0, 4, 217, 0);
0168        */
0169 
0170 
0171 
0172         setDummyInttEvent(ievent_);
0173 
0174     int adc = 0;
0175     //int amp = 0;
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         //amp = p->iValue(n, "AMPLITUE");
0198         bco = 0; // always 0 until time-in issue fixed; //-- rawhit->bco;
0199 
0200         struct InttNameSpace::Offline_s offline = InttNameSpace::ToOffline(rawdata);
0201 
0202                 //--//------------------
0203                 //--// change the ladder id by hand
0204                 //--int nladder = (offline.layer<5) ? 12 : 16;
0205                 //--//int offset  = 2;
0206                 //--//if(     offline.layer==4) offset=3;
0207                 //--//else if(offline.layer==5) offset=3;
0208                 //--//else if(offline.layer==6) offset=4;
0209                 //--
0210                 //--int offset  = 3;
0211                 //--if(     offline.layer<5)  offset=3;
0212                 //--else                      offset=4;
0213                 //--offline.ladder_phi -= offset; 
0214                 //--if(offline.ladder_phi<0) offline.ladder_phi += nladder;
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                 //cout<<"offline layer : "<<offline.layer<<endl;
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  * End the module and finish any data collection. Clean up any remaining
0241  * loose ends
0242  */
0243 int InttDummyData::End(PHCompositeNode * /*topNode*/)
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;  // 0-7
0269       module  = Mod;  // 0-13
0270       chip_id = Chip; // 1-26
0271       chan_id = Chan; // 0-127
0272       adc     = Adc;  // 0-7
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   // set dummy data
0286   inputdata input;
0287   // ievent:0-7 for felix check
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