Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:18:41

0001 #include "bcocheck.h"
0002 #include <TFile.h>
0003 #include <TH1.h>
0004 #include <TString.h>
0005 #include <TStyle.h>
0006 #include <TSystem.h>
0007 #include <ffarawobjects/InttRawHitContainer.h>
0008 #include <fun4all/Fun4AllReturnCodes.h>
0009 #include <fun4all/SubsysReco.h>
0010 #include <phool/getClass.h>
0011 #include <phool/phool.h>
0012 #include <cstdint>
0013 #include <cstdlib>
0014 #include <iostream>
0015 #include <limits>
0016 #include <ostream>
0017 #include <string>
0018 
0019 using namespace std;
0020 
0021 bcocheck::bcocheck(const string &name, const int run_num, const int felix_num)
0022   : SubsysReco(name)
0023 {
0024   run_num_ = run_num;
0025   felix_num_ = felix_num;
0026   cout << "felix_num_=" << felix_num_ << "felix_num=" << felix_num << '\n';
0027 }
0028 
0029 int bcocheck::Init(PHCompositeNode * /*topNode*/)
0030 {
0031   if (Verbosity() > 5)
0032   {
0033     std::cout << "Beginning Init in bcocheck" << '\n';
0034   }
0035 
0036   return 0;
0037 }
0038 
0039 int bcocheck::InitRun(PHCompositeNode *topNode)
0040 {
0041   if (!topNode)
0042   {
0043     std::cout << "bcocheck::InitRun(PHCompositeNode* topNode)" << '\n';
0044     std::cout << "\tCould not retrieve topNode; doing nothing" << '\n';
0045 
0046     return 1;
0047   }
0048 
0049   cout << "felix_num_=" << felix_num_ << '\n';
0050 
0051   // Initialize histograms
0052   for (int felix = 0; felix < kFelix_num_; felix++)
0053   {
0054     if (felix != felix_num_)
0055     {
0056       continue;
0057     }
0058 
0059     string const name = "h2_bco_felix_" + to_string(felix);
0060     string const title = name + Form("_Run%d", run_num_);
0061     h_full_bco[felix] = new TH1D(name.c_str(), title.c_str(), 128, 0, 128);
0062     h_full_bco[felix]->SetXTitle("BCO_FULL - BCO");
0063     h_full_bco[felix]->SetMinimum(0);
0064     tf_output_[felix] = new TFile(Form("./bco_000%d_intt%d.root", run_num_, felix), "RECREATE");
0065   }
0066   return Fun4AllReturnCodes::EVENT_OK;
0067 }
0068 
0069 int bcocheck::process_event(PHCompositeNode *topNode)
0070 {
0071   // cout<<"1234"<<endl;
0072 
0073   // get raw hit
0074   string const m_InttRawNodeName = "INTTRAWHIT";
0075   InttRawHitContainer *inttcont = findNode::getClass<InttRawHitContainer>(topNode, m_InttRawNodeName);
0076   if (!inttcont)
0077   {
0078     cout << PHWHERE << '\n';
0079     cout << "bcocheck::process_event(PHCompositeNode* topNode)" << '\n';
0080     cout << "Could not get \"" << m_InttRawNodeName << "\" from Node Tree" << '\n';
0081     cout << "Exiting" << '\n';
0082     gSystem->Exit(1);
0083     exit(1);
0084   }
0085 
0086   uint64_t const longbco_full = inttcont->get_nhits() > 0
0087                                     ? inttcont->get_hit(0)->get_bco()
0088                                     : std::numeric_limits<uint64_t>::max();
0089   // uint64_t difevent_bcofull = (longbco_full &bit )-(long_prev_bcofull &bit);
0090   // h_interval->Fill(difevent_bcofull);
0091   uint64_t const bco_full = longbco_full & 0x7FU;
0092   // cout<<"longbco_full="<<longbco_full<<endl;
0093 
0094   ievent_++;
0095   // cout<<"5678"<<endl;
0096   /*if(ievent_<500000){
0097     return Fun4AllReturnCodes::EVENT_OK;
0098   }*/
0099 
0100   if ((ievent_ % 100 == 0 && ievent_ < 1000) || ievent_ % 1000 == 0)
0101   {
0102     cout << "Process event #" << ievent_ << '\n';
0103   }
0104 
0105   int const nhits = inttcont->get_nhits();
0106 
0107   for (int i = 0; i < nhits; i++)
0108   {
0109     InttRawHit *intthit = inttcont->get_hit(i);
0110 
0111     int const fnum = intthit->get_packetid() - 3001;  // packet id
0112     int const bco = intthit->get_FPHX_BCO();          // FPHX bco
0113 
0114     int bco_diff = bco_full - bco;
0115     if (bco_diff < 0)
0116     {
0117       bco_diff = bco_diff + 128;
0118     }
0119 
0120     h_full_bco[fnum]->Fill(bco_diff);
0121   }
0122   // cout<<"910"<<endl;
0123   return Fun4AllReturnCodes::EVENT_OK;
0124 }
0125 
0126 int bcocheck::End(PHCompositeNode * /*topNode*/)
0127 {
0128   // Mixupfraction();
0129 
0130   if (Verbosity() > 1)
0131   {
0132     std::cout << "Processing bcocheck done" << '\n';
0133   }
0134 
0135   this->DrawHists();
0136 
0137   return Fun4AllReturnCodes::EVENT_OK;
0138 }
0139 
0140 void bcocheck::DrawHists()
0141 {
0142   gStyle->SetOptStat(0);
0143 
0144   for (int felix = 0; felix < kFelix_num_; felix++)
0145   {
0146     if (felix != felix_num_)
0147     {
0148       continue;
0149     }
0150 
0151     tf_output_[felix]->cd();
0152 
0153     h_full_bco[felix]->Write();
0154 
0155     tf_output_[felix]->Close();
0156   }
0157 }