Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 //#include <bbc/BbcPmtContainerV1.h>
0002 //#include <bbc/BbcGeom.h>
0003 #include <bbc/MbdOut.h>
0004 #include <bbc/MbdPmtContainer.h>
0005 #include <bbc/MbdGeom.h>
0006 #include <bbc/MbdPmtHit.h>
0007 #include <phool/getClass.h>
0008 
0009 #include <phool/PHCompositeNode.h>
0010 
0011 //Fun4All
0012 #include <fun4all/Fun4AllReturnCodes.h>
0013 #include <fun4all/Fun4AllServer.h>
0014 #include <fun4all/Fun4AllHistoManager.h>
0015 #include <phool/PHCompositeNode.h>
0016 #include <phool/getClass.h>
0017 #include <phool/phool.h>
0018 #include <ffaobjects/EventHeader.h>
0019 
0020 //ROOT stuff
0021 #include <TH1F.h>
0022 #include <TH2F.h>
0023 #include <TH3F.h>
0024 #include <TFile.h>
0025 #include <TLorentzVector.h>
0026 #include <TTree.h>
0027 
0028 #include "mbdAnalysis.h"
0029 
0030 #include <fun4all/Fun4AllReturnCodes.h>
0031 
0032 #include <phool/PHCompositeNode.h>
0033 
0034 //____________________________________________________________________________..
0035 mbdAnalysis::mbdAnalysis(const std::string &name):
0036  SubsysReco(name)
0037 {
0038   std::cout << "mbdAnalysis::mbdAnalysis(const std::string &name) Calling ctor" << std::endl;
0039 }
0040 
0041 //____________________________________________________________________________..
0042 mbdAnalysis::~mbdAnalysis()
0043 {
0044   std::cout << "mbdAnalysis::~mbdAnalysis() Calling dtor" << std::endl;
0045 }
0046 
0047 //____________________________________________________________________________..
0048 int mbdAnalysis::Init(PHCompositeNode *topNode)
0049 {
0050 
0051   out = new TFile("output.root","RECREATE");
0052   
0053   T = new TTree("T","T");
0054 //  T -> Branch("adc",&adc);
0055 //  T -> Branch("tdc0",&tdc0);
0056 //  T -> Branch("tdc1",&tdc1);
0057   T -> Branch("pmtcharge",&pmtcharge);
0058   T -> Branch("pmttime",&pmttime);
0059   T -> Branch("pmtx",&pmtx);
0060   T -> Branch("pmty",&pmty);
0061   T -> Branch("pmtz",&pmtz);
0062   T -> Branch("pmtr",&pmtr);
0063   T -> Branch("pmtphi",&pmtphi);
0064 
0065   
0066   
0067   return Fun4AllReturnCodes::EVENT_OK;
0068 }
0069 
0070 //____________________________________________________________________________..
0071 int mbdAnalysis::InitRun(PHCompositeNode *topNode)
0072 {
0073   std::cout << "mbdAnalysis::InitRun(PHCompositeNode *topNode) Initializing for Run XXX" << std::endl;
0074   return Fun4AllReturnCodes::EVENT_OK;
0075 }
0076 
0077 //____________________________________________________________________________..
0078 int mbdAnalysis::process_event(PHCompositeNode *topNode)
0079 {
0080 
0081   //tower information
0082   //mbdinfo
0083   //these two lines copied directly from wiki:
0084   //PHNodeIterator iter(topNode);
0085   //PHCompositeNode *mbdNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "MBD"));
0086   //MbdOut *mbdout = findNode::getClass<MbdOut>(mbdNode, "MbdOut");
0087 
0088   MbdPmtContainer *mbdpmts = findNode::getClass<MbdPmtContainer>(topNode,"MbdPmtContainer"); // mbd info
0089   if(!mbdpmts)
0090     {
0091       std::cout << "makeMBDTrees::process_event: Could not find MbdPmtContainer, aborting" << std::endl;
0092       return Fun4AllReturnCodes::ABORTEVENT;
0093     }
0094   
0095   //MbdGeom *mbdGeom = new MbdGeom();
0096   MbdGeom *mbdgeom = findNode::getClass<MbdGeom>(topNode, "MbdGeom");
0097 
0098 
0099 
0100 
0101   int nPMTs = mbdpmts -> get_npmt();        //size (should always be 128)
0102   for(int i = 0; i < nPMTs; i++)
0103     {
0104       //short pmtID = mbdTowerContainer -> get_pmt(i);
0105       MbdPmtHit* mbdpmt = mbdpmts -> get_pmt(i);        // grab 1 pmt (changed from pmtID)
0106       
0107       //float pmtadc =  mbdpmts -> get_adc(i);        // grab adc from the ith pmt in mbdpmts
0108       //std::cout << "adc for tower i: " << i << " is: " <<pmtadc << std::endl;
0109       
0110      // pmtadc =  mbdpmts -> get_adc(mbdpmt);
0111       //std::cout << "adc for tower mbdpmt: " << mbdpmt << " is: " <<pmtadc << std::endl;
0112       //int pmtch =  mbdpmt->get_pmtch();        //pmt charge 
0113       float charge =  mbdpmt->get_q();        //pmt charge 
0114       float time =  mbdpmt->get_time();        //pmt charge 
0115       //std::cout << " pmt channel number: " << pmtch << "; pmtcharge: " << charge <<"; pmttime: "<< time <<  std::endl;
0116       
0117       pmttime.push_back(charge);
0118       pmtcharge.push_back(time);
0119     /*    
0120       adc.push_back(pmtadc);
0121       float pmttdc0 = mbdpmts -> get_tdc0(i);
0122       std::cout << "pmttdc0: " << pmttdc0 << std::endl;
0123       tdc0.push_back(pmttdc0);
0124       float pmttdc1 = mbdpmts -> get_tdc1(i);
0125       tdc1.push_back(pmttdc1);
0126 */
0127 // according to the wiki https://wiki.sphenix.bnl.gov/index.php/MBD_DST_Output these should be get_x(i) rather tahn
0128 // get_x(mbdpmt
0129       pmtx.push_back(mbdgeom->get_x(i));
0130       pmty.push_back(mbdgeom->get_y(i));
0131       pmtz.push_back(mbdgeom->get_z(i));
0132       pmtr.push_back(mbdgeom->get_r(i));
0133       pmtphi.push_back(mbdgeom->get_phi(i));
0134 
0135       std::cout << "phi angle of pmt is mbdgeom->get_phi(i)): " << mbdgeom->get_phi(i) << std::endl;
0136     }
0137   
0138   T -> Fill();
0139   
0140    
0141   return Fun4AllReturnCodes::EVENT_OK;
0142 }
0143 
0144 //____________________________________________________________________________..
0145 int mbdAnalysis::ResetEvent(PHCompositeNode *topNode)
0146 {
0147   std::cout << "mbdAnalysis::ResetEvent(PHCompositeNode *topNode) Resetting internal structures, prepare for next event" << std::endl;
0148   return Fun4AllReturnCodes::EVENT_OK;
0149 }
0150 
0151 //____________________________________________________________________________..
0152 int mbdAnalysis::EndRun(const int runnumber)
0153 {
0154   std::cout << "mbdAnalysis::EndRun(const int runnumber) Ending Run for Run " << runnumber << std::endl;
0155   return Fun4AllReturnCodes::EVENT_OK;
0156 }
0157 
0158 //____________________________________________________________________________..
0159 int mbdAnalysis::End(PHCompositeNode *topNode)
0160 {
0161   std::cout << "mbdAnalysis::End(PHCompositeNode *topNode) This is the End..." << std::endl;
0162   out -> cd();
0163   T -> Write();
0164   out -> Close();
0165   return Fun4AllReturnCodes::EVENT_OK;
0166 }
0167 
0168 //____________________________________________________________________________..
0169 int mbdAnalysis::Reset(PHCompositeNode *topNode)
0170 {
0171  // adc.clear();
0172   //tdc0.clear();
0173   //tdc1.clear();
0174   pmtcharge.clear();
0175   pmttime.clear();
0176   pmtx.clear();
0177   pmty.clear();
0178   pmtz.clear();
0179   pmtr.clear();
0180   pmtphi.clear();
0181 
0182   
0183   return Fun4AllReturnCodes::EVENT_OK;
0184 }
0185 
0186 //____________________________________________________________________________..
0187 void mbdAnalysis::Print(const std::string &what) const
0188 {
0189   std::cout << "mbdAnalysis::Print(const std::string &what) const Printing info for " << what << std::endl;
0190 }