Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:13:25

0001 // ----------------------------------------------------------------------------
0002 /*! \file    TriggerClusterTupleMaker.cc'
0003  *  \authors Derek Anderson
0004  *  \date    06.06.2024
0005  *
0006  *  A Fun4All module to dump trigger clusters
0007  *  into an NTuple
0008  */
0009 // ----------------------------------------------------------------------------
0010 
0011 #define TRIGGERCLUSTERTUPLEMAKER_CC
0012 
0013 // module definition
0014 #include "TriggerClusterTupleMaker.h"
0015 
0016 
0017 
0018 // ctor/dtor ==================================================================
0019 
0020 // ----------------------------------------------------------------------------
0021 //! Module constructor
0022 // ----------------------------------------------------------------------------
0023 TriggerClusterTupleMaker::TriggerClusterTupleMaker(const std::string &name) : SubsysReco(name) {
0024 
0025   // print debug message
0026   if (m_config.debug && (Verbosity() > 0)) {
0027     std::cout << "TriggerClusterTupleMaker::TriggerClusterTupleMaker(const std::string &name) Calling ctor" << std::endl;
0028   }
0029 
0030   // make sure vector is empty
0031   m_vecOutVars.clear();
0032 
0033 }  // end ctor
0034 
0035 
0036 
0037 // ----------------------------------------------------------------------------
0038 //! Module destructor
0039 // ----------------------------------------------------------------------------
0040 TriggerClusterTupleMaker::~TriggerClusterTupleMaker() {
0041 
0042   // print debug message
0043   if (m_config.debug && (Verbosity() > 0)) {
0044     std::cout << "TriggerClusterTupleMaker::~TriggerClusterTupleMaker() Calling dtor" << std::endl;
0045   }
0046 
0047   /* nothing to do */
0048 
0049 }  // end dtor
0050 
0051 
0052 
0053 // fun4all methods ============================================================
0054 
0055 // ----------------------------------------------------------------------------
0056 //! Initialize module
0057 // ----------------------------------------------------------------------------
0058 int TriggerClusterTupleMaker::Init(PHCompositeNode* topNode) {
0059 
0060   if (m_config.debug) {
0061     std::cout << "TriggerClusterTupleMaker::Init(PHCompositeNode *topNode) Initializing" << std::endl;
0062   }
0063 
0064   // initialize output
0065   InitOutput(topNode);
0066   return Fun4AllReturnCodes::EVENT_OK;
0067 
0068 }  // end 'Init(PHCompositeNode*)'
0069 
0070 
0071 
0072 // ----------------------------------------------------------------------------
0073 //! Grab inputs and build trigger clusters
0074 // ----------------------------------------------------------------------------
0075 int TriggerClusterTupleMaker::process_event(PHCompositeNode* topNode) {
0076 
0077   if (m_config.debug) {
0078     std::cout << "TriggerClusterTupleMaker::process_event(PHCompositeNode *topNode) Processing Event" << std::endl;
0079   }
0080 
0081   // grab input nodes
0082   GrabInputNodes(topNode);
0083 
0084   /* TODO loop over trigger clusters here */
0085 
0086   // end event
0087   return Fun4AllReturnCodes::EVENT_OK;
0088 
0089 }  // end 'process_event(PHCompositeNode*)'
0090 
0091 
0092 
0093 // ----------------------------------------------------------------------------
0094 //! Run final calculations
0095 // ----------------------------------------------------------------------------
0096 int TriggerClusterTupleMaker::End(PHCompositeNode *topNode) {
0097 
0098   if (m_config.debug) {
0099     std::cout << "TriggerClusterTupleMaker::End(PHCompositeNode *topNode) This is the End..." << std::endl;
0100   }
0101 
0102   // save and exit
0103   SaveOutput();
0104   return Fun4AllReturnCodes::EVENT_OK;
0105 
0106 }  // end 'End(PHCompositeNode*)'
0107 
0108 
0109 
0110 // private methods ============================================================
0111 
0112 // ----------------------------------------------------------------------------
0113 //! Create output file and ntuple
0114 // ----------------------------------------------------------------------------
0115 void TriggerClusterTupleMaker::InitOutput() {
0116 
0117   // print debug message
0118   if (m_config.debug && (Verbosity() > 0)) {
0119     std::cout << "TriggerClusterTupleMaker::InitOutput(PHCompositeNode*) Creating output" << std::endl;
0120   }
0121 
0122   // open output file
0123   m_outFile = new TFile(m_config.outFile.data(), "recreate");
0124   if (!m_outFile) {
0125     std::cerr << PHWHERE << ": PANIC! Couldn't open output file!" << std::endl;
0126     assert(m_outFile);
0127   }
0128 
0129   // make list of variables
0130   const std::vector<std::string> vecLeaves = {
0131     "ntowers",
0132     "energy",
0133     "ecore",
0134     "phi",
0135     "rx",
0136     "ry",
0137     "rz",
0138     "z",
0139     "r"
0140   };
0141 
0142   // flatten list
0143   std::string argLeaves("");
0144   for (size_t iLeaf = 0; iLeaf < vecLeaves.size(); ++iLeaf) {
0145     argLeaves.append(vecLeaves[iLeaf]);
0146     if ((iLeaf + 1) != vecLeaves.size()) {
0147       argLeaves.append(":");
0148     }
0149   }
0150 
0151   // create tuple
0152   m_outTuple = new TNtuple(m_config.outTuple.data(), "Trigger Clusters", argLeaves.data());
0153   return;
0154 
0155 }  // end 'InitOutput()'
0156 
0157 
0158 
0159 // ----------------------------------------------------------------------------
0160 //! Grab input nodes
0161 // ----------------------------------------------------------------------------
0162 void TriggerClusterTupleMaker::GrabInputNodes(PHCompositeNode* topNode) {
0163 
0164   // print debug message
0165   if (m_config.debug && (Verbosity() > 0)) {
0166     std::cout << "TriggerClusterTupleMaker::GrabTowerNodes(PHCompositeNode*) Grabbing input tower nodes" << std::endl;
0167   }
0168 
0169   // get emcal tower info node
0170   m_inTrgClusts = findNode::getClass<RawClusterContainer>(topNode, m_config.inNode);
0171   if (!m_inTrgClusts) {
0172     std::cerr << PHWHERE << ": PANIC! Couldn't grab node '" << m_config.inNode << "'!" << std::endl;
0173     assert(m_inTrgClusts); 
0174   }
0175   return;
0176 
0177 }  // end 'GrabInputNodes(PHCompositeNode*)'
0178 
0179 
0180 
0181 // ----------------------------------------------------------------------------
0182 //! Set variables
0183 // ----------------------------------------------------------------------------
0184 void TriggerClusterTupleMaker::SetClusterVariables(RawClusterv1* cluster) {
0185 
0186   // print debug message
0187   if (m_config.debug && (Verbosity() > 0)) {
0188     std::cout << "TriggerClusterTupleMaker::GrabTowerNodes(PHCompositeNode*) Grabbing input tower nodes" << std::endl;
0189   }
0190 
0191   // get emcal tower info node
0192   m_inTrgClusts = findNode::getClass<RawClusterContainer>(topNode, m_config.inNode);
0193   if (!m_inTrgClusts) {
0194     std::cerr << PHWHERE << ": PANIC! Couldn't grab node '" << m_config.inNode << "'!" << std::endl;
0195     assert(m_inTrgClusts); 
0196   }
0197   return;
0198 
0199 }  // end 'GrabInputNodes(PHCompositeNode*)'
0200 
0201 
0202 
0203 
0204 
0205 
0206 // end ------------------------------------------------------------------------