Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:13:18

0001 // ----------------------------------------------------------------------------
0002 // 'SMakeClustQATree.cc'
0003 // Derek Anderson
0004 // 03.10.2024
0005 //
0006 // SCorrelatorQAMaker plugin to produce the QA tree
0007 // for calorimeter clusters.
0008 // ----------------------------------------------------------------------------
0009 
0010 #define SCORRELATORQAMAKER_SMAKECLUSTQATREE_CC
0011 
0012 // plugin definition
0013 #include "SMakeClustQATree.h"
0014 
0015 // make common namespaces implicit
0016 using namespace std;
0017 using namespace findNode;
0018 
0019 
0020 
0021 namespace SColdQcdCorrelatorAnalysis {
0022 
0023 
0024 
0025   // SMakeClustQATree public methods ------------------------------------------
0026 
0027   int SMakeClustQATree::Init(PHCompositeNode* topNode) {
0028 
0029     InitOutput();
0030     InitTree();
0031     return Fun4AllReturnCodes::EVENT_OK;
0032 
0033   }  // end 'Init(PHCompositeNode*)'
0034 
0035 
0036 
0037   int SMakeClustQATree::process_event(PHCompositeNode* topNode) {
0038 
0039     // make sure output container is empty
0040     m_output.Reset();
0041 
0042     // grab event info
0043     //   FIXME add in subevent selection
0044     m_output.recInfo.SetInfo(topNode);
0045     m_output.genInfo.SetInfo(topNode, m_config.isEmbed, {2});
0046 
0047     // grab cluster info
0048     DoClustLoop(topNode, "CLUSTER_CEMC");
0049     DoClustLoop(topNode, "CLUSTER_HCALIN");
0050     DoClustLoop(topNode, "CLUSTER_HCALOUT");
0051 
0052     // fill output tree and reset
0053     m_tClustQA -> Fill();
0054     return Fun4AllReturnCodes::EVENT_OK;
0055 
0056   }  // end 'process_event(PHCompositeNode* topNode)'
0057 
0058 
0059 
0060   int SMakeClustQATree::End(PHCompositeNode* topNode) {
0061 
0062     SaveOutput();
0063     CloseOutput();
0064     return Fun4AllReturnCodes::EVENT_OK;
0065 
0066   }  // end 'End(PHCompositeNode*)'
0067 
0068 
0069 
0070   // SMakeClustQATree internal methods -----------------------------------------
0071 
0072   void SMakeClustQATree::InitTree() {
0073 
0074     if (m_isDebugOn && (m_verbosity > 2)) {
0075       cout << "SColdQcdCorrelatorAnalysis::SMakeClustQATree::InitTree(): initializing output tree." << endl;
0076     }
0077 
0078     // initialize tree
0079     //   FIXME still having issues with vectors of types
0080     m_tClustQA = new TTree("tClustQA", "Cluster QA");
0081     m_tClustQA -> Branch("EvtRecoInfo", "Types::RecoInfo", &m_output.recInfo, 6400, 99);
0082     m_tClustQA -> Branch("EvtGenInfo", "Types::GenInfo", &m_output.genInfo, 6400, 99);
0083     m_tClustQA -> Branch("EMCalInfo", "vector<Types::ClustInfo>", &m_output.emCalInfo, 6400, 99);
0084     m_tClustQA -> Branch("IHCalInfo", "vector<Types::ClustInfo>", &m_output.ihCalInfo, 6400, 99);
0085     m_tClustQA -> Branch("OHCalInfo", "vector<Types::ClustInfo>", &m_output.ohCalInfo, 6400, 99);
0086     return;
0087 
0088   }  // end 'InitTree()'
0089 
0090 
0091 
0092   void SMakeClustQATree::SaveOutput() {
0093 
0094     if (m_isDebugOn && (m_verbosity > 2)) {
0095       cout << "SColdQcdCorrelatorAnalysis::SMakeClustQATree::SaveOutput(): saving output." << endl;
0096     }
0097 
0098     m_outDir   -> cd();
0099     m_tClustQA -> Write();
0100     return;
0101 
0102   }  // end 'SaveOutput()'
0103 
0104 
0105 
0106   void SMakeClustQATree::DoClustLoop(PHCompositeNode* topNode, const string node) {
0107 
0108     if (m_isDebugOn && (m_verbosity > 2)) {
0109       cout << "SColdQcdCorrelatorAnalysis::SMakeClustQATree::DoClustLoop(PHCompositeNode*, string): looping over clusters." << endl;
0110     }
0111 
0112     // grab clusters
0113     RawClusterContainer::ConstRange clusters = Interfaces::GetClusters(topNode, node);
0114 
0115     // loop over clusters
0116     for (
0117       RawClusterContainer::ConstIterator itClust = clusters.first;
0118       itClust != clusters.second;
0119       itClust++
0120     ) {
0121 
0122       // grab cluster
0123       const RawCluster* cluster = itClust -> second;
0124       if (!cluster) continue;
0125 
0126       // skip if bad
0127       const bool isGoodClust = IsGoodCluster(cluster);
0128       if (!isGoodClust) continue;
0129 
0130       // grab cluster info
0131       Types::ClustInfo clustInfo(cluster, ROOT::Math::XYZVector(0., 0., 0.), Const::MapNodeOntoIndex()[node]);
0132 
0133       // add to relevant list
0134       switch (Const::MapNodeOntoIndex()[node]) {
0135 
0136         case Const::Subsys::EMCal:
0137           m_output.emCalInfo.push_back(clustInfo);
0138           break;
0139 
0140         case Const::Subsys::IHCal:
0141           m_output.ihCalInfo.push_back(clustInfo);
0142           break;
0143 
0144         case Const::Subsys::OHCal:
0145           m_output.ohCalInfo.push_back(clustInfo);
0146           break;
0147 
0148         default:
0149           cerr << "SColdQcdCorrealtorAnalysis::SMakeClustQATree::DoClustLoop(PHCompositeNode*, string) WARNING: trying to add clusters from unknown node to output!" << endl;
0150           break;
0151       }
0152     }  // end cluster loop
0153     return;
0154 
0155   }  // end 'DoClustLoop(PHCompositeNode*, string)'
0156 
0157 
0158 
0159   bool SMakeClustQATree::IsGoodCluster(const RawCluster* cluster) {
0160 
0161     // print debug statement
0162     if (m_isDebugOn && (m_verbosity > 4)) {
0163       cout << "SMakeClustQATree::IsGoodCluster(RawCluster*) Checking if cluster is good..." << endl;
0164     }
0165 
0166     // grab cluster info
0167     Types::ClustInfo info(cluster);
0168 
0169     // check if cluster is in acceptance and return overall goodness
0170     const bool isInAccept = info.IsInAcceptance(m_config.clustAccept);
0171     return isInAccept;
0172 
0173   }  // end 'IsGoodTrack(RawCluster*)'
0174 
0175 }  // end SColdQcdCorrelatorAnalysis namespace
0176 
0177 // end ------------------------------------------------------------------------