Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:12:21

0001 #include "CaloUnpackPRDF.h"
0002 
0003 #include "PROTOTYPE4_FEM.h"
0004 #include "RawTower_Prototype4.h"
0005 
0006 #include <calobase/RawTower.h>  // for RawTower
0007 #include <calobase/RawTowerContainer.h>
0008 #include <calobase/RawTowerDefs.h>  // for HCALIN, HCALOUT, CEMC
0009 
0010 #include <fun4all/Fun4AllReturnCodes.h>
0011 #include <fun4all/SubsysReco.h>  // for SubsysReco
0012 
0013 #include <phool/PHCompositeNode.h>
0014 #include <phool/PHIODataNode.h>    // for PHIODataNode
0015 #include <phool/PHNodeIterator.h>  // for PHNodeIterator
0016 #include <phool/PHObject.h>        // for PHObject
0017 #include <phool/getClass.h>
0018 #include <phool/phool.h>
0019 
0020 #include <Event/Event.h>
0021 #include <Event/EventTypes.h>
0022 #include <Event/packet.h>
0023 
0024 #include <cassert>
0025 #include <cmath>  // for NAN
0026 #include <iostream>
0027 #include <map>      // for _Rb_tree_const_iterator
0028 #include <utility>  // for pair
0029 
0030 using namespace std;
0031 
0032 //____________________________________
0033 CaloUnpackPRDF::CaloUnpackPRDF()
0034   : SubsysReco("CaloUnpackPRDF")
0035   ,
0036   /*Event**/ _event(nullptr)
0037   ,
0038   /*Packet_hbd_fpgashort**/ _packet(nullptr)
0039   ,
0040   /*int*/ _nevents(0)
0041   ,
0042   /*PHCompositeNode **/ dst_node(nullptr)
0043   ,
0044   /*PHCompositeNode **/ data_node(nullptr)
0045   ,
0046   /*RawTowerContainer**/ hcalin_towers_lg(nullptr)
0047   ,
0048   /*RawTowerContainer**/ hcalout_towers_lg(nullptr)
0049   ,
0050   /*RawTowerContainer**/ hcalin_towers_hg(nullptr)
0051   ,
0052   /*RawTowerContainer**/ hcalout_towers_hg(nullptr)
0053   ,
0054   /*RawTowerContainer**/ emcal_towers(nullptr)
0055 {
0056 }
0057 
0058 //_____________________________________
0059 int CaloUnpackPRDF::InitRun(PHCompositeNode *topNode)
0060 {
0061   CreateNodeTree(topNode);
0062   return Fun4AllReturnCodes::EVENT_OK;
0063 }
0064 
0065 //____________________________________
0066 int CaloUnpackPRDF::process_event(PHCompositeNode *topNode)
0067 {
0068   _nevents++;
0069   _event = findNode::getClass<Event>(topNode, "PRDF");
0070   if (_event == 0)
0071   {
0072     cout << "CaloUnpackPRDF::Process_Event - Event not found" << endl;
0073     return -1;
0074   }
0075 
0076   if (Verbosity())
0077   {
0078     cout << PHWHERE << "Process event entered" << std::endl;
0079   }
0080 
0081   if (Verbosity())
0082     _event->identify();
0083 
0084   _packet = _event->getPacket(PROTOTYPE4_FEM::PACKET_ID);
0085 
0086   if (!_packet)
0087   {
0088     // They could be special events at the beginning or end of run
0089     if (_event->getEvtType() == DATAEVENT)
0090     {
0091       cout << "CaloUnpackPRDF::Process_Event - Packet not found" << endl;
0092       _event->identify();
0093     }
0094     return Fun4AllReturnCodes::DISCARDEVENT;
0095   }
0096   RawTower_Prototype4 *tower_lg = nullptr;
0097   RawTower_Prototype4 *tower_hg = nullptr;
0098 
0099   // HCALIN
0100   assert(hcalin_towers_lg);
0101   //  assert(hcalin_towers_hg);
0102   for (int ibinz = 0; ibinz < PROTOTYPE4_FEM::NCH_IHCAL_ROWS; ibinz++)
0103   {
0104     for (int ibinphi = 0; ibinphi < PROTOTYPE4_FEM::NCH_IHCAL_COLUMNS;
0105          ibinphi++)
0106     {
0107       tower_lg = dynamic_cast<RawTower_Prototype4 *>(
0108           hcalin_towers_lg->getTower(ibinz, ibinphi));
0109       if (!tower_lg)
0110       {
0111         tower_lg = new RawTower_Prototype4();
0112         tower_lg->set_energy(NAN);
0113         hcalin_towers_lg->AddTower(ibinz, ibinphi, tower_lg);
0114       }
0115       //      tower_hg =
0116       //          dynamic_cast<RawTower_Prototype4
0117       //          *>(hcalin_towers_hg->getTower(
0118       //              ibinz, ibinphi));
0119       //      if (!tower_hg)
0120       //      {
0121       //        tower_hg = new RawTower_Prototype4();
0122       //        tower_hg->set_energy(NAN);
0123       //        hcalin_towers_hg->AddTower(ibinz, ibinphi, tower_hg);
0124       //      }
0125 
0126       int ich = PROTOTYPE4_FEM::GetChannelNumber("HCALIN", ibinz, ibinphi);
0127       tower_lg->set_HBD_channel_number(ich);
0128       //      tower_hg->set_HBD_channel_number(ich);
0129       for (int isamp = 0; isamp < PROTOTYPE4_FEM::NSAMPLES; isamp++)
0130       {
0131         //        tower_hg->set_signal_samples(isamp, _packet->iValue(isamp,
0132         //        ich) & PROTOTYPE4_FEM::ADC_DATA_MASK);
0133         tower_lg->set_signal_samples(isamp, _packet->iValue(isamp, ich) &
0134                                                 PROTOTYPE4_FEM::ADC_DATA_MASK);
0135       }
0136     }
0137   }
0138 
0139   // HCALOUT
0140   assert(hcalout_towers_lg);
0141   assert(hcalout_towers_hg);
0142   for (int ibinz = 0; ibinz < PROTOTYPE4_FEM::NCH_OHCAL_ROWS; ibinz++)
0143   {
0144     for (int ibinphi = 0; ibinphi < PROTOTYPE4_FEM::NCH_OHCAL_COLUMNS;
0145          ibinphi++)
0146     {
0147       tower_lg = dynamic_cast<RawTower_Prototype4 *>(
0148           hcalout_towers_lg->getTower(ibinz, ibinphi));
0149       if (!tower_lg)
0150       {
0151         tower_lg = new RawTower_Prototype4();
0152         tower_lg->set_energy(NAN);
0153         hcalout_towers_lg->AddTower(ibinz, ibinphi, tower_lg);
0154       }
0155       tower_hg = dynamic_cast<RawTower_Prototype4 *>(
0156           hcalout_towers_hg->getTower(ibinz, ibinphi));
0157       if (!tower_hg)
0158       {
0159         tower_hg = new RawTower_Prototype4();
0160         tower_hg->set_energy(NAN);
0161         hcalout_towers_hg->AddTower(ibinz, ibinphi, tower_hg);
0162       }
0163       int ich = PROTOTYPE4_FEM::GetChannelNumber("HCALOUT", ibinz, ibinphi);
0164       tower_lg->set_HBD_channel_number(ich);
0165       tower_hg->set_HBD_channel_number(ich);
0166       for (int isamp = 0; isamp < PROTOTYPE4_FEM::NSAMPLES; isamp++)
0167       {
0168         tower_lg->set_signal_samples(isamp, _packet->iValue(isamp, ich) &
0169                                                 PROTOTYPE4_FEM::ADC_DATA_MASK);
0170         tower_hg->set_signal_samples(isamp, _packet->iValue(isamp, ich + 1) &
0171                                                 PROTOTYPE4_FEM::ADC_DATA_MASK);
0172       }
0173     }
0174   }
0175 
0176   // EMCAL
0177   RawTower_Prototype4 *tower = nullptr;
0178   assert(emcal_towers);
0179   for (int ibinz = 0; ibinz < PROTOTYPE4_FEM::NCH_EMCAL_ROWS; ibinz++)
0180   {
0181     for (int ibinphi = 0; ibinphi < PROTOTYPE4_FEM::NCH_EMCAL_COLUMNS;
0182          ibinphi++)
0183     {
0184       tower = dynamic_cast<RawTower_Prototype4 *>(
0185           emcal_towers->getTower(ibinz, ibinphi));
0186       if (!tower)
0187       {
0188         tower = new RawTower_Prototype4();
0189         tower->set_energy(NAN);
0190         emcal_towers->AddTower(ibinz, ibinphi, tower);
0191       }
0192 
0193       int ich = PROTOTYPE4_FEM::GetChannelNumber("EMCAL", ibinz, ibinphi);
0194       tower->set_HBD_channel_number(ich);
0195       for (int isamp = 0; isamp < PROTOTYPE4_FEM::NSAMPLES; isamp++)
0196       {
0197         tower->set_signal_samples(isamp, _packet->iValue(isamp, ich) &
0198                                              PROTOTYPE4_FEM::ADC_DATA_MASK);
0199       }
0200     }
0201   }
0202 
0203   if (Verbosity())
0204   {
0205     cout << "HCALIN Towers: " << endl;
0206     hcalin_towers_hg->identify();
0207     RawTowerContainer::ConstRange begin_end = hcalin_towers_lg->getTowers();
0208     RawTowerContainer::ConstIterator iter;
0209     for (iter = begin_end.first; iter != begin_end.second; ++iter)
0210     {
0211       RawTower_Prototype4 *tower =
0212           dynamic_cast<RawTower_Prototype4 *>(iter->second);
0213       tower->identify();
0214       cout << "Signal Samples: [" << endl;
0215       for (int isamp = 0; isamp < PROTOTYPE4_FEM::NSAMPLES; isamp++)
0216       {
0217         cout << tower->get_signal_samples(isamp) << ", ";
0218       }
0219       cout << " ]" << endl;
0220     }
0221   }
0222   delete _packet;
0223   return Fun4AllReturnCodes::EVENT_OK;
0224 }
0225 
0226 //_______________________________________
0227 void CaloUnpackPRDF::CreateNodeTree(PHCompositeNode *topNode)
0228 {
0229   PHNodeIterator nodeItr(topNode);
0230   // DST node
0231   dst_node = static_cast<PHCompositeNode *>(
0232       nodeItr.findFirst("PHCompositeNode", "DST"));
0233   if (!dst_node)
0234   {
0235     cout << "PHComposite node created: DST" << endl;
0236     dst_node = new PHCompositeNode("DST");
0237     topNode->addNode(dst_node);
0238   }
0239 
0240   // DATA nodes
0241   data_node = static_cast<PHCompositeNode *>(
0242       nodeItr.findFirst("PHCompositeNode", "RAW_DATA"));
0243   if (!data_node)
0244   {
0245     if (Verbosity())
0246       cout << "PHComposite node created: RAW_DATA" << endl;
0247     data_node = new PHCompositeNode("RAW_DATA");
0248     dst_node->addNode(data_node);
0249   }
0250 
0251   // HCAL Towers
0252   hcalin_towers_lg = new RawTowerContainer(RawTowerDefs::HCALIN);
0253   PHIODataNode<PHObject> *tower_node = new PHIODataNode<PHObject>(
0254       hcalin_towers_lg, "TOWER_RAW_LG_HCALIN", "PHObject");
0255   data_node->addNode(tower_node);
0256   hcalin_towers_hg = new RawTowerContainer(RawTowerDefs::HCALIN);
0257   tower_node = new PHIODataNode<PHObject>(hcalin_towers_hg,
0258                                           "TOWER_RAW_HG_HCALIN", "PHObject");
0259   data_node->addNode(tower_node);
0260 
0261   hcalout_towers_lg = new RawTowerContainer(RawTowerDefs::HCALOUT);
0262   tower_node = new PHIODataNode<PHObject>(hcalout_towers_lg,
0263                                           "TOWER_RAW_LG_HCALOUT", "PHObject");
0264   data_node->addNode(tower_node);
0265   hcalout_towers_hg = new RawTowerContainer(RawTowerDefs::HCALOUT);
0266   tower_node = new PHIODataNode<PHObject>(hcalout_towers_hg,
0267                                           "TOWER_RAW_HG_HCALOUT", "PHObject");
0268   data_node->addNode(tower_node);
0269 
0270   // EMCAL towers
0271   emcal_towers = new RawTowerContainer(RawTowerDefs::CEMC);
0272   PHIODataNode<PHObject> *emcal_towerNode =
0273       new PHIODataNode<PHObject>(emcal_towers, "TOWER_RAW_CEMC", "PHObject");
0274   data_node->addNode(emcal_towerNode);
0275 }