Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-12-17 09:21:28

0001 #include "TriggerValid.h"
0002 
0003 // Trigger includes
0004 #include <calobase/TowerInfo.h>
0005 #include <calobase/TowerInfoContainer.h>
0006 #include <calobase/TowerInfoDefs.h>
0007 
0008 #include <calotrigger/LL1Out.h>
0009 #include <calotrigger/LL1Outv1.h>
0010 #include <calotrigger/TriggerDefs.h>
0011 #include <calotrigger/TriggerPrimitiveContainerv1.h>
0012 #include <calotrigger/TriggerPrimitivev1.h>
0013 
0014 #include <qautils/QAHistManagerDef.h>
0015 
0016 #include <ffarawobjects/Gl1Packet.h>
0017 
0018 #include <fun4all/Fun4AllHistoManager.h>
0019 #include <fun4all/Fun4AllReturnCodes.h>
0020 
0021 #include <phool/getClass.h>
0022 #include <phool/phool.h>  // for PHWHERE
0023 
0024 #include <TFile.h>
0025 #include <TH1.h>
0026 #include <TH2.h>
0027 #include <TLorentzVector.h>
0028 #include <TNtuple.h>
0029 #include <TProfile2D.h>
0030 #include <TSystem.h>
0031 #include <TTree.h>
0032 
0033 #include <algorithm>
0034 #include <cmath>     // for log10, pow, sqrt, abs, M_PI
0035 #include <format>
0036 #include <iostream>  // for operator<<, endl, basic_...
0037 #include <limits>
0038 #include <map>  // for operator!=, _Rb_tree_con...
0039 #include <string>
0040 #include <utility>  // for pair
0041 
0042 TriggerValid::TriggerValid(const std::string& name)
0043   : SubsysReco(name)
0044 {
0045 }
0046 
0047 int TriggerValid::Init(PHCompositeNode* /*unused*/)
0048 {
0049   auto *hm = QAHistManagerDef::getHistoManager();
0050   assert(hm);
0051   // create and register your histos (all types) here
0052 
0053   if (m_debug)
0054   {
0055     std::cout << "In TriggerValid::Init" << std::endl;
0056   }
0057   auto *h_gl1_triggers = new TH1D("h_gl1_triggers", ";Trigger Name;#Triggers", 64, -0.5, 63.5);
0058   hm->registerHisto(h_gl1_triggers);
0059   for (int i = 0; i < 8; i++)
0060   {
0061     auto *h_gl1_photon_energy = new TH1D(std::format("h_gl1_photon_energy_{}", i).c_str(), ";8x8 EMCAL energy [GeV]; counts", 100, 0, 50);
0062   auto *h_gl1_jetpatch_energy = new TH1D(std::format("h_gl1_jetpatch_energy_{}", i).c_str(), ";.8 x .8 EMCAL+HCAL energy [GeV]", 50, 0, 50);
0063     hm->registerHisto(h_gl1_photon_energy);
0064     hm->registerHisto(h_gl1_jetpatch_energy);
0065   }
0066 
0067   auto *h_emu_emcal_2x2_frequency = new TH2F("h_emu_emcal_2x2_frequency", ";#eta;#phi", 48, 0, 96, 128, 0, 256);
0068   hm->registerHisto(h_emu_emcal_2x2_frequency);
0069   auto *h_emu_emcal_8x8_frequency = new TH2F("h_emu_emcal_8x8_frequency", ";#eta;#phi", 12, 0, 96, 32, 0, 256);
0070   hm->registerHisto(h_emu_emcal_8x8_frequency);
0071   auto *h_emu_ihcal_2x2_frequency = new TH2F("h_emu_ihcal_2x2_frequency", ";#eta;#phi", 12, 0, 24, 32, 0, 64);
0072   hm->registerHisto(h_emu_ihcal_2x2_frequency);
0073   auto *h_emu_ohcal_2x2_frequency = new TH2F("h_emu_ohcal_2x2_frequency", ";#eta;#phi", 12, 0, 24, 32, 0, 64);
0074   hm->registerHisto(h_emu_ohcal_2x2_frequency);
0075   auto *h_emu_hcal_2x2_frequency = new TH2F("h_emu_hcal_2x2_frequency", ";#eta;#phi", 12, 0, 24, 32, 0, 64);
0076   hm->registerHisto(h_emu_hcal_2x2_frequency);
0077   for (int i = 0; i < 4; i++)
0078   {
0079     auto *h_emu_jet_frequency_trig = new TH2F(std::format("h_emu_jet_frequency_{}", i).c_str(), ";#eta;#phi", 9, 0, 9, 32, 0, 32);
0080     hm->registerHisto(h_emu_jet_frequency_trig);
0081 auto *h_emu_photon_frequency_trig = new TH2F(std::format("h_emu_photon_frequency_{}", i).c_str(), ";#eta;#phi", 12, 0, 12, 32, 0, 32);
0082     hm->registerHisto(h_emu_photon_frequency_trig);
0083   }
0084 
0085   auto *h_emu_emcal_2x2_avg_out = new TProfile2D("h_emu_emcal_2x2_avg_out", ";#eta;#phi", 48, 0, 96, 128, 0, 256);
0086   hm->registerHisto(h_emu_emcal_2x2_avg_out);
0087   auto *h_emu_emcal_8x8_avg_out = new TProfile2D("h_emu_emcal_8x8_avg_out", ";#eta;#phi", 12, 0, 96, 32, 0, 256);
0088   hm->registerHisto(h_emu_emcal_8x8_avg_out);
0089   auto *h_emu_ihcal_2x2_avg_out = new TProfile2D("h_emu_ihcal_2x2_avg_out", ";#eta;#phi", 12, 0, 24, 32, 0, 64);
0090   hm->registerHisto(h_emu_ihcal_2x2_avg_out);
0091   auto *h_emu_ohcal_2x2_avg_out = new TProfile2D("h_emu_ohcal_2x2_avg_out", ";#eta;#phi", 12, 0, 24, 32, 0, 64);
0092   hm->registerHisto(h_emu_ohcal_2x2_avg_out);
0093   auto *h_emu_hcal_2x2_avg_out = new TProfile2D("h_emu_hcal_2x2_avg_out", ";#eta;#phi", 12, 0, 24, 64, 0, 64);
0094   hm->registerHisto(h_emu_hcal_2x2_avg_out);
0095   auto *h_emcal_2x2_energy_lutsum = new TH2F("h_emcal_2x2_energy_lutsum", ";LUT output; Energy [GeV]", 256, -0.5, 255.5, 200, 0, 20);
0096   hm->registerHisto(h_emcal_2x2_energy_lutsum);
0097   auto *h_emcal_8x8_energy_lutsum = new TH2F("h_emcal_8x8_energy_lutsum", ";LUT output; Energy [GeV]", 256, -0.5, 255.5, 200, 0, 20);
0098   hm->registerHisto(h_emcal_8x8_energy_lutsum);
0099   auto *h_hcal_2x2_energy_lutsum = new TH2F("h_hcal_2x2_energy_lutsum", ";LUT output; Energy [GeV]", 256, -0.5, 255.5, 200, 0, 20);
0100   hm->registerHisto(h_hcal_2x2_energy_lutsum);
0101   auto *h_hcalin_2x2_energy_lutsum = new TH2F("h_hcalin_2x2_energy_lutsum", ";LUT output; Energy [GeV]", 256, -0.5, 255.5, 200, 0, 20);
0102   hm->registerHisto(h_hcalin_2x2_energy_lutsum);
0103   auto *h_hcalout_2x2_energy_lutsum = new TH2F("h_hcalout_2x2_energy_lutsum", ";LUT output; Energy [GeV]", 256, -0.5, 255.5, 200, 0, 20);
0104   hm->registerHisto(h_hcalout_2x2_energy_lutsum);
0105 
0106   auto *h_jet_energy_lutsum = new TH2F("h_jet_energy_lutsum", ";LUT output; Energy [GeV]", 4096, -0.5, 4095.5, 200, 0, 20);
0107   hm->registerHisto(h_jet_energy_lutsum);
0108 
0109   if (m_debug)
0110   {
0111     std::cout << "Leaving TriggerValid::Init" << std::endl;
0112   }
0113   return 0;
0114 }
0115 
0116 int TriggerValid::process_event(PHCompositeNode* topNode)
0117 {
0118   _eventcounter++;
0119 
0120   process_towers(topNode);
0121 
0122   return Fun4AllReturnCodes::EVENT_OK;
0123 }
0124 
0125 int TriggerValid::process_towers(PHCompositeNode* topNode) const
0126 {
0127   if (m_debug)
0128   {
0129     std::cout << _eventcounter << std::endl;
0130   }
0131 
0132   TowerInfoContainer* towers_emcal = findNode::getClass<TowerInfoContainer>(topNode, "TOWERINFO_CALIB_CEMC");
0133 
0134   TowerInfoContainer* towers_hcalin = findNode::getClass<TowerInfoContainer>(topNode, "TOWERINFO_CALIB_HCALIN");
0135 
0136   TowerInfoContainer* towers_hcalout = findNode::getClass<TowerInfoContainer>(topNode, "TOWERINFO_CALIB_HCALOUT");
0137 
0138   LL1Out* ll1out_jet = findNode::getClass<LL1Out>(topNode, "LL1OUT_JET");
0139 
0140   LL1Out* ll1out_photon = findNode::getClass<LL1Out>(topNode, "LL1OUT_PHOTON");
0141 
0142   // y  LL1Out* ll1out_pair = findNode::getClass<LL1Out>(topNode, "LL1OUT_PAIR");
0143 
0144   TriggerPrimitiveContainer* trigger_primitives_emcal = findNode::getClass<TriggerPrimitiveContainer>(topNode, "TRIGGERPRIMITIVES_EMCAL");
0145 
0146   TriggerPrimitiveContainer* trigger_primitives_emcal_ll1 = findNode::getClass<TriggerPrimitiveContainer>(topNode, "TRIGGERPRIMITIVES_EMCAL_LL1");
0147 
0148   TriggerPrimitiveContainer* trigger_primitives_hcalin = findNode::getClass<TriggerPrimitiveContainer>(topNode, "TRIGGERPRIMITIVES_HCALIN");
0149 
0150   TriggerPrimitiveContainer* trigger_primitives_hcalout = findNode::getClass<TriggerPrimitiveContainer>(topNode, "TRIGGERPRIMITIVES_HCALOUT");
0151 
0152   TriggerPrimitiveContainer* trigger_primitives_hcal_ll1 = findNode::getClass<TriggerPrimitiveContainer>(topNode, "TRIGGERPRIMITIVES_HCAL_LL1");
0153 
0154   Gl1Packet* gl1_packet = findNode::getClass<Gl1Packet>(topNode, "GL1Packet");
0155 
0156   auto *hm = QAHistManagerDef::getHistoManager();
0157   assert(hm);
0158 
0159   auto *h_emu_emcal_2x2_frequency = dynamic_cast<TH2*>(hm->getHisto("h_emu_emcal_2x2_frequency"));
0160   auto *h_emu_emcal_8x8_frequency = dynamic_cast<TH2*>(hm->getHisto("h_emu_emcal_8x8_frequency"));
0161   auto *h_emu_ihcal_2x2_frequency = dynamic_cast<TH2*>(hm->getHisto("h_emu_ihcal_2x2_frequency"));
0162   auto *h_emu_ohcal_2x2_frequency = dynamic_cast<TH2*>(hm->getHisto("h_emu_ohcal_2x2_frequency"));
0163   auto *h_emu_hcal_2x2_frequency = dynamic_cast<TH2*>(hm->getHisto("h_emu_hcal_2x2_frequency"));
0164 
0165   TH2* h_emu_jet_frequency_trig[4];
0166   TH2* h_emu_photon_frequency_trig[4];
0167   for (int i = 0; i < 4; i++)
0168   {
0169     h_emu_jet_frequency_trig[i] = dynamic_cast<TH2*>(hm->getHisto(std::format("h_emu_jet_frequency_{}", i)));
0170   h_emu_photon_frequency_trig[i] = dynamic_cast<TH2*>(hm->getHisto(std::format("h_emu_photon_frequency_{}", i)));
0171   }
0172 
0173   auto *h_gl1_triggers = dynamic_cast<TH1*>(hm->getHisto("h_gl1_triggers"));
0174   TH1* h_gl1_jetpatch_energy[8];
0175   TH1* h_gl1_photon_energy[8];
0176 
0177   for (int i = 0; i < 8; i++)
0178   {
0179     h_gl1_jetpatch_energy[i] = dynamic_cast<TH1*>(hm->getHisto(std::format("h_gl1_jetpatch_energy_{}", i)));
0180 h_gl1_photon_energy[i] = dynamic_cast<TH1*>(hm->getHisto(std::format("h_gl1_photon_energy_{}", i)));
0181   }
0182 
0183   auto *h_emu_emcal_2x2_avg_out = dynamic_cast<TProfile2D*>(hm->getHisto("h_emu_emcal_2x2_avg_out"));
0184   auto *h_emu_emcal_8x8_avg_out = dynamic_cast<TProfile2D*>(hm->getHisto("h_emu_emcal_8x8_avg_out"));
0185   auto *h_emu_ihcal_2x2_avg_out = dynamic_cast<TProfile2D*>(hm->getHisto("h_emu_ihcal_2x2_avg_out"));
0186   auto *h_emu_ohcal_2x2_avg_out = dynamic_cast<TProfile2D*>(hm->getHisto("h_emu_ohcal_2x2_avg_out"));
0187   auto *h_emu_hcal_2x2_avg_out = dynamic_cast<TProfile2D*>(hm->getHisto("h_emu_hcal_2x2_avg_out"));
0188   auto *h_emcal_2x2_energy_lutsum = dynamic_cast<TH2*>(hm->getHisto("h_emcal_2x2_energy_lutsum"));
0189   auto *h_emcal_8x8_energy_lutsum = dynamic_cast<TH2*>(hm->getHisto("h_emcal_8x8_energy_lutsum"));
0190   auto *h_hcal_2x2_energy_lutsum = dynamic_cast<TH2*>(hm->getHisto("h_hcal_2x2_energy_lutsum"));
0191   auto *h_hcalin_2x2_energy_lutsum = dynamic_cast<TH2*>(hm->getHisto("h_hcalin_2x2_energy_lutsum"));
0192   auto *h_hcalout_2x2_energy_lutsum = dynamic_cast<TH2*>(hm->getHisto("h_hcalout_2x2_energy_lutsum"));
0193   auto *h_jet_energy_lutsum = dynamic_cast<TH2*>(hm->getHisto("h_jet_energy_lutsum"));
0194 
0195   std::map<TriggerDefs::TriggerSumKey, unsigned int> v_emcal_emu_2x2 = {};
0196 
0197   std::map<TriggerDefs::TriggerSumKey, unsigned int> v_emcal_emu_8x8 = {};
0198 
0199   std::map<TriggerDefs::TriggerSumKey, unsigned int> v_hcal_emu_2x2 = {};
0200   std::map<TriggerDefs::TriggerSumKey, unsigned int> v_hcalin_emu_2x2 = {};
0201   std::map<TriggerDefs::TriggerSumKey, unsigned int> v_hcalout_emu_2x2 = {};
0202 
0203   std::map<TriggerDefs::TriggerSumKey, unsigned int> v_jet_emu = {};
0204 
0205   std::vector<int> trig_bits{};
0206   if (gl1_packet)
0207   {
0208     ULong64_t gl1_scaledvec = gl1_packet->lValue(0, "ScaledVector");
0209     for (unsigned int bit = 0; bit < 64; bit++)
0210     {
0211       if (((gl1_scaledvec >> bit) & 0x1U) == 0x1U)
0212       {
0213         trig_bits.push_back(bit);
0214         h_gl1_triggers->Fill(bit);
0215       }
0216     }
0217   }
0218 
0219   if (trigger_primitives_emcal)
0220   {
0221     TriggerPrimitiveContainerv1::Range range = trigger_primitives_emcal->getTriggerPrimitives();
0222     for (TriggerPrimitiveContainerv1::Iter iter = range.first; iter != range.second; ++iter)
0223     {
0224       TriggerPrimitive* trigger_primitive = (*iter).second;
0225       TriggerPrimitivev1::Range srange = trigger_primitive->getSums();
0226       for (TriggerPrimitive::Iter siter = srange.first; siter != srange.second; ++siter)
0227       {
0228         std::vector<unsigned int>* sum = (*siter).second;
0229         std::vector<unsigned int>::iterator it = max_element(sum->begin(), sum->end());
0230         unsigned int summ = 0;
0231         unsigned int sumk = (*siter).first;
0232 
0233         if (it != sum->end())
0234         {
0235           summ = (*it);
0236         }
0237 
0238         uint16_t sum_phi = TriggerDefs::getSumPhiId(sumk) + 4 * TriggerDefs::getPrimitivePhiId_from_TriggerSumKey(sumk);
0239         uint16_t sum_eta = TriggerDefs::getSumEtaId(sumk) + 4 * TriggerDefs::getPrimitiveEtaId_from_TriggerSumKey(sumk);
0240 
0241         if (summ)
0242         {
0243           float i2x2x = h_emu_emcal_2x2_frequency->GetXaxis()->GetBinCenter(sum_eta + 1);
0244           float i2x2y = h_emu_emcal_2x2_frequency->GetYaxis()->GetBinCenter(sum_phi + 1);
0245           h_emu_emcal_2x2_frequency->Fill(i2x2x, i2x2y, 1);
0246           h_emu_emcal_2x2_avg_out->Fill(i2x2x, i2x2y, summ);
0247         }
0248         v_emcal_emu_2x2[sumk] = summ;
0249       }
0250     }
0251   }
0252 
0253   if (trigger_primitives_emcal_ll1)
0254   {
0255     TriggerPrimitiveContainerv1::Range range = trigger_primitives_emcal_ll1->getTriggerPrimitives();
0256     for (TriggerPrimitiveContainerv1::Iter iter = range.first; iter != range.second; ++iter)
0257     {
0258       TriggerPrimitive* trigger_primitive = (*iter).second;
0259       TriggerPrimitivev1::Range srange = trigger_primitive->getSums();
0260       for (TriggerPrimitive::Iter siter = srange.first; siter != srange.second; ++siter)
0261       {
0262         std::vector<unsigned int>* sum = (*siter).second;
0263         std::vector<unsigned int>::iterator it = max_element(sum->begin(), sum->end());
0264         unsigned int summ = 0;
0265         unsigned int sumk = (*siter).first;
0266 
0267         if (it != sum->end())
0268         {
0269           summ = (*it);
0270         }
0271 
0272         uint16_t sum_phi = TriggerDefs::getSumPhiId(sumk) + 2 * TriggerDefs::getPrimitivePhiId_from_TriggerSumKey(sumk);
0273         uint16_t sum_eta = TriggerDefs::getSumEtaId(sumk);
0274 
0275         if (summ)
0276         {
0277           float i2x2x = h_emu_emcal_8x8_frequency->GetXaxis()->GetBinCenter(sum_eta + 1);
0278           float i2x2y = h_emu_emcal_8x8_frequency->GetYaxis()->GetBinCenter(sum_phi + 1);
0279 
0280           h_emu_emcal_8x8_frequency->Fill(i2x2x, i2x2y, 1);
0281           h_emu_emcal_8x8_avg_out->Fill(i2x2x, i2x2y, summ);
0282         }
0283         v_emcal_emu_8x8[sumk] = summ;
0284       }
0285     }
0286   }
0287 
0288   if (trigger_primitives_hcalin)
0289   {
0290     TriggerPrimitiveContainerv1::Range range = trigger_primitives_hcalin->getTriggerPrimitives();
0291     for (TriggerPrimitiveContainerv1::Iter iter = range.first; iter != range.second; ++iter)
0292     {
0293       TriggerPrimitive* trigger_primitive = (*iter).second;
0294       TriggerPrimitivev1::Range srange = trigger_primitive->getSums();
0295       for (TriggerPrimitive::Iter siter = srange.first; siter != srange.second; ++siter)
0296       {
0297         std::vector<unsigned int>* sum = (*siter).second;
0298         std::vector<unsigned int>::iterator it = max_element(sum->begin(), sum->end());
0299         unsigned int summ = 0;
0300         unsigned int sumk = (*siter).first;
0301 
0302         if (it != sum->end())
0303         {
0304           summ = (*it);
0305         }
0306 
0307         uint16_t sum_phi = TriggerDefs::getSumPhiId(sumk) + 4 * TriggerDefs::getPrimitivePhiId_from_TriggerSumKey(sumk);
0308         uint16_t sum_eta = TriggerDefs::getSumEtaId(sumk) + 4 * TriggerDefs::getPrimitiveEtaId_from_TriggerSumKey(sumk);
0309 
0310         if (summ)
0311         {
0312           float i2x2x = h_emu_ihcal_2x2_frequency->GetXaxis()->GetBinCenter(sum_eta + 1);
0313           float i2x2y = h_emu_ihcal_2x2_frequency->GetYaxis()->GetBinCenter(sum_phi + 1);
0314           h_emu_ihcal_2x2_frequency->Fill(i2x2x, i2x2y, 1);
0315           h_emu_ihcal_2x2_avg_out->Fill(i2x2x, i2x2y, summ);
0316         }
0317         v_hcalin_emu_2x2[sumk] = summ;
0318       }
0319     }
0320   }
0321 
0322   if (trigger_primitives_hcalout)
0323   {
0324     TriggerPrimitiveContainerv1::Range range = trigger_primitives_hcalout->getTriggerPrimitives();
0325     for (TriggerPrimitiveContainerv1::Iter iter = range.first; iter != range.second; ++iter)
0326     {
0327       TriggerPrimitive* trigger_primitive = (*iter).second;
0328       TriggerPrimitivev1::Range srange = trigger_primitive->getSums();
0329       for (TriggerPrimitive::Iter siter = srange.first; siter != srange.second; ++siter)
0330       {
0331         std::vector<unsigned int>* sum = (*siter).second;
0332         std::vector<unsigned int>::iterator it = max_element(sum->begin(), sum->end());
0333         unsigned int summ = 0;
0334         unsigned int sumk = (*siter).first;
0335 
0336         if (it != sum->end())
0337         {
0338           summ = (*it);
0339         }
0340         uint16_t sum_phi = TriggerDefs::getSumPhiId(sumk) + 4 * TriggerDefs::getPrimitivePhiId_from_TriggerSumKey(sumk);
0341         uint16_t sum_eta = TriggerDefs::getSumEtaId(sumk) + 4 * TriggerDefs::getPrimitiveEtaId_from_TriggerSumKey(sumk);
0342 
0343         if (summ)
0344         {
0345           float i2x2x = h_emu_ohcal_2x2_frequency->GetXaxis()->GetBinCenter(sum_eta + 1);
0346           float i2x2y = h_emu_ohcal_2x2_frequency->GetYaxis()->GetBinCenter(sum_phi + 1);
0347           h_emu_ohcal_2x2_frequency->Fill(i2x2x, i2x2y, 1);
0348           h_emu_ohcal_2x2_avg_out->Fill(i2x2x, i2x2y, summ);
0349         }
0350         v_hcalout_emu_2x2[sumk] = summ;
0351       }
0352     }
0353   }
0354 
0355   if (trigger_primitives_hcal_ll1)
0356   {
0357     TriggerPrimitiveContainerv1::Range range = trigger_primitives_hcal_ll1->getTriggerPrimitives();
0358     for (TriggerPrimitiveContainerv1::Iter iter = range.first; iter != range.second; ++iter)
0359     {
0360       TriggerPrimitive* trigger_primitive = (*iter).second;
0361       TriggerPrimitivev1::Range srange = trigger_primitive->getSums();
0362       for (TriggerPrimitive::Iter siter = srange.first; siter != srange.second; ++siter)
0363       {
0364         std::vector<unsigned int>* sum = (*siter).second;
0365         std::vector<unsigned int>::iterator it = max_element(sum->begin(), sum->end());
0366         unsigned int summ = 0;
0367         unsigned int sumk = (*siter).first;
0368 
0369         if (it != sum->end())
0370         {
0371           summ = (*it);
0372         }
0373 
0374         uint16_t sum_phi = TriggerDefs::getSumPhiId(sumk) + 2 * TriggerDefs::getPrimitivePhiId_from_TriggerSumKey(sumk);
0375         uint16_t sum_eta = TriggerDefs::getSumEtaId(sumk);
0376 
0377         if (summ)
0378         {
0379           float i2x2x = h_emu_hcal_2x2_frequency->GetXaxis()->GetBinCenter(sum_eta + 1);
0380           float i2x2y = h_emu_hcal_2x2_frequency->GetYaxis()->GetBinCenter(sum_phi + 1);
0381           h_emu_hcal_2x2_frequency->Fill(i2x2x, i2x2y, 1);
0382           h_emu_hcal_2x2_avg_out->Fill(i2x2x, i2x2y, summ);
0383         }
0384         v_hcal_emu_2x2[sumk] = summ;
0385       }
0386     }
0387   }
0388 
0389   if (ll1out_photon)
0390   {
0391     for (int i = 0; i < 4; i++)
0392     {
0393       auto triggered_sums = ll1out_photon->getTriggeredSumKeys(i + 1);
0394       for (auto& key : triggered_sums)
0395       {
0396         unsigned int phi = TriggerDefs::getSumPhiId(key) + TriggerDefs::getPrimitivePhiId_from_TriggerSumKey(key) * 2;
0397         unsigned int eta = TriggerDefs::getSumEtaId(key);
0398 
0399         h_emu_photon_frequency_trig[i]->Fill(eta, phi);
0400       }
0401     }
0402   }
0403 
0404   if (ll1out_jet)
0405   {
0406     for (int i = 0; i < 4; i++)
0407     {
0408       auto triggered_sums = ll1out_jet->getTriggeredSumKeys(i + 1);
0409       for (auto& key : triggered_sums)
0410       {
0411         int eta = (key >> 16U) & 0xffffU;
0412         int phi = (key & 0xffffU);
0413         h_emu_jet_frequency_trig[i]->Fill(eta, phi);
0414       }
0415     }
0416   }
0417 
0418   // h_emcal_2x2_energy_lutsum = new TH2F("h_emcal_2x2_energy_lutsum",";Energy [GeV];LUT output", 100, 0, 10, 64, 0, 256);
0419   // h_emcal_8x8_energy_lutsum = new TH2F("h_emcal_8x8_energy_lutsum",";Energy [GeV];LUT output", 100, 0, 10, 64, 0, 256);
0420   // h_hcal_2x2_energy_lutsum = new TH2F("h_hcal_2x2_energy_lutsum",";Energy [GeV];LUT output", 100, 0, 10, 64, 0, 256);
0421   // h_jet_energy_lutsum = new TH2F("h_jet_energy_lutsum",";Energy [GeV];LUT output", 100, 0, 10, 64, 0, 256*16);
0422 
0423   float emcal_energies[12][35]{};
0424   float hcal_energies[12][35]{};
0425   float max_energy_emcal = 0.0;
0426   if (towers_emcal)
0427   {
0428     // go through the emulated 2x2 map for emcal
0429     for (auto& it : v_emcal_emu_2x2)
0430     {
0431       unsigned int sumk = it.first;
0432       uint16_t sum_phi = TriggerDefs::getSumPhiId(sumk) + 4 * TriggerDefs::getPrimitivePhiId_from_TriggerSumKey(sumk);
0433       uint16_t sum_eta = TriggerDefs::getSumEtaId(sumk) + 4 * TriggerDefs::getPrimitiveEtaId_from_TriggerSumKey(sumk);
0434 
0435       float energy_sum = 0.0;
0436       for (int itower = 0; itower < 4; itower++)
0437       {
0438         int ieta = sum_eta * 2 + itower % 2;
0439         int iphi = sum_phi * 2 + itower / 2;
0440         TowerInfo* tower = towers_emcal->get_tower_at_key(TowerInfoDefs::encode_emcal(ieta, iphi));
0441         float offlineenergy = tower->get_energy();
0442         if (!tower->get_isGood())
0443         {
0444           continue;
0445         }
0446         energy_sum += offlineenergy;
0447       }
0448       h_emcal_2x2_energy_lutsum->Fill(it.second, energy_sum);
0449     }
0450 
0451     // now the 8x8
0452 
0453     for (auto& it : v_emcal_emu_8x8)
0454     {
0455       unsigned int sumk = it.first;
0456       uint16_t sum_phi = TriggerDefs::getSumPhiId(sumk) + 2 * TriggerDefs::getPrimitivePhiId_from_TriggerSumKey(sumk);
0457       uint16_t sum_eta = TriggerDefs::getSumEtaId(sumk);
0458 
0459       float energy_sum = 0.0;
0460       for (int itower = 0; itower < 64; itower++)
0461       {
0462         int ieta = sum_eta * 8 + itower % 8;
0463         int iphi = sum_phi * 8 + itower / 8;
0464         TowerInfo* tower = towers_emcal->get_tower_at_key(TowerInfoDefs::encode_emcal(ieta, iphi));
0465         float offlineenergy = tower->get_energy();
0466         if (!tower->get_isGood())
0467         {
0468           continue;
0469         }
0470         energy_sum += offlineenergy;
0471       }
0472       max_energy_emcal = std::max(energy_sum, max_energy_emcal);
0473       emcal_energies[sum_eta][sum_phi] = energy_sum;
0474       h_emcal_8x8_energy_lutsum->Fill(it.second, energy_sum);
0475     }
0476   }
0477 
0478   if (towers_hcalin || towers_hcalout)
0479   {
0480     // go through the emulated 2x2 map for emcal
0481     for (auto& it : v_hcal_emu_2x2)
0482     {
0483       unsigned int sumk = it.first;
0484       uint16_t sum_phi = TriggerDefs::getSumPhiId(sumk) + 2 * TriggerDefs::getPrimitivePhiId_from_TriggerSumKey(sumk);
0485       uint16_t sum_eta = TriggerDefs::getSumEtaId(sumk);
0486 
0487       float energy_sum = 0.0;
0488       for (int itower = 0; itower < 4; itower++)
0489       {
0490         int ieta = sum_eta * 2 + itower % 2;
0491         int iphi = sum_phi * 2 + itower / 2;
0492         if (towers_hcalin)
0493         {
0494           TowerInfo* tower = towers_hcalin->get_tower_at_key(TowerInfoDefs::encode_hcal(ieta, iphi));
0495           float offlineenergy = tower->get_energy();
0496 
0497           if (!tower->get_isGood())
0498           {
0499             continue;
0500           }
0501           energy_sum += offlineenergy;
0502         }
0503         if (towers_hcalin)
0504         {
0505           TowerInfo* tower = towers_hcalout->get_tower_at_key(TowerInfoDefs::encode_hcal(ieta, iphi));
0506           float offlineenergy = tower->get_energy();
0507           if (!tower->get_isGood())
0508           {
0509             continue;
0510           }
0511           energy_sum += offlineenergy;
0512         }
0513       }
0514       h_hcal_2x2_energy_lutsum->Fill(it.second, energy_sum);
0515       hcal_energies[sum_eta][sum_phi] = energy_sum;
0516     }
0517 
0518     // go through the emulated 2x2 map for emcal
0519     for (auto& it : v_hcalin_emu_2x2)
0520     {
0521       unsigned int sumk = it.first;
0522       uint16_t sum_phi = TriggerDefs::getSumPhiId(sumk) + 2 * TriggerDefs::getPrimitivePhiId_from_TriggerSumKey(sumk);
0523       uint16_t sum_eta = TriggerDefs::getSumEtaId(sumk);
0524 
0525       float energy_sum = 0.0;
0526       for (int itower = 0; itower < 4; itower++)
0527       {
0528         int ieta = sum_eta * 2 + itower % 2;
0529         int iphi = sum_phi * 2 + itower / 2;
0530         if (towers_hcalin)
0531         {
0532           TowerInfo* tower = towers_hcalin->get_tower_at_key(TowerInfoDefs::encode_hcal(ieta, iphi));
0533           float offlineenergy = tower->get_energy();
0534 
0535           if (!tower->get_isGood())
0536           {
0537             continue;
0538           }
0539           energy_sum += offlineenergy;
0540         }
0541       }
0542       h_hcalin_2x2_energy_lutsum->Fill(it.second, energy_sum);
0543     }
0544     // go through the emulated 2x2 map for emcal
0545     for (auto& it : v_hcalout_emu_2x2)
0546     {
0547       unsigned int sumk = it.first;
0548       uint16_t sum_phi = TriggerDefs::getSumPhiId(sumk) + 2 * TriggerDefs::getPrimitivePhiId_from_TriggerSumKey(sumk);
0549       uint16_t sum_eta = TriggerDefs::getSumEtaId(sumk);
0550 
0551       float energy_sum = 0.0;
0552       for (int itower = 0; itower < 4; itower++)
0553       {
0554         int ieta = sum_eta * 2 + itower % 2;
0555         int iphi = sum_phi * 2 + itower / 2;
0556 
0557         if (towers_hcalout)
0558         {
0559           TowerInfo* tower = towers_hcalout->get_tower_at_key(TowerInfoDefs::encode_hcal(ieta, iphi));
0560           float offlineenergy = tower->get_energy();
0561           if (!tower->get_isGood())
0562           {
0563             continue;
0564           }
0565           energy_sum += offlineenergy;
0566         }
0567       }
0568       h_hcalout_2x2_energy_lutsum->Fill(it.second, energy_sum);
0569     }
0570   }
0571 
0572   float jet_energies[9][32]{};
0573   float max_energy_jetpatch = 0.0;
0574   for (int i = 0; i < 3; i++)
0575   {
0576     for (int j = 0; j < 12; j++)
0577     {
0578       emcal_energies[j][i + 32] = emcal_energies[j][i];
0579       hcal_energies[j][i + 32] = hcal_energies[j][i];
0580     }
0581   }
0582   for (int i = 0; i < 9; i++)
0583   {
0584     for (int j = 0; j < 32; j++)
0585     {
0586       for (int k = 0; k < 16; k++)
0587       {
0588         jet_energies[i][j] += emcal_energies[i + k % 4][j + k / 4];
0589         jet_energies[i][j] += hcal_energies[i + k % 4][j + k / 4];
0590       }
0591     }
0592   }
0593 
0594   for (auto& it : v_jet_emu)
0595   {
0596     unsigned int sumk = it.first;
0597     uint16_t sum_phi = sumk & 0xffffU;
0598     uint16_t sum_eta = (sumk >> 16U) & 0xffffU;
0599 
0600     max_energy_jetpatch = std::max(max_energy_jetpatch, jet_energies[sum_eta][sum_phi]);
0601     h_jet_energy_lutsum->Fill(it.second, jet_energies[sum_eta][sum_phi]);
0602   }
0603 
0604   for (auto& j : trig_bits)
0605   {
0606     if (j >= 16 && j < 24)
0607     {
0608       h_gl1_jetpatch_energy[j - 16]->Fill(max_energy_jetpatch);
0609     }
0610     else if (j >= 24 && j < 32)
0611     {
0612       h_gl1_photon_energy[j - 24]->Fill(max_energy_emcal);
0613     }
0614   }
0615   return Fun4AllReturnCodes::EVENT_OK;
0616 }