Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 #include "EventSelection.h"
0002 
0003 #include <fun4all/Fun4AllReturnCodes.h>
0004 #include <fun4all/PHTFileServer.h>
0005 
0006 #include <phool/PHCompositeNode.h>
0007 #include <phool/getClass.h>
0008 
0009 #include <jetbase/Jet.h>
0010 #include <jetbase/JetMap.h>
0011 #include <jetbase/Jetv1.h>
0012 #include <jetbase/JetAlgo.h>
0013 #include <jetbase/FastJetAlgo.h>
0014 #include <jetbase/JetInput.h>
0015 #include <jetbase/TowerJetInput.h>
0016 #include <jetbase/JetMapv1.h>
0017 #include <jetbase/JetContainer.h>
0018 #include <jetbase/JetContainerv1.h>
0019 #include <jetbase/Jetv2.h>
0020 
0021 #include <globalvertex/GlobalVertexMap.h>
0022 #include <globalvertex/GlobalVertexMapv1.h>
0023 
0024 #include <cmath>
0025 #include <map>
0026 #include <utility>
0027 #include <cstdlib>  // for exit
0028 #include <iostream>
0029 #include <memory>  // for allocator_traits<>::value_type
0030 #include <vector>
0031 
0032 #include <TTree.h>
0033 #include <TFile.h>
0034 
0035 using namespace std;
0036 
0037 EventSelection::EventSelection(const std::string& truthjetname, const std::string& outputfilename)
0038  : SubsysReco("EventSelection")
0039  , m_outputfilename(outputfilename)
0040  , outFile(nullptr)
0041  , m_tree(nullptr) // Initialize m_tree to nullptr
0042  , m_vtxZ_cut(10.0)
0043  , m_event(-1)
0044  , m_vertex_z()
0045    // , m_vertex_z()
0046 {std::cout << "Output file path: " << m_outputfilename << std::endl;
0047 }
0048 
0049 EventSelection::~EventSelection()
0050 {}
0051 
0052 /////////////////////
0053 int EventSelection::Init(PHCompositeNode *topNode)
0054 {  // create output tree
0055 
0056   std::cout << "Output file path (Init): " << m_outputfilename << std::endl;
0057   outFile = new TFile(m_outputfilename.c_str(), "RECREATE");
0058   if (!outFile || outFile->IsZombie()) {
0059     std::cerr << "Error: Could not open output file " << m_outputfilename << std::endl;
0060     return Fun4AllReturnCodes::ABORTRUN;
0061   }
0062   m_tree = new TTree("Tree", "EventSelection");
0063   m_tree->Branch("m_vertex_z", &m_vertex_z);
0064   m_tree->Branch("m_event", &m_event, "event/I");
0065 
0066   std::cout << "EventSelection::Init(PHCompositeNode *topNode) Initialization successful" << std::endl;
0067   std::cout << "EventSelection::Init(PHCompositeNode *topNode) Output tree: " << m_tree->GetName() << std::endl;
0068 
0069   return Fun4AllReturnCodes::EVENT_OK; // Ensure that this return statement is within the function body
0070 }
0071 
0072 //////////////////
0073 int EventSelection::InitRun(PHCompositeNode *topNode)
0074 {
0075   std::cout << "EventSelection::InitRun(PHCompositeNode *topNode) Initializing for Run XXX" << std::endl;
0076   return Fun4AllReturnCodes::EVENT_OK;
0077 }
0078 
0079 //////////////////
0080 int EventSelection::process_event(PHCompositeNode *topNode)
0081 {
0082   //std::cout << "EventSelection::process_event(PHCompositeNode *topNode) Processing event " << m_event << std::endl;
0083   ++m_event;
0084 
0085   GlobalVertexMap *vtxMap = findNode::getClass<GlobalVertexMapv1>(topNode,"GlobalVertexMap");
0086   if (!vtxMap)
0087     {
0088       if(Verbosity()) std::cout << "EventSelection::processEvent(PHCompositeNode *topNode) Could not find global vertex map node" << std::endl;
0089       exit(-1);
0090     }
0091   if (!vtxMap->get(0))
0092     {
0093       if(Verbosity()) std::cout << "no vertex found" << std::endl;
0094       return Fun4AllReturnCodes::ABORTEVENT;
0095     }
0096   
0097   double mvtxz =vtxMap->get(0)->get_z();
0098   
0099   if (fabs(mvtxz) > m_vtxZ_cut)
0100     {
0101       if(Verbosity()) std::cout << "vertex not in range" << std::endl;
0102       return Fun4AllReturnCodes::ABORTEVENT;
0103 
0104     }
0105   m_vertex_z = (float) mvtxz;
0106 
0107   // If the event passes the z vertex selection, fill the output tree
0108   
0109   //==================================
0110   // Fill tree
0111   //==================================
0112   m_tree->Fill();
0113   //  std::cout << "m_vertex_z after fill: " << m_vertex_z << std::endl;
0114 
0115   return Fun4AllReturnCodes::EVENT_OK;
0116 }
0117 
0118 int EventSelection::ResetEvent(PHCompositeNode *topNode)
0119 {
0120   //std::cout << "EventSelection::ResetEvent(PHCompositeNode *topNode) Resetting internal structures, prepare for next event" << std::endl;
0121 
0122   //clear vectors or arrays here 
0123   //m_vertex_z.clear();
0124 
0125  return Fun4AllReturnCodes::EVENT_OK;
0126 
0127 }
0128 //____________________________________________________________________________..
0129 int EventSelection::EndRun(const int runnumber)
0130 {
0131   std::cout << "EventSelection::EndRun(const int runnumber) Ending Run for Run " << runnumber << std::endl;
0132   return Fun4AllReturnCodes::EVENT_OK;
0133 }
0134 /////////////////_____________________________________________________________..
0135 int EventSelection::End(PHCompositeNode *topNode)
0136 {
0137 
0138   outFile->cd();
0139   //outFile->Write();
0140   m_tree->Write();
0141   outFile->Close();
0142   
0143   std::cout << "EventSelection::End(PHCompositeNode *topNode) This is the End..." << std::endl;
0144 
0145   return Fun4AllReturnCodes::EVENT_OK;
0146 }
0147 
0148 //////////////////
0149 int EventSelection::Reset(PHCompositeNode *topNode)
0150 {
0151   // std::cout << "EventSelection::Reset(PHCompositeNode *topNode) being Reset" << std::endl;
0152   return Fun4AllReturnCodes::EVENT_OK;
0153 }
0154 
0155 //____________________________________________________________________________..
0156 void EventSelection::Print(const std::string &what) const
0157 {
0158   std::cout << "EventSelection::Print(const std::string &what) const Printing info for " << what << std::endl;
0159 }