Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 #include "InttRawData.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 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  * Destructor of module
0057  */
0058 InttRawData::~InttRawData()
0059 {
0060 }
0061 
0062 /**
0063  * Initialize the module and prepare looping over events
0064  */
0065 int InttRawData::Init(PHCompositeNode * /*topNode*/)
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  * Main workhorse function where each event is looped over and
0144  * data from each event is collected from the node tree for analysis
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         //return Fun4AllReturnCodes::EVENT_OK;
0171         return Fun4AllReturnCodes::ABORTRUN;
0172     }
0173 
0174     tree_->GetEntry(ievent_++);
0175 
0176     /*
0177        offlineRawdata data[12];
0178        data[0].set(3, 0,  1, 0, 5,  45, 0);
0179        data[1].set(3, 0,  2, 0, 0, 111, 0);
0180        data[2].set(3, 0,  2, 0, 3, 128, 0);
0181        data[3].set(3, 2,  6, 0, 2,   8, 0);
0182        data[4].set(3, 2,  6, 0, 2,   9, 0);
0183        data[5].set(4, 0,  6, 0, 7,   6, 0);
0184        data[6].set(5, 0,  1, 0, 6, 180, 0);
0185        data[7].set(6, 0,  2, 0, 2, 216, 0);
0186        data[8].set(6, 1,  2, 0, 4, 195, 0);
0187        data[9].set(6, 2,  7, 0, 4, 217, 0);
0188        */
0189 
0190         cout<<"InttEvent: "<<inttEvt_->evtSeq<<" "<<inttEvt_->bco<<" "<<hex<<inttEvt_->bco<<dec<<endl;
0191 
0192 
0193 
0194     int adc = 0;
0195     //int amp = 0;
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         //static const int DAC[8] = {15, 30, 50, 70, 90, 110, 130, 150};
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; //rawhit->chip_id;
0218         rawdata.channel       = rawhit->chan_id;
0219 
0220         adc = rawhit->adc;
0221         //amp = p->iValue(n, "AMPLITUE");
0222         bco = 0; // always 0 until time-in issue fixed; //-- rawhit->bco;
0223 
0224         struct InttNameSpace::Offline_s offline = InttNameSpace::ToOffline(rawdata);
0225                 
0226                 // this modification no longer valid since the repo-code was updated
0227                 //--//------------------
0228                 //--// change the ladder id by hand
0229                 //--int nladder = (offline.layer<5) ? 12 : 16;
0230                 //--//int offset  = 2;
0231                 //--//if(     offline.layer==4) offset=3;
0232                 //--//else if(offline.layer==5) offset=3;
0233                 //--//else if(offline.layer==6) offset=4;
0234                 //--//offline.ladder_phi -= offset; 
0235                 //--
0236                 //--int offset  = 3;
0237                 //--if(     offline.layer<5)  offset=3;
0238                 //--else                      offset=4;
0239                 //--offline.ladder_phi -= offset; 
0240                 //--if(offline.ladder_phi<0) offline.ladder_phi += nladder;
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                 //cout<<"offline layer : "<<offline.layer<<endl;
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                 // remove hotchannel
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  * End the module and finish any data collection. Clean up any remaining
0283  * loose ends
0284  */
0285 int InttRawData::End(PHCompositeNode * /*topNode*/)
0286 {
0287   if (Verbosity() > 1)
0288   {
0289     std::cout << "Ending InttRawData analysis package" << std::endl;
0290   }
0291 
0292 
0293   return 0;
0294 }
0295