Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-12-17 09:21:17

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