From 3e03d3b0b224f042d1943ad5a9ffab68ccb485e0 Mon Sep 17 00:00:00 2001 From: Dillon Fitzgerald Date: Wed, 24 Jun 2026 19:46:07 -0400 Subject: [PATCH 1/3] Separate luminosity calculation into its own Subsys reco module (StreamingLumiReco) --- offline/packages/bcolumicount/Makefile.am | 12 +- .../bcolumicount/StreamingBcoCheck.cc | 69 ++++++ .../packages/bcolumicount/StreamingBcoCheck.h | 25 ++ .../bcolumicount/StreamingBcoLumiCheck.h | 26 --- .../packages/bcolumicount/StreamingBcoReco.cc | 218 ++++++++++++++++++ .../packages/bcolumicount/StreamingBcoReco.h | 53 +++++ ...gBcoLumiCheck.cc => StreamingLumiCheck.cc} | 17 +- .../bcolumicount/StreamingLumiCheck.h | 26 +++ .../packages/bcolumicount/StreamingLumiInfo.h | 10 + .../bcolumicount/StreamingLumiInfov1.h | 14 +- ...ingBcoLumiReco.cc => StreamingLumiReco.cc} | 88 ++----- ...amingBcoLumiReco.h => StreamingLumiReco.h} | 33 +-- 12 files changed, 464 insertions(+), 127 deletions(-) create mode 100644 offline/packages/bcolumicount/StreamingBcoCheck.cc create mode 100644 offline/packages/bcolumicount/StreamingBcoCheck.h delete mode 100644 offline/packages/bcolumicount/StreamingBcoLumiCheck.h create mode 100644 offline/packages/bcolumicount/StreamingBcoReco.cc create mode 100644 offline/packages/bcolumicount/StreamingBcoReco.h rename offline/packages/bcolumicount/{StreamingBcoLumiCheck.cc => StreamingLumiCheck.cc} (85%) create mode 100644 offline/packages/bcolumicount/StreamingLumiCheck.h rename offline/packages/bcolumicount/{StreamingBcoLumiReco.cc => StreamingLumiReco.cc} (70%) rename offline/packages/bcolumicount/{StreamingBcoLumiReco.h => StreamingLumiReco.h} (65%) diff --git a/offline/packages/bcolumicount/Makefile.am b/offline/packages/bcolumicount/Makefile.am index fb546ed53a..297fc5f840 100644 --- a/offline/packages/bcolumicount/Makefile.am +++ b/offline/packages/bcolumicount/Makefile.am @@ -44,8 +44,10 @@ pkginclude_HEADERS = \ StreamingBcoInfov1.h \ StreamingLumiInfo.h \ StreamingLumiInfov1.h \ - StreamingBcoLumiReco.h \ - StreamingBcoLumiCheck.h + StreamingBcoReco.h \ + StreamingBcoCheck.h \ + StreamingLumiReco.h \ + StreamingLumiCheck.h libbcolumicount_io_la_SOURCES = \ @@ -59,8 +61,10 @@ libbcolumicount_io_la_SOURCES = \ libbcolumicount_la_SOURCES = \ BcoLumiReco.cc \ - StreamingBcoLumiReco.cc \ - StreamingBcoLumiCheck.cc + StreamingBcoReco.cc \ + StreamingBcoCheck.cc \ + StreamingLumiReco.cc \ + StreamingLumiCheck.cc BUILT_SOURCES = testexternals.cc diff --git a/offline/packages/bcolumicount/StreamingBcoCheck.cc b/offline/packages/bcolumicount/StreamingBcoCheck.cc new file mode 100644 index 0000000000..e18dfb7333 --- /dev/null +++ b/offline/packages/bcolumicount/StreamingBcoCheck.cc @@ -0,0 +1,69 @@ +#include "StreamingBcoCheck.h" + +//#include "BcoInfo.h" +#include "StreamingBcoInfo.h" +#include "StreamingLumiInfo.h" +//#include "BcoStreamingLumiInfov1.h" + + +#include +#include + +#include + +#include +#include // for SubsysReco +#include +#include + + +#include +#include // for PHNode +#include // for PHNodeIterator +#include +#include // for PHWHERE + + +#include + +StreamingBcoCheck::StreamingBcoCheck(const std::string &name) + : SubsysReco(name) +{ + return; +} + +int StreamingBcoCheck::Init(PHCompositeNode *topNode) +{ + int iret = CreateNodeTree(topNode); + + return iret; +} + +int StreamingBcoCheck::CreateNodeTree(PHCompositeNode *topNode) +{ + PHNodeIterator iter(topNode); + PHCompositeNode *dstNode; + dstNode = dynamic_cast(iter.findFirst("PHCompositeNode", "DST")); + if (!dstNode) + { + std::cout << PHWHERE << " DST Node is missing doing nothing" << std::endl; + return Fun4AllReturnCodes::ABORTRUN; + } + return Fun4AllReturnCodes::EVENT_OK; +} + +int StreamingBcoCheck::process_event(PHCompositeNode *topNode) +{ + StreamingBcoInfo *streaming_bco_info = findNode::getClass(topNode, "STREAMINGBCOINFO"); + if (streaming_bco_info) + { + if (Verbosity() > 1) + { + std::cout << "bco : " << streaming_bco_info->get_bco() << std::endl; + std::cout << "usable bco tag : " << streaming_bco_info->get_usable_bco_tag() << std::endl; + std::cout << "bco streaming window : (" << streaming_bco_info->get_bco_streaming_window().first << ", " << streaming_bco_info->get_bco_streaming_window().second << ")" << std::endl; + } + } + + return Fun4AllReturnCodes::EVENT_OK; +} \ No newline at end of file diff --git a/offline/packages/bcolumicount/StreamingBcoCheck.h b/offline/packages/bcolumicount/StreamingBcoCheck.h new file mode 100644 index 0000000000..5def0f329c --- /dev/null +++ b/offline/packages/bcolumicount/StreamingBcoCheck.h @@ -0,0 +1,25 @@ +#ifndef BCOLUMICOUNT_STREAMINGBCOCHECK_H +#define BCOLUMICOUNT_STREAMINGBCOCHECK_H + +#include +#include + +#include + +#include + + +class StreamingBcoCheck : public SubsysReco +{ + public: + StreamingBcoCheck(const std::string &name = "BCOCHECKSTREAMINGOUTPUT"); + ~StreamingBcoCheck() override = default; + + int Init(PHCompositeNode *topNode) override; + int process_event(PHCompositeNode *topNode) override; + + private: + static int CreateNodeTree(PHCompositeNode *topNode); +}; + +#endif // BCOLUMICOUNT_STREAMINGBCOCHECK_H diff --git a/offline/packages/bcolumicount/StreamingBcoLumiCheck.h b/offline/packages/bcolumicount/StreamingBcoLumiCheck.h deleted file mode 100644 index 579ca524c0..0000000000 --- a/offline/packages/bcolumicount/StreamingBcoLumiCheck.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef BCOLUMICOUNT_STREAMINGBCOLUMICHECK_H -#define BCOLUMICOUNT_STREAMINGBCOLUMICHECK_H - -#include -#include - -#include - -#include - - -class StreamingBcoLumiCheck : public SubsysReco -{ - public: - StreamingBcoLumiCheck(const std::string &name = "BCOLUMICHECKSTREAMINGOUTPUT"); - ~StreamingBcoLumiCheck() override = default; - - int Init(PHCompositeNode *topNode) override; - int InitRun(PHCompositeNode *topNode) override; - int process_event(PHCompositeNode *topNode) override; - - private: - static int CreateNodeTree(PHCompositeNode *topNode); -}; - -#endif // BCOLUMICOUNT_STREAMINGBCOLUMICHECK_H diff --git a/offline/packages/bcolumicount/StreamingBcoReco.cc b/offline/packages/bcolumicount/StreamingBcoReco.cc new file mode 100644 index 0000000000..6d37a1ccca --- /dev/null +++ b/offline/packages/bcolumicount/StreamingBcoReco.cc @@ -0,0 +1,218 @@ +#include "StreamingBcoReco.h" + +#include "BcoInfo.h" +#include "StreamingBcoInfo.h" +#include "StreamingBcoInfov1.h" + + +#include +#include + +#include + +#include +#include // for SubsysReco +#include +#include + + +#include +#include // for PHNode +#include // for PHNodeIterator +#include +#include // for PHWHERE + +#include +#include +#include // for Packet + +#include + +#include + +StreamingBcoReco::StreamingBcoReco(const std::string &name) + : SubsysReco(name) +{ + hm = new Fun4AllHistoManager("bco_histos"); + Fun4AllServer *se = Fun4AllServer::instance(); + se->registerHistoManager(hm); + return; +} + +int StreamingBcoReco::Init(PHCompositeNode *topNode) +{ + int iret = CreateNodeTree(topNode); + h_bco_diff = new TH1I("h_bco_diff", ";bco diff;", 3500, 0, 3500); + std::string hist_name = "h_bco_diff_bit"; + for (int bit=0; bitregisterHisto(h_bco_diff_trigbits[bit]); + } + h_bco_tag = new TH1I("h_bco_tag", ";usable bco tag;", 2, -0.5, 1.5); + hm->registerHisto(h_bco_diff); + hm->registerHisto(h_bco_tag); + + return iret; +} + +// Do we even need to include this now that the lumi calculatin has been separated? Or should I remove `InitRun` entirely? +int StreamingBcoReco::InitRun(PHCompositeNode * topNode) +{ + PHNodeIterator iter(topNode); + PHCompositeNode *runNode; + runNode = dynamic_cast(iter.findFirst("PHCompositeNode", "RUN")); + if (!runNode) + { + std::cout << PHWHERE << " Run Node is missing doing nothing" << std::endl; + return Fun4AllReturnCodes::ABORTRUN; + } + return Fun4AllReturnCodes::EVENT_OK; +} + +int StreamingBcoReco::CreateNodeTree(PHCompositeNode *topNode) +{ + PHNodeIterator iter(topNode); + PHCompositeNode *dstNode; + dstNode = dynamic_cast(iter.findFirst("PHCompositeNode", "DST")); + if (!dstNode) + { + std::cout << PHWHERE << " DST Node is missing doing nothing" << std::endl; + return Fun4AllReturnCodes::ABORTRUN; + } + StreamingBcoInfo *streaming_bco_info = findNode::getClass(topNode, "STREAMINGBCOINFO"); + if (!streaming_bco_info) + { + streaming_bco_info = new StreamingBcoInfov1(); + PHIODataNode *bconode = new PHIODataNode(streaming_bco_info, "STREAMINGBCOINFO", "PHObject"); + dstNode->addNode(bconode); + } + return Fun4AllReturnCodes::EVENT_OK; +} + +int StreamingBcoReco::process_event(PHCompositeNode *topNode) +{ + BcoInfo *bcoinfo = findNode::getClass(topNode, "BCOINFO"); + SyncObject *syncobject = findNode::getClass(topNode, syncdefs::SYNCNODENAME); + //Gl1Packet *gl1packet = findNode::getClass(topNode, 14001); + Event *evt = findNode::getClass(topNode, "PRDF"); + if (evt) + { + if (Verbosity() > 2) + { + evt->identify(); + } + if (evt->getEvtType() != DATAEVENT) + { + return Fun4AllReturnCodes::ABORTEVENT; + } + Packet *packet = evt->getPacket(14001); + if (!packet) + { + if (Verbosity() > 0) + { + std::cout << "no gl1 packet 14001" << std::endl; + evt->identify(); + } + return Fun4AllReturnCodes::ABORTEVENT; + } + uint64_t gtm_bco = packet->lValue(0, "BCO"); + uint64_t gl1_scaledvec = packet->lValue(0, "ScaledVector"); + //uint64_t gl1_livevec = packet->lValue(0, "TriggerVector"); + + int bunchno = packet->lValue(0,"BunchNumber"); + if (bunchno < 0 || bunchno >= m_bunches) + { + if (Verbosity() > 0) + { + std::cout << PHWHERE << " invalid bunch number: " << bunchno << std::endl; + } + delete packet; + return Fun4AllReturnCodes::ABORTEVENT; + } + + delete packet; + + if (Verbosity() > 2) + { + if (!syncobject) + { + std::cout << PHWHERE << " SyncObject missing" << std::endl; + return Fun4AllReturnCodes::ABORTEVENT; + } + std::cout << "Event No: " << syncobject->EventNumber() /*<< std::hex*/ + << " gl1 bco: " << gtm_bco < 2) + { + std::cout << "prev event: " << bcoinfo->get_previous_evtno() /*<< std::hex*/ + << " bco: " << bcoinfo->get_previous_bco() << std::dec << std::endl; + std::cout << "curr event: " << bcoinfo->get_current_evtno() /*<< std::hex*/ + << " bco: " << bcoinfo->get_current_bco() << std::dec << std::endl; + std::cout << "futu event: " << bcoinfo->get_future_evtno() /*<< std::hex*/ + << " bco: " << bcoinfo->get_future_bco() << std::dec << std::endl; + } + + StreamingBcoInfo *streaming_bco_info = findNode::getClass(topNode, "STREAMINGBCOINFO"); + if (!streaming_bco_info) + { + std::cout << PHWHERE << " STREAMINGBCOINFO node missing" << std::endl; + return Fun4AllReturnCodes::ABORTEVENT; + } + m_bco = bcoinfo->get_current_bco(); + if (gtm_bco != m_bco) { std::cout << "BCO MISMATCH!!! : gtm_bco : " << gtm_bco << " m_bco " << m_bco << std::endl;} + uint64_t bco_prev = bcoinfo->get_previous_bco(); + uint64_t bco_futu = bcoinfo->get_future_bco(); + uint64_t bco_diff_prev = m_bco - bco_prev; + uint64_t bco_diff_futu = bco_futu - m_bco; + + // special case if BCO is within 20 of previous BCO? + if (bco_diff_prev < m_default_positive_window_length) + { + m_usable_bco_tag = true; + } + else + { + m_usable_bco_tag = false; + } + if (bco_diff_futu < m_default_positive_window_length) + { + // double check boundaries for overlap!! + m_bco_streaming_window = std::make_pair(get_bco() - m_default_negative_window_length, bco_futu - m_default_negative_window_length + 1); + } + else + { + m_bco_streaming_window = std::make_pair(get_bco() - m_default_negative_window_length, get_bco() + m_default_positive_window_length); + } + if (Verbosity() > 2) + { + std::cout << "bco_diff_prev : " << bco_diff_prev << std::endl; + std::cout << "bco_diff_futu : " << bco_diff_futu << std::endl; + } + h_bco_diff->Fill(bco_diff_prev); + h_bco_tag->Fill(m_usable_bco_tag); + for (int bit=0; bit> static_cast(bit)) & 0x1U) == 0x1U; + //bool scaled_trigger_fired = ((gl1_scaledvec >> bit) & 0x1U) == 0x1U; + + if (trigger_fired) + { + h_bco_diff_trigbits[bit]->Fill(bco_diff_prev); + } + } + + streaming_bco_info->set_bco(get_bco()); + streaming_bco_info->set_usable_bco_tag(get_usable_bco_tag()); + streaming_bco_info->set_bco_streaming_window(get_bco_streaming_window()); + if (syncobject) + { + streaming_bco_info->set_evtno(syncobject->EventNumber()); + } + } + } + return Fun4AllReturnCodes::EVENT_OK; +} diff --git a/offline/packages/bcolumicount/StreamingBcoReco.h b/offline/packages/bcolumicount/StreamingBcoReco.h new file mode 100644 index 0000000000..0e3ef015c7 --- /dev/null +++ b/offline/packages/bcolumicount/StreamingBcoReco.h @@ -0,0 +1,53 @@ +#ifndef BCOLUMICOUNT_STREAMINGBCORECO_H +#define BCOLUMICOUNT_STREAMINGBCORECO_H + +#include +#include + +#include +#include +#include + +class TH1; + +class StreamingBcoReco : public SubsysReco +{ + public: + StreamingBcoReco(const std::string &name = "STREAMINGBCOLUMIRECO"); + ~StreamingBcoReco() override = default; + + int Init(PHCompositeNode *topNode) override; + int InitRun(PHCompositeNode *topNode) override; + int process_event(PHCompositeNode *topNode) override; + + virtual int get_evtno() const { return m_evtno; } + + virtual uint64_t get_bco() const { return m_bco; } + + virtual bool get_usable_bco_tag() const { return m_usable_bco_tag; } + + virtual std::pair get_bco_streaming_window() const { return m_bco_streaming_window; } + + virtual void set_default_positive_window_length(int val) { m_default_positive_window_length = val; } + virtual void set_default_negative_window_length(int val) { m_default_negative_window_length = val; } + + + + private: + static int CreateNodeTree(PHCompositeNode *topNode); + const int trigbits = 40; + Fun4AllHistoManager *hm = nullptr; + TH1 *h_bco_diff = nullptr; + TH1 *h_bco_diff_trigbits[40] = {nullptr}; + TH1 *h_bco_tag = nullptr; + + uint64_t m_bco{0}; + int m_bunches = 120; + int m_evtno{0}; + bool m_usable_bco_tag = false; + std::pair m_bco_streaming_window; + unsigned int m_default_positive_window_length{340}; + unsigned int m_default_negative_window_length{20}; +}; + +#endif // BCOLUMICOUNT_STREAMINGBCORECO_H diff --git a/offline/packages/bcolumicount/StreamingBcoLumiCheck.cc b/offline/packages/bcolumicount/StreamingLumiCheck.cc similarity index 85% rename from offline/packages/bcolumicount/StreamingBcoLumiCheck.cc rename to offline/packages/bcolumicount/StreamingLumiCheck.cc index f6bf88b584..b2527bb24d 100644 --- a/offline/packages/bcolumicount/StreamingBcoLumiCheck.cc +++ b/offline/packages/bcolumicount/StreamingLumiCheck.cc @@ -1,4 +1,4 @@ -#include "StreamingBcoLumiCheck.h" +#include "StreamingLumiCheck.h" //#include "BcoInfo.h" #include "StreamingBcoInfo.h" @@ -26,20 +26,20 @@ #include -StreamingBcoLumiCheck::StreamingBcoLumiCheck(const std::string &name) +StreamingLumiCheck::StreamingLumiCheck(const std::string &name) : SubsysReco(name) { return; } -int StreamingBcoLumiCheck::Init(PHCompositeNode *topNode) +int StreamingLumiCheck::Init(PHCompositeNode *topNode) { int iret = CreateNodeTree(topNode); return iret; } -int StreamingBcoLumiCheck::InitRun(PHCompositeNode *topNode) +int StreamingLumiCheck::InitRun(PHCompositeNode *topNode) { StreamingLumiInfo *streaming_lumi_info = findNode::getClass(topNode, "STREAMINGLUMIINFO"); if (streaming_lumi_info) @@ -51,7 +51,7 @@ int StreamingBcoLumiCheck::InitRun(PHCompositeNode *topNode) return Fun4AllReturnCodes::EVENT_OK; } -int StreamingBcoLumiCheck::CreateNodeTree(PHCompositeNode *topNode) +int StreamingLumiCheck::CreateNodeTree(PHCompositeNode *topNode) { PHNodeIterator iter(topNode); PHCompositeNode *dstNode; @@ -63,8 +63,8 @@ int StreamingBcoLumiCheck::CreateNodeTree(PHCompositeNode *topNode) } return Fun4AllReturnCodes::EVENT_OK; } - -int StreamingBcoLumiCheck::process_event(PHCompositeNode *topNode) +/* +int StreamingLumiCheck::process_event(PHCompositeNode *topNode) { StreamingBcoInfo *streaming_bco_info = findNode::getClass(topNode, "STREAMINGBCOINFO"); if (streaming_bco_info) @@ -78,4 +78,5 @@ int StreamingBcoLumiCheck::process_event(PHCompositeNode *topNode) } return Fun4AllReturnCodes::EVENT_OK; -} \ No newline at end of file +} +*/ \ No newline at end of file diff --git a/offline/packages/bcolumicount/StreamingLumiCheck.h b/offline/packages/bcolumicount/StreamingLumiCheck.h new file mode 100644 index 0000000000..8fc89ff5e9 --- /dev/null +++ b/offline/packages/bcolumicount/StreamingLumiCheck.h @@ -0,0 +1,26 @@ +#ifndef BCOLUMICOUNT_STREAMINGLUMICHECK_H +#define BCOLUMICOUNT_STREAMINGLUMICHECK_H + +#include +#include + +#include + +#include + + +class StreamingLumiCheck : public SubsysReco +{ + public: + StreamingLumiCheck(const std::string &name = "LUMICHECKSTREAMINGOUTPUT"); + ~StreamingLumiCheck() override = default; + + int Init(PHCompositeNode *topNode) override; + int InitRun(PHCompositeNode *topNode) override; + //int process_event(PHCompositeNode *topNode) override; + + private: + static int CreateNodeTree(PHCompositeNode *topNode); +}; + +#endif // BCOLUMICOUNT_STREAMINGLUMICHECK_H diff --git a/offline/packages/bcolumicount/StreamingLumiInfo.h b/offline/packages/bcolumicount/StreamingLumiInfo.h index 1644b91d3b..9bea6a3dff 100644 --- a/offline/packages/bcolumicount/StreamingLumiInfo.h +++ b/offline/packages/bcolumicount/StreamingLumiInfo.h @@ -8,6 +8,7 @@ #include #include #include +#include /// @@ -27,6 +28,15 @@ class StreamingLumiInfo : public PHObject /// isValid returns non zero if object contains valid data //int isValid() const override; + virtual const std::array get_bunchnumber_lumi_raw() const { return std::array{}; } + virtual void set_bunchnumber_lumi_raw(const std::array& /*vals*/) { return; } + + virtual const std::array get_bunchnumber_lumi_live() const { return std::array{}; } + virtual void set_bunchnumber_lumi_live(const std::array& /*vals*/) { return; } + + virtual const std::array get_bunchnumber_lumi_scaled() const { return std::array{}; } + virtual void set_bunchnumber_lumi_scaled(const std::array& /*vals*/) { return; } + virtual double get_lumi_raw() const { return 0; } virtual void set_lumi_raw(double /*val*/) { return; } diff --git a/offline/packages/bcolumicount/StreamingLumiInfov1.h b/offline/packages/bcolumicount/StreamingLumiInfov1.h index b18a8a8c89..b8993c1f8d 100644 --- a/offline/packages/bcolumicount/StreamingLumiInfov1.h +++ b/offline/packages/bcolumicount/StreamingLumiInfov1.h @@ -28,6 +28,15 @@ class StreamingLumiInfov1 : public StreamingLumiInfo /// isValid returns non zero if object contains valid data //int isValid() const override; + virtual const std::array get_bunchnumber_lumi_raw() const override { return m_bunchnumber_lumi_raw; } + virtual void set_bunchnumber_lumi_raw(const std::array& vals) override { m_bunchnumber_lumi_raw = vals; } + + virtual const std::array get_bunchnumber_lumi_live() const override { return m_bunchnumber_lumi_live; } + virtual void set_bunchnumber_lumi_live(const std::array& vals) override { m_bunchnumber_lumi_live = vals; } + + virtual const std::array get_bunchnumber_lumi_scaled() const override { return m_bunchnumber_lumi_scaled; } + virtual void set_bunchnumber_lumi_scaled(const std::array& vals) override { m_bunchnumber_lumi_scaled = vals; } + virtual double get_lumi_raw() const override { return m_lumi_raw; } virtual void set_lumi_raw(double val) override { m_lumi_raw = val; } @@ -39,12 +48,15 @@ class StreamingLumiInfov1 : public StreamingLumiInfo private: + std::array m_bunchnumber_lumi_raw{0.}; + std::array m_bunchnumber_lumi_live{0.}; + std::array m_bunchnumber_lumi_scaled{0.}; + double m_lumi_raw{0.}; double m_lumi_live{0.}; double m_lumi_scaled{0.}; - ClassDefOverride(StreamingLumiInfov1, 1) }; diff --git a/offline/packages/bcolumicount/StreamingBcoLumiReco.cc b/offline/packages/bcolumicount/StreamingLumiReco.cc similarity index 70% rename from offline/packages/bcolumicount/StreamingBcoLumiReco.cc rename to offline/packages/bcolumicount/StreamingLumiReco.cc index 1e3c66d47f..57068b838c 100644 --- a/offline/packages/bcolumicount/StreamingBcoLumiReco.cc +++ b/offline/packages/bcolumicount/StreamingLumiReco.cc @@ -1,8 +1,6 @@ -#include "StreamingBcoLumiReco.h" +#include "StreamingLumiReco.h" #include "BcoInfo.h" -#include "StreamingBcoInfo.h" -#include "StreamingBcoInfov1.h" #include "StreamingLumiInfo.h" #include "StreamingLumiInfov1.h" @@ -23,6 +21,8 @@ #include // for PHNodeIterator #include #include // for PHWHERE +#include // for MDB_NS_xsec + #include #include @@ -32,34 +32,19 @@ #include -StreamingBcoLumiReco::StreamingBcoLumiReco(const std::string &name) +StreamingLumiReco::StreamingLumiReco(const std::string &name) : SubsysReco(name) { - hm = new Fun4AllHistoManager("bco_histos"); - Fun4AllServer *se = Fun4AllServer::instance(); - se->registerHistoManager(hm); return; } -int StreamingBcoLumiReco::Init(PHCompositeNode *topNode) +int StreamingLumiReco::Init(PHCompositeNode *topNode) { int iret = CreateNodeTree(topNode); - h_bco_diff = new TH1I("h_bco_diff", ";bco diff;", 3500, 0, 3500); - std::string hist_name = "h_bco_diff_bit"; - for (int bit=0; bitregisterHisto(h_bco_diff_trigbits[bit]); - } - h_bco_tag = new TH1I("h_bco_tag", ";usable bco tag;", 2, -0.5, 1.5); - hm->registerHisto(h_bco_diff); - hm->registerHisto(h_bco_tag); - return iret; } -int StreamingBcoLumiReco::InitRun(PHCompositeNode * topNode) +int StreamingLumiReco::InitRun(PHCompositeNode * topNode) { PHNodeIterator iter(topNode); PHCompositeNode *runNode; @@ -79,7 +64,7 @@ int StreamingBcoLumiReco::InitRun(PHCompositeNode * topNode) return Fun4AllReturnCodes::EVENT_OK; } -int StreamingBcoLumiReco::CreateNodeTree(PHCompositeNode *topNode) +int StreamingLumiReco::CreateNodeTree(PHCompositeNode *topNode) { PHNodeIterator iter(topNode); PHCompositeNode *dstNode; @@ -89,17 +74,10 @@ int StreamingBcoLumiReco::CreateNodeTree(PHCompositeNode *topNode) std::cout << PHWHERE << " DST Node is missing doing nothing" << std::endl; return Fun4AllReturnCodes::ABORTRUN; } - StreamingBcoInfo *streaming_bco_info = findNode::getClass(topNode, "STREAMINGBCOINFO"); - if (!streaming_bco_info) - { - streaming_bco_info = new StreamingBcoInfov1(); - PHIODataNode *bconode = new PHIODataNode(streaming_bco_info, "STREAMINGBCOINFO", "PHObject"); - dstNode->addNode(bconode); - } return Fun4AllReturnCodes::EVENT_OK; } -int StreamingBcoLumiReco::process_event(PHCompositeNode *topNode) +int StreamingLumiReco::process_event(PHCompositeNode *topNode) { BcoInfo *bcoinfo = findNode::getClass(topNode, "BCOINFO"); SyncObject *syncobject = findNode::getClass(topNode, syncdefs::SYNCNODENAME); @@ -125,9 +103,7 @@ int StreamingBcoLumiReco::process_event(PHCompositeNode *topNode) } return Fun4AllReturnCodes::ABORTEVENT; } - uint64_t gtm_bco = packet->lValue(0, "BCO"); - uint64_t gl1_scaledvec = packet->lValue(0, "ScaledVector"); - //uint64_t gl1_livevec = packet->lValue(0, "TriggerVector"); + uint64_t gtm_bco = packet->lValue(0, "BCO"); int bunchno = packet->lValue(0,"BunchNumber"); if (bunchno < 0 || bunchno >= m_bunches) @@ -175,12 +151,6 @@ int StreamingBcoLumiReco::process_event(PHCompositeNode *topNode) << " bco: " << bcoinfo->get_future_bco() << std::dec << std::endl; } - StreamingBcoInfo *streaming_bco_info = findNode::getClass(topNode, "STREAMINGBCOINFO"); - if (!streaming_bco_info) - { - std::cout << PHWHERE << " STREAMINGBCOINFO node missing" << std::endl; - return Fun4AllReturnCodes::ABORTEVENT; - } m_bco = bcoinfo->get_current_bco(); if (gtm_bco != m_bco) { std::cout << "BCO MISMATCH!!! : gtm_bco : " << gtm_bco << " m_bco " << m_bco << std::endl;} uint64_t bco_prev = bcoinfo->get_previous_bco(); @@ -200,29 +170,17 @@ int StreamingBcoLumiReco::process_event(PHCompositeNode *topNode) if (bco_diff_futu < m_default_positive_window_length) { // double check boundaries for overlap!! - m_bco_streaming_window = std::make_pair(get_bco() - m_default_negative_window_length, bco_futu - m_default_negative_window_length + 1); + m_bco_streaming_window = std::make_pair(m_bco - m_default_negative_window_length, bco_futu - m_default_negative_window_length + 1); } else { - m_bco_streaming_window = std::make_pair(get_bco() - m_default_negative_window_length, get_bco() + m_default_positive_window_length); + m_bco_streaming_window = std::make_pair(m_bco - m_default_negative_window_length, m_bco + m_default_positive_window_length); } if (Verbosity() > 2) { - std::cout << "bco_diff_prev : " << bco_diff_prev << std::endl; std::cout << "bco_diff_futu : " << bco_diff_futu << std::endl; } - h_bco_diff->Fill(bco_diff_prev); - h_bco_tag->Fill(m_usable_bco_tag); - for (int bit=0; bit> static_cast(bit)) & 0x1U) == 0x1U; - //bool scaled_trigger_fired = ((gl1_scaledvec >> bit) & 0x1U) == 0x1U; - if (trigger_fired) - { - h_bco_diff_trigbits[bit]->Fill(bco_diff_prev); - } - } // Double check Zhiwan's logic for assigning the adjusted bunch! int lower = m_bco_streaming_window.first - m_bco; int upper = m_bco_streaming_window.second - m_bco; @@ -250,27 +208,19 @@ int StreamingBcoLumiReco::process_event(PHCompositeNode *topNode) // m_bunchnumber_crossings[adjusted_bunch] += 1; //} } - - streaming_bco_info->set_bco(get_bco()); - streaming_bco_info->set_usable_bco_tag(get_usable_bco_tag()); - streaming_bco_info->set_bco_streaming_window(get_bco_streaming_window()); - if (syncobject) - { - streaming_bco_info->set_evtno(syncobject->EventNumber()); - } } } return Fun4AllReturnCodes::EVENT_OK; } -int StreamingBcoLumiReco::EndRun(int /*runnumber*/) +int StreamingLumiReco::EndRun(int /*runnumber*/) { uint64_t rawgl1scalers_per_bunch = m_rawgl1scaler/120.; for (int i=0; iset_bunchnumber_lumi_raw(get_bunchnumber_lumi_raw()); + m_streaming_lumi_info->set_bunchnumber_lumi_live(get_bunchnumber_lumi_live()); + m_streaming_lumi_info->set_bunchnumber_lumi_scaled(get_bunchnumber_lumi_scaled()); + m_streaming_lumi_info->set_lumi_raw(get_lumi_raw()); m_streaming_lumi_info->set_lumi_live(get_lumi_live()); m_streaming_lumi_info->set_lumi_scaled(get_lumi_scaled()); + if (Verbosity() > 1) { - std::cout << "MBD xsec : " << m_xsec_MBDNS << std::endl; + std::cout << "MBD xsec : " << sphenix_constants::m_xsec_MBDNS << std::endl; std::cout << "total lumi (raw) : " << m_lumi_raw << std::endl; } diff --git a/offline/packages/bcolumicount/StreamingBcoLumiReco.h b/offline/packages/bcolumicount/StreamingLumiReco.h similarity index 65% rename from offline/packages/bcolumicount/StreamingBcoLumiReco.h rename to offline/packages/bcolumicount/StreamingLumiReco.h index 77e4e27f0e..65c763d545 100644 --- a/offline/packages/bcolumicount/StreamingBcoLumiReco.h +++ b/offline/packages/bcolumicount/StreamingLumiReco.h @@ -1,5 +1,5 @@ -#ifndef BCOLUMICOUNT_STREAMINGBCOLUMIRECO_H -#define BCOLUMICOUNT_STREAMINGBCOLUMIRECO_H +#ifndef BCOLUMICOUNT_STREAMINGLUMIRECO_H +#define BCOLUMICOUNT_STREAMINGLUMIRECO_H #include "StreamingLumiInfo.h" @@ -12,24 +12,20 @@ class TH1; -class StreamingBcoLumiReco : public SubsysReco +class StreamingLumiReco : public SubsysReco { public: - StreamingBcoLumiReco(const std::string &name = "STREAMINGBCOLUMIRECO"); - ~StreamingBcoLumiReco() override = default; + StreamingLumiReco(const std::string &name = "STREAMINGBCOLUMIRECO"); + ~StreamingLumiReco() override = default; int Init(PHCompositeNode *topNode) override; int InitRun(PHCompositeNode *topNode) override; int process_event(PHCompositeNode *topNode) override; int EndRun(const int runnumber) override; - virtual uint64_t get_bco() const { return m_bco; } - - virtual int get_evtno() const { return m_evtno; } - - virtual bool get_usable_bco_tag() const { return m_usable_bco_tag; } - - virtual std::pair get_bco_streaming_window() const { return m_bco_streaming_window; } + virtual const std::array get_bunchnumber_lumi_raw() const { return m_bunchnumber_lumi_raw; } + virtual const std::array get_bunchnumber_lumi_live() const { return m_bunchnumber_lumi_live; } + virtual const std::array get_bunchnumber_lumi_scaled() const { return m_bunchnumber_lumi_scaled; } virtual double get_lumi_raw() const { return m_lumi_raw; } virtual double get_lumi_live() const { return m_lumi_live; } @@ -39,24 +35,17 @@ class StreamingBcoLumiReco : public SubsysReco virtual void set_default_negative_window_length(int val) { m_default_negative_window_length = val; } - private: static int CreateNodeTree(PHCompositeNode *topNode); - const int trigbits = 40; - Fun4AllHistoManager *hm = nullptr; - TH1 *h_bco_diff = nullptr; - TH1 *h_bco_diff_trigbits[40] = {nullptr}; - TH1 *h_bco_tag = nullptr; - uint64_t m_bco{0}; int m_bunches = 120; - int m_evtno{0}; + uint64_t m_bco{0}; bool m_usable_bco_tag = false; std::pair m_bco_streaming_window; unsigned int m_default_positive_window_length{340}; unsigned int m_default_negative_window_length{20}; - double m_xsec_MBDNS = 24.07*1e9; //convert to pb from Vernier scan DOUBLE CHECK VALUE! + //double m_xsec_MBDNS = 24.07*1e9; //convert to pb from Vernier scan DOUBLE CHECK VALUE! uint64_t m_rawgl1scaler{0}; @@ -78,4 +67,4 @@ class StreamingBcoLumiReco : public SubsysReco }; -#endif // BCOLUMICOUNT_STREAMINGBCOLUMIRECO_H +#endif // BCOLUMICOUNT_STREAMINGLUMIRECO_H From 1ecfb4b1bbcfc1dafa05a83eea82500a57dc2a45 Mon Sep 17 00:00:00 2001 From: Dillon Fitzgerald Date: Wed, 24 Jun 2026 21:01:31 -0400 Subject: [PATCH 2/3] Read output of StreamingBcoReco into StreamingLumiReco rather than output of BcoLumiReco. Update lumi calculation code accordingly. --- .../bcolumicount/StreamingLumiReco.cc | 68 +++---------------- .../packages/bcolumicount/StreamingLumiReco.h | 3 - 2 files changed, 9 insertions(+), 62 deletions(-) diff --git a/offline/packages/bcolumicount/StreamingLumiReco.cc b/offline/packages/bcolumicount/StreamingLumiReco.cc index 57068b838c..d78aa69c0e 100644 --- a/offline/packages/bcolumicount/StreamingLumiReco.cc +++ b/offline/packages/bcolumicount/StreamingLumiReco.cc @@ -1,6 +1,6 @@ #include "StreamingLumiReco.h" -#include "BcoInfo.h" +#include "StreamingBcoInfo.h" #include "StreamingLumiInfo.h" #include "StreamingLumiInfov1.h" @@ -79,9 +79,7 @@ int StreamingLumiReco::CreateNodeTree(PHCompositeNode *topNode) int StreamingLumiReco::process_event(PHCompositeNode *topNode) { - BcoInfo *bcoinfo = findNode::getClass(topNode, "BCOINFO"); - SyncObject *syncobject = findNode::getClass(topNode, syncdefs::SYNCNODENAME); - //Gl1Packet *gl1packet = findNode::getClass(topNode, 14001); + StreamingBcoInfo *streaming_bcoinfo = findNode::getClass(topNode, "STREAMINGBCOINFO"); Event *evt = findNode::getClass(topNode, "PRDF"); if (evt) { @@ -129,69 +127,21 @@ int StreamingLumiReco::process_event(PHCompositeNode *topNode) delete packet; - if (Verbosity() > 2) - { - if (!syncobject) - { - std::cout << PHWHERE << " SyncObject missing" << std::endl; - return Fun4AllReturnCodes::ABORTEVENT; - } - std::cout << "Event No: " << syncobject->EventNumber() /*<< std::hex*/ - << " gl1 bco: " << gtm_bco < 2) - { - std::cout << "prev event: " << bcoinfo->get_previous_evtno() /*<< std::hex*/ - << " bco: " << bcoinfo->get_previous_bco() << std::dec << std::endl; - std::cout << "curr event: " << bcoinfo->get_current_evtno() /*<< std::hex*/ - << " bco: " << bcoinfo->get_current_bco() << std::dec << std::endl; - std::cout << "futu event: " << bcoinfo->get_future_evtno() /*<< std::hex*/ - << " bco: " << bcoinfo->get_future_bco() << std::dec << std::endl; - } - - m_bco = bcoinfo->get_current_bco(); - if (gtm_bco != m_bco) { std::cout << "BCO MISMATCH!!! : gtm_bco : " << gtm_bco << " m_bco " << m_bco << std::endl;} - uint64_t bco_prev = bcoinfo->get_previous_bco(); - uint64_t bco_futu = bcoinfo->get_future_bco(); - uint64_t bco_diff_prev = m_bco - bco_prev; - uint64_t bco_diff_futu = bco_futu - m_bco; - - // special case if BCO is within 20 of previous BCO? - if (bco_diff_prev < m_default_positive_window_length) - { - m_usable_bco_tag = true; - } - else - { - m_usable_bco_tag = false; - } - if (bco_diff_futu < m_default_positive_window_length) - { - // double check boundaries for overlap!! - m_bco_streaming_window = std::make_pair(m_bco - m_default_negative_window_length, bco_futu - m_default_negative_window_length + 1); - } - else - { - m_bco_streaming_window = std::make_pair(m_bco - m_default_negative_window_length, m_bco + m_default_positive_window_length); - } - if (Verbosity() > 2) - { - std::cout << "bco_diff_futu : " << bco_diff_futu << std::endl; - } + if (gtm_bco != streaming_bcoinfo->get_bco()) { std::cout << "BCO MISMATCH!!! : gtm_bco : " << gtm_bco << " bco " << streaming_bcoinfo->get_bco() << std::endl;} // Double check Zhiwan's logic for assigning the adjusted bunch! - int lower = m_bco_streaming_window.first - m_bco; - int upper = m_bco_streaming_window.second - m_bco; + int lower = streaming_bcoinfo->get_bco_streaming_window().first - streaming_bcoinfo->get_bco(); + int upper = streaming_bcoinfo->get_bco_streaming_window().second - streaming_bcoinfo->get_bco(); for(int i = lower; i< upper;i++) { int adjusted_bunch = bunchno + i; - while (adjusted_bunch < 0) + while (adjusted_bunch < 0) { adjusted_bunch += 120; } - while (adjusted_bunch > 119) + while (adjusted_bunch > 119) { adjusted_bunch -= 120; } @@ -199,7 +149,7 @@ int StreamingLumiReco::process_event(PHCompositeNode *topNode) if (adjusted_bunch>110) { continue; } // Make sure this is the correct way to count crossings! Need to zero out for each run! - if(i!=0 || m_usable_bco_tag) + if(i!=0 || streaming_bcoinfo->get_usable_bco_tag()) { m_bunchnumber_crossings[adjusted_bunch] += 1; } diff --git a/offline/packages/bcolumicount/StreamingLumiReco.h b/offline/packages/bcolumicount/StreamingLumiReco.h index 65c763d545..7f74a30367 100644 --- a/offline/packages/bcolumicount/StreamingLumiReco.h +++ b/offline/packages/bcolumicount/StreamingLumiReco.h @@ -39,9 +39,6 @@ class StreamingLumiReco : public SubsysReco static int CreateNodeTree(PHCompositeNode *topNode); int m_bunches = 120; - uint64_t m_bco{0}; - bool m_usable_bco_tag = false; - std::pair m_bco_streaming_window; unsigned int m_default_positive_window_length{340}; unsigned int m_default_negative_window_length{20}; From 0fa4abb137678f309e43673773ce0943f5284b66 Mon Sep 17 00:00:00 2001 From: Dillon Fitzgerald Date: Sat, 27 Jun 2026 14:43:06 -0400 Subject: [PATCH 3/3] Remove InitRun from StreamingBcoReco --- offline/packages/bcolumicount/StreamingBcoReco.cc | 14 -------------- offline/packages/bcolumicount/StreamingBcoReco.h | 1 - 2 files changed, 15 deletions(-) diff --git a/offline/packages/bcolumicount/StreamingBcoReco.cc b/offline/packages/bcolumicount/StreamingBcoReco.cc index 6d37a1ccca..262750fcd5 100644 --- a/offline/packages/bcolumicount/StreamingBcoReco.cc +++ b/offline/packages/bcolumicount/StreamingBcoReco.cc @@ -57,20 +57,6 @@ int StreamingBcoReco::Init(PHCompositeNode *topNode) return iret; } -// Do we even need to include this now that the lumi calculatin has been separated? Or should I remove `InitRun` entirely? -int StreamingBcoReco::InitRun(PHCompositeNode * topNode) -{ - PHNodeIterator iter(topNode); - PHCompositeNode *runNode; - runNode = dynamic_cast(iter.findFirst("PHCompositeNode", "RUN")); - if (!runNode) - { - std::cout << PHWHERE << " Run Node is missing doing nothing" << std::endl; - return Fun4AllReturnCodes::ABORTRUN; - } - return Fun4AllReturnCodes::EVENT_OK; -} - int StreamingBcoReco::CreateNodeTree(PHCompositeNode *topNode) { PHNodeIterator iter(topNode); diff --git a/offline/packages/bcolumicount/StreamingBcoReco.h b/offline/packages/bcolumicount/StreamingBcoReco.h index 0e3ef015c7..b5ff71d6e7 100644 --- a/offline/packages/bcolumicount/StreamingBcoReco.h +++ b/offline/packages/bcolumicount/StreamingBcoReco.h @@ -17,7 +17,6 @@ class StreamingBcoReco : public SubsysReco ~StreamingBcoReco() override = default; int Init(PHCompositeNode *topNode) override; - int InitRun(PHCompositeNode *topNode) override; int process_event(PHCompositeNode *topNode) override; virtual int get_evtno() const { return m_evtno; }