File indexing completed on 2026-07-16 08:13:58
0001 #include "StreamingLumiReco.h"
0002
0003 #include "StreamingBcoInfo.h"
0004 #include "StreamingLumiInfo.h"
0005 #include "StreamingLumiInfov1.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 #include <phool/sphenix_constants.h> // for MDB_NS_xsec
0025
0026 #include <TH1.h>
0027
0028 #include <iostream>
0029
0030 StreamingLumiReco::StreamingLumiReco(const std::string &name)
0031 : SubsysReco(name)
0032 {
0033 return;
0034 }
0035
0036 int StreamingLumiReco::Init(PHCompositeNode *topNode)
0037 {
0038 int iret = CreateNodeTree(topNode);
0039 return iret;
0040 }
0041
0042 int StreamingLumiReco::InitRun(PHCompositeNode * topNode)
0043 {
0044 PHNodeIterator iter(topNode);
0045 PHCompositeNode *runNode;
0046 runNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "RUN"));
0047 if (!runNode)
0048 {
0049 std::cout << PHWHERE << " Run Node is missing doing nothing" << std::endl;
0050 return Fun4AllReturnCodes::ABORTRUN;
0051 }
0052 m_streaming_lumi_info = findNode::getClass<StreamingLumiInfo>(topNode, "STREAMINGLUMIINFO");
0053 if (!m_streaming_lumi_info)
0054 {
0055 m_streaming_lumi_info = new StreamingLumiInfov1();
0056 PHIODataNode<PHObject> *luminode = new PHIODataNode<PHObject>(m_streaming_lumi_info, "STREAMINGLUMIINFO", "PHObject");
0057 runNode->addNode(luminode);
0058 }
0059 return Fun4AllReturnCodes::EVENT_OK;
0060 }
0061
0062 int StreamingLumiReco::CreateNodeTree(PHCompositeNode *topNode)
0063 {
0064 PHNodeIterator iter(topNode);
0065 PHCompositeNode *dstNode;
0066 dstNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "DST"));
0067 if (!dstNode)
0068 {
0069 std::cout << PHWHERE << " DST Node is missing doing nothing" << std::endl;
0070 return Fun4AllReturnCodes::ABORTRUN;
0071 }
0072 return Fun4AllReturnCodes::EVENT_OK;
0073 }
0074
0075 int StreamingLumiReco::process_event(PHCompositeNode *topNode)
0076 {
0077 StreamingBcoInfo *streaming_bcoinfo = findNode::getClass<StreamingBcoInfo>(topNode, "STREAMINGBCOINFO");
0078 Gl1Packet *gl1packet = findNode::getClass<Gl1Packet>(topNode, "GL1RAWHIT");
0079 if (!gl1packet)
0080 {
0081 if (Verbosity() > 0)
0082 {
0083 std::cout << "no gl1 packet 14001" << std::endl;
0084 }
0085 return Fun4AllReturnCodes::ABORTEVENT;
0086 }
0087 uint64_t gtm_bco = gl1packet->lValue(0, "BCO");
0088
0089 int bunchno = gl1packet->lValue(0,"BunchNumber");
0090 if (bunchno < 0 || bunchno >= m_bunches)
0091 {
0092 if (Verbosity() > 0)
0093 {
0094 std::cout << PHWHERE << " invalid bunch number: " << bunchno << std::endl;
0095 }
0096 return Fun4AllReturnCodes::ABORTEVENT;
0097 }
0098
0099
0100 m_bunchnumber_MBDNS_raw[bunchno] = gl1packet->lValue(0, "GL1PRAW");
0101 m_bunchnumber_MBDNS_live[bunchno] = gl1packet->lValue(0, "GL1PLIVE");
0102 m_bunchnumber_MBDNS_scaled[bunchno] = gl1packet->lValue(0, "GL1PSCALED");
0103
0104
0105 if(gl1packet->lValue(0, 0))
0106 {
0107 m_rawgl1scaler = gl1packet->lValue(0, 0);
0108 }
0109
0110 if (streaming_bcoinfo)
0111 {
0112 if (gtm_bco != streaming_bcoinfo->get_bco()) { std::cout << "BCO MISMATCH!!! : gtm_bco : " << gtm_bco << " bco " << streaming_bcoinfo->get_bco() << std::endl;}
0113
0114
0115 int lower = streaming_bcoinfo->get_bco_streaming_window().first - streaming_bcoinfo->get_bco();
0116 int upper = streaming_bcoinfo->get_bco_streaming_window().second - streaming_bcoinfo->get_bco();
0117 for(int i = lower; i< upper;i++)
0118 {
0119 int adjusted_bunch = bunchno + i;
0120 while (adjusted_bunch < 0)
0121 {
0122 adjusted_bunch += 120;
0123 }
0124 while (adjusted_bunch > 119)
0125 {
0126 adjusted_bunch -= 120;
0127 }
0128
0129 if (adjusted_bunch>110) { continue; }
0130
0131
0132 if(i!=0 || streaming_bcoinfo->get_usable_bco_tag())
0133 {
0134 m_bunchnumber_crossings[adjusted_bunch] += 1;
0135 }
0136 }
0137 }
0138 return Fun4AllReturnCodes::EVENT_OK;
0139 }
0140
0141 int StreamingLumiReco::EndRun(int )
0142 {
0143 uint64_t rawgl1scalers_per_bunch = m_rawgl1scaler/120.;
0144 for (int i=0; i<m_bunches; i++)
0145 {
0146 m_bunchnumber_lumi_raw[i] = ( m_bunchnumber_crossings[i] * m_bunchnumber_MBDNS_raw[i] ) / ( rawgl1scalers_per_bunch * sphenix_constants::m_xsec_MBDNS );
0147 m_bunchnumber_lumi_live[i] = ( m_bunchnumber_crossings[i] * m_bunchnumber_MBDNS_live[i]) / ( rawgl1scalers_per_bunch * sphenix_constants::m_xsec_MBDNS );
0148 m_bunchnumber_lumi_scaled[i] = ( m_bunchnumber_crossings[i] * m_bunchnumber_MBDNS_scaled[i] ) / ( rawgl1scalers_per_bunch * sphenix_constants::m_xsec_MBDNS );
0149
0150 m_lumi_raw += m_bunchnumber_lumi_raw[i];
0151 m_lumi_live += m_bunchnumber_lumi_live[i];
0152 m_lumi_scaled += m_bunchnumber_lumi_scaled[i];
0153
0154 if (Verbosity() > 1)
0155 {
0156 std::cout << "bunchno : " << i << " lumi_raw : " << m_bunchnumber_lumi_raw[i] << std::endl;
0157 }
0158 }
0159 if (!m_streaming_lumi_info)
0160 {
0161 std::cout << PHWHERE << " STREAMINGLUMIINFO node missing in EndRun" << std::endl;
0162 return Fun4AllReturnCodes::ABORTRUN;
0163 }
0164
0165 m_streaming_lumi_info->set_bunchnumber_lumi_raw(get_bunchnumber_lumi_raw());
0166 m_streaming_lumi_info->set_bunchnumber_lumi_live(get_bunchnumber_lumi_live());
0167 m_streaming_lumi_info->set_bunchnumber_lumi_scaled(get_bunchnumber_lumi_scaled());
0168
0169 m_streaming_lumi_info->set_lumi_raw(get_lumi_raw());
0170 m_streaming_lumi_info->set_lumi_live(get_lumi_live());
0171 m_streaming_lumi_info->set_lumi_scaled(get_lumi_scaled());
0172
0173 if (Verbosity() > 1)
0174 {
0175 std::cout << "MBD xsec : " << sphenix_constants::m_xsec_MBDNS << std::endl;
0176 std::cout << "total lumi (raw) : " << m_lumi_raw << std::endl;
0177 }
0178
0179 m_bunchnumber_lumi_raw.fill(0);
0180 m_bunchnumber_lumi_live.fill(0);
0181 m_bunchnumber_lumi_scaled.fill(0);
0182 m_bunchnumber_crossings.fill(0);
0183 m_bunchnumber_MBDNS_raw.fill(0);
0184 m_bunchnumber_MBDNS_live.fill(0);
0185 m_bunchnumber_MBDNS_scaled.fill(0);
0186 m_lumi_raw = 0.;
0187 m_lumi_live = 0.;
0188 m_lumi_scaled = 0.;
0189 m_rawgl1scaler = 0;
0190
0191 return Fun4AllReturnCodes::EVENT_OK;
0192 }