Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 // Include necessary files
0002 #include "TpcChanQA.h"
0003 
0004 #include <qautils/QAHistManagerDef.h>
0005 
0006 #include <fun4all/Fun4AllHistoManager.h>
0007 #include <fun4all/Fun4AllReturnCodes.h>
0008 
0009 #include <phool/PHCompositeNode.h>
0010 #include <phool/PHIODataNode.h>    // for PHIODataNode
0011 #include <phool/PHNodeIterator.h>  // for PHNodeIterator
0012 #include <phool/PHObject.h>        // for PHObject
0013 #include <phool/getClass.h>
0014 
0015 #include <Event/Event.h>
0016 #include <Event/packet.h>
0017 
0018 #include <TH1.h>
0019 #include <TH2.h>
0020 
0021 #include <cassert>
0022 #include <cstddef>
0023 #include <format>
0024 #include <iostream>
0025 #include <memory>
0026 #include <string>
0027 
0028 //
0029 
0030 //____________________________________________________________________________..
0031 TpcChanQA::TpcChanQA(const std::string &name)
0032   : SubsysReco(name)
0033 {
0034   // reserves memory for max ADC samples
0035   m_adcSamples.resize(1024, 0);
0036 }
0037 
0038 //____________________________________________________________________________..
0039 int TpcChanQA::InitRun(PHCompositeNode * /*unused*/)
0040 {
0041   // Takes string of raw data file and truncates it down to sector number
0042   sectorNum = m_fname;
0043   size_t pos = sectorNum.find("TPC_ebdc");
0044   sectorNum.erase(sectorNum.begin(), sectorNum.begin() + pos + 8);
0045   sectorNum.erase(sectorNum.begin() + 2, sectorNum.end());
0046   if (sectorNum.at(0) == '0')
0047   {
0048     sectorNum.erase(sectorNum.begin(), sectorNum.begin() + 1);
0049   }
0050   //
0051 
0052   // Sets side to South if SectorNum > 11 (EBDC 12-23)
0053   if (stoi(sectorNum) > 11)
0054   {
0055     side = 1;
0056   }
0057 
0058   createHistos();
0059 
0060   return Fun4AllReturnCodes::EVENT_OK;
0061 }
0062 
0063 //____________________________________________________________________________..
0064 int TpcChanQA::process_event(PHCompositeNode *topNode)
0065 {
0066   // Defines object from class Event which calls getClass function from
0067   // findNode class
0068   Event *_event = findNode::getClass<Event>(topNode, "PRDF");
0069 
0070   // Checks if event exists and returns error if not
0071   if (_event == nullptr)
0072   {
0073     std::cout << "TPCRawDataTree::Process_Event - Event not found" << std::endl;
0074     return -1;
0075   }
0076 
0077   // Checks if event is "special" and discards it if so
0078   if (_event->getEvtType() >= 8)  /// special events
0079   {
0080     return Fun4AllReturnCodes::DISCARDEVENT;
0081   }
0082 
0083   // Call HistoManager
0084   auto hm = QAHistManagerDef::getHistoManager();
0085   assert(hm);
0086 
0087   // Reference histograms initialized in header file to histos in HistoManager
0088   h_channel_hits = dynamic_cast<TH1 *>(hm->getHisto(std::format("{}channel_hits_sec{}", getHistoPrefix(), sectorNum)));
0089   h_channel_ADCs = dynamic_cast<TH2 *>(hm->getHisto(std::format("{}channel_ADCs_sec{}", getHistoPrefix(), sectorNum)));
0090   //
0091 
0092   // Loop over packets in event
0093   for (int packet : m_packets)
0094   {
0095     if (Verbosity())
0096     {
0097       std::cout << __PRETTY_FUNCTION__ << " : decoding packet " << packet << std::endl;
0098     }
0099 
0100     m_packet = packet;
0101 
0102     // Assigns data from packet to variable p then checks if packet exists
0103     // Continues if not
0104     std::unique_ptr<Packet> p(_event->getPacket(m_packet));
0105     if (!p)
0106     {
0107       if (Verbosity())
0108       {
0109         std::cout << __PRETTY_FUNCTION__ << " : missing packet " << packet << std::endl;
0110       }
0111       continue;
0112     }
0113 
0114     // pull number of waveforms
0115     m_nWaveformInFrame = p->iValue(0, "NR_WF");
0116 
0117     for (int wf = 0; wf < m_nWaveformInFrame; wf++)
0118     {
0119       m_Channel = p->iValue(wf, "CHANNEL");
0120       m_nSamples = p->iValue(wf, "SAMPLES");
0121 
0122       h_channel_hits->Fill(m_Channel);
0123 
0124       // Checks if sample number and number of ADC values agrees
0125       // assert(m_nSamples < (int) m_adcSamples.size());
0126       if (m_nSamples > (int) m_adcSamples.size())
0127       {
0128         continue;
0129       }
0130 
0131       // Loop over samples in waveform
0132       for (int s = 0; s < m_nSamples; s++)
0133       {
0134         // Assign ADC value of sample s in waveform wf to adcSamples[s]
0135         m_adcSamples[s] = p->iValue(wf, s);
0136         h_channel_ADCs->Fill(m_Channel, m_adcSamples[s]);
0137       }
0138     }
0139   }
0140 
0141   return Fun4AllReturnCodes::EVENT_OK;
0142 }
0143 
0144 //____________________________________________________________________________..
0145 int TpcChanQA::End(PHCompositeNode * /*unused*/)
0146 {
0147   return Fun4AllReturnCodes::EVENT_OK;
0148 }
0149 
0150 //____________________________________________________________________________..
0151 std::string TpcChanQA::getHistoPrefix() const { return std::string("h_") + Name() + std::string("_"); }  // Define prefix to all histos in HistoManager
0152 
0153 //____________________________________________________________________________..
0154 void TpcChanQA::createHistos()
0155 {
0156   // Initialize HistoManager
0157   auto hm = QAHistManagerDef::getHistoManager();
0158   assert(hm);
0159 
0160   // Create and register histos in HistoManager
0161   {
0162     auto h = new TH1F(std::format("{}channel_hits_sec{}", getHistoPrefix(), sectorNum).c_str(), ";Channels;hits", 256, 0, 256);
0163     hm->registerHisto(h);
0164   }
0165 
0166   {
0167     auto h = new TH2F(std::format("{}channel_ADCs_sec{}", getHistoPrefix(), sectorNum).c_str(), ";Channels;ADCs", 256, 0, 256, 1024, 0, 1024);
0168     hm->registerHisto(h);
0169   }
0170 }