Back to home page

sPhenix code displayed by LXR

 
 

    


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

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