Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:17:35

0001 #include "RawClusterZVertexRecorrect.h"
0002 
0003 #include <globalvertex/MbdVertex.h>
0004 #include <globalvertex/MbdVertexMap.h>
0005 
0006 #include <globalvertex/GlobalVertex.h>
0007 #include <globalvertex/GlobalVertexMap.h>
0008 
0009 #include <calobase/RawCluster.h>
0010 #include <calobase/RawClusterContainer.h>
0011 
0012 #include <fun4all/Fun4AllReturnCodes.h>
0013 #include <fun4all/SubsysReco.h>
0014 
0015 #include <phool/getClass.h>
0016 
0017 #include <fstream>
0018 #include <iostream>
0019 #include <map>
0020 #include <sstream>
0021 #include <string>
0022 #include <utility>                         // for pair
0023 
0024 RawClusterZVertexRecorrect::RawClusterZVertexRecorrect(const std::string &name)
0025   : SubsysReco(std::string("RawClusterZVertexRecorrect_") + name)
0026   , _det_name("CEMC")  // not tested for hcal yet
0027   , m_UseTowerInfo(0)
0028   , m_UseBbcZVtx(false)
0029 {
0030 
0031 }
0032 
0033 int RawClusterZVertexRecorrect::InitRun(PHCompositeNode *topNode)
0034 {
0035   if (!topNode && Verbosity())
0036   {
0037     std::cout << "RawClusZVtxRecorrect::InitRun :  NO TOPNODE" << std::endl;
0038   }
0039 
0040   //  CreateNodeTree(topNode);
0041   m_calrecoUtilInstance.LoadProfile();
0042   return Fun4AllReturnCodes::EVENT_OK;
0043 }
0044 
0045 int RawClusterZVertexRecorrect::process_event(PHCompositeNode *topNode)
0046 {
0047   if (Verbosity())
0048   {
0049     std::cout << "RawClusZVtxRecorrect::Processing a NEW EVENT" << std::endl;
0050   }
0051 
0052   std::string rawClusNodeName = "CLUSTER_" + _det_name;
0053   if (m_UseTowerInfo)
0054   {
0055     rawClusNodeName = "CLUSTERINFO_" + _det_name;
0056   }
0057 
0058   RawClusterContainer *rawclusters = findNode::getClass<RawClusterContainer>(topNode, rawClusNodeName);
0059   if (!rawclusters)
0060   {
0061     std::cout << "No " << _det_name << " Cluster Container found while in RawClusterZVertexRecorrect, can't proceed!!!" << std::endl;
0062     return Fun4AllReturnCodes::ABORTEVENT;
0063   }
0064 
0065   // Get Vertex
0066   //float vx = 0;
0067   //  float vy = 0;
0068   float vz = 0;
0069 
0070 
0071   GlobalVertexMap *vertexmap = findNode::getClass<GlobalVertexMap>(topNode, "GlobalVertexMap");
0072     
0073   if (vertexmap && m_UseTowerInfo < 0)
0074     //  if (vertexmap)
0075     {
0076       if (!vertexmap->empty())
0077     {
0078       GlobalVertex *vertex = (vertexmap->begin()->second);
0079       //      vx = vertex->get_x();
0080       // vy = vertex->get_y();
0081       vz = vertex->get_z();
0082     }
0083     }
0084   
0085   
0086   MbdVertexMap *mbdmap = findNode::getClass<MbdVertexMap>(topNode, "MbdVertexMap");
0087  
0088   if (m_UseBbcZVtx && mbdmap && m_UseTowerInfo < 2)
0089     {
0090       //      std::cout << " in mbdmap ccpi0 " << std::endl;
0091       
0092       MbdVertex *bvertex = nullptr;
0093       for (MbdVertexMap::ConstIter mbditer = mbdmap->begin();
0094            mbditer != mbdmap->end();
0095            ++mbditer)
0096     {
0097 
0098       bvertex = mbditer->second;
0099     }
0100       //      MbdVertex *bvertex = (mbdmap->begin()->second);
0101       if (!bvertex) 
0102       {
0103     return Fun4AllReturnCodes::ABORTEVENT;
0104       }
0105       vz = bvertex->get_z();
0106     }
0107 
0108   /////////////////////////////
0109 
0110   // loop over the clusters
0111   RawClusterContainer::ConstRange begin_end = rawclusters->getClusters();
0112   RawClusterContainer::ConstIterator iter;
0113 
0114   for (iter = begin_end.first; iter != begin_end.second; ++iter)
0115   {
0116     //    RawClusterDefs::keytype key = iter->first;
0117     RawCluster *cluster = iter->second;
0118 
0119     float clus_energy = cluster->get_energy();
0120     float clus_savz = cluster->get_z();
0121     float clus_chi2 = cluster->get_chi2();
0122 
0123     CaloRecoUtility::ShowerDepthCorrZVertex(cluster, vz);
0124     m_calrecoUtilInstance.ProbCorrsZVertex(cluster, vz);
0125 
0126 
0127     /*
0128     // for if it is desired in future to make new copied node instead of 
0129     // changing clusterNode "in Situ"
0130   
0131     RawCluster *recalibcluster = dynamic_cast<RawCluster *>(cluster->CloneMe());
0132     assert(recalibcluster);
0133     //    if (m_UseTowerInfo)
0134     //  std::cout << "and here" << std::endl;
0135     recalibcluster->set_energy(clus_energy / eclus_recalib_val);
0136     recalibcluster->set_ecore(cluster->get_ecore() / ecore_recalib_val);
0137     _recalib_clusters->AddCluster(recalibcluster);
0138     */
0139 
0140     if (Verbosity() && clus_energy > 18.0)
0141     {
0142       std::cout << "Input,out eclus cluster energies: " << clus_energy 
0143         << " " << cluster->get_energy() << std::endl;
0144       std::cout << "Input, out  cluster z:" << clus_savz 
0145         << " " << cluster->get_z() << std::endl;
0146 
0147       std::cout << "Input, out  cluster ch2:" << clus_chi2 
0148         << " " << cluster->get_chi2() << std::endl;
0149     }
0150 
0151   }
0152 
0153   return Fun4AllReturnCodes::EVENT_OK;
0154 }
0155 
0156 
0157 /*
0158 
0159   //keeping this for if we want to make a new node like CLUSTER_POS_CORR
0160 void RawClusterZVertexRecorrect::CreateNodeTree(PHCompositeNode *topNode)
0161 {
0162 
0163   // Check that it is there
0164   if (!dstNode)
0165   {
0166     std::cout << "DST Node missing, quitting" << std::endl;
0167     throw std::runtime_error("failed to find DST node in RawClusterZVertexRecorrect::CreateNodeTree");
0168   }
0169 
0170   // Get the _det_name subnode
0171   PHCompositeNode *cemcNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", _det_name));
0172 
0173   // Check that it is there
0174   if (!cemcNode)
0175   {
0176     cemcNode = new PHCompositeNode(_det_name);
0177     dstNode->addNode(cemcNode);
0178   }
0179 
0180 
0181   // Check to see if the cluster recalib node is on the nodetree
0182   _recalib_clusters = findNode::getClass<RawClusterContainer>(topNode, "CLUSTER_RECALIB_" + _det_name);
0183   std::string ClusterCorrNodeName = "CLUSTER_POS_COR_" + _det_name;
0184   ;
0185 
0186   // If not, make it and add it to the _det_name subnode
0187   if (!_recalib_clusters)
0188   {
0189     _recalib_clusters = new RawClusterContainer();
0190     if (m_UseTowerInfo)
0191     {
0192       ClusterCorrNodeName = "CLUSTERINFO_POS_COR_" + _det_name;
0193     }
0194 
0195     PHIODataNode<PHObject> *clusterNode = new PHIODataNode<PHObject>(_recalib_clusters, ClusterCorrNodeName.c_str(), "PHObject");
0196     cemcNode->addNode(clusterNode);
0197   }
0198 
0199 
0200 }
0201 
0202 */
0203 
0204 int RawClusterZVertexRecorrect::End(PHCompositeNode * /*topNode*/)
0205 {
0206   return Fun4AllReturnCodes::EVENT_OK;
0207 }