Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2026-07-16 08:13:57

0001 #include "StreamingBcoReco.h"
0002 
0003 #include "BcoInfo.h"
0004 #include "StreamingBcoInfo.h"
0005 #include "StreamingBcoInfov1.h"
0006 
0007 
0008 #include <ffaobjects/SyncDefs.h>
0009 #include <ffaobjects/SyncObject.h>
0010 
0011 #include <ffarawobjects/Gl1Packet.h>
0012 
0013 #include <fun4all/Fun4AllReturnCodes.h>
0014 #include <fun4all/SubsysReco.h>  // for SubsysReco
0015 #include <fun4all/Fun4AllHistoManager.h>
0016 #include <fun4all/Fun4AllServer.h>
0017 
0018 
0019 #include <phool/PHCompositeNode.h>
0020 #include <phool/PHNode.h>          // for PHNode
0021 #include <phool/PHNodeIterator.h>  // for PHNodeIterator
0022 #include <phool/getClass.h>
0023 #include <phool/phool.h>  // for PHWHERE
0024 
0025 #include <Event/Event.h>
0026 #include <Event/EventTypes.h>
0027 #include <Event/packet.h>  // for Packet
0028 
0029 #include <TH1.h>
0030 
0031 #include <iostream>
0032 
0033 StreamingBcoReco::StreamingBcoReco(const std::string &name)
0034   : SubsysReco(name)
0035 {
0036   hm = new Fun4AllHistoManager("bco_histos");
0037   Fun4AllServer *se = Fun4AllServer::instance();
0038   se->registerHistoManager(hm); 
0039   return;
0040 }
0041 
0042 int StreamingBcoReco::Init(PHCompositeNode *topNode)
0043 {
0044   int iret = CreateNodeTree(topNode);
0045   h_bco_diff = new TH1I("h_bco_diff", ";bco diff;", 3500, 0, 3500);
0046   //std::string hist_name = "h_bco_diff_bit";
0047   //for (int bit=0; bit<trigbits; ++bit)
0048   //{
0049   //  hist_name += std::to_string(bit);
0050   //  h_bco_diff_trigbits[bit] = new TH1I(hist_name.c_str(), ";bco diff;", 3500, 0, 3500);
0051   //  hm->registerHisto(h_bco_diff_trigbits[bit]);
0052   //}
0053   h_bco_tag = new TH1I("h_bco_tag", ";usable bco tag;", 2, -0.5, 1.5);
0054   hm->registerHisto(h_bco_diff);
0055   hm->registerHisto(h_bco_tag);
0056 
0057   return iret;
0058 }
0059 
0060 int StreamingBcoReco::CreateNodeTree(PHCompositeNode *topNode)
0061 {
0062   PHNodeIterator iter(topNode);
0063   PHCompositeNode *dstNode;
0064   dstNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "DST"));
0065   if (!dstNode)
0066   {
0067     std::cout << PHWHERE << " DST Node is missing doing nothing" << std::endl;
0068     return Fun4AllReturnCodes::ABORTRUN;
0069   }
0070   StreamingBcoInfo *streaming_bco_info = findNode::getClass<StreamingBcoInfo>(topNode, "STREAMINGBCOINFO");
0071   if (!streaming_bco_info)
0072   {
0073     streaming_bco_info = new StreamingBcoInfov1();
0074     PHIODataNode<PHObject> *bconode = new PHIODataNode<PHObject>(streaming_bco_info, "STREAMINGBCOINFO", "PHObject");
0075     dstNode->addNode(bconode);
0076   }
0077   return Fun4AllReturnCodes::EVENT_OK;
0078 }
0079 
0080 int StreamingBcoReco::process_event(PHCompositeNode *topNode)
0081 {
0082   BcoInfo *bcoinfo = findNode::getClass<BcoInfo>(topNode, "BCOINFO");
0083   SyncObject *syncobject = findNode::getClass<SyncObject>(topNode, syncdefs::SYNCNODENAME);
0084   if (Verbosity() > 2)
0085   {
0086     if (!syncobject)
0087     {
0088       std::cout << PHWHERE << " SyncObject missing" << std::endl;
0089       return Fun4AllReturnCodes::ABORTEVENT;
0090     }
0091     std::cout << "Event No: " << syncobject->EventNumber() << std::endl;
0092   }
0093   if (bcoinfo)
0094   {
0095     if (Verbosity() > 2)
0096     {
0097       std::cout << "prev event: " << bcoinfo->get_previous_evtno() /*<< std::hex*/
0098                 << " bco: " << bcoinfo->get_previous_bco() << std::dec << std::endl;
0099       std::cout << "curr event: " << bcoinfo->get_current_evtno() /*<< std::hex*/
0100                 << " bco: " << bcoinfo->get_current_bco() << std::dec << std::endl;
0101       std::cout << "futu event: " << bcoinfo->get_future_evtno() /*<< std::hex*/
0102                 << " bco: " << bcoinfo->get_future_bco() << std::dec << std::endl;
0103     }
0104     StreamingBcoInfo *streaming_bco_info = findNode::getClass<StreamingBcoInfo>(topNode, "STREAMINGBCOINFO");
0105     if (!streaming_bco_info)
0106     {
0107       std::cout << PHWHERE << " STREAMINGBCOINFO node missing" << std::endl;
0108       return Fun4AllReturnCodes::ABORTEVENT;
0109     }
0110     m_bco = bcoinfo->get_current_bco();
0111     // No longer reading in the raw data for this check, but it should not be necessary
0112     //if (gtm_bco != m_bco) { std::cout << "BCO MISMATCH!!! : gtm_bco : " << gtm_bco << " m_bco " << m_bco << std::endl;}
0113     uint64_t bco_prev = bcoinfo->get_previous_bco();
0114     uint64_t bco_futu = bcoinfo->get_future_bco();
0115     uint64_t bco_diff_prev = m_bco - bco_prev;
0116     uint64_t bco_diff_futu = bco_futu - m_bco;
0117 
0118     // special case if BCO is within 20 of previous BCO?
0119     if (bco_diff_prev < m_default_positive_window_length)
0120     {
0121       m_usable_bco_tag = true;
0122     }
0123     else
0124     {
0125       m_usable_bco_tag = false;
0126     }
0127     if (bco_diff_futu < m_default_positive_window_length)
0128     {
0129       // double check boundaries for overlap!!
0130       m_bco_streaming_window = std::make_pair(get_bco() - m_default_negative_window_length, bco_futu - m_default_negative_window_length + 1);
0131     }
0132     else
0133     {
0134       m_bco_streaming_window = std::make_pair(get_bco() - m_default_negative_window_length, get_bco() + m_default_positive_window_length);
0135     }
0136     if (Verbosity() > 2)
0137     {
0138       std::cout << "bco_diff_prev : " << bco_diff_prev << std::endl;
0139       std::cout << "bco_diff_futu : " << bco_diff_futu << std::endl;
0140     }
0141     h_bco_diff->Fill(bco_diff_prev);
0142     h_bco_tag->Fill(m_usable_bco_tag);
0143     // There is no longer a need to read in the .evt file here, so we won't have access to this info. If we wish to access it we can in a different module
0144     //for (int bit=0; bit<trigbits; ++bit)
0145     //{
0146     //  bool trigger_fired = ((gl1_scaledvec >> static_cast<uint64_t>(bit)) & 0x1U) == 0x1U;
0147     //  if (trigger_fired)
0148     //  {
0149     //    h_bco_diff_trigbits[bit]->Fill(bco_diff_prev);
0150     //  }
0151     //}
0152 
0153     streaming_bco_info->set_bco(get_bco());
0154     streaming_bco_info->set_usable_bco_tag(get_usable_bco_tag());
0155     streaming_bco_info->set_bco_streaming_window(get_bco_streaming_window());
0156     if (syncobject)
0157     {
0158       streaming_bco_info->set_evtno(syncobject->EventNumber());
0159     }
0160   }
0161   return Fun4AllReturnCodes::EVENT_OK;
0162 }