Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-12-19 09:24:40

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