Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2026-04-03 08:08:52

0001 #include "DstPhotonMBDSelection.h"
0002 #include <fun4all/Fun4AllReturnCodes.h>
0003 #include <phool/getClass.h>
0004 
0005 // Spin DB
0006 #include <odbc++/connection.h>
0007 #include <odbc++/drivermanager.h>
0008 #include <odbc++/resultset.h>
0009 #include <odbc++/resultsetmetadata.h>
0010 #include <uspin/SpinDBContent.h>
0011 #include <uspin/SpinDBContentv1.h>
0012 #include <uspin/SpinDBOutput.h>
0013 
0014 #include <format>
0015 #include <fstream>
0016 #include <iomanip>
0017 #include <iostream>
0018 #include <sstream>
0019 
0020 
0021 DstPhotonMBDSelection::DstPhotonMBDSelection(const std::string &name, const int runnb)
0022   : SubsysReco(name)
0023   , runnumber(runnb)
0024 {
0025 }
0026 
0027 DstPhotonMBDSelection::~DstPhotonMBDSelection()
0028 {
0029 }
0030 
0031 int DstPhotonMBDSelection::Init(PHCompositeNode *)
0032 {  
0033   return 0;
0034 }
0035 
0036 int DstPhotonMBDSelection::InitRun(PHCompositeNode *topNode)
0037 {
0038   gl1packet = findNode::getClass<Gl1Packet>(topNode, "14001");
0039   if (!gl1packet)
0040   {
0041     std::cerr << "AnNeutralMeson Gl1Packet node is missing" << std::endl;
0042     return Fun4AllReturnCodes::ABORTRUN;
0043   }
0044   
0045   // See how the trigger logic is defined for this run in the CDB.
0046   odbc::Connection *con = nullptr;
0047   try
0048   {
0049     con = odbc::DriverManager::getConnection(db_name, user_name, "");
0050   }
0051   catch (odbc::SQLException &e)
0052   {
0053     std::cout << std::format("Error: {}.", e.getMessage()) << std::endl;
0054     return Fun4AllReturnCodes::ABORTRUN;
0055   }
0056 
0057   std::stringstream cmd;
0058   cmd << "SELECT * FROM " << table_name << " WHERE runnumber=" << runnumber << ";";
0059   odbc::Statement *stmt = con->createStatement();
0060   odbc::ResultSet *rs = nullptr;
0061   try
0062   {
0063     rs = stmt->executeQuery(cmd.str());
0064   }
0065   catch (odbc::SQLException &e)
0066   {
0067     std::cout << std::format("Error: {}.", e.getMessage()) << std::endl;
0068     delete rs;
0069     delete stmt;
0070     delete con;
0071     return Fun4AllReturnCodes::ABORTRUN;
0072   }
0073 
0074   if (rs->next() == 0)
0075   {
0076     std::cout << std::format("Error: Can't find GL1 scaledown data for run {}", runnumber) << std::endl;
0077     delete rs;
0078     delete stmt;
0079     delete con;
0080     return Fun4AllReturnCodes::ABORTRUN;
0081   }
0082 
0083   int ncols = rs->getMetaData()->getColumnCount();
0084   for (int icol = 0; icol < ncols; icol++)
0085   {
0086     std::string col_name = rs->getMetaData()->getColumnName(icol + 1);
0087     // i.e. scaledownXX where XX is the trigger number (00 to 63
0088     if (col_name.starts_with("scaledown")) 
0089     {
0090       int scaledown_index = std::stoi(col_name.substr(9,2));
0091       std::string cont = rs->getString(col_name);
0092       scaledown[scaledown_index] = std::stoi(cont);
0093     }
0094   }
0095 
0096   return Fun4AllReturnCodes::EVENT_OK;
0097 }
0098 
0099 int DstPhotonMBDSelection::process_event(PHCompositeNode *)
0100 {
0101   // Store event-level entries
0102   live_trigger = gl1packet->getLiveVector();
0103   scaled_trigger = gl1packet->getScaledVector();
0104 
0105   trigger_mbd_photon_3 = false;
0106   trigger_mbd_photon_4 = false;
0107   trigger_mbd_photon_5 = false;
0108 
0109   // If (photon 3 GeV + MBD NS >= 1) is enabled for recording
0110   if (scaledown[25] != -1) 
0111   {
0112     trigger_mbd_photon_3 = (trigger_mbd_photon_3 ||
0113                             ((scaled_trigger >> 25 & 0x1U) == 0x1U));
0114   }
0115   // Else if (photon 3 GeV + MBD NS >=1, vtx < 10) is enabled for recording
0116   if (!trigger_mbd_photon_3 && (scaledown[36] != -1))
0117   {
0118     trigger_mbd_photon_3 = (trigger_mbd_photon_3 ||
0119                             ((scaled_trigger >> 36 & 0x1U) == 0x1U));
0120   }
0121   // Else if (photon 3 GeV) is enabled for recording with no prescale
0122   if (!trigger_mbd_photon_3 && (scaledown[29] == 0))
0123   {
0124     trigger_mbd_photon_3 = (trigger_mbd_photon_3 ||
0125                             ((live_trigger >> 25 & 0x1U) == 0x1U) ||
0126                             ((live_trigger >> 36 & 0x1U) == 0x1U));
0127   }
0128 
0129   // If (photon 4 GeV + MBD NS >= 1) is enabled for recording
0130   if (scaledown[26] != -1) 
0131   {
0132     trigger_mbd_photon_4 = (trigger_mbd_photon_4 ||
0133                             ((scaled_trigger >> 26 & 0x1U) == 0x1U));
0134   }
0135   // Else if (photon 4 GeV + MBD NS >=1, vtx < 10) is enabled for recording
0136   if (!trigger_mbd_photon_4 && (scaledown[37] != -1))
0137   {
0138     trigger_mbd_photon_4 = (trigger_mbd_photon_4 ||
0139                             ((scaled_trigger >> 37 & 0x1U) == 0x1U));
0140   }
0141   // Else if (photon 4 GeV) is enabled for recording with no prescale
0142   if (!trigger_mbd_photon_4 && (scaledown[30] == 0))
0143   {
0144     trigger_mbd_photon_4 = (trigger_mbd_photon_4 ||
0145                             ((live_trigger >> 26 & 0x1U) == 0x1U) ||
0146                             ((live_trigger >> 37 & 0x1U) == 0x1U));
0147   }
0148 
0149   // If (photon 5 GeV + MBD NS >= 1) is enabled for recording
0150   if (scaledown[27] != -1) 
0151   {
0152     trigger_mbd_photon_5 = (trigger_mbd_photon_5 ||
0153                             ((scaled_trigger >> 27 & 0x1U) == 0x1U));
0154   }
0155   // Else if (photon 5 GeV + MBD NS >=1, vtx < 10) is enabled for recording
0156   if (!trigger_mbd_photon_5 && (scaledown[38] != -1))
0157   {
0158     trigger_mbd_photon_5 = (trigger_mbd_photon_5 ||
0159                             ((scaled_trigger >> 38 & 0x1U) == 0x1U));
0160   }
0161   // Else if (photon 5 GeV) is enabled for recording with no prescale
0162   if (!trigger_mbd_photon_5 && (scaledown[31] == 0))
0163   {
0164     trigger_mbd_photon_5 = (trigger_mbd_photon_5 ||
0165                             ((live_trigger >> 27 & 0x1U) == 0x1U) || 
0166                             ((live_trigger >> 38 & 0x1U) == 0x1U));
0167   }
0168 
0169   // MBD only selection
0170   trigger_mbd_any_vtx = ((scaled_trigger >> 10 & 0x1U) == 0x1U);
0171   trigger_mbd_vtx_10 = ((scaled_trigger >> 12 & 0x1U) == 0x1U);
0172   
0173   if (!(trigger_mbd_any_vtx || trigger_mbd_vtx_10 || trigger_mbd_photon_3 || trigger_mbd_photon_4 || trigger_mbd_photon_5))
0174     return Fun4AllReturnCodes::ABORTEVENT;
0175   
0176   return Fun4AllReturnCodes::EVENT_OK;
0177 }
0178 
0179 int DstPhotonMBDSelection::End(PHCompositeNode *)
0180 {
0181   return 0;
0182 }